Misc changes for 2017-09-22
Subsystems (4)
The following changes since commit b62b7ed0fc9c58e373b8946c9bd2e193be98dae6:
Merge remote-tracking branch 'remotes/gkurz/tags/for-upstream' into staging (2017-09-20 20:33:48 +0100)
are available in the git repository at:
git://github.com/bonzini/qemu.git tags/for-upstream
for you to fetch changes up to 165d4d2a77f470b6f095ec665b1d274c8ceede0a:
chardev: remove context in chr_update_read_handler (2017-09-22 01:13:58 +0200)
----------------------------------------------------------------
* Speed up AddressSpaceDispatch creation (Alexey)
* Fix kvm.c assert (David)
* Memory fixes and further speedup (me)
* Persistent reservation manager infrastructure (me)
* virtio-serial: add enable_backend callback (Pavel)
* chardev GMainContext fixes (Peter)
----------------------------------------------------------------
Alexey Kardashevskiy (17):
exec: Explicitly export target AS from address_space_translate_internal
memory: Open code FlatView rendering
memory: Move FlatView allocation to a helper
memory: Move AddressSpaceDispatch from AddressSpace to FlatView
memory: Remove AddressSpace pointer from AddressSpaceDispatch
memory: Switch memory from using AddressSpace to FlatView
memory: Cleanup after switching to FlatView
memory: Rename mem_begin/mem_commit/mem_add helpers
memory: Store physical root MR in FlatView
memory: Alloc dispatch tree where topology is generared
memory: Move address_space_update_ioeventfds
memory: Share FlatView's and dispatch trees between address spaces
memory: Do not allocate FlatView in address_space_init
memory: Rework "info mtree" to print flat views and dispatch trees
memory: Get rid of address_space_init_shareable
memory: Create FlatView directly
memory: Share special empty FlatView
David Hildenbrand (1):
kvm: drop wrong assertion creating problems with pflash
KONRAD Frederic (1):
memory: avoid a name clash with access macro
Paolo Bonzini (8):
atomic: update documentation
memory: avoid "resurrection" of dead FlatViews
memory: trace FlatView creation and destruction
memory: seek FlatView sharing candidates among children subregions scsi, file-posix: add support for persistent reservation management
scsi: build qemu-pr-helper
scsi: add multipath support to qemu-pr-helper
scsi: add persistent reservation manager using qemu-pr-helper
Pavel Butsykin (1):
virtio-serial: add enable_backend callback
Peter Xu (4):
chardev: new qemu_chr_be_update_read_handlers()
chardev: add Chardev.gcontext field
chardev: use per-dev context for io_add_watch_poll
chardev: remove context in chr_update_read_handler
Makefile | 7 +- Makefile.objs | 1 + accel/kvm/kvm-all.c | 1 - block/file-posix.c | 30 ++ chardev/char-fd.c | 5 +- chardev/char-fe.c | 7 +- chardev/char-pty.c | 5 +- chardev/char-socket.c | 7 +- chardev/char-udp.c | 5 +- chardev/char.c | 11 + configure | 60 ++- cpus.c | 5 +- docs/devel/atomics.txt | 14 +- docs/interop/pr-helper.rst | 83 +++ docs/pr-manager.rst | 111 ++++ exec.c | 330 +++++++----- hmp-commands-info.hx | 7 +- hw/arm/armv7m.c | 9 +- hw/char/virtio-console.c | 21 + hw/char/virtio-serial-bus.c | 7 + hw/intc/openpic_kvm.c | 2 +- include/chardev/char.h | 13 +- include/exec/memory-internal.h | 16 +- include/exec/memory.h | 75 ++- include/hw/arm/armv7m.h | 2 +- include/hw/virtio/virtio-serial.h | 3 + include/qemu/atomic.h | 8 + include/qemu/typedefs.h | 1 + include/scsi/pr-manager.h | 56 ++ include/scsi/utils.h | 4 + memory.c | 378 ++++++++++---- monitor.c | 3 +- qapi/block-core.json | 4 + scsi/Makefile.objs | 2 + scsi/pr-helper.h | 41 ++ scsi/pr-manager-helper.c | 302 +++++++++++ scsi/pr-manager.c | 109 ++++ scsi/qemu-pr-helper.c | 1038 +++++++++++++++++++++++++++++++++++++ scsi/trace-events | 3 + scsi/utils.c | 10 + target/arm/cpu.c | 16 +- target/i386/cpu.c | 5 +- trace-events | 3 + vl.c | 3 +- 44 files changed, 2513 insertions(+), 310 deletions(-) create mode 100644 docs/interop/pr-helper.rst create mode 100644 docs/pr-manager.rst create mode 100644 include/scsi/pr-manager.h create mode 100644 scsi/pr-helper.h create mode 100644 scsi/pr-manager-helper.c create mode 100644 scsi/pr-manager.c create mode 100644 scsi/qemu-pr-helper.c create mode 100644 scsi/trace-events
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 02/32] kvm: drop wrong assertion creating problems with pflash
From: David Hildenbrand <[email protected]>
pflash toggles mr->romd_mode. So this assert does not always hold.
1) a device was added with !mr->romd_mode, therefore effectively not creating a kvm slot as we want to trap every access (add = false).
2) mr->romd_mode was toggled on before remove it. There is now actually no slot to remove and the assert is wrong.
So let's just drop the assert.
Message-Id: <[email protected]>
--- accel/kvm/kvm-all.c | 1 - 1 file changed, 1 deletion(-)
accel/kvm/kvm-all.c +0 -1
@@ -722,7 +722,6 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, mem =kvm_lookup_matching_slot (kml, start_addr, size);if (!add) {if (!mem) { -g_assert (!memory_region_is_ram (mr) && !writeable && !mr->romd_mode);return ; }if (mem->flags &KVM_MEM_LOG_DIRTY_PAGES ) {
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 03/32] memory: avoid a name clash with access macro
In reply to Paolo BonziniFrom: KONRAD Frederic <[email protected]>
This avoids a name clash with the access macro on windows 64:
make
CHK version_gen.h
CC aarch64-softmmu/memory.o/home/konrad/qemu/memory.c: In function 'access_with_adjusted_size':/home/konrad/qemu/memory.c:591:73: error: macro "access" passed 7 arguments, \
but takes just 2
(size - access_size - i) * 8, access_mask, attrs);
^Message-Id: <[email protected]>
--- memory.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
memory.c +10 -9
@@ -560,13 +560,14 @@ static MemTxResult access_with_adjusted_size(hwaddr addr,unsigned size, unsigned access_size_min, unsigned access_size_max, - MemTxResult (*access)(MemoryRegion *mr, -hwaddr addr, -uint64_t *value, -unsigned size, -unsigned shift, -uint64_t mask, -MemTxAttrs attrs), + MemTxResult (*access_fn) + (MemoryRegion *mr, +hwaddr addr, +uint64_t *value, +unsigned size, +unsigned shift, +uint64_t mask, +MemTxAttrs attrs), MemoryRegion *mr, MemTxAttrs attrs) {
@@ -587,12 +588,12 @@ static MemTxResult access_with_adjusted_size(hwaddr addr, access_mask =-1ULL >> (64 - access_size *8 );if (memory_region_big_endian (mr)) {for (i =0 ; i < size; i += access_size) { - r |=access (mr, addr + i, value, access_size, + r |=access_fn (mr, addr + i, value, access_size, (size - access_size - i) *8 , access_mask, attrs); } }else {for (i =0 ; i < size; i += access_size) { - r |=access (mr, addr + i, value, access_size, i *8 , + r |=access_fn (mr, addr + i, value, access_size, i *8 , access_mask, attrs); } }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 01/32] virtio-serial: add enable_backend callback
In reply to Paolo BonziniFrom: Pavel Butsykin <[email protected]>
We should guarantee that RAM will not be modified while VM has a stopped state, otherwise it can lead to negative consequences during post-copy migration. In RUN_STATE_FINISH_MIGRATE step, it's expected that RAM on source side will not be modified as this could lead to non-consistent vm state on the destination side. Also RAM access during postcopy-ram migration with enabled release-ram capability can lead to sad consequences.
Let's add enable_backend() callback to avoid undesirable virtioqueue changes in the guest memory.
Message-Id: <[email protected]>
--- hw/char/virtio-console.c | 21 +++++++++++++++++++++ hw/char/virtio-serial-bus.c | 7 +++++++ include/hw/virtio/virtio-serial.h | 3 +++ 3 files changed, 31 insertions(+)
hw/char/virtio-console.c +21 -0
@@ -187,6 +187,26 @@ static int chr_be_change(void *opaque)return 0 ; } +static void virtconsole_enable_backend (VirtIOSerialPort *port,bool enable) +{ +VirtConsole *vcon =VIRTIO_CONSOLE (port); + +if (!qemu_chr_fe_backend_connected (&vcon->chr)) { +return ; + } + +if (enable) { +VirtIOSerialPortClass *k =VIRTIO_SERIAL_PORT_GET_CLASS (port); + +qemu_chr_fe_set_handlers (&vcon->chr, chr_can_read, chr_read, + k->is_console ?NULL : chr_event, + chr_be_change, vcon,NULL , false); + }else { +qemu_chr_fe_set_handlers (&vcon->chr,NULL ,NULL ,NULL , +NULL ,NULL ,NULL , false); + } +} +static void virtconsole_realize (DeviceState *dev,Error **errp) {VirtIOSerialPort *port =VIRTIO_SERIAL_PORT (dev);
@@ -258,6 +278,7 @@ static void virtserialport_class_init(ObjectClass *klass, void *data) k->unrealize = virtconsole_unrealize; k->have_data = flush_buf; k->set_guest_connected = set_guest_connected; + k->enable_backend = virtconsole_enable_backend; k->guest_writable = guest_writable; dc->props = virtserialport_properties; }
hw/char/virtio-serial-bus.c +7 -0
@@ -637,6 +637,13 @@ static void set_status(VirtIODevice *vdev, uint8_t status)if (!(status &VIRTIO_CONFIG_S_DRIVER_OK )) {guest_reset (vser); } + + QTAILQ_FOREACH(port, &vser->ports, next) { +VirtIOSerialPortClass *vsc =VIRTIO_SERIAL_PORT_GET_CLASS (port); +if (vsc->enable_backend) { + vsc->enable_backend (port, vdev->vm_running); + } + } }static void vser_reset (VirtIODevice *vdev)
include/hw/virtio/virtio-serial.h +3 -0
@@ -58,6 +58,9 @@ typedef struct VirtIOSerialPortClass {/* Guest opened/closed device. */ void (*set_guest_connected)(VirtIOSerialPort *port,int guest_connected); +/* Enable/disable backend for virtio serial port */ +void (*enable_backend)(VirtIOSerialPort *port,bool enable); +/* Guest is now ready to accept data (virtqueues set up). */ void (*guest_ready)(VirtIOSerialPort *port);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 04/32] atomic: update documentation
In reply to Paolo Bonzini--- docs/devel/atomics.txt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
docs/devel/atomics.txt +12 -1
@@ -63,11 +63,22 @@ operations: typeof(*ptr) atomic_fetch_sub(ptr, val) typeof(*ptr) atomic_fetch_and(ptr, val) typeof(*ptr) atomic_fetch_or(ptr, val) + typeof(*ptr) atomic_fetch_xor(ptr, val) typeof(*ptr) atomic_xchg(ptr, val) typeof(*ptr) atomic_cmpxchg(ptr, old, new) all of which return the old value of *ptr. These operations are -polymorphic; they operate on any type that is as wide as an int. +polymorphic; they operate on any type that is as wide as a pointer. + +Similar operations return the new value of *ptr: + + typeof(*ptr) atomic_inc_fetch(ptr) + typeof(*ptr) atomic_dec_fetch(ptr) + typeof(*ptr) atomic_add_fetch(ptr, val) + typeof(*ptr) atomic_sub_fetch(ptr, val) + typeof(*ptr) atomic_and_fetch(ptr, val) + typeof(*ptr) atomic_or_fetch(ptr, val) + typeof(*ptr) atomic_xor_fetch(ptr, val) Sequentially consistent loads and stores can be done using:
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 05/32] memory: avoid "resurrection" of dead FlatViews
In reply to Paolo BonziniIt's possible for address_space_get_flatview() as it currently stands to cause a use-after-free for the returned FlatView, if the reference count is incremented after the FlatView has been replaced by a writer:
thread 1 thread 2 RCU thread
-------------------------------------------------------------
rcu_read_lock
read as->current_map
set as->current_map
flatview_unref
'--> call_rcu
flatview_ref
[ref=1] rcu_read_unlock
flatview_destroy
<badness>
Since FlatViews are not updated very often, we can just detect the situation using a new atomic op atomic_fetch_inc_nonzero, similar to Linux's atomic_inc_not_zero, which performs the refcount increment only if it hasn't already hit zero. This is similar to Linux commit de09a9771a53 ("CRED: Fix get_task_cred() and task_state() to not resurrect dead credentials", 2010-07-29).
--- docs/devel/atomics.txt | 1 + include/qemu/atomic.h | 8 ++++++++ memory.c | 12 ++++++++---- 3 files changed, 17 insertions(+), 4 deletions(-)
docs/devel/atomics.txt +1 -0
@@ -64,6 +64,7 @@ operations: typeof(*ptr) atomic_fetch_and(ptr, val) typeof(*ptr) atomic_fetch_or(ptr, val) typeof(*ptr) atomic_fetch_xor(ptr, val) + typeof(*ptr) atomic_fetch_inc_nonzero(ptr) typeof(*ptr) atomic_xchg(ptr, val) typeof(*ptr) atomic_cmpxchg(ptr, old, new)
include/qemu/atomic.h +8 -0
@@ -442,4 +442,12 @@ } while(0)#endif +#define atomic_fetch_inc_nonzero (ptr) ({ \ + typeof_strip_qual(*ptr) _oldn = atomic_read(ptr); \ + while (_oldn && atomic_cmpxchg(ptr, _oldn, _oldn + 1) != _oldn) { \ + _oldn = atomic_read(ptr); \ + } \ + _oldn; \ +}) +#endif /* QEMU_ATOMIC_H */
memory.c +8 -4
@@ -294,9 +294,9 @@ static void flatview_destroy(FlatView *view)g_free (view); } -static void flatview_ref (FlatView *view) +static bool flatview_ref (FlatView *view) { -atomic_inc (&view->ref); +return atomic_fetch_inc_nonzero (&view->ref) >0 ; }static void flatview_unref (FlatView *view)
@@ -773,8 +773,12 @@ static FlatView *address_space_get_flatview(AddressSpace *as)FlatView *view;rcu_read_lock (); - view =atomic_rcu_read (&as->current_map); -flatview_ref (view); +do { + view =atomic_rcu_read (&as->current_map); +/* If somebody has replaced as->current_map concurrently, +* flatview_ref returns false. +*/ + }while (!flatview_ref (view));rcu_read_unlock ();return view; }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 06/32] exec: Explicitly export target AS from address_space_translate_internal
In reply to Paolo BonziniFrom: Alexey Kardashevskiy <[email protected]>
This adds an AS** parameter to address_space_do_translate() to make it easier for the next patch to share FlatViews.
This should cause no behavioural change.
Message-Id: <[email protected]>
--- exec.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
exec.c +7 -4
@@ -476,7 +476,8 @@ static MemoryRegionSection address_space_do_translate(AddressSpace *as, hwaddr *xlat, hwaddr *plen, bool is_write, - bool is_mmio) + bool is_mmio, + AddressSpace **target_as) { IOMMUTLBEntry iotlb;MemoryRegionSection *section;
@@ -503,6 +504,7 @@ static MemoryRegionSection address_space_do_translate(AddressSpace *as, } as = iotlb.target_as; + *target_as = iotlb.target_as; } *xlat = addr;
@@ -525,7 +527,7 @@ IOMMUTLBEntry address_space_get_iotlb_entry(AddressSpace *as, hwaddr addr,/* This can never be MMIO. */ section =address_space_do_translate (as, addr, &xlat, &plen, - is_write, false); + is_write, false, &as);/* Illegal translation */ if (section.mr == &io_mem_unassigned) {
@@ -548,7 +550,7 @@ IOMMUTLBEntry address_space_get_iotlb_entry(AddressSpace *as, hwaddr addr, plen -=1 ;return (IOMMUTLBEntry ) { - .target_as = section.address_space, + .target_as = as, .iova = addr & ~plen, .translated_addr = xlat & ~plen, .addr_mask = plen,
@@ -569,7 +571,8 @@ MemoryRegion *address_space_translate(AddressSpace *as, hwaddr addr,MemoryRegionSection section;/* This can be MMIO, so setup MMIO bit. */ - section =address_space_do_translate (as, addr, xlat, plen, is_write, true); + section =address_space_do_translate (as, addr, xlat, plen, is_write, true, + &as); mr = section.mr;if (xen_enabled () &&memory_access_is_direct (mr, is_write)) {
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 08/32] memory: Move FlatView allocation to a helper
In reply to Paolo BonziniFrom: Alexey Kardashevskiy <[email protected]>
This moves a FlatView allocation and initialization to a helper. While we are nere, replace g_new with g_new0 to not to bother if we add new fields in the future.
This should cause no behavioural change.
Message-Id: <[email protected]>
--- memory.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
memory.c +8 -8
@@ -258,12 +258,14 @@ static bool flatrange_equal(FlatRange *a, FlatRange *b) && a->readonly == b->readonly; } -static void flatview_init (FlatView *view) +static FlatView *flatview_new (void ) { +FlatView *view; + + view =g_new0 (FlatView,1 ); view->ref =1 ; - view->ranges =NULL ; - view->nr =0 ; - view->nr_allocated =0 ; + +return view; }/* Insert a range into a given position. Caller is responsible for maintaining
@@ -707,8 +709,7 @@ static FlatView *generate_memory_topology(MemoryRegion *mr) {FlatView *view; - view =g_new (FlatView,1 ); -flatview_init (view); + view =flatview_new ();if (mr) { render_memory_region(view, mr, int128_zero(),
@@ -2629,8 +2630,7 @@ void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name) as->ref_count =1 ; as->root = root; as->malloced = false; - as->current_map =g_new (FlatView,1 ); -flatview_init (as->current_map); + as->current_map =flatview_new (); as->ioeventfd_nb =0 ; as->ioeventfds =NULL ;QTAILQ_INIT (&as->listeners);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 07/32] memory: Open code FlatView rendering
In reply to Paolo BonziniFrom: Alexey Kardashevskiy <[email protected]>
We are going to share FlatView's between AddressSpace's and per-AS memory listeners won't suit the purpose anymore so open code the dispatch tree rendering.
Since there is a good chance that dispatch_listener was the only listener, this avoids address_space_update_topology_pass() if there is no registered listeners; this should improve starting time.
This should cause no behavioural change.
Message-Id: <[email protected]>
--- exec.c | 27 +++------------------------ include/exec/memory-internal.h | 6 ++++-- include/exec/memory.h | 1 - memory.c | 19 ++++++++++++++----- 4 files changed, 21 insertions(+), 32 deletions(-)
exec.c +3 -24
@@ -1347,9 +1347,8 @@ static void register_multipage(AddressSpaceDispatch *d,phys_page_set (d, start_addr >>TARGET_PAGE_BITS , num_pages, section_index); } -static void mem_add (MemoryListener *listener,MemoryRegionSection *section) +void mem_add (AddressSpace *as,MemoryRegionSection *section) { -AddressSpace *as =container_of (listener, AddressSpace, dispatch_listener);AddressSpaceDispatch *d = as->next_dispatch;MemoryRegionSection now = *section, remain = *section;Int128 page_size =int128_make64 (TARGET_PAGE_SIZE );
@@ -2673,9 +2672,8 @@ static void io_mem_init(void) NULL, UINT64_MAX); } -static void mem_begin (MemoryListener *listener) +void mem_begin (AddressSpace *as) { -AddressSpace *as =container_of (listener, AddressSpace, dispatch_listener);AddressSpaceDispatch *d =g_new0 (AddressSpaceDispatch,1 );uint16_t n;
@@ -2699,9 +2697,8 @@ static void address_space_dispatch_free(AddressSpaceDispatch *d)g_free (d); } -static void mem_commit (MemoryListener *listener) +void mem_commit (AddressSpace *as) { -AddressSpace *as =container_of (listener, AddressSpace, dispatch_listener);AddressSpaceDispatch *cur = as->dispatch;AddressSpaceDispatch *next = as->next_dispatch;
@@ -2731,24 +2728,6 @@ static void tcg_commit(MemoryListener *listener)tlb_flush (cpuas->cpu); } -void address_space_init_dispatch (AddressSpace *as) -{ - as->dispatch =NULL ; - as->dispatch_listener = (MemoryListener ) { - .begin = mem_begin, - .commit = mem_commit, - .region_add = mem_add, - .region_nop = mem_add, - .priority =0 , - }; -memory_listener_register (&as->dispatch_listener, as); -} - -void address_space_unregister (AddressSpace *as) -{ -memory_listener_unregister (&as->dispatch_listener); -} -void address_space_destroy_dispatch (AddressSpace *as) {AddressSpaceDispatch *d = as->dispatch;
include/exec/memory-internal.h +4 -2
@@ -22,8 +22,6 @@#ifndef CONFIG_USER_ONLY typedef struct AddressSpaceDispatch AddressSpaceDispatch ; -void address_space_init_dispatch (AddressSpace *as); -void address_space_unregister (AddressSpace *as);void address_space_destroy_dispatch (AddressSpace *as);extern const MemoryRegionOps unassigned_mem_ops;
@@ -31,5 +29,9 @@ extern const MemoryRegionOps unassigned_mem_ops;bool memory_region_access_valid (MemoryRegion *mr,hwaddr addr,unsigned size,bool is_write); +void mem_add (AddressSpace *as,MemoryRegionSection *section); +void mem_begin (AddressSpace *as); +void mem_commit (AddressSpace *as); +#endif #endif
include/exec/memory.h +0 -1
@@ -318,7 +318,6 @@ struct AddressSpace {struct MemoryRegionIoeventfd *ioeventfds;struct AddressSpaceDispatch *dispatch;struct AddressSpaceDispatch *next_dispatch; -MemoryListener dispatch_listener; QTAILQ_HEAD(memory_listeners_as, MemoryListener) listeners;QTAILQ_ENTRY (AddressSpace) address_spaces_link; };
memory.c +14 -5
@@ -884,14 +884,24 @@ static void address_space_update_topology_pass(AddressSpace *as, } } -static void address_space_update_topology (AddressSpace *as) {FlatView *old_view =address_space_get_flatview (as);FlatView *new_view =generate_memory_topology (as->root); +int i; -address_space_update_topology_pass (as, old_view, new_view, false); -address_space_update_topology_pass (as, old_view, new_view, true); +mem_begin (as); +for (i =0 ; i < new_view->nr; i++) { +MemoryRegionSection mrs = +section_from_flat_range (&new_view->ranges[i], as); +mem_add (as, &mrs); + } +mem_commit (as); + +if (!QTAILQ_EMPTY (&as->listeners)) { +address_space_update_topology_pass (as, old_view, new_view, false); +address_space_update_topology_pass (as, old_view, new_view, true); + }/* Writes are protected by the BQL. */ atomic_rcu_set (&as->current_map, new_view);
@@ -2626,7 +2636,7 @@ void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name)QTAILQ_INIT (&as->listeners);QTAILQ_INSERT_TAIL (&address_spaces, as, address_spaces_link); as->name =g_strdup (name ? name :"anonymous" ); -address_space_init_dispatch (as); + as->dispatch =NULL ; memory_region_update_pending |= root->enabled;memory_region_transaction_commit (); }
@@ -2677,7 +2687,6 @@ void address_space_destroy(AddressSpace *as) as->root =NULL ;memory_region_transaction_commit ();QTAILQ_REMOVE (&address_spaces, as, address_spaces_link); -address_space_unregister (as);/* At this point, as->dispatch and as->current_map are dummy * entries that the guest should never use. Wait for the old
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 09/32] memory: Move AddressSpaceDispatch from AddressSpace to FlatView
In reply to Paolo BonziniFrom: Alexey Kardashevskiy <[email protected]>
As we are going to share FlatView's between AddressSpace's, and AddressSpaceDispatch is a structure to perform quick lookup in FlatView, this moves ASD to FlatView.
After previosly open coded ASD rendering, we can also remove as->next_dispatch as the new FlatView pointer is stored on a stack and set to an AS atomically.
flatview_destroy() is executed under RCU instead of address_space_dispatch_free() now.
This makes mem_begin/mem_commit to work with ASD and mem_add with FV as later on mem_add will be taking FV as an argument anyway.
This should cause no behavioural change.
Message-Id: <[email protected]>
--- exec.c | 41 +++++++++++------------------------------ include/exec/memory-internal.h | 12 +++++++----- include/exec/memory.h | 2 -- memory.c | 31 ++++++++++++++++++++++++------- 4 files changed, 42 insertions(+), 44 deletions(-)
exec.c +11 -30
@@ -187,8 +187,6 @@ typedef struct PhysPageMap { } PhysPageMap;struct AddressSpaceDispatch { -struct rcu_head rcu; -MemoryRegionSection *mru_section;/* This is a multi-level map on the physical address space. * The bottom level has pointers to MemoryRegionSections.
@@ -485,7 +483,7 @@ static MemoryRegionSection address_space_do_translate(AddressSpace *as,IOMMUMemoryRegionClass *imrc;for (;;) { -AddressSpaceDispatch *d =atomic_rcu_read (&as->dispatch); +AddressSpaceDispatch *d =address_space_to_dispatch (as); section =address_space_translate_internal (d, addr, &addr, plen, is_mmio); iommu_mr =memory_region_get_iommu (section->mr);
@@ -1222,7 +1220,7 @@ hwaddr memory_region_section_get_iotlb(CPUState *cpu, }else {AddressSpaceDispatch *d; - d =atomic_rcu_read (§ion->address_space->dispatch); + d =address_space_to_dispatch (section->address_space); iotlb = section - d->map.sections; iotlb += xlat; }
@@ -1347,9 +1345,9 @@ static void register_multipage(AddressSpaceDispatch *d,phys_page_set (d, start_addr >>TARGET_PAGE_BITS , num_pages, section_index); } -void mem_add (AddressSpace *as,MemoryRegionSection *section) +void mem_add (AddressSpace *as,FlatView *fv,MemoryRegionSection *section) { -AddressSpaceDispatch *d = as->next_dispatch; +AddressSpaceDispatch *d =flatview_to_dispatch (fv);MemoryRegionSection now = *section, remain = *section;Int128 page_size =int128_make64 (TARGET_PAGE_SIZE );
@@ -2672,7 +2670,7 @@ static void io_mem_init(void) NULL, UINT64_MAX); } -void mem_begin (AddressSpace *as) +AddressSpaceDispatch *mem_begin (AddressSpace *as) {AddressSpaceDispatch *d =g_new0 (AddressSpaceDispatch,1 );uint16_t n;
@@ -2688,26 +2686,19 @@ void mem_begin(AddressSpace *as) d->phys_map = (PhysPageEntry ) { .ptr =PHYS_MAP_NODE_NIL , .skip =1 }; d->as = as; - as->next_dispatch = d; + +return d; } -static void address_space_dispatch_free (AddressSpaceDispatch *d) +void address_space_dispatch_free (AddressSpaceDispatch *d) {phys_sections_free (&d->map);g_free (d); } -void mem_commit (AddressSpace *as) +void mem_commit (AddressSpaceDispatch *d) { -AddressSpaceDispatch *cur = as->dispatch; -AddressSpaceDispatch *next = as->next_dispatch; - -phys_page_compact_all (next, next->map.nodes_nb); - -atomic_rcu_set (&as->dispatch, next); -if (cur) { -call_rcu (cur, address_space_dispatch_free, rcu); - } +phys_page_compact_all (d, d->map.nodes_nb); }static void tcg_commit (MemoryListener *listener)
@@ -2723,21 +2714,11 @@ 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 =atomic_rcu_read (&cpuas->as->dispatch); + d =address_space_to_dispatch (cpuas->as);atomic_rcu_set (&cpuas->memory_dispatch, d);tlb_flush (cpuas->cpu); } -void address_space_destroy_dispatch (AddressSpace *as) -{ -AddressSpaceDispatch *d = as->dispatch; - -atomic_rcu_set (&as->dispatch,NULL ); -if (d) { -call_rcu (d, address_space_dispatch_free, rcu); - } -} -static void memory_map_init (void ) { system_memory =g_malloc (sizeof (*system_memory));
include/exec/memory-internal.h +7 -5
@@ -22,16 +22,18 @@#ifndef CONFIG_USER_ONLY typedef struct AddressSpaceDispatch AddressSpaceDispatch ; -void address_space_destroy_dispatch (AddressSpace *as); -extern const MemoryRegionOps unassigned_mem_ops;bool memory_region_access_valid (MemoryRegion *mr,hwaddr addr,unsigned size,bool is_write); -void mem_add (AddressSpace *as,MemoryRegionSection *section); -void mem_begin (AddressSpace *as); -void mem_commit (AddressSpace *as); +void mem_add (AddressSpace *as,FlatView *fv,MemoryRegionSection *section); +AddressSpaceDispatch *mem_begin (AddressSpace *as); +void mem_commit (AddressSpaceDispatch *d); + +AddressSpaceDispatch *address_space_to_dispatch (AddressSpace *as); +AddressSpaceDispatch *flatview_to_dispatch (FlatView *fv); +void address_space_dispatch_free (AddressSpaceDispatch *d);#endif #endif
include/exec/memory.h +0 -2
@@ -316,8 +316,6 @@ struct AddressSpace {int ioeventfd_nb;struct MemoryRegionIoeventfd *ioeventfds; -struct AddressSpaceDispatch *dispatch; -struct AddressSpaceDispatch *next_dispatch; QTAILQ_HEAD(memory_listeners_as, MemoryListener) listeners;QTAILQ_ENTRY (AddressSpace) address_spaces_link; };
memory.c +24 -7
@@ -229,6 +229,7 @@ struct FlatView {FlatRange *ranges;unsigned nr;unsigned nr_allocated; +struct AddressSpaceDispatch *dispatch; };typedef struct AddressSpaceOps AddressSpaceOps ;
@@ -289,6 +290,9 @@ static void flatview_destroy(FlatView *view) {int i; +if (view->dispatch) { +address_space_dispatch_free (view->dispatch); + }for (i =0 ; i < view->nr; i++) {memory_region_unref (view->ranges[i].mr); }
@@ -304,10 +308,25 @@ static bool flatview_ref(FlatView *view)static void flatview_unref (FlatView *view) {if (atomic_fetch_dec (&view->ref) ==1 ) { -flatview_destroy (view); +call_rcu (view, flatview_destroy, rcu); } } +static FlatView *address_space_to_flatview (AddressSpace *as) +{ +return atomic_rcu_read (&as->current_map); +} + +AddressSpaceDispatch *flatview_to_dispatch (FlatView *fv) +{ +return fv->dispatch; +} + +AddressSpaceDispatch *address_space_to_dispatch (AddressSpace *as) +{ +return flatview_to_dispatch (address_space_to_flatview (as)); +} +static bool can_merge (FlatRange *r1,FlatRange *r2) {return int128_eq (addrrange_end (r1->addr), r2->addr.start)
@@ -891,13 +910,13 @@ static void address_space_update_topology(AddressSpace *as)FlatView *new_view =generate_memory_topology (as->root);int i; -mem_begin (as); + new_view->dispatch =mem_begin (as);for (i =0 ; i < new_view->nr; i++) {MemoryRegionSection mrs =section_from_flat_range (&new_view->ranges[i], as); -mem_add (as, &mrs); +mem_add (as, new_view, &mrs); } -mem_commit (as); +mem_commit (new_view->dispatch);if (!QTAILQ_EMPTY (&as->listeners)) {address_space_update_topology_pass (as, old_view, new_view, false);
@@ -906,7 +925,7 @@ static void address_space_update_topology(AddressSpace *as)/* Writes are protected by the BQL. */ atomic_rcu_set (&as->current_map, new_view); -call_rcu (old_view, flatview_unref, rcu); +flatview_unref (old_view);/* Note that all the old MemoryRegions are still alive up to this * point. This relieves most MemoryListeners from the need to
@@ -2636,7 +2655,6 @@ void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name)QTAILQ_INIT (&as->listeners);QTAILQ_INSERT_TAIL (&address_spaces, as, address_spaces_link); as->name =g_strdup (name ? name :"anonymous" ); - as->dispatch =NULL ; memory_region_update_pending |= root->enabled;memory_region_transaction_commit (); }
@@ -2645,7 +2663,6 @@ static void do_address_space_destroy(AddressSpace *as) {bool do_free = as->malloced; -address_space_destroy_dispatch (as);assert (QTAILQ_EMPTY (&as->listeners));flatview_unref (as->current_map);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 10/32] memory: Remove AddressSpace pointer from AddressSpaceDispatch
In reply to Paolo BonziniFrom: Alexey Kardashevskiy <[email protected]>
AS in ASD is only used to pass AS from mem_begin() to register_subpage() to store it in MemoryRegionSection, we can do this directly now.
This should cause no behavioural change.
Message-Id: <[email protected]>
--- exec.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
exec.c +7 -8
@@ -193,7 +193,6 @@ struct AddressSpaceDispatch {*/ PhysPageEntry phys_map;PhysPageMap map; -AddressSpace *as; };#define SUBPAGE_IDX (addr) ((addr) & ~TARGET_PAGE_MASK)
@@ -1303,7 +1302,8 @@ static void phys_sections_free(PhysPageMap *map)g_free (map->nodes); } -static void register_subpage (AddressSpaceDispatch *d,MemoryRegionSection *section) +static void register_subpage (AddressSpace *as,AddressSpaceDispatch *d, +MemoryRegionSection *section) {subpage_t *subpage;hwaddr base = section->offset_within_address_space
@@ -1318,8 +1318,8 @@ static void register_subpage(AddressSpaceDispatch *d, MemoryRegionSection *sectiassert (existing->mr->subpage || existing->mr == &io_mem_unassigned);if (!(existing->mr->subpage)) { - subpage =subpage_init (d->as, base); - subsection.address_space = d->as; + subpage =subpage_init (as, base); + subsection.address_space = as; subsection.mr = &subpage->iomem;phys_page_set (d, base >>TARGET_PAGE_BITS ,1 ,phys_section_add (&d->map, &subsection));
@@ -1356,7 +1356,7 @@ void mem_add(AddressSpace *as, FlatView *fv, MemoryRegionSection *section) - now.offset_within_address_space; now.size =int128_min (int128_make64 (left), now.size); -register_subpage (d, &now); +register_subpage (as, d, &now); }else { now.size =int128_zero (); }
@@ -1366,10 +1366,10 @@ void mem_add(AddressSpace *as, FlatView *fv, MemoryRegionSection *section) remain.offset_within_region +=int128_get64 (now.size); now = remain;if (int128_lt (remain.size, page_size)) { -register_subpage (d, &now); +register_subpage (as, d, &now); }else if (remain.offset_within_address_space & ~TARGET_PAGE_MASK ) { now.size = page_size; -register_subpage (d, &now); +register_subpage (as, d, &now); }else { now.size =int128_and (now.size,int128_neg (page_size));register_multipage (d, &now);
@@ -2685,7 +2685,6 @@ AddressSpaceDispatch *mem_begin(AddressSpace *as)assert (n ==PHYS_SECTION_WATCH ); d->phys_map = (PhysPageEntry ) { .ptr =PHYS_MAP_NODE_NIL , .skip =1 }; - d->as = as;return d; }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 12/32] memory: Cleanup after switching to FlatView
In reply to Paolo BonziniFrom: Alexey Kardashevskiy <[email protected]>
We store AddressSpaceDispatch* in FlatView anyway so there is no need to carry it from mem_add() to register_subpage/register_multipage.
This should cause no behavioural change.
Message-Id: <[email protected]>
--- exec.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
exec.c +8 -8
@@ -1302,9 +1302,9 @@ static void phys_sections_free(PhysPageMap *map)g_free (map->nodes); } -static void register_subpage (FlatView *fv,AddressSpaceDispatch *d, -MemoryRegionSection *section) +static void register_subpage (FlatView *fv,MemoryRegionSection *section) { +AddressSpaceDispatch *d =flatview_to_dispatch (fv);subpage_t *subpage;hwaddr base = section->offset_within_address_space &TARGET_PAGE_MASK ;
@@ -1333,9 +1333,10 @@ static void register_subpage(FlatView *fv, AddressSpaceDispatch *d, } -static void register_multipage (AddressSpaceDispatch *d, +static void register_multipage (FlatView *fv,MemoryRegionSection *section) { +AddressSpaceDispatch *d =flatview_to_dispatch (fv);hwaddr start_addr = section->offset_within_address_space;uint16_t section_index =phys_section_add (&d->map, section); uint64_t num_pages = int128_get64(int128_rshift(section->size,
@@ -1347,7 +1348,6 @@ static void register_multipage(AddressSpaceDispatch *d,void mem_add (FlatView *fv,MemoryRegionSection *section) { -AddressSpaceDispatch *d =flatview_to_dispatch (fv);MemoryRegionSection now = *section, remain = *section;Int128 page_size =int128_make64 (TARGET_PAGE_SIZE );
@@ -1356,7 +1356,7 @@ void mem_add(FlatView *fv, MemoryRegionSection *section) - now.offset_within_address_space; now.size =int128_min (int128_make64 (left), now.size); -register_subpage (fv, d, &now); +register_subpage (fv, &now); }else { now.size =int128_zero (); }
@@ -1366,13 +1366,13 @@ void mem_add(FlatView *fv, MemoryRegionSection *section) remain.offset_within_region +=int128_get64 (now.size); now = remain;if (int128_lt (remain.size, page_size)) { -register_subpage (fv, d, &now); +register_subpage (fv, &now); }else if (remain.offset_within_address_space & ~TARGET_PAGE_MASK ) { now.size = page_size; -register_subpage (fv, d, &now); +register_subpage (fv, &now); }else { now.size =int128_and (now.size,int128_neg (page_size)); -register_multipage (d, &now); +register_multipage (fv, &now); } } }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 13/32] memory: Rename mem_begin/mem_commit/mem_add helpers
In reply to Paolo BonziniFrom: Alexey Kardashevskiy <[email protected]>
This renames some helpers to reflect better what they do.
This should cause no behavioural change.
Message-Id: <[email protected]>
--- exec.c | 12 +++--------- include/exec/memory-internal.h | 6 +++--- memory.c | 6 +++--- 3 files changed, 9 insertions(+), 15 deletions(-)
exec.c +3 -9
@@ -358,7 +358,7 @@ static void phys_page_compact(PhysPageEntry *lp, Node *nodes) } } -static void phys_page_compact_all (AddressSpaceDispatch *d,int nodes_nb) +void address_space_dispatch_compact (AddressSpaceDispatch *d) {if (d->phys_map.skip) {phys_page_compact (&d->phys_map, d->map.nodes);
@@ -1346,7 +1346,7 @@ static void register_multipage(FlatView *fv,phys_page_set (d, start_addr >>TARGET_PAGE_BITS , num_pages, section_index); } -void mem_add (FlatView *fv,MemoryRegionSection *section) +void flatview_add_to_dispatch (FlatView *fv,MemoryRegionSection *section) {MemoryRegionSection now = *section, remain = *section;Int128 page_size =int128_make64 (TARGET_PAGE_SIZE );
@@ -2672,9 +2672,8 @@ static void io_mem_init(void) NULL, UINT64_MAX); } -AddressSpaceDispatch *mem_begin (AddressSpace *as) +AddressSpaceDispatch *address_space_dispatch_new (FlatView *fv) { -FlatView *fv =address_space_to_flatview (as);AddressSpaceDispatch *d =g_new0 (AddressSpaceDispatch,1 );uint16_t n;
@@ -2698,11 +2697,6 @@ void address_space_dispatch_free(AddressSpaceDispatch *d)g_free (d); } -void mem_commit (AddressSpaceDispatch *d) -{ -phys_page_compact_all (d, d->map.nodes_nb); -} -static void tcg_commit (MemoryListener *listener) {CPUAddressSpace *cpuas;
include/exec/memory-internal.h +3 -3
@@ -27,9 +27,9 @@ extern const MemoryRegionOps unassigned_mem_ops;bool memory_region_access_valid (MemoryRegion *mr,hwaddr addr,unsigned size,bool is_write); -void mem_add (FlatView *fv,MemoryRegionSection *section); -AddressSpaceDispatch *mem_begin (AddressSpace *as); -void mem_commit (AddressSpaceDispatch *d); +void flatview_add_to_dispatch (FlatView *fv,MemoryRegionSection *section); +AddressSpaceDispatch *address_space_dispatch_new (FlatView *fv); +void address_space_dispatch_compact (AddressSpaceDispatch *d);AddressSpaceDispatch *address_space_to_dispatch (AddressSpace *as);AddressSpaceDispatch *flatview_to_dispatch (FlatView *fv);
memory.c +3 -3
@@ -910,13 +910,13 @@ static void address_space_update_topology(AddressSpace *as)FlatView *new_view =generate_memory_topology (as->root);int i; - new_view->dispatch =mem_begin (as); + new_view->dispatch =address_space_dispatch_new (new_view);for (i =0 ; i < new_view->nr; i++) {MemoryRegionSection mrs =section_from_flat_range (&new_view->ranges[i], new_view); -mem_add (new_view, &mrs); +flatview_add_to_dispatch (new_view, &mrs); } -mem_commit (new_view->dispatch); +address_space_dispatch_compact (new_view->dispatch);if (!QTAILQ_EMPTY (&as->listeners)) {address_space_update_topology_pass (as, old_view, new_view, false);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 14/32] memory: Store physical root MR in FlatView
In reply to Paolo BonziniFrom: Alexey Kardashevskiy <[email protected]>
Address spaces get to keep a root MR (alias or not) but FlatView stores the actual MR as this is going to be used later on to decide whether to share a particular FlatView or not.
Message-Id: <[email protected]>
--- memory.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-)
memory.c +22 -4
@@ -230,6 +230,7 @@ struct FlatView {unsigned nr;unsigned nr_allocated;struct AddressSpaceDispatch *dispatch; +MemoryRegion *root; };typedef struct AddressSpaceOps AddressSpaceOps ;
@@ -259,12 +260,14 @@ static bool flatrange_equal(FlatRange *a, FlatRange *b) && a->readonly == b->readonly; } -static FlatView *flatview_new (void ) +static FlatView *flatview_new (MemoryRegion *mr_root) {FlatView *view; view =g_new0 (FlatView,1 ); view->ref =1 ; + view->root = mr_root; +memory_region_ref (mr_root);return view; }
@@ -297,6 +300,7 @@ static void flatview_destroy(FlatView *view)memory_region_unref (view->ranges[i].mr); }g_free (view->ranges); +memory_region_unref (view->root);g_free (view); }
@@ -723,12 +727,25 @@ static void render_memory_region(FlatView *view, } } +static MemoryRegion *memory_region_get_flatview_root (MemoryRegion *mr) +{ +while (mr->alias && !mr->alias_offset && +int128_ge (mr->size, mr->alias->size)) { +/* The alias is included in its entirety. Use it as +* the "real" root, so that we can share more FlatViews. +*/ + mr = mr->alias; + } + +return mr; +} +/* Render a memory topology into a list of disjoint absolute ranges. */ static FlatView *generate_memory_topology (MemoryRegion *mr) {FlatView *view; - view =flatview_new (); + view =flatview_new (mr);if (mr) { render_memory_region(view, mr, int128_zero(),
@@ -907,7 +924,8 @@ static void address_space_update_topology_pass(AddressSpace *as,static void address_space_update_topology (AddressSpace *as) {FlatView *old_view =address_space_get_flatview (as); -FlatView *new_view =generate_memory_topology (as->root); +MemoryRegion *physmr =memory_region_get_flatview_root (old_view->root); +FlatView *new_view =generate_memory_topology (physmr);int i; new_view->dispatch =address_space_dispatch_new (new_view);
@@ -2650,7 +2668,7 @@ void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name) as->ref_count =1 ; as->root = root; as->malloced = false; - as->current_map =flatview_new (); + as->current_map =flatview_new (root); as->ioeventfd_nb =0 ; as->ioeventfds =NULL ;QTAILQ_INIT (&as->listeners);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 15/32] memory: Alloc dispatch tree where topology is generared
In reply to Paolo BonziniFrom: Alexey Kardashevskiy <[email protected]>
This is to make next patches simpler.
Message-Id: <[email protected]>
--- memory.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
memory.c +9 -9
@@ -743,6 +743,7 @@ static MemoryRegion *memory_region_get_flatview_root(MemoryRegion *mr)/* Render a memory topology into a list of disjoint absolute ranges. */ static FlatView *generate_memory_topology (MemoryRegion *mr) { +int i;FlatView *view; view =flatview_new (mr);
@@ -753,6 +754,14 @@ static FlatView *generate_memory_topology(MemoryRegion *mr) }flatview_simplify (view); + view->dispatch =address_space_dispatch_new (view); +for (i =0 ; i < view->nr; i++) { +MemoryRegionSection mrs = +section_from_flat_range (&view->ranges[i], view); +flatview_add_to_dispatch (view, &mrs); + } +address_space_dispatch_compact (view->dispatch); +return view; }
@@ -926,15 +935,6 @@ static void address_space_update_topology(AddressSpace *as)FlatView *old_view =address_space_get_flatview (as);MemoryRegion *physmr =memory_region_get_flatview_root (old_view->root);FlatView *new_view =generate_memory_topology (physmr); -int i; - - new_view->dispatch =address_space_dispatch_new (new_view); -for (i =0 ; i < new_view->nr; i++) { -MemoryRegionSection mrs = -section_from_flat_range (&new_view->ranges[i], new_view); -flatview_add_to_dispatch (new_view, &mrs); - } -address_space_dispatch_compact (new_view->dispatch);if (!QTAILQ_EMPTY (&as->listeners)) {address_space_update_topology_pass (as, old_view, new_view, false);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 11/32] memory: Switch memory from using AddressSpace to FlatView
In reply to Paolo BonziniFrom: Alexey Kardashevskiy <[email protected]>
FlatView's will be shared between AddressSpace's and subpage_t and MemoryRegionSection cannot store AS anymore, hence this change.
In particular, for:
typedef struct subpage_t {
MemoryRegion iomem;
- AddressSpace *as;
+ FlatView *fv;
hwaddr base;
uint16_t sub_section[]; } subpage_t;
struct MemoryRegionSection {
MemoryRegion *mr;
- AddressSpace *address_space;
+ FlatView *fv;
hwaddr offset_within_region;
Int128 size;
hwaddr offset_within_address_space;
bool readonly;};
This should cause no behavioural change.
Message-Id: <[email protected]>
--- exec.c | 180 ++++++++++++++++++++++++----------------- hw/intc/openpic_kvm.c | 2 +- include/exec/memory-internal.h | 2 +- include/exec/memory.h | 51 ++++++++---- memory.c | 33 ++++---- 5 files changed, 159 insertions(+), 109 deletions(-)
exec.c +105 -75
@@ -198,7 +198,7 @@ struct AddressSpaceDispatch {#define SUBPAGE_IDX (addr) ((addr) & ~TARGET_PAGE_MASK)typedef struct subpage_t {MemoryRegion iomem; -AddressSpace *as; +FlatView *fv;hwaddr base;uint16_t sub_section[]; }subpage_t ;
@@ -468,13 +468,13 @@ address_space_translate_internal(AddressSpaceDispatch *d, hwaddr addr, hwaddr *x }/* Called from RCU critical section */ -static MemoryRegionSection address_space_do_translate (AddressSpace *as, -hwaddr addr, -hwaddr *xlat, -hwaddr *plen, -bool is_write, -bool is_mmio, -AddressSpace **target_as) +static MemoryRegionSection flatview_do_translate (FlatView *fv, +hwaddr addr, +hwaddr *xlat, +hwaddr *plen, +bool is_write, +bool is_mmio, +AddressSpace **target_as) {IOMMUTLBEntry iotlb;MemoryRegionSection *section;
@@ -482,8 +482,9 @@ static MemoryRegionSection address_space_do_translate(AddressSpace *as,IOMMUMemoryRegionClass *imrc;for (;;) { -AddressSpaceDispatch *d =address_space_to_dispatch (as); - section =address_space_translate_internal (d, addr, &addr, plen, is_mmio); + section =address_space_translate_internal ( +flatview_to_dispatch (fv), addr, &addr, + plen, is_mmio); iommu_mr =memory_region_get_iommu (section->mr);if (!iommu_mr) {
@@ -500,7 +501,7 @@ static MemoryRegionSection address_space_do_translate(AddressSpace *as, goto translate_fail; } - as = iotlb.target_as; + fv =address_space_to_flatview (iotlb.target_as); *target_as = iotlb.target_as; }
@@ -523,8 +524,8 @@ IOMMUTLBEntry address_space_get_iotlb_entry(AddressSpace *as, hwaddr addr, plen = (hwaddr)-1 ;/* This can never be MMIO. */ - section =address_space_do_translate (as, addr, &xlat, &plen, - is_write, false, &as); + section =flatview_do_translate (address_space_to_flatview (as), addr, + &xlat, &plen, is_write, false, &as);/* Illegal translation */ if (section.mr == &io_mem_unassigned) {
@@ -560,16 +561,15 @@ iotlb_fail: }/* Called from RCU critical section */ -MemoryRegion *address_space_translate (AddressSpace *as,hwaddr addr, -hwaddr *xlat,hwaddr *plen, -bool is_write) +MemoryRegion *flatview_translate (FlatView *fv,hwaddr addr,hwaddr *xlat, +hwaddr *plen,bool is_write) {MemoryRegion *mr;MemoryRegionSection section; +AddressSpace *as =NULL ;/* This can be MMIO, so setup MMIO bit. */ - section =address_space_do_translate (as, addr, xlat, plen, is_write, true, - &as); + section =flatview_do_translate (fv, addr, xlat, plen, is_write, true, &as); mr = section.mr;if (xen_enabled () &&memory_access_is_direct (mr, is_write)) {
@@ -1219,7 +1219,7 @@ hwaddr memory_region_section_get_iotlb(CPUState *cpu, }else {AddressSpaceDispatch *d; - d =address_space_to_dispatch (section->address_space); + d =flatview_to_dispatch (section->fv); iotlb = section - d->map.sections; iotlb += xlat; }
@@ -1245,7 +1245,7 @@ hwaddr memory_region_section_get_iotlb(CPUState *cpu,static int subpage_register (subpage_t *mmio,uint32_t start,uint32_t end,uint16_t section); -static subpage_t *subpage_init (AddressSpace *as,hwaddr base); +static subpage_t *subpage_init (FlatView *fv,hwaddr base);static void *(*phys_mem_alloc)(size_t size,uint64_t *align) = qemu_anon_ram_alloc;
@@ -1302,7 +1302,7 @@ static void phys_sections_free(PhysPageMap *map)g_free (map->nodes); } -static void register_subpage (AddressSpace *as,AddressSpaceDispatch *d, +static void register_subpage (FlatView *fv,AddressSpaceDispatch *d,MemoryRegionSection *section) {subpage_t *subpage;
@@ -1318,8 +1318,8 @@ static void register_subpage(AddressSpace *as, AddressSpaceDispatch *d,assert (existing->mr->subpage || existing->mr == &io_mem_unassigned);if (!(existing->mr->subpage)) { - subpage =subpage_init (as, base); - subsection.address_space = as; + subpage =subpage_init (fv, base); + subsection.fv = fv; subsection.mr = &subpage->iomem;phys_page_set (d, base >>TARGET_PAGE_BITS ,1 ,phys_section_add (&d->map, &subsection));
@@ -1345,7 +1345,7 @@ static void register_multipage(AddressSpaceDispatch *d,phys_page_set (d, start_addr >>TARGET_PAGE_BITS , num_pages, section_index); } -void mem_add (AddressSpace *as,FlatView *fv,MemoryRegionSection *section) +void mem_add (FlatView *fv,MemoryRegionSection *section) {AddressSpaceDispatch *d =flatview_to_dispatch (fv);MemoryRegionSection now = *section, remain = *section;
@@ -1356,7 +1356,7 @@ void mem_add(AddressSpace *as, FlatView *fv, MemoryRegionSection *section) - now.offset_within_address_space; now.size =int128_min (int128_make64 (left), now.size); -register_subpage (as, d, &now); +register_subpage (fv, d, &now); }else { now.size =int128_zero (); }
@@ -1366,10 +1366,10 @@ void mem_add(AddressSpace *as, FlatView *fv, MemoryRegionSection *section) remain.offset_within_region +=int128_get64 (now.size); now = remain;if (int128_lt (remain.size, page_size)) { -register_subpage (as, d, &now); +register_subpage (fv, d, &now); }else if (remain.offset_within_address_space & ~TARGET_PAGE_MASK ) { now.size = page_size; -register_subpage (as, d, &now); +register_subpage (fv, d, &now); }else { now.size =int128_and (now.size,int128_neg (page_size));register_multipage (d, &now);
@@ -2500,6 +2500,11 @@ static const MemoryRegionOps watch_mem_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; +static MemTxResult flatview_write (FlatView *fv,hwaddr addr,MemTxAttrs attrs, +const uint8_t *buf,int len); +static bool flatview_access_valid (FlatView *fv,hwaddr addr,int len, +bool is_write); +static MemTxResult subpage_read (void *opaque,hwaddr addr,uint64_t *data,unsigned len,MemTxAttrs attrs) {
@@ -2511,8 +2516,7 @@ static MemTxResult subpage_read(void *opaque, hwaddr addr, uint64_t *data,printf ("%s: subpage %p len %u addr " TARGET_FMT_plx"\n" , __func__, subpage, len, addr);#endif - res =address_space_read (subpage->as, addr + subpage->base, - attrs, buf, len); + res =flatview_read (subpage->fv, addr + subpage->base, attrs, buf, len);if (res) {return res; }
@@ -2561,8 +2565,7 @@ static MemTxResult subpage_write(void *opaque, hwaddr addr,default :abort (); } -return address_space_write (subpage->as, addr + subpage->base, - attrs, buf, len); +return flatview_write (subpage->fv, addr + subpage->base, attrs, buf, len); } static bool subpage_accepts(void *opaque, hwaddr addr,
@@ -2574,8 +2577,8 @@ static bool subpage_accepts(void *opaque, hwaddr addr, __func__, subpage, is_write ? 'w' : 'r', len, addr);#endif -return address_space_access_valid (subpage->as, addr + subpage->base, - len, is_write); +return flatview_access_valid (subpage->fv, addr + subpage->base, + len, is_write); }static const MemoryRegionOps subpage_ops = {
@@ -2609,12 +2612,12 @@ static int subpage_register (subpage_t *mmio, uint32_t start, uint32_t end,return 0 ; } -static subpage_t *subpage_init (AddressSpace *as,hwaddr base) +static subpage_t *subpage_init (FlatView *fv,hwaddr base) {subpage_t *mmio; mmio =g_malloc0 (sizeof (subpage_t) +TARGET_PAGE_SIZE *sizeof (uint16_t )); - mmio->as = as; + mmio->fv = fv; mmio->base = base;memory_region_init_io (&mmio->iomem,NULL , &subpage_ops, mmio,NULL ,TARGET_PAGE_SIZE );
@@ -2628,12 +2631,11 @@ static subpage_t *subpage_init(AddressSpace *as, hwaddr base)return mmio; } -static uint16_t dummy_section (PhysPageMap *map,AddressSpace *as, -MemoryRegion *mr) +static uint16_t dummy_section (PhysPageMap *map,FlatView *fv,MemoryRegion *mr) { -assert (as); +assert (fv);MemoryRegionSection section = { - .address_space = as, + .fv = fv, .mr = mr, .offset_within_address_space =0 , .offset_within_region =0 ,
@@ -2672,16 +2674,17 @@ static void io_mem_init(void)AddressSpaceDispatch *mem_begin (AddressSpace *as) { +FlatView *fv =address_space_to_flatview (as);AddressSpaceDispatch *d =g_new0 (AddressSpaceDispatch,1 );uint16_t n; - n =dummy_section (&d->map, as, &io_mem_unassigned); + n =dummy_section (&d->map, fv, &io_mem_unassigned);assert (n ==PHYS_SECTION_UNASSIGNED ); - n =dummy_section (&d->map, as, &io_mem_notdirty); + n =dummy_section (&d->map, fv, &io_mem_notdirty);assert (n ==PHYS_SECTION_NOTDIRTY ); - n =dummy_section (&d->map, as, &io_mem_rom); + n =dummy_section (&d->map, fv, &io_mem_rom);assert (n ==PHYS_SECTION_ROM ); - n =dummy_section (&d->map, as, &io_mem_watch); + n =dummy_section (&d->map, fv, &io_mem_watch);assert (n ==PHYS_SECTION_WATCH ); d->phys_map = (PhysPageEntry ) { .ptr =PHYS_MAP_NODE_NIL , .skip =1 };
@@ -2861,11 +2864,11 @@ static bool prepare_mmio_access(MemoryRegion *mr) }/* Called within RCU critical section. */ -static MemTxResult address_space_write_continue (AddressSpace *as,hwaddr addr, -MemTxAttrs attrs, -const uint8_t *buf, -int len,hwaddr addr1, -hwaddr l,MemoryRegion *mr) +static MemTxResult flatview_write_continue (FlatView *fv,hwaddr addr, +MemTxAttrs attrs, +const uint8_t *buf, +int len,hwaddr addr1, +hwaddr l,MemoryRegion *mr) {uint8_t *ptr;uint64_t val;
@@ -2927,14 +2930,14 @@ static MemTxResult address_space_write_continue(AddressSpace *as, hwaddr addr, } l = len; - mr =address_space_translate (as, addr, &addr1, &l, true); + mr =flatview_translate (fv, addr, &addr1, &l, true); }return result; } -MemTxResult address_space_write (AddressSpace *as,hwaddr addr,MemTxAttrs attrs, -const uint8_t *buf,int len) +static MemTxResult flatview_write (FlatView *fv,hwaddr addr,MemTxAttrs attrs, +const uint8_t *buf,int len) {hwaddr l;hwaddr addr1;
@@ -2944,20 +2947,27 @@ MemTxResult address_space_write(AddressSpace *as, hwaddr addr, MemTxAttrs attrs,if (len >0 ) {rcu_read_lock (); l = len; - mr =address_space_translate (as, addr, &addr1, &l, true); - result =address_space_write_continue (as, addr, attrs, buf, len, - addr1, l, mr); + mr =flatview_translate (fv, addr, &addr1, &l, true); + result =flatview_write_continue (fv, addr, attrs, buf, len, + addr1, l, mr);rcu_read_unlock (); }return result; } +MemTxResult address_space_write (AddressSpace *as,hwaddr addr, +MemTxAttrs attrs, +const uint8_t *buf,int len) +{ +return flatview_write (address_space_to_flatview (as), addr, attrs, buf, len); +} +/* Called within RCU critical section. */ -MemTxResult address_space_read_continue (AddressSpace *as,hwaddr addr, -MemTxAttrs attrs,uint8_t *buf, -int len,hwaddr addr1,hwaddr l, -MemoryRegion *mr) +MemTxResult flatview_read_continue (FlatView *fv,hwaddr addr, +MemTxAttrs attrs,uint8_t *buf, +int len,hwaddr addr1,hwaddr l, +MemoryRegion *mr) {uint8_t *ptr;uint64_t val;
@@ -3017,14 +3027,14 @@ MemTxResult address_space_read_continue(AddressSpace *as, hwaddr addr, } l = len; - mr =address_space_translate (as, addr, &addr1, &l, false); + mr =flatview_translate (fv, addr, &addr1, &l, false); }return result; } -MemTxResult address_space_read_full (AddressSpace *as,hwaddr addr, -MemTxAttrs attrs,uint8_t *buf,int len) +MemTxResult flatview_read_full (FlatView *fv,hwaddr addr, +MemTxAttrs attrs,uint8_t *buf,int len) {hwaddr l;hwaddr addr1;
@@ -3034,25 +3044,33 @@ MemTxResult address_space_read_full(AddressSpace *as, hwaddr addr,if (len >0 ) {rcu_read_lock (); l = len; - mr =address_space_translate (as, addr, &addr1, &l, false); - result =address_space_read_continue (as, addr, attrs, buf, len, - addr1, l, mr); + mr =flatview_translate (fv, addr, &addr1, &l, false); + result =flatview_read_continue (fv, addr, attrs, buf, len, + addr1, l, mr);rcu_read_unlock (); }return result; } -MemTxResult address_space_rw (AddressSpace *as,hwaddr addr,MemTxAttrs attrs, -uint8_t *buf,int len,bool is_write) +static MemTxResult flatview_rw (FlatView *fv,hwaddr addr,MemTxAttrs attrs, +uint8_t *buf,int len,bool is_write) {if (is_write) { -return address_space_write (as, addr, attrs, (uint8_t *)buf, len); +return flatview_write (fv, addr, attrs, (uint8_t *)buf, len); }else { -return address_space_read (as, addr, attrs, (uint8_t *)buf, len); +return flatview_read (fv, addr, attrs, (uint8_t *)buf, len); } } +MemTxResult address_space_rw (AddressSpace *as,hwaddr addr, +MemTxAttrs attrs,uint8_t *buf, +int len,bool is_write) +{ +return flatview_rw (address_space_to_flatview (as), + addr, attrs, buf, len, is_write); +} +void cpu_physical_memory_rw (hwaddr addr,uint8_t *buf,int len,int is_write) {
@@ -3210,7 +3228,8 @@ static void cpu_notify_map_clients(void)qemu_mutex_unlock (&map_client_list_lock); } -bool address_space_access_valid (AddressSpace *as,hwaddr addr,int len,bool is_write) +static bool flatview_access_valid (FlatView *fv,hwaddr addr,int len, +bool is_write) {MemoryRegion *mr;hwaddr l, xlat;
@@ -3218,7 +3237,7 @@ bool address_space_access_valid(AddressSpace *as, hwaddr addr, int len, bool is_rcu_read_lock ();while (len >0 ) { l = len; - mr =address_space_translate (as, addr, &xlat, &l, is_write); + mr =flatview_translate (fv, addr, &xlat, &l, is_write);if (!memory_access_is_direct (mr, is_write)) { l =memory_access_size (mr, l, addr);if (!memory_region_access_valid (mr, xlat, l, is_write)) {
@@ -3234,8 +3253,16 @@ bool address_space_access_valid(AddressSpace *as, hwaddr addr, int len, bool is_return true; } +bool address_space_access_valid (AddressSpace *as,hwaddr addr, +int len,bool is_write) +{ +return flatview_access_valid (address_space_to_flatview (as), + addr, len, is_write); +} +static hwaddr -address_space_extend_translation (AddressSpace *as,hwaddr addr,hwaddr target_len, +flatview_extend_translation (FlatView *fv,hwaddr addr, +hwaddr target_len,MemoryRegion *mr,hwaddr base,hwaddr len,bool is_write) {
@@ -3252,7 +3279,8 @@ address_space_extend_translation(AddressSpace *as, hwaddr addr, hwaddr target_le } len = target_len; - this_mr =address_space_translate (as, addr, &xlat, &len, is_write); + this_mr =flatview_translate (fv, addr, &xlat, + &len, is_write);if (this_mr != mr || xlat != base + done) {return done; }
@@ -3275,6 +3303,7 @@ void *address_space_map(AddressSpace *as,hwaddr l, xlat;MemoryRegion *mr;void *ptr; +FlatView *fv =address_space_to_flatview (as);if (len ==0 ) {return NULL ;
@@ -3282,7 +3311,7 @@ void *address_space_map(AddressSpace *as, l = len;rcu_read_lock (); - mr =address_space_translate (as, addr, &xlat, &l, is_write); + mr =flatview_translate (fv, addr, &xlat, &l, is_write);if (!memory_access_is_direct (mr, is_write)) {if (atomic_xchg (&bounce.in_use, true)) {
@@ -3298,7 +3327,7 @@ void *address_space_map(AddressSpace *as,memory_region_ref (mr); bounce.mr = mr;if (!is_write) { -address_space_read (as, addr,MEMTXATTRS_UNSPECIFIED , +flatview_read (fv, addr,MEMTXATTRS_UNSPECIFIED , bounce.buffer, l); }
@@ -3309,7 +3338,8 @@ void *address_space_map(AddressSpace *as,memory_region_ref (mr); - *plen =address_space_extend_translation (as, addr, len, mr, xlat, l, is_write); + *plen =flatview_extend_translation (fv, addr, len, mr, xlat, + l, is_write); ptr =qemu_ram_ptr_length (mr->ram_block, xlat, plen, true);rcu_read_unlock ();
hw/intc/openpic_kvm.c +1 -1
@@ -124,7 +124,7 @@ static void kvm_openpic_region_add(MemoryListener *listener,uint64_t reg_base;int ret; -if (section->address_space != &address_space_memory) { +if (section->fv !=address_space_to_flatview (&address_space_memory)) {abort (); }
include/exec/memory-internal.h +1 -1
@@ -27,7 +27,7 @@ extern const MemoryRegionOps unassigned_mem_ops;bool memory_region_access_valid (MemoryRegion *mr,hwaddr addr,unsigned size,bool is_write); -void mem_add (AddressSpace *as,FlatView *fv,MemoryRegionSection *section); +void mem_add (FlatView *fv,MemoryRegionSection *section);AddressSpaceDispatch *mem_begin (AddressSpace *as);void mem_commit (AddressSpaceDispatch *d);
include/exec/memory.h +35 -16
105 lines not on this page · raw message
memory.c +17 -16
@@ -154,7 +154,8 @@ enum ListenerDirection { Forward, Reverse };/* No need to ref/unref .mr, the FlatRange keeps it alive. */ #define MEMORY_LISTENER_UPDATE_REGION(fr, as, dir, callback, _args...) \ do { \ - MemoryRegionSection mrs = section_from_flat_range(fr, as); \ + MemoryRegionSection mrs = section_from_flat_range(fr, \ + address_space_to_flatview(as)); \ MEMORY_LISTENER_CALL(as, callback, dir, &mrs, ##_args); \ } while(0)
@@ -208,7 +209,6 @@ static bool memory_region_ioeventfd_equal(MemoryRegionIoeventfd a, }typedef struct FlatRange FlatRange ; -typedef struct FlatView FlatView ;/* Range of memory in the global map. Addresses are absolute. */ struct FlatRange {
@@ -238,11 +238,11 @@ typedef struct AddressSpaceOps AddressSpaceOps;for (var = (view)->ranges; var < (view)->ranges + (view)->nr; ++var) static inline MemoryRegionSection -section_from_flat_range (FlatRange *fr,AddressSpace *as) +section_from_flat_range (FlatRange *fr,FlatView *fv) {return (MemoryRegionSection ) { .mr = fr->mr, - .address_space = as, + .fv = fv, .offset_within_region = fr->offset_in_region, .size = fr->addr.size, .offset_within_address_space =int128_get64 (fr->addr.start),
@@ -312,7 +312,7 @@ static void flatview_unref(FlatView *view) } } -static FlatView *address_space_to_flatview (AddressSpace *as) +FlatView *address_space_to_flatview (AddressSpace *as) {return atomic_rcu_read (&as->current_map); }
@@ -761,7 +761,7 @@ static void address_space_add_del_ioeventfds(AddressSpace *as, fds_new[inew]))) { fd = &fds_old[iold]; section = (MemoryRegionSection ) { - .address_space = as, + .fv =address_space_to_flatview (as), .offset_within_address_space =int128_get64 (fd->addr.start), .size = fd->addr.size, };
@@ -774,7 +774,7 @@ static void address_space_add_del_ioeventfds(AddressSpace *as, fds_old[iold]))) { fd = &fds_new[inew]; section = (MemoryRegionSection ) { - .address_space = as, + .fv =address_space_to_flatview (as), .offset_within_address_space =int128_get64 (fd->addr.start), .size = fd->addr.size, };
@@ -794,7 +794,7 @@ static FlatView *address_space_get_flatview(AddressSpace *as)rcu_read_lock (); do { - view = atomic_rcu_read(&as->current_map); + view = address_space_to_flatview(as); /* If somebody has replaced as->current_map concurrently, * flatview_ref returns false. */
@@ -913,8 +913,8 @@ static void address_space_update_topology(AddressSpace *as) new_view->dispatch =mem_begin (as);for (i =0 ; i < new_view->nr; i++) {MemoryRegionSection mrs = -section_from_flat_range (&new_view->ranges[i], as); -mem_add (as, new_view, &mrs); +section_from_flat_range (&new_view->ranges[i], new_view); +mem_add (new_view, &mrs); }mem_commit (new_view->dispatch);
@@ -1870,7 +1870,7 @@ void memory_region_sync_dirty_bitmap(MemoryRegion *mr) view =address_space_get_flatview (as); FOR_EACH_FLAT_RANGE(fr, view) {if (fr->mr == mr) { -MemoryRegionSection mrs =section_from_flat_range (fr, as); +MemoryRegionSection mrs =section_from_flat_range (fr, view); listener->log_sync (listener, &mrs); } }
@@ -1973,7 +1973,7 @@ static void memory_region_update_coalesced_range_as(MemoryRegion *mr, AddressSpa FOR_EACH_FLAT_RANGE(fr, view) {if (fr->mr == mr) { section = (MemoryRegionSection ) { - .address_space = as, + .fv = view, .offset_within_address_space =int128_get64 (fr->addr.start), .size = fr->addr.size, };
@@ -2324,7 +2324,7 @@ static MemoryRegionSection memory_region_find_rcu(MemoryRegion *mr, } range =addrrange_make (int128_make64 (addr),int128_make64 (size)); - view =atomic_rcu_read (&as->current_map); + view =address_space_to_flatview (as); fr =flatview_lookup (view, range);if (!fr) {return ret;
@@ -2335,7 +2335,7 @@ static MemoryRegionSection memory_region_find_rcu(MemoryRegion *mr, } ret.mr = fr->mr; - ret.address_space = as; + ret.fv = view; range =addrrange_intersection (range, fr->addr); ret.offset_within_region = fr->offset_in_region; ret.offset_within_region += int128_get64(int128_sub(range.start,
@@ -2384,7 +2384,8 @@ void memory_global_dirty_log_sync(void) view =address_space_get_flatview (as); FOR_EACH_FLAT_RANGE(fr, view) {if (fr->dirty_log_mask) { -MemoryRegionSection mrs =section_from_flat_range (fr, as); +MemoryRegionSection mrs =section_from_flat_range (fr, view); + listener->log_sync (listener, &mrs); } }
@@ -2469,7 +2470,7 @@ static void listener_add_address_space(MemoryListener *listener, FOR_EACH_FLAT_RANGE(fr, view) {MemoryRegionSection section = { .mr = fr->mr, - .address_space = as, + .fv = view, .offset_within_region = fr->offset_in_region, .size = fr->addr.size, .offset_within_address_space =int128_get64 (fr->addr.start),
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 16/32] memory: Move address_space_update_ioeventfds
In reply to Paolo BonziniFrom: Alexey Kardashevskiy <[email protected]>
So it is called (twice) from the same function. This is to make the next patches a bit simpler.
Message-Id: <[email protected]>
--- memory.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
memory.c +1 -2
@@ -952,8 +952,6 @@ static void address_space_update_topology(AddressSpace *as)* counting is necessary. */ flatview_unref (old_view); - -address_space_update_ioeventfds (as); }void memory_region_transaction_begin (void )
@@ -976,6 +974,7 @@ void memory_region_transaction_commit(void) QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) {address_space_update_topology (as); +address_space_update_ioeventfds (as); } memory_region_update_pending = false;MEMORY_LISTENER_CALL_GLOBAL (commit, Forward);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 17/32] memory: Share FlatView's and dispatch trees between address spaces
In reply to Paolo BonziniFrom: Alexey Kardashevskiy <[email protected]>
This allows sharing flat views between address spaces (AS) when the same root memory region is used when creating a new address space. This is done by walking through all ASes and caching one FlatView per a physical root MR (i.e. not aliased).
This removes search for duplicates from address_space_init_shareable() as FlatViews are shared elsewhere and keeping as::ref_count correct seems an unnecessary and useless complication.
This should cause no change and memory use or boot time yet.
Message-Id: <[email protected]>
--- memory.c | 56 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 11 deletions(-)
memory.c +45 -11
@@ -47,6 +47,8 @@ static QTAILQ_HEAD(memory_listeners, MemoryListener) memory_listeners static QTAILQ_HEAD(, AddressSpace) address_spaces =QTAILQ_HEAD_INITIALIZER (address_spaces); +static GHashTable *flat_views; +typedef struct AddrRange AddrRange ;/*
@@ -761,6 +763,7 @@ static FlatView *generate_memory_topology(MemoryRegion *mr)flatview_add_to_dispatch (view, &mrs); }address_space_dispatch_compact (view->dispatch); +g_hash_table_replace (flat_views, mr, view);return view; }
@@ -930,11 +933,47 @@ static void address_space_update_topology_pass(AddressSpace *as, } } -static void address_space_update_topology (AddressSpace *as) +static void flatviews_init (void ) +{ +if (flat_views) { +return ; + } + + flat_views =g_hash_table_new_full (g_direct_hash, g_direct_equal,NULL , + (GDestroyNotify ) flatview_unref); +} + +static void flatviews_reset (void ) +{ +AddressSpace *as; + +if (flat_views) { +g_hash_table_unref (flat_views); + flat_views =NULL ; + } +flatviews_init (); + +/* Render unique FVs */ + QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { +MemoryRegion *physmr =memory_region_get_flatview_root (as->root); + +if (g_hash_table_lookup (flat_views, physmr)) { +continue ; + } + +generate_memory_topology (physmr); + } +} + +static void address_space_set_flatview (AddressSpace *as) {FlatView *old_view =address_space_get_flatview (as); -MemoryRegion *physmr =memory_region_get_flatview_root (old_view->root); -FlatView *new_view =generate_memory_topology (physmr); +MemoryRegion *physmr =memory_region_get_flatview_root (as->root); +FlatView *new_view =g_hash_table_lookup (flat_views, physmr); + +assert (new_view); + +flatview_ref (new_view);if (!QTAILQ_EMPTY (&as->listeners)) {address_space_update_topology_pass (as, old_view, new_view, false);
@@ -970,10 +1009,12 @@ void memory_region_transaction_commit(void) --memory_region_transaction_depth;if (!memory_region_transaction_depth) {if (memory_region_update_pending) { +flatviews_reset (); +MEMORY_LISTENER_CALL_GLOBAL (begin, Forward); QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { -address_space_update_topology (as); +address_space_set_flatview (as);address_space_update_ioeventfds (as); } memory_region_update_pending = false;
@@ -2696,13 +2737,6 @@ AddressSpace *address_space_init_shareable(MemoryRegion *root, const char *name) {AddressSpace *as; - QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { -if (root == as->root && as->malloced) { - as->ref_count++; -return as; - } - } - as =g_malloc0 (sizeof *as);address_space_init (as, root, name); as->malloced = true;
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 18/32] memory: Do not allocate FlatView in address_space_init
In reply to Paolo BonziniFrom: Alexey Kardashevskiy <[email protected]>
This creates a new AS object without any FlatView as memory_region_transaction_commit() may want to reuse the empty FV.
Message-Id: <[email protected]>
--- memory.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-)
memory.c +23 -6
@@ -967,22 +967,37 @@ static void flatviews_reset(void)static void address_space_set_flatview (AddressSpace *as) { -FlatView *old_view =address_space_get_flatview (as); +FlatView *old_view =address_space_to_flatview (as);MemoryRegion *physmr =memory_region_get_flatview_root (as->root);FlatView *new_view =g_hash_table_lookup (flat_views, physmr);assert (new_view); +if (old_view == new_view) { +return ; + } + +if (old_view) { +flatview_ref (old_view); + } +flatview_ref (new_view);if (!QTAILQ_EMPTY (&as->listeners)) { -address_space_update_topology_pass (as, old_view, new_view, false); -address_space_update_topology_pass (as, old_view, new_view, true); +FlatView tmpview = { .nr =0 }, *old_view2 = old_view; + +if (!old_view2) { + old_view2 = &tmpview; + } +address_space_update_topology_pass (as, old_view2, new_view, false); +address_space_update_topology_pass (as, old_view2, new_view, true); }/* Writes are protected by the BQL. */ atomic_rcu_set (&as->current_map, new_view); -flatview_unref (old_view); +if (old_view) { +flatview_unref (old_view); + }/* Note that all the old MemoryRegions are still alive up to this * point. This relieves most MemoryListeners from the need to
@@ -990,7 +1005,9 @@ static void address_space_set_flatview(AddressSpace *as)* outside the iothread mutex, in which case precise reference * counting is necessary. */ -flatview_unref (old_view); +if (old_view) { +flatview_unref (old_view); + } }void memory_region_transaction_begin (void )
@@ -2708,7 +2725,7 @@ void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name) as->ref_count =1 ; as->root = root; as->malloced = false; - as->current_map =flatview_new (root); + as->current_map =NULL ; as->ioeventfd_nb =0 ; as->ioeventfds =NULL ;QTAILQ_INIT (&as->listeners);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 19/32] memory: Rework "info mtree" to print flat views and dispatch trees
In reply to Paolo BonziniFrom: Alexey Kardashevskiy <[email protected]>
This adds a new "-d" switch to "info mtree" to print dispatch tree internals.
This changes the way "-f" is handled - it prints now flat views and associated address spaces.
Message-Id: <[email protected]>
--- exec.c | 84 +++++++++++++++++++++++++++++++++++++++ hmp-commands-info.hx | 7 ++-- include/exec/memory-internal.h | 4 ++ include/exec/memory.h | 3 +- memory.c | 90 +++++++++++++++++++++++++++++++++++++----- monitor.c | 3 +- 6 files changed, 176 insertions(+), 15 deletions(-)
exec.c +84 -0
@@ -3616,3 +3616,87 @@ void page_size_init(void) } qemu_host_page_mask = -(intptr_t )qemu_host_page_size; } + +#if !defined(CONFIG_USER_ONLY ) + +static void mtree_print_phys_entries (fprintf_function mon,void *f, +int start,int end,int skip,int ptr) +{ +if (start == end -1 ) { +mon (f,"\t%3d " , start); + }else { +mon (f,"\t%3d..%-3d " , start, end -1 ); + } +mon (f," skip=%d " , skip); +if (ptr ==PHYS_MAP_NODE_NIL ) { +mon (f," ptr=NIL" ); + }else if (!skip) { +mon (f," ptr=#%d" , ptr); + }else { +mon (f," ptr=[%d]" , ptr); + } +mon (f,"\n" ); +} + +#define MR_SIZE (size) (int128_nz(size) ? (hwaddr)int128_get64( \ + int128_sub((size), int128_one())) : 0) + +void mtree_print_dispatch (fprintf_function mon,void *f, +AddressSpaceDispatch *d,MemoryRegion *root) +{ +int i; + +mon (f," Dispatch\n" ); +mon (f," Physical sections\n" ); + +for (i =0 ; i < d->map.sections_nb; ++i) { +MemoryRegionSection *s = d->map.sections + i; +const char *names[] = {" [unassigned]" ," [not dirty]" , +" [ROM]" ," [watch]" }; + +mon (f," #%d @" TARGET_FMT_plx".." TARGET_FMT_plx" %s%s%s%s%s" , + i, + s->offset_within_address_space, + s->offset_within_address_space +MR_SIZE (s->mr->size), + s->mr->name ? s->mr->name :"(noname)" , + i <ARRAY_SIZE (names) ? names[i] :"" , + s->mr == root ?" [ROOT]" :"" , + s == d->mru_section ?" [MRU]" :"" , + s->mr->is_iommu ?" [iommu]" :"" ); + +if (s->mr->alias) { +mon (f," alias=%s" , s->mr->alias->name ? + s->mr->alias->name :"noname" ); + } +mon (f,"\n" ); + } + +mon (f," Nodes (%d bits per level, %d levels) ptr=[%d] skip=%d\n" , +P_L2_BITS ,P_L2_LEVELS , d->phys_map.ptr, d->phys_map.skip); +for (i =0 ; i < d->map.nodes_nb; ++i) { +int j, jprev; +PhysPageEntry prev; +Node *n = d->map.nodes + i; + +mon (f," [%d]\n" , i); + +for (j =0 , jprev =0 , prev = *n[0 ]; j <ARRAY_SIZE (*n); ++j) { +PhysPageEntry *pe = *n + j; + +if (pe->ptr == prev.ptr && pe->skip == prev.skip) { +continue ; + } + +mtree_print_phys_entries (mon, f, jprev, j, prev.skip, prev.ptr); + + jprev = j; + prev = *pe; + } + +if (jprev !=ARRAY_SIZE (*n)) { +mtree_print_phys_entries (mon, f, jprev, j, prev.skip, prev.ptr); + } + } +} + +#endif
hmp-commands-info.hx +4 -3
@@ -250,9 +250,10 @@ ETEXI { .name = "mtree", - .args_type = "flatview:-f", - .params = "[-f]", - .help = "show memory tree (-f: dump flat view for address spaces)", + .args_type = "flatview:-f,dispatch_tree:-d", + .params = "[-f][-d]", + .help = "show memory tree (-f: dump flat view for address spaces;" + "-d: dump dispatch tree, valid with -f only)", .cmd = hmp_info_mtree, },
include/exec/memory-internal.h +4 -0
@@ -35,5 +35,9 @@ AddressSpaceDispatch *address_space_to_dispatch(AddressSpace *as);AddressSpaceDispatch *flatview_to_dispatch (FlatView *fv);void address_space_dispatch_free (AddressSpaceDispatch *d); +void mtree_print_dispatch (fprintf_function mon,void *f, +struct AddressSpaceDispatch *d, +MemoryRegion *root); +#endif #endif
include/exec/memory.h +2 -1
@@ -1515,7 +1515,8 @@ void memory_global_dirty_log_start(void);*/ void memory_global_dirty_log_stop (void ); -void mtree_info (fprintf_function mon_printf,void *f,bool flatview); +void mtree_info (fprintf_function mon_printf,void *f,bool flatview, +bool dispatch_tree);/** * memory_region_request_mmio_ptr: request a pointer to an mmio
memory.c +80 -10
119 lines not on this page · raw message
monitor.c +2 -1
@@ -1703,8 +1703,9 @@ static void hmp_boot_set(Monitor *mon, const QDict *qdict)static void hmp_info_mtree (Monitor *mon,const QDict *qdict) {bool flatview =qdict_get_try_bool (qdict,"flatview" , false); +bool dispatch_tree =qdict_get_try_bool (qdict,"dispatch_tree" , false); -mtree_info ((fprintf_function )monitor_printf, mon, flatview); +mtree_info ((fprintf_function )monitor_printf, mon, flatview, dispatch_tree); }static void hmp_info_numa (Monitor *mon,const QDict *qdict)
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 20/32] memory: Get rid of address_space_init_shareable
In reply to Paolo BonziniFrom: Alexey Kardashevskiy <[email protected]>
Since FlatViews are shared now and ASes not, this gets rid of address_space_init_shareable().
This should cause no behavioural change.
Message-Id: <[email protected]>
--- 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 | 16 ++++++++-------- target/i386/cpu.c | 5 +++-- 7 files changed, 19 insertions(+), 58 deletions(-)
cpus.c +3 -2
@@ -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 =address_space_init_shareable (cpu->memory, -"cpu-memory" ); +AddressSpace *as =g_new0 (AddressSpace,1 ); + +address_space_init (as, cpu->memory,"cpu-memory" ); cpu->num_ases =1 ;cpu_address_space_init (cpu, as,0 ); }
hw/arm/armv7m.c +4 -5
@@ -41,7 +41,7 @@ static MemTxResult bitband_read(void *opaque, hwaddr offset,/* Find address in underlying memory and round down to multiple of size */ addr =bitband_addr (s, offset) & (-size); - res =address_space_read (s->source_as, addr, attrs, buf, size); + res =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 offset, uint64_t value,/* Find address in underlying memory and round down to multiple of size */ addr =bitband_addr (s, offset) & (-size); - res =address_space_read (s->source_as, addr, attrs, buf, size); + res =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 offset, uint64_t value, }else { buf[bitpos >>3 ] &= ~bit; } -return address_space_write (s->source_as, addr, attrs, buf, size); +return address_space_write (&s->source_as, addr, attrs, buf, size); }static const MemoryRegionOps bitband_ops = {
@@ -111,8 +111,7 @@ static void bitband_realize(DeviceState *dev, Error **errp)return ; } - s->source_as =address_space_init_shareable (s->source_memory, -"bitband-source" ); +address_space_init (&s->source_as, s->source_memory,"bitband-source" ); }/* Board init. */
include/exec/memory.h +0 -19
@@ -309,8 +309,6 @@ struct AddressSpace {struct rcu_head rcu;char *name;MemoryRegion *root; -int ref_count; -bool malloced;/* Accessed via RCU. */ struct FlatView *current_map;
@@ -1586,23 +1584,6 @@ MemTxResult memory_region_dispatch_write(MemoryRegion *mr,void address_space_init (AddressSpace *as,MemoryRegion *root,const char *name);/** -* address_space_init_shareable: return an address space for a memory region, -* 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 address space
include/hw/arm/armv7m.h +1 -1
@@ -21,7 +21,7 @@ typedef struct {SysBusDevice parent_obj;/*< public >*/ -AddressSpace *source_as; +AddressSpace source_as;MemoryRegion iomem;uint32_t base;MemoryRegion *source_memory;
memory.c +0 -21
@@ -2722,9 +2722,7 @@ void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name) {memory_region_ref (root);memory_region_transaction_begin (); - as->ref_count =1 ; as->root = root; - as->malloced = false; as->current_map =NULL ; as->ioeventfd_nb =0 ; as->ioeventfds =NULL ;
@@ -2737,37 +2735,18 @@ void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name)static void do_address_space_destroy (AddressSpace *as) { -bool do_free = as->malloced; -assert (QTAILQ_EMPTY (&as->listeners));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 =g_malloc0 (sizeof *as); -address_space_init (as, root, name); - as->malloced = true; -return as; }void address_space_destroy (AddressSpace *as) {MemoryRegion *root = as->root; - as->ref_count--; -if (as->ref_count) { -return ; - }/* Flush out anything from MemoryListeners listening in on this */ memory_region_transaction_begin (); as->root =NULL ;
target/arm/cpu.c +8 -8
@@ -684,6 +684,9 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)CPUARMState *env = &cpu->env;int pagebits;Error *local_err =NULL ; +#ifndef CONFIG_USER_ONLY +AddressSpace *as; +#endif cpu_exec_realizefn (cs, &local_err);if (local_err !=NULL ) {
@@ -874,24 +877,21 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)#ifndef CONFIG_USER_ONLY if (cpu->has_el3 ||arm_feature (env,ARM_FEATURE_M_SECURITY )) { -AddressSpace *as; + as =g_new0 (AddressSpace,1 ); cs->num_ases =2 ;if (!cpu->secure_memory) { cpu->secure_memory = cs->memory; } - as =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); }else { cs->num_ases =1 ; } - -cpu_address_space_init (cs, -address_space_init_shareable (cs->memory, -"cpu-memory" ), - ARMASIdx_NS); + as =g_new0 (AddressSpace,1 ); +address_space_init (as, cs->memory,"cpu-memory" ); +cpu_address_space_init (cs, as, ARMASIdx_NS);#endif qemu_init_vcpu (cs);
target/i386/cpu.c +3 -2
@@ -3738,10 +3738,11 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)#ifndef CONFIG_USER_ONLY if (tcg_enabled ()) { -AddressSpace *as_normal =address_space_init_shareable (cs->memory, -"cpu-memory" ); +AddressSpace *as_normal =g_new0 (AddressSpace,1 );AddressSpace *as_smm =g_new (AddressSpace,1 ); +address_space_init (as_normal, cs->memory,"cpu-memory" ); + cpu->cpu_as_mem =g_new (MemoryRegion,1 ); cpu->cpu_as_root =g_new (MemoryRegion,1 );
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 21/32] memory: Create FlatView directly
In reply to Paolo BonziniFrom: Alexey Kardashevskiy <[email protected]>
This avoids usual memory_region_transaction_commit() which rebuilds all FVs.
On POWER8 with 255 CPUs, 255 virtio-net, 40 PCI bridges guest this brings down the boot time from 25s to 20s and reduces the amount of temporary FVs allocated during machine constructon (~800000 -> ~640000) and amount of temporary dispatch trees (~370000 -> ~300000), the total memory footprint goes down (18G -> 17G).
Message-Id: <[email protected]>
--- memory.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
memory.c +13 -3
@@ -1010,6 +1010,17 @@ static void address_space_set_flatview(AddressSpace *as) } } +static void address_space_update_topology (AddressSpace *as) +{ +MemoryRegion *physmr =memory_region_get_flatview_root (as->root); + +flatviews_init (); +if (!g_hash_table_lookup (flat_views, physmr)) { +generate_memory_topology (physmr); + } +address_space_set_flatview (as); +} +void memory_region_transaction_begin (void ) {qemu_flush_coalesced_mmio_buffer ();
@@ -2721,7 +2732,6 @@ void memory_region_invalidate_mmio_ptr(MemoryRegion *mr, hwaddr offset,void address_space_init (AddressSpace *as,MemoryRegion *root,const char *name) {memory_region_ref (root); -memory_region_transaction_begin (); as->root = root; as->current_map =NULL ; as->ioeventfd_nb =0 ;
@@ -2729,8 +2739,8 @@ void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name)QTAILQ_INIT (&as->listeners);QTAILQ_INSERT_TAIL (&address_spaces, as, address_spaces_link); as->name =g_strdup (name ? name :"anonymous" ); - memory_region_update_pending |= root->enabled; -memory_region_transaction_commit (); +address_space_update_topology (as); +address_space_update_ioeventfds (as); }static void do_address_space_destroy (AddressSpace *as)
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 22/32] memory: trace FlatView creation and destruction
In reply to Paolo Bonzini--- include/exec/memory.h | 1 - include/qemu/typedefs.h | 1 + memory.c | 3 +++ trace-events | 3 +++ 4 files changed, 7 insertions(+), 1 deletion(-)
include/exec/memory.h +0 -1
@@ -48,7 +48,6 @@typedef struct MemoryRegionOps MemoryRegionOps ;typedef struct MemoryRegionMmio MemoryRegionMmio ; -typedef struct FlatView FlatView ;struct MemoryRegionMmio {CPUReadMemoryFunc *read[3 ];
include/qemu/typedefs.h +1 -0
@@ -30,6 +30,7 @@ typedef struct DisplaySurface DisplaySurface;typedef struct DriveInfo DriveInfo ;typedef struct Error Error ;typedef struct EventNotifier EventNotifier ; +typedef struct FlatView FlatView ;typedef struct FWCfgEntry FWCfgEntry ;typedef struct FWCfgIoState FWCfgIoState ;typedef struct FWCfgMemState FWCfgMemState ;
memory.c +3 -0
@@ -270,6 +270,7 @@ static FlatView *flatview_new(MemoryRegion *mr_root) view->ref =1 ; view->root = mr_root;memory_region_ref (mr_root); +trace_flatview_new (view, mr_root);return view; }
@@ -295,6 +296,7 @@ static void flatview_destroy(FlatView *view) {int i; +trace_flatview_destroy (view, view->root);if (view->dispatch) {address_space_dispatch_free (view->dispatch); }
@@ -314,6 +316,7 @@ static bool flatview_ref(FlatView *view)static void flatview_unref (FlatView *view) {if (atomic_fetch_dec (&view->ref) ==1 ) { +trace_flatview_destroy_rcu (view, view->root);call_rcu (view, flatview_destroy, rcu); } }
trace-events +3 -0
@@ -64,6 +64,9 @@ memory_region_tb_read(int cpu_index, uint64_t addr, uint64_t value, unsigned siz memory_region_tb_write(int cpu_index, uint64_t addr, uint64_t value, unsigned size) "cpu %d addr 0x%"PRIx64" value 0x%"PRIx64" size %u" memory_region_ram_device_read(int cpu_index, void *mr, uint64_t addr, uint64_t value, unsigned size) "cpu %d mr %p addr 0x%"PRIx64" value 0x%"PRIx64" size %u" memory_region_ram_device_write(int cpu_index, void *mr, uint64_t addr, uint64_t value, unsigned size) "cpu %d mr %p addr 0x%"PRIx64" value 0x%"PRIx64" size %u" +flatview_new(FlatView *view, MemoryRegion *root) "%p (root %p)" +flatview_destroy(FlatView *view, MemoryRegion *root) "%p (root %p)" +flatview_destroy_rcu(FlatView *view, MemoryRegion *root) "%p (root %p)" ### Guest events, keep at bottom
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 23/32] memory: seek FlatView sharing candidates among children subregions
In reply to Paolo BonziniA container can be used instead of an alias to allow switching between multiple subregions. In this case we cannot directly share the subregions (since they only belong to a single parent), but if the subregions are aliases we can in turn walk those.
This is not enough to remove all source of quadratic FlatView creation, but it enables sharing of the PCI bus master FlatViews (and their AddressSpaceDispatch structures) across all PCI devices. For 112 virtio-net-pci devices, boot time is reduced from 25 to 10 seconds and memory consumption from 1.4 to 1 G.
--- memory.c | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-)
memory.c +34 -6
@@ -734,12 +734,40 @@ static void render_memory_region(FlatView *view,static MemoryRegion *memory_region_get_flatview_root (MemoryRegion *mr) { -while (mr->alias && !mr->alias_offset && -int128_ge (mr->size, mr->alias->size)) { -/* The alias is included in its entirety. Use it as -* the "real" root, so that we can share more FlatViews. -*/ - mr = mr->alias; +while (mr->enabled) { +if (mr->alias) { +if (!mr->alias_offset &&int128_ge (mr->size, mr->alias->size)) { +/* The alias is included in its entirety. Use it as +* the "real" root, so that we can share more FlatViews. +*/ + mr = mr->alias; +continue ; + } + }else if (!mr->terminates) { +unsigned int found =0 ; +MemoryRegion *child, *next =NULL ; + QTAILQ_FOREACH(child, &mr->subregions, subregions_link) { +if (child->enabled) { +if (++found >1 ) { + next =NULL ; +break ; + } +if (!child->addr &&int128_ge (mr->size, child->size)) { +/* A child is included in its entirety. If it's the only +* enabled one, use it in the hope of finding an alias down the +* way. This will also let us share FlatViews. +*/ + next = child; + } + } + } +if (next) { + mr = next; +continue ; + } + } + +break ; }return mr;
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 24/32] memory: Share special empty FlatView
In reply to Paolo BonziniFrom: Alexey Kardashevskiy <[email protected]>
This shares an cached empty FlatView among address spaces. The empty FV is used every time when a root MR renders into a FV without memory sections which happens when MR or its children are not enabled or zero-sized. The empty_view is not NULL to keep the rest of memory API intact; it also has a dispatch tree for the same reason.
On POWER8 with 255 CPUs, 255 virtio-net, 40 PCI bridges guest this halves the amount of FlatView's in use (557 -> 260) and dispatch tables (~800000 -> ~370000). In an unrelated experiment with 112 non-virtio devices on x86 ("-M pc"), only 4 FlatViews are alive, and about ~2000 are created at startup.
Message-Id: <[email protected]>
--- memory.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
memory.c +16 -2
@@ -317,6 +317,7 @@ static void flatview_unref(FlatView *view) {if (atomic_fetch_dec (&view->ref) ==1 ) {trace_flatview_destroy_rcu (view, view->root); +assert (view->root);call_rcu (view, flatview_destroy, rcu); } }
@@ -761,16 +762,19 @@ static MemoryRegion *memory_region_get_flatview_root(MemoryRegion *mr) } } } +if (found ==0 ) { +return NULL ; + }if (next) { mr = next;continue ; } } -break ; +return mr; } -return mr; +return NULL ; }/* Render a memory topology into a list of disjoint absolute ranges. */
@@ -966,12 +970,22 @@ static void address_space_update_topology_pass(AddressSpace *as,static void flatviews_init (void ) { +static FlatView *empty_view; +if (flat_views) {return ; } flat_views =g_hash_table_new_full (g_direct_hash, g_direct_equal,NULL , (GDestroyNotify ) flatview_unref); +if (!empty_view) { + empty_view =generate_memory_topology (NULL ); +/* We keep it alive forever in the global variable. */ +flatview_ref (empty_view); + }else { +g_hash_table_replace (flat_views,NULL , empty_view); +flatview_ref (empty_view); + } }static void flatviews_reset (void )
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 25/32] scsi, file-posix: add support for persistent reservation management
In reply to Paolo BonziniIt is a common requirement for virtual machine to send persistent reservations, but this currently requires either running QEMU with CAP_SYS_RAWIO, or using out-of-tree patches that let an unprivileged QEMU bypass Linux's filter on SG_IO commands.
As an alternative mechanism, the next patches will introduce a privileged helper to run persistent reservation commands without expanding QEMU's attack surface unnecessarily.
The helper is invoked through a "pr-manager" QOM object, to which file-posix.c passes SG_IO requests for PERSISTENT RESERVE OUT and PERSISTENT RESERVE IN commands. For example:
$ qemu-system-x86_64
-device virtio-scsi \
-object pr-manager-helper,id=helper0,path=/var/run/qemu-pr-helper.sock
-drive if=none,id=hd,driver=raw,file.filename=/dev/sdb,file.pr-manager=helper0
-device scsi-block,drive=hdor:
$ qemu-system-x86_64
-device virtio-scsi \
-object pr-manager-helper,id=helper0,path=/var/run/qemu-pr-helper.sock
-blockdev node-name=hd,driver=raw,file.driver=host_device,file.filename=/dev/sdb,file.pr-manager=helper0
-device scsi-block,drive=hdMultiple pr-manager implementations are conceivable and possible, though only one is implemented right now. For example, a pr-manager could:
- talk directly to the multipath daemon from a privileged QEMU (i.e. QEMU links to libmpathpersist); this makes reservation work properly with multipath, but still requires CAP_SYS_RAWIO
- use the Linux IOC_PR_* ioctls (they require CAP_SYS_ADMIN though)
- more interestingly, implement reservations directly in QEMU through file system locks or a shared database (e.g. sqlite)
--- Makefile.objs | 1 + block/file-posix.c | 30 +++++++++++++ docs/pr-manager.rst | 51 ++++++++++++++++++++++ include/scsi/pr-manager.h | 56 ++++++++++++++++++++++++ qapi/block-core.json | 4 ++ scsi/Makefile.objs | 2 + scsi/pr-manager.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++ scsi/trace-events | 3 ++ vl.c | 3 +- 9 files changed, 258 insertions(+), 1 deletion(-) create mode 100644 docs/pr-manager.rst create mode 100644 include/scsi/pr-manager.h create mode 100644 scsi/pr-manager.c create mode 100644 scsi/trace-events
Makefile.objs +1 -0
@@ -171,6 +171,7 @@ trace-events-subdirs += qapi trace-events-subdirs += accel/tcg trace-events-subdirs += accel/kvm trace-events-subdirs += nbd +trace-events-subdirs += scsi trace-events-files = $(SRC_PATH)/trace-events $(trace-events-subdirs:%=$(SRC_PATH)/%/trace-events)
block/file-posix.c +30 -0
@@ -33,6 +33,9 @@#include "block/raw-aio.h" #include "qapi/qmp/qstring.h" +#include "scsi/pr-manager.h" +#include "scsi/constants.h" +#if defined(__APPLE__) && (__MACH__)#include <paths.h> #include <sys/param.h>
@@ -155,6 +158,8 @@ typedef struct BDRVRawState { bool page_cache_inconsistent:1;bool has_fallocate;bool needs_alignment; + +PRManager *pr_mgr; } BDRVRawState; typedef struct BDRVRawReopenState {
@@ -402,6 +407,11 @@ static QemuOptsList raw_runtime_opts = { .type = QEMU_OPT_STRING, .help = "file locking mode (on/off/auto, default: auto)", }, + { + .name = "pr-manager", + .type = QEMU_OPT_STRING, + .help = "id of persistent reservation manager object (default: none)", + }, {/* end of list */ } }, };
@@ -413,6 +423,7 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,QemuOpts *opts;Error *local_err =NULL ;const char *filename =NULL ; +const char *str;BlockdevAioOptions aio, aio_default;int fd, ret;struct stat st;
@@ -476,6 +487,16 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,abort (); } + str =qemu_opt_get (opts,"pr-manager" ); +if (str) { + s->pr_mgr =pr_manager_lookup (str, &local_err); +if (local_err) { +error_propagate (errp, local_err); + ret = -EINVAL ; + goto fail; + } + } + s->open_flags = open_flags;raw_parse_flags (bdrv_flags, &s->open_flags);
@@ -2597,6 +2618,15 @@ static BlockAIOCB *hdev_aio_ioctl(BlockDriverState *bs,if (fd_open (bs) <0 )return NULL ; +if (req ==SG_IO && s->pr_mgr) { +struct sg_io_hdr *io_hdr = buf; +if (io_hdr->cmdp[0 ] ==PERSISTENT_RESERVE_OUT || + io_hdr->cmdp[0 ] ==PERSISTENT_RESERVE_IN ) { +return pr_manager_execute (s->pr_mgr,bdrv_get_aio_context (bs), + s->fd, io_hdr, cb, opaque); + } + } + acb =g_new (RawPosixAIOData,1 ); acb->bs = bs; acb->aio_type =QEMU_AIO_IOCTL ;
docs/pr-manager.rst new file +51 -0
51 lines not on this page · raw message
include/scsi/pr-manager.h new file +56 -0
56 lines not on this page · raw message
qapi/block-core.json +4 -0
@@ -2241,6 +2241,9 @@ # Driver specific block device options for the file backend. # # @filename: path to the image file +# @pr-manager: the id for the object that will handle persistent reservations +# for this device (default: none, forward the commands via SG_IO; +# since 2.11) # @aio: AIO backend (default: threads) (since: 2.8) # @locking: whether to enable file locking. If set to 'auto', only enable # when Open File Descriptor (OFD) locking API is available
@@ -2250,6 +2253,7 @@ ## { 'struct': 'BlockdevOptionsFile', 'data': { 'filename': 'str', + '*pr-manager': 'str', '*locking': 'OnOffAuto', '*aio': 'BlockdevAioOptions' } }
scsi/Makefile.objs +2 -0
@@ -1 +1,3 @@ block-obj-y += utils.o + +block-obj-$(CONFIG_LINUX) += pr-manager.o
scsi/pr-manager.c new file +109 -0
109 lines not on this page · raw message
scsi/trace-events new file +3 -0
@@ -0,0 +1,3 @@ +# scsi/pr-manager.c +pr_manager_execute(int fd, int cmd, int sa, void *opaque) "fd=%d cmd=0x%02x service action=0x%02x opaque=%p" +pr_manager_run(int fd, int cmd, int sa) "fd=%d cmd=0x%02x service action=0x%02x"
vl.c +2 -1
@@ -2893,7 +2893,8 @@ static int machine_set_property(void *opaque,*/ static bool object_create_initial (const char *type) { -if (g_str_equal (type,"rng-egd" )) { +if (g_str_equal (type,"rng-egd" ) || +g_str_has_prefix (type,"pr-manager-" )) {return false; }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 29/32] chardev: new qemu_chr_be_update_read_handlers()
In reply to Paolo BonziniFrom: Peter Xu <[email protected]>
Add a wrapper for the chr_update_read_handler().
Message-Id: <[email protected]>
--- chardev/char-fe.c | 7 ++----- chardev/char.c | 10 ++++++++++ include/chardev/char.h | 10 ++++++++++ 3 files changed, 22 insertions(+), 5 deletions(-)
chardev/char-fe.c +2 -5
@@ -253,7 +253,6 @@ void qemu_chr_fe_set_handlers(CharBackend *b, bool set_open) {Chardev *s; -ChardevClass *cc;int fe_open; s = b->chr;
@@ -261,7 +260,6 @@ void qemu_chr_fe_set_handlers(CharBackend *b,return ; } - cc =CHARDEV_GET_CLASS (s);if (!opaque && !fd_can_read && !fd_read && !fd_event) { fe_open =0 ;remove_fd_in_watch (s);
@@ -273,9 +271,8 @@ void qemu_chr_fe_set_handlers(CharBackend *b, b->chr_event = fd_event; b->chr_be_change = be_change; b->opaque = opaque; -if (cc->chr_update_read_handler) { - cc->chr_update_read_handler (s, context); - } + +qemu_chr_be_update_read_handlers (s, context);if (set_open) {qemu_chr_fe_set_open (b, fe_open);
chardev/char.c +10 -0
@@ -180,6 +180,16 @@ void qemu_chr_be_write(Chardev *s, uint8_t *buf, int len) } } +void qemu_chr_be_update_read_handlers (Chardev *s, +GMainContext *context) +{ +ChardevClass *cc =CHARDEV_GET_CLASS (s); + +if (cc->chr_update_read_handler) { + cc->chr_update_read_handler (s, context); + } +} +int qemu_chr_add_client (Chardev *s,int fd) { return CHARDEV_GET_CLASS(s)->chr_add_client ?
include/chardev/char.h +10 -0
@@ -169,6 +169,16 @@ void qemu_chr_be_write(Chardev *s, uint8_t *buf, int len);void qemu_chr_be_write_impl (Chardev *s,uint8_t *buf,int len);/** +* @qemu_chr_be_update_read_handlers: +* +* Invoked when frontend read handlers are setup +* +* @context the gcontext that will be used to attach the watch sources +*/ +void qemu_chr_be_update_read_handlers (Chardev *s, +GMainContext *context); + +/** * @qemu_chr_be_event: * * Send an event from the back end to the front end.
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 28/32] scsi: add persistent reservation manager using qemu-pr-helper
In reply to Paolo BonziniThis adds a concrete subclass of pr-manager that talks to qemu-pr-helper.
--- scsi/Makefile.objs | 2 +- scsi/pr-manager-helper.c | 302 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 303 insertions(+), 1 deletion(-) create mode 100644 scsi/pr-manager-helper.c
scsi/Makefile.objs +1 -1
@@ -1,3 +1,3 @@ block-obj-y += utils.o -block-obj-$(CONFIG_LINUX) += pr-manager.o +block-obj-$(CONFIG_LINUX) += pr-manager.o pr-manager-helper.o
scsi/pr-manager-helper.c new file +302 -0
302 lines not on this page · raw message
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 26/32] scsi: build qemu-pr-helper
In reply to Paolo BonziniIntroduce a privileged helper to run persistent reservation commands. This lets virtual machines send persistent reservations without using CAP_SYS_RAWIO or out-of-tree patches. The helper uses Unix permissions and SCM_RIGHTS to restrict access to processes that can access its socket and prove that they have an open file descriptor for a raw SCSI device.
The next patch will also correct the usage of persistent reservations with multipath devices.
It would also be possible to support for Linux's IOC_PR_* ioctls in the future, to support NVMe devices. For now, however, only SCSI is supported.
--- Makefile | 4 +- configure | 2 +- docs/interop/pr-helper.rst | 83 ++++++ docs/pr-manager.rst | 33 +++ scsi/pr-helper.h | 41 +++ scsi/qemu-pr-helper.c | 698 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 859 insertions(+), 2 deletions(-) create mode 100644 docs/interop/pr-helper.rst create mode 100644 scsi/pr-helper.h create mode 100644 scsi/qemu-pr-helper.c
Makefile +3 -1
@@ -372,6 +372,8 @@ qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o $(COMMON_LDADDS) fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o fsdev/9p-marshal.o fsdev/9p-iov-marshal.o $(COMMON_LDADDS) fsdev/virtfs-proxy-helper$(EXESUF): LIBS += -lcap +scsi/qemu-pr-helper$(EXESUF): scsi/qemu-pr-helper.o scsi/utils.o $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) + qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx $(SRC_PATH)/scripts/hxtool $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"GEN","$@")
@@ -488,7 +490,7 @@ clean: rm -f *.msi find . \( -name '*.so' -o -name '*.dll' -o -name '*.mo' -o -name '*.[oda]' \) -type f -exec rm {} + rm -f $(filter-out %.tlb,$(TOOLS)) $(HELPERS-y) qemu-ga TAGS cscope.* *.pod *~ */*~ - rm -f fsdev/*.pod + rm -f fsdev/*.pod scsi/*.pod rm -f qemu-img-cmds.h rm -f ui/shader/*-vert.h ui/shader/*-frag.h @# May not be present in GENERATED_FILES
configure +1 -1
@@ -6506,7 +6506,7 @@ fi # build tree in object directory in case the source is not in the current directory DIRS="tests tests/tcg tests/tcg/cris tests/tcg/lm32 tests/libqos tests/qapi-schema tests/tcg/xtensa tests/qemu-iotests" -DIRS="$DIRS docs docs/interop fsdev" +DIRS="$DIRS docs docs/interop fsdev scsi" DIRS="$DIRS pc-bios/optionrom pc-bios/spapr-rtas pc-bios/s390-ccw" DIRS="$DIRS roms/seabios roms/vgabios" DIRS="$DIRS qapi-generated"
docs/interop/pr-helper.rst new file +83 -0
83 lines not on this page · raw message
docs/pr-manager.rst +33 -0
@@ -49,3 +49,36 @@ Alternatively, using ``-blockdev``:: -object pr-manager-helper,id=helper0,path=/var/run/qemu-pr-helper.sock -blockdev node-name=hd,driver=raw,file.driver=host_device,file.filename=/dev/sdb,file.pr-manager=helper0 -device scsi-block,drive=hd + +---------------------------------- +Invoking :program:`qemu-pr-helper` +---------------------------------- + +QEMU provides an implementation of the persistent reservation helper, +called :program:`qemu-pr-helper`. The helper should be started as a +system service and supports the following option: + +-d, --daemon run in the background +-q, --quiet decrease verbosity +-f, --pidfile=path PID file when running as a daemon +-k, --socket=path path to the socket +-T, --trace=trace-opts tracing options + +By default, the socket and PID file are placed in the runtime state +directory, for example :file:`/var/run/qemu-pr-helper.sock` and +:file:`/var/run/qemu-pr-helper.pid`. The PID file is not created +unless :option:`-d` is passed too. + +:program:`qemu-pr-helper` can also use the systemd socket activation +protocol. In this case, the systemd socket unit should specify a +Unix stream socket, like this:: + + [Socket] + ListenStream=/var/run/qemu-pr-helper.sock + +After connecting to the socket, :program:`qemu-pr-helper`` can optionally drop +root privileges, except for those capabilities that are needed for +its operation. To do this, add the following options: + +-u, --user=user user to drop privileges to +-g, --group=group group to drop privileges to
scsi/pr-helper.h new file +41 -0
41 lines not on this page · raw message
scsi/qemu-pr-helper.c new file +698 -0
698 lines not on this page · raw message
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 27/32] scsi: add multipath support to qemu-pr-helper
In reply to Paolo BonziniProper support of persistent reservation for multipath devices requires communication with the multipath daemon, so that the reservation is registered and applied when a path comes up. The device mapper utilities provide a library to do so; this patch makes qemu-pr-helper.c detect multipath devices and, when one is found, delegate the operation to libmpathpersist.
--- Makefile | 3 + configure | 58 ++++++++- docs/pr-manager.rst | 27 ++++ include/scsi/utils.h | 4 + scsi/qemu-pr-helper.c | 346 +++++++++++++++++++++++++++++++++++++++++++++++++- scsi/utils.c | 10 ++ 6 files changed, 442 insertions(+), 6 deletions(-)
Makefile +3 -0
@@ -373,6 +373,9 @@ fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o fsdev/9p-marshal fsdev/virtfs-proxy-helper$(EXESUF): LIBS += -lcap scsi/qemu-pr-helper$(EXESUF): scsi/qemu-pr-helper.o scsi/utils.o $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) +ifdef CONFIG_MPATH +scsi/qemu-pr-helper$(EXESUF): LIBS += -ludev -lmultipath -lmpathpersist +endif qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx $(SRC_PATH)/scripts/hxtool $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"GEN","$@")
configure +55 -3
107 lines not on this page · raw message
docs/pr-manager.rst +27 -0
@@ -60,6 +60,7 @@ system service and supports the following option: -d, --daemon run in the background -q, --quiet decrease verbosity +-v, --verbose increase verbosity -f, --pidfile=path PID file when running as a daemon -k, --socket=path path to the socket -T, --trace=trace-opts tracing options
@@ -82,3 +83,29 @@ its operation. To do this, add the following options: -u, --user=user user to drop privileges to -g, --group=group group to drop privileges to + +--------------------------------------------- +Multipath devices and persistent reservations +--------------------------------------------- + +Proper support of persistent reservation for multipath devices requires +communication with the multipath daemon, so that the reservation is +registered and applied when a path is newly discovered or becomes online +again. :command:`qemu-pr-helper` can do this if the ``libmpathpersist`` +library was available on the system at build time. + +As of August 2017, a reservation key must be specified in ``multipath.conf`` +for ``multipathd`` to check for persistent reservation for newly +discovered paths or reinstated paths. The attribute can be added +to the ``defaults`` section or the ``multipaths`` section; for example:: + + multipaths { + multipath { + wwid XXXXXXXXXXXXXXXX + alias yellow + reservation_key 0x123abc + } + } + +Linking :program:`qemu-pr-helper` to ``libmpathpersist`` does not impede +its usage on regular SCSI devices.
include/scsi/utils.h +4 -0
@@ -72,10 +72,14 @@ extern const struct SCSISense sense_code_IO_ERROR;extern const struct SCSISense sense_code_I_T_NEXUS_LOSS;/* Command aborted, Logical Unit failure */ extern const struct SCSISense sense_code_LUN_FAILURE; +/* Command aborted, LUN Communication failure */ +extern const struct SCSISense sense_code_LUN_COMM_FAILURE;/* Command aborted, Overlapped Commands Attempted */ extern const struct SCSISense sense_code_OVERLAPPED_COMMANDS;/* LUN not ready, Capacity data has changed */ extern const struct SCSISense sense_code_CAPACITY_CHANGED; +/* Unit attention, SCSI bus reset */ +extern const struct SCSISense sense_code_SCSI_BUS_RESET;/* LUN not ready, Medium not present */ extern const struct SCSISense sense_code_UNIT_ATTENTION_NO_MEDIUM;/* Unit attention, Power on, reset or bus device reset occurred */
scsi/qemu-pr-helper.c +343 -3
413 lines not on this page · raw message
scsi/utils.c +10 -0
@@ -206,6 +206,11 @@ const struct SCSISense sense_code_OVERLAPPED_COMMANDS = { .key = ABORTED_COMMAND, .asc = 0x4e, .ascq = 0x00 }; +/* Command aborted, LUN Communication Failure */ +const struct SCSISense sense_code_LUN_COMM_FAILURE = { + .key =ABORTED_COMMAND , .asc =0x08 , .ascq =0x00 +}; +/* Unit attention, Capacity data has changed */ const struct SCSISense sense_code_CAPACITY_CHANGED = { .key =UNIT_ATTENTION , .asc =0x2a , .ascq =0x09
@@ -216,6 +221,11 @@ const struct SCSISense sense_code_RESET = { .key = UNIT_ATTENTION, .asc = 0x29, .ascq = 0x00 }; +/* Unit attention, SCSI bus reset */ +const struct SCSISense sense_code_SCSI_BUS_RESET = { + .key =UNIT_ATTENTION , .asc =0x29 , .ascq =0x02 +}; +/* Unit attention, No medium */ const struct SCSISense sense_code_UNIT_ATTENTION_NO_MEDIUM = { .key =UNIT_ATTENTION , .asc =0x3a , .ascq =0x00
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 30/32] chardev: add Chardev.gcontext field
In reply to Paolo BonziniFrom: Peter Xu <[email protected]>
It caches the gcontext that is used to poll the chardev IO. Before this patch, we only passed it in via chr_update_read_handlers(). However that may not be enough if the char backend is disconnected and reconnected afterward. There are chardev codes that still assumed the context be NULL (which is the main context). Will fix that up in following up patches.
Message-Id: <[email protected]>
--- chardev/char.c | 1 + include/chardev/char.h | 1 + 2 files changed, 2 insertions(+)
chardev/char.c +1 -0
@@ -185,6 +185,7 @@ void qemu_chr_be_update_read_handlers(Chardev *s, {ChardevClass *cc =CHARDEV_GET_CLASS (s); + s->gcontext = context;if (cc->chr_update_read_handler) { cc->chr_update_read_handler (s, context); }
include/chardev/char.h +1 -0
@@ -55,6 +55,7 @@ struct Chardev {int logfd;int be_open;GSource *gsource; +GMainContext *gcontext;DECLARE_BITMAP (features,QEMU_CHAR_FEATURE_LAST ); };
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 31/32] chardev: use per-dev context for io_add_watch_poll
In reply to Paolo BonziniFrom: Peter Xu <[email protected]>
It was only passed in by chr_update_read_handlers(). However when reconnect, we'll lose that context information. So if a chardev was running on another context (rather than the default context, the NULL pointer), it'll switch back to the default context if reconnection happens. But, it should really stick to the old context.
Convert all the callers of io_add_watch_poll() to use the internally cached gcontext. Then the context should be able to survive even after reconnections.
Message-Id: <[email protected]>
--- chardev/char-fd.c | 2 +- chardev/char-pty.c | 2 +- chardev/char-socket.c | 4 ++-- chardev/char-udp.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-)
chardev/char-fd.c +1 -1
@@ -94,7 +94,7 @@ static void fd_chr_update_read_handler(Chardev *chr, chr->gsource =io_add_watch_poll (chr, s->ioc_in, fd_chr_read_poll, fd_chr_read, chr, - context); + chr->gcontext); } }
chardev/char-pty.c +1 -1
@@ -219,7 +219,7 @@ static void pty_chr_state(Chardev *chr, int connected) chr->gsource =io_add_watch_poll (chr, s->ioc, pty_chr_read_poll, pty_chr_read, - chr,NULL ); + chr, chr->gcontext); } } }
chardev/char-socket.c +2 -2
@@ -516,7 +516,7 @@ static void tcp_chr_connect(void *opaque) chr->gsource =io_add_watch_poll (chr, s->ioc, tcp_chr_read_poll, tcp_chr_read, - chr,NULL ); + chr, chr->gcontext); }qemu_chr_be_event (chr,CHR_EVENT_OPENED ); }
@@ -535,7 +535,7 @@ static void tcp_chr_update_read_handler(Chardev *chr, chr->gsource =io_add_watch_poll (chr, s->ioc, tcp_chr_read_poll, tcp_chr_read, chr, - context); + chr->gcontext); } }
chardev/char-udp.c +1 -1
@@ -110,7 +110,7 @@ static void udp_chr_update_read_handler(Chardev *chr, chr->gsource =io_add_watch_poll (chr, s->ioc, udp_chr_read_poll, udp_chr_read, chr, - context); + chr->gcontext); } }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 32/32] chardev: remove context in chr_update_read_handler
In reply to Paolo BonziniFrom: Peter Xu <[email protected]>
We had a per-chardev cache for context, then we don't need this parameter to be passed in every time when chr_update_read_handler() called. As long as we are calling chr_update_read_handler() using qemu_chr_be_update_read_handlers() we'll be fine.
Message-Id: <[email protected]>
--- chardev/char-fd.c | 3 +-- chardev/char-pty.c | 3 +-- chardev/char-socket.c | 3 +-- chardev/char-udp.c | 3 +-- chardev/char.c | 2 +- include/chardev/char.h | 2 +- 6 files changed, 6 insertions(+), 10 deletions(-)
chardev/char-fd.c +1 -2
@@ -84,8 +84,7 @@ static GSource *fd_chr_add_watch(Chardev *chr, GIOCondition cond)return qio_channel_create_watch (s->ioc_out, cond); } -static void fd_chr_update_read_handler (Chardev *chr, -GMainContext *context) +static void fd_chr_update_read_handler (Chardev *chr) {FDChardev *s =FD_CHARDEV (chr);
chardev/char-pty.c +1 -2
@@ -112,8 +112,7 @@ static void pty_chr_update_read_handler_locked(Chardev *chr) } } -static void pty_chr_update_read_handler (Chardev *chr, -GMainContext *context) +static void pty_chr_update_read_handler (Chardev *chr) {qemu_mutex_lock (&chr->chr_write_lock);pty_chr_update_read_handler_locked (chr);
chardev/char-socket.c +1 -2
@@ -521,8 +521,7 @@ static void tcp_chr_connect(void *opaque)qemu_chr_be_event (chr,CHR_EVENT_OPENED ); } -static void tcp_chr_update_read_handler (Chardev *chr, -GMainContext *context) +static void tcp_chr_update_read_handler (Chardev *chr) {SocketChardev *s =SOCKET_CHARDEV (chr);
chardev/char-udp.c +1 -2
@@ -100,8 +100,7 @@ static gboolean udp_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque)return TRUE; } -static void udp_chr_update_read_handler (Chardev *chr, -GMainContext *context) +static void udp_chr_update_read_handler (Chardev *chr) {UdpChardev *s =UDP_CHARDEV (chr);
chardev/char.c +1 -1
@@ -187,7 +187,7 @@ void qemu_chr_be_update_read_handlers(Chardev *s, s->gcontext = context;if (cc->chr_update_read_handler) { - cc->chr_update_read_handler (s, context); + cc->chr_update_read_handler (s); } }
include/chardev/char.h +1 -1
@@ -238,7 +238,7 @@ typedef struct ChardevClass {int (*chr_write)(Chardev *s,const uint8_t *buf,int len);int (*chr_sync_read)(Chardev *s,const uint8_t *buf,int len);GSource *(*chr_add_watch)(Chardev *s,GIOCondition cond); -void (*chr_update_read_handler)(Chardev *s,GMainContext *context); +void (*chr_update_read_handler)(Chardev *s);int (*chr_ioctl)(Chardev *s,int cmd,void *arg);int (*get_msgfds)(Chardev *s,int * fds,int num);int (*set_msgfds)(Chardev *s,int *fds,int num);
Signature · 1 line
1.8.3.1