All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] iommu/vt-d: Fixes for v5.16-rc3
@ 2021-11-26 13:55 Lu Baolu
  2021-11-26 13:55 ` [PATCH v2 1/2] iommu/vt-d: Fix an unbalanced rcu_read_lock/rcu_read_unlock() Lu Baolu
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Lu Baolu @ 2021-11-26 13:55 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: iommu, Alex Williamson, Christophe JAILLET

Hi Joerg,

Update this series with a fix for an issue reported by Intel 0-day
robot. Sorry for the inconvenience.

Best regards,
baolu

change log:
v1:
https://lore.kernel.org/all/20211122032458.2549761-1-baolu.lu@linux.intel.com/

v2: For the patch titled "iommu/vt-d: Fix unmap_pages support",
    fixed below issue reported by Intel 0-day robot.

"
drivers/iommu/intel/iommu.c:1344:7: warning: variable 'level_pfn' is
used uninitialized whenever 'if' condition is true
[-Wsometimes-uninitialized]
"

Alex Williamson (1):
  iommu/vt-d: Fix unmap_pages support

Christophe JAILLET (1):
  iommu/vt-d: Fix an unbalanced rcu_read_lock/rcu_read_unlock()

 drivers/iommu/intel/cap_audit.c | 5 +++--
 drivers/iommu/intel/iommu.c     | 6 ++----
 2 files changed, 5 insertions(+), 6 deletions(-)

-- 
2.25.1

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/2] iommu/vt-d: Fix an unbalanced rcu_read_lock/rcu_read_unlock()
  2021-11-26 13:55 [PATCH v2 0/2] iommu/vt-d: Fixes for v5.16-rc3 Lu Baolu
@ 2021-11-26 13:55 ` Lu Baolu
  2021-11-26 13:55 ` [PATCH v2 2/2] iommu/vt-d: Fix unmap_pages support Lu Baolu
  2021-11-26 21:57 ` [PATCH v2 0/2] iommu/vt-d: Fixes for v5.16-rc3 Joerg Roedel
  2 siblings, 0 replies; 5+ messages in thread
From: Lu Baolu @ 2021-11-26 13:55 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: iommu, Alex Williamson, Christophe JAILLET

From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

If we return -EOPNOTSUPP, the rcu lock remains lock. This is spurious.
Go through the end of the function instead. This way, the missing
'rcu_read_unlock()' is called.

Fixes: 7afd7f6aa21a ("iommu/vt-d: Check FL and SL capability sanity in scalable mode")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Link: https://lore.kernel.org/r/40cc077ca5f543614eab2a10e84d29dd190273f6.1636217517.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
 drivers/iommu/intel/cap_audit.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/intel/cap_audit.c b/drivers/iommu/intel/cap_audit.c
index b39d223926a4..71596fc62822 100644
--- a/drivers/iommu/intel/cap_audit.c
+++ b/drivers/iommu/intel/cap_audit.c
@@ -144,6 +144,7 @@ static int cap_audit_static(struct intel_iommu *iommu, enum cap_audit_type type)
 {
 	struct dmar_drhd_unit *d;
 	struct intel_iommu *i;
+	int rc = 0;
 
 	rcu_read_lock();
 	if (list_empty(&dmar_drhd_units))
@@ -169,11 +170,11 @@ static int cap_audit_static(struct intel_iommu *iommu, enum cap_audit_type type)
 	 */
 	if (intel_cap_smts_sanity() &&
 	    !intel_cap_flts_sanity() && !intel_cap_slts_sanity())
-		return -EOPNOTSUPP;
+		rc = -EOPNOTSUPP;
 
 out:
 	rcu_read_unlock();
-	return 0;
+	return rc;
 }
 
 int intel_cap_audit(enum cap_audit_type type, struct intel_iommu *iommu)
-- 
2.25.1

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/2] iommu/vt-d: Fix unmap_pages support
  2021-11-26 13:55 [PATCH v2 0/2] iommu/vt-d: Fixes for v5.16-rc3 Lu Baolu
  2021-11-26 13:55 ` [PATCH v2 1/2] iommu/vt-d: Fix an unbalanced rcu_read_lock/rcu_read_unlock() Lu Baolu
@ 2021-11-26 13:55 ` Lu Baolu
  2021-11-26 21:57 ` [PATCH v2 0/2] iommu/vt-d: Fixes for v5.16-rc3 Joerg Roedel
  2 siblings, 0 replies; 5+ messages in thread
From: Lu Baolu @ 2021-11-26 13:55 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: iommu, Alex Williamson, Christophe JAILLET

From: Alex Williamson <alex.williamson@redhat.com>

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>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Tested-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Link: https://lore.kernel.org/all/20211002124012.18186-1-ajaygargnsit@gmail.com/
Link: https://lore.kernel.org/r/163659074748.1617923.12716161410774184024.stgit@omen
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
 drivers/iommu/intel/iommu.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 0bde0c8b4126..b6a8f3282411 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -1339,13 +1339,11 @@ static struct page *dma_pte_clear_level(struct dmar_domain *domain, int level,
 	pte = &pte[pfn_level_offset(pfn, level)];
 
 	do {
-		unsigned long level_pfn;
+		unsigned long level_pfn = pfn & level_mask(level);
 
 		if (!dma_pte_present(pte))
 			goto next;
 
-		level_pfn = pfn & level_mask(level);
-
 		/* If range covers entire pagetable, free it */
 		if (start_pfn <= level_pfn &&
 		    last_pfn >= level_pfn + level_size(level) - 1) {
@@ -1366,7 +1364,7 @@ static struct page *dma_pte_clear_level(struct dmar_domain *domain, int level,
 						       freelist);
 		}
 next:
-		pfn += level_size(level);
+		pfn = level_pfn + level_size(level);
 	} while (!first_pte_in_page(++pte) && pfn <= last_pfn);
 
 	if (first_pte)
-- 
2.25.1

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 0/2] iommu/vt-d: Fixes for v5.16-rc3
  2021-11-26 13:55 [PATCH v2 0/2] iommu/vt-d: Fixes for v5.16-rc3 Lu Baolu
  2021-11-26 13:55 ` [PATCH v2 1/2] iommu/vt-d: Fix an unbalanced rcu_read_lock/rcu_read_unlock() Lu Baolu
  2021-11-26 13:55 ` [PATCH v2 2/2] iommu/vt-d: Fix unmap_pages support Lu Baolu
@ 2021-11-26 21:57 ` Joerg Roedel
  2021-11-27  2:10   ` Lu Baolu
  2 siblings, 1 reply; 5+ messages in thread
From: Joerg Roedel @ 2021-11-26 21:57 UTC (permalink / raw)
  To: Lu Baolu; +Cc: Alex Williamson, Christophe JAILLET, iommu

On Fri, Nov 26, 2021 at 09:55:54PM +0800, Lu Baolu wrote:
> Update this series with a fix for an issue reported by Intel 0-day
> robot. Sorry for the inconvenience.

Replaced those with the previous fixes, thanks. Please just send a fix
on-top next time. This was already in the published fixes branch, which
I had to rebase now.

Thanks,

	Joerg

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 0/2] iommu/vt-d: Fixes for v5.16-rc3
  2021-11-26 21:57 ` [PATCH v2 0/2] iommu/vt-d: Fixes for v5.16-rc3 Joerg Roedel
@ 2021-11-27  2:10   ` Lu Baolu
  0 siblings, 0 replies; 5+ messages in thread
From: Lu Baolu @ 2021-11-27  2:10 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: iommu, Alex Williamson, Christophe JAILLET

On 11/27/21 5:57 AM, Joerg Roedel wrote:
> On Fri, Nov 26, 2021 at 09:55:54PM +0800, Lu Baolu wrote:
>> Update this series with a fix for an issue reported by Intel 0-day
>> robot. Sorry for the inconvenience.
> 
> Replaced those with the previous fixes, thanks. Please just send a fix
> on-top next time. This was already in the published fixes branch, which
> I had to rebase now.

Sure.

Best regards,
baolu

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-11-27  2:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-26 13:55 [PATCH v2 0/2] iommu/vt-d: Fixes for v5.16-rc3 Lu Baolu
2021-11-26 13:55 ` [PATCH v2 1/2] iommu/vt-d: Fix an unbalanced rcu_read_lock/rcu_read_unlock() Lu Baolu
2021-11-26 13:55 ` [PATCH v2 2/2] iommu/vt-d: Fix unmap_pages support Lu Baolu
2021-11-26 21:57 ` [PATCH v2 0/2] iommu/vt-d: Fixes for v5.16-rc3 Joerg Roedel
2021-11-27  2:10   ` Lu Baolu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.