From patchwork Thu Jun 2 14:26:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Shukla, Santosh" X-Patchwork-Id: 12867921 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 776CAC433EF for ; Thu, 2 Jun 2022 14:27:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235865AbiFBO1B (ORCPT ); Thu, 2 Jun 2022 10:27:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235858AbiFBO06 (ORCPT ); Thu, 2 Jun 2022 10:26:58 -0400 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1anam02on2059.outbound.protection.outlook.com [40.107.96.59]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17D0E986E1; Thu, 2 Jun 2022 07:26:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FFii0umRjz4bWQlyKuh/eYZqppXFyBYPLHd7mahq01+38yxDA7roIm4X/VteuYTuEMhdpFH9n2WxDi289UX2yHB8+ghQapcUUJ/7DW5+bEPELCXmNYk/xxdHaA+Gf8ZcgMT/Nh24kAKtqST/bIUdk+U8x7q2ojINk3xwEj3FGfQcpxBzs6kxS9eVgvFMB+/qyga+EYMz6368IxGWqA9JQ6+h0ANKLMpCAJdLFxUZaN1lw+g1baFArbDNK7qSnmzlBw5MmG/M4i8XQ5Plow0GTM5AkTBCjiyXII4P9b8e39FXKtdNDplnptmw9DxyuHNS0eisNaC5gMB37JD8gsiURw== 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=AYmY8+gZNr9jBAMVyQG5J95vwz/PgYc3/Xb/dnLa+C4=; b=A+wMjfeXkW+w3u0Z3DtDBDcc1tIjZVvUO+hXYIT5jTYmYORDsgnb7sgW4LRAoyiFP3+KgmY3Ug2LSdxr7/59expvX8uh22SXsvbM6WScVRrE1V5GSlAxd5x/ytjCxe4RjiJ18K89a+ibnO1TyEDw+mV0udehceIVpDChJo8UNXRBUaeMMoGt1LcP/hTgzHrKcoxswYwxctuLvMOR5bpO01wnaU601PYo3JsF51JFmr2nUQAPVZfAMI/NBs70wik1H9J08nSAXWxPZ8IdjY7naqSmtdLrmgKa1K0Y/8KvsJezeddJTk9IRSqNyWLEA/2rgnMtn29DCMK54jr2rSUoLw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com 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 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=AYmY8+gZNr9jBAMVyQG5J95vwz/PgYc3/Xb/dnLa+C4=; b=VLrRDbh+wlemyq/woTeCxRyRsB6IltWNKdkztbpDqNYIA0ffYL829Am/CSVatvDH7qm/THLv5EXRy7fR8gr3XfEAbFD8j34yJFeWELZh2KYcxAwAYzAhy5gwf5yh/iqVnHV7tbSWl86lSP7VJoJTyC4MsQiPTZXd83aIgnJpSQ0= Received: from BN9PR03CA0158.namprd03.prod.outlook.com (2603:10b6:408:f4::13) by IA1PR12MB6211.namprd12.prod.outlook.com (2603:10b6:208:3e5::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.13; Thu, 2 Jun 2022 14:26:53 +0000 Received: from BN8NAM11FT007.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f4:cafe::44) by BN9PR03CA0158.outlook.office365.com (2603:10b6:408:f4::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.12 via Frontend Transport; Thu, 2 Jun 2022 14:26:53 +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 BN8NAM11FT007.mail.protection.outlook.com (10.13.177.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5314.12 via Frontend Transport; Thu, 2 Jun 2022 14:26:53 +0000 Received: from BLR-5CG113396M.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.2375.28; Thu, 2 Jun 2022 09:26:50 -0500 From: Santosh Shukla To: Paolo Bonzini CC: Sean Christopherson , Vitaly Kuznetsov , Jim Mattson , Joerg Roedel , Tom Lendacky , , , Subject: [PATCH 1/7] x86/cpu: Add CPUID feature bit for VNMI Date: Thu, 2 Jun 2022 19:56:14 +0530 Message-ID: <20220602142620.3196-2-santosh.shukla@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220602142620.3196-1-santosh.shukla@amd.com> References: <20220602142620.3196-1-santosh.shukla@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] 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-Office365-Filtering-Correlation-Id: d7adf057-53d0-4811-cb3a-08da44a3f0e4 X-MS-TrafficTypeDiagnostic: IA1PR12MB6211:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: s5vABvsx7oZLJ1jEuIrj+mWzH0Coo1CjHilOyCcyhk7jWcuah/pi2j1UNBUKNtuTZ/qclJvOvVnxBxUAdZ+S4QTDlJvb0kvjFb89+vEJkmSzBecqxLUsCOx4DQLrB9SZsXliv/0gXVtq1XNVNWHk8DxfpsPuffuyTXVe+cy38EWN/mmlF5YhbaO4jlS9h0zI2benQnwCXnQMaBat15tsHy31x7k5Ly481bTkhGAB9G31Utct0c8RmiL9f16e4O8pN3zlhi+WGm6JYt6WSi7tw7KasaaHUbRGAm9X8nVHnXuE3ohiLBtp3Akf79eEPK0aMxk4JVPmSbOCmaYOQ0KWTuv47geKfVHfbOphIvUX/hTSql4XKRKVYVESwhPaPy6CL7YcB9XbrMTeylOaH9iePP9J8DdY7RKr77KzT99/q9dhv8zYMWEWXdGQgwUku19buvN0Kg0lFxMCE+cb80228VLJm/c7E5y05Bd0F0m5ULZ5whhQBOpLAGD+54DCsVcPeCL+nlfdJbwOId6i5oUVgLWxNUzwI4XWBtv9Uu+hPemPLQCaiN7Py4GA3SA4jDH4FE0cP1go3PY9Bk36y8vKaYUqyF5+Lyo5aHy6MJZkMb1VNRfXWHNql5VIGZPrlexwjRpPq+jN1/tEJk4hT7ou9je6QxPcUe3hvuvnFIlY7eRgQ9uj8Qub8xrjnPzWZzQT84heX6a6XX8Ruf49mlFVJg== 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:(13230001)(4636009)(36840700001)(46966006)(40470700004)(356005)(40460700003)(44832011)(82310400005)(7696005)(336012)(47076005)(36756003)(426003)(316002)(2616005)(81166007)(16526019)(6666004)(186003)(1076003)(8936002)(2906002)(5660300002)(86362001)(6916009)(70586007)(70206006)(4326008)(54906003)(26005)(8676002)(36860700001)(508600001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2022 14:26:53.7449 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d7adf057-53d0-4811-cb3a-08da44a3f0e4 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: BN8NAM11FT007.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6211 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org VNMI feature allows the hypervisor to inject NMI into the guest w/o using Event injection mechanism, The benefit of using VNMI over the event Injection that does not require tracking the Guest's NMI state and intercepting the IRET for the NMI completion. VNMI achieves that by exposing 3 capability bits in VMCB intr_cntrl which helps with virtualizing NMI injection and NMI_Masking. The presence of this feature is indicated via the CPUID function 0x8000000A_EDX[25]. Signed-off-by: Santosh Shukla Reviewed-by: Maxim Levitsky --- arch/x86/include/asm/cpufeatures.h | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index 393f2bbb5e3a..c8775b25856b 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -346,6 +346,7 @@ #define X86_FEATURE_V_VMSAVE_VMLOAD (15*32+15) /* Virtual VMSAVE VMLOAD */ #define X86_FEATURE_VGIF (15*32+16) /* Virtual GIF */ #define X86_FEATURE_V_SPEC_CTRL (15*32+20) /* Virtual SPEC_CTRL */ +#define X86_FEATURE_V_NMI (15*32+25) /* Virtual NMI */ #define X86_FEATURE_SVME_ADDR_CHK (15*32+28) /* "" SVME addr check */ /* Intel-defined CPU features, CPUID level 0x00000007:0 (ECX), word 16 */ From patchwork Thu Jun 2 14:26:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Shukla, Santosh" X-Patchwork-Id: 12867922 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C65AC43334 for ; Thu, 2 Jun 2022 14:27:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235874AbiFBO1R (ORCPT ); Thu, 2 Jun 2022 10:27:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235869AbiFBO1P (ORCPT ); Thu, 2 Jun 2022 10:27:15 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2087.outbound.protection.outlook.com [40.107.223.87]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0806DC20F; Thu, 2 Jun 2022 07:27:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dzcFg6koYpWaw4tIwwzDMpADDt+6hd6prDxdLpU8Os0zG715hbginzhUOUCfjRKtyb27GedxjVTLFtfoX6cMQVnTnbDvvUj+VDBO0wR5L4ZntZdCygwa3GlrQMIwTDJHNhcRLqdBPB8zryUegCi4q3ctYIVcKR8KHkxBFZq5uEWYIeYDgh9M4Wm4PFY9XVrYCRnLwWUCZfj5fx0UYNNT+PCdSBh5pJ0+57gqrSDfd5ZsUPXfZsww9JNgWP/Hknm/h4fbLtLPL1Z18Lxfl+/7ZXX9klvgUkCsr0m95x3BoE2xF/mK71vZ5cWw5h7vhCD+arPFiPZ+h4cbLObgNs0wSg== 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=bEzWo35Wjsm5XLf86tMH/3ciVr4DeVDeyt/AhwY6QQ4=; b=DyAe8N2XRb9DNY2PE8XAu1C83BNvilKNZHdRf3Wy1jyvPh0klbNz4sqi31F1+ET+0IdbmtiFNQFU6JSbclwDgn5ZTDwz9/ySmqPqwCOqZ/XdfZ9Oi734rTA4/ZKJ+pXD6KQanIVkxf/MRtdCBwmN9DnYScBO8PNxBa7RuhVT1pL9Ftlg/ZXZ1h+YqoSF5YlkaXvKAglKCpOlFQoJbekjpgDizH895Tya5F5VPO6qz/04PqWnL3moWTWgIxuaQwtp8bQ2y5J6opnczckcG9AO7o8g9YktXJ2dTGXbv2c+HZJgrqt+D5lXuSTu+0oltGDqB2K8Wz8AuPy9JHJqbfLnDw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com 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 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=bEzWo35Wjsm5XLf86tMH/3ciVr4DeVDeyt/AhwY6QQ4=; b=Z6OZAT+HP4i8vF7SYqCcO0nt4gE7sASCQavuwySkCTWzFodjBPlALCyJTI2IACyGFwy+HDILgTd6kOPjuWVsSMZ1Gufn/e4wmM1EjjwCcIcaVsETSgxxDwj9xnDmWYd7um2dONqjLKmaGuNn9DKrsmHcVpF3TqG5Zlj5OtPcuao= Received: from BN8PR15CA0050.namprd15.prod.outlook.com (2603:10b6:408:80::27) by LV2PR12MB5895.namprd12.prod.outlook.com (2603:10b6:408:173::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.12; Thu, 2 Jun 2022 14:27:10 +0000 Received: from BN8NAM11FT019.eop-nam11.prod.protection.outlook.com (2603:10b6:408:80:cafe::6c) by BN8PR15CA0050.outlook.office365.com (2603:10b6:408:80::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.13 via Frontend Transport; Thu, 2 Jun 2022 14:27:10 +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 BN8NAM11FT019.mail.protection.outlook.com (10.13.176.158) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5314.12 via Frontend Transport; Thu, 2 Jun 2022 14:27:10 +0000 Received: from BLR-5CG113396M.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.2375.28; Thu, 2 Jun 2022 09:27:07 -0500 From: Santosh Shukla To: Paolo Bonzini CC: Sean Christopherson , Vitaly Kuznetsov , Jim Mattson , Joerg Roedel , Tom Lendacky , , , Subject: [PATCH 2/7] KVM: SVM: Add VNMI bit definition Date: Thu, 2 Jun 2022 19:56:15 +0530 Message-ID: <20220602142620.3196-3-santosh.shukla@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220602142620.3196-1-santosh.shukla@amd.com> References: <20220602142620.3196-1-santosh.shukla@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] 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-Office365-Filtering-Correlation-Id: db31a468-3007-4ba3-f8e0-08da44a3faf9 X-MS-TrafficTypeDiagnostic: LV2PR12MB5895:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SrXi+oNDcwlkPJiUZgQQkqa+drXCm/o1U500GU2Iw0mG8mUcOPUZZYfgOE6yNimwOnifeIRsyPVrVE1vuONBL9+I2onq2BgI+nx02HkRyAe9QSA0F6cPrQaJ/+j+nUSi+yyz4RMdf4VyXSPYk569fr+9x/dr/mRGQJnlzJF58B7Hw8ZR20OdZJFEvbO8fb2VKAHHB7LI9oJRTlMLoD5U/RJDMjs5raJtmfWp9UWlX1UTUgAhy7Hl0/wx+C0N7zbCgpEPMQXif/0jyNZTaFqpng6dWxIAW1tHCfWTRLHxj/0YT9OAelQoXfHS4HUfYPSYlYKDBFNPlx/NMjs7+faawxKXidn7X0hTjok1g6C3HexmUGs/2hYWiAVubAiw0H+6vE6VAqejXCrtl514jIWsMuzWmL7ZxWr3V05M6xgfH+VxJPnOM40pbtREABNmjQVxAR5pJK7jfYMPp21MErkUtT+tbHUQLQH17NZEEsXAgveipKPCPN1U6kKRWo9F9bEUN9q5Gsldozx01wWScMrna93Sh2+wkrTQ3+EpfCZ1voJ9HaKU27OqOjA2H1yD2dvZ+MpYDXvtn0ifbdnQOPEqP2Psc/huqYrD6WPLgTC/gJ3/2gqyCbCpm95i6dV+U2zVeh/KHKWj3TBSKUPFcBtLKvp1++knqqI5fNUnjkXXQB/2G7z4dBYW1ZDtoI0ifofXamWyrQiYe6BrLwqClAjShA== 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:(13230001)(4636009)(46966006)(36840700001)(40470700004)(70586007)(44832011)(36860700001)(70206006)(5660300002)(26005)(82310400005)(336012)(426003)(1076003)(47076005)(2616005)(16526019)(186003)(86362001)(316002)(508600001)(8936002)(8676002)(4326008)(6916009)(54906003)(81166007)(40460700003)(36756003)(7696005)(356005)(6666004)(2906002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2022 14:27:10.6765 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: db31a468-3007-4ba3-f8e0-08da44a3faf9 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: BN8NAM11FT019.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR12MB5895 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org VNMI exposes 3 capability bits (V_NMI, V_NMI_MASK, and V_NMI_ENABLE) to virtualize NMI and NMI_MASK, Those capability bits are part of VMCB::intr_ctrl - V_NMI(11) - Indicates whether a virtual NMI is pending in the guest. V_NMI_MASK(12) - Indicates whether virtual NMI is masked in the guest. V_NMI_ENABLE(26) - Enables the NMI virtualization feature for the guest. When Hypervisor wants to inject NMI, it will set V_NMI bit, Processor will clear the V_NMI bit and Set the V_NMI_MASK which means the Guest is handling NMI, After the guest handled the NMI, The processor will clear the V_NMI_MASK on the successful completion of IRET instruction Or if VMEXIT occurs while delivering the virtual NMI. To enable the VNMI capability, Hypervisor need to program V_NMI_ENABLE bit 1. Signed-off-by: Santosh Shukla Reviewed-by: Maxim Levitsky --- arch/x86/include/asm/svm.h | 7 +++++++ arch/x86/kvm/svm/svm.c | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h index 1b07fba11704..22d918555df0 100644 --- a/arch/x86/include/asm/svm.h +++ b/arch/x86/include/asm/svm.h @@ -195,6 +195,13 @@ struct __attribute__ ((__packed__)) vmcb_control_area { #define AVIC_ENABLE_SHIFT 31 #define AVIC_ENABLE_MASK (1 << AVIC_ENABLE_SHIFT) +#define V_NMI_PENDING_SHIFT 11 +#define V_NMI_PENDING (1 << V_NMI_PENDING_SHIFT) +#define V_NMI_MASK_SHIFT 12 +#define V_NMI_MASK (1 << V_NMI_MASK_SHIFT) +#define V_NMI_ENABLE_SHIFT 26 +#define V_NMI_ENABLE (1 << V_NMI_ENABLE_SHIFT) + #define LBR_CTL_ENABLE_MASK BIT_ULL(0) #define VIRTUAL_VMLOAD_VMSAVE_ENABLE_MASK BIT_ULL(1) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 200045f71df0..860f28c668bd 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -198,6 +198,8 @@ module_param(dump_invalid_vmcb, bool, 0644); bool intercept_smi = true; module_param(intercept_smi, bool, 0444); +static bool vnmi; +module_param(vnmi, bool, 0444); static bool svm_gp_erratum_intercept = true; @@ -4930,6 +4932,10 @@ static __init int svm_hardware_setup(void) svm_x86_ops.vcpu_get_apicv_inhibit_reasons = NULL; } + vnmi = vnmi && boot_cpu_has(X86_FEATURE_V_NMI); + if (vnmi) + pr_info("V_NMI enabled\n"); + if (vls) { if (!npt_enabled || !boot_cpu_has(X86_FEATURE_V_VMSAVE_VMLOAD) || From patchwork Thu Jun 2 14:26:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Shukla, Santosh" X-Patchwork-Id: 12867923 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 997F9C43334 for ; Thu, 2 Jun 2022 14:27:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235882AbiFBO1g (ORCPT ); Thu, 2 Jun 2022 10:27:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235896AbiFBO1d (ORCPT ); Thu, 2 Jun 2022 10:27:33 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2067.outbound.protection.outlook.com [40.107.223.67]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BD07DFF4C; Thu, 2 Jun 2022 07:27:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mgbOBmKkzvlTEwI043jTrxFgwI3M/4NtI1cOsiCLC6iRaknecHPUsrAefqEDH6fArBAGqFAwd8W/sqwUaE/MF4WcpkYEwwf7NrPnqj9c7WbawcRKmuS+TqgPVOlcCO435WXfqUexqQgPIf4IROAuUvyhWM64MbHkNwEdJ1MkH9mDiGfqFGCC++kvnYiq+1zShse0h1FixnIWoPtYKNHXuohU5XAKPOuZkob5FyjSt+EYC141e+5pOqSB4Sfwlu/0Anj+NTAE14dyZGyZAFoJlqQD9dvUdG5JK17UmmnONLKLnNOUwga1ABg+xZdy5UmWI0bklikUuPzT9JK2S78lMw== 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=SGjK0lYQ5r5zdEw1lFFLxAt1rgcslKLijmP8URQtT+8=; b=flTUS+WqTHshbW98sLwmPRvMMri8oyD0OhH7vhJVP8RMd016N8C+xyu2j4BHc5NQwNCPOvcCQ8Hs+0cnHpVOb3mrzTWHXpqHIYsQ7dtzkeokRzMvp3dww+DDSvn/mudf6UNCKAcTcQESQirOQjipsHNTsJx9KCl5+tBrjcYO4qmwEy8MLEYQBBbkFS7FfYj3kLzWXCLL9rLKrOUPi6Zrl230LKWzON/dSp/1E711cwNDtyaHa6yjcZsUKjgIC3lgaMswgqVUWAsJZvxXzM6paZu2/B3hoh0pOVa10uIm4CW0TDl123kCiTMrn12MP5vCXxDr/06tvpIgilG6zfcauw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com 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 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=SGjK0lYQ5r5zdEw1lFFLxAt1rgcslKLijmP8URQtT+8=; b=ccgx4Va105WkNGurDoxJWFjpQRAIH62Vg5FbEA7wAmeq+psILjUUZXJTrS6iL/5sHhoK9b1ifzR5qoA/CMfKghcBIR473mrpUyMatx4tcHgJuZa+tMk+GzOo24gu1V0RYsa8jPyhvTpY0aF/XDkag6aTOFAd9EosN4JieVj19jU= Received: from BN9PR03CA0549.namprd03.prod.outlook.com (2603:10b6:408:138::14) by MN2PR12MB3839.namprd12.prod.outlook.com (2603:10b6:208:168::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.13; Thu, 2 Jun 2022 14:27:27 +0000 Received: from BN8NAM11FT004.eop-nam11.prod.protection.outlook.com (2603:10b6:408:138:cafe::fc) by BN9PR03CA0549.outlook.office365.com (2603:10b6:408:138::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.13 via Frontend Transport; Thu, 2 Jun 2022 14:27:27 +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 BN8NAM11FT004.mail.protection.outlook.com (10.13.176.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5314.12 via Frontend Transport; Thu, 2 Jun 2022 14:27:27 +0000 Received: from BLR-5CG113396M.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.2375.28; Thu, 2 Jun 2022 09:27:23 -0500 From: Santosh Shukla To: Paolo Bonzini CC: Sean Christopherson , Vitaly Kuznetsov , Jim Mattson , Joerg Roedel , Tom Lendacky , , , Subject: [PATCH 3/7] KVM: SVM: Add VNMI support in get/set_nmi_mask Date: Thu, 2 Jun 2022 19:56:16 +0530 Message-ID: <20220602142620.3196-4-santosh.shukla@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220602142620.3196-1-santosh.shukla@amd.com> References: <20220602142620.3196-1-santosh.shukla@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] 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-Office365-Filtering-Correlation-Id: 5104c35c-4424-4c02-88b9-08da44a404db X-MS-TrafficTypeDiagnostic: MN2PR12MB3839:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WP7ctwBHe62lM+WOEXzsYvYOc1jgEqQGKnOT6j7BxUi8/ZKy457WikxEnzOHuvKtqm4UOFDqUHpzf4wwOPOB1V7c2T08GI2D6EL7PzhQ/KGC9g+79lzdt5q4xdlgRvwhWDWiO/+crCwc8XTXJvwot/8sG0qQDFMDaN9OTdV4QV6nJ+1bGZ/62fo8yIxy5POAa93nJlWXuB+QWDsqQ4ziQtmR8HJIgj/KJ2HV4HOLVN7jR6bxFVfOlCkCOD0gCm4YvLZ4i4kWbG0kR7Y8ETSam9EW+/Nnrzpsw78zLB8O3adyK8F1a/0kmlgk1jEkC5J73fpexXRxdlvcZADzChyp6JpX1QyhLXUheff0ZlkT9go2Ld+pk05gBZf5EZG8Bj/5R+ATNxKp+qgGonyVUvMfpftK880uViJDt2oBRKuBT0ZQvcZM0fuy0biln7e/clYkMJCopkdPwNyz21ltmJfcEeRobLhwBtaUHKuXJtgsNpjIALEmDyR9kSJXEaktKZnzhP5FyV8jrFXzJdrrUyvNYV3Ll67fiRYS/xwuMywbcYzmLTDAvTj+FinwU+bLo0JB2yZz9WS+yqdY0n5MRLrDoB7hdbrI/0U6BRdNN6MQ6vfpyeinjDVDE03V1Ev/dxap0xKMtneiieYtqMxhOd5VMVP/vEkBJrg2diVNNzB2dfp1q2nT/B1HrT7KD7eVG5EFp7jgTbCc5uwXDZwo93MJ+A== 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:(13230001)(4636009)(46966006)(36840700001)(40470700004)(508600001)(8936002)(16526019)(336012)(47076005)(1076003)(186003)(40460700003)(2616005)(83380400001)(6666004)(5660300002)(2906002)(26005)(7696005)(86362001)(4326008)(8676002)(316002)(44832011)(36756003)(6916009)(426003)(82310400005)(54906003)(70206006)(70586007)(36860700001)(356005)(81166007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2022 14:27:27.2543 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5104c35c-4424-4c02-88b9-08da44a404db 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: BN8NAM11FT004.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3839 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org VMCB intr_ctrl bit12 (V_NMI_MASK) is set by the processor when handling NMI in guest and is cleared after the NMI is handled. Treat V_NMI_MASK as read-only in the hypervisor and do not populate set accessors. Signed-off-by: Santosh Shukla --- arch/x86/kvm/svm/svm.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 860f28c668bd..d67a54517d95 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -323,6 +323,16 @@ static int is_external_interrupt(u32 info) return info == (SVM_EVTINJ_VALID | SVM_EVTINJ_TYPE_INTR); } +static bool is_vnmi_enabled(struct vmcb *vmcb) +{ + return vnmi && (vmcb->control.int_ctl & V_NMI_ENABLE); +} + +static bool is_vnmi_mask_set(struct vmcb *vmcb) +{ + return !!(vmcb->control.int_ctl & V_NMI_MASK); +} + static u32 svm_get_interrupt_shadow(struct kvm_vcpu *vcpu) { struct vcpu_svm *svm = to_svm(vcpu); @@ -3502,13 +3512,21 @@ static int svm_nmi_allowed(struct kvm_vcpu *vcpu, bool for_injection) static bool svm_get_nmi_mask(struct kvm_vcpu *vcpu) { - return !!(vcpu->arch.hflags & HF_NMI_MASK); + struct vcpu_svm *svm = to_svm(vcpu); + + if (is_vnmi_enabled(svm->vmcb)) + return is_vnmi_mask_set(svm->vmcb); + else + return !!(vcpu->arch.hflags & HF_NMI_MASK); } static void svm_set_nmi_mask(struct kvm_vcpu *vcpu, bool masked) { struct vcpu_svm *svm = to_svm(vcpu); + if (is_vnmi_enabled(svm->vmcb)) + return; + if (masked) { vcpu->arch.hflags |= HF_NMI_MASK; if (!sev_es_guest(vcpu->kvm)) From patchwork Thu Jun 2 14:26:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Shukla, Santosh" X-Patchwork-Id: 12867924 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF889C433EF for ; Thu, 2 Jun 2022 14:27:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235912AbiFBO16 (ORCPT ); Thu, 2 Jun 2022 10:27:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235899AbiFBO1z (ORCPT ); Thu, 2 Jun 2022 10:27:55 -0400 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2054.outbound.protection.outlook.com [40.107.100.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8003C133925; Thu, 2 Jun 2022 07:27:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OmRRWxx9zaS67HvCtgJQuCp7RIledLbUs4u1BQUwqiILQa0YhnD5wC8d/I6fqCpngtzXMQGkT8PuxW05ppxxg7yu4zgrm2HQhEckKEKLO2MMMJjgvruxm1ZaKKMBaWOzVPGZh7Np+ZoZ05XOO3ApHeQ9bpA+C6CsscJ40tXG4GQURYinI4jo+123mBq7ZvxZ8flyqnC+LxA3Lk3xHXdg2urget/JHprUZSxWihPulQi4puURjYA94tVdjKfyJNQs64JF5oayw+IePXb/akUCLpIUYiWCzFHy8sK8I6dd47V4LkIDzj3j0yyevcdZKsorWIvmynAq0xtqiGPmzI6Vew== 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=mlD+4SbguM0bIQlqJuEe0HNi3zDkdGvdNbQfXS3Wgws=; b=Jd1rvXYqw5DpzuOcHtlpLYr/T3YCpWc98VNcCiaw3Ytf4SXjQhEc3TYA763vnunq49fE36LHzp0nsEAw3x3vUls+bmpHvvTASOg8H/ec+Cz9NXS7P58ER7AikAK3DyjXOrrkCU5HcQvHD8Mpc78YWol5tmJRaq3KaIUTzFbdgpx0XetnQU4qJHu+TWEvBnbb8fKV+/613jI7/DmT6QNNOVL9gisJutLSw8iC1UsF5tSEzAGpW4EkDWTasMqZgM84RSGxoawOoBWJNHmjsoPYuq0MDhJMEfrd6O5wLE+e3t9ybGx5xADra3ZpV/2e5zndE783SDFwDGLMi1WZGlhIYg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com 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 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=mlD+4SbguM0bIQlqJuEe0HNi3zDkdGvdNbQfXS3Wgws=; b=xZZy3siqUawgWg6A+M6LkDATURljxb6PbCmwJunLhu0pAS3wNkBSiou3QKOcO+pnRqf7z7V/oN9zmVDYbsSMqQ2Em9gx9gTzza2YsaJwgMdtiHt3rt5LptLgKlhYLBrl72xKarFcHUQYJCg3fx4OeuZ/i3Hy9OYsOkXtHpoDa3o= Received: from BN9PR03CA0268.namprd03.prod.outlook.com (2603:10b6:408:ff::33) by BY5PR12MB4307.namprd12.prod.outlook.com (2603:10b6:a03:20c::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.13; Thu, 2 Jun 2022 14:27:45 +0000 Received: from BN8NAM11FT010.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ff:cafe::3c) by BN9PR03CA0268.outlook.office365.com (2603:10b6:408:ff::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.13 via Frontend Transport; Thu, 2 Jun 2022 14:27:45 +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 BN8NAM11FT010.mail.protection.outlook.com (10.13.177.53) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5314.12 via Frontend Transport; Thu, 2 Jun 2022 14:27:45 +0000 Received: from BLR-5CG113396M.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.2375.28; Thu, 2 Jun 2022 09:27:40 -0500 From: Santosh Shukla To: Paolo Bonzini CC: Sean Christopherson , Vitaly Kuznetsov , Jim Mattson , Joerg Roedel , Tom Lendacky , , , Subject: [PATCH 4/7] KVM: SVM: Report NMI not allowed when Guest busy handling VNMI Date: Thu, 2 Jun 2022 19:56:17 +0530 Message-ID: <20220602142620.3196-5-santosh.shukla@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220602142620.3196-1-santosh.shukla@amd.com> References: <20220602142620.3196-1-santosh.shukla@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] 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-Office365-Filtering-Correlation-Id: da666443-c178-4b50-0226-08da44a40f8e X-MS-TrafficTypeDiagnostic: BY5PR12MB4307:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vnx2e6VXePlCDnKvVIDaR7zLZy0fq3nTpQNwZzzO04aPw39ovMFrD7tgie4l9ocpbri2JYFwqkVt/0YUdpaWZWVvRnz3U15X74+6yil+RCddc9H/V/m2csA+t7djEhpEIPr/IHTP6uDct7s7ZRCNDSN15kb0G3Dudf/nNnsd1VMMBXqjHjZB/sqvpbJBgBPHa2MvnOuWpMS5dfZa1TP2wNM/Cr4GSlB+Fr5VN3DSyAIwdhicuIQPjYvKsKe8lw+/Xvl34/W0XDcNQRyI0ABjRBLcghgXU5kzfHYyZ/r6NvL8f7GJGa2b9oqDX6HIn93ljPRHqts9qYWmN4ulIvCSQE4o2mYJge0jW4wa9DUXnDyMPeep6mAfo5CdKTbxSM000U4Owtb6aThRgWnz0iUd5S/mNzxsW06nsaiZRn4jLJuLjIFClJmAvIxrO4yQGCtDdQcLBmwI8nmXicikRlvKg67pvuCu7tzPI5Jl9w4KVDovik0zbtc+G0atf0rdo1pD7kDtBhDgqmdqTvArHnhXcaj81pm+eApb1U1XvYlbP4uBxLjOeemAHQNcp1hBIRKVwhd8p5UqK8k1IMezjaNzcGN3T4aAYWK+WsveWJCqemsE+YPWxG7VonwCvDZX/ROIxV2lksAoRPxdF5ni8RLo9ldXkdYZIamqLfk1zBeqkx1n7hr0hvyOIVGi88Enioyq1k6ONZeZ5dAIrWTMFMdSWg== 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:(13230001)(4636009)(46966006)(36840700001)(40470700004)(70206006)(6916009)(54906003)(36756003)(4326008)(36860700001)(6666004)(40460700003)(8676002)(316002)(86362001)(82310400005)(70586007)(26005)(7696005)(8936002)(186003)(1076003)(81166007)(16526019)(2616005)(508600001)(5660300002)(356005)(4744005)(2906002)(44832011)(336012)(426003)(47076005)(83380400001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2022 14:27:45.1855 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: da666443-c178-4b50-0226-08da44a40f8e 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: BN8NAM11FT010.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4307 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org In the VNMI case, Report NMI is not allowed when the processor set the V_NMI_MASK to 1 which means the Guest is busy handling VNMI. Signed-off-by: Santosh Shukla --- arch/x86/kvm/svm/svm.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index d67a54517d95..a405e414cae4 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -3483,6 +3483,9 @@ bool svm_nmi_blocked(struct kvm_vcpu *vcpu) struct vmcb *vmcb = svm->vmcb; bool ret; + if (is_vnmi_enabled(vmcb) && is_vnmi_mask_set(vmcb)) + return true; + if (!gif_set(svm)) return true; @@ -3618,6 +3621,9 @@ static void svm_enable_nmi_window(struct kvm_vcpu *vcpu) { struct vcpu_svm *svm = to_svm(vcpu); + if (is_vnmi_enabled(svm->vmcb) && is_vnmi_mask_set(svm->vmcb)) + return; + if ((vcpu->arch.hflags & (HF_NMI_MASK | HF_IRET_MASK)) == HF_NMI_MASK) return; /* IRET will cause a vm exit */ From patchwork Thu Jun 2 14:26:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Shukla, Santosh" X-Patchwork-Id: 12867925 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 810B0CCA478 for ; Thu, 2 Jun 2022 14:28:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235921AbiFBO2V (ORCPT ); Thu, 2 Jun 2022 10:28:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235945AbiFBO2O (ORCPT ); Thu, 2 Jun 2022 10:28:14 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2069.outbound.protection.outlook.com [40.107.243.69]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB88C13B8C2; Thu, 2 Jun 2022 07:28:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RX56qFR8kF5ZZn663C709B3H6Iui9upaHq27VCg/5xmr8BhLnQxdfrpwuAyIGLWoTwdHdYgifK5l0wuZ5EfrEaVTPbXRYPkihHoddfo0/1eTEyCB8vcPS305PXVJO0D/a/4gUmGwdFWwJzkRjLc7DYT7gwwXswjEcfsE1Q9YkyaoyXl7Suydxa1UQY4sEV9tXeHVBas9yKTUQqUwR431vCIrCNePvHT+Qod3yhG6ucZ41zo2oxUICrKKQqi41lWn2JRmfPbGi3kymijzrosYdVBmalYIpXgqc+F+1ji2XIcNPDxoZ/7/EPFSVH9Iy88Y+7UyrUKcWiQ2mOGXJUuXkQ== 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=xvz62h4ce8x6Jlg0rnGiIt19HXPFdGmibPoOctF8Fig=; b=JSevWlUy80gC3WFeCkJasbn7roz7JIsb/7OPC+AYlPezETVw16f3ESY7yaF+5SiQbvuIgu3DDCUKG8FfqSoLTiN/fDn0jXY1HyHdgshkkZcRtHT1zCY+j3QBXz17ypheHbOGO9jeIswqNIrxExAamoOVu+6dggwCacq/JNPlciNcAQcUl3CIHtLIljhTxR4BWKAmp19bl7YJ1LD/fHB45JNKxYb3XOMUbxfCHD1SmWCXqzs7ZOdKUv11zwBbFNV6Isl3V7YcFejoYN9oY6qWu5Rbd7RoXlxP5fl1/GJeXfT58MR77UK9sAeQjUZtiXIiHPLDKJJvmWs/QAFVjWdT5A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com 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 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=xvz62h4ce8x6Jlg0rnGiIt19HXPFdGmibPoOctF8Fig=; b=s3qRPgKytzfoLQHyLCqZ8lDSvyUTcJbpL84m9HeVcrb2FuJ+1sXMBqCI5FVH3DBZMLsrzCSjYDeA3cfSvfBcyGPymAW4G97sgoyBJ3F0n5+tb7Fw4ERFco4oeDBRtrHoEMA5pABqh48xpoG4lmw0kACAmcDstOWI8Ssp1bNHz34= Received: from BN6PR19CA0116.namprd19.prod.outlook.com (2603:10b6:404:a0::30) by BN7PR12MB2802.namprd12.prod.outlook.com (2603:10b6:408:25::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.18; Thu, 2 Jun 2022 14:28:02 +0000 Received: from BN8NAM11FT022.eop-nam11.prod.protection.outlook.com (2603:10b6:404:a0:cafe::c9) by BN6PR19CA0116.outlook.office365.com (2603:10b6:404:a0::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.13 via Frontend Transport; Thu, 2 Jun 2022 14:28:02 +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 BN8NAM11FT022.mail.protection.outlook.com (10.13.176.112) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5314.12 via Frontend Transport; Thu, 2 Jun 2022 14:28:01 +0000 Received: from BLR-5CG113396M.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.2375.28; Thu, 2 Jun 2022 09:27:57 -0500 From: Santosh Shukla To: Paolo Bonzini CC: Sean Christopherson , Vitaly Kuznetsov , Jim Mattson , Joerg Roedel , Tom Lendacky , , , Subject: [PATCH 5/7] KVM: SVM: Add VNMI support in inject_nmi Date: Thu, 2 Jun 2022 19:56:18 +0530 Message-ID: <20220602142620.3196-6-santosh.shukla@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220602142620.3196-1-santosh.shukla@amd.com> References: <20220602142620.3196-1-santosh.shukla@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] 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-Office365-Filtering-Correlation-Id: 2989aefa-0f97-46b2-2f6b-08da44a4197c X-MS-TrafficTypeDiagnostic: BN7PR12MB2802:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5bbQBT7ixgC8qmdKohj87BuTMry3f2+VdE1F7KCsrmJdHNCIldFIdAck3GpzmDzSLtGNR77KQ5wVkhbEy6QexOdj6+Il4tPav7PPF6ZIeJNaMN4CuTo8Le5BZq9VU3TMEi3aIK9JD9v14eMs8SO3DksSj47AliRqm7mV3FOkhlN9t/xxJkA0biEFFsT5KO3SzJ6ePj4ahS5uc7HtXM6Ahe4Yw1yd9uKUcbsuy8zRUuyFiegqeNEcWrzKR/MpE8qDn49uk9lfcML1KqggI/o7/tDYQh38KivIkLGcC+RoJwWBdbIytXy8Z3d1BDqIoFdOS7P/VkPnuSgiL5NMTLGyg044m4HuLGCzwL0z/JKu+XNNyOX7VoxNZrH9lk/lNbEgdzaGp8RSOZLW2dgylGFhkuvtVNe31O2iEtq9b0MJJVFA3gWg9ZF80MfSuPbgdoemA89dBm4KGemSOUjPSrWzbcAev4p9DeLzYt6/74pd1kDS4b4MfmJ/+BG5RIUogjbC1XoMEXPlNP40M/bONb/Le0CVtDR+OCluRj4cx38+qzp8M9/LHw8FrNrjuH7q3cLFm4tCpVSvwRcgoMq/+cjpgyOTtheZim+y7occVEEcR1CikDGwAJPEXcX9RBYI90laQwg2z+GSK4z0Lb8gr12RKHIeCmZi70craSR6SKKrnRAGkw9yyJAlM30WWN4idPFFOc4K2zWDqmpIS4Wu4Yp7LA== 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:(13230001)(4636009)(40470700004)(36840700001)(46966006)(36756003)(6666004)(508600001)(316002)(40460700003)(6916009)(54906003)(36860700001)(336012)(186003)(426003)(82310400005)(2906002)(16526019)(70586007)(1076003)(70206006)(2616005)(47076005)(4326008)(5660300002)(8936002)(44832011)(86362001)(83380400001)(81166007)(356005)(26005)(8676002)(7696005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2022 14:28:01.8459 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2989aefa-0f97-46b2-2f6b-08da44a4197c 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: BN8NAM11FT022.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR12MB2802 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Inject the NMI by setting V_NMI in the VMCB interrupt control. processor will clear V_NMI to acknowledge processing has started and will keep the V_NMI_MASK set until the processor is done with processing the NMI event. Signed-off-by: Santosh Shukla --- arch/x86/kvm/svm/svm.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index a405e414cae4..200f979169e0 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -3385,11 +3385,16 @@ static void svm_inject_nmi(struct kvm_vcpu *vcpu) { struct vcpu_svm *svm = to_svm(vcpu); + ++vcpu->stat.nmi_injections; + if (is_vnmi_enabled(svm->vmcb)) { + svm->vmcb->control.int_ctl |= V_NMI_PENDING; + return; + } + svm->vmcb->control.event_inj = SVM_EVTINJ_VALID | SVM_EVTINJ_TYPE_NMI; vcpu->arch.hflags |= HF_NMI_MASK; if (!sev_es_guest(vcpu->kvm)) svm_set_intercept(svm, INTERCEPT_IRET); - ++vcpu->stat.nmi_injections; } static void svm_inject_irq(struct kvm_vcpu *vcpu) From patchwork Thu Jun 2 14:26:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Shukla, Santosh" X-Patchwork-Id: 12867926 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5DE4C433EF for ; Thu, 2 Jun 2022 14:28:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235932AbiFBO2X (ORCPT ); Thu, 2 Jun 2022 10:28:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235920AbiFBO2V (ORCPT ); Thu, 2 Jun 2022 10:28:21 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2055.outbound.protection.outlook.com [40.107.223.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAC1914384A; Thu, 2 Jun 2022 07:28:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FZTgb7axA73cOy+tg9NTNFt7/MtLfwqVneRkjpzwslK1KH417eSILvywvfjaVR+DhE0fEA7xNHVxF5ZdtcTp0M3ZJukFx4GJrF6zmcjNFt27ojQUznmot/BO8DN2vHVtpePg1Ix5JtCZUUG84ff0/bubh7h3zbnXpO9HqfVMoU/oAQOyLpVXB2vCnCXXCFaUBDvCQghjcr0n/xDJILTShZgBazDYDuAbALOS2aHQEhWq0p/tZ6G8ijTETsMBodklsnpOncPWy4IW4lt3pRJa9VLfnna7KMh+rjn7lg95ay0umUbKcUmlDOQ//iLvRmyL4HBqeL5/huLNZVa/r0cNfw== 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=GyEVcaBruJ4JWrm47fj0kT7aSHHgsOLC3gTRPDHESB4=; b=bHrS39CYasqfCXIWj3WzrLBk6liHpsCACDd3SKO+jW/Ktt0vKYFI5/qvBdsdqFBLH3UmeWR3Swi0D2eHbnNFj4+F6Afl+8QadqMvs2lDypPsKYY5E1wLj85zQj73GzTlJSTsbl07QdvUFRyaUxnxgwLCCxVwviCSPKqLIWYPbr3wiRq78F5v2hlQK3G3VIBQ5rga5G7gQGMqzH88IjSP37YNsq2iHXJ+CKRzAfl9xAEOI10y5FFPsY02DAeUVQ7xOSzW/ssjKIf+SICWG/wTx7hrySQ/f0nnMMpMUamCzNTzqQs5B4UIOhXuwglTvL9wcG1CuUcS86yG2oSRJexJHg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com 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 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=GyEVcaBruJ4JWrm47fj0kT7aSHHgsOLC3gTRPDHESB4=; b=qtFvEsyJFPu/j56Ij+oJewhdpsf9xHp/m70u8Wo5MTkakroXGlV8I0erOyOykYqmvAlwwH0byLzLm7cWIBTGCCZ7ETVUvImsYzL/xGbQyrSZHq3H87LsTHdhcwVl15p+CaiWXDRT60aJ2B66OPHAv9EnMv2tJXxiz4JU9bCd8jk= Received: from BN9P221CA0027.NAMP221.PROD.OUTLOOK.COM (2603:10b6:408:10a::21) by CY4PR12MB1848.namprd12.prod.outlook.com (2603:10b6:903:11d::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.17; Thu, 2 Jun 2022 14:28:18 +0000 Received: from BN8NAM11FT029.eop-nam11.prod.protection.outlook.com (2603:10b6:408:10a:cafe::2d) by BN9P221CA0027.outlook.office365.com (2603:10b6:408:10a::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.13 via Frontend Transport; Thu, 2 Jun 2022 14:28:17 +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 BN8NAM11FT029.mail.protection.outlook.com (10.13.177.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5314.12 via Frontend Transport; Thu, 2 Jun 2022 14:28:17 +0000 Received: from BLR-5CG113396M.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.2375.28; Thu, 2 Jun 2022 09:28:14 -0500 From: Santosh Shukla To: Paolo Bonzini CC: Sean Christopherson , Vitaly Kuznetsov , Jim Mattson , Joerg Roedel , Tom Lendacky , , , Subject: [PATCH 6/7] KVM: nSVM: implement nested VNMI Date: Thu, 2 Jun 2022 19:56:19 +0530 Message-ID: <20220602142620.3196-7-santosh.shukla@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220602142620.3196-1-santosh.shukla@amd.com> References: <20220602142620.3196-1-santosh.shukla@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] 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-Office365-Filtering-Correlation-Id: 286acfcb-1ea2-4682-dd9a-08da44a422f9 X-MS-TrafficTypeDiagnostic: CY4PR12MB1848:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: s3OuF0q8rpvdu09ZJ/5KThFz08dwyCZEjE9axfp9zsMKqdMVfYk5NqTLL4+nWcQZAd8vYdfBgJ4EfiXnyY2X99bnaL+O4DqE5mwi+4BhcuZfRX3zXioLHGG7nBK0FKbzqsMshNQTxT/h9mnbP782TMzYuUqOk8tk2Q0aqS4CbxYn6g7dKnFR2hZxGwaHc9XOEu29cLMkwYKLQIUCtaEWyEebrro3RSUZM0rEsFnxOLTnVjDxsY1Nj/3gLibML6rzCwr1DkYIWZQy6TrDo6JRrR31b7cMPOH5ewIGHqRLZsxH4Qae96KP1LnRjOY1mTP+4iMSXUa5KFTy//P3u3HHhgj3yKEE/YbtmMNaZ2C/MCUJnUuND69O8WPvwhyNIqAisQB1vliizKTk54SEPGdpJXRAwt4T+0y2e0sXo9poMYlGG1iqNVcstw96Kjx4HS21ndntFUoViwoAoR+mHUYE5/RjzX0jmF/wafckmAJ1Ltv7iX8/8TCmA36bIHT6Tfy3m8vOLJNnm4Zr0PXgq432774d1pFn6Q+VywpIMEAZyiXaoGSEbr6khm380/G/c3diVQNoNcwopHJuquXQaL67Ms3NSqqp3YzxsNalkWtZmzQRb3jlVhzYeV4OGoUPCKJofitgib9rOPM5XslEUCfJFjCWymQ8Do1pAbNKc2+b6kTDEZQQliRLC6a2Ls9RQ2RNAozOte87EO5yAbwSuQI5Aw== 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:(13230001)(4636009)(40470700004)(36840700001)(46966006)(36860700001)(316002)(70586007)(26005)(44832011)(1076003)(4326008)(70206006)(508600001)(82310400005)(36756003)(8676002)(5660300002)(54906003)(8936002)(86362001)(6916009)(81166007)(2616005)(2906002)(16526019)(186003)(356005)(7696005)(336012)(426003)(47076005)(40460700003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2022 14:28:17.7847 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 286acfcb-1ea2-4682-dd9a-08da44a422f9 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: BN8NAM11FT029.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1848 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Currently nested_vmcb02_prepare_control func checks and programs bits (V_TPR,_INTR, _IRQ) in nested mode, To support nested VNMI, extending the check for VNMI bits if VNMI is enabled. Tested with the KVM-unit-test that is developed for this purpose. Signed-off-by: Santosh Shukla --- arch/x86/kvm/svm/nested.c | 8 ++++++++ arch/x86/kvm/svm/svm.c | 5 +++++ arch/x86/kvm/svm/svm.h | 1 + 3 files changed, 14 insertions(+) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index bed5e1692cef..ce83739bae50 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -608,6 +608,11 @@ static void nested_vmcb02_prepare_save(struct vcpu_svm *svm, struct vmcb *vmcb12 } } +static inline bool nested_vnmi_enabled(struct vcpu_svm *svm) +{ + return svm->vnmi_enabled && (svm->nested.ctl.int_ctl & V_NMI_ENABLE); +} + static void nested_vmcb02_prepare_control(struct vcpu_svm *svm) { u32 int_ctl_vmcb01_bits = V_INTR_MASKING_MASK; @@ -627,6 +632,9 @@ static void nested_vmcb02_prepare_control(struct vcpu_svm *svm) else int_ctl_vmcb01_bits |= (V_GIF_MASK | V_GIF_ENABLE_MASK); + if (nested_vnmi_enabled(svm)) + int_ctl_vmcb12_bits |= (V_NMI_PENDING | V_NMI_ENABLE); + /* Copied from vmcb01. msrpm_base can be overwritten later. */ vmcb02->control.nested_ctl = vmcb01->control.nested_ctl; vmcb02->control.iopm_base_pa = vmcb01->control.iopm_base_pa; diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 200f979169e0..c91af728420b 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4075,6 +4075,8 @@ static void svm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) svm->vgif_enabled = vgif && guest_cpuid_has(vcpu, X86_FEATURE_VGIF); + svm->vnmi_enabled = vnmi && guest_cpuid_has(vcpu, X86_FEATURE_V_NMI); + svm_recalc_instruction_intercepts(vcpu, svm); /* For sev guests, the memory encryption bit is not reserved in CR3. */ @@ -4831,6 +4833,9 @@ static __init void svm_set_cpu_caps(void) if (vgif) kvm_cpu_cap_set(X86_FEATURE_VGIF); + if (vnmi) + kvm_cpu_cap_set(X86_FEATURE_V_NMI); + /* Nested VM can receive #VMEXIT instead of triggering #GP */ kvm_cpu_cap_set(X86_FEATURE_SVME_ADDR_CHK); } diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 21c5460e947a..f926c77bf857 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -240,6 +240,7 @@ struct vcpu_svm { bool pause_filter_enabled : 1; bool pause_threshold_enabled : 1; bool vgif_enabled : 1; + bool vnmi_enabled : 1; u32 ldr_reg; u32 dfr_reg; From patchwork Thu Jun 2 14:26:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Shukla, Santosh" X-Patchwork-Id: 12867927 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40B89C43334 for ; Thu, 2 Jun 2022 14:28:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235940AbiFBO2v (ORCPT ); Thu, 2 Jun 2022 10:28:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235955AbiFBO2q (ORCPT ); Thu, 2 Jun 2022 10:28:46 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2045.outbound.protection.outlook.com [40.107.92.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3477018C069; Thu, 2 Jun 2022 07:28:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fmRsTHgxjM+qLW8VGUDQoIsXqkInz8oCSrpRKrp6HVhEFepSR3BKkjgixOgMeCB2JOlY/z1T1D3aCwXMRjy4R5kTRoNSOnUxSfqhSzsEy8OxTZBkfmeLP+7wEFNc/IV03TrLCbopt1dSzmzaFPtkJndiFjzWihYBnASgnOM2Z6u5W0sNqfMNAFycWFnhRx37euJHqTZCxstGiVmUvhtqwisSjTtY8GTZEsgrxV2Jzqfnyz48cJ7HrgXyM8tb/G5XeJdWSlspKVzy4qHk4glezZ8Da1YZe8SnOnSYeF6H60TlFq4hUAI9nb8ejhWrL8/q8XGzuCLhxKqfsQmC23YojA== 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=4o5M/PHVM2K2EaB3FB0RY9K4/h4bIXBFz2A3qhlq/MU=; b=bEcRWrRH5OtgG/VlhxqDlGJqh8zrqhjayueAqk+OcMj7P1jQDBh1YoXZ11Rlsq30d/sGtm5ycwmxvrR/pbdQPj2JPfGnzGMFlpegOf0N4ImwQvofHkXaUPJPxweGD2vnxt/67lK/Np8nabdz+F6IKlcDgslKqWtAErh9XtQYGQUhUv/wJAVgSP4GoevcwxHzsTKuUkLSYdCe2DsMUc2OjUc7p0CjyiyeJgzQfaKJKcViX2/Sw8rdZ3lUJhWUEe+vPDVzCg4/E3szOH7ntfUvmLtHLXQLGRrVIUSfvhkGSWzbC/TRdDemudps+WkA/HOOulv2DAq5VXSbD5TM6haSyQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com 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 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=4o5M/PHVM2K2EaB3FB0RY9K4/h4bIXBFz2A3qhlq/MU=; b=QUojEj1pX1csNDuxq9TqGyK1LhoLZzpOim7OusrgGb2VqjdqHgUppEkpcNwZgavG76aMiLszob5eaid/QkCcRVJ6/seSwszc1mf+TYgzPh4sMCp/Rtvj0OgHeGETFB30izqxCZ8dZnIfugFlI4dj1GaQaEYo2fp/cnmHAnNpiic= Received: from BN9PR03CA0120.namprd03.prod.outlook.com (2603:10b6:408:fd::35) by DM4PR12MB5181.namprd12.prod.outlook.com (2603:10b6:5:394::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.13; Thu, 2 Jun 2022 14:28:35 +0000 Received: from BN8NAM11FT067.eop-nam11.prod.protection.outlook.com (2603:10b6:408:fd:cafe::6c) by BN9PR03CA0120.outlook.office365.com (2603:10b6:408:fd::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.14 via Frontend Transport; Thu, 2 Jun 2022 14:28:34 +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 BN8NAM11FT067.mail.protection.outlook.com (10.13.177.159) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5314.12 via Frontend Transport; Thu, 2 Jun 2022 14:28:34 +0000 Received: from BLR-5CG113396M.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.2375.28; Thu, 2 Jun 2022 09:28:31 -0500 From: Santosh Shukla To: Paolo Bonzini CC: Sean Christopherson , Vitaly Kuznetsov , Jim Mattson , Joerg Roedel , Tom Lendacky , , , Subject: [PATCH 7/7] KVM: SVM: Enable VNMI feature Date: Thu, 2 Jun 2022 19:56:20 +0530 Message-ID: <20220602142620.3196-8-santosh.shukla@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220602142620.3196-1-santosh.shukla@amd.com> References: <20220602142620.3196-1-santosh.shukla@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] 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-Office365-Filtering-Correlation-Id: 037eec7a-2e42-4aa6-69e8-08da44a42d17 X-MS-TrafficTypeDiagnostic: DM4PR12MB5181:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vMATC3bz/hzMS/UFskpr0JlDqLicprtCqRWCMJP1y1C85wwCep6BN3lyZoMpaFInCw3/r1pUWg6BY9xz9QR9QhU+7r9zDAcQ/5fVrFhtc7eZdVVcQ+a6BJQV+fKlbD5Pe4J406dVICnH4F2NG8PXtC6PXLvFo28N0X0gZNW+PCohj2RwCudk8FznH9oWqOYZ2e4ftivYeCpFxVTdxCvqdwOPSE/0nbHGTr9HAtwSzBn1Et8eT1W4SA132zGV4eXsrDn7qo6x1AE4JB0/dyQD8ad3grSH5UfG7Akbmnar/VRVkexu5+ZihwM0VSsOPCC6cqCErFOavri7I9NybfqWtzwKedRwOi+QLDSbeTHQiaYjhkzXjzfYhh9l8zWuKoKvoXo83TugJiqMe3sS1SFfcfrrw/3IgQ+lhnsvwZYvqhz/1a13Ml1MnB6csNsie0nW5XqUN5l5+wnCNLwCtD+fPap9QDDsGFLtH8LUZdawIVepgju1Fst6RxWc092I+ig0GvGW1zsWDLQhwiKLcj0V3KXZkO4qzQdVfCeDn7D78GjNhr/avyD1+Pr7bomDZgbE2yQsmhDagewSznb0sahKnsUaREqS5b3zbQDkVTfmhuKTv8pgr8u7nATIq74LsUntYled3KXx3UK9zXbLIMX3VhbBmsvfYUBkUQoqFPxzA+Lh3rGGBgAWajRXGYnK2k8bVCde9S4ZVqKcGrLyzbBuag== 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:(13230001)(4636009)(46966006)(40470700004)(36840700001)(70206006)(508600001)(8676002)(70586007)(6666004)(36860700001)(4326008)(316002)(86362001)(40460700003)(36756003)(336012)(426003)(186003)(16526019)(47076005)(1076003)(4744005)(82310400005)(8936002)(356005)(26005)(54906003)(6916009)(2616005)(7696005)(2906002)(81166007)(5660300002)(44832011)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2022 14:28:34.7399 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 037eec7a-2e42-4aa6-69e8-08da44a42d17 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: BN8NAM11FT067.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5181 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Enable the NMI virtualization (V_NMI_ENABLE) in the VMCB interrupt control when the vnmi module parameter is set. Signed-off-by: Santosh Shukla --- arch/x86/kvm/svm/svm.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index c91af728420b..69a98419203e 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -1205,6 +1205,9 @@ static void init_vmcb(struct kvm_vcpu *vcpu) if (kvm_vcpu_apicv_active(vcpu)) avic_init_vmcb(svm, vmcb); + if (vnmi) + svm->vmcb->control.int_ctl |= V_NMI_ENABLE; + if (vgif) { svm_clr_intercept(svm, INTERCEPT_STGI); svm_clr_intercept(svm, INTERCEPT_CLGI);