Skip to contentSkip to conversation

x86, tboot: iomem fixes

PATCH Superseded Qiaowei Ren 2 participants 4 messages Jul 18, 2013 – Jul 19, 2013

Subsystems (2)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 x86, tboot: iomem fixes

Current code doesn't use specific interface to access I/O space. So some potential bugs can be caused. We can fix this by using specific API.

---
 arch/x86/kernel/tboot.c |   21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)
arch/x86/kernel/tboot.c +12 -9
index 3ff42d2..afe8cf8 100644
@@ -466,9 +466,12 @@ struct sinit_mle_data {
 	u32               vtd_dmars_off;
 } __packed;
 
+#define SINIT_MLE_DATA_VTD_DMAR_OFF	140
+
 struct acpi_table_header *tboot_get_dmar_table(struct acpi_table_header *dmar_tbl)
 {
-	void *heap_base, *heap_ptr, *config;
+	void __iomem *heap_base, *heap_ptr, *config;
+	u32 dmar_tbl_off;
 
 	if (!tboot_enabled())
 		return dmar_tbl;
@@ -485,25 +488,25 @@ struct acpi_table_header *tboot_get_dmar_table(struct acpi_table_header *dmar_tb
 		return NULL;
 
 	/* now map TXT heap */
-	heap_base = ioremap(*(u64 *)(config + TXTCR_HEAP_BASE),
-			    *(u64 *)(config + TXTCR_HEAP_SIZE));
+	heap_base = ioremap(readl(config + TXTCR_HEAP_BASE),
+			    readl(config + TXTCR_HEAP_SIZE));
 	iounmap(config);
 	if (!heap_base)
 		return NULL;
 
 	/* walk heap to SinitMleData */
 	/* skip BiosData */
-	heap_ptr = heap_base + *(u64 *)heap_base;
+	heap_ptr = heap_base + readq(heap_base);
 	/* skip OsMleData */
-	heap_ptr += *(u64 *)heap_ptr;
+	heap_ptr += readq(heap_ptr);
 	/* skip OsSinitData */
-	heap_ptr += *(u64 *)heap_ptr;
+	heap_ptr += readq(heap_ptr);
 	/* now points to SinitMleDataSize; set to SinitMleData */
 	heap_ptr += sizeof(u64);
 	/* get addr of DMAR table */
-	dmar_tbl = (struct acpi_table_header *)(heap_ptr +
-		   ((struct sinit_mle_data *)heap_ptr)->vtd_dmars_off -
-		   sizeof(u64));
+	dmar_tbl_off = readl(heap_ptr + SINIT_MLE_DATA_VTD_DMAR_OFF);
+	memcpy_fromio(dmar_tbl, heap_ptr + dmar_tbl_off - sizeof(u64),
+			sizeof(struct acpi_table_header));
 
 	/* don't unmap heap because dmar.c needs access to this */
 
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 3 lines · Qiaowei Ren

Current code doesn't use specific interface to access I/O space. So some potential bugs can be caused. We can fix this by using specific API.

This is still very vague.

Quoted 45 lines
---
 arch/x86/kernel/tboot.c |   21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)
arch/x86/kernel/tboot.c +8 -6
index 3ff42d2..afe8cf8 100644
@@ -466,9 +466,12 @@ struct sinit_mle_data {
 	u32               vtd_dmars_off;
 } __packed;
 
+#define SINIT_MLE_DATA_VTD_DMAR_OFF	140
+
 struct acpi_table_header *tboot_get_dmar_table(struct acpi_table_header *dmar_tbl)
 {
-	void *heap_base, *heap_ptr, *config;
+	void __iomem *heap_base, *heap_ptr, *config;
+	u32 dmar_tbl_off;
 
 	if (!tboot_enabled())
 		return dmar_tbl;
@@ -485,25 +488,25 @@ struct acpi_table_header *tboot_get_dmar_table(struct acpi_table_header *dmar_tb
 		return NULL;
 
 	/* now map TXT heap */
-	heap_base = ioremap(*(u64 *)(config + TXTCR_HEAP_BASE),
-			    *(u64 *)(config + TXTCR_HEAP_SIZE));
+	heap_base = ioremap(readl(config + TXTCR_HEAP_BASE),
+			    readl(config + TXTCR_HEAP_SIZE));
 	iounmap(config);
 	if (!heap_base)
 		return NULL;
 
 	/* walk heap to SinitMleData */
 	/* skip BiosData */
-	heap_ptr = heap_base + *(u64 *)heap_base;
+	heap_ptr = heap_base + readq(heap_base);
 	/* skip OsMleData */
-	heap_ptr += *(u64 *)heap_ptr;
+	heap_ptr += readq(heap_ptr);
 	/* skip OsSinitData */
-	heap_ptr += *(u64 *)heap_ptr;

arch/x86/kernel/tboot.c struct acpi_table_header *tboot_get_dmar_table(struct acpi_table_header *dmar_tb · line 509

Quoted 10 lines
arch/x86/kernel/tboot.c +4 -3
+	heap_ptr += readq(heap_ptr);
 	/* now points to SinitMleDataSize; set to SinitMleData */
 	heap_ptr += sizeof(u64);
 	/* get addr of DMAR table */
-	dmar_tbl = (struct acpi_table_header *)(heap_ptr +
-		   ((struct sinit_mle_data *)heap_ptr)->vtd_dmars_off -
-		   sizeof(u64));
+	dmar_tbl_off = readl(heap_ptr + SINIT_MLE_DATA_VTD_DMAR_OFF);
+	memcpy_fromio(dmar_tbl, heap_ptr + dmar_tbl_off - sizeof(u64),
+			sizeof(struct acpi_table_header));

That memcpy (or an equivalent of it) was not in the code before, AFAICS.

How can this be an 'interface fix'? It adds in new code...

Thanks,

Ingo

#2 lore raw
Quoted 66 lines · Ingo Molnar
Quoted 3 lines · Qiaowei Ren

Current code doesn't use specific interface to access I/O space. So some potential bugs can be caused. We can fix this by using specific API.

This is still very vague.

arch/x86/kernel/tboot.c struct acpi_table_header

Quoted 23 lines
---
 arch/x86/kernel/tboot.c |   21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)
arch/x86/kernel/tboot.c index renamed from arch/x86/kernel/tboot.c +0 -0

3ff42d2..afe8cf8 100644

arch/x86/kernel/tboot.c +4 -1
@@ -466,9 +466,12 @@ struct sinit_mle_data {
 	u32               vtd_dmars_off;
 } __packed;
+#define SINIT_MLE_DATA_VTD_DMAR_OFF	140
+
 struct acpi_table_header *tboot_get_dmar_table(struct
 acpi_table_header *dmar_tbl)  {
-	void *heap_base, *heap_ptr, *config;
+	void __iomem *heap_base, *heap_ptr, *config;
+	u32 dmar_tbl_off;
 
 	if (!tboot_enabled())
 		return dmar_tbl;
@@ -485,25 +488,25 @@ struct acpi_table_header

*tboot_get_dmar_table(struct acpi_table_header *dmar_tb

Quoted 20 lines
arch/x86/kernel/tboot.c +4 -5
 		return NULL;
 
 	/* now map TXT heap */
-	heap_base = ioremap(*(u64 *)(config + TXTCR_HEAP_BASE),
-			    *(u64 *)(config + TXTCR_HEAP_SIZE));
+	heap_base = ioremap(readl(config + TXTCR_HEAP_BASE),
+			    readl(config + TXTCR_HEAP_SIZE));
 	iounmap(config);
 	if (!heap_base)
 		return NULL;
 
 	/* walk heap to SinitMleData */
 	/* skip BiosData */
-	heap_ptr = heap_base + *(u64 *)heap_base;
+	heap_ptr = heap_base + readq(heap_base);
 	/* skip OsMleData */
-	heap_ptr += *(u64 *)heap_ptr;
+	heap_ptr += readq(heap_ptr);
 	/* skip OsSinitData */
-	heap_ptr += *(u64 *)heap_ptr;

arch/x86/kernel/tboot.c struct acpi_table_header *tboot_get_dmar_table(struct acpi_table_header *dmar_tb · line 509

Quoted 10 lines
arch/x86/kernel/tboot.c +4 -3
+	heap_ptr += readq(heap_ptr);
 	/* now points to SinitMleDataSize; set to SinitMleData */
 	heap_ptr += sizeof(u64);
 	/* get addr of DMAR table */
-	dmar_tbl = (struct acpi_table_header *)(heap_ptr +
-		   ((struct sinit_mle_data *)heap_ptr)->vtd_dmars_off -
-		   sizeof(u64));
+	dmar_tbl_off = readl(heap_ptr + SINIT_MLE_DATA_VTD_DMAR_OFF);
+	memcpy_fromio(dmar_tbl, heap_ptr + dmar_tbl_off - sizeof(u64),
+			sizeof(struct acpi_table_header));

That memcpy (or an equivalent of it) was not in the code before, AFAICS.

Quoted 2 lines

How can this be an 'interface fix'? It adds in new code...

Sorry, current code only need to get addr of DMAR table, so memcpy_fromio may be removed, even though this will also work. So "memcpy_fromio" line will be changed to

	dmar_tbl = (struct acpi_table_header *)(heap_ptr + dmar_tbl_off + - sizeof(u64));

If so, no new interface will be added, and the changelog at the beginning of this patch is engouch?

Thanks,
Qiaowei

#3 lore raw
Quoted 67 lines · Ren, Qiaowei
Quoted 66 lines · Ingo Molnar
Quoted 3 lines · Qiaowei Ren

Current code doesn't use specific interface to access I/O space. So some potential bugs can be caused. We can fix this by using specific API.

This is still very vague.

arch/x86/kernel/tboot.c struct acpi_table_header

Quoted 23 lines
---
 arch/x86/kernel/tboot.c |   21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)
arch/x86/kernel/tboot.c index renamed from arch/x86/kernel/tboot.c +0 -0

3ff42d2..afe8cf8 100644

arch/x86/kernel/tboot.c +4 -1
@@ -466,9 +466,12 @@ struct sinit_mle_data {
 	u32               vtd_dmars_off;
 } __packed;
+#define SINIT_MLE_DATA_VTD_DMAR_OFF	140
+
 struct acpi_table_header *tboot_get_dmar_table(struct
 acpi_table_header *dmar_tbl)  {
-	void *heap_base, *heap_ptr, *config;
+	void __iomem *heap_base, *heap_ptr, *config;
+	u32 dmar_tbl_off;
 
 	if (!tboot_enabled())
 		return dmar_tbl;
@@ -485,25 +488,25 @@ struct acpi_table_header

*tboot_get_dmar_table(struct acpi_table_header *dmar_tb

Quoted 20 lines
arch/x86/kernel/tboot.c +4 -5
 		return NULL;
 
 	/* now map TXT heap */
-	heap_base = ioremap(*(u64 *)(config + TXTCR_HEAP_BASE),
-			    *(u64 *)(config + TXTCR_HEAP_SIZE));
+	heap_base = ioremap(readl(config + TXTCR_HEAP_BASE),
+			    readl(config + TXTCR_HEAP_SIZE));
 	iounmap(config);
 	if (!heap_base)
 		return NULL;
 
 	/* walk heap to SinitMleData */
 	/* skip BiosData */
-	heap_ptr = heap_base + *(u64 *)heap_base;
+	heap_ptr = heap_base + readq(heap_base);
 	/* skip OsMleData */
-	heap_ptr += *(u64 *)heap_ptr;
+	heap_ptr += readq(heap_ptr);
 	/* skip OsSinitData */
-	heap_ptr += *(u64 *)heap_ptr;

arch/x86/kernel/tboot.c struct acpi_table_header *tboot_get_dmar_table(struct acpi_table_header *dmar_tb · line 509

Quoted 10 lines
arch/x86/kernel/tboot.c +4 -3
+	heap_ptr += readq(heap_ptr);
 	/* now points to SinitMleDataSize; set to SinitMleData */
 	heap_ptr += sizeof(u64);
 	/* get addr of DMAR table */
-	dmar_tbl = (struct acpi_table_header *)(heap_ptr +
-		   ((struct sinit_mle_data *)heap_ptr)->vtd_dmars_off -
-		   sizeof(u64));
+	dmar_tbl_off = readl(heap_ptr + SINIT_MLE_DATA_VTD_DMAR_OFF);
+	memcpy_fromio(dmar_tbl, heap_ptr + dmar_tbl_off - sizeof(u64),
+			sizeof(struct acpi_table_header));

That memcpy (or an equivalent of it) was not in the code before, AFAICS.

Quoted 6 lines
Quoted 2 lines

How can this be an 'interface fix'? It adds in new code...

Sorry, current code only need to get addr of DMAR table, so memcpy_fromio may be removed, even though this will also work. So "memcpy_fromio" line will be changed to

	dmar_tbl = (struct acpi_table_header *)(heap_ptr + dmar_tbl_off + - sizeof(u64));

If so, no new interface will be added, and the changelog at the beginning of this patch is engouch?

Please resubmit the fixed patch so I can have a fresh look.

Thanks,

Ingo