Skip to content

Commit

Permalink
smsc/xpmem: retry with page upper bound if aligned range cannot be ma…
Browse files Browse the repository at this point in the history
…pped

The aligned range computed in mca_smsc_xpmem_map_peer_region may
reach past the end of the stack, which may cause the mapping to fail.
Retrying with an actual page as upper bound has a better chance to succeed.

Signed-off-by: Joseph Schuchart <[email protected]>
  • Loading branch information
devreal committed Mar 18, 2022
1 parent 1440592 commit 70b7ee2
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions opal/mca/smsc/xpmem/smsc_xpmem_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "opal/mca/smsc/base/base.h"
#include "opal/mca/smsc/xpmem/smsc_xpmem_internal.h"
#include "opal/util/minmax.h"
#include "opal/util/sys_limits.h"

OBJ_CLASS_INSTANCE(mca_smsc_xpmem_endpoint_t, opal_object_t, NULL, NULL);

Expand Down Expand Up @@ -157,8 +158,14 @@ void *mca_smsc_xpmem_map_peer_region(mca_smsc_endpoint_t *endpoint, uint64_t fla

reg->rcache_context = xpmem_attach(xpmem_addr, bound - base, NULL);
if (OPAL_UNLIKELY((void *) -1 == reg->rcache_context)) {
OBJ_RELEASE(reg);
return NULL;
/* retry with the page as upper bound */
bound = OPAL_ALIGN((uintptr_t) remote_ptr + size, opal_getpagesize(), uintptr_t);
reg->bound = (unsigned char *) bound;
reg->rcache_context = xpmem_attach(xpmem_addr, bound - base, NULL);
if (OPAL_UNLIKELY((void *) -1 == reg->rcache_context)) {
OBJ_RELEASE(reg);
return NULL;
}
}

opal_memchecker_base_mem_defined(reg->rcache_context, bound - base);
Expand Down Expand Up @@ -307,5 +314,5 @@ mca_smsc_xpmem_module_t mca_smsc_xpmem_module = {
.copy_from = mca_smsc_xpmem_copy_from,
.map_peer_region = mca_smsc_xpmem_map_peer_region,
.unmap_peer_region = mca_smsc_xpmem_unmap_peer_region,
},
},
};

0 comments on commit 70b7ee2

Please sign in to comment.