From 024ec1755eca27b0a12b54a7cb3917a0c7dbcc29 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 18 Feb 2018 18:53:46 -0500 Subject: [PATCH] Convert ram_list to RCU Allow "unlocked" reads of the ram_list by using an RCU-enabled QLIST. The ramlist mutex is kept. call_rcu callbacks are run with the iothread lock taken, but that may change in the future. Writers still take the ramlist mutex, but they no longer need to assume that the iothread lock is taken. Readers of the list, instead, no longer require either the iothread or ramlist mutex, but they need to use rcu_read_lock() and rcu_read_unlock(). One place in arch_init.c was downgrading from write side to read side like this: qemu_mutex_lock_iothread() qemu_mutex_lock_ramlist() ... qemu_mutex_unlock_iothread() ... qemu_mutex_unlock_ramlist() and the equivalent idiom is: qemu_mutex_lock_ramlist() rcu_read_lock() ... qemu_mutex_unlock_ramlist() ... rcu_read_unlock() Backports the write barriers from commit 0dc3f44aca18b1be8b425f3f4feb4b3e8d68de2e in qemu --- qemu/exec.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/qemu/exec.c b/qemu/exec.c index eb1394c2..ebc88487 100644 --- a/qemu/exec.c +++ b/qemu/exec.c @@ -1105,6 +1105,8 @@ static ram_addr_t ram_block_add(struct uc_struct *uc, RAMBlock *new_block, Error } uc->ram_list.mru_block = NULL; + /* Write list before version */ + smp_wmb(); uc->ram_list.version++; new_ram_size = last_ram_offset(uc) >> TARGET_PAGE_BITS;