x86/tlb: Opencode the use of write_cr4() in write_cr3() and flush_area_local()
PATCH 1/1 x86/tlb: Opencode the use of write_cr4() in write_cr3() and flush_area_local()
This avoids unnecessary updates to the stack shadow copy of cr4 during critical regions with interrupts disabled.
No change in behaviour.
---
CC: Jan Beulich <[email protected]>
--- xen/arch/x86/flushtlb.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
xen/arch/x86/flushtlb.c +13 -6
@@ -81,9 +81,14 @@ void write_cr3(unsigned long cr3)hvm_flush_guest_tlbs (); -write_cr4 (cr4 & ~X86_CR4_PGE ); - asmvolatile ("mov %0, %%cr3" : :"r" (cr3) :"memory" ); -write_cr4 (cr4); + asmvolatile ("mov %[npge], %%cr4;" +"mov %[cr3], %%cr3;" +"mov %[cr4], %%cr4;" + :: + [npge]"r" (cr4 & ~X86_CR4_PGE ), + [cr3]"r" (cr3), + [cr4]"r" (cr4) + :"memory" );post_flush (t);
@@ -123,9 +128,11 @@ unsigned int flush_area_local(const void *va, unsigned int flags)hvm_flush_guest_tlbs (); -write_cr4 (cr4 & ~X86_CR4_PGE ); -barrier (); -write_cr4 (cr4); + asmvolatile ("mov %[npge], %%cr4;" +"mov %[cr4], %%cr4;" + :: + [npge]"r" (cr4 & ~X86_CR4_PGE ), + [cr4]"r" (cr4));post_flush (t); }
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 21.08.17 at 13:55, <[email protected]> wrote:
This avoids unnecessary updates to the stack shadow copy of cr4 during critical regions with interrupts disabled.
Hmm, yes - we don't access CR4 in #MC or NMI handling, do we?
Quoted 3 lines
No change in behaviour.
Signed-off-by Andrew Cooper <[email protected]>
with ...
Quoted 7 lines
xen/arch/x86/flushtlb.c +0
-1@@ -81,9 +81,14 @@ void write_cr3(unsigned long cr3)hvm_flush_guest_tlbs (); -write_cr4 (cr4 & ~X86_CR4_PGE );
xen/arch/x86/flushtlb.c void write_cr3(unsigned long cr3) · line 91
Quoted 10 lines
xen/arch/x86/flushtlb.c +8
-2- asmvolatile ("mov %0, %%cr3" : :"r" (cr3) :"memory" ); -write_cr4 (cr4); + asmvolatile ("mov %[npge], %%cr4;" +"mov %[cr3], %%cr3;" +"mov %[cr4], %%cr4;" + :: + [npge]"r" (cr4 & ~X86_CR4_PGE ), + [cr3]"r" (cr3), + [cr4]"r" (cr4) + :"memory" );
... blanks added immediately inside the parentheses here and ...
xen/arch/x86/flushtlb.c unsigned int flush_area_local(const void *va, unsigned int flags) · line 135
Quoted 12 lines
xen/arch/x86/flushtlb.c +5
-3@@ -123,9 +128,11 @@ unsigned int flush_area_local(const void *va, unsigned int flags)hvm_flush_guest_tlbs (); -write_cr4 (cr4 & ~X86_CR4_PGE ); -barrier (); -write_cr4 (cr4); + asmvolatile ("mov %[npge], %%cr4;" +"mov %[cr4], %%cr4;" + :: + [npge]"r" (cr4 & ~X86_CR4_PGE ), + [cr4]"r" (cr4));
... here.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 4 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 21.08.17 at 13:55, <[email protected]> wrote:
This avoids unnecessary updates to the stack shadow copy of cr4 during critical regions with interrupts disabled.
Hmm, yes - we don't access CR4 in #MC or NMI handling, do we?
#MC and NMI are always able to observe stale values whether we update the shadow copy here or not.
The entry paths do modify cr4 to re-enable cr4_pv32_mask, but that is all. As we are interrupting Xen context here, we should take the fastpath and leave cr4 unmodified.
~Andrew
Quoted 40 lines
Quoted 4 lines
No change in behaviour.
Signed-off-by Andrew Cooper <[email protected]>Reviewed-by Jan Beulich <[email protected]>with ...
Quoted 7 lines
xen/arch/x86/flushtlb.c +0
-1@@ -81,9 +81,14 @@ void write_cr3(unsigned long cr3)hvm_flush_guest_tlbs (); -write_cr4 (cr4 & ~X86_CR4_PGE );xen/arch/x86/flushtlb.c void write_cr3(unsigned long cr3) · line 91
Quoted 10 lines
xen/arch/x86/flushtlb.c +8
-2- asmvolatile ("mov %0, %%cr3" : :"r" (cr3) :"memory" ); -write_cr4 (cr4); + asmvolatile ("mov %[npge], %%cr4;" +"mov %[cr3], %%cr3;" +"mov %[cr4], %%cr4;" + :: + [npge]"r" (cr4 & ~X86_CR4_PGE ), + [cr3]"r" (cr3), + [cr4]"r" (cr4) + :"memory" );... blanks added immediately inside the parentheses here and ...
xen/arch/x86/flushtlb.c unsigned int flush_area_local(const void *va, unsigned int flags) · line 135
Quoted 12 lines
xen/arch/x86/flushtlb.c +5
-3@@ -123,9 +128,11 @@ unsigned int flush_area_local(const void *va, unsigned int flags)hvm_flush_guest_tlbs (); -write_cr4 (cr4 & ~X86_CR4_PGE ); -barrier (); -write_cr4 (cr4); + asmvolatile ("mov %[npge], %%cr4;" +"mov %[cr4], %%cr4;" + :: + [npge]"r" (cr4 & ~X86_CR4_PGE ), + [cr4]"r" (cr4));... here.
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel