linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/7] FS-Cache: Miscellaneous fixes
@ 2018-11-30 16:39 David Howells
  2018-11-30 16:39 ` [PATCH 1/7] cachefiles: Fix an assertion failure when trying to update a failed object David Howells
                   ` (6 more replies)
  0 siblings, 7 replies; 10+ messages in thread
From: David Howells @ 2018-11-30 16:39 UTC (permalink / raw)
  To: torvalds
  Cc: Kiran Kumar Modukuri, Arnd Bergmann, Shantanu Goel, NeilBrown,
	Daniel Axtens, Zhibin Li, Nick Desaulniers, Colin Ian King,
	Nathan Chancellor, dhowells, linux-cachefs, linux-fsdevel,
	linux-kernel


Hi Linus,

Can you pull these fixes for fscache and cachefiles?

 (1) Fix an assertion failure at fs/cachefiles/xattr.c:138 caused by a race
     between a cache object lookup failing and someone attempting to
     reenable that object, thereby triggering an update of the object's
     attributes.

 (2) Fix an assertion failure at fs/fscache/operation.c:449 caused by a
     split atomic subtract and atomic read that allows a race to happen.

 (3) Fix a leak of backing pages when simultaneously reading the same page
     from the same object from two or more threads.

 (4) Fix a hang due to a race between a cache object being discarded and
     the corresponding cookie being reenabled.

There are also some minor stuff.  Do you want me to punt these to the next
merge window instead?

 (5) Cast an enum value to a different enum type to prevent clang from
     generating a warning.  This shouldn't cause any sort of change in the
     emitted code.

 (6) Use ktime_get_real_seconds() instead of get_seconds().  This is just
     used to uniquify a filename for an object to be placed in the
     graveyard.  Objects placed there are deleted by cachfilesd in
     userspace immediately thereafter.

 (7) Remove an initialised, but otherwise unused variable.  This should
     have been entirely optimised away anyway.

The patches are tagged here:

	git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git
	fscache-fixes-20181130

and can also be found on the following branch:

	http://git.kernel.org/cgit/linux/kernel/git/dhowells/linux-fs.git/log/?h=fscache-fixes

Thanks,
David
---
Arnd Bergmann (1):
      cachefiles: avoid deprecated get_seconds()

Colin Ian King (1):
      fscache, cachefiles: remove redundant variable 'cache'

David Howells (1):
      cachefiles: Fix an assertion failure when trying to update a failed object

Kiran Kumar Modukuri (1):
      cachefiles: Fix page leak in cachefiles_read_backing_file while vmscan is active

Nathan Chancellor (1):
      cachefiles: Explicitly cast enumerated type in put_object

NeilBrown (1):
      fscache: fix race between enablement and dropping of object

kiran.modukuri (1):
      fscache: Fix race in fscache_op_complete() due to split atomic_sub & read


 fs/cachefiles/namei.c         |    8 +++++---
 fs/cachefiles/rdwr.c          |    9 ++++++---
 fs/cachefiles/xattr.c         |    3 ++-
 fs/fscache/object.c           |    3 +++
 include/linux/fscache-cache.h |    3 +--
 5 files changed, 17 insertions(+), 9 deletions(-)


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/7] cachefiles: Fix an assertion failure when trying to update a failed object
  2018-11-30 16:39 [PATCH 0/7] FS-Cache: Miscellaneous fixes David Howells
@ 2018-11-30 16:39 ` David Howells
  2018-11-30 16:40 ` [PATCH 2/7] fscache: Fix race in fscache_op_complete() due to split atomic_sub & read David Howells
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: David Howells @ 2018-11-30 16:39 UTC (permalink / raw)
  To: torvalds; +Cc: Zhibin Li, dhowells, linux-cachefs, linux-fsdevel, linux-kernel

If cachefiles gets an error other then ENOENT when trying to look up an
object in the cache (in this case, EACCES), the object state machine will
eventually transition to the DROP_OBJECT state.

This state invokes fscache_drop_object() which tries to sync the auxiliary
data with the cache (this is done lazily since commit 402cb8dda949d) on an
incomplete cache object struct.

The problem comes when cachefiles_update_object_xattr() is called to
rewrite the xattr holding the data.  There's an assertion there that the
cache object points to a dentry as we're going to update its xattr.  The
assertion trips, however, as dentry didn't get set.

Fix the problem by skipping the update in cachefiles if the object doesn't
refer to a dentry.  A better way to do it could be to skip the update from
the DROP_OBJECT state handler in fscache, but that might deny the cache the
opportunity to update intermediate state.

If this error occurs, the kernel log includes lines that look like the
following:

 CacheFiles: Lookup failed error -13
 CacheFiles:
 CacheFiles: Assertion failed
 ------------[ cut here ]------------
 kernel BUG at fs/cachefiles/xattr.c:138!
 ...
 Workqueue: fscache_object fscache_object_work_func [fscache]
 RIP: 0010:cachefiles_update_object_xattr.cold.4+0x18/0x1a [cachefiles]
 ...
 Call Trace:
  cachefiles_update_object+0xdd/0x1c0 [cachefiles]
  fscache_update_aux_data+0x23/0x30 [fscache]
  fscache_drop_object+0x18e/0x1c0 [fscache]
  fscache_object_work_func+0x74/0x2b0 [fscache]
  process_one_work+0x18d/0x340
  worker_thread+0x2e/0x390
  ? pwq_unbound_release_workfn+0xd0/0xd0
  kthread+0x112/0x130
  ? kthread_bind+0x30/0x30
  ret_from_fork+0x35/0x40

Note that there are actually two issues here: (1) EACCES happened on a
cache object and (2) an oops occurred.  I think that the second is a
consequence of the first (it certainly looks like it ought to be).  This
patch only deals with the second.

Fixes: 402cb8dda949 ("fscache: Attach the index key and aux data to the cookie")
Reported-by: Zhibin Li <zhibli@redhat.com>
Signed-off-by: David Howells <dhowells@redhat.com>
---

 fs/cachefiles/xattr.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/cachefiles/xattr.c b/fs/cachefiles/xattr.c
index 0a29a00aed2e..511e6c68156a 100644
--- a/fs/cachefiles/xattr.c
+++ b/fs/cachefiles/xattr.c
@@ -135,7 +135,8 @@ int cachefiles_update_object_xattr(struct cachefiles_object *object,
 	struct dentry *dentry = object->dentry;
 	int ret;
 
-	ASSERT(dentry);
+	if (!dentry)
+		return -ESTALE;
 
 	_enter("%p,#%d", object, auxdata->len);
 


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/7] fscache: Fix race in fscache_op_complete() due to split atomic_sub & read
  2018-11-30 16:39 [PATCH 0/7] FS-Cache: Miscellaneous fixes David Howells
  2018-11-30 16:39 ` [PATCH 1/7] cachefiles: Fix an assertion failure when trying to update a failed object David Howells
@ 2018-11-30 16:40 ` David Howells
  2018-11-30 16:40 ` [PATCH 3/7] cachefiles: Fix page leak in cachefiles_read_backing_file while vmscan is active David Howells
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: David Howells @ 2018-11-30 16:40 UTC (permalink / raw)
  To: torvalds
  Cc: Kiran Kumar Modukuri, dhowells, linux-cachefs, linux-fsdevel,
	linux-kernel

From: kiran.modukuri <kiran.modukuri@gmail.com>

The code in fscache_retrieval_complete is using atomic_sub followed by an
atomic_read:

        atomic_sub(n_pages, &op->n_pages);
        if (atomic_read(&op->n_pages) <= 0)
                fscache_op_complete(&op->op, true);

This causes two threads doing a decrement of n_pages to race with each
other seeing the op->refcount 0 at same time - and they end up calling
fscache_op_complete() in both the threads leading to an assertion failure.

Fix this by using atomic_sub_return_relaxed() instead of two calls.  Note
that I'm using 'relaxed' rather than, say, 'release' as there aren't
multiple variables that appear to need ordering across the release.

The oops looks something like:

FS-Cache: Assertion failed
FS-Cache: 0 > 0 is false
...
kernel BUG at /usr/src/linux-4.4.0/fs/fscache/operation.c:449!
...
Workqueue: fscache_operation fscache_op_work_func [fscache]
...
RIP: 0010:[<ffffffffc037eacd>] fscache_op_complete+0x10d/0x180 [fscache]
...
Call Trace:
 [<ffffffffc1464cf9>] cachefiles_read_copier+0x3a9/0x410 [cachefiles]
 [<ffffffffc037e272>] fscache_op_work_func+0x22/0x50 [fscache]
 [<ffffffff81096da0>] process_one_work+0x150/0x3f0
 [<ffffffff8109751a>] worker_thread+0x11a/0x470
 [<ffffffff81808e59>] ? __schedule+0x359/0x980
 [<ffffffff81097400>] ? rescuer_thread+0x310/0x310
 [<ffffffff8109cdd6>] kthread+0xd6/0xf0
 [<ffffffff8109cd00>] ? kthread_park+0x60/0x60
 [<ffffffff8180d0cf>] ret_from_fork+0x3f/0x70
 [<ffffffff8109cd00>] ? kthread_park+0x60/0x60

This seen this in 4.4.x kernels and the same bug affects fscache in latest
upstreams kernels.

Fixes: 1bb4b7f98f36 ("FS-Cache: The retrieval remaining-pages counter needs to be atomic_t")
Signed-off-by: Kiran Kumar Modukuri <kiran.modukuri@gmail.com>
Signed-off-by: David Howells <dhowells@redhat.com>
---

 include/linux/fscache-cache.h |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
index 34cf0fdd7dc7..610815e3f1aa 100644
--- a/include/linux/fscache-cache.h
+++ b/include/linux/fscache-cache.h
@@ -196,8 +196,7 @@ static inline void fscache_enqueue_retrieval(struct fscache_retrieval *op)
 static inline void fscache_retrieval_complete(struct fscache_retrieval *op,
 					      int n_pages)
 {
-	atomic_sub(n_pages, &op->n_pages);
-	if (atomic_read(&op->n_pages) <= 0)
+	if (atomic_sub_return_relaxed(n_pages, &op->n_pages) <= 0)
 		fscache_op_complete(&op->op, false);
 }
 


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/7] cachefiles: Fix page leak in cachefiles_read_backing_file while vmscan is active
  2018-11-30 16:39 [PATCH 0/7] FS-Cache: Miscellaneous fixes David Howells
  2018-11-30 16:39 ` [PATCH 1/7] cachefiles: Fix an assertion failure when trying to update a failed object David Howells
  2018-11-30 16:40 ` [PATCH 2/7] fscache: Fix race in fscache_op_complete() due to split atomic_sub & read David Howells
@ 2018-11-30 16:40 ` David Howells
  2018-12-01  0:23   ` Daniel Axtens
  2018-12-01 13:36   ` David Howells
  2018-11-30 16:40 ` [PATCH 4/7] fscache: fix race between enablement and dropping of object David Howells
                   ` (3 subsequent siblings)
  6 siblings, 2 replies; 10+ messages in thread
From: David Howells @ 2018-11-30 16:40 UTC (permalink / raw)
  To: torvalds
  Cc: Daniel Axtens, Shantanu Goel, Kiran Kumar Modukuri,
	Daniel Axtens, dhowells, linux-cachefs, linux-fsdevel,
	linux-kernel

From: Kiran Kumar Modukuri <kiran.modukuri@gmail.com>

[Description]

In a heavily loaded system where the system pagecache is nearing memory
limits and fscache is enabled, pages can be leaked by fscache while trying
read pages from cachefiles backend.  This can happen because two
applications can be reading same page from a single mount, two threads can
be trying to read the backing page at same time.  This results in one of
the threads finding that a page for the backing file or netfs file is
already in the radix tree.  During the error handling cachefiles does not
clean up the reference on backing page, leading to page leak.

[Fix]
The fix is straightforward, to decrement the reference when error is
encountered.

  [dhowells: Note that I've removed the clearance and put of newpage as
   they aren't attested in the commit message and don't appear to actually
   achieve anything since a new page is only allocated is newpage!=NULL and
   any residual new page is cleared before returning.]

[Testing]
I have tested the fix using following method for 12+ hrs.

1) mkdir -p /mnt/nfs ; mount -o vers=3,fsc <server_ip>:/export /mnt/nfs
2) create 10000 files of 2.8MB in a NFS mount.
3) start a thread to simulate heavy VM presssure
   (while true ; do echo 3 > /proc/sys/vm/drop_caches ; sleep 1 ; done)&
4) start multiple parallel reader for data set at same time
   find /mnt/nfs -type f | xargs -P 80 cat > /dev/null &
   find /mnt/nfs -type f | xargs -P 80 cat > /dev/null &
   find /mnt/nfs -type f | xargs -P 80 cat > /dev/null &
   ..
   ..
   find /mnt/nfs -type f | xargs -P 80 cat > /dev/null &
   find /mnt/nfs -type f | xargs -P 80 cat > /dev/null &
5) finally check using cat /proc/fs/fscache/stats | grep -i pages ;
   free -h , cat /proc/meminfo and page-types -r -b lru
   to ensure all pages are freed.

Reviewed-by: Daniel Axtens <dja@axtens.net>
Signed-off-by: Shantanu Goel <sgoel01@yahoo.com>
Signed-off-by: Kiran Kumar Modukuri <kiran.modukuri@gmail.com>
[dja: forward ported to current upstream]
Signed-off-by: Daniel Axtens <dja@axtens.net>
Signed-off-by: David Howells <dhowells@redhat.com>
---

 fs/cachefiles/rdwr.c |    6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
index 40f7595aad10..db233588a69a 100644
--- a/fs/cachefiles/rdwr.c
+++ b/fs/cachefiles/rdwr.c
@@ -535,7 +535,10 @@ static int cachefiles_read_backing_file(struct cachefiles_object *object,
 					    netpage->index, cachefiles_gfp);
 		if (ret < 0) {
 			if (ret == -EEXIST) {
+				put_page(backpage);
+				backpage = NULL;
 				put_page(netpage);
+				netpage = NULL;
 				fscache_retrieval_complete(op, 1);
 				continue;
 			}
@@ -608,7 +611,10 @@ static int cachefiles_read_backing_file(struct cachefiles_object *object,
 					    netpage->index, cachefiles_gfp);
 		if (ret < 0) {
 			if (ret == -EEXIST) {
+				put_page(backpage);
+				backpage = NULL;
 				put_page(netpage);
+				netpage = NULL;
 				fscache_retrieval_complete(op, 1);
 				continue;
 			}


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 4/7] fscache: fix race between enablement and dropping of object
  2018-11-30 16:39 [PATCH 0/7] FS-Cache: Miscellaneous fixes David Howells
                   ` (2 preceding siblings ...)
  2018-11-30 16:40 ` [PATCH 3/7] cachefiles: Fix page leak in cachefiles_read_backing_file while vmscan is active David Howells
@ 2018-11-30 16:40 ` David Howells
  2018-11-30 16:40 ` [PATCH 5/7] cachefiles: Explicitly cast enumerated type in put_object David Howells
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: David Howells @ 2018-11-30 16:40 UTC (permalink / raw)
  To: torvalds; +Cc: NeilBrown, dhowells, linux-cachefs, linux-fsdevel, linux-kernel

From: NeilBrown <neilb@suse.com>

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"
 #0 [ffff881ff43efbf8] schedule at ffffffff815e56f1
 #1 [ffff881ff43efc58] bit_wait at ffffffff815e64ed
 #2 [ffff881ff43efc68] __wait_on_bit at ffffffff815e61b8
 #3 [ffff881ff43efca0] out_of_line_wait_on_bit at ffffffff815e625e
 #4 [ffff881ff43efd08] fscache_wait_for_deferred_lookup at ffffffffa04f2e8f [fscache]
 #5 [ffff881ff43efd18] __fscache_read_or_alloc_page at ffffffffa04f2ffe [fscache]
 #6 [ffff881ff43efd58] __nfs_readpage_from_fscache at ffffffffa0679668 [nfs]
 #7 [ffff881ff43efd78] nfs_readpage at ffffffffa067092b [nfs]
 #8 [ffff881ff43efda0] generic_file_read_iter at ffffffff81187a73
 #9 [ffff881ff43efe50] nfs_file_read at ffffffffa066544b [nfs]
#10 [ffff881ff43efe70] __vfs_read at ffffffff811fc756
#11 [ffff881ff43efee8] vfs_read at ffffffff811fccfa
#12 [ffff881ff43eff18] sys_read at ffffffff811fda62
#13 [ffff881ff43eff50] entry_SYSCALL_64_fastpath at ffffffff815e986e

Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: David Howells <dhowells@redhat.com>
---

 fs/fscache/object.c |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/fscache/object.c b/fs/fscache/object.c
index 9edc920f651f..6d9cb1719de5 100644
--- a/fs/fscache/object.c
+++ b/fs/fscache/object.c
@@ -730,6 +730,9 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
 
 	if (awaken)
 		wake_up_bit(&cookie->flags, FSCACHE_COOKIE_INVALIDATING);
+	if (test_and_clear_bit(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags))
+		wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
+
 
 	/* Prevent a race with our last child, which has to signal EV_CLEARED
 	 * before dropping our spinlock.


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 5/7] cachefiles: Explicitly cast enumerated type in put_object
  2018-11-30 16:39 [PATCH 0/7] FS-Cache: Miscellaneous fixes David Howells
                   ` (3 preceding siblings ...)
  2018-11-30 16:40 ` [PATCH 4/7] fscache: fix race between enablement and dropping of object David Howells
@ 2018-11-30 16:40 ` David Howells
  2018-11-30 16:41 ` [PATCH 6/7] cachefiles: avoid deprecated get_seconds() David Howells
  2018-11-30 16:41 ` [PATCH 7/7] fscache, cachefiles: remove redundant variable 'cache' David Howells
  6 siblings, 0 replies; 10+ messages in thread
From: David Howells @ 2018-11-30 16:40 UTC (permalink / raw)
  To: torvalds
  Cc: Nick Desaulniers, Nathan Chancellor, dhowells, linux-cachefs,
	linux-fsdevel, linux-kernel

From: Nathan Chancellor <natechancellor@gmail.com>

Clang warns when one enumerated type is implicitly converted to another.

fs/cachefiles/namei.c:247:50: warning: implicit conversion from
enumeration type 'enum cachefiles_obj_ref_trace' to different
enumeration type 'enum fscache_obj_ref_trace' [-Wenum-conversion]
        cache->cache.ops->put_object(&xobject->fscache,
cachefiles_obj_put_wait_retry);

Silence this warning by explicitly casting to fscache_obj_ref_trace,
which is also done in put_object.

Reported-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
Signed-off-by: David Howells <dhowells@redhat.com>
---

 fs/cachefiles/namei.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
index 95983c744164..5ab411d4bc59 100644
--- a/fs/cachefiles/namei.c
+++ b/fs/cachefiles/namei.c
@@ -244,11 +244,13 @@ static int cachefiles_mark_object_active(struct cachefiles_cache *cache,
 
 	ASSERT(!test_bit(CACHEFILES_OBJECT_ACTIVE, &xobject->flags));
 
-	cache->cache.ops->put_object(&xobject->fscache, cachefiles_obj_put_wait_retry);
+	cache->cache.ops->put_object(&xobject->fscache,
+		(enum fscache_obj_ref_trace)cachefiles_obj_put_wait_retry);
 	goto try_again;
 
 requeue:
-	cache->cache.ops->put_object(&xobject->fscache, cachefiles_obj_put_wait_timeo);
+	cache->cache.ops->put_object(&xobject->fscache,
+		(enum fscache_obj_ref_trace)cachefiles_obj_put_wait_timeo);
 	_leave(" = -ETIMEDOUT");
 	return -ETIMEDOUT;
 }


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 6/7] cachefiles: avoid deprecated get_seconds()
  2018-11-30 16:39 [PATCH 0/7] FS-Cache: Miscellaneous fixes David Howells
                   ` (4 preceding siblings ...)
  2018-11-30 16:40 ` [PATCH 5/7] cachefiles: Explicitly cast enumerated type in put_object David Howells
@ 2018-11-30 16:41 ` David Howells
  2018-11-30 16:41 ` [PATCH 7/7] fscache, cachefiles: remove redundant variable 'cache' David Howells
  6 siblings, 0 replies; 10+ messages in thread
From: David Howells @ 2018-11-30 16:41 UTC (permalink / raw)
  To: torvalds
  Cc: Arnd Bergmann, dhowells, linux-cachefs, linux-fsdevel, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

get_seconds() returns an unsigned long can overflow on some architectures
and is deprecated because of that. In cachefs, we cast that number to
a a 32-bit integer, which will overflow in year 2106 on all architectures.

As confirmed by David Howells, the overflow probably isn't harmful
in the end, since the timestamps are only used to make the file names
unique, but they don't strictly have to be in monotonically increasing
order since the files only exist in order to be deleted as quickly
as possible.

Moving to ktime_get_real_seconds() avoids the deprecated interface.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: David Howells <dhowells@redhat.com>
---

 fs/cachefiles/namei.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
index 5ab411d4bc59..1645fcfd9691 100644
--- a/fs/cachefiles/namei.c
+++ b/fs/cachefiles/namei.c
@@ -338,7 +338,7 @@ static int cachefiles_bury_object(struct cachefiles_cache *cache,
 try_again:
 	/* first step is to make up a grave dentry in the graveyard */
 	sprintf(nbuffer, "%08x%08x",
-		(uint32_t) get_seconds(),
+		(uint32_t) ktime_get_real_seconds(),
 		(uint32_t) atomic_inc_return(&cache->gravecounter));
 
 	/* do the multiway lock magic */


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 7/7] fscache, cachefiles: remove redundant variable 'cache'
  2018-11-30 16:39 [PATCH 0/7] FS-Cache: Miscellaneous fixes David Howells
                   ` (5 preceding siblings ...)
  2018-11-30 16:41 ` [PATCH 6/7] cachefiles: avoid deprecated get_seconds() David Howells
@ 2018-11-30 16:41 ` David Howells
  6 siblings, 0 replies; 10+ messages in thread
From: David Howells @ 2018-11-30 16:41 UTC (permalink / raw)
  To: torvalds
  Cc: Colin Ian King, dhowells, linux-cachefs, linux-fsdevel, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Variable 'cache' is being assigned but is never used hence it is
redundant and can be removed.

Cleans up clang warning:
warning: variable 'cache' set but not used [-Wunused-but-set-variable]

Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: David Howells <dhowells@redhat.com>
---

 fs/cachefiles/rdwr.c |    3 ---
 1 file changed, 3 deletions(-)

diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
index db233588a69a..8a577409d030 100644
--- a/fs/cachefiles/rdwr.c
+++ b/fs/cachefiles/rdwr.c
@@ -968,11 +968,8 @@ void cachefiles_uncache_page(struct fscache_object *_object, struct page *page)
 	__releases(&object->fscache.cookie->lock)
 {
 	struct cachefiles_object *object;
-	struct cachefiles_cache *cache;
 
 	object = container_of(_object, struct cachefiles_object, fscache);
-	cache = container_of(object->fscache.cache,
-			     struct cachefiles_cache, cache);
 
 	_enter("%p,{%lu}", object, page->index);
 


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/7] cachefiles: Fix page leak in cachefiles_read_backing_file while vmscan is active
  2018-11-30 16:40 ` [PATCH 3/7] cachefiles: Fix page leak in cachefiles_read_backing_file while vmscan is active David Howells
@ 2018-12-01  0:23   ` Daniel Axtens
  2018-12-01 13:36   ` David Howells
  1 sibling, 0 replies; 10+ messages in thread
From: Daniel Axtens @ 2018-12-01  0:23 UTC (permalink / raw)
  To: David Howells, torvalds
  Cc: Shantanu Goel, Kiran Kumar Modukuri, dhowells, linux-cachefs,
	linux-fsdevel, linux-kernel

David Howells <dhowells@redhat.com> writes:

> From: Kiran Kumar Modukuri <kiran.modukuri@gmail.com>
>
> [Description]
>
> In a heavily loaded system where the system pagecache is nearing memory
> limits and fscache is enabled, pages can be leaked by fscache while trying
> read pages from cachefiles backend.  This can happen because two
> applications can be reading same page from a single mount, two threads can
> be trying to read the backing page at same time.  This results in one of
> the threads finding that a page for the backing file or netfs file is
> already in the radix tree.  During the error handling cachefiles does not
> clean up the reference on backing page, leading to page leak.
>
> [Fix]
> The fix is straightforward, to decrement the reference when error is
> encountered.
>
>   [dhowells: Note that I've removed the clearance and put of newpage as
>    they aren't attested in the commit message and don't appear to actually
>    achieve anything since a new page is only allocated is newpage!=NULL and
>    any residual new page is cleared before returning.]

Sorry I hadn't got back to you on this; I think we also discussed this
with the Ubuntu kernel team and concluded - as you did - that these
didn't fix any bugs but did make things seem more consistent.

Regards,
Daniel
>
> [Testing]
> I have tested the fix using following method for 12+ hrs.
>
> 1) mkdir -p /mnt/nfs ; mount -o vers=3,fsc <server_ip>:/export /mnt/nfs
> 2) create 10000 files of 2.8MB in a NFS mount.
> 3) start a thread to simulate heavy VM presssure
>    (while true ; do echo 3 > /proc/sys/vm/drop_caches ; sleep 1 ; done)&
> 4) start multiple parallel reader for data set at same time
>    find /mnt/nfs -type f | xargs -P 80 cat > /dev/null &
>    find /mnt/nfs -type f | xargs -P 80 cat > /dev/null &
>    find /mnt/nfs -type f | xargs -P 80 cat > /dev/null &
>    ..
>    ..
>    find /mnt/nfs -type f | xargs -P 80 cat > /dev/null &
>    find /mnt/nfs -type f | xargs -P 80 cat > /dev/null &
> 5) finally check using cat /proc/fs/fscache/stats | grep -i pages ;
>    free -h , cat /proc/meminfo and page-types -r -b lru
>    to ensure all pages are freed.
>
> Reviewed-by: Daniel Axtens <dja@axtens.net>
> Signed-off-by: Shantanu Goel <sgoel01@yahoo.com>
> Signed-off-by: Kiran Kumar Modukuri <kiran.modukuri@gmail.com>
> [dja: forward ported to current upstream]
> Signed-off-by: Daniel Axtens <dja@axtens.net>
> Signed-off-by: David Howells <dhowells@redhat.com>
> ---
>
>  fs/cachefiles/rdwr.c |    6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
> index 40f7595aad10..db233588a69a 100644
> --- a/fs/cachefiles/rdwr.c
> +++ b/fs/cachefiles/rdwr.c
> @@ -535,7 +535,10 @@ static int cachefiles_read_backing_file(struct cachefiles_object *object,
>  					    netpage->index, cachefiles_gfp);
>  		if (ret < 0) {
>  			if (ret == -EEXIST) {
> +				put_page(backpage);
> +				backpage = NULL;
>  				put_page(netpage);
> +				netpage = NULL;
>  				fscache_retrieval_complete(op, 1);
>  				continue;
>  			}
> @@ -608,7 +611,10 @@ static int cachefiles_read_backing_file(struct cachefiles_object *object,
>  					    netpage->index, cachefiles_gfp);
>  		if (ret < 0) {
>  			if (ret == -EEXIST) {
> +				put_page(backpage);
> +				backpage = NULL;
>  				put_page(netpage);
> +				netpage = NULL;
>  				fscache_retrieval_complete(op, 1);
>  				continue;
>  			}

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/7] cachefiles: Fix page leak in cachefiles_read_backing_file while vmscan is active
  2018-11-30 16:40 ` [PATCH 3/7] cachefiles: Fix page leak in cachefiles_read_backing_file while vmscan is active David Howells
  2018-12-01  0:23   ` Daniel Axtens
@ 2018-12-01 13:36   ` David Howells
  1 sibling, 0 replies; 10+ messages in thread
From: David Howells @ 2018-12-01 13:36 UTC (permalink / raw)
  To: Daniel Axtens
  Cc: dhowells, torvalds, Shantanu Goel, Kiran Kumar Modukuri,
	linux-cachefs, linux-fsdevel, linux-kernel

Daniel Axtens <dja@axtens.net> wrote:

> >   [dhowells: Note that I've removed the clearance and put of newpage as
> >    they aren't attested in the commit message and don't appear to actually
> >    achieve anything since a new page is only allocated is newpage!=NULL and
> >    any residual new page is cleared before returning.]
> 
> Sorry I hadn't got back to you on this; I think we also discussed this
> with the Ubuntu kernel team and concluded - as you did - that these
> didn't fix any bugs but did make things seem more consistent.

The idea is that if it fails to use the new page it caches it for the next
iteration of the loop rather than going to the allocator twice.  But making
the change you proposed, you should also remove the bit that discards the page
on the way out of the function and probably shouldn't initialise newpage at
the top of the function so that the compiler will let you know about paths
that don't handle it.

David

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2018-12-01 13:36 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-30 16:39 [PATCH 0/7] FS-Cache: Miscellaneous fixes David Howells
2018-11-30 16:39 ` [PATCH 1/7] cachefiles: Fix an assertion failure when trying to update a failed object David Howells
2018-11-30 16:40 ` [PATCH 2/7] fscache: Fix race in fscache_op_complete() due to split atomic_sub & read David Howells
2018-11-30 16:40 ` [PATCH 3/7] cachefiles: Fix page leak in cachefiles_read_backing_file while vmscan is active David Howells
2018-12-01  0:23   ` Daniel Axtens
2018-12-01 13:36   ` David Howells
2018-11-30 16:40 ` [PATCH 4/7] fscache: fix race between enablement and dropping of object David Howells
2018-11-30 16:40 ` [PATCH 5/7] cachefiles: Explicitly cast enumerated type in put_object David Howells
2018-11-30 16:41 ` [PATCH 6/7] cachefiles: avoid deprecated get_seconds() David Howells
2018-11-30 16:41 ` [PATCH 7/7] fscache, cachefiles: remove redundant variable 'cache' David Howells

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).