[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v3] iommu/amd-vi: do not zero IOMMU MMIO region


  • To: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 7 May 2026 10:51:18 +0200
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=google header.d=suse.com header.i="@suse.com" header.h="Content-Transfer-Encoding:In-Reply-To:Autocrypt:From:Content-Language:References:Cc:To:Subject:User-Agent:MIME-Version:Date:Message-ID"
  • Autocrypt: addr=jbeulich@xxxxxxxx; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Jason Andryuk <jason.andryuk@xxxxxxx>, Teddy Astie <teddy.astie@xxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Thu, 07 May 2026 08:51:39 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 07.05.2026 10:46, Roger Pau Monné wrote:
> On Thu, May 07, 2026 at 10:03:05AM +0200, Jan Beulich wrote:
>> On 06.05.2026 18:51, Roger Pau Monne wrote:
>>> Attempting to memset the whole IOMMU MMIO region to zero is dangerous to
>>> say the least.  We don't know what registers might be there, nor which
>>> values might be safe for those registers.  On a forthcoming platform doing
>>> the zeroing of the MMIO region does put the IOMMU in a broken state, which
>>> is not recoverable by the IOMMU initialization procedure in Xen.
>>>
>>> Instead just zero the control register, which mimics the current behavior
>>> with regards to how the control register is handled, and ensures the IOMU
>>> setup is done with the unit disabled.  This approach will need revisiting
>>> in order to support Preboot DMA Protection.
>>>
>>> Fold map_iommu_mmio_region() into its only caller, as the function body is
>>> just an ioremap() call after the removal of the memset().
>>>
>>> Fixes: 0700c962ac2d ("Add AMD IOMMU support into hypervisor")
>>> Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
>>
>> While you got Andrew's R-b, I don't view that as enough to commit it. My
>> prior concern towards ...
>>
>>> --- a/xen/drivers/passthrough/amd/iommu_init.c
>>> +++ b/xen/drivers/passthrough/amd/iommu_init.c
>>> @@ -42,18 +42,6 @@ static bool iommu_has_ht_flag(struct amd_iommu *iommu, 
>>> u8 mask)
>>>      return iommu->ht_flags & mask;
>>>  }
>>>  
>>> -static int __init map_iommu_mmio_region(struct amd_iommu *iommu)
>>> -{
>>> -    iommu->mmio_base = ioremap(iommu->mmio_base_phys,
>>> -                               IOMMU_MMIO_REGION_LENGTH);
>>> -    if ( !iommu->mmio_base )
>>> -        return -ENOMEM;
>>> -
>>> -    memset(iommu->mmio_base, 0, IOMMU_MMIO_REGION_LENGTH);
>>> -
>>> -    return 0;
>>> -}
>>
>> ... this part of the change wasn't addressed, neither verbally nor by an
>> adjustment to the description of what was committed. As previously stated,
>> blindly memset()-ing the entire area may not be the best of all options,
>> but the downsides of not doing this need to somehow be addressed. As
>> indicated, once they run out of bits in the main control register, they
>> likely will add a 2nd one. That'll then also need clearing, yet we have
>> no code to do so anymore.
> 
> I could introduce an opt-in command line option that forces the
> zeroing of the MMIO region (to have the option to resort to the
> previous behavior),

But we don't want to fully go back to this. We'd need a form that zeroes
what may be zeroed, without causing the issue you're trying to address.

> but I was (wrongly) under the impression that we
> have agreement the proposed approach was the least bad of the ones
> available, sorry.
> 
> Note how VT-d also doesn't zero the IOMMU registers MMIO page either,
> neither does it seems to zero the Global Command Register either,
> which I'm not saying it's correct, but is at least a (possibly wrong)
> precedent.  I don't think there's much we can do with the handling of
> enabled bits in possibly registers not know/handled by Xen.  Like on
> VT-d, we possibly need to rely on the firmware to handle the IOMMU in
> a half-sane configuration, with no enabled features on registers Xen
> doesn't know about.

As indicated before, for firmware we can likely rely on that. Pre-boot
non-firmware environments and especially Xen being kexec-ed (or being
run past something which was kexec-ed) may be of more concern.

Jan



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.