Commit b5231b01 authored by Jason Gunthorpe's avatar Jason Gunthorpe Committed by Doug Ledford

RDMA/umem: Use ib_umem_odp in all function signatures connected to ODP

All of these functions already require the ODP version of the umem struct,
make this very clear by having the signature require it. This paves the
way to using the container_of() pattern to link umem_odp and umem
together.
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
Signed-off-by: default avatarLeon Romanovsky <leonro@mellanox.com>
Signed-off-by: default avatarDoug Ledford <dledford@redhat.com>
parent ece8ea7b
...@@ -262,7 +262,7 @@ void ib_umem_release(struct ib_umem *umem) ...@@ -262,7 +262,7 @@ void ib_umem_release(struct ib_umem *umem)
struct ib_ucontext *context = umem->context; struct ib_ucontext *context = umem->context;
if (umem->odp_data) { if (umem->odp_data) {
ib_umem_odp_release(umem); ib_umem_odp_release(to_ib_umem_odp(umem));
return; return;
} }
......
...@@ -77,41 +77,41 @@ static u64 node_last(struct umem_odp_node *n) ...@@ -77,41 +77,41 @@ static u64 node_last(struct umem_odp_node *n)
INTERVAL_TREE_DEFINE(struct umem_odp_node, rb, u64, __subtree_last, INTERVAL_TREE_DEFINE(struct umem_odp_node, rb, u64, __subtree_last,
node_start, node_last, static, rbt_ib_umem) node_start, node_last, static, rbt_ib_umem)
static void ib_umem_notifier_start_account(struct ib_umem *item) static void ib_umem_notifier_start_account(struct ib_umem_odp *umem_odp)
{ {
mutex_lock(&item->odp_data->umem_mutex); mutex_lock(&umem_odp->umem_mutex);
/* Only update private counters for this umem if it has them. /* Only update private counters for this umem if it has them.
* Otherwise skip it. All page faults will be delayed for this umem. */ * Otherwise skip it. All page faults will be delayed for this umem. */
if (item->odp_data->mn_counters_active) { if (umem_odp->mn_counters_active) {
int notifiers_count = item->odp_data->notifiers_count++; int notifiers_count = umem_odp->notifiers_count++;
if (notifiers_count == 0) if (notifiers_count == 0)
/* Initialize the completion object for waiting on /* Initialize the completion object for waiting on
* notifiers. Since notifier_count is zero, no one * notifiers. Since notifier_count is zero, no one
* should be waiting right now. */ * should be waiting right now. */
reinit_completion(&item->odp_data->notifier_completion); reinit_completion(&umem_odp->notifier_completion);
} }
mutex_unlock(&item->odp_data->umem_mutex); mutex_unlock(&umem_odp->umem_mutex);
} }
static void ib_umem_notifier_end_account(struct ib_umem *item) static void ib_umem_notifier_end_account(struct ib_umem_odp *umem_odp)
{ {
mutex_lock(&item->odp_data->umem_mutex); mutex_lock(&umem_odp->umem_mutex);
/* Only update private counters for this umem if it has them. /* Only update private counters for this umem if it has them.
* Otherwise skip it. All page faults will be delayed for this umem. */ * Otherwise skip it. All page faults will be delayed for this umem. */
if (item->odp_data->mn_counters_active) { if (umem_odp->mn_counters_active) {
/* /*
* This sequence increase will notify the QP page fault that * This sequence increase will notify the QP page fault that
* the page that is going to be mapped in the spte could have * the page that is going to be mapped in the spte could have
* been freed. * been freed.
*/ */
++item->odp_data->notifiers_seq; ++umem_odp->notifiers_seq;
if (--item->odp_data->notifiers_count == 0) if (--umem_odp->notifiers_count == 0)
complete_all(&item->odp_data->notifier_completion); complete_all(&umem_odp->notifier_completion);
} }
mutex_unlock(&item->odp_data->umem_mutex); mutex_unlock(&umem_odp->umem_mutex);
} }
/* Account for a new mmu notifier in an ib_ucontext. */ /* Account for a new mmu notifier in an ib_ucontext. */
...@@ -156,20 +156,23 @@ static void ib_ucontext_notifier_end_account(struct ib_ucontext *context) ...@@ -156,20 +156,23 @@ static void ib_ucontext_notifier_end_account(struct ib_ucontext *context)
} }
} }
static int ib_umem_notifier_release_trampoline(struct ib_umem *item, u64 start, static int ib_umem_notifier_release_trampoline(struct ib_umem_odp *umem_odp,
u64 end, void *cookie) { u64 start, u64 end, void *cookie)
{
struct ib_umem *umem = umem_odp->umem;
/* /*
* Increase the number of notifiers running, to * Increase the number of notifiers running, to
* prevent any further fault handling on this MR. * prevent any further fault handling on this MR.
*/ */
ib_umem_notifier_start_account(item); ib_umem_notifier_start_account(umem_odp);
item->odp_data->dying = 1; umem_odp->dying = 1;
/* Make sure that the fact the umem is dying is out before we release /* Make sure that the fact the umem is dying is out before we release
* all pending page faults. */ * all pending page faults. */
smp_wmb(); smp_wmb();
complete_all(&item->odp_data->notifier_completion); complete_all(&umem_odp->notifier_completion);
item->context->invalidate_range(item, ib_umem_start(item), umem->context->invalidate_range(umem_odp, ib_umem_start(umem),
ib_umem_end(item)); ib_umem_end(umem));
return 0; return 0;
} }
...@@ -191,20 +194,20 @@ static void ib_umem_notifier_release(struct mmu_notifier *mn, ...@@ -191,20 +194,20 @@ static void ib_umem_notifier_release(struct mmu_notifier *mn,
up_read(&context->umem_rwsem); up_read(&context->umem_rwsem);
} }
static int invalidate_page_trampoline(struct ib_umem *item, u64 start, static int invalidate_page_trampoline(struct ib_umem_odp *item, u64 start,
u64 end, void *cookie) u64 end, void *cookie)
{ {
ib_umem_notifier_start_account(item); ib_umem_notifier_start_account(item);
item->context->invalidate_range(item, start, start + PAGE_SIZE); item->umem->context->invalidate_range(item, start, start + PAGE_SIZE);
ib_umem_notifier_end_account(item); ib_umem_notifier_end_account(item);
return 0; return 0;
} }
static int invalidate_range_start_trampoline(struct ib_umem *item, u64 start, static int invalidate_range_start_trampoline(struct ib_umem_odp *item,
u64 end, void *cookie) u64 start, u64 end, void *cookie)
{ {
ib_umem_notifier_start_account(item); ib_umem_notifier_start_account(item);
item->context->invalidate_range(item, start, end); item->umem->context->invalidate_range(item, start, end);
return 0; return 0;
} }
...@@ -235,7 +238,7 @@ static int ib_umem_notifier_invalidate_range_start(struct mmu_notifier *mn, ...@@ -235,7 +238,7 @@ static int ib_umem_notifier_invalidate_range_start(struct mmu_notifier *mn,
return ret; return ret;
} }
static int invalidate_range_end_trampoline(struct ib_umem *item, u64 start, static int invalidate_range_end_trampoline(struct ib_umem_odp *item, u64 start,
u64 end, void *cookie) u64 end, void *cookie)
{ {
ib_umem_notifier_end_account(item); ib_umem_notifier_end_account(item);
...@@ -271,9 +274,8 @@ static const struct mmu_notifier_ops ib_umem_notifiers = { ...@@ -271,9 +274,8 @@ static const struct mmu_notifier_ops ib_umem_notifiers = {
.invalidate_range_end = ib_umem_notifier_invalidate_range_end, .invalidate_range_end = ib_umem_notifier_invalidate_range_end,
}; };
struct ib_umem *ib_alloc_odp_umem(struct ib_ucontext *context, struct ib_umem_odp *ib_alloc_odp_umem(struct ib_ucontext *context,
unsigned long addr, unsigned long addr, size_t size)
size_t size)
{ {
struct ib_umem *umem; struct ib_umem *umem;
struct ib_umem_odp *odp_data; struct ib_umem_odp *odp_data;
...@@ -326,7 +328,7 @@ struct ib_umem *ib_alloc_odp_umem(struct ib_ucontext *context, ...@@ -326,7 +328,7 @@ struct ib_umem *ib_alloc_odp_umem(struct ib_ucontext *context,
umem->odp_data = odp_data; umem->odp_data = odp_data;
return umem; return odp_data;
out_page_list: out_page_list:
vfree(odp_data->page_list); vfree(odp_data->page_list);
...@@ -462,8 +464,9 @@ int ib_umem_odp_get(struct ib_ucontext *context, struct ib_umem *umem, ...@@ -462,8 +464,9 @@ int ib_umem_odp_get(struct ib_ucontext *context, struct ib_umem *umem,
return ret_val; return ret_val;
} }
void ib_umem_odp_release(struct ib_umem *umem) void ib_umem_odp_release(struct ib_umem_odp *umem_odp)
{ {
struct ib_umem *umem = umem_odp->umem;
struct ib_ucontext *context = umem->context; struct ib_ucontext *context = umem->context;
/* /*
...@@ -472,17 +475,17 @@ void ib_umem_odp_release(struct ib_umem *umem) ...@@ -472,17 +475,17 @@ void ib_umem_odp_release(struct ib_umem *umem)
* It is the driver's responsibility to ensure, before calling us, * It is the driver's responsibility to ensure, before calling us,
* that the hardware will not attempt to access the MR any more. * that the hardware will not attempt to access the MR any more.
*/ */
ib_umem_odp_unmap_dma_pages(umem, ib_umem_start(umem), ib_umem_odp_unmap_dma_pages(umem_odp, ib_umem_start(umem),
ib_umem_end(umem)); ib_umem_end(umem));
down_write(&context->umem_rwsem); down_write(&context->umem_rwsem);
if (likely(ib_umem_start(umem) != ib_umem_end(umem))) if (likely(ib_umem_start(umem) != ib_umem_end(umem)))
rbt_ib_umem_remove(&umem->odp_data->interval_tree, rbt_ib_umem_remove(&umem_odp->interval_tree,
&context->umem_tree); &context->umem_tree);
context->odp_mrs_count--; context->odp_mrs_count--;
if (!umem->odp_data->mn_counters_active) { if (!umem_odp->mn_counters_active) {
list_del(&umem->odp_data->no_private_counters); list_del(&umem_odp->no_private_counters);
complete_all(&umem->odp_data->notifier_completion); complete_all(&umem_odp->notifier_completion);
} }
/* /*
...@@ -523,9 +526,9 @@ void ib_umem_odp_release(struct ib_umem *umem) ...@@ -523,9 +526,9 @@ void ib_umem_odp_release(struct ib_umem *umem)
out: out:
up_read(&context->umem_rwsem); up_read(&context->umem_rwsem);
vfree(umem->odp_data->dma_list); vfree(umem_odp->dma_list);
vfree(umem->odp_data->page_list); vfree(umem_odp->page_list);
kfree(umem->odp_data); kfree(umem_odp);
kfree(umem); kfree(umem);
} }
...@@ -538,7 +541,7 @@ void ib_umem_odp_release(struct ib_umem *umem) ...@@ -538,7 +541,7 @@ void ib_umem_odp_release(struct ib_umem *umem)
* @access_mask: access permissions needed for this page. * @access_mask: access permissions needed for this page.
* @current_seq: sequence number for synchronization with invalidations. * @current_seq: sequence number for synchronization with invalidations.
* the sequence number is taken from * the sequence number is taken from
* umem->odp_data->notifiers_seq. * umem_odp->notifiers_seq.
* *
* The function returns -EFAULT if the DMA mapping operation fails. It returns * The function returns -EFAULT if the DMA mapping operation fails. It returns
* -EAGAIN if a concurrent invalidation prevents us from updating the page. * -EAGAIN if a concurrent invalidation prevents us from updating the page.
...@@ -548,12 +551,13 @@ void ib_umem_odp_release(struct ib_umem *umem) ...@@ -548,12 +551,13 @@ void ib_umem_odp_release(struct ib_umem *umem)
* umem. * umem.
*/ */
static int ib_umem_odp_map_dma_single_page( static int ib_umem_odp_map_dma_single_page(
struct ib_umem *umem, struct ib_umem_odp *umem_odp,
int page_index, int page_index,
struct page *page, struct page *page,
u64 access_mask, u64 access_mask,
unsigned long current_seq) unsigned long current_seq)
{ {
struct ib_umem *umem = umem_odp->umem;
struct ib_device *dev = umem->context->device; struct ib_device *dev = umem->context->device;
dma_addr_t dma_addr; dma_addr_t dma_addr;
int stored_page = 0; int stored_page = 0;
...@@ -565,11 +569,11 @@ static int ib_umem_odp_map_dma_single_page( ...@@ -565,11 +569,11 @@ static int ib_umem_odp_map_dma_single_page(
* handle case of a racing notifier. This check also allows us to bail * handle case of a racing notifier. This check also allows us to bail
* early if we have a notifier running in parallel with us. * early if we have a notifier running in parallel with us.
*/ */
if (ib_umem_mmu_notifier_retry(umem, current_seq)) { if (ib_umem_mmu_notifier_retry(umem_odp, current_seq)) {
ret = -EAGAIN; ret = -EAGAIN;
goto out; goto out;
} }
if (!(umem->odp_data->dma_list[page_index])) { if (!(umem_odp->dma_list[page_index])) {
dma_addr = ib_dma_map_page(dev, dma_addr = ib_dma_map_page(dev,
page, page,
0, BIT(umem->page_shift), 0, BIT(umem->page_shift),
...@@ -578,15 +582,15 @@ static int ib_umem_odp_map_dma_single_page( ...@@ -578,15 +582,15 @@ static int ib_umem_odp_map_dma_single_page(
ret = -EFAULT; ret = -EFAULT;
goto out; goto out;
} }
umem->odp_data->dma_list[page_index] = dma_addr | access_mask; umem_odp->dma_list[page_index] = dma_addr | access_mask;
umem->odp_data->page_list[page_index] = page; umem_odp->page_list[page_index] = page;
umem->npages++; umem->npages++;
stored_page = 1; stored_page = 1;
} else if (umem->odp_data->page_list[page_index] == page) { } else if (umem_odp->page_list[page_index] == page) {
umem->odp_data->dma_list[page_index] |= access_mask; umem_odp->dma_list[page_index] |= access_mask;
} else { } else {
pr_err("error: got different pages in IB device and from get_user_pages. IB device page: %p, gup page: %p\n", pr_err("error: got different pages in IB device and from get_user_pages. IB device page: %p, gup page: %p\n",
umem->odp_data->page_list[page_index], page); umem_odp->page_list[page_index], page);
/* Better remove the mapping now, to prevent any further /* Better remove the mapping now, to prevent any further
* damage. */ * damage. */
remove_existing_mapping = 1; remove_existing_mapping = 1;
...@@ -599,7 +603,7 @@ static int ib_umem_odp_map_dma_single_page( ...@@ -599,7 +603,7 @@ static int ib_umem_odp_map_dma_single_page(
if (remove_existing_mapping && umem->context->invalidate_range) { if (remove_existing_mapping && umem->context->invalidate_range) {
invalidate_page_trampoline( invalidate_page_trampoline(
umem, umem_odp,
ib_umem_start(umem) + (page_index >> umem->page_shift), ib_umem_start(umem) + (page_index >> umem->page_shift),
ib_umem_start(umem) + ((page_index + 1) >> ib_umem_start(umem) + ((page_index + 1) >>
umem->page_shift), umem->page_shift),
...@@ -615,7 +619,7 @@ static int ib_umem_odp_map_dma_single_page( ...@@ -615,7 +619,7 @@ static int ib_umem_odp_map_dma_single_page(
* *
* Pins the range of pages passed in the argument, and maps them to * Pins the range of pages passed in the argument, and maps them to
* DMA addresses. The DMA addresses of the mapped pages is updated in * DMA addresses. The DMA addresses of the mapped pages is updated in
* umem->odp_data->dma_list. * umem_odp->dma_list.
* *
* Returns the number of pages mapped in success, negative error code * Returns the number of pages mapped in success, negative error code
* for failure. * for failure.
...@@ -623,7 +627,7 @@ static int ib_umem_odp_map_dma_single_page( ...@@ -623,7 +627,7 @@ static int ib_umem_odp_map_dma_single_page(
* the function from completing its task. * the function from completing its task.
* An -ENOENT error code indicates that userspace process is being terminated * An -ENOENT error code indicates that userspace process is being terminated
* and mm was already destroyed. * and mm was already destroyed.
* @umem: the umem to map and pin * @umem_odp: the umem to map and pin
* @user_virt: the address from which we need to map. * @user_virt: the address from which we need to map.
* @bcnt: the minimal number of bytes to pin and map. The mapping might be * @bcnt: the minimal number of bytes to pin and map. The mapping might be
* bigger due to alignment, and may also be smaller in case of an error * bigger due to alignment, and may also be smaller in case of an error
...@@ -633,11 +637,13 @@ static int ib_umem_odp_map_dma_single_page( ...@@ -633,11 +637,13 @@ static int ib_umem_odp_map_dma_single_page(
* range. * range.
* @current_seq: the MMU notifiers sequance value for synchronization with * @current_seq: the MMU notifiers sequance value for synchronization with
* invalidations. the sequance number is read from * invalidations. the sequance number is read from
* umem->odp_data->notifiers_seq before calling this function * umem_odp->notifiers_seq before calling this function
*/ */
int ib_umem_odp_map_dma_pages(struct ib_umem *umem, u64 user_virt, u64 bcnt, int ib_umem_odp_map_dma_pages(struct ib_umem_odp *umem_odp, u64 user_virt,
u64 access_mask, unsigned long current_seq) u64 bcnt, u64 access_mask,
unsigned long current_seq)
{ {
struct ib_umem *umem = umem_odp->umem;
struct task_struct *owning_process = NULL; struct task_struct *owning_process = NULL;
struct mm_struct *owning_mm = NULL; struct mm_struct *owning_mm = NULL;
struct page **local_page_list = NULL; struct page **local_page_list = NULL;
...@@ -703,7 +709,7 @@ int ib_umem_odp_map_dma_pages(struct ib_umem *umem, u64 user_virt, u64 bcnt, ...@@ -703,7 +709,7 @@ int ib_umem_odp_map_dma_pages(struct ib_umem *umem, u64 user_virt, u64 bcnt,
break; break;
bcnt -= min_t(size_t, npages << PAGE_SHIFT, bcnt); bcnt -= min_t(size_t, npages << PAGE_SHIFT, bcnt);
mutex_lock(&umem->odp_data->umem_mutex); mutex_lock(&umem_odp->umem_mutex);
for (j = 0; j < npages; j++, user_virt += PAGE_SIZE) { for (j = 0; j < npages; j++, user_virt += PAGE_SIZE) {
if (user_virt & ~page_mask) { if (user_virt & ~page_mask) {
p += PAGE_SIZE; p += PAGE_SIZE;
...@@ -716,7 +722,7 @@ int ib_umem_odp_map_dma_pages(struct ib_umem *umem, u64 user_virt, u64 bcnt, ...@@ -716,7 +722,7 @@ int ib_umem_odp_map_dma_pages(struct ib_umem *umem, u64 user_virt, u64 bcnt,
} }
ret = ib_umem_odp_map_dma_single_page( ret = ib_umem_odp_map_dma_single_page(
umem, k, local_page_list[j], umem_odp, k, local_page_list[j],
access_mask, current_seq); access_mask, current_seq);
if (ret < 0) if (ret < 0)
break; break;
...@@ -724,7 +730,7 @@ int ib_umem_odp_map_dma_pages(struct ib_umem *umem, u64 user_virt, u64 bcnt, ...@@ -724,7 +730,7 @@ int ib_umem_odp_map_dma_pages(struct ib_umem *umem, u64 user_virt, u64 bcnt,
p = page_to_phys(local_page_list[j]); p = page_to_phys(local_page_list[j]);
k++; k++;
} }
mutex_unlock(&umem->odp_data->umem_mutex); mutex_unlock(&umem_odp->umem_mutex);
if (ret < 0) { if (ret < 0) {
/* Release left over pages when handling errors. */ /* Release left over pages when handling errors. */
...@@ -750,9 +756,10 @@ int ib_umem_odp_map_dma_pages(struct ib_umem *umem, u64 user_virt, u64 bcnt, ...@@ -750,9 +756,10 @@ int ib_umem_odp_map_dma_pages(struct ib_umem *umem, u64 user_virt, u64 bcnt,
} }
EXPORT_SYMBOL(ib_umem_odp_map_dma_pages); EXPORT_SYMBOL(ib_umem_odp_map_dma_pages);
void ib_umem_odp_unmap_dma_pages(struct ib_umem *umem, u64 virt, void ib_umem_odp_unmap_dma_pages(struct ib_umem_odp *umem_odp, u64 virt,
u64 bound) u64 bound)
{ {
struct ib_umem *umem = umem_odp->umem;
int idx; int idx;
u64 addr; u64 addr;
struct ib_device *dev = umem->context->device; struct ib_device *dev = umem->context->device;
...@@ -764,12 +771,12 @@ void ib_umem_odp_unmap_dma_pages(struct ib_umem *umem, u64 virt, ...@@ -764,12 +771,12 @@ void ib_umem_odp_unmap_dma_pages(struct ib_umem *umem, u64 virt,
* faults from completion. We might be racing with other * faults from completion. We might be racing with other
* invalidations, so we must make sure we free each page only * invalidations, so we must make sure we free each page only
* once. */ * once. */
mutex_lock(&umem->odp_data->umem_mutex); mutex_lock(&umem_odp->umem_mutex);
for (addr = virt; addr < bound; addr += BIT(umem->page_shift)) { for (addr = virt; addr < bound; addr += BIT(umem->page_shift)) {
idx = (addr - ib_umem_start(umem)) >> umem->page_shift; idx = (addr - ib_umem_start(umem)) >> umem->page_shift;
if (umem->odp_data->page_list[idx]) { if (umem_odp->page_list[idx]) {
struct page *page = umem->odp_data->page_list[idx]; struct page *page = umem_odp->page_list[idx];
dma_addr_t dma = umem->odp_data->dma_list[idx]; dma_addr_t dma = umem_odp->dma_list[idx];
dma_addr_t dma_addr = dma & ODP_DMA_ADDR_MASK; dma_addr_t dma_addr = dma & ODP_DMA_ADDR_MASK;
WARN_ON(!dma_addr); WARN_ON(!dma_addr);
...@@ -792,12 +799,12 @@ void ib_umem_odp_unmap_dma_pages(struct ib_umem *umem, u64 virt, ...@@ -792,12 +799,12 @@ void ib_umem_odp_unmap_dma_pages(struct ib_umem *umem, u64 virt,
/* on demand pinning support */ /* on demand pinning support */
if (!umem->context->invalidate_range) if (!umem->context->invalidate_range)
put_page(page); put_page(page);
umem->odp_data->page_list[idx] = NULL; umem_odp->page_list[idx] = NULL;
umem->odp_data->dma_list[idx] = 0; umem_odp->dma_list[idx] = 0;
umem->npages--; umem->npages--;
} }
} }
mutex_unlock(&umem->odp_data->umem_mutex); mutex_unlock(&umem_odp->umem_mutex);
} }
EXPORT_SYMBOL(ib_umem_odp_unmap_dma_pages); EXPORT_SYMBOL(ib_umem_odp_unmap_dma_pages);
...@@ -824,7 +831,7 @@ int rbt_ib_umem_for_each_in_range(struct rb_root_cached *root, ...@@ -824,7 +831,7 @@ int rbt_ib_umem_for_each_in_range(struct rb_root_cached *root,
return -EAGAIN; return -EAGAIN;
next = rbt_ib_umem_iter_next(node, start, last - 1); next = rbt_ib_umem_iter_next(node, start, last - 1);
umem = container_of(node, struct ib_umem_odp, interval_tree); umem = container_of(node, struct ib_umem_odp, interval_tree);
ret_val = cb(umem->umem, start, last, cookie) || ret_val; ret_val = cb(umem, start, last, cookie) || ret_val;
} }
return ret_val; return ret_val;
......
...@@ -1150,7 +1150,7 @@ void mlx5_ib_pfault(struct mlx5_core_dev *mdev, void *context, ...@@ -1150,7 +1150,7 @@ void mlx5_ib_pfault(struct mlx5_core_dev *mdev, void *context,
int mlx5_ib_odp_init_one(struct mlx5_ib_dev *ibdev); int mlx5_ib_odp_init_one(struct mlx5_ib_dev *ibdev);
int __init mlx5_ib_odp_init(void); int __init mlx5_ib_odp_init(void);
void mlx5_ib_odp_cleanup(void); void mlx5_ib_odp_cleanup(void);
void mlx5_ib_invalidate_range(struct ib_umem *umem, unsigned long start, void mlx5_ib_invalidate_range(struct ib_umem_odp *umem_odp, unsigned long start,
unsigned long end); unsigned long end);
void mlx5_odp_init_mr_cache_entry(struct mlx5_cache_ent *ent); void mlx5_odp_init_mr_cache_entry(struct mlx5_cache_ent *ent);
void mlx5_odp_populate_klm(struct mlx5_klm *pklm, size_t offset, void mlx5_odp_populate_klm(struct mlx5_klm *pklm, size_t offset,
......
...@@ -1631,7 +1631,8 @@ static void dereg_mr(struct mlx5_ib_dev *dev, struct mlx5_ib_mr *mr) ...@@ -1631,7 +1631,8 @@ static void dereg_mr(struct mlx5_ib_dev *dev, struct mlx5_ib_mr *mr)
synchronize_srcu(&dev->mr_srcu); synchronize_srcu(&dev->mr_srcu);
/* Destroy all page mappings */ /* Destroy all page mappings */
if (umem->odp_data->page_list) if (umem->odp_data->page_list)
mlx5_ib_invalidate_range(umem, ib_umem_start(umem), mlx5_ib_invalidate_range(to_ib_umem_odp(umem),
ib_umem_start(umem),
ib_umem_end(umem)); ib_umem_end(umem));
else else
mlx5_ib_free_implicit_mr(mr); mlx5_ib_free_implicit_mr(mr);
......
...@@ -170,22 +170,24 @@ static void mr_leaf_free_action(struct work_struct *work) ...@@ -170,22 +170,24 @@ static void mr_leaf_free_action(struct work_struct *work)
wake_up(&imr->q_leaf_free); wake_up(&imr->q_leaf_free);
} }
void mlx5_ib_invalidate_range(struct ib_umem *umem, unsigned long start, void mlx5_ib_invalidate_range(struct ib_umem_odp *umem_odp, unsigned long start,
unsigned long end) unsigned long end)
{ {
struct mlx5_ib_mr *mr; struct mlx5_ib_mr *mr;
const u64 umr_block_mask = (MLX5_UMR_MTT_ALIGNMENT / const u64 umr_block_mask = (MLX5_UMR_MTT_ALIGNMENT /
sizeof(struct mlx5_mtt)) - 1; sizeof(struct mlx5_mtt)) - 1;
u64 idx = 0, blk_start_idx = 0; u64 idx = 0, blk_start_idx = 0;
struct ib_umem *umem;
int in_block = 0; int in_block = 0;
u64 addr; u64 addr;
if (!umem || !umem->odp_data) { if (!umem_odp) {
pr_err("invalidation called on NULL umem or non-ODP umem\n"); pr_err("invalidation called on NULL umem or non-ODP umem\n");
return; return;
} }
umem = umem_odp->umem;
mr = umem->odp_data->private; mr = umem_odp->private;
if (!mr || !mr->ibmr.pd) if (!mr || !mr->ibmr.pd)
return; return;
...@@ -208,7 +210,7 @@ void mlx5_ib_invalidate_range(struct ib_umem *umem, unsigned long start, ...@@ -208,7 +210,7 @@ void mlx5_ib_invalidate_range(struct ib_umem *umem, unsigned long start,
* estimate the cost of another UMR vs. the cost of bigger * estimate the cost of another UMR vs. the cost of bigger
* UMR. * UMR.
*/ */
if (umem->odp_data->dma_list[idx] & if (umem_odp->dma_list[idx] &
(ODP_READ_ALLOWED_BIT | ODP_WRITE_ALLOWED_BIT)) { (ODP_READ_ALLOWED_BIT | ODP_WRITE_ALLOWED_BIT)) {
if (!in_block) { if (!in_block) {
blk_start_idx = idx; blk_start_idx = idx;
...@@ -237,13 +239,13 @@ void mlx5_ib_invalidate_range(struct ib_umem *umem, unsigned long start, ...@@ -237,13 +239,13 @@ void mlx5_ib_invalidate_range(struct ib_umem *umem, unsigned long start,
* needed. * needed.
*/ */
ib_umem_odp_unmap_dma_pages(umem, start, end); ib_umem_odp_unmap_dma_pages(umem_odp, start, end);
if (unlikely(!umem->npages && mr->parent && if (unlikely(!umem->npages && mr->parent &&
!umem->odp_data->dying)) { !umem_odp->dying)) {
WRITE_ONCE(umem->odp_data->dying, 1); WRITE_ONCE(umem_odp->dying, 1);
atomic_inc(&mr->parent->num_leaf_free); atomic_inc(&mr->parent->num_leaf_free);
schedule_work(&umem->odp_data->work); schedule_work(&umem_odp->work);
} }
} }
...@@ -372,7 +374,6 @@ static struct ib_umem_odp *implicit_mr_get_data(struct mlx5_ib_mr *mr, ...@@ -372,7 +374,6 @@ static struct ib_umem_odp *implicit_mr_get_data(struct mlx5_ib_mr *mr,
u64 addr = io_virt & MLX5_IMR_MTT_MASK; u64 addr = io_virt & MLX5_IMR_MTT_MASK;
int nentries = 0, start_idx = 0, ret; int nentries = 0, start_idx = 0, ret;
struct mlx5_ib_mr *mtt; struct mlx5_ib_mr *mtt;
struct ib_umem *umem;
mutex_lock(&mr->umem->odp_data->umem_mutex); mutex_lock(&mr->umem->odp_data->umem_mutex);
odp = odp_lookup(ctx, addr, 1, mr); odp = odp_lookup(ctx, addr, 1, mr);
...@@ -385,22 +386,22 @@ static struct ib_umem_odp *implicit_mr_get_data(struct mlx5_ib_mr *mr, ...@@ -385,22 +386,22 @@ static struct ib_umem_odp *implicit_mr_get_data(struct mlx5_ib_mr *mr,
if (nentries) if (nentries)
nentries++; nentries++;
} else { } else {
umem = ib_alloc_odp_umem(ctx, addr, MLX5_IMR_MTT_SIZE); odp = ib_alloc_odp_umem(ctx, addr, MLX5_IMR_MTT_SIZE);
if (IS_ERR(umem)) { if (IS_ERR(odp)) {
mutex_unlock(&mr->umem->odp_data->umem_mutex); mutex_unlock(&mr->umem->odp_data->umem_mutex);
return ERR_CAST(umem); return ERR_CAST(odp);
} }
mtt = implicit_mr_alloc(mr->ibmr.pd, umem, 0, mr->access_flags); mtt = implicit_mr_alloc(mr->ibmr.pd, odp->umem, 0,
mr->access_flags);
if (IS_ERR(mtt)) { if (IS_ERR(mtt)) {
mutex_unlock(&mr->umem->odp_data->umem_mutex); mutex_unlock(&mr->umem->odp_data->umem_mutex);
ib_umem_release(umem); ib_umem_release(odp->umem);
return ERR_CAST(mtt); return ERR_CAST(mtt);
} }
odp = umem->odp_data;
odp->private = mtt; odp->private = mtt;
mtt->umem = umem; mtt->umem = odp->umem;
mtt->mmkey.iova = addr; mtt->mmkey.iova = addr;
mtt->parent = mr; mtt->parent = mr;
INIT_WORK(&odp->work, mr_leaf_free_action); INIT_WORK(&odp->work, mr_leaf_free_action);
...@@ -460,24 +461,24 @@ struct mlx5_ib_mr *mlx5_ib_alloc_implicit_mr(struct mlx5_ib_pd *pd, ...@@ -460,24 +461,24 @@ struct mlx5_ib_mr *mlx5_ib_alloc_implicit_mr(struct mlx5_ib_pd *pd,
return imr; return imr;
} }
static int mr_leaf_free(struct ib_umem *umem, u64 start, static int mr_leaf_free(struct ib_umem_odp *umem_odp, u64 start, u64 end,
u64 end, void *cookie) void *cookie)
{ {
struct mlx5_ib_mr *mr = umem->odp_data->private, *imr = cookie; struct mlx5_ib_mr *mr = umem_odp->private, *imr = cookie;
struct ib_umem *umem = umem_odp->umem;
if (mr->parent != imr) if (mr->parent != imr)
return 0; return 0;
ib_umem_odp_unmap_dma_pages(umem, ib_umem_odp_unmap_dma_pages(umem_odp, ib_umem_start(umem),
ib_umem_start(umem),
ib_umem_end(umem)); ib_umem_end(umem));
if (umem->odp_data->dying) if (umem_odp->dying)
return 0; return 0;
WRITE_ONCE(umem->odp_data->dying, 1); WRITE_ONCE(umem_odp->dying, 1);
atomic_inc(&imr->num_leaf_free); atomic_inc(&imr->num_leaf_free);
schedule_work(&umem->odp_data->work); schedule_work(&umem_odp->work);
return 0; return 0;
} }
...@@ -533,7 +534,7 @@ static int pagefault_mr(struct mlx5_ib_dev *dev, struct mlx5_ib_mr *mr, ...@@ -533,7 +534,7 @@ static int pagefault_mr(struct mlx5_ib_dev *dev, struct mlx5_ib_mr *mr,
*/ */
smp_rmb(); smp_rmb();
ret = ib_umem_odp_map_dma_pages(mr->umem, io_virt, size, ret = ib_umem_odp_map_dma_pages(to_ib_umem_odp(mr->umem), io_virt, size,
access_mask, current_seq); access_mask, current_seq);
if (ret < 0) if (ret < 0)
...@@ -542,7 +543,8 @@ static int pagefault_mr(struct mlx5_ib_dev *dev, struct mlx5_ib_mr *mr, ...@@ -542,7 +543,8 @@ static int pagefault_mr(struct mlx5_ib_dev *dev, struct mlx5_ib_mr *mr,
np = ret; np = ret;
mutex_lock(&odp->umem_mutex); mutex_lock(&odp->umem_mutex);
if (!ib_umem_mmu_notifier_retry(mr->umem, current_seq)) { if (!ib_umem_mmu_notifier_retry(to_ib_umem_odp(mr->umem),
current_seq)) {
/* /*
* No need to check whether the MTTs really belong to * No need to check whether the MTTs really belong to
* this MR, since ib_umem_odp_map_dma_pages already * this MR, since ib_umem_odp_map_dma_pages already
......
...@@ -82,15 +82,18 @@ struct ib_umem_odp { ...@@ -82,15 +82,18 @@ struct ib_umem_odp {
struct work_struct work; struct work_struct work;
}; };
static inline struct ib_umem_odp *to_ib_umem_odp(struct ib_umem *umem)
{
return umem->odp_data;
}
#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
int ib_umem_odp_get(struct ib_ucontext *context, struct ib_umem *umem, int ib_umem_odp_get(struct ib_ucontext *context, struct ib_umem *umem,
int access); int access);
struct ib_umem *ib_alloc_odp_umem(struct ib_ucontext *context, struct ib_umem_odp *ib_alloc_odp_umem(struct ib_ucontext *context,
unsigned long addr, unsigned long addr, size_t size);
size_t size); void ib_umem_odp_release(struct ib_umem_odp *umem_odp);
void ib_umem_odp_release(struct ib_umem *umem);
/* /*
* The lower 2 bits of the DMA address signal the R/W permissions for * The lower 2 bits of the DMA address signal the R/W permissions for
...@@ -105,13 +108,14 @@ void ib_umem_odp_release(struct ib_umem *umem); ...@@ -105,13 +108,14 @@ void ib_umem_odp_release(struct ib_umem *umem);
#define ODP_DMA_ADDR_MASK (~(ODP_READ_ALLOWED_BIT | ODP_WRITE_ALLOWED_BIT)) #define ODP_DMA_ADDR_MASK (~(ODP_READ_ALLOWED_BIT | ODP_WRITE_ALLOWED_BIT))
int ib_umem_odp_map_dma_pages(struct ib_umem *umem, u64 start_offset, u64 bcnt, int ib_umem_odp_map_dma_pages(struct ib_umem_odp *umem_odp, u64 start_offset,
u64 access_mask, unsigned long current_seq); u64 bcnt, u64 access_mask,
unsigned long current_seq);
void ib_umem_odp_unmap_dma_pages(struct ib_umem *umem, u64 start_offset, void ib_umem_odp_unmap_dma_pages(struct ib_umem_odp *umem_odp, u64 start_offset,
u64 bound); u64 bound);
typedef int (*umem_call_back)(struct ib_umem *item, u64 start, u64 end, typedef int (*umem_call_back)(struct ib_umem_odp *item, u64 start, u64 end,
void *cookie); void *cookie);
/* /*
* Call the callback on each ib_umem in the range. Returns the logical or of * Call the callback on each ib_umem in the range. Returns the logical or of
...@@ -129,25 +133,25 @@ int rbt_ib_umem_for_each_in_range(struct rb_root_cached *root, ...@@ -129,25 +133,25 @@ int rbt_ib_umem_for_each_in_range(struct rb_root_cached *root,
struct ib_umem_odp *rbt_ib_umem_lookup(struct rb_root_cached *root, struct ib_umem_odp *rbt_ib_umem_lookup(struct rb_root_cached *root,
u64 addr, u64 length); u64 addr, u64 length);
static inline int ib_umem_mmu_notifier_retry(struct ib_umem *item, static inline int ib_umem_mmu_notifier_retry(struct ib_umem_odp *umem_odp,
unsigned long mmu_seq) unsigned long mmu_seq)
{ {
/* /*
* This code is strongly based on the KVM code from * This code is strongly based on the KVM code from
* mmu_notifier_retry. Should be called with * mmu_notifier_retry. Should be called with
* the relevant locks taken (item->odp_data->umem_mutex * the relevant locks taken (umem_odp->umem_mutex
* and the ucontext umem_mutex semaphore locked for read). * and the ucontext umem_mutex semaphore locked for read).
*/ */
/* Do not allow page faults while the new ib_umem hasn't seen a state /* Do not allow page faults while the new ib_umem hasn't seen a state
* with zero notifiers yet, and doesn't have its own valid set of * with zero notifiers yet, and doesn't have its own valid set of
* private counters. */ * private counters. */
if (!item->odp_data->mn_counters_active) if (!umem_odp->mn_counters_active)
return 1; return 1;
if (unlikely(item->odp_data->notifiers_count)) if (unlikely(umem_odp->notifiers_count))
return 1; return 1;
if (item->odp_data->notifiers_seq != mmu_seq) if (umem_odp->notifiers_seq != mmu_seq)
return 1; return 1;
return 0; return 0;
} }
...@@ -161,14 +165,13 @@ static inline int ib_umem_odp_get(struct ib_ucontext *context, ...@@ -161,14 +165,13 @@ static inline int ib_umem_odp_get(struct ib_ucontext *context,
return -EINVAL; return -EINVAL;
} }
static inline struct ib_umem *ib_alloc_odp_umem(struct ib_ucontext *context, static inline struct ib_umem_odp *
unsigned long addr, ib_alloc_odp_umem(struct ib_ucontext *context, unsigned long addr, size_t size)
size_t size)
{ {
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
} }
static inline void ib_umem_odp_release(struct ib_umem *umem) {} static inline void ib_umem_odp_release(struct ib_umem_odp *umem_odp) {}
#endif /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */ #endif /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */
......
...@@ -69,6 +69,8 @@ ...@@ -69,6 +69,8 @@
#define IB_FW_VERSION_NAME_MAX ETHTOOL_FWVERS_LEN #define IB_FW_VERSION_NAME_MAX ETHTOOL_FWVERS_LEN
struct ib_umem_odp;
extern struct workqueue_struct *ib_wq; extern struct workqueue_struct *ib_wq;
extern struct workqueue_struct *ib_comp_wq; extern struct workqueue_struct *ib_comp_wq;
extern struct workqueue_struct *ib_comp_unbound_wq; extern struct workqueue_struct *ib_comp_unbound_wq;
...@@ -1506,7 +1508,7 @@ struct ib_ucontext { ...@@ -1506,7 +1508,7 @@ struct ib_ucontext {
* mmu notifiers registration. * mmu notifiers registration.
*/ */
struct rw_semaphore umem_rwsem; struct rw_semaphore umem_rwsem;
void (*invalidate_range)(struct ib_umem *umem, void (*invalidate_range)(struct ib_umem_odp *umem_odp,
unsigned long start, unsigned long end); unsigned long start, unsigned long end);
struct mmu_notifier mn; struct mmu_notifier mn;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment