From: Yijing Wang <wangyijing@huawei.com>
To: Yijing Wang <wangyijing@huawei.com>, <bhelgaas@google.com>
Cc: <linux-pci@vger.kernel.org>, Rajat Jain <rajatxjain@gmail.com>
Subject: Re: [PATCH] PCI: Use a local mutex instead of pci_bus_sem to avoid deadlock
Date: Fri, 12 Jun 2015 16:20:49 +0800 [thread overview]
Message-ID: <557A9661.8030603@huawei.com> (raw)
In-Reply-To: <1434021134-6519-1-git-send-email-wangyijing@huawei.com>
rajatjain@juniper.net is not reachable now.
So add CC: rajatxjain@gmail.com
On 2015/6/11 19:12, Yijing Wang wrote:
> Rajat Jain reported a deadlock when a hierarchical hot plug
> thread and aer recovery thread both run.
> https://lkml.org/lkml/2015/3/11/861
>
> thread 1:
> pciehp_enable_slot()
> pciehp_configure_device()
> pci_bus_add_devices()
> device_attach(dev)
> device_lock(dev) //acquire device mutex successfully
> ...
> pciehp_probe(dev)
> __pci_hp_register()
> pci_create_slot()
> down_write(pci_bus_sem) //deadlock here
>
> thread 2:
> aer_isr_one_error()
> aer_process_err_device()
> do_recovery()
> broadcast_error_message()
> pci_walk_bus()
> down_read(&pci_bus_sem) //acquire pci_bus_sem successfully
> report_error_detected(dev)
> device_lock(dev) // deadlock here
>
> Now we use pci_bus_sem to protect pci_slot creation and destroy,
> it's unnecessary. We could introduce a new local mutex instead of
> pci_bus_sem to avoid the deadlock.
>
> Signed-off-by: Yijing Wang <wangyijing@huawei.com>
> ---
> drivers/pci/slot.c | 11 ++++++-----
> 1 files changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/pci/slot.c b/drivers/pci/slot.c
> index 396c200..feb08de 100644
> --- a/drivers/pci/slot.c
> +++ b/drivers/pci/slot.c
> @@ -14,6 +14,7 @@
>
> struct kset *pci_slots_kset;
> EXPORT_SYMBOL_GPL(pci_slots_kset);
> +static DEFINE_MUTEX(pci_slot_mutex);
>
> static ssize_t pci_slot_attr_show(struct kobject *kobj,
> struct attribute *attr, char *buf)
> @@ -195,7 +196,7 @@ static struct pci_slot *get_slot(struct pci_bus *parent, int slot_nr)
> {
> struct pci_slot *slot;
> /*
> - * We already hold pci_bus_sem so don't worry
> + * We already hold pci_slot_mutex so don't worry
> */
> list_for_each_entry(slot, &parent->slots, list)
> if (slot->number == slot_nr) {
> @@ -253,7 +254,7 @@ struct pci_slot *pci_create_slot(struct pci_bus *parent, int slot_nr,
> int err = 0;
> char *slot_name = NULL;
>
> - down_write(&pci_bus_sem);
> + mutex_lock(&pci_slot_mutex);
>
> if (slot_nr == -1)
> goto placeholder;
> @@ -310,7 +311,7 @@ placeholder:
>
> out:
> kfree(slot_name);
> - up_write(&pci_bus_sem);
> + mutex_unlock(&pci_slot_mutex);
> return slot;
> err:
> kfree(slot);
> @@ -332,9 +333,9 @@ void pci_destroy_slot(struct pci_slot *slot)
> dev_dbg(&slot->bus->dev, "dev %02x, dec refcount to %d\n",
> slot->number, atomic_read(&slot->kobj.kref.refcount) - 1);
>
> - down_write(&pci_bus_sem);
> + mutex_lock(&pci_slot_mutex);
> kobject_put(&slot->kobj);
> - up_write(&pci_bus_sem);
> + mutex_unlock(&pci_slot_mutex);
> }
> EXPORT_SYMBOL_GPL(pci_destroy_slot);
>
>
--
Thanks!
Yijing
next prev parent reply other threads:[~2015-06-12 8:21 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-11 11:12 [PATCH] PCI: Use a local mutex instead of pci_bus_sem to avoid deadlock Yijing Wang
2015-06-12 8:20 ` Yijing Wang [this message]
2015-06-12 18:13 ` Rajat Jain
2015-06-12 18:19 ` Rajat Jain
[not found] ` <CAA93t1ooSY2keDigmUPpO7LzvT12YwQjpxH0b1xA508LL+VWdg@mail.gmail.com>
2015-06-12 18:20 ` Guenter Roeck
2015-06-15 0:40 ` Yijing Wang
2015-06-27 3:05 ` Yijing Wang
2015-06-27 3:19 ` Guenter Roeck
2015-06-27 3:37 ` Yijing Wang
2015-07-16 4:22 ` Bjorn Helgaas
2015-07-16 7:55 ` Yijing Wang
2015-07-16 15:25 ` Bjorn Helgaas
2015-07-17 1:14 ` Yijing Wang
2015-07-17 1:35 ` Bjorn Helgaas
2015-07-17 1:54 ` Yijing Wang
2015-07-17 2:05 ` Bjorn Helgaas
2015-07-17 2:24 ` Yijing Wang
2015-07-17 2:46 ` Bjorn Helgaas
2015-07-17 2:52 ` Yijing Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=557A9661.8030603@huawei.com \
--to=wangyijing@huawei.com \
--cc=bhelgaas@google.com \
--cc=linux-pci@vger.kernel.org \
--cc=rajatxjain@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.