qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] s390x/pci: small set of fixes
@ 2023-11-10 17:51 Matthew Rosato
  2023-11-10 17:51 ` [PATCH v2 1/2] s390x/pci: bypass vfio DMA counting when using cdev Matthew Rosato
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Matthew Rosato @ 2023-11-10 17:51 UTC (permalink / raw)
  To: qemu-s390x
  Cc: farman, thuth, clg, pasic, borntraeger, richard.henderson, david,
	iii, qemu-devel

The following set of changes are associated with issues exposed by testing
of the 'vfio: Adopt iommufd' series.

The first patch fixes an existing assumption that a vfio device will always
have a group fd (which is no longer true if cdev is used, which can only
happen once the iommufd backend is used).  This patch really only needs to
go into 8.2 if the 'vfio: Adopt iommufd' series does (but would be fine to 
go into 8.2 without it too).

The second patch fixes an issue where we do not detect that a vfio DMA limit
was never read from vfio.  This is actually an existing bug as it's possible
for an older host kernel to be missing this support today; so ideally this one
should be targeted for 8.2 regardless. 

Changes for v2:
- minor style changes (Phil, Thomas)

Matthew Rosato (2):
  s390x/pci: bypass vfio DMA counting when using cdev
  s390x/pci: only limit DMA aperture if vfio DMA limit reported

 hw/s390x/s390-pci-vfio.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

-- 
2.41.0



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

* [PATCH v2 1/2] s390x/pci: bypass vfio DMA counting when using cdev
  2023-11-10 17:51 [PATCH v2 0/2] s390x/pci: small set of fixes Matthew Rosato
@ 2023-11-10 17:51 ` Matthew Rosato
  2023-11-10 17:51 ` [PATCH v2 2/2] s390x/pci: only limit DMA aperture if vfio DMA limit reported Matthew Rosato
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Matthew Rosato @ 2023-11-10 17:51 UTC (permalink / raw)
  To: qemu-s390x
  Cc: farman, thuth, clg, pasic, borntraeger, richard.henderson, david,
	iii, qemu-devel

The current code assumes that there is always a vfio group, but
that's no longer guaranteed with the iommufd backend when using
cdev.  In this case, we don't need to track the vfio dma limit
anyway.

Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
---
 hw/s390x/s390-pci-vfio.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/hw/s390x/s390-pci-vfio.c b/hw/s390x/s390-pci-vfio.c
index 59a2e03873..e28573b593 100644
--- a/hw/s390x/s390-pci-vfio.c
+++ b/hw/s390x/s390-pci-vfio.c
@@ -66,6 +66,10 @@ S390PCIDMACount *s390_pci_start_dma_count(S390pciState *s,
 
     assert(vpdev);
 
+    if (!vpdev->vbasedev.group) {
+        return NULL;
+    }
+
     id = vpdev->vbasedev.group->container->fd;
 
     if (!s390_pci_update_dma_avail(id, &avail)) {
-- 
2.41.0



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

* [PATCH v2 2/2] s390x/pci: only limit DMA aperture if vfio DMA limit reported
  2023-11-10 17:51 [PATCH v2 0/2] s390x/pci: small set of fixes Matthew Rosato
  2023-11-10 17:51 ` [PATCH v2 1/2] s390x/pci: bypass vfio DMA counting when using cdev Matthew Rosato
@ 2023-11-10 17:51 ` Matthew Rosato
  2023-11-13 21:24   ` Michael Tokarev
  2023-11-13  6:29 ` [PATCH v2 0/2] s390x/pci: small set of fixes Thomas Huth
  2023-11-13 14:49 ` Eric Farman
  3 siblings, 1 reply; 7+ messages in thread
From: Matthew Rosato @ 2023-11-10 17:51 UTC (permalink / raw)
  To: qemu-s390x
  Cc: farman, thuth, clg, pasic, borntraeger, richard.henderson, david,
	iii, qemu-devel

If the host kernel lacks vfio DMA limit reporting, do not attempt
to shrink the guest DMA aperture.

Fixes: df202e3ff3 ("s390x/pci: shrink DMA aperture to be bound by vfio DMA limit")
Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
---
 hw/s390x/s390-pci-vfio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/s390x/s390-pci-vfio.c b/hw/s390x/s390-pci-vfio.c
index e28573b593..7dbbc76823 100644
--- a/hw/s390x/s390-pci-vfio.c
+++ b/hw/s390x/s390-pci-vfio.c
@@ -136,7 +136,7 @@ static void s390_pci_read_base(S390PCIBusDevice *pbdev,
      * to the guest based upon the vfio DMA limit.
      */
     vfio_size = pbdev->iommu->max_dma_limit << TARGET_PAGE_BITS;
-    if (vfio_size < (cap->end_dma - cap->start_dma + 1)) {
+    if (vfio_size > 0 && vfio_size < cap->end_dma - cap->start_dma + 1) {
         pbdev->zpci_fn.edma = cap->start_dma + vfio_size - 1;
     }
 }
-- 
2.41.0



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

* Re: [PATCH v2 0/2] s390x/pci: small set of fixes
  2023-11-10 17:51 [PATCH v2 0/2] s390x/pci: small set of fixes Matthew Rosato
  2023-11-10 17:51 ` [PATCH v2 1/2] s390x/pci: bypass vfio DMA counting when using cdev Matthew Rosato
  2023-11-10 17:51 ` [PATCH v2 2/2] s390x/pci: only limit DMA aperture if vfio DMA limit reported Matthew Rosato
@ 2023-11-13  6:29 ` Thomas Huth
  2023-11-13 14:49 ` Eric Farman
  3 siblings, 0 replies; 7+ messages in thread
From: Thomas Huth @ 2023-11-13  6:29 UTC (permalink / raw)
  To: Matthew Rosato, qemu-s390x
  Cc: farman, clg, pasic, borntraeger, richard.henderson, david, iii,
	qemu-devel

On 10/11/2023 18.51, Matthew Rosato wrote:
> The following set of changes are associated with issues exposed by testing
> of the 'vfio: Adopt iommufd' series.
> 
> The first patch fixes an existing assumption that a vfio device will always
> have a group fd (which is no longer true if cdev is used, which can only
> happen once the iommufd backend is used).  This patch really only needs to
> go into 8.2 if the 'vfio: Adopt iommufd' series does (but would be fine to
> go into 8.2 without it too).
> 
> The second patch fixes an issue where we do not detect that a vfio DMA limit
> was never read from vfio.  This is actually an existing bug as it's possible
> for an older host kernel to be missing this support today; so ideally this one
> should be targeted for 8.2 regardless.
> 
> Changes for v2:
> - minor style changes (Phil, Thomas)
> 
> Matthew Rosato (2):
>    s390x/pci: bypass vfio DMA counting when using cdev
>    s390x/pci: only limit DMA aperture if vfio DMA limit reported
> 
>   hw/s390x/s390-pci-vfio.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)

Thank you, queued them now!

  Thomas



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

* Re: [PATCH v2 0/2] s390x/pci: small set of fixes
  2023-11-10 17:51 [PATCH v2 0/2] s390x/pci: small set of fixes Matthew Rosato
                   ` (2 preceding siblings ...)
  2023-11-13  6:29 ` [PATCH v2 0/2] s390x/pci: small set of fixes Thomas Huth
@ 2023-11-13 14:49 ` Eric Farman
  3 siblings, 0 replies; 7+ messages in thread
From: Eric Farman @ 2023-11-13 14:49 UTC (permalink / raw)
  To: Matthew Rosato, qemu-s390x
  Cc: thuth, clg, pasic, borntraeger, richard.henderson, david, iii,
	qemu-devel

On Fri, 2023-11-10 at 12:51 -0500, Matthew Rosato wrote:
> The following set of changes are associated with issues exposed by
> testing
> of the 'vfio: Adopt iommufd' series.

...snip...

> Matthew Rosato (2):
>   s390x/pci: bypass vfio DMA counting when using cdev
>   s390x/pci: only limit DMA aperture if vfio DMA limit reported
> 
>  hw/s390x/s390-pci-vfio.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 

Apologies for missing v1 while I was out, but FWIW, for the series:

Reviewed-by: Eric Farman <farman@linux.ibm.com>


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

* Re: [PATCH v2 2/2] s390x/pci: only limit DMA aperture if vfio DMA limit reported
  2023-11-10 17:51 ` [PATCH v2 2/2] s390x/pci: only limit DMA aperture if vfio DMA limit reported Matthew Rosato
@ 2023-11-13 21:24   ` Michael Tokarev
  2023-11-13 21:49     ` Matthew Rosato
  0 siblings, 1 reply; 7+ messages in thread
From: Michael Tokarev @ 2023-11-13 21:24 UTC (permalink / raw)
  To: Matthew Rosato, qemu-s390x; +Cc: qemu-devel

10.11.2023 20:51, Matthew Rosato wrote:
> If the host kernel lacks vfio DMA limit reporting, do not attempt
> to shrink the guest DMA aperture.
> 
> Fixes: df202e3ff3 ("s390x/pci: shrink DMA aperture to be bound by vfio DMA limit")
> Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>

Is this stable-8.1 material?

Thanks,

/mjt

> ---
>   hw/s390x/s390-pci-vfio.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/s390x/s390-pci-vfio.c b/hw/s390x/s390-pci-vfio.c
> index e28573b593..7dbbc76823 100644
> --- a/hw/s390x/s390-pci-vfio.c
> +++ b/hw/s390x/s390-pci-vfio.c
> @@ -136,7 +136,7 @@ static void s390_pci_read_base(S390PCIBusDevice *pbdev,
>        * to the guest based upon the vfio DMA limit.
>        */
>       vfio_size = pbdev->iommu->max_dma_limit << TARGET_PAGE_BITS;
> -    if (vfio_size < (cap->end_dma - cap->start_dma + 1)) {
> +    if (vfio_size > 0 && vfio_size < cap->end_dma - cap->start_dma + 1) {
>           pbdev->zpci_fn.edma = cap->start_dma + vfio_size - 1;
>       }
>   }



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

* Re: [PATCH v2 2/2] s390x/pci: only limit DMA aperture if vfio DMA limit reported
  2023-11-13 21:24   ` Michael Tokarev
@ 2023-11-13 21:49     ` Matthew Rosato
  0 siblings, 0 replies; 7+ messages in thread
From: Matthew Rosato @ 2023-11-13 21:49 UTC (permalink / raw)
  To: Michael Tokarev, qemu-s390x; +Cc: qemu-devel

On 11/13/23 4:24 PM, Michael Tokarev wrote:
> 10.11.2023 20:51, Matthew Rosato wrote:
>> If the host kernel lacks vfio DMA limit reporting, do not attempt
>> to shrink the guest DMA aperture.
>>
>> Fixes: df202e3ff3 ("s390x/pci: shrink DMA aperture to be bound by vfio DMA limit")
>> Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
> 
> Is this stable-8.1 material?
> 
> Thanks,
> 
> /mjt
> 

Yes, I believe it is (sorry, should have added CC stable)

If you have a host kernel that doesn't report the vfio DMA limit the resulting PCI device will be rendered unusable in the s390x guest due this bug.

Thanks,
Matt


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

end of thread, other threads:[~2023-11-13 21:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-10 17:51 [PATCH v2 0/2] s390x/pci: small set of fixes Matthew Rosato
2023-11-10 17:51 ` [PATCH v2 1/2] s390x/pci: bypass vfio DMA counting when using cdev Matthew Rosato
2023-11-10 17:51 ` [PATCH v2 2/2] s390x/pci: only limit DMA aperture if vfio DMA limit reported Matthew Rosato
2023-11-13 21:24   ` Michael Tokarev
2023-11-13 21:49     ` Matthew Rosato
2023-11-13  6:29 ` [PATCH v2 0/2] s390x/pci: small set of fixes Thomas Huth
2023-11-13 14:49 ` Eric Farman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).