All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] s390/pci: Fix reset of IOMMU software counters
@ 2023-10-04  8:56 Niklas Schnelle
  2023-10-04 15:24 ` Matthew Rosato
  2023-10-05 11:01 ` Joerg Roedel
  0 siblings, 2 replies; 3+ messages in thread
From: Niklas Schnelle @ 2023-10-04  8:56 UTC (permalink / raw)
  To: Robin Murphy, Matthew Rosato, Gerd Bayer, Heiko Carstens,
	Vasily Gorbik, Alexander Gordeev, Christian Borntraeger,
	Sven Schnelle, Gerald Schaefer, Joerg Roedel
  Cc: linux-s390, linux-kernel, iommu, Niklas Schnelle

Together with enabling the Function Measurement Block
zpci_fmb_enable_device() also resets the software counters. This allows
to use "echo 0 > /sys/kernel/debug/pci/<dev>/statistics" followed by
echo "1 > /../statistics" to reset all counters. In commit c76c067e488c
("s390/pci: Use dma-iommu layer") this use of the now obsolete counters
in struct zpci_device was missed as was their removal. Fix this by
resetting the new counters and removing the old ones.

Fixes: c76c067e488c ("s390/pci: Use dma-iommu layer")
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
---
Note: This is based on and references commit IDs from Joerg Roedel's
iommu/next branch and should go in via the iommu tree.
---
 arch/s390/include/asm/pci.h |  4 ----
 arch/s390/pci/pci.c         | 13 ++++++++++---
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/arch/s390/include/asm/pci.h b/arch/s390/include/asm/pci.h
index 3f74f1cf37df..e91cd6bbc330 100644
--- a/arch/s390/include/asm/pci.h
+++ b/arch/s390/include/asm/pci.h
@@ -173,10 +173,6 @@ struct zpci_dev {
 	struct zpci_fmb *fmb;
 	u16		fmb_update;	/* update interval */
 	u16		fmb_length;
-	/* software counters */
-	atomic64_t allocated_pages;
-	atomic64_t mapped_pages;
-	atomic64_t unmapped_pages;
 
 	u8		version;
 	enum pci_bus_speed max_bus_speed;
diff --git a/arch/s390/pci/pci.c b/arch/s390/pci/pci.c
index 563cb72d9ed0..63fd9e1d9f22 100644
--- a/arch/s390/pci/pci.c
+++ b/arch/s390/pci/pci.c
@@ -157,6 +157,7 @@ int zpci_unregister_ioat(struct zpci_dev *zdev, u8 dmaas)
 int zpci_fmb_enable_device(struct zpci_dev *zdev)
 {
 	u64 req = ZPCI_CREATE_REQ(zdev->fh, 0, ZPCI_MOD_FC_SET_MEASURE);
+	struct zpci_iommu_ctrs *ctrs;
 	struct zpci_fib fib = {0};
 	u8 cc, status;
 
@@ -169,9 +170,15 @@ int zpci_fmb_enable_device(struct zpci_dev *zdev)
 	WARN_ON((u64) zdev->fmb & 0xf);
 
 	/* reset software counters */
-	atomic64_set(&zdev->allocated_pages, 0);
-	atomic64_set(&zdev->mapped_pages, 0);
-	atomic64_set(&zdev->unmapped_pages, 0);
+	ctrs = zpci_get_iommu_ctrs(zdev);
+	if (ctrs) {
+		atomic64_set(&ctrs->mapped_pages, 0);
+		atomic64_set(&ctrs->unmapped_pages, 0);
+		atomic64_set(&ctrs->global_rpcits, 0);
+		atomic64_set(&ctrs->sync_map_rpcits, 0);
+		atomic64_set(&ctrs->sync_rpcits, 0);
+	}
+
 
 	fib.fmb_addr = virt_to_phys(zdev->fmb);
 	fib.gd = zdev->gisa;

---
base-commit: 8e5ab3f54a1061c2be3e1fbcda01fbe604c3450e
change-id: 20231002-dma_iommu_fix-0a5397992f15

Best regards,
-- 
Niklas Schnelle
Linux on Z Development

IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Gregor Pillen
Geschäftsführung: David Faller
Sitz der Gesellschaft: Böblingen / Registergericht: Amtsgericht Stuttgart, HRB 243294
IBM Data Privacy Statement - https://www.ibm.com/privacy 


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

* Re: [PATCH] s390/pci: Fix reset of IOMMU software counters
  2023-10-04  8:56 [PATCH] s390/pci: Fix reset of IOMMU software counters Niklas Schnelle
@ 2023-10-04 15:24 ` Matthew Rosato
  2023-10-05 11:01 ` Joerg Roedel
  1 sibling, 0 replies; 3+ messages in thread
From: Matthew Rosato @ 2023-10-04 15:24 UTC (permalink / raw)
  To: Niklas Schnelle, Robin Murphy, Gerd Bayer, Heiko Carstens,
	Vasily Gorbik, Alexander Gordeev, Christian Borntraeger,
	Sven Schnelle, Gerald Schaefer, Joerg Roedel
  Cc: linux-s390, linux-kernel, iommu

On 10/4/23 4:56 AM, Niklas Schnelle wrote:
> Together with enabling the Function Measurement Block
> zpci_fmb_enable_device() also resets the software counters. This allows
> to use "echo 0 > /sys/kernel/debug/pci/<dev>/statistics" followed by
> echo "1 > /../statistics" to reset all counters. In commit c76c067e488c
> ("s390/pci: Use dma-iommu layer") this use of the now obsolete counters
> in struct zpci_device was missed as was their removal. Fix this by
> resetting the new counters and removing the old ones.
> 
> Fixes: c76c067e488c ("s390/pci: Use dma-iommu layer")
> Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>

Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com>

Verified that I could reproduce the initial issue + tested the fix using NVMe and mlx devices

> ---
> Note: This is based on and references commit IDs from Joerg Roedel's
> iommu/next branch and should go in via the iommu tree.
> ---
>  arch/s390/include/asm/pci.h |  4 ----
>  arch/s390/pci/pci.c         | 13 ++++++++++---
>  2 files changed, 10 insertions(+), 7 deletions(-)
> 
> diff --git a/arch/s390/include/asm/pci.h b/arch/s390/include/asm/pci.h
> index 3f74f1cf37df..e91cd6bbc330 100644
> --- a/arch/s390/include/asm/pci.h
> +++ b/arch/s390/include/asm/pci.h
> @@ -173,10 +173,6 @@ struct zpci_dev {
>  	struct zpci_fmb *fmb;
>  	u16		fmb_update;	/* update interval */
>  	u16		fmb_length;
> -	/* software counters */
> -	atomic64_t allocated_pages;
> -	atomic64_t mapped_pages;
> -	atomic64_t unmapped_pages;
>  
>  	u8		version;
>  	enum pci_bus_speed max_bus_speed;
> diff --git a/arch/s390/pci/pci.c b/arch/s390/pci/pci.c
> index 563cb72d9ed0..63fd9e1d9f22 100644
> --- a/arch/s390/pci/pci.c
> +++ b/arch/s390/pci/pci.c
> @@ -157,6 +157,7 @@ int zpci_unregister_ioat(struct zpci_dev *zdev, u8 dmaas)
>  int zpci_fmb_enable_device(struct zpci_dev *zdev)
>  {
>  	u64 req = ZPCI_CREATE_REQ(zdev->fh, 0, ZPCI_MOD_FC_SET_MEASURE);
> +	struct zpci_iommu_ctrs *ctrs;
>  	struct zpci_fib fib = {0};
>  	u8 cc, status;
>  
> @@ -169,9 +170,15 @@ int zpci_fmb_enable_device(struct zpci_dev *zdev)
>  	WARN_ON((u64) zdev->fmb & 0xf);
>  
>  	/* reset software counters */
> -	atomic64_set(&zdev->allocated_pages, 0);
> -	atomic64_set(&zdev->mapped_pages, 0);
> -	atomic64_set(&zdev->unmapped_pages, 0);
> +	ctrs = zpci_get_iommu_ctrs(zdev);
> +	if (ctrs) {
> +		atomic64_set(&ctrs->mapped_pages, 0);
> +		atomic64_set(&ctrs->unmapped_pages, 0);
> +		atomic64_set(&ctrs->global_rpcits, 0);
> +		atomic64_set(&ctrs->sync_map_rpcits, 0);
> +		atomic64_set(&ctrs->sync_rpcits, 0);
> +	}
> +
>  
>  	fib.fmb_addr = virt_to_phys(zdev->fmb);
>  	fib.gd = zdev->gisa;
> 
> ---
> base-commit: 8e5ab3f54a1061c2be3e1fbcda01fbe604c3450e
> change-id: 20231002-dma_iommu_fix-0a5397992f15
> 
> Best regards,


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

* Re: [PATCH] s390/pci: Fix reset of IOMMU software counters
  2023-10-04  8:56 [PATCH] s390/pci: Fix reset of IOMMU software counters Niklas Schnelle
  2023-10-04 15:24 ` Matthew Rosato
@ 2023-10-05 11:01 ` Joerg Roedel
  1 sibling, 0 replies; 3+ messages in thread
From: Joerg Roedel @ 2023-10-05 11:01 UTC (permalink / raw)
  To: Niklas Schnelle
  Cc: Robin Murphy, Matthew Rosato, Gerd Bayer, Heiko Carstens,
	Vasily Gorbik, Alexander Gordeev, Christian Borntraeger,
	Sven Schnelle, Gerald Schaefer, linux-s390, linux-kernel, iommu

On Wed, Oct 04, 2023 at 10:56:12AM +0200, Niklas Schnelle wrote:
>  arch/s390/include/asm/pci.h |  4 ----
>  arch/s390/pci/pci.c         | 13 ++++++++++---
>  2 files changed, 10 insertions(+), 7 deletions(-)

Applied, thanks.

-- 
Jörg Rödel
jroedel@suse.de

SUSE Software Solutions Germany GmbH
Frankenstraße 146
90461 Nürnberg
Germany

(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman


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

end of thread, other threads:[~2023-10-05 14:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-04  8:56 [PATCH] s390/pci: Fix reset of IOMMU software counters Niklas Schnelle
2023-10-04 15:24 ` Matthew Rosato
2023-10-05 11:01 ` Joerg Roedel

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.