public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Matthew Wilcox <matthew@wil.cx>
To: Yu Zhao <yu.zhao@intel.com>
Cc: jbarnes@virtuousgeek.org, linux-pci@vger.kernel.org,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Randy.Dunlap" <rdunlap@xenotime.net>
Subject: Re: [PATCH v10 4/7] PCI: add SR-IOV API for Physical Function driver
Date: Fri, 6 Mar 2009 13:37:18 -0700	[thread overview]
Message-ID: <20090306203717.GG25995@parisc-linux.org> (raw)
In-Reply-To: <1235112888-9524-5-git-send-email-yu.zhao@intel.com>

On Fri, Feb 20, 2009 at 02:54:45PM +0800, Yu Zhao wrote:
> +	virtfn->sysdata = dev->bus->sysdata;
> +	virtfn->dev.parent = dev->dev.parent;
> +	virtfn->dev.bus = dev->dev.bus;
> +	virtfn->devfn = devfn;
> +	virtfn->hdr_type = PCI_HEADER_TYPE_NORMAL;
> +	virtfn->cfg_size = PCI_CFG_SPACE_EXP_SIZE;
> +	virtfn->error_state = pci_channel_io_normal;
> +	virtfn->current_state = PCI_UNKNOWN;
> +	virtfn->is_pcie = 1;
> +	virtfn->pcie_type = PCI_EXP_TYPE_ENDPOINT;
> +	virtfn->dma_mask = 0xffffffff;
> +	virtfn->vendor = dev->vendor;
> +	virtfn->subsystem_vendor = dev->subsystem_vendor;
> +	virtfn->class = dev->class;

There seems to be a certain amount of commonality between this and
pci_scan_device().  Have you considered trying to make a common helper
function, or does it not work out well?

> +	pci_device_add(virtfn, virtfn->bus);

Greg is probably going to ding you here for adding the device, then
creating the symlinks.  I believe it's now best practice to create the
symlinks first, so there's no window where userspace can get confused.

> +	mutex_unlock(&iov->pdev->sriov->lock);

I question the existance of this mutex now.  What's it protecting?

Aren't we going to be implicitly protected by virtue of the Physical
Function device driver being the only one calling this function, and the
driver will be calling it from the ->probe routine which is not called
simultaneously for the same device.

> +	virtfn->physfn = pci_dev_get(dev);
> +
> +	rc = pci_bus_add_device(virtfn);
> +	if (rc)
> +		goto failed1;
> +	sprintf(buf, "%d", id);

%u, perhaps?  And maybe 'id' should always be unsigned?  Just a thought.

> +	rc = sysfs_create_link(&iov->dev.kobj, &virtfn->dev.kobj, buf);
> +	if (rc)
> +		goto failed1;
> +	rc = sysfs_create_link(&virtfn->dev.kobj, &dev->dev.kobj, "physfn");
> +	if (rc)
> +		goto failed2;

I'm glad to see these symlinks documented in later patches!

> +	nres = 0;
> +	for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
> +		res = dev->resource + PCI_SRIOV_RESOURCES + i;
> +		if (!res->parent)
> +			continue;
> +		nres++;
> +	}

Can't this be written more simply as:

	for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
		res = dev->resource + PCI_SRIOV_RESOURCES + i;
		if (res->parent)
			nres++;
	}
?

> +	if (nres != iov->nres) {
> +		dev_err(&dev->dev, "no enough MMIO for SR-IOV\n");
> +		return -ENOMEM;
> +	}

Randy, can you help us out with better wording here?

> +		dev_err(&dev->dev, "no enough bus range for SR-IOV\n");

and here.

> +	if (iov->link != dev->devfn) {
> +		rc = -ENODEV;
> +		list_for_each_entry(link, &dev->bus->devices, bus_list) {
> +			if (link->sriov && link->devfn == iov->link)
> +				rc = sysfs_create_link(&iov->dev.kobj,
> +						&link->dev.kobj, "dep_link");

I skipped to the end and read patch 7/7 and I still don't understand
what dep_link is for.  Can you explain please?  In particular, how is it
different from physfn?

-- 
Matthew Wilcox				Intel Open Source Technology Centre
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."

  reply	other threads:[~2009-03-06 20:37 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-20  6:54 [PATCH v10 0/7] PCI: Linux kernel SR-IOV support Yu Zhao
2009-02-20  6:54 ` [PATCH v10 1/7] PCI: initialize and release SR-IOV capability Yu Zhao
2009-03-06 20:08   ` Matthew Wilcox
2009-03-06 22:03     ` Randy Dunlap
2009-03-06 23:31       ` Duyck, Alexander H
2009-03-07  2:38     ` Greg KH
2009-03-10  1:19       ` Yu Zhao
2009-03-11  4:36         ` Greg KH
2009-03-09  8:12     ` Yu Zhao
2009-02-20  6:54 ` [PATCH v10 2/7] PCI: restore saved SR-IOV state Yu Zhao
2009-03-06 20:09   ` Matthew Wilcox
2009-02-20  6:54 ` [PATCH v10 3/7] PCI: reserve bus range for SR-IOV device Yu Zhao
2009-03-06 20:20   ` Matthew Wilcox
2009-03-09  8:13     ` Yu Zhao
2009-03-09 18:09       ` Randy Dunlap
2009-03-09 18:11         ` Matthew Wilcox
2009-02-20  6:54 ` [PATCH v10 4/7] PCI: add SR-IOV API for Physical Function driver Yu Zhao
2009-03-06 20:37   ` Matthew Wilcox [this message]
2009-03-06 21:48     ` Randy Dunlap
2009-03-09  8:29       ` Yu Zhao
2009-03-07  2:40     ` Greg KH
2009-03-09  8:25     ` Yu Zhao
2009-03-09 19:39       ` Greg KH
2009-03-10  1:37         ` Yu Zhao
2009-03-11  4:34           ` Greg KH
2009-02-20  6:54 ` [PATCH v10 5/7] PCI: handle SR-IOV Virtual Function Migration Yu Zhao
2009-03-06 21:13   ` Matthew Wilcox
2009-03-09  8:28     ` Yu Zhao
2009-02-20  6:54 ` [PATCH v10 6/7] PCI: document SR-IOV sysfs entries Yu Zhao
2009-03-06 21:16   ` Matthew Wilcox
2009-03-06 22:35     ` Randy Dunlap
2009-02-20  6:54 ` [PATCH v10 7/7] PCI: manual for SR-IOV user and driver developer Yu Zhao
2009-03-06 21:17   ` Matthew Wilcox
2009-02-24 10:47 ` [PATCH v10 0/7] PCI: Linux kernel SR-IOV support Avi Kivity
2009-02-25  1:36   ` Yu Zhao
2009-03-06 19:33   ` Matthew Wilcox
2009-03-08 14:30     ` Avi Kivity
2009-03-08 15:01       ` Matthew Wilcox
2009-03-09  0:45         ` Greg KH
2009-03-09  3:42       ` Yang, Sheng
2009-03-09  4:35         ` Yang, Sheng
2009-03-09 13:45           ` Avi Kivity
2009-03-06 19:44 ` Matthew Wilcox
2009-03-07  2:34   ` Greg KH
2009-03-10  1:11     ` Yu Zhao

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=20090306203717.GG25995@parisc-linux.org \
    --to=matthew@wil.cx \
    --cc=jbarnes@virtuousgeek.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=rdunlap@xenotime.net \
    --cc=yu.zhao@intel.com \
    /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