public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] vfio/pci: Remove shadow rom specific code paths
@ 2024-12-12 20:50 Yunxiang Li
  2024-12-12 20:50 ` [PATCH 2/3] vfio/pci: refactor vfio_pci_bar_rw Yunxiang Li
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Yunxiang Li @ 2024-12-12 20:50 UTC (permalink / raw)
  To: kvm, alex.williamson; +Cc: kevin.tian, yishaih, ankita, jgg, Yunxiang Li

After 0c0e0736acad, the shadow rom works the same as regular ROM BARs so
these code paths are no longer needed.

Signed-off-by: Yunxiang Li <Yunxiang.Li@amd.com>
---
 drivers/vfio/pci/vfio_pci_config.c |  8 ++------
 drivers/vfio/pci/vfio_pci_core.c   | 10 ++--------
 drivers/vfio/pci/vfio_pci_rdwr.c   |  3 ---
 3 files changed, 4 insertions(+), 17 deletions(-)

diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c
index ea2745c1ac5e6..e41c3a965663e 100644
--- a/drivers/vfio/pci/vfio_pci_config.c
+++ b/drivers/vfio/pci/vfio_pci_config.c
@@ -511,13 +511,9 @@ static void vfio_bar_fixup(struct vfio_pci_core_device *vdev)
 		mask = ~(pci_resource_len(pdev, PCI_ROM_RESOURCE) - 1);
 		mask |= PCI_ROM_ADDRESS_ENABLE;
 		*vbar &= cpu_to_le32((u32)mask);
-	} else if (pdev->resource[PCI_ROM_RESOURCE].flags &
-					IORESOURCE_ROM_SHADOW) {
-		mask = ~(0x20000 - 1);
-		mask |= PCI_ROM_ADDRESS_ENABLE;
-		*vbar &= cpu_to_le32((u32)mask);
-	} else
+	} else {
 		*vbar = 0;
+	}
 
 	vdev->bardirty = false;
 }
diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
index 1ab58da9f38a6..b49dd9cdc072a 100644
--- a/drivers/vfio/pci/vfio_pci_core.c
+++ b/drivers/vfio/pci/vfio_pci_core.c
@@ -1057,14 +1057,8 @@ static int vfio_pci_ioctl_get_region_info(struct vfio_pci_core_device *vdev,
 
 		/* Report the BAR size, not the ROM size */
 		info.size = pci_resource_len(pdev, info.index);
-		if (!info.size) {
-			/* Shadow ROMs appear as PCI option ROMs */
-			if (pdev->resource[PCI_ROM_RESOURCE].flags &
-			    IORESOURCE_ROM_SHADOW)
-				info.size = 0x20000;
-			else
-				break;
-		}
+		if (!info.size)
+			break;
 
 		/*
 		 * Is it really there?  Enable memory decode for implicit access
diff --git a/drivers/vfio/pci/vfio_pci_rdwr.c b/drivers/vfio/pci/vfio_pci_rdwr.c
index 66b72c2892841..a1eeacad82120 100644
--- a/drivers/vfio/pci/vfio_pci_rdwr.c
+++ b/drivers/vfio/pci/vfio_pci_rdwr.c
@@ -244,9 +244,6 @@ ssize_t vfio_pci_bar_rw(struct vfio_pci_core_device *vdev, char __user *buf,
 
 	if (pci_resource_start(pdev, bar))
 		end = pci_resource_len(pdev, bar);
-	else if (bar == PCI_ROM_RESOURCE &&
-		 pdev->resource[bar].flags & IORESOURCE_ROM_SHADOW)
-		end = 0x20000;
 	else
 		return -EINVAL;
 
-- 
2.47.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/3] vfio/pci: refactor vfio_pci_bar_rw
  2024-12-12 20:50 [PATCH 1/3] vfio/pci: Remove shadow rom specific code paths Yunxiang Li
@ 2024-12-12 20:50 ` Yunxiang Li
  2024-12-12 23:00   ` Alex Williamson
                     ` (2 more replies)
  2024-12-12 20:50 ` [PATCH 3/3] vfio/pci: Expose setup ROM at ROM bar when needed Yunxiang Li
  2024-12-12 23:00 ` [PATCH 1/3] vfio/pci: Remove shadow rom specific code paths Alex Williamson
  2 siblings, 3 replies; 9+ messages in thread
From: Yunxiang Li @ 2024-12-12 20:50 UTC (permalink / raw)
  To: kvm, alex.williamson; +Cc: kevin.tian, yishaih, ankita, jgg, Yunxiang Li

In the next patch the logic for reading ROM will get more complicated,
so decouple the ROM path from the normal path. Also check that for ROM
write is not allowed.

Signed-off-by: Yunxiang Li <Yunxiang.Li@amd.com>
---
 drivers/vfio/pci/vfio_pci_rdwr.c | 47 ++++++++++++++++----------------
 1 file changed, 24 insertions(+), 23 deletions(-)

diff --git a/drivers/vfio/pci/vfio_pci_rdwr.c b/drivers/vfio/pci/vfio_pci_rdwr.c
index a1eeacad82120..4bed9fd5af50f 100644
--- a/drivers/vfio/pci/vfio_pci_rdwr.c
+++ b/drivers/vfio/pci/vfio_pci_rdwr.c
@@ -236,10 +236,9 @@ ssize_t vfio_pci_bar_rw(struct vfio_pci_core_device *vdev, char __user *buf,
 	struct pci_dev *pdev = vdev->pdev;
 	loff_t pos = *ppos & VFIO_PCI_OFFSET_MASK;
 	int bar = VFIO_PCI_OFFSET_TO_INDEX(*ppos);
-	size_t x_start = 0, x_end = 0;
+	size_t x_start, x_end;
 	resource_size_t end;
 	void __iomem *io;
-	struct resource *res = &vdev->pdev->resource[bar];
 	ssize_t done;
 
 	if (pci_resource_start(pdev, bar))
@@ -253,41 +252,43 @@ ssize_t vfio_pci_bar_rw(struct vfio_pci_core_device *vdev, char __user *buf,
 	count = min(count, (size_t)(end - pos));
 
 	if (bar == PCI_ROM_RESOURCE) {
+		if (iswrite)
+			return -EINVAL;
 		/*
 		 * The ROM can fill less space than the BAR, so we start the
 		 * excluded range at the end of the actual ROM.  This makes
 		 * filling large ROM BARs much faster.
 		 */
 		io = pci_map_rom(pdev, &x_start);
-		if (!io) {
-			done = -ENOMEM;
-			goto out;
-		}
+		if (!io)
+			return -ENOMEM;
 		x_end = end;
+
+		done = vfio_pci_core_do_io_rw(vdev, 1, io, buf, pos,
+					      count, x_start, x_end, 0);
+
+		pci_unmap_rom(pdev, io);
 	} else {
-		int ret = vfio_pci_core_setup_barmap(vdev, bar);
-		if (ret) {
-			done = ret;
-			goto out;
-		}
+		done = vfio_pci_core_setup_barmap(vdev, bar);
+		if (done)
+			return done;
 
 		io = vdev->barmap[bar];
-	}
 
-	if (bar == vdev->msix_bar) {
-		x_start = vdev->msix_offset;
-		x_end = vdev->msix_offset + vdev->msix_size;
-	}
+		if (bar == vdev->msix_bar) {
+			x_start = vdev->msix_offset;
+			x_end = vdev->msix_offset + vdev->msix_size;
+		} else {
+			x_start = 0;
+			x_end = 0;
+		}
 
-	done = vfio_pci_core_do_io_rw(vdev, res->flags & IORESOURCE_MEM, io, buf, pos,
+		done = vfio_pci_core_do_io_rw(vdev, pci_resource_flags(pdev, bar) & IORESOURCE_MEM, io, buf, pos,
 				      count, x_start, x_end, iswrite);
-
-	if (done >= 0)
-		*ppos += done;
-
-	if (bar == PCI_ROM_RESOURCE)
-		pci_unmap_rom(pdev, io);
+	}
 out:
+	if (done > 0)
+		*ppos += done;
 	return done;
 }
 
-- 
2.47.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/3] vfio/pci: Expose setup ROM at ROM bar when needed
  2024-12-12 20:50 [PATCH 1/3] vfio/pci: Remove shadow rom specific code paths Yunxiang Li
  2024-12-12 20:50 ` [PATCH 2/3] vfio/pci: refactor vfio_pci_bar_rw Yunxiang Li
@ 2024-12-12 20:50 ` Yunxiang Li
  2024-12-12 23:00   ` Alex Williamson
  2024-12-12 23:00 ` [PATCH 1/3] vfio/pci: Remove shadow rom specific code paths Alex Williamson
  2 siblings, 1 reply; 9+ messages in thread
From: Yunxiang Li @ 2024-12-12 20:50 UTC (permalink / raw)
  To: kvm, alex.williamson; +Cc: kevin.tian, yishaih, ankita, jgg, Yunxiang Li

If ROM bar is missing for any reason, we can fallback to using pdev->rom
to expose the ROM content to the guest. This fixes some passthrough use
cases where the upstream bridge does not have enough address window.

Signed-off-by: Yunxiang Li <Yunxiang.Li@amd.com>
---
 drivers/vfio/pci/vfio_pci_config.c |  4 ++++
 drivers/vfio/pci/vfio_pci_core.c   | 35 +++++++++++++++---------------
 drivers/vfio/pci/vfio_pci_rdwr.c   | 14 ++++++++++--
 3 files changed, 34 insertions(+), 19 deletions(-)

diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c
index e41c3a965663e..4c673d842fb35 100644
--- a/drivers/vfio/pci/vfio_pci_config.c
+++ b/drivers/vfio/pci/vfio_pci_config.c
@@ -511,6 +511,10 @@ static void vfio_bar_fixup(struct vfio_pci_core_device *vdev)
 		mask = ~(pci_resource_len(pdev, PCI_ROM_RESOURCE) - 1);
 		mask |= PCI_ROM_ADDRESS_ENABLE;
 		*vbar &= cpu_to_le32((u32)mask);
+	} else if (pdev->rom && pdev->romlen) {
+		mask = ~(roundup_pow_of_two(pdev->romlen) - 1);
+		mask |= PCI_ROM_ADDRESS_ENABLE;
+		*vbar &= cpu_to_le32((u32)mask);
 	} else {
 		*vbar = 0;
 	}
diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
index b49dd9cdc072a..3120c1e9f22cb 100644
--- a/drivers/vfio/pci/vfio_pci_core.c
+++ b/drivers/vfio/pci/vfio_pci_core.c
@@ -1049,30 +1049,31 @@ static int vfio_pci_ioctl_get_region_info(struct vfio_pci_core_device *vdev,
 		break;
 	case VFIO_PCI_ROM_REGION_INDEX: {
 		void __iomem *io;
-		size_t size;
+		size_t dont_care;
 		u16 cmd;
 
 		info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
 		info.flags = 0;
+		info.size = 0;
 
-		/* Report the BAR size, not the ROM size */
-		info.size = pci_resource_len(pdev, info.index);
-		if (!info.size)
-			break;
-
-		/*
-		 * Is it really there?  Enable memory decode for implicit access
-		 * in pci_map_rom().
-		 */
-		cmd = vfio_pci_memory_lock_and_enable(vdev);
-		io = pci_map_rom(pdev, &size);
-		if (io) {
+		if (pci_resource_start(pdev, PCI_ROM_RESOURCE)) {
+			/* Check ROM content is valid. Need to enable memory
+			 * decode for ROM access in pci_map_rom().
+			 */
+			cmd = vfio_pci_memory_lock_and_enable(vdev);
+			io = pci_map_rom(pdev, &dont_care);
+			if (io) {
+				info.flags = VFIO_REGION_INFO_FLAG_READ;
+				/* Report the BAR size, not the ROM size. */
+				info.size = pci_resource_len(pdev, PCI_ROM_RESOURCE);
+				pci_unmap_rom(pdev, io);
+			}
+			vfio_pci_memory_unlock_and_restore(vdev, cmd);
+		} else if (pdev->rom && pdev->romlen) {
 			info.flags = VFIO_REGION_INFO_FLAG_READ;
-			pci_unmap_rom(pdev, io);
-		} else {
-			info.size = 0;
+			/* Report BAR size as power of two. */
+			info.size = roundup_pow_of_two(pdev->romlen);
 		}
-		vfio_pci_memory_unlock_and_restore(vdev, cmd);
 
 		break;
 	}
diff --git a/drivers/vfio/pci/vfio_pci_rdwr.c b/drivers/vfio/pci/vfio_pci_rdwr.c
index 4bed9fd5af50f..4ea983cf499d9 100644
--- a/drivers/vfio/pci/vfio_pci_rdwr.c
+++ b/drivers/vfio/pci/vfio_pci_rdwr.c
@@ -243,6 +243,8 @@ ssize_t vfio_pci_bar_rw(struct vfio_pci_core_device *vdev, char __user *buf,
 
 	if (pci_resource_start(pdev, bar))
 		end = pci_resource_len(pdev, bar);
+	else if (bar == PCI_ROM_RESOURCE && pdev->rom && pdev->romlen)
+		end = roundup_pow_of_two(pdev->romlen);
 	else
 		return -EINVAL;
 
@@ -259,7 +261,12 @@ ssize_t vfio_pci_bar_rw(struct vfio_pci_core_device *vdev, char __user *buf,
 		 * excluded range at the end of the actual ROM.  This makes
 		 * filling large ROM BARs much faster.
 		 */
-		io = pci_map_rom(pdev, &x_start);
+		if (pci_resource_start(pdev, bar)) {
+			io = pci_map_rom(pdev, &x_start);
+		} else {
+			io = ioremap(pdev->rom, pdev->romlen);
+			x_start = pdev->romlen;
+		}
 		if (!io)
 			return -ENOMEM;
 		x_end = end;
@@ -267,7 +274,10 @@ ssize_t vfio_pci_bar_rw(struct vfio_pci_core_device *vdev, char __user *buf,
 		done = vfio_pci_core_do_io_rw(vdev, 1, io, buf, pos,
 					      count, x_start, x_end, 0);
 
-		pci_unmap_rom(pdev, io);
+		if (pci_resource_start(pdev, bar))
+			pci_unmap_rom(pdev, io);
+		else
+			iounmap(io);
 	} else {
 		done = vfio_pci_core_setup_barmap(vdev, bar);
 		if (done)
-- 
2.47.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/3] vfio/pci: Remove shadow rom specific code paths
  2024-12-12 20:50 [PATCH 1/3] vfio/pci: Remove shadow rom specific code paths Yunxiang Li
  2024-12-12 20:50 ` [PATCH 2/3] vfio/pci: refactor vfio_pci_bar_rw Yunxiang Li
  2024-12-12 20:50 ` [PATCH 3/3] vfio/pci: Expose setup ROM at ROM bar when needed Yunxiang Li
@ 2024-12-12 23:00 ` Alex Williamson
  2 siblings, 0 replies; 9+ messages in thread
From: Alex Williamson @ 2024-12-12 23:00 UTC (permalink / raw)
  To: Yunxiang Li; +Cc: kvm, kevin.tian, yishaih, ankita, jgg


Please us a cover letter for any multi-part series to describe your
overall goal with the series.

On Thu, 12 Dec 2024 15:50:48 -0500
Yunxiang Li <Yunxiang.Li@amd.com> wrote:

> After 0c0e0736acad, the shadow rom works the same as regular ROM BARs so
> these code paths are no longer needed.

Commit references should be in the form of:

  After commit 0c0e0736acad ("PCI: Set ROM shadow location in arch
  code, not in PCI core"), the shadow...

Thanks,
Alex

> Signed-off-by: Yunxiang Li <Yunxiang.Li@amd.com>
> ---
>  drivers/vfio/pci/vfio_pci_config.c |  8 ++------
>  drivers/vfio/pci/vfio_pci_core.c   | 10 ++--------
>  drivers/vfio/pci/vfio_pci_rdwr.c   |  3 ---
>  3 files changed, 4 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c
> index ea2745c1ac5e6..e41c3a965663e 100644
> --- a/drivers/vfio/pci/vfio_pci_config.c
> +++ b/drivers/vfio/pci/vfio_pci_config.c
> @@ -511,13 +511,9 @@ static void vfio_bar_fixup(struct vfio_pci_core_device *vdev)
>  		mask = ~(pci_resource_len(pdev, PCI_ROM_RESOURCE) - 1);
>  		mask |= PCI_ROM_ADDRESS_ENABLE;
>  		*vbar &= cpu_to_le32((u32)mask);
> -	} else if (pdev->resource[PCI_ROM_RESOURCE].flags &
> -					IORESOURCE_ROM_SHADOW) {
> -		mask = ~(0x20000 - 1);
> -		mask |= PCI_ROM_ADDRESS_ENABLE;
> -		*vbar &= cpu_to_le32((u32)mask);
> -	} else
> +	} else {
>  		*vbar = 0;
> +	}
>  
>  	vdev->bardirty = false;
>  }
> diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
> index 1ab58da9f38a6..b49dd9cdc072a 100644
> --- a/drivers/vfio/pci/vfio_pci_core.c
> +++ b/drivers/vfio/pci/vfio_pci_core.c
> @@ -1057,14 +1057,8 @@ static int vfio_pci_ioctl_get_region_info(struct vfio_pci_core_device *vdev,
>  
>  		/* Report the BAR size, not the ROM size */
>  		info.size = pci_resource_len(pdev, info.index);
> -		if (!info.size) {
> -			/* Shadow ROMs appear as PCI option ROMs */
> -			if (pdev->resource[PCI_ROM_RESOURCE].flags &
> -			    IORESOURCE_ROM_SHADOW)
> -				info.size = 0x20000;
> -			else
> -				break;
> -		}
> +		if (!info.size)
> +			break;
>  
>  		/*
>  		 * Is it really there?  Enable memory decode for implicit access
> diff --git a/drivers/vfio/pci/vfio_pci_rdwr.c b/drivers/vfio/pci/vfio_pci_rdwr.c
> index 66b72c2892841..a1eeacad82120 100644
> --- a/drivers/vfio/pci/vfio_pci_rdwr.c
> +++ b/drivers/vfio/pci/vfio_pci_rdwr.c
> @@ -244,9 +244,6 @@ ssize_t vfio_pci_bar_rw(struct vfio_pci_core_device *vdev, char __user *buf,
>  
>  	if (pci_resource_start(pdev, bar))
>  		end = pci_resource_len(pdev, bar);
> -	else if (bar == PCI_ROM_RESOURCE &&
> -		 pdev->resource[bar].flags & IORESOURCE_ROM_SHADOW)
> -		end = 0x20000;
>  	else
>  		return -EINVAL;
>  


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] vfio/pci: refactor vfio_pci_bar_rw
  2024-12-12 20:50 ` [PATCH 2/3] vfio/pci: refactor vfio_pci_bar_rw Yunxiang Li
@ 2024-12-12 23:00   ` Alex Williamson
  2024-12-16 13:48     ` Li, Yunxiang (Teddy)
  2024-12-20 12:36   ` kernel test robot
  2024-12-20 20:22   ` kernel test robot
  2 siblings, 1 reply; 9+ messages in thread
From: Alex Williamson @ 2024-12-12 23:00 UTC (permalink / raw)
  To: Yunxiang Li; +Cc: kvm, kevin.tian, yishaih, ankita, jgg

On Thu, 12 Dec 2024 15:50:49 -0500
Yunxiang Li <Yunxiang.Li@amd.com> wrote:

> In the next patch the logic for reading ROM will get more complicated,
> so decouple the ROM path from the normal path. Also check that for ROM
> write is not allowed.

This is already enforced by the caller.  Vague references to the next
patch don't make a lot of sense once commits are in the tree, this
should describe what you're preparing for.

> 
> Signed-off-by: Yunxiang Li <Yunxiang.Li@amd.com>
> ---
>  drivers/vfio/pci/vfio_pci_rdwr.c | 47 ++++++++++++++++----------------
>  1 file changed, 24 insertions(+), 23 deletions(-)
> 
> diff --git a/drivers/vfio/pci/vfio_pci_rdwr.c b/drivers/vfio/pci/vfio_pci_rdwr.c
> index a1eeacad82120..4bed9fd5af50f 100644
> --- a/drivers/vfio/pci/vfio_pci_rdwr.c
> +++ b/drivers/vfio/pci/vfio_pci_rdwr.c
> @@ -236,10 +236,9 @@ ssize_t vfio_pci_bar_rw(struct vfio_pci_core_device *vdev, char __user *buf,
>  	struct pci_dev *pdev = vdev->pdev;
>  	loff_t pos = *ppos & VFIO_PCI_OFFSET_MASK;
>  	int bar = VFIO_PCI_OFFSET_TO_INDEX(*ppos);
> -	size_t x_start = 0, x_end = 0;
> +	size_t x_start, x_end;
>  	resource_size_t end;
>  	void __iomem *io;
> -	struct resource *res = &vdev->pdev->resource[bar];
>  	ssize_t done;
>  
>  	if (pci_resource_start(pdev, bar))
> @@ -253,41 +252,43 @@ ssize_t vfio_pci_bar_rw(struct vfio_pci_core_device *vdev, char __user *buf,
>  	count = min(count, (size_t)(end - pos));
>  
>  	if (bar == PCI_ROM_RESOURCE) {
> +		if (iswrite)
> +			return -EINVAL;
>  		/*
>  		 * The ROM can fill less space than the BAR, so we start the
>  		 * excluded range at the end of the actual ROM.  This makes
>  		 * filling large ROM BARs much faster.
>  		 */
>  		io = pci_map_rom(pdev, &x_start);
> -		if (!io) {
> -			done = -ENOMEM;
> -			goto out;
> -		}
> +		if (!io)
> +			return -ENOMEM;
>  		x_end = end;
> +
> +		done = vfio_pci_core_do_io_rw(vdev, 1, io, buf, pos,
> +					      count, x_start, x_end, 0);
> +
> +		pci_unmap_rom(pdev, io);
>  	} else {
> -		int ret = vfio_pci_core_setup_barmap(vdev, bar);
> -		if (ret) {
> -			done = ret;
> -			goto out;
> -		}
> +		done = vfio_pci_core_setup_barmap(vdev, bar);
> +		if (done)
> +			return done;
>  
>  		io = vdev->barmap[bar];
> -	}
>  
> -	if (bar == vdev->msix_bar) {
> -		x_start = vdev->msix_offset;
> -		x_end = vdev->msix_offset + vdev->msix_size;
> -	}
> +		if (bar == vdev->msix_bar) {
> +			x_start = vdev->msix_offset;
> +			x_end = vdev->msix_offset + vdev->msix_size;
> +		} else {
> +			x_start = 0;
> +			x_end = 0;
> +		}

There's a lot of semantic preference noise that obscures what you're
actually trying to accomplish here, effectively this has only
refactored the code to have separate calls to ..do_io_rw() for the ROM
vs other case and therefore pushed the unmap into the ROM case,
introducing various new exit paths.

>  
> -	done = vfio_pci_core_do_io_rw(vdev, res->flags & IORESOURCE_MEM, io, buf, pos,
> +		done = vfio_pci_core_do_io_rw(vdev, pci_resource_flags(pdev, bar) & IORESOURCE_MEM, io, buf, pos,

The line is too long already, now it's indented further and the
wrapping needs to be adjusted.

>  				      count, x_start, x_end, iswrite);
> -
> -	if (done >= 0)
> -		*ppos += done;
> -
> -	if (bar == PCI_ROM_RESOURCE)
> -		pci_unmap_rom(pdev, io);
> +	}
>  out:

Both goto's to this label were removed above, none added.  Thanks,

Alex

> +	if (done > 0)
> +		*ppos += done;
>  	return done;
>  }
>  


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] vfio/pci: Expose setup ROM at ROM bar when needed
  2024-12-12 20:50 ` [PATCH 3/3] vfio/pci: Expose setup ROM at ROM bar when needed Yunxiang Li
@ 2024-12-12 23:00   ` Alex Williamson
  0 siblings, 0 replies; 9+ messages in thread
From: Alex Williamson @ 2024-12-12 23:00 UTC (permalink / raw)
  To: Yunxiang Li; +Cc: kvm, kevin.tian, yishaih, ankita, jgg

On Thu, 12 Dec 2024 15:50:50 -0500
Yunxiang Li <Yunxiang.Li@amd.com> wrote:

> If ROM bar is missing for any reason, we can fallback to using pdev->rom
> to expose the ROM content to the guest. This fixes some passthrough use
> cases where the upstream bridge does not have enough address window.
> 
> Signed-off-by: Yunxiang Li <Yunxiang.Li@amd.com>
> ---
>  drivers/vfio/pci/vfio_pci_config.c |  4 ++++
>  drivers/vfio/pci/vfio_pci_core.c   | 35 +++++++++++++++---------------
>  drivers/vfio/pci/vfio_pci_rdwr.c   | 14 ++++++++++--
>  3 files changed, 34 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c
> index e41c3a965663e..4c673d842fb35 100644
> --- a/drivers/vfio/pci/vfio_pci_config.c
> +++ b/drivers/vfio/pci/vfio_pci_config.c
> @@ -511,6 +511,10 @@ static void vfio_bar_fixup(struct vfio_pci_core_device *vdev)
>  		mask = ~(pci_resource_len(pdev, PCI_ROM_RESOURCE) - 1);
>  		mask |= PCI_ROM_ADDRESS_ENABLE;
>  		*vbar &= cpu_to_le32((u32)mask);
> +	} else if (pdev->rom && pdev->romlen) {
> +		mask = ~(roundup_pow_of_two(pdev->romlen) - 1);
> +		mask |= PCI_ROM_ADDRESS_ENABLE;
> +		*vbar &= cpu_to_le32((u32)mask);
>  	} else {
>  		*vbar = 0;
>  	}
> diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
> index b49dd9cdc072a..3120c1e9f22cb 100644
> --- a/drivers/vfio/pci/vfio_pci_core.c
> +++ b/drivers/vfio/pci/vfio_pci_core.c
> @@ -1049,30 +1049,31 @@ static int vfio_pci_ioctl_get_region_info(struct vfio_pci_core_device *vdev,
>  		break;
>  	case VFIO_PCI_ROM_REGION_INDEX: {
>  		void __iomem *io;
> -		size_t size;
> +		size_t dont_care;

It still receives the size even if we don't consume it.

>  		u16 cmd;
>  
>  		info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
>  		info.flags = 0;
> +		info.size = 0;
>  
> -		/* Report the BAR size, not the ROM size */
> -		info.size = pci_resource_len(pdev, info.index);
> -		if (!info.size)
> -			break;
> -
> -		/*
> -		 * Is it really there?  Enable memory decode for implicit access
> -		 * in pci_map_rom().
> -		 */
> -		cmd = vfio_pci_memory_lock_and_enable(vdev);
> -		io = pci_map_rom(pdev, &size);
> -		if (io) {
> +		if (pci_resource_start(pdev, PCI_ROM_RESOURCE)) {
> +			/* Check ROM content is valid. Need to enable memory

Incorrect comment style.

> +			 * decode for ROM access in pci_map_rom().
> +			 */
> +			cmd = vfio_pci_memory_lock_and_enable(vdev);
> +			io = pci_map_rom(pdev, &dont_care);
> +			if (io) {
> +				info.flags = VFIO_REGION_INFO_FLAG_READ;
> +				/* Report the BAR size, not the ROM size. */
> +				info.size = pci_resource_len(pdev, PCI_ROM_RESOURCE);
> +				pci_unmap_rom(pdev, io);
> +			}
> +			vfio_pci_memory_unlock_and_restore(vdev, cmd);
> +		} else if (pdev->rom && pdev->romlen) {
>  			info.flags = VFIO_REGION_INFO_FLAG_READ;
> -			pci_unmap_rom(pdev, io);
> -		} else {
> -			info.size = 0;
> +			/* Report BAR size as power of two. */
> +			info.size = roundup_pow_of_two(pdev->romlen);
>  		}
> -		vfio_pci_memory_unlock_and_restore(vdev, cmd);
>  
>  		break;
>  	}
> diff --git a/drivers/vfio/pci/vfio_pci_rdwr.c b/drivers/vfio/pci/vfio_pci_rdwr.c
> index 4bed9fd5af50f..4ea983cf499d9 100644
> --- a/drivers/vfio/pci/vfio_pci_rdwr.c
> +++ b/drivers/vfio/pci/vfio_pci_rdwr.c
> @@ -243,6 +243,8 @@ ssize_t vfio_pci_bar_rw(struct vfio_pci_core_device *vdev, char __user *buf,
>  
>  	if (pci_resource_start(pdev, bar))
>  		end = pci_resource_len(pdev, bar);
> +	else if (bar == PCI_ROM_RESOURCE && pdev->rom && pdev->romlen)
> +		end = roundup_pow_of_two(pdev->romlen);
>  	else
>  		return -EINVAL;
>  
> @@ -259,7 +261,12 @@ ssize_t vfio_pci_bar_rw(struct vfio_pci_core_device *vdev, char __user *buf,
>  		 * excluded range at the end of the actual ROM.  This makes
>  		 * filling large ROM BARs much faster.
>  		 */
> -		io = pci_map_rom(pdev, &x_start);
> +		if (pci_resource_start(pdev, bar)) {
> +			io = pci_map_rom(pdev, &x_start);
> +		} else {
> +			io = ioremap(pdev->rom, pdev->romlen);
> +			x_start = pdev->romlen;
> +		}
>  		if (!io)
>  			return -ENOMEM;
>  		x_end = end;
> @@ -267,7 +274,10 @@ ssize_t vfio_pci_bar_rw(struct vfio_pci_core_device *vdev, char __user *buf,
>  		done = vfio_pci_core_do_io_rw(vdev, 1, io, buf, pos,
>  					      count, x_start, x_end, 0);
>  
> -		pci_unmap_rom(pdev, io);
> +		if (pci_resource_start(pdev, bar))
> +			pci_unmap_rom(pdev, io);
> +		else
> +			iounmap(io);
>  	} else {
>  		done = vfio_pci_core_setup_barmap(vdev, bar);
>  		if (done)

It's not clear why the refactoring of the previous patch was really
necessary simply to have an alternate map and unmap path.  Thanks,

Alex


^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [PATCH 2/3] vfio/pci: refactor vfio_pci_bar_rw
  2024-12-12 23:00   ` Alex Williamson
@ 2024-12-16 13:48     ` Li, Yunxiang (Teddy)
  0 siblings, 0 replies; 9+ messages in thread
From: Li, Yunxiang (Teddy) @ 2024-12-16 13:48 UTC (permalink / raw)
  To: Alex Williamson
  Cc: kvm@vger.kernel.org, kevin.tian@intel.com, yishaih@nvidia.com,
	ankita@nvidia.com, jgg@ziepe.ca

[Public]

> From: Alex Williamson <alex.williamson@redhat.com>
> Sent: Thursday, December 12, 2024 18:01
>
> On Thu, 12 Dec 2024 15:50:49 -0500
> Yunxiang Li <Yunxiang.Li@amd.com> wrote:
>
> > In the next patch the logic for reading ROM will get more complicated,
> > so decouple the ROM path from the normal path. Also check that for ROM
> > write is not allowed.
>
> This is already enforced by the caller.  Vague references to the next patch don't
> make a lot of sense once commits are in the tree, this should describe what you're
> preparing for.
>
> >
> > Signed-off-by: Yunxiang Li <Yunxiang.Li@amd.com>
> > ---
> >  drivers/vfio/pci/vfio_pci_rdwr.c | 47
> > ++++++++++++++++----------------
> >  1 file changed, 24 insertions(+), 23 deletions(-)
> >
> > diff --git a/drivers/vfio/pci/vfio_pci_rdwr.c
> > b/drivers/vfio/pci/vfio_pci_rdwr.c
> > index a1eeacad82120..4bed9fd5af50f 100644
> > --- a/drivers/vfio/pci/vfio_pci_rdwr.c
> > +++ b/drivers/vfio/pci/vfio_pci_rdwr.c
> > @@ -236,10 +236,9 @@ ssize_t vfio_pci_bar_rw(struct vfio_pci_core_device
> *vdev, char __user *buf,
> >     struct pci_dev *pdev = vdev->pdev;
> >     loff_t pos = *ppos & VFIO_PCI_OFFSET_MASK;
> >     int bar = VFIO_PCI_OFFSET_TO_INDEX(*ppos);
> > -   size_t x_start = 0, x_end = 0;
> > +   size_t x_start, x_end;
> >     resource_size_t end;
> >     void __iomem *io;
> > -   struct resource *res = &vdev->pdev->resource[bar];
> >     ssize_t done;
> >
> >     if (pci_resource_start(pdev, bar))
> > @@ -253,41 +252,43 @@ ssize_t vfio_pci_bar_rw(struct vfio_pci_core_device
> *vdev, char __user *buf,
> >     count = min(count, (size_t)(end - pos));
> >
> >     if (bar == PCI_ROM_RESOURCE) {
> > +           if (iswrite)
> > +                   return -EINVAL;
> >             /*
> >              * The ROM can fill less space than the BAR, so we start the
> >              * excluded range at the end of the actual ROM.  This makes
> >              * filling large ROM BARs much faster.
> >              */
> >             io = pci_map_rom(pdev, &x_start);
> > -           if (!io) {
> > -                   done = -ENOMEM;
> > -                   goto out;
> > -           }
> > +           if (!io)
> > +                   return -ENOMEM;
> >             x_end = end;
> > +
> > +           done = vfio_pci_core_do_io_rw(vdev, 1, io, buf, pos,
> > +                                         count, x_start, x_end, 0);
> > +
> > +           pci_unmap_rom(pdev, io);
> >     } else {
> > -           int ret = vfio_pci_core_setup_barmap(vdev, bar);
> > -           if (ret) {
> > -                   done = ret;
> > -                   goto out;
> > -           }
> > +           done = vfio_pci_core_setup_barmap(vdev, bar);
> > +           if (done)
> > +                   return done;
> >
> >             io = vdev->barmap[bar];
> > -   }
> >
> > -   if (bar == vdev->msix_bar) {
> > -           x_start = vdev->msix_offset;
> > -           x_end = vdev->msix_offset + vdev->msix_size;
> > -   }
> > +           if (bar == vdev->msix_bar) {
> > +                   x_start = vdev->msix_offset;
> > +                   x_end = vdev->msix_offset + vdev->msix_size;
> > +           } else {
> > +                   x_start = 0;
> > +                   x_end = 0;
> > +           }
>
> There's a lot of semantic preference noise that obscures what you're actually trying
> to accomplish here, effectively this has only refactored the code to have separate
> calls to ..do_io_rw() for the ROM vs other case and therefore pushed the unmap
> into the ROM case, introducing various new exit paths.

Yes, the primary goal was to move the resource allocation and cleanup into one clause, otherwise there would be duplicated nested if clauses at the end just for cleanup. I didn't realize the caller was checking for write like that and then calling into this. It seems like it make more sense to have different helper functions, something like this. The two code path don't really have much in common other than they call do_io_rw at the end.

        case VFIO_PCI_ROM_REGION_INDEX:
                if (iswrite)
                        return -EINVAL;
                return vfio_pci_rom_read(vdev, buf, count, ppos);

        case VFIO_PCI_BAR0_REGION_INDEX ... VFIO_PCI_BAR5_REGION_INDEX:
                return vfio_pci_bar_rw(vdev, buf, count, ppos, iswrite);

> >
> > -   done = vfio_pci_core_do_io_rw(vdev, res->flags & IORESOURCE_MEM,
> io, buf, pos,
> > +           done = vfio_pci_core_do_io_rw(vdev, pci_resource_flags(pdev, bar)
> &
> > +IORESOURCE_MEM, io, buf, pos,
>
> The line is too long already, now it's indented further and the wrapping needs to be
> adjusted.
>
> >                                   count, x_start, x_end, iswrite);
> > -
> > -   if (done >= 0)
> > -           *ppos += done;
> > -
> > -   if (bar == PCI_ROM_RESOURCE)
> > -           pci_unmap_rom(pdev, io);
> > +   }
> >  out:
>
> Both goto's to this label were removed above, none added.  Thanks,
>
> Alex
>
> > +   if (done > 0)
> > +           *ppos += done;
> >     return done;
> >  }
> >


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] vfio/pci: refactor vfio_pci_bar_rw
  2024-12-12 20:50 ` [PATCH 2/3] vfio/pci: refactor vfio_pci_bar_rw Yunxiang Li
  2024-12-12 23:00   ` Alex Williamson
@ 2024-12-20 12:36   ` kernel test robot
  2024-12-20 20:22   ` kernel test robot
  2 siblings, 0 replies; 9+ messages in thread
From: kernel test robot @ 2024-12-20 12:36 UTC (permalink / raw)
  To: Yunxiang Li, kvm, alex.williamson
  Cc: oe-kbuild-all, kevin.tian, yishaih, ankita, jgg, Yunxiang Li

Hi Yunxiang,

kernel test robot noticed the following build warnings:

[auto build test WARNING on awilliam-vfio/next]
[also build test WARNING on awilliam-vfio/for-linus linus/master v6.13-rc3 next-20241220]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Yunxiang-Li/vfio-pci-refactor-vfio_pci_bar_rw/20241213-045257
base:   https://github.com/awilliam/linux-vfio.git next
patch link:    https://lore.kernel.org/r/20241212205050.5737-2-Yunxiang.Li%40amd.com
patch subject: [PATCH 2/3] vfio/pci: refactor vfio_pci_bar_rw
config: s390-randconfig-001-20241220 (https://download.01.org/0day-ci/archive/20241220/202412202034.alL3D6CO-lkp@intel.com/config)
compiler: s390-linux-gcc (GCC) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241220/202412202034.alL3D6CO-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202412202034.alL3D6CO-lkp@intel.com/

All warnings (new ones prefixed by >>):

   drivers/vfio/pci/vfio_pci_rdwr.c: In function 'vfio_pci_bar_rw':
>> drivers/vfio/pci/vfio_pci_rdwr.c:289:1: warning: label 'out' defined but not used [-Wunused-label]
     289 | out:
         | ^~~


vim +/out +289 drivers/vfio/pci/vfio_pci_rdwr.c

0d77ed3589ac05 Alex Williamson 2018-03-21  232  
536475109c8284 Max Gurtovoy    2021-08-26  233  ssize_t vfio_pci_bar_rw(struct vfio_pci_core_device *vdev, char __user *buf,
89e1f7d4c66d85 Alex Williamson 2012-07-31  234  			size_t count, loff_t *ppos, bool iswrite)
89e1f7d4c66d85 Alex Williamson 2012-07-31  235  {
89e1f7d4c66d85 Alex Williamson 2012-07-31  236  	struct pci_dev *pdev = vdev->pdev;
89e1f7d4c66d85 Alex Williamson 2012-07-31  237  	loff_t pos = *ppos & VFIO_PCI_OFFSET_MASK;
89e1f7d4c66d85 Alex Williamson 2012-07-31  238  	int bar = VFIO_PCI_OFFSET_TO_INDEX(*ppos);
1378a17537c269 Yunxiang Li     2024-12-12  239  	size_t x_start, x_end;
89e1f7d4c66d85 Alex Williamson 2012-07-31  240  	resource_size_t end;
906ee99dd2a5c8 Alex Williamson 2013-02-14  241  	void __iomem *io;
906ee99dd2a5c8 Alex Williamson 2013-02-14  242  	ssize_t done;
89e1f7d4c66d85 Alex Williamson 2012-07-31  243  
a13b64591747e8 Alex Williamson 2016-02-22  244  	if (pci_resource_start(pdev, bar))
89e1f7d4c66d85 Alex Williamson 2012-07-31  245  		end = pci_resource_len(pdev, bar);
a13b64591747e8 Alex Williamson 2016-02-22  246  	else
a13b64591747e8 Alex Williamson 2016-02-22  247  		return -EINVAL;
89e1f7d4c66d85 Alex Williamson 2012-07-31  248  
906ee99dd2a5c8 Alex Williamson 2013-02-14  249  	if (pos >= end)
89e1f7d4c66d85 Alex Williamson 2012-07-31  250  		return -EINVAL;
89e1f7d4c66d85 Alex Williamson 2012-07-31  251  
906ee99dd2a5c8 Alex Williamson 2013-02-14  252  	count = min(count, (size_t)(end - pos));
89e1f7d4c66d85 Alex Williamson 2012-07-31  253  
89e1f7d4c66d85 Alex Williamson 2012-07-31  254  	if (bar == PCI_ROM_RESOURCE) {
1378a17537c269 Yunxiang Li     2024-12-12  255  		if (iswrite)
1378a17537c269 Yunxiang Li     2024-12-12  256  			return -EINVAL;
906ee99dd2a5c8 Alex Williamson 2013-02-14  257  		/*
906ee99dd2a5c8 Alex Williamson 2013-02-14  258  		 * The ROM can fill less space than the BAR, so we start the
906ee99dd2a5c8 Alex Williamson 2013-02-14  259  		 * excluded range at the end of the actual ROM.  This makes
906ee99dd2a5c8 Alex Williamson 2013-02-14  260  		 * filling large ROM BARs much faster.
906ee99dd2a5c8 Alex Williamson 2013-02-14  261  		 */
89e1f7d4c66d85 Alex Williamson 2012-07-31  262  		io = pci_map_rom(pdev, &x_start);
1378a17537c269 Yunxiang Li     2024-12-12  263  		if (!io)
1378a17537c269 Yunxiang Li     2024-12-12  264  			return -ENOMEM;
89e1f7d4c66d85 Alex Williamson 2012-07-31  265  		x_end = end;
1378a17537c269 Yunxiang Li     2024-12-12  266  
1378a17537c269 Yunxiang Li     2024-12-12  267  		done = vfio_pci_core_do_io_rw(vdev, 1, io, buf, pos,
1378a17537c269 Yunxiang Li     2024-12-12  268  					      count, x_start, x_end, 0);
1378a17537c269 Yunxiang Li     2024-12-12  269  
1378a17537c269 Yunxiang Li     2024-12-12  270  		pci_unmap_rom(pdev, io);
0d77ed3589ac05 Alex Williamson 2018-03-21  271  	} else {
1378a17537c269 Yunxiang Li     2024-12-12  272  		done = vfio_pci_core_setup_barmap(vdev, bar);
1378a17537c269 Yunxiang Li     2024-12-12  273  		if (done)
1378a17537c269 Yunxiang Li     2024-12-12  274  			return done;
89e1f7d4c66d85 Alex Williamson 2012-07-31  275  
89e1f7d4c66d85 Alex Williamson 2012-07-31  276  		io = vdev->barmap[bar];
89e1f7d4c66d85 Alex Williamson 2012-07-31  277  
89e1f7d4c66d85 Alex Williamson 2012-07-31  278  		if (bar == vdev->msix_bar) {
89e1f7d4c66d85 Alex Williamson 2012-07-31  279  			x_start = vdev->msix_offset;
89e1f7d4c66d85 Alex Williamson 2012-07-31  280  			x_end = vdev->msix_offset + vdev->msix_size;
1378a17537c269 Yunxiang Li     2024-12-12  281  		} else {
1378a17537c269 Yunxiang Li     2024-12-12  282  			x_start = 0;
1378a17537c269 Yunxiang Li     2024-12-12  283  			x_end = 0;
89e1f7d4c66d85 Alex Williamson 2012-07-31  284  		}
89e1f7d4c66d85 Alex Williamson 2012-07-31  285  
1378a17537c269 Yunxiang Li     2024-12-12  286  		done = vfio_pci_core_do_io_rw(vdev, pci_resource_flags(pdev, bar) & IORESOURCE_MEM, io, buf, pos,
bc93b9ae0151ae Alex Williamson 2020-08-17  287  				      count, x_start, x_end, iswrite);
1378a17537c269 Yunxiang Li     2024-12-12  288  	}
abafbc551fdded Alex Williamson 2020-04-22 @289  out:
1378a17537c269 Yunxiang Li     2024-12-12  290  	if (done > 0)
1378a17537c269 Yunxiang Li     2024-12-12  291  		*ppos += done;
906ee99dd2a5c8 Alex Williamson 2013-02-14  292  	return done;
89e1f7d4c66d85 Alex Williamson 2012-07-31  293  }
84237a826b261d Alex Williamson 2013-02-18  294  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] vfio/pci: refactor vfio_pci_bar_rw
  2024-12-12 20:50 ` [PATCH 2/3] vfio/pci: refactor vfio_pci_bar_rw Yunxiang Li
  2024-12-12 23:00   ` Alex Williamson
  2024-12-20 12:36   ` kernel test robot
@ 2024-12-20 20:22   ` kernel test robot
  2 siblings, 0 replies; 9+ messages in thread
From: kernel test robot @ 2024-12-20 20:22 UTC (permalink / raw)
  To: Yunxiang Li, kvm, alex.williamson
  Cc: llvm, oe-kbuild-all, kevin.tian, yishaih, ankita, jgg,
	Yunxiang Li

Hi Yunxiang,

kernel test robot noticed the following build warnings:

[auto build test WARNING on awilliam-vfio/next]
[also build test WARNING on awilliam-vfio/for-linus linus/master v6.13-rc3 next-20241220]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Yunxiang-Li/vfio-pci-refactor-vfio_pci_bar_rw/20241213-045257
base:   https://github.com/awilliam/linux-vfio.git next
patch link:    https://lore.kernel.org/r/20241212205050.5737-2-Yunxiang.Li%40amd.com
patch subject: [PATCH 2/3] vfio/pci: refactor vfio_pci_bar_rw
config: i386-buildonly-randconfig-004-20241220 (https://download.01.org/0day-ci/archive/20241221/202412210450.yl9DrP8o-lkp@intel.com/config)
compiler: clang version 19.1.3 (https://github.com/llvm/llvm-project ab51eccf88f5321e7c60591c5546b254b6afab99)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241221/202412210450.yl9DrP8o-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202412210450.yl9DrP8o-lkp@intel.com/

All warnings (new ones prefixed by >>):

   In file included from drivers/vfio/pci/vfio_pci_rdwr.c:14:
   In file included from include/linux/pci.h:1650:
   In file included from include/linux/dmapool.h:14:
   In file included from include/linux/scatterlist.h:8:
   In file included from include/linux/mm.h:2213:
   include/linux/vmstat.h:518:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
     518 |         return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
         |                               ~~~~~~~~~~~ ^ ~~~
>> drivers/vfio/pci/vfio_pci_rdwr.c:289:1: warning: unused label 'out' [-Wunused-label]
     289 | out:
         | ^~~~
   2 warnings generated.


vim +/out +289 drivers/vfio/pci/vfio_pci_rdwr.c

0d77ed3589ac054 Alex Williamson 2018-03-21  232  
536475109c82841 Max Gurtovoy    2021-08-26  233  ssize_t vfio_pci_bar_rw(struct vfio_pci_core_device *vdev, char __user *buf,
89e1f7d4c66d85f Alex Williamson 2012-07-31  234  			size_t count, loff_t *ppos, bool iswrite)
89e1f7d4c66d85f Alex Williamson 2012-07-31  235  {
89e1f7d4c66d85f Alex Williamson 2012-07-31  236  	struct pci_dev *pdev = vdev->pdev;
89e1f7d4c66d85f Alex Williamson 2012-07-31  237  	loff_t pos = *ppos & VFIO_PCI_OFFSET_MASK;
89e1f7d4c66d85f Alex Williamson 2012-07-31  238  	int bar = VFIO_PCI_OFFSET_TO_INDEX(*ppos);
1378a17537c2699 Yunxiang Li     2024-12-12  239  	size_t x_start, x_end;
89e1f7d4c66d85f Alex Williamson 2012-07-31  240  	resource_size_t end;
906ee99dd2a5c81 Alex Williamson 2013-02-14  241  	void __iomem *io;
906ee99dd2a5c81 Alex Williamson 2013-02-14  242  	ssize_t done;
89e1f7d4c66d85f Alex Williamson 2012-07-31  243  
a13b64591747e8a Alex Williamson 2016-02-22  244  	if (pci_resource_start(pdev, bar))
89e1f7d4c66d85f Alex Williamson 2012-07-31  245  		end = pci_resource_len(pdev, bar);
a13b64591747e8a Alex Williamson 2016-02-22  246  	else
a13b64591747e8a Alex Williamson 2016-02-22  247  		return -EINVAL;
89e1f7d4c66d85f Alex Williamson 2012-07-31  248  
906ee99dd2a5c81 Alex Williamson 2013-02-14  249  	if (pos >= end)
89e1f7d4c66d85f Alex Williamson 2012-07-31  250  		return -EINVAL;
89e1f7d4c66d85f Alex Williamson 2012-07-31  251  
906ee99dd2a5c81 Alex Williamson 2013-02-14  252  	count = min(count, (size_t)(end - pos));
89e1f7d4c66d85f Alex Williamson 2012-07-31  253  
89e1f7d4c66d85f Alex Williamson 2012-07-31  254  	if (bar == PCI_ROM_RESOURCE) {
1378a17537c2699 Yunxiang Li     2024-12-12  255  		if (iswrite)
1378a17537c2699 Yunxiang Li     2024-12-12  256  			return -EINVAL;
906ee99dd2a5c81 Alex Williamson 2013-02-14  257  		/*
906ee99dd2a5c81 Alex Williamson 2013-02-14  258  		 * The ROM can fill less space than the BAR, so we start the
906ee99dd2a5c81 Alex Williamson 2013-02-14  259  		 * excluded range at the end of the actual ROM.  This makes
906ee99dd2a5c81 Alex Williamson 2013-02-14  260  		 * filling large ROM BARs much faster.
906ee99dd2a5c81 Alex Williamson 2013-02-14  261  		 */
89e1f7d4c66d85f Alex Williamson 2012-07-31  262  		io = pci_map_rom(pdev, &x_start);
1378a17537c2699 Yunxiang Li     2024-12-12  263  		if (!io)
1378a17537c2699 Yunxiang Li     2024-12-12  264  			return -ENOMEM;
89e1f7d4c66d85f Alex Williamson 2012-07-31  265  		x_end = end;
1378a17537c2699 Yunxiang Li     2024-12-12  266  
1378a17537c2699 Yunxiang Li     2024-12-12  267  		done = vfio_pci_core_do_io_rw(vdev, 1, io, buf, pos,
1378a17537c2699 Yunxiang Li     2024-12-12  268  					      count, x_start, x_end, 0);
1378a17537c2699 Yunxiang Li     2024-12-12  269  
1378a17537c2699 Yunxiang Li     2024-12-12  270  		pci_unmap_rom(pdev, io);
0d77ed3589ac054 Alex Williamson 2018-03-21  271  	} else {
1378a17537c2699 Yunxiang Li     2024-12-12  272  		done = vfio_pci_core_setup_barmap(vdev, bar);
1378a17537c2699 Yunxiang Li     2024-12-12  273  		if (done)
1378a17537c2699 Yunxiang Li     2024-12-12  274  			return done;
89e1f7d4c66d85f Alex Williamson 2012-07-31  275  
89e1f7d4c66d85f Alex Williamson 2012-07-31  276  		io = vdev->barmap[bar];
89e1f7d4c66d85f Alex Williamson 2012-07-31  277  
89e1f7d4c66d85f Alex Williamson 2012-07-31  278  		if (bar == vdev->msix_bar) {
89e1f7d4c66d85f Alex Williamson 2012-07-31  279  			x_start = vdev->msix_offset;
89e1f7d4c66d85f Alex Williamson 2012-07-31  280  			x_end = vdev->msix_offset + vdev->msix_size;
1378a17537c2699 Yunxiang Li     2024-12-12  281  		} else {
1378a17537c2699 Yunxiang Li     2024-12-12  282  			x_start = 0;
1378a17537c2699 Yunxiang Li     2024-12-12  283  			x_end = 0;
89e1f7d4c66d85f Alex Williamson 2012-07-31  284  		}
89e1f7d4c66d85f Alex Williamson 2012-07-31  285  
1378a17537c2699 Yunxiang Li     2024-12-12  286  		done = vfio_pci_core_do_io_rw(vdev, pci_resource_flags(pdev, bar) & IORESOURCE_MEM, io, buf, pos,
bc93b9ae0151ae5 Alex Williamson 2020-08-17  287  				      count, x_start, x_end, iswrite);
1378a17537c2699 Yunxiang Li     2024-12-12  288  	}
abafbc551fddede Alex Williamson 2020-04-22 @289  out:
1378a17537c2699 Yunxiang Li     2024-12-12  290  	if (done > 0)
1378a17537c2699 Yunxiang Li     2024-12-12  291  		*ppos += done;
906ee99dd2a5c81 Alex Williamson 2013-02-14  292  	return done;
89e1f7d4c66d85f Alex Williamson 2012-07-31  293  }
84237a826b261de Alex Williamson 2013-02-18  294  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-12-20 20:23 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-12 20:50 [PATCH 1/3] vfio/pci: Remove shadow rom specific code paths Yunxiang Li
2024-12-12 20:50 ` [PATCH 2/3] vfio/pci: refactor vfio_pci_bar_rw Yunxiang Li
2024-12-12 23:00   ` Alex Williamson
2024-12-16 13:48     ` Li, Yunxiang (Teddy)
2024-12-20 12:36   ` kernel test robot
2024-12-20 20:22   ` kernel test robot
2024-12-12 20:50 ` [PATCH 3/3] vfio/pci: Expose setup ROM at ROM bar when needed Yunxiang Li
2024-12-12 23:00   ` Alex Williamson
2024-12-12 23:00 ` [PATCH 1/3] vfio/pci: Remove shadow rom specific code paths Alex Williamson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox