memory: support stateless memory listeners

Current memory listeners are incremental; that is, they are expected to
maintain their own state, and receive callbacks for changes to that state.

This patch adds support for stateless listeners; these work by receiving
a ->begin() callback (which tells them that new state is coming), a
sequence of ->region_add() and ->region_nop() callbacks, and then a
->commit() callback which signifies the end of the new state.  They should
ignore ->region_del() callbacks.

Signed-off-by: Avi Kivity <avi@redhat.com>
This commit is contained in:
Avi Kivity 2012-02-08 21:36:02 +02:00
parent 4855d41a61
commit 50c1e1491e
6 changed files with 88 additions and 0 deletions

32
exec.c
View File

@ -3488,6 +3488,14 @@ static void io_mem_init(void)
"watch", UINT64_MAX);
}
static void core_begin(MemoryListener *listener)
{
}
static void core_commit(MemoryListener *listener)
{
}
static void core_region_add(MemoryListener *listener,
MemoryRegionSection *section)
{
@ -3500,6 +3508,11 @@ static void core_region_del(MemoryListener *listener,
cpu_register_physical_memory_log(section, false);
}
static void core_region_nop(MemoryListener *listener,
MemoryRegionSection *section)
{
}
static void core_log_start(MemoryListener *listener,
MemoryRegionSection *section)
{
@ -3537,6 +3550,14 @@ static void core_eventfd_del(MemoryListener *listener,
{
}
static void io_begin(MemoryListener *listener)
{
}
static void io_commit(MemoryListener *listener)
{
}
static void io_region_add(MemoryListener *listener,
MemoryRegionSection *section)
{
@ -3551,6 +3572,11 @@ static void io_region_del(MemoryListener *listener,
isa_unassign_ioport(section->offset_within_address_space, section->size);
}
static void io_region_nop(MemoryListener *listener,
MemoryRegionSection *section)
{
}
static void io_log_start(MemoryListener *listener,
MemoryRegionSection *section)
{
@ -3587,8 +3613,11 @@ static void io_eventfd_del(MemoryListener *listener,
}
static MemoryListener core_memory_listener = {
.begin = core_begin,
.commit = core_commit,
.region_add = core_region_add,
.region_del = core_region_del,
.region_nop = core_region_nop,
.log_start = core_log_start,
.log_stop = core_log_stop,
.log_sync = core_log_sync,
@ -3600,8 +3629,11 @@ static MemoryListener core_memory_listener = {
};
static MemoryListener io_memory_listener = {
.begin = io_begin,
.commit = io_commit,
.region_add = io_region_add,
.region_del = io_region_del,
.region_nop = io_region_nop,
.log_start = io_log_start,
.log_stop = io_log_stop,
.log_sync = io_log_sync,

View File

@ -436,6 +436,14 @@ static bool vhost_section(MemoryRegionSection *section)
&& memory_region_is_ram(section->mr);
}
static void vhost_begin(MemoryListener *listener)
{
}
static void vhost_commit(MemoryListener *listener)
{
}
static void vhost_region_add(MemoryListener *listener,
MemoryRegionSection *section)
{
@ -476,6 +484,11 @@ static void vhost_region_del(MemoryListener *listener,
}
}
static void vhost_region_nop(MemoryListener *listener,
MemoryRegionSection *section)
{
}
static int vhost_virtqueue_set_addr(struct vhost_dev *dev,
struct vhost_virtqueue *vq,
unsigned idx, bool enable_log)
@ -756,8 +769,11 @@ int vhost_dev_init(struct vhost_dev *hdev, int devfd, bool force)
hdev->features = features;
hdev->memory_listener = (MemoryListener) {
.begin = vhost_begin,
.commit = vhost_commit,
.region_add = vhost_region_add,
.region_del = vhost_region_del,
.region_nop = vhost_region_nop,
.log_start = vhost_log_start,
.log_stop = vhost_log_stop,
.log_sync = vhost_log_sync,

View File

@ -680,6 +680,14 @@ static void kvm_set_phys_mem(MemoryRegionSection *section, bool add)
}
}
static void kvm_begin(MemoryListener *listener)
{
}
static void kvm_commit(MemoryListener *listener)
{
}
static void kvm_region_add(MemoryListener *listener,
MemoryRegionSection *section)
{
@ -692,6 +700,11 @@ static void kvm_region_del(MemoryListener *listener,
kvm_set_phys_mem(section, false);
}
static void kvm_region_nop(MemoryListener *listener,
MemoryRegionSection *section)
{
}
static void kvm_log_sync(MemoryListener *listener,
MemoryRegionSection *section)
{
@ -795,8 +808,11 @@ static void kvm_eventfd_del(MemoryListener *listener,
}
static MemoryListener kvm_memory_listener = {
.begin = kvm_begin,
.commit = kvm_commit,
.region_add = kvm_region_add,
.region_del = kvm_region_del,
.region_nop = kvm_region_nop,
.log_start = kvm_log_start,
.log_stop = kvm_log_stop,
.log_sync = kvm_log_sync,

View File

@ -676,6 +676,7 @@ static void address_space_update_topology_pass(AddressSpace *as,
/* In both (logging may have changed) */
if (adding) {
MEMORY_LISTENER_UPDATE_REGION(frnew, as, Forward, region_nop);
if (frold->dirty_log_mask && !frnew->dirty_log_mask) {
MEMORY_LISTENER_UPDATE_REGION(frnew, as, Reverse, log_stop);
} else if (frnew->dirty_log_mask && !frold->dirty_log_mask) {
@ -722,6 +723,8 @@ static void memory_region_update_topology(MemoryRegion *mr)
return;
}
MEMORY_LISTENER_CALL_GLOBAL(begin, Forward);
if (address_space_memory.root) {
address_space_update_topology(&address_space_memory);
}
@ -729,6 +732,8 @@ static void memory_region_update_topology(MemoryRegion *mr)
address_space_update_topology(&address_space_io);
}
MEMORY_LISTENER_CALL_GLOBAL(commit, Forward);
memory_region_update_pending = false;
}

View File

@ -180,8 +180,11 @@ typedef struct MemoryListener MemoryListener;
* Use with memory_listener_register() and memory_listener_unregister().
*/
struct MemoryListener {
void (*begin)(MemoryListener *listener);
void (*commit)(MemoryListener *listener);
void (*region_add)(MemoryListener *listener, MemoryRegionSection *section);
void (*region_del)(MemoryListener *listener, MemoryRegionSection *section);
void (*region_nop)(MemoryListener *listener, MemoryRegionSection *section);
void (*log_start)(MemoryListener *listener, MemoryRegionSection *section);
void (*log_stop)(MemoryListener *listener, MemoryRegionSection *section);
void (*log_sync)(MemoryListener *listener, MemoryRegionSection *section);

View File

@ -394,6 +394,14 @@ static void xen_set_memory(struct MemoryListener *listener,
}
}
static void xen_begin(MemoryListener *listener)
{
}
static void xen_commit(MemoryListener *listener)
{
}
static void xen_region_add(MemoryListener *listener,
MemoryRegionSection *section)
{
@ -406,6 +414,11 @@ static void xen_region_del(MemoryListener *listener,
xen_set_memory(listener, section, false);
}
static void xen_region_nop(MemoryListener *listener,
MemoryRegionSection *section)
{
}
static void xen_sync_dirty_bitmap(XenIOState *state,
target_phys_addr_t start_addr,
ram_addr_t size)
@ -500,8 +513,11 @@ static void xen_eventfd_del(MemoryListener *listener,
}
static MemoryListener xen_memory_listener = {
.begin = xen_begin,
.commit = xen_commit,
.region_add = xen_region_add,
.region_del = xen_region_del,
.region_nop = xen_region_nop,
.log_start = xen_log_start,
.log_stop = xen_log_stop,
.log_sync = xen_log_sync,