From nobody Tue Feb 10 01:30:43 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513791569831983.7425211822373; Wed, 20 Dec 2017 09:39:29 -0800 (PST) Received: from localhost ([::1]:60548 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRiL0-0007nI-Nc for importer@patchew.org; Wed, 20 Dec 2017 12:39:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56461) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRhyQ-0004jT-ET for qemu-devel@nongnu.org; Wed, 20 Dec 2017 12:16:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRhyM-0007GV-SF for qemu-devel@nongnu.org; Wed, 20 Dec 2017 12:16:06 -0500 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]:33598) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eRhyM-0007G6-Hl for qemu-devel@nongnu.org; Wed, 20 Dec 2017 12:16:02 -0500 Received: by mail-wr0-x242.google.com with SMTP id v21so12206703wrc.0 for ; Wed, 20 Dec 2017 09:16:02 -0800 (PST) Received: from 640k.lan (dynamic-adsl-78-12-251-125.clienti.tiscali.it. [78.12.251.125]) by smtp.gmail.com with ESMTPSA id f125sm2751101wme.45.2017.12.20.09.16.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Dec 2017 09:16:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=HH8jAd6ApKsaep6STCiDUVU2eqkznAdNRMGRWWt9OwI=; b=B7Jsu4VsFfQ6Mt+X3az124zNz1+5ED0leALU930V5rUUwmhHqpoUJczFN1m20lsU+w W01M9e8E9VU8sMtWsYFTIf5g8tuJFn43Gf5C9ILPkl9CYLzR9540+BVEUjBOoHorRFy4 Chrg1G28zwVJgy47pseU1Qe2XskSUxEdhHH2ijbzMbtE30BDxxDFFrVnTomPgkga4CSo A+khlXnAVRw7cmrXJmN7oL8J8owKWwn+VdjDdDvxyLIeiidTHN89VhECguRQ2cIIfkFV 757CobfJocjJ04xsUBgH55eh7h8KYZXCHfF3oqSbW2lK6prwOIyjm2QU1etfftbzc8HH jyUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=HH8jAd6ApKsaep6STCiDUVU2eqkznAdNRMGRWWt9OwI=; b=Eixmc+Q1Gw1GPQDwss5wMhah0KLv+ICPTog7H2lo9bRvZmMWISPH3N5x05vwNi5iRc uNgniWJOJ+jEf/fpEaoFJHUYFDoYvT5Qz4yHprEZ9LW2L71P5LKO2YtecFCNdjQpO/aB edOOw9r0szFz4JLKAJ6z5BS10XRiU0iKEm26pVyafv5JjmSeN7zpB1pxAXTCHnEb345t JJ7nWP13xWjmYoeLcpmBKHS1yzKLrgqK6IalLIGFPC/5bWxI2k3NS/qle4iQhrFnEQwf +dmWfobdZ2DESLktaehiV5h2iKmiIfuYF6qqv7oA/QlO9QbGrk+3FM6s/T0iSVE28Wnf Ncag== X-Gm-Message-State: AKGB3mKed7MjSL0o6twXuKeuDkwbLaRpwcE/eJZWgknkS8nTFs2Fqidn P/I1sGWiqLNhGhZzNEB4IB0x6hAR X-Google-Smtp-Source: ACJfBosSmNtOGtQc1bV1nk15vY/MA6b7LJlKijyVmPA1k3uCt43PpDFcgm/XhiNVftloWcHfj+NQJA== X-Received: by 10.223.136.184 with SMTP id f53mr8913425wrf.143.1513790161223; Wed, 20 Dec 2017 09:16:01 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 20 Dec 2017 18:14:37 +0100 Message-Id: <1513790098-9815-26-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1513790098-9815-1-git-send-email-pbonzini@redhat.com> References: <1513790098-9815-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::242 Subject: [Qemu-devel] [PULL 25/46] cpu: refactor cpu_address_space_init() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Xu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Xu Normally we create an address space for that CPU and pass that address space into the function. Let's just do it inside to unify address space creations. It'll simplify my next patch to rename those address spaces. Signed-off-by: Peter Xu Message-Id: <20171123092333.16085-3-peterx@redhat.com> Signed-off-by: Paolo Bonzini --- cpus.c | 5 +---- exec.c | 7 ++++++- include/exec/exec-all.h | 6 ++++-- target/arm/cpu.c | 13 +++---------- target/i386/cpu.c | 10 ++-------- 5 files changed, 16 insertions(+), 25 deletions(-) diff --git a/cpus.c b/cpus.c index 3740c4d..83700c1 100644 --- a/cpus.c +++ b/cpus.c @@ -1787,11 +1787,8 @@ void qemu_init_vcpu(CPUState *cpu) /* If the target cpu hasn't set up any address spaces itself, * give it the default one. */ - AddressSpace *as =3D g_new0(AddressSpace, 1); - - address_space_init(as, cpu->memory, "cpu-memory"); cpu->num_ases =3D 1; - cpu_address_space_init(cpu, as, 0); + cpu_address_space_init(cpu, 0, "cpu-memory", cpu->memory); } =20 if (kvm_enabled()) { diff --git a/exec.c b/exec.c index 3e7c57e..3ab515e 100644 --- a/exec.c +++ b/exec.c @@ -705,9 +705,14 @@ CPUState *qemu_get_cpu(int index) } =20 #if !defined(CONFIG_USER_ONLY) -void cpu_address_space_init(CPUState *cpu, AddressSpace *as, int asidx) +void cpu_address_space_init(CPUState *cpu, int asidx, + const char *prefix, MemoryRegion *mr) { CPUAddressSpace *newas; + AddressSpace *as =3D g_new0(AddressSpace, 1); + + assert(mr); + address_space_init(as, mr, prefix); =20 /* Target code should have set num_ases before calling us */ assert(asidx < cpu->num_ases); diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 0f51c92..b37f7d8 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -74,8 +74,9 @@ void cpu_reloading_memory_map(void); /** * cpu_address_space_init: * @cpu: CPU to add this address space to - * @as: address space to add * @asidx: integer index of this address space + * @prefix: prefix to be used as name of address space + * @mr: the root memory region of address space * * Add the specified address space to the CPU's cpu_ases list. * The address space added with @asidx 0 is the one used for the @@ -89,7 +90,8 @@ void cpu_reloading_memory_map(void); * * Note that with KVM only one address space is supported. */ -void cpu_address_space_init(CPUState *cpu, AddressSpace *as, int asidx); +void cpu_address_space_init(CPUState *cpu, int asidx, + const char *prefix, MemoryRegion *mr); #endif =20 #if !defined(CONFIG_USER_ONLY) && defined(CONFIG_TCG) diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 7f7a3d1..cc1856c 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -705,9 +705,6 @@ static void arm_cpu_realizefn(DeviceState *dev, Error *= *errp) CPUARMState *env =3D &cpu->env; int pagebits; Error *local_err =3D NULL; -#ifndef CONFIG_USER_ONLY - AddressSpace *as; -#endif =20 cpu_exec_realizefn(cs, &local_err); if (local_err !=3D NULL) { @@ -912,21 +909,17 @@ static void arm_cpu_realizefn(DeviceState *dev, Error= **errp) =20 #ifndef CONFIG_USER_ONLY if (cpu->has_el3 || arm_feature(env, ARM_FEATURE_M_SECURITY)) { - as =3D g_new0(AddressSpace, 1); - cs->num_ases =3D 2; =20 if (!cpu->secure_memory) { cpu->secure_memory =3D cs->memory; } - address_space_init(as, cpu->secure_memory, "cpu-secure-memory"); - cpu_address_space_init(cs, as, ARMASIdx_S); + cpu_address_space_init(cs, ARMASIdx_S, "cpu-secure-memory", + cpu->secure_memory); } else { cs->num_ases =3D 1; } - as =3D g_new0(AddressSpace, 1); - address_space_init(as, cs->memory, "cpu-memory"); - cpu_address_space_init(cs, as, ARMASIdx_NS); + cpu_address_space_init(cs, ARMASIdx_NS, "cpu-memory", cs->memory); #endif =20 qemu_init_vcpu(cs); diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 325b52e..b069eaf 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -3736,11 +3736,6 @@ static void x86_cpu_realizefn(DeviceState *dev, Erro= r **errp) =20 #ifndef CONFIG_USER_ONLY if (tcg_enabled()) { - AddressSpace *as_normal =3D g_new0(AddressSpace, 1); - AddressSpace *as_smm =3D g_new(AddressSpace, 1); - - address_space_init(as_normal, cs->memory, "cpu-memory"); - cpu->cpu_as_mem =3D g_new(MemoryRegion, 1); cpu->cpu_as_root =3D g_new(MemoryRegion, 1); =20 @@ -3755,11 +3750,10 @@ static void x86_cpu_realizefn(DeviceState *dev, Err= or **errp) get_system_memory(), 0, ~0ull); memory_region_add_subregion_overlap(cpu->cpu_as_root, 0, cpu->cpu_= as_mem, 0); memory_region_set_enabled(cpu->cpu_as_mem, true); - address_space_init(as_smm, cpu->cpu_as_root, "CPU"); =20 cs->num_ases =3D 2; - cpu_address_space_init(cs, as_normal, 0); - cpu_address_space_init(cs, as_smm, 1); + cpu_address_space_init(cs, 0, "cpu-memory", cs->memory); + cpu_address_space_init(cs, 1, "cpu-smm", cpu->cpu_as_root); =20 /* ... SMRAM with higher priority, linked from /machine/smram. */ cpu->machine_done.notify =3D x86_cpu_machine_done; --=20 1.8.3.1