x86: remove CR reads from exit-to-guest path

CR3 is - during normal operation - only ever loaded from v->arch.cr3,
so there's no need to read the actual control register. For CR4 we can
generally use the cached value on all synchronous entry end exit paths.
Drop the write_cr3 macro, as the two use sites are probably easier to
follow without its use.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Tested-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
master commit: 31bf55cb5f
master date: 2018-03-06 16:49:36 +0100
This commit is contained in:
Jan Beulich committed 2018-03-20 14:40:09 +01:00
1 parent 813fe211f2
commit 7db1c43a36
3 files changed
+14 -12

No files matched your search

+1
View File
@@ -88,6 +88,7 @@ void __dummy__(void)
OFFSET(VCPU_kernel_ss, struct vcpu, arch.pv_vcpu.kernel_ss);
OFFSET(VCPU_iopl, struct vcpu, arch.pv_vcpu.iopl);
OFFSET(VCPU_guest_context_flags, struct vcpu, arch.vgc_flags);
OFFSET(VCPU_cr3, struct vcpu, arch.cr3);
OFFSET(VCPU_arch_spec_ctrl, struct vcpu, arch.spec_ctrl);
OFFSET(VCPU_nmi_pending, struct vcpu, nmi_pending);
OFFSET(VCPU_mce_pending, struct vcpu, mce_pending);
+13 -3
View File
@@ -43,7 +43,7 @@ restore_all_guest:
mov VCPU_arch_spec_ctrl(%rbx), %r15d
/* Copy guest mappings and switch to per-CPU root page table. */
mov %cr3, %r9
mov VCPU_cr3(%rbx), %r9
GET_STACK_END(dx)
mov STACK_CPUINFO_FIELD(pv_cr3)(%rdx), %rdi
movabs $PADDR_MASK & PAGE_MASK, %rsi
@@ -65,8 +65,13 @@ restore_all_guest:
sub $(ROOT_PAGETABLE_FIRST_XEN_SLOT - \
ROOT_PAGETABLE_LAST_XEN_SLOT - 1) * 8, %rdi
rep movsq
mov STACK_CPUINFO_FIELD(cr4)(%rdx), %rdi
mov %r9, STACK_CPUINFO_FIELD(xen_cr3)(%rdx)
write_cr3 rax, rdi, rsi
mov %rdi, %rsi
and $~X86_CR4_PGE, %rdi
mov %rdi, %cr4
mov %rax, %cr3
mov %rsi, %cr4
.Lrag_keep_cr3:
/* Restore stashed SPEC_CTRL value. */
@@ -122,7 +127,12 @@ restore_all_xen:
* so "g" will have to do.
*/
UNLIKELY_START(g, exit_cr3)
write_cr3 rax, rdi, rsi
mov %cr4, %rdi
mov %rdi, %rsi
and $~X86_CR4_PGE, %rdi
mov %rdi, %cr4
mov %rax, %cr3
mov %rsi, %cr4
UNLIKELY_END(exit_cr3)
/* WARNING! `ret`, `call *`, `jmp *` not safe beyond this point. */
-9
View File
@@ -207,15 +207,6 @@ void ret_from_intr(void);
#define ASM_STAC ASM_AC(STAC)
#define ASM_CLAC ASM_AC(CLAC)
.macro write_cr3 val:req, tmp1:req, tmp2:req
mov %cr4, %\tmp1
mov %\tmp1, %\tmp2
and $~X86_CR4_PGE, %\tmp1
mov %\tmp1, %cr4
mov %\val, %cr3
mov %\tmp2, %cr4
.endm
#define CR4_PV32_RESTORE \
667: ASM_NOP5; \
.pushsection .altinstr_replacement, "ax"; \
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.