[Qemu-devel] [PATCH] make pci_bridge_region_cleanup to be done in rcu queue after flatview_destroy.

QiaoChong posted 1 patch 5 years, 9 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/1531190661-19327-1-git-send-email-qiaochong@loongson.cn
Test checkpatch failed
Test docker-mingw@fedora passed
Test docker-quick@centos7 passed
hw/pci/pci_bridge.c         | 12 +++++++++++-
include/hw/pci/pci_bridge.h |  1 +
2 files changed, 12 insertions(+), 1 deletion(-)
[Qemu-devel] [PATCH] make pci_bridge_region_cleanup to be done in rcu queue after flatview_destroy.
Posted by QiaoChong 5 years, 9 months ago
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.

    mask=<optimized out>, attrs=...) at /work/work/loongson/qemu/qemu-latest/memory.c:559
    access_size_min=<optimized out>, access_size_max=<optimized out>, access_fn=0x555555876850 <memory_region_write_accessor>,
    mr=0x5555569608c0, attrs=...) at /work/work/loongson/qemu/qemu-latest/memory.c:626
    at /work/work/loongson/qemu/qemu-latest/memory.c:1518
    buf=buf@entry=0x7fffbff0ae40 "", len=len@entry=4, addr1=4, l=4, mr=0x5555569608c0) at /work/work/loongson/qemu/qemu-latest/exec.c:3255
    at /work/work/loongson/qemu/qemu-latest/exec.c:3294
    at /work/work/loongson/qemu/qemu-latest/exec.c:2910
    shift=<optimized out>, mask=<optimized out>, attrs=...) at /work/work/loongson/qemu/qemu-latest/memory.c:585
    access_size_min=<optimized out>, access_size_max=<optimized out>, access_fn=0x555555874700 <memory_region_write_with_attrs_accessor>,
    mr=0x555557338120, attrs=...) at /work/work/loongson/qemu/qemu-latest/memory.c:626
    size=size@entry=4, attrs=...) at /work/work/loongson/qemu/qemu-latest/memory.c:1518
    val=val@entry=44040192, addr=addr@entry=18446744072502722564, retaddr=retaddr@entry=140736012783717, recheck=false, size=4)
    at /work/work/loongson/qemu/qemu-latest/accel/tcg/cputlb.c:905
    mmu_idx=<optimized out>, env=0x55555681d218) at /work/work/loongson/qemu/qemu-latest/accel/tcg/softmmu_template.h:268
    at /work/work/loongson/qemu/qemu-latest/accel/tcg/softmmu_template.h:304
    at /work/work/loongson/qemu/qemu-latest/accel/tcg/cpu-exec.c:171
    at /work/work/loongson/qemu/qemu-latest/accel/tcg/cpu-exec.c:612

here mr mr->owner, mr->name has been freed in object_unparent before.

void memory_region_unref(MemoryRegion *mr)
{
    if (mr && mr->owner) {
        object_unref(mr->owner);
    }
}

Signed-off-by: QiaoChong <qiaochong@loongson.cn>
---
 hw/pci/pci_bridge.c         | 12 +++++++++++-
 include/hw/pci/pci_bridge.h |  1 +
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/hw/pci/pci_bridge.c b/hw/pci/pci_bridge.c
index 40a39f5..a3c9501 100644
--- a/hw/pci/pci_bridge.c
+++ b/hw/pci/pci_bridge.c
@@ -233,6 +233,16 @@ static void pci_bridge_region_cleanup(PCIBridge *br, PCIBridgeWindows *w)
     g_free(w);
 }
 
+/*
+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.
+*/
+static void pci_bridge_region_cleanup_schedule(PCIBridgeWindows *w)
+{
+  pci_bridge_region_cleanup(NULL, w);
+}
+
 void pci_bridge_update_mappings(PCIBridge *br)
 {
     PCIBridgeWindows *w = br->windows;
@@ -243,7 +253,7 @@ void pci_bridge_update_mappings(PCIBridge *br)
     pci_bridge_region_del(br, br->windows);
     br->windows = pci_bridge_region_init(br);
     memory_region_transaction_commit();
-    pci_bridge_region_cleanup(br, w);
+    call_rcu(w,  pci_bridge_region_cleanup_schedule, rcu);
 }
 
 /* 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;
-- 
2.7.4



Re: [Qemu-devel] [PATCH] make pci_bridge_region_cleanup to be done in rcu queue after flatview_destroy.
Posted by no-reply@patchew.org 5 years, 9 months ago
Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 1531190661-19327-1-git-send-email-qiaochong@loongson.cn
Subject: [Qemu-devel] [PATCH] make pci_bridge_region_cleanup to be done in rcu queue after flatview_destroy.

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram

commits="$(git log --format=%H --reverse $BASE..)"
for c in $commits; do
    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))
done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 * [new tag]               patchew/1531190661-19327-1-git-send-email-qiaochong@loongson.cn -> patchew/1531190661-19327-1-git-send-email-qiaochong@loongson.cn
Switched to a new branch 'test'
47be5f4199 make pci_bridge_region_cleanup to be done in rcu queue after flatview_destroy.

=== OUTPUT BEGIN ===
Checking PATCH 1/1: make pci_bridge_region_cleanup to be done in rcu queue after flatview_destroy....
ERROR: line over 90 characters
#55: FILE: hw/pci/pci_bridge.c:238:
+because memory_region_unref need access memory regions in PCIBridgeWindows in flatview_destroy.

total: 1 errors, 0 warnings, 31 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1


---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@redhat.com