Skip to content

Commit

Permalink
enable notdirty_write for snapshots when possible
Browse files Browse the repository at this point in the history
Snapshots only happens when the priority of the memory region is smaller
then the snapshot_level. After a snapshot notdirty can be set.
  • Loading branch information
PhilippTakacs committed Oct 31, 2024
1 parent 957df0e commit 0881cee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 12 additions & 8 deletions qemu/accel/tcg/cputlb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1192,11 +1192,7 @@ static void notdirty_write(CPUState *cpu, vaddr mem_vaddr, unsigned size,
{
ram_addr_t ram_addr = mem_vaddr + iotlbentry->addr;

if (mr == NULL) {
mr = cpu->uc->memory_mapping(cpu->uc, mem_vaddr);
}

if ((mr->perms & UC_PROT_EXEC) != 0) {
if (mr && (mr->perms & UC_PROT_EXEC) != 0) {
struct page_collection *pages
= page_collection_lock(cpu->uc, ram_addr, ram_addr + size);
tb_invalidate_phys_page_fast(cpu->uc, pages, ram_addr, size, retaddr);
Expand All @@ -1208,7 +1204,7 @@ static void notdirty_write(CPUState *cpu, vaddr mem_vaddr, unsigned size,
// - have memory hooks installed
// - or doing snapshot
// , then never clean the tlb
if (!(cpu->uc->snapshot_level > 0 || mr->priority > 0) &&
if (!(!mr || mr->priority < cpu->uc->snapshot_level) &&
!(HOOK_EXISTS(cpu->uc, UC_HOOK_MEM_READ) || HOOK_EXISTS(cpu->uc, UC_HOOK_MEM_WRITE))) {
tlb_set_dirty(cpu, mem_vaddr);
}
Expand All @@ -1232,6 +1228,8 @@ void *probe_access(CPUArchState *env, target_ulong addr, int size,
target_ulong tlb_addr;
size_t elt_ofs = 0;
int wp_access = 0;
MemoryRegion *mr = NULL;
target_ulong paddr;

#ifdef _MSC_VER
g_assert(((target_ulong)0 - (addr | TARGET_PAGE_MASK)) >= size);
Expand Down Expand Up @@ -1288,7 +1286,9 @@ void *probe_access(CPUArchState *env, target_ulong addr, int size,

/* Handle clean RAM pages. */
if (tlb_addr & TLB_NOTDIRTY) {
notdirty_write(env_cpu(env), addr, size, iotlbentry, retaddr, NULL);
paddr = entry->paddr | (addr & ~TARGET_PAGE_MASK);
mr = env->uc->memory_mapping(env->uc, paddr);
notdirty_write(env_cpu(env), addr, size, iotlbentry, retaddr, mr);
}
}

Expand Down Expand Up @@ -1362,6 +1362,8 @@ static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr,
int a_bits = get_alignment_bits(mop);
int s_bits = mop & MO_SIZE;
void *hostaddr;
MemoryRegion *mr;
target_ulong paddr;

/* Adjust the given return address. */
retaddr -= GETPC_ADJ;
Expand Down Expand Up @@ -1413,8 +1415,10 @@ static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr,
hostaddr = (void *)((uintptr_t)addr + tlbe->addend);

if (unlikely(tlb_addr & TLB_NOTDIRTY)) {
paddr = tlbe->paddr | (addr & ~TARGET_PAGE_MASK);
mr = env->uc->memory_mapping(env->uc, paddr);
notdirty_write(env_cpu(env), addr, 1 << s_bits,
&env_tlb(env)->d[mmu_idx].iotlb[index], retaddr, NULL);
&env_tlb(env)->d[mmu_idx].iotlb[index], retaddr, mr);
}

return hostaddr;
Expand Down
2 changes: 2 additions & 0 deletions uc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2160,6 +2160,7 @@ uc_err uc_context_save(uc_engine *uc, uc_context *context)
}
context->ramblock_freed = uc->ram_list.freed;
context->last_block = uc->ram_list.last_block;
uc->tcg_flush_tlb(uc);
}

context->snapshot_level = uc->snapshot_level;
Expand Down Expand Up @@ -2436,6 +2437,7 @@ uc_err uc_context_restore(uc_engine *uc, uc_context *context)
if (!uc->flatview_copy(uc, uc->address_space_memory.current_map, context->fv, true)) {
return UC_ERR_NOMEM;
}
uc->tcg_flush_tlb(uc);
}

if (uc->context_content & UC_CTL_CONTEXT_CPU) {
Expand Down

0 comments on commit 0881cee

Please sign in to comment.