From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=40.107.201.9 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796510144; b=xHcOWr8wVtrjxqv5nme1ZP4MMeyWpJt4zI4UJHVlNBhVczrX/xHIlTGzmDQZpvZSM7Gj yfUQbIq8XCPs3hIdegQCl2VpexGlefsomZgN1wXrxLAydW7httJC6bp6sdpUndHO/o15R GYcRWw+76tsamx/tfImjghQ2b0KrjhrhtkLELyJ+gvtUc5WW3H2Qb1Ecg/FTlyY2/6ry9 Sk/F7R8n7kQAuN1b1y+5fiv4R121vysPAV2YDE/ivSo0HvYpoSpQ990BgzMeZERM/6HNN gzdTh5ifEnbjzovzv1Z2nDSTNYeEinvgrgD4OL6hD2SPbTPFENNxQWaV2U67+p1No+A== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796510144; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding:Content-Type:X-Originating-IP: X-ClientProxiedBy:X-EOPAttributedMessage:X-MS-PublicTrafficType: X-MS-TrafficTypeDiagnostic:X-MS-Office365-Filtering-Correlation-Id: X-MS-Exchange-SenderADCheck:X-MS-Exchange-AntiSpam-Relay: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=6tg5QmpuL9auyHklc8wiMThVgdeUwNRqgJ65RarkqRs=; b=L0U+Qy0NCBXJ8PwSBcE59KGFRsryDFQNQ+3d7GAp965eLzp309Tg8OrDA1TMy2A83KPA eMEYRq0w791K/E5ie0MtoHyfIlbJm3bDB+LbrMIFuaJd6VraRaRg8IhIWQ1pHiZOsFxr4 /UjIPQ/0w9E6XV92E9HXQts7HJrUPwLDWQtZ1fhocoJXolvIQzavNHG2jyYM075LjYeoW h+BbU/ArdKFPxuIOJkBb8X8j/G5XQjCmbOlqKhnmKZFDaMYbNjBfmHGED4b8q9TzPCwDA JtQvcw7Cz78InUBGbZ2EJq2x7rorTm7XqwI3zvn2XHHEuipjY8pV9ZXEhrp9ZhC+WBg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=Xq+2SfAJ; arc=pass header.oldest-pass=0 smtp.remote-ip=40.107.201.9 Received: from CH4PR04CU002.outbound.protection.outlook.com (mail-northcentralusazon11013009.outbound.protection.outlook.com [40.107.201.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B7EA606A336; Sat, 5 Dec 2026 22:35:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3B7EA606A336 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, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=Xq+2SfAJ ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=hmCm314ChdI/2aj03pWSsi/uRWFQAQxyLTc8+geHtd1N3qNVSFwXjSs0iAuwR7jnksakDg7GUKdzRFafHsLV4UTNFAdRdZFNpezYYcWBKaHFDD7CIZ3GdwtRgwb9P5B8mLU47leZGRVeiT9nu1ZKUVgUk/YFMjd0yeoL3WjwCeLAy8R95jlYW4VO5GRQjzGw0khC9On//+J+pRcd+zZXL4uDboUMPt7oe1dtSdpbffIPTObP3MyVMkE3cZLzW//T7v+ZfgQjtSN2hANFzjSy2NBsO77KcqfKa+X8JDfwwSYu8PS9xoH94OydCs1Sy9WSx1+M4nDgFA7DIHMsMnSBUw== 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=6tg5QmpuL9auyHklc8wiMThVgdeUwNRqgJ65RarkqRs=; b=s2v5tRI1XxJlY+oewhh0MhygdN4jb0ePLN0zZUGoCaSHZOQ56yPuRFbu/UU7/F0q/5jqWy15mrsqolV2ksMKL8bIX4HTSW8W6ujxT8212EDnDh8GvHxSXN3CQB3Pqcvo97IsUUqlX8kIhAuk4PLNhHkTm6nX6LgKCzWo82BT0r5y/HgIIzucRmXsW0UWey/+9ioOx2gQzWzL5sDh3x4LKxtmNOQ2T97itgaZMDApeotpnjgUP+XQqEOCHfxtNj32f9uoJZkb9UX6IuGbVkmP0g6kDCzWR9R4aMO4c14rqs+5mSzz3LglyUwHOCYhdUuuCxvBEyMkHE+0wpot0/45yA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=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=6tg5QmpuL9auyHklc8wiMThVgdeUwNRqgJ65RarkqRs=; b=Xq+2SfAJJQS6U/6o4ahxGbmfk4CS9sDViBEbCXFGPG9FMArgXdsSbAnG5NfPMjNyZrBR9NVZKep1aS7c5bKCTatwRHc5TlMgkjzJAaqmjY6ZJZKciWOHAZWT5IPfyDplWER3bU3z4gWuVGkMiG9aN6kxvh/BsBtznOXMPC+OaVw= Received: from BN0PR02CA0040.namprd02.prod.outlook.com (2603:10b6:408:e5::15) by IA4PR12MB480337.namprd12.prod.outlook.com (2603:10b6:207:105::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.13; Sat, 5 Dec 2026 22:35:40 +0000 Received: from LV8PEPF00000060.namprd02.prod.outlook.com (2603:10b6:408:e5:cafe::88) by BN0PR02CA0040.outlook.office365.com (2603:10b6:408:e5::15) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.688.13 via Frontend Transport; Sat, 5 Dec 2026 22:35:40 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; 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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by LV8PEPF00000060.mail.protection.outlook.com (10.167.245.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.709.6 via Frontend Transport; Sat, 5 Dec 2026 22:35:40 +0000 Received: from speedway8455host.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Sat, 5 Dec 2026 16:35:39 -0600 From: "Pratik R. Sampat" To: , , , CC: , , , , , , , , , , , , , Subject: [Patch v6 3/3] KVM: SVM: Add host support for Enhanced SMT Protection Date: Sat, 5 Dec 2026 22:35:00 +0000 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV8PEPF00000060:EE_|IA4PR12MB480337:EE_ X-MS-Office365-Filtering-Correlation-Id: 491eb577-43e1-49f0-653d-08df5320170a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700016|7416014|376014|23010399003|1800799024|10067099003|56012099006|261009223027099003|11063799006|3023799007|261022075727099003|261022105027099003|261026140227099003|261021121427099003|261021123027099003|261028144727099003|261026121527099003|261102123227099003|6133799003|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: cD0c6wT5ZD9gJwN/raj/9ZCymIH9TNEkqRst8ogb7OBm4HKV+3jcP0qgcboc3Dbjm9egGUjsiWjxxP7eCUcJf51TMjWYTrcX9V5Gzu1yr5S5Q44YQIoChmbaqCZX4f4NGP9WBUBcmmOLdj+IIWEM5yz6EVqUrMISLafkrbF04ynGzKNTVoH+i9Wy97vONUOqZ1FKmQOtbf3xyo1qjgX9FAJknCcTpr510Sw2ngq82Qk017n6zw0uFJSXu8B4Qy20YqJ03NGuNFwWiMQi7H2QTTcCBISMCpSc+tqbDojdENF1ghS3RMwtD4i30rWHyvnZX7xwPMwCFPYsjIqSSsnQ+HjWFkTW3p+boq8ApeQxhcf+T1R4oKiv6WdWQZ0PEE5GX+M1skJobRLVdEM0WmZN5cBq/31tuzsPCt3Qjp+YnG2hyN1Wr/w81/xioLib5dZdrCXbMVMxpKXFGYFOGk6ui/sQKrBFLzUFCQqqmToQc3UR002zKsa2OGxLxZ1i4KK1LhFl3Gn4W08De5md7dOmKosCTLHydux5IIscXtkvFZHoL+saL//sTDMbrseISB9Xa11Ib9shiv6P356Ro3EBDvCQah+8Fg+gxC96DHGgEk69rhDnXVgMjuBsJWnPbY1HasMzOYsWVtXTk9pt+qqAhlUFKTt8VQB8niNfpqfhMUmFHvz5l0U1TF2i6GQuUlwld3XEbNcJoE8ucQXOhR51Jw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(36860700016)(7416014)(376014)(23010399003)(1800799024)(10067099003)(56012099006)(261009223027099003)(11063799006)(3023799007)(261022075727099003)(261022105027099003)(261026140227099003)(261021121427099003)(261021123027099003)(261028144727099003)(261026121527099003)(261102123227099003)(6133799003)(22082099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Qa4d4WOZ5DFByWW/859zavGRtnxlWi/kCTk5caYeVTaE/soQ0Cfpr7FlKk2y/03LHC7rMVSKZS01r3cEdWgpYJKgfs7cwadE3xObzFWy3ZzvlVtEwKnW7jbo/c4BtnuumcH89S07VXMuSm0sI5rG6yX8zZxuYrKCxzKHdjNJSrIQPXgLYYAmRDNFFJXaq63jyOT/5lrgFI/VWKKNg3oCQgNSsRlbNQtefaTXbC2T3xQOtXdUW82SjWHWQ2jhuraSlxjJGw997LjBPnx7Kx1yVAGP65eUD31rXS8qUPYLthepk5uyqSql+1yVVKvhPhC+YYt+oKMjySg44iTB05g8OkcF2k0NMRH87bXmYwZQK0EFx/i9qio4ChD6d+rFkaDQIjcYj6CqK6bKGmEh1ExMhUv0MDRN+EtDM+bo+bhYefLB/gSlXyMm7FB/Mr3jHrNV X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Dec 2026 22:35:40.0051 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 491eb577-43e1-49f0-653d-08df5320170a 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: LV8PEPF00000060.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA4PR12MB480337 Enhanced SMT Protection (ESMTP) protects an SEV-SNP guest for ZEN 5+ systems from SMT side channels by requiring that, while a vCPU is in guest mode, its SMT sibling thread is either idle in host mode or executing a vCPU the guest has declared to be a legal sibling. A legal sibling is another ESMTP vCPU of the same guest that carries the same VCPU_SIBLING_MASK and agrees on VCPU_ID outside that mask. Hardware enforces this at VMRUN, which no longer enters guest mode right away but stalls until the condition holds. Three new exits report that it could not be met, all of them non-fatal: ESMTP_ILLSIB: a sibling thread is running a vCPU that is not a legal sibling of this one. ESMTP_TIMEOUT: the stall exceeded the timeout programmed in the VMCB. The timer bounds how long VMRUN waits for the core to settle. A module parameter exposes an interface to program this timer. ESMTP_RETRY: If DBREQ is detected, VMRUN exits. ESMTP_RETRY indicates an internal event and the hypervisor should execute a VMRUN. ESMTP synchronizes exits as well: when one thread leaves guest mode, hardware kicks any sibling that is still running guest code by writing the IDLE_WAKEUP_ICR MSR value to the APIC ICR. Program IDLE_WAKEUP_ICR when ESMTP is supported, as is already done for SMT Protection. ESMTP and SMT Protection are mutually exclusive, and VMRUN fails with VMEXIT_INVALID if both are set, so reject KVM_SEV_INIT2 requests that ask for both. Refer to the AMD64 APM Vol 2, section "AMD64 Enhanced SMT Protection". Reviewed-by: Tom Lendacky Acked-by: Borislav Petkov (AMD) # non-virtualization changes Signed-off-by: Pratik R. Sampat --- v5..v6: * Move IDLE_WAKEUP_ICR programming to patch 2 since SMT protection also depends on it --- .../admin-guide/kernel-parameters.txt | 19 +++++++++++ arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/svm.h | 4 ++- arch/x86/include/uapi/asm/svm.h | 9 +++++- arch/x86/kernel/cpu/scattered.c | 1 + arch/x86/kvm/svm/sev.c | 32 +++++++++++++++++-- arch/x86/kvm/svm/svm.c | 6 +++- 7 files changed, 67 insertions(+), 5 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 515028e4ac46..2d9b3cbe32b9 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -3260,6 +3260,25 @@ Kernel parameters max_snp_asid == min_sev_asid-1, will effectively make SEV-ES unusable. + kvm-amd.esmtp_timeout_ns= + [KVM,AMD] Enhanced SMT Protection (ESMTP) VMRUN + timeout, in nanoseconds, for SEV-SNP guests that enable + ESMTP. When an ESMTP vCPU executes VMRUN, hardware + waits for every sibling thread to either be idle or + run a legal sibling vCPU of the same guest before + entering guest mode. If the wait exceeds this timeout, + VMRUN exits with VMEXIT_ESMTP_TIMEOUT and KVM retries + the VMRUN. + + The value is converted to TSC cycles and programmed + into the VMCB when a vCPU is initialized, so changing + it at runtime only affects vCPUs that are created or + reset afterwards. + + Default is 0, which disables the timeout, i.e. VMRUN + waits until the sibling condition is met or a physical + interrupt arrives. + kvm-arm.mode= [KVM,ARM,EARLY] Select one of KVM/arm64's modes of operation. diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index 4840e90ba3c4..359bbcf3b61e 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -537,6 +537,7 @@ * and purposes if CLEAR_CPU_BUF_VM is set). */ #define X86_FEATURE_X2AVIC_EXT (21*32+20) /* AMD SVM x2AVIC support for 4k vCPUs */ +#define X86_FEATURE_AMD_ESMTP (21*32+21) /* AMD Enhanced SMT Protection */ /* * BUG word(s) diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h index a2331f5e533c..84122c7e7c50 100644 --- a/arch/x86/include/asm/svm.h +++ b/arch/x86/include/asm/svm.h @@ -165,7 +165,8 @@ struct __attribute__ ((__packed__)) vmcb_control_area { u8 reserved_9[22]; u64 allowed_sev_features; /* Offset 0x138 */ u64 guest_sev_features; /* Offset 0x140 */ - u8 reserved_10[128]; + u64 esmtp_timeout; /* Offset 0x148 */ + u8 reserved_10[120]; u64 pml_addr; /* Offset 0x1c8 */ u16 pml_index; /* Offset 0x1d0 */ u8 reserved_11[526]; @@ -315,6 +316,7 @@ static_assert((X2AVIC_4K_MAX_PHYSICAL_ID & AVIC_PHYSICAL_MAX_INDEX_MASK) == X2AV #define SVM_SEV_FEAT_DEBUG_SWAP BIT(5) #define SVM_SEV_FEAT_SECURE_TSC BIT(9) #define SVM_SEV_FEAT_SMTP BIT(15) +#define SVM_SEV_FEAT_ESMTP BIT(17) #define VMCB_ALLOWED_SEV_FEATURES_VALID BIT_ULL(63) diff --git a/arch/x86/include/uapi/asm/svm.h b/arch/x86/include/uapi/asm/svm.h index f9f972177b08..66faf87fb5c2 100644 --- a/arch/x86/include/uapi/asm/svm.h +++ b/arch/x86/include/uapi/asm/svm.h @@ -137,6 +137,10 @@ #define SVM_EXIT_ERR -1ull #define SVM_EXIT_IDLE_REQUIRED -3ull /* SMT Protection: sibling not idle */ +/* Enhanced SMT Protection VM exits taken during VMRUN sibling sync */ +#define SVM_EXIT_ESMTP_ILLSIB -5ull /* Illegal ESMTP sibling */ +#define SVM_EXIT_ESMTP_TIMEOUT -6ull /* ESMTP_TIMEOUT expired */ +#define SVM_EXIT_ESMTP_RETRY -7ull /* Internal event; retry VMRUN */ #define SVM_EXIT_REASONS \ { SVM_EXIT_READ_CR0, "read_cr0" }, \ @@ -250,7 +254,10 @@ { SVM_VMGEXIT_AP_CREATION, "vmgexit_ap_creation" }, \ { SVM_VMGEXIT_HV_FEATURES, "vmgexit_hypervisor_feature" }, \ { SVM_EXIT_ERR, "invalid_guest_state" }, \ - { SVM_EXIT_IDLE_REQUIRED, "idle_required" } + { SVM_EXIT_IDLE_REQUIRED, "idle_required" }, \ + { SVM_EXIT_ESMTP_ILLSIB, "esmtp_illsib" }, \ + { SVM_EXIT_ESMTP_TIMEOUT, "esmtp_timeout" }, \ + { SVM_EXIT_ESMTP_RETRY, "esmtp_retry" } #endif /* _UAPI__SVM_H */ diff --git a/arch/x86/kernel/cpu/scattered.c b/arch/x86/kernel/cpu/scattered.c index c990245d29d6..6d0cf3bee31b 100644 --- a/arch/x86/kernel/cpu/scattered.c +++ b/arch/x86/kernel/cpu/scattered.c @@ -71,6 +71,7 @@ static const struct cpuid_bit cpuid_bits[] = { { X86_FEATURE_AMD_LBR_V2, CPUID_EAX, 1, 0x80000022, 0 }, { X86_FEATURE_AMD_LBR_PMC_FREEZE, CPUID_EAX, 2, 0x80000022, 0 }, { X86_FEATURE_RMPOPT, CPUID_EDX, 0, 0x80000025, 0 }, + { X86_FEATURE_AMD_ESMTP, CPUID_EDX, 1, 0x80000025, 0 }, { X86_FEATURE_AMD_HTR_CORES, CPUID_EAX, 30, 0x80000026, 0 }, { 0, 0, 0, 0, 0 } }; diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index ad802211ec4f..915acb2c973e 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -67,6 +67,11 @@ module_param_named(sev_snp, sev_snp_enabled, bool, 0444); static unsigned int __ro_after_init nr_ciphertext_hiding_asids; module_param_named(ciphertext_hiding_asids, nr_ciphertext_hiding_asids, uint, 0444); +static unsigned int esmtp_timeout_ns; +module_param(esmtp_timeout_ns, uint, 0644); +MODULE_PARM_DESC(esmtp_timeout_ns, + "ESMTP VMRUN sibling-wait timeout in nanoseconds (default: 0, timer disabled)"); + #define AP_RESET_HOLD_NONE 0 #define AP_RESET_HOLD_NAE_EVENT 1 #define AP_RESET_HOLD_MSR_PROTO 2 @@ -520,11 +525,17 @@ static int __sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp, return -EINVAL; if (!snp_active) - valid_vmsa_features &= ~(SVM_SEV_FEAT_SECURE_TSC | SVM_SEV_FEAT_SMTP); + valid_vmsa_features &= ~(SVM_SEV_FEAT_SECURE_TSC | + SVM_SEV_FEAT_ESMTP | SVM_SEV_FEAT_SMTP); if (data->vmsa_features & ~valid_vmsa_features) return -EINVAL; + /* VMRUN fails with VMEXIT_INVALID if both are set. */ + if ((data->vmsa_features & SVM_SEV_FEAT_SMTP) && + (data->vmsa_features & SVM_SEV_FEAT_ESMTP)) + return -EINVAL; + if (data->ghcb_version > GHCB_VERSION_MAX || (!es_active && data->ghcb_version)) return -EINVAL; @@ -1035,6 +1046,15 @@ static int sev_es_sync_vmsa(struct vcpu_svm *svm) save->sev_features = sev->vmsa_features; + if (sev->vmsa_features & SVM_SEV_FEAT_ESMTP) { + save->vcpu_id = vcpu->vcpu_id; + /* + * All vCPUs of a guest are put into one group and can be run + * co-resident on the sibling thread of the same core. + */ + save->vcpu_sibling_mask = U32_MAX; + } + /* * Skip FPU and AVX setup with KVM_SEV_ES_INIT to avoid * breaking older measurements. @@ -3286,6 +3306,9 @@ void __init sev_hardware_setup(void) if (sev_snp_enabled && cpu_feature_enabled(X86_FEATURE_SMT_PROT)) sev_supported_vmsa_features |= SVM_SEV_FEAT_SMTP; + + if (sev_snp_enabled && cpu_feature_enabled(X86_FEATURE_AMD_ESMTP)) + sev_supported_vmsa_features |= SVM_SEV_FEAT_ESMTP; } void sev_hardware_unsetup(void) @@ -3322,7 +3345,8 @@ void sev_enable_idle_wakeup_icr(void) unsigned int cpu, sibling, shift; u32 core; - if (!(sev_supported_vmsa_features & SVM_SEV_FEAT_SMTP)) + if (!(sev_supported_vmsa_features & + (SVM_SEV_FEAT_SMTP | SVM_SEV_FEAT_ESMTP))) return; cpu = raw_smp_processor_id(); @@ -4865,6 +4889,10 @@ static void sev_es_init_vmcb(struct vcpu_svm *svm, bool init_event) svm->vmcb->control.allowed_sev_features = sev->vmsa_features | VMCB_ALLOWED_SEV_FEATURES_VALID; + if (sev->vmsa_features & SVM_SEV_FEAT_ESMTP) + svm->vmcb->control.esmtp_timeout = mul_u64_u32_div(esmtp_timeout_ns, + tsc_khz, 1000000); + /* Can't intercept CR register access, HV can't modify CR registers */ svm_clr_intercept(svm, INTERCEPT_CR0_READ); svm_clr_intercept(svm, INTERCEPT_CR4_READ); diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 7183c33a51ed..2556dd4b961f 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -3872,8 +3872,12 @@ static int svm_handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath) return 0; } - if (svm->vmcb->control.exit_code == SVM_EXIT_IDLE_REQUIRED) + if (svm->vmcb->control.exit_code == SVM_EXIT_IDLE_REQUIRED || + svm->vmcb->control.exit_code == SVM_EXIT_ESMTP_RETRY || + svm->vmcb->control.exit_code == SVM_EXIT_ESMTP_ILLSIB || + svm->vmcb->control.exit_code == SVM_EXIT_ESMTP_TIMEOUT) { return 1; + } if (exit_fastpath != EXIT_FASTPATH_NONE) return 1; -- 2.43.0