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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (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 2224EE80A86 for ; Wed, 27 Sep 2023 05:17:48 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qlMuz-0007PU-Bw; Wed, 27 Sep 2023 01:17:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qlMuw-0007P5-45 for qemu-devel@nongnu.org; Wed, 27 Sep 2023 01:16:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qlMuo-0002ld-V0 for qemu-devel@nongnu.org; Wed, 27 Sep 2023 01:16:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695791808; 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=T9gst6RwcXqh0Bu3NaQqSeNqWv5R+lCaxt8OMV4Jpc0=; b=M4VHQoTU/+/I2iSOpEFb1L07N2k/D4V2NdHCLt3orDLWu0FoQTfJYPVjfwNZinaF7+j90x Hm9xhi8wjYXIcYW+B7pfc0PtRsw+Z6TMLWHddnxSESn7OVTvi3xo7hbdz77EkgYtB/fHkd QntOHM9NCgl0u/L5xXnpdBtornKS8dw= Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-689-3S96ZRHZMAuLh1LjvgjCOA-1; Wed, 27 Sep 2023 01:16:47 -0400 X-MC-Unique: 3S96ZRHZMAuLh1LjvgjCOA-1 Received: by mail-pf1-f199.google.com with SMTP id d2e1a72fcca58-69302c30543so5474550b3a.1 for ; Tue, 26 Sep 2023 22:16:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695791806; x=1696396606; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=T9gst6RwcXqh0Bu3NaQqSeNqWv5R+lCaxt8OMV4Jpc0=; b=X0tSH1If2az3wqwEgkryjxO0KU4i51DNF+G0+Jnw1MqN4sF0h/gQwpy81vHIkBK7gY ypqsdE3HgAdTU43680ZnIrb4AA+yphd2j4JdGZ4+ur7s12CiPVGNrnANzsicKghfz8bC 6E07+SAEvrAxv/1auIQRx8HgNnyesKbq35It9G+xYtc7n6phjxqeSPDDeo7OdHS3LRDT pZv5+smTQ/tVNTzjeO7VngK+dYMTIhhVlPb1URg4gXuZmd2tUHuIDMMW7bbfBqW7xZFp gHDA5E3sdRBRg5ulZqY/kodvS2Va0e3m7snSuasTvUfzSiBvtAa1jN1jV2ag6TLh+Ii/ Vj8A== X-Gm-Message-State: AOJu0Yx3FBNRXOCGWeEVztgy1jYxsMHi9zgn6zTC/6wJmbf724DS6Erx jHWtjJxXcwwDHxZ6vi2851ZZH1OVKRFkK2RkzQlKEzjHe0j0Ja3rZvnb+hOvP6DrBNi7F+B/uRf Os9b/Y5vFloKduug= X-Received: by 2002:a05:6a00:1a13:b0:690:41a1:9b67 with SMTP id g19-20020a056a001a1300b0069041a19b67mr1144232pfv.9.1695791806023; Tue, 26 Sep 2023 22:16:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHEMvpBMME1R/4TL9qKUQFdPByjrS+Bbe3HeqYuu/VKGxDX50rlYOFlcGKwW/DDlPhbeIfhzg== X-Received: by 2002:a05:6a00:1a13:b0:690:41a1:9b67 with SMTP id g19-20020a056a001a1300b0069041a19b67mr1144200pfv.9.1695791805652; Tue, 26 Sep 2023 22:16:45 -0700 (PDT) Received: from ?IPV6:2001:8003:e5b0:9f00:dbbc:1945:6e65:ec5? ([2001:8003:e5b0:9f00:dbbc:1945:6e65:ec5]) by smtp.gmail.com with ESMTPSA id x23-20020aa793b7000000b00690204b5a8csm11221897pff.12.2023.09.26.22.16.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 26 Sep 2023 22:16:44 -0700 (PDT) Message-ID: Date: Wed, 27 Sep 2023 15:16:30 +1000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH RFC V2 03/37] hw/arm/virt: Move setting of common CPU properties in a function Content-Language: en-US To: Salil Mehta , qemu-devel@nongnu.org, qemu-arm@nongnu.org Cc: maz@kernel.org, jean-philippe@linaro.org, jonathan.cameron@huawei.com, lpieralisi@kernel.org, peter.maydell@linaro.org, richard.henderson@linaro.org, imammedo@redhat.com, andrew.jones@linux.dev, david@redhat.com, philmd@linaro.org, eric.auger@redhat.com, will@kernel.org, ardb@kernel.org, oliver.upton@linux.dev, pbonzini@redhat.com, mst@redhat.com, rafael@kernel.org, borntraeger@linux.ibm.com, alex.bennee@linaro.org, linux@armlinux.org.uk, darren@os.amperecomputing.com, ilkka@os.amperecomputing.com, vishnu@os.amperecomputing.com, karl.heubaum@oracle.com, miguel.luis@oracle.com, salil.mehta@opnsrc.net, zhukeqian1@huawei.com, wangxiongfeng2@huawei.com, wangyanan55@huawei.com, jiakernel2@gmail.com, maobibo@loongson.cn, lixianglai@loongson.cn References: <20230926100436.28284-1-salil.mehta@huawei.com> <20230926100436.28284-4-salil.mehta@huawei.com> From: Gavin Shan In-Reply-To: <20230926100436.28284-4-salil.mehta@huawei.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=170.10.129.124; envelope-from=gshan@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, NICE_REPLY_A=-1.473, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Hi Salil, On 9/26/23 20:04, Salil Mehta wrote: > Factor out CPU properties code common for {hot,cold}-plugged CPUs. This allows > code reuse. > > Signed-off-by: Salil Mehta > --- > hw/arm/virt.c | 220 ++++++++++++++++++++++++++---------------- > include/hw/arm/virt.h | 4 + > 2 files changed, 140 insertions(+), 84 deletions(-) > > diff --git a/hw/arm/virt.c b/hw/arm/virt.c > index 57fe97c242..0eb6bf5a18 100644 > --- a/hw/arm/virt.c > +++ b/hw/arm/virt.c > @@ -2018,16 +2018,130 @@ static void virt_cpu_post_init(VirtMachineState *vms, MemoryRegion *sysmem) > } > } > > +static void virt_cpu_set_properties(Object *cpuobj, const CPUArchId *cpu_slot, > + Error **errp) > +{ > + MachineState *ms = MACHINE(qdev_get_machine()); > + VirtMachineState *vms = VIRT_MACHINE(ms); > + Error *local_err = NULL; > + VirtMachineClass *vmc; > + > + vmc = VIRT_MACHINE_GET_CLASS(ms); > + > + /* now, set the cpu object property values */ > + numa_cpu_pre_plug(cpu_slot, DEVICE(cpuobj), &local_err); > + if (local_err) { > + goto out; > + } > + > + object_property_set_int(cpuobj, "mp-affinity", cpu_slot->arch_id, NULL); > + > + if (!vms->secure) { > + object_property_set_bool(cpuobj, "has_el3", false, NULL); > + } > + > + if (!vms->virt && object_property_find(cpuobj, "has_el2")) { > + object_property_set_bool(cpuobj, "has_el2", false, NULL); > + } > + > + if (vmc->kvm_no_adjvtime && > + object_property_find(cpuobj, "kvm-no-adjvtime")) { > + object_property_set_bool(cpuobj, "kvm-no-adjvtime", true, NULL); > + } > + > + if (vmc->no_kvm_steal_time && > + object_property_find(cpuobj, "kvm-steal-time")) { > + object_property_set_bool(cpuobj, "kvm-steal-time", false, NULL); > + } > + > + if (vmc->no_pmu && object_property_find(cpuobj, "pmu")) { > + object_property_set_bool(cpuobj, "pmu", false, NULL); > + } > + > + if (vmc->no_tcg_lpa2 && object_property_find(cpuobj, "lpa2")) { > + object_property_set_bool(cpuobj, "lpa2", false, NULL); > + } > + > + if (object_property_find(cpuobj, "reset-cbar")) { > + object_property_set_int(cpuobj, "reset-cbar", > + vms->memmap[VIRT_CPUPERIPHS].base, > + &local_err); > + if (local_err) { > + goto out; > + } > + } > + > + /* link already initialized {secure,tag}-memory regions to this cpu */ > + object_property_set_link(cpuobj, "memory", OBJECT(vms->sysmem), &local_err); > + if (local_err) { > + goto out; > + } > + > + if (vms->secure) { > + object_property_set_link(cpuobj, "secure-memory", > + OBJECT(vms->secure_sysmem), &local_err); > + if (local_err) { > + goto out; > + } > + } > + > + if (vms->mte) { > + if (!object_property_find(cpuobj, "tag-memory")) { > + error_setg(&local_err, "MTE requested, but not supported " > + "by the guest CPU"); > + if (local_err) { > + goto out; > + } > + } > + > + object_property_set_link(cpuobj, "tag-memory", OBJECT(vms->tag_sysmem), > + &local_err); > + if (local_err) { > + goto out; > + } > + > + if (vms->secure) { > + object_property_set_link(cpuobj, "secure-tag-memory", > + OBJECT(vms->secure_tag_sysmem), > + &local_err); > + if (local_err) { > + goto out; > + } > + } > + } > + > + /* > + * RFC: Question: this must only be called for the hotplugged cpus. For the > + * cold booted secondary cpus this is being taken care in arm_load_kernel() > + * in boot.c. Perhaps we should remove that code now? > + */ > + if (vms->psci_conduit != QEMU_PSCI_CONDUIT_DISABLED) { > + object_property_set_int(cpuobj, "psci-conduit", vms->psci_conduit, > + NULL); > + > + /* Secondary CPUs start in PSCI powered-down state */ > + if (CPU(cpuobj)->cpu_index > 0) { > + object_property_set_bool(cpuobj, "start-powered-off", true, NULL); > + } > + } > + > +out: > + if (local_err) { > + error_propagate(errp, local_err); > + } > + return; ^^^^^^ It's not needed obviously :) > +} > + > static void machvirt_init(MachineState *machine) > { > VirtMachineState *vms = VIRT_MACHINE(machine); > VirtMachineClass *vmc = VIRT_MACHINE_GET_CLASS(machine); > MachineClass *mc = MACHINE_GET_CLASS(machine); > const CPUArchIdList *possible_cpus; > - MemoryRegion *sysmem = get_system_memory(); > + MemoryRegion *secure_tag_sysmem = NULL; > MemoryRegion *secure_sysmem = NULL; > MemoryRegion *tag_sysmem = NULL; > - MemoryRegion *secure_tag_sysmem = NULL; > + MemoryRegion *sysmem; > int n, virt_max_cpus; > bool firmware_loaded; > bool aarch64 = true; > @@ -2071,6 +2185,8 @@ static void machvirt_init(MachineState *machine) > */ > finalize_gic_version(vms); > > + sysmem = vms->sysmem = get_system_memory(); > + > if (vms->secure) { > /* > * The Secure view of the world is the same as the NonSecure, > @@ -2078,7 +2194,7 @@ static void machvirt_init(MachineState *machine) > * containing the system memory at low priority; any secure-only > * devices go in at higher priority and take precedence. > */ > - secure_sysmem = g_new(MemoryRegion, 1); > + secure_sysmem = vms->secure_sysmem = g_new(MemoryRegion, 1); > memory_region_init(secure_sysmem, OBJECT(machine), "secure-memory", > UINT64_MAX); > memory_region_add_subregion_overlap(secure_sysmem, 0, sysmem, -1); > @@ -2151,6 +2267,23 @@ static void machvirt_init(MachineState *machine) > exit(1); > } > > + if (vms->mte) { > + /* Create the memory region only once, but link to all cpus later */ > + tag_sysmem = vms->tag_sysmem = g_new(MemoryRegion, 1); > + memory_region_init(tag_sysmem, OBJECT(machine), > + "tag-memory", UINT64_MAX / 32); > + > + if (vms->secure) { > + secure_tag_sysmem = vms->secure_tag_sysmem = g_new(MemoryRegion, 1); > + memory_region_init(secure_tag_sysmem, OBJECT(machine), > + "secure-tag-memory", UINT64_MAX / 32); > + > + /* As with ram, secure-tag takes precedence over tag. */ > + memory_region_add_subregion_overlap(secure_tag_sysmem, 0, > + tag_sysmem, -1); > + } > + } > + > create_fdt(vms); > > assert(possible_cpus->len == max_cpus); > @@ -2163,15 +2296,10 @@ static void machvirt_init(MachineState *machine) > } > > cpuobj = object_new(possible_cpus->cpus[n].type); > - object_property_set_int(cpuobj, "mp-affinity", > - possible_cpus->cpus[n].arch_id, NULL); > > cs = CPU(cpuobj); > cs->cpu_index = n; > > - numa_cpu_pre_plug(&possible_cpus->cpus[cs->cpu_index], DEVICE(cpuobj), > - &error_fatal); > - > aarch64 &= object_property_get_bool(cpuobj, "aarch64", NULL); > object_property_set_int(cpuobj, "socket-id", > virt_get_socket_id(machine, n), NULL); > @@ -2182,82 +2310,6 @@ static void machvirt_init(MachineState *machine) > object_property_set_int(cpuobj, "thread-id", > virt_get_thread_id(machine, n), NULL); > > - if (!vms->secure) { > - object_property_set_bool(cpuobj, "has_el3", false, NULL); > - } > - > - if (!vms->virt && object_property_find(cpuobj, "has_el2")) { > - object_property_set_bool(cpuobj, "has_el2", false, NULL); > - } > - > - if (vmc->kvm_no_adjvtime && > - object_property_find(cpuobj, "kvm-no-adjvtime")) { > - object_property_set_bool(cpuobj, "kvm-no-adjvtime", true, NULL); > - } > - > - if (vmc->no_kvm_steal_time && > - object_property_find(cpuobj, "kvm-steal-time")) { > - object_property_set_bool(cpuobj, "kvm-steal-time", false, NULL); > - } > - > - if (vmc->no_pmu && object_property_find(cpuobj, "pmu")) { > - object_property_set_bool(cpuobj, "pmu", false, NULL); > - } > - > - if (vmc->no_tcg_lpa2 && object_property_find(cpuobj, "lpa2")) { > - object_property_set_bool(cpuobj, "lpa2", false, NULL); > - } > - > - if (object_property_find(cpuobj, "reset-cbar")) { > - object_property_set_int(cpuobj, "reset-cbar", > - vms->memmap[VIRT_CPUPERIPHS].base, > - &error_abort); > - } > - > - object_property_set_link(cpuobj, "memory", OBJECT(sysmem), > - &error_abort); > - if (vms->secure) { > - object_property_set_link(cpuobj, "secure-memory", > - OBJECT(secure_sysmem), &error_abort); > - } > - > - if (vms->mte) { > - /* Create the memory region only once, but link to all cpus. */ > - if (!tag_sysmem) { > - /* > - * The property exists only if MemTag is supported. > - * If it is, we must allocate the ram to back that up. > - */ > - if (!object_property_find(cpuobj, "tag-memory")) { > - error_report("MTE requested, but not supported " > - "by the guest CPU"); > - exit(1); > - } > - > - tag_sysmem = g_new(MemoryRegion, 1); > - memory_region_init(tag_sysmem, OBJECT(machine), > - "tag-memory", UINT64_MAX / 32); > - > - if (vms->secure) { > - secure_tag_sysmem = g_new(MemoryRegion, 1); > - memory_region_init(secure_tag_sysmem, OBJECT(machine), > - "secure-tag-memory", UINT64_MAX / 32); > - > - /* As with ram, secure-tag takes precedence over tag. */ > - memory_region_add_subregion_overlap(secure_tag_sysmem, 0, > - tag_sysmem, -1); > - } > - } > - > - object_property_set_link(cpuobj, "tag-memory", OBJECT(tag_sysmem), > - &error_abort); > - if (vms->secure) { > - object_property_set_link(cpuobj, "secure-tag-memory", > - OBJECT(secure_tag_sysmem), > - &error_abort); > - } > - } > - > qdev_realize(DEVICE(cpuobj), NULL, &error_fatal); > object_unref(cpuobj); > } > diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h > index e1ddbea96b..13163adb07 100644 > --- a/include/hw/arm/virt.h > +++ b/include/hw/arm/virt.h > @@ -148,6 +148,10 @@ struct VirtMachineState { > DeviceState *platform_bus_dev; > FWCfgState *fw_cfg; > PFlashCFI01 *flash[2]; > + MemoryRegion *sysmem; > + MemoryRegion *secure_sysmem; > + MemoryRegion *tag_sysmem; > + MemoryRegion *secure_tag_sysmem; > bool secure; > bool highmem; > bool highmem_compact; Thanks, Gavin