From patchwork Mon Nov 4 07:58:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 13861011 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2051.outbound.protection.outlook.com [40.107.101.51]) (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 60FE718E363; Mon, 4 Nov 2024 07:59:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.101.51 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730707153; cv=fail; b=obGOV1SAgt/hlhxVGWlpacIf3CqhAizjtlF3zTVXoDTd9T7FqM0aGoanbpLQKxPRb1FPbvpWAhZhuXXC75uBoicne4mwMSDHOCpIawOYLCEsDVsKQ/i+R4eQjQLSpF+38asVnGZzzTzKSG+hxuf5ueL8RuUa85aWa1lsTpuXaYw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730707153; c=relaxed/simple; bh=OLn3cfqtXAnNKXZQG1jaKzwcliGNyQur4Kr0VHK3AjQ=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=hV5xEC/hEjLLUnJyuJfQKCX4b8nAhEUxhdWVUhkU6qGFpnvf3nLMMprNz8ykEG5TgWj3wXhuJ6CGQG+qU5KmOWnGDAwdqSOY/AOQCG/7ETwwrj387uq3BNZDeliGTuy9/LY0UkDm1fOtwyTY9V58U5JcSH0c7khYhEyPUlNfnms= 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=ebR08Cey; arc=fail smtp.client-ip=40.107.101.51 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="ebR08Cey" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=jzwowWi8QuttBBSRZN9WJGFAxXJK/Ttfw3XnxHb8nTti648wdn+g2zct1XT+XPoHfXbA87KDm5se06PgARxFfjTZ0DqmNwpSxRZsgkvBz3z6ZAmqPq0vdjYxNkDsMB4er80Pyzwq8o9hdmcW14iqRI6EBaus959UER7gMl1t5xVUzHOsFb+JBD8M5c/1e/0/rnuTjiWkUrh/Mubmr6QhhKDL7lDMEd3LhlZDrOsWUcQN4GEBZdbsMW1xXVQ9Nci0uO4MHmdnt9isIwRPm/ohQ28/WH/lhoJH8dOEGeXNo7Yk8HsqMHFoGIkYT/bFCGrl2bk+PX505ZU99nr9N/3yjg== 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=d9FlH64IdPN1Y+ZED1rz2MDJNIw3mhjQ7X4i97A3AkY=; b=WUD/GPYfmRgdhqyZ+FVA3VwLmQmS3wlKjEOKb/gFd68R5Nhjisa1KHD16AYfOI6wuWjxaJnpByAvkhQrwQLy3QAC4x56R8nTzf4pG6XgaHu/TpBTYDZq4X3gRMevbdB1jHmUlGaMdVtH352TZP2UjcalL9sOwIfH6SqQAA/q/udsgTva+AvO5fHZrVMKvLEsbz1InMFthtyg0IxnGHm4RRpO0sbkXmxKHlZN4dcodOSe16LddhzbaM1DIFL/qf2nVSXTHSbGzko1XK9LjD86FVSw13ZG1rVEm06r7tyw35ISqqTnZE8qXEUvP4bBP3LMSdjr9SEFiVEcEkBs1lJs2Q== 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=d9FlH64IdPN1Y+ZED1rz2MDJNIw3mhjQ7X4i97A3AkY=; b=ebR08CeyIGTC0+SoMGVLPzXOWw8G2++t0qcGGuWfLITQwUofQvopKLHl0H9PXHLHaYZwdl9JjmL/o5KDeskScnPfSyeOv+J+zPVpMz5bAzPhSTdvb8upcikzNzopSYdOTrD8AnhJidnleI/jio+o5lXlYY78Y/BhUCRe67oWQCE= Received: from SA9P221CA0014.NAMP221.PROD.OUTLOOK.COM (2603:10b6:806:25::19) by CY5PR12MB6274.namprd12.prod.outlook.com (2603:10b6:930:21::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.24; Mon, 4 Nov 2024 07:59:08 +0000 Received: from SA2PEPF00001509.namprd04.prod.outlook.com (2603:10b6:806:25:cafe::95) by SA9P221CA0014.outlook.office365.com (2603:10b6:806:25::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.31 via Frontend Transport; Mon, 4 Nov 2024 07:59:08 +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 SA2PEPF00001509.mail.protection.outlook.com (10.167.242.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8137.17 via Frontend Transport; Mon, 4 Nov 2024 07:59:07 +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, 4 Nov 2024 01:59:04 -0600 From: Suravee Suthikulpanit To: , CC: , , , , , , , Suravee Suthikulpanit Subject: [PATCH v3] KVM: SVM: Disable AVIC on SNP-enabled system without HvInUseWrAllowed feature Date: Mon, 4 Nov 2024 07:58:45 +0000 Message-ID: <20241104075845.7583-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: 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: SA2PEPF00001509:EE_|CY5PR12MB6274:EE_ X-MS-Office365-Filtering-Correlation-Id: 5dbde476-9290-4674-1d9d-08dcfca68f6e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: =?utf-8?q?0M2oSUROo2FNX/Z7d1g10frZN5ffBml?= =?utf-8?q?/SrFotqAhaonz413XmAqJNKVxmrOV7UozJwXeJjqfv5rQNalaJrp/Wqz8Tbd++kRB?= =?utf-8?q?367cDuLAcY6z7DdmQH7y8Z3H2Y60Rzz8MQpOieiVvjsuTjuZvqvis4Uk8FAVcOVqQ?= =?utf-8?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A6xKn8jgknn/kaHn/355zjWNJM9CrsQTw1QK15MpxXFdJ0vCLvZ4f+Iif?= =?utf-8?q?NUuZJuQ+PfMJiyVnd57t4yDC1QTRmWLplW8YeSrLS11QhvHWA/cxE/fIPu5JmaDeX?= =?utf-8?q?cT3powYcXoqwASVzHiuSeOCIQLegFPmrORLDJ8aILjLWE7t0S6v+mwmNTklMQAsRl?= =?utf-8?q?znXh34+DbZfm+v8fbogejtuCt0iwX1WIO6OFHwoypxoXAxhcS8k5fHoXcTyy1LaRz?= =?utf-8?q?BCqwYO3CZY9H6cAony38k2o5yKQr9b5ArM0h4nmwvm+ffXkjI7Ckrbjrn1iSrK6c7?= =?utf-8?q?6kOkWU0yAYZQE2uz9dJhbxwiwrr7vDlmLMdaVr9/nGv2SByxZQ3rrYY=3D?= 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)(376014)(82310400026)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Nov 2024 07:59:07.9959 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5dbde476-9290-4674-1d9d-08dcfca68f6e 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: SA2PEPF00001509.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6274 On SNP-enabled system, VMRUN marks AVIC Backing Page as in-use while the guest is running for both secure and non-secure guest. Any hypervisor write to the in-use vCPU's AVIC backing page (e.g. to inject an interrupt) will generate unexpected #PF in the host. Currently, 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 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). This table describes AVIC support matrix w.r.t. SNP enablement: | Non-SNP system | SNP system ----------------------------------------------------- Non-SNP guest | AVIC Activate | AVIC Activate iff | | HvInuseWrAllowed=1 ----------------------------------------------------- SNP guest | N/A | Secure AVIC Therefore, check and disable AVIC in kvm_amd driver when the feature is not available on SNP-enabled system. 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) Fixes: 216d106c7ff7 ("x86/sev: Add SEV-SNP host initialization support") Signed-off-by: Suravee Suthikulpanit --- Change log v3: * Switch back to the original design where AVIC is disabled when the feature is not available. v2: https://lore.kernel.org/kvm/20241018085037.14131-1-suravee.suthikulpanit@amd.com/ v1: https://lore.kernel.org/lkml/20240930055035.31412-1-suravee.suthikulpanit@amd.com/ 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 913fd3a7bac6..64fa42175a15 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -449,6 +449,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) /* Allow Write to in-use hypervisor-owned pages */ /* 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..65fd245a9953 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\n"); + return false; + } + if (boot_cpu_has(X86_FEATURE_AVIC)) { pr_info("AVIC enabled\n"); } else if (force_avic) {