[PATCH 1/3] plugins: Ensure vCPU index is assigned in init/exit hooks

Philippe Mathieu-Daudé posted 3 patches 5 months, 3 weeks ago
Maintainers: Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Yanan Wang <wangyanan55@huawei.com>, "Alex Bennée" <alex.bennee@linaro.org>, Alexandre Iooss <erdnaxe@crans.org>, Mahmoud Mandour <ma.mandourr@gmail.com>, Pierrick Bouvier <pierrick.bouvier@linaro.org>
[PATCH 1/3] plugins: Ensure vCPU index is assigned in init/exit hooks
Posted by Philippe Mathieu-Daudé 5 months, 3 weeks ago
Since vCPUs are hashed by their index, this index can't
be uninitialized (UNASSIGNED_CPU_INDEX).

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 plugins/core.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/plugins/core.c b/plugins/core.c
index badede28cf..d339b3db4d 100644
--- a/plugins/core.c
+++ b/plugins/core.c
@@ -245,6 +245,7 @@ void qemu_plugin_vcpu_init_hook(CPUState *cpu)
 {
     bool success;
 
+    assert(cpu->cpu_index != UNASSIGNED_CPU_INDEX);
     qemu_rec_mutex_lock(&plugin.lock);
     plugin.num_vcpus = MAX(plugin.num_vcpus, cpu->cpu_index + 1);
     plugin_cpu_update__locked(&cpu->cpu_index, NULL, NULL);
@@ -263,6 +264,7 @@ void qemu_plugin_vcpu_exit_hook(CPUState *cpu)
 
     plugin_vcpu_cb__simple(cpu, QEMU_PLUGIN_EV_VCPU_EXIT);
 
+    assert(cpu->cpu_index != UNASSIGNED_CPU_INDEX);
     qemu_rec_mutex_lock(&plugin.lock);
     success = g_hash_table_remove(plugin.cpu_ht, &cpu->cpu_index);
     g_assert(success);
-- 
2.41.0


Re: [PATCH 1/3] plugins: Ensure vCPU index is assigned in init/exit hooks
Posted by Pierrick Bouvier 5 months, 3 weeks ago
On 6/6/24 05:40, Philippe Mathieu-Daudé wrote:
> Since vCPUs are hashed by their index, this index can't
> be uninitialized (UNASSIGNED_CPU_INDEX).
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   plugins/core.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/plugins/core.c b/plugins/core.c
> index badede28cf..d339b3db4d 100644
> --- a/plugins/core.c
> +++ b/plugins/core.c
> @@ -245,6 +245,7 @@ void qemu_plugin_vcpu_init_hook(CPUState *cpu)
>   {
>       bool success;
>   
> +    assert(cpu->cpu_index != UNASSIGNED_CPU_INDEX);
>       qemu_rec_mutex_lock(&plugin.lock);
>       plugin.num_vcpus = MAX(plugin.num_vcpus, cpu->cpu_index + 1);
>       plugin_cpu_update__locked(&cpu->cpu_index, NULL, NULL);
> @@ -263,6 +264,7 @@ void qemu_plugin_vcpu_exit_hook(CPUState *cpu)
>   
>       plugin_vcpu_cb__simple(cpu, QEMU_PLUGIN_EV_VCPU_EXIT);
>   
> +    assert(cpu->cpu_index != UNASSIGNED_CPU_INDEX);
>       qemu_rec_mutex_lock(&plugin.lock);
>       success = g_hash_table_remove(plugin.cpu_ht, &cpu->cpu_index);
>       g_assert(success);

Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>