From patchwork Mon Feb 20 18:38:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13146902 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 4B4B6C27C7C for ; Mon, 20 Feb 2023 18:50:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DBE9C6B0071; Mon, 20 Feb 2023 13:50:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D464F6B0074; Mon, 20 Feb 2023 13:50:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B991D6B0075; Mon, 20 Feb 2023 13:50:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id A341E6B0071 for ; Mon, 20 Feb 2023 13:50:38 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 7D0E8C0570 for ; Mon, 20 Feb 2023 18:50:38 +0000 (UTC) X-FDA: 80488561356.02.281FD71 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2045.outbound.protection.outlook.com [40.107.223.45]) by imf18.hostedemail.com (Postfix) with ESMTP id 836D81C0009 for ; Mon, 20 Feb 2023 18:50:35 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=nToGGUcr; spf=pass (imf18.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.223.45 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676919035; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=VjpNkINyZyAw+Ocb5Ohq8zU+vpUdm3APUpg0cCkBwOo=; b=gESQrH7UyBepiOpthi7sZdvy1y1Fnisx0R3K2zu5+MWlHnj1F/oyicYKvoSUk6AgOxotMi WoqACsQzgu5i9af14BW8IxQmTevSrSGFElrTp2OALGC/d38y3E5CBN5eQPrLJcBGiphwhG m1veNYxQvhgdXK7CKrtn0lEbQcyiLSw= ARC-Authentication-Results: i=2; imf18.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=nToGGUcr; spf=pass (imf18.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.223.45 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1676919035; a=rsa-sha256; cv=pass; b=w/OOt5DhK0hLDoUN+Jlliyc8gFHUf9CrmHLrgyJSSGA45F2fLiPCW8JiNWDuL1FSNDNLKI 6LSWv27249PA16BMreiTYQTCUZJTs65tIiqZxiMfwKhT9qv02AJMiPLksQW7yU8mSxwncN XtVYOoWTKd5ubSvv6A75Ct79LRqBXcU= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IzfNFo0skAl9ryEW7VmRogVluaIfIX3HMt2YCg1/A+NiP11xkya6o4d0rT11Wf3l8inBnhoooMl1Kb8cxbvX6r0Iyn3VhkOnER6jGxXaGwkYp4Nf+JGvpjaB5faTuhPkHdbH687uTgOh3IwllKCcCnFMpO9PXLGWatnR6cUdm5Oyb4NStyxzfGSCXADCtJdBKfjC257tXGGVyoaqkx8Km9LCNKEHWAKM1Bm21pG2M9RpznggoWJrcL8X2CcOB1760lPuvtGk8GHzLft2kaeoz1AuNEXcu1Xdk5CguB2dOWpZsK/jCYjBm2yLEE0BKw4wAipirxesLJCm8KwO5BzkCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=VjpNkINyZyAw+Ocb5Ohq8zU+vpUdm3APUpg0cCkBwOo=; b=GT6TLuRyYXmDWuzKsB/W/LgVm5U6c37sx6xZD4H9ZqhnoJmpAKjexICdf+G2axA7HX43auEa0TJSgrIlAZnR97p9t7/WibYobGyWFehRLISe+uwg5IpfZg5N5osiT1etnLL0dQm3zRiV/MGv4m4fvPmY/u0DZMMoyedZA1KtMxifbaBmvv5GCJJA3G5RVq9l4Nk2gIf1LruNfzX39qm5KoL5fUDEl2zBg9QJkqWBaGOZz5WLYez9D082vd37d9yThC1T3L1Y1fF2gDtXgP7TtSs1O9M75bQo0lNhJ0CcQfSFebjbTFRuYCWRYxsk3hY+mlaT13MsCrruhW7buRO7Ug== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VjpNkINyZyAw+Ocb5Ohq8zU+vpUdm3APUpg0cCkBwOo=; b=nToGGUcrYxj4uc5JaTMuXWlwsnhb2vFuB1n7M7H8YrVdt2hguh4HkO0SQyK936Evd204wXOnUpgWBIG9q8ZESlFHntc6JLh8gI6Gn/MPxA7bKM97eGwXKNejN0cUYdNqXnNkNo6ply7zZFgN0rb1ANhNbMcoa+VqtVmfJ9n6oN4= Received: from DS7PR03CA0140.namprd03.prod.outlook.com (2603:10b6:5:3b4::25) by SJ1PR12MB6362.namprd12.prod.outlook.com (2603:10b6:a03:454::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6111.19; Mon, 20 Feb 2023 18:50:32 +0000 Received: from DM6NAM11FT037.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3b4:cafe::a6) by DS7PR03CA0140.outlook.office365.com (2603:10b6:5:3b4::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6111.19 via Frontend Transport; Mon, 20 Feb 2023 18:50:32 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT037.mail.protection.outlook.com (10.13.172.122) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6111.19 via Frontend Transport; Mon, 20 Feb 2023 18:50:32 +0000 Received: from localhost (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Mon, 20 Feb 2023 12:50:31 -0600 From: Michael Roth To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Brijesh Singh Subject: [PATCH RFC v8 28/56] crypto: ccp: Provide APIs to query extended attestation report Date: Mon, 20 Feb 2023 12:38:19 -0600 Message-ID: <20230220183847.59159-29-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230220183847.59159-1-michael.roth@amd.com> References: <20230220183847.59159-1-michael.roth@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT037:EE_|SJ1PR12MB6362:EE_ X-MS-Office365-Filtering-Correlation-Id: f23e4168-cfca-4023-1009-08db1373583e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oPlKutr988IhZ/sgWNcgrSwNoZX1IDwAm8zzME/FIAexsxr8JqaTEgFeUrul11rn/Q88NVgwUnnLJ9Sjt+2AxJOY3rM/J1OHVBx8PMlA/wCeA3bAld63buhMKj2FDeyakQenN6eHsX3MqWNZX6EjeQXGFdv1qyasrpVXKh6iVBuiHpnSaL3On3gf/36iuoC470bVSbdStAP5PR7pAJq56+YloOCanEElybqTuggYOL+yva5CbASXTRJ1fYg78chL02c3rPqG2+hsZE1izg8pfHxkmTWOCs2gDx5Te8LMYpbipRPLdvDKSGaFElzjNkguslBq8gL4KdzYNlW/kBKL5YA/Q9ECBDF5loA+xLSL2SApwGKFbeNVEM7oyxeOQoSmRODc4UzEpjK8ismJWoiEVrYVfvGI8QSy5jgWWvCe5N9z6zzi7Z8N5WQIBwE+E20Xm53j1jCgi2eLzEn4wgsSzsr6QPBn3FgXNlifKz9AAQuBEBThaE2Ul7B1v47R/xy45vKvOAjO2mMVULlp7prrB37NW7mEDl7/gs5qJ9AluRW60Ef5GWvdJLg+NQ021StUYn43gZjusP5KGE6Qffq1k47jrdDEHdKrxfNDL5Y++3Qv94e/LJKGXyHNQHguKm6RfokflEbrBPaXVpIRtYZl4xBMc4jWYe2o0tJAA+E2VkYxU1KE9ZLU/+GtvTAeNTSSwB5WlV6vzhX3FCwUpLRuj56Tu4YemQTS+lDgNtDsDLHMYMQxdKkDbHfKCf3ngSDPf8UbDWoKJU9xcJ+aPoYwcA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230025)(4636009)(376002)(346002)(136003)(39860400002)(396003)(451199018)(36840700001)(46966006)(40470700004)(6916009)(83380400001)(36756003)(40460700003)(86362001)(36860700001)(8936002)(5660300002)(7416002)(7406005)(81166007)(426003)(356005)(47076005)(82740400003)(82310400005)(40480700001)(2906002)(478600001)(336012)(2616005)(70586007)(26005)(1076003)(4326008)(6666004)(44832011)(8676002)(54906003)(16526019)(316002)(70206006)(186003)(41300700001)(36900700001)(134885004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Feb 2023 18:50:32.4905 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f23e4168-cfca-4023-1009-08db1373583e X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT037.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6362 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 836D81C0009 X-Stat-Signature: ntqaejb9j11kj8ja97nhy6cxiukky1c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aIbfRZrDJewEtM+emJilgY99rGm6W4Sc7mrf+eWIOdyTPGEZB3+LuMtd8tWMfFqInYc6dR4B1PXbdYY/ecEJuHYpga9rpT9EYxFMEzKt0+Iyq2kD2ykLD0ueH7zZP2t9pNpcWWamJOkz6DxvUTO4W088Y1sytihIIYTVmTVwr2+ZeIDi/0RNekSBX1qMoOqMKzA+woXdlRx9i+n0Ix9vQ7gxGpaUPiJGqAJGgBg8RZAm9J4K7eQCUqU86eoT2KZlw/46il0FnC9oyKO695PsjTE= 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: 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. Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra Signed-off-by: Michael Roth --- drivers/crypto/ccp/sev-dev.c | 47 ++++++++++++++++++++++++++++++++++++ include/linux/psp-sev.h | 33 +++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index b56b00ca2cd4..e65563bc8298 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -2017,6 +2017,53 @@ int sev_guest_df_flush(int *error) } EXPORT_SYMBOL_GPL(sev_guest_df_flush); +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_initialized) + return -EINVAL; + + mutex_lock(&sev->snp_certs_lock); + /* + * 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; + mutex_unlock(&sev->snp_certs_lock); + return -EINVAL; + } + + rc = sev_do_cmd(SEV_CMD_SNP_GUEST_REQUEST, data, (int *)fw_err); + if (rc) { + mutex_unlock(&sev->snp_certs_lock); + 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; + } + + mutex_unlock(&sev->snp_certs_lock); + return rc; +} +EXPORT_SYMBOL_GPL(snp_guest_ext_guest_request); + 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 d19744807471..81bafc049eca 100644 --- a/include/linux/psp-sev.h +++ b/include/linux/psp-sev.h @@ -931,6 +931,32 @@ void snp_free_firmware_page(void *addr); */ void snp_mark_pages_offline(unsigned long pfn, unsigned int npages); +/** + * 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. + * + * @sev_ret: sev command return code + * + * Returns: + * 0 if the sev successfully processed the command + * -%ENODEV if the sev device is not available + * -%ENOTSUPP if the sev does not support SEV + * -%ETIMEDOUT if the sev command timed out + * -%EIO if the sev returned a non-zero return code + */ +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 @@ -968,6 +994,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__ */