Skip to contentSkip to conversation

s390x/flic: adapter routes handling if !kernel_irqchip

PATCH In review Cornelia Huck 2 participants 3 messages Jan 16, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 s390x/flic: adapter routes handling if !kernel_irqchip

If the kernel irqchip has been disabled, we don't want the {add,release}_adapter_routes routines to call any kvm_irqchip_* interfaces, as they may rely on an irqchip actually having been created. Just take a quick exit in that case instead.

Fixes d426d9fba8ea ("s390x/virtio-ccw: wire up irq routing and irqfds")

---

Without this patch, QEMU with kernel_irqchip=off will crash in kvm_irqchip_release_virq(), so alternatively, we could add a check there. kvm_irqchip_add_adapter_route() is actually fine.

---
 hw/intc/s390_flic_kvm.c | 8 ++++++++
 1 file changed, 8 insertions(+)
hw/intc/s390_flic_kvm.c +8 -0
index dddd33ea61c8..44b7960ebcc8 100644
@@ -331,6 +331,10 @@ static int kvm_s390_add_adapter_routes(S390FLICState *fs,
     int ret, i;
     uint64_t ind_offset = routes->adapter.ind_offset;
 
+    if (!kvm_gsi_routing_enabled()) {
+        return -ENOSYS;
+    }
+
     for (i = 0; i < routes->num_routes; i++) {
         ret = kvm_irqchip_add_adapter_route(kvm_state, &routes->adapter);
         if (ret < 0) {
@@ -358,6 +362,10 @@ static void kvm_s390_release_adapter_routes(S390FLICState *fs,
 {
     int i;
 
+    if (!kvm_gsi_routing_enabled()) {
+        return;
+    }
+
     for (i = 0; i < routes->num_routes; i++) {
         if (routes->gsi[i] >= 0) {
             kvm_irqchip_release_virq(kvm_state, routes->gsi[i]);
Signature · 1 line
2.21.1
#1 lore raw
Quoted 22 lines · Cornelia Huck

If the kernel irqchip has been disabled, we don't want the {add,release}_adapter_routes routines to call any kvm_irqchip_* interfaces, as they may rely on an irqchip actually having been created. Just take a quick exit in that case instead.

Fixes d426d9fba8ea ("s390x/virtio-ccw: wire up irq routing and irqfds")

---

Without this patch, QEMU with kernel_irqchip=off will crash in kvm_irqchip_release_virq(), so alternatively, we could add a check there. kvm_irqchip_add_adapter_route() is actually fine.

---
 hw/intc/s390_flic_kvm.c | 8 ++++++++
 1 file changed, 8 insertions(+)
hw/intc/s390_flic_kvm.c +0 -0
index dddd33ea61c8..44b7960ebcc8 100644

hw/intc/s390_flic_kvm.c static int kvm_s390_add_adapter_routes(S390FLICState *fs, · line 336

Quoted 6 lines
hw/intc/s390_flic_kvm.c +3 -0
@@ -331,6 +331,10 @@ static int kvm_s390_add_adapter_routes(S390FLICState *fs,
     int ret, i;
     uint64_t ind_offset = routes->adapter.ind_offset;
 
+    if (!kvm_gsi_routing_enabled()) {
+        return -ENOSYS;
+    }

As you wrote, this check is not really necessary since it is already done in kvm_irqchip_add_adapter_route() ...

hw/intc/s390_flic_kvm.c static int kvm_s390_add_adapter_routes(S390FLICState *fs, · line 340

Quoted 3 lines
hw/intc/s390_flic_kvm.c +0 -0
     for (i = 0; i < routes->num_routes; i++) {
         ret = kvm_irqchip_add_adapter_route(kvm_state, &routes->adapter);
         if (ret < 0) {

... so I wonder if it would be simply best to set

               routes->gsi[i] = -1;

before the "goto" instead to make sure that kvm_s390_release_adapter_routes() does not try to clean it up? That would also fix a potential crash in case kvm_irqchip_add_adapter_route() returned an error code in case of a different problem, I think.

Thomas

Quoted 12 lines
hw/intc/s390_flic_kvm.c +4 -0
@@ -358,6 +362,10 @@ static void kvm_s390_release_adapter_routes(S390FLICState *fs,
 {
     int i;
 
+    if (!kvm_gsi_routing_enabled()) {
+        return;
+    }
+
     for (i = 0; i < routes->num_routes; i++) {
         if (routes->gsi[i] >= 0) {
             kvm_irqchip_release_virq(kvm_state, routes->gsi[i]);
#2 lore raw
Quoted 26 lines · On Thu, 16 Jan 2020 13:52:21 +0100 Thomas Huth <[email protected]> wrote:
Quoted 25 lines · Cornelia Huck

If the kernel irqchip has been disabled, we don't want the {add,release}_adapter_routes routines to call any kvm_irqchip_* interfaces, as they may rely on an irqchip actually having been created. Just take a quick exit in that case instead.

Fixes d426d9fba8ea ("s390x/virtio-ccw: wire up irq routing and irqfds")

---

Without this patch, QEMU with kernel_irqchip=off will crash in kvm_irqchip_release_virq(), so alternatively, we could add a check there. kvm_irqchip_add_adapter_route() is actually fine.

---
 hw/intc/s390_flic_kvm.c | 8 ++++++++
 1 file changed, 8 insertions(+)
hw/intc/s390_flic_kvm.c +0 -0
index dddd33ea61c8..44b7960ebcc8 100644
@@ -331,6 +331,10 @@ static int kvm_s390_add_adapter_routes(S390FLICState *fs,
     int ret, i;
     uint64_t ind_offset = routes->adapter.ind_offset;
 
Quoted 6 lines

hw/intc/s390_flic_kvm.c static int kvm_s390_add_adapter_routes(S390FLICState *fs, · line 336

Quoted 3 lines
hw/intc/s390_flic_kvm.c +3 -0
+    if (!kvm_gsi_routing_enabled()) {
+        return -ENOSYS;
+    }  

As you wrote, this check is not really necessary since it is already done in kvm_irqchip_add_adapter_route() ...

I do think it is cleaner, though.

Quoted 5 lines

hw/intc/s390_flic_kvm.c static int kvm_s390_add_adapter_routes(S390FLICState *fs, · line 340

Quoted 4 lines
hw/intc/s390_flic_kvm.c +0 -0
     for (i = 0; i < routes->num_routes; i++) {
         ret = kvm_irqchip_add_adapter_route(kvm_state, &routes->adapter);
         if (ret < 0) {  
Quoted 8 lines

... so I wonder if it would be simply best to set

               routes->gsi[i] = -1;

before the "goto" instead to make sure that kvm_s390_release_adapter_routes() does not try to clean it up? That would also fix a potential crash in case kvm_irqchip_add_adapter_route() returned an error code in case of a different problem, I think.

I think we should pre-initialize gsi[] to -1 instead, just to be on the safe side.