p2m/ept: Work around hardware errata setting A bit
PATCH v2 1/1 p2m/ept: Work around hardware errata setting A bit
Since commit 191b3f3344ee ("p2m/ept: enable PML in p2m-ept for log-dirty"), the A and D bits of EPT paging entries are set unconditionally, regardless of whether PML is enabled or not. This causes a regression in Xen 4.6 on some processors due to Intel Errata AVR41 -- HVM guests get severe memory corruption when the A bit is set due to incorrect TLB flushing on mov to cr3. The errata affects the Atom C2000 family (Avaton).
To fix, do not set the A bit on this processor family.
--- xen/arch/x86/mm/p2m-ept.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
xen/arch/x86/mm/p2m-ept.c +13 -8
@@ -34,6 +34,8 @@#include "mm-locks.h" +static bool_t __read_mostly cpu_has_ept_ad; +#define atomic_read_ept_entry (__pepte) \ ( (ept_entry_t) { .epte = read_atomic(&(__pepte)->epte) } )
@@ -130,14 +132,14 @@ static void ept_p2m_type_to_flags(struct p2m_domain *p2m, ept_entry_t *entry,break ;case p2m_ram_rw: entry->r = entry->w = entry->x =1 ; - entry->a = entry->d =1 ; + entry->a = entry->d = cpu_has_ept_ad;break ;case p2m_mmio_direct: entry->r = entry->x =1 ; entry->w = !rangeset_contains_singleton (mmio_ro_ranges, entry->mfn); - entry->a =1 ; - entry->d = entry->w; + entry->a = cpu_has_ept_ad; + entry->d = entry->w && cpu_has_ept_ad;break ;case p2m_ram_logdirty: entry->r = entry->x =1 ;
@@ -152,7 +154,7 @@ static void ept_p2m_type_to_flags(struct p2m_domain *p2m, ept_entry_t *entry, entry->w =1 ; else entry->w = 0; - entry->a =1 ; + entry->a = cpu_has_ept_ad;/* For both PML or non-PML cases we clear D bit anyway */ entry->d =0 ;break ;
@@ -160,20 +162,20 @@ static void ept_p2m_type_to_flags(struct p2m_domain *p2m, ept_entry_t *entry,case p2m_ram_shared: entry->r = entry->x =1 ; entry->w =0 ; - entry->a =1 ; + entry->a = cpu_has_ept_ad; entry->d =0 ;break ;case p2m_grant_map_rw:case p2m_map_foreign: entry->r = entry->w =1 ; entry->x =0 ; - entry->a = entry->d =1 ; + entry->a = entry->d = cpu_has_ept_ad;break ;case p2m_grant_map_ro:case p2m_mmio_write_dm: entry->r =1 ; entry->w = entry->x =0 ; - entry->a =1 ; + entry->a = cpu_has_ept_ad; entry->d =0 ;break ; }
@@ -233,7 +235,7 @@ static int ept_set_middle_entry(struct p2m_domain *p2m, ept_entry_t *ept_entry) ept_entry->r = ept_entry->w = ept_entry->x =1 ;/* Manually set A bit to avoid overhead of MMU having to write it later. */ - ept_entry->a =1 ; + ept_entry->a = cpu_has_ept_ad; ept_entry->suppress_ve =1 ;
@@ -1150,6 +1152,9 @@ int ept_p2m_init(struct p2m_domain *p2m) p2m->memory_type_changed = ept_memory_type_changed; p2m->audit_p2m =NULL ; +/* Work around Errata AVR41 on Avaton processors. */ + cpu_has_ept_ad = boot_cpu_data.x86_model !=0x4d ; +/* Set the memory type used when accessing EPT paging structures. */ ept->ept_mt =EPT_DEFAULT_MT ;
Signature · 1 line
2.4.3
Hi,
Quoted 11 lines · Ross Lagerwall
Since commit
191b3f3344ee("p2m/ept: enable PML in p2m-ept for log-dirty"), the A and D bits of EPT paging entries are set unconditionally, regardless of whether PML is enabled or not. This causes a regression in Xen 4.6 on some processors due to Intel Errata AVR41 -- HVM guests get severe memory corruption when the A bit is set due to incorrect TLB flushing on mov to cr3. The errata affects the Atom C2000 family (Avaton).To fix, do not set the A bit on this processor family.
Signed-off-by Ross Lagerwall <[email protected]>
This looks pretty good as a 4.6 fix, though:
xen/arch/x86/mm/p2m-ept.c int ept_p2m_init(struct p2m_domain *p2m) · line 1157
Quoted 7 lines
xen/arch/x86/mm/p2m-ept.c +3
-0@@ -1150,6 +1152,9 @@ int ept_p2m_init(struct p2m_domain *p2m) p2m->memory_type_changed = ept_memory_type_changed; p2m->audit_p2m =NULL ; +/* Work around Errata AVR41 on Avaton processors. */ + cpu_has_ept_ad = boot_cpu_data.x86_model !=0x4d ; +
Shouldn't this check the family (a.k.a. boot_cpu_data.x86) too?
Cheers,
Tim.
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 28.09.15 at 14:43, <[email protected]> wrote:
xen/arch/x86/mm/p2m-ept.c int ept_p2m_init(struct p2m_domain *p2m) · line 1157
Quoted 7 lines · Ross Lagerwall
xen/arch/x86/mm/p2m-ept.c +3
-0@@ -1150,6 +1152,9 @@ int ept_p2m_init(struct p2m_domain *p2m) p2m->memory_type_changed = ept_memory_type_changed; p2m->audit_p2m =NULL ; +/* Work around Errata AVR41 on Avaton processors. */ + cpu_has_ept_ad = boot_cpu_data.x86_model !=0x4d ; +Shouldn't this check the family (a.k.a. boot_cpu_data.x86) too?
Definitely. Considering that the spec update says that the firmware may contain a workaround (microcode update) perhaps even the stepping and microcode level would need looking at.
Jan
Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 28.09.15 at 14:43, <[email protected]> wrote:
Quoted 4 lines · Ross Lagerwall
xen/arch/x86/mm/p2m-ept.c +0
-0@@ -1150,6 +1152,9 @@ int ept_p2m_init(struct p2m_domain *p2m) p2m->memory_type_changed = ept_memory_type_changed; p2m->audit_p2m =NULL ;
Quoted 7 lines
Quoted 4 lines
xen/arch/x86/mm/p2m-ept.c int ept_p2m_init(struct p2m_domain *p2m) · line 1157
Quoted 3 lines
xen/arch/x86/mm/p2m-ept.c +3
-0+/* Work around Errata AVR41 on Avaton processors. */ + cpu_has_ept_ad = boot_cpu_data.x86_model !=0x4d ; +Shouldn't this check the family (a.k.a. boot_cpu_data.x86) too?
Definitely. Considering that the spec update says that the firmware may contain a workaround (microcode update) perhaps even the stepping and microcode level would need looking at.
There are no details available as to what firmware fix might be available, nor how to determine whether the issue is fixed.
~Andrew
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 28.09.15 at 16:48, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 28.09.15 at 14:43, <[email protected]> wrote:
xen/arch/x86/mm/p2m-ept.c int ept_p2m_init(struct p2m_domain *p2m) · line 1157
Quoted 7 lines · Ross Lagerwall
xen/arch/x86/mm/p2m-ept.c +3
-0@@ -1150,6 +1152,9 @@ int ept_p2m_init(struct p2m_domain *p2m) p2m->memory_type_changed = ept_memory_type_changed; p2m->audit_p2m =NULL ; +/* Work around Errata AVR41 on Avaton processors. */ + cpu_has_ept_ad = boot_cpu_data.x86_model !=0x4d ; +Shouldn't this check the family (a.k.a. boot_cpu_data.x86) too?
Quoted 6 lines
Quoted 3 lines
Definitely. Considering that the spec update says that the firmware may contain a workaround (microcode update) perhaps even the stepping and microcode level would need looking at.
There are no details available as to what firmware fix might be available, nor how to determine whether the issue is fixed.
Which is why we've been awaiting input from Intel forever since the submission of the first version of the patch. But of course I agree that we can always relax the check later on.
Jan
CC Kai Huang
Quoted 100 lines · Ross Lagerwall
Since commit
191b3f3344ee("p2m/ept: enable PML in p2m-ept for log-dirty"), the A and D bits of EPT paging entries are set unconditionally, regardless of whether PML is enabled or not. This causes a regression in Xen 4.6 on some processors due to Intel Errata AVR41 -- HVM guests get severe memory corruption when the A bit is set due to incorrect TLB flushing on mov to cr3. The errata affects the Atom C2000 family (Avaton).To fix, do not set the A bit on this processor family.
Signed-off-by Ross Lagerwall <[email protected]>--- xen/arch/x86/mm/p2m-ept.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)xen/arch/x86/mm/p2m-ept.c +13
-8@@ -34,6 +34,8 @@#include "mm-locks.h" +static bool_t __read_mostly cpu_has_ept_ad; +#define atomic_read_ept_entry (__pepte) \ ( (ept_entry_t) { .epte = read_atomic(&(__pepte)->epte) } )@@ -130,14 +132,14 @@ static void ept_p2m_type_to_flags(struct p2m_domain *p2m, ept_entry_t *entry,break ;case p2m_ram_rw: entry->r = entry->w = entry->x =1 ; - entry->a = entry->d =1 ; + entry->a = entry->d = cpu_has_ept_ad;break ;case p2m_mmio_direct: entry->r = entry->x =1 ; entry->w = !rangeset_contains_singleton (mmio_ro_ranges, entry->mfn); - entry->a =1 ; - entry->d = entry->w; + entry->a = cpu_has_ept_ad; + entry->d = entry->w && cpu_has_ept_ad;break ;case p2m_ram_logdirty: entry->r = entry->x =1 ;@@ -152,7 +154,7 @@ static void ept_p2m_type_to_flags(struct p2m_domain *p2m, ept_entry_t *entry, entry->w =1 ; else entry->w = 0; - entry->a =1 ; + entry->a = cpu_has_ept_ad;/* For both PML or non-PML cases we clear D bit anyway */ entry->d =0 ;break ;@@ -160,20 +162,20 @@ static void ept_p2m_type_to_flags(struct p2m_domain *p2m, ept_entry_t *entry,case p2m_ram_shared: entry->r = entry->x =1 ; entry->w =0 ; - entry->a =1 ; + entry->a = cpu_has_ept_ad; entry->d =0 ;break ;case p2m_grant_map_rw:case p2m_map_foreign: entry->r = entry->w =1 ; entry->x =0 ; - entry->a = entry->d =1 ; + entry->a = entry->d = cpu_has_ept_ad;break ;case p2m_grant_map_ro:case p2m_mmio_write_dm: entry->r =1 ; entry->w = entry->x =0 ; - entry->a =1 ; + entry->a = cpu_has_ept_ad; entry->d =0 ;break ; }@@ -233,7 +235,7 @@ static int ept_set_middle_entry(struct p2m_domain *p2m, ept_entry_t *ept_entry) ept_entry->r = ept_entry->w = ept_entry->x =1 ;/* Manually set A bit to avoid overhead of MMU having to write it later. */ - ept_entry->a =1 ; + ept_entry->a = cpu_has_ept_ad; ept_entry->suppress_ve =1 ;@@ -1150,6 +1152,9 @@ int ept_p2m_init(struct p2m_domain *p2m) p2m->memory_type_changed = ept_memory_type_changed; p2m->audit_p2m =NULL ; +/* Work around Errata AVR41 on Avaton processors. */ + cpu_has_ept_ad = boot_cpu_data.x86_model !=0x4d ; +/* Set the memory type used when accessing EPT paging structures. */ ept->ept_mt =EPT_DEFAULT_MT ;Signature · 1 line
2.4.3
xen/arch/x86/mm/p2m-ept.c line 37
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 28.09.15 at 14:39, <[email protected]> wrote:
xen/arch/x86/mm/p2m-ept.c +1
-0@@ -34,6 +34,8 @@#include "mm-locks.h" +static bool_t __read_mostly cpu_has_ept_ad;
This should be
#define cpu_has_ept_ad (vmx_ept_vpid_cap & VMX_EPT_AD_BIT) put next to the respective other ones in vmx.h.
xen/arch/x86/mm/p2m-ept.c int ept_p2m_init(struct p2m_domain *p2m) · line 1156
Quoted 6 lines
xen/arch/x86/mm/p2m-ept.c +2
-0@@ -1150,6 +1152,9 @@ int ept_p2m_init(struct p2m_domain *p2m) p2m->memory_type_changed = ept_memory_type_changed; p2m->audit_p2m =NULL ; +/* Work around Errata AVR41 on Avaton processors. */ + cpu_has_ept_ad = boot_cpu_data.x86_model !=0x4d ;
And this one then should turn off said flag (i.e. needs to be moved elsewhere).
Plus PML initialization should get a respective check added.
Jan
Quoted 17 lines · Jan Beulich
xen/arch/x86/mm/p2m-ept.c line 37
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 28.09.15 at 14:39, <[email protected]> wrote:
xen/arch/x86/mm/p2m-ept.c +1
-0@@ -34,6 +34,8 @@#include "mm-locks.h" +static bool_t __read_mostly cpu_has_ept_ad;This should be
#definecpu_has_ept_ad(vmx_ept_vpid_cap&VMX_EPT_AD_BIT) put next to the respective other ones invmx.h.Quoted 4 lines
xen/arch/x86/mm/p2m-ept.c +0
-0@@ -1150,6 +1152,9 @@ int ept_p2m_init(struct p2m_domain *p2m) p2m->memory_type_changed = ept_memory_type_changed; p2m->audit_p2m =NULL ;
Quoted 7 lines
xen/arch/x86/mm/p2m-ept.c int ept_p2m_init(struct p2m_domain *p2m) · line 1156
Quoted 2 lines
xen/arch/x86/mm/p2m-ept.c +2
-0+/* Work around Errata AVR41 on Avaton processors. */ + cpu_has_ept_ad = boot_cpu_data.x86_model !=0x4d ;And this one then should turn off said flag (i.e. needs to be moved elsewhere).
Plus PML initialization should get a respective check added.
In case there was any doubt, I am following this thread, and so far haven't had anything to disagree with the direction Tim and Jan are suggesting.
-George
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 28.09.15 at 14:39, <[email protected]> wrote:
xen/arch/x86/mm/p2m-ept.c +0
-0@@ -34,6 +34,8 @@
Quoted 7 lines
xen/arch/x86/mm/p2m-ept.c line 37
Quoted 3 lines
xen/arch/x86/mm/p2m-ept.c +1
-0#include "mm-locks.h" +static bool_t __read_mostly cpu_has_ept_ad;This should be
#definecpu_has_ept_ad(vmx_ept_vpid_cap&VMX_EPT_AD_BIT) put next to the respective other ones invmx.h.
+1.
Quoted 10 lines
xen/arch/x86/mm/p2m-ept.c int ept_p2m_init(struct p2m_domain *p2m) · line 1156
Quoted 7 lines
xen/arch/x86/mm/p2m-ept.c +2
-0@@ -1150,6 +1152,9 @@ int ept_p2m_init(struct p2m_domain *p2m) p2m->memory_type_changed = ept_memory_type_changed; p2m->audit_p2m =NULL ; +/* Work around Errata AVR41 on Avaton processors. */ + cpu_has_ept_ad = boot_cpu_data.x86_model !=0x4d ;And this one then should turn off said flag (i.e. needs to be moved elsewhere).
However if cpu_has_ept_ad is going to be a macro definition as suggested above, looks we need another variable.
Quoted 2 lines
Plus PML initialization should get a respective check added.
My first thinking is checking whether cpu_has_ept_ad is set in ept_enable_pml.
Btw sorry I am taking vacation until Oct.8 so please expect slow response if you need my comments.
Thanks,
-Kai
Quoted 8 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Signature · 2 lines
Thanks, -Kai
Quoted 7 lines · Ross Lagerwall
Since commit
191b3f3344ee("p2m/ept: enable PML in p2m-ept for log-dirty"), the A and D bits of EPT paging entries are set unconditionally, regardless of whether PML is enabled or not. This causes a regression in Xen 4.6 on some processors due to Intel Errata AVR41 -- HVM guests get severe memory corruption when the A bit is set due to incorrect TLB flushing on mov to cr3. The errata affects the Atom C2000 family (Avaton).
Typo here, should be Avoton.
Quoted 1 line
[...]
xen/arch/x86/mm/p2m-ept.c int ept_p2m_init(struct p2m_domain *p2m) · line 1155
Quoted 5 lines
xen/arch/x86/mm/p2m-ept.c +1
-0@@ -1150,6 +1152,9 @@ int ept_p2m_init(struct p2m_domain *p2m) p2m->memory_type_changed = ept_memory_type_changed; p2m->audit_p2m =NULL ; +/* Work around Errata AVR41 on Avaton processors. */
Same here, Avoton.
Quoted 7 lines
xen/arch/x86/mm/p2m-ept.c +2
-0+ cpu_has_ept_ad = boot_cpu_data.x86_model !=0x4d ; +/* Set the memory type used when accessing EPT paging structures. */ ept->ept_mt =EPT_DEFAULT_MT ;Signature · 1 line
2.4.3