12 Jun, 2020

1 commit

  • Merge some more updates from Andrew Morton:

    - various hotfixes and minor things

    - hch's use_mm/unuse_mm clearnups

    Subsystems affected by this patch series: mm/hugetlb, scripts, kcov,
    lib, nilfs, checkpatch, lib, mm/debug, ocfs2, lib, misc.

    * emailed patches from Andrew Morton :
    kernel: set USER_DS in kthread_use_mm
    kernel: better document the use_mm/unuse_mm API contract
    kernel: move use_mm/unuse_mm to kthread.c
    kernel: move use_mm/unuse_mm to kthread.c
    stacktrace: cleanup inconsistent variable type
    lib: test get_count_order/long in test_bitops.c
    mm: add comments on pglist_data zones
    ocfs2: fix spelling mistake and grammar
    mm/debug_vm_pgtable: fix kernel crash by checking for THP support
    lib: fix bitmap_parse() on 64-bit big endian archs
    checkpatch: correct check for kernel parameters doc
    nilfs2: fix null pointer dereference at nilfs_segctor_do_construct()
    lib/lz4/lz4_decompress.c: document deliberate use of `&'
    kcov: check kcov_softirq in kcov_remote_stop()
    scripts/spelling: add a few more typos
    khugepaged: selftests: fix timeout condition in wait_for_scan()

    Linus Torvalds
     

11 Jun, 2020

2 commits

  • Switch the function documentation to kerneldoc comments, and add
    WARN_ON_ONCE asserts that the calling thread is a kernel thread and does
    not have ->mm set (or has ->mm set in the case of unuse_mm).

    Also give the functions a kthread_ prefix to better document the use case.

    [hch@lst.de: fix a comment typo, cover the newly merged use_mm/unuse_mm caller in vfio]
    Link: http://lkml.kernel.org/r/20200416053158.586887-3-hch@lst.de
    [sfr@canb.auug.org.au: powerpc/vas: fix up for {un}use_mm() rename]
    Link: http://lkml.kernel.org/r/20200422163935.5aa93ba5@canb.auug.org.au

    Signed-off-by: Christoph Hellwig
    Signed-off-by: Stephen Rothwell
    Signed-off-by: Andrew Morton
    Tested-by: Jens Axboe
    Reviewed-by: Jens Axboe
    Acked-by: Felix Kuehling
    Acked-by: Greg Kroah-Hartman [usb]
    Acked-by: Haren Myneni
    Cc: Alex Deucher
    Cc: Al Viro
    Cc: Felipe Balbi
    Cc: Jason Wang
    Cc: "Michael S. Tsirkin"
    Cc: Zhenyu Wang
    Cc: Zhi Wang
    Link: http://lkml.kernel.org/r/20200404094101.672954-6-hch@lst.de
    Signed-off-by: Linus Torvalds

    Christoph Hellwig
     
  • Patch series "improve use_mm / unuse_mm", v2.

    This series improves the use_mm / unuse_mm interface by better documenting
    the assumptions, and my taking the set_fs manipulations spread over the
    callers into the core API.

    This patch (of 3):

    Use the proper API instead.

    Link: http://lkml.kernel.org/r/20200404094101.672954-1-hch@lst.de

    These helpers are only for use with kernel threads, and I will tie them
    more into the kthread infrastructure going forward. Also move the
    prototypes to kthread.h - mmu_context.h was a little weird to start with
    as it otherwise contains very low-level MM bits.

    Signed-off-by: Christoph Hellwig
    Signed-off-by: Andrew Morton
    Tested-by: Jens Axboe
    Reviewed-by: Jens Axboe
    Acked-by: Felix Kuehling
    Cc: Alex Deucher
    Cc: Al Viro
    Cc: Felipe Balbi
    Cc: Jason Wang
    Cc: "Michael S. Tsirkin"
    Cc: Zhenyu Wang
    Cc: Zhi Wang
    Cc: Greg Kroah-Hartman
    Link: http://lkml.kernel.org/r/20200404094101.672954-1-hch@lst.de
    Link: http://lkml.kernel.org/r/20200416053158.586887-1-hch@lst.de
    Link: http://lkml.kernel.org/r/20200404094101.672954-5-hch@lst.de
    Signed-off-by: Linus Torvalds

    Christoph Hellwig
     

09 May, 2020

1 commit

  • It's handy to keep the kthread_fn just as a unique cookie to identify
    classes of kthreads. E.g. if you can verify that a given task is
    running your thread_fn, then you may know what sort of type kthread_data
    points to.

    We'll use this in nfsd to pass some information into the vfs. Note it
    will need kthread_data() exported too.

    Original-patch-by: Tejun Heo
    Signed-off-by: J. Bruce Fields

    J. Bruce Fields
     

03 Apr, 2020

1 commit

  • The timer used by delayed kthread works are IRQ safe because the used
    kthread_delayed_work_timer_fn() is IRQ safe.

    It is properly marked when initialized by KTHREAD_DELAYED_WORK_INIT().
    But TIMER_IRQSAFE flag is missing when initialized by
    kthread_init_delayed_work().

    The missing flag might trigger invalid warning from del_timer_sync() when
    kthread_mod_delayed_work() is called with interrupts disabled.

    This patch is result of a discussion about using the API, see
    https://lkml.kernel.org/r/cfa886ad-e3b7-c0d2-3ff8-58d94170eab5@ti.com

    Reported-by: Grygorii Strashko
    Signed-off-by: Petr Mladek
    Signed-off-by: Andrew Morton
    Tested-by: Grygorii Strashko
    Acked-by: Tejun Heo
    Cc: Thomas Gleixner
    Link: http://lkml.kernel.org/r/20200217120709.1974-1-pmladek@suse.com
    Signed-off-by: Linus Torvalds

    Petr Mladek
     

15 May, 2019

1 commit

  • kthread.h can't be included in psi_types.h because it creates a circular
    inclusion with kthread.h eventually including psi_types.h and
    complaining on kthread structures not being defined because they are
    defined further in the kthread.h. Resolve this by removing psi_types.h
    inclusion from the headers included from kthread.h.

    Link: http://lkml.kernel.org/r/20190319235619.260832-7-surenb@google.com
    Signed-off-by: Suren Baghdasaryan
    Acked-by: Johannes Weiner
    Cc: Dennis Zhou
    Cc: Ingo Molnar
    Cc: Jens Axboe
    Cc: Li Zefan
    Cc: Peter Zijlstra
    Cc: Tejun Heo
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Suren Baghdasaryan
     

07 Mar, 2019

1 commit

  • Pull scheduler updates from Ingo Molnar:
    "The main changes in this cycle were:

    - refcount conversions

    - Solve the rq->leaf_cfs_rq_list can of worms for real.

    - improve power-aware scheduling

    - add sysctl knob for Energy Aware Scheduling

    - documentation updates

    - misc other changes"

    * 'sched-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (34 commits)
    kthread: Do not use TIMER_IRQSAFE
    kthread: Convert worker lock to raw spinlock
    sched/fair: Use non-atomic cpumask_{set,clear}_cpu()
    sched/fair: Remove unused 'sd' parameter from select_idle_smt()
    sched/wait: Use freezable_schedule() when possible
    sched/fair: Prune, fix and simplify the nohz_balancer_kick() comment block
    sched/fair: Explain LLC nohz kick condition
    sched/fair: Simplify nohz_balancer_kick()
    sched/topology: Fix percpu data types in struct sd_data & struct s_data
    sched/fair: Simplify post_init_entity_util_avg() by calling it with a task_struct pointer argument
    sched/fair: Fix O(nr_cgroups) in the load balancing path
    sched/fair: Optimize update_blocked_averages()
    sched/fair: Fix insertion in rq->leaf_cfs_rq_list
    sched/fair: Add tmp_alone_branch assertion
    sched/core: Use READ_ONCE()/WRITE_ONCE() in move_queued_task()/task_rq_lock()
    sched/debug: Initialize sd_sysctl_cpus if !CONFIG_CPUMASK_OFFSTACK
    sched/pelt: Skip updating util_est when utilization is higher than CPU's capacity
    sched/fair: Update scale invariance of PELT
    sched/fair: Move the rq_of() helper function
    sched/core: Convert task_struct.stack_refcount to refcount_t
    ...

    Linus Torvalds
     

28 Feb, 2019

2 commits

  • The TIMER_IRQSAFE usage was introduced in commit 22597dc3d97b1 ("kthread:
    initial support for delayed kthread work") which modelled the delayed
    kthread code after workqueue's code. The workqueue code requires the flag
    TIMER_IRQSAFE for synchronisation purpose. This is not true for kthread's
    delay timer since all operations occur under a lock.

    Remove TIMER_IRQSAFE from the timer initialisation and use timer_setup()
    for initialisation purpose which is the official function.

    Signed-off-by: Sebastian Andrzej Siewior
    Signed-off-by: Thomas Gleixner
    Reviewed-by: Petr Mladek
    Link: https://lkml.kernel.org/r/20190212162554.19779-2-bigeasy@linutronix.de

    Sebastian Andrzej Siewior
     
  • In order to enable the queuing of kthread work items from hardirq context
    even when PREEMPT_RT_FULL is enabled, convert the worker spin_lock to a
    raw_spin_lock.

    This is only acceptable to do because the work performed under the lock is
    well-bounded and minimal.

    Reported-by: Steffen Trumtrar
    Reported-by: Tim Sander
    Signed-off-by: Julia Cartwright
    Signed-off-by: Sebastian Andrzej Siewior
    Signed-off-by: Thomas Gleixner
    Tested-by: Steffen Trumtrar
    Reviewed-by: Petr Mladek
    Cc: Guenter Roeck
    Link: https://lkml.kernel.org/r/20190212162554.19779-1-bigeasy@linutronix.de

    Julia Cartwright
     

11 Feb, 2019

1 commit

  • kthread_should_park() is used to check if the calling kthread ('current')
    should park, but there is no function to check whether an arbitrary kthread
    should be parked. The latter is required to plug a CPU hotplug race vs. a
    parking ksoftirqd thread.

    The new __kthread_should_park() receives a task_struct as parameter to
    check if the corresponding kernel thread should be parked.

    Call __kthread_should_park() from kthread_should_park() to avoid code
    duplication.

    Signed-off-by: Matthias Kaehlcke
    Signed-off-by: Thomas Gleixner
    Cc: Peter Zijlstra
    Cc: Steven Rostedt
    Cc: "Paul E . McKenney"
    Cc: Sebastian Andrzej Siewior
    Cc: Douglas Anderson
    Cc: Stephen Boyd
    Link: https://lkml.kernel.org/r/20190128234625.78241-2-mka@chromium.org

    Matthias Kaehlcke
     

03 Jul, 2018

1 commit

  • Gaurav reports that commit:

    85f1abe0019f ("kthread, sched/wait: Fix kthread_parkme() completion issue")

    isn't working for him. Because of the following race:

    > controller Thread CPUHP Thread
    > takedown_cpu
    > kthread_park
    > kthread_parkme
    > Set KTHREAD_SHOULD_PARK
    > smpboot_thread_fn
    > set Task interruptible
    >
    >
    > wake_up_process
    > if (!(p->state & state))
    > goto out;
    >
    > Kthread_parkme
    > SET TASK_PARKED
    > schedule
    > raw_spin_lock(&rq->lock)
    > ttwu_remote
    > waiting for __task_rq_lock
    > context_switch
    >
    > finish_lock_switch
    >
    >
    >
    > Case TASK_PARKED
    > kthread_park_complete
    >
    >
    > SET Running

    Furthermore, Oleg noticed that the whole scheduler TASK_PARKED
    handling is buggered because the TASK_DEAD thing is done with
    preemption disabled, the current code can still complete early on
    preemption :/

    So basically revert that earlier fix and go with a variant of the
    alternative mentioned in the commit. Promote TASK_PARKED to special
    state to avoid the store-store issue on task->state leading to the
    WARN in kthread_unpark() -> __kthread_bind().

    But in addition, add wait_task_inactive() to kthread_park() to ensure
    the task really is PARKED when we return from kthread_park(). This
    avoids the whole kthread still gets migrated nonsense -- although it
    would be really good to get this done differently.

    Reported-by: Gaurav Kohli
    Signed-off-by: Peter Zijlstra (Intel)
    Cc: Linus Torvalds
    Cc: Oleg Nesterov
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Fixes: 85f1abe0019f ("kthread, sched/wait: Fix kthread_parkme() completion issue")
    Signed-off-by: Ingo Molnar

    Peter Zijlstra
     

03 May, 2018

1 commit

  • Even with the wait-loop fixed, there is a further issue with
    kthread_parkme(). Upon hotplug, when we do takedown_cpu(),
    smpboot_park_threads() can return before all those threads are in fact
    blocked, due to the placement of the complete() in __kthread_parkme().

    When that happens, sched_cpu_dying() -> migrate_tasks() can end up
    migrating such a still runnable task onto another CPU.

    Normally the task will have hit schedule() and gone to sleep by the
    time we do kthread_unpark(), which will then do __kthread_bind() to
    re-bind the task to the correct CPU.

    However, when we loose the initial TASK_PARKED store to the concurrent
    wakeup issue described previously, do the complete(), get migrated, it
    is possible to either:

    - observe kthread_unpark()'s clearing of SHOULD_PARK and terminate
    the park and set TASK_RUNNING, or

    - __kthread_bind()'s wait_task_inactive() to observe the competing
    TASK_RUNNING store.

    Either way the WARN() in __kthread_bind() will trigger and fail to
    correctly set the CPU affinity.

    Fix this by only issuing the complete() when the kthread has scheduled
    out. This does away with all the icky 'still running' nonsense.

    The alternative is to promote TASK_PARKED to a special state, this
    guarantees wait_task_inactive() cannot observe a 'stale' TASK_RUNNING
    and we'll end up doing the right thing, but this preserves the whole
    icky business of potentially migating the still runnable thing.

    Reported-by: Gaurav Kohli
    Signed-off-by: Peter Zijlstra (Intel)
    Cc: Linus Torvalds
    Cc: Oleg Nesterov
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Signed-off-by: Ingo Molnar

    Peter Zijlstra
     

22 Nov, 2017

3 commits

  • 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: Kees Cook

    Kees Cook
     
  • With __init_timer*() now matching __setup_timer*(), remove the redundant
    internal interface, clean up the resulting definitions and add more
    documentation.

    Cc: Thomas Gleixner
    Cc: Tejun Heo
    Cc: Lai Jiangshan
    Cc: Shaohua Li
    Cc: Jens Axboe
    Cc: Andrew Morton
    Signed-off-by: Kees Cook

    Kees Cook
     
  • With the .data field removed, the ignored data arguments in timer macros
    can be removed.

    Cc: Thomas Gleixner
    Cc: Tejun Heo
    Cc: Lai Jiangshan
    Cc: Jens Axboe
    Cc: Andrew Morton
    Cc: Shaohua Li
    Signed-off-by: Kees Cook

    Kees Cook
     

15 Nov, 2017

1 commit

  • Pull core block layer updates from Jens Axboe:
    "This is the main pull request for block storage for 4.15-rc1.

    Nothing out of the ordinary in here, and no API changes or anything
    like that. Just various new features for drivers, core changes, etc.
    In particular, this pull request contains:

    - A patch series from Bart, closing the whole on blk/scsi-mq queue
    quescing.

    - A series from Christoph, building towards hidden gendisks (for
    multipath) and ability to move bio chains around.

    - NVMe
    - Support for native multipath for NVMe (Christoph).
    - Userspace notifications for AENs (Keith).
    - Command side-effects support (Keith).
    - SGL support (Chaitanya Kulkarni)
    - FC fixes and improvements (James Smart)
    - Lots of fixes and tweaks (Various)

    - bcache
    - New maintainer (Michael Lyle)
    - Writeback control improvements (Michael)
    - Various fixes (Coly, Elena, Eric, Liang, et al)

    - lightnvm updates, mostly centered around the pblk interface
    (Javier, Hans, and Rakesh).

    - Removal of unused bio/bvec kmap atomic interfaces (me, Christoph)

    - Writeback series that fix the much discussed hundreds of millions
    of sync-all units. This goes all the way, as discussed previously
    (me).

    - Fix for missing wakeup on writeback timer adjustments (Yafang
    Shao).

    - Fix laptop mode on blk-mq (me).

    - {mq,name} tupple lookup for IO schedulers, allowing us to have
    alias names. This means you can use 'deadline' on both !mq and on
    mq (where it's called mq-deadline). (me).

    - blktrace race fix, oopsing on sg load (me).

    - blk-mq optimizations (me).

    - Obscure waitqueue race fix for kyber (Omar).

    - NBD fixes (Josef).

    - Disable writeback throttling by default on bfq, like we do on cfq
    (Luca Miccio).

    - Series from Ming that enable us to treat flush requests on blk-mq
    like any other request. This is a really nice cleanup.

    - Series from Ming that improves merging on blk-mq with schedulers,
    getting us closer to flipping the switch on scsi-mq again.

    - BFQ updates (Paolo).

    - blk-mq atomic flags memory ordering fixes (Peter Z).

    - Loop cgroup support (Shaohua).

    - Lots of minor fixes from lots of different folks, both for core and
    driver code"

    * 'for-4.15/block' of git://git.kernel.dk/linux-block: (294 commits)
    nvme: fix visibility of "uuid" ns attribute
    blk-mq: fixup some comment typos and lengths
    ide: ide-atapi: fix compile error with defining macro DEBUG
    blk-mq: improve tag waiting setup for non-shared tags
    brd: remove unused brd_mutex
    blk-mq: only run the hardware queue if IO is pending
    block: avoid null pointer dereference on null disk
    fs: guard_bio_eod() needs to consider partitions
    xtensa/simdisk: fix compile error
    nvme: expose subsys attribute to sysfs
    nvme: create 'slaves' and 'holders' entries for hidden controllers
    block: create 'slaves' and 'holders' entries for hidden gendisks
    nvme: also expose the namespace identification sysfs files for mpath nodes
    nvme: implement multipath access to nvme subsystems
    nvme: track shared namespaces
    nvme: introduce a nvme_ns_ids structure
    nvme: track subsystems
    block, nvme: Introduce blk_mq_req_flags_t
    block, scsi: Make SCSI quiesce and resume work reliably
    block: Add the QUEUE_FLAG_PREEMPT_ONLY request queue flag
    ...

    Linus Torvalds
     

14 Nov, 2017

1 commit

  • Pull timer updates from Thomas Gleixner:
    "Yet another big pile of changes:

    - More year 2038 work from Arnd slowly reaching the point where we
    need to think about the syscalls themself.

    - A new timer function which allows to conditionally (re)arm a timer
    only when it's either not running or the new expiry time is sooner
    than the armed expiry time. This allows to use a single timer for
    multiple timeout requirements w/o caring about the first expiry
    time at the call site.

    - A new NMI safe accessor to clock real time for the printk timestamp
    work. Can be used by tracing, perf as well if required.

    - A large number of timer setup conversions from Kees which got
    collected here because either maintainers requested so or they
    simply got ignored. As Kees pointed out already there are a few
    trivial merge conflicts and some redundant commits which was
    unavoidable due to the size of this conversion effort.

    - Avoid a redundant iteration in the timer wheel softirq processing.

    - Provide a mechanism to treat RTC implementations depending on their
    hardware properties, i.e. don't inflict the write at the 0.5
    seconds boundary which originates from the PC CMOS RTC to all RTCs.
    No functional change as drivers need to be updated separately.

    - The usual small updates to core code clocksource drivers. Nothing
    really exciting"

    * 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (111 commits)
    timers: Add a function to start/reduce a timer
    pstore: Use ktime_get_real_fast_ns() instead of __getnstimeofday()
    timer: Prepare to change all DEFINE_TIMER() callbacks
    netfilter: ipvs: Convert timers to use timer_setup()
    scsi: qla2xxx: Convert timers to use timer_setup()
    block/aoe: discover_timer: Convert timers to use timer_setup()
    ide: Convert timers to use timer_setup()
    drbd: Convert timers to use timer_setup()
    mailbox: Convert timers to use timer_setup()
    crypto: Convert timers to use timer_setup()
    drivers/pcmcia: omap1: Fix error in automated timer conversion
    ARM: footbridge: Fix typo in timer conversion
    drivers/sgi-xp: Convert timers to use timer_setup()
    drivers/pcmcia: Convert timers to use timer_setup()
    drivers/memstick: Convert timers to use timer_setup()
    drivers/macintosh: Convert timers to use timer_setup()
    hwrng/xgene-rng: Convert timers to use timer_setup()
    auxdisplay: Convert timers to use timer_setup()
    sparc/led: Convert timers to use timer_setup()
    mips: ip22/32: Convert timers to use timer_setup()
    ...

    Linus Torvalds
     

02 Nov, 2017

1 commit

  • Many source files in the tree are missing licensing information, which
    makes it harder for compliance tools to determine the correct license.

    By default all files without license information are under the default
    license of the kernel, which is GPL version 2.

    Update the files which contain no license information with the 'GPL-2.0'
    SPDX license identifier. The SPDX identifier is a legally binding
    shorthand, which can be used instead of the full boiler plate text.

    This patch is based on work done by Thomas Gleixner and Kate Stewart and
    Philippe Ombredanne.

    How this work was done:

    Patches were generated and checked against linux-4.14-rc6 for a subset of
    the use cases:
    - file had no licensing information it it.
    - file was a */uapi/* one with no licensing information in it,
    - file was a */uapi/* one with existing licensing information,

    Further patches will be generated in subsequent months to fix up cases
    where non-standard license headers were used, and references to license
    had to be inferred by heuristics based on keywords.

    The analysis to determine which SPDX License Identifier to be applied to
    a file was done in a spreadsheet of side by side results from of the
    output of two independent scanners (ScanCode & Windriver) producing SPDX
    tag:value files created by Philippe Ombredanne. Philippe prepared the
    base worksheet, and did an initial spot review of a few 1000 files.

    The 4.13 kernel was the starting point of the analysis with 60,537 files
    assessed. Kate Stewart did a file by file comparison of the scanner
    results in the spreadsheet to determine which SPDX license identifier(s)
    to be applied to the file. She confirmed any determination that was not
    immediately clear with lawyers working with the Linux Foundation.

    Criteria used to select files for SPDX license identifier tagging was:
    - Files considered eligible had to be source code files.
    - Make and config files were included as candidates if they contained >5
    lines of source
    - File already had some variant of a license header in it (even if
    Reviewed-by: Philippe Ombredanne
    Reviewed-by: Thomas Gleixner
    Signed-off-by: Greg Kroah-Hartman

    Greg Kroah-Hartman
     

05 Oct, 2017

2 commits

  • In preparation for unconditionally passing the struct timer_list pointer
    to all timer callbacks, switch kthread to use from_timer() and pass the
    timer pointer explicitly.

    Signed-off-by: Kees Cook
    Signed-off-by: Thomas Gleixner
    Cc: linux-mips@linux-mips.org
    Cc: Len Brown
    Cc: Benjamin Herrenschmidt
    Cc: Lai Jiangshan
    Cc: Sebastian Reichel
    Cc: Kalle Valo
    Cc: Paul Mackerras
    Cc: Pavel Machek
    Cc: linux1394-devel@lists.sourceforge.net
    Cc: Chris Metcalf
    Cc: linux-s390@vger.kernel.org
    Cc: linux-wireless@vger.kernel.org
    Cc: "James E.J. Bottomley"
    Cc: Wim Van Sebroeck
    Cc: Michael Ellerman
    Cc: Ursula Braun
    Cc: Geert Uytterhoeven
    Cc: Viresh Kumar
    Cc: Harish Patil
    Cc: Stephen Boyd
    Cc: Guenter Roeck
    Cc: Manish Chopra
    Cc: Petr Mladek
    Cc: Arnd Bergmann
    Cc: linux-pm@vger.kernel.org
    Cc: Heiko Carstens
    Cc: Martin Schwidefsky
    Cc: Julian Wiedmann
    Cc: John Stultz
    Cc: Mark Gross
    Cc: linux-watchdog@vger.kernel.org
    Cc: linux-scsi@vger.kernel.org
    Cc: "Martin K. Petersen"
    Cc: Greg Kroah-Hartman
    Cc: "Rafael J. Wysocki"
    Cc: Oleg Nesterov
    Cc: Ralf Baechle
    Cc: Stefan Richter
    Cc: Michael Reed
    Cc: netdev@vger.kernel.org
    Cc: Tejun Heo
    Cc: Andrew Morton
    Cc: linuxppc-dev@lists.ozlabs.org
    Cc: Sudip Mukherjee
    Link: https://lkml.kernel.org/r/1507159627-127660-13-git-send-email-keescook@chromium.org

    Kees Cook
     
  • The expires field is normally initialized during the first mod_timer()
    call. It was unused by all callers, so remove it from the macro.

    Signed-off-by: Kees Cook
    Cc: linux-mips@linux-mips.org
    Cc: Petr Mladek
    Cc: Benjamin Herrenschmidt
    Cc: Lai Jiangshan
    Cc: Sebastian Reichel
    Cc: Kalle Valo
    Cc: Paul Mackerras
    Cc: Pavel Machek
    Cc: linux1394-devel@lists.sourceforge.net
    Cc: Chris Metcalf
    Cc: linux-s390@vger.kernel.org
    Cc: linux-wireless@vger.kernel.org
    Cc: "James E.J. Bottomley"
    Cc: Wim Van Sebroeck
    Cc: Michael Ellerman
    Cc: Ursula Braun
    Cc: Geert Uytterhoeven
    Cc: Viresh Kumar
    Cc: Harish Patil
    Cc: Stephen Boyd
    Cc: Michael Reed
    Cc: Manish Chopra
    Cc: Len Brown
    Cc: Arnd Bergmann
    Cc: linux-pm@vger.kernel.org
    Cc: Heiko Carstens
    Cc: Tejun Heo
    Cc: Julian Wiedmann
    Cc: John Stultz
    Cc: Mark Gross
    Cc: linux-watchdog@vger.kernel.org
    Cc: linux-scsi@vger.kernel.org
    Cc: "Martin K. Petersen"
    Cc: Greg Kroah-Hartman
    Cc: "Rafael J. Wysocki"
    Cc: Oleg Nesterov
    Cc: Ralf Baechle
    Cc: Stefan Richter
    Cc: Guenter Roeck
    Cc: netdev@vger.kernel.org
    Cc: Martin Schwidefsky
    Cc: Andrew Morton
    Cc: linuxppc-dev@lists.ozlabs.org
    Cc: Sudip Mukherjee
    Link: https://lkml.kernel.org/r/1507159627-127660-12-git-send-email-keescook@chromium.org
    Signed-off-by: Thomas Gleixner

    Kees Cook
     

27 Sep, 2017

1 commit

  • The code is only for blkcg not for all cgroups

    Fixes: d4478e92d618 ("block/loop: make loop cgroup aware")
    Reported-by: kbuild test robot
    Signed-off-by: Shaohua Li
    Signed-off-by: Jens Axboe

    Shaohua Li
     

26 Sep, 2017

1 commit

  • kthread usually runs jobs on behalf of other threads. The jobs should be
    charged to cgroup of original threads. But the jobs run in a kthread,
    where we lose the cgroup context of original threads. The patch adds a
    machanism to record cgroup info of original threads in kthread context.
    Later we can retrieve the cgroup info and attach the cgroup info to jobs.

    Since this mechanism is only required by kthread, we store the cgroup
    info in kthread data instead of generic task_struct.

    Acked-by: Tejun Heo
    Signed-off-by: Shaohua Li
    Signed-off-by: Jens Axboe

    Shaohua Li
     

03 Aug, 2017

1 commit

  • The kerneldoc comment for kthread_create() had an incorrect argument
    name, leading to a warning in the docs build.

    Correct it, and make one more small step toward a warning-free build.

    Link: http://lkml.kernel.org/r/20170724135916.7f486c6f@lwn.net
    Signed-off-by: Jonathan Corbet
    Cc: Randy Dunlap
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Jonathan Corbet
     

13 Dec, 2016

1 commit

  • When commit fbae2d44aa1d ("kthread: add kthread_create_worker*()")
    introduced some kthread_create_...() functions which were taking
    printf-like parametter, it introduced __printf attributes to some
    functions (e.g. kthread_create_worker()). Nevertheless some new
    functions were forgotten (they have been detected thanks to
    -Wmissing-format-attribute warning flag).

    Add the missing __printf attributes to the newly-introduced functions in
    order to detect formatting issues at build-time with -Wformat flag.

    Link: http://lkml.kernel.org/r/20161126193543.22672-1-nicolas.iooss_linux@m4x.org
    Signed-off-by: Nicolas Iooss
    Reviewed-by: Petr Mladek
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Nicolas Iooss
     

08 Dec, 2016

1 commit

  • commit 23196f2e5f5d "kthread: Pin the stack via try_get_task_stack() /
    put_task_stack() in to_live_kthread() function" is a workaround for the
    fragile design of struct kthread being allocated on the task stack.

    struct kthread in its current form should be removed, but this needs
    cleanups outside of kthread.c.

    As a first step move struct kthread away from the task stack by making it
    kmalloc'ed. This allows to access kthread.exited without the magic of
    trying to pin task stack and the try logic in to_live_kthread().

    Signed-off-by: Oleg Nesterov
    Acked-by: Peter Zijlstra (Intel)
    Reviewed-by: Thomas Gleixner
    Cc: Chunming Zhou
    Cc: Roman Pen
    Cc: Petr Mladek
    Cc: Andy Lutomirski
    Cc: Tejun Heo
    Cc: Andy Lutomirski
    Cc: Alex Deucher
    Cc: Andrew Morton
    Link: http://lkml.kernel.org/r/20161129175057.GA5330@redhat.com
    Signed-off-by: Thomas Gleixner

    Oleg Nesterov
     

12 Oct, 2016

9 commits

  • This macro is referenced in other kerneldoc comments, but lacks one of its
    own; fix that.

    Link: http://lkml.kernel.org/r/20160826072313.726a3485@lwn.net
    Signed-off-by: Jonathan Corbet
    Reported-by: Mauro Carvalho Chehab
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Jonathan Corbet
     
  • This patch allows to make kthread worker freezable via a new @flags
    parameter. It will allow to avoid an init work in some kthreads.

    It currently does not affect the function of kthread_worker_fn()
    but it might help to do some optimization or fixes eventually.

    I currently do not know about any other use for the @flags
    parameter but I believe that we will want more flags
    in the future.

    Finally, I hope that it will not cause confusion with @flags member
    in struct kthread. Well, I guess that we will want to rework the
    basic kthreads implementation once all kthreads are converted into
    kthread workers or workqueues. It is possible that we will merge
    the two structures.

    Link: http://lkml.kernel.org/r/1470754545-17632-12-git-send-email-pmladek@suse.com
    Signed-off-by: Petr Mladek
    Acked-by: Tejun Heo
    Cc: Oleg Nesterov
    Cc: Ingo Molnar
    Cc: Peter Zijlstra
    Cc: Steven Rostedt
    Cc: "Paul E. McKenney"
    Cc: Josh Triplett
    Cc: Thomas Gleixner
    Cc: Jiri Kosina
    Cc: Borislav Petkov
    Cc: Michal Hocko
    Cc: Vlastimil Babka
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Petr Mladek
     
  • There are situations when we need to modify the delay of a delayed kthread
    work. For example, when the work depends on an event and the initial delay
    means a timeout. Then we want to queue the work immediately when the event
    happens.

    This patch implements kthread_mod_delayed_work() as inspired workqueues.
    It cancels the timer, removes the work from any worker list and queues it
    again with the given timeout.

    A very special case is when the work is being canceled at the same time.
    It might happen because of the regular kthread_cancel_delayed_work_sync()
    or by another kthread_mod_delayed_work(). In this case, we do nothing and
    let the other operation win. This should not normally happen as the caller
    is supposed to synchronize these operations a reasonable way.

    Link: http://lkml.kernel.org/r/1470754545-17632-11-git-send-email-pmladek@suse.com
    Signed-off-by: Petr Mladek
    Acked-by: Tejun Heo
    Cc: Oleg Nesterov
    Cc: Ingo Molnar
    Cc: Peter Zijlstra
    Cc: Steven Rostedt
    Cc: "Paul E. McKenney"
    Cc: Josh Triplett
    Cc: Thomas Gleixner
    Cc: Jiri Kosina
    Cc: Borislav Petkov
    Cc: Michal Hocko
    Cc: Vlastimil Babka
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Petr Mladek
     
  • We are going to use kthread workers more widely and sometimes we will need
    to make sure that the work is neither pending nor running.

    This patch implements cancel_*_sync() operations as inspired by
    workqueues. Well, we are synchronized against the other operations via
    the worker lock, we use del_timer_sync() and a counter to count parallel
    cancel operations. Therefore the implementation might be easier.

    First, we check if a worker is assigned. If not, the work has newer been
    queued after it was initialized.

    Second, we take the worker lock. It must be the right one. The work must
    not be assigned to another worker unless it is initialized in between.

    Third, we try to cancel the timer when it exists. The timer is deleted
    synchronously to make sure that the timer call back is not running. We
    need to temporary release the worker->lock to avoid a possible deadlock
    with the callback. In the meantime, we set work->canceling counter to
    avoid any queuing.

    Fourth, we try to remove the work from a worker list. It might be
    the list of either normal or delayed works.

    Fifth, if the work is running, we call kthread_flush_work(). It might
    take an arbitrary time. We need to release the worker-lock again. In the
    meantime, we again block any queuing by the canceling counter.

    As already mentioned, the check for a pending kthread work is done under a
    lock. In compare with workqueues, we do not need to fight for a single
    PENDING bit to block other operations. Therefore we do not suffer from
    the thundering storm problem and all parallel canceling jobs might use
    kthread_flush_work(). Any queuing is blocked until the counter gets zero.

    Link: http://lkml.kernel.org/r/1470754545-17632-10-git-send-email-pmladek@suse.com
    Signed-off-by: Petr Mladek
    Acked-by: Tejun Heo
    Cc: Oleg Nesterov
    Cc: Ingo Molnar
    Cc: Peter Zijlstra
    Cc: Steven Rostedt
    Cc: "Paul E. McKenney"
    Cc: Josh Triplett
    Cc: Thomas Gleixner
    Cc: Jiri Kosina
    Cc: Borislav Petkov
    Cc: Michal Hocko
    Cc: Vlastimil Babka
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Petr Mladek
     
  • We are going to use kthread_worker more widely and delayed works
    will be pretty useful.

    The implementation is inspired by workqueues. It uses a timer to queue
    the work after the requested delay. If the delay is zero, the work is
    queued immediately.

    In compare with workqueues, each work is associated with a single worker
    (kthread). Therefore the implementation could be much easier. In
    particular, we use the worker->lock to synchronize all the operations with
    the work. We do not need any atomic operation with a flags variable.

    In fact, we do not need any state variable at all. Instead, we add a list
    of delayed works into the worker. Then the pending work is listed either
    in the list of queued or delayed works. And the existing check of pending
    works is the same even for the delayed ones.

    A work must not be assigned to another worker unless reinitialized.
    Therefore the timer handler might expect that dwork->work->worker is valid
    and it could simply take the lock. We just add some sanity checks to help
    with debugging a potential misuse.

    Link: http://lkml.kernel.org/r/1470754545-17632-9-git-send-email-pmladek@suse.com
    Signed-off-by: Petr Mladek
    Acked-by: Tejun Heo
    Cc: Oleg Nesterov
    Cc: Ingo Molnar
    Cc: Peter Zijlstra
    Cc: Steven Rostedt
    Cc: "Paul E. McKenney"
    Cc: Josh Triplett
    Cc: Thomas Gleixner
    Cc: Jiri Kosina
    Cc: Borislav Petkov
    Cc: Michal Hocko
    Cc: Vlastimil Babka
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Petr Mladek
     
  • The current kthread worker users call flush() and stop() explicitly.
    This function does the same plus it frees the kthread_worker struct
    in one call.

    It is supposed to be used together with kthread_create_worker*() that
    allocates struct kthread_worker.

    Link: http://lkml.kernel.org/r/1470754545-17632-7-git-send-email-pmladek@suse.com
    Signed-off-by: Petr Mladek
    Cc: Oleg Nesterov
    Cc: Tejun Heo
    Cc: Ingo Molnar
    Cc: Peter Zijlstra
    Cc: Steven Rostedt
    Cc: "Paul E. McKenney"
    Cc: Josh Triplett
    Cc: Thomas Gleixner
    Cc: Jiri Kosina
    Cc: Borislav Petkov
    Cc: Michal Hocko
    Cc: Vlastimil Babka
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Petr Mladek
     
  • Kthread workers are currently created using the classic kthread API,
    namely kthread_run(). kthread_worker_fn() is passed as the @threadfn
    parameter.

    This patch defines kthread_create_worker() and
    kthread_create_worker_on_cpu() functions that hide implementation details.

    They enforce using kthread_worker_fn() for the main thread. But I doubt
    that there are any plans to create any alternative. In fact, I think that
    we do not want any alternative main thread because it would be hard to
    support consistency with the rest of the kthread worker API.

    The naming and function of kthread_create_worker() is inspired by the
    workqueues API like the rest of the kthread worker API.

    The kthread_create_worker_on_cpu() variant is motivated by the original
    kthread_create_on_cpu(). Note that we need to bind per-CPU kthread
    workers already when they are created. It makes the life easier.
    kthread_bind() could not be used later for an already running worker.

    This patch does _not_ convert existing kthread workers. The kthread
    worker API need more improvements first, e.g. a function to destroy the
    worker.

    IMPORTANT:

    kthread_create_worker_on_cpu() allows to use any format of the worker
    name, in compare with kthread_create_on_cpu(). The good thing is that it
    is more generic. The bad thing is that most users will need to pass the
    cpu number in two parameters, e.g. kthread_create_worker_on_cpu(cpu,
    "helper/%d", cpu).

    To be honest, the main motivation was to avoid the need for an empty
    va_list. The only legal way was to create a helper function that would be
    called with an empty list. Other attempts caused compilation warnings or
    even errors on different architectures.

    There were also other alternatives, for example, using #define or
    splitting __kthread_create_worker(). The used solution looked like the
    least ugly.

    Link: http://lkml.kernel.org/r/1470754545-17632-6-git-send-email-pmladek@suse.com
    Signed-off-by: Petr Mladek
    Acked-by: Tejun Heo
    Cc: Oleg Nesterov
    Cc: Ingo Molnar
    Cc: Peter Zijlstra
    Cc: Steven Rostedt
    Cc: "Paul E. McKenney"
    Cc: Josh Triplett
    Cc: Thomas Gleixner
    Cc: Jiri Kosina
    Cc: Borislav Petkov
    Cc: Michal Hocko
    Cc: Vlastimil Babka
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Petr Mladek
     
  • A good practice is to prefix the names of functions by the name
    of the subsystem.

    The kthread worker API is a mix of classic kthreads and workqueues. Each
    worker has a dedicated kthread. It runs a generic function that process
    queued works. It is implemented as part of the kthread subsystem.

    This patch renames the existing kthread worker API to use
    the corresponding name from the workqueues API prefixed by
    kthread_:

    __init_kthread_worker() -> __kthread_init_worker()
    init_kthread_worker() -> kthread_init_worker()
    init_kthread_work() -> kthread_init_work()
    insert_kthread_work() -> kthread_insert_work()
    queue_kthread_work() -> kthread_queue_work()
    flush_kthread_work() -> kthread_flush_work()
    flush_kthread_worker() -> kthread_flush_worker()

    Note that the names of DEFINE_KTHREAD_WORK*() macros stay
    as they are. It is common that the "DEFINE_" prefix has
    precedence over the subsystem names.

    Note that INIT() macros and init() functions use different
    naming scheme. There is no good solution. There are several
    reasons for this solution:

    + "init" in the function names stands for the verb "initialize"
    aka "initialize worker". While "INIT" in the macro names
    stands for the noun "INITIALIZER" aka "worker initializer".

    + INIT() macros are used only in DEFINE() macros

    + init() functions are used close to the other kthread()
    functions. It looks much better if all the functions
    use the same scheme.

    + There will be also kthread_destroy_worker() that will
    be used close to kthread_cancel_work(). It is related
    to the init() function. Again it looks better if all
    functions use the same naming scheme.

    + there are several precedents for such init() function
    names, e.g. amd_iommu_init_device(), free_area_init_node(),
    jump_label_init_type(), regmap_init_mmio_clk(),

    + It is not an argument but it was inconsistent even before.

    [arnd@arndb.de: fix linux-next merge conflict]
    Link: http://lkml.kernel.org/r/20160908135724.1311726-1-arnd@arndb.de
    Link: http://lkml.kernel.org/r/1470754545-17632-3-git-send-email-pmladek@suse.com
    Suggested-by: Andrew Morton
    Signed-off-by: Petr Mladek
    Cc: Oleg Nesterov
    Cc: Tejun Heo
    Cc: Ingo Molnar
    Cc: Peter Zijlstra
    Cc: Steven Rostedt
    Cc: "Paul E. McKenney"
    Cc: Josh Triplett
    Cc: Thomas Gleixner
    Cc: Jiri Kosina
    Cc: Borislav Petkov
    Cc: Michal Hocko
    Cc: Vlastimil Babka
    Signed-off-by: Arnd Bergmann
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Petr Mladek
     
  • Patch series "kthread: Kthread worker API improvements"

    The intention of this patchset is to make it easier to manipulate and
    maintain kthreads. Especially, I want to replace all the custom main
    cycles with a generic one. Also I want to make the kthreads sleep in a
    consistent state in a common place when there is no work.

    This patch (of 11):

    A good practice is to prefix the names of functions by the name of the
    subsystem.

    This patch fixes the name of probe_kthread_data(). The other wrong
    functions names are part of the kthread worker API and will be fixed
    separately.

    Link: http://lkml.kernel.org/r/1470754545-17632-2-git-send-email-pmladek@suse.com
    Signed-off-by: Petr Mladek
    Suggested-by: Andrew Morton
    Acked-by: Tejun Heo
    Cc: Oleg Nesterov
    Cc: Ingo Molnar
    Cc: Peter Zijlstra
    Cc: Steven Rostedt
    Cc: "Paul E. McKenney"
    Cc: Josh Triplett
    Cc: Thomas Gleixner
    Cc: Jiri Kosina
    Cc: Borislav Petkov
    Cc: Michal Hocko
    Cc: Vlastimil Babka
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Petr Mladek
     

05 Sep, 2015

1 commit

  • - Make it clear that the `node' arg refers to memory allocations only:
    kthread_create_on_node() does not pin the new thread to that node's
    CPUs.

    - Encourage the use of NUMA_NO_NODE.

    [nzimmer@sgi.com: use NUMA_NO_NODE in kthread_create() also]
    Cc: Nathan Zimmer
    Cc: Tejun Heo
    Cc: Eric Dumazet
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andrew Morton
     

12 Aug, 2015

1 commit

  • Because sched_setscheduler() checks p->flags & PF_NO_SETAFFINITY
    without locks, a caller might observe an old value and race with the
    set_cpus_allowed_ptr() call from __kthread_bind() and effectively undo
    it:

    __kthread_bind()
    do_set_cpus_allowed()

    sched_setaffinity()
    if (p->flags & PF_NO_SETAFFINITIY)
    set_cpus_allowed_ptr()
    p->flags |= PF_NO_SETAFFINITY

    Fix the bug by putting everything under the regular scheduler locks.

    This also closes a hole in the serialization of task_struct::{nr_,}cpus_allowed.

    Signed-off-by: Peter Zijlstra (Intel)
    Acked-by: Tejun Heo
    Cc: Linus Torvalds
    Cc: Mike Galbraith
    Cc: Oleg Nesterov
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: dedekind1@gmail.com
    Cc: juri.lelli@arm.com
    Cc: mgorman@suse.de
    Cc: riel@redhat.com
    Cc: rostedt@goodmis.org
    Link: http://lkml.kernel.org/r/20150515154833.545640346@infradead.org
    Signed-off-by: Ingo Molnar

    Peter Zijlstra
     

29 Jul, 2014

1 commit

  • The wait_queue_head_t kthread_work->done is unused since
    flush_kthread_work() has been re-implemented. Let's remove it
    including the initialization code. This makes
    DEFINE_KTHREAD_WORK_ONSTACK() unnecessary, removed.

    tj: Updated description. Removed DEFINE_KTHREAD_WORK_ONSTACK().

    Signed-off-by: Lai Jiangshan
    Signed-off-by: Tejun Heo

    Lai Jiangshan
     

01 May, 2013

1 commit

  • One of the problems that arise when converting dedicated custom threadpool
    to workqueue is that the shared worker pool used by workqueue anonimizes
    each worker making it more difficult to identify what the worker was doing
    on which target from the output of sysrq-t or debug dump from oops, BUG()
    and friends.

    For example, after writeback is converted to use workqueue instead of
    priviate thread pool, there's no easy to tell which backing device a
    writeback work item was working on at the time of task dump, which,
    according to our writeback brethren, is important in tracking down issues
    with a lot of mounted file systems on a lot of different devices.

    This patchset implements a way for a work function to mark its execution
    instance so that task dump of the worker task includes information to
    indicate what the work item was doing.

    An example WARN dump would look like the following.

    WARNING: at fs/fs-writeback.c:1015 bdi_writeback_workfn+0x2b4/0x3c0()
    Modules linked in:
    CPU: 0 Pid: 28 Comm: kworker/u18:0 Not tainted 3.9.0-rc1-work+ #24
    Hardware name: empty empty/S3992, BIOS 080011 10/26/2007
    Workqueue: writeback bdi_writeback_workfn (flush-8:16)
    ffffffff820a3a98 ffff88015b927cb8 ffffffff81c61855 ffff88015b927cf8
    ffffffff8108f500 0000000000000000 ffff88007a171948 ffff88007a1716b0
    ffff88015b49df00 ffff88015b8d3940 0000000000000000 ffff88015b927d08
    Call Trace:
    [] dump_stack+0x19/0x1b
    [] warn_slowpath_common+0x70/0xa0
    ...

    This patch:

    Implement probe_kthread_data() which returns kthread_data if accessible.
    The function is equivalent to kthread_data() except that the specified
    @task may not be a kthread or its vfork_done is already cleared rendering
    struct kthread inaccessible. In the former case, probe_kthread_data() may
    return any value. In the latter, NULL.

    This will be used to safely print debug information without affecting
    synchronization in the normal paths. Workqueue debug info printing on
    dump_stack() and friends will make use of it.

    Signed-off-by: Tejun Heo
    Cc: Oleg Nesterov
    Acked-by: Jan Kara
    Cc: Dave Chinner
    Cc: Ingo Molnar
    Cc: Jens Axboe
    Cc: Peter Zijlstra
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Tejun Heo
     

13 Aug, 2012

1 commit

  • To avoid the full teardown/setup of per cpu kthreads in the case of
    cpu hot(un)plug, provide a facility which allows to put the kthread
    into a park position and unpark it when the cpu comes online again.

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Namhyung Kim
    Cc: Peter Zijlstra
    Reviewed-by: Srivatsa S. Bhat
    Cc: Rusty Russell
    Reviewed-by: Paul E. McKenney
    Link: http://lkml.kernel.org/r/20120716103948.236618824@linutronix.de
    Signed-off-by: Thomas Gleixner

    Thomas Gleixner
     

23 Jul, 2012

1 commit

  • kthread_worker provides minimalistic workqueue-like interface for
    users which need a dedicated worker thread (e.g. for realtime
    priority). It has basic queue, flush_work, flush_worker operations
    which mostly match the workqueue counterparts; however, due to the way
    flush_work() is implemented, it has a noticeable difference of not
    allowing work items to be freed while being executed.

    While the current users of kthread_worker are okay with the current
    behavior, the restriction does impede some valid use cases. Also,
    removing this difference isn't difficult and actually makes the code
    easier to understand.

    This patch reimplements flush_kthread_work() such that it uses a
    flush_work item instead of queue/done sequence numbers.

    Signed-off-by: Tejun Heo

    Tejun Heo