mirror of
https://github.com/torvalds/linux.git
synced 2026-11-06 21:58:01 +01:00
RDMA/umem: Support an explicit DMA direction other than DMA_BIDIRECTIONAL
Add a dma_dir field to struct ib_umem to record the direction chosen at map time and reuse it at unmap. Thread an explicit dma_data_direction parameter through the internal pinning helpers so each caller can supply the direction that matches the device's actual access pattern. All existing callers still pass DMA_BIDIRECTIONAL, so this is a pure mechanism addition with no behavioural change. Signed-off-by: Yishai Hadas <yishaih@nvidia.com> Link: https://patch.msgid.link/20260915140933.40580-6-yishaih@nvidia.com Signed-off-by: Leon Romanovsky <leon@kernel.org>
This commit is contained in:
parent
b577999f6f
commit
2445d74c46
|
|
@ -55,7 +55,7 @@ static void __ib_umem_release(struct ib_device *dev, struct ib_umem *umem, int d
|
|||
|
||||
if (dirty)
|
||||
ib_dma_unmap_sgtable_attrs(dev, &umem->sgt_append.sgt,
|
||||
DMA_BIDIRECTIONAL, umem->dma_attrs);
|
||||
umem->dma_dir, umem->dma_attrs);
|
||||
|
||||
for_each_sgtable_sg(&umem->sgt_append.sgt, sg, i) {
|
||||
unpin_user_page_range_dirty_lock(sg_page(sg),
|
||||
|
|
@ -161,7 +161,8 @@ EXPORT_SYMBOL(ib_umem_find_best_pgsz);
|
|||
|
||||
static struct ib_umem *__ib_umem_get_va(struct ib_device *device,
|
||||
unsigned long addr, size_t size,
|
||||
int access)
|
||||
int access,
|
||||
enum dma_data_direction dir)
|
||||
{
|
||||
struct ib_umem *umem;
|
||||
struct page **page_list;
|
||||
|
|
@ -202,6 +203,7 @@ static struct ib_umem *__ib_umem_get_va(struct ib_device *device,
|
|||
*/
|
||||
umem->iova = addr;
|
||||
umem->writable = ib_access_writable(access);
|
||||
umem->dma_dir = dir;
|
||||
umem->owning_mm = mm = current->mm;
|
||||
umem->dma_attrs = DMA_ATTR_REQUIRE_COHERENT;
|
||||
if (access & IB_ACCESS_RELAXED_ORDERING)
|
||||
|
|
@ -261,7 +263,7 @@ static struct ib_umem *__ib_umem_get_va(struct ib_device *device,
|
|||
}
|
||||
|
||||
ret = ib_dma_map_sgtable_attrs(device, &umem->sgt_append.sgt,
|
||||
DMA_BIDIRECTIONAL, umem->dma_attrs);
|
||||
dir, umem->dma_attrs);
|
||||
if (ret)
|
||||
goto umem_release;
|
||||
goto out;
|
||||
|
|
@ -279,17 +281,16 @@ static struct ib_umem *__ib_umem_get_va(struct ib_device *device,
|
|||
return ret ? ERR_PTR(ret) : umem;
|
||||
}
|
||||
|
||||
/**
|
||||
* ib_umem_get_desc - Pin a umem from a buffer descriptor.
|
||||
* @device: IB device.
|
||||
* @desc: buffer descriptor (VA or DMABUF).
|
||||
* @access: IB access flags.
|
||||
/*
|
||||
* __ib_umem_get_desc_dir - core implementation for ib_umem_get_desc().
|
||||
*
|
||||
* Return: caller-owned umem on success, ERR_PTR(...) on error.
|
||||
* @dir applies to VA buffers only; dmabuf direction is managed by the
|
||||
* dmabuf subsystem and this argument is ignored for that type.
|
||||
*/
|
||||
struct ib_umem *ib_umem_get_desc(struct ib_device *device,
|
||||
const struct ib_uverbs_buffer_desc *desc,
|
||||
int access)
|
||||
static struct ib_umem *
|
||||
__ib_umem_get_desc_dir(struct ib_device *device,
|
||||
const struct ib_uverbs_buffer_desc *desc,
|
||||
int access, enum dma_data_direction dir)
|
||||
{
|
||||
struct ib_umem_dmabuf *umem_dmabuf;
|
||||
|
||||
|
|
@ -310,11 +311,26 @@ struct ib_umem *ib_umem_get_desc(struct ib_device *device,
|
|||
return &umem_dmabuf->umem;
|
||||
case IB_UVERBS_BUFFER_TYPE_VA:
|
||||
return __ib_umem_get_va(device, desc->addr, desc->length,
|
||||
access);
|
||||
access, dir);
|
||||
default:
|
||||
return ERR_PTR(-EINVAL);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ib_umem_get_desc - Pin a umem from a buffer descriptor.
|
||||
* @device: IB device.
|
||||
* @desc: buffer descriptor (VA or DMABUF).
|
||||
* @access: IB access flags.
|
||||
*
|
||||
* Return: caller-owned umem on success, ERR_PTR(...) on error.
|
||||
*/
|
||||
struct ib_umem *ib_umem_get_desc(struct ib_device *device,
|
||||
const struct ib_uverbs_buffer_desc *desc,
|
||||
int access)
|
||||
{
|
||||
return __ib_umem_get_desc_dir(device, desc, access, DMA_BIDIRECTIONAL);
|
||||
}
|
||||
EXPORT_SYMBOL(ib_umem_get_desc);
|
||||
|
||||
/*
|
||||
|
|
@ -376,11 +392,12 @@ static int ib_umem_resolve_desc(const struct uverbs_attr_bundle *attrs,
|
|||
static struct ib_umem *
|
||||
ib_umem_get_desc_check(struct ib_device *device,
|
||||
const struct ib_uverbs_buffer_desc *desc,
|
||||
size_t min_size, int access)
|
||||
size_t min_size, int access,
|
||||
enum dma_data_direction dir)
|
||||
{
|
||||
struct ib_umem *umem;
|
||||
|
||||
umem = ib_umem_get_desc(device, desc, access);
|
||||
umem = __ib_umem_get_desc_dir(device, desc, access, dir);
|
||||
if (IS_ERR(umem))
|
||||
return umem;
|
||||
if (umem->length < min_size) {
|
||||
|
|
@ -401,7 +418,7 @@ static struct ib_umem *
|
|||
ib_umem_get_from_attrs(struct ib_device *device,
|
||||
const struct uverbs_attr_bundle *attrs,
|
||||
u16 attr_id, ib_umem_buf_desc_filler_t legacy_filler,
|
||||
size_t size, int access)
|
||||
size_t size, int access, enum dma_data_direction dir)
|
||||
{
|
||||
struct ib_uverbs_buffer_desc desc = {};
|
||||
int ret;
|
||||
|
|
@ -411,7 +428,7 @@ ib_umem_get_from_attrs(struct ib_device *device,
|
|||
return NULL;
|
||||
if (ret)
|
||||
return ERR_PTR(ret);
|
||||
return ib_umem_get_desc_check(device, &desc, size, access);
|
||||
return ib_umem_get_desc_check(device, &desc, size, access, dir);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -431,7 +448,8 @@ ib_umem_get_from_attrs_or_va(struct ib_device *device,
|
|||
const struct uverbs_attr_bundle *attrs,
|
||||
u16 attr_id,
|
||||
ib_umem_buf_desc_filler_t legacy_filler,
|
||||
u64 addr, size_t size, int access)
|
||||
u64 addr, size_t size, int access,
|
||||
enum dma_data_direction dir)
|
||||
{
|
||||
struct ib_uverbs_buffer_desc desc = {};
|
||||
int ret;
|
||||
|
|
@ -445,7 +463,7 @@ ib_umem_get_from_attrs_or_va(struct ib_device *device,
|
|||
};
|
||||
else if (ret)
|
||||
return ERR_PTR(ret);
|
||||
return ib_umem_get_desc_check(device, &desc, size, access);
|
||||
return ib_umem_get_desc_check(device, &desc, size, access, dir);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -464,7 +482,7 @@ struct ib_umem *ib_umem_get_attr(struct ib_device *device,
|
|||
u16 attr_id, size_t size, int access)
|
||||
{
|
||||
return ib_umem_get_from_attrs(device, attrs, attr_id, NULL, size,
|
||||
access);
|
||||
access, DMA_BIDIRECTIONAL);
|
||||
}
|
||||
EXPORT_SYMBOL(ib_umem_get_attr);
|
||||
|
||||
|
|
@ -503,7 +521,7 @@ struct ib_umem *ib_umem_get_attr_or_va(struct ib_device *device,
|
|||
int access)
|
||||
{
|
||||
return ib_umem_get_from_attrs_or_va(device, attrs, attr_id, NULL, addr,
|
||||
size, access);
|
||||
size, access, DMA_BIDIRECTIONAL);
|
||||
}
|
||||
EXPORT_SYMBOL(ib_umem_get_attr_or_va);
|
||||
|
||||
|
|
@ -579,7 +597,7 @@ struct ib_umem *ib_umem_get_cq_buf(struct ib_device *device,
|
|||
return ib_umem_get_from_attrs(device, attrs,
|
||||
UVERBS_ATTR_CREATE_CQ_BUF_UMEM,
|
||||
uverbs_create_cq_get_buffer_desc,
|
||||
size, access);
|
||||
size, access, DMA_BIDIRECTIONAL);
|
||||
}
|
||||
EXPORT_SYMBOL(ib_umem_get_cq_buf);
|
||||
|
||||
|
|
@ -608,7 +626,7 @@ struct ib_umem *ib_umem_get_cq_buf_or_va(struct ib_device *device,
|
|||
return ib_umem_get_from_attrs_or_va(device, attrs,
|
||||
UVERBS_ATTR_CREATE_CQ_BUF_UMEM,
|
||||
uverbs_create_cq_get_buffer_desc,
|
||||
addr, size, access);
|
||||
addr, size, access, DMA_BIDIRECTIONAL);
|
||||
}
|
||||
EXPORT_SYMBOL(ib_umem_get_cq_buf_or_va);
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#ifndef IB_UMEM_H
|
||||
#define IB_UMEM_H
|
||||
|
||||
#include <linux/dma-direction.h>
|
||||
#include <linux/scatterlist.h>
|
||||
|
||||
struct ib_device;
|
||||
|
|
@ -19,6 +20,7 @@ struct ib_umem {
|
|||
size_t length;
|
||||
unsigned long address;
|
||||
unsigned long dma_attrs;
|
||||
enum dma_data_direction dma_dir;
|
||||
u32 writable : 1;
|
||||
u32 is_odp : 1;
|
||||
u32 is_dmabuf : 1;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user