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 0388BEE49A4 for ; Sun, 10 Sep 2023 16:26:51 +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-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To:Subject: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=pExn+mJZ6iMtCwocI+8KH9Jue5P1xH5wcp8ddxn5ZFI=; b=ivSZW1fZFuXExQ ack8myXDCBNGCPdjYFFSfuibOJWdidPmYC3qdEK561mrLZT2U3+yy7+J/bK2xEvhhVUFzTSdaPhLi Cv+jZqFP9Z58W31F6Bn5RcCK3A6qkU2gDv7AktIXUsN8LzRL2+SZHcqbNvzwbxNeKNjeztZ4XuIJH TAbpChrLmZyuh1nqtYvFTwB+EooT6FchM/Z0nhLPaarIN9fJDf0npSdBdQbG/SLUQxGugE0DddAo5 90Fz4R90psagFl3317mAflLsbx33AyhuyPBc+XYrrzR8qdCDUA2LLcnzVYlJ+uQodCs44Om1hz4Xa weju81xxsahW+PgX1Nhg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qfNGQ-00GlA3-2h; Sun, 10 Sep 2023 16:26:22 +0000 Received: from out-225.mta0.migadu.com ([2001:41d0:1004:224b::e1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qfNGM-00Gl9i-2q for linux-arm-kernel@lists.infradead.org; Sun, 10 Sep 2023 16:26:21 +0000 Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1694363170; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rsJTV4TGEiHWsO+KfLl8BIfB/jdFBOkN4/lhq6SgVaw=; b=G2BwvTyKhntpdDrUFaeWo109jjjRls1LKieTt6X/EFdnX5xJd0l02jyMyu8sYL3AgBBg3n nvp/4UVxHkAJwymOdmOn78UbWqJHSNiVwXX4sfv/NUMIBU33RMI1MhHdNj17ZhpTyC/XRI TBc5PobGJfqX7mFoU0ZzfbCayRuwbmY= Date: Mon, 11 Sep 2023 00:25:36 +0800 MIME-Version: 1.0 Subject: Re: [PATCH 4/5] KVM: arm64: vgic-v3: Refactor GICv3 SGI generation Content-Language: en-US To: Marc Zyngier , kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org Cc: James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Xu Zhao References: <20230907100931.1186690-1-maz@kernel.org> <20230907100931.1186690-5-maz@kernel.org> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Zenghui Yu In-Reply-To: <20230907100931.1186690-5-maz@kernel.org> X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230910_092619_740938_AD685E2F X-CRM114-Status: GOOD ( 20.53 ) 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-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Marc, On 2023/9/7 18:09, Marc Zyngier wrote: > As we're about to change the way SGIs are sent, start by splitting > out some of the basic functionnality: instead of intermingling functionality > the broadcast and non-broadcast cases with the actual SGI generation, > perform the following cleanups: > > - move the SGI queuing into its own helper > - split the broadcast code from the affinity-driven code > - replace the mask/shift combinations with FIELD_GET() > > The result is much more readable, and paves the way for further > optimisations. Indeed! > @@ -1070,19 +1102,30 @@ void vgic_v3_dispatch_sgi(struct kvm_vcpu *vcpu, u64 reg, bool allow_group1) > { > struct kvm *kvm = vcpu->kvm; > struct kvm_vcpu *c_vcpu; > - u16 target_cpus; > + unsigned long target_cpus; > u64 mpidr; > - int sgi; > - int vcpu_id = vcpu->vcpu_id; > - bool broadcast; > - unsigned long c, flags; > - > - sgi = (reg & ICC_SGI1R_SGI_ID_MASK) >> ICC_SGI1R_SGI_ID_SHIFT; > - broadcast = reg & BIT_ULL(ICC_SGI1R_IRQ_ROUTING_MODE_BIT); > - target_cpus = (reg & ICC_SGI1R_TARGET_LIST_MASK) >> ICC_SGI1R_TARGET_LIST_SHIFT; > + u32 sgi; > + unsigned long c; > + > + sgi = FIELD_GET(ICC_SGI1R_SGI_ID_MASK, reg); > + > + /* Broadcast */ > + if (unlikely(reg & BIT_ULL(ICC_SGI1R_IRQ_ROUTING_MODE_BIT))) { > + kvm_for_each_vcpu(c, c_vcpu, kvm) { > + /* Don't signal the calling VCPU */ > + if (c_vcpu == vcpu) > + continue; > + > + vgic_v3_queue_sgi(c_vcpu, sgi, allow_group1); > + } > + > + return; > + } > + > mpidr = SGI_AFFINITY_LEVEL(reg, 3); > mpidr |= SGI_AFFINITY_LEVEL(reg, 2); > mpidr |= SGI_AFFINITY_LEVEL(reg, 1); > + target_cpus = FIELD_GET(ICC_SGI1R_TARGET_LIST_MASK, reg); > > /* > * We iterate over all VCPUs to find the MPIDRs matching the request. > @@ -1091,54 +1134,19 @@ void vgic_v3_dispatch_sgi(struct kvm_vcpu *vcpu, u64 reg, bool allow_group1) > * VCPUs when most of the times we just signal a single VCPU. > */ > kvm_for_each_vcpu(c, c_vcpu, kvm) { > - struct vgic_irq *irq; > + int level0; > > /* Exit early if we have dealt with all requested CPUs */ > - if (!broadcast && target_cpus == 0) > + if (target_cpus == 0) > break; > - > - /* Don't signal the calling VCPU */ > - if (broadcast && c == vcpu_id) Unrelated to this patch, but it looks that we were comparing the value of *vcpu_idx* and vcpu_id to skip the calling VCPU. Is there a rule in KVM that userspace should invoke KVM_CREATE_VCPU with sequential "vcpu id"s, starting at 0, so that the user-provided vcpu_id always equals to the KVM-internal vcpu_idx for a given VCPU? I asked because it seems that in kvm/arm64 we always use kvm_get_vcpu(kvm, i) to obtain the kvm_vcpu pointer, even if *i* is sometimes essentially provided by userspace.. Besides, the refactor itself looks good to me. Thanks, Zenghui _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel