Skip to contentSkip to conversation

PCI: introduce device assignment interface and refactory related code

PATCH In review Ethan Zhao 6 participants 34 messages Jul 11, 2014 – Jul 22, 2014

Subsystems (6)
Networking Network drivers KVM PCI +2 more subsystems
lore
Share & tools
lore

Ethan Zhao

author
#0 lore raw

PATCH v3 1/2 PCI: introduce device assignment interface and refactory related code

This patch introduces two new device assignment functions

pci_iov_assign_device(),
pci_iov_deassign_device()

along with the existed one

pci_vfs_assigned()

They construct the VFs assignment management interface, used to assign/ deassign device to VM and query the VFs reference counter. instead of direct manipulation of device flag.

This patch refashioned the related code and make them atomic.

v3: change the naming of device assignment helpers, because they work for all kind of PCI device, not only SR-IOV ([email protected])

v2: reorder the patchset and make it bisectable and atomic, steps clear between interface defination and implemenation according to the suggestion from [email protected]

---
 drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c |   17 ++---------------
 drivers/pci/iov.c                                  |   20 ++++++++++++++++++++
 drivers/xen/xen-pciback/pci_stub.c                 |    4 ++--
 include/linux/pci.h                                |    4 ++++
 virt/kvm/assigned-dev.c                            |    2 +-
 virt/kvm/iommu.c                                   |    4 ++--
 6 files changed, 31 insertions(+), 20 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +2 -15
index 02c11a7..781040e 100644
@@ -693,22 +693,9 @@ complete_reset:
 static bool i40e_vfs_are_assigned(struct i40e_pf *pf)
 {
 	struct pci_dev *pdev = pf->pdev;
-	struct pci_dev *vfdev;
-
-	/* loop through all the VFs to see if we own any that are assigned */
-	vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, I40E_DEV_ID_VF , NULL);
-	while (vfdev) {
-		/* if we don't own it we don't care */
-		if (vfdev->is_virtfn && pci_physfn(vfdev) == pdev) {
-			/* if it is assigned we cannot release it */
-			if (vfdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED)
-				return true;
-		}
 
-		vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
-				       I40E_DEV_ID_VF,
-				       vfdev);
-	}
+	if (pci_vfs_assigned(pdev))
+		return true;
 
 	return false;
 }
drivers/pci/iov.c +20 -0
index de7a747..090f827 100644
@@ -644,6 +644,26 @@ int pci_vfs_assigned(struct pci_dev *dev)
 EXPORT_SYMBOL_GPL(pci_vfs_assigned);
 
 /**
+ * pci_iov_assign_device - assign device to VM
+ * @pdev: the device to be assigned.
+ */
+void pci_iov_assign_device(struct pci_dev *pdev)
+{
+	pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_assign_device);
+
+/**
+ * pci_iov_deassign_device - deasign device from VM
+ * @pdev: the device to be deassigned.
+ */
+void pci_iov_deassign_device(struct pci_dev *pdev)
+{
+	pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_deassign_device);
+
+/**
  * pci_sriov_set_totalvfs -- reduce the TotalVFs available
  * @dev: the PCI PF device
  * @numvfs: number that should be used for TotalVFs supported
drivers/xen/xen-pciback/pci_stub.c +2 -2
index 62fcd48..27e00d1 100644
@@ -133,7 +133,7 @@ static void pcistub_device_release(struct kref *kref)
 	xen_pcibk_config_free_dyn_fields(dev);
 	xen_pcibk_config_free_dev(dev);
 
-	dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+	pci_iov_deassign_device(dev);
 	pci_dev_put(dev);
 
 	kfree(psdev);
@@ -404,7 +404,7 @@ static int pcistub_init_device(struct pci_dev *dev)
 	dev_dbg(&dev->dev, "reset device\n");
 	xen_pcibk_reset_device(dev);
 
-	dev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+	pci_iov_assign_device(dev);
 	return 0;
 
 config_release:
include/linux/pci.h +4 -0
index aab57b4..5ece6d6 100644
@@ -1603,6 +1603,8 @@ int pci_num_vf(struct pci_dev *dev);
 int pci_vfs_assigned(struct pci_dev *dev);
 int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs);
 int pci_sriov_get_totalvfs(struct pci_dev *dev);
+void pci_iov_assign_device(struct pci_dev *dev);
+void pci_iov_deassign_device(struct pci_dev *dev);
 #else
 static inline int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn)
 { return -ENODEV; }
@@ -1614,6 +1616,8 @@ static inline int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs)
 { return 0; }
 static inline int pci_sriov_get_totalvfs(struct pci_dev *dev)
 { return 0; }
+static inline void pci_iov_assign_device(struct pci_dev *dev) { }
+static inline void pci_iov_deassign_device(struct pci_dev *dev) { }
 #endif
 
 #if defined(CONFIG_HOTPLUG_PCI) || defined(CONFIG_HOTPLUG_PCI_MODULE)
virt/kvm/assigned-dev.c +1 -1
index bf06577..7fac58d 100644
@@ -302,7 +302,7 @@ static void kvm_free_assigned_device(struct kvm *kvm,
 	else
 		pci_restore_state(assigned_dev->dev);
 
-	assigned_dev->dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+	pci_iov_deassign_device(assigned_dev->dev);
 
 	pci_release_regions(assigned_dev->dev);
 	pci_disable_device(assigned_dev->dev);
virt/kvm/iommu.c +2 -2
index 0df7d4b..641ee73 100644
@@ -194,7 +194,7 @@ int kvm_assign_device(struct kvm *kvm,
 			goto out_unmap;
 	}
 
-	pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+	pci_iov_assign_device(pdev);
 
 	dev_info(&pdev->dev, "kvm assign device\n");
 
@@ -220,7 +220,7 @@ int kvm_deassign_device(struct kvm *kvm,
 
 	iommu_detach_device(domain, &pdev->dev);
 
-	pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+	pci_iov_deassign_device(pdev);
 
 	dev_info(&pdev->dev, "kvm deassign device\n");
 
Signature · 14 lines
1.7.1


------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
E1000-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel® Ethernet, visit http://communities.intel.com/community/wired
author
#1 lore raw

PATCH v3 2/2 PCI: implement VFs assignment reference counter

Current implementation of helper function pci_vfs_assigned() is a little complex, to get sum of VFs that assigned to VM, access low level configuration space register and then loop in traversing device tree.

This patch introduces an atomic reference counter for VFs those were assigned to VM in struct pci_sriov. and simplify the code in pci_vfs_assigned().

v3: change the naming of device assignment helpers, because they work for all kind of PCI device, not only SR-IOV ([email protected])

v2: reorder the patchset according to the suggestion from [email protected]

---
 drivers/pci/iov.c |   42 ++++++++++++++++--------------------------
 drivers/pci/pci.h |    1 +
 2 files changed, 17 insertions(+), 26 deletions(-)
drivers/pci/iov.c +16 -26
index 090f827..10efe43 100644
@@ -382,6 +382,7 @@ found:
 	iov->nres = nres;
 	iov->ctrl = ctrl;
 	iov->total_VFs = total;
+	atomic_set(&iov->VFs_assigned_cnt, 0);
 	iov->offset = offset;
 	iov->stride = stride;
 	iov->pgsz = pgsz;
@@ -603,43 +604,22 @@ int pci_num_vf(struct pci_dev *dev)
 EXPORT_SYMBOL_GPL(pci_num_vf);
 
 /**
- * pci_vfs_assigned - returns number of VFs are assigned to a guest
- * @dev: the PCI device
+ * pci_vfs_assigned - returns number of VFs are assigned to VM
+ * @dev: the physical PCI device that contains the VFs.
  *
  * Returns number of VFs belonging to this device that are assigned to a guest.
  * If device is not a physical function returns 0.
  */
 int pci_vfs_assigned(struct pci_dev *dev)
 {
-	struct pci_dev *vfdev;
-	unsigned int vfs_assigned = 0;
-	unsigned short dev_id;
 
 	/* only search if we are a PF */
 	if (!dev->is_physfn)
 		return 0;
 
-	/*
-	 * determine the device ID for the VFs, the vendor ID will be the
-	 * same as the PF so there is no need to check for that one
-	 */
-	pci_read_config_word(dev, dev->sriov->pos + PCI_SRIOV_VF_DID, &dev_id);
-
-	/* loop through all the VFs to see if we own any that are assigned */
-	vfdev = pci_get_device(dev->vendor, dev_id, NULL);
-	while (vfdev) {
-		/*
-		 * It is considered assigned if it is a virtual function with
-		 * our dev as the physical function and the assigned bit is set
-		 */
-		if (vfdev->is_virtfn && (vfdev->physfn == dev) &&
-		    (vfdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED))
-			vfs_assigned++;
-
-		vfdev = pci_get_device(dev->vendor, dev_id, vfdev);
-	}
-
-	return vfs_assigned;
+	if (dev->sriov)
+		return atomic_read(&dev->sriov->VFs_assigned_cnt);
+	return 0;
 }
 EXPORT_SYMBOL_GPL(pci_vfs_assigned);
 
@@ -650,6 +630,11 @@ EXPORT_SYMBOL_GPL(pci_vfs_assigned);
 void pci_iov_assign_device(struct pci_dev *pdev)
 {
 	pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+	if (pdev->is_virtfn && !pdev->is_physfn)
+		if (pdev->physfn)
+			if (pdev->physfn->sriov)
+				atomic_inc(&pdev->physfn->sriov->
+					VFs_assigned_cnt);
 }
 EXPORT_SYMBOL_GPL(pci_iov_assign_device);
 
@@ -660,6 +645,11 @@ EXPORT_SYMBOL_GPL(pci_iov_assign_device);
 void pci_iov_deassign_device(struct pci_dev *pdev)
 {
 	pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+	if (pdev->is_virtfn && !pdev->is_physfn)
+		if (pdev->physfn)
+			if (pdev->physfn->sriov)
+				atomic_dec(&pdev->physfn->sriov->
+					VFs_assigned_cnt);
 }
 EXPORT_SYMBOL_GPL(pci_iov_deassign_device);
 
drivers/pci/pci.h +1 -0
index 6bd0822..d17bda2 100644
@@ -235,6 +235,7 @@ struct pci_sriov {
 	u32 pgsz;		/* page size for BAR alignment */
 	u8 link;		/* Function Dependency Link */
 	u16 driver_max_VFs;	/* max num VFs driver supports */
+	atomic_t VFs_assigned_cnt; /* counter of VFs assigned to VM */
 	struct pci_dev *dev;	/* lowest numbered PF */
 	struct pci_dev *self;	/* this PF */
 	struct mutex lock;	/* lock for VF bus */
Signature · 14 lines
1.7.1


------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
E1000-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel® Ethernet, visit http://communities.intel.com/community/wired
#2 lore raw

Re: [PATCH 2/2 V3] PCI: implement VFs assignment reference counter

Quoted 4 lines · Ethan Zhao

Current implementation of helper function pci_vfs_assigned() is a little complex, to get sum of VFs that assigned to VM, access low level configuration space register and then loop in traversing device tree.

(...)

drivers/pci/iov.c EXPORT_SYMBOL_GPL(pci_vfs_assigned); · line 635

Quoted 7 lines
drivers/pci/iov.c +3 -0
@@ -650,6 +630,11 @@ EXPORT_SYMBOL_GPL(pci_vfs_assigned);
  void pci_iov_assign_device(struct pci_dev *pdev)
  {
  	pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+	if (pdev->is_virtfn && !pdev->is_physfn)
+		if (pdev->physfn)
+			if (pdev->physfn->sriov)

Why don't we make last two 'if' conditions into single 'if'

if (pdev->physfn && pdev->physfn->sriov)

drivers/pci/iov.c EXPORT_SYMBOL_GPL(pci_iov_assign_device); · line 650

Quoted 12 lines
drivers/pci/iov.c +5 -0
+				atomic_inc(&pdev->physfn->sriov->
+					VFs_assigned_cnt);
  }
  EXPORT_SYMBOL_GPL(pci_iov_assign_device);
 
@@ -660,6 +645,11 @@ EXPORT_SYMBOL_GPL(pci_iov_assign_device);
  void pci_iov_deassign_device(struct pci_dev *pdev)
  {
  	pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+	if (pdev->is_virtfn && !pdev->is_physfn)
+		if (pdev->physfn)
+			if (pdev->physfn->sriov)

same...

Quoted 17 lines
drivers/pci/iov.c +2 -0
+				atomic_dec(&pdev->physfn->sriov->
+					VFs_assigned_cnt);
  }
  EXPORT_SYMBOL_GPL(pci_iov_deassign_device);
 
drivers/pci/pci.h +1 -0
index 6bd0822..d17bda2 100644
@@ -235,6 +235,7 @@ struct pci_sriov {
  	u32 pgsz;		/* page size for BAR alignment */
  	u8 link;		/* Function Dependency Link */
  	u16 driver_max_VFs;	/* max num VFs driver supports */
+	atomic_t VFs_assigned_cnt; /* counter of VFs assigned to VM */
  	struct pci_dev *dev;	/* lowest numbered PF */
  	struct pci_dev *self;	/* this PF */
  	struct mutex lock;	/* lock for VF bus */
Signature · 15 lines
Regards,
Varka Bhadram.


------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
E1000-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel® Ethernet, visit http://communities.intel.com/community/wired
#3 lore raw

Re: [PATCH 2/2 V3] PCI: implement VFs assignment reference counter

Quoted 22 lines · Varka Bhadram
Quoted 5 lines · Ethan Zhao

Current implementation of helper function pci_vfs_assigned() is a little complex, to get sum of VFs that assigned to VM, access low level configuration space register and then loop in traversing device tree.

(...)

drivers/pci/iov.c EXPORT_SYMBOL_GPL(pci_vfs_assigned); · line 635

Quoted 7 lines
drivers/pci/iov.c +3 -0
@@ -650,6 +630,11 @@ EXPORT_SYMBOL_GPL(pci_vfs_assigned);
  void pci_iov_assign_device(struct pci_dev *pdev)
  {
        pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+       if (pdev->is_virtfn && !pdev->is_physfn)
+               if (pdev->physfn)
+                       if (pdev->physfn->sriov)

Why don't we make last two 'if' conditions into single 'if'

Quoted 1 line

if (pdev->physfn && pdev->physfn->sriov)

Yeah, this one looks better, that style used to tell myself, I might forget the which side of && operator first, if you sure left first, I prefer that too :>

Quoted 15 lines

drivers/pci/iov.c EXPORT_SYMBOL_GPL(pci_vfs_assigned); · line 635

Quoted 13 lines
drivers/pci/iov.c +2 -0
+                               atomic_inc(&pdev->physfn->sriov->
+                                       VFs_assigned_cnt);
  }
  EXPORT_SYMBOL_GPL(pci_iov_assign_device);
  @@ -660,6 +645,11 @@ EXPORT_SYMBOL_GPL(pci_iov_assign_device);
  void pci_iov_deassign_device(struct pci_dev *pdev)
  {
        pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
drivers/pci/iov.c +3 -0
+       if (pdev->is_virtfn && !pdev->is_physfn)
+               if (pdev->physfn)
+                       if (pdev->physfn->sriov)
Quoted 1 line

same...

same as above.

Thanks,
Ethan

Quoted 15 lines
Quoted 15 lines
drivers/pci/iov.c +2 -0
+                               atomic_dec(&pdev->physfn->sriov->
+                                       VFs_assigned_cnt);
  }
  EXPORT_SYMBOL_GPL(pci_iov_deassign_device);
  diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h

index 6bd0822..d17bda2 100644

drivers/pci/pci.h +1 -0
@@ -235,6 +235,7 @@ struct pci_sriov {
        u32 pgsz;               /* page size for BAR alignment */
        u8 link;                /* Function Dependency Link */
        u16 driver_max_VFs;     /* max num VFs driver supports */
+       atomic_t VFs_assigned_cnt; /* counter of VFs assigned to VM */
Quoted 9 lines

drivers/pci/pci.h struct pci_sriov { · line 241

Quoted 3 lines
drivers/pci/pci.h +0 -0
        struct pci_dev *dev;    /* lowest numbered PF */
        struct pci_dev *self;   /* this PF */
        struct mutex lock;      /* lock for VF bus */

--
Regards,
Varka Bhadram.

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
E1000-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel® Ethernet, visit http://communities.intel.com/community/wired

#4 lore raw

Re: [PATCH 2/2 V3] PCI: implement VFs assignment reference counter

Quoted 20 lines · Ethan Zhao
Quoted 19 lines · Varka Bhadram
Quoted 4 lines · Ethan Zhao

Current implementation of helper function pci_vfs_assigned() is a little complex, to get sum of VFs that assigned to VM, access low level configuration space register and then loop in traversing device tree.

(...)

drivers/pci/iov.c EXPORT_SYMBOL_GPL(pci_vfs_assigned); · line 635

Quoted 7 lines
drivers/pci/iov.c +3 -0
@@ -650,6 +630,11 @@ EXPORT_SYMBOL_GPL(pci_vfs_assigned);
   void pci_iov_assign_device(struct pci_dev *pdev)
   {
         pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+       if (pdev->is_virtfn && !pdev->is_physfn)
+               if (pdev->physfn)
+                       if (pdev->physfn->sriov)

Why don't we make last two 'if' conditions into single 'if'

Quoted 4 lines
Quoted 1 line

if (pdev->physfn && pdev->physfn->sriov)

Yeah, this one looks better, that style used to tell myself, I might forget the which side of && operator first, if you sure left first, I prefer that too :>

|for && operator - evaluation is from Left to Right|

Signature · 2 lines
Regards,
Varka Bhadram.

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse Turn processes into business applications with Bonita BPM Community Edition Quickly connect people, data, and systems into organized workflows Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft

_______________________________________________
E1000-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel® Ethernet, visit http://communities.intel.com/community/wired

#5 lore raw

Re: [PATCH 2/2 V3] PCI: implement VFs assignment reference counter

Quoted 25 lines · Varka Bhadram

On 07/11/2014 06:21 PM, Ethan Zhao wrote:

On Fri, Jul 11, 2014 at 8:42 PM, Varka Bhadram <[email protected]> wrote:

On 07/11/2014 06:00 PM, Ethan Zhao wrote:

Current implementation of helper function pci_vfs_assigned() is a little complex, to get sum of VFs that assigned to VM, access low level configuration space register and then loop in traversing device tree.

(...)

drivers/pci/iov.c +3 -0
@@ -650,6 +630,11 @@ EXPORT_SYMBOL_GPL(pci_vfs_assigned);
  void pci_iov_assign_device(struct pci_dev *pdev)
  {
        pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+       if (pdev->is_virtfn && !pdev->is_physfn)
+               if (pdev->physfn)
+                       if (pdev->physfn->sriov)
 

Why don't we make last two 'if' conditions into single 'if'

Quoted 7 lines

if (pdev->physfn && pdev->physfn->sriov)

Yeah, this one looks better, that style used to tell myself, I might forget the which side of && operator first, if you sure left first, I prefer that too :>

for && operator - evaluation is from Left to Right

Definitely right !

Thanks,
Ethan

Quoted 4 lines

--
Regards,
Varka Bhadram.

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
E1000-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel&#174; Ethernet, visit http://communities.intel.com/community/wired

#6 lore raw
In reply to Ethan Zhao
Quoted 18 lines · Ethan Zhao

This patch introduces two new device assignment functions

pci_iov_assign_device(),
pci_iov_deassign_device()

along with the existed one

pci_vfs_assigned()

They construct the VFs assignment management interface, used to assign/ deassign device to VM and query the VFs reference counter. instead of direct manipulation of device flag.

This patch refashioned the related code and make them atomic.

v3: change the naming of device assignment helpers, because they work for all kind of PCI device, not only SR-IOV ([email protected])

Quoted 6 lines

v2: reorder the patchset and make it bisectable and atomic, steps clear between interface defination and implemenation according to the suggestion from [email protected]

---

- Use a cover patch to describe the series

- Version information goes here, below the "---", not above it

- I stand by the patch breakdown I suggested originally, there are too many logical changes here in patch 1. There are easily 3 separate patches here.

- Renaming s/sriov/iov/ doesn't address the problem David raised. The name is still synonymous with SR-IOV and it's defined on drivers/pci/iov.c, which is only built with CONFIG_PCI_IOV.

- PCI_DEV_FLAGS_ASSIGNED should be unused after this series, why is it not removed?

Quoted 6 lines
 drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c |   17 ++---------------
 drivers/pci/iov.c                                  |   20 ++++++++++++++++++++
 drivers/xen/xen-pciback/pci_stub.c                 |    4 ++--
 include/linux/pci.h                                |    4 ++++
 virt/kvm/assigned-dev.c                            |    2 +-
 virt/kvm/iommu.c                                   |    4 ++--

- This patch touch 4 separate logical code areas, who do you expect to ack and commit it? Split it up.

Quoted 133 lines
 6 files changed, 31 insertions(+), 20 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +2 -15
index 02c11a7..781040e 100644
@@ -693,22 +693,9 @@ complete_reset:
 static bool i40e_vfs_are_assigned(struct i40e_pf *pf)
 {
 	struct pci_dev *pdev = pf->pdev;
-	struct pci_dev *vfdev;
-
-	/* loop through all the VFs to see if we own any that are assigned */
-	vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, I40E_DEV_ID_VF , NULL);
-	while (vfdev) {
-		/* if we don't own it we don't care */
-		if (vfdev->is_virtfn && pci_physfn(vfdev) == pdev) {
-			/* if it is assigned we cannot release it */
-			if (vfdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED)
-				return true;
-		}
 
-		vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
-				       I40E_DEV_ID_VF,
-				       vfdev);
-	}
+	if (pci_vfs_assigned(pdev))
+		return true;
 
 	return false;
 }
drivers/pci/iov.c +20 -0
index de7a747..090f827 100644
@@ -644,6 +644,26 @@ int pci_vfs_assigned(struct pci_dev *dev)
 EXPORT_SYMBOL_GPL(pci_vfs_assigned);
 
 /**
+ * pci_iov_assign_device - assign device to VM
+ * @pdev: the device to be assigned.
+ */
+void pci_iov_assign_device(struct pci_dev *pdev)
+{
+	pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_assign_device);
+
+/**
+ * pci_iov_deassign_device - deasign device from VM
+ * @pdev: the device to be deassigned.
+ */
+void pci_iov_deassign_device(struct pci_dev *pdev)
+{
+	pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_deassign_device);
+
+/**
  * pci_sriov_set_totalvfs -- reduce the TotalVFs available
  * @dev: the PCI PF device
  * @numvfs: number that should be used for TotalVFs supported
drivers/xen/xen-pciback/pci_stub.c +2 -2
index 62fcd48..27e00d1 100644
@@ -133,7 +133,7 @@ static void pcistub_device_release(struct kref *kref)
 	xen_pcibk_config_free_dyn_fields(dev);
 	xen_pcibk_config_free_dev(dev);
 
-	dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+	pci_iov_deassign_device(dev);
 	pci_dev_put(dev);
 
 	kfree(psdev);
@@ -404,7 +404,7 @@ static int pcistub_init_device(struct pci_dev *dev)
 	dev_dbg(&dev->dev, "reset device\n");
 	xen_pcibk_reset_device(dev);
 
-	dev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+	pci_iov_assign_device(dev);
 	return 0;
 
 config_release:
include/linux/pci.h +4 -0
index aab57b4..5ece6d6 100644
@@ -1603,6 +1603,8 @@ int pci_num_vf(struct pci_dev *dev);
 int pci_vfs_assigned(struct pci_dev *dev);
 int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs);
 int pci_sriov_get_totalvfs(struct pci_dev *dev);
+void pci_iov_assign_device(struct pci_dev *dev);
+void pci_iov_deassign_device(struct pci_dev *dev);
 #else
 static inline int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn)
 { return -ENODEV; }
@@ -1614,6 +1616,8 @@ static inline int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs)
 { return 0; }
 static inline int pci_sriov_get_totalvfs(struct pci_dev *dev)
 { return 0; }
+static inline void pci_iov_assign_device(struct pci_dev *dev) { }
+static inline void pci_iov_deassign_device(struct pci_dev *dev) { }
 #endif
 
 #if defined(CONFIG_HOTPLUG_PCI) || defined(CONFIG_HOTPLUG_PCI_MODULE)
virt/kvm/assigned-dev.c +1 -1
index bf06577..7fac58d 100644
@@ -302,7 +302,7 @@ static void kvm_free_assigned_device(struct kvm *kvm,
 	else
 		pci_restore_state(assigned_dev->dev);
 
-	assigned_dev->dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+	pci_iov_deassign_device(assigned_dev->dev);
 
 	pci_release_regions(assigned_dev->dev);
 	pci_disable_device(assigned_dev->dev);
virt/kvm/iommu.c +1 -1
index 0df7d4b..641ee73 100644
@@ -194,7 +194,7 @@ int kvm_assign_device(struct kvm *kvm,
 			goto out_unmap;
 	}
 
-	pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+	pci_iov_assign_device(pdev);
 
 	dev_info(&pdev->dev, "kvm assign device\n");
 

virt/kvm/iommu.c int kvm_deassign_device(struct kvm *kvm, · line 226

Quoted 8 lines
virt/kvm/iommu.c +1 -1
@@ -220,7 +220,7 @@ int kvm_deassign_device(struct kvm *kvm,
 
 	iommu_detach_device(domain, &pdev->dev);
 
-	pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+	pci_iov_deassign_device(pdev);
 
 	dev_info(&pdev->dev, "kvm deassign device\n");
 

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
E1000-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel&#174; Ethernet, visit http://communities.intel.com/community/wired

#7 lore raw
Quoted 34 lines · Alex Williamson
Quoted 18 lines · Ethan Zhao

This patch introduces two new device assignment functions

pci_iov_assign_device(),
pci_iov_deassign_device()

along with the existed one

pci_vfs_assigned()

They construct the VFs assignment management interface, used to assign/ deassign device to VM and query the VFs reference counter. instead of direct manipulation of device flag.

This patch refashioned the related code and make them atomic.

v3: change the naming of device assignment helpers, because they work for all kind of PCI device, not only SR-IOV ([email protected])

Quoted 6 lines

v2: reorder the patchset and make it bisectable and atomic, steps clear between interface defination and implemenation according to the suggestion from [email protected]

---

- Use a cover patch to describe the series

- Version information goes here, below the "---", not above it

- I stand by the patch breakdown I suggested originally, there are too many logical changes here in patch 1. There are easily 3 separate patches here.

Quoted 6 lines

- Renaming s/sriov/iov/ doesn't address the problem David raised. The name is still synonymous with SR-IOV and it's defined on drivers/pci/iov.c, which is only built with CONFIG_PCI_IOV.

- PCI_DEV_FLAGS_ASSIGNED should be unused after this series, why is it not removed?

I guess it's still used, which is even worse because now we have separate data elements, one tracking how many VFs are assigned from a PF and another tracking each device that's assigned. What are we actually gaining or fixing by doing this?

Quoted 144 lines
Quoted 6 lines
 drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c |   17 ++---------------
 drivers/pci/iov.c                                  |   20 ++++++++++++++++++++
 drivers/xen/xen-pciback/pci_stub.c                 |    4 ++--
 include/linux/pci.h                                |    4 ++++
 virt/kvm/assigned-dev.c                            |    2 +-
 virt/kvm/iommu.c                                   |    4 ++--

- This patch touch 4 separate logical code areas, who do you expect to ack and commit it? Split it up.

Quoted 134 lines
 6 files changed, 31 insertions(+), 20 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +2 -15
index 02c11a7..781040e 100644
@@ -693,22 +693,9 @@ complete_reset:
 static bool i40e_vfs_are_assigned(struct i40e_pf *pf)
 {
 	struct pci_dev *pdev = pf->pdev;
-	struct pci_dev *vfdev;
-
-	/* loop through all the VFs to see if we own any that are assigned */
-	vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, I40E_DEV_ID_VF , NULL);
-	while (vfdev) {
-		/* if we don't own it we don't care */
-		if (vfdev->is_virtfn && pci_physfn(vfdev) == pdev) {
-			/* if it is assigned we cannot release it */
-			if (vfdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED)
-				return true;
-		}
 
-		vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
-				       I40E_DEV_ID_VF,
-				       vfdev);
-	}
+	if (pci_vfs_assigned(pdev))
+		return true;
 
 	return false;
 }
drivers/pci/iov.c +20 -0
index de7a747..090f827 100644
@@ -644,6 +644,26 @@ int pci_vfs_assigned(struct pci_dev *dev)
 EXPORT_SYMBOL_GPL(pci_vfs_assigned);
 
 /**
+ * pci_iov_assign_device - assign device to VM
+ * @pdev: the device to be assigned.
+ */
+void pci_iov_assign_device(struct pci_dev *pdev)
+{
+	pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_assign_device);
+
+/**
+ * pci_iov_deassign_device - deasign device from VM
+ * @pdev: the device to be deassigned.
+ */
+void pci_iov_deassign_device(struct pci_dev *pdev)
+{
+	pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_deassign_device);
+
+/**
  * pci_sriov_set_totalvfs -- reduce the TotalVFs available
  * @dev: the PCI PF device
  * @numvfs: number that should be used for TotalVFs supported
drivers/xen/xen-pciback/pci_stub.c +2 -2
index 62fcd48..27e00d1 100644
@@ -133,7 +133,7 @@ static void pcistub_device_release(struct kref *kref)
 	xen_pcibk_config_free_dyn_fields(dev);
 	xen_pcibk_config_free_dev(dev);
 
-	dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+	pci_iov_deassign_device(dev);
 	pci_dev_put(dev);
 
 	kfree(psdev);
@@ -404,7 +404,7 @@ static int pcistub_init_device(struct pci_dev *dev)
 	dev_dbg(&dev->dev, "reset device\n");
 	xen_pcibk_reset_device(dev);
 
-	dev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+	pci_iov_assign_device(dev);
 	return 0;
 
 config_release:
include/linux/pci.h +4 -0
index aab57b4..5ece6d6 100644
@@ -1603,6 +1603,8 @@ int pci_num_vf(struct pci_dev *dev);
 int pci_vfs_assigned(struct pci_dev *dev);
 int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs);
 int pci_sriov_get_totalvfs(struct pci_dev *dev);
+void pci_iov_assign_device(struct pci_dev *dev);
+void pci_iov_deassign_device(struct pci_dev *dev);
 #else
 static inline int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn)
 { return -ENODEV; }
@@ -1614,6 +1616,8 @@ static inline int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs)
 { return 0; }
 static inline int pci_sriov_get_totalvfs(struct pci_dev *dev)
 { return 0; }
+static inline void pci_iov_assign_device(struct pci_dev *dev) { }
+static inline void pci_iov_deassign_device(struct pci_dev *dev) { }
 #endif
 
 #if defined(CONFIG_HOTPLUG_PCI) || defined(CONFIG_HOTPLUG_PCI_MODULE)
virt/kvm/assigned-dev.c +1 -1
index bf06577..7fac58d 100644
@@ -302,7 +302,7 @@ static void kvm_free_assigned_device(struct kvm *kvm,
 	else
 		pci_restore_state(assigned_dev->dev);
 
-	assigned_dev->dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+	pci_iov_deassign_device(assigned_dev->dev);
 
 	pci_release_regions(assigned_dev->dev);
 	pci_disable_device(assigned_dev->dev);
virt/kvm/iommu.c +1 -1
index 0df7d4b..641ee73 100644
@@ -194,7 +194,7 @@ int kvm_assign_device(struct kvm *kvm,
 			goto out_unmap;
 	}
 
-	pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+	pci_iov_assign_device(pdev);
 
 	dev_info(&pdev->dev, "kvm assign device\n");
 
@@ -220,7 +220,7 @@ int kvm_deassign_device(struct kvm *kvm,
 
Quoted 9 lines

virt/kvm/iommu.c int kvm_deassign_device(struct kvm *kvm, · line 226

Quoted 7 lines
virt/kvm/iommu.c +1 -1
 	iommu_detach_device(domain, &pdev->dev);
 
-	pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+	pci_iov_deassign_device(pdev);
 
 	dev_info(&pdev->dev, "kvm deassign device\n");
 

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
E1000-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel&#174; Ethernet, visit http://communities.intel.com/community/wired

#27 lore raw
In reply to Alex Williamson
Quoted 22 lines · 在 2014年7月11日,下午9:13,Alex Williamson <[email protected]> 写道:
Quoted 20 lines · Ethan Zhao

This patch introduces two new device assignment functions

pci_iov_assign_device(),
pci_iov_deassign_device()

along with the existed one

pci_vfs_assigned()

They construct the VFs assignment management interface, used to assign/ deassign device to VM and query the VFs reference counter. instead of direct manipulation of device flag.

This patch refashioned the related code and make them atomic.

v3: change the naming of device assignment helpers, because they work for all kind of PCI device, not only SR-IOV ([email protected])

Quoted 9 lines
Quoted 6 lines

v2: reorder the patchset and make it bisectable and atomic, steps clear between interface defination and implemenation according to the suggestion from [email protected]

---

- Use a cover patch to describe the series

Hmmm,

Quoted 6 lines

- Version information goes here, below the "---", not above it

- I stand by the patch breakdown I suggested originally, there are too many logical changes here in patch 1. There are easily 3 separate patches here.

You prefer v1 again ?

Quoted 4 lines

- Renaming s/sriov/iov/ doesn't address the problem David raised. The name is still synonymous with SR-IOV and it's defined on drivers/pci/iov.c, which is only built with CONFIG_PCI_IOV.

This is real issue, the interface should work without CONFIG_PCI_IOV defined.
Should be fixed.

Quoted 2 lines

- PCI_DEV_FLAGS_ASSIGNED should be unused after this series, why is it not removed?

you wanna do all things in one step ? Be practical. That is not my original purpose.

Quoted 11 lines
Quoted 7 lines
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c |   17 ++---------------
drivers/pci/iov.c                                  |   20 ++++++++++++++++++++
drivers/xen/xen-pciback/pci_stub.c                 |    4 ++--
include/linux/pci.h                                |    4 ++++
virt/kvm/assigned-dev.c                            |    2 +-
virt/kvm/iommu.c                                   |    4 ++--

- This patch touch 4 separate logical code areas, who do you expect to ack and commit it? Split it up.

Such would go back to the v1, four patches, if one lost to be committed, kernel could be buggy.

Quoted 132 lines
Quoted 132 lines
6 files changed, 31 insertions(+), 20 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +2 -15
index 02c11a7..781040e 100644
@@ -693,22 +693,9 @@ complete_reset:
 static bool i40e_vfs_are_assigned(struct i40e_pf *pf)
 {
   struct pci_dev *pdev = pf->pdev;
-    struct pci_dev *vfdev;
-
-    /* loop through all the VFs to see if we own any that are assigned */
-    vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, I40E_DEV_ID_VF , NULL);
-    while (vfdev) {
-        /* if we don't own it we don't care */
-        if (vfdev->is_virtfn && pci_physfn(vfdev) == pdev) {
-            /* if it is assigned we cannot release it */
-            if (vfdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED)
-                return true;
-        }
 
-        vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
-                       I40E_DEV_ID_VF,
-                       vfdev);
-    }
+    if (pci_vfs_assigned(pdev))
+        return true;
 
   return false;
 }
drivers/pci/iov.c +20 -0
index de7a747..090f827 100644
@@ -644,6 +644,26 @@ int pci_vfs_assigned(struct pci_dev *dev)
 EXPORT_SYMBOL_GPL(pci_vfs_assigned);
 
 /**
+ * pci_iov_assign_device - assign device to VM
+ * @pdev: the device to be assigned.
+ */
+void pci_iov_assign_device(struct pci_dev *pdev)
+{
+    pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_assign_device);
+
+/**
+ * pci_iov_deassign_device - deasign device from VM
+ * @pdev: the device to be deassigned.
+ */
+void pci_iov_deassign_device(struct pci_dev *pdev)
+{
+    pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_deassign_device);
+
+/**
 * pci_sriov_set_totalvfs -- reduce the TotalVFs available
 * @dev: the PCI PF device
 * @numvfs: number that should be used for TotalVFs supported
drivers/xen/xen-pciback/pci_stub.c +2 -2
index 62fcd48..27e00d1 100644
@@ -133,7 +133,7 @@ static void pcistub_device_release(struct kref *kref)
   xen_pcibk_config_free_dyn_fields(dev);
   xen_pcibk_config_free_dev(dev);
 
-    dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(dev);
   pci_dev_put(dev);
 
   kfree(psdev);
@@ -404,7 +404,7 @@ static int pcistub_init_device(struct pci_dev *dev)
   dev_dbg(&dev->dev, "reset device\n");
   xen_pcibk_reset_device(dev);
 
-    dev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_assign_device(dev);
   return 0;
 

config_release:

include/linux/pci.h +4 -0
index aab57b4..5ece6d6 100644
@@ -1603,6 +1603,8 @@ int pci_num_vf(struct pci_dev *dev);
 int pci_vfs_assigned(struct pci_dev *dev);
 int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs);
 int pci_sriov_get_totalvfs(struct pci_dev *dev);
+void pci_iov_assign_device(struct pci_dev *dev);
+void pci_iov_deassign_device(struct pci_dev *dev);
 #else
 static inline int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn)
 { return -ENODEV; }
@@ -1614,6 +1616,8 @@ static inline int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs)
 { return 0; }
 static inline int pci_sriov_get_totalvfs(struct pci_dev *dev)
 { return 0; }
+static inline void pci_iov_assign_device(struct pci_dev *dev) { }
+static inline void pci_iov_deassign_device(struct pci_dev *dev) { }
 #endif
 
 #if defined(CONFIG_HOTPLUG_PCI) || defined(CONFIG_HOTPLUG_PCI_MODULE)
virt/kvm/assigned-dev.c +1 -1
index bf06577..7fac58d 100644
@@ -302,7 +302,7 @@ static void kvm_free_assigned_device(struct kvm *kvm,
   else
       pci_restore_state(assigned_dev->dev);
 
-    assigned_dev->dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(assigned_dev->dev);
 
   pci_release_regions(assigned_dev->dev);
   pci_disable_device(assigned_dev->dev);
virt/kvm/iommu.c +1 -1
index 0df7d4b..641ee73 100644
@@ -194,7 +194,7 @@ int kvm_assign_device(struct kvm *kvm,
           goto out_unmap;
   }
 
-    pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_assign_device(pdev);
 
   dev_info(&pdev->dev, "kvm assign device\n");
 
Quoted 11 lines

virt/kvm/iommu.c int kvm_deassign_device(struct kvm *kvm, · line 225

Quoted 8 lines
virt/kvm/iommu.c +1 -1
@@ -220,7 +220,7 @@ int kvm_deassign_device(struct kvm *kvm,
 
   iommu_detach_device(domain, &pdev->dev);
 
-    pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(pdev);
 
   dev_info(&pdev->dev, "kvm deassign device\n");

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
E1000-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel&#174; Ethernet, visit http://communities.intel.com/community/wired

#8 lore raw
In reply to Alex Williamson
Quoted 43 lines · 在 2014年7月11日,下午10:15,Alex Williamson <[email protected]> 写道:
Quoted 40 lines · Alex Williamson
Quoted 19 lines · Ethan Zhao

This patch introduces two new device assignment functions

pci_iov_assign_device(),
pci_iov_deassign_device()

along with the existed one

pci_vfs_assigned()

They construct the VFs assignment management interface, used to assign/ deassign device to VM and query the VFs reference counter. instead of direct manipulation of device flag.

This patch refashioned the related code and make them atomic.

v3: change the naming of device assignment helpers, because they work for all kind of PCI device, not only SR-IOV ([email protected])

Quoted 6 lines

v2: reorder the patchset and make it bisectable and atomic, steps clear between interface defination and implemenation according to the suggestion from [email protected]

---

- Use a cover patch to describe the series

- Version information goes here, below the "---", not above it

- I stand by the patch breakdown I suggested originally, there are too many logical changes here in patch 1. There are easily 3 separate patches here.

- Renaming s/sriov/iov/ doesn't address the problem David raised. The name is still synonymous with SR-IOV and it's defined on drivers/pci/iov.c, which is only built with CONFIG_PCI_IOV.

Quoted 8 lines
Quoted 2 lines

- PCI_DEV_FLAGS_ASSIGNED should be unused after this series, why is it not removed?

I guess it's still used, which is even worse because now we have separate data elements, one tracking how many VFs are assigned from a PF and another tracking each device that's assigned. What are we actually gaining or fixing by doing this?

Of course it is used to tracking PF/VF assigned, what we gained are - we hide the details In assignment helpers, we wouldn't bother the users anymore and implement what inside The helpers, my initial purpose is to simplify the ugly pci_vfs_assigned() with counter.

I don't want to push more change in one step, that would out of control to get perfect result.

Quoted 142 lines
Quoted 142 lines
Quoted 6 lines
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c |   17 ++---------------
drivers/pci/iov.c                                  |   20 ++++++++++++++++++++
drivers/xen/xen-pciback/pci_stub.c                 |    4 ++--
include/linux/pci.h                                |    4 ++++
virt/kvm/assigned-dev.c                            |    2 +-
virt/kvm/iommu.c                                   |    4 ++--

- This patch touch 4 separate logical code areas, who do you expect to ack and commit it? Split it up.

Quoted 132 lines
6 files changed, 31 insertions(+), 20 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +2 -15
index 02c11a7..781040e 100644
@@ -693,22 +693,9 @@ complete_reset:
 static bool i40e_vfs_are_assigned(struct i40e_pf *pf)
 {
   struct pci_dev *pdev = pf->pdev;
-    struct pci_dev *vfdev;
-
-    /* loop through all the VFs to see if we own any that are assigned */
-    vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, I40E_DEV_ID_VF , NULL);
-    while (vfdev) {
-        /* if we don't own it we don't care */
-        if (vfdev->is_virtfn && pci_physfn(vfdev) == pdev) {
-            /* if it is assigned we cannot release it */
-            if (vfdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED)
-                return true;
-        }
 
-        vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
-                       I40E_DEV_ID_VF,
-                       vfdev);
-    }
+    if (pci_vfs_assigned(pdev))
+        return true;
 
   return false;
 }
drivers/pci/iov.c +20 -0
index de7a747..090f827 100644
@@ -644,6 +644,26 @@ int pci_vfs_assigned(struct pci_dev *dev)
 EXPORT_SYMBOL_GPL(pci_vfs_assigned);
 
 /**
+ * pci_iov_assign_device - assign device to VM
+ * @pdev: the device to be assigned.
+ */
+void pci_iov_assign_device(struct pci_dev *pdev)
+{
+    pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_assign_device);
+
+/**
+ * pci_iov_deassign_device - deasign device from VM
+ * @pdev: the device to be deassigned.
+ */
+void pci_iov_deassign_device(struct pci_dev *pdev)
+{
+    pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_deassign_device);
+
+/**
 * pci_sriov_set_totalvfs -- reduce the TotalVFs available
 * @dev: the PCI PF device
 * @numvfs: number that should be used for TotalVFs supported
drivers/xen/xen-pciback/pci_stub.c +2 -2
index 62fcd48..27e00d1 100644
@@ -133,7 +133,7 @@ static void pcistub_device_release(struct kref *kref)
   xen_pcibk_config_free_dyn_fields(dev);
   xen_pcibk_config_free_dev(dev);
 
-    dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(dev);
   pci_dev_put(dev);
 
   kfree(psdev);
@@ -404,7 +404,7 @@ static int pcistub_init_device(struct pci_dev *dev)
   dev_dbg(&dev->dev, "reset device\n");
   xen_pcibk_reset_device(dev);
 
-    dev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_assign_device(dev);
   return 0;
 

config_release:

include/linux/pci.h +4 -0
index aab57b4..5ece6d6 100644
@@ -1603,6 +1603,8 @@ int pci_num_vf(struct pci_dev *dev);
 int pci_vfs_assigned(struct pci_dev *dev);
 int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs);
 int pci_sriov_get_totalvfs(struct pci_dev *dev);
+void pci_iov_assign_device(struct pci_dev *dev);
+void pci_iov_deassign_device(struct pci_dev *dev);
 #else
 static inline int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn)
 { return -ENODEV; }
@@ -1614,6 +1616,8 @@ static inline int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs)
 { return 0; }
 static inline int pci_sriov_get_totalvfs(struct pci_dev *dev)
 { return 0; }
+static inline void pci_iov_assign_device(struct pci_dev *dev) { }
+static inline void pci_iov_deassign_device(struct pci_dev *dev) { }
 #endif
 
 #if defined(CONFIG_HOTPLUG_PCI) || defined(CONFIG_HOTPLUG_PCI_MODULE)
virt/kvm/assigned-dev.c +1 -1
index bf06577..7fac58d 100644
@@ -302,7 +302,7 @@ static void kvm_free_assigned_device(struct kvm *kvm,
   else
       pci_restore_state(assigned_dev->dev);
 
-    assigned_dev->dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(assigned_dev->dev);
 
   pci_release_regions(assigned_dev->dev);
   pci_disable_device(assigned_dev->dev);
virt/kvm/iommu.c +1 -1
index 0df7d4b..641ee73 100644
@@ -194,7 +194,7 @@ int kvm_assign_device(struct kvm *kvm,
           goto out_unmap;
   }
 
-    pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_assign_device(pdev);
 
   dev_info(&pdev->dev, "kvm assign device\n");
 
Quoted 11 lines
Quoted 8 lines

virt/kvm/iommu.c int kvm_deassign_device(struct kvm *kvm, · line 225

Quoted 8 lines
virt/kvm/iommu.c +1 -1
@@ -220,7 +220,7 @@ int kvm_deassign_device(struct kvm *kvm,
 
   iommu_detach_device(domain, &pdev->dev);
 
-    pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(pdev);
 
   dev_info(&pdev->dev, "kvm deassign device\n");

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
E1000-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel&#174; Ethernet, visit http://communities.intel.com/community/wired

#28 lore raw
In reply to Ethan Zhao
Quoted 30 lines · Ethan Zhao
Quoted 21 lines · 在 2014年7月11日,下午9:13,Alex Williamson <[email protected]> 写道:
Quoted 20 lines · Ethan Zhao

This patch introduces two new device assignment functions

pci_iov_assign_device(),
pci_iov_deassign_device()

along with the existed one

pci_vfs_assigned()

They construct the VFs assignment management interface, used to assign/ deassign device to VM and query the VFs reference counter. instead of direct manipulation of device flag.

This patch refashioned the related code and make them atomic.

v3: change the naming of device assignment helpers, because they work for all kind of PCI device, not only SR-IOV ([email protected])

Quoted 9 lines
Quoted 6 lines

v2: reorder the patchset and make it bisectable and atomic, steps clear between interface defination and implemenation according to the suggestion from [email protected]

---

- Use a cover patch to describe the series

Quoted 8 lines

Hmmm,

Quoted 6 lines

- Version information goes here, below the "---", not above it

- I stand by the patch breakdown I suggested originally, there are too many logical changes here in patch 1. There are easily 3 separate patches here.

You prefer v1 again ?

That's not at all what I'm suggesting. In response to v1 I suggested a specific reordering that would allow the series to be bisectable. I'm surprised to see v2 ignored that and combined the first 3 suggested patches.

Quoted 10 lines
Quoted 4 lines

- Renaming s/sriov/iov/ doesn't address the problem David raised. The name is still synonymous with SR-IOV and it's defined on drivers/pci/iov.c, which is only built with CONFIG_PCI_IOV.

This is real issue, the interface should work without CONFIG_PCI_IOV defined.
Should be fixed.

Quoted 2 lines

- PCI_DEV_FLAGS_ASSIGNED should be unused after this series, why is it not removed?

you wanna do all things in one step ? Be practical. That is not my original purpose.

I never suggested collapsing steps. Maybe I'd understand the original purpose better if there was an overall description in a cover patch.

Quoted 11 lines
Quoted 10 lines
Quoted 6 lines
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c |   17 ++---------------
drivers/pci/iov.c                                  |   20 ++++++++++++++++++++
drivers/xen/xen-pciback/pci_stub.c                 |    4 ++--
include/linux/pci.h                                |    4 ++++
virt/kvm/assigned-dev.c                            |    2 +-
virt/kvm/iommu.c                                   |    4 ++--

- This patch touch 4 separate logical code areas, who do you expect to ack and commit it? Split it up.

Such would go back to the v1, four patches, if one lost to be committed, kernel could be buggy.

There seems to be confusion between multiple patches, which is fine, and the patch ordering from v1, which is wrong.

Quoted 136 lines
Quoted 136 lines
Quoted 136 lines
6 files changed, 31 insertions(+), 20 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +2 -15
index 02c11a7..781040e 100644
@@ -693,22 +693,9 @@ complete_reset:
 static bool i40e_vfs_are_assigned(struct i40e_pf *pf)
 {
   struct pci_dev *pdev = pf->pdev;
-    struct pci_dev *vfdev;
-
-    /* loop through all the VFs to see if we own any that are assigned */
-    vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, I40E_DEV_ID_VF , NULL);
-    while (vfdev) {
-        /* if we don't own it we don't care */
-        if (vfdev->is_virtfn && pci_physfn(vfdev) == pdev) {
-            /* if it is assigned we cannot release it */
-            if (vfdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED)
-                return true;
-        }
 
-        vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
-                       I40E_DEV_ID_VF,
-                       vfdev);
-    }
+    if (pci_vfs_assigned(pdev))
+        return true;
 
   return false;
 }
drivers/pci/iov.c +20 -0
index de7a747..090f827 100644
@@ -644,6 +644,26 @@ int pci_vfs_assigned(struct pci_dev *dev)
 EXPORT_SYMBOL_GPL(pci_vfs_assigned);
 
 /**
+ * pci_iov_assign_device - assign device to VM
+ * @pdev: the device to be assigned.
+ */
+void pci_iov_assign_device(struct pci_dev *pdev)
+{
+    pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_assign_device);
+
+/**
+ * pci_iov_deassign_device - deasign device from VM
+ * @pdev: the device to be deassigned.
+ */
+void pci_iov_deassign_device(struct pci_dev *pdev)
+{
+    pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_deassign_device);
+
+/**
 * pci_sriov_set_totalvfs -- reduce the TotalVFs available
 * @dev: the PCI PF device
 * @numvfs: number that should be used for TotalVFs supported
drivers/xen/xen-pciback/pci_stub.c +2 -2
index 62fcd48..27e00d1 100644
@@ -133,7 +133,7 @@ static void pcistub_device_release(struct kref *kref)
   xen_pcibk_config_free_dyn_fields(dev);
   xen_pcibk_config_free_dev(dev);
 
-    dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(dev);
   pci_dev_put(dev);
 
   kfree(psdev);
@@ -404,7 +404,7 @@ static int pcistub_init_device(struct pci_dev *dev)
   dev_dbg(&dev->dev, "reset device\n");
   xen_pcibk_reset_device(dev);
 
-    dev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_assign_device(dev);
   return 0;
 

config_release:

include/linux/pci.h +4 -0
index aab57b4..5ece6d6 100644
@@ -1603,6 +1603,8 @@ int pci_num_vf(struct pci_dev *dev);
 int pci_vfs_assigned(struct pci_dev *dev);
 int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs);
 int pci_sriov_get_totalvfs(struct pci_dev *dev);
+void pci_iov_assign_device(struct pci_dev *dev);
+void pci_iov_deassign_device(struct pci_dev *dev);
 #else
 static inline int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn)
 { return -ENODEV; }
@@ -1614,6 +1616,8 @@ static inline int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs)
 { return 0; }
 static inline int pci_sriov_get_totalvfs(struct pci_dev *dev)
 { return 0; }
+static inline void pci_iov_assign_device(struct pci_dev *dev) { }
+static inline void pci_iov_deassign_device(struct pci_dev *dev) { }
 #endif
 
 #if defined(CONFIG_HOTPLUG_PCI) || defined(CONFIG_HOTPLUG_PCI_MODULE)
virt/kvm/assigned-dev.c +1 -1
index bf06577..7fac58d 100644
@@ -302,7 +302,7 @@ static void kvm_free_assigned_device(struct kvm *kvm,
   else
       pci_restore_state(assigned_dev->dev);
 
-    assigned_dev->dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(assigned_dev->dev);
 
   pci_release_regions(assigned_dev->dev);
   pci_disable_device(assigned_dev->dev);
virt/kvm/iommu.c +1 -1
index 0df7d4b..641ee73 100644
@@ -194,7 +194,7 @@ int kvm_assign_device(struct kvm *kvm,
           goto out_unmap;
   }
 
-    pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_assign_device(pdev);
 
   dev_info(&pdev->dev, "kvm assign device\n");
 
@@ -220,7 +220,7 @@ int kvm_deassign_device(struct kvm *kvm,
 
   iommu_detach_device(domain, &pdev->dev);
 
Quoted 7 lines
Quoted 7 lines

virt/kvm/iommu.c int kvm_deassign_device(struct kvm *kvm, · line 225

Quoted 4 lines
virt/kvm/iommu.c +1 -1
-    pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(pdev);
 
   dev_info(&pdev->dev, "kvm deassign device\n");

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
E1000-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel&#174; Ethernet, visit http://communities.intel.com/community/wired

#9 lore raw
In reply to Ethan Zhao
Quoted 51 lines · Ethan Zhao
Quoted 42 lines · 在 2014年7月11日,下午10:15,Alex Williamson <[email protected]> 写道:
Quoted 40 lines · Alex Williamson
Quoted 19 lines · Ethan Zhao

This patch introduces two new device assignment functions

pci_iov_assign_device(),
pci_iov_deassign_device()

along with the existed one

pci_vfs_assigned()

They construct the VFs assignment management interface, used to assign/ deassign device to VM and query the VFs reference counter. instead of direct manipulation of device flag.

This patch refashioned the related code and make them atomic.

v3: change the naming of device assignment helpers, because they work for all kind of PCI device, not only SR-IOV ([email protected])

Quoted 6 lines

v2: reorder the patchset and make it bisectable and atomic, steps clear between interface defination and implemenation according to the suggestion from [email protected]

---

- Use a cover patch to describe the series

- Version information goes here, below the "---", not above it

- I stand by the patch breakdown I suggested originally, there are too many logical changes here in patch 1. There are easily 3 separate patches here.

- Renaming s/sriov/iov/ doesn't address the problem David raised. The name is still synonymous with SR-IOV and it's defined on drivers/pci/iov.c, which is only built with CONFIG_PCI_IOV.

Quoted 8 lines
Quoted 2 lines

- PCI_DEV_FLAGS_ASSIGNED should be unused after this series, why is it not removed?

I guess it's still used, which is even worse because now we have separate data elements, one tracking how many VFs are assigned from a PF and another tracking each device that's assigned. What are we actually gaining or fixing by doing this?

Quoted 5 lines

Of course it is used to tracking PF/VF assigned, what we gained are - we hide the details In assignment helpers, we wouldn't bother the users anymore and implement what inside The helpers, my initial purpose is to simplify the ugly pci_vfs_assigned() with counter.

I don't want to push more change in one step, that would out of control to get perfect result.

But a counter means that we're tracking the data in two separate places, which is generally a bad idea. Cleaning up direct access to flags is fine, but creating a separate counter doesn't really seem to add any value.

Quoted 146 lines
Quoted 146 lines
Quoted 146 lines
Quoted 6 lines
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c |   17 ++---------------
drivers/pci/iov.c                                  |   20 ++++++++++++++++++++
drivers/xen/xen-pciback/pci_stub.c                 |    4 ++--
include/linux/pci.h                                |    4 ++++
virt/kvm/assigned-dev.c                            |    2 +-
virt/kvm/iommu.c                                   |    4 ++--

- This patch touch 4 separate logical code areas, who do you expect to ack and commit it? Split it up.

Quoted 136 lines
6 files changed, 31 insertions(+), 20 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +2 -15
index 02c11a7..781040e 100644
@@ -693,22 +693,9 @@ complete_reset:
 static bool i40e_vfs_are_assigned(struct i40e_pf *pf)
 {
   struct pci_dev *pdev = pf->pdev;
-    struct pci_dev *vfdev;
-
-    /* loop through all the VFs to see if we own any that are assigned */
-    vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, I40E_DEV_ID_VF , NULL);
-    while (vfdev) {
-        /* if we don't own it we don't care */
-        if (vfdev->is_virtfn && pci_physfn(vfdev) == pdev) {
-            /* if it is assigned we cannot release it */
-            if (vfdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED)
-                return true;
-        }
 
-        vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
-                       I40E_DEV_ID_VF,
-                       vfdev);
-    }
+    if (pci_vfs_assigned(pdev))
+        return true;
 
   return false;
 }
drivers/pci/iov.c +20 -0
index de7a747..090f827 100644
@@ -644,6 +644,26 @@ int pci_vfs_assigned(struct pci_dev *dev)
 EXPORT_SYMBOL_GPL(pci_vfs_assigned);
 
 /**
+ * pci_iov_assign_device - assign device to VM
+ * @pdev: the device to be assigned.
+ */
+void pci_iov_assign_device(struct pci_dev *pdev)
+{
+    pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_assign_device);
+
+/**
+ * pci_iov_deassign_device - deasign device from VM
+ * @pdev: the device to be deassigned.
+ */
+void pci_iov_deassign_device(struct pci_dev *pdev)
+{
+    pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_deassign_device);
+
+/**
 * pci_sriov_set_totalvfs -- reduce the TotalVFs available
 * @dev: the PCI PF device
 * @numvfs: number that should be used for TotalVFs supported
drivers/xen/xen-pciback/pci_stub.c +2 -2
index 62fcd48..27e00d1 100644
@@ -133,7 +133,7 @@ static void pcistub_device_release(struct kref *kref)
   xen_pcibk_config_free_dyn_fields(dev);
   xen_pcibk_config_free_dev(dev);
 
-    dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(dev);
   pci_dev_put(dev);
 
   kfree(psdev);
@@ -404,7 +404,7 @@ static int pcistub_init_device(struct pci_dev *dev)
   dev_dbg(&dev->dev, "reset device\n");
   xen_pcibk_reset_device(dev);
 
-    dev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_assign_device(dev);
   return 0;
 

config_release:

include/linux/pci.h +4 -0
index aab57b4..5ece6d6 100644
@@ -1603,6 +1603,8 @@ int pci_num_vf(struct pci_dev *dev);
 int pci_vfs_assigned(struct pci_dev *dev);
 int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs);
 int pci_sriov_get_totalvfs(struct pci_dev *dev);
+void pci_iov_assign_device(struct pci_dev *dev);
+void pci_iov_deassign_device(struct pci_dev *dev);
 #else
 static inline int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn)
 { return -ENODEV; }
@@ -1614,6 +1616,8 @@ static inline int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs)
 { return 0; }
 static inline int pci_sriov_get_totalvfs(struct pci_dev *dev)
 { return 0; }
+static inline void pci_iov_assign_device(struct pci_dev *dev) { }
+static inline void pci_iov_deassign_device(struct pci_dev *dev) { }
 #endif
 
 #if defined(CONFIG_HOTPLUG_PCI) || defined(CONFIG_HOTPLUG_PCI_MODULE)
virt/kvm/assigned-dev.c +1 -1
index bf06577..7fac58d 100644
@@ -302,7 +302,7 @@ static void kvm_free_assigned_device(struct kvm *kvm,
   else
       pci_restore_state(assigned_dev->dev);
 
-    assigned_dev->dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(assigned_dev->dev);
 
   pci_release_regions(assigned_dev->dev);
   pci_disable_device(assigned_dev->dev);
virt/kvm/iommu.c +1 -1
index 0df7d4b..641ee73 100644
@@ -194,7 +194,7 @@ int kvm_assign_device(struct kvm *kvm,
           goto out_unmap;
   }
 
-    pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_assign_device(pdev);
 
   dev_info(&pdev->dev, "kvm assign device\n");
 
@@ -220,7 +220,7 @@ int kvm_deassign_device(struct kvm *kvm,
 
   iommu_detach_device(domain, &pdev->dev);
 
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

virt/kvm/iommu.c int kvm_deassign_device(struct kvm *kvm, · line 225

Quoted 4 lines
virt/kvm/iommu.c +1 -1
-    pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(pdev);
 
   dev_info(&pdev->dev, "kvm deassign device\n");

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
E1000-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel&#174; Ethernet, visit http://communities.intel.com/community/wired

#29 lore raw
In reply to Alex Williamson
Quoted 40 lines · 在 2014年7月11日,下午10:50,Alex Williamson <[email protected]> 写道:
Quoted 35 lines · Ethan Zhao
Quoted 21 lines · 在 2014年7月11日,下午9:13,Alex Williamson <[email protected]> 写道:
Quoted 20 lines · Ethan Zhao

This patch introduces two new device assignment functions

pci_iov_assign_device(),
pci_iov_deassign_device()

along with the existed one

pci_vfs_assigned()

They construct the VFs assignment management interface, used to assign/ deassign device to VM and query the VFs reference counter. instead of direct manipulation of device flag.

This patch refashioned the related code and make them atomic.

v3: change the naming of device assignment helpers, because they work for all kind of PCI device, not only SR-IOV ([email protected])

Quoted 8 lines
Quoted 6 lines

v2: reorder the patchset and make it bisectable and atomic, steps clear between interface defination and implemenation according to the suggestion from [email protected]

---

- Use a cover patch to describe the series

Hmmm,

Quoted 5 lines

- Version information goes here, below the "---", not above it

- I stand by the patch breakdown I suggested originally, there are too many logical changes here in patch 1. There are easily 3 separate patches here.

Quoted 6 lines
Quoted 1 line

You prefer v1 again ?

That's not at all what I'm suggesting. In response to v1 I suggested a specific reordering that would allow the series to be bisectable. I'm surprised to see v2 ignored that and combined the first 3 suggested patches.

If what I understand right. Your points are.
1. To be bisectable.
Combine the code into 2 parches, is really bisect able, without 2, 1 works right. If 1 was broken into 3, any of them is lost, buggy. They must work together.

2. Define and abstract first then implement.
1 &. 2 follows this point.

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

- Renaming s/sriov/iov/ doesn't address the problem David raised. The name is still synonymous with SR-IOV and it's defined on drivers/pci/iov.c, which is only built with CONFIG_PCI_IOV.

This is real issue, the interface should work without CONFIG_PCI_IOV defined. Should be fixed.

Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

- PCI_DEV_FLAGS_ASSIGNED should be unused after this series, why is it not removed?

you wanna do all things in one step ? Be practical. That is not my original purpose.

I never suggested collapsing steps. Maybe I'd understand the original purpose better if there was an overall description in a cover patch.

Compose a cover letter seems necessary to describe patch set if they are too complex.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c |   17 ++---------------
drivers/pci/iov.c                                  |   20 ++++++++++++++++++++
drivers/xen/xen-pciback/pci_stub.c                 |    4 ++--
include/linux/pci.h                                |    4 ++++
virt/kvm/assigned-dev.c                            |    2 +-
virt/kvm/iommu.c                                   |    4 ++--
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

- This patch touch 4 separate logical code areas, who do you expect to ack and commit it? Split it up.

Such would go back to the v1, four patches, if one lost to be committed, kernel could be buggy.

There seems to be confusion between multiple patches, which is fine, and the patch ordering from v1, which is wrong.

Do you want them work standalone, if no, the confusion is nothing.

Quoted 132 lines
Quoted 132 lines
Quoted 132 lines
Quoted 132 lines
6 files changed, 31 insertions(+), 20 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +2 -15
index 02c11a7..781040e 100644
@@ -693,22 +693,9 @@ complete_reset:
 static bool i40e_vfs_are_assigned(struct i40e_pf *pf)
 {
  struct pci_dev *pdev = pf->pdev;
-    struct pci_dev *vfdev;
-
-    /* loop through all the VFs to see if we own any that are assigned */
-    vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, I40E_DEV_ID_VF , NULL);
-    while (vfdev) {
-        /* if we don't own it we don't care */
-        if (vfdev->is_virtfn && pci_physfn(vfdev) == pdev) {
-            /* if it is assigned we cannot release it */
-            if (vfdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED)
-                return true;
-        }
 
-        vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
-                       I40E_DEV_ID_VF,
-                       vfdev);
-    }
+    if (pci_vfs_assigned(pdev))
+        return true;
 
  return false;
 }
drivers/pci/iov.c +20 -0
index de7a747..090f827 100644
@@ -644,6 +644,26 @@ int pci_vfs_assigned(struct pci_dev *dev)
 EXPORT_SYMBOL_GPL(pci_vfs_assigned);
 
 /**
+ * pci_iov_assign_device - assign device to VM
+ * @pdev: the device to be assigned.
+ */
+void pci_iov_assign_device(struct pci_dev *pdev)
+{
+    pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_assign_device);
+
+/**
+ * pci_iov_deassign_device - deasign device from VM
+ * @pdev: the device to be deassigned.
+ */
+void pci_iov_deassign_device(struct pci_dev *pdev)
+{
+    pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_deassign_device);
+
+/**
 * pci_sriov_set_totalvfs -- reduce the TotalVFs available
 * @dev: the PCI PF device
 * @numvfs: number that should be used for TotalVFs supported
drivers/xen/xen-pciback/pci_stub.c +2 -2
index 62fcd48..27e00d1 100644
@@ -133,7 +133,7 @@ static void pcistub_device_release(struct kref *kref)
  xen_pcibk_config_free_dyn_fields(dev);
  xen_pcibk_config_free_dev(dev);
 
-    dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(dev);
  pci_dev_put(dev);
 
  kfree(psdev);
@@ -404,7 +404,7 @@ static int pcistub_init_device(struct pci_dev *dev)
  dev_dbg(&dev->dev, "reset device\n");
  xen_pcibk_reset_device(dev);
 
-    dev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_assign_device(dev);
  return 0;
 

config_release:

include/linux/pci.h +4 -0
index aab57b4..5ece6d6 100644
@@ -1603,6 +1603,8 @@ int pci_num_vf(struct pci_dev *dev);
 int pci_vfs_assigned(struct pci_dev *dev);
 int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs);
 int pci_sriov_get_totalvfs(struct pci_dev *dev);
+void pci_iov_assign_device(struct pci_dev *dev);
+void pci_iov_deassign_device(struct pci_dev *dev);
 #else
 static inline int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn)
 { return -ENODEV; }
@@ -1614,6 +1616,8 @@ static inline int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs)
 { return 0; }
 static inline int pci_sriov_get_totalvfs(struct pci_dev *dev)
 { return 0; }
+static inline void pci_iov_assign_device(struct pci_dev *dev) { }
+static inline void pci_iov_deassign_device(struct pci_dev *dev) { }
 #endif
 
 #if defined(CONFIG_HOTPLUG_PCI) || defined(CONFIG_HOTPLUG_PCI_MODULE)
virt/kvm/assigned-dev.c +1 -1
index bf06577..7fac58d 100644
@@ -302,7 +302,7 @@ static void kvm_free_assigned_device(struct kvm *kvm,
  else
      pci_restore_state(assigned_dev->dev);
 
-    assigned_dev->dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(assigned_dev->dev);
 
  pci_release_regions(assigned_dev->dev);
  pci_disable_device(assigned_dev->dev);
virt/kvm/iommu.c +1 -1
index 0df7d4b..641ee73 100644
@@ -194,7 +194,7 @@ int kvm_assign_device(struct kvm *kvm,
          goto out_unmap;
  }
 
-    pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_assign_device(pdev);
 
  dev_info(&pdev->dev, "kvm assign device\n");
 
Quoted 11 lines
Quoted 8 lines
Quoted 8 lines

virt/kvm/iommu.c int kvm_deassign_device(struct kvm *kvm, · line 225

Quoted 8 lines
virt/kvm/iommu.c +1 -1
@@ -220,7 +220,7 @@ int kvm_deassign_device(struct kvm *kvm,
 
  iommu_detach_device(domain, &pdev->dev);
 
-    pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(pdev);
 
  dev_info(&pdev->dev, "kvm deassign device\n");

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
E1000-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel&#174; Ethernet, visit http://communities.intel.com/community/wired

#10 lore raw
In reply to Alex Williamson
Quoted 59 lines · 在 2014年7月11日,下午10:54,Alex Williamson <[email protected]> 写道:
Quoted 56 lines · Ethan Zhao
Quoted 42 lines
Quoted 42 lines · 在 2014年7月11日,下午10:15,Alex Williamson <[email protected]> 写道:
Quoted 21 lines · Alex Williamson

On Fri, 2014-07-11 at 20:30 +0800, Ethan Zhao wrote:
This patch introduces two new device assignment functions

pci_iov_assign_device(),
pci_iov_deassign_device()

along with the existed one

pci_vfs_assigned()

They construct the VFs assignment management interface, used to assign/ deassign device to VM and query the VFs reference counter. instead of direct manipulation of device flag.

This patch refashioned the related code and make them atomic.

v3: change the naming of device assignment helpers, because they work for all kind of PCI device, not only SR-IOV ([email protected])

Quoted 6 lines

v2: reorder the patchset and make it bisectable and atomic, steps clear between interface defination and implemenation according to the suggestion from [email protected]

---

- Use a cover patch to describe the series

- Version information goes here, below the "---", not above it

- I stand by the patch breakdown I suggested originally, there are too many logical changes here in patch 1. There are easily 3 separate patches here.

- Renaming s/sriov/iov/ doesn't address the problem David raised. The name is still synonymous with SR-IOV and it's defined on drivers/pci/iov.c, which is only built with CONFIG_PCI_IOV.

Quoted 7 lines
Quoted 2 lines

- PCI_DEV_FLAGS_ASSIGNED should be unused after this series, why is it not removed?

I guess it's still used, which is even worse because now we have separate data elements, one tracking how many VFs are assigned from a PF and another tracking each device that's assigned. What are we actually gaining or fixing by doing this?

Of course it is used to tracking PF/VF assigned, what we gained are - we hide the details In assignment helpers, we wouldn't bother the users anymore and implement what inside The helpers, my initial purpose is to simplify the ugly pci_vfs_assigned() with counter.

Quoted 6 lines
Quoted 1 line

I don't want to push more change in one step, that would out of control to get perfect result.

But a counter means that we're tracking the data in two separate places, which is generally a bad idea. Cleaning up direct access to flags is fine, but creating a separate counter doesn't really seem to add any value.

If you are asked how many apples in your bag , you like to count them one by one and Give the answer ? What are you doing when you put them into the bag ?

Quoted 142 lines
Quoted 142 lines
Quoted 142 lines
Quoted 142 lines
Quoted 6 lines
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c |   17 ++---------------
drivers/pci/iov.c                                  |   20 ++++++++++++++++++++
drivers/xen/xen-pciback/pci_stub.c                 |    4 ++--
include/linux/pci.h                                |    4 ++++
virt/kvm/assigned-dev.c                            |    2 +-
virt/kvm/iommu.c                                   |    4 ++--

- This patch touch 4 separate logical code areas, who do you expect to ack and commit it? Split it up.

Quoted 132 lines
6 files changed, 31 insertions(+), 20 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +2 -15
index 02c11a7..781040e 100644
@@ -693,22 +693,9 @@ complete_reset:
 static bool i40e_vfs_are_assigned(struct i40e_pf *pf)
 {
  struct pci_dev *pdev = pf->pdev;
-    struct pci_dev *vfdev;
-
-    /* loop through all the VFs to see if we own any that are assigned */
-    vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, I40E_DEV_ID_VF , NULL);
-    while (vfdev) {
-        /* if we don't own it we don't care */
-        if (vfdev->is_virtfn && pci_physfn(vfdev) == pdev) {
-            /* if it is assigned we cannot release it */
-            if (vfdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED)
-                return true;
-        }
 
-        vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
-                       I40E_DEV_ID_VF,
-                       vfdev);
-    }
+    if (pci_vfs_assigned(pdev))
+        return true;
 
  return false;
 }
drivers/pci/iov.c +20 -0
index de7a747..090f827 100644
@@ -644,6 +644,26 @@ int pci_vfs_assigned(struct pci_dev *dev)
 EXPORT_SYMBOL_GPL(pci_vfs_assigned);
 
 /**
+ * pci_iov_assign_device - assign device to VM
+ * @pdev: the device to be assigned.
+ */
+void pci_iov_assign_device(struct pci_dev *pdev)
+{
+    pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_assign_device);
+
+/**
+ * pci_iov_deassign_device - deasign device from VM
+ * @pdev: the device to be deassigned.
+ */
+void pci_iov_deassign_device(struct pci_dev *pdev)
+{
+    pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_deassign_device);
+
+/**
 * pci_sriov_set_totalvfs -- reduce the TotalVFs available
 * @dev: the PCI PF device
 * @numvfs: number that should be used for TotalVFs supported
drivers/xen/xen-pciback/pci_stub.c +2 -2
index 62fcd48..27e00d1 100644
@@ -133,7 +133,7 @@ static void pcistub_device_release(struct kref *kref)
  xen_pcibk_config_free_dyn_fields(dev);
  xen_pcibk_config_free_dev(dev);
 
-    dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(dev);
  pci_dev_put(dev);
 
  kfree(psdev);
@@ -404,7 +404,7 @@ static int pcistub_init_device(struct pci_dev *dev)
  dev_dbg(&dev->dev, "reset device\n");
  xen_pcibk_reset_device(dev);
 
-    dev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_assign_device(dev);
  return 0;
 

config_release:

include/linux/pci.h +4 -0
index aab57b4..5ece6d6 100644
@@ -1603,6 +1603,8 @@ int pci_num_vf(struct pci_dev *dev);
 int pci_vfs_assigned(struct pci_dev *dev);
 int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs);
 int pci_sriov_get_totalvfs(struct pci_dev *dev);
+void pci_iov_assign_device(struct pci_dev *dev);
+void pci_iov_deassign_device(struct pci_dev *dev);
 #else
 static inline int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn)
 { return -ENODEV; }
@@ -1614,6 +1616,8 @@ static inline int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs)
 { return 0; }
 static inline int pci_sriov_get_totalvfs(struct pci_dev *dev)
 { return 0; }
+static inline void pci_iov_assign_device(struct pci_dev *dev) { }
+static inline void pci_iov_deassign_device(struct pci_dev *dev) { }
 #endif
 
 #if defined(CONFIG_HOTPLUG_PCI) || defined(CONFIG_HOTPLUG_PCI_MODULE)
virt/kvm/assigned-dev.c +1 -1
index bf06577..7fac58d 100644
@@ -302,7 +302,7 @@ static void kvm_free_assigned_device(struct kvm *kvm,
  else
      pci_restore_state(assigned_dev->dev);
 
-    assigned_dev->dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(assigned_dev->dev);
 
  pci_release_regions(assigned_dev->dev);
  pci_disable_device(assigned_dev->dev);
virt/kvm/iommu.c +1 -1
index 0df7d4b..641ee73 100644
@@ -194,7 +194,7 @@ int kvm_assign_device(struct kvm *kvm,
          goto out_unmap;
  }
 
-    pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_assign_device(pdev);
 
  dev_info(&pdev->dev, "kvm assign device\n");
 
Quoted 11 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

virt/kvm/iommu.c int kvm_deassign_device(struct kvm *kvm, · line 225

Quoted 8 lines
virt/kvm/iommu.c +1 -1
@@ -220,7 +220,7 @@ int kvm_deassign_device(struct kvm *kvm,
 
  iommu_detach_device(domain, &pdev->dev);
 
-    pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(pdev);
 
  dev_info(&pdev->dev, "kvm deassign device\n");

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
E1000-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel&#174; Ethernet, visit http://communities.intel.com/community/wired

#30 lore raw
In reply to Ethan Zhao
Quoted 41 lines · Ethan Zhao
Quoted 41 lines · 在 2014年7月11日,下午10:50,Alex Williamson <[email protected]> 写道:
Quoted 36 lines · Ethan Zhao
Quoted 21 lines · 在 2014年7月11日,下午9:13,Alex Williamson <[email protected]> 写道:
Quoted 20 lines · Ethan Zhao

This patch introduces two new device assignment functions

pci_iov_assign_device(),
pci_iov_deassign_device()

along with the existed one

pci_vfs_assigned()

They construct the VFs assignment management interface, used to assign/ deassign device to VM and query the VFs reference counter. instead of direct manipulation of device flag.

This patch refashioned the related code and make them atomic.

v3: change the naming of device assignment helpers, because they work for all kind of PCI device, not only SR-IOV ([email protected])

Quoted 8 lines
Quoted 6 lines

v2: reorder the patchset and make it bisectable and atomic, steps clear between interface defination and implemenation according to the suggestion from [email protected]

---

- Use a cover patch to describe the series

Hmmm,

Quoted 5 lines

- Version information goes here, below the "---", not above it

- I stand by the patch breakdown I suggested originally, there are too many logical changes here in patch 1. There are easily 3 separate patches here.

You prefer v1 again ?

Quoted 8 lines
Quoted 4 lines

That's not at all what I'm suggesting. In response to v1 I suggested a specific reordering that would allow the series to be bisectable. I'm surprised to see v2 ignored that and combined the first 3 suggested patches.

If what I understand right. Your points are.
1. To be bisectable.
Combine the code into 2 parches, is really bisect able, without 2, 1 works right. If 1 was broken into 3, any of them is lost, buggy. They must work together.

No, I never said 2 patches. I said to fix and abstract the usage, then change the implementation. Fixing and abstracting the usage should be multiple patches. You should not be concerned about patches in a series getting lost, you should be concerned that each step along the way is functional.

Quoted 9 lines

2. Define and abstract first then implement.
1 &. 2 follows this point.

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

- Renaming s/sriov/iov/ doesn't address the problem David raised. The name is still synonymous with SR-IOV and it's defined on drivers/pci/iov.c, which is only built with CONFIG_PCI_IOV.

This is real issue, the interface should work without CONFIG_PCI_IOV defined. Should be fixed.

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

- PCI_DEV_FLAGS_ASSIGNED should be unused after this series, why is it not removed?

you wanna do all things in one step ? Be practical. That is not my original purpose.

I never suggested collapsing steps. Maybe I'd understand the original purpose better if there was an overall description in a cover patch.

Compose a cover letter seems necessary to describe patch set if they are too complex.

Any series with more than a single patch should have a cover letter.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c |   17 ++---------------
drivers/pci/iov.c                                  |   20 ++++++++++++++++++++
drivers/xen/xen-pciback/pci_stub.c                 |    4 ++--
include/linux/pci.h                                |    4 ++++
virt/kvm/assigned-dev.c                            |    2 +-
virt/kvm/iommu.c                                   |    4 ++--
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

- This patch touch 4 separate logical code areas, who do you expect to ack and commit it? Split it up.

Such would go back to the v1, four patches, if one lost to be committed, kernel could be buggy.

There seems to be confusion between multiple patches, which is fine, and the patch ordering from v1, which is wrong.

Do you want them work standalone, if no, the confusion is nothing.

Each step in a series should be functional. There's absolutely no requirement that any individual patch from a series can be pulled out separately and work on it's own. Patches build on each other.

Quoted 136 lines
Quoted 136 lines
Quoted 136 lines
Quoted 136 lines
Quoted 136 lines
6 files changed, 31 insertions(+), 20 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +2 -15
index 02c11a7..781040e 100644
@@ -693,22 +693,9 @@ complete_reset:
 static bool i40e_vfs_are_assigned(struct i40e_pf *pf)
 {
  struct pci_dev *pdev = pf->pdev;
-    struct pci_dev *vfdev;
-
-    /* loop through all the VFs to see if we own any that are assigned */
-    vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, I40E_DEV_ID_VF , NULL);
-    while (vfdev) {
-        /* if we don't own it we don't care */
-        if (vfdev->is_virtfn && pci_physfn(vfdev) == pdev) {
-            /* if it is assigned we cannot release it */
-            if (vfdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED)
-                return true;
-        }
 
-        vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
-                       I40E_DEV_ID_VF,
-                       vfdev);
-    }
+    if (pci_vfs_assigned(pdev))
+        return true;
 
  return false;
 }
drivers/pci/iov.c +20 -0
index de7a747..090f827 100644
@@ -644,6 +644,26 @@ int pci_vfs_assigned(struct pci_dev *dev)
 EXPORT_SYMBOL_GPL(pci_vfs_assigned);
 
 /**
+ * pci_iov_assign_device - assign device to VM
+ * @pdev: the device to be assigned.
+ */
+void pci_iov_assign_device(struct pci_dev *pdev)
+{
+    pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_assign_device);
+
+/**
+ * pci_iov_deassign_device - deasign device from VM
+ * @pdev: the device to be deassigned.
+ */
+void pci_iov_deassign_device(struct pci_dev *pdev)
+{
+    pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_deassign_device);
+
+/**
 * pci_sriov_set_totalvfs -- reduce the TotalVFs available
 * @dev: the PCI PF device
 * @numvfs: number that should be used for TotalVFs supported
drivers/xen/xen-pciback/pci_stub.c +2 -2
index 62fcd48..27e00d1 100644
@@ -133,7 +133,7 @@ static void pcistub_device_release(struct kref *kref)
  xen_pcibk_config_free_dyn_fields(dev);
  xen_pcibk_config_free_dev(dev);
 
-    dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(dev);
  pci_dev_put(dev);
 
  kfree(psdev);
@@ -404,7 +404,7 @@ static int pcistub_init_device(struct pci_dev *dev)
  dev_dbg(&dev->dev, "reset device\n");
  xen_pcibk_reset_device(dev);
 
-    dev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_assign_device(dev);
  return 0;
 

config_release:

include/linux/pci.h +4 -0
index aab57b4..5ece6d6 100644
@@ -1603,6 +1603,8 @@ int pci_num_vf(struct pci_dev *dev);
 int pci_vfs_assigned(struct pci_dev *dev);
 int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs);
 int pci_sriov_get_totalvfs(struct pci_dev *dev);
+void pci_iov_assign_device(struct pci_dev *dev);
+void pci_iov_deassign_device(struct pci_dev *dev);
 #else
 static inline int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn)
 { return -ENODEV; }
@@ -1614,6 +1616,8 @@ static inline int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs)
 { return 0; }
 static inline int pci_sriov_get_totalvfs(struct pci_dev *dev)
 { return 0; }
+static inline void pci_iov_assign_device(struct pci_dev *dev) { }
+static inline void pci_iov_deassign_device(struct pci_dev *dev) { }
 #endif
 
 #if defined(CONFIG_HOTPLUG_PCI) || defined(CONFIG_HOTPLUG_PCI_MODULE)
virt/kvm/assigned-dev.c +1 -1
index bf06577..7fac58d 100644
@@ -302,7 +302,7 @@ static void kvm_free_assigned_device(struct kvm *kvm,
  else
      pci_restore_state(assigned_dev->dev);
 
-    assigned_dev->dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(assigned_dev->dev);
 
  pci_release_regions(assigned_dev->dev);
  pci_disable_device(assigned_dev->dev);
virt/kvm/iommu.c +1 -1
index 0df7d4b..641ee73 100644
@@ -194,7 +194,7 @@ int kvm_assign_device(struct kvm *kvm,
          goto out_unmap;
  }
 
-    pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_assign_device(pdev);
 
  dev_info(&pdev->dev, "kvm assign device\n");
 
@@ -220,7 +220,7 @@ int kvm_deassign_device(struct kvm *kvm,
 
  iommu_detach_device(domain, &pdev->dev);
 
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

virt/kvm/iommu.c int kvm_deassign_device(struct kvm *kvm, · line 225

Quoted 4 lines
virt/kvm/iommu.c +1 -1
-    pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(pdev);
 
  dev_info(&pdev->dev, "kvm deassign device\n");

------------------------------------------------------------------------------
_______________________________________________
E1000-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel&#174; Ethernet, visit http://communities.intel.com/community/wired

#11 lore raw
In reply to Ethan Zhao
Quoted 60 lines · Ethan Zhao
Quoted 60 lines · 在 2014年7月11日,下午10:54,Alex Williamson <[email protected]> 写道:
Quoted 57 lines · Ethan Zhao
Quoted 42 lines
Quoted 42 lines · 在 2014年7月11日,下午10:15,Alex Williamson <[email protected]> 写道:
Quoted 21 lines · Alex Williamson

On Fri, 2014-07-11 at 20:30 +0800, Ethan Zhao wrote:
This patch introduces two new device assignment functions

pci_iov_assign_device(),
pci_iov_deassign_device()

along with the existed one

pci_vfs_assigned()

They construct the VFs assignment management interface, used to assign/ deassign device to VM and query the VFs reference counter. instead of direct manipulation of device flag.

This patch refashioned the related code and make them atomic.

v3: change the naming of device assignment helpers, because they work for all kind of PCI device, not only SR-IOV ([email protected])

Quoted 6 lines

v2: reorder the patchset and make it bisectable and atomic, steps clear between interface defination and implemenation according to the suggestion from [email protected]

---

- Use a cover patch to describe the series

- Version information goes here, below the "---", not above it

- I stand by the patch breakdown I suggested originally, there are too many logical changes here in patch 1. There are easily 3 separate patches here.

- Renaming s/sriov/iov/ doesn't address the problem David raised. The name is still synonymous with SR-IOV and it's defined on drivers/pci/iov.c, which is only built with CONFIG_PCI_IOV.

Quoted 7 lines
Quoted 2 lines

- PCI_DEV_FLAGS_ASSIGNED should be unused after this series, why is it not removed?

I guess it's still used, which is even worse because now we have separate data elements, one tracking how many VFs are assigned from a PF and another tracking each device that's assigned. What are we actually gaining or fixing by doing this?

Of course it is used to tracking PF/VF assigned, what we gained are - we hide the details In assignment helpers, we wouldn't bother the users anymore and implement what inside The helpers, my initial purpose is to simplify the ugly pci_vfs_assigned() with counter.

I don't want to push more change in one step, that would out of control to get perfect result.

Quoted 7 lines
Quoted 4 lines

But a counter means that we're tracking the data in two separate places, which is generally a bad idea. Cleaning up direct access to flags is fine, but creating a separate counter doesn't really seem to add any value.

If you are asked how many apples in your bag , you like to count them one by one and Give the answer ? What are you doing when you put them into the bag ?

If performance mattered, then yes, keeping a count may be advantageous. Performance does not matter in any path where this is used.

Quoted 146 lines
Quoted 146 lines
Quoted 146 lines
Quoted 146 lines
Quoted 146 lines
Quoted 6 lines
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c |   17 ++---------------
drivers/pci/iov.c                                  |   20 ++++++++++++++++++++
drivers/xen/xen-pciback/pci_stub.c                 |    4 ++--
include/linux/pci.h                                |    4 ++++
virt/kvm/assigned-dev.c                            |    2 +-
virt/kvm/iommu.c                                   |    4 ++--

- This patch touch 4 separate logical code areas, who do you expect to ack and commit it? Split it up.

Quoted 136 lines
6 files changed, 31 insertions(+), 20 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +2 -15
index 02c11a7..781040e 100644
@@ -693,22 +693,9 @@ complete_reset:
 static bool i40e_vfs_are_assigned(struct i40e_pf *pf)
 {
  struct pci_dev *pdev = pf->pdev;
-    struct pci_dev *vfdev;
-
-    /* loop through all the VFs to see if we own any that are assigned */
-    vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, I40E_DEV_ID_VF , NULL);
-    while (vfdev) {
-        /* if we don't own it we don't care */
-        if (vfdev->is_virtfn && pci_physfn(vfdev) == pdev) {
-            /* if it is assigned we cannot release it */
-            if (vfdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED)
-                return true;
-        }
 
-        vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
-                       I40E_DEV_ID_VF,
-                       vfdev);
-    }
+    if (pci_vfs_assigned(pdev))
+        return true;
 
  return false;
 }
drivers/pci/iov.c +20 -0
index de7a747..090f827 100644
@@ -644,6 +644,26 @@ int pci_vfs_assigned(struct pci_dev *dev)
 EXPORT_SYMBOL_GPL(pci_vfs_assigned);
 
 /**
+ * pci_iov_assign_device - assign device to VM
+ * @pdev: the device to be assigned.
+ */
+void pci_iov_assign_device(struct pci_dev *pdev)
+{
+    pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_assign_device);
+
+/**
+ * pci_iov_deassign_device - deasign device from VM
+ * @pdev: the device to be deassigned.
+ */
+void pci_iov_deassign_device(struct pci_dev *pdev)
+{
+    pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_deassign_device);
+
+/**
 * pci_sriov_set_totalvfs -- reduce the TotalVFs available
 * @dev: the PCI PF device
 * @numvfs: number that should be used for TotalVFs supported
drivers/xen/xen-pciback/pci_stub.c +2 -2
index 62fcd48..27e00d1 100644
@@ -133,7 +133,7 @@ static void pcistub_device_release(struct kref *kref)
  xen_pcibk_config_free_dyn_fields(dev);
  xen_pcibk_config_free_dev(dev);
 
-    dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(dev);
  pci_dev_put(dev);
 
  kfree(psdev);
@@ -404,7 +404,7 @@ static int pcistub_init_device(struct pci_dev *dev)
  dev_dbg(&dev->dev, "reset device\n");
  xen_pcibk_reset_device(dev);
 
-    dev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_assign_device(dev);
  return 0;
 

config_release:

include/linux/pci.h +4 -0
index aab57b4..5ece6d6 100644
@@ -1603,6 +1603,8 @@ int pci_num_vf(struct pci_dev *dev);
 int pci_vfs_assigned(struct pci_dev *dev);
 int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs);
 int pci_sriov_get_totalvfs(struct pci_dev *dev);
+void pci_iov_assign_device(struct pci_dev *dev);
+void pci_iov_deassign_device(struct pci_dev *dev);
 #else
 static inline int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn)
 { return -ENODEV; }
@@ -1614,6 +1616,8 @@ static inline int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs)
 { return 0; }
 static inline int pci_sriov_get_totalvfs(struct pci_dev *dev)
 { return 0; }
+static inline void pci_iov_assign_device(struct pci_dev *dev) { }
+static inline void pci_iov_deassign_device(struct pci_dev *dev) { }
 #endif
 
 #if defined(CONFIG_HOTPLUG_PCI) || defined(CONFIG_HOTPLUG_PCI_MODULE)
virt/kvm/assigned-dev.c +1 -1
index bf06577..7fac58d 100644
@@ -302,7 +302,7 @@ static void kvm_free_assigned_device(struct kvm *kvm,
  else
      pci_restore_state(assigned_dev->dev);
 
-    assigned_dev->dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(assigned_dev->dev);
 
  pci_release_regions(assigned_dev->dev);
  pci_disable_device(assigned_dev->dev);
virt/kvm/iommu.c +1 -1
index 0df7d4b..641ee73 100644
@@ -194,7 +194,7 @@ int kvm_assign_device(struct kvm *kvm,
          goto out_unmap;
  }
 
-    pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_assign_device(pdev);
 
  dev_info(&pdev->dev, "kvm assign device\n");
 
@@ -220,7 +220,7 @@ int kvm_deassign_device(struct kvm *kvm,
 
  iommu_detach_device(domain, &pdev->dev);
 
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

virt/kvm/iommu.c int kvm_deassign_device(struct kvm *kvm, · line 225

Quoted 4 lines
virt/kvm/iommu.c +1 -1
-    pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(pdev);
 
  dev_info(&pdev->dev, "kvm deassign device\n");

------------------------------------------------------------------------------
_______________________________________________
E1000-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel&#174; Ethernet, visit http://communities.intel.com/community/wired

#31 lore raw
In reply to Alex Williamson
Quoted 55 lines · 在 2014年7月11日,下午11:23,Alex Williamson <[email protected]> 写道:
Quoted 43 lines · Ethan Zhao
Quoted 41 lines · 在 2014年7月11日,下午10:50,Alex Williamson <[email protected]> 写道:
Quoted 36 lines · Ethan Zhao
Quoted 21 lines
Quoted 21 lines · 在 2014年7月11日,下午9:13,Alex Williamson <[email protected]> 写道:

On Fri, 2014-07-11 at 20:30 +0800, Ethan Zhao wrote:
This patch introduces two new device assignment functions

pci_iov_assign_device(),
pci_iov_deassign_device()

along with the existed one

pci_vfs_assigned()

They construct the VFs assignment management interface, used to assign/ deassign device to VM and query the VFs reference counter. instead of direct manipulation of device flag.

This patch refashioned the related code and make them atomic.

v3: change the naming of device assignment helpers, because they work for all kind of PCI device, not only SR-IOV ([email protected])

Quoted 8 lines
Quoted 6 lines

v2: reorder the patchset and make it bisectable and atomic, steps clear between interface defination and implemenation according to the suggestion from [email protected]

---

- Use a cover patch to describe the series

Hmmm,

Quoted 5 lines

- Version information goes here, below the "---", not above it

- I stand by the patch breakdown I suggested originally, there are too many logical changes here in patch 1. There are easily 3 separate patches here.

You prefer v1 again ?

Quoted 8 lines
Quoted 4 lines

That's not at all what I'm suggesting. In response to v1 I suggested a specific reordering that would allow the series to be bisectable. I'm surprised to see v2 ignored that and combined the first 3 suggested patches.

If what I understand right. Your points are.
1. To be bisectable.
Combine the code into 2 parches, is really bisect able, without 2, 1 works right. If 1 was broken into 3, any of them is lost, buggy. They must work together.

Quoted 6 lines

No, I never said 2 patches. I said to fix and abstract the usage, then change the implementation. Fixing and abstracting the usage should be multiple patches. You should not be concerned about patches in a series getting lost, you should be concerned that each step along the way is functional.

How about 5 patches ?
- 1 . Fix i40e with pci_vfs_assigned()

 - 2.  Define assign/design helper.
 - 3.  KVM uses helpers
 - 4.  Xen uses helpers

- 5. Introduce VF ref counter.

This series looks like you first suggestion.

Quoted 172 lines
Quoted 10 lines
Quoted 1 line

pci_vfs_assigned

2. Define and abstract first then implement.
1 &. 2 follows this point.

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

- Renaming s/sriov/iov/ doesn't address the problem David raised. The name is still synonymous with SR-IOV and it's defined on drivers/pci/iov.c, which is only built with CONFIG_PCI_IOV.

This is real issue, the interface should work without CONFIG_PCI_IOV defined. Should be fixed.

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

- PCI_DEV_FLAGS_ASSIGNED should be unused after this series, why is it not removed?

you wanna do all things in one step ? Be practical. That is not my original purpose.

I never suggested collapsing steps. Maybe I'd understand the original purpose better if there was an overall description in a cover patch.

Compose a cover letter seems necessary to describe patch set if they are too complex.

Any series with more than a single patch should have a cover letter.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c |   17 ++---------------
drivers/pci/iov.c                                  |   20 ++++++++++++++++++++
drivers/xen/xen-pciback/pci_stub.c                 |    4 ++--
include/linux/pci.h                                |    4 ++++
virt/kvm/assigned-dev.c                            |    2 +-
virt/kvm/iommu.c                                   |    4 ++--
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

- This patch touch 4 separate logical code areas, who do you expect to ack and commit it? Split it up.

Such would go back to the v1, four patches, if one lost to be committed, kernel could be buggy.

There seems to be confusion between multiple patches, which is fine, and the patch ordering from v1, which is wrong.

Do you want them work standalone, if no, the confusion is nothing.

Each step in a series should be functional. There's absolutely no requirement that any individual patch from a series can be pulled out separately and work on it's own. Patches build on each other.

Quoted 132 lines
Quoted 132 lines
Quoted 132 lines
Quoted 132 lines
Quoted 132 lines
6 files changed, 31 insertions(+), 20 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +2 -15
index 02c11a7..781040e 100644
@@ -693,22 +693,9 @@ complete_reset:
 static bool i40e_vfs_are_assigned(struct i40e_pf *pf)
 {
 struct pci_dev *pdev = pf->pdev;
-    struct pci_dev *vfdev;
-
-    /* loop through all the VFs to see if we own any that are assigned */
-    vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, I40E_DEV_ID_VF , NULL);
-    while (vfdev) {
-        /* if we don't own it we don't care */
-        if (vfdev->is_virtfn && pci_physfn(vfdev) == pdev) {
-            /* if it is assigned we cannot release it */
-            if (vfdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED)
-                return true;
-        }
 
-        vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
-                       I40E_DEV_ID_VF,
-                       vfdev);
-    }
+    if (pci_vfs_assigned(pdev))
+        return true;
 
 return false;
 }
drivers/pci/iov.c +20 -0
index de7a747..090f827 100644
@@ -644,6 +644,26 @@ int pci_vfs_assigned(struct pci_dev *dev)
 EXPORT_SYMBOL_GPL(pci_vfs_assigned);
 
 /**
+ * pci_iov_assign_device - assign device to VM
+ * @pdev: the device to be assigned.
+ */
+void pci_iov_assign_device(struct pci_dev *pdev)
+{
+    pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_assign_device);
+
+/**
+ * pci_iov_deassign_device - deasign device from VM
+ * @pdev: the device to be deassigned.
+ */
+void pci_iov_deassign_device(struct pci_dev *pdev)
+{
+    pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_deassign_device);
+
+/**
 * pci_sriov_set_totalvfs -- reduce the TotalVFs available
 * @dev: the PCI PF device
 * @numvfs: number that should be used for TotalVFs supported
drivers/xen/xen-pciback/pci_stub.c +2 -2
index 62fcd48..27e00d1 100644
@@ -133,7 +133,7 @@ static void pcistub_device_release(struct kref *kref)
 xen_pcibk_config_free_dyn_fields(dev);
 xen_pcibk_config_free_dev(dev);
 
-    dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(dev);
 pci_dev_put(dev);
 
 kfree(psdev);
@@ -404,7 +404,7 @@ static int pcistub_init_device(struct pci_dev *dev)
 dev_dbg(&dev->dev, "reset device\n");
 xen_pcibk_reset_device(dev);
 
-    dev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_assign_device(dev);
 return 0;
 

config_release:

include/linux/pci.h +4 -0
index aab57b4..5ece6d6 100644
@@ -1603,6 +1603,8 @@ int pci_num_vf(struct pci_dev *dev);
 int pci_vfs_assigned(struct pci_dev *dev);
 int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs);
 int pci_sriov_get_totalvfs(struct pci_dev *dev);
+void pci_iov_assign_device(struct pci_dev *dev);
+void pci_iov_deassign_device(struct pci_dev *dev);
 #else
 static inline int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn)
 { return -ENODEV; }
@@ -1614,6 +1616,8 @@ static inline int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs)
 { return 0; }
 static inline int pci_sriov_get_totalvfs(struct pci_dev *dev)
 { return 0; }
+static inline void pci_iov_assign_device(struct pci_dev *dev) { }
+static inline void pci_iov_deassign_device(struct pci_dev *dev) { }
 #endif
 
 #if defined(CONFIG_HOTPLUG_PCI) || defined(CONFIG_HOTPLUG_PCI_MODULE)
virt/kvm/assigned-dev.c +1 -1
index bf06577..7fac58d 100644
@@ -302,7 +302,7 @@ static void kvm_free_assigned_device(struct kvm *kvm,
 else
     pci_restore_state(assigned_dev->dev);
 
-    assigned_dev->dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(assigned_dev->dev);
 
 pci_release_regions(assigned_dev->dev);
 pci_disable_device(assigned_dev->dev);
virt/kvm/iommu.c +1 -1
index 0df7d4b..641ee73 100644
@@ -194,7 +194,7 @@ int kvm_assign_device(struct kvm *kvm,
         goto out_unmap;
 }
 
-    pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_assign_device(pdev);
 
 dev_info(&pdev->dev, "kvm assign device\n");
 
Quoted 11 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

virt/kvm/iommu.c int kvm_deassign_device(struct kvm *kvm, · line 225

Quoted 8 lines
virt/kvm/iommu.c +1 -1
@@ -220,7 +220,7 @@ int kvm_deassign_device(struct kvm *kvm,
 
 iommu_detach_device(domain, &pdev->dev);
 
-    pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(pdev);
 
 dev_info(&pdev->dev, "kvm deassign device\n");

------------------------------------------------------------------------------
_______________________________________________
E1000-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel&#174; Ethernet, visit http://communities.intel.com/community/wired

#12 lore raw
In reply to Alex Williamson
Quoted 70 lines · 在 2014年7月11日,下午11:25,Alex Williamson <[email protected]> 写道:
Quoted 67 lines · Ethan Zhao
Quoted 64 lines
Quoted 54 lines · 在 2014年7月11日,下午10:54,Alex Williamson <[email protected]> 写道:
Quoted 41 lines · Ethan Zhao
Quoted 41 lines · 在 2014年7月11日,下午10:15,Alex Williamson <[email protected]> 写道:
Quoted 21 lines · Alex Williamson

On Fri, 2014-07-11 at 20:30 +0800, Ethan Zhao wrote:
This patch introduces two new device assignment functions

pci_iov_assign_device(),
pci_iov_deassign_device()

along with the existed one

pci_vfs_assigned()

They construct the VFs assignment management interface, used to assign/ deassign device to VM and query the VFs reference counter. instead of direct manipulation of device flag.

This patch refashioned the related code and make them atomic.

v3: change the naming of device assignment helpers, because they work for all kind of PCI device, not only SR-IOV ([email protected])

Quoted 6 lines

v2: reorder the patchset and make it bisectable and atomic, steps clear between interface defination and implemenation according to the suggestion from [email protected]

---

- Use a cover patch to describe the series

- Version information goes here, below the "---", not above it

- I stand by the patch breakdown I suggested originally, there are too many logical changes here in patch 1. There are easily 3 separate patches here.

- Renaming s/sriov/iov/ doesn't address the problem David raised. The name is still synonymous with SR-IOV and it's defined on drivers/pci/iov.c, which is only built with CONFIG_PCI_IOV.

Quoted 7 lines
Quoted 2 lines

- PCI_DEV_FLAGS_ASSIGNED should be unused after this series, why is it not removed?

I guess it's still used, which is even worse because now we have separate data elements, one tracking how many VFs are assigned from a PF and another tracking each device that's assigned. What are we actually gaining or fixing by doing this?

Quoted 5 lines

Of course it is used to tracking PF/VF assigned, what we gained are - we hide the details In assignment helpers, we wouldn't bother the users anymore and implement what inside The helpers, my initial purpose is to simplify the ugly pci_vfs_assigned() with counter.

I don't want to push more change in one step, that would out of control to get perfect result.

But a counter means that we're tracking the data in two separate places, which is generally a bad idea. Cleaning up direct access to flags is fine, but creating a separate counter doesn't really seem to add any value.

Quoted 6 lines
Quoted 2 lines

If you are asked how many apples in your bag , you like to count them one by one and Give the answer ? What are you doing when you put them into the bag ?

If performance mattered, then yes, keeping a count may be advantageous. Performance does not matter in any path where this is used.

Not only performance, concurrency side-effect it caused. And less complication, lesser buggy.

Quoted 146 lines
Quoted 146 lines
Quoted 146 lines
Quoted 146 lines
Quoted 146 lines
Quoted 146 lines
Quoted 6 lines
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c |   17 ++---------------
drivers/pci/iov.c                                  |   20 ++++++++++++++++++++
drivers/xen/xen-pciback/pci_stub.c                 |    4 ++--
include/linux/pci.h                                |    4 ++++
virt/kvm/assigned-dev.c                            |    2 +-
virt/kvm/iommu.c                                   |    4 ++--

- This patch touch 4 separate logical code areas, who do you expect to ack and commit it? Split it up.

Quoted 136 lines
6 files changed, 31 insertions(+), 20 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +2 -15
index 02c11a7..781040e 100644
@@ -693,22 +693,9 @@ complete_reset:
 static bool i40e_vfs_are_assigned(struct i40e_pf *pf)
 {
 struct pci_dev *pdev = pf->pdev;
-    struct pci_dev *vfdev;
-
-    /* loop through all the VFs to see if we own any that are assigned */
-    vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, I40E_DEV_ID_VF , NULL);
-    while (vfdev) {
-        /* if we don't own it we don't care */
-        if (vfdev->is_virtfn && pci_physfn(vfdev) == pdev) {
-            /* if it is assigned we cannot release it */
-            if (vfdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED)
-                return true;
-        }
 
-        vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
-                       I40E_DEV_ID_VF,
-                       vfdev);
-    }
+    if (pci_vfs_assigned(pdev))
+        return true;
 
 return false;
 }
drivers/pci/iov.c +20 -0
index de7a747..090f827 100644
@@ -644,6 +644,26 @@ int pci_vfs_assigned(struct pci_dev *dev)
 EXPORT_SYMBOL_GPL(pci_vfs_assigned);
 
 /**
+ * pci_iov_assign_device - assign device to VM
+ * @pdev: the device to be assigned.
+ */
+void pci_iov_assign_device(struct pci_dev *pdev)
+{
+    pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_assign_device);
+
+/**
+ * pci_iov_deassign_device - deasign device from VM
+ * @pdev: the device to be deassigned.
+ */
+void pci_iov_deassign_device(struct pci_dev *pdev)
+{
+    pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_deassign_device);
+
+/**
 * pci_sriov_set_totalvfs -- reduce the TotalVFs available
 * @dev: the PCI PF device
 * @numvfs: number that should be used for TotalVFs supported
drivers/xen/xen-pciback/pci_stub.c +2 -2
index 62fcd48..27e00d1 100644
@@ -133,7 +133,7 @@ static void pcistub_device_release(struct kref *kref)
 xen_pcibk_config_free_dyn_fields(dev);
 xen_pcibk_config_free_dev(dev);
 
-    dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(dev);
 pci_dev_put(dev);
 
 kfree(psdev);
@@ -404,7 +404,7 @@ static int pcistub_init_device(struct pci_dev *dev)
 dev_dbg(&dev->dev, "reset device\n");
 xen_pcibk_reset_device(dev);
 
-    dev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_assign_device(dev);
 return 0;
 

config_release:

include/linux/pci.h +4 -0
index aab57b4..5ece6d6 100644
@@ -1603,6 +1603,8 @@ int pci_num_vf(struct pci_dev *dev);
 int pci_vfs_assigned(struct pci_dev *dev);
 int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs);
 int pci_sriov_get_totalvfs(struct pci_dev *dev);
+void pci_iov_assign_device(struct pci_dev *dev);
+void pci_iov_deassign_device(struct pci_dev *dev);
 #else
 static inline int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn)
 { return -ENODEV; }
@@ -1614,6 +1616,8 @@ static inline int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs)
 { return 0; }
 static inline int pci_sriov_get_totalvfs(struct pci_dev *dev)
 { return 0; }
+static inline void pci_iov_assign_device(struct pci_dev *dev) { }
+static inline void pci_iov_deassign_device(struct pci_dev *dev) { }
 #endif
 
 #if defined(CONFIG_HOTPLUG_PCI) || defined(CONFIG_HOTPLUG_PCI_MODULE)
virt/kvm/assigned-dev.c +1 -1
index bf06577..7fac58d 100644
@@ -302,7 +302,7 @@ static void kvm_free_assigned_device(struct kvm *kvm,
 else
     pci_restore_state(assigned_dev->dev);
 
-    assigned_dev->dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(assigned_dev->dev);
 
 pci_release_regions(assigned_dev->dev);
 pci_disable_device(assigned_dev->dev);
virt/kvm/iommu.c +1 -1
index 0df7d4b..641ee73 100644
@@ -194,7 +194,7 @@ int kvm_assign_device(struct kvm *kvm,
         goto out_unmap;
 }
 
-    pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_assign_device(pdev);
 
 dev_info(&pdev->dev, "kvm assign device\n");
 
@@ -220,7 +220,7 @@ int kvm_deassign_device(struct kvm *kvm,
 
 iommu_detach_device(domain, &pdev->dev);
 
Quoted 10 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

virt/kvm/iommu.c int kvm_deassign_device(struct kvm *kvm, · line 225

Quoted 4 lines
virt/kvm/iommu.c +1 -1
-    pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(pdev);
 
 dev_info(&pdev->dev, "kvm deassign device\n");

------------------------------------------------------------------------------
_______________________________________________
E1000-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel&#174; Ethernet, visit http://communities.intel.com/community/wired

#13 lore raw
Quoted 69 lines · Ethan Zhao
Quoted 69 lines · 在 2014年7月11日,下午11:25,Alex Williamson <[email protected]> 写道:
Quoted 67 lines · Ethan Zhao
Quoted 64 lines
Quoted 54 lines · 在 2014年7月11日,下午10:54,Alex Williamson <[email protected]> 写道:
Quoted 41 lines · Ethan Zhao
Quoted 41 lines · 在 2014年7月11日,下午10:15,Alex Williamson <[email protected]> 写道:
Quoted 21 lines · Alex Williamson

On Fri, 2014-07-11 at 20:30 +0800, Ethan Zhao wrote:
This patch introduces two new device assignment functions

pci_iov_assign_device(),
pci_iov_deassign_device()

along with the existed one

pci_vfs_assigned()

They construct the VFs assignment management interface, used to assign/ deassign device to VM and query the VFs reference counter. instead of direct manipulation of device flag.

This patch refashioned the related code and make them atomic.

v3: change the naming of device assignment helpers, because they work for all kind of PCI device, not only SR-IOV ([email protected])

Quoted 6 lines

v2: reorder the patchset and make it bisectable and atomic, steps clear between interface defination and implemenation according to the suggestion from [email protected]

---

- Use a cover patch to describe the series

- Version information goes here, below the "---", not above it

- I stand by the patch breakdown I suggested originally, there are too many logical changes here in patch 1. There are easily 3 separate patches here.

- Renaming s/sriov/iov/ doesn't address the problem David raised. The name is still synonymous with SR-IOV and it's defined on drivers/pci/iov.c, which is only built with CONFIG_PCI_IOV.

Quoted 7 lines
Quoted 2 lines

- PCI_DEV_FLAGS_ASSIGNED should be unused after this series, why is it not removed?

I guess it's still used, which is even worse because now we have separate data elements, one tracking how many VFs are assigned from a PF and another tracking each device that's assigned. What are we actually gaining or fixing by doing this?

Quoted 5 lines

Of course it is used to tracking PF/VF assigned, what we gained are - we hide the details In assignment helpers, we wouldn't bother the users anymore and implement what inside The helpers, my initial purpose is to simplify the ugly pci_vfs_assigned() with counter.

I don't want to push more change in one step, that would out of control to get perfect result.

But a counter means that we're tracking the data in two separate places, which is generally a bad idea. Cleaning up direct access to flags is fine, but creating a separate counter doesn't really seem to add any value.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

If you are asked how many apples in your bag , you like to count them one by one and Give the answer ? What are you doing when you put them into the bag ?

If performance mattered, then yes, keeping a count may be advantageous. Performance does not matter in any path where this is used.

Not only performance, concurrency side-effect it caused. And less complication, lesser buggy.

I'd argue that it doesn't fix anything there, the count can still change after it's been read but before any action has been taken based on the count. The only thing it does is eliminate the act of re-counting.

Quoted 149 lines
Quoted 149 lines
Quoted 149 lines
Quoted 149 lines
Quoted 149 lines
Quoted 149 lines
Quoted 149 lines
Quoted 6 lines
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c |   17 ++---------------
drivers/pci/iov.c                                  |   20 ++++++++++++++++++++
drivers/xen/xen-pciback/pci_stub.c                 |    4 ++--
include/linux/pci.h                                |    4 ++++
virt/kvm/assigned-dev.c                            |    2 +-
virt/kvm/iommu.c                                   |    4 ++--

- This patch touch 4 separate logical code areas, who do you expect to ack and commit it? Split it up.

Quoted 139 lines
6 files changed, 31 insertions(+), 20 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +2 -15
index 02c11a7..781040e 100644
@@ -693,22 +693,9 @@ complete_reset:
 static bool i40e_vfs_are_assigned(struct i40e_pf *pf)
 {
 struct pci_dev *pdev = pf->pdev;
-    struct pci_dev *vfdev;
-
-    /* loop through all the VFs to see if we own any that are assigned */
-    vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, I40E_DEV_ID_VF , NULL);
-    while (vfdev) {
-        /* if we don't own it we don't care */
-        if (vfdev->is_virtfn && pci_physfn(vfdev) == pdev) {
-            /* if it is assigned we cannot release it */
-            if (vfdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED)
-                return true;
-        }
 
-        vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
-                       I40E_DEV_ID_VF,
-                       vfdev);
-    }
+    if (pci_vfs_assigned(pdev))
+        return true;
 
 return false;
 }
drivers/pci/iov.c +20 -0
index de7a747..090f827 100644
@@ -644,6 +644,26 @@ int pci_vfs_assigned(struct pci_dev *dev)
 EXPORT_SYMBOL_GPL(pci_vfs_assigned);
 
 /**
+ * pci_iov_assign_device - assign device to VM
+ * @pdev: the device to be assigned.
+ */
+void pci_iov_assign_device(struct pci_dev *pdev)
+{
+    pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_assign_device);
+
+/**
+ * pci_iov_deassign_device - deasign device from VM
+ * @pdev: the device to be deassigned.
+ */
+void pci_iov_deassign_device(struct pci_dev *pdev)
+{
+    pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_deassign_device);
+
+/**
 * pci_sriov_set_totalvfs -- reduce the TotalVFs available
 * @dev: the PCI PF device
 * @numvfs: number that should be used for TotalVFs supported
drivers/xen/xen-pciback/pci_stub.c +2 -2
index 62fcd48..27e00d1 100644
@@ -133,7 +133,7 @@ static void pcistub_device_release(struct kref *kref)
 xen_pcibk_config_free_dyn_fields(dev);
 xen_pcibk_config_free_dev(dev);
 
-    dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(dev);
 pci_dev_put(dev);
 
 kfree(psdev);
@@ -404,7 +404,7 @@ static int pcistub_init_device(struct pci_dev *dev)
 dev_dbg(&dev->dev, "reset device\n");
 xen_pcibk_reset_device(dev);
 
-    dev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_assign_device(dev);
 return 0;
 

config_release:

include/linux/pci.h +4 -0
index aab57b4..5ece6d6 100644
@@ -1603,6 +1603,8 @@ int pci_num_vf(struct pci_dev *dev);
 int pci_vfs_assigned(struct pci_dev *dev);
 int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs);
 int pci_sriov_get_totalvfs(struct pci_dev *dev);
+void pci_iov_assign_device(struct pci_dev *dev);
+void pci_iov_deassign_device(struct pci_dev *dev);
 #else
 static inline int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn)
 { return -ENODEV; }
@@ -1614,6 +1616,8 @@ static inline int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs)
 { return 0; }
 static inline int pci_sriov_get_totalvfs(struct pci_dev *dev)
 { return 0; }
+static inline void pci_iov_assign_device(struct pci_dev *dev) { }
+static inline void pci_iov_deassign_device(struct pci_dev *dev) { }
 #endif
 
 #if defined(CONFIG_HOTPLUG_PCI) || defined(CONFIG_HOTPLUG_PCI_MODULE)
virt/kvm/assigned-dev.c +1 -1
index bf06577..7fac58d 100644
@@ -302,7 +302,7 @@ static void kvm_free_assigned_device(struct kvm *kvm,
 else
     pci_restore_state(assigned_dev->dev);
 
-    assigned_dev->dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(assigned_dev->dev);
 
 pci_release_regions(assigned_dev->dev);
 pci_disable_device(assigned_dev->dev);
virt/kvm/iommu.c +2 -2
index 0df7d4b..641ee73 100644
@@ -194,7 +194,7 @@ int kvm_assign_device(struct kvm *kvm,
         goto out_unmap;
 }
 
-    pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_assign_device(pdev);
 
 dev_info(&pdev->dev, "kvm assign device\n");
 
@@ -220,7 +220,7 @@ int kvm_deassign_device(struct kvm *kvm,
 
 iommu_detach_device(domain, &pdev->dev);
 
-    pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(pdev);
 
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

virt/kvm/iommu.c int kvm_deassign_device(struct kvm *kvm, · line 225

Quoted 1 line
virt/kvm/iommu.c +0 -0
 dev_info(&pdev->dev, "kvm deassign device\n");

------------------------------------------------------------------------------
_______________________________________________
E1000-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel&#174; Ethernet, visit http://communities.intel.com/community/wired

#14 lore raw
Quoted 77 lines · 在 2014年7月12日,上午12:13,Alex Williamson <[email protected]> 写道:
Quoted 74 lines · Ethan Zhao
Quoted 72 lines
Quoted 71 lines · 在 2014年7月11日,下午11:25,Alex Williamson <[email protected]> 写道:
Quoted 57 lines · Ethan Zhao
Quoted 57 lines · 在 2014年7月11日,下午10:54,Alex Williamson <[email protected]> 写道:
Quoted 41 lines · Ethan Zhao
Quoted 41 lines · 在 2014年7月11日,下午10:15,Alex Williamson <[email protected]> 写道:
Quoted 21 lines · Alex Williamson

On Fri, 2014-07-11 at 20:30 +0800, Ethan Zhao wrote:
This patch introduces two new device assignment functions

pci_iov_assign_device(),
pci_iov_deassign_device()

along with the existed one

pci_vfs_assigned()

They construct the VFs assignment management interface, used to assign/ deassign device to VM and query the VFs reference counter. instead of direct manipulation of device flag.

This patch refashioned the related code and make them atomic.

v3: change the naming of device assignment helpers, because they work for all kind of PCI device, not only SR-IOV ([email protected])

Quoted 6 lines

v2: reorder the patchset and make it bisectable and atomic, steps clear between interface defination and implemenation according to the suggestion from [email protected]

---

- Use a cover patch to describe the series

- Version information goes here, below the "---", not above it

- I stand by the patch breakdown I suggested originally, there are too many logical changes here in patch 1. There are easily 3 separate patches here.

- Renaming s/sriov/iov/ doesn't address the problem David raised. The name is still synonymous with SR-IOV and it's defined on drivers/pci/iov.c, which is only built with CONFIG_PCI_IOV.

Quoted 7 lines
Quoted 2 lines

- PCI_DEV_FLAGS_ASSIGNED should be unused after this series, why is it not removed?

I guess it's still used, which is even worse because now we have separate data elements, one tracking how many VFs are assigned from a PF and another tracking each device that's assigned. What are we actually gaining or fixing by doing this?

Of course it is used to tracking PF/VF assigned, what we gained are - we hide the details In assignment helpers, we wouldn't bother the users anymore and implement what inside The helpers, my initial purpose is to simplify the ugly pci_vfs_assigned() with counter.

Quoted 6 lines
Quoted 1 line

I don't want to push more change in one step, that would out of control to get perfect result.

But a counter means that we're tracking the data in two separate places, which is generally a bad idea. Cleaning up direct access to flags is fine, but creating a separate counter doesn't really seem to add any value.

If you are asked how many apples in your bag , you like to count them one by one and Give the answer ? What are you doing when you put them into the bag ?

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

If performance mattered, then yes, keeping a count may be advantageous. Performance does not matter in any path where this is used.

Not only performance, concurrency side-effect it caused. And less complication, lesser buggy.

I'd argue that it doesn't fix anything there, the count can still change after it's been read but before any action has been taken based on the count. The only thing it does is eliminate the act of re-counting.

If no counter, how to avoid traversing devices and get VFs assigned count ? To avoid Re-counting is enough I think.

Quoted 143 lines
Quoted 143 lines
Quoted 143 lines
Quoted 143 lines
Quoted 143 lines
Quoted 143 lines
Quoted 143 lines
Quoted 143 lines
Quoted 7 lines
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c |   17 ++---------------
drivers/pci/iov.c                                  |   20 ++++++++++++++++++++
drivers/xen/xen-pciback/pci_stub.c                 |    4 ++--
include/linux/pci.h                                |    4 ++++
virt/kvm/assigned-dev.c                            |    2 +-
virt/kvm/iommu.c                                   |    4 ++--

- This patch touch 4 separate logical code areas, who do you expect to ack and commit it? Split it up.

Quoted 132 lines
6 files changed, 31 insertions(+), 20 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +2 -15
index 02c11a7..781040e 100644
@@ -693,22 +693,9 @@ complete_reset:
 static bool i40e_vfs_are_assigned(struct i40e_pf *pf)
 {
 struct pci_dev *pdev = pf->pdev;
-    struct pci_dev *vfdev;
-
-    /* loop through all the VFs to see if we own any that are assigned */
-    vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, I40E_DEV_ID_VF , NULL);
-    while (vfdev) {
-        /* if we don't own it we don't care */
-        if (vfdev->is_virtfn && pci_physfn(vfdev) == pdev) {
-            /* if it is assigned we cannot release it */
-            if (vfdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED)
-                return true;
-        }
 
-        vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
-                       I40E_DEV_ID_VF,
-                       vfdev);
-    }
+    if (pci_vfs_assigned(pdev))
+        return true;
 
 return false;
 }
drivers/pci/iov.c +20 -0
index de7a747..090f827 100644
@@ -644,6 +644,26 @@ int pci_vfs_assigned(struct pci_dev *dev)
 EXPORT_SYMBOL_GPL(pci_vfs_assigned);
 
 /**
+ * pci_iov_assign_device - assign device to VM
+ * @pdev: the device to be assigned.
+ */
+void pci_iov_assign_device(struct pci_dev *pdev)
+{
+    pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_assign_device);
+
+/**
+ * pci_iov_deassign_device - deasign device from VM
+ * @pdev: the device to be deassigned.
+ */
+void pci_iov_deassign_device(struct pci_dev *pdev)
+{
+    pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_deassign_device);
+
+/**
 * pci_sriov_set_totalvfs -- reduce the TotalVFs available
 * @dev: the PCI PF device
 * @numvfs: number that should be used for TotalVFs supported
drivers/xen/xen-pciback/pci_stub.c +2 -2
index 62fcd48..27e00d1 100644
@@ -133,7 +133,7 @@ static void pcistub_device_release(struct kref *kref)
 xen_pcibk_config_free_dyn_fields(dev);
 xen_pcibk_config_free_dev(dev);
 
-    dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(dev);
 pci_dev_put(dev);
 
 kfree(psdev);
@@ -404,7 +404,7 @@ static int pcistub_init_device(struct pci_dev *dev)
 dev_dbg(&dev->dev, "reset device\n");
 xen_pcibk_reset_device(dev);
 
-    dev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_assign_device(dev);
 return 0;
 

config_release:

include/linux/pci.h +4 -0
index aab57b4..5ece6d6 100644
@@ -1603,6 +1603,8 @@ int pci_num_vf(struct pci_dev *dev);
 int pci_vfs_assigned(struct pci_dev *dev);
 int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs);
 int pci_sriov_get_totalvfs(struct pci_dev *dev);
+void pci_iov_assign_device(struct pci_dev *dev);
+void pci_iov_deassign_device(struct pci_dev *dev);
 #else
 static inline int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn)
 { return -ENODEV; }
@@ -1614,6 +1616,8 @@ static inline int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs)
 { return 0; }
 static inline int pci_sriov_get_totalvfs(struct pci_dev *dev)
 { return 0; }
+static inline void pci_iov_assign_device(struct pci_dev *dev) { }
+static inline void pci_iov_deassign_device(struct pci_dev *dev) { }
 #endif
 
 #if defined(CONFIG_HOTPLUG_PCI) || defined(CONFIG_HOTPLUG_PCI_MODULE)
virt/kvm/assigned-dev.c +0 -0
index bf06577..7fac58d 100644
@@ -302,7 +302,7 @@ static void kvm_free_assigned_device(struct kvm *kvm,

else

    pci_restore_state(assigned_dev->dev);
virt/kvm/assigned-dev.c +1 -1
-    assigned_dev->dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(assigned_dev->dev);

pci_release_regions(assigned_dev->dev);
pci_disable_device(assigned_dev->dev);

virt/kvm/iommu.c +1 -1
index 0df7d4b..641ee73 100644
@@ -194,7 +194,7 @@ int kvm_assign_device(struct kvm *kvm,
        goto out_unmap;
 }
 
-    pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_assign_device(pdev);
 
 dev_info(&pdev->dev, "kvm assign device\n");
 
Quoted 11 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

virt/kvm/iommu.c int kvm_deassign_device(struct kvm *kvm, · line 225

Quoted 8 lines
virt/kvm/iommu.c +1 -1
@@ -220,7 +220,7 @@ int kvm_deassign_device(struct kvm *kvm,
 
 iommu_detach_device(domain, &pdev->dev);
 
-    pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(pdev);
 
 dev_info(&pdev->dev, "kvm deassign device\n");

------------------------------------------------------------------------------
_______________________________________________
E1000-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel&#174; Ethernet, visit http://communities.intel.com/community/wired

#15 lore raw
In reply to Alex Williamson
Quoted 77 lines · 在 2014年7月12日,上午12:13,Alex Williamson <[email protected]> 写道:
Quoted 74 lines · Ethan Zhao
Quoted 72 lines
Quoted 71 lines · 在 2014年7月11日,下午11:25,Alex Williamson <[email protected]> 写道:
Quoted 57 lines · Ethan Zhao
Quoted 57 lines · 在 2014年7月11日,下午10:54,Alex Williamson <[email protected]> 写道:
Quoted 41 lines · Ethan Zhao
Quoted 41 lines · 在 2014年7月11日,下午10:15,Alex Williamson <[email protected]> 写道:
Quoted 21 lines · Alex Williamson

On Fri, 2014-07-11 at 20:30 +0800, Ethan Zhao wrote:
This patch introduces two new device assignment functions

pci_iov_assign_device(),
pci_iov_deassign_device()

along with the existed one

pci_vfs_assigned()

They construct the VFs assignment management interface, used to assign/ deassign device to VM and query the VFs reference counter. instead of direct manipulation of device flag.

This patch refashioned the related code and make them atomic.

v3: change the naming of device assignment helpers, because they work for all kind of PCI device, not only SR-IOV ([email protected])

Quoted 6 lines

v2: reorder the patchset and make it bisectable and atomic, steps clear between interface defination and implemenation according to the suggestion from [email protected]

---

- Use a cover patch to describe the series

- Version information goes here, below the "---", not above it

- I stand by the patch breakdown I suggested originally, there are too many logical changes here in patch 1. There are easily 3 separate patches here.

- Renaming s/sriov/iov/ doesn't address the problem David raised. The name is still synonymous with SR-IOV and it's defined on drivers/pci/iov.c, which is only built with CONFIG_PCI_IOV.

Quoted 7 lines
Quoted 2 lines

- PCI_DEV_FLAGS_ASSIGNED should be unused after this series, why is it not removed?

I guess it's still used, which is even worse because now we have separate data elements, one tracking how many VFs are assigned from a PF and another tracking each device that's assigned. What are we actually gaining or fixing by doing this?

Of course it is used to tracking PF/VF assigned, what we gained are - we hide the details In assignment helpers, we wouldn't bother the users anymore and implement what inside The helpers, my initial purpose is to simplify the ugly pci_vfs_assigned() with counter.

Quoted 6 lines
Quoted 1 line

I don't want to push more change in one step, that would out of control to get perfect result.

But a counter means that we're tracking the data in two separate places, which is generally a bad idea. Cleaning up direct access to flags is fine, but creating a separate counter doesn't really seem to add any value.

If you are asked how many apples in your bag , you like to count them one by one and Give the answer ? What are you doing when you put them into the bag ?

Quoted 9 lines
Quoted 4 lines
Quoted 2 lines

If performance mattered, then yes, keeping a count may be advantageous. Performance does not matter in any path where this is used.

Not only performance, concurrency side-effect it caused. And less complication, lesser buggy.

I'd argue that it doesn't fix anything there, the count can still change after it's been read but before any action has been taken based on the count. The only thing it does is eliminate the act of re-counting.

why do you stop me simplifying the pci_vfs_assigned() code ?

Quoted 142 lines
Quoted 142 lines
Quoted 142 lines
Quoted 142 lines
Quoted 142 lines
Quoted 142 lines
Quoted 142 lines
Quoted 142 lines
Quoted 6 lines
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c |   17 ++---------------
drivers/pci/iov.c                                  |   20 ++++++++++++++++++++
drivers/xen/xen-pciback/pci_stub.c                 |    4 ++--
include/linux/pci.h                                |    4 ++++
virt/kvm/assigned-dev.c                            |    2 +-
virt/kvm/iommu.c                                   |    4 ++--

- This patch touch 4 separate logical code areas, who do you expect to ack and commit it? Split it up.

Quoted 132 lines
6 files changed, 31 insertions(+), 20 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +2 -15
index 02c11a7..781040e 100644
@@ -693,22 +693,9 @@ complete_reset:
 static bool i40e_vfs_are_assigned(struct i40e_pf *pf)
 {
 struct pci_dev *pdev = pf->pdev;
-    struct pci_dev *vfdev;
-
-    /* loop through all the VFs to see if we own any that are assigned */
-    vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, I40E_DEV_ID_VF , NULL);
-    while (vfdev) {
-        /* if we don't own it we don't care */
-        if (vfdev->is_virtfn && pci_physfn(vfdev) == pdev) {
-            /* if it is assigned we cannot release it */
-            if (vfdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED)
-                return true;
-        }
 
-        vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
-                       I40E_DEV_ID_VF,
-                       vfdev);
-    }
+    if (pci_vfs_assigned(pdev))
+        return true;
 
 return false;
 }
drivers/pci/iov.c +20 -0
index de7a747..090f827 100644
@@ -644,6 +644,26 @@ int pci_vfs_assigned(struct pci_dev *dev)
 EXPORT_SYMBOL_GPL(pci_vfs_assigned);
 
 /**
+ * pci_iov_assign_device - assign device to VM
+ * @pdev: the device to be assigned.
+ */
+void pci_iov_assign_device(struct pci_dev *pdev)
+{
+    pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_assign_device);
+
+/**
+ * pci_iov_deassign_device - deasign device from VM
+ * @pdev: the device to be deassigned.
+ */
+void pci_iov_deassign_device(struct pci_dev *pdev)
+{
+    pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_deassign_device);
+
+/**
 * pci_sriov_set_totalvfs -- reduce the TotalVFs available
 * @dev: the PCI PF device
 * @numvfs: number that should be used for TotalVFs supported
drivers/xen/xen-pciback/pci_stub.c +2 -2
index 62fcd48..27e00d1 100644
@@ -133,7 +133,7 @@ static void pcistub_device_release(struct kref *kref)
 xen_pcibk_config_free_dyn_fields(dev);
 xen_pcibk_config_free_dev(dev);
 
-    dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(dev);
 pci_dev_put(dev);
 
 kfree(psdev);
@@ -404,7 +404,7 @@ static int pcistub_init_device(struct pci_dev *dev)
 dev_dbg(&dev->dev, "reset device\n");
 xen_pcibk_reset_device(dev);
 
-    dev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_assign_device(dev);
 return 0;
 

config_release:

include/linux/pci.h +4 -0
index aab57b4..5ece6d6 100644
@@ -1603,6 +1603,8 @@ int pci_num_vf(struct pci_dev *dev);
 int pci_vfs_assigned(struct pci_dev *dev);
 int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs);
 int pci_sriov_get_totalvfs(struct pci_dev *dev);
+void pci_iov_assign_device(struct pci_dev *dev);
+void pci_iov_deassign_device(struct pci_dev *dev);
 #else
 static inline int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn)
 { return -ENODEV; }
@@ -1614,6 +1616,8 @@ static inline int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs)
 { return 0; }
 static inline int pci_sriov_get_totalvfs(struct pci_dev *dev)
 { return 0; }
+static inline void pci_iov_assign_device(struct pci_dev *dev) { }
+static inline void pci_iov_deassign_device(struct pci_dev *dev) { }
 #endif
 
 #if defined(CONFIG_HOTPLUG_PCI) || defined(CONFIG_HOTPLUG_PCI_MODULE)
virt/kvm/assigned-dev.c +0 -0
index bf06577..7fac58d 100644
@@ -302,7 +302,7 @@ static void kvm_free_assigned_device(struct kvm *kvm,

else

    pci_restore_state(assigned_dev->dev);
virt/kvm/assigned-dev.c +1 -1
-    assigned_dev->dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(assigned_dev->dev);

pci_release_regions(assigned_dev->dev);
pci_disable_device(assigned_dev->dev);

virt/kvm/iommu.c +1 -1
index 0df7d4b..641ee73 100644
@@ -194,7 +194,7 @@ int kvm_assign_device(struct kvm *kvm,
        goto out_unmap;
 }
 
-    pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_assign_device(pdev);
 
 dev_info(&pdev->dev, "kvm assign device\n");
 
Quoted 11 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

virt/kvm/iommu.c int kvm_deassign_device(struct kvm *kvm, · line 225

Quoted 8 lines
virt/kvm/iommu.c +1 -1
@@ -220,7 +220,7 @@ int kvm_deassign_device(struct kvm *kvm,
 
 iommu_detach_device(domain, &pdev->dev);
 
-    pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+    pci_iov_deassign_device(pdev);
 
 dev_info(&pdev->dev, "kvm deassign device\n");

------------------------------------------------------------------------------
_______________________________________________
E1000-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel&#174; Ethernet, visit http://communities.intel.com/community/wired

#16 lore raw
In reply to Alex Williamson
Quoted 7 lines · Alex Williamson
Quoted 6 lines · Ethan Zhao
Quoted 5 lines

This patch introduces two new device assignment functions

pci_iov_assign_device(),
pci_iov_deassign_device()

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

along with the existed one

pci_vfs_assigned()

They construct the VFs assignment management interface, used to assign/ deassign device to VM and query the VFs reference counter. instead of direct manipulation of device flag.

Sorry for the late intrusion into the conversation, and perhaps it's a bit unrelated, but given that you're creating a 'VF assignment management' perhaps it's the right place to add some sort of mechanism in order to prevent module removal once one of its VFs is assigned.
[e.g., incrementing module reference count]

At the moment [to the best of my knowledge] there's no mechanism preventing the 'not-so-bright' user from removing the driver, and no good will come out of it.

Thanks,
Yuval

________________________________

This message and any attached documents contain information from QLogic Corporation or its wholly-owned subsidiaries that may be confidential. If you are not the intended recipient, you may not read, copy, distribute, or use this information. If you have received this transmission in error, please notify the sender immediately by reply e-mail and then delete this message.
------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
E1000-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel&#174; Ethernet, visit http://communities.intel.com/community/wired

#17 lore raw
Quoted 21 lines · Yuval Mintz
Quoted 7 lines · Alex Williamson
Quoted 6 lines · Ethan Zhao
Quoted 5 lines

This patch introduces two new device assignment functions

pci_iov_assign_device(),
pci_iov_deassign_device()

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

along with the existed one

pci_vfs_assigned()

They construct the VFs assignment management interface, used to assign/ deassign device to VM and query the VFs reference counter. instead of direct manipulation of device flag.

Sorry for the late intrusion into the conversation, and perhaps it's a bit unrelated, but given that you're creating a 'VF assignment management' perhaps it's the right place to add some sort of mechanism in order to prevent module removal once one of its VFs is assigned.
[e.g., incrementing module reference count]

Quoted 3 lines

At the moment [to the best of my knowledge] there's no mechanism preventing the 'not-so-bright' user from removing the driver, and no good will come out of it.

On what module would the reference count be increased, the PF? The entire "VF assigned" interface is a hack to work around poor architectures like legacy KVM device assignment where there's no proper device owner for the VF. This is "fixed" by using VFIO instead and hopefully deprecating legacy KVM assignment. Thanks,

Alex

------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
E1000-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel&#174; Ethernet, visit http://communities.intel.com/community/wired

#18 lore raw
Quoted 26 lines · Alex Williamson
Quoted 21 lines · Yuval Mintz
Quoted 7 lines · Alex Williamson
Quoted 6 lines · Ethan Zhao
Quoted 5 lines

This patch introduces two new device assignment functions

pci_iov_assign_device(),
pci_iov_deassign_device()

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

along with the existed one

pci_vfs_assigned()

They construct the VFs assignment management interface, used to assign/ deassign device to VM and query the VFs reference counter. instead of direct manipulation of device flag.

Sorry for the late intrusion into the conversation, and perhaps it's a bit unrelated, but given that you're creating a 'VF assignment management' perhaps it's the right place to add some sort of mechanism in order to prevent module removal once one of its VFs is assigned.
[e.g., incrementing module reference count]

Quoted 3 lines

At the moment [to the best of my knowledge] there's no mechanism preventing the 'not-so-bright' user from removing the driver, and no good will come out of it.

Quoted 5 lines

On what module would the reference count be increased, the PF? The entire "VF assigned" interface is a hack to work around poor architectures like legacy KVM device assignment where there's no proper device owner for the VF. This is "fixed" by using VFIO instead and hopefully deprecating legacy KVM assignment. Thanks,

To explain what Alex said, in another word, if VMs access VF via
VFIO driver, the owner of the device is VFIO, in this case, if you unload PF driver, you still need to unload VFIO first, then unload PF driver. but the PF driver knows how to notify the VFIO driver to unload.
But without VFIO like driver, for example some of current code will
assign devcie (PF/VF) directly to KVM or XEN without driver in the middle. and the PF driver doesn't know how to unbind the assignment...

Thanks,
Ethan

Quoted 3 lines

Alex

------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
E1000-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel&#174; Ethernet, visit http://communities.intel.com/community/wired

#26 lore raw
In reply to Yuval Mintz
Quoted 15 lines · Yuval Mintz
Quoted 7 lines · Alex Williamson
Quoted 6 lines · Ethan Zhao
Quoted 5 lines

This patch introduces two new device assignment functions

pci_iov_assign_device(),
pci_iov_deassign_device()

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

along with the existed one

pci_vfs_assigned()

They construct the VFs assignment management interface, used to assign/ deassign device to VM and query the VFs reference counter. instead of direct manipulation of device flag.

Quoted 5 lines

Sorry for the late intrusion into the conversation, and perhaps it's a bit unrelated, but given that you're creating a 'VF assignment management' perhaps it's the right place to add some sort of mechanism in order to prevent module removal once one of its VFs is assigned.
[e.g., incrementing module reference count]

This patch set is used to make the current hacked code well formed and make
the interface clear to refactory later. so we could keep the current direct assignment and woulnd't encounter the removal issue etc. in one word, manageable.

Quoted 4 lines

At the moment [to the best of my knowledge] there's no mechanism preventing the 'not-so-bright' user from removing the driver, and no good will come out of it.

The best way is there is real 'driver' between device and the VM
device manager or some similar machanism to make the assignment manageable.

Thanks,
Ethan

Quoted 7 lines

Thanks,
Yuval

________________________________

This message and any attached documents contain information from QLogic Corporation or its wholly-owned subsidiaries that may be confidential. If you are not the intended recipient, you may not read, copy, distribute, or use this information. If you have received this transmission in error, please notify the sender immediately by reply e-mail and then delete this message.

------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
E1000-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel&#174; Ethernet, visit http://communities.intel.com/community/wired

#19 lore raw
In reply to Ethan Zhao
Quoted 29 lines
Quoted 23 lines
Quoted 19 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

This patch introduces two new device assignment functions

pci_iov_assign_device(),
pci_iov_deassign_device()

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

along with the existed one

pci_vfs_assigned()

They construct the VFs assignment management interface, used to assign/ deassign device to VM and query the VFs reference counter. instead of direct manipulation of device flag.

Sorry for the late intrusion into the conversation, and perhaps it's a bit unrelated, but given that you're creating a 'VF assignment management' perhaps it's the right place to add some sort of mechanism in order to prevent module removal once one of its VFs is assigned. [e.g., incrementing module reference count]

Quoted 3 lines

At the moment [to the best of my knowledge] there's no mechanism preventing the 'not-so-bright' user from removing the driver, and no good will come out of it.

Quoted 5 lines

On what module would the reference count be increased, the PF? The entire "VF assigned" interface is a hack to work around poor architectures like legacy KVM device assignment where there's no proper device owner for the VF. This is "fixed" by using VFIO instead and hopefully deprecating legacy KVM assignment. Thanks,

Quoted 7 lines

To explain what Alex said, in another word, if VMs access VF via VFIO driver,
the owner of the device is VFIO, in this case, if you unload PF driver, you still need to unload VFIO first, then unload PF driver. but the PF driver knows how to notify the VFIO driver to unload.
But without VFIO like driver, for example some of current code will assign
devcie (PF/VF) directly to KVM or XEN without driver in the middle. and the PF driver doesn't know how to unbind the assignment...

Hi,

I thought about perhaps incrementing the reference count of the PF's module [i.e., the module supplying the driver for the PF] directly, so THAT module won't be removable as long as the VF is assigned.

Although I don't know whether the module is even accessible; Can you derive a pointer to a module from a net_device struct?

Thanks,
Yuval

________________________________

This message and any attached documents contain information from QLogic Corporation or its wholly-owned subsidiaries that may be confidential. If you are not the intended recipient, you may not read, copy, distribute, or use this information. If you have received this transmission in error, please notify the sender immediately by reply e-mail and then delete this message.
------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
E1000-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel&#174; Ethernet, visit http://communities.intel.com/community/wired

#20 lore raw
Quoted 37 lines · Yuval Mintz
Quoted 29 lines
Quoted 23 lines
Quoted 19 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

This patch introduces two new device assignment functions

pci_iov_assign_device(),
pci_iov_deassign_device()

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

along with the existed one

pci_vfs_assigned()

They construct the VFs assignment management interface, used to assign/ deassign device to VM and query the VFs reference counter. instead of direct manipulation of device flag.

Sorry for the late intrusion into the conversation, and perhaps it's a bit unrelated, but given that you're creating a 'VF assignment management' perhaps it's the right place to add some sort of mechanism in order to prevent module removal once one of its VFs is assigned. [e.g., incrementing module reference count]

Quoted 3 lines

At the moment [to the best of my knowledge] there's no mechanism preventing the 'not-so-bright' user from removing the driver, and no good will come out of it.

Quoted 5 lines

On what module would the reference count be increased, the PF? The entire "VF assigned" interface is a hack to work around poor architectures like legacy KVM device assignment where there's no proper device owner for the VF. This is "fixed" by using VFIO instead and hopefully deprecating legacy KVM assignment. Thanks,

Quoted 7 lines

To explain what Alex said, in another word, if VMs access VF via VFIO driver,
the owner of the device is VFIO, in this case, if you unload PF driver, you still need to unload VFIO first, then unload PF driver. but the PF driver knows how to notify the VFIO driver to unload.
But without VFIO like driver, for example some of current code will assign
devcie (PF/VF) directly to KVM or XEN without driver in the middle. and the PF driver doesn't know how to unbind the assignment...

Quoted 8 lines

Hi,

I thought about perhaps incrementing the reference count of the PF's module [i.e., the module supplying the driver for the PF] directly, so THAT module won't be removable as long as the VF is assigned.

Although I don't know whether the module is even accessible; Can you derive a pointer to a module from a net_device struct?

A VF is not necessarily a net device. A pci_dev does have a physfn pointer though.

------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
E1000-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel&#174; Ethernet, visit http://communities.intel.com/community/wired

#21 lore raw
Quoted 30 lines
Quoted 30 lines
Quoted 18 lines
Quoted 12 lines
Quoted 12 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

pci_iov_assign_device(),
pci_iov_deassign_device()

along with the existed one

pci_vfs_assigned()

They construct the VFs assignment management interface,

perhaps it's the right place to add some sort of mechanism in order to prevent module removal once one of its VFs is assigned. [e.g., incrementing module reference count]

Quoted 5 lines

On what module would the reference count be increased, the PF? The entire "VF assigned" interface is a hack to work around poor architectures like legacy KVM device assignment where there's no proper device owner for the VF. This is "fixed" by using VFIO instead and hopefully deprecating legacy KVM assignment. Thanks,

Quoted 7 lines

To explain what Alex said, in another word, if VMs access VF via
VFIO driver, the owner of the device is VFIO, in this case, if you unload PF driver, you still need to unload VFIO first, then unload PF driver. but the PF driver knows how to notify the VFIO driver to unload.
But without VFIO like driver, for example some of current code
will assign devcie (PF/VF) directly to KVM or XEN without driver in the middle. and the PF driver doesn't know how to unbind the assignment...

I thought about perhaps incrementing the reference count of the PF's module [i.e., the module supplying the driver for the PF] directly, so THAT module won't be removable as long as the VF is assigned.

Quoted 5 lines
Quoted 2 lines

Although I don't know whether the module is even accessible; Can you derive a pointer to a module from a net_device struct?

A VF is not necessarily a net device. A pci_dev does have a physfn pointer though.

I stand corrected.

Is there anything inherently wrong about this approach, though?

________________________________

This message and any attached documents contain information from QLogic Corporation or its wholly-owned subsidiaries that may be confidential. If you are not the intended recipient, you may not read, copy, distribute, or use this information. If you have received this transmission in error, please notify the sender immediately by reply e-mail and then delete this message.
------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
E1000-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel&#174; Ethernet, visit http://communities.intel.com/community/wired

#22 lore raw
Quoted 33 lines · Yuval Mintz
Quoted 33 lines
Quoted 32 lines
Quoted 18 lines
Quoted 12 lines
Quoted 12 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

pci_iov_assign_device(),
pci_iov_deassign_device()

along with the existed one

pci_vfs_assigned()

They construct the VFs assignment management interface,

perhaps it's the right place to add some sort of mechanism in order to prevent module removal once one of its VFs is assigned. [e.g., incrementing module reference count]

Quoted 5 lines

On what module would the reference count be increased, the PF? The entire "VF assigned" interface is a hack to work around poor architectures like legacy KVM device assignment where there's no proper device owner for the VF. This is "fixed" by using VFIO instead and hopefully deprecating legacy KVM assignment. Thanks,

Quoted 7 lines

To explain what Alex said, in another word, if VMs access VF via
VFIO driver, the owner of the device is VFIO, in this case, if you unload PF driver, you still need to unload VFIO first, then unload PF driver. but the PF driver knows how to notify the VFIO driver to unload.
But without VFIO like driver, for example some of current code
will assign devcie (PF/VF) directly to KVM or XEN without driver in the middle. and the PF driver doesn't know how to unbind the assignment...

I thought about perhaps incrementing the reference count of the PF's module [i.e., the module supplying the driver for the PF] directly, so THAT module won't be removable as long as the VF is assigned.

Although I don't know whether the module is even accessible; Can you derive a pointer to a module from a net_device struct?

Quoted 6 lines
Quoted 2 lines

A VF is not necessarily a net device. A pci_dev does have a physfn pointer though.

I stand corrected.

Is there anything inherently wrong about this approach, though?

What does incrementing the module reference on the PF driver accomplish? We can still unbind the PF device from the driver. That's what this "VF used" flag is supposed to accomplish is preventing the PF from unbinding from the driver while VFs are in use, but as has been noted, it's a terrible hack.

BTW, the below corporate disclaimer below is really inappropriate for the mailing list. Thanks,

Alex

Quoted 8 lines

________________________________

This message and any attached documents contain information from QLogic Corporation or its wholly-owned subsidiaries that may be confidential. If you are not the intended recipient, you may not read, copy, distribute, or use this information. If you have received this transmission in error, please notify the sender immediately by reply e-mail and then delete this message.

------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
E1000-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel&#174; Ethernet, visit http://communities.intel.com/community/wired

#23 lore raw
Quoted 37 lines · Alex Williamson
Quoted 36 lines · Yuval Mintz
Quoted 35 lines
Quoted 26 lines
Quoted 18 lines
Quoted 12 lines
Quoted 12 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

pci_iov_assign_device(),
pci_iov_deassign_device()

along with the existed one

pci_vfs_assigned()

They construct the VFs assignment management interface,

perhaps it's the right place to add some sort of mechanism in order to prevent module removal once one of its VFs is assigned. [e.g., incrementing module reference count]

Quoted 5 lines

On what module would the reference count be increased, the PF? The entire "VF assigned" interface is a hack to work around poor architectures like legacy KVM device assignment where there's no proper device owner for the VF. This is "fixed" by using VFIO instead and hopefully deprecating legacy KVM assignment. Thanks,

Quoted 7 lines

To explain what Alex said, in another word, if VMs access VF via
VFIO driver, the owner of the device is VFIO, in this case, if you unload PF driver, you still need to unload VFIO first, then unload PF driver. but the PF driver knows how to notify the VFIO driver to unload.
But without VFIO like driver, for example some of current code
will assign devcie (PF/VF) directly to KVM or XEN without driver in the middle. and the PF driver doesn't know how to unbind the assignment...

Quoted 6 lines

I thought about perhaps incrementing the reference count of the PF's module [i.e., the module supplying the driver for the PF] directly, so THAT module won't be removable as long as the VF is assigned.

Although I don't know whether the module is even accessible; Can you derive a pointer to a module from a net_device struct?

A VF is not necessarily a net device. A pci_dev does have a physfn pointer though.

Quoted 6 lines
Quoted 3 lines

I stand corrected.

Is there anything inherently wrong about this approach, though?

What does incrementing the module reference on the PF driver accomplish? We can still unbind the PF device from the driver. That's what this "VF

Unbind PF from its original driver should be OK. regarding some current hacked implementation that assign PF/VF to KVM/XEN without driver, unbing or removal to them is nightmare, maybe the best thing we could do is "device is in using, please
release..."

Quoted 3 lines

used" flag is supposed to accomplish is preventing the PF from unbinding from the driver while VFs are in use, but as has been noted, it's a terrible hack.

Yep.

Ethan

Quoted 10 lines

BTW, the below corporate disclaimer below is really inappropriate for the mailing list. Thanks,

Alex

Quoted 1 line

________________________________

------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
E1000-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel&#174; Ethernet, visit http://communities.intel.com/community/wired

#32 lore raw
In reply to Ethan Zhao
Quoted 51 lines · Ethan Zhao

This patch introduces two new device assignment functions

pci_iov_assign_device(),
pci_iov_deassign_device()

along with the existed one

pci_vfs_assigned()

They construct the VFs assignment management interface, used to assign/ deassign device to VM and query the VFs reference counter. instead of direct manipulation of device flag.

This patch refashioned the related code and make them atomic.

v3: change the naming of device assignment helpers, because they work for all kind of PCI device, not only SR-IOV ([email protected])

v2: reorder the patchset and make it bisectable and atomic, steps clear between interface defination and implemenation according to the suggestion from [email protected]

---
 drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c |   17 ++---------------
 drivers/pci/iov.c                                  |   20 ++++++++++++++++++++
 drivers/xen/xen-pciback/pci_stub.c                 |    4 ++--
 include/linux/pci.h                                |    4 ++++
 virt/kvm/assigned-dev.c                            |    2 +-
 virt/kvm/iommu.c                                   |    4 ++--
 6 files changed, 31 insertions(+), 20 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +0 -11
index 02c11a7..781040e 100644
@@ -693,22 +693,9 @@ complete_reset:
 static bool i40e_vfs_are_assigned(struct i40e_pf *pf)
 {
 	struct pci_dev *pdev = pf->pdev;
-	struct pci_dev *vfdev;
-
-	/* loop through all the VFs to see if we own any that are assigned */
-	vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, I40E_DEV_ID_VF , NULL);
-	while (vfdev) {
-		/* if we don't own it we don't care */
-		if (vfdev->is_virtfn && pci_physfn(vfdev) == pdev) {
-			/* if it is assigned we cannot release it */
-			if (vfdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED)
-				return true;
-		}

drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c complete_reset: · line 701

Quoted 10 lines
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +2 -4
 
-		vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
-				       I40E_DEV_ID_VF,
-				       vfdev);
-	}
+	if (pci_vfs_assigned(pdev))
+		return true;
 
 	return false;
 }

This portion for i40e should be in one patch by itself. It shouldn't be included in the bits below. Normally this would go through netdev. The rest of this below would go through linux-pci.

Quoted 21 lines
drivers/pci/iov.c +13 -0
index de7a747..090f827 100644
@@ -644,6 +644,26 @@ int pci_vfs_assigned(struct pci_dev *dev)
 EXPORT_SYMBOL_GPL(pci_vfs_assigned);
 
 /**
+ * pci_iov_assign_device - assign device to VM
+ * @pdev: the device to be assigned.
+ */
+void pci_iov_assign_device(struct pci_dev *pdev)
+{
+	pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_assign_device);
+
+/**
+ * pci_iov_deassign_device - deasign device from VM
+ * @pdev: the device to be deassigned.
+ */

drivers/pci/iov.c int pci_vfs_assigned(struct pci_dev *dev) · line 669

Quoted 10 lines
drivers/pci/iov.c +7 -0
+void pci_iov_deassign_device(struct pci_dev *pdev)
+{
+	pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_deassign_device);
+
+/**
  * pci_sriov_set_totalvfs -- reduce the TotalVFs available
  * @dev: the PCI PF device
  * @numvfs: number that should be used for TotalVFs supported

The two functions above don't have anything to do with IOV. You can direct assign a device that doesn't even support SR-IOV or MR-IOV. You might be better off defining this as something like "pci_set_flag_assigned/pci_clear_flag_assigned". I would likely also make them inline and possibly move them to pci.h since it would likely result in less actual code after you consider the overhead to push everything on the stack prior to making the call.

Quoted 80 lines
drivers/xen/xen-pciback/pci_stub.c +2 -2
index 62fcd48..27e00d1 100644
@@ -133,7 +133,7 @@ static void pcistub_device_release(struct kref *kref)
 	xen_pcibk_config_free_dyn_fields(dev);
 	xen_pcibk_config_free_dev(dev);
 
-	dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+	pci_iov_deassign_device(dev);
 	pci_dev_put(dev);
 
 	kfree(psdev);
@@ -404,7 +404,7 @@ static int pcistub_init_device(struct pci_dev *dev)
 	dev_dbg(&dev->dev, "reset device\n");
 	xen_pcibk_reset_device(dev);
 
-	dev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+	pci_iov_assign_device(dev);
 	return 0;
 
 config_release:
include/linux/pci.h +4 -0
index aab57b4..5ece6d6 100644
@@ -1603,6 +1603,8 @@ int pci_num_vf(struct pci_dev *dev);
 int pci_vfs_assigned(struct pci_dev *dev);
 int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs);
 int pci_sriov_get_totalvfs(struct pci_dev *dev);
+void pci_iov_assign_device(struct pci_dev *dev);
+void pci_iov_deassign_device(struct pci_dev *dev);
 #else
 static inline int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn)
 { return -ENODEV; }
@@ -1614,6 +1616,8 @@ static inline int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs)
 { return 0; }
 static inline int pci_sriov_get_totalvfs(struct pci_dev *dev)
 { return 0; }
+static inline void pci_iov_assign_device(struct pci_dev *dev) { }
+static inline void pci_iov_deassign_device(struct pci_dev *dev) { }
 #endif
 
 #if defined(CONFIG_HOTPLUG_PCI) || defined(CONFIG_HOTPLUG_PCI_MODULE)
virt/kvm/assigned-dev.c +1 -1
index bf06577..7fac58d 100644
@@ -302,7 +302,7 @@ static void kvm_free_assigned_device(struct kvm *kvm,
 	else
 		pci_restore_state(assigned_dev->dev);
 
-	assigned_dev->dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+	pci_iov_deassign_device(assigned_dev->dev);
 
 	pci_release_regions(assigned_dev->dev);
 	pci_disable_device(assigned_dev->dev);
virt/kvm/iommu.c +2 -2
index 0df7d4b..641ee73 100644
@@ -194,7 +194,7 @@ int kvm_assign_device(struct kvm *kvm,
 			goto out_unmap;
 	}
 
-	pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+	pci_iov_assign_device(pdev);
 
 	dev_info(&pdev->dev, "kvm assign device\n");
 
@@ -220,7 +220,7 @@ int kvm_deassign_device(struct kvm *kvm,
 
 	iommu_detach_device(domain, &pdev->dev);
 
-	pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+	pci_iov_deassign_device(pdev);
 
 	dev_info(&pdev->dev, "kvm deassign device\n");
 
#24 lore raw
In reply to Alex Williamson
Quoted 39 lines · Alex Williamson
Quoted 38 lines · Yuval Mintz
Quoted 30 lines
Quoted 30 lines
Quoted 18 lines
Quoted 12 lines
Quoted 12 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

pci_iov_assign_device(),
pci_iov_deassign_device()

along with the existed one

pci_vfs_assigned()

They construct the VFs assignment management interface,

perhaps it's the right place to add some sort of mechanism in order to prevent module removal once one of its VFs is assigned. [e.g., incrementing module reference count]

Quoted 5 lines

On what module would the reference count be increased, the PF? The entire "VF assigned" interface is a hack to work around poor architectures like legacy KVM device assignment where there's no proper device owner for the VF. This is "fixed" by using VFIO instead and hopefully deprecating legacy KVM assignment. Thanks,

Quoted 7 lines

To explain what Alex said, in another word, if VMs access VF via
VFIO driver, the owner of the device is VFIO, in this case, if you unload PF driver, you still need to unload VFIO first, then unload PF driver. but the PF driver knows how to notify the VFIO driver to unload.
But without VFIO like driver, for example some of current code
will assign devcie (PF/VF) directly to KVM or XEN without driver in the middle. and the PF driver doesn't know how to unbind the assignment...

I thought about perhaps incrementing the reference count of the PF's module [i.e., the module supplying the driver for the PF] directly, so THAT module won't be removable as long as the VF is assigned.

Quoted 5 lines
Quoted 2 lines

Although I don't know whether the module is even accessible; Can you derive a pointer to a module from a net_device struct?

A VF is not necessarily a net device. A pci_dev does have a physfn pointer though.

I stand corrected.

Quoted 8 lines
Quoted 1 line

Is there anything inherently wrong about this approach, though?

What does incrementing the module reference on the PF driver accomplish? We can still unbind the PF device from the driver. That's what this "VF used" flag is supposed to accomplish is preventing the PF from unbinding from the driver while VFs are in use, but as has been noted, it's a terrible hack.

Keep in mind there are also use cases such as what occurs in igb/ixgbe where the PF driver can be swapped out while the VFs are left in place.
Nothing explicitly says we cannot unload the PF driver while the VFs
are assigned, we just cannot free the VFs or disable SR-IOV while they are assigned.

In that scenario we just force the link down on the link state down on the VFs while the PF is not present. I'm not sure how many people make use of the behavior but that is currently how we end up supporting it for igb/ixgbe.

One approach would be to use a reference count for the SR-IOV itself. I know in the case of the igb/ixgbe drivers we use the assigned number of VFs to determine if we can change the number of VFs allocated or not. I imagine you could probably just use the assigned count as a reference count and if it is non-zero prevent SR-IOV from being disabled.

Thanks,

Alex

------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
E1000-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel&#174; Ethernet, visit http://communities.intel.com/community/wired

#25 lore raw
Quoted 49 lines · Alexander Duyck
Quoted 39 lines · Alex Williamson
Quoted 38 lines · Yuval Mintz
Quoted 30 lines
Quoted 30 lines
Quoted 18 lines
Quoted 12 lines
Quoted 12 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

pci_iov_assign_device(),
pci_iov_deassign_device()

along with the existed one

pci_vfs_assigned()

They construct the VFs assignment management interface,

perhaps it's the right place to add some sort of mechanism in order to prevent module removal once one of its VFs is assigned. [e.g., incrementing module reference count]

Quoted 5 lines

On what module would the reference count be increased, the PF? The entire "VF assigned" interface is a hack to work around poor architectures like legacy KVM device assignment where there's no proper device owner for the VF. This is "fixed" by using VFIO instead and hopefully deprecating legacy KVM assignment. Thanks,

Quoted 7 lines

To explain what Alex said, in another word, if VMs access VF via
VFIO driver, the owner of the device is VFIO, in this case, if you unload PF driver, you still need to unload VFIO first, then unload PF driver. but the PF driver knows how to notify the VFIO driver to unload.
But without VFIO like driver, for example some of current code
will assign devcie (PF/VF) directly to KVM or XEN without driver in the middle. and the PF driver doesn't know how to unbind the assignment...

I thought about perhaps incrementing the reference count of the PF's module [i.e., the module supplying the driver for the PF] directly, so THAT module won't be removable as long as the VF is assigned.

Quoted 5 lines
Quoted 2 lines

Although I don't know whether the module is even accessible; Can you derive a pointer to a module from a net_device struct?

A VF is not necessarily a net device. A pci_dev does have a physfn pointer though.

I stand corrected.

Quoted 8 lines
Quoted 1 line

Is there anything inherently wrong about this approach, though?

What does incrementing the module reference on the PF driver accomplish? We can still unbind the PF device from the driver. That's what this "VF used" flag is supposed to accomplish is preventing the PF from unbinding from the driver while VFs are in use, but as has been noted, it's a terrible hack.

Quoted 5 lines

Keep in mind there are also use cases such as what occurs in igb/ixgbe where the PF driver can be swapped out while the VFs are left in place.
Nothing explicitly says we cannot unload the PF driver while the VFs
are assigned, we just cannot free the VFs or disable SR-IOV while they are assigned.

unbind one PF from the driver but keep the VF reside in it ? the meanwhile not shutdown the PF ?

Quoted 5 lines

In that scenario we just force the link down on the link state down on the VFs while the PF is not present. I'm not sure how many people make use of the behavior but that is currently how we end up supporting it for igb/ixgbe.

Roger !

Quoted 6 lines

One approach would be to use a reference count for the SR-IOV itself. I know in the case of the igb/ixgbe drivers we use the assigned number of VFs to determine if we can change the number of VFs allocated or not. I imagine you could probably just use the assigned count as a reference count and if it is non-zero prevent SR-IOV from being disabled.

I am managing to figure out a way to cut out the VFs assigned checking before
disable SR_IOV... ...

Maybe via composing pseudo PCI driver for every user VF/PF assigned
to them ?
but does it work when PF swap out without touching VF as you mentioned ?

Thanks,
Ethan

Quoted 5 lines

Thanks,

Alex

------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
E1000-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel&#174; Ethernet, visit http://communities.intel.com/community/wired

#33 lore raw
In reply to Alexander Duyck
Quoted 60 lines · Alexander Duyck
Quoted 59 lines · Ethan Zhao

This patch introduces two new device assignment functions

pci_iov_assign_device(),
pci_iov_deassign_device()

along with the existed one

pci_vfs_assigned()

They construct the VFs assignment management interface, used to assign/ deassign device to VM and query the VFs reference counter. instead of direct manipulation of device flag.

This patch refashioned the related code and make them atomic.

v3: change the naming of device assignment helpers, because they work for all kind of PCI device, not only SR-IOV ([email protected])

v2: reorder the patchset and make it bisectable and atomic, steps clear between interface defination and implemenation according to the suggestion from [email protected]

---
 drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c |   17 ++---------------
 drivers/pci/iov.c                                  |   20 ++++++++++++++++++++
 drivers/xen/xen-pciback/pci_stub.c                 |    4 ++--
 include/linux/pci.h                                |    4 ++++
 virt/kvm/assigned-dev.c                            |    2 +-
 virt/kvm/iommu.c                                   |    4 ++--
 6 files changed, 31 insertions(+), 20 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +2 -15
index 02c11a7..781040e 100644
@@ -693,22 +693,9 @@ complete_reset:
 static bool i40e_vfs_are_assigned(struct i40e_pf *pf)
 {
      struct pci_dev *pdev = pf->pdev;
-     struct pci_dev *vfdev;
-
-     /* loop through all the VFs to see if we own any that are assigned */
-     vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, I40E_DEV_ID_VF , NULL);
-     while (vfdev) {
-             /* if we don't own it we don't care */
-             if (vfdev->is_virtfn && pci_physfn(vfdev) == pdev) {
-                     /* if it is assigned we cannot release it */
-                     if (vfdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED)
-                             return true;
-             }
 
-             vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
-                                    I40E_DEV_ID_VF,
-                                    vfdev);
-     }
+     if (pci_vfs_assigned(pdev))
+             return true;
 
Quoted 6 lines

drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c complete_reset: · line 701

Quoted 2 lines
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +0 -0
      return false;
 }

This portion for i40e should be in one patch by itself. It shouldn't be included in the bits below. Normally this would go through netdev. The rest of this below would go through linux-pci.

Agree, thanks.

Quoted 33 lines
Quoted 22 lines
drivers/pci/iov.c +13 -0
index de7a747..090f827 100644
@@ -644,6 +644,26 @@ int pci_vfs_assigned(struct pci_dev *dev)
 EXPORT_SYMBOL_GPL(pci_vfs_assigned);
 
 /**
+ * pci_iov_assign_device - assign device to VM
+ * @pdev: the device to be assigned.
+ */
+void pci_iov_assign_device(struct pci_dev *pdev)
+{
+     pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_assign_device);
+
+/**
+ * pci_iov_deassign_device - deasign device from VM
+ * @pdev: the device to be deassigned.
+ */

drivers/pci/iov.c int pci_vfs_assigned(struct pci_dev *dev) · line 669

Quoted 10 lines
drivers/pci/iov.c +7 -0
+void pci_iov_deassign_device(struct pci_dev *pdev)
+{
+     pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+}
+EXPORT_SYMBOL_GPL(pci_iov_deassign_device);
+
+/**
  * pci_sriov_set_totalvfs -- reduce the TotalVFs available
  * @dev: the PCI PF device
  * @numvfs: number that should be used for TotalVFs supported
Quoted 7 lines

The two functions above don't have anything to do with IOV. You can direct assign a device that doesn't even support SR-IOV or MR-IOV. You might be better off defining this as something like "pci_set_flag_assigned/pci_clear_flag_assigned". I would likely also make them inline and possibly move them to pci.h since it would likely result in less actual code after you consider the overhead to push everything on the stack prior to making the call

Agree, if I still stand for this set of helpers.

Quoted 73 lines
Quoted 73 lines
drivers/xen/xen-pciback/pci_stub.c +2 -2
index 62fcd48..27e00d1 100644
@@ -133,7 +133,7 @@ static void pcistub_device_release(struct kref *kref)
      xen_pcibk_config_free_dyn_fields(dev);
      xen_pcibk_config_free_dev(dev);
 
-     dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+     pci_iov_deassign_device(dev);
      pci_dev_put(dev);
 
      kfree(psdev);
@@ -404,7 +404,7 @@ static int pcistub_init_device(struct pci_dev *dev)
      dev_dbg(&dev->dev, "reset device\n");
      xen_pcibk_reset_device(dev);
 
-     dev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+     pci_iov_assign_device(dev);
      return 0;
 
 config_release:
include/linux/pci.h +4 -0
index aab57b4..5ece6d6 100644
@@ -1603,6 +1603,8 @@ int pci_num_vf(struct pci_dev *dev);
 int pci_vfs_assigned(struct pci_dev *dev);
 int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs);
 int pci_sriov_get_totalvfs(struct pci_dev *dev);
+void pci_iov_assign_device(struct pci_dev *dev);
+void pci_iov_deassign_device(struct pci_dev *dev);
 #else
 static inline int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn)
 { return -ENODEV; }
@@ -1614,6 +1616,8 @@ static inline int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs)
 { return 0; }
 static inline int pci_sriov_get_totalvfs(struct pci_dev *dev)
 { return 0; }
+static inline void pci_iov_assign_device(struct pci_dev *dev) { }
+static inline void pci_iov_deassign_device(struct pci_dev *dev) { }
 #endif
 
 #if defined(CONFIG_HOTPLUG_PCI) || defined(CONFIG_HOTPLUG_PCI_MODULE)
virt/kvm/assigned-dev.c +1 -1
index bf06577..7fac58d 100644
@@ -302,7 +302,7 @@ static void kvm_free_assigned_device(struct kvm *kvm,
      else
              pci_restore_state(assigned_dev->dev);
 
-     assigned_dev->dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+     pci_iov_deassign_device(assigned_dev->dev);
 
      pci_release_regions(assigned_dev->dev);
      pci_disable_device(assigned_dev->dev);
virt/kvm/iommu.c +1 -1
index 0df7d4b..641ee73 100644
@@ -194,7 +194,7 @@ int kvm_assign_device(struct kvm *kvm,
                      goto out_unmap;
      }
 
-     pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
+     pci_iov_assign_device(pdev);
 
      dev_info(&pdev->dev, "kvm assign device\n");
 
@@ -220,7 +220,7 @@ int kvm_deassign_device(struct kvm *kvm,
 
Quoted 9 lines

virt/kvm/iommu.c int kvm_deassign_device(struct kvm *kvm, · line 226

Quoted 8 lines
virt/kvm/iommu.c +1 -1
      iommu_detach_device(domain, &pdev->dev);
 
-     pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
+     pci_iov_deassign_device(pdev);
 
      dev_info(&pdev->dev, "kvm deassign device\n");
 

------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
E1000-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel&#174; Ethernet, visit http://communities.intel.com/community/wired