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

Philippe Mathieu-Daudé posted 4 patches 1 week, 3 days ago
There is a newer version of this series
[RFC PATCH-for-10.1 3/4] tcg: Have tcg_req_mo() use runtime TCGContext::guest_mo
Posted by Philippe Mathieu-Daudé 1 week, 3 days ago
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


Re: [RFC PATCH-for-10.1 3/4] tcg: Have tcg_req_mo() use runtime TCGContext::guest_mo
Posted by Richard Henderson 1 week, 3 days ago
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~

Re: [RFC PATCH-for-10.1 3/4] tcg: Have tcg_req_mo() use runtime TCGContext::guest_mo
Posted by Anton Johansson via 1 week, 3 days ago
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?

Re: [RFC PATCH-for-10.1 3/4] tcg: Have tcg_req_mo() use runtime TCGContext::guest_mo
Posted by Philippe Mathieu-Daudé 1 week, 3 days ago
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.