diff mbox

[v8,2/2] PCI: acpiphp: remove all functions in slot, even without ACPI _EJx

Message ID CAFeW=pazkYZ9bYZ1uG3hXxSzUC5bD3nOo2KDHLir6=Q7J-O5iw@mail.gmail.com
State Accepted
Headers show

Commit Message

Jianjun Kong May 23, 2012, 7:03 a.m. UTC
On Wed, May 23, 2012 at 1:29 PM, Yinghai Lu <yinghai@kernel.org> wrote:
> On Tue, May 22, 2012 at 10:15 PM, Amos Kong <kongjianjun@gmail.com> wrote:
>> Attached the v7,  test passed.
>
> would be better to have break...

Yeah. Otherwise, it will delete from the last function.
Attached v8, test passed.


> +static struct pci_dev *dev_in_slot(struct acpiphp_slot *slot)
> +{
> +       struct pci_bus *bus = slot->bridge->pci_bus;
> +       struct pci_dev *dev;
> +       int ret = NULL;
> +
> +       down_read(&pci_bus_sem);
> +       list_for_each_entry(dev, &bus->devices, bus_list)
> +               if (PCI_SLOT(dev->devfn) == slot->device)
> +                       ret = pci_dev_get(dev);
> +       up_read(&pci_bus_sem);
> +
> +       return ret;
> +}
>
> ===>
>
>
> +static struct pci_dev *dev_in_slot(struct acpiphp_slot *slot)
> +{
> +       struct pci_bus *bus = slot->bridge->pci_bus;
> +       struct pci_dev *dev;
> +       int ret = NULL;
> +
> +       down_read(&pci_bus_sem);
> +       list_for_each_entry(dev, &bus->devices, bus_list)
> +               if (PCI_SLOT(dev->devfn) == slot->device) {
> +                       ret = pci_dev_get(dev);
> +                      break;
> +              }
> +       up_read(&pci_bus_sem);
> +
> +       return ret;
> +}

Comments

Bjorn Helgaas May 24, 2012, 3:30 p.m. UTC | #1
On Wed, May 23, 2012 at 1:03 AM, Amos Kong <kongjianjun@gmail.com> wrote:
> On Wed, May 23, 2012 at 1:29 PM, Yinghai Lu <yinghai@kernel.org> wrote:
>> On Tue, May 22, 2012 at 10:15 PM, Amos Kong <kongjianjun@gmail.com> wrote:
>>> Attached the v7,  test passed.
>>
>> would be better to have break...
>
> Yeah. Otherwise, it will delete from the last function.
> Attached v8, test passed.
>
>
>> +static struct pci_dev *dev_in_slot(struct acpiphp_slot *slot)
>> +{
>> +       struct pci_bus *bus = slot->bridge->pci_bus;
>> +       struct pci_dev *dev;
>> +       int ret = NULL;
>> +
>> +       down_read(&pci_bus_sem);
>> +       list_for_each_entry(dev, &bus->devices, bus_list)
>> +               if (PCI_SLOT(dev->devfn) == slot->device)
>> +                       ret = pci_dev_get(dev);
>> +       up_read(&pci_bus_sem);
>> +
>> +       return ret;
>> +}
>>
>> ===>
>>
>>
>> +static struct pci_dev *dev_in_slot(struct acpiphp_slot *slot)
>> +{
>> +       struct pci_bus *bus = slot->bridge->pci_bus;
>> +       struct pci_dev *dev;
>> +       int ret = NULL;
>> +
>> +       down_read(&pci_bus_sem);
>> +       list_for_each_entry(dev, &bus->devices, bus_list)
>> +               if (PCI_SLOT(dev->devfn) == slot->device) {
>> +                       ret = pci_dev_get(dev);
>> +                      break;
>> +              }
>> +       up_read(&pci_bus_sem);
>> +
>> +       return ret;
>> +}

I applied the v6 1/2 and this v8 patch to my "for-3.6" branch.

Thanks for fixing this, Amos!  It's another step towards rationalizing
all the hotplug drivers we have.

Bjorn
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

From 32c42e815669837e114acbd14715eb60bc741bbe Mon Sep 17 00:00:00 2001
From: Amos Kong <kongjianjun@gmail.com>
Date: Tue, 22 May 2012 18:35:11 +0000
Subject: [PATCH V8 2/2] PCI: acpiphp: remove all functions in slot, even without ACPI _EJx

When we add a device with acpiphp, we enumerate all functions in the
slot with pci_scan_slot(), regardless of whether they have associated
ACPI methods such as _EJ0.

When removing the device, we previously removed only the functions
with those ACPI methods.  This patch makes the remove symmetric with the
add: we remove all functions in the slot, whether they have associated
ACPI methods or not.

With qemu-kvm and SeaBIOS, we can build a multi-function device where
only function 0 has _EJ0 and _ADR (see bugzilla below).  Removing and
re-adding that device works correctly with Windows guests.  This patch
makes it also work in Linux guests.

[bhelgaas: restructure loop iteration, pull out of slot->funcs loop]
Reference: https://bugzilla.kernel.org/show_bug.cgi?id=43219
Signed-off-by: Amos Kong <kongjianjun@gmail.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>

---
v7: keep that pci_bus_sem operation pair on return path
v8: break when the first available device is found
---
 drivers/pci/hotplug/acpiphp_glue.c |   42 +++++++++++++++++++++++++++--------
 1 files changed, 32 insertions(+), 10 deletions(-)

diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
index 0d87136..e37e73c 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -878,6 +878,24 @@  static void disable_bridges(struct pci_bus *bus)
 	}
 }
 
+/* return first device in slot, acquiring a reference on it */
+static struct pci_dev *dev_in_slot(struct acpiphp_slot *slot)
+{
+	struct pci_bus *bus = slot->bridge->pci_bus;
+	struct pci_dev *dev;
+	struct pci_dev *ret = NULL;
+
+	down_read(&pci_bus_sem);
+	list_for_each_entry(dev, &bus->devices, bus_list)
+		if (PCI_SLOT(dev->devfn) == slot->device) {
+			ret = pci_dev_get(dev);
+			break;
+		}
+	up_read(&pci_bus_sem);
+
+	return ret;
+}
+
 /**
  * disable_device - disable a slot
  * @slot: ACPI PHP slot
@@ -902,18 +920,22 @@  static int disable_device(struct acpiphp_slot *slot)
 						(u32)1, NULL, NULL);
 			func->bridge = NULL;
 		}
+	}
 
-		pdev = pci_get_slot(slot->bridge->pci_bus,
-				    PCI_DEVFN(slot->device, func->function));
-		if (pdev) {
-			pci_stop_bus_device(pdev);
-			if (pdev->subordinate) {
-				disable_bridges(pdev->subordinate);
-				pci_disable_device(pdev);
-			}
-			__pci_remove_bus_device(pdev);
-			pci_dev_put(pdev);
+	/*
+	 * enable_device() enumerates all functions in this device via
+	 * pci_scan_slot(), whether they have associated ACPI hotplug
+	 * methods (_EJ0, etc.) or not.  Therefore, we remove all functions
+	 * here.
+	 */
+	while ((pdev = dev_in_slot(slot))) {
+		pci_stop_bus_device(pdev);
+		if (pdev->subordinate) {
+			disable_bridges(pdev->subordinate);
+			pci_disable_device(pdev);
 		}
+		__pci_remove_bus_device(pdev);
+		pci_dev_put(pdev);
 	}
 
 	list_for_each_entry(func, &slot->funcs, sibling) {
-- 
1.7.1