|
7 | 7 | * reserved. |
8 | 8 | * Copyright (c) 2020-2021 Google, LLC. All rights reserved. |
9 | 9 | * Copyright (c) 2021 Nanook Consulting. All rights reserved. |
10 | | - * Copyright (c) 2022-2023 Computer Architecture and VLSI Systems (CARV) |
| 10 | + * Copyright (c) 2022-2025 Computer Architecture and VLSI Systems (CARV) |
11 | 11 | * Laboratory, ICS Forth. All rights reserved. |
12 | 12 | * $COPYRIGHT$ |
13 | 13 | * |
@@ -245,26 +245,46 @@ void mca_smsc_xpmem_unmap_peer_region(void *ctx) |
245 | 245 |
|
246 | 246 | static int mca_smsc_xpmem_endpoint_rcache_entry_cleanup(mca_rcache_base_registration_t *reg, void *ctx) |
247 | 247 | { |
248 | | - // See respective comment in mca_smsc_xpmem_map_peer_region |
249 | | - if (!(MCA_RCACHE_FLAGS_PERSIST & reg->flags)) |
250 | | - opal_atomic_add(®->ref_count, 1); |
251 | | - |
252 | | - mca_smsc_xpmem_unmap_peer_region(reg); |
| 248 | + /* We aren't allowed to delete registrations inside iterate's |
| 249 | + * callback. Add them to a list to delete right after. */ |
| 250 | + opal_list_append((opal_list_t *) ctx, ®->super.super); |
253 | 251 | return OPAL_SUCCESS; |
254 | 252 | } |
255 | 253 |
|
256 | 254 | static void mca_smsc_xpmem_cleanup_endpoint(mca_smsc_xpmem_endpoint_t *endpoint) |
257 | 255 | { |
| 256 | + mca_rcache_base_registration_t *reg; |
| 257 | + opal_list_t registrations; |
| 258 | + |
258 | 259 | opal_output_verbose(MCA_BASE_VERBOSE_INFO, opal_smsc_base_framework.framework_output, |
259 | 260 | "mca_smsc_xpmem_cleanup_endpoint: cleaning up endpoint %p", (void *) endpoint); |
260 | 261 |
|
261 | | - opal_output_verbose(MCA_BASE_VERBOSE_INFO, opal_smsc_base_framework.framework_output, |
262 | | - "mca_smsc_xpmem_cleanup_endpoint: deleting %" PRIsize_t " region mappings", |
263 | | - endpoint->vma_module->tree.tree_size); |
| 262 | + OBJ_CONSTRUCT(®istrations, opal_list_t); |
264 | 263 |
|
265 | 264 | /* clean out the registration cache */ |
266 | 265 | (void) mca_rcache_base_vma_iterate(endpoint->vma_module, NULL, (size_t) -1, true, |
267 | | - mca_smsc_xpmem_endpoint_rcache_entry_cleanup, NULL); |
| 266 | + mca_smsc_xpmem_endpoint_rcache_entry_cleanup, |
| 267 | + ®istrations); |
| 268 | + |
| 269 | + opal_output_verbose(MCA_BASE_VERBOSE_INFO, opal_smsc_base_framework.framework_output, |
| 270 | + "mca_smsc_xpmem_cleanup_endpoint: deleting %" PRIsize_t " region mappings", |
| 271 | + opal_list_get_size(®istrations)); |
| 272 | + |
| 273 | + while (NULL != (reg = (mca_rcache_base_registration_t *) |
| 274 | + opal_list_remove_first(®istrations))) { |
| 275 | + |
| 276 | + /* We shouldn't find any non-persistent regs during cleanup. Assuming correct |
| 277 | + * usage, they should have already been unmapped and therefore removed from |
| 278 | + * the tree. Nevertheless, keep with the custom (see respective comments in |
| 279 | + * map_peer_region()) and add an extra reference before calling unmap? */ |
| 280 | + if (!(MCA_RCACHE_FLAGS_PERSIST & reg->flags)) { |
| 281 | + opal_atomic_add(®->ref_count, 1); |
| 282 | + } |
| 283 | + |
| 284 | + mca_smsc_xpmem_unmap_peer_region(reg); |
| 285 | + } |
| 286 | + |
| 287 | + OBJ_DESTRUCT(®istrations); |
268 | 288 |
|
269 | 289 | OBJ_RELEASE(endpoint->vma_module); |
270 | 290 | xpmem_release(endpoint->apid); |
|
0 commit comments