FAILED: patch "[PATCH] RDMA: During rereg_mr ensure that REREG_ACCESS is compatible" failed to apply to 6.12-stable tree
Subsystems (7)
[email protected]
maintainerThe patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x badad6fad60def1b9805559dd81dbab3d97b82aa
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026061551-manor-verbalize-74cb@gregkh' --subject-prefix 'PATCH 6.12.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From badad6fad60def1b9805559dd81dbab3d97b82aa Mon Sep 17 00:00:00 2001
From: Jason Gunthorpe <[email protected]>
Date: Thu, 4 Jun 2026 15:03:13 -0300
Subject: [PATCH] RDMA: During rereg_mr ensure that REREG_ACCESS is compatible
If IB_MR_REREG_ACCESS changes from RO to RW then the umem has to be re-evaluated to ensure it is properly pinned as RW. Since the umem is hidden inside each driver's mr struct add a ib_umem_check_rereg() function that each driver has to call before processing IB_MR_REREG_ACCESS.
mlx4 has to retain its duplicate ib_access_writable check because it implements IB_MR_REREG_ACCESS | IB_MR_REREG_TRANS by changing both items in place sequentially while the MR is live, so it will continue to not support this combination.
drivers/infiniband/core/umem.c +16 -0
@@ -332,3 +332,19 @@ int ib_umem_copy_from(void *dst, struct ib_umem *umem, size_t offset,return 0 ; }EXPORT_SYMBOL (ib_umem_copy_from); + +/* +* Called during rereg mr if the driver is able to re-use a umem for +* IB_MR_REREG_ACCESS. +*/ +int ib_umem_check_rereg (struct ib_umem *umem,int flags,int new_access_flags) +{ +if (!umem) +return 0 ; + +if ((flags &IB_MR_REREG_ACCESS ) && !(flags &IB_MR_REREG_TRANS )) +if (ib_access_writable (new_access_flags) && !umem->writable) +return -EACCES ; +return 0 ; +} +EXPORT_SYMBOL (ib_umem_check_rereg);
drivers/infiniband/hw/hns/hns_roce_mr.c +4 -0
@@ -300,6 +300,10 @@ struct ib_mr *hns_roce_rereg_user_mr(struct ib_mr *ibmr, int flags, u64 start, goto err_out; } + ret =ib_umem_check_rereg (mr->pbl_mtr.umem, flags, mr_access_flags); +if (ret) + goto err_out; + mailbox =hns_roce_alloc_cmd_mailbox (hr_dev); ret =PTR_ERR_OR_ZERO (mailbox);if (ret)
drivers/infiniband/hw/irdma/verbs.c +4 -0
@@ -3803,6 +3803,10 @@ static struct ib_mr *irdma_rereg_user_mr(struct ib_mr *ib_mr, int flags,if (flags & ~(IB_MR_REREG_TRANS |IB_MR_REREG_PD |IB_MR_REREG_ACCESS ))return ERR_PTR (-EOPNOTSUPP ); + ret =ib_umem_check_rereg (iwmr->region, flags, new_access); +if (ret) +return ERR_PTR (ret); +if (dmabuf_revocable) { umem_dmabuf =to_ib_umem_dmabuf (iwmr->region);
drivers/infiniband/hw/mlx4/mr.c +4 -0
@@ -209,6 +209,10 @@ struct ib_mr *mlx4_ib_rereg_user_mr(struct ib_mr *mr, int flags, u64 start,struct mlx4_mpt_entry **pmpt_entry = &mpt_entry;int err; + err =ib_umem_check_rereg (mmr->umem, flags, mr_access_flags); +if (err) +return ERR_PTR (err); +/* Since we synchronize this call and mlx4_ib_dereg_mr via uverbs, * we assume that the calls can't run concurrently. Otherwise, a * race exists.
drivers/infiniband/hw/mlx5/mr.c +4 -0
@@ -1179,6 +1179,10 @@ struct ib_mr *mlx5_ib_rereg_user_mr(struct ib_mr *ib_mr, int flags, u64 start,if (flags & ~(IB_MR_REREG_TRANS |IB_MR_REREG_PD |IB_MR_REREG_ACCESS ))return ERR_PTR (-EOPNOTSUPP ); + err =ib_umem_check_rereg (mr->umem, flags, new_access_flags); +if (err) +return ERR_PTR (err); +if (!(flags &IB_MR_REREG_ACCESS )) new_access_flags = mr->access_flags;if (!(flags &IB_MR_REREG_PD ))
drivers/infiniband/sw/rxe/rxe_verbs.c +5 -0
@@ -1319,6 +1319,7 @@ static struct ib_mr *rxe_rereg_user_mr(struct ib_mr *ibmr, int flags,struct rxe_mr *mr =to_rmr (ibmr);struct rxe_pd *old_pd =to_rpd (ibmr->pd);struct rxe_pd *pd =to_rpd (ibpd); +int err;/* for now only support the two easy cases: * rereg_pd and rereg_access
@@ -1328,6 +1329,10 @@ static struct ib_mr *rxe_rereg_user_mr(struct ib_mr *ibmr, int flags,return ERR_PTR (-EOPNOTSUPP ); } + err =ib_umem_check_rereg (mr->umem, flags, access); +if (err) +return ERR_PTR (err); +if (flags &IB_MR_REREG_PD ) {rxe_put (old_pd);rxe_get (pd);
include/rdma/ib_umem.h +8 -0
@@ -156,6 +156,8 @@ void ib_umem_dmabuf_revoke_lock(struct ib_umem_dmabuf *umem_dmabuf);void ib_umem_dmabuf_revoke_unlock (struct ib_umem_dmabuf *umem_dmabuf);void ib_umem_dmabuf_revoke (struct ib_umem_dmabuf *umem_dmabuf); +int ib_umem_check_rereg (struct ib_umem *umem,int flags,int new_access_flags); +#else /* CONFIG_INFINIBAND_USER_MEM */ #include <linux/err.h>
@@ -230,5 +232,11 @@ static inline void ib_umem_dmabuf_revoke_lock(struct ib_umem_dmabuf *umem_dmabufstatic inline void ib_umem_dmabuf_revoke_unlock (struct ib_umem_dmabuf *umem_dmabuf) {}static inline void ib_umem_dmabuf_revoke (struct ib_umem_dmabuf *umem_dmabuf) {} +static inline int ib_umem_check_rereg (struct ib_umem *umem,int flags, +int new_access_flags) +{ +return -EOPNOTSUPP ; +} +#endif /* CONFIG_INFINIBAND_USER_MEM */ #endif /* IB_UMEM_H */
Sasha Levin
maintainerPATCH 1/4 RDMA/umem: Add ib_umem_dmabuf_get_pinned_and_lock helper
From: Jacob Moroni <[email protected]>
[ Upstream commit 553dfa8cbd0c6d36adae042d9738ddf8f8765ac7 ]
Move the inner logic of ib_umem_dmabuf_get_pinned_with_dma_device() to a new static function that returns with the lock held upon success.
The intent is to allow reuse for the future get_pinned_revocable_and_lock function.
Stable-dep-of: badad6fad60d ("RDMA: During rereg_mr ensure that REREG_ACCESS is compatible")
--- drivers/infiniband/core/umem_dmabuf.c | 35 ++++++++++++++++++++------- 1 file changed, 26 insertions(+), 9 deletions(-)
drivers/infiniband/core/umem_dmabuf.c +26 -9
@@ -198,18 +198,19 @@ static struct dma_buf_attach_ops ib_umem_dmabuf_attach_pinned_ops = { .move_notify = ib_umem_dmabuf_unsupported_move_notify, }; -struct ib_umem_dmabuf * -ib_umem_dmabuf_get_pinned_with_dma_device (struct ib_device *device, -struct device *dma_device, -unsigned long offset,size_t size, -int fd,int access) +static struct ib_umem_dmabuf * +ib_umem_dmabuf_get_pinned_and_lock (struct ib_device *device, +struct device *dma_device, +unsigned long offset, +size_t size,int fd,int access, +const struct dma_buf_attach_ops *ops) {struct ib_umem_dmabuf *umem_dmabuf;int err; - umem_dmabuf =ib_umem_dmabuf_get_with_dma_device (device, dma_device, offset, - size, fd, access, - &ib_umem_dmabuf_attach_pinned_ops); + umem_dmabuf = +ib_umem_dmabuf_get_with_dma_device (device, dma_device, offset, + size, fd, access, ops);if (IS_ERR (umem_dmabuf))return umem_dmabuf;
@@ -222,7 +223,6 @@ ib_umem_dmabuf_get_pinned_with_dma_device(struct ib_device *device, err =ib_umem_dmabuf_map_pages (umem_dmabuf);if (err) goto err_release; -dma_resv_unlock (umem_dmabuf->attach->dmabuf->resv);return umem_dmabuf;
@@ -231,6 +231,23 @@ ib_umem_dmabuf_get_pinned_with_dma_device(struct ib_device *device,ib_umem_release (&umem_dmabuf->umem);return ERR_PTR (err); } + +struct ib_umem_dmabuf * +ib_umem_dmabuf_get_pinned_with_dma_device (struct ib_device *device, +struct device *dma_device, +unsigned long offset,size_t size, +int fd,int access) +{ +struct ib_umem_dmabuf *umem_dmabuf = +ib_umem_dmabuf_get_pinned_and_lock (device, dma_device, offset, + size, fd, access, + &ib_umem_dmabuf_attach_pinned_ops); +if (IS_ERR (umem_dmabuf)) +return umem_dmabuf; + +dma_resv_unlock (umem_dmabuf->attach->dmabuf->resv); +return umem_dmabuf; +}EXPORT_SYMBOL (ib_umem_dmabuf_get_pinned_with_dma_device); struct ib_umem_dmabuf *ib_umem_dmabuf_get_pinned(struct ib_device *device,
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/4 RDMA/umem: Move umem dmabuf revoke logic into helper function
From: Jacob Moroni <[email protected]>
[ Upstream commit 797291a66ce346c96114b72222fc290d402da005 ]
This same logic will eventually be reused from within the invalidate_mappings callback which already has the dma_resv_lock held, so break it out into a separate function so it can be reused.
Stable-dep-of: badad6fad60d ("RDMA: During rereg_mr ensure that REREG_ACCESS is compatible")
--- drivers/infiniband/core/umem_dmabuf.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-)
drivers/infiniband/core/umem_dmabuf.c +17 -9
@@ -198,6 +198,22 @@ static struct dma_buf_attach_ops ib_umem_dmabuf_attach_pinned_ops = { .move_notify = ib_umem_dmabuf_unsupported_move_notify, }; +static void ib_umem_dmabuf_revoke_locked (struct dma_buf_attachment *attach) +{ +struct ib_umem_dmabuf *umem_dmabuf = attach->importer_priv; + +dma_resv_assert_held (attach->dmabuf->resv); + +if (umem_dmabuf->revoked) +return ; +ib_umem_dmabuf_unmap_pages (umem_dmabuf); +if (umem_dmabuf->pinned) { +dma_buf_unpin (umem_dmabuf->attach); + umem_dmabuf->pinned =0 ; + } + umem_dmabuf->revoked =1 ; +} +static struct ib_umem_dmabuf * ib_umem_dmabuf_get_pinned_and_lock(struct ib_device *device, struct device *dma_device,
@@ -265,15 +281,7 @@ void ib_umem_dmabuf_revoke(struct ib_umem_dmabuf *umem_dmabuf)struct dma_buf *dmabuf = umem_dmabuf->attach->dmabuf;dma_resv_lock (dmabuf->resv,NULL ); -if (umem_dmabuf->revoked) - goto end; -ib_umem_dmabuf_unmap_pages (umem_dmabuf); -if (umem_dmabuf->pinned) { -dma_buf_unpin (umem_dmabuf->attach); - umem_dmabuf->pinned =0 ; - } - umem_dmabuf->revoked =1 ; -end: +ib_umem_dmabuf_revoke_locked (umem_dmabuf->attach);dma_resv_unlock (dmabuf->resv); }EXPORT_SYMBOL (ib_umem_dmabuf_revoke);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/4 RDMA/umem: Add helpers for umem dmabuf revoke lock
In reply to Sasha LevinFrom: Jacob Moroni <[email protected]>
[ Upstream commit 3a0b171302eea1732a168e26db3b8461f51cc1f9 ]
Added helpers to acquire and release the umem dmabuf revoke lock. The intent is to avoid the need for drivers to peek into the ib_umem_dmabuf internals to get the dma_resv_lock and bring us one step closer to abstracting ib_umem_dmabuf away from drivers in general.
Stable-dep-of: badad6fad60d ("RDMA: During rereg_mr ensure that REREG_ACCESS is compatible")
--- drivers/infiniband/core/umem_dmabuf.c | 16 ++++++++++++++++ include/rdma/ib_umem.h | 4 ++++ 2 files changed, 20 insertions(+)
drivers/infiniband/core/umem_dmabuf.c +16 -0
@@ -276,6 +276,22 @@ struct ib_umem_dmabuf *ib_umem_dmabuf_get_pinned(struct ib_device *device, }EXPORT_SYMBOL (ib_umem_dmabuf_get_pinned); +void ib_umem_dmabuf_revoke_lock (struct ib_umem_dmabuf *umem_dmabuf) +{ +struct dma_buf *dmabuf = umem_dmabuf->attach->dmabuf; + +dma_resv_lock (dmabuf->resv,NULL ); +} +EXPORT_SYMBOL (ib_umem_dmabuf_revoke_lock); + +void ib_umem_dmabuf_revoke_unlock (struct ib_umem_dmabuf *umem_dmabuf) +{ +struct dma_buf *dmabuf = umem_dmabuf->attach->dmabuf; + +dma_resv_unlock (dmabuf->resv); +} +EXPORT_SYMBOL (ib_umem_dmabuf_revoke_unlock); +void ib_umem_dmabuf_revoke (struct ib_umem_dmabuf *umem_dmabuf) {struct dma_buf *dmabuf = umem_dmabuf->attach->dmabuf;
include/rdma/ib_umem.h +4 -0
@@ -159,6 +159,8 @@ ib_umem_dmabuf_get_pinned_with_dma_device(struct ib_device *device,int ib_umem_dmabuf_map_pages (struct ib_umem_dmabuf *umem_dmabuf);void ib_umem_dmabuf_unmap_pages (struct ib_umem_dmabuf *umem_dmabuf);void ib_umem_dmabuf_release (struct ib_umem_dmabuf *umem_dmabuf); +void ib_umem_dmabuf_revoke_lock (struct ib_umem_dmabuf *umem_dmabuf); +void ib_umem_dmabuf_revoke_unlock (struct ib_umem_dmabuf *umem_dmabuf);void ib_umem_dmabuf_revoke (struct ib_umem_dmabuf *umem_dmabuf);#else /* CONFIG_INFINIBAND_USER_MEM */
@@ -219,6 +221,8 @@ static inline int ib_umem_dmabuf_map_pages(struct ib_umem_dmabuf *umem_dmabuf) }static inline void ib_umem_dmabuf_unmap_pages (struct ib_umem_dmabuf *umem_dmabuf) { }static inline void ib_umem_dmabuf_release (struct ib_umem_dmabuf *umem_dmabuf) { } +static inline void ib_umem_dmabuf_revoke_lock (struct ib_umem_dmabuf *umem_dmabuf) {} +static inline void ib_umem_dmabuf_revoke_unlock (struct ib_umem_dmabuf *umem_dmabuf) {}static inline void ib_umem_dmabuf_revoke (struct ib_umem_dmabuf *umem_dmabuf) {}#endif /* CONFIG_INFINIBAND_USER_MEM */
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 4/4 RDMA: During rereg_mr ensure that REREG_ACCESS is compatible
In reply to Sasha LevinFrom: Jason Gunthorpe <[email protected]>
[ Upstream commit badad6fad60def1b9805559dd81dbab3d97b82aa ]
If IB_MR_REREG_ACCESS changes from RO to RW then the umem has to be re-evaluated to ensure it is properly pinned as RW. Since the umem is hidden inside each driver's mr struct add a ib_umem_check_rereg() function that each driver has to call before processing IB_MR_REREG_ACCESS.
mlx4 has to retain its duplicate ib_access_writable check because it implements IB_MR_REREG_ACCESS | IB_MR_REREG_TRANS by changing both items in place sequentially while the MR is live, so it will continue to not support this combination.
--- drivers/infiniband/core/umem.c | 16 ++++++++++++++++ drivers/infiniband/hw/hns/hns_roce_mr.c | 4 ++++ drivers/infiniband/hw/irdma/verbs.c | 4 ++++ drivers/infiniband/hw/mlx4/mr.c | 4 ++++ drivers/infiniband/hw/mlx5/mr.c | 4 ++++ drivers/infiniband/sw/rxe/rxe_verbs.c | 5 +++++ include/rdma/ib_umem.h | 8 ++++++++ 7 files changed, 45 insertions(+)
drivers/infiniband/core/umem.c +16 -0
@@ -326,3 +326,19 @@ int ib_umem_copy_from(void *dst, struct ib_umem *umem, size_t offset,return 0 ; }EXPORT_SYMBOL (ib_umem_copy_from); + +/* +* Called during rereg mr if the driver is able to re-use a umem for +* IB_MR_REREG_ACCESS. +*/ +int ib_umem_check_rereg (struct ib_umem *umem,int flags,int new_access_flags) +{ +if (!umem) +return 0 ; + +if ((flags &IB_MR_REREG_ACCESS ) && !(flags &IB_MR_REREG_TRANS )) +if (ib_access_writable (new_access_flags) && !umem->writable) +return -EACCES ; +return 0 ; +} +EXPORT_SYMBOL (ib_umem_check_rereg);
drivers/infiniband/hw/hns/hns_roce_mr.c +4 -0
@@ -292,6 +292,10 @@ struct ib_mr *hns_roce_rereg_user_mr(struct ib_mr *ibmr, int flags, u64 start, goto err_out; } + ret =ib_umem_check_rereg (mr->pbl_mtr.umem, flags, mr_access_flags); +if (ret) + goto err_out; + mailbox =hns_roce_alloc_cmd_mailbox (hr_dev); ret =PTR_ERR_OR_ZERO (mailbox);if (ret)
drivers/infiniband/hw/irdma/verbs.c +4 -0
@@ -3245,6 +3245,10 @@ static struct ib_mr *irdma_rereg_user_mr(struct ib_mr *ib_mr, int flags,if (flags & ~(IB_MR_REREG_TRANS |IB_MR_REREG_PD |IB_MR_REREG_ACCESS ))return ERR_PTR (-EOPNOTSUPP ); + ret =ib_umem_check_rereg (iwmr->region, flags, new_access); +if (ret) +return ERR_PTR (ret); + ret =irdma_hwdereg_mr (ib_mr);if (ret)return ERR_PTR (ret);
drivers/infiniband/hw/mlx4/mr.c +4 -0
@@ -466,6 +466,10 @@ struct ib_mr *mlx4_ib_rereg_user_mr(struct ib_mr *mr, int flags, u64 start,struct mlx4_mpt_entry **pmpt_entry = &mpt_entry;int err; + err =ib_umem_check_rereg (mmr->umem, flags, mr_access_flags); +if (err) +return ERR_PTR (err); +/* Since we synchronize this call and mlx4_ib_dereg_mr via uverbs, * we assume that the calls can't run concurrently. Otherwise, a * race exists.
drivers/infiniband/hw/mlx5/mr.c +4 -0
@@ -1829,6 +1829,10 @@ struct ib_mr *mlx5_ib_rereg_user_mr(struct ib_mr *ib_mr, int flags, u64 start,if (flags & ~(IB_MR_REREG_TRANS |IB_MR_REREG_PD |IB_MR_REREG_ACCESS ))return ERR_PTR (-EOPNOTSUPP ); + err =ib_umem_check_rereg (mr->umem, flags, new_access_flags); +if (err) +return ERR_PTR (err); +if (!(flags &IB_MR_REREG_ACCESS )) new_access_flags = mr->access_flags;if (!(flags &IB_MR_REREG_PD ))
drivers/infiniband/sw/rxe/rxe_verbs.c +5 -0
@@ -1312,6 +1312,7 @@ static struct ib_mr *rxe_rereg_user_mr(struct ib_mr *ibmr, int flags,struct rxe_mr *mr =to_rmr (ibmr);struct rxe_pd *old_pd =to_rpd (ibmr->pd);struct rxe_pd *pd =to_rpd (ibpd); +int err;/* for now only support the two easy cases: * rereg_pd and rereg_access
@@ -1321,6 +1322,10 @@ static struct ib_mr *rxe_rereg_user_mr(struct ib_mr *ibmr, int flags,return ERR_PTR (-EOPNOTSUPP ); } + err =ib_umem_check_rereg (mr->umem, flags, access); +if (err) +return ERR_PTR (err); +if (flags &IB_MR_REREG_PD ) {rxe_put (old_pd);rxe_get (pd);
include/rdma/ib_umem.h +8 -0
@@ -163,6 +163,8 @@ void ib_umem_dmabuf_revoke_lock(struct ib_umem_dmabuf *umem_dmabuf);void ib_umem_dmabuf_revoke_unlock (struct ib_umem_dmabuf *umem_dmabuf);void ib_umem_dmabuf_revoke (struct ib_umem_dmabuf *umem_dmabuf); +int ib_umem_check_rereg (struct ib_umem *umem,int flags,int new_access_flags); +#else /* CONFIG_INFINIBAND_USER_MEM */ #include <linux/err.h>
@@ -225,5 +227,11 @@ static inline void ib_umem_dmabuf_revoke_lock(struct ib_umem_dmabuf *umem_dmabufstatic inline void ib_umem_dmabuf_revoke_unlock (struct ib_umem_dmabuf *umem_dmabuf) {}static inline void ib_umem_dmabuf_revoke (struct ib_umem_dmabuf *umem_dmabuf) {} +static inline int ib_umem_check_rereg (struct ib_umem *umem,int flags, +int new_access_flags) +{ +return -EOPNOTSUPP ; +} +#endif /* CONFIG_INFINIBAND_USER_MEM */ #endif /* IB_UMEM_H */
Signature · 1 line
2.53.0