memory: use AddressSpace for MemoryListener filtering

Using the AddressSpace type reduces confusion, as you can't accidentally
supply the MemoryRegion you're interested in.

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
This commit is contained in:
Avi Kivity 2012-10-02 20:13:51 +02:00
parent 1d71148eac
commit f6790af6bc
9 changed files with 25 additions and 23 deletions

View File

@ -33,6 +33,9 @@ MemoryRegion *get_system_memory(void);
*/ */
MemoryRegion *get_system_io(void); MemoryRegion *get_system_io(void);
extern AddressSpace address_space_memory;
extern AddressSpace address_space_io;
#endif #endif
#endif #endif

10
exec.c
View File

@ -116,8 +116,8 @@ RAMList ram_list = { .blocks = QLIST_HEAD_INITIALIZER(ram_list.blocks) };
static MemoryRegion *system_memory; static MemoryRegion *system_memory;
static MemoryRegion *system_io; static MemoryRegion *system_io;
static AddressSpace address_space_io; AddressSpace address_space_io;
static AddressSpace address_space_memory; AddressSpace address_space_memory;
MemoryRegion io_mem_ram, io_mem_rom, io_mem_unassigned, io_mem_notdirty; MemoryRegion io_mem_ram, io_mem_rom, io_mem_unassigned, io_mem_notdirty;
static MemoryRegion io_mem_subpage_ram; static MemoryRegion io_mem_subpage_ram;
@ -3249,9 +3249,9 @@ static void memory_map_init(void)
address_space_init(&address_space_io, system_io); address_space_init(&address_space_io, system_io);
address_space_io.name = "I/O"; address_space_io.name = "I/O";
memory_listener_register(&core_memory_listener, system_memory); memory_listener_register(&core_memory_listener, &address_space_memory);
memory_listener_register(&io_memory_listener, system_io); memory_listener_register(&io_memory_listener, &address_space_io);
memory_listener_register(&tcg_memory_listener, system_memory); memory_listener_register(&tcg_memory_listener, &address_space_memory);
} }
MemoryRegion *get_system_memory(void) MemoryRegion *get_system_memory(void)

View File

@ -1507,8 +1507,7 @@ static int vfio_connect_container(VFIOGroup *group)
container->iommu_data.listener = vfio_memory_listener; container->iommu_data.listener = vfio_memory_listener;
container->iommu_data.release = vfio_listener_release; container->iommu_data.release = vfio_listener_release;
memory_listener_register(&container->iommu_data.listener, memory_listener_register(&container->iommu_data.listener, &address_space_memory);
get_system_memory());
} else { } else {
error_report("vfio: No available IOMMU models\n"); error_report("vfio: No available IOMMU models\n");
g_free(container); g_free(container);

View File

@ -792,7 +792,7 @@ int vhost_dev_init(struct vhost_dev *hdev, int devfd, const char *devpath,
hdev->log_size = 0; hdev->log_size = 0;
hdev->log_enabled = false; hdev->log_enabled = false;
hdev->started = false; hdev->started = false;
memory_listener_register(&hdev->memory_listener, get_system_memory()); memory_listener_register(&hdev->memory_listener, &address_space_memory);
hdev->force = force; hdev->force = force;
return 0; return 0;
fail: fail:

View File

@ -749,8 +749,8 @@ static int xen_pt_initfn(PCIDevice *d)
} }
out: out:
memory_listener_register(&s->memory_listener, get_system_memory()); memory_listener_register(&s->memory_listener, &address_space_memory);
memory_listener_register(&s->io_listener, get_system_io()); memory_listener_register(&s->io_listener, &address_space_io);
XEN_PT_LOG(d, "Real physical device %02x:%02x.%d registered successfuly!\n", XEN_PT_LOG(d, "Real physical device %02x:%02x.%d registered successfuly!\n",
bus, slot, func); bus, slot, func);

View File

@ -1375,8 +1375,8 @@ int kvm_init(void)
} }
kvm_state = s; kvm_state = s;
memory_listener_register(&kvm_memory_listener, get_system_memory()); memory_listener_register(&kvm_memory_listener, &address_space_memory);
memory_listener_register(&kvm_io_listener, get_system_io()); memory_listener_register(&kvm_io_listener, &address_space_io);
s->many_ioeventfds = kvm_check_many_ioeventfds(); s->many_ioeventfds = kvm_check_many_ioeventfds();

View File

@ -147,7 +147,7 @@ static bool memory_listener_match(MemoryListener *listener,
#define MEMORY_LISTENER_UPDATE_REGION(fr, as, dir, callback) \ #define MEMORY_LISTENER_UPDATE_REGION(fr, as, dir, callback) \
MEMORY_LISTENER_CALL(callback, dir, (&(MemoryRegionSection) { \ MEMORY_LISTENER_CALL(callback, dir, (&(MemoryRegionSection) { \
.mr = (fr)->mr, \ .mr = (fr)->mr, \
.address_space = (as)->root, \ .address_space = (as), \
.offset_within_region = (fr)->offset_in_region, \ .offset_within_region = (fr)->offset_in_region, \
.size = int128_get64((fr)->addr.size), \ .size = int128_get64((fr)->addr.size), \
.offset_within_address_space = int128_get64((fr)->addr.start), \ .offset_within_address_space = int128_get64((fr)->addr.start), \
@ -593,7 +593,7 @@ static void address_space_add_del_ioeventfds(AddressSpace *as,
fds_new[inew]))) { fds_new[inew]))) {
fd = &fds_old[iold]; fd = &fds_old[iold];
section = (MemoryRegionSection) { section = (MemoryRegionSection) {
.address_space = as->root, .address_space = as,
.offset_within_address_space = int128_get64(fd->addr.start), .offset_within_address_space = int128_get64(fd->addr.start),
.size = int128_get64(fd->addr.size), .size = int128_get64(fd->addr.size),
}; };
@ -606,7 +606,7 @@ static void address_space_add_del_ioeventfds(AddressSpace *as,
fds_old[iold]))) { fds_old[iold]))) {
fd = &fds_new[inew]; fd = &fds_new[inew];
section = (MemoryRegionSection) { section = (MemoryRegionSection) {
.address_space = as->root, .address_space = as,
.offset_within_address_space = int128_get64(fd->addr.start), .offset_within_address_space = int128_get64(fd->addr.start),
.size = int128_get64(fd->addr.size), .size = int128_get64(fd->addr.size),
}; };
@ -1137,7 +1137,7 @@ static void memory_region_update_coalesced_range_as(MemoryRegion *mr, AddressSpa
FOR_EACH_FLAT_RANGE(fr, as->current_map) { FOR_EACH_FLAT_RANGE(fr, as->current_map) {
if (fr->mr == mr) { if (fr->mr == mr) {
section = (MemoryRegionSection) { section = (MemoryRegionSection) {
.address_space = as->root, .address_space = as,
.offset_within_address_space = int128_get64(fr->addr.start), .offset_within_address_space = int128_get64(fr->addr.start),
.size = int128_get64(fr->addr.size), .size = int128_get64(fr->addr.size),
}; };
@ -1476,7 +1476,7 @@ static void listener_add_address_space(MemoryListener *listener,
FlatRange *fr; FlatRange *fr;
if (listener->address_space_filter if (listener->address_space_filter
&& listener->address_space_filter != as->root) { && listener->address_space_filter != as) {
return; return;
} }
@ -1489,7 +1489,7 @@ static void listener_add_address_space(MemoryListener *listener,
FOR_EACH_FLAT_RANGE(fr, as->current_map) { FOR_EACH_FLAT_RANGE(fr, as->current_map) {
MemoryRegionSection section = { MemoryRegionSection section = {
.mr = fr->mr, .mr = fr->mr,
.address_space = as->root, .address_space = as,
.offset_within_region = fr->offset_in_region, .offset_within_region = fr->offset_in_region,
.size = int128_get64(fr->addr.size), .size = int128_get64(fr->addr.size),
.offset_within_address_space = int128_get64(fr->addr.start), .offset_within_address_space = int128_get64(fr->addr.start),
@ -1501,7 +1501,7 @@ static void listener_add_address_space(MemoryListener *listener,
} }
} }
void memory_listener_register(MemoryListener *listener, MemoryRegion *filter) void memory_listener_register(MemoryListener *listener, AddressSpace *filter)
{ {
MemoryListener *other = NULL; MemoryListener *other = NULL;
AddressSpace *as; AddressSpace *as;

View File

@ -187,7 +187,7 @@ typedef struct MemoryRegionSection MemoryRegionSection;
*/ */
struct MemoryRegionSection { struct MemoryRegionSection {
MemoryRegion *mr; MemoryRegion *mr;
MemoryRegion *address_space; AddressSpace *address_space;
target_phys_addr_t offset_within_region; target_phys_addr_t offset_within_region;
uint64_t size; uint64_t size;
target_phys_addr_t offset_within_address_space; target_phys_addr_t offset_within_address_space;
@ -223,7 +223,7 @@ struct MemoryListener {
target_phys_addr_t addr, target_phys_addr_t len); target_phys_addr_t addr, target_phys_addr_t len);
/* Lower = earlier (during add), later (during del) */ /* Lower = earlier (during add), later (during del) */
unsigned priority; unsigned priority;
MemoryRegion *address_space_filter; AddressSpace *address_space_filter;
QTAILQ_ENTRY(MemoryListener) link; QTAILQ_ENTRY(MemoryListener) link;
}; };
@ -774,7 +774,7 @@ void memory_region_transaction_commit(void);
* @listener: an object containing the callbacks to be called * @listener: an object containing the callbacks to be called
* @filter: if non-%NULL, only regions in this address space will be observed * @filter: if non-%NULL, only regions in this address space will be observed
*/ */
void memory_listener_register(MemoryListener *listener, MemoryRegion *filter); void memory_listener_register(MemoryListener *listener, AddressSpace *filter);
/** /**
* memory_listener_unregister: undo the effect of memory_listener_register() * memory_listener_unregister: undo the effect of memory_listener_register()

View File

@ -1141,7 +1141,7 @@ int xen_hvm_init(void)
state->memory_listener = xen_memory_listener; state->memory_listener = xen_memory_listener;
QLIST_INIT(&state->physmap); QLIST_INIT(&state->physmap);
memory_listener_register(&state->memory_listener, get_system_memory()); memory_listener_register(&state->memory_listener, &address_space_memory);
state->log_for_dirtybit = NULL; state->log_for_dirtybit = NULL;
/* Initialize backend core & drivers */ /* Initialize backend core & drivers */