Skip to contentSkip to conversation

iommu/amd: Do not clear event/ppr log buffer when snp is enabled

PATCH Superseded Vasant Hegde 2 participants 3 messages Jan 5, 2023 – Jan 17, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Vasant Hegde

author maintainer
#0 lore raw

PATCH 1/1 iommu/amd: Do not clear event/ppr log buffer when snp is enabled

From: Tom Lendacky <[email protected]>

Current code clears event log and ppr log entry after processing it due to hardware errata ([1] erratum #732, #733). We do not have hardware issue on SNP enabled system.

When SNP is enabled, the event logs, PPR log and completion wait buffer are read-only to the host (see SNP FW ABI spec [2]). Clearing those entry will result in a kernel #PF for an RMP violation. Hence do not clear event and ppr log entry after processing it.

[1] http://developer.amd.com/wordpress/media/2012/10/48931_15h_Mod_10h-1Fh_Rev_Guide.pdf
[2] https://www.amd.com/system/files/TechDocs/56860.pdf

---
 drivers/iommu/amd/iommu.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/iommu/amd/iommu.c +11 -4
index cbeaab55c0db..acc5e5e4f9e2 100644
@@ -667,7 +667,13 @@ static void iommu_print_event(struct amd_iommu *iommu, void *__evt)
 			event[0], event[1], event[2], event[3]);
 	}
 
-	memset(__evt, 0, 4 * sizeof(u32));
+	if (!amd_iommu_snp_en) {
+		/*
+		 * To detect the hardware errata 732 we need to clear the
+		 * entry back to zero.
+		 */
+		memset(__evt, 0, 4 * sizeof(u32));
+	}
 }
 
 static void iommu_poll_events(struct amd_iommu *iommu)
@@ -736,10 +742,11 @@ static void iommu_poll_ppr_log(struct amd_iommu *iommu)
 		entry[1] = raw[1];
 
 		/*
-		 * To detect the hardware bug we need to clear the entry
-		 * back to zero.
+		 * To detect the hardware errata 733 we need to clear the
+		 * entry back to zero.
 		 */
-		raw[0] = raw[1] = 0UL;
+		if (!amd_iommu_snp_en)
+			raw[0] = raw[1] = 0UL;
 
 		/* Update head pointer of hardware ring-buffer */
 		head = (head + PPR_ENTRY_SIZE) % PPR_LOG_SIZE;
Signature · 1 line
2.31.1
maintainer
#1 lore raw

drivers/iommu/amd/iommu.c static void iommu_print_event(struct amd_iommu *iommu, void *__evt) · line 676

Quoted 8 lines · Vasant Hegde
drivers/iommu/amd/iommu.c +7 -1
-	memset(__evt, 0, 4 * sizeof(u32));
+	if (!amd_iommu_snp_en) {
+		/*
+		 * To detect the hardware errata 732 we need to clear the
+		 * entry back to zero.
+		 */
+		memset(__evt, 0, 4 * sizeof(u32));
+	}

This needs a comment that the buffers are not writeable with SNP enabled.

Quoted 5 lines

}

static void iommu_poll_events(struct amd_iommu *iommu)

drivers/iommu/amd/iommu.c +0 -0
@@ -736,10 +742,11 @@ static void iommu_poll_ppr_log(struct amd_iommu *iommu)
 		entry[1] = raw[1];

drivers/iommu/amd/iommu.c static void iommu_poll_ppr_log(struct amd_iommu *iommu) · line 749

Quoted 10 lines
drivers/iommu/amd/iommu.c +4 -3
 
 		/*
-		 * To detect the hardware bug we need to clear the entry
-		 * back to zero.
+		 * To detect the hardware errata 733 we need to clear the
+		 * entry back to zero.
 		 */
-		raw[0] = raw[1] = 0UL;
+		if (!amd_iommu_snp_en)
+			raw[0] = raw[1] = 0UL;

Same here.

Quoted 6 lines
drivers/iommu/amd/iommu.c +0 -0
 		/* Update head pointer of hardware ring-buffer */
 		head = (head + PPR_ENTRY_SIZE) % PPR_LOG_SIZE;
Signature · 1 line
2.31.1
author maintainer
#2 lore raw

Joerg,

Quoted 12 lines · Joerg Roedel

drivers/iommu/amd/iommu.c static void iommu_print_event(struct amd_iommu *iommu, void *__evt) · line 676

Quoted 8 lines · Vasant Hegde
drivers/iommu/amd/iommu.c +7 -1
-	memset(__evt, 0, 4 * sizeof(u32));
+	if (!amd_iommu_snp_en) {
+		/*
+		 * To detect the hardware errata 732 we need to clear the
+		 * entry back to zero.
+		 */
+		memset(__evt, 0, 4 * sizeof(u32));
+	}

This needs a comment that the buffers are not writeable with SNP enabled.

Sure. I will expand above comment and will post v2.

Quoted 7 lines
Quoted 7 lines

}

static void iommu_poll_events(struct amd_iommu *iommu)

drivers/iommu/amd/iommu.c +0 -0
@@ -736,10 +742,11 @@ static void iommu_poll_ppr_log(struct amd_iommu *iommu)
 		entry[1] = raw[1];
 
Quoted 11 lines

drivers/iommu/amd/iommu.c static void iommu_poll_ppr_log(struct amd_iommu *iommu) · line 749

Quoted 9 lines
drivers/iommu/amd/iommu.c +4 -3
 		/*
-		 * To detect the hardware bug we need to clear the entry
-		 * back to zero.
+		 * To detect the hardware errata 733 we need to clear the
+		 * entry back to zero.
 		 */
-		raw[0] = raw[1] = 0UL;
+		if (!amd_iommu_snp_en)
+			raw[0] = raw[1] = 0UL;

Same here.

Sure.

-Vasant