PCI: vmd: Fix spinlock usage on config access for RT kernel
Subsystems (4)
PATCH v3 1/1 PCI: vmd: Fix spinlock usage on config access for RT kernel
PCI config access is locked with pci_lock which is raw_spinlock. Convert cfg_lock to raw_spinlock so that the lock usage is consistent for RT kernel.
Reported as following:
[ 18.756807] BUG: sleeping function called from invalid context at kernel/locking/spinlock_rt.c:48 [ 18.756810] in_atomic(): 1, irqs_disabled(): 1, non_block: 0, pid: 1617, name: nodedev-init [ 18.756810] preempt_count: 1, expected: 0 [ 18.756811] RCU nest depth: 0, expected: 0 [ 18.756811] INFO: lockdep is turned off. [ 18.756812] irq event stamp: 0 [ 18.756812] hardirqs last enabled at (0): [<0000000000000000>] 0x0 [ 18.756815] hardirqs last disabled at (0): [<ffffffff864f1fe2>] copy_process+0xa62/0x2d90 [ 18.756819] softirqs last enabled at (0): [<ffffffff864f1fe2>] copy_process+0xa62/0x2d90 [ 18.756820] softirqs last disabled at (0): [<0000000000000000>] 0x0 [ 18.756822] CPU: 3 UID: 0 PID: 1617 Comm: nodedev-init Tainted: G W 6.12.1 #11 [ 18.756823] Tainted: [W]=WARN [ 18.756824] Hardware name: Dell Inc. Vostro 3710/0K1D6X, BIOS 1.14.0 06/09/2023 [ 18.756825] Call Trace: [ 18.756826] <TASK> [ 18.756827] dump_stack_lvl+0x9b/0xf0 [ 18.756830] dump_stack+0x10/0x20 [ 18.756831] __might_resched+0x158/0x230 [ 18.756833] rt_spin_lock+0x4e/0x130 [ 18.756837] ? vmd_pci_read+0x8d/0x100 [vmd] [ 18.756839] vmd_pci_read+0x8d/0x100 [vmd] [ 18.756840] pci_user_read_config_byte+0x6f/0xe0 [ 18.756843] pci_read_config+0xfe/0x290 [ 18.756845] sysfs_kf_bin_read+0x68/0x90 [ 18.756847] kernfs_fop_read_iter+0xd7/0x200 [ 18.756850] vfs_read+0x26d/0x360 [ 18.756853] ksys_read+0x70/0xf0 [ 18.756855] __x64_sys_read+0x1a/0x20 [ 18.756857] x64_sys_call+0x1715/0x20d0 [ 18.756859] do_syscall_64+0x8f/0x170 [ 18.756861] ? syscall_exit_to_user_mode+0xcd/0x2c0 [ 18.756863] ? do_syscall_64+0x9b/0x170 [ 18.756865] entry_SYSCALL_64_after_hwframe+0x76/0x7e
---
Hi!
This is same as the first version of the patch as discussed over v2.
v1:
https://lore.kernel.org/lkml/[email protected]/T/
Changes since v2:
https://lore.kernel.org/lkml/[email protected]/T/
- In case if CONFIG_PCI_LOCKLESS_CONFIG is set, vmd_pci_read/write() still neeed cfg_lock for their serialization. So instead of removing it, convert it to raw spinlock.
--- drivers/pci/controller/vmd.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/pci/controller/vmd.c +6 -6
@@ -125,7 +125,7 @@ struct vmd_irq_list {struct vmd_dev {struct pci_dev *dev; -spinlock_t cfg_lock; +raw_spinlock_t cfg_lock;void __iomem *cfgbar;int msix_count;
@@ -391,7 +391,7 @@ static int vmd_pci_read(struct pci_bus *bus, unsigned int devfn, int reg,if (!addr)return -EFAULT ; -spin_lock_irqsave (&vmd->cfg_lock, flags); +raw_spin_lock_irqsave (&vmd->cfg_lock, flags);switch (len) {case 1 : *value =readb (addr);
@@ -406,7 +406,7 @@ static int vmd_pci_read(struct pci_bus *bus, unsigned int devfn, int reg, ret = -EINVAL ;break ; } -spin_unlock_irqrestore (&vmd->cfg_lock, flags); +raw_spin_unlock_irqrestore (&vmd->cfg_lock, flags);return ret; }
@@ -426,7 +426,7 @@ static int vmd_pci_write(struct pci_bus *bus, unsigned int devfn, int reg,if (!addr)return -EFAULT ; -spin_lock_irqsave (&vmd->cfg_lock, flags); +raw_spin_lock_irqsave (&vmd->cfg_lock, flags);switch (len) {case 1 :writeb (value, addr);
@@ -444,7 +444,7 @@ static int vmd_pci_write(struct pci_bus *bus, unsigned int devfn, int reg, ret = -EINVAL ;break ; } -spin_unlock_irqrestore (&vmd->cfg_lock, flags); +raw_spin_unlock_irqrestore (&vmd->cfg_lock, flags);return ret; }
@@ -1009,7 +1009,7 @@ static int vmd_probe(struct pci_dev *dev, const struct pci_device_id *id)if (features &VMD_FEAT_OFFSET_FIRST_VECTOR ) vmd->first_vec =1 ; -spin_lock_init (&vmd->cfg_lock); +raw_spin_lock_init (&vmd->cfg_lock);pci_set_drvdata (dev, vmd); err =vmd_enable_domain (vmd, features);if (err)
Signature · 1 line
2.34.1
Quoted 3 lines · Ryo Takakura
PCI config access is locked with
pci_lockwhich israw_spinlock. Convertcfg_locktoraw_spinlockso that the lock usage is consistent for RT kernel.
Any movement here?
Best,
Luis
Quoted 118 lines
Reported as following:
[ 18.756807] BUG: sleeping function called from invalid context at kernel/locking/spinlock_rt.c:48 [ 18.756810] in_atomic(): 1, irqs_disabled(): 1, non_block: 0, pid: 1617, name: nodedev-init [ 18.756810] preempt_count: 1, expected: 0 [ 18.756811] RCU nest depth: 0, expected: 0 [ 18.756811] INFO: lockdep is turned off. [ 18.756812] irq event stamp: 0 [ 18.756812] hardirqs last enabled at (0): [<0000000000000000>] 0x0 [ 18.756815] hardirqs last disabled at (0): [<ffffffff864f1fe2>] copy_process+0xa62/0x2d90 [ 18.756819] softirqs last enabled at (0): [<ffffffff864f1fe2>] copy_process+0xa62/0x2d90 [ 18.756820] softirqs last disabled at (0): [<0000000000000000>] 0x0 [ 18.756822] CPU: 3 UID: 0 PID: 1617 Comm: nodedev-init Tainted: G W 6.12.1 #11 [ 18.756823] Tainted: [W]=WARN [ 18.756824] Hardware name: Dell Inc. Vostro 3710/0K1D6X, BIOS 1.14.0 06/09/2023 [ 18.756825] Call Trace: [ 18.756826] <TASK> [ 18.756827] dump_stack_lvl+0x9b/0xf0 [ 18.756830] dump_stack+0x10/0x20 [ 18.756831] __might_resched+0x158/0x230 [ 18.756833] rt_spin_lock+0x4e/0x130 [ 18.756837] ? vmd_pci_read+0x8d/0x100 [vmd] [ 18.756839] vmd_pci_read+0x8d/0x100 [vmd] [ 18.756840] pci_user_read_config_byte+0x6f/0xe0 [ 18.756843] pci_read_config+0xfe/0x290 [ 18.756845] sysfs_kf_bin_read+0x68/0x90 [ 18.756847] kernfs_fop_read_iter+0xd7/0x200 [ 18.756850] vfs_read+0x26d/0x360 [ 18.756853] ksys_read+0x70/0xf0 [ 18.756855] __x64_sys_read+0x1a/0x20 [ 18.756857] x64_sys_call+0x1715/0x20d0 [ 18.756859] do_syscall_64+0x8f/0x170 [ 18.756861] ? syscall_exit_to_user_mode+0xcd/0x2c0 [ 18.756863] ? do_syscall_64+0x9b/0x170 [ 18.756865] entry_SYSCALL_64_after_hwframe+0x76/0x7eSigned-off-by Ryo Takakura <[email protected]>---
Hi!
This is same as the first version of the patch as discussed over v2.
v1:
https://lore.kernel.org/lkml/[email protected]/T/Changes since v2:
https://lore.kernel.org/lkml/[email protected]/T/- In case if
CONFIG_PCI_LOCKLESS_CONFIGis set, vmd_pci_read/write() still neeedcfg_lockfor their serialization. So instead of removing it, convert it to raw spinlock.--- drivers/pci/controller/vmd.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)drivers/pci/controller/vmd.c +6
-6@@ -125,7 +125,7 @@ struct vmd_irq_list {struct vmd_dev {struct pci_dev *dev; -spinlock_t cfg_lock; +raw_spinlock_t cfg_lock;void __iomem *cfgbar;int msix_count;@@ -391,7 +391,7 @@ static int vmd_pci_read(struct pci_bus *bus, unsigned int devfn, int reg,if (!addr)return -EFAULT ; -spin_lock_irqsave (&vmd->cfg_lock, flags); +raw_spin_lock_irqsave (&vmd->cfg_lock, flags);switch (len) {case 1 : *value =readb (addr);@@ -406,7 +406,7 @@ static int vmd_pci_read(struct pci_bus *bus, unsigned int devfn, int reg, ret = -EINVAL ;break ; } -spin_unlock_irqrestore (&vmd->cfg_lock, flags); +raw_spin_unlock_irqrestore (&vmd->cfg_lock, flags);return ret; }@@ -426,7 +426,7 @@ static int vmd_pci_write(struct pci_bus *bus, unsigned int devfn, int reg,if (!addr)return -EFAULT ; -spin_lock_irqsave (&vmd->cfg_lock, flags); +raw_spin_lock_irqsave (&vmd->cfg_lock, flags);switch (len) {case 1 :writeb (value, addr);@@ -444,7 +444,7 @@ static int vmd_pci_write(struct pci_bus *bus, unsigned int devfn, int reg, ret = -EINVAL ;break ; } -spin_unlock_irqrestore (&vmd->cfg_lock, flags); +raw_spin_unlock_irqrestore (&vmd->cfg_lock, flags);return ret; }@@ -1009,7 +1009,7 @@ static int vmd_probe(struct pci_dev *dev, const struct pci_device_id *id)if (features &VMD_FEAT_OFFSET_FIRST_VECTOR ) vmd->first_vec =1 ; -spin_lock_init (&vmd->cfg_lock); +raw_spin_lock_init (&vmd->cfg_lock);pci_set_drvdata (dev, vmd); err =vmd_enable_domain (vmd, features);if (err)Signature · 1 line
2.34.1
---end quoted text---
Sebastian Andrzej Siewior
maintainerQuoted 6 lines · Luis Claudio R. Goncalves
Quoted 3 lines · Ryo Takakura
PCI config access is locked with
pci_lockwhich israw_spinlock. Convertcfg_locktoraw_spinlockso that the lock usage is consistent for RT kernel.Any movement here?
Reposted as https://lore.kernel.org/all/[email protected]
Quoted 2 lines
Best,
Luis
Sebastian
Hi Luis and Sebastian,
Thanks for checking in.
Quoted 9 lines · Sebastian Andrzej Siewior
Quoted 6 lines · Luis Claudio R. Goncalves
Quoted 3 lines · Ryo Takakura
PCI config access is locked with
pci_lockwhich israw_spinlock. Convertcfg_locktoraw_spinlockso that the lock usage is consistent for RT kernel.Any movement here?
Reposted as https://lore.kernel.org/all/[email protected]
Thanks for the update!
Sincerely,
Ryo Takakura