linux-coco.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Peter Gonda <pgonda@google.com>
To: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Dionna Amalie Glaze <dionnaglaze@google.com>,
	Brijesh Singh <brijesh.singh@amd.com>,
	 "the arch/x86 maintainers" <x86@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	 "open list:X86 KVM CPUs" <kvm@vger.kernel.org>,
	linux-efi <linux-efi@vger.kernel.org>,
	 platform-driver-x86@vger.kernel.org, linux-coco@lists.linux.dev,
	 Linux Memory Management List <linux-mm@kvack.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>,  Joerg Roedel <jroedel@suse.de>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Ard Biesheuvel <ardb@kernel.org>,
	 Paolo Bonzini <pbonzini@redhat.com>,
	Sean Christopherson <seanjc@google.com>,
	 Vitaly Kuznetsov <vkuznets@redhat.com>,
	Jim Mattson <jmattson@google.com>,
	 Andy Lutomirski <luto@kernel.org>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	 Sergio Lopez <slp@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	 Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>,
	David Rientjes <rientjes@google.com>,
	 Dov Murik <dovmurik@linux.ibm.com>,
	Tobin Feldman-Fitzthum <tobin@ibm.com>,
	Borislav Petkov <bp@alien8.de>,
	 Michael Roth <michael.roth@amd.com>,
	Vlastimil Babka <vbabka@suse.cz>,
	 "Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>,
	Andi Kleen <ak@linux.intel.com>,
	 "Dr . David Alan Gilbert" <dgilbert@redhat.com>,
	brijesh.ksingh@gmail.com,  Tony Luck <tony.luck@intel.com>,
	Marc Orr <marcorr@google.com>,
	 Kuppuswamy Sathyanarayanan
	<sathyanarayanan.kuppuswamy@linux.intel.com>
Subject: Re: [PATCH v12 43/46] virt: Add SEV-SNP guest driver
Date: Thu, 25 Aug 2022 14:09:26 -0600	[thread overview]
Message-ID: <CAMkAt6qBd7uoR-9NW7HbcE-N7w++3vGsviGLkhmVbnZ5TH3ZOg@mail.gmail.com> (raw)
In-Reply-To: <51298b17-9e12-7a08-7322-594deac52f53@amd.com>

On Thu, Aug 25, 2022 at 12:54 PM Tom Lendacky <thomas.lendacky@amd.com> wrote:
>
> On 8/24/22 14:28, Peter Gonda wrote:
> > On Wed, Aug 24, 2022 at 12:01 PM Dionna Amalie Glaze
> > <dionnaglaze@google.com> wrote:
> >>
> >> Apologies for the necropost, but I noticed strange behavior testing my
> >> own Golang-based wrapper around the /dev/sev-guest driver.
> >>
> >>> +
> >>> +static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, int msg_ver,
> >>> +                               u8 type, void *req_buf, size_t req_sz, void *resp_buf,
> >>> +                               u32 resp_sz, __u64 *fw_err)
> >>> +{
> >>> +       unsigned long err;
> >>> +       u64 seqno;
> >>> +       int rc;
> >>> +
> >>> +       /* Get message sequence and verify that its a non-zero */
> >>> +       seqno = snp_get_msg_seqno(snp_dev);
> >>> +       if (!seqno)
> >>> +               return -EIO;
> >>> +
> >>> +       memset(snp_dev->response, 0, sizeof(struct snp_guest_msg));
> >>> +
> >>> +       /* Encrypt the userspace provided payload */
> >>> +       rc = enc_payload(snp_dev, seqno, msg_ver, type, req_buf, req_sz);
> >>> +       if (rc)
> >>> +               return rc;
> >>> +
> >>> +       /* Call firmware to process the request */
> >>> +       rc = snp_issue_guest_request(exit_code, &snp_dev->input, &err);
> >>> +       if (fw_err)
> >>> +               *fw_err = err;
> >>> +
> >>> +       if (rc)
> >>> +               return rc;
> >>> +
> >>
> >> The fw_err is written back regardless of rc, so since err is
> >> uninitialized, you can end up with garbage written back. I've worked
> >> around this by only caring about fw_err when the result is -EIO, but
> >> thought that I should bring this up.
> >
> > I also noticed that we use a u64 in snp_guest_request_ioctl.fw_err and
> > u32 in sev_issue_cmd.error when these should be errors from the
> > sev_ret_code enum IIUC.
>
> The reason for the u64 is that the Extended Guest Request can return a
> firmware error or a hypervisor error. To distinguish between the two, a
> firmware error is contained in the lower 32-bits, while a hypervisor error
> is contained in the upper 32-bits (e.g. when not enough contiguous pages
> of memory have been supplied).

Ah, makes sense. I was trying to think of a way to codify the state
described above where we error so early in the IOCTL or call that the
PSP is never called, something like below. I think using UINT32_MAX
still works with how u64 of Extended Guest Request is spec'd. Is this
interesting to clean up the PSP driver and internal calls, and the new
sev-guest driver?

diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c
index 63dc626627a0..d1e605567d5e 100644
--- a/arch/x86/kernel/sev.c
+++ b/arch/x86/kernel/sev.c
@@ -22,6 +22,7 @@
 #include <linux/efi.h>
 #include <linux/platform_device.h>
 #include <linux/io.h>
+#include <linux/psp-sev.h>

 #include <asm/cpu_entry_area.h>
 #include <asm/stacktrace.h>
@@ -2177,6 +2178,8 @@ int snp_issue_guest_request(u64 exit_code,
struct snp_req_data *input, unsigned
        if (!fw_err)
                return -EINVAL;

+       fw_err = SEV_RET_NO_FW_CALL;
+
        /*
         * __sev_get_ghcb() needs to run with IRQs disabled because it is using
         * a per-CPU GHCB.
@@ -2209,6 +2212,8 @@ int snp_issue_guest_request(u64 exit_code,
struct snp_req_data *input, unsigned
                *fw_err = ghcb->save.sw_exit_info_2;

                ret = -EIO;
+       } else {
+               *fw_err = 0;
        }

 e_put:
diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
index 9f588c9728f8..e71d6e39aa2b 100644
--- a/drivers/crypto/ccp/sev-dev.c
+++ b/drivers/crypto/ccp/sev-dev.c
@@ -439,7 +439,7 @@ static int __sev_platform_init_locked(int *error)
 {
        struct psp_device *psp = psp_master;
        struct sev_device *sev;
-       int rc, psp_ret = -1;
+       int rc, psp_ret = SEV_RET_NO_FW_CALL;
        int (*init_function)(int *error);

        if (!psp || !psp->sev_data)
diff --git a/include/uapi/linux/psp-sev.h b/include/uapi/linux/psp-sev.h
index 91b4c63d5cbf..b8f2c129d63d 100644
--- a/include/uapi/linux/psp-sev.h
+++ b/include/uapi/linux/psp-sev.h
@@ -36,6 +36,11 @@ enum {
  * SEV Firmware status code
  */
...skipping...

 #include <asm/cpu_entry_area.h>
 #include <asm/stacktrace.h>
@@ -2177,6 +2178,8 @@ int snp_issue_guest_request(u64 exit_code,
struct snp_req_data *input, unsigned
        if (!fw_err)
                return -EINVAL;

+       fw_err = SEV_RET_NO_FW_CALL;
+
        /*
         * __sev_get_ghcb() needs to run with IRQs disabled because it is using
         * a per-CPU GHCB.
@@ -2209,6 +2212,8 @@ int snp_issue_guest_request(u64 exit_code,
struct snp_req_data *input, unsigned
                *fw_err = ghcb->save.sw_exit_info_2;

                ret = -EIO;
+       } else {
+               *fw_err = 0;
        }

 e_put:
diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
index 9f588c9728f8..e71d6e39aa2b 100644
--- a/drivers/crypto/ccp/sev-dev.c
+++ b/drivers/crypto/ccp/sev-dev.c
@@ -439,7 +439,7 @@ static int __sev_platform_init_locked(int *error)
 {
        struct psp_device *psp = psp_master;
        struct sev_device *sev;
-       int rc, psp_ret = -1;
+       int rc, psp_ret = SEV_RET_NO_FW_CALL;
        int (*init_function)(int *error);

        if (!psp || !psp->sev_data)
diff --git a/include/uapi/linux/psp-sev.h b/include/uapi/linux/psp-sev.h
index 91b4c63d5cbf..b8f2c129d63d 100644
--- a/include/uapi/linux/psp-sev.h
+++ b/include/uapi/linux/psp-sev.h
@@ -36,6 +36,11 @@ enum {
  * SEV Firmware status code
  */
 typedef enum {
+       /*
+        * This error code is not in the SEV spec but is added to convey that
+        * there was an error that prevented the SEV Firmware from being called.
+        */
+       SEV_RET_NO_FW_CALL = -1,
        SEV_RET_SUCCESS = 0,
        SEV_RET_INVALID_PLATFORM_STATE,
        SEV_RET_INVALID_GUEST_STATE,




> >
> >>
> >> --
> >> -Dionna Glaze, PhD (she/her)

  reply	other threads:[~2022-08-25 20:09 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-07 21:33 [PATCH v12 00/46] Add AMD Secure Nested Paging (SEV-SNP) Guest Support Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 01/46] KVM: SVM: Define sev_features and vmpl field in the VMSA Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 02/46] KVM: SVM: Create a separate mapping for the SEV-ES save area Brijesh Singh
2022-04-05 18:27   ` [PATCH v12 2.1/46] " Brijesh Singh
2022-04-05 18:55     ` Borislav Petkov
2022-03-07 21:33 ` [PATCH v12 03/46] KVM: SVM: Create a separate mapping for the GHCB " Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 04/46] KVM: SVM: Update the SEV-ES save area mapping Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 05/46] x86/boot: Introduce helpers for MSR reads/writes Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 06/46] x86/boot: Use MSR read/write helpers instead of inline assembly Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 07/46] x86/compressed/64: Detect/setup SEV/SME features earlier in boot Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 08/46] x86/sev: " Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 09/46] x86/mm: Extend cc_attr to include AMD SEV-SNP Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 10/46] x86/sev: Define the Linux specific guest termination reasons Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 11/46] x86/sev: Save the negotiated GHCB version Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 12/46] x86/sev: Check SEV-SNP features support Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 13/46] x86/sev: Add a helper for the PVALIDATE instruction Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 14/46] x86/sev: Check the vmpl level Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 15/46] x86/compressed: Add helper for validating pages in the decompression stage Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 16/46] x86/compressed: Register GHCB memory when SEV-SNP is active Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 17/46] x86/sev: " Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 18/46] x86/sev: Add helper for validating pages in early enc attribute changes Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 19/46] x86/kernel: Make the .bss..decrypted section shared in RMP table Brijesh Singh
2022-06-14  0:46   ` Sean Christopherson
2022-06-14 15:43     ` Sean Christopherson
2022-06-14 16:01       ` Tom Lendacky
2022-06-14 16:13         ` Sean Christopherson
2022-06-14 19:00           ` Tom Lendacky
2022-06-14 19:52             ` Sean Christopherson
2022-06-16 16:17               ` Tom Lendacky
2022-06-16 16:41                 ` Sean Christopherson
2022-07-01 16:51                   ` Borislav Petkov
2022-07-07 20:43                     ` Sean Christopherson
2022-03-07 21:33 ` [PATCH v12 20/46] x86/kernel: Validate ROM memory before accessing when SEV-SNP is active Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 21/46] x86/mm: Validate memory when changing the C-bit Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 22/46] x86/sev: Use SEV-SNP AP creation to start secondary CPUs Brijesh Singh
2022-04-05  0:24   ` Sean Christopherson
2022-04-05 16:20     ` Brijesh Singh
2022-04-05 19:41       ` Sean Christopherson
2022-03-07 21:33 ` [PATCH v12 23/46] x86/head/64: Re-enable stack protection Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 24/46] x86/compressed/acpi: Move EFI detection to helper Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 25/46] x86/compressed/acpi: Move EFI system table lookup " Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 26/46] x86/compressed/acpi: Move EFI config " Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 27/46] x86/compressed/acpi: Move EFI vendor " Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 28/46] x86/compressed/acpi: Move EFI kexec handling into common code Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 29/46] x86/boot: Add Confidential Computing type to setup_data Brijesh Singh
2022-04-06 21:19   ` Thomas Gleixner
2022-04-07 14:47     ` Borislav Petkov
2022-04-07 14:57     ` Brijesh Singh
2022-07-17  5:08       ` H. Peter Anvin
2022-03-07 21:33 ` [PATCH v12 30/46] KVM: x86: Move lookup of indexed CPUID leafs to helper Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 31/46] x86/sev: Move MSR-based VMGEXITs for CPUID " Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 32/46] x86/compressed/64: Add support for SEV-SNP CPUID table in #VC handlers Brijesh Singh
2022-03-10 14:51   ` Peter Gonda
2022-03-10 21:25     ` Michael Roth
2022-03-11 17:06       ` Joerg Roedel
2022-03-14 17:34         ` Peter Gonda
2022-03-17 13:11           ` Boris Petkov
2022-03-17 20:20             ` Peter Gonda
2022-03-07 21:33 ` [PATCH v12 33/46] x86/boot: Add a pointer to Confidential Computing blob in bootparams Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 34/46] x86/compressed: Add SEV-SNP feature detection/setup Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 35/46] x86/compressed: Use firmware-validated CPUID leaves for SEV-SNP guests Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 36/46] x86/compressed: Export and rename add_identity_map() Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 37/46] x86/compressed/64: Add identity mapping for Confidential Computing blob Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 38/46] x86/sev: Add SEV-SNP feature detection/setup Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 39/46] x86/sev: Use firmware-validated CPUID for SEV-SNP guests Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 40/46] x86/sev: add sev=debug cmdline option to dump SNP CPUID table Brijesh Singh
2022-03-25  9:24   ` Borislav Petkov
2022-03-07 21:33 ` [PATCH v12 41/46] x86/sev: Provide support for SNP guest request NAEs Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 42/46] x86/sev: Register SEV-SNP guest request platform device Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 43/46] virt: Add SEV-SNP guest driver Brijesh Singh
2022-08-24 18:01   ` Dionna Amalie Glaze
2022-08-24 19:28     ` Peter Gonda
2022-08-25 18:54       ` Tom Lendacky
2022-08-25 20:09         ` Peter Gonda [this message]
2022-03-07 21:33 ` [PATCH v12 44/46] virt: sevguest: Add support to derive key Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 45/46] virt: sevguest: Add support to get extended report Brijesh Singh
2022-03-07 21:33 ` [PATCH v12 46/46] virt: sevguest: Add documentation for SEV-SNP CPUID Enforcement Brijesh Singh
2022-03-14 15:37   ` Peter Gonda
2022-03-07 21:53 ` [PATCH v12 43.1/46] virt: Add SEV-SNP guest driver Brijesh Singh

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=CAMkAt6qBd7uoR-9NW7HbcE-N7w++3vGsviGLkhmVbnZ5TH3ZOg@mail.gmail.com \
    --to=pgonda@google.com \
    --cc=ak@linux.intel.com \
    --cc=ardb@kernel.org \
    --cc=bp@alien8.de \
    --cc=brijesh.ksingh@gmail.com \
    --cc=brijesh.singh@amd.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=dgilbert@redhat.com \
    --cc=dionnaglaze@google.com \
    --cc=dovmurik@linux.ibm.com \
    --cc=hpa@zytor.com \
    --cc=jmattson@google.com \
    --cc=jroedel@suse.de \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-coco@lists.linux.dev \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=luto@kernel.org \
    --cc=marcorr@google.com \
    --cc=michael.roth@amd.com \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=rientjes@google.com \
    --cc=sathyanarayanan.kuppuswamy@linux.intel.com \
    --cc=seanjc@google.com \
    --cc=slp@redhat.com \
    --cc=srinivas.pandruvada@linux.intel.com \
    --cc=tglx@linutronix.de \
    --cc=thomas.lendacky@amd.com \
    --cc=tobin@ibm.com \
    --cc=tony.luck@intel.com \
    --cc=vbabka@suse.cz \
    --cc=vkuznets@redhat.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).