mirror of
https://github.com/torvalds/linux.git
synced 2026-05-12 16:18:45 +02:00
struct vfio_cdx_device carries three fields that track whether MSI has been configured: vdev->cdx_irqs (the allocated vector array), vdev-> msi_count (the array length), and vdev->config_msi (a boolean flag). The three are set together when vfio_cdx_msi_enable() succeeds and cleared together by vfio_cdx_msi_disable(). However, the error paths in vfio_cdx_msi_enable() free the cdx_irqs allocation on failure without resetting the pointer, leaving it stale and skewed from the other two fields until the next enable call overwrites it. Clear vdev->cdx_irqs to NULL alongside the kfree() in both error paths so the pointer consistently reflects the configured state. With that invariant restored and access to the MSI state serialized by cdx_irqs_lock, vdev->config_msi is fully redundant with (vdev->cdx_irqs != NULL). Drop the config_msi field and switch all readers to test cdx_irqs directly. Assisted-by: Claude:claude-opus-4-7 Signed-off-by: Alex Williamson <alex.williamson@nvidia.com> Acked-by: Nikhil Agarwal <nikhil.agarwal@amd.com> Link: https://lore.kernel.org/r/20260417202800.88287-4-alex.williamson@nvidia.com Signed-off-by: Alex Williamson <alex@shazbot.org>
65 lines
1.3 KiB
C
65 lines
1.3 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
/*
|
|
* Copyright (C) 2022-2023, Advanced Micro Devices, Inc.
|
|
*/
|
|
|
|
#ifndef VFIO_CDX_PRIVATE_H
|
|
#define VFIO_CDX_PRIVATE_H
|
|
|
|
#include <linux/mutex.h>
|
|
|
|
#define VFIO_CDX_OFFSET_SHIFT 40
|
|
|
|
static inline u64 vfio_cdx_index_to_offset(u32 index)
|
|
{
|
|
return ((u64)(index) << VFIO_CDX_OFFSET_SHIFT);
|
|
}
|
|
|
|
struct vfio_cdx_irq {
|
|
u32 flags;
|
|
u32 count;
|
|
int irq_no;
|
|
struct eventfd_ctx *trigger;
|
|
char *name;
|
|
};
|
|
|
|
struct vfio_cdx_region {
|
|
u32 flags;
|
|
u32 type;
|
|
u64 addr;
|
|
resource_size_t size;
|
|
};
|
|
|
|
struct vfio_cdx_device {
|
|
struct vfio_device vdev;
|
|
struct vfio_cdx_region *regions;
|
|
struct mutex cdx_irqs_lock;
|
|
struct vfio_cdx_irq *cdx_irqs;
|
|
u32 flags;
|
|
#define BME_SUPPORT BIT(0)
|
|
u32 msi_count;
|
|
};
|
|
|
|
#ifdef CONFIG_GENERIC_MSI_IRQ
|
|
int vfio_cdx_set_irqs_ioctl(struct vfio_cdx_device *vdev,
|
|
u32 flags, unsigned int index,
|
|
unsigned int start, unsigned int count,
|
|
void *data);
|
|
|
|
void vfio_cdx_irqs_cleanup(struct vfio_cdx_device *vdev);
|
|
#else
|
|
static int vfio_cdx_set_irqs_ioctl(struct vfio_cdx_device *vdev,
|
|
u32 flags, unsigned int index,
|
|
unsigned int start, unsigned int count,
|
|
void *data)
|
|
{
|
|
return -EINVAL;
|
|
}
|
|
|
|
static void vfio_cdx_irqs_cleanup(struct vfio_cdx_device *vdev)
|
|
{
|
|
}
|
|
#endif
|
|
|
|
#endif /* VFIO_CDX_PRIVATE_H */
|