From: Bjorn Helgaas <helgaas@kernel.org>
To: Lukasz Laguna <lukasz.laguna@intel.com>
Cc: linux-pci@vger.kernel.org, bhelgaas@google.com,
michal.winiarski@intel.com, djbw@kernel.org,
brett.creeley@amd.com, anthony.l.nguyen@intel.com,
przemyslaw.kitszel@intel.com, pabeni@redhat.com,
andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org
Subject: Re: [PATCH v2 02/13] PCI/IOV: Introduce VF iterators
Date: Tue, 27 Oct 2026 16:35:04 -0500 [thread overview]
Message-ID: <20261027213504.GA456799@bhelgaas> (raw)
In-Reply-To: <20261027160446.858300-3-lukasz.laguna@intel.com>
On Tue, Oct 27, 2026 at 05:04:35PM +0100, Lukasz Laguna wrote:
> Introduce helpers to iterate over the enabled VFs of a PF. Add
> pci_get_vf() and pci_get_vf_reverse() to retrieve the next enabled VF
> of a PF in ascending or descending VF ID order, along with
> for_each_pci_vf(), for_each_pci_vf_reverse(), and
> for_each_pci_vf_continue_reverse() built on top of them. The helpers
> return each VF with a reference held, matching existing PCI device
> lookup APIs.
>
> This provides a common and convenient way to iterate over a PF's enabled
> VFs and avoids duplicating the iteration logic in drivers.
>
> Assisted-by: LLM
> Signed-off-by: Lukasz Laguna <lukasz.laguna@intel.com>
> ---
> drivers/pci/iov.c | 63 +++++++++++++++++++++++++++++++++++++++++++++
> include/linux/pci.h | 57 ++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 120 insertions(+)
>
> diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
> index eb019201faed..a437370c4e36 100644
> --- a/drivers/pci/iov.c
> +++ b/drivers/pci/iov.c
> @@ -70,6 +70,69 @@ struct pci_dev *pci_iov_get_virtfn(struct pci_dev *dev, int id)
> }
> EXPORT_SYMBOL_GPL(pci_iov_get_virtfn);
>
> +/**
> + * pci_get_vf() - Return the first or next existing VF of a PF
> + * @dev: PCI PF whose VFs are being iterated
> + * @from: Previous VF returned by this function, or %NULL to return the first VF
> + *
> + * Iterate over existing VFs of @dev in ascending VF ID order, skipping VF IDs
> + * with no device present. If a VF is found, its reference count is incremented.
> + * A new iteration is started by passing %NULL as the @from argument. Otherwise,
> + * iteration continues after @from, and the reference count on @from is
> + * decremented.
> + *
> + * Return: a pointer to the first or next VF, or %NULL if no further VF is found.
> + */
> +struct pci_dev *pci_get_vf(struct pci_dev *dev, struct pci_dev *from)
> +{
> + int id = 0;
> +
> + if (from) {
> + id = pci_iov_vf_id(from) + 1;
> + pci_dev_put(from);
> + }
> +
> + for (; id < pci_num_vf(dev); id++) {
> + from = pci_iov_get_virtfn(dev, id);
> + if (from)
> + return from;
> + }
> +
> + return NULL;
> +}
> +EXPORT_SYMBOL_GPL(pci_get_vf);
> +
> +/**
> + * pci_get_vf_reverse() - Return the last or previous existing VF of a PF
> + * @dev: PCI PF whose VFs are being iterated
> + * @from: Previous VF returned by this function, or %NULL to return the last VF
> + *
> + * Same semantics as pci_get_vf(), except iteration proceeds in descending VF
> + * ID order.
> + *
> + * Return: a pointer to the last or previous VF, or %NULL if no further VF is
> + * found.
> + */
> +struct pci_dev *pci_get_vf_reverse(struct pci_dev *dev, struct pci_dev *from)
> +{
> + int id = pci_num_vf(dev);
> +
> + if (from) {
> + id = pci_iov_vf_id(from);
> + pci_dev_put(from);
> + }
> +
> + while (id > 0) {
> + id--;
> + from = pci_iov_get_virtfn(dev, id);
> + if (from)
> + return from;
> + }
Seems slightly odd to use different loop control in pci_get_vf() and
pci_get_vf_reverse(). I think I would use "while" in pci_get_vf() to
match, obviously with id++ at the tail.
> + return NULL;
> +}
> +EXPORT_SYMBOL_GPL(pci_get_vf_reverse);
next prev parent reply other threads:[~2026-10-27 21:35 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-27 16:04 [PATCH v2 00/13] PCI/IOV: Improve reset handling with VFs enabled Lukasz Laguna
2026-10-27 16:04 ` [PATCH v2 01/13] PCI/IOV: Introduce pci_iov_get_virtfn() Lukasz Laguna
2026-10-27 16:20 ` sashiko-bot
2026-10-27 16:04 ` [PATCH v2 02/13] PCI/IOV: Introduce VF iterators Lukasz Laguna
2026-10-27 16:21 ` sashiko-bot
2026-10-27 21:35 ` Bjorn Helgaas [this message]
2026-10-28 7:29 ` Laguna, Lukasz
2026-10-27 16:04 ` [PATCH v2 03/13] PCI/IOV: Introduce VF locking helpers Lukasz Laguna
2026-10-27 16:26 ` sashiko-bot
2026-10-27 16:04 ` [PATCH v2 04/13] PCI/IOV: Allow VF drivers to handle resets Lukasz Laguna
2026-10-27 16:34 ` sashiko-bot
2026-10-27 16:51 ` Laguna, Lukasz
2026-10-28 8:52 ` Weili Qian
2026-10-28 14:05 ` Laguna, Lukasz
2026-10-27 20:00 ` Bjorn Helgaas
2026-10-28 6:39 ` Laguna, Lukasz
2026-10-27 16:04 ` [PATCH v2 05/13] ionic: Lock VFs around pci_reset_function_locked() Lukasz Laguna
2026-10-27 16:14 ` sashiko-bot
2026-10-27 16:04 ` [PATCH v2 06/13] pds_core: " Lukasz Laguna
2026-10-27 16:12 ` sashiko-bot
2026-10-27 16:04 ` [PATCH v2 07/13] i40e: Drop VF MSI state restore from PF reset_done Lukasz Laguna
2026-10-27 16:13 ` sashiko-bot
2026-10-27 16:04 ` [PATCH v2 08/13] PCI/IOV: Allow bus reset_method for PF with VFs enabled Lukasz Laguna
2026-10-27 16:20 ` sashiko-bot
2026-10-27 16:04 ` [PATCH v2 09/13] PCI/TSM: Use generic VF iterators Lukasz Laguna
2026-10-27 16:15 ` sashiko-bot
2026-10-27 20:08 ` Bjorn Helgaas
2026-10-28 7:25 ` Laguna, Lukasz
2026-10-27 16:04 ` [PATCH v2 10/13] ixgbe: Use generic VF iterator Lukasz Laguna
2026-10-27 16:17 ` sashiko-bot
2026-10-27 16:04 ` [PATCH v2 11/13] ice: Use pci_iov_get_virtfn() Lukasz Laguna
2026-10-27 16:20 ` sashiko-bot
2026-10-27 16:04 ` [PATCH v2 12/13] liquidio: " Lukasz Laguna
2026-10-27 16:19 ` sashiko-bot
2026-10-27 16:04 ` [PATCH v2 13/13] drm/xe/pf: " Lukasz Laguna
2026-10-27 16:21 ` sashiko-bot
2026-10-27 19:49 ` [PATCH v2 00/13] PCI/IOV: Improve reset handling with VFs enabled Bjorn Helgaas
2026-10-28 7:03 ` Laguna, Lukasz
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=20261027213504.GA456799@bhelgaas \
--to=helgaas@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=anthony.l.nguyen@intel.com \
--cc=bhelgaas@google.com \
--cc=brett.creeley@amd.com \
--cc=davem@davemloft.net \
--cc=djbw@kernel.org \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lukasz.laguna@intel.com \
--cc=michal.winiarski@intel.com \
--cc=pabeni@redhat.com \
--cc=przemyslaw.kitszel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.