linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] swiotlb: save io_tlb_used to local variable before leaving critical section
@ 2019-04-12 11:38 Dongli Zhang
  2019-04-12 14:13 ` Joe Jin
  0 siblings, 1 reply; 4+ messages in thread
From: Dongli Zhang @ 2019-04-12 11:38 UTC (permalink / raw)
  To: iommu, konrad.wilk
  Cc: linux-kernel, hch, m.szyprowski, robin.murphy, joe.jin,
	haakon.bugge, dongli.zhang

When swiotlb is full, the kernel would print io_tlb_used. However, the
result might be inaccurate at that time because we have left the critical
section protected by spinlock.

Therefore, we backup the io_tlb_used into local variable before leaving
critical section.

Fixes: 83ca25948940 ("swiotlb: dump used and total slots when swiotlb buffer is full")
Suggested-by: Håkon Bugge <haakon.bugge@oracle.com>
Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
---
 kernel/dma/swiotlb.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 857e823..6f7619c 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -452,6 +452,7 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev,
 	unsigned long mask;
 	unsigned long offset_slots;
 	unsigned long max_slots;
+	unsigned long tmp_io_tlb_used;
 
 	if (no_iotlb_memory)
 		panic("Can not allocate SWIOTLB buffer earlier and can't now provide you with the DMA bounce buffer");
@@ -538,10 +539,12 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev,
 	} while (index != wrap);
 
 not_found:
+	tmp_io_tlb_used = io_tlb_used;
+
 	spin_unlock_irqrestore(&io_tlb_lock, flags);
 	if (!(attrs & DMA_ATTR_NO_WARN) && printk_ratelimit())
-		dev_warn(hwdev, "swiotlb buffer is full (sz: %zd bytes), total %lu, used %lu\n",
-			 size, io_tlb_nslabs, io_tlb_used);
+		dev_warn(hwdev, "swiotlb buffer is full (sz: %zd bytes), total %lu (slots), used %lu (slots)\n",
+			 size, io_tlb_nslabs, tmp_io_tlb_used);
 	return DMA_MAPPING_ERROR;
 found:
 	io_tlb_used += nslots;
-- 
2.7.4


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

* Re: [PATCH 1/1] swiotlb: save io_tlb_used to local variable before leaving critical section
  2019-04-12 11:38 [PATCH 1/1] swiotlb: save io_tlb_used to local variable before leaving critical section Dongli Zhang
@ 2019-04-12 14:13 ` Joe Jin
  2019-04-15  6:50   ` Dongli Zhang
  0 siblings, 1 reply; 4+ messages in thread
From: Joe Jin @ 2019-04-12 14:13 UTC (permalink / raw)
  To: Dongli Zhang, iommu, konrad.wilk
  Cc: linux-kernel, hch, m.szyprowski, robin.murphy, haakon.bugge

I'm good to have this patch, which helps identify the cause of failure is
fragmentation or it really been used up.

On 4/12/19 4:38 AM, Dongli Zhang wrote:
> When swiotlb is full, the kernel would print io_tlb_used. However, the
> result might be inaccurate at that time because we have left the critical
> section protected by spinlock.
> 
> Therefore, we backup the io_tlb_used into local variable before leaving
> critical section.
> 
> Fixes: 83ca25948940 ("swiotlb: dump used and total slots when swiotlb buffer is full")
> Suggested-by: Håkon Bugge <haakon.bugge@oracle.com>
> Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>

Reviewed-by: Joe Jin <joe.jin@oracle.com> 

Thanks,
Joe


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

* Re: [PATCH 1/1] swiotlb: save io_tlb_used to local variable before leaving critical section
  2019-04-12 14:13 ` Joe Jin
@ 2019-04-15  6:50   ` Dongli Zhang
       [not found]     ` <CAPbh3rvyVd_D9tMfE-Bo2JmdabaiQnaipmmadc67tUt_Lrt2gw@mail.gmail.com>
  0 siblings, 1 reply; 4+ messages in thread
From: Dongli Zhang @ 2019-04-15  6:50 UTC (permalink / raw)
  To: Joe Jin, iommu, konrad.wilk
  Cc: linux-kernel, hch, m.szyprowski, robin.murphy, haakon.bugge

As the patch to be fixed is still in Konrad's own tree, I will send the v2 for
the patch to be fixed, instead of an incremental fix.

Dongli Zhang

On 4/12/19 10:13 PM, Joe Jin wrote:
> I'm good to have this patch, which helps identify the cause of failure is
> fragmentation or it really been used up.
> 
> On 4/12/19 4:38 AM, Dongli Zhang wrote:
>> When swiotlb is full, the kernel would print io_tlb_used. However, the
>> result might be inaccurate at that time because we have left the critical
>> section protected by spinlock.
>>
>> Therefore, we backup the io_tlb_used into local variable before leaving
>> critical section.
>>
>> Fixes: 83ca25948940 ("swiotlb: dump used and total slots when swiotlb buffer is full")
>> Suggested-by: Håkon Bugge <haakon.bugge@oracle.com>
>> Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
> 
> Reviewed-by: Joe Jin <joe.jin@oracle.com> 
> 
> Thanks,
> Joe
> 

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

* Re: [PATCH 1/1] swiotlb: save io_tlb_used to local variable before leaving critical section
       [not found]     ` <CAPbh3rvyVd_D9tMfE-Bo2JmdabaiQnaipmmadc67tUt_Lrt2gw@mail.gmail.com>
@ 2019-04-15 12:08       ` Dongli Zhang
  0 siblings, 0 replies; 4+ messages in thread
From: Dongli Zhang @ 2019-04-15 12:08 UTC (permalink / raw)
  To: konrad
  Cc: joe.jin, iommu, konrad.wilk, haakon.bugge, robin.murphy,
	linux-kernel, hch



On 04/15/2019 07:26 PM, Konrad Rzeszutek Wilk wrote:
> 
> 
> On Mon, Apr 15, 2019, 2:50 AM Dongli Zhang <dongli.zhang@oracle.com
> <mailto:dongli.zhang@oracle.com>> wrote:
> 
>     As the patch to be fixed is still in Konrad's own tree, I will send the v2 for
>     the patch to be fixed, instead of an incremental fix.
> 
> 
> I squashed it in.

Thank you very much!

I saw it is at:

https://git.kernel.org/pub/scm/linux/kernel/git/konrad/swiotlb.git/commit/?h=devel/for-linus-5.1&id=53b29c336830db48ad3dc737f88b8c065b1f0851

Dongli Zhang

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

end of thread, other threads:[~2019-04-15 12:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-12 11:38 [PATCH 1/1] swiotlb: save io_tlb_used to local variable before leaving critical section Dongli Zhang
2019-04-12 14:13 ` Joe Jin
2019-04-15  6:50   ` Dongli Zhang
     [not found]     ` <CAPbh3rvyVd_D9tMfE-Bo2JmdabaiQnaipmmadc67tUt_Lrt2gw@mail.gmail.com>
2019-04-15 12:08       ` Dongli Zhang

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).