From nobody Tue Feb 10 19:10:40 2026 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2070.outbound.protection.outlook.com [40.107.102.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2AA5A763F7 for ; Mon, 25 Mar 2024 22:26:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.102.70 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711405616; cv=fail; b=pBBTDzg6hZoVxhnUnZ8VHEwUDfmDyt6n7Kz6JGb9NYvO3Ozr9lcnK3O115aPA9pH8oMqo8YxB5t2MQVp8lOhKWCVg2R92iDJhMqMon8NzLK1m4AlBPQbHpEzdeAmdQnlexf7cuVGDNjK66IiWpvDaN2zBBk37Gt6o0EbgIM1Rq8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711405616; c=relaxed/simple; bh=/p//XbU4+2CDUGb8+GVs8AmBxw+VQYCrdyK9Zdl1kK4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LQA82R57ndes2I7LwmAaYXHB1kjLdxtg3uleptAHLiIc0lJnkR/m3bHWypXOOpL/8f0J6CJnV5YAYW2FYIccqu+KSMiHehdKEonj9qPTlxrFqQDBALZ7mqH8P8/tiDdOEnJoEqGwwWzVPKPH2vR6tlwDkvIdKaApl9IdWaTsyUU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=KFnQfFA7; arc=fail smtp.client-ip=40.107.102.70 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="KFnQfFA7" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PLBTSaz84wavkwbl42rwh7+g9rwRzN1hw1cN2jUV2gRVl5ez7kMmxEvHqoBpOnI4FdZiyW4h2CGOtSIb1zZAgcc9FPhgr/i8hERe+lUywgthpJnmUzrlRvb54t3C2ZEuKbOmsqQrmzw1Uw08iEThKf0GHbE3BoHD/WuQNzpeJ4MzOYENKWe2WxjgOKNvpARANfWM3HczM39KhLGplfDg4tgJL6Ms/HENBX+YL9nfAG+GTIwYTgpHJmPEg3r3Ec2EBcfHXzoyjaBALtKWA2xYkQ79uUWeo0iImCG7T32ltUi4+Veztvu5qnfvEJ0wJCNVOS9u0zPAUzB326wI3t9Xdg== 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=tU4myvcDtCnR1U+pxZrwfxKRIdvQWY1JvfuKBFtRs3M=; b=OrJR48o7P5R51JNdiKK42O8RUWLzwtVlSoxmeRpDrb6iolHIjegoHIg0TZpDkOXsP3xMYOcdkPARM8MH+vnO0+g2h9e8QDRag+m22iv0r5M5Z2AJnaIY0ntswIHPUmyL8VRgXq7DCPsWDFvIb9VPyIX5zccU5w0Z0fNuRzBPXJJKrlLQhIiipYYJbqf+cCBgmkGqpaiggoMG1Onbki+j5hptoveb2UZxKdVB1aIF1BbRrooOkatve7w+6ysgmfgpurtsG9voqBDzIIBO/+pVYLiQmxuhSurbw2200piL9V87sCISQfvK2baHZtTeNVC0BRY49aqQqBcwOZvWStl7Ow== 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 (0) 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=tU4myvcDtCnR1U+pxZrwfxKRIdvQWY1JvfuKBFtRs3M=; b=KFnQfFA7AmpVa2GTO5493mnBSLF4Qufu0x0C12fgmvRPDbImXVNbACBMUg1vCB+GfXb+UBOQIC8hmJ3adaqI6rybTot3TSF2AG4Da8k6++qIVPwPuBkWalDGmxvFY/kN8HYfJPg2q9Brf5TnwULXVov77QWUzveznfnj0HvdxwQ= Received: from BY5PR17CA0021.namprd17.prod.outlook.com (2603:10b6:a03:1b8::34) by PH0PR12MB7012.namprd12.prod.outlook.com (2603:10b6:510:21c::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.32; Mon, 25 Mar 2024 22:26:51 +0000 Received: from SJ1PEPF00001CDF.namprd05.prod.outlook.com (2603:10b6:a03:1b8:cafe::f6) by BY5PR17CA0021.outlook.office365.com (2603:10b6:a03:1b8::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.13 via Frontend Transport; Mon, 25 Mar 2024 22:26:51 +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 SJ1PEPF00001CDF.mail.protection.outlook.com (10.167.242.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Mon, 25 Mar 2024 22:26:51 +0000 Received: from tlendack-t1.amdoffice.net (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.35; Mon, 25 Mar 2024 17:26:50 -0500 From: Tom Lendacky To: , , , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , "Peter Zijlstra" , Dan Williams , Michael Roth , Ashish Kalra Subject: [PATCH v3 01/14] x86/sev: Rename snp_init() in the boot/compressed/sev.c file Date: Mon, 25 Mar 2024 17:26:20 -0500 Message-ID: <425afa6512994b1ca1bb366eb7abfb24d65175aa.1711405593.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: SJ1PEPF00001CDF:EE_|PH0PR12MB7012:EE_ X-MS-Office365-Filtering-Correlation-Id: b51125f9-73e3-4d14-0e9d-08dc4d1aab23 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IUSXffQmIb9gtVlGtw79g+HOEjSA1cJLtb9Tbf4DhQz6ZX53FIqRQpliX98m7BNkzFp5vESp6WSQCxdk1rxYSdmBIyZMCIwZyaXq2boFMutOnE0GmcpmWLN8qo5DIwi0ojxcb3wIaJAh5v12WGQX871fRl/bKDJTbfxAUURL4Kl5fuvVqja3sYgFeAWV83ZTsZ6qMsBuLgZNj82xqJhNWT0Z+njE0gY5l6kwIzozcQtGOSEH2Ygm2JVwqftLMB4adVdysYewbmCUKhBi88lp+TodOF0L6gh0PPb0dxjavlIVx332Wmsi9XYxRC+mZDulqbmz2DFj16ztOSK6rPD8wbg+kFFYct9px/S95wCZnC/H7kMnDaXanTfOZ7Dib+KV640iIDYwMhwgvBqa0kQSDPrH98xwzimKGLcHZJDIhwWT2OEaMrx/7YDHzTvUOEzIaL5q9n6br0/pnkkayN8UA0HDa/zj9TfzBrxDpBBpbVscf6kwyG57+gb7L99cO914pBH3rG+KoKYm6VItDblYAEbnXFmZXMQgnSzslsaM8/lR8bWJuse+0dRraOaXg1ti/Mtq7tZkJ2Shd7jBPxE2pMJLcj7xriUxOwh3CpAfgwXeYJ3Qv43U9/j9JQyMHJNW7R8pVUEfVb91U5BJM2OTU/Ks75u1y2SoA0QqO1+9HkC/AsEnRbjGjMmQbDdL6jsW63SNGwIDzZNTP3UUd1EeK0I81OwUwtLlvQcySzyXH2gfHnPR/E2p+WO0yjGEp/zw 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)(1800799015)(36860700004)(7416005)(82310400014)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2024 22:26:51.4052 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b51125f9-73e3-4d14-0e9d-08dc4d1aab23 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: SJ1PEPF00001CDF.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7012 Content-Type: text/plain; charset="utf-8" The snp_init() in boot/compressed/sev.c is local to that file and is not called from outside of the file. Change the name so that it is not tied to the function definition in arch/x86/include/asm/sev.h. Move the renamed snp_init() and related functions up in the file to avoid having to add a forward declaration and make the function static, too. This will allow the snp_init() function in arch/x86/kernel/sev.c to be changed without having to make the same change in boot/compressed/sev.c. Signed-off-by: Tom Lendacky Reviewed-by: Pankaj Gupta --- arch/x86/boot/compressed/sev.c | 162 ++++++++++++++++----------------- 1 file changed, 81 insertions(+), 81 deletions(-) diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c index ec71846d28c9..5ad0ff4664f1 100644 --- a/arch/x86/boot/compressed/sev.c +++ b/arch/x86/boot/compressed/sev.c @@ -413,6 +413,85 @@ void snp_check_features(void) } } =20 +/* Search for Confidential Computing blob in the EFI config table. */ +static struct cc_blob_sev_info *find_cc_blob_efi(struct boot_params *bp) +{ + unsigned long cfg_table_pa; + unsigned int cfg_table_len; + int ret; + + ret =3D efi_get_conf_table(bp, &cfg_table_pa, &cfg_table_len); + if (ret) + return NULL; + + return (struct cc_blob_sev_info *)efi_find_vendor_table(bp, cfg_table_pa, + cfg_table_len, + EFI_CC_BLOB_GUID); +} + +/* + * Initial set up of SNP relies on information provided by the + * Confidential Computing blob, which can be passed to the boot kernel + * by firmware/bootloader in the following ways: + * + * - via an entry in the EFI config table + * - via a setup_data structure, as defined by the Linux Boot Protocol + * + * Scan for the blob in that order. + */ +static struct cc_blob_sev_info *find_cc_blob(struct boot_params *bp) +{ + struct cc_blob_sev_info *cc_info; + + cc_info =3D find_cc_blob_efi(bp); + if (cc_info) + goto found_cc_info; + + cc_info =3D find_cc_blob_setup_data(bp); + if (!cc_info) + return NULL; + +found_cc_info: + if (cc_info->magic !=3D CC_BLOB_SEV_HDR_MAGIC) + sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SNP_UNSUPPORTED); + + return cc_info; +} + +/* + * Indicate SNP based on presence of SNP-specific CC blob. Subsequent chec= ks + * will verify the SNP CPUID/MSR bits. + */ +static bool early_snp_init(struct boot_params *bp) +{ + struct cc_blob_sev_info *cc_info; + + if (!bp) + return false; + + cc_info =3D find_cc_blob(bp); + if (!cc_info) + return false; + + /* + * If a SNP-specific Confidential Computing blob is present, then + * firmware/bootloader have indicated SNP support. Verifying this + * involves CPUID checks which will be more reliable if the SNP + * CPUID table is used. See comments over snp_setup_cpuid_table() for + * more details. + */ + setup_cpuid_table(cc_info); + + /* + * Pass run-time kernel a pointer to CC info via boot_params so EFI + * config table doesn't need to be searched again during early startup + * phase. + */ + bp->cc_blob_address =3D (u32)(unsigned long)cc_info; + + return true; +} + /* * sev_check_cpu_support - Check for SEV support in the CPU capabilities * @@ -463,7 +542,7 @@ void sev_enable(struct boot_params *bp) bp->cc_blob_address =3D 0; =20 /* - * Do an initial SEV capability check before snp_init() which + * Do an initial SEV capability check before early_snp_init() which * loads the CPUID page and the same checks afterwards are done * without the hypervisor and are trustworthy. * @@ -478,7 +557,7 @@ void sev_enable(struct boot_params *bp) * Setup/preliminary detection of SNP. This will be sanity-checked * against CPUID/MSR values later. */ - snp =3D snp_init(bp); + snp =3D early_snp_init(bp); =20 /* Now repeat the checks with the SNP CPUID table. */ =20 @@ -535,85 +614,6 @@ u64 sev_get_status(void) return m.q; } =20 -/* Search for Confidential Computing blob in the EFI config table. */ -static struct cc_blob_sev_info *find_cc_blob_efi(struct boot_params *bp) -{ - unsigned long cfg_table_pa; - unsigned int cfg_table_len; - int ret; - - ret =3D efi_get_conf_table(bp, &cfg_table_pa, &cfg_table_len); - if (ret) - return NULL; - - return (struct cc_blob_sev_info *)efi_find_vendor_table(bp, cfg_table_pa, - cfg_table_len, - EFI_CC_BLOB_GUID); -} - -/* - * Initial set up of SNP relies on information provided by the - * Confidential Computing blob, which can be passed to the boot kernel - * by firmware/bootloader in the following ways: - * - * - via an entry in the EFI config table - * - via a setup_data structure, as defined by the Linux Boot Protocol - * - * Scan for the blob in that order. - */ -static struct cc_blob_sev_info *find_cc_blob(struct boot_params *bp) -{ - struct cc_blob_sev_info *cc_info; - - cc_info =3D find_cc_blob_efi(bp); - if (cc_info) - goto found_cc_info; - - cc_info =3D find_cc_blob_setup_data(bp); - if (!cc_info) - return NULL; - -found_cc_info: - if (cc_info->magic !=3D CC_BLOB_SEV_HDR_MAGIC) - sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SNP_UNSUPPORTED); - - return cc_info; -} - -/* - * Indicate SNP based on presence of SNP-specific CC blob. Subsequent chec= ks - * will verify the SNP CPUID/MSR bits. - */ -bool snp_init(struct boot_params *bp) -{ - struct cc_blob_sev_info *cc_info; - - if (!bp) - return false; - - cc_info =3D find_cc_blob(bp); - if (!cc_info) - return false; - - /* - * If a SNP-specific Confidential Computing blob is present, then - * firmware/bootloader have indicated SNP support. Verifying this - * involves CPUID checks which will be more reliable if the SNP - * CPUID table is used. See comments over snp_setup_cpuid_table() for - * more details. - */ - setup_cpuid_table(cc_info); - - /* - * Pass run-time kernel a pointer to CC info via boot_params so EFI - * config table doesn't need to be searched again during early startup - * phase. - */ - bp->cc_blob_address =3D (u32)(unsigned long)cc_info; - - return true; -} - void sev_prep_identity_maps(unsigned long top_level_pgt) { /* --=20 2.43.2 From nobody Tue Feb 10 19:10:40 2026 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2073.outbound.protection.outlook.com [40.107.223.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 08F75763E6 for ; Mon, 25 Mar 2024 22:27:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.73 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711405622; cv=fail; b=LGhVei+GI0vB1wJSzz9rk5J3kmmGPp6HAMjGwHZFuiQ6xyZ0YZ8+uzXX2nLakHyiXZG9T3LL7x4toEg2jfdIbEcnabR8bcTTir1Org/nlWQ9H/QUOUl4OwCt5pjwiXlJl0b/dBOTy+hf0rrTjyfAUTr0eOLivW6mHMc2rHXyJRA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711405622; c=relaxed/simple; bh=PB3ScLP4+/wcGJgVO8STzESNjf5T1O50EMshE3dpi5k=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lU3iGGchFDQUM/4vwTo8kNZE+LePjcd7mXo/72OtXM6FTLJ62NfkiVfYezBHpI3WhzN7Re4n4QrZ6lDBQCqVSpMdbDNk5rwsFQjsGiJ1aktEZofcDunC3vSeuLxL3quiuTtp3bZoKafDyb+/u0MYiX+h4M0kfHrM8Hb7XRHyLmc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=zzvXCRDM; arc=fail smtp.client-ip=40.107.223.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="zzvXCRDM" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oXOTJU6Cf9/aCtmFldYeaphVgnOakk5rUa0ChKCCc2JzFXZhAtzSrVx1S/l3+IaZD8NdoIvzZbORkOQksJjR6VA6R7B7pVjPLfd9rLQdUN5fwPuWKcvKEbcyc3htDbzh3wLCQV2B7M002ImwJ//dKod7Ewern2lPOgP1YMbDJh3HvVEl24imNy9qpDzPIqLBEGIskbZYh+eg7N2robm9zaxOPTbUaPv5KJnmjgfqrIf89HHPPaaJEtbrYMllbFLH3/MJMMRe0Y8favRpnY/9fMz8ZAgPxWSGRQrtINa1Mnlrnnkc01FrnV4say/oX+AaMnaINA2W5IrFE0NncqsAkg== 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=aN5QZrGS3+Cj+q5tlmfvaqsYgq1ZY9uSlVZFVWphlp0=; b=PULCyS03oPETwjfiKZ13CvGMSfj5f1Pnj022Wi2tjOZD6TxtkfJl+1UX2rlVaKeK8Vx/hth6TMu9S+E2S+1AN7wCQz0eEl+O3yltunUHHLrY7pVDO6uMjVeaxn3O/RI2QJYdDfyiUmONPNuqGDph3FaWA1e//pgYBy/C2qPnSHj32KfniQ5yI1oZC4fhQqTq+abkHaY3tqrvvLcddMXtkPLHqCiNKDx0Y6Hcn3jI5jSzEUgZff0zV+kO5+NXskUM46TtWECcDMZpizul2lyG9uMmnyhiLopvzqViEOkrNku48Y2xFGwD4QTTrMWcE/LbQhhMzdpCmIasN4+t0esGTA== 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 (0) 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=aN5QZrGS3+Cj+q5tlmfvaqsYgq1ZY9uSlVZFVWphlp0=; b=zzvXCRDMuVMEjcbzZm1/nlBNsa5Goq/34yVISYqC6wIGTGbOVIuX538+cv8pH5u0imKVjAhIh7XLkfiECRPoE2f15r1+YuSs8oJIK5TQfficK/iNtyExpzL5hwreZzOP5ctfP5onQg83R0PFwMQ6zJD1C9vDE9+M2mugNNMttas= Received: from BY5PR16CA0028.namprd16.prod.outlook.com (2603:10b6:a03:1a0::41) by MN0PR12MB6317.namprd12.prod.outlook.com (2603:10b6:208:3c2::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.31; Mon, 25 Mar 2024 22:26:58 +0000 Received: from SJ1PEPF00001CE3.namprd05.prod.outlook.com (2603:10b6:a03:1a0:cafe::f3) by BY5PR16CA0028.outlook.office365.com (2603:10b6:a03:1a0::41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.13 via Frontend Transport; Mon, 25 Mar 2024 22:26:58 +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 SJ1PEPF00001CE3.mail.protection.outlook.com (10.167.242.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Mon, 25 Mar 2024 22:26:58 +0000 Received: from tlendack-t1.amdoffice.net (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.35; Mon, 25 Mar 2024 17:26:57 -0500 From: Tom Lendacky To: , , , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , "Peter Zijlstra" , Dan Williams , Michael Roth , Ashish Kalra Subject: [PATCH v3 02/14] x86/sev: Make the VMPL0 checking function more generic Date: Mon, 25 Mar 2024 17:26:21 -0500 Message-ID: <1b0d8ec8e671ad957a2ad888725ce24edeedf74a.1711405593.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: SJ1PEPF00001CE3:EE_|MN0PR12MB6317:EE_ X-MS-Office365-Filtering-Correlation-Id: 3d9c53ea-3f57-4b6e-8e14-08dc4d1aaf53 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: C9Om5KurYmE/w+e6vbSQM+zHhj6TuUFGga68qqB2IlZ0vQiONkjZ052rhjb0fXWTy+hYVhBikF0lqXifP1YMmworOV76IoA+vNmHBAXzp4jfy0k292PBLfwUI3h/cnEKK84pEeCmG8Ei7bMFSiH74TuGW7sx/ckfiDW59Zo8udE0rEYsYYnV9VThC617LlfAwXEW5QwheD/2tMF3axKoM7n5asspNcU3GIFxWL8Gy2rXzzUJYujoP5EnjtPHH8QbWoJq7741k7d4+6uJjFazjglIZzqstIG+JBDi/Ayt+L4oa12P3g9yRNM2nARLc7DJKczSq5AjuwIih7aX9+osoeW5E4aBwRjsL3ynY+Bpkk852uB+xmnxFYIOqLmCNGUa3gCLzTfW2/tUyjUTFW+d3smXbXU8Si1gehkSvmpL7cEqi1IPrSRm1Y2yVCmYcjwzcLwDEkcL3V0cCB7KdYt8chkPoodxl53FgXB5cQ6H1HNMW6ndiIulzmhx5ZsNAzitNAuKzs3i9tOLHDKy55ZsZRQKrHQur3v4teuxMjzD8Iw5TAIPxOKROpU9NssTSP5Wpmucfux1DmFVSJo/LSgQa4RoEnf/So8dMKyLxX9cIMX8Nip3nUdiMYuixQYJi73ZMQlMqsU+c3c8LgrLD9fnFRF2vrUOf0j4VNhKEV9FLgLQax+XhBfUFuoMdWpOlDczlz9bzIhcEbQa+wQyLfHeI8VyypAMPixdL4C3B3AQMdIz8z1BiFDX9ezu3As3h7xP 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)(7416005)(376005)(82310400014)(36860700004)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2024 22:26:58.4338 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3d9c53ea-3f57-4b6e-8e14-08dc4d1aaf53 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: SJ1PEPF00001CE3.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6317 Content-Type: text/plain; charset="utf-8" Currently, the enforce_vmpl0() function uses a set argument when testing for VMPL0 and terminates the guest if the guest is not running at VMPL0. Make the function more generic by moving it into the common code, renaming it, allowing it to take an argument for use in the VMPL0 check (RMPADJUST instruction) and return the result of the check, allowing the caller to determine the action taken based on the result. Signed-off-by: Tom Lendacky Reviewed-by: Pankaj Gupta --- arch/x86/boot/compressed/sev.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c index 5ad0ff4664f1..49dc9661176d 100644 --- a/arch/x86/boot/compressed/sev.c +++ b/arch/x86/boot/compressed/sev.c @@ -335,10 +335,9 @@ void do_boot_stage2_vc(struct pt_regs *regs, unsigned = long exit_code) sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SEV_ES_GEN_REQ); } =20 -static void enforce_vmpl0(void) +static bool running_at_vmpl0(void *va) { u64 attrs; - int err; =20 /* * RMPADJUST modifies RMP permissions of a lesser-privileged (numerically @@ -347,12 +346,11 @@ static void enforce_vmpl0(void) * * If the guest is running at VMPL0, it will succeed. Even if that operat= ion * modifies permission bits, it is still ok to do so currently because Li= nux - * SNP guests are supported only on VMPL0 so VMPL1 or higher permission m= asks - * changing is a don't-care. + * SNP guests running at VMPL0 only run at VMPL0, so VMPL1 or higher + * permission mask changes are a don't-care. */ attrs =3D 1; - if (rmpadjust((unsigned long)&boot_ghcb_page, RMP_PG_SIZE_4K, attrs)) - sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_NOT_VMPL0); + return !rmpadjust((unsigned long)va, RMP_PG_SIZE_4K, attrs); } =20 /* @@ -588,7 +586,8 @@ void sev_enable(struct boot_params *bp) if (!(get_hv_features() & GHCB_HV_FT_SNP)) sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SNP_UNSUPPORTED); =20 - enforce_vmpl0(); + if (!running_at_vmpl0(&boot_ghcb_page)) + sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_NOT_VMPL0); } =20 if (snp && !(sev_status & MSR_AMD64_SEV_SNP_ENABLED)) --=20 2.43.2 From nobody Tue Feb 10 19:10:40 2026 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2047.outbound.protection.outlook.com [40.107.102.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B47A57F460 for ; Mon, 25 Mar 2024 22:27:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.102.47 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711405632; cv=fail; b=D/Z1stHsSsIpS61aW7KdRMVZU6DTB3OT81xYCXQXplUvjCDJ+bDKEogkIyaSgZj6OZzgF8McHIfuSdPdEgwA0vJ+JB1OCr9oB4M1ipdnf3q5r5Kt441h12rlxyggbvjHXkYWxVejSh2R8XC7G6Rj+LiyuXyahnQEL9dZ7X1G9Vg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711405632; c=relaxed/simple; bh=/KUj5qkMAEtD+t6qHDZiPmcngZT4OhjXs8XrdueYYbU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jD4Kx3pW00RZyCW1nR1SXrIESflYpa+NTr0QDpBKrQywdAYtpkeNR/umRB6T/lbfEiWiCQeUJReGb7UE0BNSvOA28Afmlp803cNvsvjA8WjD04Y62STb1DRBsMkQOrFjzJJ3RouPN9rJTN7hvEsFktai5N0LPjA9gJuGHaFK2G8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=RC7BqtuK; arc=fail smtp.client-ip=40.107.102.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="RC7BqtuK" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dbhr83X/JlEVlPt72xhYbPanyInCzXr6Myv+g81PD4WjFXGHMrK64knLIvoMNewUni6wILZ0N86UF8vIL1/XVIaknipE7IQEeZ/7wBiaEHPzvgXnq7CCf4NXFEM3K92YKlXICOmAVOlepYm60nYxVv7/maJz6aQimEnqo4Mral5K1bZf8He3lmIXw0wL1gCCbhZQWNuoFwoNXPtzyqt1sJcZiL9miIG3okWEQU2iWNY6whVu5k5wy+nOeDRQ+zD3fqGdMuVhVbNnZOtEuZAER6dseP5BJuV7eBltA0IhuOm4M1ziPQXBJveiaIhvr/MId408DgZvHVvnhTzJke3Z0Q== 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=9TDtg9k/dOEDJFCyzrJQCnvaqeVp7dyvWBkPtoY2Pkk=; b=iROJqyQKqumPiK2FnPSL5bj+KqO87VU0peouKI/JK+OInjxTgIpGQ3priovB8XjLho7+VhtVTIUiP5oGLZnq6eLAriTTwA4PFQVvaosmZQS3Eat+CUiIphEKXpG0BlQGh5t2e2I4C5BWXAav1vtHPhAMdqpuY6ExyUt6ac7d/rcHAfNhTUZKO8K/Z0Nn1a1xxP2vXig2+5LY6iyOgdXNlXnyTHK8IQYN7749KbBLBFZL9/74TxBB26whGEqOFm5QATeK2qQpUiNkVOptduBg2YgVVgvAitlxgpyXnemKZ7c2a+r9/K1/uY9femO0taV+QeKuUCbvJeB8Le6abiR30g== 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 (0) 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=9TDtg9k/dOEDJFCyzrJQCnvaqeVp7dyvWBkPtoY2Pkk=; b=RC7BqtuKn1g0sCfSnH/qxrIpU0QfczUbsaTyYeyWf+waMi7ZG68QuCMKgJ+U3KbBbR+nFNy2Psjyr1YnteF07W+6xJs7fgWkVXA7QkdoD8BUpuOOaOj/XcheGdlZi48DG9c8PehxZZCKRhWFuuWhI//S3NgI2dfLhpBeR2eK6kI= Received: from SJ0PR03CA0137.namprd03.prod.outlook.com (2603:10b6:a03:33c::22) by DM4PR12MB6230.namprd12.prod.outlook.com (2603:10b6:8:a7::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.31; Mon, 25 Mar 2024 22:27:06 +0000 Received: from SJ1PEPF00001CDD.namprd05.prod.outlook.com (2603:10b6:a03:33c:cafe::be) by SJ0PR03CA0137.outlook.office365.com (2603:10b6:a03:33c::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.13 via Frontend Transport; Mon, 25 Mar 2024 22:27:05 +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 SJ1PEPF00001CDD.mail.protection.outlook.com (10.167.242.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Mon, 25 Mar 2024 22:27:05 +0000 Received: from tlendack-t1.amdoffice.net (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.35; Mon, 25 Mar 2024 17:27:04 -0500 From: Tom Lendacky To: , , , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , "Peter Zijlstra" , Dan Williams , Michael Roth , Ashish Kalra Subject: [PATCH v3 03/14] x86/sev: Check for the presence of an SVSM in the SNP Secrets page Date: Mon, 25 Mar 2024 17:26:22 -0500 Message-ID: X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: SJ1PEPF00001CDD:EE_|DM4PR12MB6230:EE_ X-MS-Office365-Filtering-Correlation-Id: 0c18fc25-9445-4ea1-7021-08dc4d1ab3a5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lqG6IaU/z3sMI/iHrIhUTuDZ5QYkid5TfwEHMxDLxNlkGtzPtjIxMkZdoacfc2RsZnMTzkwoxgpWDczJpwAmwOt3H9PnMgWjWNWhddywBreidF09SppPPdU0lS76QPx6P+Lg/LdpgbAq1Y22Lx6B/oMDsG4xM83hrPQmDaTw0MaJIE0o1eYzz3VLYml/FC6En6jHgr70+qMv+ZVX6IfOdcilZgKD9a3zPg2WYh/2gNq1qN4mbGy1I8/P36nas/gc5hamlxUZZrq9WV2jhPYiMo/TjN+o+eh3z2BvpF8Kv1PgfkS3/4Wt6lOi5ZZFyOzNQJzE8RF24T1Jjc/okAziXXsga7MRLerJDm0hICmzK0GwQPHgNpkmeN+Te0GMF9UG/TTs4KXgWxk1pwlUAD1DOCbg6y0kYHXX4AhObcX7nxc8xnS3qyY3zGiEEHpUgaM71F9qRrfvkbuIWH7vScpJ/0Hcsm5fLfEQDbNNveyGf2gCtsPF1kt1CfozbSHBfmG+2/0k8G1DgWfcVVxAev9BWE4yp8I3YSxbJSWpPITe0FppOLWHB+MFkmTEXMcylnHk+andBfMdi1tkrUbqmrPy/9//Yh6r3208McdiURLkRao6Qla2HJXXwXvhn2CTDdT3/sQkgkhdIm/pwQqfVbLXkYhw3Em9z3VfQgA/npnMw66ULdoSfALIe8NunZ6vAHLc5EwRtO1xv1hTyTnUptSHAXcr1xTk+h2Xt7uxCLam6vgA67Uq5MD0p/TRAZCVKmO7 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)(7416005)(1800799015)(376005)(36860700004)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2024 22:27:05.6970 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0c18fc25-9445-4ea1-7021-08dc4d1ab3a5 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: SJ1PEPF00001CDD.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6230 Content-Type: text/plain; charset="utf-8" During early boot phases, check for the presence of an SVSM when running as an SEV-SNP guest. An SVSM is present if the 64-bit value at offset 0x148 into the secrets page is non-zero. If an SVSM is present, save the SVSM Calling Area address (CAA), located at offset 0x150 into the secrets page, and set the VMPL level of the guest, which should be non-zero, to indicate the presence of an SVSM. Signed-off-by: Tom Lendacky Reviewed-by: Pankaj Gupta --- arch/x86/boot/compressed/sev.c | 35 ++++++++--------- arch/x86/include/asm/sev-common.h | 4 ++ arch/x86/include/asm/sev.h | 25 +++++++++++- arch/x86/kernel/sev-shared.c | 64 +++++++++++++++++++++++++++++++ arch/x86/kernel/sev.c | 16 ++++++++ 5 files changed, 125 insertions(+), 19 deletions(-) diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c index 49dc9661176d..fe61ff630c7e 100644 --- a/arch/x86/boot/compressed/sev.c +++ b/arch/x86/boot/compressed/sev.c @@ -12,6 +12,7 @@ */ #include "misc.h" =20 +#include #include #include #include @@ -29,6 +30,15 @@ static struct ghcb boot_ghcb_page __aligned(PAGE_SIZE); struct ghcb *boot_ghcb; =20 +/* + * SVSM related information: + * When running under an SVSM, the VMPL that Linux is executing at must = be + * non-zero. The VMPL is therefore used to indicate the presence of an S= VSM. + */ +static u8 vmpl __section(".data"); +static u64 boot_svsm_caa_pa __section(".data"); +static struct svsm_ca *boot_svsm_caa __section(".data"); + /* * Copy a version of this function here - insn-eval.c can't be used in * pre-decompression code. @@ -335,24 +345,6 @@ void do_boot_stage2_vc(struct pt_regs *regs, unsigned = long exit_code) sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SEV_ES_GEN_REQ); } =20 -static bool running_at_vmpl0(void *va) -{ - u64 attrs; - - /* - * RMPADJUST modifies RMP permissions of a lesser-privileged (numerically - * higher) privilege level. Here, clear the VMPL1 permission mask of the - * GHCB page. If the guest is not running at VMPL0, this will fail. - * - * If the guest is running at VMPL0, it will succeed. Even if that operat= ion - * modifies permission bits, it is still ok to do so currently because Li= nux - * SNP guests running at VMPL0 only run at VMPL0, so VMPL1 or higher - * permission mask changes are a don't-care. - */ - attrs =3D 1; - return !rmpadjust((unsigned long)va, RMP_PG_SIZE_4K, attrs); -} - /* * SNP_FEATURES_IMPL_REQ is the mask of SNP features that will need * guest side implementation for proper functioning of the guest. If any @@ -480,6 +472,13 @@ static bool early_snp_init(struct boot_params *bp) */ setup_cpuid_table(cc_info); =20 + /* + * Record the SVSM Calling Area address (CAA) if the guest is not + * running at VMPL0. The CA will be used to communicate with the + * SVSM to perform the SVSM services. + */ + setup_svsm_ca(cc_info); + /* * Pass run-time kernel a pointer to CC info via boot_params so EFI * config table doesn't need to be searched again during early startup diff --git a/arch/x86/include/asm/sev-common.h b/arch/x86/include/asm/sev-c= ommon.h index b463fcbd4b90..68a8cdf6fd6a 100644 --- a/arch/x86/include/asm/sev-common.h +++ b/arch/x86/include/asm/sev-common.h @@ -159,6 +159,10 @@ struct snp_psc_desc { #define GHCB_TERM_NOT_VMPL0 3 /* SNP guest is not running at VMPL-0 */ #define GHCB_TERM_CPUID 4 /* CPUID-validation failure */ #define GHCB_TERM_CPUID_HV 5 /* CPUID failure during hypervisor fallback = */ +#define GHCB_TERM_SECRETS_PAGE 6 /* Secrets page failure */ +#define GHCB_TERM_NO_SVSM 7 /* SVSM is not advertised in the secrets page= */ +#define GHCB_TERM_SVSM_VMPL0 8 /* SVSM is present but has set VMPL to 0 */ +#define GHCB_TERM_SVSM_CAA 9 /* SVSM is present but the CA is not page al= igned */ =20 #define GHCB_RESP_CODE(v) ((v) & GHCB_MSR_INFO_MASK) =20 diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 9477b4053bce..891e7d9a1f66 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -152,9 +152,32 @@ struct snp_secrets_page_layout { u8 vmpck2[VMPCK_KEY_LEN]; u8 vmpck3[VMPCK_KEY_LEN]; struct secrets_os_area os_area; - u8 rsvd3[3840]; + + u8 vmsa_tweak_bitmap[64]; + + /* SVSM fields */ + u64 svsm_base; + u64 svsm_size; + u64 svsm_caa; + u32 svsm_max_version; + u8 svsm_guest_vmpl; + u8 rsvd3[3]; + + /* Remainder of page */ + u8 rsvd4[3744]; } __packed; =20 +/* + * The SVSM Calling Area (CA) related structures. + */ +struct svsm_ca { + u8 call_pending; + u8 mem_available; + u8 rsvd1[6]; + + u8 svsm_buffer[PAGE_SIZE - 8]; +}; + #ifdef CONFIG_AMD_MEM_ENCRYPT extern void __sev_es_ist_enter(struct pt_regs *regs); extern void __sev_es_ist_exit(void); diff --git a/arch/x86/kernel/sev-shared.c b/arch/x86/kernel/sev-shared.c index 8b04958da5e7..66d33292eb78 100644 --- a/arch/x86/kernel/sev-shared.c +++ b/arch/x86/kernel/sev-shared.c @@ -111,6 +111,24 @@ sev_es_terminate(unsigned int set, unsigned int reason) asm volatile("hlt\n" : : : "memory"); } =20 +static bool running_at_vmpl0(void *va) +{ + u64 attrs; + + /* + * RMPADJUST modifies RMP permissions of a lesser-privileged (numerically + * higher) privilege level. Here, clear the VMPL1 permission mask of the + * GHCB page. If the guest is not running at VMPL0, this will fail. + * + * If the guest is running at VMPL0, it will succeed. Even if that operat= ion + * modifies permission bits, it is still ok to do so currently because Li= nux + * SNP guests running at VMPL0 only run at VMPL0, so VMPL1 or higher + * permission mask changes are a don't-care. + */ + attrs =3D 1; + return !rmpadjust((unsigned long)va, RMP_PG_SIZE_4K, attrs); +} + /* * The hypervisor features are available from GHCB version 2 onward. */ @@ -1267,3 +1285,49 @@ static enum es_result vc_check_opcode_bytes(struct e= s_em_ctxt *ctxt, =20 return ES_UNSUPPORTED; } + +/* + * Maintain the GPA of the SVSM Calling Area (CA) in order to utilize the = SVSM + * services needed when not running in VMPL0. + */ +static void __head setup_svsm_ca(const struct cc_blob_sev_info *cc_info) +{ + struct snp_secrets_page_layout *secrets_page; + u64 caa; + + BUILD_BUG_ON(sizeof(*secrets_page) !=3D PAGE_SIZE); + + /* + * Use __pa() since this routine is running identity mapped when + * called, both by the decompressor code and the early kernel code. + */ + if (running_at_vmpl0((void *)__pa(&boot_ghcb_page))) + return; + + /* + * Not running at VMPL0, ensure everything has been properly supplied + * for running under an SVSM. + */ + if (!cc_info || !cc_info->secrets_phys || cc_info->secrets_len !=3D PAGE_= SIZE) + sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_SECRETS_PAGE); + + secrets_page =3D (struct snp_secrets_page_layout *)cc_info->secrets_phys; + if (!secrets_page->svsm_size) + sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_NO_SVSM); + + if (!secrets_page->svsm_guest_vmpl) + sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_SVSM_VMPL0); + + vmpl =3D secrets_page->svsm_guest_vmpl; + + caa =3D secrets_page->svsm_caa; + if (!PAGE_ALIGNED(caa)) + sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_SVSM_CAA); + + /* + * The CA is identity mapped when this routine is called, both by the + * decompressor code and the early kernel code. + */ + boot_svsm_caa =3D (struct svsm_ca *)caa; + boot_svsm_caa_pa =3D caa; +} diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index b59b09c2f284..64799a04feb4 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -135,6 +135,15 @@ struct ghcb_state { static DEFINE_PER_CPU(struct sev_es_runtime_data*, runtime_data); static DEFINE_PER_CPU(struct sev_es_save_area *, sev_vmsa); =20 +/* + * SVSM related information: + * When running under an SVSM, the VMPL that Linux is executing at must = be + * non-zero. The VMPL is therefore used to indicate the presence of an S= VSM. + */ +static u8 vmpl __ro_after_init; +static struct svsm_ca *boot_svsm_caa __ro_after_init; +static u64 boot_svsm_caa_pa __ro_after_init; + struct sev_config { __u64 debug : 1, =20 @@ -2122,6 +2131,13 @@ bool __head snp_init(struct boot_params *bp) =20 setup_cpuid_table(cc_info); =20 + /* + * Record the SVSM Calling Area address (CAA) if the guest is not + * running at VMPL0. The CA will be used to communicate with the + * SVSM to perform the SVSM services. + */ + setup_svsm_ca(cc_info); + /* * The CC blob will be used later to access the secrets page. Cache * it here like the boot kernel does. --=20 2.43.2 From nobody Tue Feb 10 19:10:40 2026 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2054.outbound.protection.outlook.com [40.107.220.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5581C823DF for ; Mon, 25 Mar 2024 22:27:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.54 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711405637; cv=fail; b=hQYYcijRMzYwL0zV/igo9lD3MEkvJLXoeX2TzZlYsmGxTiyB+8m1MjkDlyNgefaJNrB1EGsI8+lF8GnC5qN59uwUKaLfP2vVzrfVUqFRIulZglCkcP8ldWPjeU3RgxDVRMTXHR/5N3UqvuNlEu+Dx2s/BzGhec0UxsRAcmsVZI4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711405637; c=relaxed/simple; bh=3YI47tA64VfPE5YhZPBic049PelyM/d5oqUT2AH5ZL0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=q7fGoQgf4PK1x2mj/v5no87TQIIEncEoP41MYWepylsdeyN67wjph57+lGs9AJBG/W+oebDOIciDR/S/dZmGVD2s98CEmkNcXzcRFZW6IzAqN1SqmTgnzLlc2t/2byEl/ugAICxMD0zkV9IvOvWbGprUmkiDtP1H/+9XjdSbwAA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=Kh9THjYd; arc=fail smtp.client-ip=40.107.220.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="Kh9THjYd" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R9jKOTgYsB64o2kewm6nb6KyL+YZuzbEjXHiohtVWHheHJ82AIkJdc3XBw+meOO2sBNIljXitZFRhaZLfPrahm5YKD/e1XI4vDh3WsL69guT6S64sOfmzHZX0h05txOmj770tpjnM6fNSWc2wa0OAP6/ebpmQrbRfN75ldIDElbM2Y1Dz49oB3eMhM8Ftb9PRIc5pjgpMrJQ0I7yjjoscrfxg+4Z1C2Oie7mYd8GIMElhh5ybEeEYc6GWJVKxTfLP0vc9OyeGCEvX9i10ByMbD135GsuG7kv3qj2g8O9LDxw8tisOCtHgkl2+8d5y240IRzzjK+hY/DvzoTAjOr65g== 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=AJbmdbB4Yrwx0JJuNiBP9vbEUDNeSn9lZwoulR8aD/w=; b=VzV4/9lrY2SMLoje5b3TtPLU4KaRD3L+JEL7CkQfnyiZP0tNLgNET68xUknvBspFTBCHu4igolgiUOoaJRu/y34+0xUxnZHZLfRZ8rgGqBCmA2IfXwpy/ATXOQSsqXl3g2JZa/RfjD+QJSB9i+IlIvQD0oLiCohvzEQqpho5Zk8lCglcBekFx2BLrlBAWpEM8YnGsB+aw4YPQWtS3dex1AQiYn6llJqXwfzVSXy7LiM35AoIYxpQTkvOi17bdOiwJNLC7bwPdrJ3aYBcQZC/kGjVpfcDSANV3sfMCLkVXAhLPJlpaC97zPo3MahmO9ccRsYqrSc590uBJfO5Z9a6lA== 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 (0) 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=AJbmdbB4Yrwx0JJuNiBP9vbEUDNeSn9lZwoulR8aD/w=; b=Kh9THjYdnb3t6qP+zCaXnYNZ6VyJUrh05jKNbriHCX260eNzb4I6ZGqfCUofWcQoxFirv9fG4hqQdTjZj8fDfDlnZOHspJBFNILCFKq6WuO8mIt237OZH4IZQC5S0bnDdDnKreNBN9lQx59oa552bNTUtozLEKGTDU0XahgdnLc= Received: from SJ0PR05CA0092.namprd05.prod.outlook.com (2603:10b6:a03:334::7) by DS0PR12MB8442.namprd12.prod.outlook.com (2603:10b6:8:125::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.31; Mon, 25 Mar 2024 22:27:13 +0000 Received: from SJ1PEPF00001CDC.namprd05.prod.outlook.com (2603:10b6:a03:334:cafe::cf) by SJ0PR05CA0092.outlook.office365.com (2603:10b6:a03:334::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.12 via Frontend Transport; Mon, 25 Mar 2024 22:27:12 +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 SJ1PEPF00001CDC.mail.protection.outlook.com (10.167.242.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Mon, 25 Mar 2024 22:27:12 +0000 Received: from tlendack-t1.amdoffice.net (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.35; Mon, 25 Mar 2024 17:27:11 -0500 From: Tom Lendacky To: , , , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , "Peter Zijlstra" , Dan Williams , Michael Roth , Ashish Kalra Subject: [PATCH v3 04/14] x86/sev: Use kernel provided SVSM Calling Areas Date: Mon, 25 Mar 2024 17:26:23 -0500 Message-ID: <9318f3ebc1f5692bfc90b5b995ef7e936cb31a5c.1711405593.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: SJ1PEPF00001CDC:EE_|DS0PR12MB8442:EE_ X-MS-Office365-Filtering-Correlation-Id: fcafe51b-18da-44a4-a075-08dc4d1ab7e1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ok0ejEZJnNW2YKOM4UyxNbIp4oooc6799Gqj8opZhMLll144TO2h12mOakyHy/OZ+TDwWWTCuBgRMRgLh/reHr9lYfMQjZGJ6n+BMJKQl5VWEkCyXqdxbrH5A20xttko1jzZTwFgcbBSRQWtPfwKzq1C110txhCmt1LgViqto03cL8c+BT2PPxCrpn9RUjTveIYZ/D73Fj/adlHrfCM1jiU+54LTNl4ddzCR/9vAuKBars0cq8fzGvSYu/VCMmot9duaL8/AwSb+dh40Cy+OR+yQp2rdkHwvKDTNVUe43mBxhcWxJGM3+8wMK/cOgEMHp0S8HB64OLiJKVcgzK04Ge0JnvLIBsxrb89v66j8OWD8PqNpKxDz4FDx6YVF74xt1DMwPAX5J00q4Gkg0do6qEx5vBN18Fcmq/ig8vMC/0KJ6ZO8qno+NYN6iQS4nlTcfoNCJ0hFtCHEYf3YEm+ZfAxJ3M4IQ1QXRe3jI7VnONZd67LsXLFE5f3/6P5lqFwlLLJx1jT7KK/aT3kP5jFoljD0SCx182BKAFEgkj+xq/drjhT72slUM6bcLpganIyjiBVjlcHVCVDJZy44hKLfEmcs9TD8DtyabXWn56+u67x6fCi7tMnVb7wIn/V/LZv6FI5lSgvVkRrcGSd3zV6OhuHeevMnOBrTms7Fkfm0ZHbnW4xfXI+ceZ2qm7J0r5z7o0gYMtL2C5Y3/1UV7LIlpVZBAzENEROZmQG6CsRTS8A9sQQm0T4vuh0XhypVWSUT 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)(7416005)(1800799015)(376005)(36860700004)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2024 22:27:12.7867 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fcafe51b-18da-44a4-a075-08dc4d1ab7e1 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: SJ1PEPF00001CDC.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8442 Content-Type: text/plain; charset="utf-8" The SVSM Calling Area (CA) is used to communicate between Linux and the SVSM. Since the firmware supplied CA for the BSP is likely to be in reserved memory, switch off that CA to a kernel provided CA so that access and use of the CA is available during boot. The CA switch is done using the SVSM core protocol SVSM_CORE_REMAP_CA call. An SVSM call is executed by filling out the SVSM CA and setting the proper register state as documented by the SVSM protocol. The SVSM is invoked by by requesting the hypervisor to run VMPL0. Once it is safe to allocate/reserve memory, allocate a CA for each CPU. After allocating the new CAs, the BSP will switch from the boot CA to the per-CPU CA. The CA for an AP is identified to the SVSM when creating the VMSA in preparation for booting the AP. Signed-off-by: Tom Lendacky Reviewed-by: Pankaj Gupta --- arch/x86/include/asm/sev-common.h | 13 ++ arch/x86/include/asm/sev.h | 32 +++++ arch/x86/include/uapi/asm/svm.h | 1 + arch/x86/kernel/sev-shared.c | 94 +++++++++++++- arch/x86/kernel/sev.c | 205 +++++++++++++++++++++++++----- arch/x86/mm/mem_encrypt_amd.c | 8 +- 6 files changed, 318 insertions(+), 35 deletions(-) diff --git a/arch/x86/include/asm/sev-common.h b/arch/x86/include/asm/sev-c= ommon.h index 68a8cdf6fd6a..71db5ba020b9 100644 --- a/arch/x86/include/asm/sev-common.h +++ b/arch/x86/include/asm/sev-common.h @@ -96,6 +96,19 @@ enum psc_op { /* GHCBData[63:32] */ \ (((u64)(val) & GENMASK_ULL(63, 32)) >> 32) =20 +/* GHCB Run at VMPL Request/Response */ +#define GHCB_MSR_VMPL_REQ 0x016 +#define GHCB_MSR_VMPL_REQ_LEVEL(v) \ + /* GHCBData[39:32] */ \ + (((u64)(v) & GENMASK_ULL(7, 0) << 32) | \ + /* GHCBDdata[11:0] */ \ + GHCB_MSR_VMPL_REQ) + +#define GHCB_MSR_VMPL_RESP 0x017 +#define GHCB_MSR_VMPL_RESP_VAL(v) \ + /* GHCBData[63:32] */ \ + (((u64)(v) & GENMASK_ULL(63, 32)) >> 32) + /* GHCB Hypervisor Feature Request/Response */ #define GHCB_MSR_HV_FT_REQ 0x080 #define GHCB_MSR_HV_FT_RESP 0x081 diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 891e7d9a1f66..4aa36905b047 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -178,6 +178,36 @@ struct svsm_ca { u8 svsm_buffer[PAGE_SIZE - 8]; }; =20 +#define SVSM_SUCCESS 0 +#define SVSM_ERR_INCOMPLETE 0x80000000 +#define SVSM_ERR_UNSUPPORTED_PROTOCOL 0x80000001 +#define SVSM_ERR_UNSUPPORTED_CALL 0x80000002 +#define SVSM_ERR_INVALID_ADDRESS 0x80000003 +#define SVSM_ERR_INVALID_FORMAT 0x80000004 +#define SVSM_ERR_INVALID_PARAMETER 0x80000005 +#define SVSM_ERR_INVALID_REQUEST 0x80000006 +#define SVSM_ERR_BUSY 0x80000007 + +/* + * SVSM protocol structure + */ +struct svsm_call { + struct svsm_ca *caa; + u64 rax; + u64 rcx; + u64 rdx; + u64 r8; + u64 r9; + u64 rax_out; + u64 rcx_out; + u64 rdx_out; + u64 r8_out; + u64 r9_out; +}; + +#define SVSM_CORE_CALL(x) ((0ULL << 32) | (x)) +#define SVSM_CORE_REMAP_CA 0 + #ifdef CONFIG_AMD_MEM_ENCRYPT extern void __sev_es_ist_enter(struct pt_regs *regs); extern void __sev_es_ist_exit(void); @@ -253,6 +283,7 @@ u64 snp_get_unsupported_features(u64 status); u64 sev_get_status(void); void kdump_sev_callback(void); void sev_show_status(void); +void snp_remap_svsm_ca(void); #else static inline void sev_es_ist_enter(struct pt_regs *regs) { } static inline void sev_es_ist_exit(void) { } @@ -283,6 +314,7 @@ static inline u64 snp_get_unsupported_features(u64 stat= us) { return 0; } static inline u64 sev_get_status(void) { return 0; } static inline void kdump_sev_callback(void) { } static inline void sev_show_status(void) { } +static inline void snp_remap_svsm_ca(void) { } #endif =20 #ifdef CONFIG_KVM_AMD_SEV diff --git a/arch/x86/include/uapi/asm/svm.h b/arch/x86/include/uapi/asm/sv= m.h index 80e1df482337..1814b413fd57 100644 --- a/arch/x86/include/uapi/asm/svm.h +++ b/arch/x86/include/uapi/asm/svm.h @@ -115,6 +115,7 @@ #define SVM_VMGEXIT_AP_CREATE_ON_INIT 0 #define SVM_VMGEXIT_AP_CREATE 1 #define SVM_VMGEXIT_AP_DESTROY 2 +#define SVM_VMGEXIT_SNP_RUN_VMPL 0x80000018 #define SVM_VMGEXIT_HV_FEATURES 0x8000fffd #define SVM_VMGEXIT_TERM_REQUEST 0x8000fffe #define SVM_VMGEXIT_TERM_REASON(reason_set, reason_code) \ diff --git a/arch/x86/kernel/sev-shared.c b/arch/x86/kernel/sev-shared.c index 66d33292eb78..78d2b9f570de 100644 --- a/arch/x86/kernel/sev-shared.c +++ b/arch/x86/kernel/sev-shared.c @@ -18,9 +18,11 @@ #define sev_printk_rtl(fmt, ...) printk_ratelimited(fmt, ##__VA_ARGS__) #else #undef WARN -#define WARN(condition, format...) (!!(condition)) +#define WARN(condition, format...) (!!(condition)) #define sev_printk(fmt, ...) #define sev_printk_rtl(fmt, ...) +#undef vc_forward_exception +#define vc_forward_exception(c) panic("SNP: Hypervisor requested exceptio= n\n") #endif =20 /* I/O parameters for CPUID-related helpers */ @@ -247,6 +249,96 @@ static enum es_result verify_exception_info(struct ghc= b *ghcb, struct es_em_ctxt return ES_VMM_ERROR; } =20 +static __always_inline void issue_svsm_call(struct svsm_call *call, u8 *pe= nding) +{ + /* + * Issue the VMGEXIT to run the SVSM: + * - Load the SVSM register state (RAX, RCX, RDX, R8 and R9) + * - Set the CA call pending field to 1 + * - Issue VMGEXIT + * - Save the SVSM return register state (RAX, RCX, RDX, R8 and R9) + * - Perform atomic exchange of the CA call pending field + */ + asm volatile("mov %9, %%r8\n\t" + "mov %10, %%r9\n\t" + "movb $1, %11\n\t" + "rep; vmmcall\n\t" + "mov %%r8, %3\n\t" + "mov %%r9, %4\n\t" + "xchgb %5, %11\n\t" + : "=3Da" (call->rax_out), "=3Dc" (call->rcx_out), "=3Dd" (call->rdx= _out), + "=3Dm" (call->r8_out), "=3Dm" (call->r9_out), + "+r" (*pending) + : "a" (call->rax), "c" (call->rcx), "d" (call->rdx), + "r" (call->r8), "r" (call->r9), + "m" (call->caa->call_pending) + : "r8", "r9", "memory"); +} + +static int __svsm_msr_protocol(struct svsm_call *call) +{ + u64 val, resp; + u8 pending; + + val =3D sev_es_rd_ghcb_msr(); + + sev_es_wr_ghcb_msr(GHCB_MSR_VMPL_REQ_LEVEL(0)); + + pending =3D 0; + issue_svsm_call(call, &pending); + + resp =3D sev_es_rd_ghcb_msr(); + + sev_es_wr_ghcb_msr(val); + + if (pending) + return -EINVAL; + + if (GHCB_RESP_CODE(resp) !=3D GHCB_MSR_VMPL_RESP) + return -EINVAL; + + if (GHCB_MSR_VMPL_RESP_VAL(resp) !=3D 0) + return -EINVAL; + + return call->rax_out; +} + +static int __svsm_ghcb_protocol(struct ghcb *ghcb, struct svsm_call *call) +{ + struct es_em_ctxt ctxt; + u8 pending; + + vc_ghcb_invalidate(ghcb); + + /* Fill in protocol and format specifiers */ + ghcb->protocol_version =3D ghcb_version; + ghcb->ghcb_usage =3D GHCB_DEFAULT_USAGE; + + ghcb_set_sw_exit_code(ghcb, SVM_VMGEXIT_SNP_RUN_VMPL); + ghcb_set_sw_exit_info_1(ghcb, 0); + ghcb_set_sw_exit_info_2(ghcb, 0); + + sev_es_wr_ghcb_msr(__pa(ghcb)); + + pending =3D 0; + issue_svsm_call(call, &pending); + + if (pending) + return -EINVAL; + + switch (verify_exception_info(ghcb, &ctxt)) { + case ES_OK: + break; + case ES_EXCEPTION: + vc_forward_exception(&ctxt); + fallthrough; + default: + return -EINVAL; + } + + return call->rax_out; +} + static enum es_result sev_es_ghcb_hv_call(struct ghcb *ghcb, struct es_em_ctxt *ctxt, u64 exit_code, u64 exit_info_1, diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index 64799a04feb4..af5017ab9746 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -134,6 +134,8 @@ struct ghcb_state { =20 static DEFINE_PER_CPU(struct sev_es_runtime_data*, runtime_data); static DEFINE_PER_CPU(struct sev_es_save_area *, sev_vmsa); +static DEFINE_PER_CPU(struct svsm_ca *, svsm_caa); +static DEFINE_PER_CPU(u64, svsm_caa_pa); =20 /* * SVSM related information: @@ -141,6 +143,7 @@ static DEFINE_PER_CPU(struct sev_es_save_area *, sev_vm= sa); * non-zero. The VMPL is therefore used to indicate the presence of an S= VSM. */ static u8 vmpl __ro_after_init; +static struct svsm_ca boot_svsm_ca_page __aligned(PAGE_SIZE); static struct svsm_ca *boot_svsm_caa __ro_after_init; static u64 boot_svsm_caa_pa __ro_after_init; =20 @@ -158,11 +161,26 @@ struct sev_config { */ ghcbs_initialized : 1, =20 + /* + * A flag used to indicate when the per-CPU SVSM CA is to be + * used instead of the boot SVSM CA. + * + * For APs, the per-CPU SVSM CA is created as part of the AP + * bringup, so this flag can be used globally for the BSP and APs. + */ + cas_initialized : 1, + __reserved : 62; }; =20 static struct sev_config sev_cfg __read_mostly; =20 +static struct svsm_ca *__svsm_get_caa(void) +{ + return sev_cfg.cas_initialized ? this_cpu_read(svsm_caa) + : boot_svsm_caa; +} + static __always_inline bool on_vc_stack(struct pt_regs *regs) { unsigned long sp =3D regs->sp; @@ -580,6 +598,33 @@ static enum es_result vc_ioio_check(struct es_em_ctxt = *ctxt, u16 port, size_t si return ES_EXCEPTION; } =20 +static __always_inline void vc_forward_exception(struct es_em_ctxt *ctxt) +{ + long error_code =3D ctxt->fi.error_code; + int trapnr =3D ctxt->fi.vector; + + ctxt->regs->orig_ax =3D ctxt->fi.error_code; + + switch (trapnr) { + case X86_TRAP_GP: + exc_general_protection(ctxt->regs, error_code); + break; + case X86_TRAP_UD: + exc_invalid_op(ctxt->regs); + break; + case X86_TRAP_PF: + write_cr2(ctxt->fi.cr2); + exc_page_fault(ctxt->regs, error_code); + break; + case X86_TRAP_AC: + exc_alignment_check(ctxt->regs, error_code); + break; + default: + pr_emerg("Unsupported exception in #VC instruction emulation - can't con= tinue\n"); + BUG(); + } +} + /* Include code shared with pre-decompression boot stage */ #include "sev-shared.c" =20 @@ -608,6 +653,42 @@ static noinstr void __sev_put_ghcb(struct ghcb_state *= state) } } =20 +static int svsm_protocol(struct svsm_call *call) +{ + struct ghcb_state state; + unsigned long flags; + struct ghcb *ghcb; + int ret; + + /* + * This can be called very early in the boot, use native functions in + * order to avoid paravirt issues. + */ + flags =3D native_save_fl(); + if (flags & X86_EFLAGS_IF) + native_irq_disable(); + + if (sev_cfg.ghcbs_initialized) + ghcb =3D __sev_get_ghcb(&state); + else if (boot_ghcb) + ghcb =3D boot_ghcb; + else + ghcb =3D NULL; + + do { + ret =3D ghcb ? __svsm_ghcb_protocol(ghcb, call) + : __svsm_msr_protocol(call); + } while (ret =3D=3D SVSM_ERR_BUSY); + + if (sev_cfg.ghcbs_initialized) + __sev_put_ghcb(&state); + + if (flags & X86_EFLAGS_IF) + native_irq_enable(); + + return ret; +} + void noinstr __sev_es_nmi_complete(void) { struct ghcb_state state; @@ -1369,6 +1450,18 @@ static void __init alloc_runtime_data(int cpu) panic("Can't allocate SEV-ES runtime data"); =20 per_cpu(runtime_data, cpu) =3D data; + + if (vmpl) { + struct svsm_ca *caa; + + /* Allocate the SVSM CA page if an SVSM is present */ + caa =3D memblock_alloc(sizeof(*caa), PAGE_SIZE); + if (!caa) + panic("Can't allocate SVSM CA page\n"); + + per_cpu(svsm_caa, cpu) =3D caa; + per_cpu(svsm_caa_pa, cpu) =3D __pa(caa); + } } =20 static void __init init_ghcb(int cpu) @@ -1418,6 +1511,31 @@ void __init sev_es_init_vc_handling(void) init_ghcb(cpu); } =20 + /* If running under an SVSM, switch to the per-cpu CA */ + if (vmpl) { + struct svsm_call call =3D {}; + unsigned long flags; + int ret; + + local_irq_save(flags); + + /* + * SVSM_CORE_REMAP_CA call: + * RAX =3D 0 (Protocol=3D0, CallID=3D0) + * RCX =3D New CA GPA + */ + call.caa =3D __svsm_get_caa(); + call.rax =3D SVSM_CORE_CALL(SVSM_CORE_REMAP_CA); + call.rcx =3D this_cpu_read(svsm_caa_pa); + ret =3D svsm_protocol(&call); + if (ret !=3D SVSM_SUCCESS) + panic("Can't remap the SVSM CA, ret=3D%#x (%d)\n", ret, ret); + + sev_cfg.cas_initialized =3D true; + + local_irq_restore(flags); + } + sev_es_setup_play_dead(); =20 /* Secondary CPUs use the runtime #VC handler */ @@ -1842,33 +1960,6 @@ static enum es_result vc_handle_exitcode(struct es_e= m_ctxt *ctxt, return result; } =20 -static __always_inline void vc_forward_exception(struct es_em_ctxt *ctxt) -{ - long error_code =3D ctxt->fi.error_code; - int trapnr =3D ctxt->fi.vector; - - ctxt->regs->orig_ax =3D ctxt->fi.error_code; - - switch (trapnr) { - case X86_TRAP_GP: - exc_general_protection(ctxt->regs, error_code); - break; - case X86_TRAP_UD: - exc_invalid_op(ctxt->regs); - break; - case X86_TRAP_PF: - write_cr2(ctxt->fi.cr2); - exc_page_fault(ctxt->regs, error_code); - break; - case X86_TRAP_AC: - exc_alignment_check(ctxt->regs, error_code); - break; - default: - pr_emerg("Unsupported exception in #VC instruction emulation - can't con= tinue\n"); - BUG(); - } -} - static __always_inline bool is_vc2_stack(unsigned long sp) { return (sp >=3D __this_cpu_ist_bottom_va(VC2) && sp < __this_cpu_ist_top_= va(VC2)); @@ -2118,6 +2209,50 @@ static __head struct cc_blob_sev_info *find_cc_blob(= struct boot_params *bp) return cc_info; } =20 +static __head void setup_svsm(struct cc_blob_sev_info *cc_info) +{ + struct svsm_call call =3D {}; + int ret; + u64 pa; + + /* + * Record the SVSM Calling Area address (CAA) if the guest is not + * running at VMPL0. The CA will be used to communicate with the + * SVSM to perform the SVSM services. + */ + setup_svsm_ca(cc_info); + + /* Nothing to do if not running under an SVSM. */ + if (!vmpl) + return; + + /* + * It is very early in the boot and the kernel is running identity + * mapped but without having adjusted the pagetables to where the + * kernel was loaded (physbase), so the get the CA address using + * RIP-relative addressing. + */ + pa =3D (u64)&RIP_REL_REF(boot_svsm_ca_page); + + /* + * Switch over to the boot SVSM CA while the current CA is still + * addressable. There is no GHCB at this point so use the MSR protocol. + * + * SVSM_CORE_REMAP_CA call: + * RAX =3D 0 (Protocol=3D0, CallID=3D0) + * RCX =3D New CA GPA + */ + call.caa =3D __svsm_get_caa(); + call.rax =3D SVSM_CORE_CALL(SVSM_CORE_REMAP_CA); + call.rcx =3D pa; + ret =3D svsm_protocol(&call); + if (ret !=3D SVSM_SUCCESS) + panic("Can't remap the SVSM CA, ret=3D%#x (%d)\n", ret, ret); + + boot_svsm_caa =3D (struct svsm_ca *)pa; + boot_svsm_caa_pa =3D pa; +} + bool __head snp_init(struct boot_params *bp) { struct cc_blob_sev_info *cc_info; @@ -2131,12 +2266,7 @@ bool __head snp_init(struct boot_params *bp) =20 setup_cpuid_table(cc_info); =20 - /* - * Record the SVSM Calling Area address (CAA) if the guest is not - * running at VMPL0. The CA will be used to communicate with the - * SVSM to perform the SVSM services. - */ - setup_svsm_ca(cc_info); + setup_svsm(cc_info); =20 /* * The CC blob will be used later to access the secrets page. Cache @@ -2328,3 +2458,12 @@ void sev_show_status(void) } pr_cont("\n"); } + +void __init snp_remap_svsm_ca(void) +{ + if (!vmpl) + return; + + /* Update the CAA to a proper kernel address */ + boot_svsm_caa =3D &boot_svsm_ca_page; +} diff --git a/arch/x86/mm/mem_encrypt_amd.c b/arch/x86/mm/mem_encrypt_amd.c index 70b91de2e053..8943286f9fdc 100644 --- a/arch/x86/mm/mem_encrypt_amd.c +++ b/arch/x86/mm/mem_encrypt_amd.c @@ -2,7 +2,7 @@ /* * AMD Memory Encryption Support * - * Copyright (C) 2016 Advanced Micro Devices, Inc. + * Copyright (C) 2016-2024 Advanced Micro Devices, Inc. * * Author: Tom Lendacky */ @@ -492,6 +492,12 @@ void __init sme_early_init(void) */ if (sev_status & MSR_AMD64_SEV_ENABLED) ia32_disable(); + + /* + * Switch the SVSM CA mapping (if active) from identity mapped to + * kernel mapped. + */ + snp_remap_svsm_ca(); } =20 void __init mem_encrypt_free_decrypted_mem(void) --=20 2.43.2 From nobody Tue Feb 10 19:10:40 2026 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2057.outbound.protection.outlook.com [40.107.92.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63D0A73175 for ; Mon, 25 Mar 2024 22:27:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711405649; cv=fail; b=O+OxAWgoWS86XNwRg4rBi21Toa09F7JrDgRfXTsOB5dMpkyWAozc1W/BMseI3+DZzPqeZFRV4HXvMfHwS7gjyy5228L3dNS7Zh0iDYpbyvgJDf/fCf3rQD1dsPyZiXtSCwGvgE/Gb8RiH78Q5bIMzkYvgmXFQEW1/ZTE0QdU3xg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711405649; c=relaxed/simple; bh=xgZ9oC/wPG6vU4Kjtv6sCsL4G08D3NrdT5eDTMyX4ao=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MzYwinC36V3beY6UKp/tQ0hz9HShXL9d2c/g8DJqxqswjYA+Ar9nK1mpTvQ280JR99qE7t4JQyCSwIC8FVeI0ZGsFHZzPh5g0kCRAZIF6k8pLPHFbrCQeeNwhR4Cfz6oGs+hwSlwUTN4QpQ3mdCjZtHmO13JqFAVbMwNeiz+alk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=0gHTaVQZ; arc=fail smtp.client-ip=40.107.92.57 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="0gHTaVQZ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f9XdD4LTsiXNKoDNQQZt578bHB65MVBgA10A6+iNyyiUIdy9kaEEIBdEKGUhs/FBXH6JNio0wOpTgn91QuyKbPOZO5gIowqzpEt7CMkSVqaxWPVVxQA9DWgaaj3oHqxLrKAyrL62eqKyj06AqAtvVCKMbOnsHkgKxco+n+glL6i3VSROz/Sl49xfOTy3s5JFEhMZ103RzBADskUEF/bG75R8POVLy/y37aBo2KB2RggoTYNuPNnMWyy0RAFD+VYgie9QyxN1KM3ZsrHnukWikfFbj1qvUN4fH4Nb2QSeYz98MBEuoWqVDiqacVVf9FoErBsv6NOTFGH88GZ5hG/Sow== 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=mQy/AAAIqsf19LIMZDnbL7cJdKBhGNCP0aelG2Ws77g=; b=WMoxoE5iGtcZ9XXJAvFaBle5Lpgt6VQ1uaHVvGE6nFBysQrwGRa54UBScMgqNioy8iutoa0f6C2zBx0a1uWinMzPx5yXNEcbt6bO24ymEodYzXjrFzg/8t3XV+ko7kV04fGklaIhuv96FkPyEQj1WMoc/v2awNivJJ2uUO5a6tU4+Nq38ekA5FbCKfdJogSb7e7BAoTaE6fOvFYLZuwCIIypZkASrVtLCSlHZBJwObIuyOABuHl8jUUclO/lttwuYfv+s8RjWZWI/oy9LfHHK+chylAPNdOWdW2XN8XSibmCBPEGEFVKsC90P5aoxY+2TtJyOsuf+jL/erdm6WGLIg== 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 (0) 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=mQy/AAAIqsf19LIMZDnbL7cJdKBhGNCP0aelG2Ws77g=; b=0gHTaVQZr0+WQVi9JF1lUjBd6Idyux75UTus+ug5ZJ0BRX0jekLn1iE3cs6KmGuv7xf2eyNW8iY/N14XWHFH/q/8wtYyD98eJHmWS2sIp20IBfVsO7kMYzsMaEtvXqs5tA29dSlfI3lS39P1/fskn1EGpVj8Dypda+XSGqEoCio= Received: from SJ0PR05CA0006.namprd05.prod.outlook.com (2603:10b6:a03:33b::11) by DM4PR12MB8524.namprd12.prod.outlook.com (2603:10b6:8:18d::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.31; Mon, 25 Mar 2024 22:27:20 +0000 Received: from SJ1PEPF00001CDE.namprd05.prod.outlook.com (2603:10b6:a03:33b:cafe::d6) by SJ0PR05CA0006.outlook.office365.com (2603:10b6:a03:33b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.12 via Frontend Transport; Mon, 25 Mar 2024 22:27:20 +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 SJ1PEPF00001CDE.mail.protection.outlook.com (10.167.242.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Mon, 25 Mar 2024 22:27:19 +0000 Received: from tlendack-t1.amdoffice.net (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.35; Mon, 25 Mar 2024 17:27:18 -0500 From: Tom Lendacky To: , , , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , "Peter Zijlstra" , Dan Williams , Michael Roth , Ashish Kalra Subject: [PATCH v3 05/14] x86/sev: Perform PVALIDATE using the SVSM when not at VMPL0 Date: Mon, 25 Mar 2024 17:26:24 -0500 Message-ID: <2edc2899e35b6eced2778eba4cf9388586c2b97e.1711405593.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: SJ1PEPF00001CDE:EE_|DM4PR12MB8524:EE_ X-MS-Office365-Filtering-Correlation-Id: 0883c65b-cf8b-4ddd-2283-08dc4d1abc74 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /FMFuAozrXWLO8lRRaTIlKSm51qykxz9QziSmhXcD7lb9sQZhzUyqey6z9V72FWXIXPsKEVGVIlBAoCxYSkCelLAaEVgNBzqzH+aaJnxWDiWvHFhfX0mrEG5sQXyu9U7AcGmXoJQYlhghPN/wBG6WQ6XI7UW/hwXAu2zqtbJAxmIx22gccoS6xKlNzG6T2GYy0tkRKUCkB1vvFL9uYYjP+tFy076mFQAsOa6voVnDgvlj6c83UqC3GnZqqrnf0A0IIAKQ/SItuigMv3myjaudUrVxJWeyxaCifLhhKgKhTeI4TqeFRFimaP2Lpesj4xZ1z/U460Vi4GFNCf4Pi1vfUqD9WT+xpUKLNcYKpd2RjteSXZRexexL/QCyr6t5syn60Q4tig2j4izoz0YgXLAVleAYReKntMemLq8OCnfGn4Cp2GInK+rW9Q4zrG15LWqa8SrcZP4S9mO34JI4rKb8zjeCfcIZ7dNMExS+rWyrnm8X5neuJGWZItItHe+1pwLo8yBn5KB3uu76sAkC7KOb/jd6kvtulslc2n770A2gDr8G91S9cm5++egp7UvZhFJk03WkIB3LcnpUZSHX+Hx/cuoB66AIsaA5jp0gofMnbrv/GepDMICvb6zR3n7ljgbv7GHY2+Sq2XiyGoSKK5Y0VZdRkL75y2NtmCCN/izkqC6Rd/wnDMD2NErZrIx8jlnk7vSf7yY8IAN1JLVlmzp96uz1qYLh0n2tliiAo6fTyhOGgUSi3yPleUcDBFFGwuv 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)(7416005)(1800799015)(376005)(36860700004)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2024 22:27:19.9890 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0883c65b-cf8b-4ddd-2283-08dc4d1abc74 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: SJ1PEPF00001CDE.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB8524 Content-Type: text/plain; charset="utf-8" The PVALIDATE instruction can only be performed at VMPL0. An SVSM will be present when running at VMPL1 or a lower privilege level. When an SVSM is present, use the SVSM_CORE_PVALIDATE call to perform memory validation instead of issuing the PVALIDATE instruction directly. The validation of a single 4K page is now explicitly identified as such in the function name, pvalidate_4k_page(). The pvalidate_pages() function is used for validating 1 or more pages at either 4K or 2M in size. Each function, however, determines whether it can issue the PVALIDATE directly or whether the SVSM needs to be invoked. Signed-off-by: Tom Lendacky --- arch/x86/boot/compressed/sev.c | 45 ++++++++- arch/x86/include/asm/sev.h | 22 +++++ arch/x86/kernel/sev-shared.c | 176 ++++++++++++++++++++++++++++++++- arch/x86/kernel/sev.c | 25 +++-- 4 files changed, 250 insertions(+), 18 deletions(-) diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c index fe61ff630c7e..f8407ee83ac8 100644 --- a/arch/x86/boot/compressed/sev.c +++ b/arch/x86/boot/compressed/sev.c @@ -39,6 +39,16 @@ static u8 vmpl __section(".data"); static u64 boot_svsm_caa_pa __section(".data"); static struct svsm_ca *boot_svsm_caa __section(".data"); =20 +static struct svsm_ca *__svsm_get_caa(void) +{ + return boot_svsm_caa; +} + +static u64 __svsm_get_caa_pa(void) +{ + return boot_svsm_caa_pa; +} + /* * Copy a version of this function here - insn-eval.c can't be used in * pre-decompression code. @@ -139,6 +149,24 @@ static bool fault_in_kernel_space(unsigned long addres= s) /* Include code for early handlers */ #include "../../kernel/sev-shared.c" =20 +static int svsm_protocol(struct svsm_call *call) +{ + struct ghcb *ghcb; + int ret; + + if (boot_ghcb) + ghcb =3D boot_ghcb; + else + ghcb =3D NULL; + + do { + ret =3D ghcb ? __svsm_ghcb_protocol(ghcb, call) + : __svsm_msr_protocol(call); + } while (ret =3D=3D SVSM_ERR_BUSY); + + return ret; +} + bool sev_snp_enabled(void) { return sev_status & MSR_AMD64_SEV_SNP_ENABLED; @@ -155,8 +183,8 @@ static void __page_state_change(unsigned long paddr, en= um psc_op op) * If private -> shared then invalidate the page before requesting the * state change in the RMP table. */ - if (op =3D=3D SNP_PAGE_STATE_SHARED && pvalidate(paddr, RMP_PG_SIZE_4K, 0= )) - sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_PVALIDATE); + if (op =3D=3D SNP_PAGE_STATE_SHARED) + pvalidate_4k_page(paddr, paddr, 0); =20 /* Issue VMGEXIT to change the page state in RMP table. */ sev_es_wr_ghcb_msr(GHCB_MSR_PSC_REQ_GFN(paddr >> PAGE_SHIFT, op)); @@ -171,8 +199,8 @@ static void __page_state_change(unsigned long paddr, en= um psc_op op) * Now that page state is changed in the RMP table, validate it so that i= t is * consistent with the RMP entry. */ - if (op =3D=3D SNP_PAGE_STATE_PRIVATE && pvalidate(paddr, RMP_PG_SIZE_4K, = 1)) - sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_PVALIDATE); + if (op =3D=3D SNP_PAGE_STATE_PRIVATE) + pvalidate_4k_page(paddr, paddr, 1); } =20 void snp_set_page_private(unsigned long paddr) @@ -265,6 +293,15 @@ void sev_es_shutdown_ghcb(void) if (!sev_es_check_cpu_features()) error("SEV-ES CPU Features missing."); =20 + /* + * The boot_ghcb value is used to determine whether to use the GHCB MSR + * protocol or the GHCB shared page to perform a GHCB request. Since the + * GHCB page is being changed to encrypted, it can't be used to perform + * GHCB requests. Clear the boot_ghcb variable so that the GHCB MSR + * protocol is used to change the GHCB page over to an encrypted page. + */ + boot_ghcb =3D NULL; + /* * GHCB Page must be flushed from the cache and mapped encrypted again. * Otherwise the running kernel will see strange cache effects when diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 4aa36905b047..204f0a4857d6 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -187,6 +187,27 @@ struct svsm_ca { #define SVSM_ERR_INVALID_PARAMETER 0x80000005 #define SVSM_ERR_INVALID_REQUEST 0x80000006 #define SVSM_ERR_BUSY 0x80000007 +#define SVSM_PVALIDATE_FAIL_SIZEMISMATCH 0x80001006 + +/* + * The SVSM PVALIDATE related structures + */ +struct svsm_pvalidate_entry { + u64 page_size : 2, + action : 1, + ignore_cf : 1, + rsvd : 8, + pfn : 52; +}; + +struct svsm_pvalidate_call { + u16 entries; + u16 next; + + u8 rsvd1[4]; + + struct svsm_pvalidate_entry entry[]; +}; =20 /* * SVSM protocol structure @@ -207,6 +228,7 @@ struct svsm_call { =20 #define SVSM_CORE_CALL(x) ((0ULL << 32) | (x)) #define SVSM_CORE_REMAP_CA 0 +#define SVSM_CORE_PVALIDATE 1 =20 #ifdef CONFIG_AMD_MEM_ENCRYPT extern void __sev_es_ist_enter(struct pt_regs *regs); diff --git a/arch/x86/kernel/sev-shared.c b/arch/x86/kernel/sev-shared.c index 78d2b9f570de..e63c0a6eccd6 100644 --- a/arch/x86/kernel/sev-shared.c +++ b/arch/x86/kernel/sev-shared.c @@ -87,6 +87,8 @@ static u32 cpuid_std_range_max __ro_after_init; static u32 cpuid_hyp_range_max __ro_after_init; static u32 cpuid_ext_range_max __ro_after_init; =20 +static int svsm_protocol(struct svsm_call *call); + static bool __init sev_es_check_cpu_features(void) { if (!has_cpuflag(X86_FEATURE_RDRAND)) { @@ -1189,7 +1191,65 @@ static void __head setup_cpuid_table(const struct cc= _blob_sev_info *cc_info) } } =20 -static void pvalidate_pages(struct snp_psc_desc *desc) +static int base_pvalidate_4k_page(unsigned long vaddr, bool validate) +{ + return pvalidate(vaddr, RMP_PG_SIZE_4K, validate); +} + +static int svsm_pvalidate_4k_page(unsigned long paddr, bool validate) +{ + struct svsm_pvalidate_call *pvalidate_call; + struct svsm_call call =3D {}; + u64 pvalidate_call_pa; + unsigned long flags; + int ret; + + /* + * This can be called very early in the boot, use native functions in + * order to avoid paravirt issues. + */ + flags =3D native_save_fl(); + if (flags & X86_EFLAGS_IF) + native_irq_disable(); + + call.caa =3D __svsm_get_caa(); + + pvalidate_call =3D (struct svsm_pvalidate_call *)call.caa->svsm_buffer; + pvalidate_call_pa =3D __svsm_get_caa_pa() + offsetof(struct svsm_ca, svsm= _buffer); + + pvalidate_call->entries =3D 1; + pvalidate_call->next =3D 0; + pvalidate_call->entry[0].page_size =3D RMP_PG_SIZE_4K; + pvalidate_call->entry[0].action =3D validate; + pvalidate_call->entry[0].ignore_cf =3D 0; + pvalidate_call->entry[0].pfn =3D paddr >> PAGE_SHIFT; + + /* Protocol 0, Call ID 1 */ + call.rax =3D SVSM_CORE_CALL(SVSM_CORE_PVALIDATE); + call.rcx =3D pvalidate_call_pa; + + ret =3D svsm_protocol(&call); + + if (flags & X86_EFLAGS_IF) + native_irq_enable(); + + return ret; +} + +static void pvalidate_4k_page(unsigned long vaddr, unsigned long paddr, bo= ol validate) +{ + int ret; + + ret =3D vmpl ? svsm_pvalidate_4k_page(paddr, validate) + : base_pvalidate_4k_page(vaddr, validate); + + if (ret) { + WARN(1, "Failed to validate address 0x%lx ret %d", vaddr, ret); + sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_PVALIDATE); + } +} + +static void base_pvalidate_pages(struct snp_psc_desc *desc) { struct psc_entry *e; unsigned long vaddr; @@ -1223,6 +1283,120 @@ static void pvalidate_pages(struct snp_psc_desc *de= sc) } } =20 +static void svsm_pvalidate_pages(struct snp_psc_desc *desc) +{ + struct svsm_pvalidate_call *pvalidate_call; + struct svsm_pvalidate_entry *pe; + unsigned int call_count, i; + struct svsm_call call =3D {}; + u64 pvalidate_call_pa; + struct psc_entry *e; + unsigned long flags; + unsigned long vaddr; + bool action; + int ret; + + /* + * This can be called very early in the boot, use native functions in + * order to avoid paravirt issues. + */ + flags =3D native_save_fl(); + if (flags & X86_EFLAGS_IF) + native_irq_disable(); + + call.caa =3D __svsm_get_caa(); + + pvalidate_call =3D (struct svsm_pvalidate_call *)call.caa->svsm_buffer; + pvalidate_call_pa =3D __svsm_get_caa_pa() + offsetof(struct svsm_ca, svsm= _buffer); + + /* Calculate how many entries the CA buffer can hold */ + call_count =3D sizeof(call.caa->svsm_buffer); + call_count -=3D offsetof(struct svsm_pvalidate_call, entry); + call_count /=3D sizeof(pvalidate_call->entry[0]); + + /* Protocol 0, Call ID 1 */ + call.rax =3D SVSM_CORE_CALL(SVSM_CORE_PVALIDATE); + call.rcx =3D pvalidate_call_pa; + + pvalidate_call->entries =3D 0; + pvalidate_call->next =3D 0; + + for (i =3D 0; i <=3D desc->hdr.end_entry; i++) { + e =3D &desc->entries[i]; + pe =3D &pvalidate_call->entry[pvalidate_call->entries]; + + pe->page_size =3D e->pagesize ? RMP_PG_SIZE_2M : RMP_PG_SIZE_4K; + pe->action =3D e->operation =3D=3D SNP_PAGE_STATE_PRIVATE; + pe->ignore_cf =3D 0; + pe->pfn =3D e->gfn; + + pvalidate_call->entries++; + if (pvalidate_call->entries < call_count && i !=3D desc->hdr.end_entry) + continue; + + ret =3D svsm_protocol(&call); + if (ret =3D=3D SVSM_PVALIDATE_FAIL_SIZEMISMATCH && + pvalidate_call->entry[pvalidate_call->next].page_size =3D=3D RMP_PG_= SIZE_2M) { + u64 pfn, pfn_end; + + /* + * The "next" field is the index of the failed entry. Calculate the + * index of the entry after the failed entry before the fields are + * cleared so that processing can continue on from that point (take + * into account the for loop adding 1 to the entry). + */ + i -=3D pvalidate_call->entries - pvalidate_call->next; + i +=3D 1; + + action =3D pvalidate_call->entry[pvalidate_call->next].action; + pfn =3D pvalidate_call->entry[pvalidate_call->next].pfn; + pfn_end =3D pfn + 511; + + pvalidate_call->entries =3D 0; + pvalidate_call->next =3D 0; + for (; pfn <=3D pfn_end; pfn++) { + pe =3D &pvalidate_call->entry[pvalidate_call->entries]; + + pe->page_size =3D RMP_PG_SIZE_4K; + pe->action =3D action; + pe->ignore_cf =3D 0; + pe->pfn =3D pfn; + + pvalidate_call->entries++; + if (pvalidate_call->entries < call_count && pfn !=3D pfn_end) + continue; + + ret =3D svsm_protocol(&call); + if (ret !=3D SVSM_SUCCESS) + break; + + pvalidate_call->entries =3D 0; + pvalidate_call->next =3D 0; + } + } + + if (ret !=3D SVSM_SUCCESS) { + pe =3D &pvalidate_call->entry[pvalidate_call->next]; + vaddr =3D (unsigned long)pfn_to_kaddr(pe->pfn); + + WARN(1, "Failed to validate address %lx ret=3D%#x (%d)", vaddr, ret, re= t); + sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_PVALIDATE); + } + + pvalidate_call->entries =3D 0; + pvalidate_call->next =3D 0; + } + + if (flags & X86_EFLAGS_IF) + native_irq_enable(); +} + +static void pvalidate_pages(struct snp_psc_desc *desc) +{ + vmpl ? svsm_pvalidate_pages(desc) + : base_pvalidate_pages(desc); +} + static int vmgexit_psc(struct ghcb *ghcb, struct snp_psc_desc *desc) { int cur_entry, end_entry, ret =3D 0; diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index af5017ab9746..d3e182d69d65 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -181,6 +181,12 @@ static struct svsm_ca *__svsm_get_caa(void) : boot_svsm_caa; } =20 +static u64 __svsm_get_caa_pa(void) +{ + return sev_cfg.cas_initialized ? this_cpu_read(svsm_caa_pa) + : boot_svsm_caa_pa; +} + static __always_inline bool on_vc_stack(struct pt_regs *regs) { unsigned long sp =3D regs->sp; @@ -798,7 +804,6 @@ early_set_pages_state(unsigned long vaddr, unsigned lon= g paddr, { unsigned long paddr_end; u64 val; - int ret; =20 vaddr =3D vaddr & PAGE_MASK; =20 @@ -806,12 +811,9 @@ early_set_pages_state(unsigned long vaddr, unsigned lo= ng paddr, paddr_end =3D paddr + (npages << PAGE_SHIFT); =20 while (paddr < paddr_end) { - if (op =3D=3D SNP_PAGE_STATE_SHARED) { - /* Page validation must be rescinded before changing to shared */ - ret =3D pvalidate(vaddr, RMP_PG_SIZE_4K, false); - if (WARN(ret, "Failed to validate address 0x%lx ret %d", paddr, ret)) - goto e_term; - } + /* Page validation must be rescinded before changing to shared */ + if (op =3D=3D SNP_PAGE_STATE_SHARED) + pvalidate_4k_page(vaddr, paddr, false); =20 /* * Use the MSR protocol because this function can be called before @@ -833,12 +835,9 @@ early_set_pages_state(unsigned long vaddr, unsigned lo= ng paddr, paddr, GHCB_MSR_PSC_RESP_VAL(val))) goto e_term; =20 - if (op =3D=3D SNP_PAGE_STATE_PRIVATE) { - /* Page validation must be performed after changing to private */ - ret =3D pvalidate(vaddr, RMP_PG_SIZE_4K, true); - if (WARN(ret, "Failed to validate address 0x%lx ret %d", paddr, ret)) - goto e_term; - } + /* Page validation must be performed after changing to private */ + if (op =3D=3D SNP_PAGE_STATE_PRIVATE) + pvalidate_4k_page(vaddr, paddr, true); =20 vaddr +=3D PAGE_SIZE; paddr +=3D PAGE_SIZE; --=20 2.43.2 From nobody Tue Feb 10 19:10:40 2026 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2062.outbound.protection.outlook.com [40.107.220.62]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 40B9076408 for ; Mon, 25 Mar 2024 22:27:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.62 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711405652; cv=fail; b=E9SiuKUPusyKdAha1cATbxB6DkmEAev5/+lQUDeJvHUsBjhjXcoq+yxaeQqDXsZJ/Aa+9ZiUFdezKL+RiGwmJy7/W/awnIZT/ErDQ0x/IF6ZYxvKBURIMwLX8vwXyuHGHO3Mj+VmQSAtjN1VEadFJFPdPTExkEBHFHm/uF77juk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711405652; c=relaxed/simple; bh=X2v5cEkAcRCX1dyqyKw7iILJUex4l2tWxy+ANKC2a74=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pLmAmcZzij4gGB8P/mFH8JMEr+NcWf3eOcQ6jjdaZkXLBp89eHcxxLmbYzqrsy2WuCcO9aen8MM4/RrSkid9/cVC26qHU+SiZRlhDVz3NlE9SzCj7jcfVqgLrqNfXX3IoFFmQ3yFJa6mXH9xg8KymH41LrIoAfQz+4cAQ0Ll88o= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=AjbQXagK; arc=fail smtp.client-ip=40.107.220.62 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="AjbQXagK" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LB+ldLuD1SxUUoI9qk2VlnrO3Mrrh8OnWpDM6GfTteZ+6ZKGWm7g38cXewo9fTm2cln403U7QDRPcddkmbDAIddOQC8EogM1NvXrLV1DMr9WOjB5kEQNRbpw7J2IhuDbV4qLKLzODHFC3J5JGKQMisEog/X6Hklrfrj9iaNeqmduWFr06jz8fB9q87Yix81hGl35J5W2OtJjWygb19FeP5uoFTOZo+kds87eIsPU0cyK1gowyy3P/GNUucwwK2qxrw1lBlB4dlEKxHdGQ7gIT7uOCVqfhnAqJxee7zKQCMgIdBu9AeMw8bqzIPa1p604YakGLkVBTI8wnB4Wjmjaeg== 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=aDtEpCB9mVaxWH0uRMNOlsWbvRGbagEam0dsVHi1Nsg=; b=KrXoGAM9t4ACprDH/Qq55UbU8us/f5NEQs55Ei/LnMxaFp6WghxjHTpEZCwluBEP9GsqnlpKpC5GCam7riuBw1OGJX/tkyVD7ACeJcMzWHA5zv8+8O4msv0JrkHeTah5SbnokEZBsKpU1+orQUep/ngiZbsOJcNVhWKq/Hesb2qFt7c5nxIK4flkJdJdtv8VyflOboXPo7f3MQJzPPWvJ71zIjv2oPbzp+cfF4S+xpK38IlrCUuh1xxwvJpAt2yRVa5MrrnRoVkU6i5qpkE4DY4utikx8wfWo4L3xaTESYLPSwGr7OevNMB1Nn+/nxkIbk8FT2pdF1SxbVpO8dy6tQ== 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 (0) 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=aDtEpCB9mVaxWH0uRMNOlsWbvRGbagEam0dsVHi1Nsg=; b=AjbQXagKt7U3wUWrdhFlHCWHeMXIDElEft3fwwN/h0fa6tVvPk/1NNWT7fDqm9sf+KrEjloN50XO1ePMkO91vwyszA8DNonISuQorsxbDplFB30mordYyupfzr/0paIoxfb7/IR3Kt5gVoZQ43pchoJ9mZgcyIAktXoGoMhhHjU= Received: from SJ0PR05CA0100.namprd05.prod.outlook.com (2603:10b6:a03:334::15) by PH7PR12MB6762.namprd12.prod.outlook.com (2603:10b6:510:1ac::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.31; Mon, 25 Mar 2024 22:27:27 +0000 Received: from SJ1PEPF00001CE1.namprd05.prod.outlook.com (2603:10b6:a03:334:cafe::f3) by SJ0PR05CA0100.outlook.office365.com (2603:10b6:a03:334::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.12 via Frontend Transport; Mon, 25 Mar 2024 22:27:27 +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 SJ1PEPF00001CE1.mail.protection.outlook.com (10.167.242.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Mon, 25 Mar 2024 22:27:27 +0000 Received: from tlendack-t1.amdoffice.net (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.35; Mon, 25 Mar 2024 17:27:26 -0500 From: Tom Lendacky To: , , , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , "Peter Zijlstra" , Dan Williams , Michael Roth , Ashish Kalra Subject: [PATCH v3 06/14] x86/sev: Use the SVSM to create a vCPU when not in VMPL0 Date: Mon, 25 Mar 2024 17:26:25 -0500 Message-ID: X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: SJ1PEPF00001CE1:EE_|PH7PR12MB6762:EE_ X-MS-Office365-Filtering-Correlation-Id: 63940f3a-ac36-420a-d5ef-08dc4d1ac058 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: K/oYJ+Lg3W7lS1EymmmSsaqh05kmR6on7u5b/cokpWGDDROfcS5qB8OtGt/8Bw51rZIHvl9szI4gBMtfkPk864HNPjQZIXbwfNhiAa/uTypzN9kVZLkHVmBCYe2O1qKkdOa6xKMdIB5WftHyms2xc+7Je2xcczfKHTsR+GLGHyn4ebxlI9ZBlsxdhVNgRE+HeueV7dasF1oiIx+MyLfTVkPclX275V1pEnffJWzVse+oOP3s6kjdnqkcoYAA0Au0zE12ZiTUuaBAzrgyPtUNEnbNFg2W7ivmzscMothhxk/6Jkb8vHvt89l5Ebk1OQWz0OUm0NYTFRwKWv4legOchLlpuT8BY/X2ZjjKBNx6EcFMv0LMOph9xBxt3RnIaimOlhKjy3f1q4yEqAEgyETBzXS22VQnvllqbXP72rjX/gb+zyMv8GzBTbbVSL/c4gR6mxKXgzK8wl5+eR4nd5rAT2rl9H3dREw4gFu3qH4WGRzfxEAuZ1DkSkaYgeDQxCjMrD0rQ3/ek2i7oofUn/nBY9EiAYVdlZebQxD+/X6rW70O9AIwyFYrrTmZkxDb0VekKgswRhsxbCyPZBwGjcfc3V41hVU3qYvNUUmpNcyZ50z1drr+VzQPtJVxlh5pq9Buxf9DTdcA2InXUJpIsOCepLZHdx9UwzQN1y/uzZjLU94VEmaucUFgzH/dEegSW2RLIo5DeGUKPkMtoGznR2iAZ+QX2L5DJ0vypojkmiHtO2t5ar7Lk14DGvIVdjI0iF1s 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)(1800799015)(82310400014)(376005)(7416005)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2024 22:27:27.0053 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 63940f3a-ac36-420a-d5ef-08dc4d1ac058 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: SJ1PEPF00001CE1.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6762 Content-Type: text/plain; charset="utf-8" Using the RMPADJUST instruction, the VSMA attribute can only be changed at VMPL0. An SVSM will be present when running at VMPL1 or a lower privilege level. When an SVSM is present, use the SVSM_CORE_CREATE_VCPU call or the SVSM_CORE_DESTROY_VCPU call to perform VMSA attribute changes. Use the VMPL level supplied by the SVSM within the VMSA and when starting the AP. Signed-off-by: Tom Lendacky Reviewed-by: Pankaj Gupta --- arch/x86/include/asm/sev.h | 2 ++ arch/x86/kernel/sev.c | 60 +++++++++++++++++++++++++++++++++----- 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 204f0a4857d6..d7be613b7372 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -229,6 +229,8 @@ struct svsm_call { #define SVSM_CORE_CALL(x) ((0ULL << 32) | (x)) #define SVSM_CORE_REMAP_CA 0 #define SVSM_CORE_PVALIDATE 1 +#define SVSM_CORE_CREATE_VCPU 2 +#define SVSM_CORE_DELETE_VCPU 3 =20 #ifdef CONFIG_AMD_MEM_ENCRYPT extern void __sev_es_ist_enter(struct pt_regs *regs); diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index d3e182d69d65..ea8b43a0f01b 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -1016,7 +1016,7 @@ void snp_accept_memory(phys_addr_t start, phys_addr_t= end) set_pages_state(vaddr, npages, SNP_PAGE_STATE_PRIVATE); } =20 -static int snp_set_vmsa(void *va, bool vmsa) +static int base_snp_set_vmsa(void *va, bool vmsa) { u64 attrs; =20 @@ -1034,6 +1034,40 @@ static int snp_set_vmsa(void *va, bool vmsa) return rmpadjust((unsigned long)va, RMP_PG_SIZE_4K, attrs); } =20 +static int svsm_snp_set_vmsa(void *va, void *caa, int apic_id, bool vmsa) +{ + struct svsm_call call =3D {}; + unsigned long flags; + int ret; + + local_irq_save(flags); + + call.caa =3D this_cpu_read(svsm_caa); + call.rcx =3D __pa(va); + + if (vmsa) { + /* Protocol 0, Call ID 2 */ + call.rax =3D SVSM_CORE_CALL(SVSM_CORE_CREATE_VCPU); + call.rdx =3D __pa(caa); + call.r8 =3D apic_id; + } else { + /* Protocol 0, Call ID 3 */ + call.rax =3D SVSM_CORE_CALL(SVSM_CORE_DELETE_VCPU); + } + + ret =3D svsm_protocol(&call); + + local_irq_restore(flags); + + return ret; +} + +static int snp_set_vmsa(void *va, void *caa, int apic_id, bool vmsa) +{ + return vmpl ? svsm_snp_set_vmsa(va, caa, apic_id, vmsa) + : base_snp_set_vmsa(va, vmsa); +} + #define __ATTR_BASE (SVM_SELECTOR_P_MASK | SVM_SELECTOR_S_MASK) #define INIT_CS_ATTRIBS (__ATTR_BASE | SVM_SELECTOR_READ_MASK | SVM_SELEC= TOR_CODE_MASK) #define INIT_DS_ATTRIBS (__ATTR_BASE | SVM_SELECTOR_WRITE_MASK) @@ -1065,11 +1099,11 @@ static void *snp_alloc_vmsa_page(void) return page_address(p + 1); } =20 -static void snp_cleanup_vmsa(struct sev_es_save_area *vmsa) +static void snp_cleanup_vmsa(struct sev_es_save_area *vmsa, int apic_id) { int err; =20 - err =3D snp_set_vmsa(vmsa, false); + err =3D snp_set_vmsa(vmsa, NULL, apic_id, false); if (err) pr_err("clear VMSA page failed (%u), leaking page\n", err); else @@ -1080,6 +1114,7 @@ static int wakeup_cpu_via_vmgexit(u32 apic_id, unsign= ed long start_ip) { struct sev_es_save_area *cur_vmsa, *vmsa; struct ghcb_state state; + struct svsm_ca *caa; unsigned long flags; struct ghcb *ghcb; u8 sipi_vector; @@ -1126,6 +1161,12 @@ static int wakeup_cpu_via_vmgexit(u32 apic_id, unsig= ned long start_ip) if (!vmsa) return -ENOMEM; =20 + /* + * If an SVSM is present, then the SVSM CAA per-CPU variable will + * have a value, otherwise it will be NULL. + */ + caa =3D per_cpu(svsm_caa, cpu); + /* CR4 should maintain the MCE value */ cr4 =3D native_read_cr4() & X86_CR4_MCE; =20 @@ -1173,11 +1214,11 @@ static int wakeup_cpu_via_vmgexit(u32 apic_id, unsi= gned long start_ip) * VMPL level * SEV_FEATURES (matches the SEV STATUS MSR right shifted 2 bits) */ - vmsa->vmpl =3D 0; + vmsa->vmpl =3D vmpl; vmsa->sev_features =3D sev_status >> 2; =20 /* Switch the page over to a VMSA page now that it is initialized */ - ret =3D snp_set_vmsa(vmsa, true); + ret =3D snp_set_vmsa(vmsa, caa, apic_id, true); if (ret) { pr_err("set VMSA page failed (%u)\n", ret); free_page((unsigned long)vmsa); @@ -1193,7 +1234,10 @@ static int wakeup_cpu_via_vmgexit(u32 apic_id, unsig= ned long start_ip) vc_ghcb_invalidate(ghcb); ghcb_set_rax(ghcb, vmsa->sev_features); ghcb_set_sw_exit_code(ghcb, SVM_VMGEXIT_AP_CREATION); - ghcb_set_sw_exit_info_1(ghcb, ((u64)apic_id << 32) | SVM_VMGEXIT_AP_CREAT= E); + ghcb_set_sw_exit_info_1(ghcb, + ((u64)apic_id << 32) | + ((u64)vmpl << 16) | + SVM_VMGEXIT_AP_CREATE); ghcb_set_sw_exit_info_2(ghcb, __pa(vmsa)); =20 sev_es_wr_ghcb_msr(__pa(ghcb)); @@ -1211,13 +1255,13 @@ static int wakeup_cpu_via_vmgexit(u32 apic_id, unsi= gned long start_ip) =20 /* Perform cleanup if there was an error */ if (ret) { - snp_cleanup_vmsa(vmsa); + snp_cleanup_vmsa(vmsa, apic_id); vmsa =3D NULL; } =20 /* Free up any previous VMSA page */ if (cur_vmsa) - snp_cleanup_vmsa(cur_vmsa); + snp_cleanup_vmsa(cur_vmsa, apic_id); =20 /* Record the current VMSA page */ per_cpu(sev_vmsa, cpu) =3D vmsa; --=20 2.43.2 From nobody Tue Feb 10 19:10:40 2026 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2055.outbound.protection.outlook.com [40.107.244.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0FFF839ED for ; Mon, 25 Mar 2024 22:27:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.55 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711405662; cv=fail; b=Slmti9mqwhQqTua2WyxXFRAwJd2iUq66j/dPGlOFD7qYEmm981ujIZ0Xo+ljA+zR/iQwB5tNpzDT4pxAsq9wnWsp7TxxuUe04Bz5tNldLAxaixmavjFYbiaS5+3sAg3M5o3utM757WBD4uZznHuZHtQ/g6GLMB7ZrHeE0XfMWgQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711405662; c=relaxed/simple; bh=+uLA34KELh/HMXYaV67TH/9MLk/g6ENrRMGD+cuI0wc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bRdqUD6+f4IeuLXjl/mzLZIZds2KOvcsEZ2HvSpLEWG0KVAKbHL95KUeuyDImgviTbprRlR13tg67t4AA23zLaLFP9kqixwtobPzGD4nohZ19OAHb23Wrsjy0ckXQe3BfpXXkyBOmPlX1cWfpTjur5tcW0epS43rlrQh1XN2kaU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=Mijlasm1; arc=fail smtp.client-ip=40.107.244.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="Mijlasm1" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aBY38ccDL97KXm/388pt2Q9OF3EaleemdOYYMc8dX4JNwxUputHGFYInELgz7cEYPA5bHX3eNvDsY/OTEwEq+OapgPr4q7a8ccwZ5JAINf6Q7S5qch5RZQrFoVYVTcNpbaBCDfHy9TIJJ3biWf7kmGRADySq+Hoob9bWfEU8wnVvc6lKQlz302GgH0xhxBPeQfYL8utn30SDBDvQ56feDA16VIYk5o0qJkXpQnMnmtGQsd4QccfIIOcTKk4SY6iVAvWV0jjD7WO0xvlWYtbT7w992l/vPDEdOp/l5wMk8YshTKA60+LBcZ9TMdN7y2ma/k42zBNUjfjUxo+C5of+3w== 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=kzA5pECaIDf87S7AUfWsYLpoq6tLV5uBE0LPeK9qlBQ=; b=k1aCNDIT696olwKWAMkMk+ksAqwPvjZx3ym2N7+ii5fWp1StMihlRnBKymfttlPGSef3fPRyB5lg3mgu8lH+UwI18FkoRc8y+5P/O2e+waxT19jxBGAsPU4EByPD+pnu3YbJJ6tL365/9ZziBpiZom/O1izZp7hfBGq0vc465E89CQqm9zX6h0I5g0q2o3ZZ+TaZITVnejgnuGHOSsqpxaosWRWI7ArrUf8u5SYwmViFTK6U1LjfgY0DYO8CtimQK1q1/JjZLfkR3UyyGoKV1pfnr8VYhv8iC2N8HnCenZKAQ5uGOKcKvIhtMCpmsPw97zqOjxQ+//SkERt4yrqj9w== 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 (0) 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=kzA5pECaIDf87S7AUfWsYLpoq6tLV5uBE0LPeK9qlBQ=; b=Mijlasm1jUGuN650zGkwxvkugj3Uz4Sbw4bL5ed4Ww8TUTdQt0wIdp11wYmNOC9W6oVdUx2lFTTcmsyTLscKGjbmJ8Z1twQBeaqPUxGSlg69ERGJ1BOVV8ojGldElK3UDzKi+wknMPeomtxwFci7G7rkc18pFTVutUs4Lk9w+E0= Received: from BY3PR10CA0003.namprd10.prod.outlook.com (2603:10b6:a03:255::8) by CH3PR12MB7524.namprd12.prod.outlook.com (2603:10b6:610:146::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.31; Mon, 25 Mar 2024 22:27:34 +0000 Received: from SJ1PEPF00001CDD.namprd05.prod.outlook.com (2603:10b6:a03:255:cafe::c4) by BY3PR10CA0003.outlook.office365.com (2603:10b6:a03:255::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.13 via Frontend Transport; Mon, 25 Mar 2024 22:27:34 +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 SJ1PEPF00001CDD.mail.protection.outlook.com (10.167.242.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Mon, 25 Mar 2024 22:27:34 +0000 Received: from tlendack-t1.amdoffice.net (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.35; Mon, 25 Mar 2024 17:27:33 -0500 From: Tom Lendacky To: , , , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , "Peter Zijlstra" , Dan Williams , Michael Roth , Ashish Kalra Subject: [PATCH v3 07/14] x86/sev: Provide SVSM discovery support Date: Mon, 25 Mar 2024 17:26:26 -0500 Message-ID: <6468ce125086997ffb043238d12a347f77c7a3fa.1711405593.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: SJ1PEPF00001CDD:EE_|CH3PR12MB7524:EE_ X-MS-Office365-Filtering-Correlation-Id: 9713a4eb-7e34-4e6f-3e11-08dc4d1ac496 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: S6O8LaYvuaKgtCXDMuVcDa1XZeLSnlqJBuXvpd/fO9MfTPhGphsmkEec/uDs5F8Rq6Wj8k2n1rW2PnKG13u5wCCmG1IIHo2HjYXk2DtHa7tG9AaQtvZWSoIgIJjVfL2PBXPTTp4WeUy7o0nlA+cmmSoiYblohdctiSAddbbQmhGdocBm47cQgLL3Akg0B9MPYDSVATi5QDF7rkcTgcSOjCtPsYxOe88AEuBcT5ClQ3Qh5TepbIMPVPocjOeGrClDRqlc47AoSRFfd/CUiYTPHOV2mjBTY3tl+SfAj7roDvSDDqEo0On+FiFvALy7HnJCgWKR23NAxJ9uEvhGluV+9RjotLPxx/Cs1zK/tuWr322ar7JjUu1dxKZS4/gmsxfSzW9rtgCmf9iLM7DuhlXiC1BA9J07gVFHy8nnAM1POKen4TF3ZZfXv5bb12TcYrrOTomKO6RI91/cjC41Bd2wH/FF0Q8ecY2MbtBvcydj8IJ8EtRXa1Mcwp8CgTTBhAn4a7qBGyHHz4zJ3M4uU7oQ06nUD4XxMz0S1XAO+mZ5IKoPIennistc94Akta1fp4+aBGWjTEQ62hlvqZsior9jU1N2HkWzMZaX7EIKCA/Dap3pdhccJzJc94x/cAeVkeFIuwW3wqFwkqpal/KOfEsjHr2Ddh2inn7XtlBkobj5p2zTNo8DiU0AfkEGDgeLNbRM+W6KPDC9D0ewHbodm2dhB15PfcI/tewvJjt9Jlw3co0A7jlRK6G1gGzNZkoKKlgB 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)(376005)(7416005)(82310400014)(36860700004)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2024 22:27:34.1343 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9713a4eb-7e34-4e6f-3e11-08dc4d1ac496 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: SJ1PEPF00001CDD.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB7524 Content-Type: text/plain; charset="utf-8" The SVSM specification documents an alternative method of discovery for the SVSM using a reserved CPUID bit and a reserved MSR. For the CPUID support, the SNP CPUID table is updated to set bit 28 of the EAX register of the 0x8000001f leaf when an SVSM is present. This bit has been reserved for use in this capacity. For the MSR support, a new reserved MSR 0xc001f000 has been defined. A #VC should be generated when accessing this MSR. The #VC handler is expected to ignore writes to this MSR and return the physical calling area address (CAA) on reads of this MSR. Signed-off-by: Tom Lendacky Reviewed-by: Pankaj Gupta --- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/msr-index.h | 2 ++ arch/x86/kernel/sev-shared.c | 11 +++++++++++ arch/x86/kernel/sev.c | 17 +++++++++++++++++ 4 files changed, 31 insertions(+) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpuf= eatures.h index a38f8f9ba657..51e7c879f057 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -446,6 +446,7 @@ #define X86_FEATURE_V_TSC_AUX (19*32+ 9) /* "" Virtual TSC_AUX */ #define X86_FEATURE_SME_COHERENT (19*32+10) /* "" AMD hardware-enforced ca= che coherency */ #define X86_FEATURE_DEBUG_SWAP (19*32+14) /* AMD SEV-ES full debug state = swap support */ +#define X86_FEATURE_SVSM_PRESENT (19*32+28) /* "" SNP SVSM is present */ =20 /* AMD-defined Extended Feature 2 EAX, CPUID level 0x80000021 (EAX), word = 20 */ #define X86_FEATURE_NO_NESTED_DATA_BP (20*32+ 0) /* "" No Nested Data Brea= kpoints */ diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-in= dex.h index 05956bd8bacf..cc4de3379265 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -654,6 +654,8 @@ #define MSR_AMD64_RMP_BASE 0xc0010132 #define MSR_AMD64_RMP_END 0xc0010133 =20 +#define MSR_SVSM_CAA 0xc001f000 + /* AMD Collaborative Processor Performance Control MSRs */ #define MSR_AMD_CPPC_CAP1 0xc00102b0 #define MSR_AMD_CPPC_ENABLE 0xc00102b1 diff --git a/arch/x86/kernel/sev-shared.c b/arch/x86/kernel/sev-shared.c index e63c0a6eccd6..17eb42c4ae71 100644 --- a/arch/x86/kernel/sev-shared.c +++ b/arch/x86/kernel/sev-shared.c @@ -1559,6 +1559,8 @@ static enum es_result vc_check_opcode_bytes(struct es= _em_ctxt *ctxt, static void __head setup_svsm_ca(const struct cc_blob_sev_info *cc_info) { struct snp_secrets_page_layout *secrets_page; + struct snp_cpuid_table *cpuid_table; + unsigned int i; u64 caa; =20 BUILD_BUG_ON(sizeof(*secrets_page) !=3D PAGE_SIZE); @@ -1596,4 +1598,13 @@ static void __head setup_svsm_ca(const struct cc_blo= b_sev_info *cc_info) */ boot_svsm_caa =3D (struct svsm_ca *)caa; boot_svsm_caa_pa =3D caa; + + /* Advertise the SVSM presence via CPUID. */ + cpuid_table =3D (struct snp_cpuid_table *)snp_cpuid_get_table(); + for (i =3D 0; i < cpuid_table->count; i++) { + struct snp_cpuid_fn *fn =3D &cpuid_table->fn[i]; + + if (fn->eax_in =3D=3D 0x8000001f) + fn->eax |=3D BIT(28); + } } diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index ea8b43a0f01b..7f399ea87a3c 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -1347,12 +1347,29 @@ int __init sev_es_efi_map_ghcbs(pgd_t *pgd) return 0; } =20 +static enum es_result vc_handle_svsm_caa_msr(struct es_em_ctxt *ctxt) +{ + struct pt_regs *regs =3D ctxt->regs; + + /* Writes to the SVSM CAA msr are ignored */ + if (ctxt->insn.opcode.bytes[1] =3D=3D 0x30) + return ES_OK; + + regs->ax =3D lower_32_bits(this_cpu_read(svsm_caa_pa)); + regs->dx =3D upper_32_bits(this_cpu_read(svsm_caa_pa)); + + return ES_OK; +} + static enum es_result vc_handle_msr(struct ghcb *ghcb, struct es_em_ctxt *= ctxt) { struct pt_regs *regs =3D ctxt->regs; enum es_result ret; u64 exit_info_1; =20 + if (regs->cx =3D=3D MSR_SVSM_CAA) + return vc_handle_svsm_caa_msr(ctxt); + /* Is it a WRMSR? */ exit_info_1 =3D (ctxt->insn.opcode.bytes[1] =3D=3D 0x30) ? 1 : 0; =20 --=20 2.43.2 From nobody Tue Feb 10 19:10:40 2026 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2040.outbound.protection.outlook.com [40.107.236.40]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E2D879DB9 for ; Mon, 25 Mar 2024 22:27:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.40 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711405665; cv=fail; b=qHLNSDb1FYhNEkAp4jE+Ul8GEVuy8ruKMYhSCVsIenPnl1xo1+vdR+q5K4wqmYXwCn87Gz8145OL4nK47A0MDJhs9LbhLbdoWPkaFryLgPqxfpXmyIEyI8pMrZMqW5EogTabTNIhnZnjinxR3RFwUye0v3+p+JjJNiB6zDZVJSI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711405665; c=relaxed/simple; bh=DGGY+b1Ik7ExH648RwoVZml0FpCXCoSzYz63F3dGB8U=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OiEMryXHkEtnpndInLyx3H6o5v4SOliWwaQzbvFWKKKEwz1Bm1MG2l6soO/x0ohiUSF5TiNaiD1UbITpmgZwXkdt4LTqKDbl5g6OtEl3K4yj47v57KwZIlD84PWG/Q4qF00vDlijKwWnmmo4q5xZJhb2uzmuoEsv1UDCIuZARxI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=GkaW2C2X; arc=fail smtp.client-ip=40.107.236.40 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="GkaW2C2X" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Wbofx6DfP7gg+GnKEwAZ8PmmWXC92JLxFe7eWTM6q4va4m9cyMWIYk5h1E32u4lrrFDjwL9+1O8QW9jSeuRrhOwLPp4/7Ili1budCWzjdhkkBF3MOmTK/vlM5w4IzNpXMC1Qe70eqBTC1Gt24039O8GqFSULUOy9jm0APLJNoBzsrKzeeT04K9kCksebOryKkfT+p5yUUANYpfWkKV7tabhBkofX3BzWV4ZZBd12upMjQk4VeR/Xl4PSuk105KrRaYPpWrFa60SqHiYxp6GJCS01T2s4FXMSNHzeinAjGKcoBoYrwbhHa4IxLNRKgXb8mE7DGKH9HF3lCud0hucwgQ== 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=DUFekUHq3ri6fK8WX25LSjrtTNUyC2BaVsA3y2IVSSs=; b=PbacovLkcaF0rWEpDa/eAZ3iwkLXAl0zBv3R6pJMQI8gY1prkXBeMlWRDup/UT2q+4OpZN/rBjwAf5588xrLBE0BsSi0NePiYP3+HdDLrb4BLtVo5vft/VREjb9R0bpjncC+jsN5pvWnKtv5i0rUNN3xhN3TVDdJsZGSnpFMyjQzAombZC57NKU3apXRLUsTz0TxEEgmHbWR3P2f3S1Kn0KugW8t8bbiaRsFfq9QbZMgmAeQ9uS52oS3k3NBm9rC4tG6EjgHUCK5fMIJLeRBVQhS7PeWSQ3G3rnmwVo+RHjSicAcaVBZDLP1gjPs4VxLwqmbUYwfLxlB8UAwm2WCbA== 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 (0) 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=DUFekUHq3ri6fK8WX25LSjrtTNUyC2BaVsA3y2IVSSs=; b=GkaW2C2Xxv1z3AjLtNPo4CL7F+Mq+/FRY/foYrTahsS0MeSjn8S2zczdqXIznwNTNCZ3p149ExxSWNHv/IQVh0dA0bixgjlLiIgIQQf3LVCq9+nQuMKLyYX0b24l5IQdWKNByaLHH0ohR8ug5sFQfYbOt+1K/GxIuiKZqZuGQAY= Received: from BYAPR08CA0014.namprd08.prod.outlook.com (2603:10b6:a03:100::27) by MW3PR12MB4378.namprd12.prod.outlook.com (2603:10b6:303:52::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.32; Mon, 25 Mar 2024 22:27:41 +0000 Received: from SJ1PEPF00001CE0.namprd05.prod.outlook.com (2603:10b6:a03:100:cafe::bf) by BYAPR08CA0014.outlook.office365.com (2603:10b6:a03:100::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.13 via Frontend Transport; Mon, 25 Mar 2024 22:27:41 +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 SJ1PEPF00001CE0.mail.protection.outlook.com (10.167.242.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Mon, 25 Mar 2024 22:27:41 +0000 Received: from tlendack-t1.amdoffice.net (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.35; Mon, 25 Mar 2024 17:27:40 -0500 From: Tom Lendacky To: , , , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , "Peter Zijlstra" , Dan Williams , Michael Roth , Ashish Kalra Subject: [PATCH v3 08/14] x86/sev: Provide guest VMPL level to userspace Date: Mon, 25 Mar 2024 17:26:27 -0500 Message-ID: X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: SJ1PEPF00001CE0:EE_|MW3PR12MB4378:EE_ X-MS-Office365-Filtering-Correlation-Id: 22961b62-8807-4b65-c0ef-08dc4d1ac8d5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: G3b0Xlvsz8J3p2ZW05hcY797clPm1oiqeauQEHO8/EbTgBD0ft09Eyly6jTiV05uuCATrrJF1W3cin9XrTIeUz9hWnIqo8VLJiQyj5i1jSXwbHu72JwQroY0YE4+pU20Gkmns2IIVtcZlMwkmm1Kd30q53SB+EC+dP1G6DdSp8/agi9H82qvYWcpiMGTg0gBCeaF+pZTXK3k+FOratwLy7W07GEigjkfDsrJFFirCL4Gx5WuHoFfn5UCyG9/Fh36zmBWNdVn4Km4AQHE3g2bdjK/R55sz49DwHrbJ6tV1F0QMojKQMegv7/EvQ1L8y3s6czlw6FJkvq+T1ko8iYRRVUuKPE7oAvvycMlmcDgdSyrRZCzgNYT3byOXnuh9ajiWUzE2Hy6qOAkF3iliSHbAInApWC7mgAISTfzp5zhjd6569Yv7vj7/cN+dPMj38vM5O4CqpERkn4eOLpGmN8nCejNwYaal42QNH3Sjpb2PYPO0yMY5q/1asOD5T+6GfIJQietTAkQSvGdfjPYPt4AEQkDWsQoVjaL/HCGdq8x5EF9vAJ2CmNXQsR6DZsoF9SH9Vy0usnTCgp4BbzxbPSxDsNa89XzLWV+Lh6JN6e6k1TbLRJQvTv4EM5LKwj22J9wUcGrjyl0rFz1z6We4bxyXSljX3BDvte6cmNdKjKv0Ij3mmsqvU9A8iogIAvpKmqMqPNgb1B5wOvw+pvu6R4JutwF9ceAzHEqHNrMVLRVFbTpk0NlBHTfAKCDS+RmGcbk 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)(36860700004)(82310400014)(7416005)(1800799015)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2024 22:27:41.2614 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 22961b62-8807-4b65-c0ef-08dc4d1ac8d5 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: SJ1PEPF00001CE0.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR12MB4378 Content-Type: text/plain; charset="utf-8" Requesting an attestation report from userspace involves providing the VMPL level for the report. Currently any value from 0-3 is valid because Linux enforces running at VMPL0. When an SVSM is present, though, Linux will not be running at VMPL0 and only VMPL values starting at the VMPL level Linux is running at to 3 are valid. In order to allow userspace to determine the minimum VMPL value that can be supplied to an attestation report, create a sysfs entry that can be used to retrieve the current VMPL level of Linux. Signed-off-by: Tom Lendacky --- arch/x86/kernel/sev.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index 7f399ea87a3c..b027b00e315d 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -2527,3 +2527,40 @@ void __init snp_remap_svsm_ca(void) /* Update the CAA to a proper kernel address */ boot_svsm_caa =3D &boot_svsm_ca_page; } + +static ssize_t vmpl_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + return sysfs_emit(buf, "%d\n", vmpl); +} + +static struct kobj_attribute vmpl_attr =3D __ATTR_RO(vmpl); + +static struct attribute *vmpl_attrs[] =3D { + &vmpl_attr.attr, + NULL +}; + +static struct attribute_group sev_attr_group =3D { + .attrs =3D vmpl_attrs, +}; + +static int __init sev_sysfs_init(void) +{ + struct kobject *sev_kobj; + int ret; + + if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) + return -ENODEV; + + sev_kobj =3D kobject_create_and_add("sev", kernel_kobj); + if (!sev_kobj) + return -ENOMEM; + + ret =3D sysfs_create_group(sev_kobj, &sev_attr_group); + if (ret) + kobject_put(sev_kobj); + + return ret; +} +arch_initcall(sev_sysfs_init); --=20 2.43.2 From nobody Tue Feb 10 19:10:40 2026 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2081.outbound.protection.outlook.com [40.107.92.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8026479DB9 for ; Mon, 25 Mar 2024 22:27:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.81 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711405674; cv=fail; b=gKXpVYG6KsMXdaro+99Sss790JVVOBIwPzFNxO10V4DRPYXkMoEHs6k5f1zzjMN7l2ii1LzjrPHMv4DircaZoA7AXRme2mrP7mMWHS2G1cAXi4LPoEExV82xRz3uQxoxeO/XzvIXaPqgpMYcDsek+jr8VYbMVZsA2JhnWT5C4H8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711405674; c=relaxed/simple; bh=XEHK48UoZVdRFi+ouiDElocCFCWd7/OHjXwAVnnNO04=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=l0J7r8qOxpFooN7k9SOOlkNUlika3sbi6/X0GNaLj5ge2x10t/GzGYSoTmc+lYaQ2gRzFm4WTJm3QoyFirbX1nlr/hUUsdNf8EkQsX3Y+2Mi3duKzPWyxKySieST9I6kDrIyA+rrnWx+t3hVpuXeUl+x8GqaAnDNglNDLsFp1d0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=vm69o6ue; arc=fail smtp.client-ip=40.107.92.81 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="vm69o6ue" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=W+JxAsUftURqmsNWFrAvJJSXvifsdNcqPmDltCRw8G7nnQOj0E2Y/vZH6vPJiYOwbIqIzVzSmvmg54HbAZkZcz/GtuR2UmZi4wTSXov9Ryddgs0c1SdBRF0qZ6KXXt11g/4cKdD3xVHPkJYt1AoD7zjtyrZk2keGH10r8e7SuUYWQSm6dsk9StC4ow22gwHPv0epUJjhB6E40AVJ7W90h4szf4qKfOrORllCrlYeHleVm7mi3d3ekXJkcdRy3lgf+GSTetOy+bdfDcIHIX+09duTqZr0iqlWTGzPQ+pFc4hBbFEGsic0450af5xV7OV6a6R15jd//4nbuGKoQpzJ3A== 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=9y7Qs8owcCGIArd5/qD8aez+FctSryByYyMxiAU78g8=; b=CTa9TZF27Kldvks9juo0SXaIC74rsnKtJsER77I4sv08aOG+xQgFUdcq+x/IaWirOZPjuUv+YTYVFqjC1CAt+K6K+50slazyAxotYUzb8sNWezglG/tSHnFEfKLdKi1jedmW/5XdXoadtMjX3PHif4Gx+jEShiH6MilwwFkU23HTzer2EXLWgymq74Yu0J5sXC1GzcuZzwI6zTFTFBtp3+qUPwiu4S4yqJ5Rqo+j+Pzrwlzkp4Mlyv3lZMt8YpTgGfDhe9f+kPWnN9AyvICNohxIvsnPK8gcc9X+Wq4VQDlihr7dhqYpSsEQlv9w4ekwooRQC8uAlEgsg8vhCuScUw== 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 (0) 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=9y7Qs8owcCGIArd5/qD8aez+FctSryByYyMxiAU78g8=; b=vm69o6ueJ1MH1iCEETRdekH69cLq4+yYgygvYUKzfxiCbUqsbqPDnM8y+LUTyL+tcm10vYPCxrKZFg7vgkZK0cU6FDjOKc1GflffguQuU5Xex7m9TuUkQXvP6cZoZcVvREqUtFvBJe/qA5C0kLq14ncYfH+IK0NCN+Tk323Lqms= Received: from SJ0PR05CA0112.namprd05.prod.outlook.com (2603:10b6:a03:334::27) by DS0PR12MB7780.namprd12.prod.outlook.com (2603:10b6:8:152::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.26; Mon, 25 Mar 2024 22:27:48 +0000 Received: from SJ1PEPF00001CE1.namprd05.prod.outlook.com (2603:10b6:a03:334:cafe::75) by SJ0PR05CA0112.outlook.office365.com (2603:10b6:a03:334::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.12 via Frontend Transport; Mon, 25 Mar 2024 22:27:48 +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 SJ1PEPF00001CE1.mail.protection.outlook.com (10.167.242.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Mon, 25 Mar 2024 22:27:48 +0000 Received: from tlendack-t1.amdoffice.net (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.35; Mon, 25 Mar 2024 17:27:47 -0500 From: Tom Lendacky To: , , , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , "Peter Zijlstra" , Dan Williams , Michael Roth , Ashish Kalra Subject: [PATCH v3 09/14] virt: sev-guest: Choose the VMPCK key based on executing VMPL Date: Mon, 25 Mar 2024 17:26:28 -0500 Message-ID: <9615e6055e5b262a22bf312608647223517595b5.1711405593.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: SJ1PEPF00001CE1:EE_|DS0PR12MB7780:EE_ X-MS-Office365-Filtering-Correlation-Id: eea6356e-7d19-42c8-6c77-08dc4d1acd16 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8+85Th94efYneApQSu2pWiGcSBdn1VBAM75eFRrPMCG1bkBqgOn3E5g70m/zSqNm69PO07ORyd0D1Gf2WMXZuH0JihlgU5MSiXf+5679uDc8Ikp5wcFluX8iLrjhD+bio8UvSKC9dEzTqUMoiOff+00Zq5Yy6WsIe2ujpEl7oGlzTsqgigIU0BkUtRQaTltAszMMW69DwSIiaNJtq0Y3IyuuhrVOjj/Y2P4KpLrL2Dm3xmSEK3E5qh3cXS2xD5tWDfuvTWWJF4IcdW6nVSeLQKiaROQ0x5aa6813e5B/7sC1Tu9deih4dIw5y84tIhxZStnqFw8qkUhVbhKV3HuvtdLiYfPQcRrs5QrcwyYbpneY41xwN2hhxkhmfb8gPGcDYC1QJmJSqnK5QkKGqagEpQTYCzimOvKDfFWy2cF8uq9Iwwj5wMBpzjT8xRPqsqRu5sebDnJb2au8x7U0UQcTYt96iAFZLDBUnlOWdbjCXmmoqtfYuOMOzLvPIFgvsTzfQ57Z3o6ST22CYXuCMOL2a6J3bUf8bnUxKCSpp+M/hikYMUKnGdf10e9q03A+mpk4/SbAf8zuU1m1zQs1y9dK5GbIsbSipWrHjopIuvrP0FP/KjiwueBIljcuigQMd0kxNhDJ9V1ok/aRjaf0jbHJ9RooCmRkV4jj9zrFl43Bmkp7OqaslkMMIUOJqiV+n+jlgCxY7DQa5HnueO2kedPkzsYvRI0/45j85fjJ5bA7U4CtTVhKjh+UQ6u6LyC0uWe9 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)(1800799015)(7416005)(376005)(36860700004)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2024 22:27:48.3648 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: eea6356e-7d19-42c8-6c77-08dc4d1acd16 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: SJ1PEPF00001CE1.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7780 Content-Type: text/plain; charset="utf-8" Currently, the sev-guest driver uses the vmpck-0 key by default. When an SVSM is present the kernel is running at a VMPL other than 0 and the vmpck-0 key is no longer available. So choose the vmpck key based on the active VMPL level. Signed-off-by: Tom Lendacky --- arch/x86/include/asm/sev.h | 2 ++ arch/x86/kernel/sev.c | 6 ++++++ drivers/virt/coco/sev-guest/sev-guest.c | 10 +++++++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index d7be613b7372..066eb0ba3d63 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -308,6 +308,7 @@ u64 sev_get_status(void); void kdump_sev_callback(void); void sev_show_status(void); void snp_remap_svsm_ca(void); +int snp_get_vmpl(void); #else static inline void sev_es_ist_enter(struct pt_regs *regs) { } static inline void sev_es_ist_exit(void) { } @@ -339,6 +340,7 @@ static inline u64 sev_get_status(void) { return 0; } static inline void kdump_sev_callback(void) { } static inline void sev_show_status(void) { } static inline void snp_remap_svsm_ca(void) { } +static inline int snp_get_vmpl(void) { return 0; } #endif =20 #ifdef CONFIG_KVM_AMD_SEV diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index b027b00e315d..7e2b9934a95d 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -2464,6 +2464,12 @@ int snp_issue_guest_request(u64 exit_code, struct sn= p_req_data *input, struct sn } EXPORT_SYMBOL_GPL(snp_issue_guest_request); =20 +int snp_get_vmpl(void) +{ + return vmpl; +} +EXPORT_SYMBOL_GPL(snp_get_vmpl); + static struct platform_device sev_guest_device =3D { .name =3D "sev-guest", .id =3D -1, diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/se= v-guest/sev-guest.c index 87f241825bc3..1ff897913bf4 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -2,7 +2,7 @@ /* * AMD Secure Encrypted Virtualization (SEV) guest driver interface * - * Copyright (C) 2021 Advanced Micro Devices, Inc. + * Copyright (C) 2021-2024 Advanced Micro Devices, Inc. * * Author: Brijesh Singh */ @@ -70,8 +70,8 @@ struct snp_guest_dev { u8 *vmpck; }; =20 -static u32 vmpck_id; -module_param(vmpck_id, uint, 0444); +static int vmpck_id =3D -1; +module_param(vmpck_id, int, 0444); MODULE_PARM_DESC(vmpck_id, "The VMPCK ID to use when communicating with th= e PSP."); =20 /* Mutex to serialize the shared buffer access and command handling. */ @@ -923,6 +923,10 @@ static int __init sev_guest_probe(struct platform_devi= ce *pdev) if (!snp_dev) goto e_unmap; =20 + /* Adjust the default VMPCK key based on the executing VMPL level */ + if (vmpck_id =3D=3D -1) + vmpck_id =3D snp_get_vmpl(); + ret =3D -EINVAL; snp_dev->vmpck =3D get_vmpck(vmpck_id, layout, &snp_dev->os_area_msg_seqn= o); if (!snp_dev->vmpck) { --=20 2.43.2 From nobody Tue Feb 10 19:10:40 2026 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2063.outbound.protection.outlook.com [40.107.94.63]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D902C8287F for ; Mon, 25 Mar 2024 22:27:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.63 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711405679; cv=fail; b=isYeV8Ki34MNm+D0K3j7oI6luvgUOtvQz7S76pqBaDz2aAP80Kvt3j/zdi8e8sKDcVX9BTehdLhe0rLV6UL5mJJpDu8CWI1r6wa5KqKgwetSAp/c+ypaLangn3NqM00QO8JeWdJ2L1KFaoN1ZXMV4BmjudQ0y2jt0chIXalOzdg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711405679; c=relaxed/simple; bh=OWB8YqMR6+ubxClvOGMFr/5+2vbqxc8R+T+UHSSCbvU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Lb6DEvl8WJSuYDbed3kvBIDTk6J473xxDAH8ofeIWW/XotafO93yU1ZCGGE3nR78FwyasLOdAeMsth1lr08NCGtzpt2kOx6Tuo96RkiSvRq6aeR4Th0AStdFo+m/onEswp0iNvPYeTYv9dbRWf8S1lYvNI4vObJoqr3Ihatjn18= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=isrUjIEf; arc=fail smtp.client-ip=40.107.94.63 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="isrUjIEf" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VGzhXlGD99vUI79XfB7j+0mhOfMp0CgOa0rQNDmD2G9CsfnrCxXgczhSBhT8yKrc3b0F32wlDMxmH0SqQG7oVUXiG7JD0kR5QGbmTp6YL/7nUiTfMz+gPL+60SP4YjX9tGfz70dlKH9vyBDbPfBMcZEXmjTmvzxHQmokwGGT9jeTD8rsKTaMxuFoHRryxndF/hwG2mBEM9kEL0ON7nGteXnRhfdwfEpnUkYXzbqW5YeuQSLb0uxvTjBfVqjkP6kQO+jXFS3MUd7LqTHPj2dFy9XbzwqdcPBrttdXd3uIDnkptRxIpKuPp1OXDOONc9+QbxurGzemWA6Rs57nS/nvqw== 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=JAmK2+/fKsarqC5Jy2zMoU/XCCPURo4lIHxka8k69Vk=; b=S7DNmy5scsBkxEARwusmxomFUBXjpDM12cjvRkeKTT9CYfsuwA8Mr5GhPjVnPlRwfQ8pZaPmAZ/vDw6vzX3FlyFW4PN2x6CIRzHokkw6TyfLBBn2OVscqkrPd21JEz/j5lZnHh78JHIqGMx37UMxShgJz80HBq8MAI7lqN+vuphn70kASM8FkFXNSWKiBYg3e6MNilAlR3FriUf6Eq45wtYHve6aW5d8fwwFg3zAEYh+EVGofROXDmT9BT3jGosURS5xa9uKwZ8LlS57pkJLKIUR74jeoAvF3L/Wa7x9TXkyA8xeh/6TldHRz6uv56X6PSC2Rp/hxUAeWjLxXlmOUg== 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 (0) 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=JAmK2+/fKsarqC5Jy2zMoU/XCCPURo4lIHxka8k69Vk=; b=isrUjIEfCKCmfEi4wA8hPtPfxm0ydTT1K+LOgbuSCLrdIDR5hIDh5702ayGe3yFTuCNzV5GXVVq5nkURds27QdiYX+f1WrdhDzREi7DCjcfsBxokcO2Ctf3OcvDCH7htg8AiNvgmrEalRlQe5yww+tKpjlAbSCsT6+7yPRalWRw= Received: from BY3PR10CA0029.namprd10.prod.outlook.com (2603:10b6:a03:255::34) by CH3PR12MB8852.namprd12.prod.outlook.com (2603:10b6:610:17d::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.32; Mon, 25 Mar 2024 22:27:56 +0000 Received: from SJ1PEPF00001CDD.namprd05.prod.outlook.com (2603:10b6:a03:255:cafe::8a) by BY3PR10CA0029.outlook.office365.com (2603:10b6:a03:255::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.13 via Frontend Transport; Mon, 25 Mar 2024 22:27:55 +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 SJ1PEPF00001CDD.mail.protection.outlook.com (10.167.242.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Mon, 25 Mar 2024 22:27:55 +0000 Received: from tlendack-t1.amdoffice.net (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.35; Mon, 25 Mar 2024 17:27:54 -0500 From: Tom Lendacky To: , , , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , "Peter Zijlstra" , Dan Williams , Michael Roth , Ashish Kalra Subject: [PATCH v3 10/14] configfs-tsm: Allow the privlevel_floor attribute to be updated Date: Mon, 25 Mar 2024 17:26:29 -0500 Message-ID: X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: SJ1PEPF00001CDD:EE_|CH3PR12MB8852:EE_ X-MS-Office365-Filtering-Correlation-Id: 3a2d899d-20de-468e-c910-08dc4d1ad153 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VzN0MVft/99+JJBOnvw/0AyvHgx5QAB4BFF+4y82fK3Yug1KrnHt9JbklmjnljUD/iWKElUuwGaHfVISAhT0xveybF+7tJJRcPcI7zmVxjXVBzWuski4JKbtoxQo2CnR/bkHW1KQnkE5vOQXrRUNjgDNwLWYT5QPo7ieaqOAWC5JtyGC7ISl/mkAYwejrTVLeHRQ/Ri4V6HMzthtmNeJAAndzsWgeX25azJXhDdB4bPQxX0WQI2KMb1k/AdtHgNVaNIgOxuq/xIVzO6OJpsZ4J3mDvrHqzFKAU7ekVm/IL1PR5WxbA8KAG1IszeqJxgyQVUZK2cE/QXW4M/xczN9ngixVA0Jst2K76d2w5UNeKyip6SwaIKKtLQxDtLD0xFIZw9/I9kdWx1AKeNDB5k/37mpJDpJwLMuLHJdPlelhqZOcCs8x/6uQg+G5Nm/VaIMVmUihooMmvGHLPSUe1NQuUbyXfxIGMhtJNUPZcJ7J2xYJD9KXDyuf9ACL6H6D0qdTthoH3l+mOkqSXV39Jr/19fUCNCpAZDc0ylb5ZbyPMSKMHyle672AfWhaCiRf6mMOB6kNbrTDUeWBevKQxiNkU2eLF3tCdPQHKrTq/pIU57bbrTO5/xB8QDvHAFlTS5E7FqDQfDehyxrEW5BZtM+M/riOq2QO/FlCz0s98Wp5NbgfK33mbzqC2IAXdmik1CmbFSzwc97xoOq9p+telmuF+IMVx5L/0CdOSHHngq4AX/SRo2YG+kF8XH7Ipr6QesA 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)(7416005)(36860700004)(82310400014)(376005)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2024 22:27:55.5091 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3a2d899d-20de-468e-c910-08dc4d1ad153 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: SJ1PEPF00001CDD.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8852 Content-Type: text/plain; charset="utf-8" With the introduction of an SVSM, Linux will be running at a non-zero VMPL. Any request for an attestation report at a higher priviledge VMPL than what Linux is currently running will result in an error. Allow for the privlevel_floor attribute to be updated dynamically so that the attribute may be set dynamically. Signed-off-by: Tom Lendacky --- drivers/virt/coco/sev-guest/sev-guest.c | 5 ++++- include/linux/tsm.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/se= v-guest/sev-guest.c index 1ff897913bf4..bba6531cb606 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -885,7 +885,7 @@ static int sev_report_new(struct tsm_report *report, vo= id *data) return 0; } =20 -static const struct tsm_ops sev_tsm_ops =3D { +static struct tsm_ops sev_tsm_ops =3D { .name =3D KBUILD_MODNAME, .report_new =3D sev_report_new, }; @@ -972,6 +972,9 @@ static int __init sev_guest_probe(struct platform_devic= e *pdev) snp_dev->input.resp_gpa =3D __pa(snp_dev->response); snp_dev->input.data_gpa =3D __pa(snp_dev->certs_data); =20 + /* Set the privlevel_floor attribute based on the current VMPL */ + sev_tsm_ops.privlevel_floor =3D snp_get_vmpl(); + ret =3D tsm_register(&sev_tsm_ops, snp_dev, &tsm_report_extra_type); if (ret) goto e_free_cert_data; diff --git a/include/linux/tsm.h b/include/linux/tsm.h index de8324a2223c..50c5769657d8 100644 --- a/include/linux/tsm.h +++ b/include/linux/tsm.h @@ -54,7 +54,7 @@ struct tsm_report { */ struct tsm_ops { const char *name; - const unsigned int privlevel_floor; + unsigned int privlevel_floor; int (*report_new)(struct tsm_report *report, void *data); }; =20 --=20 2.43.2 From nobody Tue Feb 10 19:10:40 2026 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2041.outbound.protection.outlook.com [40.107.93.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66B5C85280 for ; Mon, 25 Mar 2024 22:28:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.41 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711405687; cv=fail; b=pcuFJKX2d48wCXsgqqBwCu+ysvSr9M9ZGkHro85mrhwOic5yybOvdatlEzmURPrIM4gRnPWZqRWP7M5VuqKSq0iUY6NkJBtwfJ5MY3k5tL+DPViTT8AHXaIBnNZLJR+H/gVjUtgK36CNJ/3bubXzP9IPylbOtsUIVcaEPNhnBnc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711405687; c=relaxed/simple; bh=/bP5ARkfqpiSdkC/tYFUlQfedg2OlcCRN/Xo3klQa5A=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=d3sCz6/Zs3Tr9T/fe63jMCsYK45rpsMnUJGomCgNgCMwcl/wKVhcLtmbcr3MrGgId2IzMIkgXAIz8B+MT1pkA/5SpirXiJClBkgOu/ltrXs8oBErEF0E/qh3mYWffuSbTKywr8VvfBVfTU5jbpmPjOEJ+X7isqxZl4StgvwJ0aI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=EQ20BQCU; arc=fail smtp.client-ip=40.107.93.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="EQ20BQCU" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Yl2kCO6msuNdRXddUwvrVHjwVh2opkuifQ14XG35U73/85Xf227PTZCv/L2Pl9cOA7OPeiuJADzh8gbb9Yp2Al0MCnAvvppy1XHopz59YZMoewRW+4k9GaNHZXHWoLs2K5tjBi2LzBbJpSJupaWrpAEaB6jA6Dzd/IzxqnEJcQ8XSSb5JebiihBgbBTV5NzjOrySqXsAs4J7NPKP8+NA1YZkb044rUdh2rq4yabIkEcVXTS55IX3Rvg8f8bpPo14ftrM/YWx0y81kYbWf/sv7AuUmFv7dd+OvOqsNqYjlaWi8FJOYrX82EFPtYhtD0B+IhOOs0MmP/hoxhIpuNFwsQ== 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=vSaVNakca2nMCkuBpXIs+7OWDCTqpRwg3zFouBQcMSU=; b=XuZeVroOQps/vJzYTrgqZplvJAk6JRBN/xyto2t/+Key6rSC9hzc1+aULV+LMfZTZl0SbeeqzCOvYco2QiQS3Z0Scm7sMQEmLvdTTCbUbeEwn4jeFfVts666IznpXLDzZHzT9neHdkhTZIhdypIPd12AuWQJj5qP4jff2D+4zlqv0Lxj67AIIyQ0EMOa0uI4WM//zMhGdLjTcoBH8Gi9r1zrX64QmJtwmhRNds7hzoKoWoranc9a4Ow/sOifKIhgEWybxH7kjtji78pCJxCJ+egPNToQ4Jqe5j9odN0v+f3jeSbrkPyLZh+3lADxaneqSsrkrU2lpP6IqltB0qgu0g== 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 (0) 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=vSaVNakca2nMCkuBpXIs+7OWDCTqpRwg3zFouBQcMSU=; b=EQ20BQCUnMUN3fsH+Hj5Pg6ECi/+WOr0Gb6Pws7SA0tmNf8ZUwoqeE2jBqDg8B+jW1Y6PmE8CFfVJiA9SrT0VnacZ3KK4SbCduq0j6/aFqu7hsFF99jdgnC+tEu/7qmxB10j5Qb2iLIhFP2VMguMl13lT1YfujG8BrgEIpLWNvM= Received: from BYAPR08CA0019.namprd08.prod.outlook.com (2603:10b6:a03:100::32) by DS7PR12MB6069.namprd12.prod.outlook.com (2603:10b6:8:9f::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.31; Mon, 25 Mar 2024 22:28:02 +0000 Received: from SJ1PEPF00001CE0.namprd05.prod.outlook.com (2603:10b6:a03:100:cafe::b2) by BYAPR08CA0019.outlook.office365.com (2603:10b6:a03:100::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.13 via Frontend Transport; Mon, 25 Mar 2024 22:28:02 +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 SJ1PEPF00001CE0.mail.protection.outlook.com (10.167.242.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Mon, 25 Mar 2024 22:28:02 +0000 Received: from tlendack-t1.amdoffice.net (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.35; Mon, 25 Mar 2024 17:28:01 -0500 From: Tom Lendacky To: , , , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , "Peter Zijlstra" , Dan Williams , Michael Roth , Ashish Kalra Subject: [PATCH v3 11/14] x86/sev: Extend the config-fs attestation support for an SVSM Date: Mon, 25 Mar 2024 17:26:30 -0500 Message-ID: <1ca853e149fe37be748c028a9b0d00237eb73938.1711405593.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: SJ1PEPF00001CE0:EE_|DS7PR12MB6069:EE_ X-MS-Office365-Filtering-Correlation-Id: 04274778-c340-4d2b-436f-08dc4d1ad580 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yC1h327QlHwRPJCBxfMypBcTYMbpxd7g6cFv/Qo711ljCaZLI67ApmRIQERyKgimFvoxoYINrwSzi6DYlRqOwO8V7vthDz1x3ygD/0+gUdSscfWcb2p8aJlv3HXCiCVWeU3rDS5lQIChQwd9JljGConktTIuZlJ7F9UOikf6FUo8e/dXHdMGWl1Q269q8d4jUnSNX0FsWuWEfAP++5yMo9VFKSjKIzYfd9FmshnOf91s9Jo9WzJQTHTzfAf/sYPaq5/W+wjg0M5GUKDk6sk38z//ZubUnDccuwn8JCk4dY6e4FKJ7GDbwY0GpuwGKVlb090Qt5bTpx/KXa33+7u2XDBZ09iP/0mm7XuC3miaUIMzciFq7/bCfDKiJT3VCIZAUj5Rs1y3xn83P862YlGHwkyiPDw9fATBavVkscrrBJYbQrLsQEvhKtDaVRGCWaYQcSu7FkNJEx6KiNBPdfEwAw1HPi2nELK1NrO9xkPQrp6XG7WI4laMLAU1uTy0lyd+spGolKvjBG3Jv9ILgC1+YPmtPfyuLARE3s/Zbcq6YRr8c8tJWx37GgXoM2l9JjxPrUuVpn1u9QpxzAabmwc6kgsryI/gOjDBpwXQfHfXkOnNm/KMMOOHBreSMyFLE4l0VlNuAb1vpWNxYs0MhFfj9aq55DFGAUpR/mLG27YGlNvIBkrpN0roLtq/IGzFnpyCiOQqh78mPJYpK2JDE93fh2/obnEB93U+8GLcQDVwNRSpu61XyU1s/e2EG98yIAIEotatIWpmokfj7QeWJN+zvQ== 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)(7416005)(1800799015)(376005)(36860700004)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2024 22:28:02.5115 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 04274778-c340-4d2b-436f-08dc4d1ad580 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: SJ1PEPF00001CE0.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB6069 Content-Type: text/plain; charset="utf-8" When an SVSM is present, the guest can also request attestation reports from the SVSM. These SVSM attestation reports can be used to attest the SVSM and any services running within the SVSM. Extend the config-fs attestation support to allow for an SVSM attestation report. This involves creating four (4) new config-fs attributes: - 'service-provider' (input) This attribute is used to determine whether the attestation request should be sent to the specified service provider or to the SEV firmware. The SVSM service provider is represented by the value 'svsm'. - 'service_guid' (input) Used for requesting the attestation of a single service within the service provider. A null GUID implies that the SVSM_ATTEST_SERVICES call should be used to request the attestation report. A non-null GUID implies that the SVSM_ATTEST_SINGLE_SERVICE call should be used. - 'service_manifest_version' (input) Used with the SVSM_ATTEST_SINGLE_SERVICE call, the service version represents a specific service manifest version be used for the attestation report. - 'manifestblob' (output) Used to return the service manifest associated with the attestation report. Signed-off-by: Tom Lendacky --- Documentation/ABI/testing/configfs-tsm | 69 +++++++++++ arch/x86/include/asm/sev.h | 31 ++++- arch/x86/kernel/sev.c | 50 ++++++++ drivers/virt/coco/sev-guest/sev-guest.c | 151 ++++++++++++++++++++++++ drivers/virt/coco/tsm.c | 93 ++++++++++++++- include/linux/tsm.h | 11 ++ 6 files changed, 402 insertions(+), 3 deletions(-) diff --git a/Documentation/ABI/testing/configfs-tsm b/Documentation/ABI/tes= ting/configfs-tsm index dd24202b5ba5..72a7acdb5258 100644 --- a/Documentation/ABI/testing/configfs-tsm +++ b/Documentation/ABI/testing/configfs-tsm @@ -31,6 +31,21 @@ Description: Standardization v2.03 Section 4.1.8.1 MSG_REPORT_REQ. https://www.amd.com/content/dam/amd/en/documents/epyc-technical-docs/spe= cifications/56421.pdf =20 +What: /sys/kernel/config/tsm/report/$name/manifestblob +Date: January, 2024 +KernelVersion: v6.10 +Contact: linux-coco@lists.linux.dev +Description: + (RO) Optional supplemental data that a TSM may emit, visibility + of this attribute depends on TSM, and may be empty if no + manifest data is available. + + When @provider is "sev_guest" and the @service_provider is + "svsm" this file contains the service manifest used for the SVSM + attestation report from the Secure VM Service Module for SEV-SNP + Guests v1.00 Section 7. + https://www.amd.com/content/dam/amd/en/documents/epyc-technical-docs/spe= cifications/58019.pdf + What: /sys/kernel/config/tsm/report/$name/provider Date: September, 2023 KernelVersion: v6.7 @@ -80,3 +95,57 @@ Contact: linux-coco@lists.linux.dev Description: (RO) Indicates the minimum permissible value that can be written to @privlevel. + +What: /sys/kernel/config/tsm/report/$name/service_provider +Date: January, 2024 +KernelVersion: v6.10 +Contact: linux-coco@lists.linux.dev +Description: + (WO) Attribute is visible if a TSM implementation provider + supports the concept of attestation reports from a service + provider for TVMs, like SEV-SNP running under an SVSM. + Specifying the service provider via this attribute will create + an attestation report as specified by the service provider. + Currently supported service-providers are: + svsm + + For the SVSM service provider, see the Secure VM Service Module + for SEV-SNP Guests v1.00 Section 7. + https://www.amd.com/content/dam/amd/en/documents/epyc-technical-docs/spe= cifications/58019.pdf + +What: /sys/kernel/config/tsm/report/$name/service_guid +Date: January, 2024 +KernelVersion: v6.10 +Contact: linux-coco@lists.linux.dev +Description: + (WO) Attribute is visible if a TSM implementation provider + supports the concept of attestation reports from a service + provider for TVMs, like SEV-SNP running under an SVSM. + Specifying an empty/null GUID (00000000-0000-0000-0000-000000) + requests all active services within the service provider be + part of the attestation report. Specifying a GUID request + an attestation report of just the specified service using the + manifest form specified by the service_manifest_version + attribute. + + For the SVSM service provider, see the Secure VM Service Module + for SEV-SNP Guests v1.00 Section 7. + https://www.amd.com/content/dam/amd/en/documents/epyc-technical-docs/spe= cifications/58019.pdf + +What: /sys/kernel/config/tsm/report/$name/service_manifest_version +Date: January, 2024 +KernelVersion: v6.10 +Contact: linux-coco@lists.linux.dev +Description: + (WO) Attribute is visible if a TSM implementation provider + supports the concept of attestation reports from a service + provider for TVMs, like SEV-SNP running under an SVSM. + Indicates the service manifest version requested for the + attestation report. If this field is not set by the user, + the default manifest version of the service (the service's + initial/first manifest version) is returned. The initial + manifest version is always available. + + For the SVSM service provider, see the Secure VM Service Module + for SEV-SNP Guests v1.00 Section 7. + https://www.amd.com/content/dam/amd/en/documents/epyc-technical-docs/spe= cifications/58019.pdf diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 066eb0ba3d63..94af7fb7a8e1 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -209,6 +209,27 @@ struct svsm_pvalidate_call { struct svsm_pvalidate_entry entry[]; }; =20 +/* + * The SVSM Attestation related structures + */ +struct svsm_location_entry { + u64 pa; + u32 len; + u8 rsvd[4]; +}; + +struct svsm_attestation_call { + struct svsm_location_entry report_buffer; + struct svsm_location_entry nonce; + struct svsm_location_entry manifest_buffer; + struct svsm_location_entry certificates_buffer; + + /* For attesting a single service */ + u8 service_guid[16]; + u32 service_manifest_version; + u8 rsvd[4]; +}; + /* * SVSM protocol structure */ @@ -232,6 +253,10 @@ struct svsm_call { #define SVSM_CORE_CREATE_VCPU 2 #define SVSM_CORE_DELETE_VCPU 3 =20 +#define SVSM_ATTEST_CALL(x) ((1ULL << 32) | (x)) +#define SVSM_ATTEST_SERVICES 0 +#define SVSM_ATTEST_SINGLE_SERVICE 1 + #ifdef CONFIG_AMD_MEM_ENCRYPT extern void __sev_es_ist_enter(struct pt_regs *regs); extern void __sev_es_ist_exit(void); @@ -302,6 +327,7 @@ void snp_set_wakeup_secondary_cpu(void); bool snp_init(struct boot_params *bp); void __noreturn snp_abort(void); int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, str= uct snp_guest_request_ioctl *rio); +int snp_issue_svsm_attestation_request(u64 call_id, struct svsm_attestatio= n_call *input); void snp_accept_memory(phys_addr_t start, phys_addr_t end); u64 snp_get_unsupported_features(u64 status); u64 sev_get_status(void); @@ -333,7 +359,10 @@ static inline int snp_issue_guest_request(u64 exit_cod= e, struct snp_req_data *in { return -ENOTTY; } - +static inline int snp_issue_svsm_attestation_request(u64 call_id, struct s= vsm_attestation_call *input) +{ + return -ENOTTY; +} static inline void snp_accept_memory(phys_addr_t start, phys_addr_t end) {= } static inline u64 snp_get_unsupported_features(u64 status) { return 0; } static inline u64 sev_get_status(void) { return 0; } diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index 7e2b9934a95d..0a06632898c6 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -2400,6 +2400,56 @@ static int __init init_sev_config(char *str) } __setup("sev=3D", init_sev_config); =20 +static void update_attestation_input(struct svsm_call *call, struct svsm_a= ttestation_call *input) +{ + /* If (new) lengths have been returned, propograte them up */ + if (call->rcx_out !=3D call->rcx) + input->manifest_buffer.len =3D call->rcx_out; + + if (call->rdx_out !=3D call->rdx) + input->certificates_buffer.len =3D call->rdx_out; + + if (call->r8_out !=3D call->r8) + input->report_buffer.len =3D call->r8_out; +} + +int snp_issue_svsm_attestation_request(u64 call_id, struct svsm_attestatio= n_call *input) +{ + struct svsm_attestation_call *attest_call; + struct svsm_call call =3D {}; + unsigned long flags; + u64 attest_call_pa; + int ret; + + if (!vmpl) + return -EINVAL; + + local_irq_save(flags); + + call.caa =3D __svsm_get_caa(); + + attest_call =3D (struct svsm_attestation_call *)call.caa->svsm_buffer; + attest_call_pa =3D __svsm_get_caa_pa() + offsetof(struct svsm_ca, svsm_bu= ffer); + + *attest_call =3D *input; + + /* + * Set input registers for the request and set RDX and R8 to known + * values in order to detect length values being returned in them. + */ + call.rax =3D call_id; + call.rcx =3D attest_call_pa; + call.rdx =3D -1; + call.r8 =3D -1; + ret =3D svsm_protocol(&call); + update_attestation_input(&call, input); + + local_irq_restore(flags); + + return ret; +} +EXPORT_SYMBOL_GPL(snp_issue_svsm_attestation_request); + int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, str= uct snp_guest_request_ioctl *rio) { struct ghcb_state state; diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/se= v-guest/sev-guest.c index bba6531cb606..0d2c9926a97c 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -38,6 +38,8 @@ #define SNP_REQ_MAX_RETRY_DURATION (60*HZ) #define SNP_REQ_RETRY_DELAY (2*HZ) =20 +#define SVSM_MAX_RETRIES 3 + struct snp_guest_crypto { struct crypto_aead *tfm; u8 *iv, *authtag; @@ -783,6 +785,148 @@ struct snp_msg_cert_entry { u32 length; }; =20 +static int sev_svsm_report_new(struct tsm_report *report, void *data) +{ + unsigned int report_len, manifest_len, certificates_len; + void *report_blob, *manifest_blob, *certificates_blob; + struct svsm_attestation_call attest_call =3D {}; + struct tsm_desc *desc =3D &report->desc; + unsigned int retry_count; + unsigned int size; + bool try_again; + void *buffer; + u64 call_id; + int ret; + + /* + * Allocate pages for the request: + * - Report blob (4K) + * - Manifest blob (4K) + * - Certificate blob (16K) + * + * Above addresses must be 4K aligned + */ + report_len =3D SZ_4K; + manifest_len =3D SZ_4K; + certificates_len =3D SEV_FW_BLOB_MAX_SIZE; + + if (guid_is_null(&desc->service_guid)) { + call_id =3D SVSM_ATTEST_CALL(SVSM_ATTEST_SERVICES); + } else { + export_guid(attest_call.service_guid, &desc->service_guid); + attest_call.service_manifest_version =3D desc->service_manifest_version; + + call_id =3D SVSM_ATTEST_CALL(SVSM_ATTEST_SINGLE_SERVICE); + } + + retry_count =3D 0; + +retry: + size =3D report_len + manifest_len + certificates_len; + buffer =3D alloc_pages_exact(size, __GFP_ZERO); + if (!buffer) + return -ENOMEM; + + report_blob =3D buffer; + attest_call.report_buffer.pa =3D __pa(report_blob); + attest_call.report_buffer.len =3D report_len; + + manifest_blob =3D report_blob + report_len; + attest_call.manifest_buffer.pa =3D __pa(manifest_blob); + attest_call.manifest_buffer.len =3D manifest_len; + + certificates_blob =3D manifest_blob + manifest_len; + attest_call.certificates_buffer.pa =3D __pa(certificates_blob); + attest_call.certificates_buffer.len =3D certificates_len; + + attest_call.nonce.pa =3D __pa(desc->inblob); + attest_call.nonce.len =3D desc->inblob_len; + + ret =3D snp_issue_svsm_attestation_request(call_id, &attest_call); + switch (ret) { + case SVSM_SUCCESS: + break; + case SVSM_ERR_INVALID_PARAMETER: + ret =3D -EINVAL; + + if (retry_count >=3D SVSM_MAX_RETRIES) + goto error; + + try_again =3D false; + + if (attest_call.report_buffer.len > report_len) { + report_len =3D PAGE_ALIGN(attest_call.report_buffer.len); + try_again =3D true; + } + + if (attest_call.manifest_buffer.len > manifest_len) { + manifest_len =3D PAGE_ALIGN(attest_call.manifest_buffer.len); + try_again =3D true; + } + + if (attest_call.certificates_buffer.len > certificates_len) { + certificates_len =3D PAGE_ALIGN(attest_call.certificates_buffer.len); + try_again =3D true; + } + + /* If one of the buffers wasn't large enough, retry the request */ + if (try_again) { + free_pages_exact(buffer, size); + retry_count++; + goto retry; + } + + goto error; + case SVSM_ERR_BUSY: + ret =3D -EAGAIN; + goto error; + default: + pr_err_ratelimited("SVSM attestation request failed (%#x)\n", ret); + ret =3D -EINVAL; + goto error; + } + + ret =3D -ENOMEM; + + report_len =3D attest_call.report_buffer.len; + void *rbuf __free(kvfree) =3D kvzalloc(report_len, GFP_KERNEL); + if (!rbuf) + goto error; + + memcpy(rbuf, report_blob, report_len); + report->outblob =3D no_free_ptr(rbuf); + report->outblob_len =3D report_len; + + manifest_len =3D attest_call.manifest_buffer.len; + void *mbuf __free(kvfree) =3D kvzalloc(manifest_len, GFP_KERNEL); + if (!mbuf) + goto error; + + memcpy(mbuf, manifest_blob, manifest_len); + report->manifestblob =3D no_free_ptr(mbuf); + report->manifestblob_len =3D manifest_len; + + certificates_len =3D attest_call.certificates_buffer.len; + if (!certificates_len) + goto success; + + void *cbuf __free(kvfree) =3D kvzalloc(certificates_len, GFP_KERNEL); + if (!cbuf) + goto error; + + memcpy(cbuf, certificates_blob, certificates_len); + report->auxblob =3D no_free_ptr(cbuf); + report->auxblob_len =3D certificates_len; + +success: + ret =3D 0; + +error: + free_pages_exact(buffer, size); + + return ret; +} + static int sev_report_new(struct tsm_report *report, void *data) { struct snp_msg_cert_entry *cert_table; @@ -797,6 +941,13 @@ static int sev_report_new(struct tsm_report *report, v= oid *data) if (desc->inblob_len !=3D SNP_REPORT_USER_DATA_SIZE) return -EINVAL; =20 + if (desc->service_provider) { + if (strcmp(desc->service_provider, "svsm")) + return -EINVAL; + + return sev_svsm_report_new(report, data); + } + void *buf __free(kvfree) =3D kvzalloc(size, GFP_KERNEL); if (!buf) return -ENOMEM; diff --git a/drivers/virt/coco/tsm.c b/drivers/virt/coco/tsm.c index d1c2db83a8ca..46f230bf13ac 100644 --- a/drivers/virt/coco/tsm.c +++ b/drivers/virt/coco/tsm.c @@ -35,7 +35,7 @@ static DECLARE_RWSEM(tsm_rwsem); * The attestation report format is TSM provider specific, when / if a sta= ndard * materializes that can be published instead of the vendor layout. Until = then * the 'provider' attribute indicates the format of 'outblob', and optiona= lly - * 'auxblob'. + * 'auxblob' and 'manifestblob'. */ =20 struct tsm_report_state { @@ -48,6 +48,7 @@ struct tsm_report_state { enum tsm_data_select { TSM_REPORT, TSM_CERTS, + TSM_MANIFEST, }; =20 static struct tsm_report *to_tsm_report(struct config_item *cfg) @@ -119,6 +120,74 @@ static ssize_t tsm_report_privlevel_floor_show(struct = config_item *cfg, } CONFIGFS_ATTR_RO(tsm_report_, privlevel_floor); =20 +static ssize_t tsm_report_service_provider_store(struct config_item *cfg, + const char *buf, size_t len) +{ + struct tsm_report *report =3D to_tsm_report(cfg); + size_t sp_len; + char *sp; + int rc; + + guard(rwsem_write)(&tsm_rwsem); + rc =3D try_advance_write_generation(report); + if (rc) + return rc; + + sp_len =3D (buf[len - 1] !=3D '\n') ? len : len - 1; + + sp =3D kstrndup(buf, sp_len, GFP_KERNEL); + if (!sp) + return -ENOMEM; + kfree(report->desc.service_provider); + + report->desc.service_provider =3D sp; + + return len; +} +CONFIGFS_ATTR_WO(tsm_report_, service_provider); + +static ssize_t tsm_report_service_guid_store(struct config_item *cfg, + const char *buf, size_t len) +{ + struct tsm_report *report =3D to_tsm_report(cfg); + int rc; + + guard(rwsem_write)(&tsm_rwsem); + rc =3D try_advance_write_generation(report); + if (rc) + return rc; + + report->desc.service_guid =3D guid_null; + + rc =3D guid_parse(buf, &report->desc.service_guid); + if (rc) + return rc; + + return len; +} +CONFIGFS_ATTR_WO(tsm_report_, service_guid); + +static ssize_t tsm_report_service_manifest_version_store(struct config_ite= m *cfg, + const char *buf, size_t len) +{ + struct tsm_report *report =3D to_tsm_report(cfg); + unsigned int val; + int rc; + + rc =3D kstrtouint(buf, 0, &val); + if (rc) + return rc; + + guard(rwsem_write)(&tsm_rwsem); + rc =3D try_advance_write_generation(report); + if (rc) + return rc; + report->desc.service_manifest_version =3D val; + + return len; +} +CONFIGFS_ATTR_WO(tsm_report_, service_manifest_version); + static ssize_t tsm_report_inblob_write(struct config_item *cfg, const void *buf, size_t count) { @@ -163,6 +232,9 @@ static ssize_t __read_report(struct tsm_report *report,= void *buf, size_t count, if (select =3D=3D TSM_REPORT) { out =3D report->outblob; len =3D report->outblob_len; + } else if (select =3D=3D TSM_MANIFEST) { + out =3D report->manifestblob; + len =3D report->manifestblob_len; } else { out =3D report->auxblob; len =3D report->auxblob_len; @@ -188,7 +260,7 @@ static ssize_t read_cached_report(struct tsm_report *re= port, void *buf, =20 /* * A given TSM backend always fills in ->outblob regardless of - * whether the report includes an auxblob or not. + * whether the report includes an auxblob/manifestblob or not. */ if (!report->outblob || state->read_generation !=3D state->write_generation) @@ -224,8 +296,10 @@ static ssize_t tsm_report_read(struct tsm_report *repo= rt, void *buf, =20 kvfree(report->outblob); kvfree(report->auxblob); + kvfree(report->manifestblob); report->outblob =3D NULL; report->auxblob =3D NULL; + report->manifestblob =3D NULL; rc =3D ops->report_new(report, provider.data); if (rc < 0) return rc; @@ -252,6 +326,15 @@ static ssize_t tsm_report_auxblob_read(struct config_i= tem *cfg, void *buf, } CONFIGFS_BIN_ATTR_RO(tsm_report_, auxblob, NULL, TSM_OUTBLOB_MAX); =20 +static ssize_t tsm_report_manifestblob_read(struct config_item *cfg, void = *buf, + size_t count) +{ + struct tsm_report *report =3D to_tsm_report(cfg); + + return tsm_report_read(report, buf, count, TSM_MANIFEST); +} +CONFIGFS_BIN_ATTR_RO(tsm_report_, manifestblob, NULL, TSM_OUTBLOB_MAX); + #define TSM_DEFAULT_ATTRS() \ &tsm_report_attr_generation, \ &tsm_report_attr_provider @@ -265,6 +348,9 @@ static struct configfs_attribute *tsm_report_extra_attr= s[] =3D { TSM_DEFAULT_ATTRS(), &tsm_report_attr_privlevel, &tsm_report_attr_privlevel_floor, + &tsm_report_attr_service_provider, + &tsm_report_attr_service_guid, + &tsm_report_attr_service_manifest_version, NULL, }; =20 @@ -280,6 +366,7 @@ static struct configfs_bin_attribute *tsm_report_bin_at= trs[] =3D { static struct configfs_bin_attribute *tsm_report_bin_extra_attrs[] =3D { TSM_DEFAULT_BIN_ATTRS(), &tsm_report_attr_auxblob, + &tsm_report_attr_manifestblob, NULL, }; =20 @@ -288,8 +375,10 @@ static void tsm_report_item_release(struct config_item= *cfg) struct tsm_report *report =3D to_tsm_report(cfg); struct tsm_report_state *state =3D to_state(report); =20 + kvfree(report->manifestblob); kvfree(report->auxblob); kvfree(report->outblob); + kfree(report->desc.service_provider); kfree(state); } =20 diff --git a/include/linux/tsm.h b/include/linux/tsm.h index 50c5769657d8..27cc97fe8dcd 100644 --- a/include/linux/tsm.h +++ b/include/linux/tsm.h @@ -4,6 +4,7 @@ =20 #include #include +#include =20 #define TSM_INBLOB_MAX 64 #define TSM_OUTBLOB_MAX SZ_32K @@ -19,11 +20,17 @@ * @privlevel: optional privilege level to associate with @outblob * @inblob_len: sizeof @inblob * @inblob: arbitrary input data + * @service_provider: optional name of where to obtain the tsm report blob + * @service_guid: optional service-provider service guid to attest + * @service_manifest_version: optional service-provider service manifest v= ersion requested */ struct tsm_desc { unsigned int privlevel; size_t inblob_len; u8 inblob[TSM_INBLOB_MAX]; + char *service_provider; + guid_t service_guid; + unsigned int service_manifest_version; }; =20 /** @@ -33,6 +40,8 @@ struct tsm_desc { * @outblob: generated evidence to provider to the attestation agent * @auxblob_len: sizeof(@auxblob) * @auxblob: (optional) auxiliary data to the report (e.g. certificate dat= a) + * @manifestblob_len: sizeof(@manifestblob) + * @manifestblob: (optional) manifest data associated with the report */ struct tsm_report { struct tsm_desc desc; @@ -40,6 +49,8 @@ struct tsm_report { u8 *outblob; size_t auxblob_len; u8 *auxblob; + size_t manifestblob_len; + u8 *manifestblob; }; =20 /** --=20 2.43.2 From nobody Tue Feb 10 19:10:40 2026 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2080.outbound.protection.outlook.com [40.107.102.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D2ADC82D64 for ; Mon, 25 Mar 2024 22:28:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.102.80 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711405694; cv=fail; b=mzJa+iiZmcuCf9Ag6M4ZF1VkkD+GzAcvIsyo4UxA8lEeIRUyLGLcCJzeiS2N4ATFzX2w4e/Jki1/WkVJTuRUh89RLXzNdAH4KgRNzuLVCUxYGUVsVRa4Br3IxL9W3x0uixyj5z1SA+fT6758lEOS4JaTKtXfcfrIW1lUfkv4LGY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711405694; c=relaxed/simple; bh=ysluWvnWCwEP/hdYBTFjSr3RcG8VRQR7xXXsrrnHylo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qq4s/u1VgqWd3vysDmhpUK14bJlwl8cZQya0UluHlDGMhaJrkRoZ4jekp8+l7/j42fty5ZOkjoleHGPb2hrQaA+LbxdrlGsiKK9AHH7oRX1jMMoLrO1xDqLMzB4oDXRwY6IIIb+5hk2ALPZM2eHc6gkfu/fCXZN0t2fj/w6yTm0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=nyTlTE3d; arc=fail smtp.client-ip=40.107.102.80 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="nyTlTE3d" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZfISG2H9E0im2QdyonCWeWrQynYEqNSNOsruSzsot0uP9XkJXQr6aXnC5r/LZ+ZVw4bxAZLbGjiTFzQG/5fuj3E9rBUuR1rpAO14LGEd0rdh0VV6cNFoe9pXEXxDrgLEA2gFJzkga2S0fqH+hF6RzFAO1h75WUX29REAJlgOvYCNAct4tscE0zcLK+KSuVrcOpx1/FEvkXhf36aXKAFCtiEyuhXrXLkcXMG6KiZ38ReAO/MIebbaa0AZaDfXDRIanSmTdtca1M5VxINkY8oQt8Md0W6xqhYs+9drr8nNG/weaMMrnwvEyQOAKgeFeiNiXXr+N9RnRN9aH4vtB475EQ== 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=PwHDeN04OmRtSSW0Zf1iHFTZa+AKo4apEWL7A8XQfoQ=; b=Ns/eTDVCYtXQ143f5An//RLK7jusnZKpSKRXLmeJhq5DS3IeAFWHBKthFLzhgV7MSZnUCfKTG5crNuImrcSSR7sTWbtpxlCIvIHzJkT5Gomvr19QgRFSb5Pr/0HiPAIJbMd2ZRPau3wc2NvebIWr+6asMpx7IYxOBxNOgwV1sCIRawbMF4CezYFvQ/XDWChn2iyC0CksGqhVF7Dwf9uAVAE/CrenpADcRCcfZYYoKEt/vCmUw4uYzDH74GSH36fpBaf1kMnRK8fRKIlWjQHbsXE2wXC4omVgTMPWw89ugNlpRNWG5KFb5TnRKJZpIOW4TNy5Ppf6pK65xjXjF9UT9w== 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 (0) 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=PwHDeN04OmRtSSW0Zf1iHFTZa+AKo4apEWL7A8XQfoQ=; b=nyTlTE3dCS4ADJj95T+0025swyVzTcKe2JAGOTFDuO8/YIaWapK9u8ImgwKvoPGxdniXZwLvVaJVIAqMSefv226omljPWIloGqDJv06OGxd3L+rupE89DvHIts59Me8BuaaIQx95rrENSQjZA/DtXWOqMWnJKtdHPxzy+VGLZb8= Received: from BYAPR06CA0030.namprd06.prod.outlook.com (2603:10b6:a03:d4::43) by DM4PR12MB5914.namprd12.prod.outlook.com (2603:10b6:8:67::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.31; Mon, 25 Mar 2024 22:28:10 +0000 Received: from SJ1PEPF00001CE2.namprd05.prod.outlook.com (2603:10b6:a03:d4:cafe::6e) by BYAPR06CA0030.outlook.office365.com (2603:10b6:a03:d4::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.13 via Frontend Transport; Mon, 25 Mar 2024 22:28:10 +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 SJ1PEPF00001CE2.mail.protection.outlook.com (10.167.242.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Mon, 25 Mar 2024 22:28:10 +0000 Received: from tlendack-t1.amdoffice.net (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.35; Mon, 25 Mar 2024 17:28:08 -0500 From: Tom Lendacky To: , , , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , "Peter Zijlstra" , Dan Williams , Michael Roth , Ashish Kalra , Joel Becker , Christoph Hellwig Subject: [PATCH v3 12/14] fs/configfs: Add a callback to determine attribute visibility Date: Mon, 25 Mar 2024 17:26:31 -0500 Message-ID: X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: SJ1PEPF00001CE2:EE_|DM4PR12MB5914:EE_ X-MS-Office365-Filtering-Correlation-Id: 19df8a6f-55a2-4d29-703a-08dc4d1ad9fb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9CyS04CyhtmhH/ETH94xDPgickoaBuv41gX9HFLmk2HxcBkNIxCbzJ8N8Gfez23ED0lGFy+1mXa5bdNg6t2Yqp4LLHKOa7Q4nBcVFDn75PAYs1an/958tS6VdXKCzpjpeO3JKRsjSPlsHQb53AskQBd9nbFbz6xPnsE0kvxp0jvWXyqwIDKHupja/EiPUff8Pn1OlcIVp3f7We4WFFBpzeOxTygclDFOm0nO7AAEDQRdS2VtxBA5+2soYiMqzOsGzPcYldyalsgNWY3cb0FwP/hVnojCHNHAMpM1RPqDACHqulPYegVms5TN5Blt58XkUdyvVkuaOTf3i4AcQpxcz4SySQ/L+YBOBBpECqB9NmujbebDnTWNhKlLHEKefmWVkliP3njg9sTd7EIBc1E7+3B9o+pUwRBOhw7byS025iNS8vGfU2MjZHQxD5jxbq5SPNKOBF5UgICAeZi0lxhCpmsswCzahh83sa+GWi81/yLuLwe4rqhSw+BRbS1erX/UrGmGkNABKoQZ6qEqsWTNhUomt+s5d+UQ+vMuCQ/LMoTG9ym/i03n/pvXWY15fP0J3LukWCkgcAx+aA3R+PNMjkH9o9rGskRVxoehfRyrPATR8hTkbzfhIZzoASs+4t0gLKoT/LPu1zhFQi0sd0OJXRKiqPZIwJmpNqf7zxLtaBdU5DQhzEuVlNj44+H1c7kN9MMW/6h5oNN7AKvHguJXAhSJVfUN4zvEfNLK0tHCBrQqAA2BJXff/QZhLrJsLNoK 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)(7416005)(36860700004)(82310400014)(376005)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2024 22:28:10.0140 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 19df8a6f-55a2-4d29-703a-08dc4d1ad9fb 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: SJ1PEPF00001CE2.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5914 Content-Type: text/plain; charset="utf-8" In order to support dynamic decisions as to whether an attribute should be created, add a callback that returns a bool to indicate whether the attribute should be display. If no callback is registered, the attribute is displayed by default. Cc: Joel Becker Cc: Christoph Hellwig Signed-off-by: Tom Lendacky --- fs/configfs/file.c | 7 +++ include/linux/configfs.h | 111 +++++++++++++++++++++++++++------------ 2 files changed, 84 insertions(+), 34 deletions(-) diff --git a/fs/configfs/file.c b/fs/configfs/file.c index 0ad32150611e..a976c183756c 100644 --- a/fs/configfs/file.c +++ b/fs/configfs/file.c @@ -451,6 +451,9 @@ int configfs_create_file(struct config_item * item, con= st struct configfs_attrib umode_t mode =3D (attr->ca_mode & S_IALLUGO) | S_IFREG; int error =3D 0; =20 + if (attr->is_visible && !attr->is_visible(item, attr)) + return 0; + inode_lock_nested(d_inode(dir), I_MUTEX_NORMAL); error =3D configfs_make_dirent(parent_sd, NULL, (void *) attr, mode, CONFIGFS_ITEM_ATTR, parent_sd->s_frag); @@ -470,9 +473,13 @@ int configfs_create_bin_file(struct config_item *item, { struct dentry *dir =3D item->ci_dentry; struct configfs_dirent *parent_sd =3D dir->d_fsdata; + const struct configfs_attribute *attr =3D &bin_attr->cb_attr; umode_t mode =3D (bin_attr->cb_attr.ca_mode & S_IALLUGO) | S_IFREG; int error =3D 0; =20 + if (attr->is_visible && !attr->is_visible(item, attr)) + return 0; + inode_lock_nested(dir->d_inode, I_MUTEX_NORMAL); error =3D configfs_make_dirent(parent_sd, NULL, (void *) bin_attr, mode, CONFIGFS_ITEM_BIN_ATTR, parent_sd->s_frag); diff --git a/include/linux/configfs.h b/include/linux/configfs.h index 2606711adb18..c836d7bc7c9e 100644 --- a/include/linux/configfs.h +++ b/include/linux/configfs.h @@ -116,35 +116,57 @@ struct configfs_attribute { const char *ca_name; struct module *ca_owner; umode_t ca_mode; + bool (*is_visible)(const struct config_item *, const struct configfs_attr= ibute *); ssize_t (*show)(struct config_item *, char *); ssize_t (*store)(struct config_item *, const char *, size_t); }; =20 -#define CONFIGFS_ATTR(_pfx, _name) \ +#define __CONFIGFS_ATTR(_pfx, _name, _vis) \ static struct configfs_attribute _pfx##attr_##_name =3D { \ .ca_name =3D __stringify(_name), \ .ca_mode =3D S_IRUGO | S_IWUSR, \ .ca_owner =3D THIS_MODULE, \ + .is_visible =3D _vis, \ .show =3D _pfx##_name##_show, \ .store =3D _pfx##_name##_store, \ } =20 -#define CONFIGFS_ATTR_RO(_pfx, _name) \ +#define __CONFIGFS_ATTR_RO(_pfx, _name, _vis) \ static struct configfs_attribute _pfx##attr_##_name =3D { \ .ca_name =3D __stringify(_name), \ .ca_mode =3D S_IRUGO, \ .ca_owner =3D THIS_MODULE, \ + .is_visible =3D _vis, \ .show =3D _pfx##_name##_show, \ } =20 -#define CONFIGFS_ATTR_WO(_pfx, _name) \ +#define __CONFIGFS_ATTR_WO(_pfx, _name, _vis) \ static struct configfs_attribute _pfx##attr_##_name =3D { \ .ca_name =3D __stringify(_name), \ .ca_mode =3D S_IWUSR, \ .ca_owner =3D THIS_MODULE, \ + .is_visible =3D _vis, \ .store =3D _pfx##_name##_store, \ } =20 +#define CONFIGFS_ATTR(_pfx, _name) \ + __CONFIGFS_ATTR(_pfx, _name, NULL) + +#define CONFIGFS_ATTR_RO(_pfx, _name) \ + __CONFIGFS_ATTR_RO(_pfx, _name, NULL) + +#define CONFIGFS_ATTR_WO(_pfx, _name) \ + __CONFIGFS_ATTR_WO(_pfx, _name, NULL) + +#define CONFIGFS_ATTR_VISIBLE(_pfx, _name, _vis) \ + __CONFIGFS_ATTR(_pfx, _name, _vis) + +#define CONFIGFS_ATTR_VISIBLE_RO(_pfx, _name, _vis) \ + __CONFIGFS_ATTR_RO(_pfx, _name, _vis) + +#define CONFIGFS_ATTR_VISIBLE_WO(_pfx, _name, _vis) \ + __CONFIGFS_ATTR_WO(_pfx, _name, _vis) + struct file; struct vm_area_struct; =20 @@ -156,43 +178,64 @@ struct configfs_bin_attribute { ssize_t (*write)(struct config_item *, const void *, size_t); }; =20 -#define CONFIGFS_BIN_ATTR(_pfx, _name, _priv, _maxsz) \ -static struct configfs_bin_attribute _pfx##attr_##_name =3D { \ - .cb_attr =3D { \ - .ca_name =3D __stringify(_name), \ - .ca_mode =3D S_IRUGO | S_IWUSR, \ - .ca_owner =3D THIS_MODULE, \ - }, \ - .cb_private =3D _priv, \ - .cb_max_size =3D _maxsz, \ - .read =3D _pfx##_name##_read, \ - .write =3D _pfx##_name##_write, \ +#define __CONFIGFS_BIN_ATTR(_pfx, _name, _priv, _maxsz, _vis) \ +static struct configfs_bin_attribute _pfx##attr_##_name =3D { \ + .cb_attr =3D { \ + .ca_name =3D __stringify(_name), \ + .ca_mode =3D S_IRUGO | S_IWUSR, \ + .ca_owner =3D THIS_MODULE, \ + .is_visible =3D _vis, \ + }, \ + .cb_private =3D _priv, \ + .cb_max_size =3D _maxsz, \ + .read =3D _pfx##_name##_read, \ + .write =3D _pfx##_name##_write, \ } =20 -#define CONFIGFS_BIN_ATTR_RO(_pfx, _name, _priv, _maxsz) \ -static struct configfs_bin_attribute _pfx##attr_##_name =3D { \ - .cb_attr =3D { \ - .ca_name =3D __stringify(_name), \ - .ca_mode =3D S_IRUGO, \ - .ca_owner =3D THIS_MODULE, \ - }, \ - .cb_private =3D _priv, \ - .cb_max_size =3D _maxsz, \ - .read =3D _pfx##_name##_read, \ +#define __CONFIGFS_BIN_ATTR_RO(_pfx, _name, _priv, _maxsz, _vis) \ +static struct configfs_bin_attribute _pfx##attr_##_name =3D { \ + .cb_attr =3D { \ + .ca_name =3D __stringify(_name), \ + .ca_mode =3D S_IRUGO, \ + .ca_owner =3D THIS_MODULE, \ + .is_visible =3D _vis, \ + }, \ + .cb_private =3D _priv, \ + .cb_max_size =3D _maxsz, \ + .read =3D _pfx##_name##_read, \ } =20 -#define CONFIGFS_BIN_ATTR_WO(_pfx, _name, _priv, _maxsz) \ -static struct configfs_bin_attribute _pfx##attr_##_name =3D { \ - .cb_attr =3D { \ - .ca_name =3D __stringify(_name), \ - .ca_mode =3D S_IWUSR, \ - .ca_owner =3D THIS_MODULE, \ - }, \ - .cb_private =3D _priv, \ - .cb_max_size =3D _maxsz, \ - .write =3D _pfx##_name##_write, \ +#define __CONFIGFS_BIN_ATTR_WO(_pfx, _name, _priv, _maxsz, _vis) \ +static struct configfs_bin_attribute _pfx##attr_##_name =3D { \ + .cb_attr =3D { \ + .ca_name =3D __stringify(_name), \ + .ca_mode =3D S_IWUSR, \ + .ca_owner =3D THIS_MODULE, \ + .is_visible =3D _vis, \ + }, \ + .cb_private =3D _priv, \ + .cb_max_size =3D _maxsz, \ + .write =3D _pfx##_name##_write, \ } =20 +#define CONFIGFS_BIN_ATTR(_pfx, _name, _priv, _maxsz) \ + __CONFIGFS_BIN_ATTR(_pfx, _name, _priv, _maxsz, NULL) + +#define CONFIGFS_BIN_ATTR_RO(_pfx, _name, _priv, _maxsz) \ + __CONFIGFS_BIN_ATTR_RO(_pfx, _name, _priv, _maxsz, NULL) + +#define CONFIGFS_BIN_ATTR_WO(_pfx, _name, _priv, _maxsz) \ + __CONFIGFS_BIN_ATTR_WO(_pfx, _name, _priv, _maxsz, NULL) + +#define CONFIGFS_BIN_ATTR_VISIBLE(_pfx, _name, _priv, _maxs, _vis) \ + __CONFIGFS_BIN_ATTR(_pfx, _name, _priv, _maxsz, _vis) + +#define CONFIGFS_BIN_ATTR_VISIBLE_RO(_pfx, _name, _priv, _maxsz, _vis) \ + __CONFIGFS_BIN_ATTR_RO(_pfx, _name, _priv, _maxsz, _vis) + +#define CONFIGFS_BIN_ATTR_VISIBLE_WO(_pfx, _name, _priv, _maxsz, _vis) \ + __CONFIGFS_BIN_ATTR_WO(_pfx, _name, _priv, _maxsz, _vis) + /* * If allow_link() exists, the item can symlink(2) out to other * items. If the item is a group, it may support mkdir(2). --=20 2.43.2 From nobody Tue Feb 10 19:10:40 2026 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2040.outbound.protection.outlook.com [40.107.223.40]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8647B1272AF for ; Mon, 25 Mar 2024 22:28:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.40 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711405701; cv=fail; b=jwwI/oe13KtPl+VwuPZhzAHofp3rn/DwkmzuoHFSHE8taKE/UCQJZ2KyQwmQEs+ioQ/67xfmNX8Fty4J/dX9FsXhR5Vf3kjuaNHJJr9rZrOxxwGbIc5i2kFqQXlAmqFIfi6sqkO1Fqahfg0WGrFJJG+FcQz35kE4mMxV3bsLdcc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711405701; c=relaxed/simple; bh=DDZd0WN5F6BECdbQNJZVbfNtxMnskqrpkK+ff+OnkE4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Vdm0uHmjrpsfjxc4yZslv+IOUkTBIy3xoRP6tYipepcmwbAzoXBlPIr551gNMJXM+LdD1ZykrL6YXrs0WRK2/7JScaHrvFPVEuslGfJJ9Yn+qNQM08tY4k3XBPdKLxqJz4EWkkTz+TdFM3QZjFKC4JEW8rPpEXaUBYdojQ2qSjc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=O5/A8pDd; arc=fail smtp.client-ip=40.107.223.40 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="O5/A8pDd" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oOUvWvzoUi3eCFVVdTn6cnCbYx8EOkXeCKPWuxJHUmARt3TsaB+YPmk4Ly9lBSiE4s++Rmmnhn6Lu6nwGlb+dYG87N2dWANj7GJPDpXIizIheccoLIB2NhAfmUoYIiLhREHkgzVxSr6DvmkhSVzOQI8Y3FS7leRqImcjA7XG4TyG6dXkaMdlkItoJ+z0BqCX9MdfxQkP5osliKtLuegick/mw03jAwGtgusExIw1Lq9f9pUcR5+MeCsDYHTZWYPfibW1QbkbkVmfK2qfarR8zxQMCyDGL6o0u2xQbQ3lzumNP6/nHyFGq7wsVc60EsnfPLSj07Xx0lPn+vKK9Tlojw== 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=bapwT55uQTS6AuYgBCA0ykncqA3KdfOyh2/IbGaBgKM=; b=AEsFuHFv8JiStf67GoZ3oVZ3YEZEn1zyBcyz969li3qhWectoNXXh3fajft2hBU8qz5nHT2HED067opuH/Nh0kbMzmvZudt9FScaMktWmU/0zQ/m/ZRBGkHHAxmuZZgDtdghMRoQ/2xwKL54BSVUP30UEZbc/2xma+5rIqLOVdif8DdjAn6j2opCTsbbDA4cetB17YLp2eTS0BlPzZrR+Uif4OCGWOCEGT6yA3ScFrY6ivYA8vK+XPd7S99iCCAQ7K0eagunCd/ZFplWI4a5uvwh0iSa5mHuqgZcOQamdYzG2yywvBgRqPvqz8rK2ahuUij2p6J7s/6QLRRKJL2jzg== 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 (0) 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=bapwT55uQTS6AuYgBCA0ykncqA3KdfOyh2/IbGaBgKM=; b=O5/A8pDdjWkap3RtZfnWjsyboqNK3ntvfEfsGasHPSS8Sj4MuVyLfJLJdGEcgLdKe3lMwhm/Pd/LO4/+832MD88MEa/g9HQKuT/CxEL2VNJkQY7YFCe025p28kKpcOw04iE2iMkq+1sDwOFekBaNodTFA3qfA4prT6tmlQP2i4Q= Received: from SJ0PR05CA0023.namprd05.prod.outlook.com (2603:10b6:a03:33b::28) by CY8PR12MB7124.namprd12.prod.outlook.com (2603:10b6:930:5f::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.31; Mon, 25 Mar 2024 22:28:17 +0000 Received: from SJ1PEPF00001CDE.namprd05.prod.outlook.com (2603:10b6:a03:33b:cafe::55) by SJ0PR05CA0023.outlook.office365.com (2603:10b6:a03:33b::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.12 via Frontend Transport; Mon, 25 Mar 2024 22:28:17 +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 SJ1PEPF00001CDE.mail.protection.outlook.com (10.167.242.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Mon, 25 Mar 2024 22:28:17 +0000 Received: from tlendack-t1.amdoffice.net (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.35; Mon, 25 Mar 2024 17:28:16 -0500 From: Tom Lendacky To: , , , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , "Peter Zijlstra" , Dan Williams , Michael Roth , Ashish Kalra , Joel Becker , Christoph Hellwig Subject: [PATCH v3 13/14] x86/sev: Hide SVSM attestation entries if not running under an SVSM Date: Mon, 25 Mar 2024 17:26:32 -0500 Message-ID: <67893f352bc54de61160bfe251cba0bdf0431f37.1711405593.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: SJ1PEPF00001CDE:EE_|CY8PR12MB7124:EE_ X-MS-Office365-Filtering-Correlation-Id: f3511009-b646-439d-d103-08dc4d1ade42 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xdW6WWI/WE9jPCWIKhZF/R7upZgon5L7F/OSnVZJ05n6EmtIAKOjC6AEi5ST79Z71NXngStNuHoONHbgXXvU0W6YEemccCra2mTqIIlDIv4XBgecPZ62WbbZZEIF+S+6rBaTh/VhEdka/9R85xlFOprzhxv76mFzPcEg9EN5m3U2enV3f4IDrRhY+o6eGGXDr++MaZAbBWedpzQOioKqNlIl6HpRP5fB/qRfTlX+6JtY2AunnLUZisnddQfUCCIuZeWp6QO46e3mB9lfhsOL4acE8//Mw28WMBJ+Fdrj0YiqacP+PotACbY0ZSZIGRvzVux9iGTxycrpJn8rP38QhGrlw2qHxV9MmfFT2gvI15FqfgKZ6rFgh+tO5aJ4XnDLUuRvbSETMUKy/fB3xq621vE0E76mP8g+sWvY49r6+T4HR2Fqc1WQW3EGKvFcetrrtbhm5jYG2CE8huJZybUgEVqUhGdUmpBfB1+Qz6Wpv4BHkhOWr3z+05CnhQ4Q+3zhmC9wtLjM3SOOHSG6p7HFVRIhpef3Oko3upYLTGt+X+xHhGFTAE9Dm9Ocny7LqC0i7fLKMq5gnb/YuOmZNecAfzx8+YEnnHiL3JnTuww0amyU/tG1qSSQbrkPEkD1yroSXvsTrzNpyZAkAutKWsSmAlBsxATNTR8MM5Ug5/fGM2SHOme0zRUPPIhmv8qSs6qraMC1ra8PHnJiFZ0JCkkLgPwJI6WmbnuXQ/gkdq5NoufI7Hqz0JNsvUwv44ZsszCa 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)(36860700004)(1800799015)(376005)(82310400014)(7416005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2024 22:28:17.1927 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f3511009-b646-439d-d103-08dc4d1ade42 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: SJ1PEPF00001CDE.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7124 Content-Type: text/plain; charset="utf-8" Config-fs provides support to hide individual attribute entries. Using this support, base the display of the SVSM related entries on the presence of an SVSM. Cc: Joel Becker Cc: Christoph Hellwig Signed-off-by: Tom Lendacky --- arch/x86/coco/core.c | 4 ++++ drivers/virt/coco/tsm.c | 14 ++++++++++---- include/linux/cc_platform.h | 8 ++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/arch/x86/coco/core.c b/arch/x86/coco/core.c index d07be9d05cd0..efa0f648f754 100644 --- a/arch/x86/coco/core.c +++ b/arch/x86/coco/core.c @@ -12,6 +12,7 @@ =20 #include #include +#include =20 enum cc_vendor cc_vendor __ro_after_init =3D CC_VENDOR_NONE; u64 cc_mask __ro_after_init; @@ -78,6 +79,9 @@ static bool noinstr amd_cc_platform_has(enum cc_attr attr) case CC_ATTR_GUEST_STATE_ENCRYPT: return sev_status & MSR_AMD64_SEV_ES_ENABLED; =20 + case CC_ATTR_GUEST_SVSM_PRESENT: + return snp_get_vmpl(); + /* * With SEV, the rep string I/O instructions need to be unrolled * but SEV-ES supports them through the #VC handler. diff --git a/drivers/virt/coco/tsm.c b/drivers/virt/coco/tsm.c index 46f230bf13ac..d30471874e87 100644 --- a/drivers/virt/coco/tsm.c +++ b/drivers/virt/coco/tsm.c @@ -64,6 +64,12 @@ static struct tsm_report_state *to_state(struct tsm_repo= rt *report) return container_of(report, struct tsm_report_state, report); } =20 +static bool provider_visibility(const struct config_item *item, + const struct configfs_attribute *attr) +{ + return cc_platform_has(CC_ATTR_GUEST_SVSM_PRESENT); +} + static int try_advance_write_generation(struct tsm_report *report) { struct tsm_report_state *state =3D to_state(report); @@ -144,7 +150,7 @@ static ssize_t tsm_report_service_provider_store(struct= config_item *cfg, =20 return len; } -CONFIGFS_ATTR_WO(tsm_report_, service_provider); +CONFIGFS_ATTR_VISIBLE_WO(tsm_report_, service_provider, provider_visibilit= y); =20 static ssize_t tsm_report_service_guid_store(struct config_item *cfg, const char *buf, size_t len) @@ -165,7 +171,7 @@ static ssize_t tsm_report_service_guid_store(struct con= fig_item *cfg, =20 return len; } -CONFIGFS_ATTR_WO(tsm_report_, service_guid); +CONFIGFS_ATTR_VISIBLE_WO(tsm_report_, service_guid, provider_visibility); =20 static ssize_t tsm_report_service_manifest_version_store(struct config_ite= m *cfg, const char *buf, size_t len) @@ -186,7 +192,7 @@ static ssize_t tsm_report_service_manifest_version_stor= e(struct config_item *cfg =20 return len; } -CONFIGFS_ATTR_WO(tsm_report_, service_manifest_version); +CONFIGFS_ATTR_VISIBLE_WO(tsm_report_, service_manifest_version, provider_v= isibility); =20 static ssize_t tsm_report_inblob_write(struct config_item *cfg, const void *buf, size_t count) @@ -333,7 +339,7 @@ static ssize_t tsm_report_manifestblob_read(struct conf= ig_item *cfg, void *buf, =20 return tsm_report_read(report, buf, count, TSM_MANIFEST); } -CONFIGFS_BIN_ATTR_RO(tsm_report_, manifestblob, NULL, TSM_OUTBLOB_MAX); +CONFIGFS_BIN_ATTR_VISIBLE_RO(tsm_report_, manifestblob, NULL, TSM_OUTBLOB_= MAX, provider_visibility); =20 #define TSM_DEFAULT_ATTRS() \ &tsm_report_attr_generation, \ diff --git a/include/linux/cc_platform.h b/include/linux/cc_platform.h index cb0d6cd1c12f..f1b4266c1484 100644 --- a/include/linux/cc_platform.h +++ b/include/linux/cc_platform.h @@ -90,6 +90,14 @@ enum cc_attr { * Examples include TDX Guest. */ CC_ATTR_HOTPLUG_DISABLED, + + /** + * @CC_ATTR_GUEST_SVSM_PRESENT: Guest is running under an SVSM + * + * The platform/OS is running as a guest/virtual machine and is + * running under a Secure VM Service Module (SVSM). + */ + CC_ATTR_GUEST_SVSM_PRESENT, }; =20 #ifdef CONFIG_ARCH_HAS_CC_PLATFORM --=20 2.43.2 From nobody Tue Feb 10 19:10:40 2026 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2050.outbound.protection.outlook.com [40.107.223.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CF1C7FBDB for ; Mon, 25 Mar 2024 22:28:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.50 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711405713; cv=fail; b=EqirtuoWHirvzIm7oi60y0Eq1lFfHx48HJ/Nzwx5+4samQ1RA/47mqbGiJWdtUrFikEMUGLlML9tOyl23YLoVgIvxZXjWpQMl1K/1Tg7byYB7SE2rIw/DAil9GDtShgn4X/3zbJ8zkq/RtkA8I2NQYLlpAuanEp8EVyfQzfEssQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711405713; c=relaxed/simple; bh=QQhkyT6QIDBtWGX00rAc5lJs5zR7OM2eIzf1MVq0h60=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LlEpFyDb5GpHhnKGgcccfbaFg2ExB5JVPzp5KGTC1bo0ihuHcqGSuKA9DUbfIhAWI5/TQCbROQ+FkQz1kGU1MyyNrqSrN37xluIBF8DBfpJDdWbczY8W2UFG4NIiAbypcpOUDasHG8YKk9/7FWsOiCvE7qQxJnorO8bPnxi7qDs= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=JzqwUAvF; arc=fail smtp.client-ip=40.107.223.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="JzqwUAvF" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Gij8HOA/UzqMiVkTDReBySqKxEvT18/diYjjpRNWJPC/f767X12sj8Jwu69KQp/16ZKxQSKpUbvKimXPwm/4benkYORv6eZrPZaQTFx199vM6j+CojRyZYw42W3yJsqGmh+On/zsblpRZW9QgDfQKdYi7DPCxM/xVz/S+7M+hITQ2I7BTFf9nnYtQzzhBGsczK+TK9Wh6W1nW25JzJ+GQ+hgG49+FeKSCe5nrN27p+9ncNGY872f54mM1TQs2TSN6N06oH5kJZhoIXXhYoNEZe2s9+/N9it1X6wRb8LI4UevvkcAksZnhyj/DhqssTkR8mq72zYDs8hy6pHRqB1tGQ== 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=NyOP7wRB6eRIlMoQiE2Kf+SIeSqP5YrGjG/YA52yKjo=; b=JqI4cdi0TXav6X4fxiAXWaTW60ou/MQcqO15ibQDBC7271YWaOxRx6jkhFQdGI+MiT02QsFcbM/MJUB4Ls7g82dZulZHQ/jh+ZHYT+M/TM8K4ohxQAws4RiGcOPC5hPcIUg83qrkG/ZkrnQwLvQWCei7U5MBoQcObHnUi7NTW4lOIIqOSY9HI6Lr1Kdbfc9sSx401ewEeG9IFf/tZsRMB2+sPrjyT9CE7uXzbxjZ0blj47CX8+keLoQNvDsFMziQlrRP0SDR2SH5gM8fSumCdYp+AmbnqPKm4VKHQM6QF1EQnX5bpOYEKLVBd2Z/ihCd8sfRhjCnNefEQrJ1gRSLyQ== 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 (0) 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=NyOP7wRB6eRIlMoQiE2Kf+SIeSqP5YrGjG/YA52yKjo=; b=JzqwUAvF/wNPGMK/AIc48M/wt+tkJKzZTumGW/oc8Ye9Jo8iP739o9r/63wLY38Q9JLNDJ9xGI9+1JG/VkPCYUbwASd8/O1L5vQdB26FlgY0zyT+Pv65u0BReV7mbfBaW3rnXq0XV8bqq4MzgZpHH+HKtM2issczzTX9qCfTZTE= Received: from MW4P220CA0006.NAMP220.PROD.OUTLOOK.COM (2603:10b6:303:115::11) by CYXPR12MB9442.namprd12.prod.outlook.com (2603:10b6:930:e3::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.32; Mon, 25 Mar 2024 22:28:27 +0000 Received: from MWH0EPF000A672E.namprd04.prod.outlook.com (2603:10b6:303:115:cafe::95) by MW4P220CA0006.outlook.office365.com (2603:10b6:303:115::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.13 via Frontend Transport; Mon, 25 Mar 2024 22:28:27 +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 MWH0EPF000A672E.mail.protection.outlook.com (10.167.249.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Mon, 25 Mar 2024 22:28:27 +0000 Received: from tlendack-t1.amdoffice.net (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.35; Mon, 25 Mar 2024 17:28:23 -0500 From: Tom Lendacky To: , , , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , "Peter Zijlstra" , Dan Williams , Michael Roth , Ashish Kalra Subject: [PATCH v3 14/14] x86/sev: Allow non-VMPL0 execution when an SVSM is present Date: Mon, 25 Mar 2024 17:26:33 -0500 Message-ID: X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: MWH0EPF000A672E:EE_|CYXPR12MB9442:EE_ X-MS-Office365-Filtering-Correlation-Id: 705f9240-2bfe-4e4c-8dc9-08dc4d1ae457 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IWOb9zllJcGUFT1gcnyEj1NulCRvbX612wGiaS2fXUapOGN+ehGsF0nCpEdf9qAKUWqFyVx55OoM36hEUxl5bC03z16CVnX/OP/B6lV+n0crZxrEoYLeh6K4P8pu/o3TJU3Pp74dSZjmId97JYirjWRioW4Mr1bbXjpQmOQ6+c8387hTYyMWrHK5zouEKlAhhG+CZGdUchxgmaeSl0a1SC1Z42xCz9cf11Po2PGfogm6ztjVzeIzRsG6jB514y3X44YEbDLnIM9TQuNxdhwSu2znBxytYonTccpseaZDdFiWsLTBj/qVPiwpTR+Ry0oNLHT8u19GiF2MmnbC9BdKLa8y/0fnezMa1TMPqEf+4DE97SMSpAXIA8zcck32nW8Ffb78j5FQBwaz093qaIaGL+Gh6CQzrodHmuPzkQSgnqS2YG78pkXGBSs2HFBLQnrWxufnQlwacSFok5Teem3ZfT0H73ghFFbBzZmpOBq2figQzGl7Zt3i41toUrh5Db4jUKWxt9++vM9LE/hbBmexDI4JxdTq1hUCICN6f6eIqDalCi/skXXxFbJ23eqWO5V+BrBeRUlAVTlmKZnilU/grnMRZGJzDybbMUQPji4zNymPUqimmYG+B7zXLRkQ1RtRmeuBczVgY7dPPrRRiL97EaAG4nX9h8gcsJO7dqyq8z/rTEpRhr40QsmZ9g1HFubSiyvLbfLscPI8R/unCtcgzybenynNPLcDjuKry1fPt5kqOKKDKQm2Y3+QqDFvtQc9 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)(7416005)(36860700004)(82310400014)(376005)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2024 22:28:27.3480 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 705f9240-2bfe-4e4c-8dc9-08dc4d1ae457 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: MWH0EPF000A672E.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYXPR12MB9442 Content-Type: text/plain; charset="utf-8" To allow execution at a level other than VMPL0, an SVSM must be present. Allow the SEV-SNP guest to continue booting if an SVSM is detected and the hypervisor supports the SVSM feature as indicated in the GHCB hypervisor features bitmap. Signed-off-by: Tom Lendacky --- arch/x86/boot/compressed/sev.c | 11 +++++++++-- arch/x86/include/asm/sev-common.h | 1 + arch/x86/kernel/sev.c | 20 +++++++++++++++++--- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c index f8407ee83ac8..974201ba2499 100644 --- a/arch/x86/boot/compressed/sev.c +++ b/arch/x86/boot/compressed/sev.c @@ -619,10 +619,17 @@ void sev_enable(struct boot_params *bp) * features. */ if (sev_status & MSR_AMD64_SEV_SNP_ENABLED) { - if (!(get_hv_features() & GHCB_HV_FT_SNP)) + u64 hv_features =3D get_hv_features(); + + if (!(hv_features & GHCB_HV_FT_SNP)) sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SNP_UNSUPPORTED); =20 - if (!running_at_vmpl0(&boot_ghcb_page)) + /* + * VMPL0 is not required if an SVSM is present and the hypervisor + * supports the required SVSM GHCB events. + */ + if (!running_at_vmpl0(&boot_ghcb_page) && + !(vmpl && (hv_features & GHCB_HV_FT_SNP_MULTI_VMPL))) sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_NOT_VMPL0); } =20 diff --git a/arch/x86/include/asm/sev-common.h b/arch/x86/include/asm/sev-c= ommon.h index 71db5ba020b9..3de377a4e981 100644 --- a/arch/x86/include/asm/sev-common.h +++ b/arch/x86/include/asm/sev-common.h @@ -118,6 +118,7 @@ enum psc_op { =20 #define GHCB_HV_FT_SNP BIT_ULL(0) #define GHCB_HV_FT_SNP_AP_CREATION BIT_ULL(1) +#define GHCB_HV_FT_SNP_MULTI_VMPL BIT_ULL(5) =20 /* * SNP Page State Change NAE event diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index 0a06632898c6..fd3a832c65ec 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -2366,22 +2366,36 @@ static void dump_cpuid_table(void) * sort of indicator, and there's not really any other good place to do it, * so do it here. */ -static int __init report_cpuid_table(void) +static void __init report_cpuid_table(void) { const struct snp_cpuid_table *cpuid_table =3D snp_cpuid_get_table(); =20 if (!cpuid_table->count) - return 0; + return; =20 pr_info("Using SNP CPUID table, %d entries present.\n", cpuid_table->count); =20 if (sev_cfg.debug) dump_cpuid_table(); +} + +static void __init report_vmpl_level(void) +{ + if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) + return; + + pr_info("SNP running at VMPL%u.\n", vmpl); +} + +static int __init report_snp_info(void) +{ + report_vmpl_level(); + report_cpuid_table(); =20 return 0; } -arch_initcall(report_cpuid_table); +arch_initcall(report_snp_info); =20 static int __init init_sev_config(char *str) { --=20 2.43.2