Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2808508rwb; Thu, 17 Nov 2022 16:48:07 -0800 (PST) X-Google-Smtp-Source: AA0mqf5382h29tDjoZ+0JWMTaDB4BiHQ/RkQxObfhL8JdrBlEYhC8asWHNpCe966w+w6TLZSgnZx X-Received: by 2002:a17:906:1695:b0:7aa:493b:679 with SMTP id s21-20020a170906169500b007aa493b0679mr4216793ejd.320.1668732487651; Thu, 17 Nov 2022 16:48:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1668732487; cv=pass; d=google.com; s=arc-20160816; b=jTwRdAt47DilXe9nipY0Sdz8L6WbE+NeKiKpgDrwzcgXckXAk41rxbHTjsE72bTEv+ kFhjlZ8M7ODejeyCyxkYU2yZDKhrDMWbXRovIAsogn/iJALeRiHkn8/a1w4+JpqxavRy 7JjkGvkqNTO7r0aFJHIWKrlAaWa8jTKfPOOuGk8t94HF4mdJQiWvcWfWK/faaHlrLW8Z wAMdSNVtGLVfUWRpPWzgtUY47uKjoHezaWDQWO/ICliuzIaM/ECGM3r+ZkxHIQNNHupl IZhNIwE3AfaSLzJZ5h+nRYkGslga+JCrAGW0M8DDVFFS9gWShxl2yqvuo1pQVosa1GjI itXg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :dlp-reaction:dlp-version:dlp-product:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature; bh=1iYbZpaUTCGfGd9P05C8Irxqym+0RtC6CWVKkletdhU=; b=WtVfxwD/YP3trEQ0JpajC/0SEDI6Xz7ux376zXvM0/BYSb5DbW30A8JSh79P1JUIBc N3I9h8DiGnz/QlRshHQEgOk9LeQ5us/66YCvvho5CBho6u3xDnFcWOvMPFCZLcbn8k8j vaM7C8Jn5vOeYI4xxKPYVghdGyP9AIc/bHxCetM/GkT4qeQ3GTxV7bLihhzHicvBHTEz lEnBt+wvPEpOItYN7F4SKXv9/vSuXxOXadv6gBRRmmo6D0oRcPx1VhpisIH6niPSkiSr llpSQHX04e8yWdI3sgkmjNQUkybXlsTIvasr3r4KT6NeGsYPgFAW3tolVU6uEEMOgCy3 DLYg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=oHVoQNty; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sg39-20020a170907a42700b00780a240cfd7si1958623ejc.493.2022.11.17.16.47.40; Thu, 17 Nov 2022 16:48:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=oHVoQNty; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240484AbiKRAGL (ORCPT + 91 others); Thu, 17 Nov 2022 19:06:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240291AbiKRAGG (ORCPT ); Thu, 17 Nov 2022 19:06:06 -0500 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4564D94; Thu, 17 Nov 2022 16:06:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668729964; x=1700265964; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=LO+JMyw3swSKtZInxFM7EbXUsU0yBHkMaQviRrFTZyQ=; b=oHVoQNtyQ16JtlsqoV6zafNdXvU6Olwq3taPOJeJeyPoRUSJFBcRB4TU iVen77lqQXOlZqcX32jF56pywD3kFcgMDpt5vhIm5dghboedGdgZHTWqa SG154C7bLRQlK1GyO5Jn3VDy4QzrE/ubxnoVkmdyZX5m/Z+Zcdz+1xvIy ddprCV4PA1VXl8R1TdVwGw+hEvups26ViiXtH4D0QcWfCtc7PphGQPM9q CXWx18o+Q6SR+PlUBjbP/sUCON1dY8cI6RJzukRbJvBYKtFo9qvH3IoPU SNUkpzkmuIivJ3siFGXDc6OXFeU8wIzrNVJfY7UlmMJODGlhqo5Ykg0e0 Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10534"; a="293401248" X-IronPort-AV: E=Sophos;i="5.96,172,1665471600"; d="scan'208";a="293401248" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2022 16:06:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10534"; a="745760309" X-IronPort-AV: E=Sophos;i="5.96,172,1665471600"; d="scan'208";a="745760309" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by fmsmga002.fm.intel.com with ESMTP; 17 Nov 2022 16:06:04 -0800 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 17 Nov 2022 16:06:03 -0800 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31 via Frontend Transport; Thu, 17 Nov 2022 16:06:03 -0800 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.168) by edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2375.31; Thu, 17 Nov 2022 16:06:03 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OdWJ/eLdcleWaYE9ibu/BRZ70vjEoD7EhqiczOcAsmlhPkq+2AUNEl+p22Dz8RtORErjBvt/PrRxTwC3i0IdWysdZ97n7/aZDXjcQ7qDnX5lm8dPWbOtN+AFKfUlvxPtUJXtd7/l9suf5XJ0ha1i2f7DJ+Ps5N9dNDr43gbuzNl4w1TqQLRgV8Q2H44nqQ+cEjDoPj/7Hc0nKTLVOLlMi9yyXmuxjhluGwKP9DwVTj1fu/GwlfzKtZgQjSL9hDqdYb0t8G++HuM/gbLd0izMEYXy0OxZoX5q8jjtAvmBGsFz1ocfy7LgjE5et1cW4yW+3jUvACodIcqHK5eMkBLl/A== 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=1iYbZpaUTCGfGd9P05C8Irxqym+0RtC6CWVKkletdhU=; b=JpYX9b9VH14c6aNWI72Mu2a6lUDFFTIEeUVFxdBJfvi7kKEhaRHnJCQtR/5Prp1ThchAhW/LEbXmRHGtbmK6O/kQLtgxwFVTzmRza1MxN25UxW+wEHA5P6MTbE/5r7eu5nvces2uDQyjsoCav46ejIsejE6B5cSqvlac9+xFgNleG9/uWvMam31r/1D8wYMb5I1QQokWRb/ID/I+ExqMelXBUkbhxv1Ld62fvqaLwXwRGVeLXr6SD/PCEQ+i88tmI6reNPAjLBIPrishqhdVvUuGCuy90FWhBzXYaQlCLBB3z/uBhZetbHHZCb3zLfJ06NbFFHdTUTrh9TxVOyuW0w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from BN6PR1101MB2161.namprd11.prod.outlook.com (2603:10b6:405:52::15) by SA2PR11MB5164.namprd11.prod.outlook.com (2603:10b6:806:f9::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.20; Fri, 18 Nov 2022 00:05:53 +0000 Received: from BN6PR1101MB2161.namprd11.prod.outlook.com ([fe80::40a1:5197:e1df:bb6c]) by BN6PR1101MB2161.namprd11.prod.outlook.com ([fe80::40a1:5197:e1df:bb6c%11]) with mapi id 15.20.5813.020; Fri, 18 Nov 2022 00:05:53 +0000 From: "Li, Xin3" To: "Christopherson,, Sean" CC: Peter Zijlstra , Paolo Bonzini , "linux-kernel@vger.kernel.org" , "x86@kernel.org" , "kvm@vger.kernel.org" , "tglx@linutronix.de" , "mingo@redhat.com" , "bp@alien8.de" , "dave.hansen@linux.intel.com" , "hpa@zytor.com" , "Tian, Kevin" Subject: RE: [RESEND PATCH 5/6] KVM: x86/VMX: add kvm_vmx_reinject_nmi_irq() for NMI/IRQ reinjection Thread-Topic: [RESEND PATCH 5/6] KVM: x86/VMX: add kvm_vmx_reinject_nmi_irq() for NMI/IRQ reinjection Thread-Index: AQHY9M9YytlyKV7ob0GK/oJbeBhPY6433PwAgACmfxCAAO8aAIAAL0qAgAAENoCAAAgUAIAAGnuAgAA1qHCAACERAIADuBAAgABQYICAAXpoEIAAGnIAgAK/reCAANL/AIAAhVlg Date: Fri, 18 Nov 2022 00:05:53 +0000 Message-ID: References: <6fd26a70-3774-6ae7-73ea-4653aee106f0@redhat.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.6.500.17 dlp-reaction: no-action authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: BN6PR1101MB2161:EE_|SA2PR11MB5164:EE_ x-ms-office365-filtering-correlation-id: 2374ee2e-c3b0-469a-fd68-08dac8f8a8d4 x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: lZLpAph64d4y0M19hSQyqKB5M2PC9EaD6HFWn0xHa4DkFQ9U/RsjxFMi/Bs42HAlbGUXcmWgxnZ9qca1Twu7BdpWP9AGFSwPKm9JGFhxYlHfr3hXFhDBJrLYgi7QWa+SaA8KQM3qvOeYlKJhqBklxBxCsr6jgogtjIaUEtkwkDvIWKenUoF8jS9ZICsKz12V7CiKyV3jq9lX8rDcDeFAiM5CLLyroy2B9L1adJGVuy2V2NO1VkZjUYmTB2ue31dqFaOTW+r88Lbw/S87282eiTD0q83ATU6W6cu62YyjNDl+SLfKX68dfWMAYg7RfsnAEB+eV2+KgxiZ+PnkGjguPtdNP74lZ4UgIo0VBmVjjhL3zt6jHZ/cW9gQ5OcxT4q7222lQVu/RzpAfmjPCV5yQV1ErV1vBATfnXadhpjW2IGUaeWcWroz++mFj29qYr8xAyjOvJoDnCjlUzn2U6Sto9/cUC0hbwc+RR3OLpEpwGDkTqfvy1JSYtrJkrSMX1CsYSHs8ak7X4IAaNl1k+5Qr+HkR6zSacl5LqcrBWgF/PvFScqL5VHrp4yKESLncpPTwvUrkb5lw35wXTa4kVSQzqgmJkfBtqIXJ3J3oNqHnc56/JXcJyUt/dg1hS7rdJ/3cP3PhLWAN7CyzsfeXhlpnGzunN+Jy3Jtk04I21Oo/VNVMubm5FIzL0QjfN+3yCDZl0anIR4VvyK4RKuBsjBBGA== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN6PR1101MB2161.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(39860400002)(396003)(136003)(346002)(366004)(376002)(451199015)(7416002)(33656002)(5660300002)(186003)(6916009)(7696005)(6506007)(54906003)(316002)(26005)(41300700001)(76116006)(52536014)(9686003)(8676002)(66476007)(4326008)(64756008)(8936002)(66556008)(66446008)(66946007)(122000001)(38100700002)(38070700005)(86362001)(82960400001)(2906002)(83380400001)(55016003)(71200400001)(66899015)(478600001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?aB3THmhxR+k9//7OJ/fg3wFgDv6deCId7u3GJ59TcS8kue5Bd+gM1GY1b578?= =?us-ascii?Q?utIpto11FhAArTEdbyUT2B28fG/zIucdzLpJAKhdoeA+yyE019PyHO9hdufO?= =?us-ascii?Q?Va80osTR8cJo3+rp5F0i7F9uAtbIuGr33pZsDGbLBVNVayXgZEUJLaz55WjD?= =?us-ascii?Q?Xl/l3Du1MlRZv+s22HmkWLJN0vHvK/6BJeEH0jIQawYcX/octoFg+PcOUY8P?= =?us-ascii?Q?9DzBCIAQ/rcw1OilwHnP6/nmGgRUPT7wc8cw6289plO/FcaCwy0xf5ZGHlfD?= =?us-ascii?Q?T9iJ7Ceqb1ivA+hDBtb4zT3Ym7rUvlA2Gx/5mcxheJPlP7qaedQ59DZQhU9E?= =?us-ascii?Q?L5zUSFriT+/clgJLMd25Hx/l7EW0H+RnAAF6NTe56OAriqs1BEOFKJtoxFKT?= =?us-ascii?Q?Q6MD+VJG/cx0fidZGsKCBWfQeFnPGYxx7oRJResdh27oe2K2ch7j47Ax41Xm?= =?us-ascii?Q?8NxjFPOgGUspgsp1EZ+hfuI4jg4RPissQ0XMuXDW//x3e/nOdYlb6IHMpduf?= =?us-ascii?Q?g8f6fmkhUnUTq01dCABzA98ZwTczfOjvvjKJmrHkRUFeJph9weJMqbZ0Yu4r?= =?us-ascii?Q?kFYS7r88Roh9ccOL+qSInrZwpFrtxYHcwmZJSDEYz5Q7bnf9hWo1SSjf0CvY?= =?us-ascii?Q?GZYYFv5Nkc2ufud/W2nVaRsCobAQ7h/NsBKJB+8DG9FpdQdsXcuUKGwCbxoo?= =?us-ascii?Q?JWZaMu9N1EoqKXvFmpQvN9uV3ltzxrWRxBCDvU1W0OnJs7DwsEdMgd+zGrfF?= =?us-ascii?Q?6UN2IN55JXeidC6BP88cekKDoCFrqWdjkiEwTMx7SNA2X12tpZXBLawYCVZ3?= =?us-ascii?Q?cKMwBKsPa9wihXLKTr45E10pkSW+O1Z7eM3gg6bBGWdozQLCr7+zn6evz9o2?= =?us-ascii?Q?QHfg/+hWhYqaqXHcypth/MeEa+2hk5SLLm45dNLvU/jpRv0jh9/Devs6D+I6?= =?us-ascii?Q?EC2oxIV5YgvB7S00DmKViV/ssQTFbqSvchMslitPPIqvrIOcOniXHeJJo1fh?= =?us-ascii?Q?HzrNvUkuM63SBYhixzsPUBnikcs6+I2uF7IX53EGO0x9NrEGdeMvaW97yE60?= =?us-ascii?Q?7ssLWumsuVOMIEv6ypt1SwdnshwgJQQ8RYI2PwFVPQdsV6ZH/3INhf0kTnxf?= =?us-ascii?Q?dkm98BnWZT8q+nsiWwJt6jEi1MQm3SVZgUquUVGY46XqSTHcErqXrJR6mmXA?= =?us-ascii?Q?CM7QL85ufKn7ZYfsjJP0fpHJrNHsUIquDT1NtoKRMVnX4AJDCY5L4VKK7eJc?= =?us-ascii?Q?KKdx9rr6mk8+9t21Nmh4bcN1nH21+nIfi2VpdzAvLWA5nyo0+sUkvRAe68Ii?= =?us-ascii?Q?eTMSBdrB1ai9y+1jL1XwRumxxzY+NK+RgtYDB7mMcLLDGWaIJG6L1G3nrok2?= =?us-ascii?Q?P7+wg8C0aH6v7P7yogaG1bHgo1LbgvGUglq3CjS4xWEqbfL2d27K/waGfd7K?= =?us-ascii?Q?m/rV7ifNFZnmJFMZ/OPcZ3whkm3TjeuK5xDkTr12QGgQOrOTfKD8AmvMEDvH?= =?us-ascii?Q?ZQde8tDCV9v5uZzpWCovafLP3hngAgS05FLJCwvsiyHZnU/JlWNQ80dg97CR?= =?us-ascii?Q?R50czSiB7JGWB5nDEeo=3D?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BN6PR1101MB2161.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2374ee2e-c3b0-469a-fd68-08dac8f8a8d4 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Nov 2022 00:05:53.5853 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: AW3Odj5t1Gbjf5kG0960FKxqWjAWjcJ24qYcdRmcFujbhBxct8NWQTvbYJwQMvRgxQqZLstmkVXs7GemeweZOw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR11MB5164 X-OriginatorOrg: intel.com X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > > > > > > > But what about NMIs, afaict this is all horribly broken for N= MIs. > > > > > > > So the whole VMX thing latches the NMI (which stops NMI > > > > > > > recursion), right? > > > > > > > > > > > > > > But then you drop out of noinstr code, which means any > > > > > > > random exception can happen (kprobes #BP, hw_breakpoint #DB, > > > > > > > or even #PF due to random nonsense like *SAN). This > > > > > > > exception will do IRET and clear the NMI latch, all before > > > > > > > you get to run any of the NMI code. > > > > > > > > > > > > What you said here implies that we have this problem in the exi= sting > code. > > > > > > Because a fake iret stack is created to call the NMI handler > > > > > > in the IDT NMI descriptor, which lastly executes the IRET instr= uction. > > > > > > > > > > I can't follow; of course the IDT handler terminates with IRET, i= t has to > no? > > > > > > > > > > And yes, the current code appears to suffer the same defect. >=20 > That defect isn't going to be fixed simply by changing how KVM forwards N= MIs > though. IIUC, _everything_ between VM-Exit and the invocation of the NMI > handler needs to be noinstr. On VM-Exit due to NMI, NMIs are blocked. I= f a > #BP/#DB/#PF occurs before KVM gets to kvm_x86_handle_exit_irqoff(), the > subsequent IRET will unblock NMIs before the original NMI is serviced, i.= e. a > second NMI could come in at anytime regardless of how KVM forwards the NM= I > to the kernel. >=20 > Is there any way to solve this without tagging everything noinstr? There= is a > metric shit ton of code between VM-Exit and the handling of NMIs, and muc= h > of that code is common helpers. It might be possible to hoist NMI handle= r > much earlier, though we'd need to do a super thorough audit to ensure all > necessary host state is restored. As NMI is the only vector with this potential issue, it sounds a good idea to only promote its handling. > > > > With FRED, ERETS/ERETU replace IRET, and use bit 28 of the popped > > > > CS field to control whether to unblock NMI. If bit 28 of the field > > > > (above the selector) is 1, ERETS/ERETU unblocks NMIs. >=20 > Side topic, there's a bug in the ISE docs. Section "9.4.2 NMI Blocking" = states > that bit 16 holds the "unblock NMI" magic, which I'm guessing is a holdov= er > from an earlier revision of FRED. Good catch, the latest 3.0 draft spec changed it to bit 28, but section 9.4= .2 didn't get a proper update. >=20 > As specified in Section 6.1.3 and Section 6.2.3, ERETS and ERETU each > unblocks NMIs > if bit 16 of the popped CS field is 1. The following items detail how t= his > behavior may be > changed in VMX non-root operation, depending on the settings of certain= VM- > execution > controls: >=20 > > > Yes, I know that. It is one of the many improvements FRED brings. > > > Ideally the IBT WAIT-FOR-ENDBR state also gets squirreled away in > > > the hardware exception frame, but that's still up in the air I > > > believe :/ > > > > > > Anyway.. given there is interrupt priority and NMI is pretty much on > > > top of everything else the reinject crap *should* run NMI first. > > > That way NMI runs with the latch disabled and whatever other pending > interrupts will run later. > > > > > > But that all is still broken because afaict the current code also > > > leaves noinstr -- and once you leave noinstr (or use a static_key, > > > static_call or anything else that > > > *can* change at runtime) you can't guarantee nothing. > > > > For NMI, HPA asked me to use "int $2", as it switches to the NMI IST > > stack to execute the NMI handler, essentially like how HW deals with a > > NMI in host. and I tested it with NMI watchdog, it looks working fine. >=20 > Heh, well yeah, because that's how KVM used to handle NMIs back before I > reworked NMI handling to use the direct call method. Ironically, that or= iginal > change was done in part to try and make it _easier_ to deal with FRED (ba= ck > before FRED was publicly disclosed). >=20 > If KVM reverts to INTn, the fix to route KVM=3D>NMI through the non-IST e= ntry > can be reverted too. >=20 > a217a6593cec ("KVM/VMX: Invoke NMI non-IST entry instead of IST entry") > 1a5488ef0dcf ("KVM: VMX: Invoke NMI handler via indirect call instead o= f > INTn") Sure, I'm just thinking to put asm("int $2") in a new function exc_raise_nm= i() defined in arch/x86/kernel/traps.c. Thus we will need to change it only whenever we have any better facility, and no KVM VMX change required.