Skip to content

Commit b5f687f

Browse files
committed
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: Thomas Gleixner <[email protected]> Tested-by: Michael Kelley <[email protected]> Tested-by: Nishanth Menon <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 125282c commit b5f687f

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

include/linux/msi.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#define LINUX_MSI_H
44

55
#include <linux/cpumask.h>
6+
#include <linux/mutex.h>
67
#include <linux/list.h>
78
#include <asm/msi.h>
89

@@ -145,17 +146,21 @@ struct msi_desc {
145146
* @attrs: Pointer to the sysfs attribute group
146147
* @platform_data: Platform-MSI specific data
147148
* @list: List of MSI descriptors associated to the device
149+
* @mutex: Mutex protecting the MSI list
148150
*/
149151
struct msi_device_data {
150152
unsigned long properties;
151153
const struct attribute_group **attrs;
152154
struct platform_msi_priv_data *platform_data;
153155
struct list_head list;
156+
struct mutex mutex;
154157
};
155158

156159
int msi_setup_device_data(struct device *dev);
157160

158161
unsigned int msi_get_virq(struct device *dev, unsigned int index);
162+
void msi_lock_descs(struct device *dev);
163+
void msi_unlock_descs(struct device *dev);
159164

160165
/* Helpers to hide struct msi_desc implementation details */
161166
#define msi_desc_to_dev(desc) ((desc)->dev)

kernel/irq/msi.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,32 @@ int msi_setup_device_data(struct device *dev)
103103
return -ENOMEM;
104104

105105
INIT_LIST_HEAD(&md->list);
106+
mutex_init(&md->mutex);
106107
dev->msi.data = md;
107108
devres_add(dev, md);
108109
return 0;
109110
}
110111

112+
/**
113+
* msi_lock_descs - Lock the MSI descriptor storage of a device
114+
* @dev: Device to operate on
115+
*/
116+
void msi_lock_descs(struct device *dev)
117+
{
118+
mutex_lock(&dev->msi.data->mutex);
119+
}
120+
EXPORT_SYMBOL_GPL(msi_lock_descs);
121+
122+
/**
123+
* msi_unlock_descs - Unlock the MSI descriptor storage of a device
124+
* @dev: Device to operate on
125+
*/
126+
void msi_unlock_descs(struct device *dev)
127+
{
128+
mutex_unlock(&dev->msi.data->mutex);
129+
}
130+
EXPORT_SYMBOL_GPL(msi_unlock_descs);
131+
111132
/**
112133
* msi_get_virq - Return Linux interrupt number of a MSI interrupt
113134
* @dev: Device to operate on

0 commit comments

Comments
 (0)