staging: lustre: improve API and implementation of blocking signals.
authorNeilBrown <neilb@suse.com>
Tue, 20 Feb 2018 02:23:37 +0000 (13:23 +1100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 22 Feb 2018 14:03:23 +0000 (15:03 +0100)
According to comment for set_current_blocked() in
kernel/signal.c, changing ->blocked directly is wrong.
sigprocmask() should be called instead.

So change cfs_block_sigsinv() and cfs_restore_sigs()
to use sigprocmask().
For consistency, change them to pass the sigset_t by reference
rather than by value.

Also fix cfs_block_sigsinv() so that it correctly blocks
signals above 32 on a 32bit host.

Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/lustre/include/linux/libcfs/libcfs.h
drivers/staging/lustre/lnet/libcfs/linux/linux-prim.c
drivers/staging/lustre/lustre/include/lustre_lib.h
drivers/staging/lustre/lustre/llite/llite_mmap.c

index 7f06b01181548a183c7e11c63fd68d764f136ec2..9dff050810c4eb632606e602b26c6bf31daf771c 100644 (file)
@@ -67,8 +67,8 @@
 /*
  * Defined by platform
  */
-sigset_t cfs_block_sigsinv(unsigned long sigs);
-void cfs_restore_sigs(sigset_t sigset);
+void cfs_block_sigsinv(unsigned long sigs, sigset_t *sigset);
+void cfs_restore_sigs(sigset_t *sigset);
 
 struct libcfs_ioctl_handler {
        struct list_head item;
index 6b73b9845e3f66941a5bd62d5ecd44256b29313f..0766659ddf7096ea4e5d699887f99f542346e015 100644 (file)
 #endif
 
 /* Block all signals except for the @sigs */
-sigset_t cfs_block_sigsinv(unsigned long sigs)
+void cfs_block_sigsinv(unsigned long sigs, sigset_t *old)
 {
-       unsigned long flags;
-       sigset_t old;
+       sigset_t new;
 
-       spin_lock_irqsave(&current->sighand->siglock, flags);
-       old = current->blocked;
-       sigaddsetmask(&current->blocked, ~sigs);
-       recalc_sigpending();
-       spin_unlock_irqrestore(&current->sighand->siglock, flags);
-
-       return old;
+       siginitsetinv(&new, sigs);
+       sigorsets(&new, &current->blocked, &new);
+       sigprocmask(SIG_BLOCK, &new, old);
 }
 EXPORT_SYMBOL(cfs_block_sigsinv);
 
 void
-cfs_restore_sigs(sigset_t old)
+cfs_restore_sigs(sigset_t *old)
 {
-       unsigned long flags;
-
-       spin_lock_irqsave(&current->sighand->siglock, flags);
-       current->blocked = old;
-       recalc_sigpending();
-       spin_unlock_irqrestore(&current->sighand->siglock, flags);
+       sigprocmask(SIG_SETMASK, old, NULL);
 }
 EXPORT_SYMBOL(cfs_restore_sigs);
index 1efd86f18c1fcddf5d5bbb56c373bd8ad4e69836..0053eafc1c1000ae5f0135c4a6d69d728e28776d 100644 (file)
@@ -94,31 +94,31 @@ static inline int l_fatal_signal_pending(struct task_struct *p)
  */
 #define l_wait_event_abortable(wq, condition)                          \
 ({                                                                     \
-       sigset_t __blocked;                                             \
+       sigset_t __old_blocked;                                         \
        int __ret = 0;                                                  \
-       __blocked = cfs_block_sigsinv(LUSTRE_FATAL_SIGS);               \
+       cfs_block_sigsinv(LUSTRE_FATAL_SIGS, &__old_blocked);           \
        __ret = wait_event_interruptible(wq, condition);                \
-       cfs_restore_sigs(__blocked);                                    \
+       cfs_restore_sigs(&__old_blocked);                               \
        __ret;                                                          \
 })
 
 #define l_wait_event_abortable_timeout(wq, condition, timeout)         \
 ({                                                                     \
-       sigset_t __blocked;                                             \
+       sigset_t __old_blocked;                                         \
        int __ret = 0;                                                  \
-       __blocked = cfs_block_sigsinv(LUSTRE_FATAL_SIGS);               \
+       cfs_block_sigsinv(LUSTRE_FATAL_SIGS, &__old_blocked);           \
        __ret = wait_event_interruptible_timeout(wq, condition, timeout);\
-       cfs_restore_sigs(__blocked);                                    \
+       cfs_restore_sigs(&__old_blocked);                               \
        __ret;                                                          \
 })
 
 #define l_wait_event_abortable_exclusive(wq, condition)                        \
 ({                                                                     \
-       sigset_t __blocked;                                             \
+       sigset_t __old_blocked;                                         \
        int __ret = 0;                                                  \
-       __blocked = cfs_block_sigsinv(LUSTRE_FATAL_SIGS);               \
+       cfs_block_sigsinv(LUSTRE_FATAL_SIGS, &__old_blocked);           \
        __ret = wait_event_interruptible_exclusive(wq, condition);      \
-       cfs_restore_sigs(__blocked);                                    \
+       cfs_restore_sigs(&__old_blocked);                               \
        __ret;                                                          \
 })
 #endif /* _LUSTRE_LIB_H */
index c0533bd6f3529e366c40d1acb341b397eb19f4f5..214b07554e62700fbf69e9250669c53693642162 100644 (file)
@@ -177,14 +177,14 @@ static int ll_page_mkwrite0(struct vm_area_struct *vma, struct page *vmpage,
        vio->u.fault.ft_vma    = vma;
        vio->u.fault.ft_vmpage = vmpage;
 
-       set = cfs_block_sigsinv(sigmask(SIGKILL) | sigmask(SIGTERM));
+       cfs_block_sigsinv(sigmask(SIGKILL) | sigmask(SIGTERM), &set);
 
        inode = vvp_object_inode(io->ci_obj);
        lli = ll_i2info(inode);
 
        result = cl_io_loop(env, io);
 
-       cfs_restore_sigs(set);
+       cfs_restore_sigs(&set);
 
        if (result == 0) {
                struct inode *inode = file_inode(vma->vm_file);
@@ -334,7 +334,7 @@ static int ll_fault(struct vm_fault *vmf)
         * so that it can be killed by admin but not cause segfault by
         * other signals.
         */
-       set = cfs_block_sigsinv(sigmask(SIGKILL) | sigmask(SIGTERM));
+       cfs_block_sigsinv(sigmask(SIGKILL) | sigmask(SIGTERM), &set);
 
 restart:
        result = ll_fault0(vmf->vma, vmf);
@@ -360,7 +360,7 @@ restart:
 
                result = VM_FAULT_LOCKED;
        }
-       cfs_restore_sigs(set);
+       cfs_restore_sigs(&set);
        return result;
 }