Skip to content

Commit 360b2b1

Browse files
authored
Merge pull request #10127 from devreal/smsc-xpmem-fixes
smsc/xpmem: alignment and stack memory space
2 parents 404b812 + 4201c94 commit 360b2b1

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

opal/mca/smsc/xpmem/smsc_xpmem_module.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "opal/mca/smsc/base/base.h"
2424
#include "opal/mca/smsc/xpmem/smsc_xpmem_internal.h"
2525
#include "opal/util/minmax.h"
26+
#include "opal/util/sys_limits.h"
2627

2728
OBJ_CLASS_INSTANCE(mca_smsc_xpmem_endpoint_t, opal_object_t, NULL, NULL);
2829

@@ -116,7 +117,7 @@ void *mca_smsc_xpmem_map_peer_region(mca_smsc_endpoint_t *endpoint, uint64_t fla
116117
int rc;
117118

118119
base = OPAL_DOWN_ALIGN((uintptr_t) remote_ptr, attach_align, uintptr_t);
119-
bound = OPAL_ALIGN((uintptr_t) remote_ptr + size - 1, attach_align, uintptr_t) + 1;
120+
bound = OPAL_ALIGN((uintptr_t) remote_ptr + size, attach_align, uintptr_t);
120121
if (OPAL_UNLIKELY(bound > xpmem_endpoint->address_max)) {
121122
bound = xpmem_endpoint->address_max;
122123
}
@@ -157,8 +158,14 @@ void *mca_smsc_xpmem_map_peer_region(mca_smsc_endpoint_t *endpoint, uint64_t fla
157158

158159
reg->rcache_context = xpmem_attach(xpmem_addr, bound - base, NULL);
159160
if (OPAL_UNLIKELY((void *) -1 == reg->rcache_context)) {
160-
OBJ_RELEASE(reg);
161-
return NULL;
161+
/* retry with the page as upper bound */
162+
bound = OPAL_ALIGN((uintptr_t) remote_ptr + size, opal_getpagesize(), uintptr_t);
163+
reg->bound = (unsigned char *) bound;
164+
reg->rcache_context = xpmem_attach(xpmem_addr, bound - base, NULL);
165+
if (OPAL_UNLIKELY((void *) -1 == reg->rcache_context)) {
166+
OBJ_RELEASE(reg);
167+
return NULL;
168+
}
162169
}
163170

164171
opal_memchecker_base_mem_defined(reg->rcache_context, bound - base);
@@ -307,5 +314,5 @@ mca_smsc_xpmem_module_t mca_smsc_xpmem_module = {
307314
.copy_from = mca_smsc_xpmem_copy_from,
308315
.map_peer_region = mca_smsc_xpmem_map_peer_region,
309316
.unmap_peer_region = mca_smsc_xpmem_unmap_peer_region,
310-
},
317+
},
311318
};

0 commit comments

Comments
 (0)