android_kernel_oneplus_msm8998/fs/fscache
NeilBrown b1ef956a8b fscache: fix race between enablement and dropping of object
[ Upstream commit c5a94f434c82529afda290df3235e4d85873c5b4 ]

It was observed that a process blocked indefintely in
__fscache_read_or_alloc_page(), waiting for FSCACHE_COOKIE_LOOKING_UP
to be cleared via fscache_wait_for_deferred_lookup().

At this time, ->backing_objects was empty, which would normaly prevent
__fscache_read_or_alloc_page() from getting to the point of waiting.
This implies that ->backing_objects was cleared *after*
__fscache_read_or_alloc_page was was entered.

When an object is "killed" and then "dropped",
FSCACHE_COOKIE_LOOKING_UP is cleared in fscache_lookup_failure(), then
KILL_OBJECT and DROP_OBJECT are "called" and only in DROP_OBJECT is
->backing_objects cleared.  This leaves a window where
something else can set FSCACHE_COOKIE_LOOKING_UP and
__fscache_read_or_alloc_page() can start waiting, before
->backing_objects is cleared

There is some uncertainty in this analysis, but it seems to be fit the
observations.  Adding the wake in this patch will be handled correctly
by __fscache_read_or_alloc_page(), as it checks if ->backing_objects
is empty again, after waiting.

Customer which reported the hang, also report that the hang cannot be
reproduced with this fix.

The backtrace for the blocked process looked like:

PID: 29360  TASK: ffff881ff2ac0f80  CPU: 3   COMMAND: "zsh"
  [ffff881ff43efbf8] schedule at ffffffff815e56f1
  [ffff881ff43efc58] bit_wait at ffffffff815e64ed
  [ffff881ff43efc68] __wait_on_bit at ffffffff815e61b8
  [ffff881ff43efca0] out_of_line_wait_on_bit at ffffffff815e625e
  [ffff881ff43efd08] fscache_wait_for_deferred_lookup at ffffffffa04f2e8f [fscache]
  [ffff881ff43efd18] __fscache_read_or_alloc_page at ffffffffa04f2ffe [fscache]
  [ffff881ff43efd58] __nfs_readpage_from_fscache at ffffffffa0679668 [nfs]
  [ffff881ff43efd78] nfs_readpage at ffffffffa067092b [nfs]
  [ffff881ff43efda0] generic_file_read_iter at ffffffff81187a73
  [ffff881ff43efe50] nfs_file_read at ffffffffa066544b [nfs]
 [ffff881ff43efe70] __vfs_read at ffffffff811fc756
 [ffff881ff43efee8] vfs_read at ffffffff811fccfa
 [ffff881ff43eff18] sys_read at ffffffff811fda62
 [ffff881ff43eff50] entry_SYSCALL_64_fastpath at ffffffff815e986e

Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2018-12-17 21:55:11 +01:00
..
cache.c fs/fscache: convert printk to pr_foo() 2014-06-04 16:53:51 -07:00
cookie.c fscache: Clear outstanding writes when disabling a cookie 2017-06-17 06:39:37 +02:00
fsdef.c FS-Cache: Provide the ability to enable/disable cookies 2013-09-27 18:40:25 +01:00
histogram.c fs/fscache: replace seq_printf by seq_puts 2014-06-04 16:53:52 -07:00
internal.h FS-Cache: The operation cancellation method needs calling in more places 2015-04-02 14:28:53 +01:00
Kconfig
main.c fs/fscache: make ctl_table static 2014-08-06 18:01:12 -07:00
Makefile
netfs.c FS-Cache: Initialise stores_lock in netfs cookie 2017-06-17 06:39:37 +02:00
object-list.c FS-Cache: fix dereference of NULL user_key_payload 2017-10-27 10:23:18 +02:00
object.c fscache: fix race between enablement and dropping of object 2018-12-17 21:55:11 +01:00
operation.c fscache: Allow cancelled operations to be enqueued 2018-09-05 09:18:35 +02:00
page.c fscache: Fix hanging wait on page discarded by writeback 2018-05-30 07:49:08 +02:00
proc.c
stats.c FS-Cache: Count the number of initialised operations 2015-04-02 14:28:53 +01:00