From patchwork Mon Sep 30 05:50:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 13815410 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2062.outbound.protection.outlook.com [40.107.244.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 B245F2D7B8; Mon, 30 Sep 2024 05:51:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.62 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727675505; cv=fail; b=FPw9AtCtS+GBvKBLXEgDUGevyPyzd5WoRuG+LQIw+6hsm8PNrsXGZEzJbqHABysDzPLhR3+hmcyWIYkpLHXyAlhRHjcT66Q1EwpwubCO4e5DpkXww5UmZfvtoe3F9RsaVhP5QKyeew1K+heyoqkzxZmRBDqCSiF/EWuyh0oh0Gk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727675505; c=relaxed/simple; bh=ebRI2CfcmGvxA+kJ9GNE3pUNIIMBn0WXkNGX95zgXlA=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=sL7eeQNhdRludYSajLYLSmB/trl5OZD8b6rkDEIykQRgwA5DBisLbwTXt03/xrfEGPA74PidD+6oHnDDOSaDTUDD+GpYqIfLegvmTUi0vg7MK4upv6Ixtw4UNWf1iKnKWlcdjQNHy3gL2Tmn70bRrryF/J5nFRGQ/23tgJcMbho= 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=hSyeDSvd; arc=fail smtp.client-ip=40.107.244.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="hSyeDSvd" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Qjcm/2bJB1bSGaZKbk7rcYgdU3BvOKjQtYoFBBQVXVtZEiCH3Y7gjVDNHrVMC/BlBRWtduCFi7yNeHYpY8RnuZMjTNhcgUXLHoblwrSX3pQtxgz0r3TxhzDEpYKoYR8flify9Wmq3C100lkF2nTDAVCm4QmKkCyZMkguGBa06Jd4FO9wkZ+RTJl8Z9hrqURHU5+i2Wdyj4RIElgm9XSNih+pHWgDGxB6iMYovyx+hKxkzFuertS3Vm417+h5eO42EiucLH9kWyqyzQWRuJFWo96Oz4UJ9J2vfMjCRjCESOhTK3FN0kJxULIe2PvHg8WczllF6UmQxOPNPm66bBHd2g== 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=Qs46or+RWY0H641ytAqfmyEdFPGIr/umifWyuHQT/Tk=; b=H9C8TOI5G8YhmfeprGZQmaP7ldrSdIPGWTsjOJpZHJxOnBvkSxYz46JiykvYFjGN9g5ptxImWJw8XoXG1TI1p7FaTCV05VpYujIEN3vkXIpy+rteBCrLyVBYMWGF/a9HqTCuRtDSrHGkCFtuBCty+aRjRnOtnBCBkC6Y4sYeoj7rFYMQ4xOxbyCDAmgC8rbCYGvtjrWbNICIlOxajhN58Q38/tYd0xxBO//X0G4rFTbYVrn3JOSpnjRU3mbvhn7Ri3nmRNDzdxnyuzXaxbJ+5VVxAkvZEjoUSPMngtvpFxY49X3KdHUFay8E/CgoeT71QdvYTn2rXshHsspCuP8PPA== 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=Qs46or+RWY0H641ytAqfmyEdFPGIr/umifWyuHQT/Tk=; b=hSyeDSvdiHcPp5zK/gwHfb+ab8Q9Kye5C66+P61wMUs+mEMwVk8kn+X0CF89s8LQZI4atALX0uEyjfYjRqKTAo7ID0XPWQlytqBLP3eIhNs5cw2/RGzFRLOxCWeo01nITQmAIDUnrMF93JISIY9WGOJmLZ20EeVZ5HM52eheCqM= Received: from SN6PR04CA0105.namprd04.prod.outlook.com (2603:10b6:805:f2::46) by SJ0PR12MB8116.namprd12.prod.outlook.com (2603:10b6:a03:4ec::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.26; Mon, 30 Sep 2024 05:51:40 +0000 Received: from SA2PEPF00003AE4.namprd02.prod.outlook.com (2603:10b6:805:f2:cafe::9e) by SN6PR04CA0105.outlook.office365.com (2603:10b6:805:f2::46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.26 via Frontend Transport; Mon, 30 Sep 2024 05:51:39 +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 SA2PEPF00003AE4.mail.protection.outlook.com (10.167.248.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8026.11 via Frontend Transport; Mon, 30 Sep 2024 05:51:39 +0000 Received: from volcano-62e7host.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, 30 Sep 2024 00:51:11 -0500 From: Suravee Suthikulpanit To: , CC: , , , Suravee Suthikulpanit Subject: [PATCH] KVM: SVM: Disable AVIC on SNP-enabled system without HvInUseWrAllowed feature Date: Mon, 30 Sep 2024 05:50:35 +0000 Message-ID: <20240930055035.31412-1-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: kvm@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: SA2PEPF00003AE4:EE_|SJ0PR12MB8116:EE_ X-MS-Office365-Filtering-Correlation-Id: ae88b105-5f4a-4941-0773-08dce113f3e0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: =?utf-8?q?TD/Y3jL+OPAu7AscNY/n8W7MVhlMP8G?= =?utf-8?q?JXroqCgh3IgxoRTssAHz0xejrrxPPD50V9kyvUdIH27WMxprhQfpt7OlLP4yjZxcp?= =?utf-8?q?bdokOKjlHHY6p7Ts4DN6VMZIpdcfGP6yiZM5Jzy2lnJxSyDPYx5F/wCKbN7c3U8vP?= =?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Z9E0SW2Lix3g33q1vuFovpvbBwb5EbfNZVudsrbKrD+CMieVKYqxWJA4NaT4eD?= =?utf-8?q?VlqM4VRH5hhV/epAeaAqzw4VkvGvBoBE03GmLWfbg9YgG5UnWGa7gfSyr9r2ltSVK?= =?utf-8?q?lm6bv/EhKnqTvyWvS3r46+6tCRbiLEi+SIlL58bxMZAWWuuerN9RwFtbVOdOCx5mI?= =?utf-8?q?RoaOnPkqqbaBtvmTOqmmzWMyE1xUr5i7RLIkqT8OWvedptKv2flimEAddZocSO7S4?= =?utf-8?q?BT2jWSxdQe0iWWoxHRO90V8aKjBQxHjKkKW/eT8QPYz/z8dPAUOsamh07YTuq6yFE?= =?utf-8?q?YIK7t0XE2mLCUzkFe0AuaqrjnXQtDYCYWTKm3C56YhzulqjRHP3YYdsfqvjiP8hp4?= =?utf-8?q?cLqRra3wL8e?= 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)(82310400026)(376014)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2024 05:51:39.1160 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ae88b105-5f4a-4941-0773-08dce113f3e0 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: SA2PEPF00003AE4.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB8116 On SNP-enabled system, VMRUN marks AVIC Backing Page as in-use while the guest is running for both secure and non-secure guest. This causes any attempts to modify the RMP entries for the backing page to result in FAIL_INUSE response. This is to ensure that the AVIC backing page is not maliciously assigned to an SNP guest while the unencrypted guest is active. Currently, an attempt to run AVIC guest would result in the following error: BUG: unable to handle page fault for address: ff3a442e549cc270 #PF: supervisor write access in kernel mode #PF: error_code(0x80000003) - RMP violation PGD b6ee01067 P4D b6ee02067 PUD 10096d063 PMD 11c540063 PTE 80000001149cc163 SEV-SNP: PFN 0x1149cc unassigned, dumping non-zero entries in 2M PFN region: [0x114800 - 0x114a00] ... Newer AMD system is enhanced to allow hypervisor to modify RMP entries of the backing page for non-secure guest on SNP-enabled system. This enhancement is available when the CPUID Fn8000_001F_EAX bit 30 is set (HvInUseWrAllowed) See the AMD64 Architecture Programmer’s Manual (APM) Volume 2 for detail. (https://www.amd.com/content/dam/amd/en/documents/ processor-tech-docs/programmer-references/40332.pdf) Therefore, add logic to check the new CPUID bit before enabling AVIC on SNP-enabled system. Signed-off-by: Suravee Suthikulpanit --- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/kvm/svm/avic.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index dd4682857c12..921b6de80e24 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -448,6 +448,7 @@ #define X86_FEATURE_SME_COHERENT (19*32+10) /* AMD hardware-enforced cache coherency */ #define X86_FEATURE_DEBUG_SWAP (19*32+14) /* "debug_swap" AMD SEV-ES full debug state swap support */ #define X86_FEATURE_SVSM (19*32+28) /* "svsm" SVSM present */ +#define X86_FEATURE_HV_INUSE_WR_ALLOWED (19*32+30) /* Write to in-use hypervisor-owned pages allowed */ /* 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 Breakpoints */ diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c index 4b74ea91f4e6..42f2caf17d6a 100644 --- a/arch/x86/kvm/svm/avic.c +++ b/arch/x86/kvm/svm/avic.c @@ -1199,6 +1199,12 @@ bool avic_hardware_setup(void) return false; } + if (cc_platform_has(CC_ATTR_HOST_SEV_SNP) && + !boot_cpu_has(X86_FEATURE_HV_INUSE_WR_ALLOWED)) { + pr_warn("AVIC disabled: missing HvInUseWrAllowed on SNP-enabled system"); + return false; + } + if (boot_cpu_has(X86_FEATURE_AVIC)) { pr_info("AVIC enabled\n"); } else if (force_avic) {