NFS: Don't allow waiting for exiting tasks
authorTrond Myklebust <trond.myklebust@hammerspace.com>
Fri, 28 Mar 2025 17:19:18 +0000 (13:19 -0400)
committerTrond Myklebust <trond.myklebust@hammerspace.com>
Fri, 28 Mar 2025 20:38:02 +0000 (16:38 -0400)
Once a task calls exit_signals() it can no longer be signalled. So do
not allow it to do killable waits.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
fs/nfs/inode.c
fs/nfs/internal.h
fs/nfs/nfs3proc.c
fs/nfs/nfs4proc.c

index 1aa67fca69b2fbd8afb1c51be78198220b1e13c7..119e447758b994b34e55e7b28fd4f34fa089e2e1 100644 (file)
@@ -74,6 +74,8 @@ nfs_fattr_to_ino_t(struct nfs_fattr *fattr)
 
 int nfs_wait_bit_killable(struct wait_bit_key *key, int mode)
 {
+       if (unlikely(nfs_current_task_exiting()))
+               return -EINTR;
        schedule();
        if (signal_pending_state(mode, current))
                return -ERESTARTSYS;
index fae2c7ae4acc286e1c5ad2b2225b1e9a6930b56b..2133b3c20bad6cbcdf0799e51594f6499eb335f6 100644 (file)
@@ -912,6 +912,11 @@ static inline u32 nfs_stateid_hash(nfs4_stateid *stateid)
 }
 #endif
 
+static inline bool nfs_current_task_exiting(void)
+{
+       return (current->flags & PF_EXITING) != 0;
+}
+
 static inline bool nfs_error_is_fatal(int err)
 {
        switch (err) {
index 0c3bc98cd999cc39a0a883102a83a8b35b57c30d..c1736dbb92b638edaaf7f24d1a4dcbe09dcb3c69 100644 (file)
@@ -39,7 +39,7 @@ nfs3_rpc_wrapper(struct rpc_clnt *clnt, struct rpc_message *msg, int flags)
                __set_current_state(TASK_KILLABLE|TASK_FREEZABLE_UNSAFE);
                schedule_timeout(NFS_JUKEBOX_RETRY_TIME);
                res = -ERESTARTSYS;
-       } while (!fatal_signal_pending(current));
+       } while (!fatal_signal_pending(current) && !nfs_current_task_exiting());
        return res;
 }
 
index 50be54e0f578e69ccdcfc03152e1133e3912474d..da97f87ecaa9b00b63d9c5c8887d0207c401dd04 100644 (file)
@@ -446,6 +446,8 @@ static int nfs4_delay_killable(long *timeout)
 {
        might_sleep();
 
+       if (unlikely(nfs_current_task_exiting()))
+               return -EINTR;
        __set_current_state(TASK_KILLABLE|TASK_FREEZABLE_UNSAFE);
        schedule_timeout(nfs4_update_delay(timeout));
        if (!__fatal_signal_pending(current))
@@ -457,6 +459,8 @@ static int nfs4_delay_interruptible(long *timeout)
 {
        might_sleep();
 
+       if (unlikely(nfs_current_task_exiting()))
+               return -EINTR;
        __set_current_state(TASK_INTERRUPTIBLE|TASK_FREEZABLE_UNSAFE);
        schedule_timeout(nfs4_update_delay(timeout));
        if (!signal_pending(current))
@@ -1777,7 +1781,8 @@ static void nfs_set_open_stateid_locked(struct nfs4_state *state,
                rcu_read_unlock();
                trace_nfs4_open_stateid_update_wait(state->inode, stateid, 0);
 
-               if (!fatal_signal_pending(current)) {
+               if (!fatal_signal_pending(current) &&
+                   !nfs_current_task_exiting()) {
                        if (schedule_timeout(5*HZ) == 0)
                                status = -EAGAIN;
                        else
@@ -3581,7 +3586,7 @@ static bool nfs4_refresh_open_old_stateid(nfs4_stateid *dst,
                write_sequnlock(&state->seqlock);
                trace_nfs4_close_stateid_update_wait(state->inode, dst, 0);
 
-               if (fatal_signal_pending(current))
+               if (fatal_signal_pending(current) || nfs_current_task_exiting())
                        status = -EINTR;
                else
                        if (schedule_timeout(5*HZ) != 0)