diff mbox series

[RFC,PATCH-for-10.1,3/4] tcg: Have tcg_req_mo() use runtime TCGContext::guest_mo

Message ID 20250321125737.72839-4-philmd@linaro.org
State New
Headers show
Series tcg: Move TCG_GUEST_DEFAULT_MO -> TCGCPUOps::guest_default_memory_order | expand

Commit Message

Philippe Mathieu-Daudé March 21, 2025, 12:57 p.m. UTC
In order to use TCG with multiple targets, replace the
compile time use of TCG_GUEST_DEFAULT_MO by a runtime
access to tcg_ctx->guest_mo.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 accel/tcg/internal-target.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Comments

Anton Johansson March 21, 2025, 2:39 p.m. UTC | #1
On 21/03/25, Philippe Mathieu-Daudé wrote:
> In order to use TCG with multiple targets, replace the
> compile time use of TCG_GUEST_DEFAULT_MO by a runtime
> access to tcg_ctx->guest_mo.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  accel/tcg/internal-target.h | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/accel/tcg/internal-target.h b/accel/tcg/internal-target.h
> index 1cb35dba99e..014ee756f9d 100644
> --- a/accel/tcg/internal-target.h
> +++ b/accel/tcg/internal-target.h
> @@ -49,11 +49,9 @@ G_NORETURN void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr);
>   * Filter @type to the barrier that is required for the guest
>   * memory ordering vs the host memory ordering.  A non-zero
>   * result indicates that some barrier is required.
> - *
> - * This is a macro so that it's constant even without optimization.
>   */
>  #define tcg_req_mo(type) \
> -    ((type) & TCG_GUEST_DEFAULT_MO & ~TCG_TARGET_DEFAULT_MO)
> +    ((type) & tcg_ctx->guest_mo & ~TCG_TARGET_DEFAULT_MO)
>  
>  /**
>   * cpu_req_mo:
> -- 
> 2.47.1
> 

I'll parrot some older feedback by Richard

  https://lore.kernel.org/all/92cc9335-10bf-4a74-9eb4-249de5545dc5@linaro.org/

but tcg_ctx->guest_mo can be undefined or bogus here. Could we not
take cpu and access cpu->cc->tcg_ops->guest_default_memory_order
directly instead?
Philippe Mathieu-Daudé March 21, 2025, 2:46 p.m. UTC | #2
On 21/3/25 15:39, Anton Johansson wrote:
> On 21/03/25, Philippe Mathieu-Daudé wrote:
>> In order to use TCG with multiple targets, replace the
>> compile time use of TCG_GUEST_DEFAULT_MO by a runtime
>> access to tcg_ctx->guest_mo.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> ---
>>   accel/tcg/internal-target.h | 4 +---
>>   1 file changed, 1 insertion(+), 3 deletions(-)
>>
>> diff --git a/accel/tcg/internal-target.h b/accel/tcg/internal-target.h
>> index 1cb35dba99e..014ee756f9d 100644
>> --- a/accel/tcg/internal-target.h
>> +++ b/accel/tcg/internal-target.h
>> @@ -49,11 +49,9 @@ G_NORETURN void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr);
>>    * Filter @type to the barrier that is required for the guest
>>    * memory ordering vs the host memory ordering.  A non-zero
>>    * result indicates that some barrier is required.
>> - *
>> - * This is a macro so that it's constant even without optimization.
>>    */
>>   #define tcg_req_mo(type) \
>> -    ((type) & TCG_GUEST_DEFAULT_MO & ~TCG_TARGET_DEFAULT_MO)
>> +    ((type) & tcg_ctx->guest_mo & ~TCG_TARGET_DEFAULT_MO)
>>   
>>   /**
>>    * cpu_req_mo:
>> -- 
>> 2.47.1
>>
> 
> I'll parrot some older feedback by Richard
> 
>    https://lore.kernel.org/all/92cc9335-10bf-4a74-9eb4-249de5545dc5@linaro.org/
> 
> but tcg_ctx->guest_mo can be undefined or bogus here. Could we not
> take cpu and access cpu->cc->tcg_ops->guest_default_memory_order
> directly instead?

Yes, cpu_req_mo() has access to @cpu.
Richard Henderson March 21, 2025, 3:16 p.m. UTC | #3
On 3/21/25 05:57, Philippe Mathieu-Daudé wrote:
> In order to use TCG with multiple targets, replace the
> compile time use of TCG_GUEST_DEFAULT_MO by a runtime
> access to tcg_ctx->guest_mo.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   accel/tcg/internal-target.h | 4 +---
>   1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/accel/tcg/internal-target.h b/accel/tcg/internal-target.h
> index 1cb35dba99e..014ee756f9d 100644
> --- a/accel/tcg/internal-target.h
> +++ b/accel/tcg/internal-target.h
> @@ -49,11 +49,9 @@ G_NORETURN void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr);
>    * Filter @type to the barrier that is required for the guest
>    * memory ordering vs the host memory ordering.  A non-zero
>    * result indicates that some barrier is required.
> - *
> - * This is a macro so that it's constant even without optimization.
>    */
>   #define tcg_req_mo(type) \
> -    ((type) & TCG_GUEST_DEFAULT_MO & ~TCG_TARGET_DEFAULT_MO)
> +    ((type) & tcg_ctx->guest_mo & ~TCG_TARGET_DEFAULT_MO)


Incorrect.  The setting in tcg_ctx is only valid during compilation.

This macro is used during execution, in cpu_req_mo(),
from the cpu memory access routines.


r~
diff mbox series

Patch

diff --git a/accel/tcg/internal-target.h b/accel/tcg/internal-target.h
index 1cb35dba99e..014ee756f9d 100644
--- a/accel/tcg/internal-target.h
+++ b/accel/tcg/internal-target.h
@@ -49,11 +49,9 @@  G_NORETURN void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr);
  * Filter @type to the barrier that is required for the guest
  * memory ordering vs the host memory ordering.  A non-zero
  * result indicates that some barrier is required.
- *
- * This is a macro so that it's constant even without optimization.
  */
 #define tcg_req_mo(type) \
-    ((type) & TCG_GUEST_DEFAULT_MO & ~TCG_TARGET_DEFAULT_MO)
+    ((type) & tcg_ctx->guest_mo & ~TCG_TARGET_DEFAULT_MO)
 
 /**
  * cpu_req_mo: