public inbox for linux-pci@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] PCI: hv: Fix ring buffer size calculation
@ 2024-02-13  6:19 mhkelley58
  2024-02-13  6:54 ` Kuppuswamy Sathyanarayanan
  2024-02-14 14:18 ` Ilpo Järvinen
  0 siblings, 2 replies; 4+ messages in thread
From: mhkelley58 @ 2024-02-13  6:19 UTC (permalink / raw)
  To: haiyangz, wei.liu, decui, lpieralisi, kw, robh, bhelgaas,
	linux-pci, linux-kernel, linux-hyperv

From: Michael Kelley <mhklinux@outlook.com>

For a physical PCI device that is passed through to a Hyper-V guest VM,
current code specifies the VMBus ring buffer size as 4 pages.  But this
is an inappropriate dependency, since the amount of ring buffer space
needed is unrelated to PAGE_SIZE. For example, on x86 the ring buffer
size ends up as 16 Kbytes, while on ARM64 with 64 Kbyte pages, the ring
size bloats to 256 Kbytes. The ring buffer for PCI pass-thru devices
is used for only a few messages during device setup and removal, so any
space above a few Kbytes is wasted.

Fix this by declaring the ring buffer size to be a fixed 16 Kbytes.
Furthermore, use the VMBUS_RING_SIZE() macro so that the ring buffer
header is properly accounted for, and so the size is rounded up to a
page boundary, using the page size for which the kernel is built. While
w/64 Kbyte pages this results in a 64 Kbyte ring buffer header plus a
64 Kbyte ring buffer, that's the smallest possible with that page size.
It's still 128 Kbytes better than the current code.

Cc: <stable@vger.kernel.org> # 5.15.x
Signed-off-by: Michael Kelley <mhklinux@outlook.com>
---
 drivers/pci/controller/pci-hyperv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c
index 1eaffff40b8d..5f22ad38bb98 100644
--- a/drivers/pci/controller/pci-hyperv.c
+++ b/drivers/pci/controller/pci-hyperv.c
@@ -465,7 +465,7 @@ struct pci_eject_response {
 	u32 status;
 } __packed;
 
-static int pci_ring_size = (4 * PAGE_SIZE);
+static int pci_ring_size = VMBUS_RING_SIZE(16 * 1024);
 
 /*
  * Driver specific state.
-- 
2.25.1


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

* Re: [PATCH 1/1] PCI: hv: Fix ring buffer size calculation
  2024-02-13  6:19 [PATCH 1/1] PCI: hv: Fix ring buffer size calculation mhkelley58
@ 2024-02-13  6:54 ` Kuppuswamy Sathyanarayanan
  2024-02-15  7:26   ` Michael Kelley
  2024-02-14 14:18 ` Ilpo Järvinen
  1 sibling, 1 reply; 4+ messages in thread
From: Kuppuswamy Sathyanarayanan @ 2024-02-13  6:54 UTC (permalink / raw)
  To: mhklinux, haiyangz, wei.liu, decui, lpieralisi, kw, robh,
	bhelgaas, linux-pci, linux-kernel, linux-hyperv


On 2/12/24 10:19 PM, mhkelley58@gmail.com wrote:
> From: Michael Kelley <mhklinux@outlook.com>
>
> For a physical PCI device that is passed through to a Hyper-V guest VM,
> current code specifies the VMBus ring buffer size as 4 pages.  But this
> is an inappropriate dependency, since the amount of ring buffer space
> needed is unrelated to PAGE_SIZE. For example, on x86 the ring buffer
> size ends up as 16 Kbytes, while on ARM64 with 64 Kbyte pages, the ring
> size bloats to 256 Kbytes. The ring buffer for PCI pass-thru devices
> is used for only a few messages during device setup and removal, so any
> space above a few Kbytes is wasted.
>
> Fix this by declaring the ring buffer size to be a fixed 16 Kbytes.
> Furthermore, use the VMBUS_RING_SIZE() macro so that the ring buffer
> header is properly accounted for, and so the size is rounded up to a
> page boundary, using the page size for which the kernel is built. While
> w/64 Kbyte pages this results in a 64 Kbyte ring buffer header plus a
> 64 Kbyte ring buffer, that's the smallest possible with that page size.
> It's still 128 Kbytes better than the current code.
>
> Cc: <stable@vger.kernel.org> # 5.15.x
> Signed-off-by: Michael Kelley <mhklinux@outlook.com>
> ---
Looks good to me.

Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
>  drivers/pci/controller/pci-hyperv.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c
> index 1eaffff40b8d..5f22ad38bb98 100644
> --- a/drivers/pci/controller/pci-hyperv.c
> +++ b/drivers/pci/controller/pci-hyperv.c
> @@ -465,7 +465,7 @@ struct pci_eject_response {
>  	u32 status;
>  } __packed;
>  
> -static int pci_ring_size = (4 * PAGE_SIZE);
> +static int pci_ring_size = VMBUS_RING_SIZE(16 * 1024);
>  
Nit: I think you can use SZ_16K to make it more readable.
>  /*
>   * Driver specific state.

-- 
Sathyanarayanan Kuppuswamy
Linux Kernel Developer


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

* Re: [PATCH 1/1] PCI: hv: Fix ring buffer size calculation
  2024-02-13  6:19 [PATCH 1/1] PCI: hv: Fix ring buffer size calculation mhkelley58
  2024-02-13  6:54 ` Kuppuswamy Sathyanarayanan
@ 2024-02-14 14:18 ` Ilpo Järvinen
  1 sibling, 0 replies; 4+ messages in thread
From: Ilpo Järvinen @ 2024-02-14 14:18 UTC (permalink / raw)
  To: mhklinux
  Cc: haiyangz, wei.liu, decui, lpieralisi, kw, robh, bhelgaas,
	linux-pci, LKML, linux-hyperv

On Mon, 12 Feb 2024, mhkelley58@gmail.com wrote:

> From: Michael Kelley <mhklinux@outlook.com>
> 
> For a physical PCI device that is passed through to a Hyper-V guest VM,
> current code specifies the VMBus ring buffer size as 4 pages.  But this
> is an inappropriate dependency, since the amount of ring buffer space
> needed is unrelated to PAGE_SIZE. For example, on x86 the ring buffer
> size ends up as 16 Kbytes, while on ARM64 with 64 Kbyte pages, the ring
> size bloats to 256 Kbytes. The ring buffer for PCI pass-thru devices
> is used for only a few messages during device setup and removal, so any
> space above a few Kbytes is wasted.
> 
> Fix this by declaring the ring buffer size to be a fixed 16 Kbytes.
> Furthermore, use the VMBUS_RING_SIZE() macro so that the ring buffer
> header is properly accounted for, and so the size is rounded up to a
> page boundary, using the page size for which the kernel is built. While
> w/64 Kbyte pages this results in a 64 Kbyte ring buffer header plus a
> 64 Kbyte ring buffer, that's the smallest possible with that page size.
> It's still 128 Kbytes better than the current code.
> 
> Cc: <stable@vger.kernel.org> # 5.15.x
> Signed-off-by: Michael Kelley <mhklinux@outlook.com>
> ---
>  drivers/pci/controller/pci-hyperv.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c
> index 1eaffff40b8d..5f22ad38bb98 100644
> --- a/drivers/pci/controller/pci-hyperv.c
> +++ b/drivers/pci/controller/pci-hyperv.c
> @@ -465,7 +465,7 @@ struct pci_eject_response {
>  	u32 status;
>  } __packed;
>  
> -static int pci_ring_size = (4 * PAGE_SIZE);
> +static int pci_ring_size = VMBUS_RING_SIZE(16 * 1024);

SZ_16K (and add the relevant #include if needed).

-- 
 i.


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

* RE: [PATCH 1/1] PCI: hv: Fix ring buffer size calculation
  2024-02-13  6:54 ` Kuppuswamy Sathyanarayanan
@ 2024-02-15  7:26   ` Michael Kelley
  0 siblings, 0 replies; 4+ messages in thread
From: Michael Kelley @ 2024-02-15  7:26 UTC (permalink / raw)
  To: Kuppuswamy Sathyanarayanan, Ilpo Järvinen
  Cc: haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com,
	lpieralisi@kernel.org, kw@linux.com, robh@kernel.org,
	bhelgaas@google.com, linux-pci@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org

From: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
> 
> On 2/12/24 10:19 PM, mhkelley58@gmail.com wrote:
> > From: Michael Kelley <mhklinux@outlook.com>
> >
> > For a physical PCI device that is passed through to a Hyper-V guest VM,
> > current code specifies the VMBus ring buffer size as 4 pages.  But this
> > is an inappropriate dependency, since the amount of ring buffer space
> > needed is unrelated to PAGE_SIZE. For example, on x86 the ring buffer
> > size ends up as 16 Kbytes, while on ARM64 with 64 Kbyte pages, the ring
> > size bloats to 256 Kbytes. The ring buffer for PCI pass-thru devices
> > is used for only a few messages during device setup and removal, so any
> > space above a few Kbytes is wasted.
> >
> > Fix this by declaring the ring buffer size to be a fixed 16 Kbytes.
> > Furthermore, use the VMBUS_RING_SIZE() macro so that the ring buffer
> > header is properly accounted for, and so the size is rounded up to a
> > page boundary, using the page size for which the kernel is built. While
> > w/64 Kbyte pages this results in a 64 Kbyte ring buffer header plus a
> > 64 Kbyte ring buffer, that's the smallest possible with that page size.
> > It's still 128 Kbytes better than the current code.
> >
> > Cc: <stable@vger.kernel.org> # 5.15.x
> > Signed-off-by: Michael Kelley <mhklinux@outlook.com>
> > ---
> Looks good to me.
> 
> Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
> >  drivers/pci/controller/pci-hyperv.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c
> > index 1eaffff40b8d..5f22ad38bb98 100644
> > --- a/drivers/pci/controller/pci-hyperv.c
> > +++ b/drivers/pci/controller/pci-hyperv.c
> > @@ -465,7 +465,7 @@ struct pci_eject_response {
> >  	u32 status;
> >  } __packed;
> >
> > -static int pci_ring_size = (4 * PAGE_SIZE);
> > +static int pci_ring_size = VMBUS_RING_SIZE(16 * 1024);
> >
> Nit: I think you can use SZ_16K to make it more readable.

Thanks for the review.  I'll send a v2 that uses SZ_16K per your
and Ilpo Järvinen's comment.

Michael 

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

end of thread, other threads:[~2024-02-15  7:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-13  6:19 [PATCH 1/1] PCI: hv: Fix ring buffer size calculation mhkelley58
2024-02-13  6:54 ` Kuppuswamy Sathyanarayanan
2024-02-15  7:26   ` Michael Kelley
2024-02-14 14:18 ` Ilpo Järvinen

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