From c333585a4d4c796467e3eb73011010ffca0d690b Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 13 Feb 2018 09:18:27 -0500 Subject: [PATCH] translate-all: make less of tb_invalidate_phys_page_range depend on is_cpu_write_access is_cpu_write_access is only set if tb_invalidate_phys_page_range is called from tb_invalidate_phys_page_fast, and hence from notdirty_mem_write. However: - the code bitmap can be built directly in tb_invalidate_phys_page_fast (unconditionally, since is_cpu_write_access would always be passed as 1); - the virtual address is not needed to mark the page as "not containing code" (dirty code bitmap = 1), so we can also remove that use of is_cpu_write_access. For calls of tb_invalidate_phys_page_range that do not come from notdirty_mem_write, the next call to notdirty_mem_write will notice that the page does not contain code anymore, and will fix up the TLB entry. The parameter needs to remain in order to guard accesses to cpu->mem_io_pc. Backports commit fc377bcf617a48233a99a9fe0a26247c38b5cb76 from qemu --- qemu/translate-all.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/qemu/translate-all.c b/qemu/translate-all.c index 4167aefa..e69213db 100644 --- a/qemu/translate-all.c +++ b/qemu/translate-all.c @@ -1175,12 +1175,6 @@ void tb_invalidate_phys_page_range(struct uc_struct *uc, tb_page_addr_t start, t if (!p) { return; } - if (!p->code_bitmap && - ++p->code_write_count >= SMC_BITMAP_USE_THRESHOLD && - is_cpu_write_access) { - /* build code bitmap */ - build_page_bitmap(p); - } #if defined(TARGET_HAS_PRECISE_SMC) if (cpu != NULL) { env = cpu->env_ptr; @@ -1251,9 +1245,7 @@ void tb_invalidate_phys_page_range(struct uc_struct *uc, tb_page_addr_t start, t /* if no code remaining, no need to continue to use slow writes */ if (!p->first_tb) { invalidate_page_bitmap(p); - if (is_cpu_write_access) { - tlb_unprotect_code(cpu, start); - } + tlb_unprotect_code(cpu, start); } #endif #ifdef TARGET_HAS_PRECISE_SMC @@ -1410,6 +1402,11 @@ void tb_invalidate_phys_page_fast(struct uc_struct* uc, tb_page_addr_t start, in if (!p) { return; } + if (!p->code_bitmap && + ++p->code_write_count >= SMC_BITMAP_USE_THRESHOLD) { + /* build code bitmap */ + build_page_bitmap(p); + } if (p->code_bitmap) { unsigned int nr; unsigned long b;