Received: by 2002:ac2:4c26:0:0:0:0:0 with SMTP id u6csp526287lfq; Thu, 17 Sep 2020 05:17:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMLdH63PCZge+UKFypdAwjqCbM99rMUhHajzmdLclL+FWrTcwZnelsz0ORgve9oQts3Kt1 X-Received: by 2002:a05:6902:72b:: with SMTP id l11mr9541646ybt.419.1600345056695; Thu, 17 Sep 2020 05:17:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600345056; cv=none; d=google.com; s=arc-20160816; b=mkrg8UnrazWd4vabLOlx2rlR8oUrjy25lJU5jz1T4et50s2mrpW3AcQkGJoBKMtEcf pWSCyXTEmSgXrw/Bd+be/06I4PmbIhLlLh/7QgO1Gjg059326mZrAqh/Ax7PNd90TGPp xYUEj7EmRElc8SSIkcs8Dh0ocHyzTG9fNkhBbtBEZnxFKaTEV92DHjpTXZTD/qxk5x8S iUR0Zavh226M7xwZ7m+TIJ+UDj+ulQK/lNrcqJ4JpjAaTkU145E3VCG37tdJ7G4TfwL9 FXYzkEGaNO1dVzqDiyoVAKIXR8oR8YP9/Y+zNEifqOEdEB1uPMN4BMJuAu1QK/znp6g8 zoqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject; bh=r7INStwlvrBRDNBIaLxnGq5lr5ccF8V+/KKoeqDJp1Q=; b=b0DIJeWxZ8QyIjog2l2X1yuMVCcFTBbE8XbH6vkT6ugjno5DAWipoSBzO5RwYGDTVj N1SBwM3UaYeUzgJViIqtrBZAvFVuXrxwvHtqL+eIsjHSra7ouitYzFO/aZrQLf11Es1P FW80N8UfyntO0DXm6QapJJbtpMmEHK2ClB1tjOjvLcXScIoFCwFtUjVeHiLtSYIR/agM ZAn4TQXcNYufNSShKZp9IPrbg5+GSp+ADmYZI6vhGJ+Y9Q1IAzMpzO6H5cyLmwRK4vtx h9YuQOxLnpHrH79STiKJDxEjY0i0OoamysYF3TAQRbyzVNSRNRlC/MaYQaVGJXVj/Xwi ENjg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o81si26468290ybc.465.2020.09.17.05.17.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 17 Sep 2020 05:17:36 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org" Received: from localhost ([::1]:46700 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIsr2-0005cz-31 for alex.bennee@linaro.org; Thu, 17 Sep 2020 08:17:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33700) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIsqt-0005bW-9T; Thu, 17 Sep 2020 08:17:27 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4710 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIsqp-0002oN-P0; Thu, 17 Sep 2020 08:17:26 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 7D2577891D1007D95006; Thu, 17 Sep 2020 20:17:12 +0800 (CST) Received: from [10.174.185.104] (10.174.185.104) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Thu, 17 Sep 2020 20:17:03 +0800 Subject: Re: [RFC PATCH 02/12] target/arm/kvm64: make MPIDR consistent with CPU Topology To: Andrew Jones References: <20200917032033.2020-1-fangying1@huawei.com> <20200917032033.2020-3-fangying1@huawei.com> <20200917075330.7sx3xm7gd4mwqqtq@kamzik.brq.redhat.com> From: Ying Fang Message-ID: <0e8aa66e-2440-07a5-1fa6-5b42ac757a8a@huawei.com> Date: Thu, 17 Sep 2020 20:17:02 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20200917075330.7sx3xm7gd4mwqqtq@kamzik.brq.redhat.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.185.104] X-CFilter-Loop: Reflected Received-SPF: pass client-ip=45.249.212.190; envelope-from=fangying1@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/17 08:17:13 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, zhang.zhanghailiang@huawei.com, qemu-devel@nongnu.org, alex.chen@huawei.com, shannon.zhaosl@gmail.com, qemu-arm@nongnu.org, alistair.francis@wdc.com, imammedo@redhat.com Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-arm" X-TUID: 8uB+KQrYVity On 9/17/2020 3:53 PM, Andrew Jones wrote: > On Thu, Sep 17, 2020 at 11:20:23AM +0800, Ying Fang wrote: >> MPIDR helps to provide an additional PE identification in a multiprocessor >> system. This patch adds support for setting MPIDR from userspace, so that >> MPIDR is consistent with CPU topology configured. >> >> Signed-off-by: Ying Fang >> --- >> target/arm/kvm64.c | 46 ++++++++++++++++++++++++++++++++++++++-------- >> 1 file changed, 38 insertions(+), 8 deletions(-) >> >> diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c >> index ef1e960285..fcce261a10 100644 >> --- a/target/arm/kvm64.c >> +++ b/target/arm/kvm64.c >> @@ -757,10 +757,46 @@ static int kvm_arm_sve_set_vls(CPUState *cs) >> >> #define ARM_CPU_ID_MPIDR 3, 0, 0, 0, 5 >> >> +static int kvm_arm_set_mp_affinity(CPUState *cs) >> +{ >> + uint64_t mpidr; >> + ARMCPU *cpu = ARM_CPU(cs); >> + >> + if (kvm_check_extension(kvm_state, KVM_CAP_ARM_MP_AFFINITY)) { >> + /* Make MPIDR consistent with CPU topology */ >> + MachineState *ms = MACHINE(qdev_get_machine()); >> + >> + mpidr = (kvm_arch_vcpu_id(cs) % ms->smp.threads) << ARM_AFF0_SHIFT; > > We should query KVM first to determine if it wants guests to see their PEs > as threads or not. If not, and ms->smp.threads is > 1, then that's an > error. And, in any case, if ms->smp.threads == 1, then we shouldn't waste > aff0 on it, as that could reduce IPI broadcast performance. Yes, good catch. Should check against smp.threads before filling the MPIDR value. > >> + mpidr |= ((kvm_arch_vcpu_id(cs) / ms->smp.threads % ms->smp.cores) >> + & 0xff) << ARM_AFF1_SHIFT; >> + mpidr |= (kvm_arch_vcpu_id(cs) / (ms->smp.cores * ms->smp.threads) >> + & 0xff) << ARM_AFF2_SHIFT; >> + >> + /* Override mp affinity when KVM is in use */ >> + cpu->mp_affinity = mpidr & ARM64_AFFINITY_MASK; >> + >> + /* Bit 31 is RES1 indicates the ARMv7 Multiprocessing Extensions */ >> + mpidr |= (1ULL << 31); >> + return kvm_vcpu_ioctl(cs, KVM_ARM_SET_MP_AFFINITY, &mpidr); >> + } else { >> + /* >> + * When KVM_CAP_ARM_MP_AFFINITY is not supported, it means KVM has its >> + * own idea about MPIDR assignment, so we override our defaults with >> + * what we get from KVM. >> + */ >> + int ret = kvm_get_one_reg(cs, ARM64_SYS_REG(ARM_CPU_ID_MPIDR), &mpidr); >> + if (ret) { >> + error_report("failed to set MPIDR"); > > We don't need this error, kvm_get_one_reg() has trace support already. > Anyway, the wording is wrong since it says 'set' instead of 'get'. Yes, my careless, I will fix it. > >> + return ret; >> + } >> + cpu->mp_affinity = mpidr & ARM32_AFFINITY_MASK; >> + return ret; >> + } >> +} >> + >> int kvm_arch_init_vcpu(CPUState *cs) >> { >> int ret; >> - uint64_t mpidr; >> ARMCPU *cpu = ARM_CPU(cs); >> CPUARMState *env = &cpu->env; >> >> @@ -814,16 +850,10 @@ int kvm_arch_init_vcpu(CPUState *cs) >> } >> } >> >> - /* >> - * When KVM is in use, PSCI is emulated in-kernel and not by qemu. >> - * Currently KVM has its own idea about MPIDR assignment, so we >> - * override our defaults with what we get from KVM. >> - */ >> - ret = kvm_get_one_reg(cs, ARM64_SYS_REG(ARM_CPU_ID_MPIDR), &mpidr); >> + ret = kvm_arm_set_mp_affinity(cs); >> if (ret) { >> return ret; >> } >> - cpu->mp_affinity = mpidr & ARM64_AFFINITY_MASK; >> >> kvm_arm_init_debug(cs); >> >> -- >> 2.23.0 >> >> > > Thanks, > drew > > . >