* Why hold device_lock when calling callback in pci_walk_bus?
@ 2012-09-28 8:15 Huang Ying
2012-09-28 8:29 ` Zhang, Yanmin
0 siblings, 1 reply; 3+ messages in thread
From: Huang Ying @ 2012-09-28 8:15 UTC (permalink / raw)
To: bhelgaas; +Cc: Greg Kroah-Hartman, yanmin.zhang, linux-pci, linux-kernel, rjw
Hi, All,
If my understanding were correct, device_lock is used to provide mutual
exclusion between device probe/remove/suspend/resume etc. Why hold
device_lock when calling callback in pci_walk_bus.
This is introduced by the following commit.
commit d71374dafbba7ec3f67371d3b7e9f6310a588808
Author: Zhang Yanmin <yanmin.zhang@intel.com>
Date: Fri Jun 2 12:35:43 2006 +0800
[PATCH] PCI: fix race with pci_walk_bus and pci_destroy_dev
pci_walk_bus has a race with pci_destroy_dev. When cb is called
in pci_walk_bus, pci_destroy_dev might unlink the dev pointed by next.
Later on in the next loop, pointer next becomes NULL and cause
kernel panic.
Below patch against 2.6.17-rc4 fixes it by changing pci_bus_lock (spin_lock)
to pci_bus_sem (rw_semaphore).
Signed-off-by: Zhang Yanmin <yanmin.zhang@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Corresponding email thread is: https://lkml.org/lkml/2006/5/26/38
But from the commit and email thread, I can not find why we need to do
that.
I ask this question because I want to use pci_walk_bus in a function (in
pci runtime resume path) which may be called with device_lock held.
Can anyone help me on that?
Best Regards,
Huang Ying
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: Why hold device_lock when calling callback in pci_walk_bus?
2012-09-28 8:15 Why hold device_lock when calling callback in pci_walk_bus? Huang Ying
@ 2012-09-28 8:29 ` Zhang, Yanmin
2012-09-28 13:27 ` Huang Ying
0 siblings, 1 reply; 3+ messages in thread
From: Zhang, Yanmin @ 2012-09-28 8:29 UTC (permalink / raw)
To: Huang, Ying, bhelgaas; +Cc: Greg Kroah-Hartman, linux-pci, linux-kernel, rjw
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 1903 bytes --]
Some error handling functions call pci_walk_bus. For example, pci-e aer. Here we lock the device, so the driver wouldn't detach from the device, as the cb might call driver's callback function.
-----Original Message-----
From: Huang, Ying
Sent: Friday, September 28, 2012 4:15 PM
To: bhelgaas@google.com
Cc: Greg Kroah-Hartman; Zhang, Yanmin; linux-pci@vger.kernel.org; linux-kernel@vger.kernel.org; rjw@sisk.pl
Subject: Why hold device_lock when calling callback in pci_walk_bus?
Hi, All,
If my understanding were correct, device_lock is used to provide mutual exclusion between device probe/remove/suspend/resume etc. Why hold device_lock when calling callback in pci_walk_bus.
This is introduced by the following commit.
commit d71374dafbba7ec3f67371d3b7e9f6310a588808
Author: Zhang Yanmin <yanmin.zhang@intel.com>
Date: Fri Jun 2 12:35:43 2006 +0800
[PATCH] PCI: fix race with pci_walk_bus and pci_destroy_dev
pci_walk_bus has a race with pci_destroy_dev. When cb is called
in pci_walk_bus, pci_destroy_dev might unlink the dev pointed by next.
Later on in the next loop, pointer next becomes NULL and cause
kernel panic.
Below patch against 2.6.17-rc4 fixes it by changing pci_bus_lock (spin_lock)
to pci_bus_sem (rw_semaphore).
Signed-off-by: Zhang Yanmin <yanmin.zhang@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Corresponding email thread is: https://lkml.org/lkml/2006/5/26/38
But from the commit and email thread, I can not find why we need to do that.
I ask this question because I want to use pci_walk_bus in a function (in pci runtime resume path) which may be called with device_lock held.
Can anyone help me on that?
Best Regards,
Huang Ying
ÿôèº{.nÇ+·®+%Ëÿ±éݶ\x17¥wÿº{.nÇ+·¥{±þG«éÿ{ayº\x1dÊÚë,j\a¢f£¢·hïêÿêçz_è®\x03(éÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?¨èÚ&£ø§~á¶iOæ¬z·vØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?I¥
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Why hold device_lock when calling callback in pci_walk_bus?
2012-09-28 8:29 ` Zhang, Yanmin
@ 2012-09-28 13:27 ` Huang Ying
0 siblings, 0 replies; 3+ messages in thread
From: Huang Ying @ 2012-09-28 13:27 UTC (permalink / raw)
To: Zhang, Yanmin; +Cc: bhelgaas, Greg Kroah-Hartman, linux-pci, linux-kernel, rjw
Hi, Yanmin,
Thanks for your explain.
On Fri, 2012-09-28 at 02:29 -0600, Zhang, Yanmin wrote:
> Some error handling functions call pci_walk_bus. For example, pci-e aer. Here we lock the device, so the driver wouldn't detach from the device, as the cb might call driver's callback function.
Still has two question.
1. Is it a good practice to hold device_lock when calling driver
callback to prevent driver be unbind?
2. Is it a good idea to let callback of pci_walk_bus to acquire
device_lock when necessary. Because pci_walk_bus may be used by driver
callback too.
Best Regards,
Huang Ying
> -----Original Message-----
> From: Huang, Ying
> Sent: Friday, September 28, 2012 4:15 PM
> To: bhelgaas@google.com
> Cc: Greg Kroah-Hartman; Zhang, Yanmin; linux-pci@vger.kernel.org; linux-kernel@vger.kernel.org; rjw@sisk.pl
> Subject: Why hold device_lock when calling callback in pci_walk_bus?
>
> Hi, All,
>
> If my understanding were correct, device_lock is used to provide mutual exclusion between device probe/remove/suspend/resume etc. Why hold device_lock when calling callback in pci_walk_bus.
>
> This is introduced by the following commit.
>
> commit d71374dafbba7ec3f67371d3b7e9f6310a588808
> Author: Zhang Yanmin <yanmin.zhang@intel.com>
> Date: Fri Jun 2 12:35:43 2006 +0800
>
> [PATCH] PCI: fix race with pci_walk_bus and pci_destroy_dev
>
> pci_walk_bus has a race with pci_destroy_dev. When cb is called
> in pci_walk_bus, pci_destroy_dev might unlink the dev pointed by next.
> Later on in the next loop, pointer next becomes NULL and cause
> kernel panic.
>
> Below patch against 2.6.17-rc4 fixes it by changing pci_bus_lock (spin_lock)
> to pci_bus_sem (rw_semaphore).
>
> Signed-off-by: Zhang Yanmin <yanmin.zhang@intel.com>
> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
>
> Corresponding email thread is: https://lkml.org/lkml/2006/5/26/38
>
> But from the commit and email thread, I can not find why we need to do that.
>
> I ask this question because I want to use pci_walk_bus in a function (in pci runtime resume path) which may be called with device_lock held.
>
> Can anyone help me on that?
>
> Best Regards,
> Huang Ying
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-09-28 13:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-28 8:15 Why hold device_lock when calling callback in pci_walk_bus? Huang Ying
2012-09-28 8:29 ` Zhang, Yanmin
2012-09-28 13:27 ` Huang Ying
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®