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 F0E4FCCA46C for ; Fri, 16 Oct 2026 15:51:49 +0000 (UTC) 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-Owner; bh=qYrA4alYLnpWk7LMWSg9VZG/4/dspGuqfh+8t9FeWkA=; b=CnY8M3+iCLuGS7mk53Qlqfyv+I xn9ffHEBL8+LipHYIB7147tjNNG4NO+r4sc2L3ihE72pDv7Rx6RuRNs/fMFwQv+B1637G+jg27U0I lAB1X3nCFPDNfL7KejmQHtITyePsMT0jia1kZZnPHqOduucNYyYVAsdzm/lHKSaBoJfemvkSr2vh8 4/o8szQ4RA+UhgEFpCpBM5QjgBm91IM0zIv46wBBGZYurxpFRVZ1QoGOX11wpSYslc39dtgXb//Oa ZA+8scBvdALxzsar6D2/Yo0GiOTJBVe3TsZ2rTxsCm1bMjnZejYrBDJp0vRdRFjDH5O59v9PAU/GZ X8m0KEzA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1xHkDd-00000003KWq-2RFB; Fri, 16 Oct 2026 15:51:41 +0000 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1xHkDc-00000003KWZ-1o1G for linux-arm-kernel@lists.infradead.org; Fri, 16 Oct 2026 15:51:40 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id D2BEF40289; Fri, 16 Oct 2026 15:51:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3F611F000C5; Fri, 16 Oct 2026 15:51:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1792165899; bh=qYrA4alYLnpWk7LMWSg9VZG/4/dspGuqfh+8t9FeWkA=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=cyEsOz5WDZ/fh13BKcjsRgcbrrf4NSXU1ME4JbcFbsqs+wjT7fkOrgP+GG2Fb9RfR UAtvcBPB2E0oKx8GP82e/y+x9oADQNLJWp9g0HEpG60A5rTUP5CudT3SjiSd9GOGEN as1oj+01MgD40tHhRKDjunaUKyZ7TVsFt+pqp+aYnmz05AgMyQY/z+r4cB+kb0z9HS gLgd2jZvGGsWDpZe8MyK9vwEZHjyu+Esk9yG/AAT86Y3QWYbXVMhn+Z6JL6Zh3aKcf 77c2KEru32TS1XGRR9DWf4HKfG5XsW7ws3O1bHUMdnqzDDh7hNaSZQTMkJD8XbTns9 NSinEzCKwOuRg== 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 1xHkDZ-00000003pee-298p; Fri, 16 Oct 2026 15:51:37 +0000 Date: Fri, 16 Oct 2026 16:51:37 +0100 Message-ID: <867bjh1w52.wl-maz@kernel.org> From: Marc Zyngier To: Fuad Tabba Cc: Oliver Upton , Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Mark Rutland , Andre Przywara , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Fuad Tabba Subject: Re: [PATCH v2 2/2] KVM: arm64: vgic-its: Remove the pending state of a discarded LPI In-Reply-To: <20261013081646.933312-3-fuad.tabba@linux.dev> References: <20261013081646.933312-1-fuad.tabba@linux.dev> <20261013081646.933312-3-fuad.tabba@linux.dev> 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) 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: fuad.tabba@linux.dev, oupton@kernel.org, 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, andre.przywara@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, tabba@google.com 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-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, 13 Oct 2026 09:16:46 +0100, Fuad Tabba wrote: > > DISCARD removes the mapping of an event and instructs the Redistributor > to remove the pending state of its LPI (IHI 0069H.b, 5.3.4). KVM only > frees the ITE, so an LPI that is pending when the guest discards it > stays queued on its target vCPU, and the guest still takes it. > > Clear the pending state before freeing the ITE. A queued LPI can be > pending in a running vCPU's list register, so halt the guest first when > the LPI is queued, to fold that state back. A forwarded LPI already > loses its pending state in its_free_ite(), whose unmap from the vPE > sends a DISCARD to the host ITS. > > Fixes: df9f58fbea9bc ("KVM: arm64: vgic-its: Implement ITS command queue command handlers") > Suggested-by: Marc Zyngier > Signed-off-by: Fuad Tabba > --- > arch/arm64/kvm/vgic/vgic-its.c | 24 +++++++++++++++++++----- > 1 file changed, 19 insertions(+), 5 deletions(-) > > diff --git a/arch/arm64/kvm/vgic/vgic-its.c b/arch/arm64/kvm/vgic/vgic-its.c > index 44b92c01bc727..3b8e0e5b097e0 100644 > --- a/arch/arm64/kvm/vgic/vgic-its.c > +++ b/arch/arm64/kvm/vgic/vgic-its.c > @@ -829,13 +829,27 @@ static int vgic_its_cmd_handle_discard(struct kvm *kvm, struct vgic_its *its, > struct its_device *device = find_its_device(its, device_id); > int ite_esz = vgic_its_get_abi(its)->ite_esz; > gpa_t gpa = device->itt_addr + ite->event_id * ite_esz; > - /* > - * Though the spec talks about removing the pending state, we > - * don't bother here since we clear the ITTE anyway and the > - * pending state is a property of the ITTE struct. > - */ > + struct vgic_irq *irq = ite->irq; > + bool queued; > + > vgic_its_invalidate_cache(its); > > + /* > + * A queued LPI can be pending in a running vCPU's list register, > + * which the exit path folds back: halt the guest before clearing. > + */ > + scoped_guard(raw_spinlock_irqsave, &irq->irq_lock) > + queued = irq->vcpu; Is this comment correct? This is only checking that the LPI is on the AP list of a vcpu, not that it is in the LRs. > + > + if (queued) > + kvm_arm_halt_guest(kvm); And should we move this to kvm_pause_vcpu() instead of the big hammer, this still works because - we hold the ITS lock, so no MOVI can be issued on the same ITS - mapping of the same LPI is already prevented by the previous patch, so no sneaky MOVI generated somewhere else can impact this LPI Do you agree? > + > + scoped_guard(raw_spinlock_irqsave, &irq->irq_lock) > + irq->pending_latch = false; > + > + if (queued) > + kvm_arm_resume_guest(kvm); > + > its_free_ite(kvm, ite); > > return vgic_its_write_entry_lock(its, gpa, 0ULL, ite); If you're OK with the above, I'll make the corresponding changes as I apply the patches. Thanks, M. -- Without deviation from the norm, progress is not possible.