From patchwork Tue May 20 00:02: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: 891162 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2066.outbound.protection.outlook.com [40.107.94.66]) (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 7CFB3335C7; Tue, 20 May 2025 00:03:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.66 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747699389; cv=fail; b=GIfnG3lcDJuREBymv4BNoJS8fbokNhKmxWZRfXxhXc1QoVa+QWVgOAGAxAN/iLsTVDRkl0yPjUTt2adreO2YhUvANf6W7+xDmdIjNdtjalQFgBO0US8flQu0MGIjvwsXYGbgoI6LI3TWHLSf8YvZ4y10Nbus+3NrAwwJQXbFiOs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747699389; c=relaxed/simple; bh=BaNzUTImRzdPjBturwi/5uz0NwWkgavQbTPx2vz7VqY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RVcg5JeaW2mwk/DblkoAPxcayWezGbV4sTw/d8wg3CpF/o/meUWFjoV/a4inh9ZpNYXbYls7lL6T/3Bu6cwbMmeRyS3JL6gg2mu6M93La5LgXhWxALh4CwEKUK5iX7ylGwUbyeKjc7+wEYqeWNLiHcwlyH+t3ln1CrHkEPwkdUs= 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=uzqgLw31; arc=fail smtp.client-ip=40.107.94.66 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="uzqgLw31" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=hDn9Yy7IMH8qpl5ausOGJlWfI6NpeGwAtqXCA1I9sv4U4dnsVmNCzsqBpA1ts61sr60LHAxZnm+T3QekyoQQhgmxr7kkdZdIpWev0oAemjwW99HTqxEi3fzhjDbE183ZqeFIImPXWedQbLkNmQ39xr2IKd0DzhDRT2d8PzlWAel1kSate1OhvoyB2nCtYAgdkygs7WgtoWiy6ODi44hiPir5bTCmiem/9E8CIiJq/Smx257+m6IyxC9pMmsQcNJFv4IIncsMsYXb7oXRk8YlHIvAPhaBCY7xcOiwQv4Q+DUdqKJH66bFHxOixyIHLGM5OD2MuVc9FFMy9g+9DvX7gQ== 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=fqqNuGg2xxDWvpxqCX9OYUfVnJDf8MFJJeN4KOt7hLQ=; b=Mp9K89cwKa478ITEcbOQMMyFEI9KkQCTTKodxVR0USA36evuVD27/UBDUw9AaHM4EwNsd7fbD+S7g6RYjWhrh5Wn7A1DgA55+IdrqkQXq3zZSvRvh56IVKW50nWBZKnt623puyERNnr9ibERcmoeqc24CSlOi9z7JlNOdfImSfeAJFD2ktstX+vu9sJpj+1UXahiU/DbVW+lggQtSBy2OtwHoftmVfn0zY9oafPB0LkVO6DUVve23RQ7xM7XYXl25xdxxIfLAJQF3sPwyaWb7eeO1cA8KbgaEhjbS4pSM4Or+pPGZ0NvVeeyoBLISQflI9L7eZY0kn0aLf/UXn0RcA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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=fqqNuGg2xxDWvpxqCX9OYUfVnJDf8MFJJeN4KOt7hLQ=; b=uzqgLw31fAhBX+Dp0CjQn5DRZ92Y1qwhiPRlaDxIPH1+Dgf2TP4gnPef0yQJ3PD2/5ert8I1MfaXHewub/3BFUJupqzRrwAGXzCZP9oVAfgW6zA3EewfMqgM5ZGBZQFBQpOg7kUsghcyAsJdk1ud1nZStQQUAm21MGF6ka87D4c= Received: from SJ0PR05CA0085.namprd05.prod.outlook.com (2603:10b6:a03:332::30) by SJ5PPF1C7838BF6.namprd12.prod.outlook.com (2603:10b6:a0f:fc02::98d) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8699.24; Tue, 20 May 2025 00:02:59 +0000 Received: from MWH0EPF000989E7.namprd02.prod.outlook.com (2603:10b6:a03:332:cafe::66) by SJ0PR05CA0085.outlook.office365.com (2603:10b6:a03:332::30) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8769.10 via Frontend Transport; Tue, 20 May 2025 00:02:59 +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 MWH0EPF000989E7.mail.protection.outlook.com (10.167.241.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8769.18 via Frontend Transport; Tue, 20 May 2025 00:02:59 +0000 Received: from purico-ed09host.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; Mon, 19 May 2025 19:02:56 -0500 From: Ashish Kalra To: , , , , , , , , , , , CC: , , , , , , , , , , , Subject: [PATCH v4 5/5] KVM: SEV: Add SEV-SNP CipherTextHiding support Date: Tue, 20 May 2025 00:02:47 +0000 Message-ID: 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: 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: MWH0EPF000989E7:EE_|SJ5PPF1C7838BF6:EE_ X-MS-Office365-Filtering-Correlation-Id: 9d912732-340d-4839-01bb-08dd9731ae64 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|7416014|36860700013|1800799024|376014|82310400026|921020; X-Microsoft-Antispam-Message-Info: Zea+Md+zU0PAs6p4UQtqODtQXMdEMqmdiG6zmeyJC6/YChR6gwo8i9xukO09TtV3HTm44yiYLl9e7zcqsoe3CUopC1B4kalNL/rKFyTgGhEH119oxcBvkmXqd2utlNl3bKv/1AU/0NJ7jUoV1FeJuItntKvFnn55+rdUnuJZiHhCHuuy20IXG9MKKQ+qvXWlIfQ0+c3B7IpA2hzVa6oAiwFN0uLgf7InHBwudgPWnUsE3Ta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esJMjH7sWnPfTbR70byEgKcA+URAE+ihCN96jNi4aNhze61EgteWvAO4uWjjklc1E5Hd/fHZ4zcx9vIFknRCROwgFhnCDZ6DkqjfFXUE0/BvUYKuCDlLo9pW1pYdvTWpGcXAheRUrwr2zSoiQSmDWq0FUf0r4GBsHcxpDCWUQg09wVEO7ha49VglfD9Lkt4JN6zUUPm3glcKWUWzN/9GDpolgMpFlRfBCpq9HA6zKzNQ== 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)(7416014)(36860700013)(1800799024)(376014)(82310400026)(921020); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 May 2025 00:02:59.0076 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9d912732-340d-4839-01bb-08dd9731ae64 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: MWH0EPF000989E7.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ5PPF1C7838BF6 From: Ashish Kalra Ciphertext hiding prevents host accesses from reading the ciphertext of SNP guest private memory. Instead of reading ciphertext, the host reads will see constant default values (0xff). The SEV ASID space is basically split into legacy SEV and SEV-ES+. CipherTextHiding further partitions the SEV-ES+ ASID space into SEV-ES and SEV-SNP. Add new module parameter to the KVM module to enable CipherTextHiding support and a user configurable system-wide maximum SNP ASID value. If the module parameter value is -1 then the ASID space is equally divided between SEV-SNP and SEV-ES guests. Suggested-by: Sean Christopherson Signed-off-by: Ashish Kalra --- .../admin-guide/kernel-parameters.txt | 10 ++++++ arch/x86/kvm/svm/sev.c | 31 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 1e5e76bba9da..2cddb2b5c59d 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -2891,6 +2891,16 @@ (enabled). Disable by KVM if hardware lacks support for NPT. + kvm-amd.ciphertext_hiding_nr_asids= + [KVM,AMD] Enables SEV-SNP CipherTextHiding feature and + controls show many ASIDs are available for SEV-SNP guests. + The ASID space is basically split into legacy SEV and + SEV-ES+. CipherTextHiding feature further splits the + SEV-ES+ ASID space into SEV-ES and SEV-SNP. + If the value is -1, then it is used as an auto flag + and splits the ASID space equally between SEV-ES and + SEV-SNP ASIDs. + kvm-arm.mode= [KVM,ARM,EARLY] Select one of KVM/arm64's modes of operation. diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 383db1da8699..68dcb13d98f2 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -59,6 +59,10 @@ static bool sev_es_debug_swap_enabled = true; module_param_named(debug_swap, sev_es_debug_swap_enabled, bool, 0444); static u64 sev_supported_vmsa_features; +static int ciphertext_hiding_nr_asids; +module_param(ciphertext_hiding_nr_asids, int, 0444); +MODULE_PARM_DESC(max_snp_asid, " Number of ASIDs available for SEV-SNP guests when CipherTextHiding is enabled"); + #define AP_RESET_HOLD_NONE 0 #define AP_RESET_HOLD_NAE_EVENT 1 #define AP_RESET_HOLD_MSR_PROTO 2 @@ -200,6 +204,9 @@ static int sev_asid_new(struct kvm_sev_info *sev, unsigned long vm_type) /* * The min ASID can end up larger than the max if basic SEV support is * effectively disabled by disallowing use of ASIDs for SEV guests. + * Similarly for SEV-ES guests the min ASID can end up larger than the + * max when CipherTextHiding is enabled, effectively disabling SEV-ES + * support. */ if (min_asid > max_asid) @@ -2955,6 +2962,7 @@ 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 snp_cipher_text_hiding = false; bool sev_snp_supported = false; bool sev_es_supported = false; bool sev_supported = false; @@ -3052,6 +3060,27 @@ void __init sev_hardware_setup(void) if (min_sev_asid == 1) goto out; + /* + * The ASID space is basically split into legacy SEV and SEV-ES+. + * CipherTextHiding feature further partitions the SEV-ES+ ASID space + * into ASIDs for SEV-ES and SEV-SNP guests. + */ + if (ciphertext_hiding_nr_asids && sev_is_snp_ciphertext_hiding_supported()) { + /* Do sanity checks on user-defined ciphertext_hiding_nr_asids */ + if (ciphertext_hiding_nr_asids != -1 && + ciphertext_hiding_nr_asids >= min_sev_asid) { + pr_info("ciphertext_hiding_nr_asids module parameter invalid, limiting SEV-SNP ASIDs to %d\n", + min_sev_asid); + ciphertext_hiding_nr_asids = min_sev_asid - 1; + } + + min_sev_es_asid = ciphertext_hiding_nr_asids == -1 ? (min_sev_asid - 1) / 2 : + ciphertext_hiding_nr_asids + 1; + max_snp_asid = min_sev_es_asid - 1; + snp_cipher_text_hiding = true; + pr_info("SEV-SNP CipherTextHiding feature support enabled\n"); + } + sev_es_asid_count = min_sev_asid - 1; WARN_ON_ONCE(misc_cg_set_capacity(MISC_CG_RES_SEV_ES, sev_es_asid_count)); sev_es_supported = true; @@ -3092,6 +3121,8 @@ void __init sev_hardware_setup(void) * Do both SNP and SEV initialization at KVM module load. */ init_args.probe = true; + if (snp_cipher_text_hiding) + init_args.snp_max_snp_asid = max_snp_asid; sev_platform_init(&init_args); }