Skip to contentSkip to conversation

Patch "vfio/pci: Prepare for dynamic interrupt context storage" has been added to the 6.1-stable tree

DISCUSSION Alex Williamson 2 participants 2 messages Mar 29, 2024 – Mar 30, 2024 1 message not in the archive Stable branch

lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive
Quoted 50 lines · On Wed, 27 Mar 2024 07:41:33 -0400 Sasha Levin <[email protected]> wrote:

This is a note to let you know that I've just added the patch titled

vfio/pci: Prepare for dynamic interrupt context storage

to the 6.1-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
vfio-pci-prepare-for-dynamic-interrupt-context-stora.patch
and it can be found in the queue-6.1 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

commit bca808da62c6a87ef168554caa318c2801d19b70

Author: Reinette Chatre <[email protected]>
Date:   Thu May 11 08:44:30 2023 -0700

vfio/pci: Prepare for dynamic interrupt context storage

[ Upstream commit d977e0f7663961368f6442589e52d27484c2f5c2 ]

Interrupt context storage is statically allocated at the time interrupts are allocated. Following allocation, the interrupt context is managed by directly accessing the elements of the array using the vector as index.

It is possible to allocate additional MSI-X vectors after MSI-X has been enabled. Dynamic storage of interrupt context is needed to support adding new MSI-X vectors after initial allocation.

Replace direct access of array elements with pointers to the array elements. Doing so reduces impact of moving to a new data structure. Move interactions with the array to helpers to mostly contain changes needed to transition to a dynamic data structure.

No functional change intended.

Stable-dep-of: fe9a7082684e ("vfio/pci: Disable auto-enable of exclusive INTx IRQ")

...

Quoted 17 lines
(quoted diff) +4 -3
@@ -171,15 +225,24 @@ static irqreturn_t vfio_intx_handler(int irq, void *dev_id)
 
 static int vfio_intx_enable(struct vfio_pci_core_device *vdev)
 {
+	struct vfio_pci_irq_ctx *ctx;
+	int ret;
+
 	if (!is_irq_none(vdev))
 		return -EINVAL;
 
 	if (!vdev->pdev->irq)
 		return -ENODEV;
 
-	vdev->ctx = kzalloc(sizeof(struct vfio_pci_irq_ctx), GFP_KERNEL_ACCOUNT);
-	if (!vdev->ctx)
-		return -ENOMEM;
+	ret = vfio_irq_ctx_alloc_num(vdev, 1);

Review static irqreturn_t vfio_intx_handler(int irq, void *dev_id) · line 247

Quoted 10 lines
(quoted diff) +8 -0
+	if (ret)
+		return ret;
+
+	ctx = vfio_irq_ctx_get(vdev, 0);
+	if (!ctx) {
+		vfio_irq_ctx_free_all(vdev);
+		return -EINVAL;
+	}
 
 	vdev->num_ctx = 1;

This is broken on it's own, vfio_irq_ctx_get() depends on a valid num_ctx, therefore this function always returns -EINVAL. This was resolved upstream by b156e48fffa9 ("vfio/pci: Use xarray for interrupt context storage") which was from the same series, so this issue was never apparent upstream. Suggest dropping this and fe9a7082684e ("vfio/pci: Disable auto-enable of exclusive INTx IRQ") for now and we'll try to rework the latter to remove the dependency. Thanks,

Alex

maintainer
#2 lore raw
Quoted 79 lines · Alex Williamson
Quoted 50 lines · On Wed, 27 Mar 2024 07:41:33 -0400 Sasha Levin <[email protected]> wrote:

This is a note to let you know that I've just added the patch titled

vfio/pci: Prepare for dynamic interrupt context storage

to the 6.1-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
vfio-pci-prepare-for-dynamic-interrupt-context-stora.patch
and it can be found in the queue-6.1 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

commit bca808da62c6a87ef168554caa318c2801d19b70

Author: Reinette Chatre <[email protected]>
Date:   Thu May 11 08:44:30 2023 -0700

vfio/pci: Prepare for dynamic interrupt context storage

[ Upstream commit d977e0f7663961368f6442589e52d27484c2f5c2 ]

Interrupt context storage is statically allocated at the time interrupts are allocated. Following allocation, the interrupt context is managed by directly accessing the elements of the array using the vector as index.

It is possible to allocate additional MSI-X vectors after MSI-X has been enabled. Dynamic storage of interrupt context is needed to support adding new MSI-X vectors after initial allocation.

Replace direct access of array elements with pointers to the array elements. Doing so reduces impact of moving to a new data structure. Move interactions with the array to helpers to mostly contain changes needed to transition to a dynamic data structure.

No functional change intended.

Stable-dep-of: fe9a7082684e ("vfio/pci: Disable auto-enable of exclusive INTx IRQ")

...

Quoted 26 lines
(quoted diff) +12 -3
@@ -171,15 +225,24 @@ static irqreturn_t vfio_intx_handler(int irq, void *dev_id)
 
 static int vfio_intx_enable(struct vfio_pci_core_device *vdev)
 {
+	struct vfio_pci_irq_ctx *ctx;
+	int ret;
+
 	if (!is_irq_none(vdev))
 		return -EINVAL;
 
 	if (!vdev->pdev->irq)
 		return -ENODEV;
 
-	vdev->ctx = kzalloc(sizeof(struct vfio_pci_irq_ctx), GFP_KERNEL_ACCOUNT);
-	if (!vdev->ctx)
-		return -ENOMEM;
+	ret = vfio_irq_ctx_alloc_num(vdev, 1);
+	if (ret)
+		return ret;
+
+	ctx = vfio_irq_ctx_get(vdev, 0);
+	if (!ctx) {
+		vfio_irq_ctx_free_all(vdev);
+		return -EINVAL;
+	}
 
Quoted 9 lines

Review static irqreturn_t vfio_intx_handler(int irq, void *dev_id) · line 247

Quoted 1 line
(quoted diff) +0 -0
 	vdev->num_ctx = 1;

This is broken on it's own, vfio_irq_ctx_get() depends on a valid num_ctx, therefore this function always returns -EINVAL. This was resolved upstream by b156e48fffa9 ("vfio/pci: Use xarray for interrupt context storage") which was from the same series, so this issue was never apparent upstream. Suggest dropping this and fe9a7082684e ("vfio/pci: Disable auto-enable of exclusive INTx IRQ") for now and we'll try to rework the latter to remove the dependency. Thanks,

Ok, I'll go drop both of these and take the series you just sent, thanks.

greg k-h