Skip to contentSkip to conversation

iommu/amd: Fix failure return from snp_lookup_rmpentry().

PATCH In review Ashish Kalra 2 participants 2 messages Feb 5, 2024 – Feb 6, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iommu/amd: Fix failure return from snp_lookup_rmpentry().

From: Ashish Kalra <[email protected]>

The patch f366a8dac1b8: "iommu/amd: Clean up RMP entries for IOMMU pages during SNP shutdown" (linux-next), leads to the following Smatch static checker warning:

	drivers/iommu/amd/init.c:3820 iommu_page_make_shared()
	error: uninitialized symbol 'assigned'.

Fix it.

Fixes f366a8dac1b8 ("iommu/amd: Clean up RMP entries for IOMMU pages during SNP shutdown")
---
 drivers/iommu/amd/init.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iommu/amd/init.c +3 -1
index 88bb08ae39b2..11340380111d 100644
@@ -3813,9 +3813,11 @@ static int iommu_page_make_shared(void *page)
 		bool assigned;
 
 		ret = snp_lookup_rmpentry(pfn, &assigned, &level);
-		if (ret)
+		if (ret) {
 			pr_warn("IOMMU PFN %lx RMP lookup failed, ret %d\n",
 				pfn, ret);
+			return ret;
+		}
 
 		if (!assigned)
 			pr_warn("IOMMU PFN %lx not assigned in RMP table\n",
Signature · 1 line
2.34.1
#1 lore raw
Quoted 4 lines · Ashish Kalra

From: Ashish Kalra <[email protected]>

The patch f366a8dac1b8: "iommu/amd: Clean up RMP entries for IOMMU pages during SNP shutdown" (linux-next), leads to the following

Add this:

[alias]

        one = show -s --pretty='format:%h (\"%s\")'

to your .git/config so that when you do

$ git one f366a8dac1b8

it can give you the proper formatting for commit references:

f366a8dac1b8 ("iommu/amd: Clean up RMP entries for IOMMU pages during SNP shutdown")

Quoted 5 lines
drivers/iommu/amd/init.c +0 -0
index 88bb08ae39b2..11340380111d 100644

drivers/iommu/amd/init.c static int iommu_page_make_shared(void *page) · line 3820

Quoted 9 lines
drivers/iommu/amd/init.c +3 -1
@@ -3813,9 +3813,11 @@ static int iommu_page_make_shared(void *page)
 		bool assigned;
 
 		ret = snp_lookup_rmpentry(pfn, &assigned, &level);
-		if (ret)
+		if (ret) {
 			pr_warn("IOMMU PFN %lx RMP lookup failed, ret %d\n",
 				pfn, ret);
+			return ret;
+		}

This one is incomplete and we should've caught this in review: any of those failure cases here should return an error and not attempt to make a pfn shared again.

Diff ontop:

---

drivers/iommu/amd/init.c +12 -9
index 11340380111d..480e7681f4f3 100644
@@ -3814,24 +3814,27 @@ static int iommu_page_make_shared(void *page)
 
 		ret = snp_lookup_rmpentry(pfn, &assigned, &level);
 		if (ret) {
-			pr_warn("IOMMU PFN %lx RMP lookup failed, ret %d\n",
-				pfn, ret);
+			pr_warn("IOMMU PFN %lx RMP lookup failed, ret %d\n", pfn, ret);
 			return ret;
 		}
 
-		if (!assigned)
-			pr_warn("IOMMU PFN %lx not assigned in RMP table\n",
-				pfn);
+		if (!assigned) {
+			pr_warn("IOMMU PFN %lx not assigned in RMP table\n", pfn);
+			return -EINVAL;
+		}
 
 		if (level > PG_LEVEL_4K) {
 			ret = psmash(pfn);
-			if (ret) {
-				pr_warn("IOMMU PFN %lx had a huge RMP entry, but attempted psmash failed, ret: %d, level: %d\n",
-					pfn, ret, level);
-			}
+			if (!ret)
+				goto done;
+
+			pr_warn("PSMASH failed for IOMMU PFN %lx huge RMP entry, ret: %d, level: %d\n",
+				pfn, ret, level);
+			return ret;
 		}
 	}
 
+done:
 	return rmp_make_shared(pfn, PG_LEVEL_4K);
 }
 
Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette