From patchwork Fri May 31 04:30:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13681123 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2057.outbound.protection.outlook.com [40.107.237.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 D00FF2135B; Fri, 31 May 2024 04:34:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717130075; cv=fail; b=m0jrfe+FssqvlyHykFqcolLFpgmrmZaQwtDXcOH1cYmB6VrjcFtwTkk7Cd35jYlhK2phIt93JXNddeblgjC6a6PuX8A36cYTPUad/k40h2gf8yl0dBs9MUux1BH7yBL65KgS6zEfPHSh3Gd6qW2AjK77X04igeR1wLIPoYLsb88= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717130075; c=relaxed/simple; bh=7RatBNCnIbDRhEKO1UiiuqJEpLxL39hIQkT7wV0TAJw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QKJZUoNn9Kj4qfLC5ZRRqgf9k2OEQyIf2iZjReagK2ZaLwMLyOINC54hSoPz11/3HAnc14ZNP/PfHmYaVbylDgZ/cy7PTcocdfd+DNE4pXw88C2PBTPpxUbaGapSo31yUvYklJYjaLGeJJt8iyMJDzYegmtwG0Hz6NRIMklU0cc= 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=gogVyGb+; arc=fail smtp.client-ip=40.107.237.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="gogVyGb+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j37lGsRfELBG8p5AIOwFGecRoEI7qnR46YIothLtZBSrnhwvDRRybS3MaAhD5MODKCqbqL+wgAkKUXkCbTpfzc8J3dRYeSPM/g+PXGAxSefu/y6uN8wKAkN92b1TJ5HHL2wqewMM40vC5rQ4Sf9Y87N1kS744gKMoFwVo46fpVLvWVAEFrIZS3DB4rOTCgv80WipnAZh9amD8uAq2ISmTymFeDUZjFli1cg0PEZgVa/zI+fKwxrH0qyU2DzjHSNLdc27wfYmQ2ZR0KOb8SK5YJePEPPICfsVYFzKFZheNvA6xx8BRf+oqaaozeolV/mfx0BrPkCrtVEdnhvKLdJTcg== 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=8FW1kVb2HUuaBogO5Iihlfq+YjSLq/wBGzEKbi3itwQ=; b=ZQJiD3NLjQwOFlljMeNZm1Nb6HkO/k81h9aHMSmlsF+sSaMheG9uNjWw9qjeC/j1L35IkM8E13xdovW01CMTkYWzR8mTPniSGZNbED1K0I0xJjI2keo1ku8Zjnx7AvWbQ01wuaLFDRSmlajhhJCgDaezzHlUOTLN7zc3p7DZ3ia10AXGmCkOQhz45klEY/1ZmwWRbWHv46OVoR9XdprrVOXmJ7ecH3hc4monhYDFgYo1mS/UhfLDewJaO5LYAso57h870KAoR0uxxVib43blXNEyLsMg4bjPMuO2wxxXvRFdHmjvrJTSCzv+H7g3txu365+B0smRfBBVQSlEVBcJEw== 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=8FW1kVb2HUuaBogO5Iihlfq+YjSLq/wBGzEKbi3itwQ=; b=gogVyGb+x7v31ArH5MSBHXy1u1EhlQ4VlI0/RYGcuI4FPISzOjpc7dReCzkSeuvhhXlLmCxOGFg3QZLJ2vsehKwiBVrJsYLYLTP8j/S6mKNNuokt15wNQropcYaAHmSd+ieq0hqNWK8fbjBDC3fj1QT70/ieDw1ljdQfIM0RLII= Received: from CH2PR07CA0058.namprd07.prod.outlook.com (2603:10b6:610:5b::32) by DM6PR12MB4042.namprd12.prod.outlook.com (2603:10b6:5:215::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.22; Fri, 31 May 2024 04:34:29 +0000 Received: from DS3PEPF000099D8.namprd04.prod.outlook.com (2603:10b6:610:5b:cafe::21) by CH2PR07CA0058.outlook.office365.com (2603:10b6:610:5b::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.28 via Frontend Transport; Fri, 31 May 2024 04:34:29 +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 DS3PEPF000099D8.mail.protection.outlook.com (10.167.17.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Fri, 31 May 2024 04:34:03 +0000 Received: from gomati.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.35; Thu, 30 May 2024 23:33:59 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v9 15/24] x86/sev: Cache the secrets page address Date: Fri, 31 May 2024 10:00:29 +0530 Message-ID: <20240531043038.3370793-16-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240531043038.3370793-1-nikunj@amd.com> References: <20240531043038.3370793-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@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: DS3PEPF000099D8:EE_|DM6PR12MB4042:EE_ X-MS-Office365-Filtering-Correlation-Id: da6abbc3-0884-434c-82c0-08dc812af5e2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|7416005|1800799015|376005|36860700004|82310400017; X-Microsoft-Antispam-Message-Info: 2Kq+m/pCm2g3gkTQpcTIhbARQ5ZWSVIW6OFWVSHbrJTO8A4zCr/yoh+s+RUAnDOvLr2yCn8QdN3ytKaAyoReN8TQ1rWyQipAgSPPuQMkoHaTCqtHfXOjDaTamT20LS27+iSMjGORqrifjq5jRte3zjbvPQj5qg4qQueYKccDkRBdleS8JWWsJc7uZr0UDy0BycEeDqjSSnhDM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aG7flcNDz7apBm1Vi+8Taeen1U+sxQmO8uDs/zSenN5L1ow6rViOuTjD6LQ9LfJEZUTQ1phOhQreGBL+U1QdgdTdiFVPHZBOQ0vPerKNmLdmuUiz469O1QHav8xs+ 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)(82310400017);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2024 04:34:03.8952 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: da6abbc3-0884-434c-82c0-08dc812af5e2 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: DS3PEPF000099D8.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4042 Instead of calling get_secrets_page() that parses the CC blob every time for getting the secrets page physical address(secrets_pa), save the secrets page physical address during snp_init() from the CC blob. Now that there are no users of get_secrets_page() drop the function. Signed-off-by: Nikunj A Dadhania --- arch/x86/kernel/sev.c | 51 ++++++++++--------------------------------- 1 file changed, 11 insertions(+), 40 deletions(-) diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index 878575b05b2d..141a670d2a85 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -93,6 +93,9 @@ static struct ghcb *boot_ghcb __section(".data"); /* Bitmap of SEV features supported by the hypervisor */ static u64 sev_hv_features __ro_after_init; +/* Secrets page physical address from the CC blob */ +static u64 secrets_pa __ro_after_init; + /* #VC handler runtime per-CPU data */ struct sev_es_runtime_data { struct ghcb ghcb_page; @@ -619,45 +622,13 @@ void noinstr __sev_es_nmi_complete(void) __sev_put_ghcb(&state); } -static u64 __init get_secrets_page(void) -{ - u64 pa_data = boot_params.cc_blob_address; - struct cc_blob_sev_info info; - void *map; - - /* - * The CC blob contains the address of the secrets page, check if the - * blob is present. - */ - if (!pa_data) - return 0; - - map = early_memremap(pa_data, sizeof(info)); - if (!map) { - pr_err("Unable to locate SNP secrets page: failed to map the Confidential Computing blob.\n"); - return 0; - } - memcpy(&info, map, sizeof(info)); - early_memunmap(map, sizeof(info)); - - /* smoke-test the secrets page passed */ - if (!info.secrets_phys || info.secrets_len != PAGE_SIZE) - return 0; - - return info.secrets_phys; -} - static u64 __init get_snp_jump_table_addr(void) { struct snp_secrets_page *secrets; void __iomem *mem; - u64 pa, addr; - - pa = get_secrets_page(); - if (!pa) - return 0; + u64 addr; - mem = ioremap_encrypted(pa, PAGE_SIZE); + mem = ioremap_encrypted(secrets_pa, PAGE_SIZE); if (!mem) { pr_err("Unable to locate AP jump table address: failed to map the SNP secrets page.\n"); return 0; @@ -2107,6 +2078,11 @@ bool __head snp_init(struct boot_params *bp) if (!cc_info) return false; + if (cc_info->secrets_phys && cc_info->secrets_len == PAGE_SIZE) + secrets_pa = cc_info->secrets_phys; + else + return false; + setup_cpuid_table(cc_info); /* @@ -2264,16 +2240,11 @@ static struct platform_device sev_guest_device = { static int __init snp_init_platform_device(void) { struct sev_guest_platform_data data; - u64 gpa; if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) return -ENODEV; - gpa = get_secrets_page(); - if (!gpa) - return -ENODEV; - - data.secrets_gpa = gpa; + data.secrets_gpa = secrets_pa; if (platform_device_add_data(&sev_guest_device, &data, sizeof(data))) return -ENODEV;