Skip to contentSkip to conversation

x86/PCI: add spinlock held check to 'pcibios_fwaddrmap_lookup()'

PATCH Applied Myron Stowe 4 participants 7 messages Mar 2, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/PCI: add spinlock held check to 'pcibios_fwaddrmap_lookup()'

'pcibios_fwaddrmap_lookup()' is used to maintain FW-assigned BIOS BAR values for reinstatement when normal resource assignment attempts fail and must be called with the 'pcibios_fwaddrmap_lock' spinlock held.

This patch adds a WARN_ON notification if the spinlock is not currently held by the caller.

---

 arch/x86/pci/i386.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
arch/x86/pci/i386.c +2 -0
index 33e6a0b..831971e 100644
@@ -57,6 +57,8 @@ static struct pcibios_fwaddrmap *pcibios_fwaddrmap_lookup(struct pci_dev *dev)
 {
 	struct pcibios_fwaddrmap *map;
 
+	WARN_ON(!spin_is_locked(&pcibios_fwaddrmap_lock));
+
 	list_for_each_entry(map, &pcibios_fwaddrmappings, list)
 		if (map->dev == dev)
 			return map;
Applied
#1 lore raw
Quoted 21 lines · On Fri, 02 Mar 2012 12:45:01 -0700 Myron Stowe <[email protected]> wrote:

'pcibios_fwaddrmap_lookup()' is used to maintain FW-assigned BIOS BAR values for reinstatement when normal resource assignment attempts fail and must be called with the 'pcibios_fwaddrmap_lock' spinlock held.

This patch adds a WARN_ON notification if the spinlock is not currently held by the caller.

---

 arch/x86/pci/i386.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
arch/x86/pci/i386.c +0 -0
index 33e6a0b..831971e 100644

arch/x86/pci/i386.c static struct pcibios_fwaddrmap *pcibios_fwaddrmap_lookup(struct pci_dev *dev) · line 64

Quoted 8 lines
arch/x86/pci/i386.c +2 -0
@@ -57,6 +57,8 @@ static struct pcibios_fwaddrmap *pcibios_fwaddrmap_lookup(struct pci_dev *dev)
 {
 	struct pcibios_fwaddrmap *map;
 
+	WARN_ON(!spin_is_locked(&pcibios_fwaddrmap_lock));
+
 	list_for_each_entry(map, &pcibios_fwaddrmappings, list)
 		if (map->dev == dev)
 			return map;

Applied, thanks.

Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
#2 lore raw
In reply to Myron Stowe
Quoted 19 lines · Myron Stowe

'pcibios_fwaddrmap_lookup()' is used to maintain FW-assigned BIOS BAR values for reinstatement when normal resource assignment attempts fail and must be called with the 'pcibios_fwaddrmap_lock' spinlock held.

This patch adds a WARN_ON notification if the spinlock is not currently held by the caller.

---

 arch/x86/pci/i386.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
arch/x86/pci/i386.c +0 -0
index 33e6a0b..831971e 100644

arch/x86/pci/i386.c static struct pcibios_fwaddrmap *pcibios_fwaddrmap_lookup(struct pci_dev *dev) · line 61

Quoted 5 lines
arch/x86/pci/i386.c +2 -0
@@ -57,6 +57,8 @@ static struct pcibios_fwaddrmap *pcibios_fwaddrmap_lookup(struct pci_dev *dev)
 {
 	struct pcibios_fwaddrmap *map;
 
+	WARN_ON(!spin_is_locked(&pcibios_fwaddrmap_lock));
+

What is this going to help with? How can someone then recover from this issue? Just adding a warning message isn't going to fix any problems here, why not fix the root cause?

thanks,

greg k-h

#3 lore raw
Quoted 23 lines · Greg KH
Quoted 22 lines · Myron Stowe

'pcibios_fwaddrmap_lookup()' is used to maintain FW-assigned BIOS BAR values for reinstatement when normal resource assignment attempts fail and must be called with the 'pcibios_fwaddrmap_lock' spinlock held.

This patch adds a WARN_ON notification if the spinlock is not currently held by the caller.

---

 arch/x86/pci/i386.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
arch/x86/pci/i386.c +0 -0
index 33e6a0b..831971e 100644
@@ -57,6 +57,8 @@ static struct pcibios_fwaddrmap *pcibios_fwaddrmap_lookup(struct pci_dev *dev)
 {
 	struct pcibios_fwaddrmap *map;
 
Quoted 6 lines

arch/x86/pci/i386.c static struct pcibios_fwaddrmap *pcibios_fwaddrmap_lookup(struct pci_dev *dev) · line 61

Quoted 2 lines
arch/x86/pci/i386.c +2 -0
+	WARN_ON(!spin_is_locked(&pcibios_fwaddrmap_lock));
+

What is this going to help with? How can someone then recover from this issue? Just adding a warning message isn't going to fix any problems here, why not fix the root cause?

Greg:

We have not seen any issues. Jesse just asked me to consider adding such as a sanity check (I believe he said something to the effect: "I had to read the code a couple of times to assure myself that the lock was held" - but I should let Jesse comment himself).

Myron

Quoted 4 lines

thanks,

greg k-h

#4 lore raw
In reply to Greg KH
Quoted 23 lines · On Fri, 2 Mar 2012 12:00:27 -0800 Greg KH <[email protected]> wrote:
Quoted 22 lines · Myron Stowe

'pcibios_fwaddrmap_lookup()' is used to maintain FW-assigned BIOS BAR values for reinstatement when normal resource assignment attempts fail and must be called with the 'pcibios_fwaddrmap_lock' spinlock held.

This patch adds a WARN_ON notification if the spinlock is not currently held by the caller.

---

 arch/x86/pci/i386.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
arch/x86/pci/i386.c +0 -0
index 33e6a0b..831971e 100644
@@ -57,6 +57,8 @@ static struct pcibios_fwaddrmap *pcibios_fwaddrmap_lookup(struct pci_dev *dev)
 {
 	struct pcibios_fwaddrmap *map;
 
Quoted 6 lines

arch/x86/pci/i386.c static struct pcibios_fwaddrmap *pcibios_fwaddrmap_lookup(struct pci_dev *dev) · line 61

Quoted 2 lines
arch/x86/pci/i386.c +2 -0
+	WARN_ON(!spin_is_locked(&pcibios_fwaddrmap_lock));
+

What is this going to help with? How can someone then recover from this issue? Just adding a warning message isn't going to fix any problems here, why not fix the root cause?

It's just a self-documenting assert; doesn't trigger anything and has more functionality than
/* Must hold the fwaddrmap_lock here */

Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
#5 lore raw
Quoted 33 lines · Jesse Barnes
Quoted 23 lines · On Fri, 2 Mar 2012 12:00:27 -0800 Greg KH <[email protected]> wrote:
Quoted 22 lines · Myron Stowe

'pcibios_fwaddrmap_lookup()' is used to maintain FW-assigned BIOS BAR values for reinstatement when normal resource assignment attempts fail and must be called with the 'pcibios_fwaddrmap_lock' spinlock held.

This patch adds a WARN_ON notification if the spinlock is not currently held by the caller.

---

 arch/x86/pci/i386.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
arch/x86/pci/i386.c +0 -0
index 33e6a0b..831971e 100644
@@ -57,6 +57,8 @@ static struct pcibios_fwaddrmap *pcibios_fwaddrmap_lookup(struct pci_dev *dev)
 {
 	struct pcibios_fwaddrmap *map;
 
Quoted 6 lines

arch/x86/pci/i386.c static struct pcibios_fwaddrmap *pcibios_fwaddrmap_lookup(struct pci_dev *dev) · line 61

Quoted 2 lines
arch/x86/pci/i386.c +2 -0
+	WARN_ON(!spin_is_locked(&pcibios_fwaddrmap_lock));
+

What is this going to help with? How can someone then recover from this issue? Just adding a warning message isn't going to fix any problems here, why not fix the root cause?

Quoted 3 lines

It's just a self-documenting assert; doesn't trigger anything and has more functionality than
/* Must hold the fwaddrmap_lock here */

Don't we have sparse markups that we can use to verify this instead somehow? Adding asserts isn't the nicest, as what will a user really do about this if it ever gets hit? And if a user isn't supposed to do anything, then yes, a comment would be best I would think.

But I didn't realize you had asked for this, so no big deal, I'll go back to lurking :)

greg k-h

#6 lore raw
Quoted 34 lines · On Fri, 2 Mar 2012 12:41:36 -0800 Greg KH <[email protected]> wrote:
Quoted 33 lines · Jesse Barnes
Quoted 29 lines · On Fri, 2 Mar 2012 12:00:27 -0800 Greg KH <[email protected]> wrote:
Quoted 19 lines · Myron Stowe

'pcibios_fwaddrmap_lookup()' is used to maintain FW-assigned BIOS BAR values for reinstatement when normal resource assignment attempts fail and must be called with the 'pcibios_fwaddrmap_lock' spinlock held.

This patch adds a WARN_ON notification if the spinlock is not currently held by the caller.

---

 arch/x86/pci/i386.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
arch/x86/pci/i386.c +0 -0
index 33e6a0b..831971e 100644

arch/x86/pci/i386.c static struct pcibios_fwaddrmap *pcibios_fwaddrmap_lookup(struct pci_dev *dev) · line 61

Quoted 5 lines
arch/x86/pci/i386.c +2 -0
@@ -57,6 +57,8 @@ static struct pcibios_fwaddrmap *pcibios_fwaddrmap_lookup(struct pci_dev *dev)
 {
 	struct pcibios_fwaddrmap *map;
 
+	WARN_ON(!spin_is_locked(&pcibios_fwaddrmap_lock));
+

What is this going to help with? How can someone then recover from this issue? Just adding a warning message isn't going to fix any problems here, why not fix the root cause?

Quoted 8 lines
Quoted 3 lines

It's just a self-documenting assert; doesn't trigger anything and has more functionality than
/* Must hold the fwaddrmap_lock here */

Don't we have sparse markups that we can use to verify this instead somehow? Adding asserts isn't the nicest, as what will a user really do about this if it ever gets hit? And if a user isn't supposed to do anything, then yes, a comment would be best I would think.

The user is supposed to report a bug, but it likely won't cause a crash, just a worrying message in the log.

And yeah I think we have some sparse bits for this, and at one point I thought we had an assert_spin_is_locked or somesuch.

I like the idea of self-documenting code checks better than just comments. Sparse annotations are a good second solution, but not as nice since sparse isn't always run, and has a harder time with control flow dependent stuff like this.

Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center