* [PATCH 1/4] fs: Introduce FOP_ASYNC_LOCK
2026-12-04 14:20 [PATCH 6.12.y 0/4] Backport for "NLM/NFSD: Fix lock notifications for async-capable" Salvatore Bonaccorso
@ 2026-12-04 14:20 ` Salvatore Bonaccorso
2026-12-04 14:20 ` [PATCH 2/4] gfs2/ocfs2: set FOP_ASYNC_LOCK Salvatore Bonaccorso
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Salvatore Bonaccorso @ 2026-12-04 14:20 UTC (permalink / raw)
To: Julien Leclerc, Jeff Layton
Cc: linux-nfs, 1153524, Chuck Lever, regressions, stable,
Benjamin Coddington, Christian Brauner, Salvatore Bonaccorso
From: Benjamin Coddington <bcodding@redhat.com>
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.
Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
Link: https://lore.kernel.org/r/3330d5a324abe2ce9c1dafe89cacdc6db41945d1.1726083391.git.bcodding@redhat.com
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
[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.]
Signed-off-by: Salvatore Bonaccorso <carnil@debian.org>
---
include/linux/filelock.h | 5 +++++
include/linux/fs.h | 2 ++
2 files changed, 7 insertions(+)
diff --git a/include/linux/filelock.h b/include/linux/filelock.h
index bb44224c6676..c412ded9171e 100644
--- a/include/linux/filelock.h
+++ b/include/linux/filelock.h
@@ -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);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index fc63611ac3c6..57a9f2e1e23c 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -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 *,
--
2.55.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH 2/4] gfs2/ocfs2: set FOP_ASYNC_LOCK
2026-12-04 14:20 [PATCH 6.12.y 0/4] Backport for "NLM/NFSD: Fix lock notifications for async-capable" Salvatore Bonaccorso
2026-12-04 14:20 ` [PATCH 1/4] fs: Introduce FOP_ASYNC_LOCK Salvatore Bonaccorso
@ 2026-12-04 14:20 ` Salvatore Bonaccorso
2026-12-04 14:20 ` [PATCH 3/4] NLM/NFSD: Fix lock notifications for async-capable filesystems Salvatore Bonaccorso
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Salvatore Bonaccorso @ 2026-12-04 14:20 UTC (permalink / raw)
To: Julien Leclerc, Jeff Layton
Cc: linux-nfs, 1153524, Chuck Lever, regressions, stable,
Benjamin Coddington, Christian Brauner, Salvatore Bonaccorso
From: Benjamin Coddington <bcodding@redhat.com>
commit 2253ab99f2e978d94693d6f63c83aa5b5d4c7839 upstream.
Both GFS2 and OCFS2 use DLM locking, which will allow async lock requests.
Signal this support by setting FOP_ASYNC_LOCK.
Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
Link: https://lore.kernel.org/r/fc4163dbbf33c58e5a8b8ee8cb8c57e555f53ce5.1726083391.git.bcodding@redhat.com
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Salvatore Bonaccorso <carnil@debian.org>
---
fs/gfs2/file.c | 2 ++
fs/ocfs2/file.c | 2 ++
2 files changed, 4 insertions(+)
diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c
index 0b5be4ad3a96..1b40ab240913 100644
--- a/fs/gfs2/file.c
+++ b/fs/gfs2/file.c
@@ -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 */
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index 451f0c5a5352..2bebb10a0754 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -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,
};
/*
--
2.55.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH 3/4] NLM/NFSD: Fix lock notifications for async-capable filesystems
2026-12-04 14:20 [PATCH 6.12.y 0/4] Backport for "NLM/NFSD: Fix lock notifications for async-capable" Salvatore Bonaccorso
2026-12-04 14:20 ` [PATCH 1/4] fs: Introduce FOP_ASYNC_LOCK Salvatore Bonaccorso
2026-12-04 14:20 ` [PATCH 2/4] gfs2/ocfs2: set FOP_ASYNC_LOCK Salvatore Bonaccorso
@ 2026-12-04 14:20 ` Salvatore Bonaccorso
2026-12-04 14:20 ` [PATCH 4/4] nfsd: fix FL_SLEEP being set unconditionally for all LOCK types Salvatore Bonaccorso
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Salvatore Bonaccorso @ 2026-12-04 14:20 UTC (permalink / raw)
To: Julien Leclerc, Jeff Layton
Cc: linux-nfs, 1153524, Chuck Lever, regressions, stable,
Benjamin Coddington, Christian Brauner, Salvatore Bonaccorso
From: Benjamin Coddington <bcodding@redhat.com>
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().
Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
Link: https://lore.kernel.org/r/865c40da44af67939e8eb560d17a26c9c50f23e0.1726083391.git.bcodding@redhat.com
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Salvatore Bonaccorso <carnil@debian.org>
---
fs/lockd/svclock.c | 7 +++----
fs/nfsd/nfs4state.c | 19 ++++---------------
2 files changed, 7 insertions(+), 19 deletions(-)
diff --git a/fs/lockd/svclock.c b/fs/lockd/svclock.c
index ab5e9ba9015b..73204014d2c7 100644
--- a/fs/lockd/svclock.c
+++ b/fs/lockd/svclock.c
@@ -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;
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 061ce98eb414..6487d9706de0 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -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) {
--
2.55.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH 4/4] nfsd: fix FL_SLEEP being set unconditionally for all LOCK types
2026-12-04 14:20 [PATCH 6.12.y 0/4] Backport for "NLM/NFSD: Fix lock notifications for async-capable" Salvatore Bonaccorso
` (2 preceding siblings ...)
2026-12-04 14:20 ` [PATCH 3/4] NLM/NFSD: Fix lock notifications for async-capable filesystems Salvatore Bonaccorso
@ 2026-12-04 14:20 ` Salvatore Bonaccorso
2026-12-04 14:37 ` [PATCH 6.12.y 0/4] Backport for "NLM/NFSD: Fix lock notifications for async-capable" Jeff Layton
2026-12-04 19:49 ` Sasha Levin
5 siblings, 0 replies; 7+ messages in thread
From: Salvatore Bonaccorso @ 2026-12-04 14:20 UTC (permalink / raw)
To: Julien Leclerc, Jeff Layton
Cc: linux-nfs, 1153524, Chuck Lever, regressions, stable, Chuck Lever,
Salvatore Bonaccorso
From: Jeff Layton <jlayton@kernel.org>
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.
Fixes: 7e64c5bc497c ("NLM/NFSD: Fix lock notifications for async-capable filesystems")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Jeff Layton <jlayton@kernel.org>
Link: https://patch.msgid.link/20260611-nfsd-testing-v2-10-5b90e276f2d9@kernel.org
Signed-off-by: Chuck Lever <cel@kernel.org>
Signed-off-by: Salvatore Bonaccorso <carnil@debian.org>
---
fs/nfsd/nfs4state.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 6487d9706de0..b911c08546dc 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -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) {
--
2.55.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH 6.12.y 0/4] Backport for "NLM/NFSD: Fix lock notifications for async-capable"
2026-12-04 14:20 [PATCH 6.12.y 0/4] Backport for "NLM/NFSD: Fix lock notifications for async-capable" Salvatore Bonaccorso
` (3 preceding siblings ...)
2026-12-04 14:20 ` [PATCH 4/4] nfsd: fix FL_SLEEP being set unconditionally for all LOCK types Salvatore Bonaccorso
@ 2026-12-04 14:37 ` Jeff Layton
2026-12-04 19:49 ` Sasha Levin
5 siblings, 0 replies; 7+ messages in thread
From: Jeff Layton @ 2026-12-04 14:37 UTC (permalink / raw)
To: Salvatore Bonaccorso, Julien Leclerc
Cc: linux-nfs, 1153524, Chuck Lever, regressions, stable
On Fri, 2026-12-04 at 15:20 +0100, Salvatore Bonaccorso wrote:
> 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:
>
> > 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_MAXTIMEOUT back-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 true
> >
> > Expected: 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 without FL_SLEEP: posix_lock_inode shows
> > fl_flags=FL_POSIX only. The server therefore treats it as non-
> > blocking: it returns NFS4ERR_DENIED and records no blocked lock.
> > * When client A releases the lock (OP_LOCKU), no nfsd_cb_queue or
> > nfsd_cb_notify_lock event appears. CB_NOTIFY_LOCK is 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 the FL_SLEEP test in
> > nfsd4_lock (introduced by 7e64c5bc497c), but for the opposite
> > case: FL_SLEEP wrongly set on non-blocking locks. This report
> > may be the mirror case, but I have not confirmed the root cause.
> >
> > 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:
>
> https://lore.kernel.org/linux-nfs/SADPR02MB574770B2C27CA5277D9878958CE84D2@SADPR02MB574770.namprd02.prod.outlook.com/T/#mf090eb57d7770d471224ec0cb6a564ae2010d75f
>
> Jeff Layton determined:
>
> > Ben Coddington's series fixed the check in v6.13. None of it went to
> > 6.12.y:
> >
> > 8cf9a01edc21 ("fs: Introduce FOP_ASYNC_LOCK")
> > 2253ab99f2e9 ("gfs2/ocfs2: set FOP_ASYNC_LOCK")
> > 7e64c5bc497c ("NLM/NFSD: Fix lock notifications for async-capable
> > filesystems")
> >
> > The recent patch you noticed is 246a90a5109b ("nfsd: fix FL_SLEEP
> > being set unconditionally for all LOCK types"). It fixes a bug that
> > 7e64c5bc497c introduced, 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
This all looks fine to me. Thanks for doing this, Salvatore.
Reviewed-by: Jeff Layton <jlayton@kernel.org>
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH 6.12.y 0/4] Backport for "NLM/NFSD: Fix lock notifications for async-capable"
2026-12-04 14:20 [PATCH 6.12.y 0/4] Backport for "NLM/NFSD: Fix lock notifications for async-capable" Salvatore Bonaccorso
` (4 preceding siblings ...)
2026-12-04 14:37 ` [PATCH 6.12.y 0/4] Backport for "NLM/NFSD: Fix lock notifications for async-capable" Jeff Layton
@ 2026-12-04 19:49 ` Sasha Levin
5 siblings, 0 replies; 7+ messages in thread
From: Sasha Levin @ 2026-12-04 19:49 UTC (permalink / raw)
To: Julien Leclerc, Jeff Layton
Cc: Sasha Levin, linux-nfs, 1153524, Chuck Lever, regressions, stable,
Salvatore Bonaccorso
> 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.
--
Thanks,
Sasha
^ permalink raw reply [flat|nested] 7+ messages in thread