Skip to content

Commit

Permalink
Merge pull request #10127 from devreal/smsc-xpmem-fixes
Browse files Browse the repository at this point in the history
smsc/xpmem: alignment and stack memory space
  • Loading branch information
devreal authored Nov 10, 2022
2 parents 404b812 + 4201c94 commit 360b2b1
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 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 @@ -116,7 +117,7 @@ void *mca_smsc_xpmem_map_peer_region(mca_smsc_endpoint_t *endpoint, uint64_t fla
int rc;

base = OPAL_DOWN_ALIGN((uintptr_t) remote_ptr, attach_align, uintptr_t);
bound = OPAL_ALIGN((uintptr_t) remote_ptr + size - 1, attach_align, uintptr_t) + 1;
bound = OPAL_ALIGN((uintptr_t) remote_ptr + size, attach_align, uintptr_t);
if (OPAL_UNLIKELY(bound > xpmem_endpoint->address_max)) {
bound = xpmem_endpoint->address_max;
}
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 360b2b1

Please sign in to comment.