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 696D5C00140 for ; Tue, 2 Aug 2022 12:40:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F337C6B0071; Tue, 2 Aug 2022 08:40:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EBB838E0001; Tue, 2 Aug 2022 08:40:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D5C456B0073; Tue, 2 Aug 2022 08:40:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C0A956B0071 for ; Tue, 2 Aug 2022 08:40:01 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 6AE40ABAE0 for ; Tue, 2 Aug 2022 12:40:01 +0000 (UTC) X-FDA: 79754609802.04.F7C9DB8 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf15.hostedemail.com (Postfix) with ESMTP id B7E7EA0101 for ; Tue, 2 Aug 2022 12:40:00 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B221EB81EF7; Tue, 2 Aug 2022 12:39:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EA5BDC433D6; Tue, 2 Aug 2022 12:39:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659443997; bh=PCR0ioV6fNZP3YUrBL59/cNasicX5SaYXfiF0EyEclg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=NQqr3uk+c9m8SmN+EpeKHs99sSRP5o4d6itRIx1sQ9JIx0GuQN0Zh7stPoohY+zo0 3PF69OpEy4klTKYs0DWgkN8uzyVg15Z9jCPwtINZX9ljfqMcBTxrDFYGNrdKAScBmu b9Yjfa66tjoqT6Ride43cu6yx0fVXlu9PZ6h8G5RKm8rF0jQKJ9cBKG6cKWXaIL7IW crcs5ni4zlwinZuKU/9i42bKlDq/67Ii6Era/B43XFJaMgwTdr50bjUPoljnk0YpaA J+OGdQHe36jFoy30fIx8dy3et4mHaQxnD+88QDJTxg27K2vokVRduOlR5UONFbgpx7 1tk4aP1uvMa3Q== Date: Tue, 2 Aug 2022 15:39:54 +0300 From: Jarkko Sakkinen To: Ashish Kalra Cc: x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-mm@kvack.org, linux-crypto@vger.kernel.org, tglx@linutronix.de, mingo@redhat.com, jroedel@suse.de, thomas.lendacky@amd.com, hpa@zytor.com, ardb@kernel.org, pbonzini@redhat.com, seanjc@google.com, vkuznets@redhat.com, jmattson@google.com, luto@kernel.org, dave.hansen@linux.intel.com, slp@redhat.com, pgonda@google.com, peterz@infradead.org, srinivas.pandruvada@linux.intel.com, rientjes@google.com, dovmurik@linux.ibm.com, tobin@ibm.com, bp@alien8.de, michael.roth@amd.com, vbabka@suse.cz, kirill@shutemov.name, ak@linux.intel.com, tony.luck@intel.com, marcorr@google.com, sathyanarayanan.kuppuswamy@linux.intel.com, alpergun@google.com, dgilbert@redhat.com Subject: Re: [PATCH Part2 v6 18/49] crypto: ccp: Provide APIs to query extended attestation report Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659444001; a=rsa-sha256; cv=none; b=p9ddK5qAkgd040bNOqJqtxyx/rAb37UFryZslPA/skD6i+IdwCPwWEzmjr0XkeHDxG92LB PFy2mgjZwn35GWqqAQ9XvhSByLrD18+t5d8r/PVT7Yke5gFx7vecJ7V6Rb8h9SerFpnzyN y4WsI04iX5IQW6P8bq1MzdkfIbzEZyM= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=NQqr3uk+; spf=pass (imf15.hostedemail.com: domain of jarkko@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=jarkko@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659444000; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=KiKCwap3bQECh28xrf/9mBlyQGPdLWzcDbwdAqHTC+o=; b=Gf5wltUbcXrohEvDbPxBwUFIX8sZ9lTxbS30Mw+aE7nnbCtqbqOnzXz1TOcM3xGA6eXLzI OgqcsDZTnYHtTv+evSyHiWPjXOuvdKJxzkmsIDuPlDvKuvlaZlKVbRaXZdbQkYKQeVIQDX MiW2HwnsGgeDZG4z1H69p3XE0w/1574= X-Stat-Signature: 5xqj6ie9jaxu5jij4drcgwzp8gcmrdjy X-Rspamd-Queue-Id: B7E7EA0101 X-Rspam-User: Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=NQqr3uk+; spf=pass (imf15.hostedemail.com: domain of jarkko@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=jarkko@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Rspamd-Server: rspam03 X-HE-Tag: 1659444000-821391 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: I'd rephrase "Provide in-kernel API..." (e.g. not uapi). On Mon, Jun 20, 2022 at 11:06:06PM +0000, Ashish Kalra wrote: > From: Brijesh Singh > > Version 2 of the GHCB specification defines VMGEXIT that is used to get > the extended attestation report. The extended attestation report includes > the certificate blobs provided through the SNP_SET_EXT_CONFIG. > > The snp_guest_ext_guest_request() will be used by the hypervisor to get > the extended attestation report. See the GHCB specification for more > details. What is "the hypersivor"? Could it be replaced with e.g. KVM for clarity? > > Signed-off-by: Brijesh Singh > --- > drivers/crypto/ccp/sev-dev.c | 43 ++++++++++++++++++++++++++++++++++++ > include/linux/psp-sev.h | 24 ++++++++++++++++++++ > 2 files changed, 67 insertions(+) > > diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c > index 97b479d5aa86..f6306b820b86 100644 > --- a/drivers/crypto/ccp/sev-dev.c > +++ b/drivers/crypto/ccp/sev-dev.c > @@ -25,6 +25,7 @@ > #include > > #include > +#include > > #include "psp-dev.h" > #include "sev-dev.h" > @@ -1857,6 +1858,48 @@ int snp_guest_dbg_decrypt(struct sev_data_snp_dbg *data, int *error) > } > EXPORT_SYMBOL_GPL(snp_guest_dbg_decrypt); > > +int snp_guest_ext_guest_request(struct sev_data_snp_guest_request *data, > + unsigned long vaddr, unsigned long *npages, unsigned long *fw_err) > +{ > + unsigned long expected_npages; > + struct sev_device *sev; > + int rc; > + > + if (!psp_master || !psp_master->sev_data) > + return -ENODEV; > + > + sev = psp_master->sev_data; > + > + if (!sev->snp_inited) > + return -EINVAL; > + > + /* > + * Check if there is enough space to copy the certificate chain. Otherwise > + * return ERROR code defined in the GHCB specification. > + */ > + expected_npages = sev->snp_certs_len >> PAGE_SHIFT; > + if (*npages < expected_npages) { > + *npages = expected_npages; > + *fw_err = SNP_GUEST_REQ_INVALID_LEN; > + return -EINVAL; > + } > + > + rc = sev_do_cmd(SEV_CMD_SNP_GUEST_REQUEST, data, (int *)&fw_err); > + if (rc) > + return rc; > + > + /* Copy the certificate blob */ > + if (sev->snp_certs_data) { > + *npages = expected_npages; > + memcpy((void *)vaddr, sev->snp_certs_data, *npages << PAGE_SHIFT); > + } else { > + *npages = 0; > + } > + > + return rc; > +} > +EXPORT_SYMBOL_GPL(snp_guest_ext_guest_request); Undocumented export. > + > static void sev_exit(struct kref *ref) > { > misc_deregister(&misc_dev->misc); > diff --git a/include/linux/psp-sev.h b/include/linux/psp-sev.h > index a3bb792bb842..cd37ccd1fa1f 100644 > --- a/include/linux/psp-sev.h > +++ b/include/linux/psp-sev.h > @@ -945,6 +945,23 @@ void *psp_copy_user_blob(u64 uaddr, u32 len); > void *snp_alloc_firmware_page(gfp_t mask); > void snp_free_firmware_page(void *addr); > > +/** > + * snp_guest_ext_guest_request - perform the SNP extended guest request command > + * defined in the GHCB specification. > + * > + * @data: the input guest request structure > + * @vaddr: address where the certificate blob need to be copied. > + * @npages: number of pages for the certificate blob. > + * If the specified page count is less than the certificate blob size, then the > + * required page count is returned with error code defined in the GHCB spec. > + * If the specified page count is more than the certificate blob size, then > + * page count is updated to reflect the amount of valid data copied in the > + * vaddr. > + */ This kdoc is misplaced: it should be in sev-dev.c, right before the implementation. Also it does not say anything about return value, and still the return type is "int". > +int snp_guest_ext_guest_request(struct sev_data_snp_guest_request *data, > + unsigned long vaddr, unsigned long *npages, > + unsigned long *error); > + > #else /* !CONFIG_CRYPTO_DEV_SP_PSP */ > > static inline int > @@ -992,6 +1009,13 @@ static inline void *snp_alloc_firmware_page(gfp_t mask) > > static inline void snp_free_firmware_page(void *addr) { } > > +static inline int snp_guest_ext_guest_request(struct sev_data_snp_guest_request *data, > + unsigned long vaddr, unsigned long *n, > + unsigned long *error) > +{ > + return -ENODEV; > +} > + > #endif /* CONFIG_CRYPTO_DEV_SP_PSP */ > > #endif /* __PSP_SEV_H__ */ > -- > 2.25.1 > BR, Jarkko