2005-07-08 08:57:14 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2005 Topspin Communications. All rights reserved.
|
|
|
|
* Copyright (c) 2005 Cisco Systems. All rights reserved.
|
2005-08-11 14:03:10 +08:00
|
|
|
* Copyright (c) 2005 Mellanox Technologies. All rights reserved.
|
2020-12-16 05:27:13 +08:00
|
|
|
* Copyright (c) 2020 Intel Corporation. All rights reserved.
|
2005-07-08 08:57:14 +08:00
|
|
|
*
|
|
|
|
* This software is available to you under a choice of one of two
|
|
|
|
* licenses. You may choose to be licensed under the terms of the GNU
|
|
|
|
* General Public License (GPL) Version 2, available from the file
|
|
|
|
* COPYING in the main directory of this source tree, or the
|
|
|
|
* OpenIB.org BSD license below:
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or
|
|
|
|
* without modification, are permitted provided that the following
|
|
|
|
* conditions are met:
|
|
|
|
*
|
|
|
|
* - Redistributions of source code must retain the above
|
|
|
|
* copyright notice, this list of conditions and the following
|
|
|
|
* disclaimer.
|
|
|
|
*
|
|
|
|
* - Redistributions in binary form must reproduce the above
|
|
|
|
* copyright notice, this list of conditions and the following
|
|
|
|
* disclaimer in the documentation and/or other materials
|
|
|
|
* provided with the distribution.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
2017-02-09 01:51:30 +08:00
|
|
|
#include <linux/sched/signal.h>
|
2017-02-09 01:51:29 +08:00
|
|
|
#include <linux/sched/mm.h>
|
2011-05-28 03:29:33 +08:00
|
|
|
#include <linux/export.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2019-04-03 03:52:52 +08:00
|
|
|
#include <linux/pagemap.h>
|
2020-09-05 06:41:44 +08:00
|
|
|
#include <linux/count_zeros.h>
|
2014-12-11 23:04:17 +08:00
|
|
|
#include <rdma/ib_umem_odp.h>
|
2005-07-08 08:57:14 +08:00
|
|
|
|
|
|
|
#include "uverbs.h"
|
|
|
|
|
|
|
|
static void __ib_umem_release(struct ib_device *dev, struct ib_umem *umem, int dirty)
|
|
|
|
{
|
2019-04-03 03:52:52 +08:00
|
|
|
struct sg_page_iter sg_iter;
|
2014-01-28 19:40:15 +08:00
|
|
|
struct page *page;
|
2005-07-08 08:57:14 +08:00
|
|
|
|
2014-01-28 19:40:15 +08:00
|
|
|
if (umem->nmap > 0)
|
2019-04-03 03:52:52 +08:00
|
|
|
ib_dma_unmap_sg(dev, umem->sg_head.sgl, umem->sg_nents,
|
2014-01-28 19:40:15 +08:00
|
|
|
DMA_BIDIRECTIONAL);
|
2007-10-23 03:19:53 +08:00
|
|
|
|
2019-04-03 03:52:52 +08:00
|
|
|
for_each_sg_page(umem->sg_head.sgl, &sg_iter, umem->sg_nents, 0) {
|
|
|
|
page = sg_page_iter_page(&sg_iter);
|
2020-01-31 14:13:35 +08:00
|
|
|
unpin_user_pages_dirty_lock(&page, 1, umem->writable && dirty);
|
2005-07-08 08:57:14 +08:00
|
|
|
}
|
2014-01-28 19:40:15 +08:00
|
|
|
|
|
|
|
sg_free_table(&umem->sg_head);
|
2005-07-08 08:57:14 +08:00
|
|
|
}
|
|
|
|
|
2019-05-06 21:53:32 +08:00
|
|
|
/**
|
|
|
|
* ib_umem_find_best_pgsz - Find best HW page size to use for this MR
|
|
|
|
*
|
|
|
|
* @umem: umem struct
|
|
|
|
* @pgsz_bitmap: bitmap of HW supported page sizes
|
|
|
|
* @virt: IOVA
|
|
|
|
*
|
|
|
|
* This helper is intended for HW that support multiple page
|
|
|
|
* sizes but can do only a single page size in an MR.
|
|
|
|
*
|
|
|
|
* Returns 0 if the umem requires page sizes not supported by
|
|
|
|
* the driver to be mapped. Drivers always supporting PAGE_SIZE
|
|
|
|
* or smaller will never see a 0 result.
|
|
|
|
*/
|
|
|
|
unsigned long ib_umem_find_best_pgsz(struct ib_umem *umem,
|
|
|
|
unsigned long pgsz_bitmap,
|
|
|
|
unsigned long virt)
|
|
|
|
{
|
|
|
|
struct scatterlist *sg;
|
|
|
|
unsigned long va, pgoff;
|
|
|
|
dma_addr_t mask;
|
|
|
|
int i;
|
|
|
|
|
2020-10-26 21:23:14 +08:00
|
|
|
if (umem->is_odp) {
|
|
|
|
unsigned int page_size = BIT(to_ib_umem_odp(umem)->page_shift);
|
|
|
|
|
|
|
|
/* ODP must always be self consistent. */
|
|
|
|
if (!(pgsz_bitmap & page_size))
|
|
|
|
return 0;
|
|
|
|
return page_size;
|
|
|
|
}
|
|
|
|
|
2020-09-05 06:41:43 +08:00
|
|
|
/* rdma_for_each_block() has a bug if the page size is smaller than the
|
|
|
|
* page size used to build the umem. For now prevent smaller page sizes
|
|
|
|
* from being returned.
|
|
|
|
*/
|
|
|
|
pgsz_bitmap &= GENMASK(BITS_PER_LONG - 1, PAGE_SHIFT);
|
|
|
|
|
2019-05-06 21:53:32 +08:00
|
|
|
/* At minimum, drivers must support PAGE_SIZE or smaller */
|
|
|
|
if (WARN_ON(!(pgsz_bitmap & GENMASK(PAGE_SHIFT, 0))))
|
|
|
|
return 0;
|
|
|
|
|
2020-09-05 06:41:47 +08:00
|
|
|
umem->iova = va = virt;
|
2020-09-05 06:41:42 +08:00
|
|
|
/* The best result is the smallest page size that results in the minimum
|
|
|
|
* number of required pages. Compute the largest page size that could
|
|
|
|
* work based on VA address bits that don't change.
|
|
|
|
*/
|
|
|
|
mask = pgsz_bitmap &
|
|
|
|
GENMASK(BITS_PER_LONG - 1,
|
|
|
|
bits_per((umem->length - 1 + virt) ^ virt));
|
2019-05-06 21:53:32 +08:00
|
|
|
/* offset into first SGL */
|
|
|
|
pgoff = umem->address & ~PAGE_MASK;
|
|
|
|
|
|
|
|
for_each_sg(umem->sg_head.sgl, sg, umem->nmap, i) {
|
|
|
|
/* Walk SGL and reduce max page size if VA/PA bits differ
|
|
|
|
* for any address.
|
|
|
|
*/
|
|
|
|
mask |= (sg_dma_address(sg) + pgoff) ^ va;
|
|
|
|
va += sg_dma_len(sg) - pgoff;
|
2020-01-28 21:56:12 +08:00
|
|
|
/* Except for the last entry, the ending iova alignment sets
|
|
|
|
* the maximum possible page size as the low bits of the iova
|
|
|
|
* must be zero when starting the next chunk.
|
|
|
|
*/
|
|
|
|
if (i != (umem->nmap - 1))
|
|
|
|
mask |= va;
|
2019-05-06 21:53:32 +08:00
|
|
|
pgoff = 0;
|
|
|
|
}
|
|
|
|
|
2020-09-05 06:41:44 +08:00
|
|
|
/* The mask accumulates 1's in each position where the VA and physical
|
|
|
|
* address differ, thus the length of trailing 0 is the largest page
|
|
|
|
* size that can pass the VA through to the physical.
|
|
|
|
*/
|
|
|
|
if (mask)
|
|
|
|
pgsz_bitmap &= GENMASK(count_trailing_zeros(mask), 0);
|
2021-01-13 20:16:59 +08:00
|
|
|
return pgsz_bitmap ? rounddown_pow_of_two(pgsz_bitmap) : 0;
|
2019-05-06 21:53:32 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_umem_find_best_pgsz);
|
|
|
|
|
2007-03-05 08:15:11 +08:00
|
|
|
/**
|
|
|
|
* ib_umem_get - Pin and DMA map userspace memory.
|
2014-12-11 23:04:17 +08:00
|
|
|
*
|
2020-01-15 20:43:31 +08:00
|
|
|
* @device: IB device to connect UMEM
|
2007-03-05 08:15:11 +08:00
|
|
|
* @addr: userspace virtual address to start at
|
|
|
|
* @size: length of region to pin
|
|
|
|
* @access: IB_ACCESS_xxx flags for memory being pinned
|
|
|
|
*/
|
2020-01-15 20:43:31 +08:00
|
|
|
struct ib_umem *ib_umem_get(struct ib_device *device, unsigned long addr,
|
2019-11-13 15:32:14 +08:00
|
|
|
size_t size, int access)
|
2005-07-08 08:57:14 +08:00
|
|
|
{
|
2007-03-05 08:15:11 +08:00
|
|
|
struct ib_umem *umem;
|
2005-07-08 08:57:14 +08:00
|
|
|
struct page **page_list;
|
|
|
|
unsigned long lock_limit;
|
2018-09-21 23:30:13 +08:00
|
|
|
unsigned long new_pinned;
|
2005-07-08 08:57:14 +08:00
|
|
|
unsigned long cur_base;
|
2020-02-12 15:35:59 +08:00
|
|
|
unsigned long dma_attr = 0;
|
2018-09-17 01:44:45 +08:00
|
|
|
struct mm_struct *mm;
|
2005-07-08 08:57:14 +08:00
|
|
|
unsigned long npages;
|
2007-03-05 08:15:11 +08:00
|
|
|
int ret;
|
2020-10-04 23:43:40 +08:00
|
|
|
struct scatterlist *sg = NULL;
|
2016-10-13 08:20:16 +08:00
|
|
|
unsigned int gup_flags = FOLL_WRITE;
|
2008-04-29 16:00:34 +08:00
|
|
|
|
2015-03-19 01:39:08 +08:00
|
|
|
/*
|
|
|
|
* If the combination of the addr and size requested for this memory
|
|
|
|
* region causes an integer overflow, return error.
|
|
|
|
*/
|
2015-04-13 20:56:23 +08:00
|
|
|
if (((addr + size) < addr) ||
|
|
|
|
PAGE_ALIGN(addr + size) < (addr + size))
|
2015-03-19 01:39:08 +08:00
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
2005-07-08 08:57:14 +08:00
|
|
|
if (!can_do_mlock())
|
2007-03-05 08:15:11 +08:00
|
|
|
return ERR_PTR(-EPERM);
|
2005-07-08 08:57:14 +08:00
|
|
|
|
2019-08-19 19:17:04 +08:00
|
|
|
if (access & IB_ACCESS_ON_DEMAND)
|
|
|
|
return ERR_PTR(-EOPNOTSUPP);
|
2005-07-08 08:57:14 +08:00
|
|
|
|
2019-08-19 19:17:04 +08:00
|
|
|
umem = kzalloc(sizeof(*umem), GFP_KERNEL);
|
|
|
|
if (!umem)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
2020-01-15 20:43:31 +08:00
|
|
|
umem->ibdev = device;
|
2017-04-05 14:23:50 +08:00
|
|
|
umem->length = size;
|
|
|
|
umem->address = addr;
|
2020-09-05 06:41:47 +08:00
|
|
|
/*
|
|
|
|
* Drivers should call ib_umem_find_best_pgsz() to set the iova
|
|
|
|
* correctly.
|
|
|
|
*/
|
|
|
|
umem->iova = addr;
|
2018-05-23 20:30:30 +08:00
|
|
|
umem->writable = ib_access_writable(access);
|
2018-09-17 01:48:05 +08:00
|
|
|
umem->owning_mm = mm = current->mm;
|
|
|
|
mmgrab(mm);
|
2005-07-08 08:57:14 +08:00
|
|
|
|
2007-03-05 08:15:11 +08:00
|
|
|
page_list = (struct page **) __get_free_page(GFP_KERNEL);
|
|
|
|
if (!page_list) {
|
2018-07-10 18:31:49 +08:00
|
|
|
ret = -ENOMEM;
|
2018-09-17 01:48:05 +08:00
|
|
|
goto umem_kfree;
|
2007-03-05 08:15:11 +08:00
|
|
|
}
|
2005-07-08 08:57:14 +08:00
|
|
|
|
2014-12-11 23:04:12 +08:00
|
|
|
npages = ib_umem_num_pages(umem);
|
2018-09-21 23:30:12 +08:00
|
|
|
if (npages == 0 || npages > UINT_MAX) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2005-07-08 08:57:14 +08:00
|
|
|
|
2010-02-12 07:40:48 +08:00
|
|
|
lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT;
|
2005-07-08 08:57:14 +08:00
|
|
|
|
2019-02-07 01:59:20 +08:00
|
|
|
new_pinned = atomic64_add_return(npages, &mm->pinned_vm);
|
2019-02-07 01:59:15 +08:00
|
|
|
if (new_pinned > lock_limit && !capable(CAP_IPC_LOCK)) {
|
2019-02-07 01:59:20 +08:00
|
|
|
atomic64_sub(npages, &mm->pinned_vm);
|
2005-07-08 08:57:14 +08:00
|
|
|
ret = -ENOMEM;
|
2018-09-21 23:30:13 +08:00
|
|
|
goto out;
|
2005-07-08 08:57:14 +08:00
|
|
|
}
|
|
|
|
|
2007-03-05 08:15:11 +08:00
|
|
|
cur_base = addr & PAGE_MASK;
|
2005-07-08 08:57:14 +08:00
|
|
|
|
2016-10-13 08:20:16 +08:00
|
|
|
if (!umem->writable)
|
|
|
|
gup_flags |= FOLL_FORCE;
|
|
|
|
|
2005-07-08 08:57:14 +08:00
|
|
|
while (npages) {
|
2020-07-30 09:57:55 +08:00
|
|
|
cond_resched();
|
2020-01-31 14:13:02 +08:00
|
|
|
ret = pin_user_pages_fast(cur_base,
|
2020-01-31 14:12:47 +08:00
|
|
|
min_t(unsigned long, npages,
|
|
|
|
PAGE_SIZE /
|
|
|
|
sizeof(struct page *)),
|
|
|
|
gup_flags | FOLL_LONGTERM, page_list);
|
|
|
|
if (ret < 0)
|
2018-07-10 18:31:49 +08:00
|
|
|
goto umem_release;
|
2005-07-08 08:57:14 +08:00
|
|
|
|
|
|
|
cur_base += ret * PAGE_SIZE;
|
2020-10-04 23:43:40 +08:00
|
|
|
npages -= ret;
|
2020-11-07 02:19:33 +08:00
|
|
|
sg = __sg_alloc_table_from_pages(&umem->sg_head, page_list, ret,
|
|
|
|
0, ret << PAGE_SHIFT,
|
|
|
|
ib_dma_max_seg_size(device), sg, npages,
|
|
|
|
GFP_KERNEL);
|
2020-10-04 23:43:40 +08:00
|
|
|
umem->sg_nents = umem->sg_head.nents;
|
|
|
|
if (IS_ERR(sg)) {
|
|
|
|
unpin_user_pages_dirty_lock(page_list, ret, 0);
|
|
|
|
ret = PTR_ERR(sg);
|
|
|
|
goto umem_release;
|
|
|
|
}
|
2005-07-08 08:57:14 +08:00
|
|
|
}
|
|
|
|
|
2020-02-12 15:35:59 +08:00
|
|
|
if (access & IB_ACCESS_RELAXED_ORDERING)
|
|
|
|
dma_attr |= DMA_ATTR_WEAK_ORDERING;
|
|
|
|
|
|
|
|
umem->nmap =
|
|
|
|
ib_dma_map_sg_attrs(device, umem->sg_head.sgl, umem->sg_nents,
|
|
|
|
DMA_BIDIRECTIONAL, dma_attr);
|
2014-01-28 19:40:15 +08:00
|
|
|
|
2018-06-24 16:23:48 +08:00
|
|
|
if (!umem->nmap) {
|
2014-01-28 19:40:15 +08:00
|
|
|
ret = -ENOMEM;
|
2018-07-10 18:31:49 +08:00
|
|
|
goto umem_release;
|
2014-01-28 19:40:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
2018-07-10 18:31:49 +08:00
|
|
|
goto out;
|
2014-01-28 19:40:15 +08:00
|
|
|
|
2018-07-10 18:31:49 +08:00
|
|
|
umem_release:
|
2020-01-15 20:43:31 +08:00
|
|
|
__ib_umem_release(device, umem, 0);
|
2019-02-07 01:59:15 +08:00
|
|
|
atomic64_sub(ib_umem_num_pages(umem), &mm->pinned_vm);
|
2005-07-08 08:57:14 +08:00
|
|
|
out:
|
|
|
|
free_page((unsigned long) page_list);
|
2018-07-10 18:31:49 +08:00
|
|
|
umem_kfree:
|
2018-09-17 01:48:05 +08:00
|
|
|
if (ret) {
|
|
|
|
mmdrop(umem->owning_mm);
|
2018-07-10 18:31:49 +08:00
|
|
|
kfree(umem);
|
2018-09-17 01:48:05 +08:00
|
|
|
}
|
2018-07-10 18:31:49 +08:00
|
|
|
return ret ? ERR_PTR(ret) : umem;
|
2005-07-08 08:57:14 +08:00
|
|
|
}
|
2007-03-05 08:15:11 +08:00
|
|
|
EXPORT_SYMBOL(ib_umem_get);
|
2005-07-08 08:57:14 +08:00
|
|
|
|
2007-03-05 08:15:11 +08:00
|
|
|
/**
|
|
|
|
* ib_umem_release - release memory pinned with ib_umem_get
|
|
|
|
* @umem: umem struct to release
|
|
|
|
*/
|
|
|
|
void ib_umem_release(struct ib_umem *umem)
|
2005-07-08 08:57:14 +08:00
|
|
|
{
|
2019-06-16 20:05:20 +08:00
|
|
|
if (!umem)
|
|
|
|
return;
|
2020-12-16 05:27:13 +08:00
|
|
|
if (umem->is_dmabuf)
|
|
|
|
return ib_umem_dmabuf_release(to_ib_umem_dmabuf(umem));
|
2019-08-19 19:17:05 +08:00
|
|
|
if (umem->is_odp)
|
|
|
|
return ib_umem_odp_release(to_ib_umem_odp(umem));
|
2014-12-11 23:04:17 +08:00
|
|
|
|
2019-08-07 07:15:44 +08:00
|
|
|
__ib_umem_release(umem->ibdev, umem, 1);
|
2005-07-08 08:57:14 +08:00
|
|
|
|
2019-02-07 01:59:15 +08:00
|
|
|
atomic64_sub(ib_umem_num_pages(umem), &umem->owning_mm->pinned_vm);
|
2019-08-19 19:17:05 +08:00
|
|
|
mmdrop(umem->owning_mm);
|
|
|
|
kfree(umem);
|
2007-03-05 08:15:11 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_umem_release);
|
|
|
|
|
2014-12-11 23:04:13 +08:00
|
|
|
/*
|
|
|
|
* Copy from the given ib_umem's pages to the given buffer.
|
|
|
|
*
|
|
|
|
* umem - the umem to copy from
|
|
|
|
* offset - offset to start copying from
|
|
|
|
* dst - destination buffer
|
|
|
|
* length - buffer length
|
|
|
|
*
|
|
|
|
* Returns 0 on success, or an error code.
|
|
|
|
*/
|
|
|
|
int ib_umem_copy_from(void *dst, struct ib_umem *umem, size_t offset,
|
|
|
|
size_t length)
|
|
|
|
{
|
|
|
|
size_t end = offset + length;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (offset > umem->length || length > umem->length - offset) {
|
|
|
|
pr_err("ib_umem_copy_from not in range. offset: %zd umem length: %zd end: %zd\n",
|
|
|
|
offset, umem->length, end);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2019-04-04 23:22:47 +08:00
|
|
|
ret = sg_pcopy_to_buffer(umem->sg_head.sgl, umem->sg_nents, dst, length,
|
|
|
|
offset + ib_umem_offset(umem));
|
2014-12-11 23:04:13 +08:00
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
else if (ret != length)
|
|
|
|
return -EINVAL;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ib_umem_copy_from);
|