mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-26 19:00:25 +00:00
PCI/MSI: Protect msi_desc::masked for multi-MSI
commit77e89afc25
upstream. Multi-MSI uses a single MSI descriptor and there is a single mask register when the device supports per vector masking. To avoid reading back the mask register the value is cached in the MSI descriptor and updates are done by clearing and setting bits in the cache and writing it to the device. But nothing protects msi_desc::masked and the mask register from being modified concurrently on two different CPUs for two different Linux interrupts which belong to the same multi-MSI descriptor. Add a lock to struct device and protect any operation on the mask and the mask register with it. This makes the update of msi_desc::masked unconditional, but there is no place which requires a modification of the hardware register without updating the masked cache. msi_mask_irq() is now an empty wrapper which will be cleaned up in follow up changes. The problem goes way back to the initial support of multi-MSI, but picking the commit which introduced the mask cache is a valid cut off point (2.6.30). Fixes:f2440d9acb
("PCI MSI: Refactor interrupt masking code") Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Tested-by: Marc Zyngier <maz@kernel.org> Reviewed-by: Marc Zyngier <maz@kernel.org> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20210729222542.726833414@linutronix.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
724d0a9850
commit
312730cd15
4 changed files with 13 additions and 10 deletions
|
@ -2452,6 +2452,7 @@ void device_initialize(struct device *dev)
|
||||||
device_pm_init(dev);
|
device_pm_init(dev);
|
||||||
set_dev_node(dev, -1);
|
set_dev_node(dev, -1);
|
||||||
#ifdef CONFIG_GENERIC_MSI_IRQ
|
#ifdef CONFIG_GENERIC_MSI_IRQ
|
||||||
|
raw_spin_lock_init(&dev->msi_lock);
|
||||||
INIT_LIST_HEAD(&dev->msi_list);
|
INIT_LIST_HEAD(&dev->msi_list);
|
||||||
#endif
|
#endif
|
||||||
INIT_LIST_HEAD(&dev->links.consumers);
|
INIT_LIST_HEAD(&dev->links.consumers);
|
||||||
|
|
|
@ -171,24 +171,25 @@ static inline __attribute_const__ u32 msi_mask(unsigned x)
|
||||||
* reliably as devices without an INTx disable bit will then generate a
|
* reliably as devices without an INTx disable bit will then generate a
|
||||||
* level IRQ which will never be cleared.
|
* level IRQ which will never be cleared.
|
||||||
*/
|
*/
|
||||||
u32 __pci_msi_desc_mask_irq(struct msi_desc *desc, u32 mask, u32 flag)
|
void __pci_msi_desc_mask_irq(struct msi_desc *desc, u32 mask, u32 flag)
|
||||||
{
|
{
|
||||||
u32 mask_bits = desc->masked;
|
raw_spinlock_t *lock = &desc->dev->msi_lock;
|
||||||
|
unsigned long flags;
|
||||||
|
|
||||||
if (pci_msi_ignore_mask || !desc->msi_attrib.maskbit)
|
if (pci_msi_ignore_mask || !desc->msi_attrib.maskbit)
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
mask_bits &= ~mask;
|
raw_spin_lock_irqsave(lock, flags);
|
||||||
mask_bits |= flag;
|
desc->masked &= ~mask;
|
||||||
|
desc->masked |= flag;
|
||||||
pci_write_config_dword(msi_desc_to_pci_dev(desc), desc->mask_pos,
|
pci_write_config_dword(msi_desc_to_pci_dev(desc), desc->mask_pos,
|
||||||
mask_bits);
|
desc->masked);
|
||||||
|
raw_spin_unlock_irqrestore(lock, flags);
|
||||||
return mask_bits;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void msi_mask_irq(struct msi_desc *desc, u32 mask, u32 flag)
|
static void msi_mask_irq(struct msi_desc *desc, u32 mask, u32 flag)
|
||||||
{
|
{
|
||||||
desc->masked = __pci_msi_desc_mask_irq(desc, mask, flag);
|
__pci_msi_desc_mask_irq(desc, mask, flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __iomem *pci_msix_desc_addr(struct msi_desc *desc)
|
static void __iomem *pci_msix_desc_addr(struct msi_desc *desc)
|
||||||
|
|
|
@ -497,6 +497,7 @@ struct device {
|
||||||
struct dev_pin_info *pins;
|
struct dev_pin_info *pins;
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_GENERIC_MSI_IRQ
|
#ifdef CONFIG_GENERIC_MSI_IRQ
|
||||||
|
raw_spinlock_t msi_lock;
|
||||||
struct list_head msi_list;
|
struct list_head msi_list;
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_DMA_OPS
|
#ifdef CONFIG_DMA_OPS
|
||||||
|
|
|
@ -194,7 +194,7 @@ void __pci_read_msi_msg(struct msi_desc *entry, struct msi_msg *msg);
|
||||||
void __pci_write_msi_msg(struct msi_desc *entry, struct msi_msg *msg);
|
void __pci_write_msi_msg(struct msi_desc *entry, struct msi_msg *msg);
|
||||||
|
|
||||||
u32 __pci_msix_desc_mask_irq(struct msi_desc *desc, u32 flag);
|
u32 __pci_msix_desc_mask_irq(struct msi_desc *desc, u32 flag);
|
||||||
u32 __pci_msi_desc_mask_irq(struct msi_desc *desc, u32 mask, u32 flag);
|
void __pci_msi_desc_mask_irq(struct msi_desc *desc, u32 mask, u32 flag);
|
||||||
void pci_msi_mask_irq(struct irq_data *data);
|
void pci_msi_mask_irq(struct irq_data *data);
|
||||||
void pci_msi_unmask_irq(struct irq_data *data);
|
void pci_msi_unmask_irq(struct irq_data *data);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue