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 C18C6C04AAC for ; Thu, 21 Sep 2023 11:47:32 +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-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Subject:Cc:To:From:Message-ID:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=x42Bq1HbqKojrlWa0IF0EIDqBdRUA/9yo40A4GhSMOM=; b=C6//hVOuAJVXAq lAtUJ0gPTCWBpvH5oRwvnBqn/Wl/2QXVNf08l4Ab3HStuC959NaBnukFLgw7OTfFq6t53M12dZvR2 Ign9SjFzYLX0q/HReX66YAnFFofeiSqs33Cvb7r9FOdg7VP0osERa+qpNiocqKcxSF3XmwaZX8RrE hsEB9hy0CQeH8qbOzYZo1/jzEo/AEuMKQyDD1bdCs37T3sHTdf49t3zSxEembhUYqzqElqkOmsd1S pEkJLrNanUpPz4rYpkxPrzgMgopg2YPMErF0wW05OLwOKkRui2ADu07LJ//hKOdDgSvQa6gPJNBwg 2DZYPj4bIGwhuV8az0Gw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qjI9A-005wBX-1p; Thu, 21 Sep 2023 11:47:04 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qjI96-005wAl-2h for linux-arm-kernel@lists.infradead.org; Thu, 21 Sep 2023 11:47:02 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1D98061E5B; Thu, 21 Sep 2023 11:47:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76C96C4AF79; Thu, 21 Sep 2023 11:46:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695296819; bh=fiYc5ghkW/7v/T1rlIkHaYaas3fXswaaMtajC58ND6A=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=SM8YuEua+WZxBwhLR9cccf8Uf71M9CPQzPZ5nucjGRh2Tw9viyfk3jvmllq64w1we jaeeJ4adyP/riIO6/JvLBzRtT8S4TtepGtn5rt1eA6UHJBcHyDxx3jVIaWng4vyepJ l6eaU3LkQmX3T0MER0u7X0UH//AKyFQnB1HO8MafKnDwuZMCe4obOxUBZptQ4fLYP+ /rm/dx03iDOJdVneETnJ21EWa4PTU9tZMfmxF2GCkTeB8jcaZIbJ7fGDVAqVKpc0zk fAAlJNSgu0L6gS3X6SSRcmEWxs+s+BGeKDJkmrmfTW+x/eKi+UIiNpre4zgOa8mlc4 xbVoOBOSisGVA== 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.95) (envelope-from ) id 1qjI92-00EubZ-JW; Thu, 21 Sep 2023 12:46:56 +0100 Date: Thu, 21 Sep 2023 12:46:51 +0100 Message-ID: <861qerpx3o.wl-maz@kernel.org> From: Marc Zyngier To: Zenghui Yu Cc: , , , James Morse , Suzuki K Poulose , Oliver Upton , Joey Gouly , Shameerali Kolothum Thodi , Xu Zhao , Eric Auger Subject: Re: [PATCH v2 02/11] KVM: arm64: vgic-its: Treat the collection target address as a vcpu_id In-Reply-To: References: <20230920181731.2232453-1-maz@kernel.org> <20230920181731.2232453-3-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/29.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: yuzenghui@huawei.com, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, joey.gouly@arm.com, shameerali.kolothum.thodi@huawei.com, zhaoxu.35@bytedance.com, eric.auger@redhat.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-20230921_044700_958659_C3B0D57C X-CRM114-Status: GOOD ( 27.48 ) 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-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, 21 Sep 2023 10:14:55 +0100, Zenghui Yu wrote: > > On 2023/9/21 2:17, Marc Zyngier wrote: > > Since our emulated ITS advertises GITS_TYPER.PTA=0, the target > > address associated to a collection is a PE number and not > > an address. So far, so good. However, the PE number is what userspace > > has provided given us (aka the vcpu_id), and not the internal vcpu > > index. > > > > Make sure we consistently retrieve the vcpu by ID rather than > > by index, adding a helper that deals with most of the cases. > > > > Signed-off-by: Marc Zyngier > > Looks good, with 2 more points: > > - Like patch#1, we should have a go at all > 'target_addr >= kvm->online_vcpus' comparisons in vgic-its.c > - There is still a remaining kvm_get_vcpu() in vgic_its_restore_ite() > which needs to be fixed Yup, well spotted. I have this additional hack which I plan to put on top. Thanks, M. diff --git a/arch/arm64/kvm/vgic/vgic-its.c b/arch/arm64/kvm/vgic/vgic-its.c index 4aadcd24f6f6..6ec9dd970cbb 100644 --- a/arch/arm64/kvm/vgic/vgic-its.c +++ b/arch/arm64/kvm/vgic/vgic-its.c @@ -1248,21 +1248,22 @@ static int vgic_its_cmd_handle_mapc(struct kvm *kvm, struct vgic_its *its, u64 *its_cmd) { u16 coll_id; - u32 target_addr; struct its_collection *collection; bool valid; valid = its_cmd_get_validbit(its_cmd); coll_id = its_cmd_get_collection(its_cmd); - target_addr = its_cmd_get_target_addr(its_cmd); - - if (target_addr >= atomic_read(&kvm->online_vcpus)) - return E_ITS_MAPC_PROCNUM_OOR; if (!valid) { vgic_its_free_collection(its, coll_id); vgic_its_invalidate_cache(kvm); } else { + struct kvm_vcpu *vcpu; + + vcpu = kvm_get_vcpu_by_id(kvm, its_cmd_get_target_addr(its_cmd)); + if (!vcpu) + return E_ITS_MAPC_PROCNUM_OOR; + collection = find_collection(its, coll_id); if (!collection) { @@ -1276,9 +1277,9 @@ static int vgic_its_cmd_handle_mapc(struct kvm *kvm, struct vgic_its *its, coll_id); if (ret) return ret; - collection->target_addr = target_addr; + collection->target_addr = vcpu->vcpu_id; } else { - collection->target_addr = target_addr; + collection->target_addr = vcpu->vcpu_id; update_affinity_collection(kvm, its, collection); } } @@ -1405,24 +1406,21 @@ static int vgic_its_cmd_handle_invall(struct kvm *kvm, struct vgic_its *its, static int vgic_its_cmd_handle_movall(struct kvm *kvm, struct vgic_its *its, u64 *its_cmd) { - u32 target1_addr = its_cmd_get_target_addr(its_cmd); - u32 target2_addr = its_cmd_mask_field(its_cmd, 3, 16, 32); struct kvm_vcpu *vcpu1, *vcpu2; struct vgic_irq *irq; u32 *intids; int irq_count, i; - if (target1_addr >= atomic_read(&kvm->online_vcpus) || - target2_addr >= atomic_read(&kvm->online_vcpus)) + /* We advertise GITS_TYPER.PTA==0, making the address the vcpu ID */ + vcpu1 = kvm_get_vcpu_by_id(kvm, its_cmd_get_target_addr(its_cmd)); + vcpu2 = kvm_get_vcpu_by_id(kvm, its_cmd_mask_field(its_cmd, 3, 16, 32)); + + if (!vcpu1 || !vcpu2) return E_ITS_MOVALL_PROCNUM_OOR; - if (target1_addr == target2_addr) + if (vcpu1 == vcpu2) return 0; - /* We advertise GITS_TYPER.PTA==0, making the address the vcpu ID */ - vcpu1 = kvm_get_vcpu_by_id(kvm, target1_addr); - vcpu2 = kvm_get_vcpu_by_id(kvm, target2_addr); - irq_count = vgic_copy_lpi_list(kvm, vcpu1, &intids); if (irq_count < 0) return irq_count; @@ -2265,7 +2263,7 @@ static int vgic_its_restore_ite(struct vgic_its *its, u32 event_id, return PTR_ERR(ite); if (its_is_collection_mapped(collection)) - vcpu = kvm_get_vcpu(kvm, collection->target_addr); + vcpu = kvm_get_vcpu_by_id(kvm, collection->target_addr); irq = vgic_add_lpi(kvm, lpi_id, vcpu); if (IS_ERR(irq)) { @@ -2580,7 +2578,7 @@ static int vgic_its_restore_cte(struct vgic_its *its, gpa_t gpa, int esz) coll_id = val & KVM_ITS_CTE_ICID_MASK; if (target_addr != COLLECTION_NOT_MAPPED && - target_addr >= atomic_read(&kvm->online_vcpus)) + !kvm_get_vcpu_by_id(kvm, target_addr)) return -EINVAL; collection = find_collection(its, coll_id); -- Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel