* Re: [PATCH] swiotlb: Do not set total_used to 0 in swiotlb_create_debugfs_files()
2024-03-29 19:28 [PATCH] swiotlb: Do not set total_used to 0 in swiotlb_create_debugfs_files() Dexuan Cui
@ 2024-03-29 19:46 ` Easwar Hariharan
2024-03-29 20:23 ` Dexuan Cui
2024-03-29 22:59 ` Michael Kelley
` (3 subsequent siblings)
4 siblings, 1 reply; 9+ messages in thread
From: Easwar Hariharan @ 2024-03-29 19:46 UTC (permalink / raw)
To: Dexuan Cui, hch, m.szyprowski, robin.murphy, zhangpeng362, iommu,
mhklinux
Cc: linux-kernel, stable
On 3/29/2024 12:28 PM, Dexuan Cui wrote:
> Sometimes the readout of /sys/kernel/debug/swiotlb/io_tlb_used and
> io_tlb_used_hiwater can be a huge number (e.g. 18446744073709551615),
> which is actually a negative number if we use "%ld" to print the number.
>
> When swiotlb_create_default_debugfs() is running from late_initcall,
> mem->total_used may already be non-zero, because the storage driver
> may have already started to perform I/O operations: if the storage
> driver is built-in, its probe() callback is called before late_initcall.
>
> swiotlb_create_debugfs_files() should not blindly set mem->total_used
> and mem->used_hiwater to 0; actually it doesn't have to initialize the
> fields at all, because the fields, as part of the global struct
> io_tlb_default_mem, have been implicitly initialized to zero.
>
> Also don't explicitly set mem->transient_nslabs to 0.
>
> Fixes: 8b0977ecc8b3 ("swiotlb: track and report io_tlb_used high water marks in debugfs")
> Fixes: 02e765697038 ("swiotlb: add debugfs to track swiotlb transient pool usage")
> Cc: stable@vger.kernel.org
> Signed-off-by: Dexuan Cui <decui@microsoft.com>
> ---
> kernel/dma/swiotlb.c | 4 ----
> 1 file changed, 4 deletions(-)
>
Sorry, I'm missing a why in this commit message. Can you say what happens if the
total_used and used_hiwater IS blindly set to 0? Is the only effect the change in
the readout of the swiotlb debugfs files?
Thanks,
Easwar
^ permalink raw reply [flat|nested] 9+ messages in thread* RE: [PATCH] swiotlb: Do not set total_used to 0 in swiotlb_create_debugfs_files()
2024-03-29 19:46 ` Easwar Hariharan
@ 2024-03-29 20:23 ` Dexuan Cui
2024-03-29 20:30 ` Dexuan Cui
0 siblings, 1 reply; 9+ messages in thread
From: Dexuan Cui @ 2024-03-29 20:23 UTC (permalink / raw)
To: Easwar Hariharan, hch@lst.de, m.szyprowski@samsung.com,
robin.murphy@arm.com, zhangpeng362@huawei.com,
iommu@lists.linux.dev, mhklinux@outlook.com
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org
> From: Easwar Hariharan <eahariha@linux.microsoft.com>
> Sent: Friday, March 29, 2024 12:47 PM
> [...]
> Sorry, I'm missing a why in this commit message. Can you say what happens
> if the total_used and used_hiwater IS blindly set to 0? Is the only effect
> the change in the readout of the swiotlb debugfs files?
>
> Thanks,
> Easwar
Right, when the system is not doing any I/O, the readout may
return a huge number while it should return 0. This is the only effect.
Thanks,
Dexuan
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: [PATCH] swiotlb: Do not set total_used to 0 in swiotlb_create_debugfs_files()
2024-03-29 20:23 ` Dexuan Cui
@ 2024-03-29 20:30 ` Dexuan Cui
2024-03-29 20:42 ` Easwar Hariharan
0 siblings, 1 reply; 9+ messages in thread
From: Dexuan Cui @ 2024-03-29 20:30 UTC (permalink / raw)
To: Easwar Hariharan, hch@lst.de, m.szyprowski@samsung.com,
robin.murphy@arm.com, zhangpeng362@huawei.com,
iommu@lists.linux.dev, mhklinux@outlook.com
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org
> From: Dexuan Cui
> Sent: Friday, March 29, 2024 1:23 PM
> To: Easwar Hariharan <eahariha@linux.microsoft.com>; hch@lst.de;
> m.szyprowski@samsung.com; robin.murphy@arm.com;
> zhangpeng362@huawei.com; iommu@lists.linux.dev;
> mhklinux@outlook.com
> Cc: linux-kernel@vger.kernel.org; stable@vger.kernel.org
> Subject: RE: [PATCH] swiotlb: Do not set total_used to 0 in
> swiotlb_create_debugfs_files()
>
> > From: Easwar Hariharan <eahariha@linux.microsoft.com>
> > Sent: Friday, March 29, 2024 12:47 PM
> > [...]
> > Sorry, I'm missing a why in this commit message. Can you say what
> happens
> > if the total_used and used_hiwater IS blindly set to 0? Is the only effect
> > the change in the readout of the swiotlb debugfs files?
> >
> > Thanks,
> > Easwar
>
> Right, when the system is not doing any I/O, the readout may
> return a huge number while it should return 0. This is the only effect.
>
> Thanks,
> Dexuan
Let me share more details.
kernel/dma/swiotlb.c uses inc_used_and_hiwater() and dec_used()
to do the accounting.
The issue happens this way:
1. inc_used_and_hiwater() adds n to total_used.
2. swiotlb_create_debugfs_files() sets total_used to 0.
3. dec_used() decreases total_used by n, i.e. total_used incorrectly
becomes a negative number -n, which is a huge number since
mem_used() converts the 'long' to 'unsigned long'.
Thanks,
Dexuan
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] swiotlb: Do not set total_used to 0 in swiotlb_create_debugfs_files()
2024-03-29 20:30 ` Dexuan Cui
@ 2024-03-29 20:42 ` Easwar Hariharan
0 siblings, 0 replies; 9+ messages in thread
From: Easwar Hariharan @ 2024-03-29 20:42 UTC (permalink / raw)
To: Dexuan Cui, hch@lst.de, m.szyprowski@samsung.com,
robin.murphy@arm.com, zhangpeng362@huawei.com,
iommu@lists.linux.dev, mhklinux@outlook.com
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org
On 3/29/2024 1:30 PM, Dexuan Cui wrote:
>> From: Dexuan Cui
>> Sent: Friday, March 29, 2024 1:23 PM
>> To: Easwar Hariharan <eahariha@linux.microsoft.com>; hch@lst.de;
>> m.szyprowski@samsung.com; robin.murphy@arm.com;
>> zhangpeng362@huawei.com; iommu@lists.linux.dev;
>> mhklinux@outlook.com
>> Cc: linux-kernel@vger.kernel.org; stable@vger.kernel.org
>> Subject: RE: [PATCH] swiotlb: Do not set total_used to 0 in
>> swiotlb_create_debugfs_files()
>>
>>> From: Easwar Hariharan <eahariha@linux.microsoft.com>
>>> Sent: Friday, March 29, 2024 12:47 PM
>>> [...]
>>> Sorry, I'm missing a why in this commit message. Can you say what
>> happens
>>> if the total_used and used_hiwater IS blindly set to 0? Is the only effect
>>> the change in the readout of the swiotlb debugfs files?
>>>
>>> Thanks,
>>> Easwar
>>
>> Right, when the system is not doing any I/O, the readout may
>> return a huge number while it should return 0. This is the only effect.
>>
>> Thanks,
>> Dexuan
>
> Let me share more details.
>
> kernel/dma/swiotlb.c uses inc_used_and_hiwater() and dec_used()
> to do the accounting.
>
> The issue happens this way:
>
> 1. inc_used_and_hiwater() adds n to total_used.
> 2. swiotlb_create_debugfs_files() sets total_used to 0.
> 3. dec_used() decreases total_used by n, i.e. total_used incorrectly
> becomes a negative number -n, which is a huge number since
> mem_used() converts the 'long' to 'unsigned long'.
>
> Thanks,
> Dexuan
>
Thanks for the detail. I only ask because the patch is marked for stable, and
I was wondering if it meets the criteria. But, as you mentioned off list, two Fixes
tags probably do meet the bar.
Thanks,
Easwar
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: [PATCH] swiotlb: Do not set total_used to 0 in swiotlb_create_debugfs_files()
2024-03-29 19:28 [PATCH] swiotlb: Do not set total_used to 0 in swiotlb_create_debugfs_files() Dexuan Cui
2024-03-29 19:46 ` Easwar Hariharan
@ 2024-03-29 22:59 ` Michael Kelley
2024-03-30 1:19 ` zhangpeng (AS)
` (2 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Michael Kelley @ 2024-03-29 22:59 UTC (permalink / raw)
To: Dexuan Cui, hch@lst.de, m.szyprowski@samsung.com,
robin.murphy@arm.com, zhangpeng362@huawei.com,
iommu@lists.linux.dev
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org
From: Dexuan Cui <decui@microsoft.com> Sent: Friday, March 29, 2024 12:28 PM
>
> Sometimes the readout of /sys/kernel/debug/swiotlb/io_tlb_used and
> io_tlb_used_hiwater can be a huge number (e.g. 18446744073709551615),
> which is actually a negative number if we use "%ld" to print the number.
>
> When swiotlb_create_default_debugfs() is running from late_initcall,
> mem->total_used may already be non-zero, because the storage driver
> may have already started to perform I/O operations: if the storage
> driver is built-in, its probe() callback is called before late_initcall.
>
> swiotlb_create_debugfs_files() should not blindly set mem->total_used
> and mem->used_hiwater to 0; actually it doesn't have to initialize the
> fields at all, because the fields, as part of the global struct
> io_tlb_default_mem, have been implicitly initialized to zero.
>
> Also don't explicitly set mem->transient_nslabs to 0.
>
> Fixes: 8b0977ecc8b3 ("swiotlb: track and report io_tlb_used high water marks in debugfs")
> Fixes: 02e765697038 ("swiotlb: add debugfs to track swiotlb transient pool usage")
> Cc: stable@vger.kernel.org
> Signed-off-by: Dexuan Cui <decui@microsoft.com>
> ---
> kernel/dma/swiotlb.c | 4 ----
> 1 file changed, 4 deletions(-)
>
> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index 86fe172b5958..4a9f02c13da6 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -1647,9 +1647,6 @@
> DEFINE_DEBUGFS_ATTRIBUTE(fops_io_tlb_hiwater, io_tlb_hiwater_get,
> static void swiotlb_create_debugfs_files(struct io_tlb_mem *mem,
> const char *dirname)
> {
> - atomic_long_set(&mem->total_used, 0);
> - atomic_long_set(&mem->used_hiwater, 0);
> -
> mem->debugfs = debugfs_create_dir(dirname, io_tlb_default_mem.debugfs);
> if (!mem->nslabs)
> return;
> @@ -1660,7 +1657,6 @@ static void swiotlb_create_debugfs_files(struct io_tlb_mem *mem,
> debugfs_create_file("io_tlb_used_hiwater", 0600, mem->debugfs, mem,
> &fops_io_tlb_hiwater);
> #ifdef CONFIG_SWIOTLB_DYNAMIC
> - atomic_long_set(&mem->transient_nslabs, 0);
> debugfs_create_file("io_tlb_transient_nslabs", 0400, mem->debugfs,
> mem, &fops_io_tlb_transient_used);
> #endif
> --
> 2.34.1
Reviewed-by: Michael Kelley <mhklinux@outlook.com>
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH] swiotlb: Do not set total_used to 0 in swiotlb_create_debugfs_files()
2024-03-29 19:28 [PATCH] swiotlb: Do not set total_used to 0 in swiotlb_create_debugfs_files() Dexuan Cui
2024-03-29 19:46 ` Easwar Hariharan
2024-03-29 22:59 ` Michael Kelley
@ 2024-03-30 1:19 ` zhangpeng (AS)
2024-03-30 8:25 ` Petr Tesařík
2024-04-02 15:10 ` Christoph Hellwig
4 siblings, 0 replies; 9+ messages in thread
From: zhangpeng (AS) @ 2024-03-30 1:19 UTC (permalink / raw)
To: Dexuan Cui, hch, m.szyprowski, robin.murphy, iommu, mhklinux
Cc: linux-kernel, stable
On 2024/3/30 3:28, Dexuan Cui wrote:
> Sometimes the readout of /sys/kernel/debug/swiotlb/io_tlb_used and
> io_tlb_used_hiwater can be a huge number (e.g. 18446744073709551615),
> which is actually a negative number if we use "%ld" to print the number.
>
> When swiotlb_create_default_debugfs() is running from late_initcall,
> mem->total_used may already be non-zero, because the storage driver
> may have already started to perform I/O operations: if the storage
> driver is built-in, its probe() callback is called before late_initcall.
>
> swiotlb_create_debugfs_files() should not blindly set mem->total_used
> and mem->used_hiwater to 0; actually it doesn't have to initialize the
> fields at all, because the fields, as part of the global struct
> io_tlb_default_mem, have been implicitly initialized to zero.
>
> Also don't explicitly set mem->transient_nslabs to 0.
>
> Fixes: 8b0977ecc8b3 ("swiotlb: track and report io_tlb_used high water marks in debugfs")
> Fixes: 02e765697038 ("swiotlb: add debugfs to track swiotlb transient pool usage")
> Cc: stable@vger.kernel.org
> Signed-off-by: Dexuan Cui <decui@microsoft.com>
Reviewed-by: ZhangPeng<zhangpeng362@huawei.com>
--
Best Regards,
Peng
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH] swiotlb: Do not set total_used to 0 in swiotlb_create_debugfs_files()
2024-03-29 19:28 [PATCH] swiotlb: Do not set total_used to 0 in swiotlb_create_debugfs_files() Dexuan Cui
` (2 preceding siblings ...)
2024-03-30 1:19 ` zhangpeng (AS)
@ 2024-03-30 8:25 ` Petr Tesařík
2024-04-02 15:10 ` Christoph Hellwig
4 siblings, 0 replies; 9+ messages in thread
From: Petr Tesařík @ 2024-03-30 8:25 UTC (permalink / raw)
To: Dexuan Cui
Cc: hch, m.szyprowski, robin.murphy, zhangpeng362, iommu, mhklinux,
linux-kernel, stable
V Fri, 29 Mar 2024 12:28:09 -0700
Dexuan Cui <decui@microsoft.com> napsáno:
> Sometimes the readout of /sys/kernel/debug/swiotlb/io_tlb_used and
> io_tlb_used_hiwater can be a huge number (e.g. 18446744073709551615),
> which is actually a negative number if we use "%ld" to print the number.
>
> When swiotlb_create_default_debugfs() is running from late_initcall,
> mem->total_used may already be non-zero, because the storage driver
> may have already started to perform I/O operations: if the storage
> driver is built-in, its probe() callback is called before late_initcall.
>
> swiotlb_create_debugfs_files() should not blindly set mem->total_used
> and mem->used_hiwater to 0; actually it doesn't have to initialize the
> fields at all, because the fields, as part of the global struct
> io_tlb_default_mem, have been implicitly initialized to zero.
>
> Also don't explicitly set mem->transient_nslabs to 0.
>
> Fixes: 8b0977ecc8b3 ("swiotlb: track and report io_tlb_used high water marks in debugfs")
> Fixes: 02e765697038 ("swiotlb: add debugfs to track swiotlb transient pool usage")
> Cc: stable@vger.kernel.org
> Signed-off-by: Dexuan Cui <decui@microsoft.com>
FWIW I confirm that the transient_nslabs counter does not have to be
initialized either.
Reviewed-by: Petr Tesarik <petr.tesarik1@huawei-partners.com>
Petr T
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH] swiotlb: Do not set total_used to 0 in swiotlb_create_debugfs_files()
2024-03-29 19:28 [PATCH] swiotlb: Do not set total_used to 0 in swiotlb_create_debugfs_files() Dexuan Cui
` (3 preceding siblings ...)
2024-03-30 8:25 ` Petr Tesařík
@ 2024-04-02 15:10 ` Christoph Hellwig
4 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2024-04-02 15:10 UTC (permalink / raw)
To: Dexuan Cui
Cc: hch, m.szyprowski, robin.murphy, zhangpeng362, iommu, mhklinux,
linux-kernel, stable
Thanks,
applied to the dma-mapping tree for Linux 6.9-rc.
^ permalink raw reply [flat|nested] 9+ messages in thread