From: Alex Chiang <achiang@hp.com>
To: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
jbarnes@virtuousgeek.org, kristen.c.accardi@intel.com,
matthew@wil.cx
Subject: Re: [PATCH v4 03/15] PCI: prevent duplicate slot names
Date: Wed, 8 Oct 2008 22:12:47 -0600 [thread overview]
Message-ID: <20081009041247.GD4668@ldl.fc.hp.com> (raw)
In-Reply-To: <48EC4C67.9060501@jp.fujitsu.com>
* Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>:
> Alex Chiang wrote:
>
>> diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
>> index e00266b..b196ea1 100644
>> --- a/drivers/pci/hotplug/pci_hotplug_core.c
>> +++ b/drivers/pci/hotplug/pci_hotplug_core.c
>> @@ -572,41 +572,32 @@ int pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus, int slot_nr,
>> return -EINVAL;
>> }
>> - /* Check if we have already registered a slot with the same name. */
>> - if (get_slot_from_name(name))
>> - return -EEXIST;
>> -
>> /*
>> - * No problems if we call this interface from both ACPI_PCI_SLOT
>> - * driver and call it here again. If we've already created the
>> - * pci_slot, the interface will simply bump the refcount.
>> + * Look for existing slot. If we find it, and it was created by a
>> + * slot detection driver (ie, doesn't have a ->hotplug()) then we
>> + * allow the hotplug driver calling us to rename the slot if desired.
>> + *
>> + * Otherwise, create the slot and carry on with life.
>> */
>> - pci_slot = pci_create_slot(bus, slot_nr, name);
>> - if (IS_ERR(pci_slot))
>> - return PTR_ERR(pci_slot);
>> -
>> mutex_lock(&pci_hp_mutex);
>> - if (pci_slot->hotplug) {
>> - mutex_unlock(&pci_hp_mutex);
>> - dbg("%s: already claimed\n", __func__);
>> - pci_destroy_slot(pci_slot);
>> - return -EBUSY;
>> + pci_slot = pci_get_pci_slot(bus, slot_nr);
>> + if (pci_slot) {
>> + if (pci_slot->hotplug) {
>> + result = -EBUSY;
>> + goto err;
>> + }
>> +
>> + if (strcmp(kobject_name(&pci_slot->kobj), name))
>> + if ((result = pci_rename_slot(pci_slot, name)))
>> + goto err;
>> + } else {
>> + pci_slot = pci_create_slot(bus, slot_nr, name);
>> + if ((result = IS_ERR(pci_slot)))
>> + goto out;
>> }
>>
>
> I think there still remain race condition. The situation I imagine
> is as follows, though I might be misunderstanding something.
>
> If pci_slot driver created pci_slot between pci_get_pci_slot() and
> pci_create_slot() in pci_hp_register() in the hotplug driver's thread,
> pci_rename_slot() would never be called and name specified by pci_slot
> driver would be used instead of the one specified by hotplug driver.
Ah, now I finally understand.
And I think the solution is to avoid all the crap code I've been
introducing into pci_hp_register.
A better way to do it would be to make slot creation and name
override into one atomic operation, inside of pci_create_slot.
We are already serializing pci_create_slot by acquiring
pci_bus_sem, so that should prevent any race condition.
I wrote a long changelog entry for my patches that should explain
it all.
Please review. :)
>> -void pci_update_slot_number(struct pci_slot *slot, int slot_nr)
>> +void pci_renumber_slot(struct pci_slot *slot, int slot_nr)
>> {
>> - int name_count = 0;
>> struct pci_slot *tmp;
>> down_write(&pci_bus_sem);
>> list_for_each_entry(tmp, &slot->bus->slots, list) {
>> WARN_ON(tmp->number == slot_nr);
>> - if (!strcmp(kobject_name(&tmp->kobj), kobject_name(&slot->kobj)))
>> - name_count++;
>> + goto out;
>> }
>> - if (name_count > 1)
>> - printk(KERN_WARNING "pci_update_slot_number found %d slots with the same name: %s\n", name_count, kobject_name(&slot->kobj));
>> -
>> slot->number = slot_nr;
>> +out:
>> up_write(&pci_bus_sem);
>> }
>> -EXPORT_SYMBOL_GPL(pci_update_slot_number);
>> +EXPORT_SYMBOL_GPL(pci_renumber_slot);
>>
>
> You changed exported symbol name. I think it should be made as
> an another patch.
Ok.
Thanks.
/ac
next prev parent reply other threads:[~2008-10-09 4:21 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-03 23:17 [PATCH v4 00/15] PCI: let the core manage slot names Alex Chiang
2008-10-03 23:17 ` [PATCH v4 01/15] PCI Hotplug core: add 'name' param pci_hp_register interface Alex Chiang
2008-10-06 9:04 ` Matthew Wilcox
2008-10-03 23:17 ` [PATCH v4 02/15] PCI Hotplug: serialize pci_hp_register/deregister Alex Chiang
2008-10-06 14:45 ` Matthew Wilcox
2008-10-09 4:09 ` Alex Chiang
2008-10-08 5:42 ` Kenji Kaneshige
2008-10-03 23:17 ` [PATCH v4 03/15] PCI: prevent duplicate slot names Alex Chiang
2008-10-08 6:00 ` Kenji Kaneshige
2008-10-09 4:12 ` Alex Chiang [this message]
2008-10-03 23:17 ` [PATCH v4 04/15] PCI, PCI Hotplug: introduce slot_name helpers Alex Chiang
2008-10-03 23:17 ` [PATCH v4 05/15] PCI: acpiphp: remove 'name' parameter Alex Chiang
2008-10-03 23:17 ` [PATCH v4 06/15] PCI: cpci_hotplug: stop managing hotplug_slot->name Alex Chiang
2008-10-03 23:18 ` [PATCH v4 07/15] PCI: cpqphp: " Alex Chiang
2008-10-03 23:18 ` [PATCH v4 08/15] PCI: fakephp: remove 'name' parameter Alex Chiang
2008-10-03 23:18 ` [PATCH v4 09/15] PCI: ibmphp: stop managing hotplug_slot->name Alex Chiang
2008-10-03 23:18 ` [PATCH v4 10/15] PCI: pciehp: remove 'name' parameter Alex Chiang
2008-10-03 23:18 ` [PATCH v4 11/15] PCI: rpaphp: kmalloc/kfree slot->name directly Alex Chiang
2008-10-06 6:44 ` Pekka Enberg
2008-10-09 4:05 ` Alex Chiang
2008-10-03 23:18 ` [PATCH v4 12/15] PCI: SGI Hotplug: stop managing bss_hotplug_slot->name Alex Chiang
2008-10-03 23:18 ` [PATCH v4 13/15] PCI: shcphp: remove 'name' parameter Alex Chiang
2008-10-03 23:18 ` [PATCH v4 14/15] PCI: Hotplug core: remove 'name' Alex Chiang
2008-10-03 23:18 ` [PATCH v4 15/15] PCI Hotplug: fakephp: add duplicate slot name debugging Alex Chiang
2008-10-08 6:31 ` [PATCH v4 00/15] PCI: let the core manage slot names Kenji Kaneshige
2008-10-08 6:33 ` [01/03] Sample patch for [PATCH v4 02/15] Kenji Kaneshige
2008-10-08 6:34 ` [02/03] Sample patch for [PATCH v4 03/15] Kenji Kaneshige
2008-10-08 6:36 ` [03/03] Sample patch for [PATCH v4 14/15] Kenji Kaneshige
2008-10-09 4:19 ` [PATCH v4 00/15] PCI: let the core manage slot names Alex Chiang
2008-10-09 5:01 ` Kenji Kaneshige
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=20081009041247.GD4668@ldl.fc.hp.com \
--to=achiang@hp.com \
--cc=jbarnes@virtuousgeek.org \
--cc=kaneshige.kenji@jp.fujitsu.com \
--cc=kristen.c.accardi@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=matthew@wil.cx \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox