From patchwork Fri Jan 3 20:01:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 854912 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2058.outbound.protection.outlook.com [40.107.223.58]) (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 9A2301BBBF1; Fri, 3 Jan 2025 20:02:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.58 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735934529; cv=fail; b=jTFb/ZZyd86Ek6zIE2Qf1OLX1F+bgRGsvD6JE3mTO+fObF2VkzAeOh/z3uCrzeiR8TAnqxXBNVaNYm/vusjg2BVq4hVWaCG0B+KjERZtVMQmY4EO7klz5L3/+o9yw5khgxuRUpKm7S3OQHCGKzyLbczoyafDY7+tf1QV/kz8OXs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735934529; c=relaxed/simple; bh=3WVBlN6W2cc3jq7KTXYDW0VvO1JMun4z1wdx2ZFHe3o=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZGaHjqu1yhjNLPPTrOIyhfm86GmRrrsirlCGWNsHQAOxcTHRFJZzt6/0DT67bs5LHQA/YXt+EBgFPH7ARPvvAioVgV3hhehi8TKQYK/rFolg3lJOMzQPQVEOzMb5jRCVhyLEvwyAlBmEFBSHDvdBBYF9u1fAxQJ+r/NFuobv3dM= 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=2psI60Qh; arc=fail smtp.client-ip=40.107.223.58 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="2psI60Qh" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Gb0Ng/1YNOMgLcEJ3jU26msG1KpZEdWPFuiOkhBWnZI/5uZQJtuemGG+a84VdiLeTJJp3ohNsSCCeA0bxZw1HjczFwwGP0p4j83aty2K77WITB6yuhrRa61yUZyabcuQ2DISNSWQt7sEuDQQhpEYJxleMNyX+vFqj2OseVDPiDMnXSOkZNziFHNgCJUgHLsWl6WbAuOaHPAL2DGx3tE1+ZUCJxlXVx1vZN63A5diiQWM+DVpqR43/Z2y4VXCzMdfmgQHb71nwK8l2fhWlnIspwDw6KG8P20gZKU2Lp1PpTdDV4HuDURSaHKc9gpmV1wLL8wVvxz5XbWDOPaDEUBKaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=fJp5bO021neq9pm8lBDqNpqpM5PPNhfaH5qCwyw4Prg=; b=ilKQTVPZ0I5Y8tm7nyu47BW4MUpF24egOFQBH00AcxFZQMc1CrloHxDpDyJZIXxHoEuYIcsiQwXjPRVUiIj1Xfr2w1nZ8X3VfsOhf8zheelp1NmLj6agePymbTxweOYdvFa9pRN+pkHc60Nxb2LKs0YlrxV2MtdWteihfV2SmUqoqyqHRJUZnl5PvduXIfSocu5Eg31XjjJWNFJ4kLW8ObFOqv5QF/lzt9nUdJLgqpXg9uM1UFit/0TIci29j42pFXP8sKtvVYCNknPLnSV7vHZqjUMakNfSKjgd14QYDyXSoiH4C0U2JsbOTapXroDlXD0cjURVdNxJO64HG8yPsg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=google.com 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=fJp5bO021neq9pm8lBDqNpqpM5PPNhfaH5qCwyw4Prg=; b=2psI60QhWbwERj2BI1OdthH1RRavcLNKYh5D94d+OnUBfMfOx6F1YEd2KKZVeZ/53Ms3LzOX9bE01hZkRRMHH1UY9RU/UoTZD5ji5NEsgOYvacskrt6MTJgfoYNtS8K60+FGMf9auH/ZVPz78sMNMQnagD3EF4SAsMO2YQkFnfc= Received: from CH0PR13CA0036.namprd13.prod.outlook.com (2603:10b6:610:b2::11) by MN6PR12MB8516.namprd12.prod.outlook.com (2603:10b6:208:46f::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.11; Fri, 3 Jan 2025 20:01:57 +0000 Received: from CH1PEPF0000A346.namprd04.prod.outlook.com (2603:10b6:610:b2:cafe::ae) by CH0PR13CA0036.outlook.office365.com (2603:10b6:610:b2::11) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8335.6 via Frontend Transport; Fri, 3 Jan 2025 20:01:57 +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 CH1PEPF0000A346.mail.protection.outlook.com (10.167.244.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8335.7 via Frontend Transport; Fri, 3 Jan 2025 20:01:57 +0000 Received: from ethanolx7e2ehost.amd.com (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.39; Fri, 3 Jan 2025 14:01:56 -0600 From: Ashish Kalra To: , , , , , , , , , , , CC: , , , , , Subject: [PATCH v3 6/7] KVM: SVM: Add support to initialize SEV/SNP functionality in KVM Date: Fri, 3 Jan 2025 20:01:47 +0000 Message-ID: <14f97f58d6150c6784909261db7f9a05d8d32566.1735931639.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0000A346:EE_|MN6PR12MB8516:EE_ X-MS-Office365-Filtering-Correlation-Id: b33d7066-6869-44eb-bf7e-08dd2c317a55 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|36860700013|82310400026|376014|7416014|921020; X-Microsoft-Antispam-Message-Info: eIn1hxulqCYQGbasD1CXokWxWftffDD3x2Na0bo+xOO4gvVpi59h90102+FLBAK6cXRfzLlfjSd3MZJaGFnVmPOeWs64T8HCCH10LdKktLLad1U6aaB5l2S1r4qyulCiDI3SFtgIt23ykKRsVaNDtsuE54lydVsatSwL5OiAmXs1Xiru4nPzZLokOY6mXgL/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UVtuOc8oD12B+4ngCGPnQoCe7E0x1o2B7keCbGuGvF6h0ilgx4hbVfxpL0ONKiGla2J78UMSeVQszFgFQBdmz/JCr2EALFq7ZuneqUB1hA3STtxNvBW67oitWwHJNjqdq4eY4dvFCS1Rh1BYG1VbXBTujVg+M37igjWLcyXN2y4uWSeUEScx6tgTWXSb9IetFynDdhM6LsYodez2nkccEQTbuevNa680FtFA+KPqvz2XdsOEFqn1mW3mDkEc617Gj1hfxnJMpcZRkZG1t0 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:(13230040)(1800799024)(36860700013)(82310400026)(376014)(7416014)(921020); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jan 2025 20:01:57.3155 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b33d7066-6869-44eb-bf7e-08dd2c317a55 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: CH1PEPF0000A346.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN6PR12MB8516 From: Ashish Kalra Remove platform initialization of SEV/SNP from PSP driver probe time and move it to KVM module load time so that KVM can do SEV/SNP platform initialization explicitly if it actually wants to use SEV/SNP functionality. With this patch, KVM will explicitly call into the PSP driver at load time to initialize SEV/SNP by default but this behavior can be altered with KVM module parameters to not do SEV/SNP platform initialization at module load time if required. Additionally SEV/SNP platform shutdown is invoked during KVM module unload time. Signed-off-by: Ashish Kalra --- arch/x86/kvm/svm/sev.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 943bd074a5d3..0dc8294582c6 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -444,7 +444,6 @@ static int __sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp, if (ret) goto e_no_asid; - init_args.probe = false; ret = sev_platform_init(&init_args); if (ret) goto e_free; @@ -2953,6 +2952,7 @@ void __init sev_set_cpu_caps(void) void __init sev_hardware_setup(void) { unsigned int eax, ebx, ecx, edx, sev_asid_count, sev_es_asid_count; + struct sev_platform_init_args init_args = {0}; bool sev_snp_supported = false; bool sev_es_supported = false; bool sev_supported = false; @@ -3069,6 +3069,16 @@ void __init sev_hardware_setup(void) sev_supported_vmsa_features = 0; if (sev_es_debug_swap_enabled) sev_supported_vmsa_features |= SVM_SEV_FEAT_DEBUG_SWAP; + + if (!sev_enabled) + return; + + /* + * NOTE: Always do SNP INIT regardless of sev_snp_supported + * as SNP INIT has to be done to launch legacy SEV/SEV-ES + * VMs in case SNP is enabled system-wide. + */ + sev_platform_init(&init_args); } void sev_hardware_unsetup(void) @@ -3084,6 +3094,9 @@ void sev_hardware_unsetup(void) misc_cg_set_capacity(MISC_CG_RES_SEV, 0); misc_cg_set_capacity(MISC_CG_RES_SEV_ES, 0); + + /* Do SEV and SNP Shutdown */ + sev_platform_shutdown(); } int sev_cpu_init(struct svm_cpu_data *sd)