From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 042C4606A31E for ; Tue, 24 Nov 2026 12:50:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=UvhA8WVR; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Gr2PEFt6 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=fkcXNh2S892P26zeb4v8GatV81GnIFMuUNe4sWAuvks=; b=UvhA8WVR4EOA6AKYULDPdUgl3K CbNyfYRJ6cL/AsCHMgLTHfQFCyHzbKWgh+X50tenFpGT0Lbd5CT2+SIE1zbbLeWLS2Y+fpjZWslyM n0WXaAZQJ16YQBSdZBpfPpW0htwc5e0Hw+qpRKHGf4LRhheLr0ddAGyRTCwhOwO1AVzRsHXl/vqXA odbiOqj++GQbplFnmXpwru7eDyTN8H+FlSoMoTEAa8pm8vE4ApPkmafxJH+15TagweayBVmYRTm29 pOaek25I6fhqn1IGYNAARygaiCo1hp0dlAMT7igyM6s4Ja0Kn7I4jzUmJwAlCemtl6wmlHAB7qUHe w/UDcl5w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xVpyP-00000006Y7u-01g7; Tue, 24 Nov 2026 12:50:13 +0000 Received: from sea.source.kernel.org ([172.234.252.31]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xVpyN-00000006Y7m-2vsu for linux-arm-kernel@lists.infradead.org; Tue, 24 Nov 2026 12:50:11 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 3F27D43821; Tue, 24 Nov 2026 12:50:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80B391F000C0; Tue, 24 Nov 2026 12:50:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795524610; bh=fkcXNh2S892P26zeb4v8GatV81GnIFMuUNe4sWAuvks=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=Gr2PEFt6Nif4bgQBkTr20iv52muiiKwwK0cRcdA2K0e825bGiSD/zpBb8TnonFISy fxqG4PZIaD/LsMIx6VJ2b9q82i6NAso2o9l3lcff2wZgZkU/fYbcM/T1MqnYuWA5Tg 3OeTKCka90kyPatC5NxqPl3gda+lX38e3x5q9Xv9FcQFwO5Hm6v6qeV1eyZY8VMU3F 31mirC74x45EEyhE3MU0Q/la2PlvYX/UX1LzUgFtaIRv/t1AIgC+BMlOFtbXOH4PID x2aHnvY+gDaxfJFp3TjoCIPM2cpf8Lj3JiVjlcrTrKDx8/nQN8aFOKLv7UkpNWOquZ swhINiwhDxj8w== 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.98.2) (envelope-from ) id 1xVpyK-00000002Zmv-16Az; Tue, 24 Nov 2026 12:50:08 +0000 Date: Tue, 24 Nov 2026 12:50:07 +0000 Message-ID: <868q2iz94w.wl-maz@kernel.org> From: Marc Zyngier To: Justin He Cc: Oliver Upton , Fuad Tabba , Joey Gouly , Steffen Eiden , Suzuki Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Mark Rutland , Paolo Bonzini , Sean Christopherson , Shuah Khan , Sascha Bischoff , "linux-arm-kernel@lists.infradead.org" , "kvmarm@lists.linux.dev" , "linux-kernel@vger.kernel.org" , "kvm@vger.kernel.org" , "linux-kselftest@vger.kernel.org" , Lorenzo Stoakes , Dan Carpenter Subject: Re: [PATCH 1/3] KVM: arm64: Don't load hardware vCPU state before first run In-Reply-To: References: <20261123150917.2679600-1-justin.he@arm.com> <20261123150917.2679600-2-justin.he@arm.com> <86eccbzcqh.wl-maz@kernel.org> 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/30.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) X-Archived-By: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: Justin.He@arm.com, oupton@kernel.org, fuad.tabba@linux.dev, Joey.Gouly@arm.com, seiden@linux.ibm.com, Suzuki.Poulose@arm.com, yuzenghui@huawei.com, Catalin.Marinas@arm.com, will@kernel.org, Mark.Rutland@arm.com, pbonzini@redhat.com, seanjc@google.com, shuah@kernel.org, Sascha.Bischoff@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, ljs@kernel.org, dan@pereq.eu X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-5.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Adding Dan to this loop, as I reckon something else is amiss. On Tue, 24 Nov 2026 01:39:23 +0000, Justin He wrote: > > Hi, Marc > > > -----Original Message----- > [...] > > > KVM_PRE_FAULT_MEMORY calls vcpu_load() as soon as > > KVM_ARM_VCPU_INIT has > > > completed. On arm64, however, kvm->arch.sysreg_masks, the trap > > > configuration, vncr_tlb and nested vGIC state are only set up on the > > > first KVM_RUN in kvm_arch_vcpu_run_pid_change(). > > > > I think I'm going to queue a patch disabling prefaulting immediately, > > and then we can fix this crap. > > > Fine with me. I'll rebase on top of it and have v2 re-enable > pre-faulting together with the load/put change. Don't worry about that. I can fix that myself when applying the patches. > > > Since kvm_running_vcpu can now be set without VHE state on the CPU, use > > > host_ctxt->__hyp_running_vcpu in VHE enter_vmid_context() (matching > > > nVHE) > > > > Can you clarify under which circumstances we end-up on the TLB > > invalidation path? Simply faulting things in should not result in > > invalidation. Unless we end-up with MMU notifiers firing? > > > I found this by code inspection, not from a failure. A TLBI from a stage-2 > BBM or an MMU notifier can hit this path during pre-faulting, but before > the first run hw_mmu is canonical, so it makes no difference. As Lorenzo > said, I'll drop this hunk. vcpu->arch.hw_mmu being the canonical one before the first run doesn't hold anymore, since a7602ea542d4e ("KVM: arm64: nv: Initialize hw_mmu to NULL for nested vCPUs"), as userspace can configure things for an L2, before first run, and bad things happen otherwise. But the observation remains: if an MMU notifier occurs for any reason while pre-faulting (likely a concurrent reclaim), we get the "not quite loaded" vcpu in enter_vmid_context(). If vcpu->arch.hw_mmu is a valid (non-null) pointer, then we will restore whatever is in that structure when reaching exit_vmid_context(), and that's not what is intended. So I think we need that sort of exclusion. Either we track what is actually properly loaded (using __hyp_running_vcpu as you did before, or by checking whether the vcpu is in a valid state). I think we have a somewhat similar breakage with 5651590be08a6 ("KVM: arm64: Load the vcpu in KVM_SET_VCPU_EVENTS"): as vcpu_load() now becomes sensitive to vcpu_has_run_once() being true, we can't tell anything of the state that is going to be evaluated by the event injection helper. We could prevent the non-running injection in KVM_SET_VCPU_EVENTS, but that's also a change in the API... M. -- Without deviation from the norm, progress is not possible.