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 9B56AFF8875 for ; Thu, 30 Apr 2026 10:37:25 +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=dvlI2arhnUtJoUf3ZtMZQtMLGBbw4pk7njCiMEtbTJU=; b=jVhKtAfzqe7Pc97XgITCNOPrFy GYvOXzfg1lPOslmtJ5l/n0P2ZqD/Jt1vxIC/ir0mFHele+2Y3OrYAnYa1thfE95vUqQidjwM7g/5c HQKiDHmQcfNHrnE6IAJIxpi81KAgdvoCMiKxHjEpozY1yhh9nNIcqSN7necraG3bo4McYr8PPyPPv 0G+gvZYIrn+PFy3ijmDrTn9iQb5C5JEzAcNiDN9n5JANpzBnaF/Vkw9NSdEePm9Sh+RTrGEJPMmA4 +hKcE1E/P5y5ionwVs1Tf6GqBll9rf+RmTTaxuHcBy7EN16YYqFfjy9gCyu9ZEhlpv2tx/JBoaDrR sNIS0Z+A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1wIOle-00000005D3L-2ieO; Thu, 30 Apr 2026 10:37:14 +0000 Received: from sea.source.kernel.org ([172.234.252.31]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1wIOlc-00000005D2u-22s9 for linux-arm-kernel@lists.infradead.org; Thu, 30 Apr 2026 10:37:13 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id A727644112; Thu, 30 Apr 2026 10:37:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 78169C2BCB3; Thu, 30 Apr 2026 10:37:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777545431; bh=1NvrjGfoiqQQbhKpYby6bZ0eDOwXMUv9+GR0prZV2wU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Ej48oWuxftmWidWm0SJN8vta3Pv+TG1Jf/29ag9BoIjKFRMPmMyg2pE6DinPnb46n tTOovZ/l+ENzryvcE3irvr9k5M4EFHjP10rB6pIj2DubPhKWvJlI9JA7Xmg6+18EH3 Y2dE2YCCxEoEbYETzNjNBUT2Sb5gOkM+aTG4a6cLUKn4xoadkLMCXaitK56BNFr3i6 hvcD+S3Gl98TjWNqxNuGSMtj4MhX47Ndm4ELfLBNgLSceNgapgK666WoGtPHuGHYEj 80oJEujqaZ0iCqzfdmyqIQiDwhjCkw7P7OR6PaQrCUoSZpmaWawVQ1XxNMQjbxTZpu d7KQ130gRtkhA== 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 1wIOlY-0000000GDpb-3vRA; Thu, 30 Apr 2026 10:37:09 +0000 Date: Thu, 30 Apr 2026 11:37:08 +0100 Message-ID: <86ecjwzqcr.wl-maz@kernel.org> From: Marc Zyngier To: Sascha Bischoff Cc: "linux-arm-kernel@lists.infradead.org" , "kvmarm@lists.linux.dev" , "kvm@vger.kernel.org" , nd , "oliver.upton@linux.dev" , Joey Gouly , Suzuki Poulose , "yuzenghui@huawei.com" , "peter.maydell@linaro.org" , "lpieralisi@kernel.org" , Timothy Hayes Subject: Re: [PATCH 14/43] KVM: arm64: gic-v5: Request VPE doorbells when going non-resident In-Reply-To: <20260427160547.3129448-15-sascha.bischoff@arm.com> References: <20260427160547.3129448-1-sascha.bischoff@arm.com> <20260427160547.3129448-15-sascha.bischoff@arm.com> 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: Sascha.Bischoff@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, nd@arm.com, oliver.upton@linux.dev, Joey.Gouly@arm.com, Suzuki.Poulose@arm.com, yuzenghui@huawei.com, peter.maydell@linaro.org, lpieralisi@kernel.org, Timothy.Hayes@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-20260430_033712_608094_B8406ABA X-CRM114-Status: GOOD ( 30.83 ) 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 Mon, 27 Apr 2026 17:10:49 +0100, Sascha Bischoff wrote: > > When a VPE is made non-resident and is entering WFI, a doorbell should > be requested for the VPE. This allows the VPE to be easily woken once > an SPI/LPI interrupt is pending for it. This is tracked by the IRS, > which will signal the specific VPE doorbell for the VPE once such an > interrupt arrives. > > Requesting a doorbell involves calculating the DBPM - DoorBell > Priority Mask - which ensures that the DB is only signalled by the > hardware if the pending interrupt is of sufficient priority. This > avoids waking a VPE that can't process the incoming interrupt. > > Doorbells are NOT requested if a VPE is not entering WFI as we expect > to enter again imminently. > > Signed-off-by: Sascha Bischoff > --- > arch/arm64/kvm/vgic/vgic-v5.c | 28 ++++++++++++++++++++++++++++ > 1 file changed, 28 insertions(+) > > diff --git a/arch/arm64/kvm/vgic/vgic-v5.c b/arch/arm64/kvm/vgic/vgic-v5.c > index 11a1a491b7e0a..2fc6fa4df034f 100644 > --- a/arch/arm64/kvm/vgic/vgic-v5.c > +++ b/arch/arm64/kvm/vgic/vgic-v5.c > @@ -1077,6 +1077,9 @@ void vgic_v5_load(struct kvm_vcpu *vcpu) > void vgic_v5_put(struct kvm_vcpu *vcpu) > { > struct vgic_v5_cpu_if *cpu_if = &vcpu->arch.vgic_cpu.vgic_v5; > + bool req_db = !!vcpu_get_flag(vcpu, IN_WFI); Drop the spurious variable and move the check in the if () statement. This is way more readable than declaring a variable. > + u32 priority_mask; > + int dbpm; Move these in the inner block. > > /* > * Do nothing if we're not resident. This can happen in the WFI path > @@ -1090,6 +1093,31 @@ void vgic_v5_put(struct kvm_vcpu *vcpu) > kvm_call_hyp(__vgic_v5_save_apr, cpu_if); > > cpu_if->vgic_contextr = 0; > + if (req_db) { > + /* > + * Find the virtual running priority and use this to calculate > + * the doorbell priority mask. We combine the highest active > + * priority and the CPU's priority mask. The guest can't handle > + * interrupts with priorities less than or equal to the virtual > + * running priority, so there's literally no point in waking the > + * guest for these. > + * > + * The priority needs to be higher than the mask to signal, so > + * pick the next higher priority (subtract 1). > + */ > + priority_mask = vgic_v5_get_effective_priority_mask(vcpu); > + > + /* Don't request a doorbell if the max priority is masked */ This comment reads badly. I'd suggest something like "Request a doorbell *unless* the priority is 0, indicating that no interrupt can wake the vcpu up". > + if (priority_mask) { > + dbpm = priority_mask - 1; > + cpu_if->vgic_contextr = FIELD_PREP(ICH_CONTEXTR_EL2_DB, 1) | > + FIELD_PREP(ICH_CONTEXTR_EL2_DBPM, dbpm); > + } > + > + /* Make the doorbell affine to this CPU */ > + WARN_ON(irq_set_affinity(vgic_v5_vpe_db(vcpu), > + cpumask_of(smp_processor_id()))); Repeatedly setting the affinity is likely to be costly. It may be worth comparing with the current affinity somehow. > + } > > kvm_call_hyp(__vgic_v5_make_non_resident, cpu_if); > Thanks, M. -- Without deviation from the norm, progress is not possible.