[PATCH] ppc/spapr: fix drc index mismatch for partially enabled vcpus

Harsh Prateek Bora posted 1 patch 1 year, 2 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20241119090849.1335829-1-harshpb@linux.ibm.com
Maintainers: Nicholas Piggin <npiggin@gmail.com>, Daniel Henrique Barboza <danielhb413@gmail.com>, Harsh Prateek Bora <harshpb@linux.ibm.com>
hw/ppc/spapr.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] ppc/spapr: fix drc index mismatch for partially enabled vcpus
Posted by Harsh Prateek Bora 1 year, 2 months ago
In case when vcpus are explicitly enabled/disabled in a non-consecutive
order within a libvirt xml, it results in a drc index mismatch during
vcpu hotplug later because the existing logic uses vcpu id to derive the
corresponding drc index which is not correct. Use env->core_index to
derive a vcpu's drc index as appropriate to fix this issue.

For ex, for the given libvirt xml config:
  <vcpus>
    <vcpu id='0' enabled='yes' hotpluggable='no'/>
    <vcpu id='1' enabled='yes' hotpluggable='yes'/>
    <vcpu id='2' enabled='no' hotpluggable='yes'/>
    <vcpu id='3' enabled='yes' hotpluggable='yes'/>
    <vcpu id='4' enabled='no' hotpluggable='yes'/>
    <vcpu id='5' enabled='yes' hotpluggable='yes'/>
    <vcpu id='6' enabled='no' hotpluggable='yes'/>
    <vcpu id='7' enabled='no' hotpluggable='yes'/>
  </vcpus>

We see below error on guest console with "virsh setvcpus <domain> 5" :

pseries-hotplug-cpu: CPU with drc index 10000002 already exists

This patch fixes the issue by using correct drc index for explicitly
enabled vcpus during init.

Reported-by: Anushree Mathur <anushree.mathur@linux.vnet.ibm.com>
Tested-by: Anushree Mathur <anushree.mathur@linux.vnet.ibm.com>
Signed-off-by: Harsh Prateek Bora <harshpb@linux.ibm.com>
---
 hw/ppc/spapr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 5c02037c56..0d4efaa0c0 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -701,7 +701,7 @@ static void spapr_dt_cpu(CPUState *cs, void *fdt, int offset,
     uint32_t radix_AP_encodings[PPC_PAGE_SIZES_MAX_SZ];
     int i;
 
-    drc = spapr_drc_by_id(TYPE_SPAPR_DRC_CPU, index);
+    drc = spapr_drc_by_id(TYPE_SPAPR_DRC_CPU, env->core_index);
     if (drc) {
         drc_index = spapr_drc_index(drc);
         _FDT((fdt_setprop_cell(fdt, offset, "ibm,my-drc-index", drc_index)));
-- 
2.45.2
Re: [PATCH] ppc/spapr: fix drc index mismatch for partially enabled vcpus
Posted by Nicholas Piggin 1 year, 2 months ago
On Tue Nov 19, 2024 at 7:08 PM AEST, Harsh Prateek Bora wrote:
> In case when vcpus are explicitly enabled/disabled in a non-consecutive
> order within a libvirt xml, it results in a drc index mismatch during
> vcpu hotplug later because the existing logic uses vcpu id to derive the
> corresponding drc index which is not correct. Use env->core_index to
> derive a vcpu's drc index as appropriate to fix this issue.
>
> For ex, for the given libvirt xml config:
>   <vcpus>
>     <vcpu id='0' enabled='yes' hotpluggable='no'/>
>     <vcpu id='1' enabled='yes' hotpluggable='yes'/>
>     <vcpu id='2' enabled='no' hotpluggable='yes'/>
>     <vcpu id='3' enabled='yes' hotpluggable='yes'/>
>     <vcpu id='4' enabled='no' hotpluggable='yes'/>
>     <vcpu id='5' enabled='yes' hotpluggable='yes'/>
>     <vcpu id='6' enabled='no' hotpluggable='yes'/>
>     <vcpu id='7' enabled='no' hotpluggable='yes'/>
>   </vcpus>
>
> We see below error on guest console with "virsh setvcpus <domain> 5" :
>
> pseries-hotplug-cpu: CPU with drc index 10000002 already exists
>
> This patch fixes the issue by using correct drc index for explicitly
> enabled vcpus during init.
>
> Reported-by: Anushree Mathur <anushree.mathur@linux.vnet.ibm.com>
> Tested-by: Anushree Mathur <anushree.mathur@linux.vnet.ibm.com>
> Signed-off-by: Harsh Prateek Bora <harshpb@linux.ibm.com>

Reviewed-by: Nicholas Piggin <npiggin@gmail.com>

> ---
>  hw/ppc/spapr.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index 5c02037c56..0d4efaa0c0 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -701,7 +701,7 @@ static void spapr_dt_cpu(CPUState *cs, void *fdt, int offset,
>      uint32_t radix_AP_encodings[PPC_PAGE_SIZES_MAX_SZ];
>      int i;
>  
> -    drc = spapr_drc_by_id(TYPE_SPAPR_DRC_CPU, index);
> +    drc = spapr_drc_by_id(TYPE_SPAPR_DRC_CPU, env->core_index);
>      if (drc) {
>          drc_index = spapr_drc_index(drc);
>          _FDT((fdt_setprop_cell(fdt, offset, "ibm,my-drc-index", drc_index)));