From nobody Tue Dec 16 16:35:53 2025 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 1512588512827978.5651184577467; Wed, 6 Dec 2017 11:28:32 -0800 (PST) Received: from localhost ([::1]:57217 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMfMo-0002hw-T4 for importer@patchew.org; Wed, 06 Dec 2017 14:28:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48933) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMfCB-0000Kp-H2 for qemu-devel@nongnu.org; Wed, 06 Dec 2017 14:17:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eMfC8-0000J3-Bl for qemu-devel@nongnu.org; Wed, 06 Dec 2017 14:17:27 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:60084 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eMfC8-0000I0-49 for qemu-devel@nongnu.org; Wed, 06 Dec 2017 14:17:24 -0500 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vB6JEAJ1037337 for ; Wed, 6 Dec 2017 14:17:23 -0500 Received: from e36.co.us.ibm.com (e36.co.us.ibm.com [32.97.110.154]) by mx0b-001b2d01.pphosted.com with ESMTP id 2epne8b89u-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 06 Dec 2017 14:17:23 -0500 Received: from localhost by e36.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 6 Dec 2017 12:17:22 -0700 Received: from b03cxnp08027.gho.boulder.ibm.com (9.17.130.19) by e36.co.us.ibm.com (192.168.1.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 6 Dec 2017 12:17:19 -0700 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vB6JHJfE6226280; Wed, 6 Dec 2017 12:17:19 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 04A1D78038; Wed, 6 Dec 2017 12:17:19 -0700 (MST) Received: from localhost (unknown [9.80.93.86]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP id B5E1B78043; Wed, 6 Dec 2017 12:17:18 -0700 (MST) From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 6 Dec 2017 13:16:13 -0600 X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171206191648.18208-1-mdroth@linux.vnet.ibm.com> References: <20171206191648.18208-1-mdroth@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17120619-0020-0000-0000-00000D1F948B X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008161; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000244; SDB=6.00956379; UDB=6.00483442; IPR=6.00736416; BA=6.00005729; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018387; XFM=3.00000015; UTC=2017-12-06 19:17:21 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17120619-0021-0000-0000-00005F320E7D Message-Id: <20171206191648.18208-21-mdroth@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-12-06_07:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=62 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1712060273 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH 20/55] memory: Get rid of address_space_init_shareable 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: Alexey Kardashevskiy , Paolo Bonzini , qemu-stable@nongnu.org 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" From: Alexey Kardashevskiy Since FlatViews are shared now and ASes not, this gets rid of address_space_init_shareable(). This should cause no behavioural change. Signed-off-by: Alexey Kardashevskiy Message-Id: <20170921085110.25598-17-aik@ozlabs.ru> Signed-off-by: Paolo Bonzini (cherry picked from commit b516572f31c0ea0937cd9d11d9bd72dd83809886) Conflicts: target/arm/cpu.c * drop context deps on 1d2091bc and 1e577cc7 Signed-off-by: Michael Roth --- cpus.c | 5 +++-- hw/arm/armv7m.c | 9 ++++----- include/exec/memory.h | 19 ------------------- include/hw/arm/armv7m.h | 2 +- memory.c | 21 --------------------- target/arm/cpu.c | 15 ++++++++------- target/i386/cpu.c | 5 +++-- 7 files changed, 19 insertions(+), 57 deletions(-) diff --git a/cpus.c b/cpus.c index 9bed61eefc..c9a624003a 100644 --- a/cpus.c +++ b/cpus.c @@ -1764,8 +1764,9 @@ 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 address_space_init_shareable(cpu->memory, - "cpu-memory"); + 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); } diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c index c8a11f2b53..475a88fc56 100644 --- a/hw/arm/armv7m.c +++ b/hw/arm/armv7m.c @@ -41,7 +41,7 @@ static MemTxResult bitband_read(void *opaque, hwaddr offs= et, =20 /* Find address in underlying memory and round down to multiple of siz= e */ addr =3D bitband_addr(s, offset) & (-size); - res =3D address_space_read(s->source_as, addr, attrs, buf, size); + res =3D address_space_read(&s->source_as, addr, attrs, buf, size); if (res) { return res; } @@ -66,7 +66,7 @@ static MemTxResult bitband_write(void *opaque, hwaddr off= set, uint64_t value, =20 /* Find address in underlying memory and round down to multiple of siz= e */ addr =3D bitband_addr(s, offset) & (-size); - res =3D address_space_read(s->source_as, addr, attrs, buf, size); + res =3D address_space_read(&s->source_as, addr, attrs, buf, size); if (res) { return res; } @@ -79,7 +79,7 @@ static MemTxResult bitband_write(void *opaque, hwaddr off= set, uint64_t value, } else { buf[bitpos >> 3] &=3D ~bit; } - return address_space_write(s->source_as, addr, attrs, buf, size); + return address_space_write(&s->source_as, addr, attrs, buf, size); } =20 static const MemoryRegionOps bitband_ops =3D { @@ -117,8 +117,7 @@ static void bitband_realize(DeviceState *dev, Error **e= rrp) return; } =20 - s->source_as =3D address_space_init_shareable(s->source_memory, - "bitband-source"); + address_space_init(&s->source_as, s->source_memory, "bitband-source"); } =20 /* Board init. */ diff --git a/include/exec/memory.h b/include/exec/memory.h index 6715551fc6..631daf0cce 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -319,8 +319,6 @@ struct AddressSpace { struct rcu_head rcu; char *name; MemoryRegion *root; - int ref_count; - bool malloced; =20 /* Accessed via RCU. */ struct FlatView *current_map; @@ -1595,23 +1593,6 @@ MemTxResult memory_region_dispatch_write(MemoryRegio= n *mr, void address_space_init(AddressSpace *as, MemoryRegion *root, const char *= name); =20 /** - * address_space_init_shareable: return an address space for a memory regi= on, - * creating it if it does not already exist - * - * @root: a #MemoryRegion that routes addresses for the address space - * @name: an address space name. The name is only used for debugging - * output. - * - * This function will return a pointer to an existing AddressSpace - * which was initialized with the specified MemoryRegion, or it will - * create and initialize one if it does not already exist. The ASes - * are reference-counted, so the memory will be freed automatically - * when the AddressSpace is destroyed via address_space_destroy. - */ -AddressSpace *address_space_init_shareable(MemoryRegion *root, - const char *name); - -/** * address_space_destroy: destroy an address space * * Releases all resources associated with an address space. After an addr= ess space diff --git a/include/hw/arm/armv7m.h b/include/hw/arm/armv7m.h index a9b3f2ab35..dba77dfa39 100644 --- a/include/hw/arm/armv7m.h +++ b/include/hw/arm/armv7m.h @@ -21,7 +21,7 @@ typedef struct { SysBusDevice parent_obj; /*< public >*/ =20 - AddressSpace *source_as; + AddressSpace source_as; MemoryRegion iomem; uint32_t base; MemoryRegion *source_memory; diff --git a/memory.c b/memory.c index 6914d87d0d..2e0def18ee 100644 --- a/memory.c +++ b/memory.c @@ -2721,9 +2721,7 @@ void address_space_init(AddressSpace *as, MemoryRegio= n *root, const char *name) { memory_region_ref(root); memory_region_transaction_begin(); - as->ref_count =3D 1; as->root =3D root; - as->malloced =3D false; as->current_map =3D NULL; as->ioeventfd_nb =3D 0; as->ioeventfds =3D NULL; @@ -2736,37 +2734,18 @@ void address_space_init(AddressSpace *as, MemoryReg= ion *root, const char *name) =20 static void do_address_space_destroy(AddressSpace *as) { - bool do_free =3D as->malloced; - assert(QTAILQ_EMPTY(&as->listeners)); =20 flatview_unref(as->current_map); g_free(as->name); g_free(as->ioeventfds); memory_region_unref(as->root); - if (do_free) { - g_free(as); - } -} - -AddressSpace *address_space_init_shareable(MemoryRegion *root, const char = *name) -{ - AddressSpace *as; - - as =3D g_malloc0(sizeof *as); - address_space_init(as, root, name); - as->malloced =3D true; - return as; } =20 void address_space_destroy(AddressSpace *as) { MemoryRegion *root =3D as->root; =20 - as->ref_count--; - if (as->ref_count) { - return; - } /* Flush out anything from MemoryListeners listening in on this */ memory_region_transaction_begin(); as->root =3D NULL; diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 05c038bf17..24ef71ad8b 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -650,6 +650,9 @@ 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) { @@ -835,19 +838,17 @@ static void arm_cpu_realizefn(DeviceState *dev, Error= **errp) } =20 if (cpu->has_el3) { - AddressSpace *as; + as =3D g_new0(AddressSpace, 1); =20 if (!cpu->secure_memory) { cpu->secure_memory =3D cs->memory; } - as =3D address_space_init_shareable(cpu->secure_memory, - "cpu-secure-memory"); + address_space_init(as, cpu->secure_memory, "cpu-secure-memory"); cpu_address_space_init(cs, as, ARMASIdx_S); } - cpu_address_space_init(cs, - address_space_init_shareable(cs->memory, - "cpu-memory"), - ARMASIdx_NS); + as =3D g_new0(AddressSpace, 1); + address_space_init(as, cs->memory, "cpu-memory"); + cpu_address_space_init(cs, as, ARMASIdx_NS); #endif =20 qemu_init_vcpu(cs); diff --git a/target/i386/cpu.c b/target/i386/cpu.c index ddc45abd70..df73958b82 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -3702,10 +3702,11 @@ static void x86_cpu_realizefn(DeviceState *dev, Err= or **errp) =20 #ifndef CONFIG_USER_ONLY if (tcg_enabled()) { - AddressSpace *as_normal =3D address_space_init_shareable(cs->memor= y, - "cpu-memory= "); + AddressSpace *as_normal =3D g_new0(AddressSpace, 1); AddressSpace *as_smm =3D g_new(AddressSpace, 1); =20 + 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 --=20 2.11.0