Commit b5f687f9 authored by Thomas Gleixner's avatar Thomas Gleixner

genirq/msi: Add mutex for MSI list protection

For upcoming runtime extensions of MSI-X interrupts it's required to
protect the MSI descriptor list. Add a mutex to struct msi_device_data and
provide lock/unlock functions.
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Tested-by: default avatarMichael Kelley <mikelley@microsoft.com>
Tested-by: default avatarNishanth Menon <nm@ti.com>
Reviewed-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/20211206210747.708877269@linutronix.de
parent 125282cd
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#define LINUX_MSI_H #define LINUX_MSI_H
#include <linux/cpumask.h> #include <linux/cpumask.h>
#include <linux/mutex.h>
#include <linux/list.h> #include <linux/list.h>
#include <asm/msi.h> #include <asm/msi.h>
...@@ -145,17 +146,21 @@ struct msi_desc { ...@@ -145,17 +146,21 @@ struct msi_desc {
* @attrs: Pointer to the sysfs attribute group * @attrs: Pointer to the sysfs attribute group
* @platform_data: Platform-MSI specific data * @platform_data: Platform-MSI specific data
* @list: List of MSI descriptors associated to the device * @list: List of MSI descriptors associated to the device
* @mutex: Mutex protecting the MSI list
*/ */
struct msi_device_data { struct msi_device_data {
unsigned long properties; unsigned long properties;
const struct attribute_group **attrs; const struct attribute_group **attrs;
struct platform_msi_priv_data *platform_data; struct platform_msi_priv_data *platform_data;
struct list_head list; struct list_head list;
struct mutex mutex;
}; };
int msi_setup_device_data(struct device *dev); int msi_setup_device_data(struct device *dev);
unsigned int msi_get_virq(struct device *dev, unsigned int index); unsigned int msi_get_virq(struct device *dev, unsigned int index);
void msi_lock_descs(struct device *dev);
void msi_unlock_descs(struct device *dev);
/* Helpers to hide struct msi_desc implementation details */ /* Helpers to hide struct msi_desc implementation details */
#define msi_desc_to_dev(desc) ((desc)->dev) #define msi_desc_to_dev(desc) ((desc)->dev)
......
...@@ -103,11 +103,32 @@ int msi_setup_device_data(struct device *dev) ...@@ -103,11 +103,32 @@ int msi_setup_device_data(struct device *dev)
return -ENOMEM; return -ENOMEM;
INIT_LIST_HEAD(&md->list); INIT_LIST_HEAD(&md->list);
mutex_init(&md->mutex);
dev->msi.data = md; dev->msi.data = md;
devres_add(dev, md); devres_add(dev, md);
return 0; return 0;
} }
/**
* msi_lock_descs - Lock the MSI descriptor storage of a device
* @dev: Device to operate on
*/
void msi_lock_descs(struct device *dev)
{
mutex_lock(&dev->msi.data->mutex);
}
EXPORT_SYMBOL_GPL(msi_lock_descs);
/**
* msi_unlock_descs - Unlock the MSI descriptor storage of a device
* @dev: Device to operate on
*/
void msi_unlock_descs(struct device *dev)
{
mutex_unlock(&dev->msi.data->mutex);
}
EXPORT_SYMBOL_GPL(msi_unlock_descs);
/** /**
* msi_get_virq - Return Linux interrupt number of a MSI interrupt * msi_get_virq - Return Linux interrupt number of a MSI interrupt
* @dev: Device to operate on * @dev: Device to operate on
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment