Skip to contentSkip to conversation

x86: tboot adjustments

PATCH In review Jan Beulich 3 participants 12 messages Feb 18, 2015 – Mar 6, 2015 1 message not in the archive

lore
Share & tools
lore
#1 lore raw

PATCH 1/2 x86/tboot: invalidate FIX_TBOOT_MAP_ADDRESS mapping after use

In order for commit cbeeaa7d ("x86/nmi: fix shootdown of pcpus running in VMX non-root mode")'s re-use of that fixmap entry to not cause undesirable (in crash context) cross-CPU TLB flushes, invalidate the fixmap entry right after use.

xen/arch/x86/tboot.c +3 -0
@@ -138,6 +138,7 @@ void __init tboot_probe(void)
                       TXT_PUB_CONFIG_REGS_BASE + TXTCR_SINIT_BASE);
     tboot_copy_memory((unsigned char *)&sinit_size, sizeof(sinit_size),
                       TXT_PUB_CONFIG_REGS_BASE + TXTCR_SINIT_SIZE);
+    __set_fixmap(FIX_TBOOT_MAP_ADDRESS, 0, 0);
 }
 
 /* definitions from xen/drivers/passthrough/vtd/iommu.h
@@ -476,6 +477,8 @@ int __init tboot_parse_dmar_table(acpi_t
     dmar_table_raw = xmalloc_array(unsigned char, dmar_table_length);
     tboot_copy_memory(dmar_table_raw, dmar_table_length, pa);
     dmar_table = (struct acpi_table_header *)dmar_table_raw;
+    __set_fixmap(FIX_TBOOT_MAP_ADDRESS, 0, 0);
+
     rc = dmar_handler(dmar_table);
     xfree(dmar_table_raw);
 

x86/tboot: invalidate FIX_TBOOT_MAP_ADDRESS mapping after use

In order for commit cbeeaa7d ("x86/nmi: fix shootdown of pcpus running in VMX non-root mode")'s re-use of that fixmap entry to not cause undesirable (in crash context) cross-CPU TLB flushes, invalidate the fixmap entry right after use.

xen/arch/x86/tboot.c +3 -0
@@ -138,6 +138,7 @@ void __init tboot_probe(void)
                       TXT_PUB_CONFIG_REGS_BASE + TXTCR_SINIT_BASE);
     tboot_copy_memory((unsigned char *)&sinit_size, sizeof(sinit_size),
                       TXT_PUB_CONFIG_REGS_BASE + TXTCR_SINIT_SIZE);
+    __set_fixmap(FIX_TBOOT_MAP_ADDRESS, 0, 0);
 }
 
 /* definitions from xen/drivers/passthrough/vtd/iommu.h
@@ -476,6 +477,8 @@ int __init tboot_parse_dmar_table(acpi_t
     dmar_table_raw = xmalloc_array(unsigned char, dmar_table_length);
     tboot_copy_memory(dmar_table_raw, dmar_table_length, pa);
     dmar_table = (struct acpi_table_header *)dmar_table_raw;
+    __set_fixmap(FIX_TBOOT_MAP_ADDRESS, 0, 0);
+
     rc = dmar_handler(dmar_table);
     xfree(dmar_table_raw);
 

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] x86/tboot: invalidate FIX_TBOOT_MAP_ADDRESS mapping after use

Quoted 6 lines · Jan Beulich

In order for commit cbeeaa7d ("x86/nmi: fix shootdown of pcpus running in VMX non-root mode")'s re-use of that fixmap entry to not cause undesirable (in crash context) cross-CPU TLB flushes, invalidate the fixmap entry right after use.

Quoted 23 lines
xen/arch/x86/tboot.c +3 -0
@@ -138,6 +138,7 @@ void __init tboot_probe(void)
                       TXT_PUB_CONFIG_REGS_BASE + TXTCR_SINIT_BASE);
     tboot_copy_memory((unsigned char *)&sinit_size, sizeof(sinit_size),
                       TXT_PUB_CONFIG_REGS_BASE + TXTCR_SINIT_SIZE);
+    __set_fixmap(FIX_TBOOT_MAP_ADDRESS, 0, 0);
 }
 
 /* definitions from xen/drivers/passthrough/vtd/iommu.h
@@ -476,6 +477,8 @@ int __init tboot_parse_dmar_table(acpi_t
     dmar_table_raw = xmalloc_array(unsigned char, dmar_table_length);
     tboot_copy_memory(dmar_table_raw, dmar_table_length, pa);
     dmar_table = (struct acpi_table_header *)dmar_table_raw;
+    __set_fixmap(FIX_TBOOT_MAP_ADDRESS, 0, 0);
+
     rc = dmar_handler(dmar_table);
     xfree(dmar_table_raw);
 
#3 lore raw

Re: [PATCH 1/2] x86/tboot: invalidate FIX_TBOOT_MAP_ADDRESS mapping after use

In reply to Jan Beulich
Quoted 20 lines · Jan Beulich

In order for commit cbeeaa7d ("x86/nmi: fix shootdown of pcpus running in VMX non-root mode")'s re-use of that fixmap entry to not cause undesirable (in crash context) cross-CPU TLB flushes, invalidate the fixmap entry right after use.

xen/arch/x86/tboot.c +1 -0
@@ -138,6 +138,7 @@ void __init tboot_probe(void)
                       TXT_PUB_CONFIG_REGS_BASE + TXTCR_SINIT_BASE);
                       tboot_copy_memory((unsigned char *)&sinit_size,
                       sizeof(sinit_size), TXT_PUB_CONFIG_REGS_BASE +
                       TXTCR_SINIT_SIZE);
+    __set_fixmap(FIX_TBOOT_MAP_ADDRESS, 0, 0);
 }
 

/* definitions from xen/drivers/passthrough/vtd/iommu.h

xen/arch/x86/tboot.c int __init tboot_parse_dmar_table(acpi_t · line 484

Quoted 8 lines
xen/arch/x86/tboot.c +2 -0
@@ -476,6 +477,8 @@ int __init tboot_parse_dmar_table(acpi_t
     dmar_table_raw = xmalloc_array(unsigned char, dmar_table_length);
     tboot_copy_memory(dmar_table_raw, dmar_table_length, pa);
     dmar_table = (struct acpi_table_header *)dmar_table_raw;
+    __set_fixmap(FIX_TBOOT_MAP_ADDRESS, 0, 0);
+
     rc = dmar_handler(dmar_table);
     xfree(dmar_table_raw);
 

It might be better to move the fixmap invalidations into tboot_copy_memory like below.

xen/arch/x86/tboot.c Thu Mar 05 12:40:25 2015 +0800 renamed from xen/arch/x86/tboot.c Wed Mar 04 10:03:48 2015 +0100 +2 -0
diff -r 37706d651593 xen/arch/x86/tboot.c
@@ -88,6 +88,8 @@ static void __init tboot_copy_memory(uns
         }
         va[i] = map_addr[pa + i - (map_base << PAGE_SHIFT)];
     }
+
+    __set_fixmap(FIX_TBOOT_MAP_ADDRESS, 0, 0);
 }
 
 void __init tboot_probe(void)

Thanks
Jimmy

#4 lore raw

Re: [PATCH 1/2] x86/tboot: invalidate FIX_TBOOT_MAP_ADDRESS mapping after use

Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 05.03.15 at 05:45, <[email protected]> wrote:
Quoted 17 lines · Jan Beulich

In order for commit cbeeaa7d ("x86/nmi: fix shootdown of pcpus running in VMX non-root mode")'s re-use of that fixmap entry to not cause undesirable (in crash context) cross-CPU TLB flushes, invalidate the fixmap entry right after use.

xen/arch/x86/tboot.c +1 -0
@@ -138,6 +138,7 @@ void __init tboot_probe(void)
                       TXT_PUB_CONFIG_REGS_BASE + TXTCR_SINIT_BASE);
                       tboot_copy_memory((unsigned char *)&sinit_size,
                       sizeof(sinit_size), TXT_PUB_CONFIG_REGS_BASE +
                       TXTCR_SINIT_SIZE);
+    __set_fixmap(FIX_TBOOT_MAP_ADDRESS, 0, 0);
 }
 
Quoted 14 lines

xen/arch/x86/tboot.c int __init tboot_parse_dmar_table(acpi_t · line 484

Quoted 11 lines

/* definitions from xen/drivers/passthrough/vtd/iommu.h

xen/arch/x86/tboot.c +2 -0
@@ -476,6 +477,8 @@ int __init tboot_parse_dmar_table(acpi_t
     dmar_table_raw = xmalloc_array(unsigned char, dmar_table_length);
     tboot_copy_memory(dmar_table_raw, dmar_table_length, pa);
     dmar_table = (struct acpi_table_header *)dmar_table_raw;
+    __set_fixmap(FIX_TBOOT_MAP_ADDRESS, 0, 0);
+
     rc = dmar_handler(dmar_table);
     xfree(dmar_table_raw);
 

It might be better to move the fixmap invalidations into tboot_copy_memory like below.

I considered this, but dropped the idea due to resulting in several redundant invalidations.

Jan

#5 lore raw

Re: [PATCH 1/2] x86/tboot: invalidate FIX_TBOOT_MAP_ADDRESS mapping after use

Quoted 33 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 05.03.15 at 05:45, <[email protected]> wrote:
Quoted 17 lines · Jan Beulich

In order for commit cbeeaa7d ("x86/nmi: fix shootdown of pcpus running in VMX non-root mode")'s re-use of that fixmap entry to not cause undesirable (in crash context) cross-CPU TLB flushes, invalidate the fixmap entry right after use.

xen/arch/x86/tboot.c +1 -0
@@ -138,6 +138,7 @@ void __init tboot_probe(void)
                       TXT_PUB_CONFIG_REGS_BASE + TXTCR_SINIT_BASE);
                       tboot_copy_memory((unsigned char *)&sinit_size,
                       sizeof(sinit_size), TXT_PUB_CONFIG_REGS_BASE +
                       TXTCR_SINIT_SIZE);
+    __set_fixmap(FIX_TBOOT_MAP_ADDRESS, 0, 0);
 }
 
Quoted 13 lines

xen/arch/x86/tboot.c int __init tboot_parse_dmar_table(acpi_t · line 484

Quoted 10 lines

/* definitions from xen/drivers/passthrough/vtd/iommu.h

xen/arch/x86/tboot.c +2 -0
@@ -476,6 +477,8 @@ int __init tboot_parse_dmar_table(acpi_t
     dmar_table_raw = xmalloc_array(unsigned char, dmar_table_length);
     tboot_copy_memory(dmar_table_raw, dmar_table_length, pa);
     dmar_table = (struct acpi_table_header *)dmar_table_raw;
+    __set_fixmap(FIX_TBOOT_MAP_ADDRESS, 0, 0);
+
     rc = dmar_handler(dmar_table);
     xfree(dmar_table_raw);
 

It might be better to move the fixmap invalidations into tboot_copy_memory like below.

Quoted 4 lines

I considered this, but dropped the idea due to resulting in several redundant invalidations.

From performance perspective, I am ok with your final changes.

Jimmy

#6 lore raw

PATCH 2/2 x86/tboot: simplify DMAR table copying

In reply to Jan Beulich

There's no need for more than one variable, no need for casts, and no point in using the type-safe xmalloc_array() here.

xen/arch/x86/tboot.c +4 -6
@@ -435,13 +435,12 @@ int __init tboot_protect_mem_regions(voi
 
 int __init tboot_parse_dmar_table(acpi_table_handler dmar_handler)
 {
-    struct acpi_table_header *dmar_table;
     int rc;
     uint64_t size;
     uint32_t dmar_table_length;
     unsigned long pa;
     sinit_mle_data_t sinit_mle_data;
-    unsigned char *dmar_table_raw;
+    void *dmar_table;
 
     if ( !tboot_in_measured_env() )
         return acpi_table_parse(ACPI_SIG_DMAR, dmar_handler);
@@ -474,13 +473,12 @@ int __init tboot_parse_dmar_table(acpi_t
     tboot_copy_memory((unsigned char *)&dmar_table_length,
                       sizeof(dmar_table_length),
                       pa + sizeof(char) * ACPI_NAME_SIZE);
-    dmar_table_raw = xmalloc_array(unsigned char, dmar_table_length);
-    tboot_copy_memory(dmar_table_raw, dmar_table_length, pa);
-    dmar_table = (struct acpi_table_header *)dmar_table_raw;
+    dmar_table = xmalloc_bytes(dmar_table_length);
+    tboot_copy_memory(dmar_table, dmar_table_length, pa);
     __set_fixmap(FIX_TBOOT_MAP_ADDRESS, 0, 0);
 
     rc = dmar_handler(dmar_table);
-    xfree(dmar_table_raw);
+    xfree(dmar_table);
 
     /* acpi_parse_dmar() zaps APCI DMAR signature in TXT heap table */
     /* but dom0 will read real table, so must zap it there too */

x86/tboot: simplify DMAR table copying

There's no need for more than one variable, no need for casts, and no point in using the type-safe xmalloc_array() here.

xen/arch/x86/tboot.c +4 -6
@@ -435,13 +435,12 @@ int __init tboot_protect_mem_regions(voi
 
 int __init tboot_parse_dmar_table(acpi_table_handler dmar_handler)
 {
-    struct acpi_table_header *dmar_table;
     int rc;
     uint64_t size;
     uint32_t dmar_table_length;
     unsigned long pa;
     sinit_mle_data_t sinit_mle_data;
-    unsigned char *dmar_table_raw;
+    void *dmar_table;
 
     if ( !tboot_in_measured_env() )
         return acpi_table_parse(ACPI_SIG_DMAR, dmar_handler);
@@ -474,13 +473,12 @@ int __init tboot_parse_dmar_table(acpi_t
     tboot_copy_memory((unsigned char *)&dmar_table_length,
                       sizeof(dmar_table_length),
                       pa + sizeof(char) * ACPI_NAME_SIZE);
-    dmar_table_raw = xmalloc_array(unsigned char, dmar_table_length);
-    tboot_copy_memory(dmar_table_raw, dmar_table_length, pa);
-    dmar_table = (struct acpi_table_header *)dmar_table_raw;
+    dmar_table = xmalloc_bytes(dmar_table_length);
+    tboot_copy_memory(dmar_table, dmar_table_length, pa);
     __set_fixmap(FIX_TBOOT_MAP_ADDRESS, 0, 0);
 
     rc = dmar_handler(dmar_table);
-    xfree(dmar_table_raw);
+    xfree(dmar_table);
 
     /* acpi_parse_dmar() zaps APCI DMAR signature in TXT heap table */
     /* but dom0 will read real table, so must zap it there too */

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Reviewed-by on v1 2/2
#7 lore raw

Re: [PATCH 2/2] x86/tboot: simplify DMAR table copying

Quoted 4 lines · Jan Beulich

There's no need for more than one variable, no need for casts, and no point in using the type-safe xmalloc_array() here.

Quoted 38 lines
xen/arch/x86/tboot.c +4 -6
@@ -435,13 +435,12 @@ int __init tboot_protect_mem_regions(voi
 
 int __init tboot_parse_dmar_table(acpi_table_handler dmar_handler)
 {
-    struct acpi_table_header *dmar_table;
     int rc;
     uint64_t size;
     uint32_t dmar_table_length;
     unsigned long pa;
     sinit_mle_data_t sinit_mle_data;
-    unsigned char *dmar_table_raw;
+    void *dmar_table;
 
     if ( !tboot_in_measured_env() )
         return acpi_table_parse(ACPI_SIG_DMAR, dmar_handler);
@@ -474,13 +473,12 @@ int __init tboot_parse_dmar_table(acpi_t
     tboot_copy_memory((unsigned char *)&dmar_table_length,
                       sizeof(dmar_table_length),
                       pa + sizeof(char) * ACPI_NAME_SIZE);
-    dmar_table_raw = xmalloc_array(unsigned char, dmar_table_length);
-    tboot_copy_memory(dmar_table_raw, dmar_table_length, pa);
-    dmar_table = (struct acpi_table_header *)dmar_table_raw;
+    dmar_table = xmalloc_bytes(dmar_table_length);
+    tboot_copy_memory(dmar_table, dmar_table_length, pa);
     __set_fixmap(FIX_TBOOT_MAP_ADDRESS, 0, 0);
 
     rc = dmar_handler(dmar_table);
-    xfree(dmar_table_raw);
+    xfree(dmar_table);
 
     /* acpi_parse_dmar() zaps APCI DMAR signature in TXT heap table */
     /* but dom0 will read real table, so must zap it there too */
#8 lore raw

Re: [PATCH 2/2] x86/tboot: simplify DMAR table copying

In reply to Jan Beulich
Quoted 29 lines · Jan Beulich

There's no need for more than one variable, no need for casts, and no point in using the type-safe xmalloc_array() here.

xen/arch/x86/tboot.c +1 -2
@@ -435,13 +435,12 @@ int __init tboot_protect_mem_regions(voi
 
 int __init tboot_parse_dmar_table(acpi_table_handler dmar_handler)  {
-    struct acpi_table_header *dmar_table;
     int rc;
     uint64_t size;
     uint32_t dmar_table_length;
     unsigned long pa;
     sinit_mle_data_t sinit_mle_data;
-    unsigned char *dmar_table_raw;
+    void *dmar_table;
 
     if ( !tboot_in_measured_env() )
         return acpi_table_parse(ACPI_SIG_DMAR, dmar_handler); @@ -

474,13 +473,12 @@ int __init tboot_parse_dmar_table(acpi_t
tboot_copy_memory((unsigned char *)&dmar_table_length,
sizeof(dmar_table_length), pa + sizeof(char) * ACPI_NAME_SIZE);

xen/arch/x86/tboot.c +0 -3
-    dmar_table_raw = xmalloc_array(unsigned char, dmar_table_length);
-    tboot_copy_memory(dmar_table_raw, dmar_table_length, pa);
-    dmar_table = (struct acpi_table_header *)dmar_table_raw;

xen/arch/x86/tboot.c int __init tboot_parse_dmar_table(acpi_t · line 484

Quoted 10 lines
xen/arch/x86/tboot.c +3 -1
+    dmar_table = xmalloc_bytes(dmar_table_length);
+    tboot_copy_memory(dmar_table, dmar_table_length, pa);
     __set_fixmap(FIX_TBOOT_MAP_ADDRESS, 0, 0);
 
     rc = dmar_handler(dmar_table);
-    xfree(dmar_table_raw);
+    xfree(dmar_table);
 
     /* acpi_parse_dmar() zaps APCI DMAR signature in TXT heap table */
     /* but dom0 will read real table, so must zap it there too */

Ack.

Jimmy

#9 lore raw

Ping: [PATCH 0/2] x86: tboot adjustments

In reply to Jan Beulich

I'm intending to commit the first of these right now (i.e. without an ack), as we need the bug fixed (and want the fix backported for the pending stable tree releases). I'll holding off on the 2nd one (as being cleanup) for another week or so, in the hope that at least one of you will respond one way or another.

Jan

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 18.02.15 at 09:56, <[email protected]> wrote:

1: invalidate FIX_TBOOT_MAP_ADDRESS mapping after use 2: simplify DMAR table copying

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

A message that is not in the archive (sent off-list or not yet received): 9F57BF860713DF4BA3EFA4F8C6DFEDAC9AD71F89@ORSMSX110.amr.corp.intel.com

#11 lore raw

Re: Ping: [PATCH 0/2] x86: tboot adjustments

(re-adding xen-devel to Cc)

Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 04.03.15 at 08:59, <[email protected]> wrote:

FYI, I no longer work on tboot (haven't for 4+ years). Jimmy is still Mr. tboot, however ;-)

Thanks for letting us know. I'll send a patch to update ./MAINTAINERS then.

Jan