From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1082FC433F5 for ; Thu, 3 Mar 2022 14:54:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9966D8D0002; Thu, 3 Mar 2022 09:54:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 91F338D0001; Thu, 3 Mar 2022 09:54:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7C0C68D0002; Thu, 3 Mar 2022 09:54:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id 698F48D0001 for ; Thu, 3 Mar 2022 09:54:06 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 35467255C5 for ; Thu, 3 Mar 2022 14:54:06 +0000 (UTC) X-FDA: 79203370092.14.0BB2516 Received: from mail-oo1-f47.google.com (mail-oo1-f47.google.com [209.85.161.47]) by imf19.hostedemail.com (Postfix) with ESMTP id 86B4E1A000D for ; Thu, 3 Mar 2022 14:54:05 +0000 (UTC) Received: by mail-oo1-f47.google.com with SMTP id n5-20020a4a9545000000b0031d45a442feso6029139ooi.3 for ; Thu, 03 Mar 2022 06:54:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=O5iL6uUeO62UPrSkGXZq3lP4aWlaw5JT5YJH3gIcMgk=; b=Yus1QxeU93fbVJNbAl6vhTAcK1+baKkaAhSX1oqTIneAUwRmLWqRgVaa0Sk61Wp0AG gk9OnCGiWDHPCRzc0KYDovQ8ZzNuV91nYdNpZd2rYfrnBp0CErdvlNDpJ0PLOGIiF0TO mzr8ECmYFBh4du9No6R1HRjZM/VrwLBkhjPiooq9U0B2+KsHVBdkgynZea1RxRwwq2w9 lhJxsLOOTfWq4/wF70KIfvdWOyuG21AU7XcEpoyNGy4jvvh5kt/4A6UsdVWOcn2DgvQa U3cPRX3QucjbyN2x7EQ0UjMCb6jGiA0fhyVIhiQcYo1esA1d6ugPgMVjOO30QBNOQknu RAyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=O5iL6uUeO62UPrSkGXZq3lP4aWlaw5JT5YJH3gIcMgk=; b=L1I71jimOgyuxTEEoORJqTm+Uz/Vxsn+T0Ks2tgsdtrixc3Ui4jhloJaMZieVBKrCn xCYwsN2v0xXxJe0m5xt4EzcltBno/CN/O2JZ9RJZUgCu3BvR+aZDglKsqKeNkwx+ylpE 5vS4wAmL4eUAIxGN9+S1ubESXz569EG6f74t9PMPIjDu22lP744EuGtxWqYlyST3ffR0 qpiBDvc3pFBM058imr3ew6OvQk9R9jDsL5myOiOjeD/nQBI3u49DhHguu7EFU0ejHBVu 3uLBbPCr+6fR43xuGW4hVb0datjDYfOCnS4C8G0kWDpuLvpUXVKeyTNx5jbM1pS5UvpO JU7A== X-Gm-Message-State: AOAM531Z7xKe/ZfPGuzus+NSRMI0mG5aWNct4l/HzP6GUTWQ/xTQLWa+ paUmQdb4xR/MjmDh15AFu2f2RaYvnAZjpxc1fLI= X-Google-Smtp-Source: ABdhPJxH7aINZfgFxXx1q4Mc+31Ixa9VwFFZiPL2NuoWLPbVUU7UKMTbZaMmBYO2zd5mRkkeNQcX4WVfFFhkdoKZmfw= X-Received: by 2002:a05:6870:7c0c:b0:d6:c338:f5c3 with SMTP id je12-20020a0568707c0c00b000d6c338f5c3mr4332355oab.63.1646319244625; Thu, 03 Mar 2022 06:54:04 -0800 (PST) MIME-Version: 1.0 References: <20220128171804.569796-1-brijesh.singh@amd.com> <20220128171804.569796-40-brijesh.singh@amd.com> In-Reply-To: From: Brijesh Singh Date: Thu, 3 Mar 2022 08:53:53 -0600 Message-ID: Subject: Re: [PATCH v9 39/43] x86/sev: Provide support for SNP guest request NAEs To: Peter Gonda Cc: Brijesh Singh , "the arch/x86 maintainers" , LKML , kvm list , linux-efi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-coco@lists.linux.dev, linux-mm@kvack.org, Thomas Gleixner , Ingo Molnar , Joerg Roedel , Tom Lendacky , "H. Peter Anvin" , Ard Biesheuvel , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Jim Mattson , Andy Lutomirski , Dave Hansen , Sergio Lopez , Peter Zijlstra , Srinivas Pandruvada , David Rientjes , Dov Murik , Tobin Feldman-Fitzthum , Borislav Petkov , Michael Roth , Vlastimil Babka , "Kirill A . Shutemov" , Andi Kleen , "Dr . David Alan Gilbert" , Tony Luck , Marc Orr , Sathyanarayanan Kuppuswamy Content-Type: multipart/alternative; boundary="000000000000c34d4505d9519150" X-Rspamd-Queue-Id: 86B4E1A000D X-Stat-Signature: o8nthhx4sdu3rm98p4fuxqwrsihw7wgo Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Yus1QxeU; spf=pass (imf19.hostedemail.com: domain of brijesh.ksingh@gmail.com designates 209.85.161.47 as permitted sender) smtp.mailfrom=brijesh.ksingh@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1646319245-737584 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: --000000000000c34d4505d9519150 Content-Type: text/plain; charset="UTF-8" On Tue, Feb 1, 2022 at 2:17 PM Peter Gonda wrote: > On Fri, Jan 28, 2022 at 10:19 AM Brijesh Singh > wrote: > > > > Version 2 of GHCB specification provides SNP_GUEST_REQUEST and > > SNP_EXT_GUEST_REQUEST NAE that can be used by the SNP guest to > communicate > > with the PSP. > > > > While at it, add a snp_issue_guest_request() helper that will be used by > > driver or other subsystem to issue the request to PSP. > > > > See SEV-SNP firmware and GHCB spec for more details. > > > > Signed-off-by: Brijesh Singh > > --- > > arch/x86/include/asm/sev-common.h | 3 ++ > > arch/x86/include/asm/sev.h | 14 ++++++++ > > arch/x86/include/uapi/asm/svm.h | 4 +++ > > arch/x86/kernel/sev.c | 55 +++++++++++++++++++++++++++++++ > > 4 files changed, 76 insertions(+) > > > > diff --git a/arch/x86/include/asm/sev-common.h > b/arch/x86/include/asm/sev-common.h > > index cd769984e929..442614879dad 100644 > > --- a/arch/x86/include/asm/sev-common.h > > +++ b/arch/x86/include/asm/sev-common.h > > @@ -128,6 +128,9 @@ struct snp_psc_desc { > > struct psc_entry entries[VMGEXIT_PSC_MAX_ENTRY]; > > } __packed; > > > > +/* Guest message request error code */ > > +#define SNP_GUEST_REQ_INVALID_LEN BIT_ULL(32) > > + > > #define GHCB_MSR_TERM_REQ 0x100 > > #define GHCB_MSR_TERM_REASON_SET_POS 12 > > #define GHCB_MSR_TERM_REASON_SET_MASK 0xf > > diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h > > index 219abb4590f2..9830ee1d6ef0 100644 > > --- a/arch/x86/include/asm/sev.h > > +++ b/arch/x86/include/asm/sev.h > > @@ -87,6 +87,14 @@ extern bool handle_vc_boot_ghcb(struct pt_regs *regs); > > > > #define RMPADJUST_VMSA_PAGE_BIT BIT(16) > > > > +/* SNP Guest message request */ > > +struct snp_req_data { > > + unsigned long req_gpa; > > + unsigned long resp_gpa; > > + unsigned long data_gpa; > > + unsigned int data_npages; > > +}; > > + > > #ifdef CONFIG_AMD_MEM_ENCRYPT > > extern struct static_key_false sev_es_enable_key; > > extern void __sev_es_ist_enter(struct pt_regs *regs); > > @@ -154,6 +162,7 @@ void snp_set_memory_private(unsigned long vaddr, > unsigned int npages); > > void snp_set_wakeup_secondary_cpu(void); > > bool snp_init(struct boot_params *bp); > > void snp_abort(void); > > +int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, > unsigned long *fw_err); > > #else > > static inline void sev_es_ist_enter(struct pt_regs *regs) { } > > static inline void sev_es_ist_exit(void) { } > > @@ -173,6 +182,11 @@ static inline void snp_set_memory_private(unsigned > long vaddr, unsigned int npag > > static inline void snp_set_wakeup_secondary_cpu(void) { } > > static inline bool snp_init(struct boot_params *bp) { return false; } > > static inline void snp_abort(void) { } > > +static inline int snp_issue_guest_request(u64 exit_code, struct > snp_req_data *input, > > + unsigned long *fw_err) > > +{ > > + return -ENOTTY; > > +} > > #endif > > > > #endif > > diff --git a/arch/x86/include/uapi/asm/svm.h > b/arch/x86/include/uapi/asm/svm.h > > index 8b4c57baec52..5b8bc2b65a5e 100644 > > --- a/arch/x86/include/uapi/asm/svm.h > > +++ b/arch/x86/include/uapi/asm/svm.h > > @@ -109,6 +109,8 @@ > > #define SVM_VMGEXIT_SET_AP_JUMP_TABLE 0 > > #define SVM_VMGEXIT_GET_AP_JUMP_TABLE 1 > > #define SVM_VMGEXIT_PSC 0x80000010 > > +#define SVM_VMGEXIT_GUEST_REQUEST 0x80000011 > > +#define SVM_VMGEXIT_EXT_GUEST_REQUEST 0x80000012 > > #define SVM_VMGEXIT_AP_CREATION 0x80000013 > > #define SVM_VMGEXIT_AP_CREATE_ON_INIT 0 > > #define SVM_VMGEXIT_AP_CREATE 1 > > @@ -225,6 +227,8 @@ > > { SVM_VMGEXIT_AP_HLT_LOOP, "vmgexit_ap_hlt_loop" }, \ > > { SVM_VMGEXIT_AP_JUMP_TABLE, "vmgexit_ap_jump_table" }, \ > > { SVM_VMGEXIT_PSC, "vmgexit_page_state_change" }, \ > > + { SVM_VMGEXIT_GUEST_REQUEST, "vmgexit_guest_request" > }, \ > > + { SVM_VMGEXIT_EXT_GUEST_REQUEST, > "vmgexit_ext_guest_request" }, \ > > { SVM_VMGEXIT_AP_CREATION, "vmgexit_ap_creation" }, \ > > { SVM_VMGEXIT_HV_FEATURES, "vmgexit_hypervisor_feature" }, \ > > { SVM_EXIT_ERR, "invalid_guest_state" } > > diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c > > index cb97200bfda7..1d3ac83226fc 100644 > > --- a/arch/x86/kernel/sev.c > > +++ b/arch/x86/kernel/sev.c > > @@ -2122,3 +2122,58 @@ static int __init snp_check_cpuid_table(void) > > } > > > > arch_initcall(snp_check_cpuid_table); > > + > > +int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, > unsigned long *fw_err) > > +{ > > + struct ghcb_state state; > > + struct es_em_ctxt ctxt; > > + unsigned long flags; > > + struct ghcb *ghcb; > > + int ret; > > + > > + if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) > > + return -ENODEV; > > + > > + /* > > + * __sev_get_ghcb() needs to run with IRQs disabled because it > is using > > + * a per-CPU GHCB. > > + */ > > + local_irq_save(flags); > > + > > + ghcb = __sev_get_ghcb(&state); > > + if (!ghcb) { > > + ret = -EIO; > > + goto e_restore_irq; > > + } > > + > > + vc_ghcb_invalidate(ghcb); > > + > > + if (exit_code == SVM_VMGEXIT_EXT_GUEST_REQUEST) { > > + ghcb_set_rax(ghcb, input->data_gpa); > > + ghcb_set_rbx(ghcb, input->data_npages); > > + } > > + > > + ret = sev_es_ghcb_hv_call(ghcb, true, &ctxt, exit_code, > input->req_gpa, input->resp_gpa); > > + if (ret) > > + goto e_put; > > + > > + if (ghcb->save.sw_exit_info_2) { > > + /* Number of expected pages are returned in RBX */ > > + if (exit_code == SVM_VMGEXIT_EXT_GUEST_REQUEST && > > + ghcb->save.sw_exit_info_2 == > SNP_GUEST_REQ_INVALID_LEN) > > + input->data_npages = ghcb_get_rbx(ghcb); > > + > > + if (fw_err) > > + *fw_err = ghcb->save.sw_exit_info_2; > > In the PSP driver we've had a bit of discussion around the fw_err and > the return code and that it would be preferable to have fw_err be a > required parameter. And then we can easily make sure fw_err is always > non-zero when the return code is non-zero. Thoughts about doing the > same inside the guest? > > As per the GHCB spec, we will always have a non-zero error code. So, yes, I can drop the if() check. FYI, somehow this email did not show up on my @amd.com so I did not address it in v10. thanks --000000000000c34d4505d9519150 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Tue, Feb 1, 2022 at 2:17 PM Peter = Gonda <pgonda@google.com> wr= ote:
On Fri, Jan= 28, 2022 at 10:19 AM Brijesh Singh <brijesh.singh@amd.com> wrote:
>
> Version 2 of GHCB specification provides SNP_GUEST_REQUEST and
> SNP_EXT_GUEST_REQUEST NAE that can be used by the SNP guest to communi= cate
> with the PSP.
>
> While at it, add a snp_issue_guest_request() helper that will be used = by
> driver or other subsystem to issue the request to PSP.
>
> See SEV-SNP firmware and GHCB spec for more details.
>
> Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
> ---
>=C2=A0 arch/x86/include/asm/sev-common.h |=C2=A0 3 ++
>=C2=A0 arch/x86/include/asm/sev.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 | 14 +++++= +++
>=C2=A0 arch/x86/include/uapi/asm/svm.h=C2=A0 =C2=A0|=C2=A0 4 +++
>=C2=A0 arch/x86/kernel/sev.c=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0| 55 +++++++++++++++++++++++++++++++
>=C2=A0 4 files changed, 76 insertions(+)
>
> diff --git a/arch/x86/include/asm/sev-common.h b/arch/x86/include/asm/= sev-common.h
> index cd769984e929..442614879dad 100644
> --- a/arch/x86/include/asm/sev-common.h
> +++ b/arch/x86/include/asm/sev-common.h
> @@ -128,6 +128,9 @@ struct snp_psc_desc {
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0struct psc_entry entries[VMGEXIT_PSC_= MAX_ENTRY];
>=C2=A0 } __packed;
>
> +/* Guest message request error code */
> +#define SNP_GUEST_REQ_INVALID_LEN=C2=A0 =C2=A0 =C2=A0 BIT_ULL(32)
> +
>=C2=A0 #define GHCB_MSR_TERM_REQ=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 0x100
>=C2=A0 #define GHCB_MSR_TERM_REASON_SET_POS=C2=A0 =C2=A012
>=C2=A0 #define GHCB_MSR_TERM_REASON_SET_MASK=C2=A0 0xf
> diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h > index 219abb4590f2..9830ee1d6ef0 100644
> --- a/arch/x86/include/asm/sev.h
> +++ b/arch/x86/include/asm/sev.h
> @@ -87,6 +87,14 @@ extern bool handle_vc_boot_ghcb(struct pt_regs *reg= s);
>
>=C2=A0 #define RMPADJUST_VMSA_PAGE_BIT=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 BIT(16)
>
> +/* SNP Guest message request */
> +struct snp_req_data {
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0unsigned long req_gpa;
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0unsigned long resp_gpa;
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0unsigned long data_gpa;
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0unsigned int data_npages;
> +};
> +
>=C2=A0 #ifdef CONFIG_AMD_MEM_ENCRYPT
>=C2=A0 extern struct static_key_false sev_es_enable_key;
>=C2=A0 extern void __sev_es_ist_enter(struct pt_regs *regs);
> @@ -154,6 +162,7 @@ void snp_set_memory_private(unsigned long vaddr, u= nsigned int npages);
>=C2=A0 void snp_set_wakeup_secondary_cpu(void);
>=C2=A0 bool snp_init(struct boot_params *bp);
>=C2=A0 void snp_abort(void);
> +int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input= , unsigned long *fw_err);
>=C2=A0 #else
>=C2=A0 static inline void sev_es_ist_enter(struct pt_regs *regs) { } >=C2=A0 static inline void sev_es_ist_exit(void) { }
> @@ -173,6 +182,11 @@ static inline void snp_set_memory_private(unsigne= d long vaddr, unsigned int npag
>=C2=A0 static inline void snp_set_wakeup_secondary_cpu(void) { }
>=C2=A0 static inline bool snp_init(struct boot_params *bp) { return fal= se; }
>=C2=A0 static inline void snp_abort(void) { }
> +static inline int snp_issue_guest_request(u64 exit_code, struct snp_r= eq_data *input,
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0unsigned long *fw_err)
> +{
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0return -ENOTTY;
> +}
>=C2=A0 #endif
>
>=C2=A0 #endif
> diff --git a/arch/x86/include/uapi/asm/svm.h b/arch/x86/include/uapi/a= sm/svm.h
> index 8b4c57baec52..5b8bc2b65a5e 100644
> --- a/arch/x86/include/uapi/asm/svm.h
> +++ b/arch/x86/include/uapi/asm/svm.h
> @@ -109,6 +109,8 @@
>=C2=A0 #define SVM_VMGEXIT_SET_AP_JUMP_TABLE=C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 0
>=C2=A0 #define SVM_VMGEXIT_GET_AP_JUMP_TABLE=C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 1
>=C2=A0 #define SVM_VMGEXIT_PSC=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 0x80= 000010
> +#define SVM_VMGEXIT_GUEST_REQUEST=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 0x80000011
> +#define SVM_VMGEXIT_EXT_GUEST_REQUEST=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 0x80000012
>=C2=A0 #define SVM_VMGEXIT_AP_CREATION=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 0x80000013
>=C2=A0 #define SVM_VMGEXIT_AP_CREATE_ON_INIT=C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 0
>=C2=A0 #define SVM_VMGEXIT_AP_CREATE=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 1
> @@ -225,6 +227,8 @@
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0{ SVM_VMGEXIT_AP_HLT_LOOP,=C2=A0 =C2= =A0 =C2=A0 "vmgexit_ap_hlt_loop" }, \
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0{ SVM_VMGEXIT_AP_JUMP_TABLE,=C2=A0 = =C2=A0 "vmgexit_ap_jump_table" }, \
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0{ SVM_VMGEXIT_PSC,=C2=A0 =C2=A0 =C2= =A0 "vmgexit_page_state_change" }, \
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0{ SVM_VMGEXIT_GUEST_REQUEST,=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 "vmgexit_guest_request" }, \
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0{ SVM_VMGEXIT_EXT_GUEST_REQUEST,=C2=A0 =C2= =A0 =C2=A0 =C2=A0 "vmgexit_ext_guest_request" }, \
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0{ SVM_VMGEXIT_AP_CREATION,=C2=A0 =C2= =A0 =C2=A0 "vmgexit_ap_creation" }, \
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0{ SVM_VMGEXIT_HV_FEATURES,=C2=A0 =C2= =A0 =C2=A0 "vmgexit_hypervisor_feature" }, \
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0{ SVM_EXIT_ERR,=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0"invalid_guest_state" }
> diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c
> index cb97200bfda7..1d3ac83226fc 100644
> --- a/arch/x86/kernel/sev.c
> +++ b/arch/x86/kernel/sev.c
> @@ -2122,3 +2122,58 @@ static int __init snp_check_cpuid_table(void) >=C2=A0 }
>
>=C2=A0 arch_initcall(snp_check_cpuid_table);
> +
> +int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input= , unsigned long *fw_err)
> +{
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0struct ghcb_state state;
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0struct es_em_ctxt ctxt;
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0unsigned long flags;
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0struct ghcb *ghcb;
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0int ret;
> +
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP= ))
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return -ENODEV= ;
> +
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0/*
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 * __sev_get_ghcb() needs to run with IRQs= disabled because it is using
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 * a per-CPU GHCB.
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 */
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0local_irq_save(flags);
> +
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0ghcb =3D __sev_get_ghcb(&state);
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0if (!ghcb) {
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ret =3D -EIO;<= br> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0goto e_restore= _irq;
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0}
> +
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0vc_ghcb_invalidate(ghcb);
> +
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0if (exit_code =3D=3D SVM_VMGEXIT_EXT_GUEST= _REQUEST) {
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ghcb_set_rax(g= hcb, input->data_gpa);
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ghcb_set_rbx(g= hcb, input->data_npages);
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0}
> +
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0ret =3D sev_es_ghcb_hv_call(ghcb, true, &a= mp;ctxt, exit_code, input->req_gpa, input->resp_gpa);
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0if (ret)
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0goto e_put; > +
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0if (ghcb->save.sw_exit_info_2) {
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0/* Number of e= xpected pages are returned in RBX */
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (exit_code = =3D=3D SVM_VMGEXIT_EXT_GUEST_REQUEST &&
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= ghcb->save.sw_exit_info_2 =3D=3D SNP_GUEST_REQ_INVALID_LEN)
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0input->data_npages =3D ghcb_get_rbx(ghcb);
> +
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (fw_err) > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0*fw_err =3D ghcb->save.sw_exit_info_2;

In the PSP driver we've had a bit of discussion around the fw_err and the return code and that it would be preferable to have fw_err be a
required parameter. And then we can easily make sure fw_err is always
non-zero when the return code is non-zero. Thoughts about doing the
same inside the guest?


As per the GHCB spec, we will always h= ave a non-zero error code. So, yes, I can drop the if() check.
FYI, somehow this email did not show up on my=C2=A0@amd.com so I did not address it in v10.

=
thanks=C2=A0
--000000000000c34d4505d9519150--