[PATCH for-11.0 v3] accel/kvm: return early from kvm_irqchip_create if kvm does not support irqchip

Ani Sinha posted 1 patch 2 weeks, 1 day ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260414045911.63662-1-anisinha@redhat.com
Maintainers: Paolo Bonzini <pbonzini@redhat.com>
accel/kvm/kvm-all.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
[PATCH for-11.0 v3] accel/kvm: return early from kvm_irqchip_create if kvm does not support irqchip
Posted by Ani Sinha 2 weeks, 1 day ago
During refactoring of kvm_irqchip_create(), the refactored code was returning
early from do_kvm_irqchip_create() function if the required essential
capabilities were not present in KVM. This was not translating to an early
return from kvm_irqchip_create() as was the case before refactoring.
This is because, do_kvm_irqchip_create() did not have a means to notify the
caller of the lack of required kvm capabilities. Fix this by making
do_notify_irqchip_create() return EOPNOTSUPP error when  capabilities
are absent and then the caller can check the return code and return early.

Due to this regression during refactoring, all KVM guests on ppc64le hang
immediately during startup and this completely breaks all functionality on
that platform.

Fixes: 98884e0cc1 ("accel/kvm: add changes required to support KVM VM file descriptor change")
Message-ID: <20260413090010.60339-1-anisinha@redhat.com>
Reported-by: Misbah Anjum N <misanjum@linux.ibm.com>
Reported-by: Gautam Menghani <gautam@linux.ibm.com>
Suggested-by: Fabiano Rosas <farosas@suse.de>
Suggested-by: Harsh Prateek Bora <harshpb@linux.ibm.com>
Tested-by: Misbah Anjum N <misanjum@linux.ibm.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Ani Sinha <anisinha@redhat.com>
---
 accel/kvm/kvm-all.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

changelogs:
v2: refactoring included which will resubmitted again for 11.1
v3: basically v1 with tags added.

diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 774499d34f..92af42503b 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -2575,7 +2575,7 @@ void kvm_irqchip_set_qemuirq_gsi(KVMState *s, qemu_irq irq, int gsi)
     g_hash_table_insert(s->gsimap, irq, GINT_TO_POINTER(gsi));
 }
 
-static void do_kvm_irqchip_create(KVMState *s)
+static int do_kvm_irqchip_create(KVMState *s)
 {
     int ret;
     if (kvm_check_extension(s, KVM_CAP_IRQCHIP)) {
@@ -2587,7 +2587,7 @@ static void do_kvm_irqchip_create(KVMState *s)
             exit(1);
         }
     } else {
-        return;
+        return -EOPNOTSUPP;
     }
 
     if (kvm_check_extension(s, KVM_CAP_IRQFD) <= 0) {
@@ -2610,13 +2610,17 @@ static void do_kvm_irqchip_create(KVMState *s)
         fprintf(stderr, "Create kernel irqchip failed: %s\n", strerror(-ret));
         exit(1);
     }
+
+    return 0;
 }
 
 static void kvm_irqchip_create(KVMState *s)
 {
     assert(s->kernel_irqchip_split != ON_OFF_AUTO_AUTO);
 
-    do_kvm_irqchip_create(s);
+    if (do_kvm_irqchip_create(s) < 0) {
+        return;
+    }
     kvm_kernel_irqchip = true;
     /* If we have an in-kernel IRQ chip then we must have asynchronous
      * interrupt delivery (though the reverse is not necessarily true)
@@ -2835,6 +2839,7 @@ static int kvm_reset_vmfd(MachineState *ms)
     }
 
     if (s->kernel_irqchip_allowed) {
+        /* ignore return from this function */
         do_kvm_irqchip_create(s);
     }
 
-- 
2.49.0
Re: [PATCH for-11.0 v3] accel/kvm: return early from kvm_irqchip_create if kvm does not support irqchip
Posted by Peter Maydell 2 weeks, 1 day ago
On Tue, 14 Apr 2026 at 05:59, Ani Sinha <anisinha@redhat.com> wrote:
>
> During refactoring of kvm_irqchip_create(), the refactored code was returning
> early from do_kvm_irqchip_create() function if the required essential
> capabilities were not present in KVM. This was not translating to an early
> return from kvm_irqchip_create() as was the case before refactoring.
> This is because, do_kvm_irqchip_create() did not have a means to notify the
> caller of the lack of required kvm capabilities. Fix this by making
> do_notify_irqchip_create() return EOPNOTSUPP error when  capabilities
> are absent and then the caller can check the return code and return early.
>
> Due to this regression during refactoring, all KVM guests on ppc64le hang
> immediately during startup and this completely breaks all functionality on
> that platform.
>
> Fixes: 98884e0cc1 ("accel/kvm: add changes required to support KVM VM file descriptor change")
> Message-ID: <20260413090010.60339-1-anisinha@redhat.com>
> Reported-by: Misbah Anjum N <misanjum@linux.ibm.com>
> Reported-by: Gautam Menghani <gautam@linux.ibm.com>
> Suggested-by: Fabiano Rosas <farosas@suse.de>
> Suggested-by: Harsh Prateek Bora <harshpb@linux.ibm.com>
> Tested-by: Misbah Anjum N <misanjum@linux.ibm.com>
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Ani Sinha <anisinha@redhat.com>
> ---
>  accel/kvm/kvm-all.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)

Thanks; I'm going to apply this directly to git so we can get it
into rc4.

-- PMM
Re: [PATCH for-11.0 v3] accel/kvm: return early from kvm_irqchip_create if kvm does not support irqchip
Posted by Philippe Mathieu-Daudé 2 weeks, 1 day ago
On 14/4/26 06:59, Ani Sinha wrote:
> During refactoring of kvm_irqchip_create(), the refactored code was returning
> early from do_kvm_irqchip_create() function if the required essential
> capabilities were not present in KVM. This was not translating to an early
> return from kvm_irqchip_create() as was the case before refactoring.
> This is because, do_kvm_irqchip_create() did not have a means to notify the
> caller of the lack of required kvm capabilities. Fix this by making
> do_notify_irqchip_create() return EOPNOTSUPP error when  capabilities
> are absent and then the caller can check the return code and return early.
> 
> Due to this regression during refactoring, all KVM guests on ppc64le hang
> immediately during startup and this completely breaks all functionality on
> that platform.
> 
> Fixes: 98884e0cc1 ("accel/kvm: add changes required to support KVM VM file descriptor change")
> Message-ID: <20260413090010.60339-1-anisinha@redhat.com>
> Reported-by: Misbah Anjum N <misanjum@linux.ibm.com>
> Reported-by: Gautam Menghani <gautam@linux.ibm.com>
> Suggested-by: Fabiano Rosas <farosas@suse.de>
> Suggested-by: Harsh Prateek Bora <harshpb@linux.ibm.com>
> Tested-by: Misbah Anjum N <misanjum@linux.ibm.com>
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Ani Sinha <anisinha@redhat.com>
> ---
>   accel/kvm/kvm-all.c | 11 ++++++++---
>   1 file changed, 8 insertions(+), 3 deletions(-)
> 
> changelogs:
> v2: refactoring included which will resubmitted again for 11.1
> v3: basically v1 with tags added.
> 
> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
> index 774499d34f..92af42503b 100644
> --- a/accel/kvm/kvm-all.c
> +++ b/accel/kvm/kvm-all.c
> @@ -2575,7 +2575,7 @@ void kvm_irqchip_set_qemuirq_gsi(KVMState *s, qemu_irq irq, int gsi)
>       g_hash_table_insert(s->gsimap, irq, GINT_TO_POINTER(gsi));
>   }
>   
> -static void do_kvm_irqchip_create(KVMState *s)
> +static int do_kvm_irqchip_create(KVMState *s)
>   {
>       int ret;
>       if (kvm_check_extension(s, KVM_CAP_IRQCHIP)) {
> @@ -2587,7 +2587,7 @@ static void do_kvm_irqchip_create(KVMState *s)
>               exit(1);
>           }
>       } else {
> -        return;
> +        return -EOPNOTSUPP;
>       }
>   
>       if (kvm_check_extension(s, KVM_CAP_IRQFD) <= 0) {
> @@ -2610,13 +2610,17 @@ static void do_kvm_irqchip_create(KVMState *s)
>           fprintf(stderr, "Create kernel irqchip failed: %s\n", strerror(-ret));
>           exit(1);
>       }
> +
> +    return 0;
>   }
>   
>   static void kvm_irqchip_create(KVMState *s)
>   {
>       assert(s->kernel_irqchip_split != ON_OFF_AUTO_AUTO);
>   
> -    do_kvm_irqchip_create(s);
> +    if (do_kvm_irqchip_create(s) < 0) {
> +        return;
> +    }
>       kvm_kernel_irqchip = true;
>       /* If we have an in-kernel IRQ chip then we must have asynchronous
>        * interrupt delivery (though the reverse is not necessarily true)
> @@ -2835,6 +2839,7 @@ static int kvm_reset_vmfd(MachineState *ms)
>       }
>   
>       if (s->kernel_irqchip_allowed) {
> +        /* ignore return from this function */

No need to explain the code. If you want to add a comment, explain
the "why".

>           do_kvm_irqchip_create(s);
>       }
>