From: Lu Baolu <baolu.lu@linux.intel.com>
To: Jerry Snitselaar <jsnitsel@redhat.com>,
Alex Williamson <alex.williamson@redhat.com>
Cc: iommu@lists.linux-foundation.org, dwmw2@infradead.org
Subject: Re: [PATCH] iommu/vt-d: Fix unmap_pages support
Date: Fri, 19 Nov 2021 08:52:44 +0800 [thread overview]
Message-ID: <824525d8-a367-a7ec-9706-4ec99be7161f@linux.intel.com> (raw)
In-Reply-To: <a68f646759351becc665896b72a308c734295892.camel@redhat.com>
Hi Jerry,
On 11/19/21 3:48 AM, Jerry Snitselaar wrote:
> On Fri, 2021-11-12 at 10:59 +0800, Lu Baolu wrote:
>> Hi Alex,
>>
>> On 11/11/21 8:32 AM, Alex Williamson wrote:
>>> When supporting only the .map and .unmap callbacks of iommu_ops,
>>> the IOMMU driver can make assumptions about the size and alignment
>>> used for mappings based on the driver provided pgsize_bitmap. VT-d
>>> previously used essentially PAGE_MASK for this bitmap as any power
>>> of two mapping was acceptably filled by native page sizes.
>>>
>>> However, with the .map_pages and .unmap_pages interface we're now
>>> getting page-size and count arguments. If we simply combine these
>>> as (page-size * count) and make use of the previous map/unmap
>>> functions internally, any size and alignment assumptions are very
>>> different.
>>>
>>> As an example, a given vfio device assignment VM will often create
>>> a 4MB mapping at IOVA pfn [0x3fe00 - 0x401ff]. On a system that
>>> does not support IOMMU super pages, the unmap_pages interface will
>>> ask to unmap 1024 4KB pages at the base IOVA.
>>> dma_pte_clear_level()
>>> will recurse down to level 2 of the page table where the first half
>>> of the pfn range exactly matches the entire pte level. We clear
>>> the
>>> pte, increment the pfn by the level size, but (oops) the next pte
>>> is
>>> on a new page, so we exit the loop an pop back up a level. When we
>>> then update the pfn based on that higher level, we seem to assume
>>> that the previous pfn value was at the start of the level. In this
>>> case the level size is 256K pfns, which we add to the base pfn and
>>> get a results of 0x7fe00, which is clearly greater than 0x401ff,
>>> so we're done. Meanwhile we never cleared the ptes for the
>>> remainder
>>> of the range. When the VM remaps this range, we're overwriting
>>> valid
>>> ptes and the VT-d driver complains loudly, as reported by the user
>>> report linked below.
>>>
>>> The fix for this seems relatively simple, if each iteration of the
>>> loop in dma_pte_clear_level() is assumed to clear to the end of the
>>> level pte page, then our next pfn should be calculated from
>>> level_pfn
>>> rather than our working pfn.
>>>
>>> Fixes: 3f34f1259776 ("iommu/vt-d: Implement map/unmap_pages()
>>> iommu_ops callback")
>>> Reported-by: Ajay Garg <ajaygargnsit@gmail.com>
>>> Link:
>>> https://lore.kernel.org/all/20211002124012.18186-1-ajaygargnsit@gmail.com/
>>> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
>>
>> Thank you for fixing this! I will queue it for v5.16.
>>
>> Best regards,
>> baolu
>>
>
> Hi Baolu,
>
> Do you have an estimate of when this will be submitted?
I will submit all fix patches in my queue to Joerg early the next week.
Best regards,
baolu
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
prev parent reply other threads:[~2021-11-19 0:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-11 0:32 [PATCH] iommu/vt-d: Fix unmap_pages support Alex Williamson
2021-11-11 8:49 ` Ajay Garg
2021-11-11 9:52 ` Giovanni Cabiddu
2021-11-12 2:59 ` Lu Baolu
2021-11-18 19:48 ` Jerry Snitselaar
2021-11-19 0:52 ` Lu Baolu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=824525d8-a367-a7ec-9706-4ec99be7161f@linux.intel.com \
--to=baolu.lu@linux.intel.com \
--cc=alex.williamson@redhat.com \
--cc=dwmw2@infradead.org \
--cc=iommu@lists.linux-foundation.org \
--cc=jsnitsel@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox