accel/tcg: Restrict page_collection structure to system TB maintainance
cover accel/tcg: Restrict page_collection structure to system TB maintainance
Few cleanups noticed while reviewing Richard's "Rewrite user-only vma tracking" v3 ([*], based on top of it).
- Move accel/tcg/ trace events out of trace-root.h
- Refactor tb_invalidate_phys_range_fast() to restrict page_collection to sysemu.
[*] https://lore.kernel.org/qemu-devel/[email protected]/
Based-on: <[email protected]>
Philippe Mathieu-Daudé (5):
accel/tcg: Restrict cpu_io_recompile() to system emulation accel/tcg: Remove trace events from trace-root.h accel/tcg: Rename tb_invalidate_phys_page_[locked_]fast() accel/tcg: Factor tb_invalidate_phys_range_fast() out accel/tcg: Restrict page_collection structure to system TB
maintainance
accel/tcg/cputlb.c | 7 ++----- accel/tcg/internal.h | 12 ++++-------- accel/tcg/tb-maint.c | 33 +++++++++++++++++++++++---------- accel/tcg/trace-events | 4 ++++ trace-events | 4 ---- 5 files changed, 33 insertions(+), 27 deletions(-)
Signature · 1 line
2.38.1
PATCH 1/5 accel/tcg: Restrict cpu_io_recompile() to system emulation
Missed in commit 6526919224 ("accel/tcg: Restrict cpu_io_recompile() from other accelerators").
--- accel/tcg/internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
accel/tcg/internal.h +1 -1
@@ -43,12 +43,12 @@ void tb_invalidate_phys_page_fast(struct page_collection *pages,struct page_collection *page_collection_lock (tb_page_addr_t start,tb_page_addr_t end);void page_collection_unlock (struct page_collection *set); +G_NORETURN void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr);#endif /* CONFIG_SOFTMMU */ TranslationBlock *tb_gen_code (CPUState *cpu,target_ulong pc,target_ulong cs_base,uint32_t flags,int cflags); -G_NORETURN void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr);void page_init (void );void tb_htable_init (void );void tb_reset_jump (TranslationBlock *tb,int n);
Signature · 1 line
2.38.1
Re: [PATCH-for-8.0 1/5] accel/tcg: Restrict cpu_io_recompile() to system emulation
Quoted 4 lines · Philippe Mathieu-Daudé
Missed in commit 6526919224 ("accel/tcg: Restrict
cpu_io_recompile()from other accelerators").Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
PATCH 2/5 accel/tcg: Remove trace events from trace-root.h
In reply to Philippe Mathieu-DaudéCommit d9bb58e510 ("tcg: move tcg related files into accel/tcg/ subdirectory") introduced accel/tcg/trace-events, so we don't need to use the root trace-events anymore.
--- accel/tcg/cputlb.c | 2 +- accel/tcg/trace-events | 4 ++++ trace-events | 4 ---- 3 files changed, 5 insertions(+), 5 deletions(-)
accel/tcg/cputlb.c +1 -1
@@ -33,7 +33,7 @@#include "qemu/atomic.h" #include "qemu/atomic128.h" #include "exec/translate-all.h" -#include "trace/trace-root.h" +#include "trace.h" #include "tb-hash.h" #include "internal.h" #ifdef CONFIG_PLUGIN
accel/tcg/trace-events +4 -0
@@ -6,5 +6,9 @@ exec_tb(void *tb, uintptr_t pc) "tb:%p pc=0x%"PRIxPTR exec_tb_nocache(void *tb, uintptr_t pc) "tb:%p pc=0x%"PRIxPTR exec_tb_exit(void *last_tb, unsigned int flags) "tb:%p flags=0x%x" +# cputlb.c +memory_notdirty_write_access(uint64_t vaddr, uint64_t ram_addr, unsigned size) "0x%" PRIx64 " ram_addr 0x%" PRIx64 " size %u" +memory_notdirty_set_dirty(uint64_t vaddr) "0x%" PRIx64 + # translate-all.c translate_block(void *tb, uintptr_t pc, const void *tb_code) "tb:%p, pc:0x%"PRIxPTR", tb_code:%p"
trace-events +0 -4
@@ -42,10 +42,6 @@ find_ram_offset(uint64_t size, uint64_t offset) "size: 0x%" PRIx64 " @ 0x%" PRIx find_ram_offset_loop(uint64_t size, uint64_t candidate, uint64_t offset, uint64_t next, uint64_t mingap) "trying size: 0x%" PRIx64 " @ 0x%" PRIx64 ", offset: 0x%" PRIx64" next: 0x%" PRIx64 " mingap: 0x%" PRIx64 ram_block_discard_range(const char *rbname, void *hva, size_t length, bool need_madvise, bool need_fallocate, int ret) "%s@%p + 0x%zx: madvise: %d fallocate: %d ret: %d" -# accel/tcg/cputlb.c -memory_notdirty_write_access(uint64_t vaddr, uint64_t ram_addr, unsigned size) "0x%" PRIx64 " ram_addr 0x%" PRIx64 " size %u" -memory_notdirty_set_dirty(uint64_t vaddr) "0x%" PRIx64 - # job.c job_state_transition(void *job, int ret, const char *legal, const char *s0, const char *s1) "job %p (ret: %d) attempting %s transition (%s-->%s)" job_apply_verb(void *job, const char *state, const char *verb, const char *legal) "job %p in state %s; applying verb %s (%s)"
Signature · 1 line
2.38.1
Re: [PATCH-for-8.0 2/5] accel/tcg: Remove trace events from trace-root.h
Quoted 5 lines · Philippe Mathieu-Daudé
Commit
d9bb58e510("tcg: move tcg related files into accel/tcg/ subdirectory") introduced accel/tcg/trace-events, so we don't need to use the root trace-events anymore.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
BTW I wonder how much of a hot-path cputlb really is to jump the hoops of DEBUG_TLB and friends. They could certainly be rationalised.
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
PATCH 3/5 accel/tcg: Rename tb_invalidate_phys_page_[locked_]fast()
In reply to Philippe Mathieu-DaudéEmphasize this function is called with pages locked.
--- accel/tcg/cputlb.c | 2 +- accel/tcg/internal.h | 6 +++--- accel/tcg/tb-maint.c | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-)
accel/tcg/cputlb.c +1 -1
@@ -1510,7 +1510,7 @@ static void notdirty_write(CPUState *cpu, vaddr mem_vaddr, unsigned size,if (!cpu_physical_memory_get_dirty_flag (ram_addr,DIRTY_MEMORY_CODE )) {struct page_collection *pages =page_collection_lock (ram_addr, ram_addr + size); -tb_invalidate_phys_page_fast (pages, ram_addr, size, retaddr); +tb_invalidate_phys_page_locked_fast (pages, ram_addr, size, retaddr);page_collection_unlock (pages); }
accel/tcg/internal.h +3 -3
@@ -37,9 +37,9 @@ void page_table_config_init(void);#ifdef CONFIG_SOFTMMU struct page_collection ; -void tb_invalidate_phys_page_fast (struct page_collection *pages, -tb_page_addr_t start,int len, -uintptr_t retaddr); +void tb_invalidate_phys_page_locked_fast (struct page_collection *pages, +tb_page_addr_t start,int len, +uintptr_t retaddr);struct page_collection *page_collection_lock (tb_page_addr_t start,tb_page_addr_t end);void page_collection_unlock (struct page_collection *set);
accel/tcg/tb-maint.c +3 -3
@@ -1200,9 +1200,9 @@ void tb_invalidate_phys_range(tb_page_addr_t start, tb_page_addr_t end)* * Call with all @pages in the range [@start, @start + len[ locked. */ -void tb_invalidate_phys_page_fast (struct page_collection *pages, -tb_page_addr_t start,int len, -uintptr_t retaddr) +void tb_invalidate_phys_page_locked_fast (struct page_collection *pages, +tb_page_addr_t start,int len, +uintptr_t retaddr) {PageDesc *p;
Signature · 1 line
2.38.1
Re: [PATCH-for-8.0 3/5] accel/tcg: Rename tb_invalidate_phys_page_[locked_]fast()
Quoted 1 line · Philippe Mathieu-Daudé
Emphasize this function is called with pages locked.
The _locked should be a suffix rather than in the function and possibly a __locked for continuity with the other __locked functions in the file.
Otherwise:
Quoted 54 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- accel/tcg/cputlb.c | 2 +- accel/tcg/internal.h | 6 +++--- accel/tcg/tb-maint.c | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-)accel/tcg/cputlb.c +1
-1@@ -1510,7 +1510,7 @@ static void notdirty_write(CPUState *cpu, vaddr mem_vaddr, unsigned size,if (!cpu_physical_memory_get_dirty_flag (ram_addr,DIRTY_MEMORY_CODE )) {struct page_collection *pages =page_collection_lock (ram_addr, ram_addr + size); -tb_invalidate_phys_page_fast (pages, ram_addr, size, retaddr); +tb_invalidate_phys_page_locked_fast (pages, ram_addr, size, retaddr);page_collection_unlock (pages); }accel/tcg/internal.h +3
-3@@ -37,9 +37,9 @@ void page_table_config_init(void);#ifdef CONFIG_SOFTMMU struct page_collection ; -void tb_invalidate_phys_page_fast (struct page_collection *pages, -tb_page_addr_t start,int len, -uintptr_t retaddr); +void tb_invalidate_phys_page_locked_fast (struct page_collection *pages, +tb_page_addr_t start,int len, +uintptr_t retaddr);struct page_collection *page_collection_lock (tb_page_addr_t start,tb_page_addr_t end);void page_collection_unlock (struct page_collection *set);accel/tcg/tb-maint.c +3
-3@@ -1200,9 +1200,9 @@ void tb_invalidate_phys_range(tb_page_addr_t start, tb_page_addr_t end)* * Call with all @pages in the range [@start, @start + len[ locked. */ -void tb_invalidate_phys_page_fast (struct page_collection *pages, -tb_page_addr_t start,int len, -uintptr_t retaddr) +void tb_invalidate_phys_page_locked_fast (struct page_collection *pages, +tb_page_addr_t start,int len, +uintptr_t retaddr) {PageDesc *p;
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Re: [PATCH-for-8.0 3/5] accel/tcg: Rename tb_invalidate_phys_page_[locked_]fast()
In reply to Philippe Mathieu-DaudéQuoted 8 lines · Philippe Mathieu-Daudé
Emphasize this function is called with pages locked.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- accel/tcg/cputlb.c | 2 +- accel/tcg/internal.h | 6 +++--- accel/tcg/tb-maint.c | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-)
Our other subroutines of the same form use the suffix "__locked". As this is my only quibble with the series, I'll fix it up when applying.
r~
PATCH 4/5 accel/tcg: Factor tb_invalidate_phys_range_fast() out
In reply to Philippe Mathieu-Daudé--- accel/tcg/cputlb.c | 5 +---- accel/tcg/internal.h | 3 +++ accel/tcg/tb-maint.c | 21 +++++++++++++++++---- 3 files changed, 21 insertions(+), 8 deletions(-)
accel/tcg/cputlb.c +1 -4
@@ -1508,10 +1508,7 @@ static void notdirty_write(CPUState *cpu, vaddr mem_vaddr, unsigned size,trace_memory_notdirty_write_access (mem_vaddr, ram_addr, size);if (!cpu_physical_memory_get_dirty_flag (ram_addr,DIRTY_MEMORY_CODE )) { -struct page_collection *pages - =page_collection_lock (ram_addr, ram_addr + size); -tb_invalidate_phys_page_locked_fast (pages, ram_addr, size, retaddr); -page_collection_unlock (pages); +tb_invalidate_phys_range_fast (ram_addr, size, retaddr); }/*
accel/tcg/internal.h +3 -0
@@ -42,6 +42,9 @@ void tb_invalidate_phys_page_locked_fast(struct page_collection *pages, uintptr_t retaddr);struct page_collection *page_collection_lock (tb_page_addr_t start,tb_page_addr_t end); +void tb_invalidate_phys_range_fast (ram_addr_t ram_addr, +unsigned size, +uintptr_t retaddr);void page_collection_unlock (struct page_collection *set); G_NORETURN void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr);#endif /* CONFIG_SOFTMMU */
accel/tcg/tb-maint.c +17 -4
@@ -1194,10 +1194,6 @@ void tb_invalidate_phys_range(tb_page_addr_t start, tb_page_addr_t end) }/* -* len must be <= 8 and start must be a multiple of len. -* Called via softmmu_template.h when code areas are written to with -* iothread mutex not held. -* * Call with all @pages in the range [@start, @start + len[ locked. */ void tb_invalidate_phys_page_locked_fast(struct page_collection *pages,
@@ -1215,4 +1211,21 @@ void tb_invalidate_phys_page_locked_fast(struct page_collection *pages,tb_invalidate_phys_page_range__locked (pages, p, start, start + len, retaddr); } + +/* +* len must be <= 8 and start must be a multiple of len. +* Called via softmmu_template.h when code areas are written to with +* iothread mutex not held. +*/ +void tb_invalidate_phys_range_fast (ram_addr_t ram_addr, +unsigned size, +uintptr_t retaddr) +{ +struct page_collection *pages; + + pages =page_collection_lock (ram_addr, ram_addr + size); +tb_invalidate_phys_page_locked_fast (pages, ram_addr, size, retaddr); +page_collection_unlock (pages); +} +#endif /* CONFIG_USER_ONLY */
Signature · 1 line
2.38.1
Re: [PATCH-for-8.0 4/5] accel/tcg: Factor tb_invalidate_phys_range_fast() out
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
PATCH 5/5 accel/tcg: Restrict page_collection structure to system TB maintainance
In reply to Philippe Mathieu-DaudéOnly the system emulation part of TB maintainance uses the page_collection structure. Restrict its declaration (and the functions requiring it) to tb-maint.c.
Convert the 'len' argument of tb_invalidate_phys_page_locked_fast() from signed to unsigned.
--- accel/tcg/internal.h | 7 ------- accel/tcg/tb-maint.c | 12 ++++++------ 2 files changed, 6 insertions(+), 13 deletions(-)
accel/tcg/internal.h +0 -7
@@ -36,16 +36,9 @@ void page_table_config_init(void);#endif #ifdef CONFIG_SOFTMMU -struct page_collection ; -void tb_invalidate_phys_page_locked_fast (struct page_collection *pages, -tb_page_addr_t start,int len, -uintptr_t retaddr); -struct page_collection *page_collection_lock (tb_page_addr_t start, -tb_page_addr_t end);void tb_invalidate_phys_range_fast (ram_addr_t ram_addr,unsigned size,uintptr_t retaddr); -void page_collection_unlock (struct page_collection *set); G_NORETURN void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr);#endif /* CONFIG_SOFTMMU */
accel/tcg/tb-maint.c +6 -6
@@ -523,8 +523,8 @@ static gint tb_page_addr_cmp(gconstpointer ap, gconstpointer bp, gpointer udata)* intersecting TBs. * Locking order: acquire locks in ascending order of page index. */ -struct page_collection * -page_collection_lock (tb_page_addr_t start,tb_page_addr_t end) +static struct page_collection *page_collection_lock (tb_page_addr_t start, +tb_page_addr_t end) {struct page_collection *set =g_malloc (sizeof (*set));tb_page_addr_t index;
@@ -568,7 +568,7 @@ page_collection_lock(tb_page_addr_t start, tb_page_addr_t end)return set; } -void page_collection_unlock (struct page_collection *set) +static void page_collection_unlock (struct page_collection *set) {/* entries are unlocked and freed via page_entry_destroy */ g_tree_destroy (set->tree);
@@ -1196,9 +1196,9 @@ void tb_invalidate_phys_range(tb_page_addr_t start, tb_page_addr_t end)/* * Call with all @pages in the range [@start, @start + len[ locked. */ -void tb_invalidate_phys_page_locked_fast (struct page_collection *pages, -tb_page_addr_t start,int len, -uintptr_t retaddr) +static void tb_invalidate_phys_page_locked_fast (struct page_collection *pages, +tb_page_addr_t start, +unsigned len,uintptr_t retaddr) {PageDesc *p;
Signature · 1 line
2.38.1
Quoted 6 lines · Philippe Mathieu-Daudé
Only the system emulation part of TB maintainance uses the
page_collectionstructure. Restrict its declaration (and the functions requiring it) totb-maint.c.Convert the 'len' argument of
tb_invalidate_phys_page_locked_fast()from signed to unsigned.
You could push that cleanup higher because I think we only ever have DATA_SIZE which is always in a fixed range.
Anyway:
Quoted 64 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- accel/tcg/internal.h | 7 ------- accel/tcg/tb-maint.c | 12 ++++++------ 2 files changed, 6 insertions(+), 13 deletions(-)accel/tcg/internal.h +0
-7@@ -36,16 +36,9 @@ void page_table_config_init(void);#endif #ifdef CONFIG_SOFTMMU -struct page_collection ; -void tb_invalidate_phys_page_locked_fast (struct page_collection *pages, -tb_page_addr_t start,int len, -uintptr_t retaddr); -struct page_collection *page_collection_lock (tb_page_addr_t start, -tb_page_addr_t end);void tb_invalidate_phys_range_fast (ram_addr_t ram_addr,unsigned size,uintptr_t retaddr); -void page_collection_unlock (struct page_collection *set); G_NORETURN void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr);#endif /* CONFIG_SOFTMMU */ accel/tcg/tb-maint.c +6
-6@@ -523,8 +523,8 @@ static gint tb_page_addr_cmp(gconstpointer ap, gconstpointer bp, gpointer udata)* intersecting TBs. * Locking order: acquire locks in ascending order of page index. */ -struct page_collection * -page_collection_lock (tb_page_addr_t start,tb_page_addr_t end) +static struct page_collection *page_collection_lock (tb_page_addr_t start, +tb_page_addr_t end) {struct page_collection *set =g_malloc (sizeof (*set));tb_page_addr_t index;@@ -568,7 +568,7 @@ page_collection_lock(tb_page_addr_t start, tb_page_addr_t end)return set; } -void page_collection_unlock (struct page_collection *set) +static void page_collection_unlock (struct page_collection *set) {/* entries are unlocked and freed via page_entry_destroy */ g_tree_destroy (set->tree);@@ -1196,9 +1196,9 @@ void tb_invalidate_phys_range(tb_page_addr_t start, tb_page_addr_t end)/* * Call with all @pages in the range [@start, @start + len[ locked. */ -void tb_invalidate_phys_page_locked_fast (struct page_collection *pages, -tb_page_addr_t start,int len, -uintptr_t retaddr) +static void tb_invalidate_phys_page_locked_fast (struct page_collection *pages, +tb_page_addr_t start, +unsigned len,uintptr_t retaddr) {PageDesc *p;
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro