All of lore.kernel.org
 help / color / mirror / Atom feed
* incoming
@ 2021-04-23 21:28 Andrew Morton
  2021-04-23 21:28 ` [patch 1/5] coda: fix reference counting in coda_file_mmap error path Andrew Morton
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Andrew Morton @ 2021-04-23 21:28 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: mm-commits, linux-mm


5 patches, based on 5bfc75d92efd494db37f5c4c173d3639d4772966.

Subsystems affected by this patch series:

  coda
  overlayfs
  mm/pagecache
  mm/memcg

Subsystem: coda

    Christian König <christian.koenig@amd.com>:
      coda: fix reference counting in coda_file_mmap error path

Subsystem: overlayfs

    Christian König <christian.koenig@amd.com>:
      ovl: fix reference counting in ovl_mmap error path

Subsystem: mm/pagecache

    Hugh Dickins <hughd@google.com>:
      mm/filemap: fix find_lock_entries hang on 32-bit THP
      mm/filemap: fix mapping_seek_hole_data on THP & 32-bit

Subsystem: mm/memcg

    Vasily Averin <vvs@virtuozzo.com>:
      tools/cgroup/slabinfo.py: updated to work on current kernel

 fs/coda/file.c                 |    6 +++---
 fs/overlayfs/file.c            |   11 +----------
 mm/filemap.c                   |   31 +++++++++++++++++++------------
 tools/cgroup/memcg_slabinfo.py |    8 ++++----
 4 files changed, 27 insertions(+), 29 deletions(-)


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

* [patch 1/5] coda: fix reference counting in coda_file_mmap error path
  2021-04-23 21:28 incoming Andrew Morton
@ 2021-04-23 21:28 ` Andrew Morton
  2021-04-23 21:28 ` [patch 2/5] ovl: fix reference counting in ovl_mmap " Andrew Morton
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Andrew Morton @ 2021-04-23 21:28 UTC (permalink / raw)
  To: akpm, christian.koenig, daniel.vetter, jaharkes, jgg, linux-mm,
	miklos, mm-commits, stable, torvalds

From: Christian König <christian.koenig@amd.com>
Subject: coda: fix reference counting in coda_file_mmap error path

mmap_region() now calls fput() on the vma->vm_file.

So we need to drop the extra reference on the coda file instead of the
host file.

Link: https://lkml.kernel.org/r/20210421132012.82354-1-christian.koenig@amd.com
Fixes: 1527f926fd04 ("mm: mmap: fix fput in error path v2")
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Acked-by: Jan Harkes <jaharkes@cs.cmu.edu>
Cc: Miklos Szeredi <miklos@szeredi.hu>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: <stable@vger.kernel.org>	[5.11+]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 fs/coda/file.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

--- a/fs/coda/file.c~coda-fix-reference-counting-in-coda_file_mmap-error-path
+++ a/fs/coda/file.c
@@ -175,10 +175,10 @@ coda_file_mmap(struct file *coda_file, s
 	ret = call_mmap(vma->vm_file, vma);
 
 	if (ret) {
-		/* if call_mmap fails, our caller will put coda_file so we
-		 * should drop the reference to the host_file that we got.
+		/* if call_mmap fails, our caller will put host_file so we
+		 * should drop the reference to the coda_file that we got.
 		 */
-		fput(host_file);
+		fput(coda_file);
 		kfree(cvm_ops);
 	} else {
 		/* here we add redirects for the open/close vm_operations */
_

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

* [patch 2/5] ovl: fix reference counting in ovl_mmap error path
  2021-04-23 21:28 incoming Andrew Morton
  2021-04-23 21:28 ` [patch 1/5] coda: fix reference counting in coda_file_mmap error path Andrew Morton
@ 2021-04-23 21:28 ` Andrew Morton
  2021-04-23 21:28 ` [patch 3/5] mm/filemap: fix find_lock_entries hang on 32-bit THP Andrew Morton
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Andrew Morton @ 2021-04-23 21:28 UTC (permalink / raw)
  To: akpm, christian.koenig, daniel.vetter, jaharkes, jgg, linux-mm,
	miklos, mm-commits, stable, torvalds

From: Christian König <christian.koenig@amd.com>
Subject: ovl: fix reference counting in ovl_mmap error path

mmap_region() now calls fput() on the vma->vm_file.

Fix this by using vma_set_file() so it doesn't need to be handled manually
here any more.

Link: https://lkml.kernel.org/r/20210421132012.82354-2-christian.koenig@amd.com
Fixes: 1527f926fd04 ("mm: mmap: fix fput in error path v2")
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Jan Harkes <jaharkes@cs.cmu.edu>
Cc: Miklos Szeredi <miklos@szeredi.hu>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: <stable@vger.kernel.org>	[5.11+]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 fs/overlayfs/file.c |   11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)

--- a/fs/overlayfs/file.c~ovl-fix-reference-counting-in-ovl_mmap-error-path
+++ a/fs/overlayfs/file.c
@@ -430,20 +430,11 @@ static int ovl_mmap(struct file *file, s
 	if (WARN_ON(file != vma->vm_file))
 		return -EIO;
 
-	vma->vm_file = get_file(realfile);
+	vma_set_file(vma, realfile);
 
 	old_cred = ovl_override_creds(file_inode(file)->i_sb);
 	ret = call_mmap(vma->vm_file, vma);
 	revert_creds(old_cred);
-
-	if (ret) {
-		/* Drop reference count from new vm_file value */
-		fput(realfile);
-	} else {
-		/* Drop reference count from previous vm_file value */
-		fput(file);
-	}
-
 	ovl_file_accessed(file);
 
 	return ret;
_

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

* [patch 3/5] mm/filemap: fix find_lock_entries hang on 32-bit THP
  2021-04-23 21:28 incoming Andrew Morton
  2021-04-23 21:28 ` [patch 1/5] coda: fix reference counting in coda_file_mmap error path Andrew Morton
  2021-04-23 21:28 ` [patch 2/5] ovl: fix reference counting in ovl_mmap " Andrew Morton
@ 2021-04-23 21:28 ` Andrew Morton
  2021-04-23 21:29 ` [patch 4/5] mm/filemap: fix mapping_seek_hole_data on THP & 32-bit Andrew Morton
  2021-04-23 21:29 ` [patch 5/5] tools/cgroup/slabinfo.py: updated to work on current kernel Andrew Morton
  4 siblings, 0 replies; 6+ messages in thread
From: Andrew Morton @ 2021-04-23 21:28 UTC (permalink / raw)
  To: akpm, dchinner, hannes, hch, hughd, jack, kirill.shutemov,
	linux-mm, mm-commits, torvalds, william.kucharski, willy,
	yang.shi

From: Hugh Dickins <hughd@google.com>
Subject: mm/filemap: fix find_lock_entries hang on 32-bit THP

No problem on 64-bit, or without huge pages, but xfstests generic/308 hung
uninterruptibly on 32-bit huge tmpfs.  Since 4.13's 0cc3b0ec23ce ("Clarify
(and fix) MAX_LFS_FILESIZE macros"), MAX_LFS_FILESIZE is only a PAGE_SIZE
away from wrapping 32-bit xa_index to 0, so the new find_lock_entries()
has to be extra careful when handling a THP.

Link: https://lkml.kernel.org/r/alpine.LSU.2.11.2104211735430.3299@eggly.anvils
Fixes: 5c211ba29deb ("mm: add and use find_lock_entries")
Signed-off-by: Hugh Dickins <hughd@google.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: William Kucharski <william.kucharski@oracle.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Jan Kara <jack@suse.cz>
Cc: Dave Chinner <dchinner@redhat.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Yang Shi <yang.shi@linux.alibaba.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 mm/filemap.c |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

--- a/mm/filemap.c~mm-filemap-fix-find_lock_entries-hang-on-32-bit-thp
+++ a/mm/filemap.c
@@ -1969,8 +1969,14 @@ unlock:
 put:
 		put_page(page);
 next:
-		if (!xa_is_value(page) && PageTransHuge(page))
-			xas_set(&xas, page->index + thp_nr_pages(page));
+		if (!xa_is_value(page) && PageTransHuge(page)) {
+			unsigned int nr_pages = thp_nr_pages(page);
+
+			/* Final THP may cross MAX_LFS_FILESIZE on 32-bit */
+			xas_set(&xas, page->index + nr_pages);
+			if (xas.xa_index < nr_pages)
+				break;
+		}
 	}
 	rcu_read_unlock();
 
_

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

* [patch 4/5] mm/filemap: fix mapping_seek_hole_data on THP & 32-bit
  2021-04-23 21:28 incoming Andrew Morton
                   ` (2 preceding siblings ...)
  2021-04-23 21:28 ` [patch 3/5] mm/filemap: fix find_lock_entries hang on 32-bit THP Andrew Morton
@ 2021-04-23 21:29 ` Andrew Morton
  2021-04-23 21:29 ` [patch 5/5] tools/cgroup/slabinfo.py: updated to work on current kernel Andrew Morton
  4 siblings, 0 replies; 6+ messages in thread
From: Andrew Morton @ 2021-04-23 21:29 UTC (permalink / raw)
  To: akpm, dchinner, hannes, hch, hughd, jack, kirill.shutemov,
	linux-mm, mm-commits, torvalds, william.kucharski, willy,
	yang.shi

From: Hugh Dickins <hughd@google.com>
Subject: mm/filemap: fix mapping_seek_hole_data on THP & 32-bit

No problem on 64-bit without huge pages, but xfstests generic/285 and
other SEEK_HOLE/SEEK_DATA tests have regressed on huge tmpfs, and on
32-bit architectures, with the new mapping_seek_hole_data().  Several
different bugs turned out to need fixing.

u64 cast to stop losing bits when converting unsigned long to loff_t (and
let's use shifts throughout, rather than mixed with * and /).

Use round_up() when advancing pos, to stop assuming that pos was already
THP-aligned when advancing it by THP-size.  (This use of round_up()
assumes that any THP has THP-aligned index: true at present and true going
forward, but could be recoded to avoid the assumption.)

Use xas_set() when iterating away from a THP, so that xa_index stays in
synch with start, instead of drifting away to return bogus offset.

Check start against end to avoid wrapping 32-bit xa_index to 0 (and to
handle these additional cases, seek_data or not, it's easier to break the
loop than goto: so rearrange exit from the function).

[hughd@google.com: remove unneeded u64 casts, per Matthew]
  Link: https://lkml.kernel.org/r/alpine.LSU.2.11.2104221347240.1170@eggly.anvils
Link: https://lkml.kernel.org/r/alpine.LSU.2.11.2104211737410.3299@eggly.anvils
Fixes: 41139aa4c3a3 ("mm/filemap: add mapping_seek_hole_data")
Signed-off-by: Hugh Dickins <hughd@google.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Dave Chinner <dchinner@redhat.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: William Kucharski <william.kucharski@oracle.com>
Cc: Yang Shi <yang.shi@linux.alibaba.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 mm/filemap.c |   21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

--- a/mm/filemap.c~mm-filemap-fix-mapping_seek_hole_data-on-thp-32-bit
+++ a/mm/filemap.c
@@ -2678,7 +2678,7 @@ loff_t mapping_seek_hole_data(struct add
 		loff_t end, int whence)
 {
 	XA_STATE(xas, &mapping->i_pages, start >> PAGE_SHIFT);
-	pgoff_t max = (end - 1) / PAGE_SIZE;
+	pgoff_t max = (end - 1) >> PAGE_SHIFT;
 	bool seek_data = (whence == SEEK_DATA);
 	struct page *page;
 
@@ -2687,7 +2687,8 @@ loff_t mapping_seek_hole_data(struct add
 
 	rcu_read_lock();
 	while ((page = find_get_entry(&xas, max, XA_PRESENT))) {
-		loff_t pos = xas.xa_index * PAGE_SIZE;
+		loff_t pos = (u64)xas.xa_index << PAGE_SHIFT;
+		unsigned int seek_size;
 
 		if (start < pos) {
 			if (!seek_data)
@@ -2695,25 +2696,25 @@ loff_t mapping_seek_hole_data(struct add
 			start = pos;
 		}
 
-		pos += seek_page_size(&xas, page);
+		seek_size = seek_page_size(&xas, page);
+		pos = round_up(pos + 1, seek_size);
 		start = page_seek_hole_data(&xas, mapping, page, start, pos,
 				seek_data);
 		if (start < pos)
 			goto unlock;
+		if (start >= end)
+			break;
+		if (seek_size > PAGE_SIZE)
+			xas_set(&xas, pos >> PAGE_SHIFT);
 		if (!xa_is_value(page))
 			put_page(page);
 	}
-	rcu_read_unlock();
-
 	if (seek_data)
-		return -ENXIO;
-	goto out;
-
+		start = -ENXIO;
 unlock:
 	rcu_read_unlock();
-	if (!xa_is_value(page))
+	if (page && !xa_is_value(page))
 		put_page(page);
-out:
 	if (start > end)
 		return end;
 	return start;
_

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

* [patch 5/5] tools/cgroup/slabinfo.py: updated to work on current kernel
  2021-04-23 21:28 incoming Andrew Morton
                   ` (3 preceding siblings ...)
  2021-04-23 21:29 ` [patch 4/5] mm/filemap: fix mapping_seek_hole_data on THP & 32-bit Andrew Morton
@ 2021-04-23 21:29 ` Andrew Morton
  4 siblings, 0 replies; 6+ messages in thread
From: Andrew Morton @ 2021-04-23 21:29 UTC (permalink / raw)
  To: akpm, guro, linux-mm, mhocko, mm-commits, torvalds, vvs

From: Vasily Averin <vvs@virtuozzo.com>
Subject: tools/cgroup/slabinfo.py: updated to work on current kernel

slabinfo.py script does not work with actual kernel version.
First, it was unable to recognise SLUB susbsytem,
when I specified it manually, it was failed again with
AttributeError: 'struct page' has no member 'obj_cgroups'
... and then again with
  File "tools/cgroup/memcg_slabinfo.py", line 221, in main
    memcg.kmem_caches.address_of_(),
AttributeError: 'struct mem_cgroup' has no member 'kmem_caches'

Link: https://lkml.kernel.org/r/cec1a75e-43b4-3d64-2084-d9f98fda037f@virtuozzo.com
Signed-off-by: Vasily Averin <vvs@virtuozzo.com>
Tested-by: Roman Gushchin <guro@fb.com>
Acked-by: Roman Gushchin <guro@fb.com>
Cc: Michal Hocko <mhocko@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 tools/cgroup/memcg_slabinfo.py |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

--- a/tools/cgroup/memcg_slabinfo.py~tools-cgroup-slabinfopy-updated-to-work-on-current-kernel
+++ a/tools/cgroup/memcg_slabinfo.py
@@ -128,9 +128,9 @@ def detect_kernel_config():
 
     cfg['nr_nodes'] = prog['nr_online_nodes'].value_()
 
-    if prog.type('struct kmem_cache').members[1][1] == 'flags':
+    if prog.type('struct kmem_cache').members[1].name == 'flags':
         cfg['allocator'] = 'SLUB'
-    elif prog.type('struct kmem_cache').members[1][1] == 'batchcount':
+    elif prog.type('struct kmem_cache').members[1].name == 'batchcount':
         cfg['allocator'] = 'SLAB'
     else:
         err('Can\'t determine the slab allocator')
@@ -193,7 +193,7 @@ def main():
         # look over all slab pages, belonging to non-root memcgs
         # and look for objects belonging to the given memory cgroup
         for page in for_each_slab_page(prog):
-            objcg_vec_raw = page.obj_cgroups.value_()
+            objcg_vec_raw = page.memcg_data.value_()
             if objcg_vec_raw == 0:
                 continue
             cache = page.slab_cache
@@ -202,7 +202,7 @@ def main():
             addr = cache.value_()
             caches[addr] = cache
             # clear the lowest bit to get the true obj_cgroups
-            objcg_vec = Object(prog, page.obj_cgroups.type_,
+            objcg_vec = Object(prog, 'struct obj_cgroup **',
                                value=objcg_vec_raw & ~1)
 
             if addr not in stats:
_

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

end of thread, other threads:[~2021-04-23 21:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-23 21:28 incoming Andrew Morton
2021-04-23 21:28 ` [patch 1/5] coda: fix reference counting in coda_file_mmap error path Andrew Morton
2021-04-23 21:28 ` [patch 2/5] ovl: fix reference counting in ovl_mmap " Andrew Morton
2021-04-23 21:28 ` [patch 3/5] mm/filemap: fix find_lock_entries hang on 32-bit THP Andrew Morton
2021-04-23 21:29 ` [patch 4/5] mm/filemap: fix mapping_seek_hole_data on THP & 32-bit Andrew Morton
2021-04-23 21:29 ` [patch 5/5] tools/cgroup/slabinfo.py: updated to work on current kernel Andrew Morton

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.