[PATCH 02/11] include: Introduce tlb_ptr field to CPUState

Anton Johansson via posted 11 patches 2 years, 5 months ago
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, Riku Voipio <riku.voipio@iki.fi>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Yanan Wang <wangyanan55@huawei.com>, Peter Maydell <peter.maydell@linaro.org>
There is a newer version of this series
[PATCH 02/11] include: Introduce tlb_ptr field to CPUState
Posted by Anton Johansson via 2 years, 5 months ago
Adds a CPUTLB * field to CPUState in order to access the TLB without
knowledge of the ArchCPU struct layout. A cpu_tlb(CPUState *) function
is added for ease of access.

Signed-off-by: Anton Johansson <anjo@rev.ng>
---
 include/exec/cpu-all.h | 12 ++++++++++++
 include/hw/core/cpu.h  |  6 ++++++
 2 files changed, 18 insertions(+)

diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
index c2c62160c6..b03218d7d3 100644
--- a/include/exec/cpu-all.h
+++ b/include/exec/cpu-all.h
@@ -435,6 +435,7 @@ static inline void cpu_set_cpustate_pointers(ArchCPU *cpu)
 {
     cpu->parent_obj.env_ptr = &cpu->env;
     cpu->parent_obj.icount_decr_ptr = &cpu->neg.icount_decr;
+    cpu->parent_obj.tlb_ptr = &cpu->neg.tlb;
 }
 
 /**
@@ -494,4 +495,15 @@ static inline CPUTLB *env_tlb(CPUArchState *env)
     return &env_neg(env)->tlb;
 }
 
+/**
+ * cpu_tlb(cpu)
+ * @cpu: The generic CPUState
+ *
+ * Return the CPUTLB state associated with the cpu.
+ */
+static inline CPUTLB *cpu_tlb(CPUState *cpu)
+{
+    return cpu->tlb_ptr;
+}
+
 #endif /* CPU_ALL_H */
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 92a4234439..dd31303480 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -238,7 +238,12 @@ typedef struct SavedIOTLB {
 } SavedIOTLB;
 #endif
 
+/* see include/exec/cpu-defs.h */
+struct CPUTLB;
+
+/* see include/sysemu/kvm_int.h */
 struct KVMState;
+/* see linux-headers/linux/kvm.h */
 struct kvm_run;
 
 /* work queue */
@@ -372,6 +377,7 @@ struct CPUState {
 
     CPUArchState *env_ptr;
     IcountDecr *icount_decr_ptr;
+    struct CPUTLB *tlb_ptr;
 
     CPUJumpCache *tb_jmp_cache;
 
-- 
2.41.0
Re: [PATCH 02/11] include: Introduce tlb_ptr field to CPUState
Posted by Richard Henderson 2 years, 5 months ago
On 9/12/23 08:34, Anton Johansson wrote:
>       IcountDecr *icount_decr_ptr;
> +    struct CPUTLB *tlb_ptr;

These are both in CPUNegativeOffsetState.
We might as well use that pointer instead.


r~
Re: [PATCH 02/11] include: Introduce tlb_ptr field to CPUState
Posted by Anton Johansson via 2 years, 5 months ago
> On 9/12/23 08:34, Anton Johansson wrote:
>>       IcountDecr *icount_decr_ptr;
>> +    struct CPUTLB *tlb_ptr;
>
> These are both in CPUNegativeOffsetState.
> We might as well use that pointer instead.
>
>
> r~

Ah, good point.

-- 
Anton Johansson,
rev.ng Labs Srl.