Skip to contentSkip to conversation

incoming

PATCH In review Andrew Morton 5 participants 24 messages Feb 9, 2021 – Feb 11, 2021

Subsystems (15)
lore
Share & tools
lore

Andrew Morton

author maintainer
#0 lore raw

14 patches, based on e0756cfc7d7cd08c98a53b6009c091a3f6a50be6.

Subsystems affected by this patch series:

squashfs
mm/kasan
firmware
mm/mremap
mm/tmpfs
mm/selftests
MAINTAINERS
mm/memcg
mm/slub
nilfs2

Subsystem: squashfs

Phillip Lougher <[email protected]>:
Patch series "Squashfs: fix BIO migration regression and add sanity checks":
squashfs: avoid out of bounds writes in decompressors
squashfs: add more sanity checks in id lookup
squashfs: add more sanity checks in inode lookup
squashfs: add more sanity checks in xattr id lookup

Subsystem: mm/kasan

Andrey Konovalov <[email protected]>:
kasan: fix stack traces dependency for HW_TAGS

Subsystem: firmware

Fangrui Song <[email protected]>:
firmware_loader: align .builtin_fw to 8

Subsystem: mm/mremap

Arnd Bergmann <[email protected]>:
mm/mremap: fix BUILD_BUG_ON() error in get_extent

Subsystem: mm/tmpfs

Seth Forshee <[email protected]>:
tmpfs: disallow CONFIG_TMPFS_INODE64 on s390
tmpfs: disallow CONFIG_TMPFS_INODE64 on alpha

Subsystem: mm/selftests

Rong Chen <[email protected]>:
selftests/vm: rename file run_vmtests to run_vmtests.sh

Subsystem: MAINTAINERS

Andrey Ryabinin <[email protected]>:
MAINTAINERS: update Andrey Ryabinin's email address

Subsystem: mm/memcg

Johannes Weiner <[email protected]>:
Revert "mm: memcontrol: avoid workload stalls when lowering memory.high"

Subsystem: mm/slub

Vlastimil Babka <[email protected]>:
mm, slub: better heuristic for number of cpus when calculating slab order

Subsystem: nilfs2

Joachim Henke <[email protected]>:
nilfs2: make splice write available again

 .mailmap                          |    1 
 Documentation/dev-tools/kasan.rst |    3 -
 MAINTAINERS                       |    2 -
 fs/Kconfig                        |    4 +-
 fs/nilfs2/file.c                  |    1 
 fs/squashfs/block.c               |    8 ++++
 fs/squashfs/export.c              |   41 +++++++++++++++++++----
 fs/squashfs/id.c                  |   40 ++++++++++++++++++-----
 fs/squashfs/squashfs_fs_sb.h      |    1 
 fs/squashfs/super.c               |    6 +--
 fs/squashfs/xattr.h               |   10 +++++
 fs/squashfs/xattr_id.c            |   66 ++++++++++++++++++++++++++++++++------
 include/asm-generic/vmlinux.lds.h |    2 -
 mm/kasan/hw_tags.c                |    8 +---
 mm/memcontrol.c                   |    5 +-
 mm/mremap.c                       |    5 +-
 mm/slub.c                         |   18 +++++++++-
 17 files changed, 172 insertions(+), 49 deletions(-)
author maintainer
#1 lore raw

PATCH 1/14 squashfs: avoid out of bounds writes in decompressors

From: Phillip Lougher <[email protected]>
Subject: squashfs: avoid out of bounds writes in decompressors

Patch series "Squashfs: fix BIO migration regression and add sanity checks".

Patch [1/4] fixes a regression introduced by the "migrate from ll_rw_block usage to BIO" patch, which has produced a number of Sysbot/Syzkaller reports.

Patches [2/4], [3/4], and [4/4] fix a number of filesystem corruption issues which have produced Sysbot reports in the id, inode and xattr lookup code.

Each patch has been tested against the Sysbot reproducers using the given kernel configuration. They have the appropriate "Reported-by:" lines added.

Additionally, all of the reproducer filesystems are indirectly fixed by patch [4/4] due to the fact they all have xattr corruption which is now detected there.

Additional testing with other configurations and architectures (32bit, big endian), and normal filesystems has also been done to trap any inadvertent regressions caused by the additional sanity checks.

This patch (of 4):

This is a regression introduced by the patch "migrate from ll_rw_block usage to BIO".

Sysbot/Syskaller has reported a number of "out of bounds writes" and "unable to handle kernel paging request in squashfs_decompress" errors which have been identified as a regression introduced by the above patch.

Specifically, the patch removed the following sanity check

if (length < 0 || length > output->length ||

		(index + length) > msblk->bytes_used)

This check did two things:

1. It ensured any reads were not beyond the end of the filesystem

2. It ensured that the "length" field read from the filesystem was within the expected maximum length. Without this any corrupted values can over-run allocated buffers.

---

 fs/squashfs/block.c |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
fs/squashfs/block.c renamed from fs/squashfs/block.c~squashfs-avoid-out-of-bounds-writes-in-decompressors +7 -1
@@ -196,9 +196,15 @@ int squashfs_read_data(struct super_bloc
 		length = SQUASHFS_COMPRESSED_SIZE(length);
 		index += 2;
 
-		TRACE("Block @ 0x%llx, %scompressed size %d\n", index,
+		TRACE("Block @ 0x%llx, %scompressed size %d\n", index - 2,
 		      compressed ? "" : "un", length);
 	}
+	if (length < 0 || length > output->length ||
+			(index + length) > msblk->bytes_used) {
+		res = -EIO;
+		goto out;
+	}
+
 	if (next_index)
 		*next_index = index + length;
 

_

author maintainer
#2 lore raw

PATCH 2/14 squashfs: add more sanity checks in id lookup

In reply to Andrew Morton

From: Phillip Lougher <[email protected]>
Subject: squashfs: add more sanity checks in id lookup

Sysbot has reported a number of "slab-out-of-bounds reads" and "use-after-free read" errors which has been identified as being caused by a corrupted index value read from the inode. This could be because the metadata block is uncompressed, or because the "compression" bit has been corrupted (turning a compressed block into an uncompressed block).

This patch adds additional sanity checks to detect this, and the following corruption.

1. It checks against corruption of the ids count. This can either lead to a larger table to be read, or a smaller than expected table to be read.

In the case of a too large ids count, this would often have been trapped by the existing sanity checks, but this patch introduces a more exact check, which can identify too small values.

2. It checks the contents of the index table for corruption.

---

 fs/squashfs/id.c             |   40 ++++++++++++++++++++++++++-------
 fs/squashfs/squashfs_fs_sb.h |    1 
 fs/squashfs/super.c          |    6 ++--
 fs/squashfs/xattr.h          |   10 +++++++-
 4 files changed, 45 insertions(+), 12 deletions(-)
fs/squashfs/id.c renamed from fs/squashfs/id.c~squashfs-add-more-sanity-checks-in-id-lookup +32 -8
@@ -35,10 +35,15 @@ int squashfs_get_id(struct super_block *
 	struct squashfs_sb_info *msblk = sb->s_fs_info;
 	int block = SQUASHFS_ID_BLOCK(index);
 	int offset = SQUASHFS_ID_BLOCK_OFFSET(index);
-	u64 start_block = le64_to_cpu(msblk->id_table[block]);
+	u64 start_block;
 	__le32 disk_id;
 	int err;
 
+	if (index >= msblk->ids)
+		return -EINVAL;
+
+	start_block = le64_to_cpu(msblk->id_table[block]);
+
 	err = squashfs_read_metadata(sb, &disk_id, &start_block, &offset,
 							sizeof(disk_id));
 	if (err < 0)
@@ -56,7 +61,10 @@ __le64 *squashfs_read_id_index_table(str
 		u64 id_table_start, u64 next_table, unsigned short no_ids)
 {
 	unsigned int length = SQUASHFS_ID_BLOCK_BYTES(no_ids);
+	unsigned int indexes = SQUASHFS_ID_BLOCKS(no_ids);
+	int n;
 	__le64 *table;
+	u64 start, end;
 
 	TRACE("In read_id_index_table, length %d\n", length);
 
@@ -67,20 +75,36 @@ __le64 *squashfs_read_id_index_table(str
 		return ERR_PTR(-EINVAL);
 
 	/*
-	 * length bytes should not extend into the next table - this check
-	 * also traps instances where id_table_start is incorrectly larger
-	 * than the next table start
+	 * The computed size of the index table (length bytes) should exactly
+	 * match the table start and end points
 	 */
-	if (id_table_start + length > next_table)
+	if (length != (next_table - id_table_start))
 		return ERR_PTR(-EINVAL);
 
 	table = squashfs_read_table(sb, id_table_start, length);
+	if (IS_ERR(table))
+		return table;
 
 	/*
-	 * table[0] points to the first id lookup table metadata block, this
-	 * should be less than id_table_start
+	 * table[0], table[1], ... table[indexes - 1] store the locations
+	 * of the compressed id blocks.   Each entry should be less than
+	 * the next (i.e. table[0] < table[1]), and the difference between them
+	 * should be SQUASHFS_METADATA_SIZE or less.  table[indexes - 1]
+	 * should be less than id_table_start, and again the difference
+	 * should be SQUASHFS_METADATA_SIZE or less
 	 */
-	if (!IS_ERR(table) && le64_to_cpu(table[0]) >= id_table_start) {
+	for (n = 0; n < (indexes - 1); n++) {
+		start = le64_to_cpu(table[n]);
+		end = le64_to_cpu(table[n + 1]);
+
+		if (start >= end || (end - start) > SQUASHFS_METADATA_SIZE) {
+			kfree(table);
+			return ERR_PTR(-EINVAL);
+		}
+	}
+
+	start = le64_to_cpu(table[indexes - 1]);
+	if (start >= id_table_start || (id_table_start - start) > SQUASHFS_METADATA_SIZE) {
 		kfree(table);
 		return ERR_PTR(-EINVAL);
 	}
fs/squashfs/squashfs_fs_sb.h renamed from fs/squashfs/squashfs_fs_sb.h~squashfs-add-more-sanity-checks-in-id-lookup +1 -0
@@ -64,5 +64,6 @@ struct squashfs_sb_info {
 	unsigned int				inodes;
 	unsigned int				fragments;
 	int					xattr_ids;
+	unsigned int				ids;
 };
 #endif
fs/squashfs/super.c renamed from fs/squashfs/super.c~squashfs-add-more-sanity-checks-in-id-lookup +3 -3
@@ -166,6 +166,7 @@ static int squashfs_fill_super(struct su
 	msblk->directory_table = le64_to_cpu(sblk->directory_table_start);
 	msblk->inodes = le32_to_cpu(sblk->inodes);
 	msblk->fragments = le32_to_cpu(sblk->fragments);
+	msblk->ids = le16_to_cpu(sblk->no_ids);
 	flags = le16_to_cpu(sblk->flags);
 
 	TRACE("Found valid superblock on %pg\n", sb->s_bdev);
@@ -177,7 +178,7 @@ static int squashfs_fill_super(struct su
 	TRACE("Block size %d\n", msblk->block_size);
 	TRACE("Number of inodes %d\n", msblk->inodes);
 	TRACE("Number of fragments %d\n", msblk->fragments);
-	TRACE("Number of ids %d\n", le16_to_cpu(sblk->no_ids));
+	TRACE("Number of ids %d\n", msblk->ids);
 	TRACE("sblk->inode_table_start %llx\n", msblk->inode_table);
 	TRACE("sblk->directory_table_start %llx\n", msblk->directory_table);
 	TRACE("sblk->fragment_table_start %llx\n",
@@ -236,8 +237,7 @@ static int squashfs_fill_super(struct su
 allocate_id_index_table:
 	/* Allocate and read id index table */
 	msblk->id_table = squashfs_read_id_index_table(sb,
-		le64_to_cpu(sblk->id_table_start), next_table,
-		le16_to_cpu(sblk->no_ids));
+		le64_to_cpu(sblk->id_table_start), next_table, msblk->ids);
 	if (IS_ERR(msblk->id_table)) {
 		errorf(fc, "unable to read id index table");
 		err = PTR_ERR(msblk->id_table);
fs/squashfs/xattr.h renamed from fs/squashfs/xattr.h~squashfs-add-more-sanity-checks-in-id-lookup +9 -1
@@ -17,8 +17,16 @@ extern int squashfs_xattr_lookup(struct
 static inline __le64 *squashfs_read_xattr_id_table(struct super_block *sb,
 		u64 start, u64 *xattr_table_start, int *xattr_ids)
 {
+	struct squashfs_xattr_id_table *id_table;
+
+	id_table = squashfs_read_table(sb, start, sizeof(*id_table));
+	if (IS_ERR(id_table))
+		return (__le64 *) id_table;
+
+	*xattr_table_start = le64_to_cpu(id_table->xattr_table_start);
+	kfree(id_table);
+
 	ERROR("Xattrs in filesystem, these will be ignored\n");
-	*xattr_table_start = start;
 	return ERR_PTR(-ENOTSUPP);
 }
 

_

author maintainer
#3 lore raw

PATCH 3/14 squashfs: add more sanity checks in inode lookup

In reply to Andrew Morton

From: Phillip Lougher <[email protected]>
Subject: squashfs: add more sanity checks in inode lookup

Sysbot has reported an "slab-out-of-bounds read" error which has been identified as being caused by a corrupted "ino_num" value read from the inode. This could be because the metadata block is uncompressed, or because the "compression" bit has been corrupted (turning a compressed block into an uncompressed block).

This patch adds additional sanity checks to detect this, and the following corruption.

1. It checks against corruption of the inodes count. This can either lead to a larger table to be read, or a smaller than expected table to be read.

In the case of a too large inodes count, this would often have been trapped by the existing sanity checks, but this patch introduces a more exact check, which can identify too small values.

2. It checks the contents of the index table for corruption.

---

 fs/squashfs/export.c |   41 +++++++++++++++++++++++++++++++++--------
 1 file changed, 33 insertions(+), 8 deletions(-)
fs/squashfs/export.c renamed from fs/squashfs/export.c~squashfs-add-more-sanity-checks-in-inode-lookup +33 -8
@@ -41,12 +41,17 @@ static long long squashfs_inode_lookup(s
 	struct squashfs_sb_info *msblk = sb->s_fs_info;
 	int blk = SQUASHFS_LOOKUP_BLOCK(ino_num - 1);
 	int offset = SQUASHFS_LOOKUP_BLOCK_OFFSET(ino_num - 1);
-	u64 start = le64_to_cpu(msblk->inode_lookup_table[blk]);
+	u64 start;
 	__le64 ino;
 	int err;
 
 	TRACE("Entered squashfs_inode_lookup, inode_number = %d\n", ino_num);
 
+	if (ino_num == 0 || (ino_num - 1) >= msblk->inodes)
+		return -EINVAL;
+
+	start = le64_to_cpu(msblk->inode_lookup_table[blk]);
+
 	err = squashfs_read_metadata(sb, &ino, &start, &offset, sizeof(ino));
 	if (err < 0)
 		return err;
@@ -111,7 +116,10 @@ __le64 *squashfs_read_inode_lookup_table
 		u64 lookup_table_start, u64 next_table, unsigned int inodes)
 {
 	unsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(inodes);
+	unsigned int indexes = SQUASHFS_LOOKUP_BLOCKS(inodes);
+	int n;
 	__le64 *table;
+	u64 start, end;
 
 	TRACE("In read_inode_lookup_table, length %d\n", length);
 
@@ -121,20 +129,37 @@ __le64 *squashfs_read_inode_lookup_table
 	if (inodes == 0)
 		return ERR_PTR(-EINVAL);
 
-	/* length bytes should not extend into the next table - this check
-	 * also traps instances where lookup_table_start is incorrectly larger
-	 * than the next table start
+	/*
+	 * The computed size of the lookup table (length bytes) should exactly
+	 * match the table start and end points
 	 */
-	if (lookup_table_start + length > next_table)
+	if (length != (next_table - lookup_table_start))
 		return ERR_PTR(-EINVAL);
 
 	table = squashfs_read_table(sb, lookup_table_start, length);
+	if (IS_ERR(table))
+		return table;
 
 	/*
-	 * table[0] points to the first inode lookup table metadata block,
-	 * this should be less than lookup_table_start
+	 * table0], table[1], ... table[indexes - 1] store the locations
+	 * of the compressed inode lookup blocks.  Each entry should be
+	 * less than the next (i.e. table[0] < table[1]), and the difference
+	 * between them should be SQUASHFS_METADATA_SIZE or less.
+	 * table[indexes - 1] should  be less than lookup_table_start, and
+	 * again the difference should be SQUASHFS_METADATA_SIZE or less
 	 */
-	if (!IS_ERR(table) && le64_to_cpu(table[0]) >= lookup_table_start) {
+	for (n = 0; n < (indexes - 1); n++) {
+		start = le64_to_cpu(table[n]);
+		end = le64_to_cpu(table[n + 1]);
+
+		if (start >= end || (end - start) > SQUASHFS_METADATA_SIZE) {
+			kfree(table);
+			return ERR_PTR(-EINVAL);
+		}
+	}
+
+	start = le64_to_cpu(table[indexes - 1]);
+	if (start >= lookup_table_start || (lookup_table_start - start) > SQUASHFS_METADATA_SIZE) {
 		kfree(table);
 		return ERR_PTR(-EINVAL);
 	}

_

author maintainer
#4 lore raw

PATCH 4/14 squashfs: add more sanity checks in xattr id lookup

In reply to Andrew Morton

From: Phillip Lougher <[email protected]>
Subject: squashfs: add more sanity checks in xattr id lookup

Sysbot has reported a warning where a kmalloc() attempt exceeds the maximum limit. This has been identified as corruption of the xattr_ids count when reading the xattr id lookup table.

This patch adds a number of additional sanity checks to detect this corruption and others.

1. It checks for a corrupted xattr index read from the inode. This could be because the metadata block is uncompressed, or because the "compression" bit has been corrupted (turning a compressed block into an uncompressed block). This would cause an out of bounds read.

2. It checks against corruption of the xattr_ids count. This can either lead to the above kmalloc failure, or a smaller than expected table to be read.

3. It checks the contents of the index table for corruption.

---

 fs/squashfs/xattr_id.c |   66 +++++++++++++++++++++++++++++++++------
 1 file changed, 57 insertions(+), 9 deletions(-)
fs/squashfs/xattr_id.c renamed from fs/squashfs/xattr_id.c~squashfs-add-more-sanity-checks-in-xattr-id-lookup +57 -9
@@ -31,10 +31,15 @@ int squashfs_xattr_lookup(struct super_b
 	struct squashfs_sb_info *msblk = sb->s_fs_info;
 	int block = SQUASHFS_XATTR_BLOCK(index);
 	int offset = SQUASHFS_XATTR_BLOCK_OFFSET(index);
-	u64 start_block = le64_to_cpu(msblk->xattr_id_table[block]);
+	u64 start_block;
 	struct squashfs_xattr_id id;
 	int err;
 
+	if (index >= msblk->xattr_ids)
+		return -EINVAL;
+
+	start_block = le64_to_cpu(msblk->xattr_id_table[block]);
+
 	err = squashfs_read_metadata(sb, &id, &start_block, &offset,
 							sizeof(id));
 	if (err < 0)
@@ -50,13 +55,17 @@ int squashfs_xattr_lookup(struct super_b
 /*
  * Read uncompressed xattr id lookup table indexes from disk into memory
  */
-__le64 *squashfs_read_xattr_id_table(struct super_block *sb, u64 start,
+__le64 *squashfs_read_xattr_id_table(struct super_block *sb, u64 table_start,
 		u64 *xattr_table_start, int *xattr_ids)
 {
-	unsigned int len;
+	struct squashfs_sb_info *msblk = sb->s_fs_info;
+	unsigned int len, indexes;
 	struct squashfs_xattr_id_table *id_table;
+	__le64 *table;
+	u64 start, end;
+	int n;
 
-	id_table = squashfs_read_table(sb, start, sizeof(*id_table));
+	id_table = squashfs_read_table(sb, table_start, sizeof(*id_table));
 	if (IS_ERR(id_table))
 		return (__le64 *) id_table;
 
@@ -70,13 +79,52 @@ __le64 *squashfs_read_xattr_id_table(str
 	if (*xattr_ids == 0)
 		return ERR_PTR(-EINVAL);
 
-	/* xattr_table should be less than start */
-	if (*xattr_table_start >= start)
+	len = SQUASHFS_XATTR_BLOCK_BYTES(*xattr_ids);
+	indexes = SQUASHFS_XATTR_BLOCKS(*xattr_ids);
+
+	/*
+	 * The computed size of the index table (len bytes) should exactly
+	 * match the table start and end points
+	 */
+	start = table_start + sizeof(*id_table);
+	end = msblk->bytes_used;
+
+	if (len != (end - start))
 		return ERR_PTR(-EINVAL);
 
-	len = SQUASHFS_XATTR_BLOCK_BYTES(*xattr_ids);
+	table = squashfs_read_table(sb, start, len);
+	if (IS_ERR(table))
+		return table;
+
+	/* table[0], table[1], ... table[indexes - 1] store the locations
+	 * of the compressed xattr id blocks.  Each entry should be less than
+	 * the next (i.e. table[0] < table[1]), and the difference between them
+	 * should be SQUASHFS_METADATA_SIZE or less.  table[indexes - 1]
+	 * should be less than table_start, and again the difference
+	 * shouls be SQUASHFS_METADATA_SIZE or less.
+	 *
+	 * Finally xattr_table_start should be less than table[0].
+	 */
+	for (n = 0; n < (indexes - 1); n++) {
+		start = le64_to_cpu(table[n]);
+		end = le64_to_cpu(table[n + 1]);
+
+		if (start >= end || (end - start) > SQUASHFS_METADATA_SIZE) {
+			kfree(table);
+			return ERR_PTR(-EINVAL);
+		}
+	}
+
+	start = le64_to_cpu(table[indexes - 1]);
+	if (start >= table_start || (table_start - start) > SQUASHFS_METADATA_SIZE) {
+		kfree(table);
+		return ERR_PTR(-EINVAL);
+	}
 
-	TRACE("In read_xattr_index_table, length %d\n", len);
+	if (*xattr_table_start >= le64_to_cpu(table[0])) {
+		kfree(table);
+		return ERR_PTR(-EINVAL);
+	}
 
-	return squashfs_read_table(sb, start + sizeof(*id_table), len);
+	return table;
 }

_

author maintainer
#5 lore raw

PATCH 5/14 kasan: fix stack traces dependency for HW_TAGS

In reply to Andrew Morton

From: Andrey Konovalov <[email protected]>
Subject: kasan: fix stack traces dependency for HW_TAGS

Currently, whether the alloc/free stack traces collection is enabled by default for hardware tag-based KASAN depends on CONFIG_DEBUG_KERNEL. The intention for this dependency was to only enable collection on slow debug kernels due to a significant perf and memory impact.

As it turns out, CONFIG_DEBUG_KERNEL is not considered a debug option and is enabled on many productions kernels including Android and Ubuntu. As the result, this dependency is pointless and only complicates the code and documentation.

Having stack traces collection disabled by default would make the hardware mode work differently to to the software ones, which is confusing.

This change removes the dependency and enables stack traces collection by default.

Looking into the future, this default might makes sense for production kernels, assuming we implement a fast stack trace collection approach.

---

 Documentation/dev-tools/kasan.rst |    3 +--
 mm/kasan/hw_tags.c                |    8 ++------
 2 files changed, 3 insertions(+), 8 deletions(-)
Documentation/dev-tools/kasan.rst renamed from Documentation/dev-tools/kasan.rst~kasan-fix-stack-traces-dependency-for-hw_tags +1 -2
@@ -163,8 +163,7 @@ particular KASAN features.
 - ``kasan=off`` or ``=on`` controls whether KASAN is enabled (default: ``on``).
 
 - ``kasan.stacktrace=off`` or ``=on`` disables or enables alloc and free stack
-  traces collection (default: ``on`` for ``CONFIG_DEBUG_KERNEL=y``, otherwise
-  ``off``).
+  traces collection (default: ``on``).
 
 - ``kasan.fault=report`` or ``=panic`` controls whether to only print a KASAN
   report or also panic the kernel (default: ``report``).
mm/kasan/hw_tags.c renamed from mm/kasan/hw_tags.c~kasan-fix-stack-traces-dependency-for-hw_tags +2 -6
@@ -134,12 +134,8 @@ void __init kasan_init_hw_tags(void)
 
 	switch (kasan_arg_stacktrace) {
 	case KASAN_ARG_STACKTRACE_DEFAULT:
-		/*
-		 * Default to enabling stack trace collection for
-		 * debug kernels.
-		 */
-		if (IS_ENABLED(CONFIG_DEBUG_KERNEL))
-			static_branch_enable(&kasan_flag_stacktrace);
+		/* Default to enabling stack trace collection. */
+		static_branch_enable(&kasan_flag_stacktrace);
 		break;
 	case KASAN_ARG_STACKTRACE_OFF:
 		/* Do nothing, kasan_flag_stacktrace keeps its default value. */

_

author maintainer
#6 lore raw

PATCH 6/14 firmware_loader: align .builtin_fw to 8

In reply to Andrew Morton

From: Fangrui Song <[email protected]>
Subject: firmware_loader: align .builtin_fw to 8

arm64 references the start address of .builtin_fw (__start_builtin_fw) with a pair of R_AARCH64_ADR_PREL_PG_HI21/R_AARCH64_LDST64_ABS_LO12_NC relocations. The compiler is allowed to emit the R_AARCH64_LDST64_ABS_LO12_NC relocation because struct builtin_fw in include/linux/firmware.h is 8-byte aligned.

The R_AARCH64_LDST64_ABS_LO12_NC relocation requires the address to be a multiple of 8, which may not be the case if .builtin_fw is empty. Unconditionally align .builtin_fw to fix the linker error. 32-bit architectures could use ALIGN(4) but that would add unnecessary complexity, so just use ALIGN(8).

---

 include/asm-generic/vmlinux.lds.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/asm-generic/vmlinux.lds.h renamed from include/asm-generic/vmlinux.lds.h~firmware_loader-align-builtin_fw-to-8 +1 -1
@@ -459,7 +459,7 @@
 	}								\
 									\
 	/* Built-in firmware blobs */					\
-	.builtin_fw        : AT(ADDR(.builtin_fw) - LOAD_OFFSET) {	\
+	.builtin_fw : AT(ADDR(.builtin_fw) - LOAD_OFFSET) ALIGN(8) {	\
 		__start_builtin_fw = .;					\
 		KEEP(*(.builtin_fw))					\
 		__end_builtin_fw = .;					\

_

author maintainer
#7 lore raw

PATCH 7/14 mm/mremap: fix BUILD_BUG_ON() error in get_extent

In reply to Andrew Morton

From: Arnd Bergmann <[email protected]>
Subject: mm/mremap: fix BUILD_BUG_ON() error in get_extent

clang can't evaluate this function argument at compile time when the function is not inlined, which leads to a link time failure:

ld.lld: error: undefined symbol: __compiletime_assert_414

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

referenced by mremap.c
mremap.o:(get_extent) in archive mm/built-in.a

Mark the function as __always_inline to avoid it.

Fixes 9ad9718bfa41 ("mm/mremap: calculate extent in one place")
Cc Kirill A. Shutemov" <[email protected]>
Cc Wei Yang <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Dmitry Safonov <[email protected]>
Cc Brian Geffon <[email protected]>

---

 mm/mremap.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
mm/mremap.c renamed from mm/mremap.c~mm-mremap-fix-build_bug_on-error-in-get_extent +3 -2
@@ -336,8 +336,9 @@ enum pgt_entry {
  * valid. Else returns a smaller extent bounded by the end of the source and
  * destination pgt_entry.
  */
-static unsigned long get_extent(enum pgt_entry entry, unsigned long old_addr,
-			unsigned long old_end, unsigned long new_addr)
+static __always_inline unsigned long get_extent(enum pgt_entry entry,
+			unsigned long old_addr, unsigned long old_end,
+			unsigned long new_addr)
 {
 	unsigned long next, extent, mask, size;
 

_

author maintainer
#8 lore raw

PATCH 8/14 tmpfs: disallow CONFIG_TMPFS_INODE64 on s390

In reply to Andrew Morton

From: Seth Forshee <[email protected]>
Subject: tmpfs: disallow CONFIG_TMPFS_INODE64 on s390

Currently there is an assumption in tmpfs that 64-bit architectures also have a 64-bit ino_t. This is not true on s390 which has a 32-bit ino_t. With CONFIG_TMPFS_INODE64=y tmpfs mounts will get 64-bit inode numbers and display "inode64" in the mount options, but passing the "inode64" mount option will fail. This leads to the following behavior:

 # mkdir mnt
 # mount -t tmpfs nodev mnt
 # mount -o remount,rw mnt
 mount: /home/ubuntu/mnt: mount point not mounted or bad option.

As mount sees "inode64" in the mount options and thus passes it in the options for the remount.

So prevent CONFIG_TMPFS_INODE64 from being selected on s390.

Fixes ea3271f7196c ("tmpfs: support 64-bit inums per-sb")
Cc Chris Down <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Amir Goldstein <[email protected]>
Cc Heiko Carstens <[email protected]>
Cc Vasily Gorbik <[email protected]>
Cc Christian Borntraeger <[email protected]>
Cc <[email protected]> [5.9+]

---

 fs/Kconfig |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/Kconfig renamed from fs/Kconfig~tmpfs-disallow-config_tmpfs_inode64-on-s390 +1 -1
@@ -203,7 +203,7 @@ config TMPFS_XATTR
 
 config TMPFS_INODE64
 	bool "Use 64-bit ino_t by default in tmpfs"
-	depends on TMPFS && 64BIT
+	depends on TMPFS && 64BIT && !S390
 	default n
 	help
 	  tmpfs has historically used only inode numbers as wide as an unsigned

_

author maintainer
#9 lore raw

PATCH 9/14 tmpfs: disallow CONFIG_TMPFS_INODE64 on alpha

In reply to Andrew Morton

From: Seth Forshee <[email protected]>
Subject: tmpfs: disallow CONFIG_TMPFS_INODE64 on alpha

As with s390, alpha is a 64-bit architecture with a 32-bit ino_t. With CONFIG_TMPFS_INODE64=y tmpfs mounts will get 64-bit inode numbers and display "inode64" in the mount options, whereas passing "inode64" in the mount options will fail. This leads to erroneous behaviours such as this:

 # mkdir mnt
 # mount -t tmpfs nodev mnt
 # mount -o remount,rw mnt
 mount: /home/ubuntu/mnt: mount point not mounted or bad option.

Prevent CONFIG_TMPFS_INODE64 from being selected on alpha.

Fixes ea3271f7196c ("tmpfs: support 64-bit inums per-sb")
Cc Chris Down <[email protected]>
Cc Amir Goldstein <[email protected]>
Cc Richard Henderson <[email protected]>
Cc Ivan Kokshaysky <[email protected]>
Cc Matt Turner <[email protected]>
Cc <[email protected]> [5.9+]

---

 fs/Kconfig |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/Kconfig renamed from fs/Kconfig~tmpfs-disallow-config_tmpfs_inode64-on-alpha +1 -1
@@ -203,7 +203,7 @@ config TMPFS_XATTR
 
 config TMPFS_INODE64
 	bool "Use 64-bit ino_t by default in tmpfs"
-	depends on TMPFS && 64BIT && !S390
+	depends on TMPFS && 64BIT && !(S390 || ALPHA)
 	default n
 	help
 	  tmpfs has historically used only inode numbers as wide as an unsigned

_

#10 lore raw

Re: [patch 09/14] tmpfs: disallow CONFIG_TMPFS_INODE64 on alpha

Quoted 5 lines · Andrew Morton

As with s390, alpha is a 64-bit architecture with a 32-bit ino_t. With CONFIG_TMPFS_INODE64=y tmpfs mounts will get 64-bit inode numbers and display "inode64" in the mount options, whereas passing "inode64" in the mount options will fail.

Ugh.

The two patches for s390 and alpha are obviously the right thing to do, but I do wonder if we could strive to make __kernel_ino_t go away entirely.

It's actually not used very much, because it's such a nasty type, and s390 and alpha are the only ones that override it from the default "word length" version (and honestly, even that default is not a great type).

The main use of it is for "ino_t" and for "struct ustat".

And yes, "ino_t" is widely used, but I think pretty much all uses of it are entirely internal to the kernel, and we could just make it be "unsigned long".

Does anybody see any actual user interfaces that depend on "__kernel_ino_t", aka "ino_t" (apart from that "struct ustat")?

I guess this is mostly a question for s390, which is actively maintained?

Linus

maintainer
#11 lore raw

Re: [patch 09/14] tmpfs: disallow CONFIG_TMPFS_INODE64 on alpha

Quoted 20 lines · Linus Torvalds
Quoted 5 lines · Andrew Morton

As with s390, alpha is a 64-bit architecture with a 32-bit ino_t. With CONFIG_TMPFS_INODE64=y tmpfs mounts will get 64-bit inode numbers and display "inode64" in the mount options, whereas passing "inode64" in the mount options will fail.

Ugh.

The two patches for s390 and alpha are obviously the right thing to do, but I do wonder if we could strive to make __kernel_ino_t go away entirely.

It's actually not used very much, because it's such a nasty type, and s390 and alpha are the only ones that override it from the default "word length" version (and honestly, even that default is not a great type).

The main use of it is for "ino_t" and for "struct ustat".

Quoted 8 lines

And yes, "ino_t" is widely used, but I think pretty much all uses of it are entirely internal to the kernel, and we could just make it be "unsigned long".

Does anybody see any actual user interfaces that depend on "__kernel_ino_t", aka "ino_t" (apart from that "struct ustat")?

I guess this is mostly a question for s390, which is actively maintained?

I couldn't spot any and also gave the patch below a try and my system still boots without any errors.
So, as far as I can tell it _should_ be ok to change this.

Note that the unusual 32 bit ino_t also recently caused a bug on s390. See commit ebce3eb2f7ef ("ceph: fix inode number handling on arches with 32-bit ino_t"). So getting rid of this would be a good thing.

arch/Kconfig +4 -0
index 24862d15f3a3..383c98e86a70 100644
@@ -327,6 +327,10 @@ config ARCH_32BIT_OFF_T
 	  still support 32-bit off_t. This option is enabled for all such
 	  architectures explicitly.
 
+# Selected by 64 bit architectures which have a 32 bit f_tinode in struct ustat
+config ARCH_32BIT_USTAT_F_TINODE
+	bool
+
 config HAVE_ASM_MODVERSIONS
 	bool
 	help
arch/alpha/Kconfig +1 -0
index 1f51437d5765..96ce6565890e 100644
@@ -2,6 +2,7 @@
 config ALPHA
 	bool
 	default y
+	select ARCH_32BIT_USTAT_F_TINODE
 	select ARCH_MIGHT_HAVE_PC_PARPORT
 	select ARCH_MIGHT_HAVE_PC_SERIO
 	select ARCH_NO_PREEMPT
arch/s390/Kconfig +1 -0
index c72874f09741..434efd9ca0c5 100644
@@ -58,6 +58,7 @@ config S390
 	# Note: keep this list sorted alphabetically
 	#
 	imply IMA_SECURE_AND_OR_TRUSTED_BOOT
+	select ARCH_32BIT_USTAT_F_TINODE
 	select ARCH_BINFMT_ELF_STATE
 	select ARCH_HAS_DEBUG_VM_PGTABLE
 	select ARCH_HAS_DEBUG_WX
fs/statfs.c +4 -1
index 68cb07788750..0ba34c135593 100644
@@ -255,7 +255,10 @@ SYSCALL_DEFINE2(ustat, unsigned, dev, struct ustat __user *, ubuf)
 
 	memset(&tmp,0,sizeof(struct ustat));
 	tmp.f_tfree = sbuf.f_bfree;
-	tmp.f_tinode = sbuf.f_ffree;
+	if (IS_ENABLED(CONFIG_ARCH_32BIT_USTAT_F_TINODE))
+		tmp.f_tinode = min_t(u64, sbuf.f_ffree, UINT_MAX);
+	else
+		tmp.f_tinode = sbuf.f_ffree;
 
 	return copy_to_user(ubuf, &tmp, sizeof(struct ustat)) ? -EFAULT : 0;
 }
include/linux/types.h +6 -2
index a147977602b5..1e9d0a2c1dba 100644
@@ -14,7 +14,7 @@ typedef u32 __kernel_dev_t;
 
 typedef __kernel_fd_set		fd_set;
 typedef __kernel_dev_t		dev_t;
-typedef __kernel_ino_t		ino_t;
+typedef __kernel_ulong_t	ino_t;
 typedef __kernel_mode_t		mode_t;
 typedef unsigned short		umode_t;
 typedef u32			nlink_t;
@@ -189,7 +189,11 @@ struct hlist_node {
 
 struct ustat {
 	__kernel_daddr_t	f_tfree;
-	__kernel_ino_t		f_tinode;
+#ifdef ARCH_HAS_32BIT_F_TINODE
+	unsigned int		f_tinode;
+#else
+	unsigned long		f_tinode;
+#endif
 	char			f_fname[6];
 	char			f_fpack[6];
 };
maintainer
#12 lore raw

Re: [patch 09/14] tmpfs: disallow CONFIG_TMPFS_INODE64 on alpha

Quoted 14 lines · Heiko Carstens
include/linux/types.h +1 -1
index a147977602b5..1e9d0a2c1dba 100644
@@ -14,7 +14,7 @@ typedef u32 __kernel_dev_t;
 
 typedef __kernel_fd_set		fd_set;
 typedef __kernel_dev_t		dev_t;
-typedef __kernel_ino_t		ino_t;
+typedef __kernel_ulong_t	ino_t;
 typedef __kernel_mode_t		mode_t;
 typedef unsigned short		umode_t;
 typedef u32			nlink_t;

include/linux/types.h struct hlist_node { · line 196

Quoted 9 lines
include/linux/types.h +5 -1
@@ -189,7 +189,11 @@ struct hlist_node {
 
 struct ustat {
 	__kernel_daddr_t	f_tfree;
-	__kernel_ino_t		f_tinode;
+#ifdef ARCH_HAS_32BIT_F_TINODE
+	unsigned int		f_tinode;
+#else
+	unsigned long		f_tinode;
+#endif

Of course that should have been CONFIG_ARCH_32BIT_USTAT_F_TINODE in order to not break the existing ABI for alpha and s390.

#13 lore raw

Re: [patch 09/14] tmpfs: disallow CONFIG_TMPFS_INODE64 on alpha

In reply to Heiko Carstens
Quoted 4 lines · Heiko Carstens

I couldn't spot any and also gave the patch below a try and my system still boots without any errors.
So, as far as I can tell it _should_ be ok to change this.

So your patch (with the fix on top) looks sane to me.

I'm not entirely sure it is worth it, but the fact that we've had bugs wrt this before does seem to imply that we should do this.

I'd remove the __kernel_ino_t type entirely, but I wonder if user space might depend on it. I do find

   #ifndef __kernel_ino_t
   typedef __kernel_ulong_t __kernel_ino_t;
   #endif

in the GNU libc headers I have, but then I don't find any actual use of that, so it looks like it may be jyst a "we copied things for other reasons".

On the whole I think this would be the right thing to do, but I'm a bit worried that it's more pain that it might be worth.

Heiko, I think I'll leave this decision entirely to you. If you think it's worth it to avoid any possible future pain wrt this odd inode number thing for s390, just add it to the s390 tree with my ack. Because honestly, I think s390 is the only architecture that really cares by now.

Linus

#14 lore raw

Re: [patch 09/14] tmpfs: disallow CONFIG_TMPFS_INODE64 on alpha

Quoted 15 lines · Linus Torvalds
Quoted 4 lines · Heiko Carstens

I couldn't spot any and also gave the patch below a try and my system still boots without any errors.
So, as far as I can tell it _should_ be ok to change this.

So your patch (with the fix on top) looks sane to me.

I'm not entirely sure it is worth it, but the fact that we've had bugs wrt this before does seem to imply that we should do this.

I'd remove the __kernel_ino_t type entirely, but I wonder if user space might depend on it. I do find

Quoted 7 lines
   #ifndef __kernel_ino_t
   typedef __kernel_ulong_t __kernel_ino_t;
   #endif

in the GNU libc headers I have, but then I don't find any actual use of that, so it looks like it may be jyst a "we copied things for other reasons".

I checked debian codesearch to see if there are any users in distro source code and found exactly one instance that will definitely break at compile time:

https://sources.debian.org/src/nfs-utils/1:1.3.4-4/support/include/nfs/nfs.h/?hl=99#L99

This is a copy of a kernel header that was removed ten years ago with commit c152292f9ee7 ("nfsd: remove include/linux/nfsd/syscall.h").

The mainline version of that package removed the contents in 2016 in the following release (2.1.1), but debian is still on the previous version (1.3.4)
http://git.linux-nfs.org/?p=steved/nfs-utils.git;a=commitdiff;h=fc1127d754578cd1

Someone will have to update the package for Debian, but it seems that would be a good idea anyway.

Arnd

maintainer
#15 lore raw

Re: [patch 09/14] tmpfs: disallow CONFIG_TMPFS_INODE64 on alpha

In reply to Linus Torvalds
Quoted 22 lines · Linus Torvalds
Quoted 4 lines · Heiko Carstens

I couldn't spot any and also gave the patch below a try and my system still boots without any errors.
So, as far as I can tell it _should_ be ok to change this.

So your patch (with the fix on top) looks sane to me.

I'm not entirely sure it is worth it, but the fact that we've had bugs wrt this before does seem to imply that we should do this.

I'd remove the __kernel_ino_t type entirely, but I wonder if user space might depend on it. I do find

   #ifndef __kernel_ino_t
   typedef __kernel_ulong_t __kernel_ino_t;
   #endif

in the GNU libc headers I have, but then I don't find any actual use of that, so it looks like it may be jyst a "we copied things for other reasons".

Quoted 8 lines

On the whole I think this would be the right thing to do, but I'm a bit worried that it's more pain that it might be worth.

Heiko, I think I'll leave this decision entirely to you. If you think it's worth it to avoid any possible future pain wrt this odd inode number thing for s390, just add it to the s390 tree with my ack. Because honestly, I think s390 is the only architecture that really cares by now.

So, yes. We will go to change this to hopefully avoid future problems. The patch is supposed to be part of the next merge window and converts both s390 and alpha, unless somebody objects.

After that has been merged I'll provide a follow-on patch which enables TMPFS_INODE64 for alpha and s390 again, and yet another one which removes __kernel_ino_t as suggested by you.

author maintainer
#16 lore raw

PATCH 10/14 selftests/vm: rename file run_vmtests to run_vmtests.sh

In reply to Andrew Morton

From: Rong Chen <[email protected]>
Subject: selftests/vm: rename file run_vmtests to run_vmtests.sh

Commit c2aa8afc36fa has renamed run_vmtests in Makefile, but the file still uses the old name.

The kernel test robot reported the following issue:

# selftests: vm: run_vmtests.sh
# Warning: file run_vmtests.sh is missing!
not ok 1 selftests: vm: run_vmtests.sh

Fixes c2aa8afc36fa (selftests/vm: rename run_vmtests --> run_vmtests.sh)

---

 tools/testing/selftests/vm/{run_vmtests => run_vmtests.sh} | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename tools/testing/selftests/vm/{run_vmtests => run_vmtests.sh} (100%)
tools/testing/selftests/vm/run_vmtests.sh renamed from tools/testing/selftests/vm/run_vmtests +0 -0
similarity index 100%
rename from tools/testing/selftests/vm/run_vmtests
rename to tools/testing/selftests/vm/run_vmtests.sh
author maintainer
#17 lore raw

PATCH 11/14 MAINTAINERS: update Andrey Ryabinin's email address

In reply to Andrew Morton

From: Andrey Ryabinin <[email protected]>
Subject: MAINTAINERS: update Andrey Ryabinin's email address

Update my email, @virtuozzo.com will stop working shortly.

---

 .mailmap    |    1 +
 MAINTAINERS |    2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
.mailmap renamed from .mailmap~maintainers-update-andrey-ryabinins-email-address +1 -0
@@ -37,6 +37,7 @@ Andrew Murray <[email protected]
 Andrew Murray <[email protected]> <[email protected]>
 Andrew Vasquez <[email protected]>
 Andrey Ryabinin <[email protected]> <[email protected]>
+Andrey Ryabinin <[email protected]> <[email protected]>
 Andy Adamson <[email protected]>
 Antoine Tenart <[email protected]> <[email protected]>
 Antoine Tenart <[email protected]> <[email protected]>
MAINTAINERS renamed from MAINTAINERS~maintainers-update-andrey-ryabinins-email-address +1 -1
@@ -9559,7 +9559,7 @@ F:	Documentation/hwmon/k8temp.rst
 F:	drivers/hwmon/k8temp.c
 
 KASAN
-M:	Andrey Ryabinin <[email protected]>
+M:	Andrey Ryabinin <[email protected]>
 R:	Alexander Potapenko <[email protected]>
 R:	Dmitry Vyukov <[email protected]>
 L:	[email protected]

_

author maintainer
#18 lore raw

PATCH 12/14 Revert "mm: memcontrol: avoid workload stalls when lowering memory.high"

In reply to Andrew Morton

From: Johannes Weiner <[email protected]>
Subject: Revert "mm: memcontrol: avoid workload stalls when lowering memory.high"

This reverts commit 536d3bf261a2fc3b05b3e91e7eef7383443015cf, as it can cause writers to memory.high to get stuck in the kernel forever, performing page reclaim and consuming excessive amounts of CPU cycles.

Before the patch, a write to memory.high would first put the new limit in place for the workload, and then reclaim the requested delta. After the patch, the kernel tries to reclaim the delta before putting the new limit into place, in order to not overwhelm the workload with a sudden, large excess over the limit. However, if reclaim is actively racing with new allocations from the uncurbed workload, it can keep the write() working inside the kernel indefinitely.

This is causing problems in Facebook production. A privileged system-level daemon that adjusts memory.high for various workloads running on a host can get unexpectedly stuck in the kernel and essentially turn into a sort of involuntary kswapd for one of the workloads. We've observed that daemon busy-spin in a write() for minutes at a time, neglecting its other duties on the system, and expending privileged system resources on behalf of a workload.

To remedy this, we have first considered changing the reclaim logic to break out after a couple of loops - whether the workload has converged to the new limit or not - and bound the write() call this way. However, the root cause that inspired the sequence change in the first place has been fixed through other means, and so a revert back to the proven limit-setting sequence, also used by memory.max, is preferable.

The sequence was changed to avoid extreme latencies in the workload when the limit was lowered: the sudden, large excess created by the limit lowering would erroneously trigger the penalty sleeping code that is meant to throttle excessive growth from below. Allocating threads could end up sleeping long after the write() had already reclaimed the delta for which they were being punished.

However, erroneous throttling also caused problems in other scenarios at around the same time. This resulted in commit b3ff92916af3 ("mm, memcg:
reclaim more aggressively before high allocator throttling"), included in the same release as the offending commit. When allocating threads now encounter large excess caused by a racing write() to memory.high, instead of entering punitive sleeps, they will simply be tasked with helping reclaim down the excess, and will be held no longer than it takes to accomplish that. This is in line with regular limit enforcement - i.e. if the workload allocates up against or over an otherwise unchanged limit from below.

With the patch breaking userspace, and the root cause addressed by other means already, revert it again.

Fixes 536d3bf261a2 ("mm: memcontrol: avoid workload stalls when lowering memory.high")
Cc Roman Gushchin <[email protected]>
Cc Shakeel Butt <[email protected]>
Cc Michal Koutný <[email protected]>
Cc <[email protected]> [5.8+]

---

 mm/memcontrol.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
mm/memcontrol.c renamed from mm/memcontrol.c~revert-mm-memcontrol-avoid-workload-stalls-when-lowering-memoryhigh +2 -3
@@ -6271,6 +6271,8 @@ static ssize_t memory_high_write(struct
 	if (err)
 		return err;
 
+	page_counter_set_high(&memcg->memory, high);
+
 	for (;;) {
 		unsigned long nr_pages = page_counter_read(&memcg->memory);
 		unsigned long reclaimed;
@@ -6294,10 +6296,7 @@ static ssize_t memory_high_write(struct
 			break;
 	}
 
-	page_counter_set_high(&memcg->memory, high);
-
 	memcg_wb_domain_size_changed(memcg);
-
 	return nbytes;
 }
 

_

author maintainer
#19 lore raw

PATCH 13/14 mm, slub: better heuristic for number of cpus when calculating slab order

In reply to Andrew Morton

From: Vlastimil Babka <[email protected]>
Subject: mm, slub: better heuristic for number of cpus when calculating slab order

When creating a new kmem cache, SLUB determines how large the slab pages will based on number of inputs, including the number of CPUs in the system. Larger slab pages mean that more objects can be allocated/free from per-cpu slabs before accessing shared structures, but also potentially more memory can be wasted due to low slab usage and fragmentation.
The rough idea of using number of CPUs is that larger systems will be more likely to benefit from reduced contention, and also should have enough memory to spare.

Number of CPUs used to be determined as nr_cpu_ids, which is number of possible cpus, but on some systems many will never be onlined, thus commit 045ab8c9487b ("mm/slub: let number of online CPUs determine the slub page order") changed it to nr_online_cpus(). However, for kmem caches created early before CPUs are onlined, this may lead to permamently low slab page sizes.

Vincent reports a regression [1] of hackbench on arm64 systems:

Quoted 8 lines

I'm facing significant performances regression on a large arm64 server system (224 CPUs). Regressions is also present on small arm64 system (8 CPUs) but in a far smaller order of magnitude

On 224 CPUs system : 9 iterations of hackbench -l 16000 -g 16 v5.11-rc4 : 9.135sec (+/- 0.45%)
v5.11-rc4 + revert this patch: 3.173sec (+/- 0.48%) v5.10: 3.136sec (+/- 0.40%)

Mel reports a regression [2] of hackbench on x86_64, with lockstat suggesting page allocator contention:

Quoted 9 lines

i.e. the patch incurs a 7% to 32% performance penalty. This bisected cleanly yesterday when I was looking for the regression and then found the thread.

Numerous caches change size. For example, kmalloc-512 goes from order-0 (vanilla) to order-2 with the revert.

So mostly this is down to the number of times SLUB calls into the page allocator which only caches order-0 pages on a per-cpu basis.

Clearly num_online_cpus() doesn't work too early in bootup. We could change the order dynamically in a memory hotplug callback, but runtime order changing for existing kmem caches has been already shown as dangerous, and removed in 32a6f409b693 ("mm, slub: remove runtime allocation order changes"). It could be resurrected in a safe manner with some effort, but to fix the regression we need something simpler.

We could use num_present_cpus() that should be the number of physically present CPUs even before they are onlined. That would work for PowerPC [3], which triggered the original commit, but that still doesn't work on arm64 [4] as explained in [5].

So this patch tries to determine the best available value without specific arch knowledge.

- num_present_cpus() if the number is larger than 1, as that means the arch is likely setting it properly

- nr_cpu_ids otherwise

This should fix the reported regressions while also keeping the effect of 045ab8c9487b for PowerPC systems. It's possible there are configurations where num_present_cpus() is 1 during boot while nr_cpu_ids is at the same time bloated, so these (if they exist) would keep the large orders based on nr_cpu_ids as was before 045ab8c9487b.

[1] https://lore.kernel.org/linux-mm/CAKfTPtA_JgMf_+zdFbcb_V9rM7JBWNPjAz9irgwFj7Rou=xzZg@mail.gmail.com/
[2] https://lore.kernel.org/linux-mm/[email protected]/
[3] https://lore.kernel.org/linux-mm/[email protected]/
[4] https://lore.kernel.org/linux-mm/CAKfTPtAjyVmS5VYvU6DBxg4-JEo5bdmWbngf-03YsY18cmWv_g@mail.gmail.com/
[5] https://lore.kernel.org/linux-mm/20210126230305.GD30941@willie-the-truck/

Fixes 045ab8c9487b ("mm/slub: let number of online CPUs determine the slub page order")
Cc Catalin Marinas <[email protected]>
Cc Aneesh Kumar K.V <[email protected]>
Cc Bharata B Rao <[email protected]>
Cc Christoph Lameter <[email protected]>
Cc Roman Gushchin <[email protected]>
Cc Johannes Weiner <[email protected]>
Cc Joonsoo Kim <[email protected]>
Cc Jann Horn <[email protected]>
Cc Michal Hocko <[email protected]>
Cc David Rientjes <[email protected]>
Cc Shakeel Butt <[email protected]>
Cc Will Deacon <[email protected]>

---

 mm/slub.c |   18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
mm/slub.c renamed from mm/slub.c~mm-slub-better-heuristic-for-number-of-cpus-when-calculating-slab-order +16 -2
@@ -3423,6 +3423,7 @@ static inline int calculate_order(unsign
 	unsigned int order;
 	unsigned int min_objects;
 	unsigned int max_objects;
+	unsigned int nr_cpus;
 
 	/*
 	 * Attempt to find best configuration for a slab. This
@@ -3433,8 +3434,21 @@ static inline int calculate_order(unsign
 	 * we reduce the minimum objects required in a slab.
 	 */
 	min_objects = slub_min_objects;
-	if (!min_objects)
-		min_objects = 4 * (fls(num_online_cpus()) + 1);
+	if (!min_objects) {
+		/*
+		 * Some architectures will only update present cpus when
+		 * onlining them, so don't trust the number if it's just 1. But
+		 * we also don't want to use nr_cpu_ids always, as on some other
+		 * architectures, there can be many possible cpus, but never
+		 * onlined. Here we compromise between trying to avoid too high
+		 * order on systems that appear larger than they are, and too
+		 * low order on systems that appear smaller than they are.
+		 */
+		nr_cpus = num_present_cpus();
+		if (nr_cpus <= 1)
+			nr_cpus = nr_cpu_ids;
+		min_objects = 4 * (fls(nr_cpus) + 1);
+	}
 	max_objects = order_objects(slub_max_order, size);
 	min_objects = min(min_objects, max_objects);
 

_

#20 lore raw

Re: [patch 13/14] mm, slub: better heuristic for number of cpus when calculating slab order

Quoted 3 lines · Andrew Morton

From: Vlastimil Babka <[email protected]>
Subject: mm, slub: better heuristic for number of cpus when calculating slab order

...

Quoted 6 lines
Fixes 045ab8c9487b ("mm/slub: let number of online CPUs determine the slub page order")

As Andrew's incoming series might have been not merged yet, I will point to Mel's Tested-by:

https://lore.kernel.org/linux-mm/[email protected]/

Thanks, Mel!

Quoted 19 lines
Cc Catalin Marinas <[email protected]>
Cc Aneesh Kumar K.V <[email protected]>
Cc Bharata B Rao <[email protected]>
Cc Christoph Lameter <[email protected]>
Cc Roman Gushchin <[email protected]>
Cc Johannes Weiner <[email protected]>
Cc Joonsoo Kim <[email protected]>
Cc Jann Horn <[email protected]>
Cc Michal Hocko <[email protected]>
Cc David Rientjes <[email protected]>
Cc Shakeel Butt <[email protected]>
Cc Will Deacon <[email protected]>

---

 mm/slub.c |   18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
#21 lore raw

Re: [patch 13/14] mm, slub: better heuristic for number of cpus when calculating slab order

Quoted 3 lines · Vlastimil Babka

As Andrew's incoming series might have been not merged yet, I will point to Mel's Tested-by:

Thanks, added.

Linus

author maintainer
#22 lore raw

PATCH 14/14 nilfs2: make splice write available again

In reply to Andrew Morton

From: Joachim Henke <[email protected]>
Subject: nilfs2: make splice write available again

Since 5.10, splice() or sendfile() to NILFS2 return EINVAL. This was caused by commit 36e2c7421f02 ("fs: don't allow splice read/write without explicit ops").

This patch initializes the splice_write field in file_operations, like most file systems do, to restore the functionality.

---

 fs/nilfs2/file.c |    1 +
 1 file changed, 1 insertion(+)
fs/nilfs2/file.c renamed from fs/nilfs2/file.c~nilfs2-make-splice-write-available-again +1 -0
@@ -141,6 +141,7 @@ const struct file_operations nilfs_file_
 	/* .release	= nilfs_release_file, */
 	.fsync		= nilfs_sync_file,
 	.splice_read	= generic_file_splice_read,
+	.splice_write   = iter_file_splice_write,
 };
 
 const struct inode_operations nilfs_file_inode_operations = {

_

#23 lore raw
In reply to Andrew Morton

Hah. This series shows a small deficiency in your scripting wrt the diffstat:

Quoted 2 lines · Andrew Morton
 .mailmap                          |    1

...

Quoted 2 lines
 mm/slub.c                         |   18 +++++++++-
 17 files changed, 172 insertions(+), 49 deletions(-)

It actually has 18 files changed, but one of them is a pure rename (no change to the content), and apparently your diffstat tool can't handle that case.

It *should* have ended with

...

 mm/slub.c                                          | 18 +++++-
 .../selftests/vm/{run_vmtests => run_vmtests.sh}   |  0
 18 files changed, 172 insertions(+), 49 deletions(-)
 rename tools/testing/selftests/vm/{run_vmtests => run_vmtests.sh} (100%)

if you'd done a proper "git diff -M --stat --summary" of the series.

[ Ok, by default git would actually have said

    18 files changed, 171 insertions(+), 48 deletions(-)

but it looks like you use the patience diff option, which gives that
extra insertion/deletion line because it generates the diff a bit differently ]

Not a big deal,, but it made me briefly wonder "why doesn't my diffstat match yours".

Linus