From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Jan Beulich <JBeulich@suse.com>
Cc: xen-devel <xen-devel@lists.xenproject.org>,
Boris Ostrovsky <boris.ostrovsky@oracle.com>,
Keir Fraser <keir@xen.org>, Jacob Shin <jacob.shin@amd.com>,
suravee.suthikulpanit@amd.com
Subject: Re: [PATCH 4/4] SVM: streamline entry.S code
Date: Mon, 26 Aug 2013 17:20:07 +0100 [thread overview]
Message-ID: <521B8037.3090809@citrix.com> (raw)
In-Reply-To: <521787FA02000078000EE083@nat28.tlf.novell.com>
[-- Attachment #1.1: Type: text/plain, Size: 6055 bytes --]
On 23/08/2013 15:04, Jan Beulich wrote:
> - move stuff easily/better done in C into C code
> - re-arrange code paths so that no redundant GET_CURRENT() would remain
> on the fast paths
> - move long latency operations earlier
> - slightly defer disabling global interrupts on the VM entry path
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>
> --- a/xen/arch/x86/hvm/svm/entry.S
> +++ b/xen/arch/x86/hvm/svm/entry.S
> @@ -32,28 +32,34 @@
> #define CLGI .byte 0x0F,0x01,0xDD
>
> ENTRY(svm_asm_do_resume)
> + GET_CURRENT(%rbx)
> +.Lsvm_do_resume:
> call svm_intr_assist
> mov %rsp,%rdi
> call nsvm_vcpu_switch
> ASSERT_NOT_IN_ATOMIC
>
> - GET_CURRENT(%rbx)
> - CLGI
> -
> mov VCPU_processor(%rbx),%eax
> - shl $IRQSTAT_shift,%eax
> lea irq_stat+IRQSTAT_softirq_pending(%rip),%rdx
> - cmpl $0,(%rdx,%rax,1)
> + xor %ecx,%ecx
> + shl $IRQSTAT_shift,%eax
> + CLGI
> + cmp %ecx,(%rdx,%rax,1)
> jne .Lsvm_process_softirqs
>
> - testb $0, VCPU_nsvm_hap_enabled(%rbx)
> -UNLIKELY_START(nz, nsvm_hap)
> - mov VCPU_nhvm_p2m(%rbx),%rax
> - test %rax,%rax
> + cmp %cl,VCPU_nsvm_hap_enabled(%rbx)
> +UNLIKELY_START(ne, nsvm_hap)
> + cmp %rcx,VCPU_nhvm_p2m(%rbx)
> sete %al
> - andb VCPU_nhvm_guestmode(%rbx),%al
> - jnz .Lsvm_nsvm_no_p2m
> -UNLIKELY_END(nsvm_hap)
> + test VCPU_nhvm_guestmode(%rbx),%al
> + UNLIKELY_DONE(z, nsvm_hap)
> + /*
> + * Someone shot down our nested p2m table; go round again
> + * and nsvm_vcpu_switch() will fix it for us.
> + */
> + STGI
> + jmp .Lsvm_do_resume
> +__UNLIKELY_END(nsvm_hap)
>
> call svm_asid_handle_vmrun
>
> @@ -72,13 +78,12 @@ UNLIKELY_END(svm_trace)
> mov UREGS_eflags(%rsp),%rax
> mov %rax,VMCB_rflags(%rcx)
>
> - mov VCPU_svm_vmcb_pa(%rbx),%rax
> -
> pop %r15
> pop %r14
> pop %r13
> pop %r12
> pop %rbp
> + mov VCPU_svm_vmcb_pa(%rbx),%rax
> pop %rbx
> pop %r11
> pop %r10
> @@ -92,25 +97,26 @@ UNLIKELY_END(svm_trace)
>
> VMRUN
>
> + GET_CURRENT(%rax)
> push %rdi
> push %rsi
> push %rdx
> push %rcx
> + mov VCPU_svm_vmcb(%rax),%rcx
> push %rax
Having read the manual several times, I am now more and more confused
about this.
My reading of the AMD programmer manual vol 3 indicates that %rax after
VMRUN completes will be the host %rax, i.e. VCPU_svm_vmcb_pa.
However, I cant find anywhere in the code which overwrites regs->rax
from vmcb->rax, which I would have thought would have thought would
cause utter devastation in combination with the generic functions
working with a cpu_user_regs structure.
The alternative is that %rax after VMRUN is actually the guest %rax, at
which point the pushes used to do the correct thing, but are now broken
by this patch clobbering it before being saved.
Can someone with more knowledge please confirm? I really hope I have
overlooked something in the code.
~Andrew
> push %r8
> push %r9
> push %r10
> push %r11
> push %rbx
> + mov %rax,%rbx
> push %rbp
> push %r12
> push %r13
> push %r14
> push %r15
>
> - GET_CURRENT(%rbx)
> movb $0,VCPU_svm_vmcb_in_sync(%rbx)
> - mov VCPU_svm_vmcb(%rbx),%rcx
> mov VMCB_rax(%rcx),%rax
> mov %rax,UREGS_rax(%rsp)
> mov VMCB_rip(%rcx),%rax
> @@ -120,33 +126,14 @@ UNLIKELY_END(svm_trace)
> mov VMCB_rflags(%rcx),%rax
> mov %rax,UREGS_eflags(%rsp)
>
> -#ifndef NDEBUG
> - mov $0xbeef,%ax
> - mov %ax,UREGS_error_code(%rsp)
> - mov %ax,UREGS_entry_vector(%rsp)
> - mov %ax,UREGS_saved_upcall_mask(%rsp)
> - mov %ax,UREGS_cs(%rsp)
> - mov %ax,UREGS_ds(%rsp)
> - mov %ax,UREGS_es(%rsp)
> - mov %ax,UREGS_fs(%rsp)
> - mov %ax,UREGS_gs(%rsp)
> - mov %ax,UREGS_ss(%rsp)
> -#endif
> -
> STGI
> .globl svm_stgi_label
> svm_stgi_label:
> mov %rsp,%rdi
> call svm_vmexit_handler
> - jmp svm_asm_do_resume
> + jmp .Lsvm_do_resume
>
> .Lsvm_process_softirqs:
> STGI
> call do_softirq
> - jmp svm_asm_do_resume
> -
> -.Lsvm_nsvm_no_p2m:
> - /* Someone shot down our nested p2m table; go round again
> - * and nsvm_vcpu_switch() will fix it for us. */
> - STGI
> - jmp svm_asm_do_resume
> + jmp .Lsvm_do_resume
> --- a/xen/arch/x86/hvm/svm/svm.c
> +++ b/xen/arch/x86/hvm/svm/svm.c
> @@ -2069,6 +2069,8 @@ void svm_vmexit_handler(struct cpu_user_
> vintr_t intr;
> bool_t vcpu_guestmode = 0;
>
> + hvm_invalidate_regs_fields(regs);
> +
> if ( paging_mode_hap(v->domain) )
> v->arch.hvm_vcpu.guest_cr[3] = v->arch.hvm_vcpu.hw_cr[3] =
> vmcb_get_cr3(vmcb);
> --- a/xen/include/asm-x86/asm_defns.h
> +++ b/xen/include/asm-x86/asm_defns.h
> @@ -39,11 +39,17 @@ void ret_from_intr(void);
> .subsection 1; \
> .Lunlikely.tag:
>
> -#define UNLIKELY_END(tag) \
> - jmp .Llikely.tag; \
> +#define UNLIKELY_DONE(cond, tag) \
> + j##cond .Llikely.tag
> +
> +#define __UNLIKELY_END(tag) \
> .subsection 0; \
> .Llikely.tag:
>
> +#define UNLIKELY_END(tag) \
> + UNLIKELY_DONE(mp, tag); \
> + __UNLIKELY_END(tag)
> +
> #define STACK_CPUINFO_FIELD(field) (STACK_SIZE-CPUINFO_sizeof+CPUINFO_##field)
> #define GET_STACK_BASE(reg) \
> movq $~(STACK_SIZE-1),reg; \
>
>
>
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> http://lists.xen.org/xen-devel
[-- Attachment #1.2: Type: text/html, Size: 6689 bytes --]
[-- Attachment #2: Type: text/plain, Size: 126 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
next prev parent reply other threads:[~2013-08-26 16:20 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-23 13:58 [PATCH 0/4] HVM: produce better binary code Jan Beulich
2013-08-23 14:01 ` [PATCH 1/4] VMX: streamline entry.S code Jan Beulich
2013-08-26 10:44 ` Andrew Cooper
2013-08-26 11:01 ` Jan Beulich
2013-08-26 11:48 ` Andrew Cooper
2013-08-26 13:12 ` Jan Beulich
2013-08-26 13:22 ` Andrew Cooper
2013-08-29 11:01 ` Tim Deegan
2013-08-29 12:35 ` Jan Beulich
2013-08-23 14:02 ` [PATCH 2/4] VMX: move various uses of UD2 out of fast paths Jan Beulich
2013-08-23 22:06 ` Andrew Cooper
2013-08-26 8:50 ` Jan Beulich
2013-08-26 9:07 ` Andrew Cooper
2013-08-26 8:58 ` [PATCH v2 " Jan Beulich
2013-08-26 9:09 ` Andrew Cooper
2013-08-29 11:08 ` Tim Deegan
2013-08-23 14:03 ` [PATCH 3/4] VMX: use proper instruction mnemonics if assembler supports them Jan Beulich
2013-08-24 22:18 ` Andrew Cooper
2013-08-26 9:06 ` Jan Beulich
2013-08-26 9:25 ` Andrew Cooper
2013-08-26 9:41 ` Jan Beulich
2013-08-26 10:18 ` [PATCH v3 " Jan Beulich
2013-08-26 13:05 ` Andrew Cooper
2013-08-26 13:20 ` Jan Beulich
2013-08-26 14:03 ` [PATCH v4 " Jan Beulich
2013-08-26 14:18 ` Andrew Cooper
2013-08-26 14:29 ` Jan Beulich
2013-08-26 15:07 ` Andrew Cooper
2013-08-26 15:10 ` Andrew Cooper
2013-08-26 15:30 ` Jan Beulich
2013-08-26 15:29 ` Jan Beulich
2013-08-26 15:33 ` Andrew Cooper
2013-08-26 15:31 ` [PATCH v5 " Jan Beulich
2013-08-26 15:36 ` Andrew Cooper
2013-08-29 11:47 ` Tim Deegan
2013-08-29 12:30 ` Jan Beulich
2013-08-29 13:11 ` Tim Deegan
2013-08-29 13:27 ` Jan Beulich
2013-08-29 14:02 ` Tim Deegan
2013-08-29 12:45 ` Jan Beulich
2013-08-29 13:19 ` Tim Deegan
2013-08-26 9:03 ` [PATCH v2 " Jan Beulich
2013-08-23 14:04 ` [PATCH 4/4] SVM: streamline entry.S code Jan Beulich
2013-08-26 16:20 ` Andrew Cooper [this message]
2013-08-26 17:20 ` Keir Fraser
2013-08-26 17:46 ` Andrew Cooper
2013-08-26 21:47 ` Andrew Cooper
2013-08-27 7:38 ` Jan Beulich
2013-08-29 11:56 ` Tim Deegan
2013-09-04 14:39 ` Boris Ostrovsky
2013-09-04 14:50 ` Jan Beulich
2013-09-04 15:09 ` Boris Ostrovsky
2013-09-04 15:20 ` Jan Beulich
2013-09-04 16:42 ` Boris Ostrovsky
2013-09-05 7:10 ` Jan Beulich
2013-09-04 10:06 ` Ping: [PATCH 0/4] HVM: produce better binary code Jan Beulich
2013-09-04 16:16 ` Andrew Cooper
2013-09-04 16:30 ` Tim Deegan
2013-09-05 7:52 ` Jan Beulich
2013-09-05 7:58 ` Tim Deegan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=521B8037.3090809@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=JBeulich@suse.com \
--cc=boris.ostrovsky@oracle.com \
--cc=jacob.shin@amd.com \
--cc=keir@xen.org \
--cc=suravee.suthikulpanit@amd.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.