* [PATCH] RDMA/hns: Use dma_alloc_coherent() instead of kmalloc/dma_map_single()
@ 2021-09-26 6:11 Cai Huoqing
2021-09-27 11:59 ` Jason Gunthorpe
2021-10-12 16:11 ` Jason Gunthorpe
0 siblings, 2 replies; 7+ messages in thread
From: Cai Huoqing @ 2021-09-26 6:11 UTC (permalink / raw)
To: caihuoqing
Cc: Lijun Ou, Weihang Li, Doug Ledford, Jason Gunthorpe, linux-rdma,
linux-kernel
Replacing kmalloc/kfree/dma_map_single/dma_unmap_single()
with dma_alloc_coherent/dma_free_coherent() helps to reduce
code size, and simplify the code, and coherent DMA will not
clear the cache every time.
Signed-off-by: Cai Huoqing <caihuoqing@baidu.com>
---
drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 20 +++++---------------
1 file changed, 5 insertions(+), 15 deletions(-)
diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
index 5b9953105752..380445f98a49 100644
--- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
+++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
@@ -1165,32 +1165,22 @@ static int hns_roce_alloc_cmq_desc(struct hns_roce_dev *hr_dev,
{
int size = ring->desc_num * sizeof(struct hns_roce_cmq_desc);
- ring->desc = kzalloc(size, GFP_KERNEL);
+ ring->desc = dma_alloc_coherent(hr_dev->dev, size,
+ &ring->desc_dma_addr, GFP_KERNEL);
if (!ring->desc)
return -ENOMEM;
- ring->desc_dma_addr = dma_map_single(hr_dev->dev, ring->desc, size,
- DMA_BIDIRECTIONAL);
- if (dma_mapping_error(hr_dev->dev, ring->desc_dma_addr)) {
- ring->desc_dma_addr = 0;
- kfree(ring->desc);
- ring->desc = NULL;
-
- return -ENOMEM;
- }
-
return 0;
}
static void hns_roce_free_cmq_desc(struct hns_roce_dev *hr_dev,
struct hns_roce_v2_cmq_ring *ring)
{
- dma_unmap_single(hr_dev->dev, ring->desc_dma_addr,
- ring->desc_num * sizeof(struct hns_roce_cmq_desc),
- DMA_BIDIRECTIONAL);
+ dma_free_coherent(hr_dev->dev,
+ ring->desc_num * sizeof(struct hns_roce_cmq_desc),
+ ring->desc, ring->desc_dma_addr);
ring->desc_dma_addr = 0;
- kfree(ring->desc);
}
static int init_csq(struct hns_roce_dev *hr_dev,
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] RDMA/hns: Use dma_alloc_coherent() instead of kmalloc/dma_map_single()
2021-09-26 6:11 [PATCH] RDMA/hns: Use dma_alloc_coherent() instead of kmalloc/dma_map_single() Cai Huoqing
@ 2021-09-27 11:59 ` Jason Gunthorpe
2021-10-04 19:52 ` Jason Gunthorpe
2021-10-12 16:11 ` Jason Gunthorpe
1 sibling, 1 reply; 7+ messages in thread
From: Jason Gunthorpe @ 2021-09-27 11:59 UTC (permalink / raw)
To: Cai Huoqing; +Cc: Lijun Ou, Weihang Li, Doug Ledford, linux-rdma, linux-kernel
On Sun, Sep 26, 2021 at 02:11:15PM +0800, Cai Huoqing wrote:
> Replacing kmalloc/kfree/dma_map_single/dma_unmap_single()
> with dma_alloc_coherent/dma_free_coherent() helps to reduce
> code size, and simplify the code, and coherent DMA will not
> clear the cache every time.
>
> Signed-off-by: Cai Huoqing <caihuoqing@baidu.com>
> ---
> drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 20 +++++---------------
> 1 file changed, 5 insertions(+), 15 deletions(-)
Given I don't see any dma_sync_single calls for this mapping, isn't
this a correctness fix too?
Jason
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] RDMA/hns: Use dma_alloc_coherent() instead of kmalloc/dma_map_single()
2021-09-27 11:59 ` Jason Gunthorpe
@ 2021-10-04 19:52 ` Jason Gunthorpe
2021-10-09 9:50 ` Wenpeng Liang
0 siblings, 1 reply; 7+ messages in thread
From: Jason Gunthorpe @ 2021-10-04 19:52 UTC (permalink / raw)
To: Cai Huoqing; +Cc: Lijun Ou, Weihang Li, Doug Ledford, linux-rdma, linux-kernel
On Mon, Sep 27, 2021 at 08:59:13AM -0300, Jason Gunthorpe wrote:
> On Sun, Sep 26, 2021 at 02:11:15PM +0800, Cai Huoqing wrote:
> > Replacing kmalloc/kfree/dma_map_single/dma_unmap_single()
> > with dma_alloc_coherent/dma_free_coherent() helps to reduce
> > code size, and simplify the code, and coherent DMA will not
> > clear the cache every time.
> >
> > Signed-off-by: Cai Huoqing <caihuoqing@baidu.com>
> > drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 20 +++++---------------
> > 1 file changed, 5 insertions(+), 15 deletions(-)
>
> Given I don't see any dma_sync_single calls for this mapping, isn't
> this a correctness fix too?
HNS folks?
Jason
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] RDMA/hns: Use dma_alloc_coherent() instead of kmalloc/dma_map_single()
2021-10-04 19:52 ` Jason Gunthorpe
@ 2021-10-09 9:50 ` Wenpeng Liang
2021-10-09 10:42 ` Cai Huoqing
0 siblings, 1 reply; 7+ messages in thread
From: Wenpeng Liang @ 2021-10-09 9:50 UTC (permalink / raw)
To: Jason Gunthorpe, Cai Huoqing
Cc: Lijun Ou, Weihang Li, Doug Ledford, linux-rdma, linux-kernel
On 2021/10/5 3:52, Jason Gunthorpe wrote:
> On Mon, Sep 27, 2021 at 08:59:13AM -0300, Jason Gunthorpe wrote:
>> On Sun, Sep 26, 2021 at 02:11:15PM +0800, Cai Huoqing wrote:
>>> Replacing kmalloc/kfree/dma_map_single/dma_unmap_single()
>>> with dma_alloc_coherent/dma_free_coherent() helps to reduce
>>> code size, and simplify the code, and coherent DMA will not
>>> clear the cache every time.
>>>
>>> Signed-off-by: Cai Huoqing <caihuoqing@baidu.com>
>>> drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 20 +++++---------------
>>> 1 file changed, 5 insertions(+), 15 deletions(-)
>>
>> Given I don't see any dma_sync_single calls for this mapping, isn't
>> this a correctness fix too?
>
> HNS folks?
>
> Jason
> .
>
Our SoC can keep cache coherent, so there is no exception even if
dma_sync_single* is not called, but the driver should not make
assumptions about SoC.
So using dma_alloc_coherent() instead of kmalloc/dma_map_single()
can simplify the code and achieve the same purpose.
Wenpeng Liang
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] RDMA/hns: Use dma_alloc_coherent() instead of kmalloc/dma_map_single()
2021-10-09 9:50 ` Wenpeng Liang
@ 2021-10-09 10:42 ` Cai Huoqing
2021-10-09 12:03 ` Wenpeng Liang
0 siblings, 1 reply; 7+ messages in thread
From: Cai Huoqing @ 2021-10-09 10:42 UTC (permalink / raw)
To: Wenpeng Liang
Cc: Jason Gunthorpe, Lijun Ou, Weihang Li, Doug Ledford, linux-rdma,
linux-kernel
On 09 10月 21 17:50:50, Wenpeng Liang wrote:
>
>
> On 2021/10/5 3:52, Jason Gunthorpe wrote:
> > On Mon, Sep 27, 2021 at 08:59:13AM -0300, Jason Gunthorpe wrote:
> >> On Sun, Sep 26, 2021 at 02:11:15PM +0800, Cai Huoqing wrote:
> >>> Replacing kmalloc/kfree/dma_map_single/dma_unmap_single()
> >>> with dma_alloc_coherent/dma_free_coherent() helps to reduce
> >>> code size, and simplify the code, and coherent DMA will not
> >>> clear the cache every time.
> >>>
> >>> Signed-off-by: Cai Huoqing <caihuoqing@baidu.com>
> >>> drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 20 +++++---------------
> >>> 1 file changed, 5 insertions(+), 15 deletions(-)
> >>
> >> Given I don't see any dma_sync_single calls for this mapping, isn't
> >> this a correctness fix too?
> >
> > HNS folks?
> >
> > Jason
> > .
> >
>
> Our SoC can keep cache coherent, so there is no exception even if
> dma_sync_single* is not called, but the driver should not make
> assumptions about SoC.
>
> So using dma_alloc_coherent() instead of kmalloc/dma_map_single()
> can simplify the code and achieve the same purpose.
>
> Wenpeng Liang
Hi Liang
Thanks for your feedback.
If you think my patch is correct, you can give a Reviewed-by: to it.
You can also give a Tested-by: to it, if the test on hardware was made.
Thanks
Cai
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] RDMA/hns: Use dma_alloc_coherent() instead of kmalloc/dma_map_single()
2021-10-09 10:42 ` Cai Huoqing
@ 2021-10-09 12:03 ` Wenpeng Liang
0 siblings, 0 replies; 7+ messages in thread
From: Wenpeng Liang @ 2021-10-09 12:03 UTC (permalink / raw)
To: Cai Huoqing
Cc: Jason Gunthorpe, Lijun Ou, Weihang Li, Doug Ledford, linux-rdma,
linux-kernel
On 2021/10/9 18:42, Cai Huoqing wrote:
> On 09 10月 21 17:50:50, Wenpeng Liang wrote:
>>
>>
>> On 2021/10/5 3:52, Jason Gunthorpe wrote:
>>> On Mon, Sep 27, 2021 at 08:59:13AM -0300, Jason Gunthorpe wrote:
>>>> On Sun, Sep 26, 2021 at 02:11:15PM +0800, Cai Huoqing wrote:
>>>>> Replacing kmalloc/kfree/dma_map_single/dma_unmap_single()
>>>>> with dma_alloc_coherent/dma_free_coherent() helps to reduce
>>>>> code size, and simplify the code, and coherent DMA will not
>>>>> clear the cache every time.
>>>>>
>>>>> Signed-off-by: Cai Huoqing <caihuoqing@baidu.com>
>>>>> drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 20 +++++---------------
>>>>> 1 file changed, 5 insertions(+), 15 deletions(-)
>>>>
>>>> Given I don't see any dma_sync_single calls for this mapping, isn't
>>>> this a correctness fix too?
>>>
>>> HNS folks?
>>>
>>> Jason
>>> .
>>>
>>
>> Our SoC can keep cache coherent, so there is no exception even if
>> dma_sync_single* is not called, but the driver should not make
>> assumptions about SoC.
>>
>> So using dma_alloc_coherent() instead of kmalloc/dma_map_single()
>> can simplify the code and achieve the same purpose.
>>
>> Wenpeng Liang
>
>
> Hi Liang
>
> Thanks for your feedback.
>
> If you think my patch is correct, you can give a Reviewed-by: to it.
> You can also give a Tested-by: to it, if the test on hardware was made.
>
> Thanks
> Cai
> .
>
Hi, Cai
After testing, it seems ok to me.
Reviewed-by: Wenpeng Liang <liangwenpeng@huawei.com>
Tested-by: Wenpeng Liang <liangwenpeng@huawei.com>
Thanks,
Wenpeng
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] RDMA/hns: Use dma_alloc_coherent() instead of kmalloc/dma_map_single()
2021-09-26 6:11 [PATCH] RDMA/hns: Use dma_alloc_coherent() instead of kmalloc/dma_map_single() Cai Huoqing
2021-09-27 11:59 ` Jason Gunthorpe
@ 2021-10-12 16:11 ` Jason Gunthorpe
1 sibling, 0 replies; 7+ messages in thread
From: Jason Gunthorpe @ 2021-10-12 16:11 UTC (permalink / raw)
To: Cai Huoqing; +Cc: Lijun Ou, Weihang Li, Doug Ledford, linux-rdma, linux-kernel
On Sun, Sep 26, 2021 at 02:11:15PM +0800, Cai Huoqing wrote:
> Replacing kmalloc/kfree/dma_map_single/dma_unmap_single()
> with dma_alloc_coherent/dma_free_coherent() helps to reduce
> code size, and simplify the code, and coherent DMA will not
> clear the cache every time.
>
> Signed-off-by: Cai Huoqing <caihuoqing@baidu.com>
> Reviewed-by: Wenpeng Liang <liangwenpeng@huawei.com>
> Tested-by: Wenpeng Liang <liangwenpeng@huawei.com>
> ---
> drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 20 +++++---------------
> 1 file changed, 5 insertions(+), 15 deletions(-)
Applied to for-next, thanks
Jason
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-10-12 16:11 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-26 6:11 [PATCH] RDMA/hns: Use dma_alloc_coherent() instead of kmalloc/dma_map_single() Cai Huoqing
2021-09-27 11:59 ` Jason Gunthorpe
2021-10-04 19:52 ` Jason Gunthorpe
2021-10-09 9:50 ` Wenpeng Liang
2021-10-09 10:42 ` Cai Huoqing
2021-10-09 12:03 ` Wenpeng Liang
2021-10-12 16:11 ` Jason Gunthorpe
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).