From nobody Mon Apr 29 07:32:41 2024 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; 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1511509076222964.8708456073919; Thu, 23 Nov 2017 23:37:56 -0800 (PST) Received: from localhost ([::1]:47604 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eI8YR-0005IK-Hi for importer@patchew.org; Fri, 24 Nov 2017 02:37:43 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52216) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eI8VN-0002zg-20 for qemu-devel@nongnu.org; Fri, 24 Nov 2017 02:34:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eI8VH-0004og-0A for qemu-devel@nongnu.org; Fri, 24 Nov 2017 02:34:33 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33750) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eI8VG-0004nS-NK for qemu-devel@nongnu.org; Fri, 24 Nov 2017 02:34:26 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C66613C40; Fri, 24 Nov 2017 07:34:25 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-111.nay.redhat.com [10.66.14.111]) by smtp.corp.redhat.com (Postfix) with ESMTP id ABFCB5E1C9; Fri, 24 Nov 2017 07:34:23 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Fri, 24 Nov 2017 15:34:15 +0800 Message-Id: <20171124073417.4342-2-peterx@redhat.com> In-Reply-To: <20171124073417.4342-1-peterx@redhat.com> References: <20171124073417.4342-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 24 Nov 2017 07:34:25 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 1/3] 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 Maydell , Eduardo Habkost , Alexey Kardashevskiy , peterx@redhat.com, Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- 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 114c29b6a0..ae9dbf9510 100644 --- a/cpus.c +++ b/cpus.c @@ -1778,11 +1778,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 03238a3449..d845542139 100644 --- a/exec.c +++ b/exec.c @@ -708,9 +708,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 0f51c92adb..b37f7d8d92 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 7f7a3d1e32..cc1856c32b 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 045d66191f..d5b58abecb 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 2.14.3 From nobody Mon Apr 29 07:32:41 2024 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; 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1511508965980111.98583659533813; Thu, 23 Nov 2017 23:36:05 -0800 (PST) Received: from localhost ([::1]:47598 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eI8Wd-0003ek-BR for importer@patchew.org; Fri, 24 Nov 2017 02:35:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52192) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eI8VK-0002y8-7k for qemu-devel@nongnu.org; Fri, 24 Nov 2017 02:34:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eI8VJ-0004py-D1 for qemu-devel@nongnu.org; Fri, 24 Nov 2017 02:34:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44050) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eI8VJ-0004pX-7R for qemu-devel@nongnu.org; Fri, 24 Nov 2017 02:34:29 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 578226A7C3; Fri, 24 Nov 2017 07:34:28 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-111.nay.redhat.com [10.66.14.111]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3AD825FFF2; Fri, 24 Nov 2017 07:34:26 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Fri, 24 Nov 2017 15:34:16 +0800 Message-Id: <20171124073417.4342-3-peterx@redhat.com> In-Reply-To: <20171124073417.4342-1-peterx@redhat.com> References: <20171124073417.4342-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 24 Nov 2017 07:34:28 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 2/3] cpu: suffix cpu address spaces with cpu index 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 Maydell , Eduardo Habkost , Alexey Kardashevskiy , peterx@redhat.com, Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Renaming cpu address space names so that they won't be the same when there are more than one. Signed-off-by: Peter Xu --- exec.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/exec.c b/exec.c index d845542139..41f89f8164 100644 --- a/exec.c +++ b/exec.c @@ -713,9 +713,12 @@ void cpu_address_space_init(CPUState *cpu, int asidx, { CPUAddressSpace *newas; AddressSpace *as =3D g_new0(AddressSpace, 1); + char *as_name; =20 assert(mr); - address_space_init(as, mr, prefix); + as_name =3D g_strdup_printf("%s-%d", prefix, cpu->cpu_index); + address_space_init(as, mr, as_name); + g_free(as_name); =20 /* Target code should have set num_ases before calling us */ assert(asidx < cpu->num_ases); --=20 2.14.3 From nobody Mon Apr 29 07:32:41 2024 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; 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1511509068821731.2697462696706; Thu, 23 Nov 2017 23:37:48 -0800 (PST) Received: from localhost ([::1]:47603 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eI8YN-0005Fm-Rt for importer@patchew.org; Fri, 24 Nov 2017 02:37:39 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52218) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eI8VN-0002zh-31 for qemu-devel@nongnu.org; Fri, 24 Nov 2017 02:34:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eI8VM-0004rP-0d for qemu-devel@nongnu.org; Fri, 24 Nov 2017 02:34:33 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46762) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eI8VL-0004qs-OH for qemu-devel@nongnu.org; Fri, 24 Nov 2017 02:34:31 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DF73EC05679B; Fri, 24 Nov 2017 07:34:30 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-111.nay.redhat.com [10.66.14.111]) by smtp.corp.redhat.com (Postfix) with ESMTP id C0BF61719E; Fri, 24 Nov 2017 07:34:28 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Fri, 24 Nov 2017 15:34:17 +0800 Message-Id: <20171124073417.4342-4-peterx@redhat.com> In-Reply-To: <20171124073417.4342-1-peterx@redhat.com> References: <20171124073417.4342-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 24 Nov 2017 07:34:30 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 3/3] cpu: put AddressSpace into CPUAddressSpace 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 Maydell , Eduardo Habkost , Alexey Kardashevskiy , peterx@redhat.com, Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Now we can put AddressSpace into CPUAddressSpace struct, then we don't need dynamic allocation of AddressSpaces. Suggested-by: Paolo Bonzini Signed-off-by: Peter Xu --- exec.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/exec.c b/exec.c index 41f89f8164..511217f38c 100644 --- a/exec.c +++ b/exec.c @@ -221,7 +221,7 @@ static MemoryRegion io_mem_watch; */ struct CPUAddressSpace { CPUState *cpu; - AddressSpace *as; + AddressSpace as; struct AddressSpaceDispatch *memory_dispatch; MemoryListener tcg_as_listener; }; @@ -712,10 +712,19 @@ void cpu_address_space_init(CPUState *cpu, int asidx, const char *prefix, MemoryRegion *mr) { CPUAddressSpace *newas; - AddressSpace *as =3D g_new0(AddressSpace, 1); + AddressSpace *as; char *as_name; =20 assert(mr); + + if (!cpu->cpu_ases) { + /* This should be setup before calling the function. */ + assert(cpu->num_ases > 0); + cpu->cpu_ases =3D g_new0(CPUAddressSpace, cpu->num_ases); + } + newas =3D &cpu->cpu_ases[asidx]; + as =3D &newas->as; + as_name =3D g_strdup_printf("%s-%d", prefix, cpu->cpu_index); address_space_init(as, mr, as_name); g_free(as_name); @@ -731,13 +740,7 @@ void cpu_address_space_init(CPUState *cpu, int asidx, /* KVM cannot currently support multiple address spaces. */ assert(asidx =3D=3D 0 || !kvm_enabled()); =20 - if (!cpu->cpu_ases) { - cpu->cpu_ases =3D g_new0(CPUAddressSpace, cpu->num_ases); - } - - newas =3D &cpu->cpu_ases[asidx]; newas->cpu =3D cpu; - newas->as =3D as; if (tcg_enabled()) { newas->tcg_as_listener.commit =3D tcg_commit; memory_listener_register(&newas->tcg_as_listener, as); @@ -747,7 +750,7 @@ void cpu_address_space_init(CPUState *cpu, int asidx, AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx) { /* Return the AddressSpace corresponding to the specified index */ - return cpu->cpu_ases[asidx].as; + return &cpu->cpu_ases[asidx].as; } #endif =20 @@ -830,7 +833,7 @@ static void breakpoint_invalidate(CPUState *cpu, target= _ulong pc) int asidx =3D cpu_asidx_from_attrs(cpu, attrs); if (phys !=3D -1) { /* Locks grabbed by tb_invalidate_phys_addr */ - tb_invalidate_phys_addr(cpu->cpu_ases[asidx].as, + tb_invalidate_phys_addr(cpu_get_address_space(cpu, asidx), phys | (pc & ~TARGET_PAGE_MASK)); } } @@ -2518,7 +2521,7 @@ static MemTxResult watch_mem_read(void *opaque, hwadd= r addr, uint64_t *pdata, MemTxResult res; uint64_t data; int asidx =3D cpu_asidx_from_attrs(current_cpu, attrs); - AddressSpace *as =3D current_cpu->cpu_ases[asidx].as; + AddressSpace *as =3D cpu_get_address_space(current_cpu, asidx); =20 check_watchpoint(addr & ~TARGET_PAGE_MASK, size, attrs, BP_MEM_READ); switch (size) { @@ -2546,7 +2549,7 @@ static MemTxResult watch_mem_write(void *opaque, hwad= dr addr, { MemTxResult res; int asidx =3D cpu_asidx_from_attrs(current_cpu, attrs); - AddressSpace *as =3D current_cpu->cpu_ases[asidx].as; + AddressSpace *as =3D cpu_get_address_space(current_cpu, asidx); =20 check_watchpoint(addr & ~TARGET_PAGE_MASK, size, attrs, BP_MEM_WRITE); switch (size) { @@ -2793,7 +2796,7 @@ static void tcg_commit(MemoryListener *listener) * We reload the dispatch pointer now because cpu_reloading_memory_map= () * may have split the RCU critical section. */ - d =3D address_space_to_dispatch(cpuas->as); + d =3D address_space_to_dispatch(&cpuas->as); atomic_rcu_set(&cpuas->memory_dispatch, d); tlb_flush(cpuas->cpu); } @@ -3539,10 +3542,10 @@ int cpu_memory_rw_debug(CPUState *cpu, target_ulong= addr, l =3D len; phys_addr +=3D (addr & ~TARGET_PAGE_MASK); if (is_write) { - cpu_physical_memory_write_rom(cpu->cpu_ases[asidx].as, + cpu_physical_memory_write_rom(cpu_get_address_space(cpu, asidx= ), phys_addr, buf, l); } else { - address_space_rw(cpu->cpu_ases[asidx].as, phys_addr, + address_space_rw(cpu_get_address_space(cpu, asidx), phys_addr, MEMTXATTRS_UNSPECIFIED, buf, l, 0); } --=20 2.14.3