FAILED: patch "[PATCH] ocfs2: cache the mount context for dentry lock callbacks" failed to apply to 5.10-stable tree
Subsystems (2)
Sasha Levin
maintainerThe patch below does not apply to the 5.10-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-5.10.y
git checkout FETCH_HEAD
git cherry-pick -x 5b4696e0bfc358619adaeab25ad35b4979af8331
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 5.10.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 5b4696e0bfc358619adaeab25ad35b4979af8331 Mon Sep 17 00:00:00 2001
From: Cen Zhang <[email protected]>
Date: Tue, 20 Oct 2026 22:25:53 +0800
Subject: [PATCH] ocfs2: cache the mount context for dentry lock callbacks
ocfs2_drop_dentry_lock() drops the inode reference before releasing the DENTRY lock. This lets inode eviction release the local inode and open locks before a remote unlink can proceed past the DENTRY lock.
A DLM callback can still arrive before the DENTRY lock has been dropped. ocfs2_get_dentry_osb() obtains the mount context through dl_inode->i_sb, which can access a freed inode when the downconvert thread drops the last inode reference in its post-unlock callback:
Downconvert thread DLM callback thread
------------------ -------------------
ocfs2_process_blocked_lock()
ocfs2_dentry_post_unlock()
ocfs2_dentry_lock_put()
ocfs2_drop_dentry_lock()
iput(dl->dl_inode)
[inode reclaimed after RCU]
ocfs2_blocking_ast()
ocfs2_get_dentry_osb()
dl->dl_inode->i_sb
ocfs2_simple_drop_lockres()Store the mount context in the DENTRY lock resource's l_priv field and use the default mount-context lookup. Recover the containing dentry lock with container_of(), as already done for refcount locks, and remove ocfs2_get_dentry_osb(). ocfs2_dismount_volume() shuts down the DLM before freeing the mount context, so callbacks can use it without accessing the inode. Preserve the existing iput-before-unlock order to avoid delaying local inode and open lock release until after the DENTRY lock is released.
--- fs/ocfs2/dcache.h | 5 ++--- fs/ocfs2/dlmglue.c | 16 ++++------------ 2 files changed, 6 insertions(+), 15 deletions(-)
fs/ocfs2/dcache.h +2 -3
@@ -17,9 +17,8 @@ struct ocfs2_dentry_lock {u64 dl_parent_blkno;/* -* The ocfs2_dentry_lock keeps an inode reference until -* dl_lockres has been destroyed. This is usually done in -* ->d_iput() anyway, so there should be minimal impact. +* The inode reference is dropped before dl_lockres is unlocked. +* Callbacks must not use it to find the mount context during teardown. */ struct inode *dl_inode;struct ocfs2_lock_res dl_lockres;
fs/ocfs2/dlmglue.c +4 -12
@@ -58,7 +58,6 @@ struct ocfs2_mask_waiter {#endif }; -static struct ocfs2_super *ocfs2_get_dentry_osb (struct ocfs2_lock_res *lockres);static struct ocfs2_super *ocfs2_get_inode_osb (struct ocfs2_lock_res *lockres);static struct ocfs2_super *ocfs2_get_file_osb (struct ocfs2_lock_res *lockres);static struct ocfs2_super *ocfs2_get_qinfo_osb (struct ocfs2_lock_res *lockres);
@@ -258,7 +257,6 @@ static const struct ocfs2_lock_res_ops ocfs2_orphan_scan_lops = { };static const struct ocfs2_lock_res_ops ocfs2_dentry_lops = { - .get_osb = ocfs2_get_dentry_osb, .post_unlock = ocfs2_dentry_post_unlock, .downconvert_worker = ocfs2_dentry_convert_worker, .flags =0 ,
@@ -309,7 +307,7 @@ static inline struct ocfs2_dentry_lock *ocfs2_lock_res_dl(struct ocfs2_lock_res {BUG_ON (lockres->l_type !=OCFS2_LOCK_TYPE_DENTRY ); -return (struct ocfs2_dentry_lock *)lockres->l_priv; + return container_of(lockres, struct ocfs2_dentry_lock, dl_lockres); }static inline struct ocfs2_mem_dqinfo *ocfs2_lock_res_qinfo (struct ocfs2_lock_res *lockres)
@@ -610,13 +608,6 @@ static __u64 ocfs2_get_dentry_lock_ino(struct ocfs2_lock_res *lockres)return be64_to_cpu (inode_blkno_be); } -static struct ocfs2_super *ocfs2_get_dentry_osb (struct ocfs2_lock_res *lockres) -{ -struct ocfs2_dentry_lock *dl = lockres->l_priv; - -return OCFS2_SB (dl->dl_inode->i_sb); -} -void ocfs2_dentry_lock_res_init (struct ocfs2_dentry_lock *dl,u64 parent,struct inode *inode) {
@@ -624,6 +615,7 @@ void ocfs2_dentry_lock_res_init(struct ocfs2_dentry_lock *dl,u64 inode_blkno =OCFS2_I (inode)->ip_blkno;__be64 inode_blkno_be =cpu_to_be64 (inode_blkno);struct ocfs2_lock_res *lockres = &dl->dl_lockres; +struct ocfs2_super *osb =OCFS2_SB (inode->i_sb);ocfs2_lock_res_init_once (lockres);
@@ -652,9 +644,9 @@ void ocfs2_dentry_lock_res_init(struct ocfs2_dentry_lock *dl,memcpy (&lockres->l_name[OCFS2_DENTRY_LOCK_INO_START ], &inode_blkno_be,sizeof (__be64)); -ocfs2_lock_res_init_common (OCFS2_SB (inode->i_sb), lockres, +ocfs2_lock_res_init_common (osb, lockres,OCFS2_LOCK_TYPE_DENTRY , &ocfs2_dentry_lops, - dl); + osb); } static void ocfs2_super_lock_res_init(struct ocfs2_lock_res *res,
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/2 ocfs2: constify struct ocfs2_lock_res_ops
From: Christophe JAILLET <[email protected]>
[ Upstream commit 3ebe69c0c3ae3ef5ecd1ad86aa98a3b7cbe3c7e9 ]
"struct ocfs2_lock_res_ops" are not modified in this driver.
Constifying this structure moves some data to a read-only section, so increase overall security.
In order to do it, "struct ocfs2_lock_res" also needs to be adjusted to this new const qualifier.
On a x86_64, with allmodconfig:
Before:
======
text data bss dec hex filename 83038 2632 400 86070 15036 fs/ocfs2/dlmglue.o
After:
=====
text data bss dec hex filename 83806 1992 272 86070 15036 fs/ocfs2/dlmglue.o
Stable-dep-of: 5b4696e0bfc3 ("ocfs2: cache the mount context for dentry lock callbacks")
--- fs/ocfs2/dlmglue.c | 28 ++++++++++++++-------------- fs/ocfs2/ocfs2.h | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-)
fs/ocfs2/dlmglue.c +14 -14
@@ -223,12 +223,12 @@ struct ocfs2_lock_res_ops {*/ #define LOCK_TYPE_USES_LVB 0x2 -static struct ocfs2_lock_res_ops ocfs2_inode_rw_lops = { +static const struct ocfs2_lock_res_ops ocfs2_inode_rw_lops = { .get_osb = ocfs2_get_inode_osb, .flags =0 , }; -static struct ocfs2_lock_res_ops ocfs2_inode_inode_lops = { +static const struct ocfs2_lock_res_ops ocfs2_inode_inode_lops = { .get_osb = ocfs2_get_inode_osb, .check_downconvert = ocfs2_check_meta_downconvert, .set_lvb = ocfs2_set_meta_lvb,
@@ -236,50 +236,50 @@ static struct ocfs2_lock_res_ops ocfs2_inode_inode_lops = { .flags = LOCK_TYPE_REQUIRES_REFRESH|LOCK_TYPE_USES_LVB, }; -static struct ocfs2_lock_res_ops ocfs2_super_lops = { +static const struct ocfs2_lock_res_ops ocfs2_super_lops = { .flags =LOCK_TYPE_REQUIRES_REFRESH , }; -static struct ocfs2_lock_res_ops ocfs2_rename_lops = { +static const struct ocfs2_lock_res_ops ocfs2_rename_lops = { .flags =0 , }; -static struct ocfs2_lock_res_ops ocfs2_nfs_sync_lops = { +static const struct ocfs2_lock_res_ops ocfs2_nfs_sync_lops = { .flags =0 , }; -static struct ocfs2_lock_res_ops ocfs2_trim_fs_lops = { +static const struct ocfs2_lock_res_ops ocfs2_trim_fs_lops = { .flags =LOCK_TYPE_REQUIRES_REFRESH |LOCK_TYPE_USES_LVB , }; -static struct ocfs2_lock_res_ops ocfs2_orphan_scan_lops = { +static const struct ocfs2_lock_res_ops ocfs2_orphan_scan_lops = { .flags =LOCK_TYPE_REQUIRES_REFRESH |LOCK_TYPE_USES_LVB , }; -static struct ocfs2_lock_res_ops ocfs2_dentry_lops = { +static const struct ocfs2_lock_res_ops ocfs2_dentry_lops = { .get_osb = ocfs2_get_dentry_osb, .post_unlock = ocfs2_dentry_post_unlock, .downconvert_worker = ocfs2_dentry_convert_worker, .flags =0 , }; -static struct ocfs2_lock_res_ops ocfs2_inode_open_lops = { +static const struct ocfs2_lock_res_ops ocfs2_inode_open_lops = { .get_osb = ocfs2_get_inode_osb, .flags =0 , }; -static struct ocfs2_lock_res_ops ocfs2_flock_lops = { +static const struct ocfs2_lock_res_ops ocfs2_flock_lops = { .get_osb = ocfs2_get_file_osb, .flags =0 , }; -static struct ocfs2_lock_res_ops ocfs2_qinfo_lops = { +static const struct ocfs2_lock_res_ops ocfs2_qinfo_lops = { .set_lvb = ocfs2_set_qinfo_lvb, .get_osb = ocfs2_get_qinfo_osb, .flags =LOCK_TYPE_REQUIRES_REFRESH |LOCK_TYPE_USES_LVB , }; -static struct ocfs2_lock_res_ops ocfs2_refcount_block_lops = { +static const struct ocfs2_lock_res_ops ocfs2_refcount_block_lops = { .check_downconvert = ocfs2_check_refcount_downconvert, .downconvert_worker = ocfs2_refcount_convert_worker, .flags =0 ,
@@ -512,7 +512,7 @@ static inline void ocfs2_init_start_time(struct ocfs2_mask_waiter *mw)static void ocfs2_lock_res_init_common (struct ocfs2_super *osb,struct ocfs2_lock_res *res,enum ocfs2_lock_type type, -struct ocfs2_lock_res_ops *ops, +const struct ocfs2_lock_res_ops *ops,void *priv) { res->l_type = type;
@@ -555,7 +555,7 @@ void ocfs2_inode_lock_res_init(struct ocfs2_lock_res *res,unsigned int generation, struct inode *inode) { - struct ocfs2_lock_res_ops *ops; + const struct ocfs2_lock_res_ops *ops;switch (type) {case OCFS2_LOCK_TYPE_RW :
fs/ocfs2/ocfs2.h +1 -1
@@ -156,7 +156,7 @@ struct ocfs2_lock_stats {struct ocfs2_lock_res {void *l_priv; -struct ocfs2_lock_res_ops *l_ops; +const struct ocfs2_lock_res_ops *l_ops;struct list_head l_blocked_list;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 ocfs2: cache the mount context for dentry lock callbacks
From: Cen Zhang <[email protected]>
[ Upstream commit 5b4696e0bfc358619adaeab25ad35b4979af8331 ]
ocfs2_drop_dentry_lock() drops the inode reference before releasing the DENTRY lock. This lets inode eviction release the local inode and open locks before a remote unlink can proceed past the DENTRY lock.
A DLM callback can still arrive before the DENTRY lock has been dropped. ocfs2_get_dentry_osb() obtains the mount context through dl_inode->i_sb, which can access a freed inode when the downconvert thread drops the last inode reference in its post-unlock callback:
Downconvert thread DLM callback thread
------------------ -------------------
ocfs2_process_blocked_lock()
ocfs2_dentry_post_unlock()
ocfs2_dentry_lock_put()
ocfs2_drop_dentry_lock()
iput(dl->dl_inode)
[inode reclaimed after RCU]
ocfs2_blocking_ast()
ocfs2_get_dentry_osb()
dl->dl_inode->i_sb
ocfs2_simple_drop_lockres()Store the mount context in the DENTRY lock resource's l_priv field and use the default mount-context lookup. Recover the containing dentry lock with container_of(), as already done for refcount locks, and remove ocfs2_get_dentry_osb(). ocfs2_dismount_volume() shuts down the DLM before freeing the mount context, so callbacks can use it without accessing the inode. Preserve the existing iput-before-unlock order to avoid delaying local inode and open lock release until after the DENTRY lock is released.
--- fs/ocfs2/dcache.h | 5 ++--- fs/ocfs2/dlmglue.c | 16 ++++------------ 2 files changed, 6 insertions(+), 15 deletions(-)
fs/ocfs2/dcache.h +2 -3
@@ -19,9 +19,8 @@ struct ocfs2_dentry_lock {u64 dl_parent_blkno;/* -* The ocfs2_dentry_lock keeps an inode reference until -* dl_lockres has been destroyed. This is usually done in -* ->d_iput() anyway, so there should be minimal impact. +* The inode reference is dropped before dl_lockres is unlocked. +* Callbacks must not use it to find the mount context during teardown. */ struct inode *dl_inode;struct ocfs2_lock_res dl_lockres;
fs/ocfs2/dlmglue.c +4 -12
@@ -57,7 +57,6 @@ struct ocfs2_mask_waiter {#endif }; -static struct ocfs2_super *ocfs2_get_dentry_osb (struct ocfs2_lock_res *lockres);static struct ocfs2_super *ocfs2_get_inode_osb (struct ocfs2_lock_res *lockres);static struct ocfs2_super *ocfs2_get_file_osb (struct ocfs2_lock_res *lockres);static struct ocfs2_super *ocfs2_get_qinfo_osb (struct ocfs2_lock_res *lockres);
@@ -257,7 +256,6 @@ static const struct ocfs2_lock_res_ops ocfs2_orphan_scan_lops = { };static const struct ocfs2_lock_res_ops ocfs2_dentry_lops = { - .get_osb = ocfs2_get_dentry_osb, .post_unlock = ocfs2_dentry_post_unlock, .downconvert_worker = ocfs2_dentry_convert_worker, .flags =0 ,
@@ -308,7 +306,7 @@ static inline struct ocfs2_dentry_lock *ocfs2_lock_res_dl(struct ocfs2_lock_res {BUG_ON (lockres->l_type !=OCFS2_LOCK_TYPE_DENTRY ); -return (struct ocfs2_dentry_lock *)lockres->l_priv; + return container_of(lockres, struct ocfs2_dentry_lock, dl_lockres); }static inline struct ocfs2_mem_dqinfo *ocfs2_lock_res_qinfo (struct ocfs2_lock_res *lockres)
@@ -609,13 +607,6 @@ static __u64 ocfs2_get_dentry_lock_ino(struct ocfs2_lock_res *lockres)return be64_to_cpu (inode_blkno_be); } -static struct ocfs2_super *ocfs2_get_dentry_osb (struct ocfs2_lock_res *lockres) -{ -struct ocfs2_dentry_lock *dl = lockres->l_priv; - -return OCFS2_SB (dl->dl_inode->i_sb); -} -void ocfs2_dentry_lock_res_init (struct ocfs2_dentry_lock *dl,u64 parent,struct inode *inode) {
@@ -623,6 +614,7 @@ void ocfs2_dentry_lock_res_init(struct ocfs2_dentry_lock *dl,u64 inode_blkno =OCFS2_I (inode)->ip_blkno;__be64 inode_blkno_be =cpu_to_be64 (inode_blkno);struct ocfs2_lock_res *lockres = &dl->dl_lockres; +struct ocfs2_super *osb =OCFS2_SB (inode->i_sb);ocfs2_lock_res_init_once (lockres);
@@ -651,9 +643,9 @@ void ocfs2_dentry_lock_res_init(struct ocfs2_dentry_lock *dl,memcpy (&lockres->l_name[OCFS2_DENTRY_LOCK_INO_START ], &inode_blkno_be,sizeof (__be64)); -ocfs2_lock_res_init_common (OCFS2_SB (inode->i_sb), lockres, +ocfs2_lock_res_init_common (osb, lockres,OCFS2_LOCK_TYPE_DENTRY , &ocfs2_dentry_lops, - dl); + osb); } static void ocfs2_super_lock_res_init(struct ocfs2_lock_res *res,
Signature · 1 line
2.53.0