# git rev-parse -q --verify 472e5b056f000a778abb41f1e443de58eb259783^{commit} 472e5b056f000a778abb41f1e443de58eb259783 already have revision, skipping fetch # git checkout -q -f -B kisskb 472e5b056f000a778abb41f1e443de58eb259783 # git clean -qxdf # < git log -1 # commit 472e5b056f000a778abb41f1e443de58eb259783 # Author: Linus Torvalds # Date: Thu Oct 1 19:14:36 2020 -0700 # # pipe: remove pipe_wait() and fix wakeup race with splice # # The pipe splice code still used the old model of waiting for pipe IO by # using a non-specific "pipe_wait()" that waited for any pipe event to # happen, which depended on all pipe IO being entirely serialized by the # pipe lock. So by checking the state you were waiting for, and then # adding yourself to the wait queue before dropping the lock, you were # guaranteed to see all the wakeups. # # Strictly speaking, the actual wakeups were not done under the lock, but # the pipe_wait() model still worked, because since the waiter held the # lock when checking whether it should sleep, it would always see the # current state, and the wakeup was always done after updating the state. # # However, commit 0ddad21d3e99 ("pipe: use exclusive waits when reading or # writing") split the single wait-queue into two, and in the process also # made the "wait for event" code wait for _two_ wait queues, and that then # showed a race with the wakers that were not serialized by the pipe lock. # # It's only splice that used that "pipe_wait()" model, so the problem # wasn't obvious, but Josef Bacik reports: # # "I hit a hang with fstest btrfs/187, which does a btrfs send into # /dev/null. This works by creating a pipe, the write side is given to # the kernel to write into, and the read side is handed to a thread that # splices into a file, in this case /dev/null. # # The box that was hung had the write side stuck here [pipe_write] and # the read side stuck here [splice_from_pipe_next -> pipe_wait]. # # [ more details about pipe_wait() scenario ] # # The problem is we're doing the prepare_to_wait, which sets our state # each time, however we can be woken up either with reads or writes. In # the case above we race with the WRITER waking us up, and re-set our # state to INTERRUPTIBLE, and thus never break out of schedule" # # Josef had a patch that avoided the issue in pipe_wait() by just making # it set the state only once, but the deeper problem is that pipe_wait() # depends on a level of synchonization by the pipe mutex that it really # shouldn't. And the whole "wait for any pipe state change" model really # isn't very good to begin with. # # So rather than trying to work around things in pipe_wait(), remove that # legacy model of "wait for arbitrary pipe event" entirely, and actually # create functions that wait for the pipe actually being readable or # writable, and can do so without depending on the pipe lock serializing # everything. # # Fixes: 0ddad21d3e99 ("pipe: use exclusive waits when reading or writing") # Link: https://lore.kernel.org/linux-fsdevel/bfa88b5ad6f069b2b679316b9e495a970130416c.1601567868.git.josef@toxicpanda.com/ # Reported-by: Josef Bacik # Reviewed-and-tested-by: Josef Bacik # Signed-off-by: Linus Torvalds # < /opt/cross/kisskb/korg/gcc-8.1.0-nolibc/nds32le-linux/bin/nds32le-linux-gcc --version # < /opt/cross/kisskb/korg/gcc-8.1.0-nolibc/nds32le-linux/bin/nds32le-linux-ld --version # < git log --format=%s --max-count=1 472e5b056f000a778abb41f1e443de58eb259783 # < make -s -j 24 ARCH=nds32 O=/kisskb/build/linus_nds32-allyesconfig_nds32le-gcc8 CROSS_COMPILE=/opt/cross/kisskb/korg/gcc-8.1.0-nolibc/nds32le-linux/bin/nds32le-linux- allyesconfig # < make -s -j 24 ARCH=nds32 O=/kisskb/build/linus_nds32-allyesconfig_nds32le-gcc8 CROSS_COMPILE=/opt/cross/kisskb/korg/gcc-8.1.0-nolibc/nds32le-linux/bin/nds32le-linux- help # make -s -j 24 ARCH=nds32 O=/kisskb/build/linus_nds32-allyesconfig_nds32le-gcc8 CROSS_COMPILE=/opt/cross/kisskb/korg/gcc-8.1.0-nolibc/nds32le-linux/bin/nds32le-linux- olddefconfig # make -s -j 24 ARCH=nds32 O=/kisskb/build/linus_nds32-allyesconfig_nds32le-gcc8 CROSS_COMPILE=/opt/cross/kisskb/korg/gcc-8.1.0-nolibc/nds32le-linux/bin/nds32le-linux- :1511:2: warning: #warning syscall clone3 not implemented [-Wcpp] /kisskb/src/drivers/input/joystick/analog.c:160:2: warning: #warning Precise timer not defined for this architecture. [-Wcpp] #warning Precise timer not defined for this architecture. ^~~~~~~ In file included from /kisskb/src/include/linux/printk.h:405, from /kisskb/src/include/linux/kernel.h:15, from /kisskb/src/include/linux/clk.h:13, from /kisskb/src/drivers/crypto/sa2ul.c:11: /kisskb/src/drivers/crypto/sa2ul.c: In function 'sa_sha_init': /kisskb/src/drivers/crypto/sa2ul.c:1486:33: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] crypto_ahash_digestsize(tfm), (u64)rctx); ^ /kisskb/src/include/linux/dynamic_debug.h:129:15: note: in definition of macro '__dynamic_func_call' func(&id, ##__VA_ARGS__); \ ^~~~~~~~~~~ /kisskb/src/include/linux/dynamic_debug.h:161:2: note: in expansion of macro '_dynamic_func_call' _dynamic_func_call(fmt,__dynamic_dev_dbg, \ ^~~~~~~~~~~~~~~~~~ /kisskb/src/include/linux/dev_printk.h:115:2: note: in expansion of macro 'dynamic_dev_dbg' dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__) ^~~~~~~~~~~~~~~ /kisskb/src/drivers/crypto/sa2ul.c:1485:2: note: in expansion of macro 'dev_dbg' dev_dbg(sa_k3_dev, "init: digest size: %d, rctx=%llx\n", ^~~~~~~ WARNING: modpost: EXPORT symbol "copy_page" [vmlinux] version generation failed, symbol will not be versioned. WARNING: modpost: EXPORT symbol "clear_page" [vmlinux] version generation failed, symbol will not be versioned. Completed OK # rm -rf /kisskb/build/linus_nds32-allyesconfig_nds32le-gcc8 # Build took: 0:16:13.776001