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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8F03CA0ECF for ; Tue, 12 Sep 2023 13:14:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235423AbjILNOT (ORCPT ); Tue, 12 Sep 2023 09:14:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235522AbjILNOF (ORCPT ); Tue, 12 Sep 2023 09:14:05 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70D361996; Tue, 12 Sep 2023 06:06:12 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 196E1C433C8; Tue, 12 Sep 2023 13:06:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694523972; bh=PBatigLooCafkXd5Xk10QKKr4lnQGUF685h7vHWrU54=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=tJ5sy9g9yhlRyrigQHP7XUtlSnxcLPWilG+U71PTzBFN0NBmLLM6SW0liYkLAjPuV z+jBkOGydGu9kAP+RG9SUXkQ4wW7Zcf+zuF+3yA4ZCAzlpRqf1lTE6zVqL1vpyFqJL YbeJhD9wM5bR5K5zVV1iGozYmeCVA9N/XqkFlH4A84DxoYrxXdss/qjmGW/TnUv0/B yLP9dtdQRGDZjpRqzgdtZiW8NP2xDbxMdDO0YtgDrwfyBCARsEisHFZFDrbPHsW1A5 dYUZzbXlKkOy37mrztMblKeGw1fjDYJpyK1x5QT6Jm+WmCQu5PxirujdZWUv9+0Bx1 HgOkJJQ9dUZGQ== Received: from [104.132.96.100] (helo=wait-a-minute.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 1qg35l-00CGuA-5R; Tue, 12 Sep 2023 14:06:09 +0100 Date: Tue, 12 Sep 2023 14:06:03 +0100 Message-ID: <87h6nz4k3o.wl-maz@kernel.org> From: Marc Zyngier To: zhaoxu Cc: oliver.upton@linux.dev, james.morse@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, zhouyibo@bytedance.com, zhouliang.001@bytedance.com Subject: Re: [RFC v2] KVM: arm/arm64: optimize vSGI injection performance In-Reply-To: <28610076-6ac7-4004-8479-e0005ff96c63@bytedance.com> References: <20230825015811.5292-1-zhaoxu.35@bytedance.com> <86o7iidzwb.wl-maz@kernel.org> <28610076-6ac7-4004-8479-e0005ff96c63@bytedance.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/28.2 (x86_64-pc-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: 104.132.96.100 X-SA-Exim-Rcpt-To: zhaoxu.35@bytedance.com, oliver.upton@linux.dev, james.morse@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, zhouyibo@bytedance.com, zhouliang.001@bytedance.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 12 Sep 2023 05:13:19 +0100, zhaoxu wrote: > > > > On 2023/9/4 17:57, Marc Zyngier wrote: > > On Fri, 25 Aug 2023 02:58:11 +0100, > > Xu Zhao wrote: > [...] > >> - unsigned long affinity; > >> - int level0; > >> + u64 aff; > >> - /* > >> - * Split the current VCPU's MPIDR into affinity level 0 and the > >> - * rest as this is what we have to compare against. > >> - */ > >> - affinity = kvm_vcpu_get_mpidr_aff(vcpu); > >> - level0 = MPIDR_AFFINITY_LEVEL(affinity, 0); > >> - affinity &= ~MPIDR_LEVEL_MASK; > >> + /* aff3 - aff1 */ > >> + aff = (((reg) & ICC_SGI1R_AFFINITY_3_MASK) >> ICC_SGI1R_AFFINITY_3_SHIFT) << 16 | > >> + (((reg) & ICC_SGI1R_AFFINITY_2_MASK) >> ICC_SGI1R_AFFINITY_2_SHIFT) << 8 | > >> + (((reg) & ICC_SGI1R_AFFINITY_1_MASK) >> ICC_SGI1R_AFFINITY_1_SHIFT); > > > > Here, you assume that you can directly map a vcpu index to an > > affinity. It would be awesome if that was the case. However, this is > > only valid at reset time, and userspace is perfectly allowed to change > > this mapping by writing to the vcpu's MPIDR_EL1. > > > > So this won't work at all if userspace wants to set its own specific > > CPU numbering. > > > > M. > > > Hi Marc, > > Yes, i don't think too much about userspace can change MPIDR value, I > checked the source code of qemu, qemu create vcpu sequentially, so in > this case, vcpu_id is equivalent to vcpu_idx which means vcpu_id > represents the position in vcpu array. The problem is that this is only a convention, and userspace is totally free to use vcpu_id in a different way. Note that we have other bugs in the KVM code that treat them interchangeably, but I'm trying to fix that. > These days, I'm still thinking about whether it is because of the > content related to future vcpu hot-plug feature that vcpu_id can be > modified, but now it seems that's not entirely the case. There are 3 levels of identification: - vcpu_idx, which is an internal KVM index that userspace is not suppose to rely on (or know) - vcpu_id, which is provided by userspace as a CPU number, and from which we derive the default MPIDR_EL1 value. This is used all over the code to identify a CPU from userspace. - MPIDR_EL1, which is how the architecture identifies a CPU. For CPU hotplug, I expect usespace to set vcpu_id and MPIDR_EL1 as it sees fit, knowing that the vpcu must have been allocated upfront (and vcpu_idx set). > I have read your latest patch and have been deeply inspired, and > Thanks for agreeing with this issue. No worries. I'd appreciate you testing it and reporting whether this matches the results you are observing with your own patch. Thanks, M. -- Without deviation from the norm, progress is not possible.