1. 15 Sep, 2018 2 commits
    • Johannes Berg's avatar
      workqueue: re-add lockdep dependencies for flushing · 13892551
      Johannes Berg authored
      [ Upstream commit 87915adc ]
      
      In flush_work(), we need to create a lockdep dependency so that
      the following scenario is appropriately tagged as a problem:
      
        work_function()
        {
          mutex_lock(&mutex);
          ...
        }
      
        other_function()
        {
          mutex_lock(&mutex);
          flush_work(&work); // or cancel_work_sync(&work);
        }
      
      This is a problem since the work might be running and be blocked
      on trying to acquire the mutex.
      
      Similarly, in flush_workqueue().
      
      These were removed after cross-release partially caught these
      problems, but now cross-release was reverted anyway. IMHO the
      removal was erroneous anyway though, since lockdep should be
      able to catch potential problems, not just actual ones, and
      cross-release would only have caught the problem when actually
      invoking wait_for_completion().
      
      Fixes: fd1a5b04 ("workqueue: Remove now redundant lock acquisitions wrt. workqueue flushes")
      Signed-off-by: 's avatarJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: 's avatarTejun Heo <tj@kernel.org>
      Signed-off-by: 's avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: 's avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      13892551
    • Johannes Berg's avatar
      workqueue: skip lockdep wq dependency in cancel_work_sync() · b7a3d36d
      Johannes Berg authored
      [ Upstream commit d6e89786 ]
      
      In cancel_work_sync(), we can only have one of two cases, even
      with an ordered workqueue:
       * the work isn't running, just cancelled before it started
       * the work is running, but then nothing else can be on the
         workqueue before it
      
      Thus, we need to skip the lockdep workqueue dependency handling,
      otherwise we get false positive reports from lockdep saying that
      we have a potential deadlock when the workqueue also has other
      work items with locking, e.g.
      
        work1_function() { mutex_lock(&mutex); ... }
        work2_function() { /* nothing */ }
      
        other_function() {
          queue_work(ordered_wq, &work1);
          queue_work(ordered_wq, &work2);
          mutex_lock(&mutex);
          cancel_work_sync(&work2);
        }
      
      As described above, this isn't a problem, but lockdep will
      currently flag it as if cancel_work_sync() was flush_work(),
      which *is* a problem.
      Signed-off-by: 's avatarJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: 's avatarTejun Heo <tj@kernel.org>
      Signed-off-by: 's avatarSasha Levin <alexander.levin@microsoft.com>
      Signed-off-by: 's avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b7a3d36d
  2. 05 Sep, 2018 1 commit
  3. 12 Jun, 2018 1 commit
    • Kees Cook's avatar
      treewide: kzalloc() -> kcalloc() · 6396bb22
      Kees Cook authored
      The kzalloc() function has a 2-factor argument form, kcalloc(). This
      patch replaces cases of:
      
              kzalloc(a * b, gfp)
      
      with:
              kcalloc(a * b, gfp)
      
      as well as handling cases of:
      
              kzalloc(a * b * c, gfp)
      
      with:
      
              kzalloc(array3_size(a, b, c), gfp)
      
      as it's slightly less ugly than:
      
              kzalloc_array(array_size(a, b), c, gfp)
      
      This does, however, attempt to ignore constant size factors like:
      
              kzalloc(4 * 1024, gfp)
      
      though any constants defined via macros get caught up in the conversion.
      
      Any factors with a sizeof() of "unsigned char", "char", and "u8" were
      dropped, since they're redundant.
      
      The Coccinelle script used for this was:
      
      // Fix redundant parens around sizeof().
      @@
      type TYPE;
      expression THING, E;
      @@
      
      (
        kzalloc(
      -	(sizeof(TYPE)) * E
      +	sizeof(TYPE) * E
        , ...)
      |
        kzalloc(
      -	(sizeof(THING)) * E
      +	sizeof(THING) * E
        , ...)
      )
      
      // Drop single-byte sizes and redundant parens.
      @@
      expression COUNT;
      typedef u8;
      typedef __u8;
      @@
      
      (
        kzalloc(
      -	sizeof(u8) * (COUNT)
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(__u8) * (COUNT)
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(char) * (COUNT)
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(unsigned char) * (COUNT)
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(u8) * COUNT
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(__u8) * COUNT
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(char) * COUNT
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(unsigned char) * COUNT
      +	COUNT
        , ...)
      )
      
      // 2-factor product with sizeof(type/expression) and identifier or constant.
      @@
      type TYPE;
      expression THING;
      identifier COUNT_ID;
      constant COUNT_CONST;
      @@
      
      (
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * (COUNT_ID)
      +	COUNT_ID, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * COUNT_ID
      +	COUNT_ID, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * (COUNT_CONST)
      +	COUNT_CONST, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * COUNT_CONST
      +	COUNT_CONST, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * (COUNT_ID)
      +	COUNT_ID, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * COUNT_ID
      +	COUNT_ID, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * (COUNT_CONST)
      +	COUNT_CONST, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * COUNT_CONST
      +	COUNT_CONST, sizeof(THING)
        , ...)
      )
      
      // 2-factor product, only identifiers.
      @@
      identifier SIZE, COUNT;
      @@
      
      - kzalloc
      + kcalloc
        (
      -	SIZE * COUNT
      +	COUNT, SIZE
        , ...)
      
      // 3-factor product with 1 sizeof(type) or sizeof(expression), with
      // redundant parens removed.
      @@
      expression THING;
      identifier STRIDE, COUNT;
      type TYPE;
      @@
      
      (
        kzalloc(
      -	sizeof(TYPE) * (COUNT) * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE) * (COUNT) * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE) * COUNT * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE) * COUNT * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kzalloc(
      -	sizeof(THING) * (COUNT) * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        kzalloc(
      -	sizeof(THING) * (COUNT) * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        kzalloc(
      -	sizeof(THING) * COUNT * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        kzalloc(
      -	sizeof(THING) * COUNT * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      )
      
      // 3-factor product with 2 sizeof(variable), with redundant parens removed.
      @@
      expression THING1, THING2;
      identifier COUNT;
      type TYPE1, TYPE2;
      @@
      
      (
        kzalloc(
      -	sizeof(TYPE1) * sizeof(TYPE2) * COUNT
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
        , ...)
      |
        kzalloc(
      -	sizeof(THING1) * sizeof(THING2) * COUNT
      +	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
        , ...)
      |
        kzalloc(
      -	sizeof(THING1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * COUNT
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
        , ...)
      )
      
      // 3-factor product, only identifiers, with redundant parens removed.
      @@
      identifier STRIDE, SIZE, COUNT;
      @@
      
      (
        kzalloc(
      -	(COUNT) * STRIDE * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	COUNT * (STRIDE) * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	COUNT * STRIDE * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	(COUNT) * (STRIDE) * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	COUNT * (STRIDE) * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	(COUNT) * STRIDE * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	(COUNT) * (STRIDE) * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	COUNT * STRIDE * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      )
      
      // Any remaining multi-factor products, first at least 3-factor products,
      // when they're not all constants...
      @@
      expression E1, E2, E3;
      constant C1, C2, C3;
      @@
      
      (
        kzalloc(C1 * C2 * C3, ...)
      |
        kzalloc(
      -	(E1) * E2 * E3
      +	array3_size(E1, E2, E3)
        , ...)
      |
        kzalloc(
      -	(E1) * (E2) * E3
      +	array3_size(E1, E2, E3)
        , ...)
      |
        kzalloc(
      -	(E1) * (E2) * (E3)
      +	array3_size(E1, E2, E3)
        , ...)
      |
        kzalloc(
      -	E1 * E2 * E3
      +	array3_size(E1, E2, E3)
        , ...)
      )
      
      // And then all remaining 2 factors products when they're not all constants,
      // keeping sizeof() as the second factor argument.
      @@
      expression THING, E1, E2;
      type TYPE;
      constant C1, C2, C3;
      @@
      
      (
        kzalloc(sizeof(THING) * C2, ...)
      |
        kzalloc(sizeof(TYPE) * C2, ...)
      |
        kzalloc(C1 * C2 * C3, ...)
      |
        kzalloc(C1 * C2, ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * (E2)
      +	E2, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * E2
      +	E2, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * (E2)
      +	E2, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * E2
      +	E2, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	(E1) * E2
      +	E1, E2
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	(E1) * (E2)
      +	E1, E2
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	E1 * E2
      +	E1, E2
        , ...)
      )
      Signed-off-by: 's avatarKees Cook <keescook@chromium.org>
      6396bb22
  4. 06 Jun, 2018 1 commit
    • Kees Cook's avatar
      treewide: Use struct_size() for kmalloc()-family · acafe7e3
      Kees Cook authored
      One of the more common cases of allocation size calculations is finding
      the size of a structure that has a zero-sized array at the end, along
      with memory for some number of elements for that array. For example:
      
      struct foo {
          int stuff;
          void *entry[];
      };
      
      instance = kmalloc(sizeof(struct foo) + sizeof(void *) * count, GFP_KERNEL);
      
      Instead of leaving these open-coded and prone to type mistakes, we can
      now use the new struct_size() helper:
      
      instance = kmalloc(struct_size(instance, entry, count), GFP_KERNEL);
      
      This patch makes the changes for kmalloc()-family (and kvmalloc()-family)
      uses. It was done via automatic conversion with manual review for the
      "CHECKME" non-standard cases noted below, using the following Coccinelle
      script:
      
      // pkey_cache = kmalloc(sizeof *pkey_cache + tprops->pkey_tbl_len *
      //                      sizeof *pkey_cache->table, GFP_KERNEL);
      @@
      identifier alloc =~ "kmalloc|kzalloc|kvmalloc|kvzalloc";
      expression GFP;
      identifier VAR, ELEMENT;
      expression COUNT;
      @@
      
      - alloc(sizeof(*VAR) + COUNT * sizeof(*VAR->ELEMENT), GFP)
      + alloc(struct_size(VAR, ELEMENT, COUNT), GFP)
      
      // mr = kzalloc(sizeof(*mr) + m * sizeof(mr->map[0]), GFP_KERNEL);
      @@
      identifier alloc =~ "kmalloc|kzalloc|kvmalloc|kvzalloc";
      expression GFP;
      identifier VAR, ELEMENT;
      expression COUNT;
      @@
      
      - alloc(sizeof(*VAR) + COUNT * sizeof(VAR->ELEMENT[0]), GFP)
      + alloc(struct_size(VAR, ELEMENT, COUNT), GFP)
      
      // Same pattern, but can't trivially locate the trailing element name,
      // or variable name.
      @@
      identifier alloc =~ "kmalloc|kzalloc|kvmalloc|kvzalloc";
      expression GFP;
      expression SOMETHING, COUNT, ELEMENT;
      @@
      
      - alloc(sizeof(SOMETHING) + COUNT * sizeof(ELEMENT), GFP)
      + alloc(CHECKME_struct_size(&SOMETHING, ELEMENT, COUNT), GFP)
      Signed-off-by: 's avatarKees Cook <keescook@chromium.org>
      acafe7e3
  5. 23 May, 2018 1 commit
    • Mathieu Malaterre's avatar
      workqueue: move function definitions within CONFIG_SMP block · 66448bc2
      Mathieu Malaterre authored
      In commit 7ee681b2 ("workqueue: Convert to state machine callbacks"),
      three new function definitions were added: ‘workqueue_prepare_cpu’,
      ‘workqueue_online_cpu’ and ‘workqueue_offline_cpu’.
      
      Move these function definitions within a CONFIG_SMP block since they are
      not used outside of it. This will match function declarations in header
      <include/linux/workqueue.h>, and silence the following gcc warning (W=1):
      
        kernel/workqueue.c:4743:5: warning: no previous prototype for ‘workqueue_prepare_cpu’ [-Wmissing-prototypes]
        kernel/workqueue.c:4756:5: warning: no previous prototype for ‘workqueue_online_cpu’ [-Wmissing-prototypes]
        kernel/workqueue.c:4783:5: warning: no previous prototype for ‘workqueue_offline_cpu’ [-Wmissing-prototypes]
      Signed-off-by: 's avatarMathieu Malaterre <malat@debian.org>
      Signed-off-by: 's avatarTejun Heo <tj@kernel.org>
      66448bc2
  6. 21 May, 2018 1 commit
  7. 18 May, 2018 5 commits
    • Tejun Heo's avatar
      workqueue: Show the latest workqueue name in /proc/PID/{comm,stat,status} · 6b59808b
      Tejun Heo authored
      There can be a lot of workqueue workers and they all show up with the
      cryptic kworker/* names making it difficult to understand which is
      doing what and how they came to be.
      
        # ps -ef | grep kworker
        root           4       2  0 Feb25 ?        00:00:00 [kworker/0:0H]
        root           6       2  0 Feb25 ?        00:00:00 [kworker/u112:0]
        root          19       2  0 Feb25 ?        00:00:00 [kworker/1:0H]
        root          25       2  0 Feb25 ?        00:00:00 [kworker/2:0H]
        root          31       2  0 Feb25 ?        00:00:00 [kworker/3:0H]
        ...
      
      This patch makes workqueue workers report the latest workqueue it was
      executing for through /proc/PID/{comm,stat,status}.  The extra
      information is appended to the kthread name with intervening '+' if
      currently executing, otherwise '-'.
      
        # cat /proc/25/comm
        kworker/2:0-events_power_efficient
        # cat /proc/25/stat
        25 (kworker/2:0-events_power_efficient) I 2 0 0 0 -1 69238880 0 0...
        # grep Name /proc/25/status
        Name:   kworker/2:0-events_power_efficient
      
      Unfortunately, ps(1) truncates comm to 15 characters,
      
        # ps 25
          PID TTY      STAT   TIME COMMAND
           25 ?        I      0:00 [kworker/2:0-eve]
      
      making it a lot less useful; however, this should be an easy fix from
      ps(1) side.
      Signed-off-by: 's avatarTejun Heo <tj@kernel.org>
      Suggested-by: 's avatarLinus Torvalds <torvalds@linux-foundation.org>
      Cc: Craig Small <csmall@enc.com.au>
      6b59808b
    • Tejun Heo's avatar
      workqueue: Set worker->desc to workqueue name by default · 8bf89593
      Tejun Heo authored
      Work functions can use set_worker_desc() to improve the visibility of
      what the worker task is doing.  Currently, the desc field is unset at
      the beginning of each execution and there is a separate field to track
      the field is set during the current execution.
      
      Instead of leaving empty till desc is set, worker->desc can be used to
      remember the last workqueue the worker worked on by default and users
      that use set_worker_desc() can override it to something more
      informative as necessary.
      
      This simplifies desc handling and helps tracking the last workqueue
      that the worker exected on to improve visibility.
      Signed-off-by: 's avatarTejun Heo <tj@kernel.org>
      8bf89593
    • Tejun Heo's avatar
      workqueue: Make worker_attach/detach_pool() update worker->pool · a2d812a2
      Tejun Heo authored
      For historical reasons, the worker attach/detach functions don't
      currently manage worker->pool and the callers are manually and
      inconsistently updating it.
      
      This patch moves worker->pool updates into the worker attach/detach
      functions.  This makes worker->pool consistent and clearly defines how
      worker->pool updates are synchronized.
      
      This will help later workqueue visibility improvements by allowing
      safe access to workqueue information from worker->task.
      Signed-off-by: 's avatarTejun Heo <tj@kernel.org>
      a2d812a2
    • Tejun Heo's avatar
      workqueue: Replace pool->attach_mutex with global wq_pool_attach_mutex · 1258fae7
      Tejun Heo authored
      To improve workqueue visibility, we want to be able to access
      workqueue information from worker tasks.  The per-pool attach mutex
      makes that difficult because there's no way of stabilizing task ->
      worker pool association without knowing the pool first.
      
      Worker attach/detach is a slow path and there's no need for different
      pools to be able to perform them concurrently.  This patch replaces
      the per-pool attach_mutex with global wq_pool_attach_mutex to prepare
      for visibility improvement changes.
      Signed-off-by: 's avatarTejun Heo <tj@kernel.org>
      1258fae7
    • Steffen Maier's avatar
      scsi: zfcp: workqueue: set description for port work items with their WWPN as context · 5c750d58
      Steffen Maier authored
      As a prerequisite, complement commit 3d1cb205 ("workqueue: include
      workqueue info when printing debug dump of a worker task") to be usable with
      kernel modules by exporting the symbol set_worker_desc().  Current built-in
      user was introduced with commit ef3b1019 ("writeback: set worker desc to
      identify writeback workers in task dumps").
      
      Can help distinguishing work items which do not have adapter scope.
      Description is printed out with task dump for debugging on WARN, BUG, panic,
      or magic-sysrq [show-task-states(t)].
      
      Example:
      $ echo 0 >| /sys/bus/ccw/drivers/zfcp/0.0.1880/0x50050763031bd327/failed &
      $ echo 't' >| /proc/sysrq-trigger
      $ dmesg
      sysrq: SysRq : Show State
        task                        PC stack   pid father
      ...
      zfcp_q_0.0.1880 S14640  2165      2 0x02000000
      Call Trace:
      ([<00000000009df464>] __schedule+0xbf4/0xc78)
       [<00000000009df57c>] schedule+0x94/0xc0
       [<0000000000168654>] rescuer_thread+0x33c/0x3a0
       [<000000000016f8be>] kthread+0x166/0x178
       [<00000000009e71f2>] kernel_thread_starter+0x6/0xc
       [<00000000009e71ec>] kernel_thread_starter+0x0/0xc
      no locks held by zfcp_q_0.0.1880/2165.
      ...
      kworker/u512:2  D11280  2193      2 0x02000000
      Workqueue: zfcp_q_0.0.1880 zfcp_scsi_rport_work [zfcp] (zrpd-50050763031bd327)
                                                              ^^^^^^^^^^^^^^^^^^^^^
      Call Trace:
      ([<00000000009df464>] __schedule+0xbf4/0xc78)
       [<00000000009df57c>] schedule+0x94/0xc0
       [<00000000009e50c0>] schedule_timeout+0x488/0x4d0
       [<00000000001e425c>] msleep+0x5c/0x78                  >>test code only<<
       [<000003ff8008a21e>] zfcp_scsi_rport_work+0xbe/0x100 [zfcp]
       [<0000000000167154>] process_one_work+0x3b4/0x718
       [<000000000016771c>] worker_thread+0x264/0x408
       [<000000000016f8be>] kthread+0x166/0x178
       [<00000000009e71f2>] kernel_thread_starter+0x6/0xc
       [<00000000009e71ec>] kernel_thread_starter+0x0/0xc
      2 locks held by kworker/u512:2/2193:
       #0:  (name){++++.+}, at: [<0000000000166f4e>] process_one_work+0x1ae/0x718
       #1:  ((&(&port->rport_work)->work)){+.+.+.}, at: [<0000000000166f4e>] process_one_work+0x1ae/0x718
      ...
      
      =============================================
      Showing busy workqueues and worker pools:
      workqueue zfcp_q_0.0.1880: flags=0x2000a
        pwq 512: cpus=0-255 flags=0x4 nice=0 active=1/1
          in-flight: 2193:zfcp_scsi_rport_work [zfcp]
      pool 512: cpus=0-255 flags=0x4 nice=0 hung=0s workers=4 idle: 5 2354 2311
      
      Work items with adapter scope are already identified by the workqueue name
      "zfcp_q_<devbusid>" and the work item function name.
      Signed-off-by: 's avatarSteffen Maier <maier@linux.ibm.com>
      Cc: Tejun Heo <tj@kernel.org>
      Cc: Lai Jiangshan <jiangshanlai@gmail.com>
      Reviewed-by: 's avatarBenjamin Block <bblock@linux.ibm.com>
      Acked-by: 's avatarTejun Heo <tj@kernel.org>
      Signed-off-by: 's avatarMartin K. Petersen <martin.petersen@oracle.com>
      5c750d58
  8. 20 Mar, 2018 2 commits
  9. 19 Mar, 2018 1 commit
    • Tejun Heo's avatar
      RCU, workqueue: Implement rcu_work · 05f0fe6b
      Tejun Heo authored
      There are cases where RCU callback needs to be bounced to a sleepable
      context.  This is currently done by the RCU callback queueing a work
      item, which can be cumbersome to write and confusing to read.
      
      This patch introduces rcu_work, a workqueue work variant which gets
      executed after a RCU grace period, and converts the open coded
      bouncing in fs/aio and kernel/cgroup.
      
      v3: Dropped queue_rcu_work_on().  Documented rcu grace period behavior
          after queue_rcu_work().
      
      v2: Use rcu_barrier() instead of synchronize_rcu() to wait for
          completion of previously queued rcu callback as per Paul.
      Signed-off-by: 's avatarTejun Heo <tj@kernel.org>
      Acked-by: 's avatar"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      05f0fe6b
  10. 13 Mar, 2018 2 commits
  11. 21 Feb, 2018 1 commit
  12. 16 Feb, 2018 1 commit
  13. 15 Jan, 2018 1 commit
    • NeilBrown's avatar
      staging: lustre: lnet: convert selftest to use workqueues · 6106c0f8
      NeilBrown authored
      Instead of the cfs workitem library, use workqueues.
      
      As lnet wants to provide a cpu mask of allowed cpus, it
      needs to be a WQ_UNBOUND work queue so that tasks can
      run on cpus other than where they were submitted.
      
      This patch also exported apply_workqueue_attrs() which is
      a documented part of the workqueue API, that isn't currently
      exported.  lustre needs it to allow workqueue thread to be limited
      to a subset of CPUs.
      
      Acked-by: Tejun Heo <tj@kernel.org> (for export of apply_workqueue_attrs)
      Signed-off-by: 's avatarNeilBrown <neilb@suse.com>
      Signed-off-by: 's avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6106c0f8
  14. 12 Jan, 2018 1 commit
  15. 08 Jan, 2018 2 commits
    • Tejun Heo's avatar
      workqueue: allow WQ_MEM_RECLAIM on early init workqueues · 40c17f75
      Tejun Heo authored
      Workqueues can be created early during boot before workqueue subsystem
      in fully online - work items are queued waiting for later full
      initialization.  However, early init wasn't supported for
      WQ_MEM_RECLAIM workqueues causing unnecessary annoyances for a subset
      of users.  Expand early init support to include WQ_MEM_RECLAIM
      workqueues.
      Signed-off-by: 's avatarTejun Heo <tj@kernel.org>
      Cc: Paul McKenney <paulmck@linux.vnet.ibm.com>
      40c17f75
    • Tejun Heo's avatar
      workqueue: separate out init_rescuer() · 983c7515
      Tejun Heo authored
      Separate out init_rescuer() from __alloc_workqueue_key() to prepare
      for early init support for WQ_MEM_RECLAIM.  This patch doesn't
      introduce any functional changes.
      Signed-off-by: 's avatarTejun Heo <tj@kernel.org>
      Cc: Paul McKenney <paulmck@linux.vnet.ibm.com>
      983c7515
  16. 11 Dec, 2017 1 commit
  17. 04 Dec, 2017 3 commits
  18. 27 Nov, 2017 1 commit
  19. 22 Nov, 2017 1 commit
    • Kees Cook's avatar
      treewide: Remove TIMER_FUNC_TYPE and TIMER_DATA_TYPE casts · 841b86f3
      Kees Cook authored
      With all callbacks converted, and the timer callback prototype
      switched over, the TIMER_FUNC_TYPE cast is no longer needed,
      so remove it. Conversion was done with the following scripts:
      
          perl -pi -e 's|\(TIMER_FUNC_TYPE\)||g' \
              $(git grep TIMER_FUNC_TYPE | cut -d: -f1 | sort -u)
      
          perl -pi -e 's|\(TIMER_DATA_TYPE\)||g' \
              $(git grep TIMER_DATA_TYPE | cut -d: -f1 | sort -u)
      
      The now unused macros are also dropped from include/linux/timer.h.
      Signed-off-by: 's avatarKees Cook <keescook@chromium.org>
      841b86f3
  20. 08 Nov, 2017 1 commit
  21. 06 Nov, 2017 1 commit
  22. 03 Nov, 2017 1 commit
  23. 25 Oct, 2017 2 commits
    • Byungchul Park's avatar
      workqueue: Remove now redundant lock acquisitions wrt. workqueue flushes · fd1a5b04
      Byungchul Park authored
      The workqueue code added manual lock acquisition annotations to catch
      deadlocks.
      
      After lockdepcrossrelease was introduced, some of those became redundant,
      since wait_for_completion() already does the acquisition and tracking.
      
      Remove the duplicate annotations.
      Signed-off-by: 's avatarByungchul Park <byungchul.park@lge.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: amir73il@gmail.com
      Cc: axboe@kernel.dk
      Cc: darrick.wong@oracle.com
      Cc: david@fromorbit.com
      Cc: hch@infradead.org
      Cc: idryomov@gmail.com
      Cc: johan@kernel.org
      Cc: johannes.berg@intel.com
      Cc: kernel-team@lge.com
      Cc: linux-block@vger.kernel.org
      Cc: linux-fsdevel@vger.kernel.org
      Cc: linux-mm@kvack.org
      Cc: linux-xfs@vger.kernel.org
      Cc: oleg@redhat.com
      Cc: tj@kernel.org
      Link: http://lkml.kernel.org/r/1508921765-15396-9-git-send-email-byungchul.park@lge.comSigned-off-by: 's avatarIngo Molnar <mingo@kernel.org>
      fd1a5b04
    • Mark Rutland's avatar
      locking/atomics, workqueue: Convert ACCESS_ONCE() to READ_ONCE()/WRITE_ONCE() · c95491ed
      Mark Rutland authored
      For several reasons, it is desirable to use {READ,WRITE}_ONCE() in
      preference to ACCESS_ONCE(), and new code is expected to use one of the
      former. So far, there's been no reason to change most existing uses of
      ACCESS_ONCE(), as these aren't currently harmful.
      
      However, for some features it is necessary to instrument reads and
      writes separately, which is not possible with ACCESS_ONCE(). This
      distinction is critical to correct operation.
      
      It's possible to transform the bulk of kernel code using the Coccinelle
      script below. However, this doesn't handle comments, leaving references
      to ACCESS_ONCE() instances which have been removed. As a preparatory
      step, this patch converts the workqueue code and comments to use
      {READ,WRITE}_ONCE() consistently.
      
      ----
      virtual patch
      
      @ depends on patch @
      expression E1, E2;
      @@
      
      - ACCESS_ONCE(E1) = E2
      + WRITE_ONCE(E1, E2)
      
      @ depends on patch @
      expression E;
      @@
      
      - ACCESS_ONCE(E)
      + READ_ONCE(E)
      ----
      Signed-off-by: 's avatarMark Rutland <mark.rutland@arm.com>
      Signed-off-by: 's avatarPaul E. McKenney <paulmck@linux.vnet.ibm.com>
      Acked-by: 's avatarTejun Heo <tj@kernel.org>
      Cc: Lai Jiangshan <jiangshanlai@gmail.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: davem@davemloft.net
      Cc: linux-arch@vger.kernel.org
      Cc: mpe@ellerman.id.au
      Cc: shuah@kernel.org
      Cc: snitzer@redhat.com
      Cc: thor.thayer@linux.intel.com
      Cc: viro@zeniv.linux.org.uk
      Cc: will.deacon@arm.com
      Link: http://lkml.kernel.org/r/1508792849-3115-12-git-send-email-paulmck@linux.vnet.ibm.comSigned-off-by: 's avatarIngo Molnar <mingo@kernel.org>
      c95491ed
  24. 21 Oct, 2017 1 commit
  25. 18 Oct, 2017 1 commit
  26. 10 Oct, 2017 1 commit
    • Tejun Heo's avatar
      workqueue: replace pool->manager_arb mutex with a flag · 692b4825
      Tejun Heo authored
      Josef reported a HARDIRQ-safe -> HARDIRQ-unsafe lock order detected by
      lockdep:
      
       [ 1270.472259] WARNING: HARDIRQ-safe -> HARDIRQ-unsafe lock order detected
       [ 1270.472783] 4.14.0-rc1-xfstests-12888-g76833e8 #110 Not tainted
       [ 1270.473240] -----------------------------------------------------
       [ 1270.473710] kworker/u5:2/5157 [HC0[0]:SC0[0]:HE0:SE1] is trying to acquire:
       [ 1270.474239]  (&(&lock->wait_lock)->rlock){+.+.}, at: [<ffffffff8da253d2>] __mutex_unlock_slowpath+0xa2/0x280
       [ 1270.474994]
       [ 1270.474994] and this task is already holding:
       [ 1270.475440]  (&pool->lock/1){-.-.}, at: [<ffffffff8d2992f6>] worker_thread+0x366/0x3c0
       [ 1270.476046] which would create a new lock dependency:
       [ 1270.476436]  (&pool->lock/1){-.-.} -> (&(&lock->wait_lock)->rlock){+.+.}
       [ 1270.476949]
       [ 1270.476949] but this new dependency connects a HARDIRQ-irq-safe lock:
       [ 1270.477553]  (&pool->lock/1){-.-.}
       ...
       [ 1270.488900] to a HARDIRQ-irq-unsafe lock:
       [ 1270.489327]  (&(&lock->wait_lock)->rlock){+.+.}
       ...
       [ 1270.494735]  Possible interrupt unsafe locking scenario:
       [ 1270.494735]
       [ 1270.495250]        CPU0                    CPU1
       [ 1270.495600]        ----                    ----
       [ 1270.495947]   lock(&(&lock->wait_lock)->rlock);
       [ 1270.496295]                                local_irq_disable();
       [ 1270.496753]                                lock(&pool->lock/1);
       [ 1270.497205]                                lock(&(&lock->wait_lock)->rlock);
       [ 1270.497744]   <Interrupt>
       [ 1270.497948]     lock(&pool->lock/1);
      
      , which will cause a irq inversion deadlock if the above lock scenario
      happens.
      
      The root cause of this safe -> unsafe lock order is the
      mutex_unlock(pool->manager_arb) in manage_workers() with pool->lock
      held.
      
      Unlocking mutex while holding an irq spinlock was never safe and this
      problem has been around forever but it never got noticed because the
      only time the mutex is usually trylocked while holding irqlock making
      actual failures very unlikely and lockdep annotation missed the
      condition until the recent b9c16a0e ("locking/mutex: Fix
      lockdep_assert_held() fail").
      
      Using mutex for pool->manager_arb has always been a bit of stretch.
      It primarily is an mechanism to arbitrate managership between workers
      which can easily be done with a pool flag.  The only reason it became
      a mutex is that pool destruction path wants to exclude parallel
      managing operations.
      
      This patch replaces the mutex with a new pool flag POOL_MANAGER_ACTIVE
      and make the destruction path wait for the current manager on a wait
      queue.
      
      v2: Drop unnecessary flag clearing before pool destruction as
          suggested by Boqun.
      Signed-off-by: 's avatarTejun Heo <tj@kernel.org>
      Reported-by: 's avatarJosef Bacik <josef@toxicpanda.com>
      Reviewed-by: 's avatarLai Jiangshan <jiangshanlai@gmail.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Boqun Feng <boqun.feng@gmail.com>
      Cc: stable@vger.kernel.org
      692b4825
  27. 05 Oct, 2017 2 commits
    • Kees Cook's avatar
      workqueue: Convert callback to use from_timer() · 8c20feb6
      Kees Cook authored
      In preparation for unconditionally passing the struct timer_list pointer
      to all timer callbacks, switch workqueue to use from_timer() and pass the
      timer pointer explicitly.
      Signed-off-by: 's avatarKees Cook <keescook@chromium.org>
      Signed-off-by: 's avatarThomas Gleixner <tglx@linutronix.de>
      Cc: linux-mips@linux-mips.org
      Cc: Petr Mladek <pmladek@suse.com>
      Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
      Cc: Lai Jiangshan <jiangshanlai@gmail.com>
      Cc: Sebastian Reichel <sre@kernel.org>
      Cc: Kalle Valo <kvalo@qca.qualcomm.com>
      Cc: Paul Mackerras <paulus@samba.org>
      Cc: Pavel Machek <pavel@ucw.cz>
      Cc: linux1394-devel@lists.sourceforge.net
      Cc: Chris Metcalf <cmetcalf@mellanox.com>
      Cc: linux-s390@vger.kernel.org
      Cc: linux-wireless@vger.kernel.org
      Cc: "James E.J. Bottomley" <jejb@linux.vnet.ibm.com>
      Cc: Wim Van Sebroeck <wim@iguana.be>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Ursula Braun <ubraun@linux.vnet.ibm.com>
      Cc: Geert Uytterhoeven <geert@linux-m68k.org>
      Cc: Viresh Kumar <viresh.kumar@linaro.org>
      Cc: Harish Patil <harish.patil@cavium.com>
      Cc: Stephen Boyd <sboyd@codeaurora.org>
      Cc: Guenter Roeck <linux@roeck-us.net>
      Cc: Manish Chopra <manish.chopra@cavium.com>
      Cc: Len Brown <len.brown@intel.com>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: linux-pm@vger.kernel.org
      Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
      Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
      Cc: Julian Wiedmann <jwi@linux.vnet.ibm.com>
      Cc: John Stultz <john.stultz@linaro.org>
      Cc: Mark Gross <mark.gross@intel.com>
      Cc: linux-watchdog@vger.kernel.org
      Cc: linux-scsi@vger.kernel.org
      Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Ralf Baechle <ralf@linux-mips.org>
      Cc: Stefan Richter <stefanr@s5r6.in-berlin.de>
      Cc: Michael Reed <mdr@sgi.com>
      Cc: netdev@vger.kernel.org
      Cc: Tejun Heo <tj@kernel.org>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: linuxppc-dev@lists.ozlabs.org
      Cc: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
      Link: https://lkml.kernel.org/r/1507159627-127660-14-git-send-email-keescook@chromium.org
      8c20feb6
    • Kees Cook's avatar
      timer: Remove users of TIMER_DEFERRED_INITIALIZER · 5cd79d6a
      Kees Cook authored
      This removes uses of TIMER_DEFERRED_INITIALIZER and chooses a location
      to call timer_setup() from before add_timer() or mod_timer() is called.
      Adjusts callbacks to use from_timer() as needed.
      Signed-off-by: 's avatarKees Cook <keescook@chromium.org>
      Signed-off-by: 's avatarThomas Gleixner <tglx@linutronix.de>
      Cc: linux-mips@linux-mips.org
      Cc: Petr Mladek <pmladek@suse.com>
      Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
      Cc: Lai Jiangshan <jiangshanlai@gmail.com>
      Cc: Sebastian Reichel <sre@kernel.org>
      Cc: Kalle Valo <kvalo@qca.qualcomm.com>
      Cc: Paul Mackerras <paulus@samba.org>
      Cc: Pavel Machek <pavel@ucw.cz>
      Cc: linux1394-devel@lists.sourceforge.net
      Cc: Chris Metcalf <cmetcalf@mellanox.com>
      Cc: linux-s390@vger.kernel.org
      Cc: linux-wireless@vger.kernel.org
      Cc: "James E.J. Bottomley" <jejb@linux.vnet.ibm.com>
      Cc: Wim Van Sebroeck <wim@iguana.be>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Ursula Braun <ubraun@linux.vnet.ibm.com>
      Cc: Geert Uytterhoeven <geert@linux-m68k.org>
      Cc: Viresh Kumar <viresh.kumar@linaro.org>
      Cc: Harish Patil <harish.patil@cavium.com>
      Cc: Stephen Boyd <sboyd@codeaurora.org>
      Cc: Guenter Roeck <linux@roeck-us.net>
      Cc: Manish Chopra <manish.chopra@cavium.com>
      Cc: Len Brown <len.brown@intel.com>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: linux-pm@vger.kernel.org
      Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
      Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
      Cc: Julian Wiedmann <jwi@linux.vnet.ibm.com>
      Cc: John Stultz <john.stultz@linaro.org>
      Cc: Mark Gross <mark.gross@intel.com>
      Cc: linux-watchdog@vger.kernel.org
      Cc: linux-scsi@vger.kernel.org
      Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Ralf Baechle <ralf@linux-mips.org>
      Cc: Stefan Richter <stefanr@s5r6.in-berlin.de>
      Cc: Michael Reed <mdr@sgi.com>
      Cc: netdev@vger.kernel.org
      Cc: Tejun Heo <tj@kernel.org>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: linuxppc-dev@lists.ozlabs.org
      Cc: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
      Link: https://lkml.kernel.org/r/1507159627-127660-7-git-send-email-keescook@chromium.org
      5cd79d6a
  28. 29 Aug, 2017 1 commit