Skip to contentSkip to conversation

PCI: set correct value for iov device before device

PATCH Applied Jiang Liu 5 participants 16 messages May 31, 2013 – Jun 5, 2013

Subsystems (2)
lore
Share & tools
lore

Jiang Liu

author
#0 lore raw

PATCH 1/3 PCI: set correct value for iov device before device

From: Xudong Hao <[email protected]>

Commit 4f535093cf8f6da8 "PCI: Put pci_dev in device tree as early as possible" moves device registering from pci_bus_add_devices() to pci_device_add(). That change causes troubles to PCI virtual functions because device_add(&virtfn->dev) is called before setting virtfn->is_virtfn flag, which then causes Xen to report PCI virtual functions as PCI physical functions.

So fix it by setting virtfn->is_virtfn before calling pci_device_add().

[Jiang Liu]:
move the setting of virtfn->is_virtfn ahead further for better readability and modify changelog.

---
Hi Bjorn and Yinghai,
How about this? I split out the bugfix patch as separate patch
so it could be easily back ported to stable branches. Regards!
Gerry

---
 drivers/pci/iov.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/pci/iov.c +2 -3
index 5fffca9..de8ffac 100644
@@ -82,6 +82,8 @@ static int virtfn_add(struct pci_dev *dev, int id, int reset)
 	pci_read_config_word(dev, iov->pos + PCI_SRIOV_VF_DID, &virtfn->device);
 	pci_setup_device(virtfn);
 	virtfn->dev.parent = dev->dev.parent;
+	virtfn->physfn = pci_dev_get(dev);
+	virtfn->is_virtfn = 1;
 
 	for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
 		res = dev->resource + PCI_IOV_RESOURCES + i;
@@ -103,9 +105,6 @@ static int virtfn_add(struct pci_dev *dev, int id, int reset)
 	pci_device_add(virtfn, virtfn->bus);
 	mutex_unlock(&iov->dev->sriov->lock);
 
-	virtfn->physfn = pci_dev_get(dev);
-	virtfn->is_virtfn = 1;
-
 	rc = pci_bus_add_device(virtfn);
 	sprintf(buf, "virtfn%u", id);
 	rc = sysfs_create_link(&dev->dev.kobj, &virtfn->dev.kobj, buf);
Signature · 1 line
1.8.1.2
author
#1 lore raw

PATCH 2/3 PCI, ACPI: Don't glue ACPI dev with pci VFs

From: Yinghai Lu <[email protected]>

When sriov is enabled, VF could just start after PF in pci tree. like c1:00.0 will be PF, and c1:00.1 and after will be VF.

acpi do have dev with same ADR. that will make them get glued wrongly.

Skip that if it is virtfn.

---
 drivers/pci/pci-acpi.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/pci/pci-acpi.c +4 -0
index e4b1fb2..720f3a2 100644
@@ -321,6 +321,10 @@ static int acpi_pci_find_device(struct device *dev, acpi_handle *handle)
 	u64	addr;
 
 	pci_dev = to_pci_dev(dev);
+	/* don't mix vf with real pci device */
+	if (pci_dev->is_virtfn)
+		return -ENODEV;
+
 	/* Please ref to ACPI spec for the syntax of _ADR */
 	addr = (PCI_SLOT(pci_dev->devfn) << 16) | PCI_FUNC(pci_dev->devfn);
 	*handle = acpi_get_child(DEVICE_ACPI_HANDLE(dev->parent), addr);
Signature · 1 line
1.8.1.2
maintainer
#2 lore raw

Re: [PATCH 2/3] PCI, ACPI: Don't glue ACPI dev with pci VFs

[+cc Rafael]

Quoted 21 lines · Jiang Liu

From: Yinghai Lu <[email protected]>

When sriov is enabled, VF could just start after PF in pci tree. like c1:00.0 will be PF, and c1:00.1 and after will be VF.

acpi do have dev with same ADR. that will make them get glued wrongly.

Skip that if it is virtfn.

---
 drivers/pci/pci-acpi.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/pci/pci-acpi.c +0 -0
index e4b1fb2..720f3a2 100644

drivers/pci/pci-acpi.c static int acpi_pci_find_device(struct device *dev, acpi_handle *handle) · line 326

Quoted 6 lines
drivers/pci/pci-acpi.c +3 -0
@@ -321,6 +321,10 @@ static int acpi_pci_find_device(struct device *dev, acpi_handle *handle)
        u64     addr;
 
        pci_dev = to_pci_dev(dev);
+       /* don't mix vf with real pci device */
+       if (pci_dev->is_virtfn)
+               return -ENODEV;

Rafael, can you review this? I don't understand the implications of this change.

And I don't know exactly what problem this would fix, so I don't know
if it's stable material or not. Yinghai did propose it as v3.10
material in https://lkml.kernel.org/r/[email protected],
but I don't know why.

Bjorn

Quoted 6 lines
drivers/pci/pci-acpi.c +0 -1
        /* Please ref to ACPI spec for the syntax of _ADR */
        addr = (PCI_SLOT(pci_dev->devfn) << 16) | PCI_FUNC(pci_dev->devfn);
        *handle = acpi_get_child(DEVICE_ACPI_HANDLE(dev->parent), addr);
--

1.8.1.2

maintainer
#3 lore raw

Re: [PATCH 2/3] PCI, ACPI: Don't glue ACPI dev with pci VFs

Quoted 34 lines · Bjorn Helgaas

[+cc Rafael]

Quoted 21 lines · Jiang Liu

From: Yinghai Lu <[email protected]>

When sriov is enabled, VF could just start after PF in pci tree. like c1:00.0 will be PF, and c1:00.1 and after will be VF.

acpi do have dev with same ADR. that will make them get glued wrongly.

Skip that if it is virtfn.

---
 drivers/pci/pci-acpi.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/pci/pci-acpi.c +0 -0
index e4b1fb2..720f3a2 100644

drivers/pci/pci-acpi.c static int acpi_pci_find_device(struct device *dev, acpi_handle *handle) · line 326

Quoted 6 lines
drivers/pci/pci-acpi.c +3 -0
@@ -321,6 +321,10 @@ static int acpi_pci_find_device(struct device *dev, acpi_handle *handle)
        u64     addr;
 
        pci_dev = to_pci_dev(dev);
+       /* don't mix vf with real pci device */
+       if (pci_dev->is_virtfn)
+               return -ENODEV;

Rafael, can you review this? I don't understand the implications of this change.

Quoted 4 lines

And I don't know exactly what problem this would fix, so I don't know
if it's stable material or not. Yinghai did propose it as v3.10
material in https://lkml.kernel.org/r/[email protected],
but I don't know why.

Ping?

Jiang or Yinghai, what problem does this fix?

I'm guessing maybe all three of these should be marked for stable, but I'd like confirmation of that.

Quoted 6 lines
Quoted 6 lines
drivers/pci/pci-acpi.c +0 -1
        /* Please ref to ACPI spec for the syntax of _ADR */
        addr = (PCI_SLOT(pci_dev->devfn) << 16) | PCI_FUNC(pci_dev->devfn);
        *handle = acpi_get_child(DEVICE_ACPI_HANDLE(dev->parent), addr);
--

1.8.1.2

#4 lore raw

Re: [PATCH 2/3] PCI, ACPI: Don't glue ACPI dev with pci VFs

Quoted 35 lines · Bjorn Helgaas
Quoted 34 lines · Bjorn Helgaas

[+cc Rafael]

Quoted 21 lines · Jiang Liu

From: Yinghai Lu <[email protected]>

When sriov is enabled, VF could just start after PF in pci tree. like c1:00.0 will be PF, and c1:00.1 and after will be VF.

acpi do have dev with same ADR. that will make them get glued wrongly.

Skip that if it is virtfn.

---
 drivers/pci/pci-acpi.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/pci/pci-acpi.c +0 -0
index e4b1fb2..720f3a2 100644

drivers/pci/pci-acpi.c static int acpi_pci_find_device(struct device *dev, acpi_handle *handle) · line 326

Quoted 6 lines
drivers/pci/pci-acpi.c +3 -0
@@ -321,6 +321,10 @@ static int acpi_pci_find_device(struct device *dev, acpi_handle *handle)
        u64     addr;
 
        pci_dev = to_pci_dev(dev);
+       /* don't mix vf with real pci device */
+       if (pci_dev->is_virtfn)
+               return -ENODEV;

Rafael, can you review this? I don't understand the implications of this change.

Quoted 8 lines
Quoted 4 lines

And I don't know exactly what problem this would fix, so I don't know
if it's stable material or not. Yinghai did propose it as v3.10
material in https://lkml.kernel.org/r/[email protected],
but I don't know why.

Ping?

Jiang or Yinghai, what problem does this fix?

fix the wrong binding between acpi dev and VFs.

Found that in my recent sriov test.

Quoted 3 lines

I'm guessing maybe all three of these should be marked for stable, but I'd like confirmation of that.

Yes

Yinghai

maintainer
#5 lore raw

Re: [PATCH 2/3] PCI, ACPI: Don't glue ACPI dev with pci VFs

Quoted 41 lines · Yinghai Lu
Quoted 40 lines · Bjorn Helgaas
Quoted 38 lines · Bjorn Helgaas

[+cc Rafael]

Quoted 21 lines · Jiang Liu

From: Yinghai Lu <[email protected]>

When sriov is enabled, VF could just start after PF in pci tree. like c1:00.0 will be PF, and c1:00.1 and after will be VF.

acpi do have dev with same ADR. that will make them get glued wrongly.

Skip that if it is virtfn.

---
 drivers/pci/pci-acpi.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/pci/pci-acpi.c +0 -0
index e4b1fb2..720f3a2 100644

drivers/pci/pci-acpi.c static int acpi_pci_find_device(struct device *dev, acpi_handle *handle) · line 326

Quoted 6 lines
drivers/pci/pci-acpi.c +3 -0
@@ -321,6 +321,10 @@ static int acpi_pci_find_device(struct device *dev, acpi_handle *handle)
        u64     addr;
 
        pci_dev = to_pci_dev(dev);
+       /* don't mix vf with real pci device */
+       if (pci_dev->is_virtfn)
+               return -ENODEV;

Rafael, can you review this? I don't understand the implications of this change.

And I don't know exactly what problem this would fix, so I don't know
if it's stable material or not. Yinghai did propose it as v3.10
material in https://lkml.kernel.org/r/[email protected],
but I don't know why.

Quoted 5 lines
Quoted 3 lines

Ping?

Jiang or Yinghai, what problem does this fix?

fix the wrong binding between acpi dev and VFs.

Well, I read that in the changelog, but that doesn't tell me what bad things happen as a result. Can you elaborate a little bit? Does it mean PM doesn't work, hotplug doesn't work, drivers can't bind to the VFs correctly, the magic smoke comes out of the PF, or what?

Quoted 9 lines

Found that in my recent sriov test.

Quoted 3 lines

I'm guessing maybe all three of these should be marked for stable, but I'd like confirmation of that.

Yes

Yinghai

#6 lore raw

Re: [PATCH 2/3] PCI, ACPI: Don't glue ACPI dev with pci VFs

Quoted 5 lines · Bjorn Helgaas

On Tue, Jun 4, 2013 at 3:57 PM, Yinghai Lu <[email protected]> wrote:
Well, I read that in the changelog, but that doesn't tell me what bad things happen as a result. Can you elaborate a little bit? Does it mean PM doesn't work, hotplug doesn't work, drivers can't bind to the VFs correctly, the magic smoke comes out of the PF, or what?

no, I did not notice anything unusual except the binding message. as my platform have those PM disabled.

#7 lore raw

Re: [PATCH 2/3] PCI, ACPI: Don't glue ACPI dev with pci VFs

In reply to Jiang Liu
Quoted 7 lines · Jiang Liu

From: Yinghai Lu <[email protected]>

When sriov is enabled, VF could just start after PF in pci tree. like c1:00.0 will be PF, and c1:00.1 and after will be VF.

acpi do have dev with same ADR. that will make them get glued wrongly.

How exactly are they glued in that case?

Quoted 1 line

Skip that if it is virtfn.

That should be a bit more specific as far as I can say. I don't see why a VF would not have a valid ACPI device object corresponding to it. Is there any particular reason?

Rafael

Quoted 22 lines
---
 drivers/pci/pci-acpi.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/pci/pci-acpi.c +4 -0
index e4b1fb2..720f3a2 100644
@@ -321,6 +321,10 @@ static int acpi_pci_find_device(struct device *dev, acpi_handle *handle)
 	u64	addr;
 
 	pci_dev = to_pci_dev(dev);
+	/* don't mix vf with real pci device */
+	if (pci_dev->is_virtfn)
+		return -ENODEV;
+
 	/* Please ref to ACPI spec for the syntax of _ADR */
 	addr = (PCI_SLOT(pci_dev->devfn) << 16) | PCI_FUNC(pci_dev->devfn);
 	*handle = acpi_get_child(DEVICE_ACPI_HANDLE(dev->parent), addr);
Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#8 lore raw

Re: [PATCH 2/3] PCI, ACPI: Don't glue ACPI dev with pci VFs

Quoted 9 lines · Rafael J. Wysocki
Quoted 7 lines · Jiang Liu

From: Yinghai Lu <[email protected]>

When sriov is enabled, VF could just start after PF in pci tree. like c1:00.0 will be PF, and c1:00.1 and after will be VF.

acpi do have dev with same ADR. that will make them get glued wrongly.

Quoted 7 lines

How exactly are they glued in that case?

Quoted 1 line

Skip that if it is virtfn.

That should be a bit more specific as far as I can say. I don't see why a VF would not have a valid ACPI device object corresponding to it. Is there any particular reason?

To be precise, I don't quite see why it is impossible or invalid for a VF to have a corresponding ACPI device object. It may not be the case on this particular system, but why not in general?

Rafael

Quoted 23 lines
Quoted 22 lines
---
 drivers/pci/pci-acpi.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/pci/pci-acpi.c +4 -0
index e4b1fb2..720f3a2 100644
@@ -321,6 +321,10 @@ static int acpi_pci_find_device(struct device *dev, acpi_handle *handle)
 	u64	addr;
 
 	pci_dev = to_pci_dev(dev);
+	/* don't mix vf with real pci device */
+	if (pci_dev->is_virtfn)
+		return -ENODEV;
+
 	/* Please ref to ACPI spec for the syntax of _ADR */
 	addr = (PCI_SLOT(pci_dev->devfn) << 16) | PCI_FUNC(pci_dev->devfn);
 	*handle = acpi_get_child(DEVICE_ACPI_HANDLE(dev->parent), addr);
Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#9 lore raw

Re: [PATCH 2/3] PCI, ACPI: Don't glue ACPI dev with pci VFs

Quoted 14 lines · Rafael J. Wysocki
Quoted 13 lines · Rafael J. Wysocki
Quoted 7 lines · Jiang Liu

From: Yinghai Lu <[email protected]>

When sriov is enabled, VF could just start after PF in pci tree. like c1:00.0 will be PF, and c1:00.1 and after will be VF.

acpi do have dev with same ADR. that will make them get glued wrongly.

How exactly are they glued in that case?

Quoted 1 line

Skip that if it is virtfn.

Quoted 7 lines
Quoted 3 lines

That should be a bit more specific as far as I can say. I don't see why a VF would not have a valid ACPI device object corresponding to it. Is there any particular reason?

To be precise, I don't quite see why it is impossible or invalid for a VF to have a corresponding ACPI device object. It may not be the case on this particular system, but why not in general?

at least for ioapic routing GSI, we should not mix VF to use other PF's setting.

Yinghai

#10 lore raw

Re: [PATCH 2/3] PCI, ACPI: Don't glue ACPI dev with pci VFs

Quoted 19 lines · Yinghai Lu
Quoted 18 lines · Rafael J. Wysocki
Quoted 16 lines · Rafael J. Wysocki
Quoted 7 lines · Jiang Liu

From: Yinghai Lu <[email protected]>

When sriov is enabled, VF could just start after PF in pci tree. like c1:00.0 will be PF, and c1:00.1 and after will be VF.

acpi do have dev with same ADR. that will make them get glued wrongly.

How exactly are they glued in that case?

Quoted 1 line

Skip that if it is virtfn.

That should be a bit more specific as far as I can say. I don't see why a VF would not have a valid ACPI device object corresponding to it. Is there any particular reason?

Quoted 6 lines
Quoted 3 lines

To be precise, I don't quite see why it is impossible or invalid for a VF to have a corresponding ACPI device object. It may not be the case on this particular system, but why not in general?

at least for ioapic routing GSI, we should not mix VF to use other PF's setting.

I can agree with that, but your patch is far more general than this. It won't allow any VF on any system to be "glued" to any ACPI device object and I'm thinking that that may just go too far.

May that be addressed in a more specific way?

Also, I don't quite understand what the problem *exactly* is, because you haven't given any details so far. Can you possibly attach the specific piece of AML causing the problem to happen on your system?

Rafael

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#11 lore raw

Re: [PATCH 2/3] PCI, ACPI: Don't glue ACPI dev with pci VFs

Quoted 6 lines · Rafael J. Wysocki
Quoted 5 lines · Yinghai Lu
Quoted 4 lines

To be precise, I don't quite see why it is impossible or invalid for a VF to have a corresponding ACPI device object. It may not be the case on this particular system, but why not in general?

Quoted 6 lines
Quoted 2 lines

at least for ioapic routing GSI, we should not mix VF to use other PF's setting.

I can agree with that, but your patch is far more general than this. It won't allow any VF on any system to be "glued" to any ACPI device object and I'm thinking that that may just go too far.

I think that we should look reversely:
Is there any reason or use case that we need to bind PCI VF to acpi device? PCI vf is only showing up after PF driver call pci_enable_siov.

Yinghai

maintainer
#12 lore raw

Re: [PATCH 2/3] PCI, ACPI: Don't glue ACPI dev with pci VFs

Quoted 10 lines · Yinghai Lu
Quoted 9 lines · Rafael J. Wysocki
Quoted 7 lines · Yinghai Lu
Quoted 4 lines

To be precise, I don't quite see why it is impossible or invalid for a VF to have a corresponding ACPI device object. It may not be the case on this particular system, but why not in general?

at least for ioapic routing GSI, we should not mix VF to use other PF's setting.

Quoted 7 lines
Quoted 3 lines

I can agree with that, but your patch is far more general than this. It won't allow any VF on any system to be "glued" to any ACPI device object and I'm thinking that that may just go too far.

I think that we should look reversely:
Is there any reason or use case that we need to bind PCI VF to acpi device? PCI vf is only showing up after PF driver call pci_enable_siov.

I disagree with this sentiment. We should handle VFs the same as PFs except when that's impossible. You're proposing a special case of treating VFs differently, so I think the burden is on you to explain why we need to do that.

It would be helpful if you answered the questions people ask you, for example, if you could supply the AML Rafael asked about. If it's secret, just say so instead of leaving us with the impression that you're ignoring the question.

Bjorn

author
#13 lore raw

PATCH 3/3 PCI: Hide remove and rescan sysfs interfaces for SR-IOV virtual functions

In reply to Jiang Liu

From: Jiang Liu <[email protected]>

PCI devices for SR-IOV virtual functions should only be created/ destroyed by pci_enable_sriov()/pci_disable_sriov() because special data structures are associated with SR-IOV virtual functions. So hide hotplug related sysfs interfaces "remove" and "rescan" for SR-IOV virtual functions, otherwise it may causes memory leakage and other issues.

---
 drivers/pci/pci-sysfs.c | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)
drivers/pci/pci-sysfs.c +28 -2
index 5b4a9d9..403da60 100644
@@ -325,6 +325,8 @@ dev_rescan_store(struct device *dev, struct device_attribute *attr,
 	}
 	return count;
 }
+struct device_attribute dev_rescan_attr = __ATTR(rescan, (S_IWUSR|S_IWGRP),
+						 NULL, dev_rescan_store);
 
 static void remove_callback(struct device *dev)
 {
@@ -354,6 +356,8 @@ remove_store(struct device *dev, struct device_attribute *dummy,
 		count = ret;
 	return count;
 }
+struct device_attribute dev_remove_attr = __ATTR(remove, (S_IWUSR|S_IWGRP),
+						 NULL, remove_store);
 
 static ssize_t
 dev_bus_rescan_store(struct device *dev, struct device_attribute *attr,
@@ -504,8 +508,6 @@ struct device_attribute pci_dev_attrs[] = {
 	__ATTR(broken_parity_status,(S_IRUGO|S_IWUSR),
 		broken_parity_status_show,broken_parity_status_store),
 	__ATTR(msi_bus, 0644, msi_bus_show, msi_bus_store),
-	__ATTR(remove, (S_IWUSR|S_IWGRP), NULL, remove_store),
-	__ATTR(rescan, (S_IWUSR|S_IWGRP), NULL, dev_rescan_store),
 #if defined(CONFIG_PM_RUNTIME) && defined(CONFIG_ACPI)
 	__ATTR(d3cold_allowed, 0644, d3cold_allowed_show, d3cold_allowed_store),
 #endif
@@ -1463,6 +1465,29 @@ static umode_t pci_dev_attrs_are_visible(struct kobject *kobj,
 	return a->mode;
 }
 
+static struct attribute *pci_dev_hp_attrs[] = {
+	&dev_remove_attr.attr,
+	&dev_rescan_attr.attr,
+	NULL,
+};
+
+static umode_t pci_dev_hp_attrs_are_visible(struct kobject *kobj,
+						struct attribute *a, int n)
+{
+	struct device *dev = container_of(kobj, struct device, kobj);
+	struct pci_dev *pdev = to_pci_dev(dev);
+
+	if (pdev->is_virtfn)
+		return 0;
+
+	return a->mode;
+}
+
+static struct attribute_group pci_dev_hp_attr_group = {
+	.attrs = pci_dev_hp_attrs,
+	.is_visible = pci_dev_hp_attrs_are_visible,
+};
+
 #ifdef CONFIG_PCI_IOV
 static struct attribute *sriov_dev_attrs[] = {
 	&sriov_totalvfs_attr.attr,
@@ -1494,6 +1519,7 @@ static struct attribute_group pci_dev_attr_group = {
 
 static const struct attribute_group *pci_dev_attr_groups[] = {
 	&pci_dev_attr_group,
+	&pci_dev_hp_attr_group,
 #ifdef CONFIG_PCI_IOV
 	&sriov_dev_attr_group,
 #endif
Signature · 1 line
1.8.1.2
maintainer Applied
#14 lore raw

Re: [PATCH 3/3] PCI: Hide remove and rescan sysfs interfaces for SR-IOV virtual functions

Quoted 9 lines · Jiang Liu

From: Jiang Liu <[email protected]>

PCI devices for SR-IOV virtual functions should only be created/ destroyed by pci_enable_sriov()/pci_disable_sriov() because special data structures are associated with SR-IOV virtual functions. So hide hotplug related sysfs interfaces "remove" and "rescan" for SR-IOV virtual functions, otherwise it may causes memory leakage and other issues.

Quoted 6 lines

Applied to my -next branch for v3.11, thanks!

Quoted 76 lines
---
 drivers/pci/pci-sysfs.c | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)
drivers/pci/pci-sysfs.c +28 -3
index 5b4a9d9..403da60 100644
@@ -325,6 +325,8 @@ dev_rescan_store(struct device *dev, struct device_attribute *attr,
        }
        return count;
 }
+struct device_attribute dev_rescan_attr = __ATTR(rescan, (S_IWUSR|S_IWGRP),
+                                                NULL, dev_rescan_store);
 
 static void remove_callback(struct device *dev)
 {
@@ -354,6 +356,8 @@ remove_store(struct device *dev, struct device_attribute *dummy,
                count = ret;
        return count;
 }
+struct device_attribute dev_remove_attr = __ATTR(remove, (S_IWUSR|S_IWGRP),
+                                                NULL, remove_store);
 
 static ssize_t
 dev_bus_rescan_store(struct device *dev, struct device_attribute *attr,
@@ -504,8 +508,6 @@ struct device_attribute pci_dev_attrs[] = {
        __ATTR(broken_parity_status,(S_IRUGO|S_IWUSR),
                broken_parity_status_show,broken_parity_status_store),
        __ATTR(msi_bus, 0644, msi_bus_show, msi_bus_store),
-       __ATTR(remove, (S_IWUSR|S_IWGRP), NULL, remove_store),
-       __ATTR(rescan, (S_IWUSR|S_IWGRP), NULL, dev_rescan_store),
 #if defined(CONFIG_PM_RUNTIME) && defined(CONFIG_ACPI)
        __ATTR(d3cold_allowed, 0644, d3cold_allowed_show, d3cold_allowed_store),
 #endif
@@ -1463,6 +1465,29 @@ static umode_t pci_dev_attrs_are_visible(struct kobject *kobj,
        return a->mode;
 }
 
+static struct attribute *pci_dev_hp_attrs[] = {
+       &dev_remove_attr.attr,
+       &dev_rescan_attr.attr,
+       NULL,
+};
+
+static umode_t pci_dev_hp_attrs_are_visible(struct kobject *kobj,
+                                               struct attribute *a, int n)
+{
+       struct device *dev = container_of(kobj, struct device, kobj);
+       struct pci_dev *pdev = to_pci_dev(dev);
+
+       if (pdev->is_virtfn)
+               return 0;
+
+       return a->mode;
+}
+
+static struct attribute_group pci_dev_hp_attr_group = {
+       .attrs = pci_dev_hp_attrs,
+       .is_visible = pci_dev_hp_attrs_are_visible,
+};
+
 #ifdef CONFIG_PCI_IOV
 static struct attribute *sriov_dev_attrs[] = {
        &sriov_totalvfs_attr.attr,
@@ -1494,6 +1519,7 @@ static struct attribute_group pci_dev_attr_group = {
 
 static const struct attribute_group *pci_dev_attr_groups[] = {
        &pci_dev_attr_group,
+       &pci_dev_hp_attr_group,
 #ifdef CONFIG_PCI_IOV
        &sriov_dev_attr_group,
 #endif
--

1.8.1.2

maintainer Applied
#15 lore raw
In reply to Jiang Liu
Quoted 15 lines · Jiang Liu

From: Xudong Hao <[email protected]>

Commit 4f535093cf8f6da8 "PCI: Put pci_dev in device tree as early as possible" moves device registering from pci_bus_add_devices() to pci_device_add(). That change causes troubles to PCI virtual functions because device_add(&virtfn->dev) is called before setting virtfn->is_virtfn flag, which then causes Xen to report PCI virtual functions as PCI physical functions.

So fix it by setting virtfn->is_virtfn before calling pci_device_add().

[Jiang Liu]:
move the setting of virtfn->is_virtfn ahead further for better readability and modify changelog.

Quoted 7 lines

---
Hi Bjorn and Yinghai,
How about this? I split out the bugfix patch as separate patch
so it could be easily back ported to stable branches.

Applied to my -next branch for v3.11, thanks!

Quoted 30 lines
---
 drivers/pci/iov.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/pci/iov.c +2 -4
index 5fffca9..de8ffac 100644
@@ -82,6 +82,8 @@ static int virtfn_add(struct pci_dev *dev, int id, int reset)
        pci_read_config_word(dev, iov->pos + PCI_SRIOV_VF_DID, &virtfn->device);
        pci_setup_device(virtfn);
        virtfn->dev.parent = dev->dev.parent;
+       virtfn->physfn = pci_dev_get(dev);
+       virtfn->is_virtfn = 1;
 
        for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
                res = dev->resource + PCI_IOV_RESOURCES + i;
@@ -103,9 +105,6 @@ static int virtfn_add(struct pci_dev *dev, int id, int reset)
        pci_device_add(virtfn, virtfn->bus);
        mutex_unlock(&iov->dev->sriov->lock);
 
-       virtfn->physfn = pci_dev_get(dev);
-       virtfn->is_virtfn = 1;
-
        rc = pci_bus_add_device(virtfn);
        sprintf(buf, "virtfn%u", id);
        rc = sysfs_create_link(&dev->dev.kobj, &virtfn->dev.kobj, buf);
--

1.8.1.2