From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795081998; b=KFVlS2tmFH2AekregFKJ02UnezyS00B9493Yw7V2g4/g4IIHEvLQ281iqQseGXkHbjRO Ldsexr6flNzcUzWecDaWYMdKCZ5IEkyviBe8bqoLRVrAX6P9Hl47mIpuY/kCSlhLo0v+H JWTMsHONrwtBYpAjxvdFgzFSJwfwU1hO3g/fF4LL6SXGolRA6nqvxuH8SljYNF7yTLf1E P1U5Fl4OD3+YhEmFfXLlX98kUmTwwU2pKec1JRKOf382MUjqJwsKY1npQUMmCQUzpOL9i F2f1RsFUbGgsqmxUQfyo5ryhuj72Z1yfaYovVNb7XUBWBApJ4JklBwQys8ed7/Ib9Lw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795081998; h=Received:DKIM-Signature:Received:Date:Message-ID:From:To:Cc:Subject: In-Reply-To:References:User-Agent:MIME-Version:Content-Type: X-SA-Exim-Connect-IP:X-SA-Exim-Rcpt-To:X-SA-Exim-Mail-From: X-SA-Exim-Scanned; bh=uw9sRkfoNYdFSz9CTJOiwcLRj7YgovINkuToV5+7kGc=; b=yttuEkZUcLxmjbZOVZzCu39Tn7VLPKpmc29kelCecFfgGPe7NW/0jO8sk0LcZaKEw8ZW EH4XoTZ08K1vfMnE9iVQCo/6aw1smFdilzZNimvB+2oE0KTuD19gvnwgmqot9dbU/LiPh yupBD9iqV3hTD4XUPlSGgLH+fZnHfDXEv4FqzIYtBOOoS7QRyD5VahCE6griiBk6FQc6x izdRwQWNyoXjvPPXQPPXXzqU1qJsa7agLoigMpyeysUq+uJaDA3lsNb0bD/5oFG35lZjm WFXHMpGhmVYGth91FWiiA6+Ug/vg8pQd9qZCOrnx5ZTMGk6gQIpYv0oaXTsASejffXw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=G1AYgeOv; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C342606A324; Thu, 19 Nov 2026 09:53:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=G1AYgeOv Received: by smtp.kernel.org (Postfix) with ESMTPSA id 185D91F000C5; Thu, 19 Nov 2026 09:53:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795081998; bh=uw9sRkfoNYdFSz9CTJOiwcLRj7YgovINkuToV5+7kGc=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=G1AYgeOvg+nwbbnhI1meZ1wYPN1z/5PbRqm5ZqSVd7+WeQEkhMeL63tDZWtqLbxE7 FrlYNzl3+53uiAvojpykPofsM/Epg9a5eiwVW/sHe3crHChT2i7oAI4nomF0mRmZ7t y9xnXhXZFSBIwHj43RXMpdESV9ygE+vXe5rmP7wRCNoNS2QhBaZ0SolafqNpV8rQAW tMLD+pN0cslCjXntdWgT9L24hM26o3cKCvh5277hPR7xZQaeEkf6rvlIiEnzcjsIT1 LmqES8UvSHE9u9HuhnpUQvohM0kY2Hcf+m4Lym+HeKchvblyq4wgMB1IIqZw9hLh46 eVYMZWLQwuxdA== 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 1xTypQ-00000000NfP-070Z; Thu, 19 Nov 2026 09:53:16 +0000 Date: Thu, 19 Nov 2026 09:53:15 +0000 Message-ID: <86y0apywok.wl-maz@kernel.org> From: Marc Zyngier To: Dan Carpenter Cc: Oliver Upton , kvmarm@lists.linux.dev, sashiko-reviews@lists.linux.dev Subject: Re: [PATCH v2 1/2] KVM: arm64: Load the vcpu in KVM_SET_VCPU_EVENTS In-Reply-To: References: <033a2d49e0f48426281b46eb1131ae64012aba18.1795006659.git.dan@pereq.eu> <86zev6yqzd.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-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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: dan@pereq.eu, oupton@kernel.org, kvmarm@lists.linux.dev, sashiko-reviews@lists.linux.dev X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Thu, 19 Nov 2026 08:18:18 +0000, Dan Carpenter wrote: > > On Wed, Nov 18, 2026 at 05:44:06PM +0000, Marc Zyngier wrote: > > On Wed, 18 Nov 2026 13:45:34 +0000, > > sashiko-bot@kernel.org wrote: > > > > > > Thank you for your contribution! Sashiko AI review found 1 potential > > > issue to consider: > > > - [Medium] KVM: arm64: stale mmio_needed after kvm_inject_nested() in > > > KVM_SET_VCPU_EVENTS > > > -- > > > > > > commit 178d0de7451612b8ddf14a943cb82094efbd77d1 > > > Author: Dan Carpenter > > > > > > KVM: arm64: Load the vcpu in KVM_SET_VCPU_EVENTS > > > > > > This commit wraps __kvm_arm_vcpu_set_events() in vcpu_load() and vcpu_put() > > > so that kvm_inject_nested() operates on a loaded vCPU during > > > KVM_SET_VCPU_EVENTS. > > > > > > > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c > > > > index 84a52e27ed859..a148e80d0aef7 100644 > > > > --- a/arch/arm64/kvm/arm.c > > > > +++ b/arch/arm64/kvm/arm.c > > > > @@ -2002,7 +2002,7 @@ static int kvm_arm_vcpu_get_events(struct kvm_vcpu *vcpu, > > > > static int kvm_arm_vcpu_set_events(struct kvm_vcpu *vcpu, > > > > struct kvm_vcpu_events *events) > > > > { > > > > - int i; > > > > + int i, ret; > > > > > > > > /* check whether the reserved field is zero */ > > > > for (i = 0; i < ARRAY_SIZE(events->reserved); i++) > > > > @@ -2014,7 +2014,11 @@ static int kvm_arm_vcpu_set_events(struct kvm_vcpu *vcpu, > > > > if (events->exception.pad[i]) > > > > return -EINVAL; > > > > > > > > - return __kvm_arm_vcpu_set_events(vcpu, events); > > > > + vcpu_load(vcpu); > > > > + ret = __kvm_arm_vcpu_set_events(vcpu, events); > > > > + vcpu_put(vcpu); > > > > + > > > > + return ret; > > > > } > > > > > > [Severity: Medium] > > > Does vcpu->mmio_needed remain set when KVM_SET_VCPU_EVENTS injects an > > > exception from L2 that routes to L1 EL2? > > > > > > When an L2 guest exits with KVM_EXIT_MMIO and userspace aborts the access via > > > KVM_SET_VCPU_EVENTS (for example with ext_dabt_pending = 1 while HCR_EL2.TEA > > > is set), kvm_inject_sea_dabt() -> kvm_inject_nested() commits the EL2 > > > exception entry directly via __kvm_adjust_pc(), which clears > > > PENDING_EXCEPTION. When __kvm_arm_vcpu_set_events() then calls > > > commit_pending_events(), PENDING_EXCEPTION is already clear, so it returns > > > early without clearing vcpu->mmio_needed: > > > > > > arch/arm64/kvm/guest.c:commit_pending_events() { > > > if (!vcpu_get_flag(vcpu, PENDING_EXCEPTION)) > > > return; > > > > > > vcpu->mmio_needed = false; > > > kvm_call_hyp(__kvm_adjust_pc, vcpu); > > > } > > > > > > On the next KVM_RUN, kvm_handle_mmio_return() sees vcpu->mmio_needed still > > > set, writes the MMIO read value into L1 EL2's destination register and > > > advances L1 EL2's exception vector PC by 4 bytes via kvm_incr_pc(). > > > > I think this is a separate issue, which doesn't intersect with the > > current patch. > > Yep. > > > The problem is that we have multiple ways to "commit' > > the state on exception delivery, and that we miss MMIO handling in the > > EL1->EL2 path. > > > > Oliver, WDYT? > > > > I have a reproducer for the bug Sashiko found and this patch doesn't > work. Attached. Claude wanted to just set vcpu->mmio_needed = false; > but I told it to call commit_pending_events() instead. Duh, yes. I had the wrong __adjust_pc()... :-( We need to replace the one that triggers the exception delivery, rather than the one that performs a previous instruction skip in the original context... Please send this, and I'll queue it immediately. Thanks a lot for making it easy to understand the issue! M. -- Without deviation from the norm, progress is not possible.