public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: "Michał Winiarski" <michal.winiarski@intel.com>
Cc: linux-pci@vger.kernel.org, intel-xe@lists.freedesktop.org,
	dri-devel@lists.freedesktop.org,
	LKML <linux-kernel@vger.kernel.org>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Christian König" <christian.koenig@amd.com>,
	"Krzysztof Wilczyński" <kw@linux.com>,
	"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
	"Michal Wajdeczko" <michal.wajdeczko@intel.com>,
	"Lucas De Marchi" <lucas.demarchi@intel.com>,
	"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
	"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Matt Roper" <matthew.d.roper@intel.com>
Subject: Re: [PATCH v7 3/6] PCI: Allow IOV resources to be resized in pci_resize_resource()
Date: Thu, 3 Apr 2025 12:45:45 +0300 (EEST)	[thread overview]
Message-ID: <31c9a59c-b90c-80e4-cd2f-2eb992ce8556@linux.intel.com> (raw)
In-Reply-To: <20250402141122.2818478-4-michal.winiarski@intel.com>

[-- Attachment #1: Type: text/plain, Size: 6167 bytes --]

On Wed, 2 Apr 2025, Michał Winiarski wrote:

> Similar to regular resizable BAR, VF BAR can also be resized.
> 
> The capability layout is the same as PCI_EXT_CAP_ID_REBAR, which means
> we can reuse most of the implementation, the only difference being
> resource size calculation (which is multiplied by total VFs) and memory
> decoding (which is controlled by a separate VF MSE field in SR-IOV cap).
> 
> Extend the pci_resize_resource() function to accept IOV resources.
> 
> See PCIe r6.2, sec 7.8.7.
> 
> Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
> ---
>  drivers/pci/iov.c       | 21 +++++++++++++++++++++
>  drivers/pci/pci.c       | 10 +++++++++-
>  drivers/pci/pci.h       |  9 +++++++++
>  drivers/pci/setup-res.c | 35 ++++++++++++++++++++++++++++++-----
>  4 files changed, 69 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
> index 3d5da055c3dc1..fee99e15a943f 100644
> --- a/drivers/pci/iov.c
> +++ b/drivers/pci/iov.c
> @@ -154,6 +154,27 @@ resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno)
>  	return dev->sriov->barsz[pci_resource_num_to_vf_bar(resno)];
>  }
>  
> +void pci_iov_resource_set_size(struct pci_dev *dev, int resno,
> +			       resource_size_t size)
> +{
> +	if (!pci_resource_is_iov(resno)) {
> +		pci_warn(dev, "%s is not an IOV resource\n",
> +			 pci_resource_name(dev, resno));
> +		return;
> +	}
> +
> +	dev->sriov->barsz[pci_resource_num_to_vf_bar(resno)] = size;
> +}
> +
> +bool pci_iov_is_memory_decoding_enabled(struct pci_dev *dev)
> +{
> +	u16 cmd;
> +
> +	pci_read_config_word(dev, dev->sriov->pos + PCI_SRIOV_CTRL, &cmd);
> +
> +	return cmd & PCI_SRIOV_CTRL_MSE;
> +}
> +
>  static void pci_read_vf_config_common(struct pci_dev *virtfn)
>  {
>  	struct pci_dev *physfn = virtfn->physfn;
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 4d7c9f64ea24e..6878e3b1e3fcf 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -3745,7 +3745,15 @@ static int pci_rebar_find_pos(struct pci_dev *pdev, int bar)
>  	unsigned int pos, nbars, i;
>  	u32 ctrl;
>  
> -	pos = pdev->rebar_cap;
> +	if (pci_resource_is_iov(bar)) {
> +		if (!pdev->physfn)
> +			return -ENOTSUPP;
> +		pos = pdev->sriov->vf_rebar_cap;
> +		bar = pci_resource_num_to_vf_bar(bar);
> +	} else {
> +		pos = pdev->rebar_cap;
> +	}
> +
>  	if (!pos)
>  		return -ENOTSUPP;
>  
> diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
> index f44840ee3c327..643cd8c737f66 100644
> --- a/drivers/pci/pci.h
> +++ b/drivers/pci/pci.h
> @@ -689,6 +689,9 @@ void pci_iov_update_resource(struct pci_dev *dev, int resno);
>  resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, int resno);
>  void pci_restore_iov_state(struct pci_dev *dev);
>  int pci_iov_bus_range(struct pci_bus *bus);
> +void pci_iov_resource_set_size(struct pci_dev *dev, int resno,
> +			       resource_size_t size);
> +bool pci_iov_is_memory_decoding_enabled(struct pci_dev *dev);
>  static inline bool pci_resource_is_iov(int resno)
>  {
>  	return resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END;
> @@ -722,6 +725,12 @@ static inline int pci_iov_bus_range(struct pci_bus *bus)
>  {
>  	return 0;
>  }
> +static inline void pci_iov_resource_set_size(struct pci_dev *dev, int resno,
> +					     resource_size_t size) { }
> +static inline bool pci_iov_is_memory_decoding_enabled(struct pci_dev *dev)
> +{
> +	return false;
> +}
>  static inline bool pci_resource_is_iov(int resno)
>  {
>  	return false;
> diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
> index c6657cdd06f67..d2b3ed51e8804 100644
> --- a/drivers/pci/setup-res.c
> +++ b/drivers/pci/setup-res.c
> @@ -423,13 +423,39 @@ void pci_release_resource(struct pci_dev *dev, int resno)
>  }
>  EXPORT_SYMBOL(pci_release_resource);
>  
> +static bool pci_resize_is_memory_decoding_enabled(struct pci_dev *dev,
> +						  int resno)
> +{
> +	u16 cmd;
> +
> +	if (pci_resource_is_iov(resno))
> +		return pci_iov_is_memory_decoding_enabled(dev);
> +
> +	pci_read_config_word(dev, PCI_COMMAND, &cmd);
> +
> +	return cmd & PCI_COMMAND_MEMORY;
> +}
> +
> +static void pci_resize_resource_set_size(struct pci_dev *dev, int resno,
> +					 int size)
> +{
> +	resource_size_t res_size = pci_rebar_size_to_bytes(size);
> +	struct resource *res = pci_resource_n(dev, resno);
> +
> +	if (!pci_resource_is_iov(resno)) {
> +		resource_set_size(res, res_size);
> +	} else {
> +		resource_set_size(res, res_size * pci_sriov_get_totalvfs(dev));
> +		pci_iov_resource_set_size(dev, resno, res_size);
> +	}
> +}
> +
>  int pci_resize_resource(struct pci_dev *dev, int resno, int size)
>  {
>  	struct resource *res = pci_resource_n(dev, resno);
>  	struct pci_host_bridge *host;
>  	int old, ret;
>  	u32 sizes;
> -	u16 cmd;
>  
>  	/* Check if we must preserve the firmware's resource assignment */
>  	host = pci_find_host_bridge(dev->bus);
> @@ -440,8 +466,7 @@ int pci_resize_resource(struct pci_dev *dev, int resno, int size)
>  	if (!(res->flags & IORESOURCE_UNSET))
>  		return -EBUSY;
>  
> -	pci_read_config_word(dev, PCI_COMMAND, &cmd);
> -	if (cmd & PCI_COMMAND_MEMORY)
> +	if (pci_resize_is_memory_decoding_enabled(dev, resno))
>  		return -EBUSY;
>  
>  	sizes = pci_rebar_get_possible_sizes(dev, resno);
> @@ -459,7 +484,7 @@ int pci_resize_resource(struct pci_dev *dev, int resno, int size)
>  	if (ret)
>  		return ret;
>  
> -	resource_set_size(res, pci_rebar_size_to_bytes(size));
> +	pci_resize_resource_set_size(dev, resno, size);
>  
>  	/* Check if the new config works by trying to assign everything. */
>  	if (dev->bus->self) {
> @@ -471,7 +496,7 @@ int pci_resize_resource(struct pci_dev *dev, int resno, int size)
>  
>  error_resize:
>  	pci_rebar_set_size(dev, resno, old);
> -	resource_set_size(res, pci_rebar_size_to_bytes(old));
> +	pci_resize_resource_set_size(dev, resno, old);
>  	return ret;
>  }
>  EXPORT_SYMBOL(pci_resize_resource);

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

-- 
 i.

  reply	other threads:[~2025-04-03  9:46 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-02 14:11 [PATCH v7 0/6] PCI: VF resizable BAR Michał Winiarski
2025-04-02 14:11 ` [PATCH v7 1/6] PCI/IOV: Restore VF resizable BAR state after reset Michał Winiarski
2025-04-02 14:11 ` [PATCH v7 2/6] PCI: Add a helper to convert between VF BAR number and IOV resource Michał Winiarski
2025-04-03  9:24   ` Ilpo Järvinen
2025-04-02 14:11 ` [PATCH v7 3/6] PCI: Allow IOV resources to be resized in pci_resize_resource() Michał Winiarski
2025-04-03  9:45   ` Ilpo Järvinen [this message]
2025-04-02 14:11 ` [PATCH v7 4/6] PCI/IOV: Check that VF BAR fits within the reservation Michał Winiarski
2025-04-03  9:54   ` Ilpo Järvinen
2025-04-02 14:11 ` [PATCH v7 5/6] PCI: Allow drivers to control VF BAR size Michał Winiarski
2025-04-03 10:20   ` Ilpo Järvinen
2025-05-26 21:54     ` Michał Winiarski
2025-04-02 14:11 ` [PATCH v7 6/6] drm/xe/pf: Set VF LMEM " Michał Winiarski

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=31c9a59c-b90c-80e4-cd2f-2eb992ce8556@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=airlied@gmail.com \
    --cc=bhelgaas@google.com \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=kw@linux.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lucas.demarchi@intel.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=matthew.d.roper@intel.com \
    --cc=michal.wajdeczko@intel.com \
    --cc=michal.winiarski@intel.com \
    --cc=mripard@kernel.org \
    --cc=rodrigo.vivi@intel.com \
    --cc=simona@ffwll.ch \
    --cc=thomas.hellstrom@linux.intel.com \
    --cc=tzimmermann@suse.de \
    /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