virtio_pci: avoid to request intx irq if pin is zero
PATCH v2 1/1 virtio_pci: avoid to request intx irq if pin is zero
The background is that we use dpu in cloud computing,the arch is x86,80 cores.We will have a lots of virtio devices,like 512 or more. When we probe about 200 virtio_blk devices,it will fail and the stack is print as follows:
[25338.485128] virtio-pci 0000:b3:00.0: virtio_pci: leaving for legacy driver [25338.496174] genirq: Flags mismatch irq 0. 00000080 (virtio418) vs. 00015a00 (timer) [25338.503822] CPU: 20 PID: 5431 Comm: kworker/20:0 Kdump: loaded Tainted: G OE --------- - - 4.18.0-305.30.1.el8.x86_64 [25338.516403] Hardware name: Inspur NF5280M5/YZMB-00882-10E, BIOS 4.1.21 08/25/2021 [25338.523881] Workqueue: events work_for_cpu_fn [25338.528235] Call Trace: [25338.530687] dump_stack+0x5c/0x80 [25338.534000] __setup_irq.cold.53+0x7c/0xd3 [25338.538098] request_threaded_irq+0xf5/0x160 [25338.542371] vp_find_vqs+0xc7/0x190 [25338.545866] init_vq+0x17c/0x2e0 [virtio_blk] [25338.550223] ? ncpus_cmp_func+0x10/0x10 [25338.554061] virtblk_probe+0xe6/0x8a0 [virtio_blk] [25338.558846] virtio_dev_probe+0x158/0x1f0 [25338.562861] really_probe+0x255/0x4a0 [25338.566524] ? __driver_attach_async_helper+0x90/0x90 [25338.571567] driver_probe_device+0x49/0xc0 [25338.575660] bus_for_each_drv+0x79/0xc0 [25338.579499] __device_attach+0xdc/0x160 [25338.583337] bus_probe_device+0x9d/0xb0 [25338.587167] device_add+0x418/0x780 [25338.590654] register_virtio_device+0x9e/0xe0 [25338.595011] virtio_pci_probe+0xb3/0x140 [25338.598941] local_pci_probe+0x41/0x90 [25338.602689] work_for_cpu_fn+0x16/0x20 [25338.606443] process_one_work+0x1a7/0x360 [25338.610456] ? create_worker+0x1a0/0x1a0 [25338.614381] worker_thread+0x1cf/0x390 [25338.618132] ? create_worker+0x1a0/0x1a0 [25338.622051] kthread+0x116/0x130 [25338.625283] ? kthread_flush_work_fn+0x10/0x10 [25338.629731] ret_from_fork+0x1f/0x40 [25338.633395] virtio_blk: probe of virtio418 failed with error -16
The log :
"genirq: Flags mismatch irq 0. 00000080 (virtio418) vs. 00015a00 (timer)" was print because of the irq 0 is used by timer exclusive,and when vp_find_vqs call vp_find_vqs_msix and return false twice for whatever reason,then it will call vp_find_vqs_intx for the last try. Because vp_dev->pci_dev->irq is zero,so it will be request irq 0 with flag IRQF_SHARED,we will get a backtrace like above.
according to PCI spec , Devices (or device functions)
that do not use an interrupt pin must put a 0 in this register. So if vp_dev->pci_dev->pin is zero, maybe we should not request legacy interrupt.
---
v2:
- Decide whether to request an intx interrupt by pin instead of irq
- suggested by mst
v1:https://lore.kernel.org/virtualization/[email protected]/T/#u
drivers/virtio/virtio_pci_common.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/virtio/virtio_pci_common.c +3 -0
@@ -362,6 +362,9 @@ static int vp_find_vqs_intx(struct virtio_device *vdev, unsigned int nvqs,struct virtio_pci_device *vp_dev =to_vp_device (vdev);int i, err, queue_idx =0 ; +if (vp_dev->pci_dev->pin ==0 ) +return -EINVAL ; + vp_dev->vqs =kcalloc (nvqs,sizeof (*vp_dev->vqs),GFP_KERNEL );if (!vp_dev->vqs)return -ENOMEM ;
Signature · 1 line
2.17.1
Michael S. Tsirkin
maintainerThanks! More minor issues to address
Quoted 47 lines · Angus Chen
The background is that we use dpu in cloud computing,the arch is x86,80 cores.We will have a lots of virtio devices,like 512 or more. When we probe about 200
virtio_blkdevices,it will fail and the stack is print as follows:[25338.485128] virtio-pci 0000:b3:00.0: virtio_pci: leaving for legacy driver [25338.496174] genirq: Flags mismatch irq 0. 00000080 (virtio418) vs. 00015a00 (timer) [25338.503822] CPU: 20 PID: 5431 Comm: kworker/20:0 Kdump: loaded Tainted: G OE --------- - - 4.18.0-305.30.1.el8.x86_64 [25338.516403] Hardware name: Inspur NF5280M5/YZMB-00882-10E, BIOS 4.1.21 08/25/2021 [25338.523881] Workqueue: events work_for_cpu_fn [25338.528235] Call Trace: [25338.530687] dump_stack+0x5c/0x80 [25338.534000] __setup_irq.cold.53+0x7c/0xd3 [25338.538098] request_threaded_irq+0xf5/0x160 [25338.542371] vp_find_vqs+0xc7/0x190 [25338.545866] init_vq+0x17c/0x2e0 [virtio_blk] [25338.550223] ? ncpus_cmp_func+0x10/0x10 [25338.554061] virtblk_probe+0xe6/0x8a0 [virtio_blk] [25338.558846] virtio_dev_probe+0x158/0x1f0 [25338.562861] really_probe+0x255/0x4a0 [25338.566524] ? __driver_attach_async_helper+0x90/0x90 [25338.571567] driver_probe_device+0x49/0xc0 [25338.575660] bus_for_each_drv+0x79/0xc0 [25338.579499] __device_attach+0xdc/0x160 [25338.583337] bus_probe_device+0x9d/0xb0 [25338.587167] device_add+0x418/0x780 [25338.590654] register_virtio_device+0x9e/0xe0 [25338.595011] virtio_pci_probe+0xb3/0x140 [25338.598941] local_pci_probe+0x41/0x90 [25338.602689] work_for_cpu_fn+0x16/0x20 [25338.606443] process_one_work+0x1a7/0x360 [25338.610456] ? create_worker+0x1a0/0x1a0 [25338.614381] worker_thread+0x1cf/0x390 [25338.618132] ? create_worker+0x1a0/0x1a0 [25338.622051] kthread+0x116/0x130 [25338.625283] ? kthread_flush_work_fn+0x10/0x10 [25338.629731] ret_from_fork+0x1f/0x40 [25338.633395] virtio_blk: probe of virtio418 failed with error -16The log :
"genirq: Flags mismatch irq 0. 00000080 (virtio418) vs.00015a00(timer)" was print because of the irq 0 is used by timer exclusive,and whenvp_find_vqscallvp_find_vqs_msixand return false twice for whatever reason,then it will callvp_find_vqs_intxfor the last try. Becausevp_dev->pci_dev->irqis zero,so it will be request irq 0 with flag IRQF_SHARED,we will get a backtrace like above.
Quoted 2 lines
according to PCI spec , Devices (or device functions) that do not use an interrupt pin must put a 0 in this register.
Pls add quotes and add "Interrupt Pin:" to make it clear in which register.
Quoted 2 lines
So if
vp_dev->pci_dev->pinis zero, maybe we should not request legacy interrupt.
and drop "maybe" here pls. I guess it sounds impolite to you but as the patch author you get to make the tough decisions :)
Quoted 18 lines
Signed-off-by Angus Chen <[email protected]>Suggested-by Michael S. Tsirkin <[email protected]>---
v2:
- Decide whether to request an intx interrupt by pin instead of irq
- suggested by mstv1:https://lore.kernel.org/virtualization/[email protected]/T/#u
drivers/virtio/virtio_pci_common.c | 3 +++ 1 file changed, 3 insertions(+)drivers/virtio/virtio_pci_common.c +0
-0
drivers/virtio/virtio_pci_common.c static int vp_find_vqs_intx(struct virtio_device *vdev, unsigned int nvqs, · line 367
Quoted 6 lines
drivers/virtio/virtio_pci_common.c +3
-0@@ -362,6 +362,9 @@ static int vp_find_vqs_intx(struct virtio_device *vdev, unsigned int nvqs,struct virtio_pci_device *vp_dev =to_vp_device (vdev);int i, err, queue_idx =0 ; +if (vp_dev->pci_dev->pin ==0 ) +return -EINVAL ; +
Pls use !pin for brevity.
drivers/virtio/virtio_pci_common.c static int vp_find_vqs_intx(struct virtio_device *vdev, unsigned int nvqs, · line 370
Quoted 3 lines
drivers/virtio/virtio_pci_common.c +0
-0vp_dev->vqs =kcalloc (nvqs,sizeof (*vp_dev->vqs),GFP_KERNEL );if (!vp_dev->vqs)return -ENOMEM ;
So, this is mostly ok. The only issue is this:
int vp_find_vqs(struct virtio_device *vdev, unsigned int nvqs,
struct virtqueue *vqs[], vq_callback_t *callbacks[],
const char * const names[], const bool *ctx,
struct irq_affinity *desc)
{
int err;
/* Try MSI-X with one vector per queue. */
err = vp_find_vqs_msix(vdev, nvqs, vqs, callbacks, names, true, ctx, desc);
if (!err)
return 0;
/* Fallback: MSI-X with one vector for config, one shared for queues. */
err = vp_find_vqs_msix(vdev, nvqs, vqs, callbacks, names, false, ctx, desc);
if (!err)
return 0;
/* Finally fall back to regular interrupts. */
return vp_find_vqs_intx(vdev, nvqs, vqs, callbacks, names, ctx);
}So the real source of failure to use msix, will be overwritten in err by EINVAL.
How about moving the "if" to vp_find_vqs?
E.g.
/* Is there an interrupt pin? If not give up. */ if (!vdev->pci_dev->pin) return err;
Quoted 2 lines
Signature · 1 line
2.17.1
Quoted 96 lines
-----Original Message-----
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, September 28, 2022 1:59 PM
To: Angus Chen <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2]virtio_pci: avoid to request intx irq if pin is zeroThanks! More minor issues to address
Quoted 7 lines · Angus Chen
The background is that we use dpu in cloud computing,the arch is x86,80 cores.We will have a lots of virtio devices,like 512 or more. When we probe about 200
virtio_blkdevices,it will fail and the stack is print as follows:[25338.485128] virtio-pci 0000:b3:00.0: virtio_pci: leaving for legacy driver [25338.496174] genirq: Flags mismatch irq 0. 00000080 (virtio418) vs.
00015a00(timer)Quoted 1 line
[25338.503822] CPU: 20 PID: 5431 Comm: kworker/20:0 Kdump: loadedTainted: G OE --------- - - 4.18.0-305.30.1.el8.x86_64Quoted 1 line
[25338.516403] Hardware name: Inspur NF5280M5/YZMB-00882-10E, BIOS4.1.21 08/25/2021
Quoted 38 lines
[25338.523881] Workqueue: events work_for_cpu_fn [25338.528235] Call Trace: [25338.530687] dump_stack+0x5c/0x80 [25338.534000] __setup_irq.cold.53+0x7c/0xd3 [25338.538098] request_threaded_irq+0xf5/0x160 [25338.542371] vp_find_vqs+0xc7/0x190 [25338.545866] init_vq+0x17c/0x2e0 [virtio_blk] [25338.550223] ? ncpus_cmp_func+0x10/0x10 [25338.554061] virtblk_probe+0xe6/0x8a0 [virtio_blk] [25338.558846] virtio_dev_probe+0x158/0x1f0 [25338.562861] really_probe+0x255/0x4a0 [25338.566524] ? __driver_attach_async_helper+0x90/0x90 [25338.571567] driver_probe_device+0x49/0xc0 [25338.575660] bus_for_each_drv+0x79/0xc0 [25338.579499] __device_attach+0xdc/0x160 [25338.583337] bus_probe_device+0x9d/0xb0 [25338.587167] device_add+0x418/0x780 [25338.590654] register_virtio_device+0x9e/0xe0 [25338.595011] virtio_pci_probe+0xb3/0x140 [25338.598941] local_pci_probe+0x41/0x90 [25338.602689] work_for_cpu_fn+0x16/0x20 [25338.606443] process_one_work+0x1a7/0x360 [25338.610456] ? create_worker+0x1a0/0x1a0 [25338.614381] worker_thread+0x1cf/0x390 [25338.618132] ? create_worker+0x1a0/0x1a0 [25338.622051] kthread+0x116/0x130 [25338.625283] ? kthread_flush_work_fn+0x10/0x10 [25338.629731] ret_from_fork+0x1f/0x40 [25338.633395] virtio_blk: probe of virtio418 failed with error -16The log :
"genirq: Flags mismatch irq 0. 00000080 (virtio418) vs.00015a00(timer)" was print because of the irq 0 is used by timer exclusive,and whenvp_find_vqscallvp_find_vqs_msixand return false twice for whatever reason,then it will callvp_find_vqs_intxfor the last try. Becausevp_dev->pci_dev->irqis zero,so it will be request irq 0 with flag IRQF_SHARED,we will get a backtrace like above.Quoted 2 lines
according to PCI spec , Devices (or device functions) that do not use an interrupt pin must put a 0 in this register.
Pls add quotes and add "Interrupt Pin:" to make it clear in which register.
Quoted 2 lines
So if
vp_dev->pci_dev->pinis zero, maybe we should not request legacy interrupt.and drop "maybe" here pls. I guess it sounds impolite to you but as the patch author you get to make the tough decisions :)
Quoted 9 lines
Signed-off-by Angus Chen <[email protected]>Suggested-by Michael S. Tsirkin <[email protected]>---
v2:
- Decide whether to request an intx interrupt by pin instead of irq
- suggested by mstv1:https://lore.kernel.org/virtualization/20220928000228-mutt-send-email-mst @kernel.org/T/#u
Review
Quoted 5 lines
drivers/virtio/virtio_pci_common.c | 3 +++ 1 file changed, 3 insertions(+)(quoted diff) +0
-0
b/drivers/virtio/virtio_pci_common.cdrivers/virtio/virtio_pci_common.c static int vp_find_vqs_intx(struct virtio_device *vdev,
Quoted 4 lines
index
ad258a9d3b9f..81225e503e69100644drivers/virtio/virtio_pci_common.c +0
-0@@ -362,6 +362,9 @@ static int vp_find_vqs_intx(struct virtio_device *vdev,unsigned int nvqs,
Quoted 8 lines
drivers/virtio/virtio_pci_common.c static int vp_find_vqs_intx(struct virtio_device *vdev, unsigned int nvqs, · line 367
Quoted 6 lines
drivers/virtio/virtio_pci_common.c +3
-0struct virtio_pci_device *vp_dev =to_vp_device (vdev);int i, err, queue_idx =0 ; +if (vp_dev->pci_dev->pin ==0 ) +return -EINVAL ; +Pls use !pin for brevity.
Yes,that looks better.
Quoted 32 lines
drivers/virtio/virtio_pci_common.c static int vp_find_vqs_intx(struct virtio_device *vdev, unsigned int nvqs, · line 370
Quoted 4 lines
drivers/virtio/virtio_pci_common.c +0
-0vp_dev->vqs =kcalloc (nvqs,sizeof (*vp_dev->vqs),GFP_KERNEL );if (!vp_dev->vqs)return -ENOMEM ;So, this is mostly ok. The only issue is this:
int vp_find_vqs(struct
virtio_device*vdev, unsigned int nvqs,struct virtqueue *vqs[], vq_callback_t *callbacks[], const char * const names[], const bool *ctx, struct irq_affinity *desc) { int err; /* Try MSI-X with one vector per queue. */ err = vp_find_vqs_msix(vdev, nvqs, vqs, callbacks, names, true, ctx, desc); if (!err) return 0; /* Fallback: MSI-X with one vector for config, one shared for queues. */ err = vp_find_vqs_msix(vdev, nvqs, vqs, callbacks, names, false, ctx, desc); if (!err) return 0; /* Finally fall back to regular interrupts. */ return vp_find_vqs_intx(vdev, nvqs, vqs, callbacks, names, ctx); }
Quoted 8 lines
So the real source of failure to use msix, will be overwritten in err by EINVAL.
How about moving the "if" to
vp_find_vqs?
E.g./* Is there an interrupt pin? If not give up. */ if (!vdev->pci_dev->pin) return err;
OK. vp_find_vqs_intx is staic and it only be called by vp_find_vqs, and it will avoids a single press into the stack . I will send this in another version.
Quoted 3 lines
Quoted 3 lines
--
2.17.1