Skip to contentSkip to conversation

incoming

PATCH New Andrew Morton 1 participant 6 messages Apr 23, 2021

Subsystems (6)
lore
Share & tools
lore

Andrew Morton

author maintainer
#0 lore raw

5 patches, based on 5bfc75d92efd494db37f5c4c173d3639d4772966.

Subsystems affected by this patch series:

coda
overlayfs
mm/pagecache
mm/memcg

Subsystem: coda

Christian König <[email protected]>:
coda: fix reference counting in coda_file_mmap error path

Subsystem: overlayfs

Christian König <[email protected]>:
ovl: fix reference counting in ovl_mmap error path

Subsystem: mm/pagecache

Hugh Dickins <[email protected]>:
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 <[email protected]>:
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(-)
author maintainer
#1 lore raw

PATCH 1/5 coda: fix reference counting in coda_file_mmap error path

From: Christian König <[email protected]>
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.

Fixes 1527f926fd04 ("mm: mmap: fix fput in error path v2")
Cc Miklos Szeredi <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc <[email protected]> [5.11+]

---

 fs/coda/file.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/coda/file.c renamed from fs/coda/file.c~coda-fix-reference-counting-in-coda_file_mmap-error-path +3 -3
@@ -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 */

_

author maintainer
#2 lore raw

PATCH 2/5 ovl: fix reference counting in ovl_mmap error path

In reply to Andrew Morton

From: Christian König <[email protected]>
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.

Fixes 1527f926fd04 ("mm: mmap: fix fput in error path v2")
Cc Jan Harkes <[email protected]>
Cc Miklos Szeredi <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc <[email protected]> [5.11+]

---

 fs/overlayfs/file.c |   11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)
fs/overlayfs/file.c renamed from fs/overlayfs/file.c~ovl-fix-reference-counting-in-ovl_mmap-error-path +1 -10
@@ -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;

_

author maintainer
#3 lore raw

PATCH 3/5 mm/filemap: fix find_lock_entries hang on 32-bit THP

In reply to Andrew Morton

From: Hugh Dickins <[email protected]>
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.

Fixes 5c211ba29deb ("mm: add and use find_lock_entries")
Cc Matthew Wilcox <[email protected]>
Cc William Kucharski <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Jan Kara <[email protected]>
Cc Dave Chinner <[email protected]>
Cc Johannes Weiner <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc Yang Shi <[email protected]>

---

 mm/filemap.c |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
mm/filemap.c renamed from mm/filemap.c~mm-filemap-fix-find_lock_entries-hang-on-32-bit-thp +8 -2
@@ -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();
 

_

author maintainer
#4 lore raw

PATCH 4/5 mm/filemap: fix mapping_seek_hole_data on THP & 32-bit

In reply to Andrew Morton

From: Hugh Dickins <[email protected]>
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).

[[email protected]: remove unneeded u64 casts, per Matthew]
Fixes 41139aa4c3a3 ("mm/filemap: add mapping_seek_hole_data")
Cc Christoph Hellwig <[email protected]>
Cc Dave Chinner <[email protected]>
Cc Jan Kara <[email protected]>
Cc Johannes Weiner <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc William Kucharski <[email protected]>
Cc Yang Shi <[email protected]>

---

 mm/filemap.c |   21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
mm/filemap.c renamed from mm/filemap.c~mm-filemap-fix-mapping_seek_hole_data-on-thp-32-bit +11 -10
@@ -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;

_

author maintainer
#5 lore raw

PATCH 5/5 tools/cgroup/slabinfo.py: updated to work on current kernel

In reply to Andrew Morton

From: Vasily Averin <[email protected]>
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'

---

 tools/cgroup/memcg_slabinfo.py |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tools/cgroup/memcg_slabinfo.py renamed from tools/cgroup/memcg_slabinfo.py~tools-cgroup-slabinfopy-updated-to-work-on-current-kernel +4 -4
@@ -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:

_