From: Sean Christopherson <seanjc@google.com>
To: Nathan Chancellor <natechancellor@gmail.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Tom Lendacky <thomas.lendacky@amd.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
x86@kernel.org, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com,
Nick Desaulniers <ndesaulniers@google.com>,
Sami Tolvanen <samitolvanen@google.com>,
Michael Roth <michael.roth@amd.com>
Subject: Re: [PATCH] KVM: SVM: Add register operand to vmsave call in sev_es_vcpu_load
Date: Mon, 21 Dec 2020 10:10:18 -0800 [thread overview]
Message-ID: <X+DlCpHSu+opeOge@google.com> (raw)
In-Reply-To: <X+Df2oQczVBmwEzi@google.com>
+Michael, as this will conflict with an in-progress series to use VMSAVE in the
common SVM run path.
https://lkml.kernel.org/r/20201214174127.1398114-1-michael.roth@amd.com
On Mon, Dec 21, 2020, Sean Christopherson wrote:
> On Fri, Dec 18, 2020, Nathan Chancellor wrote:
> > When using LLVM's integrated assembler (LLVM_IAS=1) while building
> > x86_64_defconfig + CONFIG_KVM=y + CONFIG_KVM_AMD=y, the following build
> > error occurs:
> >
> > $ make LLVM=1 LLVM_IAS=1 arch/x86/kvm/svm/sev.o
> > arch/x86/kvm/svm/sev.c:2004:15: error: too few operands for instruction
> > asm volatile(__ex("vmsave") : : "a" (__sme_page_pa(sd->save_area)) : "memory");
> > ^
> > arch/x86/kvm/svm/sev.c:28:17: note: expanded from macro '__ex'
> > #define __ex(x) __kvm_handle_fault_on_reboot(x)
> > ^
> > ./arch/x86/include/asm/kvm_host.h:1646:10: note: expanded from macro '__kvm_handle_fault_on_reboot'
> > "666: \n\t" \
> > ^
> > <inline asm>:2:2: note: instantiated into assembly here
> > vmsave
> > ^
> > 1 error generated.
> >
> > This happens because LLVM currently does not support calling vmsave
> > without the fixed register operand (%rax for 64-bit and %eax for
> > 32-bit). This will be fixed in LLVM 12 but the kernel currently supports
> > LLVM 10.0.1 and newer so this needs to be handled.
> >
> > Add the proper register using the _ASM_AX macro, which matches the
> > vmsave call in vmenter.S.
>
> There are also two instances in tools/testing/selftests/kvm/lib/x86_64/svm.c
> that likely need to be fixed.
>
> > Fixes: 861377730aa9 ("KVM: SVM: Provide support for SEV-ES vCPU loading")
> > Link: https://reviews.llvm.org/D93524
> > Link: https://github.com/ClangBuiltLinux/linux/issues/1216
> > Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
> > ---
> > arch/x86/kvm/svm/sev.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> > index e57847ff8bd2..958370758ed0 100644
> > --- a/arch/x86/kvm/svm/sev.c
> > +++ b/arch/x86/kvm/svm/sev.c
> > @@ -2001,7 +2001,7 @@ void sev_es_vcpu_load(struct vcpu_svm *svm, int cpu)
> > * of which one step is to perform a VMLOAD. Since hardware does not
> > * perform a VMSAVE on VMRUN, the host savearea must be updated.
> > */
> > - asm volatile(__ex("vmsave") : : "a" (__sme_page_pa(sd->save_area)) : "memory");
> > + asm volatile(__ex("vmsave %%"_ASM_AX) : : "a" (__sme_page_pa(sd->save_area)) : "memory");
>
> I vote to add a helper in svm.h to encode VMSAVE, even if there is only the one
> user. Between the rAX behavior (it _must_ be rAX) and taking the HPA of the
> VMCB, the semantics of VMSAVE are just odd enough to cause a bit of head
> scratching when reading the code for the first time. E.g. something like:
>
> void vmsave(struct page *vmcb)
> {
> /*
> * VMSAVE takes the HPA of a VMCB in rAX (hardcoded by VMSAVE itself).
> * The _ASM_AX operand is required to specify the address size, which
> * means VMSAVE cannot consume a 64-bit address outside of 64-bit mode.
> */
> hpa_t vmcb_pa = __sme_page_pa(vmcb);
>
> BUG_ON(!IS_ENABLED(CONFIG_X86_64) && (vmcb_pa >> 32));
>
> asm volatile(__ex("vmsave %%"_ASM_AX) : : "a" (vmcb_pa) : "memory");
> }
>
> >
> > /*
> > * Certain MSRs are restored on VMEXIT, only save ones that aren't
> > --
> > 2.30.0.rc0
> >
next prev parent reply other threads:[~2020-12-21 18:11 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-19 6:37 [PATCH] KVM: SVM: Add register operand to vmsave call in sev_es_vcpu_load Nathan Chancellor
2020-12-21 17:48 ` Sean Christopherson
2020-12-21 18:10 ` Sean Christopherson [this message]
2020-12-21 18:12 ` Paolo Bonzini
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=X+DlCpHSu+opeOge@google.com \
--to=seanjc@google.com \
--cc=bp@alien8.de \
--cc=clang-built-linux@googlegroups.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michael.roth@amd.com \
--cc=mingo@redhat.com \
--cc=natechancellor@gmail.com \
--cc=ndesaulniers@google.com \
--cc=pbonzini@redhat.com \
--cc=samitolvanen@google.com \
--cc=tglx@linutronix.de \
--cc=thomas.lendacky@amd.com \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.com \
--cc=x86@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).