From nobody Tue Nov 4 21:33:45 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1531192421301890.7287798412465; Mon, 9 Jul 2018 20:13:41 -0700 (PDT) Received: from localhost ([::1]:45562 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcj5w-0002b8-9x for importer@patchew.org; Mon, 09 Jul 2018 23:13:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35794) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcj50-0002IC-Q2 for qemu-devel@nongnu.org; Mon, 09 Jul 2018 23:12:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcj4x-0002Ul-K3 for qemu-devel@nongnu.org; Mon, 09 Jul 2018 23:12:42 -0400 Received: from mail.loongson.cn ([114.242.206.163]:47732) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcj4w-0002U5-QM for qemu-devel@nongnu.org; Mon, 09 Jul 2018 23:12:39 -0400 Received: from martinqiao.loongson.cn (unknown [10.50.122.95]) by mail (Coremail) with SMTP id QMiowPAx6OH_IkRbszmRAA--.58482S2; Tue, 10 Jul 2018 11:07:49 +0800 (CST) From: QiaoChong To: qemu-devel@nongnu.org Date: Tue, 10 Jul 2018 11:12:28 +0800 Message-Id: <1531192348-21056-1-git-send-email-qiaochong@loongson.cn> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: QMiowPAx6OH_IkRbszmRAA--.58482S2 X-Coremail-Antispam: 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 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 114.242.206.163 Subject: [Qemu-devel] [PATCH] make pci_bridge_region_cleanup to be done in rcu queue after flatview_destroy. 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: qiaochong@loongson.cn 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" pci_bridge_region_cleanup need to done after flatview_destroy, because memory_region_unref need access memory regions in PCIBridgeWindows = in flatview_destroy. here we delay pci_bridge_region_cleanup to be done in rcu queue work. bellow are gdb backtraces. oldcode mr->name will be freed in object_unparent, before flatview_destroy. 0 _int_free (av=3D0x7fffe00bcb20 , p=3D0x555556a988c0, have_lo= ck=3D0) at malloc.c:3947 1 0x00007fffdfd7c53c in __GI___libc_free (mem=3D) at malloc= .c:2968 2 0x000055555587ad73 in memory_region_finalize (obj=3D) at = /work/work/loongson/qemu/qemu-latest/memory.c:1731 3 0x0000555555b52e52 in object_deinit (type=3D0x5555565a54f0, obj=3D0x5555= 567dcbf0) at qom/object.c:462 4 object_finalize (data=3D0x5555567dcbf0) at qom/object.c:476 5 object_unref (obj=3D0x5555567dcbf0) at qom/object.c:924 6 0x0000555555b51e57 in object_property_del_child (obj=3D0x55555695f3d0, c= hild=3Dchild@entry=3D0x5555567dcbf0, errp=3D0x0) at qom/object.c:436 7 0x0000555555b525e4 in object_unparent (obj=3Dobj@entry=3D0x5555567dcbf0)= at qom/object.c:455 8 0x0000555555a7bd70 in pci_bridge_region_cleanup (w=3D0x5555567dca10, br= =3D) at hw/pci/pci_bridge.c:229 9 0x0000555555a7c336 in pci_bridge_update_mappings (br=3D) = at hw/pci/pci_bridge.c:248 10 0x0000555555a7c3ba in pci_bridge_write_config (d=3D0x55555695f3d0, addre= ss=3D4, val=3D44040192, len=3D4) at hw/pci/pci_bridge.c:272 here mr mr->owner, mr->name has been freed in object_unparent before. 0 memory_region_unref_do (mr=3D0x5555567dcbf0) at /work/work/loongson/qemu= /qemu-latest/memory.c:296 1 0x0000555555877c49 in flatview_destroy (view=3D0x555557344020) at /work/= work/loongson/qemu/qemu-latest/memory.c:290 2 0x0000555555c4a0ae in call_rcu_thread (opaque=3D) at util= /rcu.c:284 3 0x00007fffe00c96ba in start_thread (arg=3D0x7fffd007c700) at pthread_cre= ate.c:333 4 0x00007fffdfdff41d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clon= e.S:109 void memory_region_unref(MemoryRegion *mr) { if (mr && mr->owner) { object_unref(mr->owner); } } Signed-off-by: QiaoChong --- hw/pci/pci_bridge.c | 14 +++++++++++++- include/hw/pci/pci_bridge.h | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/hw/pci/pci_bridge.c b/hw/pci/pci_bridge.c index 40a39f5..c080471 100644 --- a/hw/pci/pci_bridge.c +++ b/hw/pci/pci_bridge.c @@ -233,6 +233,18 @@ static void pci_bridge_region_cleanup(PCIBridge *br, P= CIBridgeWindows *w) g_free(w); } =20 +/* + * pci_bridge_region_cleanup need to done after flatview_destroy, + * because memory_region_unref need access memory regions in PCIBridgeWind= ows + * in flatview_destroy.Here we delay pci_bridge_region_cleanup to be done + * in rcu queue work. + */ + +static void pci_bridge_region_cleanup_schedule(PCIBridgeWindows *w) +{ + pci_bridge_region_cleanup(NULL, w); +} + void pci_bridge_update_mappings(PCIBridge *br) { PCIBridgeWindows *w =3D br->windows; @@ -243,7 +255,7 @@ void pci_bridge_update_mappings(PCIBridge *br) pci_bridge_region_del(br, br->windows); br->windows =3D pci_bridge_region_init(br); memory_region_transaction_commit(); - pci_bridge_region_cleanup(br, w); + call_rcu(w, pci_bridge_region_cleanup_schedule, rcu); } =20 /* default write_config function for PCI-to-PCI bridge */ diff --git a/include/hw/pci/pci_bridge.h b/include/hw/pci/pci_bridge.h index 0347da5..0e1fd82 100644 --- a/include/hw/pci/pci_bridge.h +++ b/include/hw/pci/pci_bridge.h @@ -37,6 +37,7 @@ typedef struct PCIBridgeWindows PCIBridgeWindows; * as subregions. */ struct PCIBridgeWindows { + struct rcu_head rcu; MemoryRegion alias_pref_mem; MemoryRegion alias_mem; MemoryRegion alias_io; --=20 2.7.4