|
@@ -1037,16 +1037,14 @@ void tb_invalidate_phys_addr(AddressSpace *as, hwaddr addr, MemTxAttrs attrs)
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- rcu_read_lock();
|
|
|
+ RCU_READ_LOCK_GUARD();
|
|
|
mr = address_space_translate(as, addr, &addr, &l, false, attrs);
|
|
|
if (!(memory_region_is_ram(mr)
|
|
|
|| memory_region_is_romd(mr))) {
|
|
|
- rcu_read_unlock();
|
|
|
return;
|
|
|
}
|
|
|
ram_addr = memory_region_get_ram_addr(mr) + addr;
|
|
|
tb_invalidate_phys_page_range(ram_addr, ram_addr + 1);
|
|
|
- rcu_read_unlock();
|
|
|
}
|
|
|
|
|
|
static void breakpoint_invalidate(CPUState *cpu, target_ulong pc)
|
|
@@ -1332,14 +1330,13 @@ static void tlb_reset_dirty_range_all(ram_addr_t start, ram_addr_t length)
|
|
|
end = TARGET_PAGE_ALIGN(start + length);
|
|
|
start &= TARGET_PAGE_MASK;
|
|
|
|
|
|
- rcu_read_lock();
|
|
|
+ RCU_READ_LOCK_GUARD();
|
|
|
block = qemu_get_ram_block(start);
|
|
|
assert(block == qemu_get_ram_block(end - 1));
|
|
|
start1 = (uintptr_t)ramblock_ptr(block, start - block->offset);
|
|
|
CPU_FOREACH(cpu) {
|
|
|
tlb_reset_dirty(cpu, start1, length);
|
|
|
}
|
|
|
- rcu_read_unlock();
|
|
|
}
|
|
|
|
|
|
/* Note: start and end must be within the same ram block. */
|
|
@@ -1360,30 +1357,29 @@ bool cpu_physical_memory_test_and_clear_dirty(ram_addr_t start,
|
|
|
end = TARGET_PAGE_ALIGN(start + length) >> TARGET_PAGE_BITS;
|
|
|
page = start >> TARGET_PAGE_BITS;
|
|
|
|
|
|
- rcu_read_lock();
|
|
|
+ WITH_RCU_READ_LOCK_GUARD() {
|
|
|
+ blocks = atomic_rcu_read(&ram_list.dirty_memory[client]);
|
|
|
+ ramblock = qemu_get_ram_block(start);
|
|
|
+ /* Range sanity check on the ramblock */
|
|
|
+ assert(start >= ramblock->offset &&
|
|
|
+ start + length <= ramblock->offset + ramblock->used_length);
|
|
|
|
|
|
- blocks = atomic_rcu_read(&ram_list.dirty_memory[client]);
|
|
|
- ramblock = qemu_get_ram_block(start);
|
|
|
- /* Range sanity check on the ramblock */
|
|
|
- assert(start >= ramblock->offset &&
|
|
|
- start + length <= ramblock->offset + ramblock->used_length);
|
|
|
+ while (page < end) {
|
|
|
+ unsigned long idx = page / DIRTY_MEMORY_BLOCK_SIZE;
|
|
|
+ unsigned long offset = page % DIRTY_MEMORY_BLOCK_SIZE;
|
|
|
+ unsigned long num = MIN(end - page,
|
|
|
+ DIRTY_MEMORY_BLOCK_SIZE - offset);
|
|
|
|
|
|
- while (page < end) {
|
|
|
- unsigned long idx = page / DIRTY_MEMORY_BLOCK_SIZE;
|
|
|
- unsigned long offset = page % DIRTY_MEMORY_BLOCK_SIZE;
|
|
|
- unsigned long num = MIN(end - page, DIRTY_MEMORY_BLOCK_SIZE - offset);
|
|
|
+ dirty |= bitmap_test_and_clear_atomic(blocks->blocks[idx],
|
|
|
+ offset, num);
|
|
|
+ page += num;
|
|
|
+ }
|
|
|
|
|
|
- dirty |= bitmap_test_and_clear_atomic(blocks->blocks[idx],
|
|
|
- offset, num);
|
|
|
- page += num;
|
|
|
+ mr_offset = (ram_addr_t)(page << TARGET_PAGE_BITS) - ramblock->offset;
|
|
|
+ mr_size = (end - page) << TARGET_PAGE_BITS;
|
|
|
+ memory_region_clear_dirty_bitmap(ramblock->mr, mr_offset, mr_size);
|
|
|
}
|
|
|
|
|
|
- mr_offset = (ram_addr_t)(page << TARGET_PAGE_BITS) - ramblock->offset;
|
|
|
- mr_size = (end - page) << TARGET_PAGE_BITS;
|
|
|
- memory_region_clear_dirty_bitmap(ramblock->mr, mr_offset, mr_size);
|
|
|
-
|
|
|
- rcu_read_unlock();
|
|
|
-
|
|
|
if (dirty && tcg_enabled()) {
|
|
|
tlb_reset_dirty_range_all(start, length);
|
|
|
}
|
|
@@ -1411,28 +1407,27 @@ DirtyBitmapSnapshot *cpu_physical_memory_snapshot_and_clear_dirty
|
|
|
end = last >> TARGET_PAGE_BITS;
|
|
|
dest = 0;
|
|
|
|
|
|
- rcu_read_lock();
|
|
|
+ WITH_RCU_READ_LOCK_GUARD() {
|
|
|
+ blocks = atomic_rcu_read(&ram_list.dirty_memory[client]);
|
|
|
|
|
|
- blocks = atomic_rcu_read(&ram_list.dirty_memory[client]);
|
|
|
+ while (page < end) {
|
|
|
+ unsigned long idx = page / DIRTY_MEMORY_BLOCK_SIZE;
|
|
|
+ unsigned long offset = page % DIRTY_MEMORY_BLOCK_SIZE;
|
|
|
+ unsigned long num = MIN(end - page,
|
|
|
+ DIRTY_MEMORY_BLOCK_SIZE - offset);
|
|
|
|
|
|
- while (page < end) {
|
|
|
- unsigned long idx = page / DIRTY_MEMORY_BLOCK_SIZE;
|
|
|
- unsigned long offset = page % DIRTY_MEMORY_BLOCK_SIZE;
|
|
|
- unsigned long num = MIN(end - page, DIRTY_MEMORY_BLOCK_SIZE - offset);
|
|
|
-
|
|
|
- assert(QEMU_IS_ALIGNED(offset, (1 << BITS_PER_LEVEL)));
|
|
|
- assert(QEMU_IS_ALIGNED(num, (1 << BITS_PER_LEVEL)));
|
|
|
- offset >>= BITS_PER_LEVEL;
|
|
|
+ assert(QEMU_IS_ALIGNED(offset, (1 << BITS_PER_LEVEL)));
|
|
|
+ assert(QEMU_IS_ALIGNED(num, (1 << BITS_PER_LEVEL)));
|
|
|
+ offset >>= BITS_PER_LEVEL;
|
|
|
|
|
|
- bitmap_copy_and_clear_atomic(snap->dirty + dest,
|
|
|
- blocks->blocks[idx] + offset,
|
|
|
- num);
|
|
|
- page += num;
|
|
|
- dest += num >> BITS_PER_LEVEL;
|
|
|
+ bitmap_copy_and_clear_atomic(snap->dirty + dest,
|
|
|
+ blocks->blocks[idx] + offset,
|
|
|
+ num);
|
|
|
+ page += num;
|
|
|
+ dest += num >> BITS_PER_LEVEL;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- rcu_read_unlock();
|
|
|
-
|
|
|
if (tcg_enabled()) {
|
|
|
tlb_reset_dirty_range_all(start, length);
|
|
|
}
|
|
@@ -1643,7 +1638,7 @@ void ram_block_dump(Monitor *mon)
|
|
|
RAMBlock *block;
|
|
|
char *psize;
|
|
|
|
|
|
- rcu_read_lock();
|
|
|
+ RCU_READ_LOCK_GUARD();
|
|
|
monitor_printf(mon, "%24s %8s %18s %18s %18s\n",
|
|
|
"Block Name", "PSize", "Offset", "Used", "Total");
|
|
|
RAMBLOCK_FOREACH(block) {
|
|
@@ -1655,7 +1650,6 @@ void ram_block_dump(Monitor *mon)
|
|
|
(uint64_t)block->max_length);
|
|
|
g_free(psize);
|
|
|
}
|
|
|
- rcu_read_unlock();
|
|
|
}
|
|
|
|
|
|
#ifdef __linux__
|
|
@@ -2009,11 +2003,10 @@ static unsigned long last_ram_page(void)
|
|
|
RAMBlock *block;
|
|
|
ram_addr_t last = 0;
|
|
|
|
|
|
- rcu_read_lock();
|
|
|
+ RCU_READ_LOCK_GUARD();
|
|
|
RAMBLOCK_FOREACH(block) {
|
|
|
last = MAX(last, block->offset + block->max_length);
|
|
|
}
|
|
|
- rcu_read_unlock();
|
|
|
return last >> TARGET_PAGE_BITS;
|
|
|
}
|
|
|
|
|
@@ -2100,7 +2093,7 @@ void qemu_ram_set_idstr(RAMBlock *new_block, const char *name, DeviceState *dev)
|
|
|
}
|
|
|
pstrcat(new_block->idstr, sizeof(new_block->idstr), name);
|
|
|
|
|
|
- rcu_read_lock();
|
|
|
+ RCU_READ_LOCK_GUARD();
|
|
|
RAMBLOCK_FOREACH(block) {
|
|
|
if (block != new_block &&
|
|
|
!strcmp(block->idstr, new_block->idstr)) {
|
|
@@ -2109,7 +2102,6 @@ void qemu_ram_set_idstr(RAMBlock *new_block, const char *name, DeviceState *dev)
|
|
|
abort();
|
|
|
}
|
|
|
}
|
|
|
- rcu_read_unlock();
|
|
|
}
|
|
|
|
|
|
/* Called with iothread lock held. */
|
|
@@ -2651,17 +2643,16 @@ RAMBlock *qemu_ram_block_from_host(void *ptr, bool round_offset,
|
|
|
|
|
|
if (xen_enabled()) {
|
|
|
ram_addr_t ram_addr;
|
|
|
- rcu_read_lock();
|
|
|
+ RCU_READ_LOCK_GUARD();
|
|
|
ram_addr = xen_ram_addr_from_mapcache(ptr);
|
|
|
block = qemu_get_ram_block(ram_addr);
|
|
|
if (block) {
|
|
|
*offset = ram_addr - block->offset;
|
|
|
}
|
|
|
- rcu_read_unlock();
|
|
|
return block;
|
|
|
}
|
|
|
|
|
|
- rcu_read_lock();
|
|
|
+ RCU_READ_LOCK_GUARD();
|
|
|
block = atomic_rcu_read(&ram_list.mru_block);
|
|
|
if (block && block->host && host - block->host < block->max_length) {
|
|
|
goto found;
|
|
@@ -2677,7 +2668,6 @@ RAMBlock *qemu_ram_block_from_host(void *ptr, bool round_offset,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- rcu_read_unlock();
|
|
|
return NULL;
|
|
|
|
|
|
found:
|
|
@@ -2685,7 +2675,6 @@ found:
|
|
|
if (round_offset) {
|
|
|
*offset &= TARGET_PAGE_MASK;
|
|
|
}
|
|
|
- rcu_read_unlock();
|
|
|
return block;
|
|
|
}
|
|
|
|
|
@@ -3281,10 +3270,9 @@ MemTxResult address_space_read_full(AddressSpace *as, hwaddr addr,
|
|
|
FlatView *fv;
|
|
|
|
|
|
if (len > 0) {
|
|
|
- rcu_read_lock();
|
|
|
+ RCU_READ_LOCK_GUARD();
|
|
|
fv = address_space_to_flatview(as);
|
|
|
result = flatview_read(fv, addr, attrs, buf, len);
|
|
|
- rcu_read_unlock();
|
|
|
}
|
|
|
|
|
|
return result;
|
|
@@ -3298,10 +3286,9 @@ MemTxResult address_space_write(AddressSpace *as, hwaddr addr,
|
|
|
FlatView *fv;
|
|
|
|
|
|
if (len > 0) {
|
|
|
- rcu_read_lock();
|
|
|
+ RCU_READ_LOCK_GUARD();
|
|
|
fv = address_space_to_flatview(as);
|
|
|
result = flatview_write(fv, addr, attrs, buf, len);
|
|
|
- rcu_read_unlock();
|
|
|
}
|
|
|
|
|
|
return result;
|
|
@@ -3341,7 +3328,7 @@ static inline MemTxResult address_space_write_rom_internal(AddressSpace *as,
|
|
|
hwaddr addr1;
|
|
|
MemoryRegion *mr;
|
|
|
|
|
|
- rcu_read_lock();
|
|
|
+ RCU_READ_LOCK_GUARD();
|
|
|
while (len > 0) {
|
|
|
l = len;
|
|
|
mr = address_space_translate(as, addr, &addr1, &l, true, attrs);
|
|
@@ -3366,7 +3353,6 @@ static inline MemTxResult address_space_write_rom_internal(AddressSpace *as,
|
|
|
buf += l;
|
|
|
addr += l;
|
|
|
}
|
|
|
- rcu_read_unlock();
|
|
|
return MEMTX_OK;
|
|
|
}
|
|
|
|
|
@@ -3511,10 +3497,9 @@ bool address_space_access_valid(AddressSpace *as, hwaddr addr,
|
|
|
FlatView *fv;
|
|
|
bool result;
|
|
|
|
|
|
- rcu_read_lock();
|
|
|
+ RCU_READ_LOCK_GUARD();
|
|
|
fv = address_space_to_flatview(as);
|
|
|
result = flatview_access_valid(fv, addr, len, is_write, attrs);
|
|
|
- rcu_read_unlock();
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -3569,13 +3554,12 @@ void *address_space_map(AddressSpace *as,
|
|
|
}
|
|
|
|
|
|
l = len;
|
|
|
- rcu_read_lock();
|
|
|
+ RCU_READ_LOCK_GUARD();
|
|
|
fv = address_space_to_flatview(as);
|
|
|
mr = flatview_translate(fv, addr, &xlat, &l, is_write, attrs);
|
|
|
|
|
|
if (!memory_access_is_direct(mr, is_write)) {
|
|
|
if (atomic_xchg(&bounce.in_use, true)) {
|
|
|
- rcu_read_unlock();
|
|
|
return NULL;
|
|
|
}
|
|
|
/* Avoid unbounded allocations */
|
|
@@ -3591,7 +3575,6 @@ void *address_space_map(AddressSpace *as,
|
|
|
bounce.buffer, l);
|
|
|
}
|
|
|
|
|
|
- rcu_read_unlock();
|
|
|
*plen = l;
|
|
|
return bounce.buffer;
|
|
|
}
|
|
@@ -3601,7 +3584,6 @@ void *address_space_map(AddressSpace *as,
|
|
|
*plen = flatview_extend_translation(fv, addr, len, mr, xlat,
|
|
|
l, is_write, attrs);
|
|
|
ptr = qemu_ram_ptr_length(mr->ram_block, xlat, plen, true);
|
|
|
- rcu_read_unlock();
|
|
|
|
|
|
return ptr;
|
|
|
}
|
|
@@ -3869,13 +3851,12 @@ bool cpu_physical_memory_is_io(hwaddr phys_addr)
|
|
|
hwaddr l = 1;
|
|
|
bool res;
|
|
|
|
|
|
- rcu_read_lock();
|
|
|
+ RCU_READ_LOCK_GUARD();
|
|
|
mr = address_space_translate(&address_space_memory,
|
|
|
phys_addr, &phys_addr, &l, false,
|
|
|
MEMTXATTRS_UNSPECIFIED);
|
|
|
|
|
|
res = !(memory_region_is_ram(mr) || memory_region_is_romd(mr));
|
|
|
- rcu_read_unlock();
|
|
|
return res;
|
|
|
}
|
|
|
|
|
@@ -3884,14 +3865,13 @@ int qemu_ram_foreach_block(RAMBlockIterFunc func, void *opaque)
|
|
|
RAMBlock *block;
|
|
|
int ret = 0;
|
|
|
|
|
|
- rcu_read_lock();
|
|
|
+ RCU_READ_LOCK_GUARD();
|
|
|
RAMBLOCK_FOREACH(block) {
|
|
|
ret = func(block, opaque);
|
|
|
if (ret) {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- rcu_read_unlock();
|
|
|
return ret;
|
|
|
}
|
|
|
|