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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7FE37EB64DC for ; Mon, 3 Jul 2023 09:46:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Subject:Cc:To:From:Message-ID:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=jB00Anz+hWGC/2ehTcRms+ZSeaMfYKpT3GXzknh88CQ=; b=MBSmAhYgHuyYDj bMuV9sp3Sg64lPOQ+M8ipSR6XvbC49anggYLSZ7BOkwlqOf+p5vmZGAXBoHFSJ2Xnqti6qqEKY8Y/ LrJtSk2DEDePyJeJwW8GcMYCKI2LYOOb+s6v5nelGHxaNdM+xxEa51u/SLE8vRVWKkciJTr30xije rP9lshIoJ8QuWnJ0AcrgQgyW8HMxajPyvVCyCqEzGJtHCe50Mrqmknc9EB2Q16HqX5Y6SCHmK3vJM UVx0jle3GnHcnXJ01/BPdBg+OWcEamnw2WLUWVFm+EnJw5WsEHXpE7HWu+JZYGWklOgjGJaZgF9rY CwrzJ5iKca3NKNh/fUtQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qGG7j-009yyg-1u; Mon, 03 Jul 2023 09:45:35 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qGG7h-009ywF-0d for linux-arm-kernel@lists.infradead.org; Mon, 03 Jul 2023 09:45:34 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 95BDF60EA9; Mon, 3 Jul 2023 09:45:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02412C433C8; Mon, 3 Jul 2023 09:45:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1688377530; bh=07vPEXuHNAjSyb/jCUmI2nBGwG00D9SJ31afLJUgB10=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=ekNgQGsW5LceWciZOTwVmsTRBUks/1hJheWaZlaPwggWKp2ncHo5CsiPqrLwfwo41 3u3HRKntVO0KGjU5mxvQJKRfxhObIT3+rf0N/BU0cOmaQw5hpAW9DT9I+nTs2yzqJ7 C29MnDWjoZ2KcJIML8pfp9Wv1SpCsKgSZHA759ql+QEcHonijAcIelfoKFkU0tJhSs VUfTas7Std/Yjmq9UQ3mtkdARrqA2yaZ2bWm5PTNP46H4Mq8ZUhTmiNqdUAfVPrvjS f8FiFLKZeajO1xXnuRyJ39XkbQNKT1WnBQYcq0GMU36E5gFoN71OrfVYXvxItod5Qw j85J53OspIPgQ== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1qGG7a-00A7cd-S8; Mon, 03 Jul 2023 10:45:27 +0100 Date: Mon, 03 Jul 2023 10:45:26 +0100 Message-ID: <867crhxr9l.wl-maz@kernel.org> From: Marc Zyngier To: Oliver Upton , Kristina Martsenko Cc: isaku.yamahata@intel.com, seanjc@google.com, pbonzini@redhat.com, kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, James Morse Subject: Re: KVM CPU hotplug notifier triggers BUG_ON on arm64 In-Reply-To: References: User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/28.2 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: oliver.upton@linux.dev, kristina.martsenko@arm.com, isaku.yamahata@intel.com, seanjc@google.com, pbonzini@redhat.com, kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, james.morse@arm.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230703_024533_321334_7DD5BF9F X-CRM114-Status: GOOD ( 30.72 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Sat, 01 Jul 2023 18:42:28 +0100, Oliver Upton wrote: > > Hi Kristina, > > Thanks for the bug report. > > On Sat, Jul 01, 2023 at 01:50:52PM +0100, Kristina Martsenko wrote: > > Hi, > > > > When I try to online a CPU on arm64 while a KVM guest is running, I hit a > > BUG_ON(preemptible()) (as well as a WARN_ON). See below for the full log. > > > > This is on kvmarm/next, but seems to have been broken since 6.3. Bisecting it > > points at commit: > > > > 0bf50497f03b ("KVM: Drop kvm_count_lock and instead protect kvm_usage_count with kvm_lock") > > Makes sense. We were using a spinlock before, which implictly disables > preemption. > > Well, one way to hack around the problem would be to just cram > preempt_{disable,enable}() into kvm_arch_hardware_disable(), but that's > kinda gross in the context of cpuhp which isn't migratable in the first > place. Let me have a look... An alternative would be to replace the preemptible() checks with a one that looks at the migration state, but I'm not sure that's much better (it certainly looks more costly). There is also the fact that most of our per-CPU accessors are already using preemption disabling, and this code has a bunch of them. So I'm not sure there is a lot to be gained from not disabling preemption upfront. Anyway, as I was able to reproduce the issue under NV, I tested the hack below. If anything, I expect it to be a reasonable fix for 6.3/6.4, and until we come up with a better approach. Thanks, M. diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index aaeae1145359..a28c4ffe4932 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1894,8 +1894,17 @@ static void _kvm_arch_hardware_enable(void *discard) int kvm_arch_hardware_enable(void) { - int was_enabled = __this_cpu_read(kvm_arm_hardware_enabled); + int was_enabled; + /* + * Most calls to this function are made with migration + * disabled, but not with preemption disabled. The former is + * enough to ensure correctness, but most of the helpers + * expect the later and will throw a tantrum otherwise. + */ + preempt_disable(); + + was_enabled = __this_cpu_read(kvm_arm_hardware_enabled); _kvm_arch_hardware_enable(NULL); if (!was_enabled) { @@ -1903,6 +1912,8 @@ int kvm_arch_hardware_enable(void) kvm_timer_cpu_up(); } + preempt_enable(); + return 0; } -- Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel