Backport for "NLM/NFSD: Fix lock notifications for async-capable"
Subsystems (7)
cover Backport for "NLM/NFSD: Fix lock notifications for async-capable"
Hi
In Debian bug https://bugs.debian.org/1153524 reported a regression after updating from 6.1.y to the 6.12.y series, explained as follows:
Quoted 43 lines
After upgrading an NFS server from the bookworm 6.1 kernel to the trixie 6.12 kernel, blocking locks taken on an NFSv4.2 export by two different clients are no longer woken up when the holder releases them. The waiting client stalls for about 30 seconds (the client-side
NFS4_LOCK_MAXTIMEOUTback-off) instead of getting the lock as soon as it is released. Setup* Server: Debian 13.7, linux-image-6.12.116+deb13-amd64 6.12.116-
1, nfs-kernel-server 1:2.8.3-1. The export is on ext4 (md RAID), options sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,roo- t_squash,no_all_squash.* Clients: two Debian 13 hosts running 6.12.116+deb13-amd64,
mounted with vers=4.2.
* The clients have run 6.12 since August 2026, and cross-client
locking worked while the server ran 6.1.0-54-amd64. The stalls started on 2026-11-05, when the server moved to 6.12.115-1. Nothing changed on the clients that day, so the regression is on the server side.Reproducer
client A: flock -x /mnt/share/testfile sleep 5 client B (1.5 s later): time flock -x -w 60 /mnt/share/testfile trueExpected: B gets the lock after about 3.5 s. Observed on 2026-11-09 with 6.12.116-1: 31.61 s. With both processes on client A, the wait is 3.51 s. Server-side traces (6.12.115-1, 2026-11-06, kernel tracepoints during the same test)
* The blocking LOCK from client B (
WRITEW_LT) reaches nfsd, but
nfsd sets the lock withoutFL_SLEEP:posix_lock_inodeshows fl_flags=FL_POSIX only. The server therefore treats it as non-
blocking: it returnsNFS4ERR_DENIEDand records no blocked lock.
* When client A releases the lock (OP_LOCKU), nonfsd_cb_queueor
nfsd_cb_notify_lockevent appears.CB_NOTIFY_LOCKis never sent.
* The client behaves as designed. It waits for the notification up
to the 30 s cap, then retries: two LOCK attempts in total, at t0 and at t0+31 s.
* I found a recent nfsd series that fixes theFL_SLEEPtest in
nfsd4_lock(introduced by7e64c5bc497c), but for the opposite
case:FL_SLEEPwrongly set on non-blocking locks. This report may be the mirror case, but I have not confirmed the root cause.
Quoted 6 lines
Impact
Any application that serialises on files shared across NFS clients stalls for 30 s per contended lock. In our case, PHP file sessions on a two-node web front caused gateway timeouts. We have worked around it (sessions moved to a database, load-balancer session affinity), but the bug still affects other shared directories.
It was forwarded to th NFS list:
Jeff Layton determined:
Quoted 8 lines
Ben Coddington's series fixed the check in v6.13. None of it went to 6.12.y:
8cf9a01edc21("fs: IntroduceFOP_ASYNC_LOCK")2253ab99f2e9("gfs2/ocfs2: setFOP_ASYNC_LOCK")7e64c5bc497c("NLM/NFSD: Fix lock notifications for async-capable
filesystems")
Quoted 4 lines
The recent patch you noticed is
246a90a5109b("nfsd: fixFL_SLEEPbeing set unconditionally for all LOCK types"). It fixes a bug that7e64c5bc497cintroduced, so it needs to be backported along with the other three.
The 4 patches following are matching the above.
*Though* I defintively prefer if those will come directly from Jeff or will get an ack from him here.
In Debian we will be in need to apply those ideally with the next round of updates we are going to push.
Regards,
Salvatore
PATCH 1/4 fs: Introduce FOP_ASYNC_LOCK
From: Benjamin Coddington <[email protected]>
commit 8cf9a01edc216b16b5839eb793ac544d2c97ce97 upstream.
Some lock managers (NLM, kNFSD) fastidiously avoid blocking their kernel threads while servicing blocking locks. If a filesystem supports asynchronous lock requests those lock managers can use notifications to quickly inform clients they have acquired a file lock.
Historically, only posix_lock_file() was capable of supporting asynchronous locks so the check for support was simply file_operations->lock(), but with recent changes in DLM, both GFS2 and OCFS2 also support asynchronous locks and have started signalling their support with EXPORT_OP_ASYNC_LOCK.
We recently noticed that those changes dropped the checks for whether a filesystem simply defaults to posix_lock_file(), so async lock notifications have not been attempted for NLM and NFSv4.1+ for most filesystems. While trying to fix this it has become clear that testing both the export flag combined with testing ->lock() creates quite a layering mess. It seems appropriate to signal support with a fop_flag.
Add FOP_ASYNC_LOCK so that filesystems with ->lock() can signal their capability to handle lock requests asynchronously. Add a helper for lock managers to properly test that support.
[Salvatore Bonaccorso: Resolve conflict in include/linux/fs.h. v6.12 already defines FOP_UNSIGNED_OFFSET as bit 5, so FOP_ASYNC_LOCK goes in as (1 << 6), its value in v6.13.]
--- include/linux/filelock.h | 5 +++++ include/linux/fs.h | 2 ++ 2 files changed, 7 insertions(+)
include/linux/filelock.h +5 -0
@@ -180,6 +180,11 @@ static inline void locks_wake_up(struct file_lock *fl)wake_up (&fl->c.flc_wait); } +static inline bool locks_can_async_lock (const struct file_operations *fops) +{ +return !fops->lock || fops->fop_flags &FOP_ASYNC_LOCK ; +} +/* fs/locks.c */ void locks_free_lock_context (struct inode *inode);void locks_free_lock (struct file_lock *fl);
include/linux/fs.h +2 -0
@@ -2177,6 +2177,8 @@ struct file_operations {#define FOP_HUGE_PAGES ((__force fop_flags_t)(1 << 4))/* Treat loff_t as unsigned (e.g., /dev/mem) */ #define FOP_UNSIGNED_OFFSET ((__force fop_flags_t)(1 << 5)) +/* Supports asynchronous lock callbacks */ +#define FOP_ASYNC_LOCK ((__force fop_flags_t)(1 << 6))/* Wrap a directory iterator that needs exclusive inode access */ int wrap_directory_iterator(struct file *, struct dir_context *,
Signature · 1 line
2.55.0
PATCH 2/4 gfs2/ocfs2: set FOP_ASYNC_LOCK
In reply to Salvatore BonaccorsoFrom: Benjamin Coddington <[email protected]>
commit 2253ab99f2e978d94693d6f63c83aa5b5d4c7839 upstream.
Both GFS2 and OCFS2 use DLM locking, which will allow async lock requests. Signal this support by setting FOP_ASYNC_LOCK.
--- fs/gfs2/file.c | 2 ++ fs/ocfs2/file.c | 2 ++ 2 files changed, 4 insertions(+)
fs/gfs2/file.c +2 -0
@@ -1597,6 +1597,7 @@ const struct file_operations gfs2_file_fops = { .splice_write = gfs2_file_splice_write, .setlease = simple_nosetlease, .fallocate = gfs2_fallocate, + .fop_flags = FOP_ASYNC_LOCK, };const struct file_operations gfs2_dir_fops = {
@@ -1609,6 +1610,7 @@ const struct file_operations gfs2_dir_fops = { .lock = gfs2_lock, .flock = gfs2_flock, .llseek = default_llseek, + .fop_flags = FOP_ASYNC_LOCK, };#endif /* CONFIG_GFS2_FS_LOCKING_DLM */
fs/ocfs2/file.c +2 -0
@@ -2852,6 +2852,7 @@ const struct file_operations ocfs2_fops = { .splice_write = iter_file_splice_write, .fallocate = ocfs2_fallocate, .remap_file_range = ocfs2_remap_file_range, + .fop_flags = FOP_ASYNC_LOCK, };WRAP_DIR_ITER (ocfs2_readdir)// FIXME!
@@ -2868,6 +2869,7 @@ const struct file_operations ocfs2_dops = {#endif .lock = ocfs2_lock, .flock = ocfs2_flock, + .fop_flags = FOP_ASYNC_LOCK, };/*
Signature · 1 line
2.55.0
PATCH 3/4 NLM/NFSD: Fix lock notifications for async-capable filesystems
In reply to Salvatore BonaccorsoFrom: Benjamin Coddington <[email protected]>
commit 7e64c5bc497cf17872b38003307f320e8f077880 upstream.
Instead of checking just the exportfs flag, use the new locks_can_async_lock() helper which allows NLM and NFSD to once again support lock notifications for all filesystems which use posix_lock_file().
--- fs/lockd/svclock.c | 7 +++---- fs/nfsd/nfs4state.c | 19 ++++--------------- 2 files changed, 7 insertions(+), 19 deletions(-)
fs/lockd/svclock.c +3 -4
@@ -30,7 +30,6 @@#include <linux/sunrpc/svc_xprt.h> #include <linux/lockd/nlm.h> #include <linux/lockd/lockd.h> -#include <linux/exportfs.h> #define NLMDBG_FACILITY NLMDBG_SVCLOCK
@@ -481,7 +480,7 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file, struct nlm_host *host, struct nlm_lock *lock, int wait, struct nlm_cookie *cookie, int reclaim) { - struct inode *inode = nlmsvc_file_inode(file); + struct inode *inode __maybe_unused = nlmsvc_file_inode(file);struct nlm_block *block =NULL ;int error;int mode;
@@ -496,7 +495,7 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file, (long long )lock->fl.fl_end, wait); -if (!exportfs_lock_op_is_async (inode->i_sb->s_export_op)) { +if (!locks_can_async_lock (nlmsvc_file_file (file)->f_op)) { async_block = wait; wait =0 ; }
@@ -550,7 +549,7 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file,* requests on the underlaying ->lock() implementation but * only one nlm_block to being granted by lm_grant(). */ -if (exportfs_lock_op_is_async (inode->i_sb->s_export_op) && +if (locks_can_async_lock (nlmsvc_file_file (file)->f_op) && !list_empty (&block->b_list)) {spin_unlock (&nlm_blocked_lock); ret = nlm_lck_blocked;
fs/nfsd/nfs4state.c +4 -15
@@ -8369,9 +8369,6 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, fp = lock_stp->st_stid.sc_file;switch (lock->lk_type) {case NFS4_READW_LT : -if (nfsd4_has_session (cstate) || -exportfs_lock_op_is_async (sb->s_export_op)) - flags |=FL_SLEEP ; fallthrough;case NFS4_READ_LT :spin_lock (&fp->fi_lock);
@@ -8382,9 +8379,6 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, type =F_RDLCK ;break ;case NFS4_WRITEW_LT : -if (nfsd4_has_session (cstate) || -exportfs_lock_op_is_async (sb->s_export_op)) - flags |=FL_SLEEP ; fallthrough;case NFS4_WRITE_LT :spin_lock (&fp->fi_lock);
@@ -8404,15 +8398,10 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, goto out; } -/* -* Most filesystems with their own ->lock operations will block -* the nfsd thread waiting to acquire the lock. That leads to -* deadlocks (we don't want every nfsd thread tied up waiting -* for file locks), so don't attempt blocking lock notifications -* on those filesystems: -*/ -if (!exportfs_lock_op_is_async (sb->s_export_op)) - flags &= ~FL_SLEEP ; +if (lock->lk_type & (NFS4_READW_LT |NFS4_WRITEW_LT ) && +nfsd4_has_session (cstate) && +locks_can_async_lock (nf->nf_file->f_op)) + flags |=FL_SLEEP ; nbl =find_or_allocate_block (lock_sop, &fp->fi_fhandle, nn);if (!nbl) {
Signature · 1 line
2.55.0
PATCH 4/4 nfsd: fix FL_SLEEP being set unconditionally for all LOCK types
In reply to Salvatore BonaccorsoFrom: Jeff Layton <[email protected]>
commit 246a90a5109bb2857db41f491277882ee2743b26 upstream.
The FL_SLEEP guard uses lk_type & (NFS4_READW_LT | NFS4_WRITEW_LT) which computes lk_type & 7, non-zero for all valid lock types including non-blocking ones. This was introduced by commit 7e64c5bc497c ("NLM/NFSD: Fix lock notifications for async-capable filesystems") when refactoring from per-case switch arms.
Replace the bitmask test with explicit equality checks.
--- fs/nfsd/nfs4state.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
fs/nfsd/nfs4state.c +5 -4
@@ -8398,10 +8398,11 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, goto out; } -if (lock->lk_type & (NFS4_READW_LT |NFS4_WRITEW_LT ) && -nfsd4_has_session (cstate) && -locks_can_async_lock (nf->nf_file->f_op)) - flags |=FL_SLEEP ; +if ((lock->lk_type ==NFS4_READW_LT || + lock->lk_type ==NFS4_WRITEW_LT ) && +nfsd4_has_session (cstate) && +locks_can_async_lock (nf->nf_file->f_op)) + flags |=FL_SLEEP ; nbl =find_or_allocate_block (lock_sop, &fp->fi_fhandle, nn);if (!nbl) {
Signature · 1 line
2.55.0
Quoted 76 lines · Salvatore Bonaccorso
Hi
In Debian bug https://bugs.debian.org/1153524 reported a regression after updating from 6.1.y to the 6.12.y series, explained as follows:
Quoted 43 lines
After upgrading an NFS server from the bookworm 6.1 kernel to the trixie 6.12 kernel, blocking locks taken on an NFSv4.2 export by two different clients are no longer woken up when the holder releases them. The waiting client stalls for about 30 seconds (the client-side
NFS4_LOCK_MAXTIMEOUTback-off) instead of getting the lock as soon as it is released. Setup* Server: Debian 13.7, linux-image-6.12.116+deb13-amd64 6.12.116-
1, nfs-kernel-server 1:2.8.3-1. The export is on ext4 (md RAID), options sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,roo- t_squash,no_all_squash.* Clients: two Debian 13 hosts running 6.12.116+deb13-amd64,
mounted with vers=4.2.
* The clients have run 6.12 since August 2026, and cross-client
locking worked while the server ran 6.1.0-54-amd64. The stalls started on 2026-11-05, when the server moved to 6.12.115-1. Nothing changed on the clients that day, so the regression is on the server side.Reproducer
client A: flock -x /mnt/share/testfile sleep 5 client B (1.5 s later): time flock -x -w 60 /mnt/share/testfile trueExpected: B gets the lock after about 3.5 s. Observed on 2026-11-09 with 6.12.116-1: 31.61 s. With both processes on client A, the wait is 3.51 s. Server-side traces (6.12.115-1, 2026-11-06, kernel tracepoints during the same test)
* The blocking LOCK from client B (
WRITEW_LT) reaches nfsd, but
nfsd sets the lock withoutFL_SLEEP:posix_lock_inodeshows fl_flags=FL_POSIX only. The server therefore treats it as non-
blocking: it returnsNFS4ERR_DENIEDand records no blocked lock.
* When client A releases the lock (OP_LOCKU), nonfsd_cb_queueor
nfsd_cb_notify_lockevent appears.CB_NOTIFY_LOCKis never sent.
* The client behaves as designed. It waits for the notification up
to the 30 s cap, then retries: two LOCK attempts in total, at t0 and at t0+31 s.
* I found a recent nfsd series that fixes theFL_SLEEPtest in
nfsd4_lock(introduced by7e64c5bc497c), but for the opposite
case:FL_SLEEPwrongly set on non-blocking locks. This report may be the mirror case, but I have not confirmed the root cause.Quoted 6 lines
Impact
Any application that serialises on files shared across NFS clients stalls for 30 s per contended lock. In our case, PHP file sessions on a two-node web front caused gateway timeouts. We have worked around it (sessions moved to a database, load-balancer session affinity), but the bug still affects other shared directories.It was forwarded to th NFS list:
Jeff Layton determined:
Quoted 8 lines
Ben Coddington's series fixed the check in v6.13. None of it went to 6.12.y:
8cf9a01edc21("fs: IntroduceFOP_ASYNC_LOCK")2253ab99f2e9("gfs2/ocfs2: setFOP_ASYNC_LOCK")7e64c5bc497c("NLM/NFSD: Fix lock notifications for async-capable
filesystems")Quoted 4 lines
The recent patch you noticed is
246a90a5109b("nfsd: fixFL_SLEEPbeing set unconditionally for all LOCK types"). It fixes a bug that7e64c5bc497cintroduced, so it needs to be backported along with the other three.The 4 patches following are matching the above.
Quoted 8 lines
*Though* I defintively prefer if those will come directly from Jeff or will get an ack from him here.
In Debian we will be in need to apply those ideally with the next round of updates we are going to push.
Regards,
Salvatore
This all looks fine to me. Thanks for doing this, Salvatore.
Quoted 2 lines
In Debian we will be in need to apply those ideally with the next round of updates we are going to push.
Queued the series for 6.12, thanks.
Signature · 2 lines
Thanks, Sasha