Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp2580770rdb; Tue, 12 Sep 2023 06:24:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGQSCCJaTXazThegY+GOzyAUvPjhY0T5dtEuI3VDRb8YTGXhM8BR8Z3a3p+ZCXS1VNV8u9K X-Received: by 2002:a05:6a00:1490:b0:68a:5197:619f with SMTP id v16-20020a056a00149000b0068a5197619fmr16289221pfu.31.1694525080156; Tue, 12 Sep 2023 06:24:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694525080; cv=none; d=google.com; s=arc-20160816; b=em0oQd+fd2ZU5o1RzznSuaSjlRNtZgsCt4pQ0Xltcddu0pq9FFgctkg3TZg5vDh0hp 3ThvUHmE//eX+A3UX4RwylPN3SL9gE9wVKRyfBKC6M1AVzT5xwVn2R+zjqOqPyA4i4RQ eJhEMHEDbf9mfOyMbLZ9ejajvGuoi3nyJTNZdq5i21wmm5QLPaUmmWsfKZ2x0GzqDxkR 4c83Cihz1oWt4e9b3mO6JdoMz8aptvmR3Dgpw0gCFt/nVvjnlTCovuqFYuEV03FKWTT+ bKzRWLjMgSaGVFl0t7Wwd9VLlVT9xmknTBHKvmn2Q5H0z++rg0BuufUsrtTGn15DDv8w U5Wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature; bh=PBIX9ZlShOnKqzU6otPvLR/E0cTMIHmkgzmPArTtyoQ=; fh=Cur0Xn34eUhyRTJMF5rP6o1CQQ/JrEzdM24zXun/Jq4=; b=NiAnpwLCFPUoHFlVvsz6VM2XksQF2uAUsp+oEaVuGssm4K0vc1xfQdyNyAJcAyNTxo Mp/qqfSF4+2GlE6+MRgi/1inDANesuwVcAaHWoOHqkyh6f1Am5K3iouH0dsRGJIZ0SD6 bgztS5MR42/8hjT/DjyHlOpn9EJjTJp0FvrKb1/D4oJDSFkEcNgNYXKjFrIH9bZ1Kz5C C0f5yB7jdzxyBa47sxZq0nJPTP9RhQWD5tMOxCe3MONqXvnNOHt1tsUCKQHbnUecytiB /8debCrdlTuJAHDbwSBkxGux4UWzQDamLwfCeArXG3dniu84c/QAZ4Qg5R1a2VzE24Ce ViqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tJ5sy9g9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id f20-20020a63f114000000b00563f72935e3si7805047pgi.608.2023.09.12.06.24.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 06:24:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tJ5sy9g9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 3FF438075927; Tue, 12 Sep 2023 06:14:17 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.8 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235400AbjILNOS (ORCPT + 99 others); Tue, 12 Sep 2023 09:14:18 -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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 12 Sep 2023 06:14:17 -0700 (PDT) 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.