From patchwork Wed Aug 10 06:12: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: 12940262 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 A92FDC00140 for ; Wed, 10 Aug 2022 06:13:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231267AbiHJGNj (ORCPT ); Wed, 10 Aug 2022 02:13:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229490AbiHJGNh (ORCPT ); Wed, 10 Aug 2022 02:13:37 -0400 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2061d.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e8c::61d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4E93606BA; Tue, 9 Aug 2022 23:13:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DxGK/T5HWL5zgPGs4gsNLEFoYh1RdibB7Fb8ZE+zq9TEp2A7QDLeYh9EJ2CXWIFQgX39hNvtqcfNapRZZvbx0Hq18mx/+kNw9HZJJuzZnUdjH5JVKNwYtcorxKt91e/btKBoW8GJkhMqZ0xUqoHoERYpUpJRh2hNHZK26CuSATSps48B9/zRDzy3js4UL6b4dWblq7uOep8o7dE5PLsYEC7ijOdqG5EbWAsxi9gKzvRDSp0dH55GKLx+U2TpQikTKDslZTe8zx/GOQesiTqw5lYL1T45zJhfTIWWjqq4Wz+QDX56B/PTJ8fge4EOkzkVyffMB56Kql7WNzaVxI+CAg== 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=8cuinjq2l4FGfhpt3iGm/+BclBbGZ9YyXMyHBW+EC9g=; b=KUwjMwpOibdlUdYi3j/f/9FYOjh52Wf/DPscW9LUCdoOCS9UwLuBzefeZhInTKXoU08TcIenh40S1CmPY5Tu7+VcPBvuCUKmcTiqFnXKRZzprCH7r8fxluL4Lt5/cviMAQh2aXCNNgnkgfSeaYF5+ya4Yti3UEhOYpfDfXOSA5vNJrrLCufxAxT4eVJrpMhshWETPLdvpRYB51rFKVrDu9IEhJCxvCYZnKMcE3xCGI5x6W16gzJq2QZaejf8yrjL5rKJijs/IH66BBRzU6BU92w2jOPlLgxxDxHz5NtdYIEjn+StWbkhoBiVsBjVNthAgICZxUrKcsTQ3mwZG1XAvQ== 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=8cuinjq2l4FGfhpt3iGm/+BclBbGZ9YyXMyHBW+EC9g=; b=hkfwQ9Xdt64Is+Gofno2d3xcnwym7TrXCnBQme/kRXVn8WaQ63JY+OstkaTXTC6qGC9K8H2H/G6GVGOXYndlnfj/fh1YFJLVTfZFpbtRinK7AhLOb3jpPD+aeOlmvpqaInJYyemihzaRzgYf0ufRaj2/2jCmLApSX60df9Axo2M= Received: from MW4P222CA0012.NAMP222.PROD.OUTLOOK.COM (2603:10b6:303:114::17) by PH7PR12MB5685.namprd12.prod.outlook.com (2603:10b6:510:13c::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5525.10; Wed, 10 Aug 2022 06:13:33 +0000 Received: from CO1NAM11FT049.eop-nam11.prod.protection.outlook.com (2603:10b6:303:114:cafe::29) by MW4P222CA0012.outlook.office365.com (2603:10b6:303:114::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.23 via Frontend Transport; Wed, 10 Aug 2022 06:13:33 +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 CO1NAM11FT049.mail.protection.outlook.com (10.13.175.50) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5525.11 via Frontend Transport; Wed, 10 Aug 2022 06:13:33 +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; Wed, 10 Aug 2022 01:13:27 -0500 From: Santosh Shukla To: Paolo Bonzini CC: Sean Christopherson , Vitaly Kuznetsov , Jim Mattson , Joerg Roedel , Tom Lendacky , , , , Subject: [PATCHv3 1/8] x86/cpu: Add CPUID feature bit for VNMI Date: Wed, 10 Aug 2022 11:42:19 +0530 Message-ID: <20220810061226.1286-2-santosh.shukla@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220810061226.1286-1-santosh.shukla@amd.com> References: <20220810061226.1286-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: bb21811d-4428-4c8d-9b38-08da7a977435 X-MS-TrafficTypeDiagnostic: PH7PR12MB5685:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RlQiek6+thtZ4J4C6/ZRUx6amkvzwaSBPhuz+b1CSUF8WnUw1f4u3sodNXTiTSi7iLrzlR3blenex8tdhJpLQeo18PK+3zGT9YAGL+HvhSqTqSYqcaW+RYPHL6TO0tIiK4GLN/27DNd+WGFezeOppy8CLrapibvWbxaSv1ESXJmQkSlK2uB0xLeB5s6Tatc32es2KZe7f97r83yI+eq7xQ67tTXfbUl++yFgJEHAZg6TGBZGEIy/B/JwGtu9DDPyXm7xI8zCpEa6HB2cM5fTqsGi0D4cvH6bgp0DeZ0pIBgehHyCqhslqspduo22iok1KrLe1ggSaAZxjofI88Od/eVR4GCKPItjqjvAvChiZlleTVmQ27Fyn8zJ+yKubhIzEIsoVznUmzrmkCMqr9Y7A/j0twJIMO8+lkeYyGK5NveTmcQf7Bvnc59C8RInkrjYfmLtldzGHVZ/K1yJI9F+RRuTRjN1hd0JRSNCWyUu1hR6Djo6vmiDRPJDqlhXVftphJnVfNenNyi7cqdzMEEJdI3bmmN/wo+6qGQ+oEjQVYQ/i22rR1HNCxnvsP2EujMXOo/aZRkQyIDAxtJkfeAM4wKStKoLdCmb0v/s+hU1TjLccN98KVyXIxWTSJbC1JYNb4Vew+nOEms/uw29wni27TBC0VtFjGftxFyjRuubX2jFRRlbP45yA7ip2i1lMilIc2D4YdGp5oJrn2pr/7vAYsjnh8V600hZWdp9Z0McNIKBvtCddJfyz5JpORqQAHwjxm0ZOwvJkb1eqr/ddUOU60KG54JpbDq1GJq3erTJ0WGtlTA3ufB3wKT1P8TJvS01jt8oCU5tkDDrA4zc2p2tSA== 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:(13230016)(4636009)(39860400002)(136003)(346002)(376002)(396003)(46966006)(36840700001)(40470700004)(70586007)(2906002)(44832011)(82310400005)(4326008)(8676002)(70206006)(316002)(6916009)(5660300002)(478600001)(40480700001)(54906003)(7696005)(81166007)(86362001)(41300700001)(6666004)(26005)(36860700001)(36756003)(336012)(8936002)(356005)(426003)(47076005)(82740400003)(186003)(16526019)(2616005)(1076003)(40460700003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Aug 2022 06:13:33.2479 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bb21811d-4428-4c8d-9b38-08da7a977435 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: CO1NAM11FT049.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5685 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]. Reviewed-by: Maxim Levitsky Signed-off-by: Santosh Shukla --- 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 14ed039dff55..3d984fd9d41b 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -355,6 +355,7 @@ #define X86_FEATURE_VGIF (15*32+16) /* Virtual GIF */ #define X86_FEATURE_X2AVIC (15*32+18) /* Virtual x2apic */ #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 Wed Aug 10 06:12: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: 12940263 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 DDD32C00140 for ; Wed, 10 Aug 2022 06:13:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231281AbiHJGN7 (ORCPT ); Wed, 10 Aug 2022 02:13:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230368AbiHJGN5 (ORCPT ); Wed, 10 Aug 2022 02:13:57 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2042.outbound.protection.outlook.com [40.107.220.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7095642CC; Tue, 9 Aug 2022 23:13:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U2+r9yluFU1K2ISYAd8nH1sC9E9ks/Gq6IJMAgGdZ8Yt1LG1AeBzGkDKNBw0rlY+KJDnpi6gWDEmujsRBBUszb5Lo2qdsesmRVRPshJXWdcfigZ9pet+J+7genYbSU5cnOzfTLwbiRRJqNlgKWW52QwIwbU11/37wExUvUFJFuPFjJwj0FOmbMCtq0kmRQX8VOX8AGiq40T1heQQL3g/rZpWvqRT2wOrl2b+Z78KNHA+FOLs/ecpxJqY3XDeGOXWytAqkw5gdUoss1YN96o9oAZ+T/abqp8fa7qp8i7YIZwPBTxnGG05dzlQJb6T9FLgQhQvtX7hUewIR7Jx/wkCEw== 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=6oV4hAHpWP/Vz1gxeXYquk7m1U1CsrZ2Hiuj57enKLQ=; b=AMVjQMTmUCHBg/sRNivoHFzk8VU5uW8qsoFaXy34BziSNRIDnfTTOwm5BYAOgHLZEBSkPQg2oDFXlvs+Lw+13l9gvZBKIXk8VIKdQixL7zyPDMO0z5gfNkCQeHLkH0WTKYktOCwS2KS6J3ApTG8z3JQ34n/I2vwEKD4eCc4RncVhaIFtfKUS5AAVhAq5mkXdj3/ym344fNPVo2DTwbcsEr1SQQ7IbdlDAkgBNSAPjNEwm4v4t14lSvu3p5GUxjFRUr4pl6lE4enOO8maC/aiwZR15rc+Wtr4M7lPWEvxW7mLwH6lqMYz/ep/2Klo5I+2LarO1wjCc1D49QioBFMJVA== 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=6oV4hAHpWP/Vz1gxeXYquk7m1U1CsrZ2Hiuj57enKLQ=; b=CHLeYB3x2uY471N51a+qD234RzPhWgZZUu6nfi2VpK+8QpXxzPdcBzgFjL5zzWRX3Bbq/tFH43Nh26YGRfLScLyBhtVbGQhbQDDE9fTI8QALsHK2jGrcUXy63TzbxVotQTYtJrFonQ/PgfYEO5gO+Qa+8wt0XAJFMumjpdfWYf4= Received: from MW4PR03CA0090.namprd03.prod.outlook.com (2603:10b6:303:b6::35) by CY5PR12MB6204.namprd12.prod.outlook.com (2603:10b6:930:23::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.20; Wed, 10 Aug 2022 06:13:53 +0000 Received: from CO1NAM11FT035.eop-nam11.prod.protection.outlook.com (2603:10b6:303:b6:cafe::20) by MW4PR03CA0090.outlook.office365.com (2603:10b6:303:b6::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.14 via Frontend Transport; Wed, 10 Aug 2022 06:13: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 CO1NAM11FT035.mail.protection.outlook.com (10.13.175.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5525.11 via Frontend Transport; Wed, 10 Aug 2022 06:13:52 +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; Wed, 10 Aug 2022 01:13:46 -0500 From: Santosh Shukla To: Paolo Bonzini CC: Sean Christopherson , Vitaly Kuznetsov , Jim Mattson , Joerg Roedel , Tom Lendacky , , , , Subject: [PATCHv3 2/8] KVM: SVM: Add VNMI bit definition Date: Wed, 10 Aug 2022 11:42:20 +0530 Message-ID: <20220810061226.1286-3-santosh.shukla@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220810061226.1286-1-santosh.shukla@amd.com> References: <20220810061226.1286-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: e093b420-b434-4ee5-8bd8-08da7a977fe4 X-MS-TrafficTypeDiagnostic: CY5PR12MB6204:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VVy57DrA9rkmxweIPmLirbg5vj2he9XjhET+BEy+M3AIkZnBlXutcg7sFXl428Uhm90viKxfam8hT6Nsw17OlOJsqM0ELoFaVRVQkYLOAhLC4GbwOPdpNFKKQ8XF3SLtE/Pxa5VhbNUUrut2BIx3gRCRUuUqvPN+iX9wl6qMpWuL6k/PkT+7nx/VMxzbuU18OkmouE4mVg9n+W+qze0GGB+vfkOlvnTfvCkGQsGrmlxpX36JYZP19JSJFbWgzZohNB0lQpxXd6FLuH2Ol611ajPz1N+/M7O3PPCccAVzjtTsT0Lx9h84kuSMFUhsZzdql5PzQhYbzCvH91GLSqx9uKo0rVncdJefveK+XmQqzGeQZjKlrCzRtGdVl11c7EzX1QYkxgdu87brGmSc3HJN48yIPTpQKHwFY7XtTTsfiXAfvtofwRt+3S0v8hAa9gDnuz23QQNsbjt6ssbdMCvF90017Clbg0ncyyknlFms7II9LA4XKU2gSv+/PNaYW0Y7h95nlMjGlPrNoGzZ9p31Es4IkUMzYU80dMulj8dfZSPw/x/STUjurDWw8ef1FAKJp8whaQb5Wh4M5Jh1MObs7zwwzemZwMZvb7YLIybRitnfGAqRDbTd4BS2DQj4aKNZzuK0tcByk8Rz2ZtEXZCiwIrrXE8DRnA+lSjWUjbFdLMeKg/Jo5CJkEJM94Bs4tzUZgsiZJjI6JImGHSE9hnBJRW0HCcVLD1vy8YtqoBtUROAhM9frxdlbPINRsxjiow0iQAJu/a5PMworqtlt4dvSP5MA6xzz6eVDxdWCsefBItFwdsrorzv9uPEP51yEK0+DHZFNpRoHqPtXIN0eSj4Qw== 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:(13230016)(4636009)(346002)(136003)(39860400002)(396003)(376002)(40470700004)(36840700001)(46966006)(8676002)(70206006)(8936002)(4326008)(186003)(36756003)(426003)(478600001)(40460700003)(16526019)(1076003)(70586007)(336012)(54906003)(6916009)(316002)(5660300002)(44832011)(86362001)(41300700001)(26005)(7696005)(6666004)(356005)(81166007)(2906002)(2616005)(82310400005)(82740400003)(36860700001)(40480700001)(47076005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Aug 2022 06:13:52.8650 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e093b420-b434-4ee5-8bd8-08da7a977fe4 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: CO1NAM11FT035.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6204 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. Reviewed-by: Maxim Levitsky Signed-off-by: Santosh Shukla --- 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 0361626841bc..73bf97e04fe3 100644 --- a/arch/x86/include/asm/svm.h +++ b/arch/x86/include/asm/svm.h @@ -198,6 +198,13 @@ struct __attribute__ ((__packed__)) vmcb_control_area { #define X2APIC_MODE_SHIFT 30 #define X2APIC_MODE_MASK (1 << X2APIC_MODE_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 38f873cb6f2c..0259b909ed16 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -229,6 +229,8 @@ module_param(dump_invalid_vmcb, bool, 0644); bool intercept_smi = true; module_param(intercept_smi, bool, 0444); +bool vnmi = true; +module_param(vnmi, bool, 0444); static bool svm_gp_erratum_intercept = true; @@ -5060,6 +5062,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 Wed Aug 10 06:12:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Shukla, Santosh" X-Patchwork-Id: 12940264 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 2C207C00140 for ; Wed, 10 Aug 2022 06:14:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230494AbiHJGOt (ORCPT ); Wed, 10 Aug 2022 02:14:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230368AbiHJGOp (ORCPT ); Wed, 10 Aug 2022 02:14:45 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2049.outbound.protection.outlook.com [40.107.223.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29A5561B2C; Tue, 9 Aug 2022 23:14:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YKjjC0w1ydT0ct8US3a79WQUfa4KTLM590/KKMJZT7drR/1MMXffjRjpNLfaw+Ex8nbzoLJOWsdNfYoKe1323xchfQQM+jlltltLEkhDejSPNWWN2uQkBWS21aBDKgNGyJYF8gMZuc9Z0Qt01mKffMHYLfvLlrDPspz1L5VTR8WaadPrQMeglppO/NOEGV5fx06J5ieBLls69Q3S+C5Y/2ctIhcLGGxHtxzqdSYfI6fHfSJMpese2w/iiJziE6EpoumMjJ7kdjg77SGwPtoelvgEUugHGDzG3cAbIP8Qn++4HtbyBvbUA97NCfofGoq/hFF/9ml4cVyZASJbojENMg== 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=SBwOqhxIGGrJHDbjGcvPIsSk4XPM0bC7oeQv0qWEYMk=; b=e9e1J4/Kk2Qme5lL8tDk2GPUnfiDlq/wsKF9Zr5XLSebWfDOYiaAEoaEReJWhz6D/IXvnsXcaU0GxSyZ5/WsCsH2jMwPsJ5pHkQJvoW3fZsNwakjnQXUWR1c16IkotLtxVkTh1tjjSfS41y6L9QCBmZgIhLFj4OUdLnp+4k7Vr7LrZJpHPsLsaD4mFQpRQv1M9ZaSO0Qrp8ZERLLjUnS7VQDXQojXy9+xJtzZxfFxdW/XitN1LWSh6+iPwQhtiBqeRiE6Kn0H2pbauSC7yyWkl8A5pzO+aiksWGHudSvIroply+eyqn9HMbG3qxNk3RGrwSxTR4yto2M8mwHc0HMgw== 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=SBwOqhxIGGrJHDbjGcvPIsSk4XPM0bC7oeQv0qWEYMk=; b=0qqLHHue0VlBY8ycV7Ms7+Kj1hPd4f6Qf0TJwND7x0cPZ1T57bRzjJGpZXsMf7PQikEPcLNpzEaDlhtd6OZ/yosyEMQ9N8XHvwwZ05V4+X2Gxs/73V6Lb0+r/Wn2T8KPANyvL/pVWymqEiZzwPJS8eD6JeGuT7lkmLxKAwWldoo= Received: from MW4PR04CA0284.namprd04.prod.outlook.com (2603:10b6:303:89::19) by DM6PR12MB3579.namprd12.prod.outlook.com (2603:10b6:5:11f::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.16; Wed, 10 Aug 2022 06:14:41 +0000 Received: from CO1NAM11FT038.eop-nam11.prod.protection.outlook.com (2603:10b6:303:89:cafe::eb) by MW4PR04CA0284.outlook.office365.com (2603:10b6:303:89::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.14 via Frontend Transport; Wed, 10 Aug 2022 06:14:41 +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 CO1NAM11FT038.mail.protection.outlook.com (10.13.174.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5525.11 via Frontend Transport; Wed, 10 Aug 2022 06:14:41 +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; Wed, 10 Aug 2022 01:14:06 -0500 From: Santosh Shukla To: Paolo Bonzini CC: Sean Christopherson , Vitaly Kuznetsov , Jim Mattson , Joerg Roedel , Tom Lendacky , , , , Subject: [PATCHv3 3/8] KVM: SVM: Add VNMI support in get/set_nmi_mask Date: Wed, 10 Aug 2022 11:42:21 +0530 Message-ID: <20220810061226.1286-4-santosh.shukla@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220810061226.1286-1-santosh.shukla@amd.com> References: <20220810061226.1286-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: c02be749-98c8-4c3e-c3e5-08da7a979ca5 X-MS-TrafficTypeDiagnostic: DM6PR12MB3579:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jf1PEFY9I5ZVYUIpMswwV+RYXDqpIk1/CTa8riRnoLo0FX3QoAGQdS9PIeQwbqhUbDd0mSEQ3/cBr5AdQfnU4YIi2wCZHDiQM9ShghS6OGXIP7RWobxLN0A/fTmSTr+WA6NDI/0FxohKDLzfFSEJTEh9B0yX1YQZwU7Wf/f8mVS4OUNdymKxrJ9PaB7FgsKehG2hhE+sjk9n2oWzpwqIfJEarCehXZxVNZraj7/dDtmjvQ/cCbQdeYh7QRNtN8TrIj/vxHB61tINIe/j0P288qANY0eiMqsGoZB0p6NiiiwSkik4JsgNmVUZzPLzNjAKmJ4rwaaC2LEL1aNsPz47b3jLgiQta+GX/5Sy2edI6rcDAv//pR1cBvxopUesZfG1ZnT2KNsBBFpM64Q32S9/fq7QRTteFXrwNzEgoZ0SGP+7W2r/4Xtg3XS+dquNWwPl6vHxO3zPPhDLvpPVL9xVzqEC8qH/cXdR90IVbxeGCzaAK1tIOkDxoq+HQRGhWY0zChDQJrql9jntaS+5wlovaP9f8pCO1cB8TQeqGbqLWa99K1I5HbD5P27cdKIaW+FdSZf013NTgDXqGWGtooZNSArcYU+Ue/HVdh+uywchh9tj6ulS1EIKPh8cST45dDW8NHdM0MIrSaGuufuPbTi2g04xFErB0q7pv0NCS2qdbpFlqw0IirIjGwPbHu+YZos7hfIy1GcFcMChcpuvDKNzEnBxE1erDiq9lTaPa5d3TF8kdLb082uzgTp/HHEmaU2msBWIuuLzJr+Bw6oI8jQ3bN6Kv1bT1ojWYhzM9CaPeSHCPpNSEcTUT2g2qBMeopXBVoVM7K8ZiSyx2/dSEkp3nQ== 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:(13230016)(4636009)(346002)(136003)(376002)(396003)(39860400002)(36840700001)(40470700004)(46966006)(54906003)(6916009)(8676002)(41300700001)(26005)(5660300002)(336012)(2616005)(426003)(47076005)(478600001)(186003)(86362001)(1076003)(16526019)(36756003)(4326008)(7696005)(6666004)(44832011)(8936002)(316002)(70586007)(70206006)(40460700003)(36860700001)(82310400005)(2906002)(83380400001)(82740400003)(40480700001)(81166007)(356005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Aug 2022 06:14:41.1075 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c02be749-98c8-4c3e-c3e5-08da7a979ca5 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: CO1NAM11FT038.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3579 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 except for the SMM case where hypervisor before entring and after leaving SMM mode requires to set and unset V_NMI_MASK. Adding API(get_vnmi_vmcb) in order to return the correct vmcb for L1 or L2, and also API(clear/set_vnmi_mask) to clear and set mask. Signed-off-by: Santosh Shukla --- v3: * Handle SMM case * Added set/clear_vnmi_mask() API. v2: - Added get_vnmi_vmcb API to return vmcb for l1 and l2. - Use get_vnmi_vmcb to get correct vmcb in func - is_vnmi_enabled/_mask_set() - removed vnmi check from is_vnmi_enabled() func. arch/x86/kvm/svm/svm.c | 17 +++++++++++++- arch/x86/kvm/svm/svm.h | 52 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 0259b909ed16..f0ac197fd965 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -3621,13 +3621,28 @@ 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)) + return is_vnmi_mask_set(svm); + 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)) { + if (is_smm(vcpu)) { + if (masked) + set_vnmi_mask(svm); + else + clear_vnmi_mask(svm); + } + return; + } + if (masked) { vcpu->arch.hflags |= HF_NMI_MASK; if (!sev_es_guest(vcpu->kvm)) diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 6a7686bf6900..cc98ec7bd119 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -35,6 +35,7 @@ extern u32 msrpm_offsets[MSRPM_OFFSETS] __read_mostly; extern bool npt_enabled; extern int vgif; extern bool intercept_smi; +extern bool vnmi; enum avic_modes { AVIC_MODE_NONE = 0, @@ -532,6 +533,57 @@ static inline bool is_x2apic_msrpm_offset(u32 offset) (msr < (APIC_BASE_MSR + 0x100)); } +static inline struct vmcb *get_vnmi_vmcb(struct vcpu_svm *svm) +{ + if (!vnmi) + return NULL; + + if (is_guest_mode(&svm->vcpu)) + return svm->nested.vmcb02.ptr; + else + return svm->vmcb01.ptr; +} + +static inline bool is_vnmi_enabled(struct vcpu_svm *svm) +{ + struct vmcb *vmcb = get_vnmi_vmcb(svm); + + if (vmcb) + return !!(vmcb->control.int_ctl & V_NMI_ENABLE); + else + return false; +} + +static inline bool is_vnmi_mask_set(struct vcpu_svm *svm) +{ + struct vmcb *vmcb = get_vnmi_vmcb(svm); + + if (vmcb) + return !!(vmcb->control.int_ctl & V_NMI_MASK); + else + return false; +} + +static inline void set_vnmi_mask(struct vcpu_svm *svm) +{ + struct vmcb *vmcb = get_vnmi_vmcb(svm); + + if (vmcb) + vmcb->control.int_ctl |= V_NMI_MASK; + else + svm->vcpu.arch.hflags |= HF_GIF_MASK; +} + +static inline void clear_vnmi_mask(struct vcpu_svm *svm) +{ + struct vmcb *vmcb = get_vnmi_vmcb(svm); + + if (vmcb) + vmcb->control.int_ctl &= ~V_NMI_MASK; + else + svm->vcpu.arch.hflags &= ~HF_GIF_MASK; +} + /* svm.c */ #define MSR_INVALID 0xffffffffU From patchwork Wed Aug 10 06:12:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Shukla, Santosh" X-Patchwork-Id: 12940265 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 C117DC00140 for ; Wed, 10 Aug 2022 06:15:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231296AbiHJGPH (ORCPT ); Wed, 10 Aug 2022 02:15:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231330AbiHJGPE (ORCPT ); Wed, 10 Aug 2022 02:15:04 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2060f.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e89::60f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA7966555B; Tue, 9 Aug 2022 23:15:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HEXArPLlnMgzWixgVOTlXyzfYObWyfG33dm61azdroCRC+LmQSM38oNj903Sjastn1izWgKv2/GXvQa4IOANqjyRyRT4JOc8vEt8WukwahgilCInJiN2PiZmvXl7J1Jit9Eg0sIfcoFC5f8qMhRPgM1YA7Kjyy+5pE+hVBtLKbvwnNq+5XzzW3Ajm0PSc4dlpxv7USIZoBadVudqBZiwE6/OQ2W8vqOPWa1S3j4ynsoHmDdqqyCB4NZ4wMkqwmea4ed4YpGSJ2Wrf8SJWIQtqRGFFgUpop1KlYXnyh28ubXGRRU53BdDLqBEL8weqJuElXysUcx1D6PnOLCl/f6vOQ== 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=O+FS/Kl16tw7VhK3S/8TQWrebXA+HNq8NiRCKqQfG/c=; b=CTHFV6XAp8dkitbIrMkw6FESlhItb97Wx76QaFSgKxjNoY9sRp8VEhMwS1WTHIJ3gl23o+Y0Sm4YIi1Rk0J26r0wstm7Z0XuPPILves4eaLrvnaWDQrqCKwgrArJE57FmUZg20/n9UJJDKOOrW5ds2f3Ljw8vvFysPi9IdxfrQ1kSpIkz+XeAwPTSTy6rgaFjn3ZC6iqCNHgSTlGNdSOlGZ+UlgX5ru5gByBa0llzU8gQ0o9bvoH9yG/gzkOegqf047jhZny6sNdcgcIPe5UqysOsqLFE8KIeBrUSvtrni4EykqEOBaed4tg2iBQ3eyPuCtVApfDt1R8y6m3uW14cg== 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=O+FS/Kl16tw7VhK3S/8TQWrebXA+HNq8NiRCKqQfG/c=; b=gKobG6OheG54VEn01Yj2v0moAluTHYL3+ZSZiBIGlPxpGKugsUmS2ZG/yNvg58PhQ3Ara77yq2zNq0dSrjc4GDA0iZrpJ3E1IPA1b+ulb7/eUsInXnVEcFX6/O3Y0dA+efYDmLL2Ak9H9vTOdGzinsBL6++kUBPvsTd3Co5yKRA= Received: from MW4PR04CA0250.namprd04.prod.outlook.com (2603:10b6:303:88::15) by BN8PR12MB3044.namprd12.prod.outlook.com (2603:10b6:408:45::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.16; Wed, 10 Aug 2022 06:14:58 +0000 Received: from CO1NAM11FT024.eop-nam11.prod.protection.outlook.com (2603:10b6:303:88:cafe::5e) by MW4PR04CA0250.outlook.office365.com (2603:10b6:303:88::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.14 via Frontend Transport; Wed, 10 Aug 2022 06:14:58 +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 CO1NAM11FT024.mail.protection.outlook.com (10.13.174.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5525.11 via Frontend Transport; Wed, 10 Aug 2022 06:14:58 +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; Wed, 10 Aug 2022 01:14:52 -0500 From: Santosh Shukla To: Paolo Bonzini CC: Sean Christopherson , Vitaly Kuznetsov , Jim Mattson , Joerg Roedel , Tom Lendacky , , , , Subject: [PATCHv3 4/8] KVM: SVM: Report NMI not allowed when Guest busy handling VNMI Date: Wed, 10 Aug 2022 11:42:22 +0530 Message-ID: <20220810061226.1286-5-santosh.shukla@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220810061226.1286-1-santosh.shukla@amd.com> References: <20220810061226.1286-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: ba4b4b65-0d07-44b3-fa09-08da7a97a6f4 X-MS-TrafficTypeDiagnostic: BN8PR12MB3044:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XW8kJVfma+gdkZW02yaullU0ufbKmB5JtX5oKRDSzxcLpAwtIbTBaybdumYhdJp3Y72R4QYhac2n0vztqRicW5PaGuZx8rLwSx6rP7ijguDzXDjUqUmcNDknONLcLx1a2acf67edB4hfxy/qfhW68Jislxv5eFe/9zztQNL7/3c+7V6VyDt3Oo5LhNf2mAi/jOTa4gkRQrR0aaDf2JjKLzikuXhHhkDAM9TmV2ONycjgQbF9r64YocI74ZH1xaTUDgdZmwpjga8XbXbZQ9jGxuSH1BFerXZFjoLKqGOwDT5Ht1+qeqKX8ya5QSMTENXJrscNbwTCiFgSW2mcE2pobwhZrhLhPvDZznfLaeD/eU9V61yckI0KjmpUegN0jWhu3Fpv15Wz+gydoMFc0AssIFwsGnZfZF2vFc3TVGByn3I0vZCOTwPUntZGkysyoj83o6UQpRWmFTxYAZ8AIygUJQvaKYJKL/ih/bestdD+HEDj/Xm1Tnm9cEi1j5t0u6r8E4elOBsNjPluqBRIdXztRPsy/Ch1wTNL1FKbkoe66gGnz3AY6WMOpvrZxI2l86XghXLsIgua44+iLTxJzhqE9zsD5hvb2YNPMADmjpQ46ueqXQiTXGFe8EOfwvtscLqrH/G5oiOevf3FqOArI8EsSgA8nCE2pEhiOkI3ouwDP86/kFQgapxRv0RWNFuxj68rTcSBEuFKuZQu5sWcxm6vZrqZeNKIdJOrm/Y+yhHkg02t1lpnhv2y/1Iv8hW02cLFTtcbDQHpDpSSdUBZONzbnb/DqZ8L5LXAeAKTyk+amC0PH6sjitD57LtFM18sjOkHYhSEMYb2bnBWamOArQpE5Q== 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:(13230016)(4636009)(376002)(136003)(39860400002)(346002)(396003)(36840700001)(40470700004)(46966006)(36860700001)(70206006)(70586007)(83380400001)(81166007)(8676002)(4326008)(36756003)(2906002)(8936002)(40460700003)(82740400003)(356005)(6916009)(54906003)(186003)(26005)(16526019)(426003)(336012)(47076005)(478600001)(5660300002)(7696005)(41300700001)(44832011)(316002)(1076003)(2616005)(6666004)(40480700001)(82310400005)(86362001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Aug 2022 06:14:58.4038 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ba4b4b65-0d07-44b3-fa09-08da7a97a6f4 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: CO1NAM11FT024.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB3044 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org In the VNMI case, Report NMI is not allowed when V_NMI_PENDING is set which mean virtual NMI already pended for Guest to process while the Guest is busy handling the current virtual NMI. The Guest will first finish handling the current virtual NMI and then it will take the pended event w/o vmexit. Signed-off-by: Santosh Shukla --- v3: - Added is_vnmi_pending_set API so to check the vnmi pending state. - Replaced is_vnmi_mask_set check with is_vnmi_pending_set. v2: - Moved vnmi check after is_guest_mode() in func _nmi_blocked(). - Removed is_vnmi_mask_set check from _enable_nmi_window(). as it was a redundent check. arch/x86/kvm/svm/svm.c | 6 ++++++ arch/x86/kvm/svm/svm.h | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index f0ac197fd965..e260e8cb0c81 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -3598,6 +3598,9 @@ bool svm_nmi_blocked(struct kvm_vcpu *vcpu) if (is_guest_mode(vcpu) && nested_exit_on_nmi(svm)) return false; + if (is_vnmi_enabled(svm) && is_vnmi_pending_set(svm)) + return true; + ret = (vmcb->control.int_state & SVM_INTERRUPT_SHADOW_MASK) || (vcpu->arch.hflags & HF_NMI_MASK); @@ -3734,6 +3737,9 @@ static void svm_enable_nmi_window(struct kvm_vcpu *vcpu) { struct vcpu_svm *svm = to_svm(vcpu); + if (is_vnmi_enabled(svm) && is_vnmi_pending_set(svm)) + return; + if ((vcpu->arch.hflags & (HF_NMI_MASK | HF_IRET_MASK)) == HF_NMI_MASK) return; /* IRET will cause a vm exit */ diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index cc98ec7bd119..7857a89d0ec8 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -584,6 +584,16 @@ static inline void clear_vnmi_mask(struct vcpu_svm *svm) svm->vcpu.arch.hflags &= ~HF_GIF_MASK; } +static inline bool is_vnmi_pending_set(struct vcpu_svm *svm) +{ + struct vmcb *vmcb = get_vnmi_vmcb(svm); + + if (vmcb) + return !!(vmcb->control.int_ctl & V_NMI_PENDING); + else + return false; +} + /* svm.c */ #define MSR_INVALID 0xffffffffU From patchwork Wed Aug 10 06:12:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Shukla, Santosh" X-Patchwork-Id: 12940266 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 ED01EC00140 for ; Wed, 10 Aug 2022 06:15:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230492AbiHJGPv (ORCPT ); Wed, 10 Aug 2022 02:15:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229636AbiHJGPu (ORCPT ); Wed, 10 Aug 2022 02:15:50 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2082.outbound.protection.outlook.com [40.107.223.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1655813F3B; Tue, 9 Aug 2022 23:15:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=M6DRhY6ozXlbQMvshrS65XOw5a2B0elPMSdJXE6nklbzwLoGN7I4bBH7iZJv2SqavQK3S19xlarXmG1AtRg6gK9m2ZcEi3o0wJUsrfNEoYTMgnVcZjGZy4V3KO4HjqIhJDqEKVCwCXYc9IP99w88J33tnUW9CluDlDwFR6W9TYVjhCeRooAUEgn55WTFT75QNBBNTQ+Ixju7M+ZX/pDU57mNKXqrPVpE+Jjk6JOMTebgRZzyB0o5Pjl5bGzK9KpbagLmD4AIplq7MxF9oaBmYa7EhUCQXnBGpgOSy4OvS4n2mW9tkLBw4Rby/YF5Fh9ye5joUFapSyV7ZjaDb8gAMQ== 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=k/Oh4S8RoMKO3zD+uy2c7MW79/v4N5JzTGiWH2cKENo=; b=bHexZfI99qVdy/6dkhjKPFHxtIREg4zOnIqlfI3H8jg+ZyTAQ4fPeAobBM3rFiUbdhd96MBqhLa6NN/fE624Ib7RwYjeZ0ViMM3gMJp2060Kgxxz+pWsAuJCdQujpxouj4wqe60bHxY8v2kvwtfVwnL/CUZNvsdRjAJKcHfRAG+cjPMMScq2p9RIRKT8Lzf3oyHYTavLcg6xAksQgQsDBS1+WOI60JkN6R5rPz2+/EcSZvqcNMTLJRgUO9/IALjceL1I9aCg51BiRD7SWZmseVWP2XoGIMLO8WyiRws3fSjeKAMj24xkadPTm+8viwFfHwlZ+3LqWJa1VSTzjh2v9g== 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=k/Oh4S8RoMKO3zD+uy2c7MW79/v4N5JzTGiWH2cKENo=; b=nwAm9T2FXAtjG8oKd1kZnaOMnwo4i8rppoC4hOb0aXTQUUpszy+QpK+JjtSAlOKY/Jvupijaj+J81Zj/G/sWJslzr+2eWs/nNSoE0KMcuQr0/jO3fNRJy/mTO1Krxyc2rvV7tGc9zwyuWHjpXMZQPVlCXAFRnvbyyC4To8DUZes= Received: from MW4PR03CA0139.namprd03.prod.outlook.com (2603:10b6:303:8c::24) by BY5PR12MB4644.namprd12.prod.outlook.com (2603:10b6:a03:1f9::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5525.10; Wed, 10 Aug 2022 06:15:45 +0000 Received: from CO1NAM11FT007.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8c:cafe::bc) by MW4PR03CA0139.outlook.office365.com (2603:10b6:303:8c::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.20 via Frontend Transport; Wed, 10 Aug 2022 06:15: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 CO1NAM11FT007.mail.protection.outlook.com (10.13.174.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5525.11 via Frontend Transport; Wed, 10 Aug 2022 06:15: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; Wed, 10 Aug 2022 01:15:39 -0500 From: Santosh Shukla To: Paolo Bonzini CC: Sean Christopherson , Vitaly Kuznetsov , Jim Mattson , Joerg Roedel , Tom Lendacky , , , , Subject: [PATCHv3 5/8] KVM: SVM: Add VNMI support in inject_nmi Date: Wed, 10 Aug 2022 11:42:23 +0530 Message-ID: <20220810061226.1286-6-santosh.shukla@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220810061226.1286-1-santosh.shukla@amd.com> References: <20220810061226.1286-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: 3ab54a61-a281-4244-aa68-08da7a97c307 X-MS-TrafficTypeDiagnostic: BY5PR12MB4644:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7DPDe+vQfWnuhsb+bLt4/YGXzUZIUW2Lb9R4eN4XZ0bylLx4N/Ex4Zqi9JIhYHidURoXUmfugJFX+XDEN3ejJfK8QIjUv4mRlZ9c64FIGEeSufTxLf0c8nnmEYbcmkph2bn3PPEILdpmNPsDvc6CyVAiPQ7IA4DyS+ipK21E6YO/6VGPEK5uJOm0A2i/igAL0ffcInXpuOa7IQ7H0bsr3hZzuoHlRnPrpTnNdJvR0A0DEaCepJ+ZTLOL1OoXP4GYg1dBp2KrLerccvCiK92gL8TY+5CFVEYqSLoGd4DGzE1n9m2KMb/PVkqnYqOL+R0kwYfAV7Bjky8QVnBCaD4nqvDDYUhTqEy4FDT/dmvV8TjgkXOZS4XEOiIaOcCJ2cRWD1u3LPWM6c/zNMVOFvUSc3UFduk92X2l6g9qL/99E0LNVzBPz8I75Mbq3TOJPnHPvnzeJAOT5u4ERhrUXsYqZa7QA9cBslFHtjGYNA9UBfzPpSSN7sgNNbJvvyJMsVs43dC9rDUBwglaOmwOci0R0p0uCFADn8TgDkm36fxbPww6kr4CYpgIV5DCXKzszXWJSv+1VUkureoC6K6whmF3Ozd/iZ49UAamuYIyO4e+sTU3MVWhyskNWgINODd9CjGJ8WMRUiOZjGbBetUob6WeEIaadiHYM/nuBKU4Ku/pIfOnDF71W1HOyiLWt5Q/dc8DntnWptTgiaQcVH9SQ/DmOn0wx/MIqHWXQn4brDCjlFzLdMYpRg4C+JTu0bxNRMv52t1RryVI3G/ZGxa4FLMz+zmqmssB65o3cscfG+QOooggPcyxc+D9RJt4DEDj9e1pwWZqrD4IrF7ZlPVSF8NlZw== 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:(13230016)(4636009)(346002)(39860400002)(376002)(396003)(136003)(46966006)(36840700001)(40470700004)(478600001)(41300700001)(26005)(7696005)(6666004)(86362001)(356005)(81166007)(16526019)(2616005)(1076003)(426003)(336012)(186003)(47076005)(40480700001)(54906003)(82310400005)(40460700003)(36756003)(4326008)(8676002)(70586007)(70206006)(5660300002)(6916009)(316002)(8936002)(36860700001)(82740400003)(2906002)(44832011)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Aug 2022 06:15:45.4869 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3ab54a61-a281-4244-aa68-08da7a97c307 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: CO1NAM11FT007.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4644 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 --- v3: - Removed WARN_ON check. v2: - Added WARN_ON check for vnmi pending. - use `get_vnmi_vmcb` to get correct vmcb so to inject vnmi. arch/x86/kvm/svm/svm.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index e260e8cb0c81..8c4098b8a63e 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -3479,7 +3479,14 @@ static void pre_svm_run(struct kvm_vcpu *vcpu) static void svm_inject_nmi(struct kvm_vcpu *vcpu) { struct vcpu_svm *svm = to_svm(vcpu); + struct vmcb *vmcb = NULL; + if (is_vnmi_enabled(svm)) { + vmcb = get_vnmi_vmcb(svm); + vmcb->control.int_ctl |= V_NMI_PENDING; + ++vcpu->stat.nmi_injections; + return; + } svm->vmcb->control.event_inj = SVM_EVTINJ_VALID | SVM_EVTINJ_TYPE_NMI; if (svm->nmi_l1_to_l2) From patchwork Wed Aug 10 06:12:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Shukla, Santosh" X-Patchwork-Id: 12940267 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 18357C00140 for ; Wed, 10 Aug 2022 06:16:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230440AbiHJGQQ (ORCPT ); Wed, 10 Aug 2022 02:16:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231388AbiHJGQL (ORCPT ); Wed, 10 Aug 2022 02:16:11 -0400 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam07on2062.outbound.protection.outlook.com [40.107.212.62]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A91224BC7; Tue, 9 Aug 2022 23:16:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Revx+4IIqmWlZzmQqN6iOCn8MlISmiGWqmE0HGM7sBzxga67hbhkK1mSiyO1KZu6tH3msrFJixt8bRcCxfUccxZRHKTLGjv78FAtWYGmSioUZKwHy1siSgBIF5z+6L3k9iVTguAT9aqGyMGDvTisEC5JvfAiomH7g/fBzLJrceN2NUqBP3uxIxZK4VnUIkpoLnyo2P2gEK5POemW8KPDZOCNLPWadLGX034j/vfFVnuOrCEWUR3xoy97iNb/RLzh/bK+kZ0xdlfmrYTif4WVy8u/nsN2ZycJcfuC51GDYrQ2aTNGaYiAR8YrcrjKX+Qdt7KQh6q+1z6flgWLEEuvHw== 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=GR4F0hLb1RfTPlWxdUvliDgkDtRGi/1FubkI13uYPg8=; b=Ex72Tzx5vIsyULgZtbJe8LeaWornGCM/9mSgeXRJVltDgDaNWIMC3oS5yDpgwIoipDoDeHKvHV+rixIHplbgcqwvWVM9uf9ZSdaZyitEMrryfFsMJntGCghaoZkH7HFRnPt/fjpLddT6uoQr6kPPBK1wi6aL8bZGEryPCQcv+j7mc8qscARofKVTPX6MKUnbvA1kPzlsugB5rJ3Zw97PNnxag+uLAu9jpNlIhuM9NIncwrei+araRpvWBn8KiBLiAom0bIIvaWkerYUshPhqDfjUVMEdzVOazJtgQjgxutWOYt8UV7OoIOV7a/hrvGzNFIdoOpDA2w7rTSF6h5hTRA== 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=GR4F0hLb1RfTPlWxdUvliDgkDtRGi/1FubkI13uYPg8=; b=EW20Ok+Y+R9h4Gm7DeQu66I4LRBqqd9UYfiFtervUYMy7bcND/cp0dbrs7oBJwdKXRAvXYoNyIAUwMWRnUlhRr3TXZIFi3abtd8zvpYPCJlu53I2HI0VCeoPAXHSbs8AEpvFuK1+Ud4pPkXk7iQkOCTUbzRcs/l2i7b062uwp6M= Received: from MW4PR04CA0061.namprd04.prod.outlook.com (2603:10b6:303:6b::6) by BYAPR12MB3240.namprd12.prod.outlook.com (2603:10b6:a03:136::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.17; Wed, 10 Aug 2022 06:16:07 +0000 Received: from CO1NAM11FT029.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6b:cafe::9c) by MW4PR04CA0061.outlook.office365.com (2603:10b6:303:6b::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5482.14 via Frontend Transport; Wed, 10 Aug 2022 06:16:07 +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 CO1NAM11FT029.mail.protection.outlook.com (10.13.174.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5525.11 via Frontend Transport; Wed, 10 Aug 2022 06:16:07 +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; Wed, 10 Aug 2022 01:15:58 -0500 From: Santosh Shukla To: Paolo Bonzini CC: Sean Christopherson , Vitaly Kuznetsov , Jim Mattson , Joerg Roedel , Tom Lendacky , , , , Subject: [PATCHv3 6/8] KVM: nSVM: implement nested VNMI Date: Wed, 10 Aug 2022 11:42:24 +0530 Message-ID: <20220810061226.1286-7-santosh.shukla@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220810061226.1286-1-santosh.shukla@amd.com> References: <20220810061226.1286-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: 7c5e26a6-b800-48f8-4541-08da7a97cfeb X-MS-TrafficTypeDiagnostic: BYAPR12MB3240:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Pxln12FpWZ2NWV7qGIDXMYJYlbxT2kXgz6vRWsdBxQX6ZKs9QNM5dUhtuQZVIRb9+EBR2VSfOB3xGYJelBpCgKu8J6YGkYbb3mNYBeD3kfft7VN9Nhe3zeaAuFTGqaUPP6/hmQnPRkFkYpaQTO2sipp+2jXGUeIHMptQkM5BqfeXTFZKh6Ut8hqxv6I6sx0jvWmIXnERrlQLWM+CtVD9n1cSGigAUSJT3tsKNFSQpfUsM+V7uPn1Han5ta+7rsqKnAOwk5A71MomcpaTMY/0gM7TOTkwzgcUCU9WdCnaLu8y9vCl8DoQ+7RlvmdRoWyaoa6MmjMPPgs13BAS8Mr98rlWJWxto/tjxdzQhC3oSNrBfNe2b58h80KFwdSdoGTTfh7JwINaRj7FsmV+wXTHNpFYgT1+OYro9KhOacMoC46Ka6ngTcYbzEIeH14eRr+BT9pkPQDZGLlxEsAJX4nHM9xiw9uAjaVzputaxRLz8Xs54jvXZTOXwIyX1W9oSoQfVpua9Q4zX544856sCHUgffKrHQA8LfEJi5JLRfSD6UneP6vXR6685pCCZwyCWiZnlqe3z9FRZv3V9eUotLadilRAL0UU6uUAxrH45r+E07NCC7CsCb4kzH+CBGC/ZE7re5o808Z+5wGyS/C8WYzFR1NOP8DpfldZZWqTUmHzp1tsqgRAETb27uqhebyPxYUXKUUHaW94vx7RcYh8Z1CI//gCkLAvFqSGZAHarhqGJ2uNuFhAOiYO0iSdvVf4nWTMHz18Aq4UCVdcPv1pdI1pZW9A+DAoaDWBpIJO2m5yBeEL1zAkyUCUh75jJw6/qyuh6ft/F0biWkXlxBXuUZ7NQg== 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:(13230016)(4636009)(136003)(396003)(376002)(39860400002)(346002)(40470700004)(46966006)(36840700001)(6916009)(316002)(5660300002)(70206006)(40460700003)(4326008)(54906003)(82310400005)(8676002)(86362001)(40480700001)(36756003)(478600001)(8936002)(44832011)(70586007)(36860700001)(2906002)(83380400001)(82740400003)(81166007)(356005)(47076005)(41300700001)(7696005)(6666004)(426003)(2616005)(186003)(1076003)(16526019)(26005)(336012)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Aug 2022 06:16:07.0955 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7c5e26a6-b800-48f8-4541-08da7a97cfeb 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: CO1NAM11FT029.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB3240 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org In order to support nested VNMI requires saving and restoring the VNMI bits during nested entry and exit. In case of L1 and L2 both using VNMI- Copy VNMI bits from vmcb12 to vmcb02 during entry and vice-versa during exit. And in case of L1 uses VNMI and L2 doesn't- Copy VNMI bits from vmcb01 to vmcb02 during entry and vice-versa during exit. Tested with the KVM-unit-test and Nested Guest scenario. Signed-off-by: Santosh Shukla --- v3: - Added code to save and restore VNMI bit for L1 using vnmi and L2 doesn't for the entry and exit case. v2: - Save the V_NMI_PENDING/MASK state in vmcb12 on vmexit. - Tested nested environment - L1 injecting vnmi to L2. - Tested vnmi in kvm-unit-test. arch/x86/kvm/svm/nested.c | 27 +++++++++++++++++++++++++++ arch/x86/kvm/svm/svm.c | 5 +++++ arch/x86/kvm/svm/svm.h | 6 ++++++ 3 files changed, 38 insertions(+) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index 76dcc8a3e849..3d986ec83147 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -662,6 +662,11 @@ 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 | V_NMI_MASK); + else + int_ctl_vmcb01_bits |= (V_NMI_PENDING | V_NMI_ENABLE | V_NMI_MASK); + /* 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; @@ -1010,6 +1015,28 @@ int nested_svm_vmexit(struct vcpu_svm *svm) vmcb12->control.event_inj = svm->nested.ctl.event_inj; vmcb12->control.event_inj_err = svm->nested.ctl.event_inj_err; + if (nested_vnmi_enabled(svm)) { + if (vmcb02->control.int_ctl & V_NMI_MASK) + vmcb12->control.int_ctl |= V_NMI_MASK; + else + vmcb12->control.int_ctl &= ~V_NMI_MASK; + + if (vmcb02->control.int_ctl & V_NMI_PENDING) + vmcb12->control.int_ctl |= V_NMI_PENDING; + else + vmcb12->control.int_ctl &= ~V_NMI_PENDING; + } else { + if (vmcb02->control.int_ctl & V_NMI_MASK) + vmcb01->control.int_ctl |= V_NMI_MASK; + else + vmcb01->control.int_ctl &= ~V_NMI_MASK; + + if (vmcb02->control.int_ctl & V_NMI_PENDING) + vmcb01->control.int_ctl |= V_NMI_PENDING; + else + vmcb01->control.int_ctl &= ~V_NMI_PENDING; + } + if (!kvm_pause_in_guest(vcpu->kvm)) { vmcb01->control.pause_filter_count = vmcb02->control.pause_filter_count; vmcb_mark_dirty(vmcb01, VMCB_INTERCEPTS); diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 8c4098b8a63e..c9636e033782 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4217,6 +4217,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. */ @@ -4967,6 +4969,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 7857a89d0ec8..4d6245ef5b6c 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -253,6 +253,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; @@ -533,6 +534,11 @@ static inline bool is_x2apic_msrpm_offset(u32 offset) (msr < (APIC_BASE_MSR + 0x100)); } +static inline bool nested_vnmi_enabled(struct vcpu_svm *svm) +{ + return svm->vnmi_enabled && (svm->nested.ctl.int_ctl & V_NMI_ENABLE); +} + static inline struct vmcb *get_vnmi_vmcb(struct vcpu_svm *svm) { if (!vnmi) From patchwork Wed Aug 10 06:12:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Shukla, Santosh" X-Patchwork-Id: 12940268 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 679E1C00140 for ; Wed, 10 Aug 2022 06:17:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231134AbiHJGRT (ORCPT ); Wed, 10 Aug 2022 02:17:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231384AbiHJGRO (ORCPT ); Wed, 10 Aug 2022 02:17:14 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2080.outbound.protection.outlook.com [40.107.244.80]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E60953A4A6; Tue, 9 Aug 2022 23:17:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MJAz8mE9wfkJg1TE8O7WSeixLNj376XKIxzYDcx+H24dVXRBk/AMzLyBS1WehIUzHuUt64TNXGCRLLx623HRINFr1tTT5hbnwURtp1zk5EhrfiGe8so6kgjnkqp0Jf+OadKA2mcPI7rrDUueZCT80svevoEHVgd80F9ZNTZmwB3OL6G+RjFWz2lwcnz2ANEisgpOkd4bXuecNu1tA5w7tXPVlvejWHVpEJMfgZnTLyTLkPMfiaK/ueso6tQASgi3UptXnBcX/L/p5qNJif3yjATRxJTTNR2g0al1zxMz8AccksWj29yEiNHdBDFVihII9dXSDRVd2r3z/nlYOjVXYg== 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=av/DJE8D6kP2/Aub97o2cS1hU4kJbUl90ppjiJRXwhk=; b=R3fC4UiYpAUEtyMTCPooAkV581ehaa9zRdNJLoPZoSXvIhzrZxg4wJFzaFoBBt22VD91choyaMRErB6xwgnVep1Wsxut/f0GdDO0O7sriOr8yUVVYyDmYJg56pE4jKs3K5WX+/vT8Kyean0poUH6N5xxwjR9xGjrWjTknn8T+Yp6IxVYctl7otnYeVmQypO+kFDDXc+hYTicZRV9u0nkEjH1K/EWnKz1Bf/DOPi7EnTy6uYjU2IsdVA1GdL077X8k3X76NvjzOVhc05QyY7/nhZeJfRjYzCRH/3c6Bkjcl4LHOYKWFxqyjlC9rnVhth3eigDrq3oy9pTGJ2kHkHlLg== 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=av/DJE8D6kP2/Aub97o2cS1hU4kJbUl90ppjiJRXwhk=; b=kQSUxUobI4+3jNHPxVbvNKe0M+IU86kgEsG2fu8rqy0LRMQKmZG6ftclymz8vh3Tw0n4uWt/AkeUVEv2Rra6mo/OmW7oAKxMyfLGqA/ckPdZE1AlZm/DP4p1XnDNlszzTMHcmXIfacVsRmRvD5Ue9jVeI1F6v6fqffgTNve+h40= Received: from BN0PR04CA0024.namprd04.prod.outlook.com (2603:10b6:408:ee::29) by PH8PR12MB6794.namprd12.prod.outlook.com (2603:10b6:510:1c5::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5525.10; Wed, 10 Aug 2022 06:17:11 +0000 Received: from BN8NAM11FT024.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ee:cafe::cf) by BN0PR04CA0024.outlook.office365.com (2603:10b6:408:ee::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.16 via Frontend Transport; Wed, 10 Aug 2022 06:17: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 BN8NAM11FT024.mail.protection.outlook.com (10.13.177.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5525.11 via Frontend Transport; Wed, 10 Aug 2022 06:17: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; Wed, 10 Aug 2022 01:17:02 -0500 From: Santosh Shukla To: Paolo Bonzini CC: Sean Christopherson , Vitaly Kuznetsov , Jim Mattson , Joerg Roedel , Tom Lendacky , , , , Subject: [PATCHv3 7/8] KVM: nSVM: emulate VMEXIT_INVALID case for nested VNMI Date: Wed, 10 Aug 2022 11:42:25 +0530 Message-ID: <20220810061226.1286-8-santosh.shukla@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220810061226.1286-1-santosh.shukla@amd.com> References: <20220810061226.1286-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: 0275ab3e-de7d-45df-4991-08da7a97f5c4 X-MS-TrafficTypeDiagnostic: PH8PR12MB6794:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: crEV3+RaY+CJ5zT+u+hxRlqhl3KPSgdS4daO736sBN2fxHlvWm0mqnVz59e3tFRflMoCKVE9s0D8GZDuq6n4PEcZV9ybrPH9qkzo5zplUvRTJncFghopsJdKu9ctup2ERZOOh42Xrj/0CFRf/Tf5K0YhM72cGIbvtMPxUWZx410cCgI2Ona3bKMjgczs+KUjXj9tV2QseIYpchLC0lvzoy+JVcBiRXICv79COEdXw+HzM3Trd7piEM6fx4uwcQC9xfns1S+ShkfuTDXrtD2GVSf4Rxx6IhAOfq7IKKRY86q/SdjzAjvTz7ndwjBUfRdnNb9oXjCts94VZ8lXbqnsuwa/OcXC71+DQuPKJ3BvkOBQBaVCLjd7mPZ84kUHxRP+hRGIiQSe2QadOZt9q+zv39TXP/1h136J776L1Ys+zElFUE8kn5qNPfKRjHMlTo3eEP2CikI/VaeIEyD7Hf5Ln/QgvB5Zjn6RWzN70zlzhdx5WSKLK1/9WxTvl/FEwe8zav4Yivo9VLlg4lhoOL9YR6quFhGf7lPm5nC0SMXYR0AYdXtfYym1KsYVU54+txqyrh9GopKDACrvyc2X/mty35OnwsnYjURolH4vEeRiLqaPir4I6m3afkl07wMTTgQKUobHmiG+SNsgFr9jeJ4OtiRAA3Jdt6JRzxOk1cvKVIeDxB8iUsvBmdkYaivv7Nkj1J3Ib7Ba3YTui5vPxuos4L9i0de8xW5Q1kLIliQpSsZ8NZAVBYHYkbIiGoVucfrOVcf97GZ1b4cb40f3MUARGrlZ+9YDOWkzzmDN6FnTxohfO5Pv8xaUYbEf+/N2OfM3/hb/s4fDBbVmHXkRjl09fA== 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:(13230016)(4636009)(39860400002)(376002)(136003)(346002)(396003)(46966006)(40470700004)(36840700001)(426003)(83380400001)(81166007)(7696005)(478600001)(47076005)(6666004)(82740400003)(8936002)(26005)(2906002)(186003)(16526019)(5660300002)(4744005)(40460700003)(336012)(41300700001)(1076003)(316002)(2616005)(40480700001)(44832011)(36756003)(82310400005)(54906003)(36860700001)(6916009)(356005)(70586007)(70206006)(86362001)(4326008)(8676002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Aug 2022 06:17:10.7653 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0275ab3e-de7d-45df-4991-08da7a97f5c4 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: BN8NAM11FT024.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB6794 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org If NMI virtualization enabled and NMI_INTERCEPT is unset then next vm entry will exit with #INVALID exit reason. In order to emulate above (VMEXIT(#INVALID)) scenario for nested environment, extending check for V_NMI_ENABLE, NMI_INTERCEPT bit in func __nested_vmcb_check_controls. Signed-off-by: Santosh Shukla --- arch/x86/kvm/svm/nested.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index 3d986ec83147..9d031fadcd67 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -296,6 +296,11 @@ static bool __nested_vmcb_check_controls(struct kvm_vcpu *vcpu, if (CC(!nested_svm_check_tlb_ctl(vcpu, control->tlb_ctl))) return false; + if (CC((control->int_ctl & V_NMI_ENABLE) && + !vmcb12_is_intercept(control, INTERCEPT_NMI))) { + return false; + } + return true; } From patchwork Wed Aug 10 06:12:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Shukla, Santosh" X-Patchwork-Id: 12940269 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 B6700C00140 for ; Wed, 10 Aug 2022 06:18:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230163AbiHJGSH (ORCPT ); Wed, 10 Aug 2022 02:18:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229589AbiHJGSF (ORCPT ); Wed, 10 Aug 2022 02:18:05 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2083.outbound.protection.outlook.com [40.107.220.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97BD065577; Tue, 9 Aug 2022 23:18:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oXidEQYdLN9qCJcJngK8bIeKpkNMDK0BquibT0DkJi58kHw75FREBhmywgrs1lCaQWYi+kQPbsMjz1ms+PJP0NPcT5/90d7qmhD8bXnlPFuBuAHLQpUZr7qDX84DKL07WNIPq6NGGEy+cWRq8TRaEma/JCuw/zBfQ7md3qhEP8DIoz8sI+JkEjhjGo0s3JdATUow8bgngtKVTNCR3TnddI5Pz4/mmd66YVhlw94GGx+34W339S75g7jLEZuBLPdJxt8VakLNACnxZNsvJ9uxiMzmsrbWAH25VMOEeRwcjhBEfehY3G9Fc4N52CIDkJCadmbypuBCm5x1hP8s2wbEUQ== 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=dc4x+2O5Nq8AE+1JxRdXG6tPPbs3D0HGYoKEgd/YFlo=; b=ON75FYxJ8kk+0LH/SBe2/oIBk/D8vndJNp9wFXV7yU8Vb6xcwtmbaZxxWyUv1t+g1n6GqzkNaR7pScym8M3CrRstWLB8FuLXkHLDC+41KoyFZB4ie+6nPS3UEcx+YrzJUap50KIsIRNbR4MDDjIwKyHxEDUwC+y50KounCMbgOOIGaHdzzZDqRBTDKwGcHUhJuOwdSNViAvCKQOf1um423PIgigtworKkMIv7z3wJ8kVsjBFH7F9zS1L9jjUTOuCq4ZvuZ9e+iu+siGRi1ZR5l7ZpGxJOU4VgwxZtCLkR69DWNGOZMrwEb1fCZZPUuktTLwM6bnK7d+CRQfx4e06ow== 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=dc4x+2O5Nq8AE+1JxRdXG6tPPbs3D0HGYoKEgd/YFlo=; b=tceevALirQ5cDJttR4gAHDbpRfUHLegyX74dkt+LCYpkm+dMVAFYqSsre7A5DtCe3rS319ihJ/zCp0GEa84eSLI8DfjXGqvqdGWFv43jZdejoFi7TgNN84PSl5hDcPokiG6KQodEW7ae5JUzpl5HmcxipQ7NPY/ADB99EHkiQnc= Received: from BN0PR02CA0042.namprd02.prod.outlook.com (2603:10b6:408:e5::17) by DM6PR12MB2908.namprd12.prod.outlook.com (2603:10b6:5:185::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.16; Wed, 10 Aug 2022 06:18:02 +0000 Received: from BN8NAM11FT037.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e5:cafe::6d) by BN0PR02CA0042.outlook.office365.com (2603:10b6:408:e5::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.20 via Frontend Transport; Wed, 10 Aug 2022 06:18: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 BN8NAM11FT037.mail.protection.outlook.com (10.13.177.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5525.11 via Frontend Transport; Wed, 10 Aug 2022 06:18:02 +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; Wed, 10 Aug 2022 01:17:22 -0500 From: Santosh Shukla To: Paolo Bonzini CC: Sean Christopherson , Vitaly Kuznetsov , Jim Mattson , Joerg Roedel , Tom Lendacky , , , , Subject: [PATCHv3 8/8] KVM: SVM: Enable VNMI feature Date: Wed, 10 Aug 2022 11:42:26 +0530 Message-ID: <20220810061226.1286-9-santosh.shukla@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220810061226.1286-1-santosh.shukla@amd.com> References: <20220810061226.1286-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: 13141c24-945f-4ce1-46b7-08da7a98145c X-MS-TrafficTypeDiagnostic: DM6PR12MB2908:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cBAsx7xJkVR6Js6gt1M8eF4VNM1rVmz9NCZfDI3Cz7CG0eXABt1Y7eKIcObdrWbrUAeN3Dkjm+6smIEMXS/0oKNOF6QU4TJ5Q2otnkOF/nHwvs9/+hZwJwrzE6Qf9G9GqKvHZH4QQR3UkV0EU6Xskwe2+rw/uP8lSRI58zyBpIe8Eq7HjhXs2HM1dRzZrGC9jxcBm2M+Uqg87IZFq0Fh81XOZZTMMSCyTWOSpiP/w7TCYkHS/+XHK/i2RjCDYtXI0hG7Es3lm0Al2+NiFkAU3jaUPXyH341Jk8k3QZnczMvo6JY5RNykVXEYVAtvQvlRTH61EeOPmeyQNgC+UJju6YdUfkkrDQBbZpJwQtAnaAbWsOnV29rpEwBGrxV2gtJFHzzlErey7z9rhK8nFMI8414L+gaU8OVBQNLR66y8Jb/1kixgGu9Ln7p61WyTquCZUjr2mny8NBP/5WyPVRYbfmwucE6rBUDrAg5UaEWJoSMsB6Up/jeVp8G3bAiWyD6Kw0h2f59VCVLw+UcejE1DD66NkngG9A4g+knb6lW2JVIIod/Pu11Q5B1xAIA3NNGf5daHZspvOOJO+w9UJj3VAgoUXYLKuacur8XmMAeatMsKqLe9/w2LY5vgISeOYuvLZWGNlsjgcSARqzFo+bwZFpjZrPDX9vPol9SgZpotHLeDgR5GQJFOciPVVX3iEt9y8xDs2qgsO/QgltTEI9tbJ7BtJJqSYmglpLxIqdXCMlrFpQJKH8Kse3pDr8yu++Us2dCkwhcwish6hVvWfrT1Ka8cG3fy25oILFSCIbkal0FwL5RStz7sqKIIjsnIPOTC9ZgWaPY/pidnlAEKCCY0tw== 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:(13230016)(4636009)(136003)(376002)(396003)(346002)(39860400002)(46966006)(36840700001)(40470700004)(2906002)(36860700001)(82310400005)(2616005)(40480700001)(81166007)(356005)(40460700003)(82740400003)(26005)(8676002)(41300700001)(54906003)(336012)(5660300002)(6916009)(8936002)(44832011)(4744005)(4326008)(70586007)(70206006)(316002)(186003)(47076005)(478600001)(426003)(1076003)(16526019)(7696005)(86362001)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Aug 2022 06:18:02.0930 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 13141c24-945f-4ce1-46b7-08da7a98145c 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: BN8NAM11FT037.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB2908 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 c9636e033782..eefb4d5428c4 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -1309,6 +1309,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);