Skip to contentSkip to conversation

accel/tcg: Stubs cleanups

PATCH In review Philippe Mathieu-Daudé 2 participants 12 messages Sep 14, 2023 – Sep 19, 2023

lore
Share & tools
lore
#0 lore raw

cover accel/tcg: Stubs cleanups

- Remove unused stubs,
- Guard with tcg_enabled() and remove more,
- Reduce tlb_set_dirty() scope?

Philippe Mathieu-Daudé (4):
accel/tcg: Remove tlb_set_dirty() stub
accel/tcg: Remove unused tcg_flush_jmp_cache() stub accel/tcg: Guard tb_flush() with tcg_enabled() and remove the stub accel/tcg: Keep tlb_set_dirty() internal

 include/exec/exec-all.h |  1 -
 accel/stubs/tcg-stub.c  | 12 ------------
 accel/tcg/cputlb.c      |  2 +-
 cpu.c                   | 15 +++++++++------
 gdbstub/softmmu.c       |  5 ++++-
 hw/ppc/spapr_hcall.c    |  2 +-
 6 files changed, 15 insertions(+), 22 deletions(-)
Signature · 1 line
2.41.0
#1 lore raw

PATCH 1/4 accel/tcg: Remove tlb_set_dirty() stub

Since commit 34d49937e4 ("accel/tcg: Handle atomic accesses to notdirty memory correctly") there is only a single call to tlb_set_dirty(), within accel/tcg/cputlb.c itself where the function is defined.

---
 accel/stubs/tcg-stub.c | 4 ----
 1 file changed, 4 deletions(-)
accel/stubs/tcg-stub.c +0 -4
index a9e7a2d5b4..f088054f34 100644
@@ -18,10 +18,6 @@ void tb_flush(CPUState *cpu)
 {
 }
 
-void tlb_set_dirty(CPUState *cpu, vaddr vaddr)
-{
-}
-
 void tcg_flush_jmp_cache(CPUState *cpu)
 {
 }
Signature · 1 line
2.41.0
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] accel/tcg: Remove tlb_set_dirty() stub

Quoted 6 lines · Philippe Mathieu-Daudé

Since commit 34d49937e4 ("accel/tcg: Handle atomic accesses to notdirty memory correctly") there is only a single call to tlb_set_dirty(), within accel/tcg/cputlb.c itself where the function is defined.

Quoted 19 lines
---
  accel/stubs/tcg-stub.c | 4 ----
  1 file changed, 4 deletions(-)
accel/stubs/tcg-stub.c +0 -4
index a9e7a2d5b4..f088054f34 100644
@@ -18,10 +18,6 @@ void tb_flush(CPUState *cpu)
  {
  }
 
-void tlb_set_dirty(CPUState *cpu, vaddr vaddr)
-{
-}
-
  void tcg_flush_jmp_cache(CPUState *cpu)
  {
  }
#3 lore raw

PATCH 2/4 accel/tcg: Remove unused tcg_flush_jmp_cache() stub

In reply to Philippe Mathieu-Daudé

Since commit ba7d3d1858 ("cpu_common_reset: wrap TCG specific code in tcg_enabled()") we protect the single call to tcg_flush_jmp_cache() with a check on tcg_enabled(). The stub isn't needed anymore.

---
 accel/stubs/tcg-stub.c | 4 ----
 1 file changed, 4 deletions(-)
accel/stubs/tcg-stub.c +0 -4
index f088054f34..dd890d6cf6 100644
@@ -18,10 +18,6 @@ void tb_flush(CPUState *cpu)
 {
 }
 
-void tcg_flush_jmp_cache(CPUState *cpu)
-{
-}
-
 int probe_access_flags(CPUArchState *env, vaddr addr, int size,
                        MMUAccessType access_type, int mmu_idx,
                        bool nonfault, void **phost, uintptr_t retaddr)
Signature · 1 line
2.41.0
#4 lore raw

Re: [PATCH 2/4] accel/tcg: Remove unused tcg_flush_jmp_cache() stub

Quoted 6 lines · Philippe Mathieu-Daudé

Since commit ba7d3d1858 ("cpu_common_reset: wrap TCG specific code in tcg_enabled()") we protect the single call to tcg_flush_jmp_cache() with a check on tcg_enabled(). The stub isn't needed anymore.

Commit log might need rephrase as I see multiple instance of call,
with one without check for tcg_enabled() in plugin_cpu_update__async but seems to be building only with tcg enabled so no build breaks.

Thanks
Harsh

Quoted 19 lines
---
  accel/stubs/tcg-stub.c | 4 ----
  1 file changed, 4 deletions(-)
accel/stubs/tcg-stub.c +0 -4
index f088054f34..dd890d6cf6 100644
@@ -18,10 +18,6 @@ void tb_flush(CPUState *cpu)
  {
  }
 
-void tcg_flush_jmp_cache(CPUState *cpu)
-{
-}
-
  int probe_access_flags(CPUArchState *env, vaddr addr, int size,
                         MMUAccessType access_type, int mmu_idx,
                         bool nonfault, void **phost, uintptr_t retaddr)
#5 lore raw

Re: [PATCH 2/4] accel/tcg: Remove unused tcg_flush_jmp_cache() stub

Quoted 8 lines · Harsh Prateek Bora
Quoted 5 lines · Philippe Mathieu-Daudé

Since commit ba7d3d1858 ("cpu_common_reset: wrap TCG specific code in tcg_enabled()") we protect the single call to tcg_flush_jmp_cache() with a check on tcg_enabled(). The stub isn't needed anymore.

Quoted 4 lines
Quoted 1 line

Commit log might need rephrase as I see multiple instance of call,
with one without check for tcg_enabled() in plugin_cpu_update__async but seems to be building only with tcg enabled so no build breaks.

TCG Plugins are restricted to TCG, so we don't need to guard there :) I'll update the description mentioning it.

Thanks for your review!

Quoted 20 lines

Thanks
Harsh

Quoted 18 lines

---
  accel/stubs/tcg-stub.c | 4 ----

  1 file changed, 4 deletions(-)
accel/stubs/tcg-stub.c +0 -4
index f088054f34..dd890d6cf6 100644
@@ -18,10 +18,6 @@ void tb_flush(CPUState *cpu)
   {
   }
-void tcg_flush_jmp_cache(CPUState *cpu)
-{
-}
-
   int probe_access_flags(CPUArchState *env, vaddr addr, int size,
                          MMUAccessType access_type, int mmu_idx,
                          bool nonfault, void **phost, uintptr_t retaddr)
#6 lore raw

RFC PATCH 3/4 accel/tcg: Guard tb_flush() with tcg_enabled() and remove the stub

In reply to Philippe Mathieu-Daudé

The check on tcg_enabled() make it clearer we want this call under TCG.

---
 accel/stubs/tcg-stub.c |  4 ----
 cpu.c                  | 15 +++++++++------
 gdbstub/softmmu.c      |  5 ++++-
 hw/ppc/spapr_hcall.c   |  2 +-
 4 files changed, 14 insertions(+), 12 deletions(-)
accel/stubs/tcg-stub.c +0 -4
index dd890d6cf6..7d9846f7f2 100644
@@ -14,10 +14,6 @@
 #include "exec/tb-flush.h"
 #include "exec/exec-all.h"
 
-void tb_flush(CPUState *cpu)
-{
-}
-
 int probe_access_flags(CPUArchState *env, vaddr addr, int size,
                        MMUAccessType access_type, int mmu_idx,
                        bool nonfault, void **phost, uintptr_t retaddr)
cpu.c +9 -6
index 0769b0b153..ce3b04f21f 100644
@@ -57,12 +57,15 @@ static int cpu_common_post_load(void *opaque, int version_id)
     cpu->interrupt_request &= ~0x01;
     tlb_flush(cpu);
 
-    /* loadvm has just updated the content of RAM, bypassing the
-     * usual mechanisms that ensure we flush TBs for writes to
-     * memory we've translated code from. So we must flush all TBs,
-     * which will now be stale.
-     */
-    tb_flush(cpu);
+    if (tcg_enabled()) {
+        /*
+         * loadvm has just updated the content of RAM, bypassing the
+         * usual mechanisms that ensure we flush TBs for writes to
+         * memory we've translated code from. So we must flush all TBs,
+         * which will now be stale.
+         */
+        tb_flush(cpu);
+    }
 
     return 0;
 }
gdbstub/softmmu.c +4 -1
index 9f0b8b5497..edd13f047d 100644
@@ -21,6 +21,7 @@
 #include "sysemu/cpus.h"
 #include "sysemu/runstate.h"
 #include "sysemu/replay.h"
+#include "sysemu/tcg.h"
 #include "hw/core/cpu.h"
 #include "hw/cpu/cluster.h"
 #include "hw/boards.h"
@@ -170,7 +171,9 @@ static void gdb_vm_state_change(void *opaque, bool running, RunState state)
         } else {
             trace_gdbstub_hit_break();
         }
-        tb_flush(cpu);
+        if (tcg_enabled()) {
+            tb_flush(cpu);
+        }
         ret = GDB_SIGNAL_TRAP;
         break;
     case RUN_STATE_PAUSED:
hw/ppc/spapr_hcall.c +1 -1
index b7dc388f2f..306f8fdf55 100644
@@ -296,7 +296,7 @@ static target_ulong h_page_init(PowerPCCPU *cpu, SpaprMachineState *spapr,
     if (flags & (H_ICACHE_SYNCHRONIZE | H_ICACHE_INVALIDATE)) {
         if (kvm_enabled()) {
             kvmppc_icbi_range(cpu, pdst, len);
-        } else {
+        } else if (tcg_enabled()) {
             tb_flush(CPU(cpu));
         }
     }
Signature · 1 line
2.41.0
#7 lore raw

Re: [RFC PATCH 3/4] accel/tcg: Guard tb_flush() with tcg_enabled() and remove the stub

Quoted 3 lines · Philippe Mathieu-Daudé

The check on tcg_enabled() make it clearer we want this call under TCG.

tb_flush already has a check for tcg_enabled() in its definition. Do we really need to check for same before calling it?

Thanks
Harsh

Quoted 85 lines
---
  accel/stubs/tcg-stub.c |  4 ----
  cpu.c                  | 15 +++++++++------
  gdbstub/softmmu.c      |  5 ++++-
  hw/ppc/spapr_hcall.c   |  2 +-
  4 files changed, 14 insertions(+), 12 deletions(-)
accel/stubs/tcg-stub.c +0 -4
index dd890d6cf6..7d9846f7f2 100644
@@ -14,10 +14,6 @@
  #include "exec/tb-flush.h"
  #include "exec/exec-all.h"
 
-void tb_flush(CPUState *cpu)
-{
-}
-
  int probe_access_flags(CPUArchState *env, vaddr addr, int size,
                         MMUAccessType access_type, int mmu_idx,
                         bool nonfault, void **phost, uintptr_t retaddr)
cpu.c +9 -6
index 0769b0b153..ce3b04f21f 100644
@@ -57,12 +57,15 @@ static int cpu_common_post_load(void *opaque, int version_id)
      cpu->interrupt_request &= ~0x01;
      tlb_flush(cpu);
 
-    /* loadvm has just updated the content of RAM, bypassing the
-     * usual mechanisms that ensure we flush TBs for writes to
-     * memory we've translated code from. So we must flush all TBs,
-     * which will now be stale.
-     */
-    tb_flush(cpu);
+    if (tcg_enabled()) {
+        /*
+         * loadvm has just updated the content of RAM, bypassing the
+         * usual mechanisms that ensure we flush TBs for writes to
+         * memory we've translated code from. So we must flush all TBs,
+         * which will now be stale.
+         */
+        tb_flush(cpu);
+    }
 
      return 0;
  }
gdbstub/softmmu.c +4 -1
index 9f0b8b5497..edd13f047d 100644
@@ -21,6 +21,7 @@
  #include "sysemu/cpus.h"
  #include "sysemu/runstate.h"
  #include "sysemu/replay.h"
+#include "sysemu/tcg.h"
  #include "hw/core/cpu.h"
  #include "hw/cpu/cluster.h"
  #include "hw/boards.h"
@@ -170,7 +171,9 @@ static void gdb_vm_state_change(void *opaque, bool running, RunState state)
          } else {
              trace_gdbstub_hit_break();
          }
-        tb_flush(cpu);
+        if (tcg_enabled()) {
+            tb_flush(cpu);
+        }
          ret = GDB_SIGNAL_TRAP;
          break;
      case RUN_STATE_PAUSED:
hw/ppc/spapr_hcall.c +1 -1
index b7dc388f2f..306f8fdf55 100644
@@ -296,7 +296,7 @@ static target_ulong h_page_init(PowerPCCPU *cpu, SpaprMachineState *spapr,
      if (flags & (H_ICACHE_SYNCHRONIZE | H_ICACHE_INVALIDATE)) {
          if (kvm_enabled()) {
              kvmppc_icbi_range(cpu, pdst, len);
-        } else {
+        } else if (tcg_enabled()) {
              tb_flush(CPU(cpu));
          }
      }
#8 lore raw

Re: [RFC PATCH 3/4] accel/tcg: Guard tb_flush() with tcg_enabled() and remove the stub

Quoted 9 lines · Harsh Prateek Bora
Quoted 3 lines · Philippe Mathieu-Daudé

The check on tcg_enabled() make it clearer we want this call under TCG.

tb_flush already has a check for tcg_enabled() in its definition. Do we really need to check for same before calling it?

Good point, I didn't notice. I'll replace the call in tb_flush() by an assertion.

Quoted 11 lines

Thanks
Harsh

Quoted 7 lines

---
  accel/stubs/tcg-stub.c |  4 ----
  cpu.c                  | 15 +++++++++------
  gdbstub/softmmu.c      |  5 ++++-
  hw/ppc/spapr_hcall.c   |  2 +-

  4 files changed, 14 insertions(+), 12 deletions(-)
#9 lore raw

Re: [RFC PATCH 3/4] accel/tcg: Guard tb_flush() with tcg_enabled() and remove the stub

Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Harsh Prateek Bora
Quoted 3 lines · Philippe Mathieu-Daudé

The check on tcg_enabled() make it clearer we want this call under TCG.

Quoted 5 lines
Quoted 2 lines

tb_flush already has a check for tcg_enabled() in its definition. Do we really need to check for same before calling it?

Good point, I didn't notice. I'll replace the call in tb_flush() by an assertion.

I guess you meant asserting in else case of the check inside ?
We may want to have the check internally only than having every caller to do that.

Quoted 14 lines
Quoted 12 lines

Thanks
Harsh

Quoted 7 lines

---
  accel/stubs/tcg-stub.c |  4 ----
  cpu.c                  | 15 +++++++++------
  gdbstub/softmmu.c      |  5 ++++-
  hw/ppc/spapr_hcall.c   |  2 +-

  4 files changed, 14 insertions(+), 12 deletions(-)
#10 lore raw

RFC PATCH 4/4 accel/tcg: Keep tlb_set_dirty() internal

In reply to Philippe Mathieu-Daudé

Since commit 34d49937e4 ("accel/tcg: Handle atomic accesses to notdirty memory correctly") tlb_set_dirty() is only used (once) in the very same file it is defined... Make it static.

---
 include/exec/exec-all.h | 1 -
 accel/tcg/cputlb.c      | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)
include/exec/exec-all.h +0 -1
index b2f5cd4c2a..59efa7bc28 100644
@@ -695,7 +695,6 @@ static inline void mmap_unlock(void) {}
 #define WITH_MMAP_LOCK_GUARD()
 
 void tlb_reset_dirty(CPUState *cpu, ram_addr_t start1, ram_addr_t length);
-void tlb_set_dirty(CPUState *cpu, vaddr addr);
 
 MemoryRegionSection *
 address_space_translate_for_iotlb(CPUState *cpu, int asidx, hwaddr addr,
accel/tcg/cputlb.c +1 -1
index c643d66190..fe9d702f3e 100644
@@ -1062,7 +1062,7 @@ static inline void tlb_set_dirty1_locked(CPUTLBEntry *tlb_entry,
 
 /* update the TLB corresponding to virtual page vaddr
    so that it is no longer dirty */
-void tlb_set_dirty(CPUState *cpu, vaddr addr)
+static void tlb_set_dirty(CPUState *cpu, vaddr addr)
 {
     CPUArchState *env = cpu->env_ptr;
     int mmu_idx;
Signature · 1 line
2.41.0
Reviewed-by on v1 4/4
#11 lore raw

Re: [RFC PATCH 4/4] accel/tcg: Keep tlb_set_dirty() internal

Quoted 5 lines · Philippe Mathieu-Daudé

Since commit 34d49937e4 ("accel/tcg: Handle atomic accesses to notdirty memory correctly") tlb_set_dirty() is only used (once) in the very same file it is defined... Make it static.

Quoted 30 lines
---
  include/exec/exec-all.h | 1 -
  accel/tcg/cputlb.c      | 2 +-
  2 files changed, 1 insertion(+), 2 deletions(-)
include/exec/exec-all.h +0 -1
index b2f5cd4c2a..59efa7bc28 100644
@@ -695,7 +695,6 @@ static inline void mmap_unlock(void) {}
  #define WITH_MMAP_LOCK_GUARD()
 
  void tlb_reset_dirty(CPUState *cpu, ram_addr_t start1, ram_addr_t length);
-void tlb_set_dirty(CPUState *cpu, vaddr addr);
 
  MemoryRegionSection *
  address_space_translate_for_iotlb(CPUState *cpu, int asidx, hwaddr addr,
accel/tcg/cputlb.c +1 -1
index c643d66190..fe9d702f3e 100644
@@ -1062,7 +1062,7 @@ static inline void tlb_set_dirty1_locked(CPUTLBEntry *tlb_entry,
 
  /* update the TLB corresponding to virtual page vaddr
     so that it is no longer dirty */
-void tlb_set_dirty(CPUState *cpu, vaddr addr)
+static void tlb_set_dirty(CPUState *cpu, vaddr addr)
  {
      CPUArchState *env = cpu->env_ptr;
      int mmu_idx;