[PATCH v4 02/65] system/cpus: Defer memory layout changes until vCPUs are realized

Philippe Mathieu-Daudé posted 65 patches 4 months, 2 weeks ago
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, Cameron Esfahani <dirty@apple.com>, Roman Bolshakov <rbolshakov@ddn.com>, Phil Dennis-Jordan <phil@philjordan.eu>, Mads Ynddal <mads@ynddal.dk>, Fabiano Rosas <farosas@suse.de>, Laurent Vivier <lvivier@redhat.com>, Stefano Stabellini <sstabellini@kernel.org>, Anthony PERARD <anthony@xenproject.org>, Paul Durrant <paul@xen.org>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Warner Losh <imp@bsdimp.com>, Kyle Evans <kevans@freebsd.org>, "Alex Bennée" <alex.bennee@linaro.org>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, "Dr. David Alan Gilbert" <dave@treblig.org>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Yanan Wang <wangyanan55@huawei.com>, Zhao Liu <zhao1.liu@intel.com>, Reinoud Zandijk <reinoud@netbsd.org>, Sunil Muthuswamy <sunilmut@microsoft.com>, Eric Blake <eblake@redhat.com>, Markus Armbruster <armbru@redhat.com>, Michael Roth <michael.roth@amd.com>, Peter Xu <peterx@redhat.com>, David Hildenbrand <david@redhat.com>, Peter Maydell <peter.maydell@linaro.org>, Alexander Graf <agraf@csgraf.de>
There is a newer version of this series
[PATCH v4 02/65] system/cpus: Defer memory layout changes until vCPUs are realized
Posted by Philippe Mathieu-Daudé 4 months, 2 weeks ago
vCPUs are not really usable until fully realized. Do not attempt
to commit memory changes in the middle of vCPU realization. Defer
until realization is completed and vCPU fully operational.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 system/physmem.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/system/physmem.c b/system/physmem.c
index ff0ca40222d..8b2be31fa7e 100644
--- a/system/physmem.c
+++ b/system/physmem.c
@@ -2792,6 +2792,14 @@ static void tcg_commit(MemoryListener *listener)
     cpuas = container_of(listener, CPUAddressSpace, tcg_as_listener);
     cpu = cpuas->cpu;
 
+    if (!qdev_is_realized(DEVICE(cpu))) {
+        /*
+         * The listener is also called during realize, before
+         * all of the tcg machinery for run-on is initialized.
+         */
+        return;
+    }
+
     /*
      * Defer changes to as->memory_dispatch until the cpu is quiescent.
      * Otherwise we race between (1) other cpu threads and (2) ongoing
-- 
2.49.0


Re: [PATCH v4 02/65] system/cpus: Defer memory layout changes until vCPUs are realized
Posted by Alex Bennée 4 months, 2 weeks ago
Philippe Mathieu-Daudé <philmd@linaro.org> writes:

> vCPUs are not really usable until fully realized. Do not attempt
> to commit memory changes in the middle of vCPU realization. Defer
> until realization is completed and vCPU fully operational.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  system/physmem.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/system/physmem.c b/system/physmem.c
> index ff0ca40222d..8b2be31fa7e 100644
> --- a/system/physmem.c
> +++ b/system/physmem.c
> @@ -2792,6 +2792,14 @@ static void tcg_commit(MemoryListener *listener)
>      cpuas = container_of(listener, CPUAddressSpace, tcg_as_listener);
>      cpu = cpuas->cpu;
>  
> +    if (!qdev_is_realized(DEVICE(cpu))) {
> +        /*
> +         * The listener is also called during realize, before
> +         * all of the tcg machinery for run-on is initialized.
> +         */
> +        return;
> +    }
> +

This is a c&p of the wording bellow:

     * That said, the listener is also called during realize, before
     * all of the tcg machinery for run-on is initialized: thus halt_cond.

which is now redundant because of the early exit?


>      /*
>       * Defer changes to as->memory_dispatch until the cpu is quiescent.
>       * Otherwise we race between (1) other cpu threads and (2) ongoing

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro
Re: [PATCH v4 02/65] system/cpus: Defer memory layout changes until vCPUs are realized
Posted by Philippe Mathieu-Daudé 4 months, 2 weeks ago
On 3/7/25 18:37, Alex Bennée wrote:
> Philippe Mathieu-Daudé <philmd@linaro.org> writes:
> 
>> vCPUs are not really usable until fully realized. Do not attempt
>> to commit memory changes in the middle of vCPU realization. Defer
>> until realization is completed and vCPU fully operational.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
>> ---
>>   system/physmem.c | 8 ++++++++
>>   1 file changed, 8 insertions(+)
>>
>> diff --git a/system/physmem.c b/system/physmem.c
>> index ff0ca40222d..8b2be31fa7e 100644
>> --- a/system/physmem.c
>> +++ b/system/physmem.c
>> @@ -2792,6 +2792,14 @@ static void tcg_commit(MemoryListener *listener)
>>       cpuas = container_of(listener, CPUAddressSpace, tcg_as_listener);
>>       cpu = cpuas->cpu;
>>   
>> +    if (!qdev_is_realized(DEVICE(cpu))) {
>> +        /*
>> +         * The listener is also called during realize, before
>> +         * all of the tcg machinery for run-on is initialized.
>> +         */
>> +        return;
>> +    }
>> +
> 
> This is a c&p of the wording bellow:
> 
>       * That said, the listener is also called during realize, before
>       * all of the tcg machinery for run-on is initialized: thus halt_cond.
> 
> which is now redundant because of the early exit?

Commit 0d58c660689 ("softmmu: Use async_run_on_cpu in tcg_commit") hmmm.

I don't understand enough this area, so I'll drop this patch for now and
keep carrying it for split accel.

Regards,

Phil.