Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1885099rwb; Fri, 11 Nov 2022 01:40:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf6YE/oZocAF3BgaUiZZu8+1u4n4FrxRntYfJvkCMO0ZDSyVn5dvKrDp5ltc0O1htCccw0m/ X-Received: by 2002:a17:906:13c6:b0:78d:b5be:e5f with SMTP id g6-20020a17090613c600b0078db5be0e5fmr1182461ejc.601.1668159650328; Fri, 11 Nov 2022 01:40:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668159650; cv=none; d=google.com; s=arc-20160816; b=T20/Tk/eamUnv7gyBREUiaFOUqY/bU95vc+3Rr8osfTPQe90r8tUWNkFhZGDOqtau2 ElBO/n7yM47WwrHhn4OM8jwYFq1L/Qa/xfTVccW8zWdB/DLoNbT75sAvdcSQ5reAFcGO oSb+0f8zdv7TsLgpJxmnMmyklJjtUbP/F46rdcYvn8macKju6V+muqIvK42B+mAKQI5O SQfiKsPqNBgCrPARIlld65eDCFbtRR/PMBE9B7AcT0sSfWcpdBMmHIABhE0OVypGMuzW rBEbSibbnnmIsEZgEolxZJo4XT6rDtQ+GRaQ6OegwxjofL2RkTmUq/8rTpvq8ma8pyfk kLRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=J/Kd/DRS7pK3+FItfTHVpYFeOxFkIUYqgC78gar9GRk=; b=A4lk44etboXzZ3rO2e8h4BoLowg8qXAxqLGIKOHUyMRdmXxFkQk/Pa68uyJNRQrf7o BO6dctclkQGmaM5zC68vdDeMjvlu/fYXt7W/apZTNDPqHsJH/u8inR8LQREFcPHjqORd zurgyVTWJsAbTNIOU2MAu29mVnH1b21qHeIhgD43rWOTaTp+11GwOYLrh19/cXtPSx/C T3QPSVgzswYiUqjiYVduK63Vjj1ZBaqzNUvJKRLfrTRAVJVLHHWiaJd0/hT0D5yPLKMp QJhKjoUVJm0D/l4kqHGKy5SSONDinbgYULjhSmLWJfmuTXcbweSWvu3g3hnctVBovrAo peRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=YJVgPIWa; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v8-20020a50a448000000b00457e9f88b90si1921456edb.246.2022.11.11.01.40.28; Fri, 11 Nov 2022 01:40:50 -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=@infradead.org header.s=casper.20170209 header.b=YJVgPIWa; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232985AbiKKJPd (ORCPT + 92 others); Fri, 11 Nov 2022 04:15:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232190AbiKKJP1 (ORCPT ); Fri, 11 Nov 2022 04:15:27 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1172D45; Fri, 11 Nov 2022 01:15:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=J/Kd/DRS7pK3+FItfTHVpYFeOxFkIUYqgC78gar9GRk=; b=YJVgPIWaArlf7N5fpU/UogHAmO mWD5B0E+ZO2AhawIJ01HBDc6MejEiDn7khBC++KF43indIGBtSKwU9Y+ev/lv7ar6m1psOpIpBgmV kIDBnHnrc3Syn569tR4AlKSok8yuP4bWVfS/27kK894uDjTTOdHYngsUtjvoGDBopGtfKL0CcddXk OBFxc7SiIVxyShcrJteUUxeNyjqdoDzJe8tshj/uPVLQSuROCfR65DrTGt5nVCO78K1j6q5TBoqtx uuGXyi1l6s2qrkesccc9b6QryAzLjNnhYQmWDM8wA5l1W81+m0eHpnaqvyINU2T75CeNfKJ7Q0oiQ RHFhRnoQ==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1otQ86-00CtP3-Gy; Fri, 11 Nov 2022 09:15:18 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 711CE30031B; Fri, 11 Nov 2022 10:15:12 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 56B2C20243A99; Fri, 11 Nov 2022 10:15:12 +0100 (CET) Date: Fri, 11 Nov 2022 10:15:12 +0100 From: Peter Zijlstra To: "Li, Xin3" Cc: "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" , "Christopherson,, Sean" , "pbonzini@redhat.com" , "Tian, Kevin" Subject: Re: [RESEND PATCH 5/6] KVM: x86/VMX: add kvm_vmx_reinject_nmi_irq() for NMI/IRQ reinjection Message-ID: References: <20221110061545.1531-1-xin3.li@intel.com> <20221110061545.1531-6-xin3.li@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,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 On Thu, Nov 10, 2022 at 08:53:30PM +0000, Li, Xin3 wrote: > > > static void handle_external_interrupt_irqoff(struct kvm_vcpu *vcpu) > > > { > > > u32 intr_info = vmx_get_intr_info(vcpu); > > > unsigned int vector = intr_info & INTR_INFO_VECTOR_MASK; > > > - gate_desc *desc = (gate_desc *)host_idt_base + vector; > > > > > > if (KVM_BUG(!is_external_intr(intr_info), vcpu->kvm, > > > "KVM: unexpected VM-Exit interrupt info: 0x%x", intr_info)) > > > return; > > > > > > - handle_interrupt_nmi_irqoff(vcpu, gate_offset(desc)); > > > + handle_interrupt_nmi_irqoff(vcpu, vector); > > > vcpu->arch.at_instruction_boundary = true; } > > > > How does any of this work? You're calling into entry/noinstr code from a > > random context. > > Can you please elaborate your concern a bit more? > > We are here in handle_external_interrupt_irqoff () because an external > interrupt happened when a guest was running and the CPU vm-exits to host > to dispatch to the IRQ handler with IRQ disabled. I don't speak virt (but this all sounds disguisting) -- but what appears to be the case is you calling into entry code from regular kernel context, which is odd at best. Specifically, going by the fact that all this is not noinstr code, the assumption is that RCU/lockdep/etc.. is all set-up and running. This means you should not be calling DEFINE_IDTENTRY_*(func) functions because those will try and set all that up again. Granted, irqentry_{enter,exit}() do nest, but *yuck*.