From patchwork Mon Oct 16 13:28:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13423392 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 03DA4CDB465 for ; Mon, 16 Oct 2023 13:46:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 98A2D8D0099; Mon, 16 Oct 2023 09:46:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9133C8D0001; Mon, 16 Oct 2023 09:46:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 766388D0099; Mon, 16 Oct 2023 09:46:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 622B48D0001 for ; Mon, 16 Oct 2023 09:46:48 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 2F6218091A for ; Mon, 16 Oct 2023 13:46:48 +0000 (UTC) X-FDA: 81351450096.03.69E3515 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2053.outbound.protection.outlook.com [40.107.237.53]) by imf15.hostedemail.com (Postfix) with ESMTP id 25086A0025 for ; Mon, 16 Oct 2023 13:46:44 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=14GEXMts; spf=pass (imf15.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.237.53 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=1697464005; 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=gFsydmQ2ndIxaav3q1fno1Hd8BL8fOrNy6ngmAARfqs=; b=q04ompRYr7DsM+JYj2Jule/svIa5vik84grDtQXnO5mnb8PT2awb9U4FlgHnOJjILmggvP VFDa4sBfJmVoHT7mGNOn/126CN+jlI1q5tCw7tp3OJwR34P8XJT+k8jEupFD2OcLR/3dsB 0lEZcDbxgFZ6RToAdY55qbSFrL6mTRY= ARC-Authentication-Results: i=2; imf15.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=14GEXMts; spf=pass (imf15.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.237.53 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=1697464005; a=rsa-sha256; cv=pass; b=cVH7yS3SgTZWI2FTjedhQj27n66DPnJ5gELGT4W8d5GLilWjCrkw+fqFphoOIRnJl3zVAd E1uvDDbYCOkK/M419Q5befcAEJTnW60XqWRALGlEryFrlvq2knuJPQ3FDJIr/U66cuhroQ m15gUr2KGnVCBv2w/ecca6bO9g2iFR4= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KOU3daugj8XRNXFPoBPtolhTof8P1FpFLXaOaIOlqkltQjGJtpeXH/y95/QmjHnVvKwwcMtdpQQ1DZMNYgrxIrhiU5pnqpNUOn+tjDNMddeAj1uq8eO2dvR6gDJlfGkRES7DD4nkuKaFLZtjza1wBVpACCqGuqDwt24PveZcBB8hJyAhlkhz5TebZxIt7t/MAkp+Cy6Uw3kD7ooCLqcdm5TF/22GwfYThPqqY+Edck1Sp3gl9KBRuifjVHm3xKk/mzWZo2DEKLX9fFQ54F/QG60FwYV5OPa44G/NJdR/ojgh/nL7G1jN024dultKoV1j+RPZcP/JsceS8pBMOJ11wA== 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=gFsydmQ2ndIxaav3q1fno1Hd8BL8fOrNy6ngmAARfqs=; b=h/G7zvK8Z/7zxHS8ViV9ee8D0w2zaPcQu2p7pYajBoH8XduG+l4uo+0NuYW0SoOTALjS7pQqX79KnMEDIY3PEZhb+0OWRR6bZt7G2TCrdYz3lnBxYNwFiPnBNXXMqlr+aA+IAm+K6oEgz0/Q2jGx31PLD0zQT8S0vkxpHjpLdfTddNfswHwm+2fREzGYmfUNppzfp3TThtusmDkIQ0BZHhYwRQmbyS+W56fufv1L2f3zIcOXn7lnRFcV298VGRrJ5x3XYLsJ1/DepmMcmJ47kiuu4OOAIa3JW+x4c6QUUHZcac8vp64GYYgMktDZoUfySh7MM1ECZF07hY8cTfo7Jw== 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=gFsydmQ2ndIxaav3q1fno1Hd8BL8fOrNy6ngmAARfqs=; b=14GEXMtsH5QmXB2g0s7FuOMOmVfyUksRtmEVicYm4//oqH2HZa+bj73D93YnWHcuMFUh4kX8AtaNtGJ3BN5a5n+xxMCoBwrgFEpddirlpRDYF/IF4/WM0XAz+GWgjzHZNoIC7UUSZltqdIs0vgfE8k1J3DAWFPuANsU0cBdL8Zg= Received: from BL0PR0102CA0040.prod.exchangelabs.com (2603:10b6:208:25::17) by CH2PR12MB4277.namprd12.prod.outlook.com (2603:10b6:610:ae::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.38; Mon, 16 Oct 2023 13:46:42 +0000 Received: from MN1PEPF0000F0DE.namprd04.prod.outlook.com (2603:10b6:208:25:cafe::41) by BL0PR0102CA0040.outlook.office365.com (2603:10b6:208:25::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.35 via Frontend Transport; Mon, 16 Oct 2023 13:46:42 +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 MN1PEPF0000F0DE.mail.protection.outlook.com (10.167.242.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.22 via Frontend Transport; Mon, 16 Oct 2023 13:46:42 +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.2507.27; Mon, 16 Oct 2023 08:46:40 -0500 From: Michael Roth To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Dionna Glaze , Tom Lendacky , Alexey Kardashevskiy Subject: [PATCH v10 47/50] x86/sev: Add KVM commands for per-instance certs Date: Mon, 16 Oct 2023 08:28:16 -0500 Message-ID: <20231016132819.1002933-48-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231016132819.1002933-1-michael.roth@amd.com> References: <20231016132819.1002933-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: MN1PEPF0000F0DE:EE_|CH2PR12MB4277:EE_ X-MS-Office365-Filtering-Correlation-Id: 8af17115-3d52-4395-7621-08dbce4e545e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HjRabIGdfB09RwFhe3AypUM+MK4q+DULofbUxycVT463BRTUuY8DSrNE99rtkyWrB3XXdmGbeT4IbDVKUHzCAv/EFB/23eterJbUFRWeX63aQCHmMCz+WcYvX0YSsUnL0//cq2QzGMVKeAijRbWUXCWdYjYYvBXgQRYghx9+TXZWppgpEpDraAhAgrhg/zDX2iifSDTAfx9z0HkFawOLHZrqMy9O7dNc9rop+XZeoe91qSWdg95wFf68E9qY66CwTct4XmYe9fh/sU4m2UlFVUAs+1w23d4b3ah+1A8lKZLeyNGWMNFgwwJ8TqRQh4v584oc6ZDwRjTufVfXu63CVvQSmyhFW2CBAR9iYjekHhpCVwQFl7HIvUhLNNjLZ8ElyMhsPLwIPrUuxtLU4pdlCZZdhww3Z8n387Je2n5BVHALZipP2qkTf5ze9smEgaWFKCWa6g8SqiBd1iswSSSL/FNgyCvJqdabOh3OGTLAH/Moj1NuG0nHY0BX/ogDHT8WLu8GesM7LuWpPLbpZyYLW5hNW9t4REkvTUppZKCZqPStNWaTRDjsyhLXRSqbQ+TNe2Gvo0GgCsZyVPlOUP2xfP2+NVGSuSrv4n+MWqFoXL8kj8FaL/w1e4lAAinQnGNNxYcQtspkFF30OP4gO7OG8ZYRp++/jQmk6qh+bdCRHTnQKOifU3iD7rp+wUbiEA47JDgb3qHmaVjKoEi+YLHDtckGKYjvfOp30PiSUdcDy/LOKKt6b/vcsPzjV63gqPnTWbr0GgfcaekvYs8nqicxLg== 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:(13230031)(4636009)(39860400002)(346002)(376002)(136003)(396003)(230922051799003)(451199024)(64100799003)(82310400011)(1800799009)(186009)(46966006)(40470700004)(36840700001)(478600001)(40480700001)(6916009)(47076005)(356005)(16526019)(26005)(82740400003)(81166007)(83380400001)(8936002)(336012)(8676002)(4326008)(36860700001)(40460700003)(70206006)(1076003)(2906002)(2616005)(7416002)(44832011)(54906003)(426003)(5660300002)(316002)(41300700001)(70586007)(6666004)(7406005)(36756003)(86362001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2023 13:46:42.0523 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8af17115-3d52-4395-7621-08dbce4e545e 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: MN1PEPF0000F0DE.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4277 X-Rspamd-Queue-Id: 25086A0025 X-Rspam-User: X-Stat-Signature: 9f17qngzpq9oczdx8zf5d17kpk8tjhp4 X-Rspamd-Server: rspam01 X-HE-Tag: 1697464004-576124 X-HE-Meta: U2FsdGVkX1+OrG/mw1u+Ua/vqBIRpDfjogN1zG5D2yy5iJ4dzH2MvjFN8iQPTmgAwv1gPfcp1VmsFsZlHf5oWgFwbAgJIuZoZFeLjBfE45za2V6EOfFiHWUhU15SLOy83ixH1hbJVFnbwjiJ4y5R+fDETwn1U8XHrhEjcm73JBFADO011NIi3XVHyT6N7fjvPfHkP0aGBFZXVnRtiX0+m1oqru7uJoRhMqmEoh5PTvd3aJ9GlURP7UDzgLudBva8pmwvrjz54MbE49SUo37p9d3Xcupb61G3qzkG55bPF5EgyyrCBRX1PmcLdoPWTKcSo8I4bPCLpWQMYat1+38boXjFc4dWkx45n8+u+HU8u9VpLE6NJn3cmNQVnZVO6mi2Ow6cD4vuL6H59Fkb5niSWyNCbTM7ogP/Ld7/vT9O2vqy3fFKjT/enwXP6+iqUwjdWWasztqrXFBQ1biR23Mvuo9ZmUpV2OaAGC1rUv1d/DQhy5pM8FUd6zwH4utbiPBmrd16Nk7H+ra8b5v9HQEUQ9vXsjVsCm6omrzCP9rsjQ602Hpnk4xFDMS3NXPOvuvKjaTwXgsDJaIGFZK48K0eFPc0NSpMjyUBx6zsrOHA8jpzESIqOI7QQIwH8ttjBvm33dHLKyalt7M4eOa/LclER4Jy2EuwjTFSsjRWkBBLVEeUuNzlKLQ3Bl6w4xEia13jjIlGQuuOfpy5N6d1NGxBj7bVeYtcl8QIFKTmNNz73rT88Oy810CKWPsfd0ePVplFbo1Fc4g5wgJ3B03FAesewZsC+/Sj36PaQe0ny4iB8lX5YG0qPivGsq/kx7U3UQSZyt3tIjEA3ZsOHPfnqmDM11cO78MyJCnzH47MF9Rbp18QIZSgrErUAJkfyhNvfUNHKvg/xcxdinf9HZb0l2iTiEUrm1LbY5azfLVmjek+ladU4kIgJ5gvSqF17uGItOCvCu3VM2/KKtR06/pPcpR b/yZ7npW zgcKFLZPWUC9fQr8X5cyoNriQmYh0JwhCzoFc3ReZx8Fb4f62qKXRozzLVEvD9O9G7q/GeM0mvlpZ36bRtXwyBrmitgDMoMwqP1m8Y0HfW3PPqhfWlfiojG5+DkBH7imC1N4X9zrJtSlEAWy2RZb2iv+2XlBtKkCBG5gwLJU3Q0LH62pr0G3naQHVntaRPUeAlLn62Fv4fsDPAp/KMPKzTRDkYKsowoRloPDAtUfB6bMHXcCwWNdzQBGm1HyXAZ514GKl9VKUBfWrmZj10WnuSjydMTbvFvrImUjuU0xyBReT6G1JmjhDzTDs341eTCrpkzbosnSRZdOBOHeppqFO4Ef4C0QsTJHiVqaD 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: Dionna Glaze The /dev/sev device has the ability to store host-wide certificates for the key used by the AMD-SP for SEV-SNP attestation report signing, but for hosts that want to specify additional certificates that are specific to the image launched in a VM, a different way is needed to communicate those certificates. Add two new KVM ioctl to handle this: KVM_SEV_SNP_{GET,SET}_CERTS The certificates that are set with this command are expected to follow the same format as the host certificates, but that format is opaque to the kernel. The new behavior for custom certificates is that the extended guest request command will now return the overridden certificates if they were installed for the instance. The error condition for a too small data buffer is changed to return the overridden certificate data size if there is an overridden certificate set installed. Setting a 0 length certificate returns the system state to only return the host certificates on an extended guest request. Also increase the SEV_FW_BLOB_MAX_SIZE another 4K page to allow space for an extra certificate. Cc: Tom Lendacky Cc: Paolo Bonzini Signed-off-by: Dionna Glaze Signed-off-by: Ashish Kalra [mdr: remove used of "we" and "this patch" in commit log, squash in documentation patch] Signed-off-by: Michael Roth [aik: snp_handle_ext_guest_request() now uses the CCP's cert object without copying things over, only refcounting needed.] Signed-off-by: Alexey Kardashevskiy --- .../virt/kvm/x86/amd-memory-encryption.rst | 44 +++++++ arch/x86/kvm/svm/sev.c | 115 ++++++++++++++++++ arch/x86/kvm/svm/svm.h | 1 + include/linux/psp-sev.h | 2 +- include/uapi/linux/kvm.h | 12 ++ 5 files changed, 173 insertions(+), 1 deletion(-) diff --git a/Documentation/virt/kvm/x86/amd-memory-encryption.rst b/Documentation/virt/kvm/x86/amd-memory-encryption.rst index b89634cfcc06..2ce6c90f07d4 100644 --- a/Documentation/virt/kvm/x86/amd-memory-encryption.rst +++ b/Documentation/virt/kvm/x86/amd-memory-encryption.rst @@ -537,6 +537,50 @@ Returns: 0 on success, -negative on error See SEV-SNP specification for further details on launch finish input parameters. +22. KVM_SEV_SNP_GET_CERTS +------------------------- + +After the SNP guest launch flow has started, the KVM_SEV_SNP_GET_CERTS command +can be issued to request the data that has been installed with the +KVM_SEV_SNP_SET_CERTS command. + +Parameters (in/out): struct kvm_sev_snp_get_certs + +Returns: 0 on success, -negative on error + +:: + + struct kvm_sev_snp_get_certs { + __u64 certs_uaddr; + __u64 certs_len + }; + +If no certs have been installed, then the return value is -ENOENT. +If the buffer specified in the struct is too small, the certs_len field will be +overwritten with the required bytes to receive all the certificate bytes and the +return value will be -EINVAL. + +23. KVM_SEV_SNP_SET_CERTS +------------------------- + +After the SNP guest launch flow has started, the KVM_SEV_SNP_SET_CERTS command +can be issued to override the /dev/sev certs data that is returned when a +guest issues an extended guest request. This is useful for instance-specific +extensions to the host certificates. + +Parameters (in/out): struct kvm_sev_snp_set_certs + +Returns: 0 on success, -negative on error + +:: + + struct kvm_sev_snp_set_certs { + __u64 certs_uaddr; + __u64 certs_len + }; + +The certs_len field may not exceed SEV_FW_BLOB_MAX_SIZE. + References ========== diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index efe879524b6c..602aaf82eef3 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -2301,6 +2301,113 @@ static int snp_launch_finish(struct kvm *kvm, struct kvm_sev_cmd *argp) return ret; } +static int snp_get_instance_certs(struct kvm *kvm, struct kvm_sev_cmd *argp) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + struct kvm_sev_snp_get_certs params; + struct sev_snp_certs *snp_certs; + int rc = 0; + + if (!sev_snp_guest(kvm)) + return -ENOTTY; + + if (!sev->snp_context) + return -EINVAL; + + if (copy_from_user(¶ms, (void __user *)(uintptr_t)argp->data, + sizeof(params))) + return -EFAULT; + + snp_certs = sev_snp_certs_get(sev->snp_certs); + /* No instance certs set. */ + if (!snp_certs) + return -ENOENT; + + if (params.certs_len < sev->snp_certs->len) { + /* Output buffer too small. Return the required size. */ + params.certs_len = sev->snp_certs->len; + + if (copy_to_user((void __user *)(uintptr_t)argp->data, ¶ms, + sizeof(params))) + rc = -EFAULT; + else + rc = -EINVAL; /* May be ENOSPC? */ + } else { + if (copy_to_user((void __user *)(uintptr_t)params.certs_uaddr, + snp_certs->data, snp_certs->len)) + rc = -EFAULT; + } + + sev_snp_certs_put(snp_certs); + + return rc; +} + +static void snp_replace_certs(struct kvm_sev_info *sev, struct sev_snp_certs *snp_certs) +{ + sev_snp_certs_put(sev->snp_certs); + sev->snp_certs = snp_certs; +} + +static int snp_set_instance_certs(struct kvm *kvm, struct kvm_sev_cmd *argp) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + unsigned long length = SEV_FW_BLOB_MAX_SIZE; + struct kvm_sev_snp_set_certs params; + struct sev_snp_certs *snp_certs; + void *to_certs; + int ret; + + if (!sev_snp_guest(kvm)) + return -ENOTTY; + + if (!sev->snp_context) + return -EINVAL; + + if (copy_from_user(¶ms, (void __user *)(uintptr_t)argp->data, + sizeof(params))) + return -EFAULT; + + if (params.certs_len > SEV_FW_BLOB_MAX_SIZE) + return -EINVAL; + + /* + * Setting a length of 0 is the same as "uninstalling" instance- + * specific certificates. + */ + if (params.certs_len == 0) { + snp_replace_certs(sev, NULL); + return 0; + } + + /* Page-align the length */ + length = ALIGN(params.certs_len, PAGE_SIZE); + + to_certs = kmalloc(length, GFP_KERNEL | __GFP_ZERO); + if (!to_certs) + return -ENOMEM; + + if (copy_from_user(to_certs, + (void __user *)(uintptr_t)params.certs_uaddr, + params.certs_len)) { + ret = -EFAULT; + goto error_exit; + } + + snp_certs = sev_snp_certs_new(to_certs, length); + if (!snp_certs) { + ret = -ENOMEM; + goto error_exit; + } + + snp_replace_certs(sev, snp_certs); + + return 0; +error_exit: + kfree(to_certs); + return ret; +} + int sev_mem_enc_ioctl(struct kvm *kvm, void __user *argp) { struct kvm_sev_cmd sev_cmd; @@ -2400,6 +2507,12 @@ int sev_mem_enc_ioctl(struct kvm *kvm, void __user *argp) case KVM_SEV_SNP_LAUNCH_FINISH: r = snp_launch_finish(kvm, &sev_cmd); break; + case KVM_SEV_SNP_GET_CERTS: + r = snp_get_instance_certs(kvm, &sev_cmd); + break; + case KVM_SEV_SNP_SET_CERTS: + r = snp_set_instance_certs(kvm, &sev_cmd); + break; default: r = -EINVAL; goto out; @@ -2616,6 +2729,8 @@ static int snp_decommission_context(struct kvm *kvm) snp_free_firmware_page(sev->snp_context); sev->snp_context = NULL; + sev_snp_certs_put(sev->snp_certs); + return 0; } diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 1fd90a88b0db..bdf792ba06e1 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -97,6 +97,7 @@ struct kvm_sev_info { u64 snp_init_flags; void *snp_context; /* SNP guest context page */ u64 sev_features; /* Features set at VMSA creation */ + struct sev_snp_certs *snp_certs; }; struct kvm_svm { diff --git a/include/linux/psp-sev.h b/include/linux/psp-sev.h index 3c605856ef4f..722e26d28d2f 100644 --- a/include/linux/psp-sev.h +++ b/include/linux/psp-sev.h @@ -14,7 +14,7 @@ #include -#define SEV_FW_BLOB_MAX_SIZE 0x4000 /* 16KB */ +#define SEV_FW_BLOB_MAX_SIZE 0x5000 /* 20KB */ struct sev_snp_certs { void *data; diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 3af546adb962..0444e122ac5e 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1973,6 +1973,8 @@ enum sev_cmd_id { KVM_SEV_SNP_LAUNCH_START, KVM_SEV_SNP_LAUNCH_UPDATE, KVM_SEV_SNP_LAUNCH_FINISH, + KVM_SEV_SNP_GET_CERTS, + KVM_SEV_SNP_SET_CERTS, KVM_SEV_NR_MAX, }; @@ -2120,6 +2122,16 @@ struct kvm_sev_snp_launch_finish { __u8 pad[6]; }; +struct kvm_sev_snp_get_certs { + __u64 certs_uaddr; + __u64 certs_len; +}; + +struct kvm_sev_snp_set_certs { + __u64 certs_uaddr; + __u64 certs_len; +}; + #define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0) #define KVM_DEV_ASSIGN_PCI_2_3 (1 << 1) #define KVM_DEV_ASSIGN_MASK_INTX (1 << 2)