From: Alexander Duyck <alexander.duyck@gmail.com>
To: Mark D Rustad <mark.d.rustad@intel.com>, bhelgaas@google.com
Cc: linux-pci@vger.kernel.org, intel-wired-lan@lists.osuosl.org,
netdev@vger.kernel.org
Subject: Re: [Intel-wired-lan] [PATCH V2 1/2] pci: Add dev_flags bit to access VPD through function 0
Date: Tue, 02 Jun 2015 19:28:55 -0700 [thread overview]
Message-ID: <556E6667.1020000@gmail.com> (raw)
In-Reply-To: <20150603001011.71269.79857.stgit@mdrustad-wks.jf.intel.com>
On 06/02/2015 05:10 PM, Mark D Rustad wrote:
> Add a dev_flags bit, PCI_DEV_FLAGS_VPD_REF_F0, to access VPD through
> function 0 to provide VPD access on other functions. This solves
> concurrent access problems on many devices without changing the
> attributes exposed in sysfs. Never set this bit on function 0 or
> there will be an infinite recursion.
>
> Signed-off-by: Mark Rustad <mark.d.rustad@intel.com>
> ---
> Changes in V2:
> - Corrected spelling in log message
> - Added checks to see that the referenced function 0 is reasonable
> ---
> drivers/pci/access.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 47 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/pci/access.c b/drivers/pci/access.c
> index d9b64a175990..74634d4868a2 100644
> --- a/drivers/pci/access.c
> +++ b/drivers/pci/access.c
> @@ -439,6 +439,40 @@ static const struct pci_vpd_ops pci_vpd_pci22_ops = {
> .release = pci_vpd_pci22_release,
> };
>
> +static ssize_t pci_vpd_f0_read(struct pci_dev *dev, loff_t pos, size_t count,
> + void *arg)
> +{
> + struct pci_dev *tdev = pci_get_slot(dev->bus, PCI_SLOT(dev->devfn));
> + ssize_t ret;
> +
> + if (!tdev)
> + return -ENODEV;
> +
> + ret = pci_read_vpd(tdev, pos, count, arg);
> + pci_dev_put(tdev);
> + return ret;
> +}
> +
> +static ssize_t pci_vpd_f0_write(struct pci_dev *dev, loff_t pos, size_t count,
> + const void *arg)
> +{
> + struct pci_dev *tdev = pci_get_slot(dev->bus, PCI_SLOT(dev->devfn));
> + ssize_t ret;
> +
> + if (!tdev)
> + return -ENODEV;
> +
> + ret = pci_write_vpd(tdev, pos, count, arg);
> + pci_dev_put(tdev);
> + return ret;
> +}
> +
> +static const struct pci_vpd_ops pci_vpd_f0_ops = {
> + .read = pci_vpd_f0_read,
> + .write = pci_vpd_f0_write,
> + .release = pci_vpd_pci22_release,
> +};
> +
> int pci_vpd_pci22_init(struct pci_dev *dev)
> {
> struct pci_vpd_pci22 *vpd;
> @@ -447,12 +481,24 @@ int pci_vpd_pci22_init(struct pci_dev *dev)
> cap = pci_find_capability(dev, PCI_CAP_ID_VPD);
> if (!cap)
> return -ENODEV;
> + if (dev->dev_flags & PCI_DEV_FLAGS_VPD_REF_F0) {
> + struct pci_dev *tdev;
> +
> + tdev = pci_get_slot(dev->bus, PCI_SLOT(dev->devfn));
> + if (!tdev || !dev->multifunction || !tdev->multifunction ||
> + dev->class != tdev->class || dev->vendor != tdev->vendor ||
> + dev->device != tdev->device)
> + return -ENODEV;
> + }
You can probably combine the dev->multifunction check with the dev_flags
check. After all you don't need this workaround if the device is not
multifunction. It might even make more sense to move the multifunction
check to the quirk in patch 2/2.
I also believe this leaks a reference to the device. You should be
calling pci_dev_put(tdev) if tdev is not NULL. As such you probably
need to split up the !tdev and the rest of the checks.
- Alex
next prev parent reply other threads:[~2015-06-03 2:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-03 0:10 [PATCH V2 0/2] pci: Provide a flag to access VPD through function 0 Mark D Rustad
2015-06-03 0:10 ` [PATCH V2 1/2] pci: Add dev_flags bit " Mark D Rustad
2015-06-03 2:28 ` Alexander Duyck [this message]
2015-06-03 16:16 ` [Intel-wired-lan] " Rustad, Mark D
2015-06-03 0:10 ` [PATCH V2 2/2] pci: Add VPD quirk for Intel Ethernet devices Mark D Rustad
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=556E6667.1020000@gmail.com \
--to=alexander.duyck@gmail.com \
--cc=bhelgaas@google.com \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=linux-pci@vger.kernel.org \
--cc=mark.d.rustad@intel.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).