Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp1087409pxb; Thu, 9 Sep 2021 20:18:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybCvzLIKy3AK32kr7KPLue7Jqho5YIKoimdEIouktwN5JTvor/Wso5GD1fo/fbC8LPJHVM X-Received: by 2002:a02:ad19:: with SMTP id s25mr2667307jan.17.1631243920256; Thu, 09 Sep 2021 20:18:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631243920; cv=none; d=google.com; s=arc-20160816; b=NJO2YGMk0F6xx+FQsaPWNJrJQvSnsSPOr7oPCQhM7elTO2AESuW9dfIVp8/7odD2/o tuOB6f5kDACqMX3tLMbPQE30oHP9mGN/lIVmi5aGkZvAg+/wmP6Lxmv0neFYKXXy+AcJ KoSniaX924ZlNlHl+RDyV7C/ExAsl2ImBBxtr9Zzgm/Obk1N3/eORdCfIVXWqwL8R7nn nam1GrxjkodHrd62WG8b0I/yIBztwhH5CO/iulHqlKty7dWrV9piYEPgAlIoNO2Nk8kR mfbfrtoFD42bo5h94AXFrDurDDwHMXMHo6m7frL10is2IbZ5mXbGJZMJjRkUcwX58hVL GQUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=qCAr61hpoK6IKG40PpJaKVqIxCQSvqZ6i3qbQqvhygc=; b=enubePBzYyIrdsSZKER+fWUcv/ytHbaSY/L87OX1Niv+7MZg6C+Ye46sRBAC1xcmdm MRkT69UA/YCG20U9Z16vPYBTJvn8Y3xYPqv2MEkJiAQIu0vComOwKNxwJNihOjNTimpf 0Y6dtv2GcCrc4PWRXijecgFAX77A7YL/y/O97kwDBExrJnmODlUW0Vf8iUErkRLsHFWP lETV48xi+66mNt4piTFdgij7sMane0efN/V5CqvvKAwdntLJnzvy+8bi9xPRsrLuaj1m I0iyySdcJsIUGFtV2n023U53np3DDXyylPX+IVoRkijvH7MdvsvgIep1mRnI6Ywq81eL Fltg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=XjDL0OYY; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c1si3427985jaa.58.2021.09.09.20.18.16; Thu, 09 Sep 2021 20:18:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=XjDL0OYY; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230001AbhIJDTW (ORCPT + 99 others); Thu, 9 Sep 2021 23:19:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229993AbhIJDTW (ORCPT ); Thu, 9 Sep 2021 23:19:22 -0400 Received: from mail-ot1-x32b.google.com (mail-ot1-x32b.google.com [IPv6:2607:f8b0:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 474A2C061756 for ; Thu, 9 Sep 2021 20:18:12 -0700 (PDT) Received: by mail-ot1-x32b.google.com with SMTP id l7-20020a0568302b0700b0051c0181deebso422649otv.12 for ; Thu, 09 Sep 2021 20:18:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=qCAr61hpoK6IKG40PpJaKVqIxCQSvqZ6i3qbQqvhygc=; b=XjDL0OYY74Mq3fMUE3D498DEIpvbWZvfPnUKICeBvPjA69xmSRNlHfBckOLkxZJMwq NPjAT1OcacqQuwHsHeUU7ksBviqq06IGCsnQK/0uiY1weBqIzL9NRvGWjgPKazFjFdLg NiS2ExZJlPA2Y6/tj9EvzDAmNW5u/fu7OcEhvZvtiOe1TtV2dY4lYCrVBIZsrefEiRN2 h+jRjJA7x//dnjRmX5Xf2vwKNo7wwAqcXO5R2gLkEeyggnEclaNduCo3n8zLy+3An3HZ ZkGrwHWqoKQt7DpLVZc5jOU3SJa6n07Cmmlw0Ez1N0kU8AvFREm9u372nF2GzPUyRtcC /Yyg== 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=qCAr61hpoK6IKG40PpJaKVqIxCQSvqZ6i3qbQqvhygc=; b=NL+S7mZR4Ao68jb75y+tzLETijyw3+7/ljtTdNruwCqKgcZ3tgbymPxowUomMOlnRa wucUoOjub9xjD9Ap6eQzU7G+B3sZdkvHGjFnXHjEwsC7jcuwEJods4jN4SQme2T7pRkN Mdr+CpEpFMeHxFuNLynyuRVvW2HRODf47SvYOSrQFJLWQbyhUiHdOH04xwvlH7nKJ+vs 9hq1RbBgxFXBPdjK32E1NYhxhWvb2kr1coZhJpmoz2uH6sKBHllE1OO45ozAIpf47oxs ItcwvHZRhPEZkiQuE7hSXjMGPyFMKT+Twb54Pr5LvqApHb2BuHx0l2WtrtX8XDDNn9jv 9uYQ== X-Gm-Message-State: AOAM531ycRr6XYpgYuwHcLYrfTLc4BP20WACItcCzCha57KcBDCVMWE0 OP5C3HS465SKz7sCBOaapgkJ63JPxPgaij18WrVstuwdhv5GPw== X-Received: by 2002:a05:6830:349c:: with SMTP id c28mr2849513otu.35.1631243891225; Thu, 09 Sep 2021 20:18:11 -0700 (PDT) MIME-Version: 1.0 References: <20210820155918.7518-1-brijesh.singh@amd.com> <20210820155918.7518-17-brijesh.singh@amd.com> In-Reply-To: <20210820155918.7518-17-brijesh.singh@amd.com> From: Marc Orr Date: Thu, 9 Sep 2021 20:18:00 -0700 Message-ID: Subject: Re: [PATCH Part2 v5 16/45] crypto: ccp: Add the SNP_PLATFORM_STATUS command To: Brijesh Singh Cc: x86 , LKML , kvm list , linux-coco@lists.linux.dev, linux-mm@kvack.org, linux-crypto@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Joerg Roedel , Tom Lendacky , "H. Peter Anvin" , Ard Biesheuvel , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Andy Lutomirski , Dave Hansen , Sergio Lopez , Peter Gonda , Peter Zijlstra , Srinivas Pandruvada , David Rientjes , Dov Murik , Tobin Feldman-Fitzthum , Borislav Petkov , Michael Roth , Vlastimil Babka , "Kirill A . Shutemov" , Andi Kleen , tony.luck@intel.com, sathyanarayanan.kuppuswamy@linux.intel.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Fri, Aug 20, 2021 at 9:00 AM Brijesh Singh wrote: > > The command can be used by the userspace to query the SNP platform status > report. See the SEV-SNP spec for more details. > > Signed-off-by: Brijesh Singh > --- > Documentation/virt/coco/sevguest.rst | 27 +++++++++++++++++ > drivers/crypto/ccp/sev-dev.c | 45 ++++++++++++++++++++++++++++ > include/uapi/linux/psp-sev.h | 1 + > 3 files changed, 73 insertions(+) > > diff --git a/Documentation/virt/coco/sevguest.rst b/Documentation/virt/coco/sevguest.rst > index 7acb8696fca4..7c51da010039 100644 > --- a/Documentation/virt/coco/sevguest.rst > +++ b/Documentation/virt/coco/sevguest.rst > @@ -52,6 +52,22 @@ to execute due to the firmware error, then fw_err code will be set. > __u64 fw_err; > }; > > +The host ioctl should be called to /dev/sev device. The ioctl accepts command > +id and command input structure. > + > +:: > + struct sev_issue_cmd { > + /* Command ID */ > + __u32 cmd; > + > + /* Command request structure */ > + __u64 data; > + > + /* firmware error code on failure (see psp-sev.h) */ > + __u32 error; > + }; > + > + > 2.1 SNP_GET_REPORT > ------------------ > > @@ -107,3 +123,14 @@ length of the blob is lesser than expected then snp_ext_report_req.certs_len wil > be updated with the expected value. > > See GHCB specification for further detail on how to parse the certificate blob. > + > +2.3 SNP_PLATFORM_STATUS > +----------------------- > +:Technology: sev-snp > +:Type: hypervisor ioctl cmd > +:Parameters (in): struct sev_data_snp_platform_status > +:Returns (out): 0 on success, -negative on error > + > +The SNP_PLATFORM_STATUS command is used to query the SNP platform status. The > +status includes API major, minor version and more. See the SEV-SNP > +specification for further details. > diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c > index 4cd7d803a624..16c6df5d412c 100644 > --- a/drivers/crypto/ccp/sev-dev.c > +++ b/drivers/crypto/ccp/sev-dev.c > @@ -1394,6 +1394,48 @@ static int sev_ioctl_do_pdh_export(struct sev_issue_cmd *argp, bool writable) > return ret; > } > > +static int sev_ioctl_snp_platform_status(struct sev_issue_cmd *argp) > +{ > + struct sev_device *sev = psp_master->sev_data; > + struct sev_data_snp_platform_status_buf buf; > + struct page *status_page; > + void *data; > + int ret; > + > + if (!sev->snp_inited || !argp->data) > + return -EINVAL; > + > + status_page = alloc_page(GFP_KERNEL_ACCOUNT); > + if (!status_page) > + return -ENOMEM; > + > + data = page_address(status_page); > + if (snp_set_rmp_state(__pa(data), 1, true, true, false)) { > + __free_pages(status_page, 0); > + return -EFAULT; > + } > + > + buf.status_paddr = __psp_pa(data); > + ret = __sev_do_cmd_locked(SEV_CMD_SNP_PLATFORM_STATUS, &buf, &argp->error); > + > + /* Change the page state before accessing it */ > + if (snp_set_rmp_state(__pa(data), 1, false, true, true)) { > + snp_leak_pages(__pa(data) >> PAGE_SHIFT, 1); Calling `snp_leak_pages()` here seems wrong, because `snp_set_rmp_state()` calls `snp_leak_pages()` when it returns an error. > + return -EFAULT; > + } > + > + if (ret) > + goto cleanup; > + > + if (copy_to_user((void __user *)argp->data, data, > + sizeof(struct sev_user_data_snp_status))) > + ret = -EFAULT; > + > +cleanup: > + __free_pages(status_page, 0); > + return ret; > +} > + > static long sev_ioctl(struct file *file, unsigned int ioctl, unsigned long arg) > { > void __user *argp = (void __user *)arg; > @@ -1445,6 +1487,9 @@ static long sev_ioctl(struct file *file, unsigned int ioctl, unsigned long arg) > case SEV_GET_ID2: > ret = sev_ioctl_do_get_id2(&input); > break; > + case SNP_PLATFORM_STATUS: > + ret = sev_ioctl_snp_platform_status(&input); > + break; > default: > ret = -EINVAL; > goto out; > diff --git a/include/uapi/linux/psp-sev.h b/include/uapi/linux/psp-sev.h > index bed65a891223..ffd60e8b0a31 100644 > --- a/include/uapi/linux/psp-sev.h > +++ b/include/uapi/linux/psp-sev.h > @@ -28,6 +28,7 @@ enum { > SEV_PEK_CERT_IMPORT, > SEV_GET_ID, /* This command is deprecated, use SEV_GET_ID2 */ > SEV_GET_ID2, > + SNP_PLATFORM_STATUS, > > SEV_MAX, > }; > -- > 2.17.1 > >