libibverbs: Set vmr->access in ibv_cmd_reg_mr_ex()

[ Upstream commit 45c66ed5603b7a11491214fb3dc4a1d0b1626277 ]

ibv_cmd_reg_mr_ex() did not record the MR's access flags in vmr->access,
unlike ibv_cmd_reg_mr().  ibv_dereg_mr() decides whether to re-enable fork
tracking from verbs_get_mr(mr)->access:

    if (... && !(access & IBV_ACCESS_ON_DEMAND))
            ibv_dofork_range(addr, length);

With vmr->access left zero, an on-demand (ODP) MR registered through
ibv_reg_mr_ex() / ibv_cmd_reg_mr_ex() reads access == 0 at dereg, so
ibv_dofork_range() runs even though registration skipped the matching
ibv_dontfork_range() for ODP (need_fork = !(ON_DEMAND || FD)).  The
unbalanced dofork corrupts the fork-range accounting when ibv_fork_init()
is enabled.

Set vmr->access = mr_init_attr->access on the success path, mirroring
ibv_cmd_reg_mr(), so the dereg fork decision is correct.  (The write-ABI
fallback path already goes through ibv_cmd_reg_mr(), which sets it.)

Fixes: ca61708a8838 ("verbs: Add ibv_cmd_reg_mr_ex() to be used by drivers")
Signed-off-by: Yishai Hadas <yishaih@nvidia.com>
Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Nicolas Morey <nmorey@suse.com>
diff --git a/libibverbs/cmd_mr.c b/libibverbs/cmd_mr.c
index bf09532..f45ce39 100644
--- a/libibverbs/cmd_mr.c
+++ b/libibverbs/cmd_mr.c
@@ -235,6 +235,7 @@
 		vmr->mr_type = IBV_MR_TYPE_DMABUF_MR;
 	else
 		vmr->mr_type = IBV_MR_TYPE_MR;
+	vmr->access = mr_init_attr->access;
 
 	return 0;
 }