From mboxrd@z Thu Jan 1 00:00:00 1970 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 74A9FEB64DD for ; Mon, 24 Jul 2023 21:20:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230521AbjGXVU5 (ORCPT ); Mon, 24 Jul 2023 17:20:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229550AbjGXVUz (ORCPT ); Mon, 24 Jul 2023 17:20:55 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45816139; Mon, 24 Jul 2023 14:20:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=eygDX+Dak0hX6wMmwhav7dSyFRNIJ5Acv7NgHDwNRpc=; b=WGEXN2JUsOgpzIB3RZJCo0vMkf CLh9IxjQq548vMnPN/rkTvygms33yuOdLFJgKJ8T/rqSSJqUzEV6RBhVpaE+dw5bR2uKad3Yl0scJ 77rki0hyuUHSbXyBctykRCLHJ9rSPFyXFixhB1D8v3qjlq0fHhcTiBT3zlooXIcs7VPcw+WNV7/wD OMz6kAOm5HmfWJl0Db4Z7vKVum3zvkbRxIEwv129+nu2hM/iYGgovQqUQWTDJ5/UsYlyPEfqp5hgk xlziLL8XfOeSezF0MqWNFMWRFpNtYF3ZTYI2dGC5yNKGK5X5xHFZu2l2mHgHVGnujra0NnjQAEzhj MF0EoczQ==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qO2y7-002ibB-2t; Mon, 24 Jul 2023 21:19:57 +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 1D7D630020C; Mon, 24 Jul 2023 23:19:50 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 079B2265C4A2D; Mon, 24 Jul 2023 23:19:50 +0200 (CEST) Date: Mon, 24 Jul 2023 23:19:49 +0200 From: Peter Zijlstra To: Sean Christopherson Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Paolo Bonzini , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Andrew Cooper , Kai Huang , Chao Gao Subject: Re: [PATCH v4 05/19] x86/reboot: Assert that IRQs are disabled when turning off virtualization Message-ID: <20230724211949.GG3745454@hirez.programming.kicks-ass.net> References: <20230721201859.2307736-1-seanjc@google.com> <20230721201859.2307736-6-seanjc@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230721201859.2307736-6-seanjc@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 21, 2023 at 01:18:45PM -0700, Sean Christopherson wrote: > Assert that IRQs are disabled when turning off virtualization in an > emergency. KVM enables hardware via on_each_cpu(), i.e. could re-enable > hardware if a pending IPI were delivered after disabling virtualization. > > Remove a misleading comment from emergency_reboot_disable_virtualization() > about "just" needing to guarantee the CPU is stable (see above). > > Reviewed-by: Kai Huang > Signed-off-by: Sean Christopherson > --- > arch/x86/kernel/reboot.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c > index 48ad2d1ff83d..4cad7183b89e 100644 > --- a/arch/x86/kernel/reboot.c > +++ b/arch/x86/kernel/reboot.c > @@ -532,7 +532,6 @@ static inline void nmi_shootdown_cpus_on_restart(void); > > static void emergency_reboot_disable_virtualization(void) > { > - /* Just make sure we won't change CPUs while doing this */ > local_irq_disable(); > > /* > @@ -821,6 +820,13 @@ void cpu_emergency_disable_virtualization(void) > { > cpu_emergency_virt_cb *callback; > > + /* > + * IRQs must be disabled as KVM enables virtualization in hardware via > + * function call IPIs, i.e. IRQs need to be disabled to guarantee > + * virtualization stays disabled. > + */ > + lockdep_assert_irqs_disabled(); > + > rcu_read_lock(); > callback = rcu_dereference(cpu_emergency_virt_callback); > if (callback) Strictly speaking you don't need rcu_read_lock() when IRQs are already disabled, but since this is non-performance critical code, it might be best to keep it super obvious. IOW, carry on.