All of lore.kernel.org
 help / color / mirror / Atom feed
* incoming
@ 2021-09-24 22:42 Andrew Morton
  2021-09-24 22:43 ` [patch 01/16] mm, hwpoison: add is_free_buddy_page() in HWPoisonHandlable() Andrew Morton
                   ` (15 more replies)
  0 siblings, 16 replies; 17+ messages in thread
From: Andrew Morton @ 2021-09-24 22:42 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: mm-commits, linux-mm

16 patches, based on 7d42e98182586f57f376406d033f05fe135edb75.

Subsystems affected by this patch series:

  mm/memory-failure
  mm/kasan
  mm/damon
  xtensa
  mm/shmem
  ocfs2
  scripts
  mm/tools
  lib
  mm/pagecache
  mm/debug
  sh
  mm/kasan
  mm/memory-failure
  mm/pagemap

Subsystem: mm/memory-failure

    Naoya Horiguchi <naoya.horiguchi@nec.com>:
      mm, hwpoison: add is_free_buddy_page() in HWPoisonHandlable()

Subsystem: mm/kasan

    Marco Elver <elver@google.com>:
      kasan: fix Kconfig check of CC_HAS_WORKING_NOSANITIZE_ADDRESS

Subsystem: mm/damon

    Adam Borowski <kilobyte@angband.pl>:
      mm/damon: don't use strnlen() with known-bogus source length

Subsystem: xtensa

    Guenter Roeck <linux@roeck-us.net>:
      xtensa: increase size of gcc stack frame check

Subsystem: mm/shmem

    Liu Yuntao <liuyuntao10@huawei.com>:
      mm/shmem.c: fix judgment error in shmem_is_huge()

Subsystem: ocfs2

    Wengang Wang <wen.gang.wang@oracle.com>:
      ocfs2: drop acl cache for directories too

Subsystem: scripts

    Miles Chen <miles.chen@mediatek.com>:
      scripts/sorttable: riscv: fix undeclared identifier 'EM_RISCV' error

Subsystem: mm/tools

    Changbin Du <changbin.du@gmail.com>:
      tools/vm/page-types: remove dependency on opt_file for idle page tracking

Subsystem: lib

    Paul Menzel <pmenzel@molgen.mpg.de>:
      lib/zlib_inflate/inffast: check config in C to avoid unused function warning

Subsystem: mm/pagecache

    Minchan Kim <minchan@kernel.org>:
      mm: fs: invalidate bh_lrus for only cold path

Subsystem: mm/debug

    Weizhao Ouyang <o451686892@gmail.com>:
      mm/debug: sync up MR_CONTIG_RANGE and MR_LONGTERM_PIN
      mm/debug: sync up latest migrate_reason to migrate_reason_names

Subsystem: sh

    Geert Uytterhoeven <geert+renesas@glider.be>:
      sh: pgtable-3level: fix cast to pointer from integer of different size

Subsystem: mm/kasan

    Nathan Chancellor <nathan@kernel.org>:
      kasan: always respect CONFIG_KASAN_STACK

Subsystem: mm/memory-failure

    Qi Zheng <zhengqi.arch@bytedance.com>:
      mm/memory_failure: fix the missing pte_unmap() call

Subsystem: mm/pagemap

    Chen Jun <chenjun102@huawei.com>:
      mm: fix uninitialized use in overcommit_policy_handler

 arch/sh/include/asm/pgtable-3level.h |    2 +-
 fs/buffer.c                          |    8 ++++++--
 fs/ocfs2/dlmglue.c                   |    3 ++-
 include/linux/buffer_head.h          |    4 ++--
 include/linux/migrate.h              |    6 +++++-
 lib/Kconfig.debug                    |    2 +-
 lib/Kconfig.kasan                    |    2 ++
 lib/zlib_inflate/inffast.c           |   13 ++++++-------
 mm/damon/dbgfs-test.h                |   16 ++++++++--------
 mm/debug.c                           |    4 +++-
 mm/memory-failure.c                  |   12 ++++++------
 mm/shmem.c                           |    4 ++--
 mm/swap.c                            |   19 ++++++++++++++++---
 mm/util.c                            |    4 ++--
 scripts/Makefile.kasan               |    3 ++-
 scripts/sorttable.c                  |    4 ++++
 tools/vm/page-types.c                |    2 +-
 17 files changed, 69 insertions(+), 39 deletions(-)


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

* [patch 01/16] mm, hwpoison: add is_free_buddy_page() in HWPoisonHandlable()
  2021-09-24 22:42 incoming Andrew Morton
@ 2021-09-24 22:43 ` Andrew Morton
  2021-09-24 22:43 ` [patch 02/16] kasan: fix Kconfig check of CC_HAS_WORKING_NOSANITIZE_ADDRESS Andrew Morton
                   ` (14 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: Andrew Morton @ 2021-09-24 22:43 UTC (permalink / raw)
  To: akpm, david, linux-mm, mhocko, mike.kravetz, mm-commits,
	naoya.horiguchi, osalvador, shy828301, stable, tony.luck,
	torvalds

From: Naoya Horiguchi <naoya.horiguchi@nec.com>
Subject: mm, hwpoison: add is_free_buddy_page() in HWPoisonHandlable()

commit fcc00621d88b ("mm/hwpoison: retry with shake_page() for unhandlable
pages") changes the return value of __get_hwpoison_page() to retry for
transiently unhandlable cases.  However, __get_hwpoison_page() currently
fails to properly judge buddy pages as handlable, so hard/soft offline for
buddy pages always fail as "unhandlable page".  This is totally
regrettable.

So let's add is_free_buddy_page() in HWPoisonHandlable(), so that
__get_hwpoison_page() returns different return values between buddy
pages and unhandlable pages as intended.

Link: https://lkml.kernel.org/r/20210909004131.163221-1-naoya.horiguchi@linux.dev
Fixes: fcc00621d88b ("mm/hwpoison: retry with shake_page() for unhandlable pages")
Signed-off-by: Naoya Horiguchi <naoya.horiguchi@nec.com>
Acked-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Yang Shi <shy828301@gmail.com>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 mm/memory-failure.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/mm/memory-failure.c~mm-hwpoison-add-is_free_buddy_page-in-hwpoisonhandlable
+++ a/mm/memory-failure.c
@@ -1126,7 +1126,7 @@ static int page_action(struct page_state
  */
 static inline bool HWPoisonHandlable(struct page *page)
 {
-	return PageLRU(page) || __PageMovable(page);
+	return PageLRU(page) || __PageMovable(page) || is_free_buddy_page(page);
 }
 
 static int __get_hwpoison_page(struct page *page)
_

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

* [patch 02/16] kasan: fix Kconfig check of CC_HAS_WORKING_NOSANITIZE_ADDRESS
  2021-09-24 22:42 incoming Andrew Morton
  2021-09-24 22:43 ` [patch 01/16] mm, hwpoison: add is_free_buddy_page() in HWPoisonHandlable() Andrew Morton
@ 2021-09-24 22:43 ` Andrew Morton
  2021-09-24 22:43 ` [patch 03/16] mm/damon: don't use strnlen() with known-bogus source length Andrew Morton
                   ` (13 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: Andrew Morton @ 2021-09-24 22:43 UTC (permalink / raw)
  To: akpm, andreyknvl, dvyukov, elver, glider, linux-mm, mm-commits,
	nogikh, ryabinin.a.a, tarasmadan, torvalds

From: Marco Elver <elver@google.com>
Subject: kasan: fix Kconfig check of CC_HAS_WORKING_NOSANITIZE_ADDRESS

In the main KASAN config option CC_HAS_WORKING_NOSANITIZE_ADDRESS is
checked for instrumentation-based modes.  However, if
HAVE_ARCH_KASAN_HW_TAGS is true all modes may still be selected.

To fix, also make the software modes depend on
CC_HAS_WORKING_NOSANITIZE_ADDRESS.

Link: https://lkml.kernel.org/r/20210910084240.1215803-1-elver@google.com
Fixes: 6a63a63ff1ac ("kasan: introduce CONFIG_KASAN_HW_TAGS")
Signed-off-by: Marco Elver <elver@google.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andrey Konovalov <andreyknvl@gmail.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Aleksandr Nogikh <nogikh@google.com>
Cc: Taras Madan <tarasmadan@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 lib/Kconfig.kasan |    2 ++
 1 file changed, 2 insertions(+)

--- a/lib/Kconfig.kasan~kasan-fix-kconfig-check-of-cc_has_working_nosanitize_address
+++ a/lib/Kconfig.kasan
@@ -66,6 +66,7 @@ choice
 config KASAN_GENERIC
 	bool "Generic mode"
 	depends on HAVE_ARCH_KASAN && CC_HAS_KASAN_GENERIC
+	depends on CC_HAS_WORKING_NOSANITIZE_ADDRESS
 	select SLUB_DEBUG if SLUB
 	select CONSTRUCTORS
 	help
@@ -86,6 +87,7 @@ config KASAN_GENERIC
 config KASAN_SW_TAGS
 	bool "Software tag-based mode"
 	depends on HAVE_ARCH_KASAN_SW_TAGS && CC_HAS_KASAN_SW_TAGS
+	depends on CC_HAS_WORKING_NOSANITIZE_ADDRESS
 	select SLUB_DEBUG if SLUB
 	select CONSTRUCTORS
 	help
_

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

* [patch 03/16] mm/damon: don't use strnlen() with known-bogus source length
  2021-09-24 22:42 incoming Andrew Morton
  2021-09-24 22:43 ` [patch 01/16] mm, hwpoison: add is_free_buddy_page() in HWPoisonHandlable() Andrew Morton
  2021-09-24 22:43 ` [patch 02/16] kasan: fix Kconfig check of CC_HAS_WORKING_NOSANITIZE_ADDRESS Andrew Morton
@ 2021-09-24 22:43 ` Andrew Morton
  2021-09-24 22:43 ` [patch 04/16] xtensa: increase size of gcc stack frame check Andrew Morton
                   ` (12 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: Andrew Morton @ 2021-09-24 22:43 UTC (permalink / raw)
  To: akpm, kilobyte, linux-mm, mm-commits, sj38.park, torvalds

From: Adam Borowski <kilobyte@angband.pl>
Subject: mm/damon: don't use strnlen() with known-bogus source length

gcc knows the true length too, and rightfully complains.

Link: https://lkml.kernel.org/r/20210912204447.10427-1-kilobyte@angband.pl
Signed-off-by: Adam Borowski <kilobyte@angband.pl>
Cc: SeongJae Park <sj38.park@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 mm/damon/dbgfs-test.h |   16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

--- a/mm/damon/dbgfs-test.h~mm-damon-dont-use-strnlen-with-known-bogus-source-length
+++ a/mm/damon/dbgfs-test.h
@@ -20,27 +20,27 @@ static void damon_dbgfs_test_str_to_targ
 	ssize_t nr_integers = 0, i;
 
 	question = "123";
-	answers = str_to_target_ids(question, strnlen(question, 128),
+	answers = str_to_target_ids(question, strlen(question),
 			&nr_integers);
 	KUNIT_EXPECT_EQ(test, (ssize_t)1, nr_integers);
 	KUNIT_EXPECT_EQ(test, 123ul, answers[0]);
 	kfree(answers);
 
 	question = "123abc";
-	answers = str_to_target_ids(question, strnlen(question, 128),
+	answers = str_to_target_ids(question, strlen(question),
 			&nr_integers);
 	KUNIT_EXPECT_EQ(test, (ssize_t)1, nr_integers);
 	KUNIT_EXPECT_EQ(test, 123ul, answers[0]);
 	kfree(answers);
 
 	question = "a123";
-	answers = str_to_target_ids(question, strnlen(question, 128),
+	answers = str_to_target_ids(question, strlen(question),
 			&nr_integers);
 	KUNIT_EXPECT_EQ(test, (ssize_t)0, nr_integers);
 	kfree(answers);
 
 	question = "12 35";
-	answers = str_to_target_ids(question, strnlen(question, 128),
+	answers = str_to_target_ids(question, strlen(question),
 			&nr_integers);
 	KUNIT_EXPECT_EQ(test, (ssize_t)2, nr_integers);
 	for (i = 0; i < nr_integers; i++)
@@ -48,7 +48,7 @@ static void damon_dbgfs_test_str_to_targ
 	kfree(answers);
 
 	question = "12 35 46";
-	answers = str_to_target_ids(question, strnlen(question, 128),
+	answers = str_to_target_ids(question, strlen(question),
 			&nr_integers);
 	KUNIT_EXPECT_EQ(test, (ssize_t)3, nr_integers);
 	for (i = 0; i < nr_integers; i++)
@@ -56,7 +56,7 @@ static void damon_dbgfs_test_str_to_targ
 	kfree(answers);
 
 	question = "12 35 abc 46";
-	answers = str_to_target_ids(question, strnlen(question, 128),
+	answers = str_to_target_ids(question, strlen(question),
 			&nr_integers);
 	KUNIT_EXPECT_EQ(test, (ssize_t)2, nr_integers);
 	for (i = 0; i < 2; i++)
@@ -64,13 +64,13 @@ static void damon_dbgfs_test_str_to_targ
 	kfree(answers);
 
 	question = "";
-	answers = str_to_target_ids(question, strnlen(question, 128),
+	answers = str_to_target_ids(question, strlen(question),
 			&nr_integers);
 	KUNIT_EXPECT_EQ(test, (ssize_t)0, nr_integers);
 	kfree(answers);
 
 	question = "\n";
-	answers = str_to_target_ids(question, strnlen(question, 128),
+	answers = str_to_target_ids(question, strlen(question),
 			&nr_integers);
 	KUNIT_EXPECT_EQ(test, (ssize_t)0, nr_integers);
 	kfree(answers);
_

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

* [patch 04/16] xtensa: increase size of gcc stack frame check
  2021-09-24 22:42 incoming Andrew Morton
                   ` (2 preceding siblings ...)
  2021-09-24 22:43 ` [patch 03/16] mm/damon: don't use strnlen() with known-bogus source length Andrew Morton
@ 2021-09-24 22:43 ` Andrew Morton
  2021-09-24 22:43 ` [patch 05/16] mm/shmem.c: fix judgment error in shmem_is_huge() Andrew Morton
                   ` (11 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: Andrew Morton @ 2021-09-24 22:43 UTC (permalink / raw)
  To: akpm, chris, David.Laight, jcmvbkbc, linux-mm, linux, masahiroy,
	mm-commits, torvalds

From: Guenter Roeck <linux@roeck-us.net>
Subject: xtensa: increase size of gcc stack frame check

xtensa frame size is larger than the frame size for almost all other
architectures.  This results in more than 50 "the frame size of <n> is
larger than 1024 bytes" errors when trying to build xtensa:allmodconfig.

Increase frame size for xtensa to 1536 bytes to avoid compile errors
due to frame size limits.

Link: https://lkml.kernel.org/r/20210912025235.3514761-1-linux@roeck-us.net
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Max Filippov <jcmvbkbc@gmail.com>
Cc: Chris Zankel <chris@zankel.net>
Cc: David Laight <David.Laight@ACULAB.COM>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 lib/Kconfig.debug |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/lib/Kconfig.debug~xtensa-increase-size-of-gcc-stack-frame-check
+++ a/lib/Kconfig.debug
@@ -346,7 +346,7 @@ config FRAME_WARN
 	int "Warn for stack frames larger than"
 	range 0 8192
 	default 2048 if GCC_PLUGIN_LATENT_ENTROPY
-	default 1536 if (!64BIT && PARISC)
+	default 1536 if (!64BIT && (PARISC || XTENSA))
 	default 1024 if (!64BIT && !PARISC)
 	default 2048 if 64BIT
 	help
_

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

* [patch 05/16] mm/shmem.c: fix judgment error in shmem_is_huge()
  2021-09-24 22:42 incoming Andrew Morton
                   ` (3 preceding siblings ...)
  2021-09-24 22:43 ` [patch 04/16] xtensa: increase size of gcc stack frame check Andrew Morton
@ 2021-09-24 22:43 ` Andrew Morton
  2021-09-24 22:43 ` [patch 06/16] ocfs2: drop acl cache for directories too Andrew Morton
                   ` (10 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: Andrew Morton @ 2021-09-24 22:43 UTC (permalink / raw)
  To: akpm, hughd, kirill.shutemov, linux-mm, liuyuntao10, mm-commits,
	torvalds, wuxu.wu

From: Liu Yuntao <liuyuntao10@huawei.com>
Subject: mm/shmem.c: fix judgment error in shmem_is_huge()

In the case of SHMEM_HUGE_WITHIN_SIZE, the page index is not rounded up
correctly.  When the page index points to the first page in a huge page,
round_up() cannot bring it to the end of the huge page, but to the end of
the previous one.

An example:

HPAGE_PMD_NR on my machine is 512(2 MB huge page size).  After allcoating
a 3000 KB buffer, I access it at location 2050 KB.  In shmem_is_huge(),
the corresponding index happens to be 512.  After rounded up by
HPAGE_PMD_NR, it will still be 512 which is smaller than i_size, and
shmem_is_huge() will return true.  As a result, my buffer takes an
additional huge page, and that shouldn't happen when shmem_enabled is set
to within_size.

Link: https://lkml.kernel.org/r/20210909032007.18353-1-liuyuntao10@huawei.com
Fixes: f3f0e1d2150b2b ("khugepaged: add support of collapse for tmpfs/shmem pages")
Signed-off-by: Liu Yuntao <liuyuntao10@huawei.com>
Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Hugh Dickins <hughd@google.com>
Cc: wuxu.wu <wuxu.wu@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 mm/shmem.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- a/mm/shmem.c~fix-judgment-error-in-shmem_is_huge
+++ a/mm/shmem.c
@@ -490,9 +490,9 @@ bool shmem_is_huge(struct vm_area_struct
 	case SHMEM_HUGE_ALWAYS:
 		return true;
 	case SHMEM_HUGE_WITHIN_SIZE:
-		index = round_up(index, HPAGE_PMD_NR);
+		index = round_up(index + 1, HPAGE_PMD_NR);
 		i_size = round_up(i_size_read(inode), PAGE_SIZE);
-		if (i_size >= HPAGE_PMD_SIZE && (i_size >> PAGE_SHIFT) >= index)
+		if (i_size >> PAGE_SHIFT >= index)
 			return true;
 		fallthrough;
 	case SHMEM_HUGE_ADVISE:
_

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

* [patch 06/16] ocfs2: drop acl cache for directories too
  2021-09-24 22:42 incoming Andrew Morton
                   ` (4 preceding siblings ...)
  2021-09-24 22:43 ` [patch 05/16] mm/shmem.c: fix judgment error in shmem_is_huge() Andrew Morton
@ 2021-09-24 22:43 ` Andrew Morton
  2021-09-24 22:43 ` [patch 07/16] scripts/sorttable: riscv: fix undeclared identifier 'EM_RISCV' error Andrew Morton
                   ` (9 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: Andrew Morton @ 2021-09-24 22:43 UTC (permalink / raw)
  To: akpm, gechangwei, ghe, jlbec, joseph.qi, junxiao.bi, linux-mm,
	mark, mm-commits, piaojun, stable, torvalds, wen.gang.wang

From: Wengang Wang <wen.gang.wang@oracle.com>
Subject: ocfs2: drop acl cache for directories too

ocfs2_data_convert_worker() is currently dropping any cached acl info for
FILE before down-converting meta lock.  It should also drop for DIRECTORY.
Otherwise the second acl lookup returns the cached one (from VFS layer)
which could be already stale.

The problem we are seeing is that the acl changes on one node doesn't get
refreshed on other nodes in the following case:

  Node 1                    Node 2
--------------            ----------------
getfacl dir1

			  getfacl dir1    <-- this is OK

setfacl -m u:user1:rwX dir1
getfacl dir1   <-- see the change for user1

			  getfacl dir1    <-- can't see change for user1

Link: https://lkml.kernel.org/r/20210903012631.6099-1-wen.gang.wang@oracle.com
Signed-off-by: Wengang Wang <wen.gang.wang@oracle.com>
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Cc: Mark Fasheh <mark@fasheh.com>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Junxiao Bi <junxiao.bi@oracle.com>
Cc: Changwei Ge <gechangwei@live.cn>
Cc: Gang He <ghe@suse.com>
Cc: Jun Piao <piaojun@huawei.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

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

--- a/fs/ocfs2/dlmglue.c~ocfs2-drop-acl-cache-for-directories-too
+++ a/fs/ocfs2/dlmglue.c
@@ -3951,7 +3951,7 @@ static int ocfs2_data_convert_worker(str
 		oi = OCFS2_I(inode);
 		oi->ip_dir_lock_gen++;
 		mlog(0, "generation: %u\n", oi->ip_dir_lock_gen);
-		goto out;
+		goto out_forget;
 	}
 
 	if (!S_ISREG(inode->i_mode))
@@ -3982,6 +3982,7 @@ static int ocfs2_data_convert_worker(str
 		filemap_fdatawait(mapping);
 	}
 
+out_forget:
 	forget_all_cached_acls(inode);
 
 out:
_

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

* [patch 07/16] scripts/sorttable: riscv: fix undeclared identifier 'EM_RISCV' error
  2021-09-24 22:42 incoming Andrew Morton
                   ` (5 preceding siblings ...)
  2021-09-24 22:43 ` [patch 06/16] ocfs2: drop acl cache for directories too Andrew Morton
@ 2021-09-24 22:43 ` Andrew Morton
  2021-09-24 22:43 ` [patch 08/16] tools/vm/page-types: remove dependency on opt_file for idle page tracking Andrew Morton
                   ` (8 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: Andrew Morton @ 2021-09-24 22:43 UTC (permalink / raw)
  To: akpm, aou, jszhang, linux-mm, miles.chen, mkubecek, mm-commits,
	mmayer, palmer, paul.walmsley, stefan.wahren, torvalds

From: Miles Chen <miles.chen@mediatek.com>
Subject: scripts/sorttable: riscv: fix undeclared identifier 'EM_RISCV' error

Fix the following build break by adding a conditional definition of
EM_RISCV in order to allow cross-compilation on machines which do not have
EM_RISCV definition in their host.

build break log from [1]:
scripts/sorttable.c:352:7: error: use of undeclared identifier 'EM_RISCV'

[1] https://lore.kernel.org/lkml/e8965b25-f15b-c7b4-748c-d207dda9c8e8@i2se.com/

EM_RISCV was added to <elf.h> in glibc 2.24 so builds on systems with
glibc headers < 2.24 should show this error.

[mkubecek@suse.cz: changelog addition]
Link: https://lkml.kernel.org/r/20210913030625.4525-1-miles.chen@mediatek.com
Fixes: 54fed35fd393 ("riscv: Enable BUILDTIME_TABLE_SORT")
Signed-off-by: Miles Chen <miles.chen@mediatek.com>
Reported-by: Stefan Wahren <stefan.wahren@i2se.com>
Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
Reviewed-by: Jisheng Zhang <jszhang@kernel.org>
Cc: Michal Kubecek <mkubecek@suse.cz>
Cc: Paul Walmsley <paul.walmsley@sifive.com>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Markus Mayer <mmayer@broadcom.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 scripts/sorttable.c |    4 ++++
 1 file changed, 4 insertions(+)

--- a/scripts/sorttable.c~scripts-sorttable-riscv-fix-undelcred-identifier-em_riscv-error
+++ a/scripts/sorttable.c
@@ -54,6 +54,10 @@
 #define EM_ARCV2	195
 #endif
 
+#ifndef EM_RISCV
+#define EM_RISCV	243
+#endif
+
 static uint32_t (*r)(const uint32_t *);
 static uint16_t (*r2)(const uint16_t *);
 static uint64_t (*r8)(const uint64_t *);
_

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

* [patch 08/16] tools/vm/page-types: remove dependency on opt_file for idle page tracking
  2021-09-24 22:42 incoming Andrew Morton
                   ` (6 preceding siblings ...)
  2021-09-24 22:43 ` [patch 07/16] scripts/sorttable: riscv: fix undeclared identifier 'EM_RISCV' error Andrew Morton
@ 2021-09-24 22:43 ` Andrew Morton
  2021-09-24 22:43 ` [patch 09/16] lib/zlib_inflate/inffast: check config in C to avoid unused function warning Andrew Morton
                   ` (7 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: Andrew Morton @ 2021-09-24 22:43 UTC (permalink / raw)
  To: akpm, changbin.du, linux-mm, mm-commits, torvalds

From: Changbin Du <changbin.du@gmail.com>
Subject: tools/vm/page-types: remove dependency on opt_file for idle page tracking

Idle page tracking can also be used for process address space, not only
file mappings.

Without this change, using with '-i' option for process address space
encounters below errors reported.

$ sudo ./page-types -p $(pidof bash) -i
mark page idle: Bad file descriptor
mark page idle: Bad file descriptor
mark page idle: Bad file descriptor
mark page idle: Bad file descriptor
mark page idle: Bad file descriptor
mark page idle: Bad file descriptor
....

Link: https://lkml.kernel.org/r/20210917032826.10669-1-changbin.du@gmail.com
Signed-off-by: Changbin Du <changbin.du@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 tools/vm/page-types.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/tools/vm/page-types.c~tools-vm-page-types-remove-dependency-on-opt_file-for-idle-page-tracking
+++ a/tools/vm/page-types.c
@@ -1331,7 +1331,7 @@ int main(int argc, char *argv[])
 	if (opt_list && opt_list_mapcnt)
 		kpagecount_fd = checked_open(PROC_KPAGECOUNT, O_RDONLY);
 
-	if (opt_mark_idle && opt_file)
+	if (opt_mark_idle)
 		page_idle_fd = checked_open(SYS_KERNEL_MM_PAGE_IDLE, O_RDWR);
 
 	if (opt_list && opt_pid)
_

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

* [patch 09/16] lib/zlib_inflate/inffast: check config in C to avoid unused function warning
  2021-09-24 22:42 incoming Andrew Morton
                   ` (7 preceding siblings ...)
  2021-09-24 22:43 ` [patch 08/16] tools/vm/page-types: remove dependency on opt_file for idle page tracking Andrew Morton
@ 2021-09-24 22:43 ` Andrew Morton
  2021-09-24 22:43 ` [patch 10/16] mm: fs: invalidate bh_lrus for only cold path Andrew Morton
                   ` (6 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: Andrew Morton @ 2021-09-24 22:43 UTC (permalink / raw)
  To: akpm, benh, christophe.leroy, linux-mm, mm-commits, mpe, nathan,
	ndesaulniers, paulus, pmenzel, thunder.leizhen, torvalds

From: Paul Menzel <pmenzel@molgen.mpg.de>
Subject: lib/zlib_inflate/inffast: check config in C to avoid unused function warning

Building Linux for ppc64le with Ubuntu clang version
12.0.0-3ubuntu1~21.04.1 shows the warning below.

    arch/powerpc/boot/inffast.c:20:1: warning: unused function 'get_unaligned16' [-Wunused-function]
    get_unaligned16(const unsigned short *p)
    ^
    1 warning generated.

Fix it, by moving the check from the preprocessor to C, so the compiler
sees the use.

Link: https://lkml.kernel.org/r/20210920084332.5752-1-pmenzel@molgen.mpg.de
Signed-off-by: Paul Menzel <pmenzel@molgen.mpg.de>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 lib/zlib_inflate/inffast.c |   13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

--- a/lib/zlib_inflate/inffast.c~lib-zlib_inflate-inffast-check-config-in-c-to-avoid-unused-function-warning
+++ a/lib/zlib_inflate/inffast.c
@@ -253,13 +253,12 @@ void inflate_fast(z_streamp strm, unsign
 
 			sfrom = (unsigned short *)(from);
 			loops = len >> 1;
-			do
-#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
-			    *sout++ = *sfrom++;
-#else
-			    *sout++ = get_unaligned16(sfrom++);
-#endif
-			while (--loops);
+			do {
+			    if (IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS))
+				*sout++ = *sfrom++;
+			    else
+				*sout++ = get_unaligned16(sfrom++);
+			} while (--loops);
 			out = (unsigned char *)sout;
 			from = (unsigned char *)sfrom;
 		    } else { /* dist == 1 or dist == 2 */
_

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

* [patch 10/16] mm: fs: invalidate bh_lrus for only cold path
  2021-09-24 22:42 incoming Andrew Morton
                   ` (8 preceding siblings ...)
  2021-09-24 22:43 ` [patch 09/16] lib/zlib_inflate/inffast: check config in C to avoid unused function warning Andrew Morton
@ 2021-09-24 22:43 ` Andrew Morton
  2021-09-24 22:43 ` [patch 11/16] mm/debug: sync up MR_CONTIG_RANGE and MR_LONGTERM_PIN Andrew Morton
                   ` (5 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: Andrew Morton @ 2021-09-24 22:43 UTC (permalink / raw)
  To: akpm, cgoldswo, linux-mm, minchan, mm-commits, oliver.sang,
	torvalds, zhengjun.xing

From: Minchan Kim <minchan@kernel.org>
Subject: mm: fs: invalidate bh_lrus for only cold path

kernel test robot reported the regression of fio.write_iops[1] with [2].

Since lru_add_drain is called frequently, invalidate bh_lrus there could
increase bh_lrus cache miss ratio, which needs more IO in the end.

This patch moves the bh_lrus invalidation from the hot path( e.g.,
zap_page_range, pagevec_release) to cold path(i.e., lru_add_drain_all,
lru_cache_disable).

"Xing, Zhengjun" confirmed 

: I test the patch, the regression reduced to -2.9%.

[1] https://lore.kernel.org/lkml/20210520083144.GD14190@xsang-OptiPlex-9020/
[2] 8cc621d2f45d, mm: fs: invalidate BH LRU during page migration

Link: https://lkml.kernel.org/r/20210907212347.1977686-1-minchan@kernel.org
Signed-off-by: Minchan Kim <minchan@kernel.org>
Reported-by: kernel test robot <oliver.sang@intel.com>
Reviewed-by: Chris Goldsworthy <cgoldswo@codeaurora.org>
Tested-by: "Xing, Zhengjun" <zhengjun.xing@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 fs/buffer.c                 |    8 ++++++--
 include/linux/buffer_head.h |    4 ++--
 mm/swap.c                   |   19 ++++++++++++++++---
 3 files changed, 24 insertions(+), 7 deletions(-)

--- a/fs/buffer.c~mm-fs-invalidate-bh_lrus-for-only-cold-path
+++ a/fs/buffer.c
@@ -1425,12 +1425,16 @@ void invalidate_bh_lrus(void)
 }
 EXPORT_SYMBOL_GPL(invalidate_bh_lrus);
 
-void invalidate_bh_lrus_cpu(int cpu)
+/*
+ * It's called from workqueue context so we need a bh_lru_lock to close
+ * the race with preemption/irq.
+ */
+void invalidate_bh_lrus_cpu(void)
 {
 	struct bh_lru *b;
 
 	bh_lru_lock();
-	b = per_cpu_ptr(&bh_lrus, cpu);
+	b = this_cpu_ptr(&bh_lrus);
 	__invalidate_bh_lrus(b);
 	bh_lru_unlock();
 }
--- a/include/linux/buffer_head.h~mm-fs-invalidate-bh_lrus-for-only-cold-path
+++ a/include/linux/buffer_head.h
@@ -194,7 +194,7 @@ void __breadahead_gfp(struct block_devic
 struct buffer_head *__bread_gfp(struct block_device *,
 				sector_t block, unsigned size, gfp_t gfp);
 void invalidate_bh_lrus(void);
-void invalidate_bh_lrus_cpu(int cpu);
+void invalidate_bh_lrus_cpu(void);
 bool has_bh_in_lru(int cpu, void *dummy);
 struct buffer_head *alloc_buffer_head(gfp_t gfp_flags);
 void free_buffer_head(struct buffer_head * bh);
@@ -408,7 +408,7 @@ static inline int inode_has_buffers(stru
 static inline void invalidate_inode_buffers(struct inode *inode) {}
 static inline int remove_inode_buffers(struct inode *inode) { return 1; }
 static inline int sync_mapping_buffers(struct address_space *mapping) { return 0; }
-static inline void invalidate_bh_lrus_cpu(int cpu) {}
+static inline void invalidate_bh_lrus_cpu(void) {}
 static inline bool has_bh_in_lru(int cpu, void *dummy) { return false; }
 #define buffer_heads_over_limit 0
 
--- a/mm/swap.c~mm-fs-invalidate-bh_lrus-for-only-cold-path
+++ a/mm/swap.c
@@ -620,7 +620,6 @@ void lru_add_drain_cpu(int cpu)
 		pagevec_lru_move_fn(pvec, lru_lazyfree_fn);
 
 	activate_page_drain(cpu);
-	invalidate_bh_lrus_cpu(cpu);
 }
 
 /**
@@ -703,6 +702,20 @@ void lru_add_drain(void)
 	local_unlock(&lru_pvecs.lock);
 }
 
+/*
+ * It's called from per-cpu workqueue context in SMP case so
+ * lru_add_drain_cpu and invalidate_bh_lrus_cpu should run on
+ * the same cpu. It shouldn't be a problem in !SMP case since
+ * the core is only one and the locks will disable preemption.
+ */
+static void lru_add_and_bh_lrus_drain(void)
+{
+	local_lock(&lru_pvecs.lock);
+	lru_add_drain_cpu(smp_processor_id());
+	local_unlock(&lru_pvecs.lock);
+	invalidate_bh_lrus_cpu();
+}
+
 void lru_add_drain_cpu_zone(struct zone *zone)
 {
 	local_lock(&lru_pvecs.lock);
@@ -717,7 +730,7 @@ static DEFINE_PER_CPU(struct work_struct
 
 static void lru_add_drain_per_cpu(struct work_struct *dummy)
 {
-	lru_add_drain();
+	lru_add_and_bh_lrus_drain();
 }
 
 /*
@@ -858,7 +871,7 @@ void lru_cache_disable(void)
 	 */
 	__lru_add_drain_all(true);
 #else
-	lru_add_drain();
+	lru_add_and_bh_lrus_drain();
 #endif
 }
 
_

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

* [patch 11/16] mm/debug: sync up MR_CONTIG_RANGE and MR_LONGTERM_PIN
  2021-09-24 22:42 incoming Andrew Morton
                   ` (9 preceding siblings ...)
  2021-09-24 22:43 ` [patch 10/16] mm: fs: invalidate bh_lrus for only cold path Andrew Morton
@ 2021-09-24 22:43 ` Andrew Morton
  2021-09-24 22:43 ` [patch 12/16] mm/debug: sync up latest migrate_reason to migrate_reason_names Andrew Morton
                   ` (4 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: Andrew Morton @ 2021-09-24 22:43 UTC (permalink / raw)
  To: akpm, almasrymina, dave.hansen, jhubbard, khandual, linux-mm,
	mhocko, minchan, mm-commits, o451686892, osalvador,
	pasha.tatashin, stable, torvalds, weixugc, willy, yang.shi,
	ying.huang, ziy

From: Weizhao Ouyang <o451686892@gmail.com>
Subject: mm/debug: sync up MR_CONTIG_RANGE and MR_LONGTERM_PIN

Sync up MR_CONTIG_RANGE and MR_LONGTERM_PIN to migrate_reason_names.

Link: https://lkml.kernel.org/r/20210921064553.293905-2-o451686892@gmail.com
Fixes: 310253514bbf ("mm/migrate: rename migration reason MR_CMA to MR_CONTIG_RANGE")
Fixes: d1e153fea2a8 ("mm/gup: migrate pinned pages out of movable zone")
Signed-off-by: Weizhao Ouyang <o451686892@gmail.com>
Reviewed-by: "Huang, Ying" <ying.huang@intel.com>
Reviewed-by: John Hubbard <jhubbard@nvidia.com>
Cc: Anshuman Khandual <khandual@linux.vnet.ibm.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Pavel Tatashin <pasha.tatashin@soleen.com>
Cc: Yang Shi <yang.shi@linux.alibaba.com>
Cc: Zi Yan <ziy@nvidia.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Mina Almasry <almasrymina@google.com>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Wei Xu <weixugc@google.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 mm/debug.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

--- a/mm/debug.c~mm-debug-sync-up-mr_contig_range-and-mr_longterm_pin
+++ a/mm/debug.c
@@ -24,7 +24,8 @@ const char *migrate_reason_names[MR_TYPE
 	"syscall_or_cpuset",
 	"mempolicy_mbind",
 	"numa_misplaced",
-	"cma",
+	"contig_range",
+	"longterm_pin",
 };
 
 const struct trace_print_flags pageflag_names[] = {
_

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

* [patch 12/16] mm/debug: sync up latest migrate_reason to migrate_reason_names
  2021-09-24 22:42 incoming Andrew Morton
                   ` (10 preceding siblings ...)
  2021-09-24 22:43 ` [patch 11/16] mm/debug: sync up MR_CONTIG_RANGE and MR_LONGTERM_PIN Andrew Morton
@ 2021-09-24 22:43 ` Andrew Morton
  2021-09-24 22:43 ` [patch 13/16] sh: pgtable-3level: fix cast to pointer from integer of different size Andrew Morton
                   ` (3 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: Andrew Morton @ 2021-09-24 22:43 UTC (permalink / raw)
  To: akpm, almasrymina, dave.hansen, jhubbard, khandual, linux-mm,
	mhocko, minchan, mm-commits, o451686892, osalvador,
	pasha.tatashin, torvalds, weixugc, willy, yang.shi, ying.huang,
	ziy

From: Weizhao Ouyang <o451686892@gmail.com>
Subject: mm/debug: sync up latest migrate_reason to migrate_reason_names

Sync up MR_DEMOTION to migrate_reason_names and add a synch prompt.

Link: https://lkml.kernel.org/r/20210921064553.293905-3-o451686892@gmail.com
Fixes: 26aa2d199d6f ("mm/migrate: demote pages during reclaim")
Signed-off-by: Weizhao Ouyang <o451686892@gmail.com>
Reviewed-by: "Huang, Ying" <ying.huang@intel.com>
Reviewed-by: John Hubbard <jhubbard@nvidia.com>
Cc: Anshuman Khandual <khandual@linux.vnet.ibm.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Pavel Tatashin <pasha.tatashin@soleen.com>
Cc: Yang Shi <yang.shi@linux.alibaba.com>
Cc: Zi Yan <ziy@nvidia.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Mina Almasry <almasrymina@google.com>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Wei Xu <weixugc@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 include/linux/migrate.h |    6 +++++-
 mm/debug.c              |    1 +
 2 files changed, 6 insertions(+), 1 deletion(-)

--- a/include/linux/migrate.h~mm-debug-sync-up-latest-migrate_reason-to-migrate_reason_names
+++ a/include/linux/migrate.h
@@ -19,6 +19,11 @@ struct migration_target_control;
  */
 #define MIGRATEPAGE_SUCCESS		0
 
+/*
+ * Keep sync with:
+ * - macro MIGRATE_REASON in include/trace/events/migrate.h
+ * - migrate_reason_names[MR_TYPES] in mm/debug.c
+ */
 enum migrate_reason {
 	MR_COMPACTION,
 	MR_MEMORY_FAILURE,
@@ -32,7 +37,6 @@ enum migrate_reason {
 	MR_TYPES
 };
 
-/* In mm/debug.c; also keep sync with include/trace/events/migrate.h */
 extern const char *migrate_reason_names[MR_TYPES];
 
 #ifdef CONFIG_MIGRATION
--- a/mm/debug.c~mm-debug-sync-up-latest-migrate_reason-to-migrate_reason_names
+++ a/mm/debug.c
@@ -26,6 +26,7 @@ const char *migrate_reason_names[MR_TYPE
 	"numa_misplaced",
 	"contig_range",
 	"longterm_pin",
+	"demotion",
 };
 
 const struct trace_print_flags pageflag_names[] = {
_

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

* [patch 13/16] sh: pgtable-3level: fix cast to pointer from integer of different size
  2021-09-24 22:42 incoming Andrew Morton
                   ` (11 preceding siblings ...)
  2021-09-24 22:43 ` [patch 12/16] mm/debug: sync up latest migrate_reason to migrate_reason_names Andrew Morton
@ 2021-09-24 22:43 ` Andrew Morton
  2021-09-24 22:44 ` [patch 14/16] kasan: always respect CONFIG_KASAN_STACK Andrew Morton
                   ` (2 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: Andrew Morton @ 2021-09-24 22:43 UTC (permalink / raw)
  To: akpm, aneesh.kumar, dalias, daniel, geert+renesas,
	jacopo+renesas, linux-mm, mm-commits, rob, torvalds, ysato

From: Geert Uytterhoeven <geert+renesas@glider.be>
Subject: sh: pgtable-3level: fix cast to pointer from integer of different size

If X2TLB=y (CPU_SHX2=y or CPU_SHX3=y, e.g. migor_defconfig), pgd_t.pgd
is "unsigned long long", causing:

    In file included from arch/sh/include/asm/pgtable.h:13,
		     from include/linux/pgtable.h:6,
		     from include/linux/mm.h:33,
		     from arch/sh/kernel/asm-offsets.c:14:
    arch/sh/include/asm/pgtable-3level.h: In function `pud_pgtable':
    arch/sh/include/asm/pgtable-3level.h:37:9: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
       37 |  return (pmd_t *)pud_val(pud);
	  |         ^

Fix this by adding an intermediate cast to "unsigned long", which is
basically what the old code did before.

Link: https://lkml.kernel.org/r/2c2eef3c9a2f57e5609100a4864715ccf253d30f.1631713483.git.geert+renesas@glider.be
Fixes: 9cf6fa2458443118 ("mm: rename pud_page_vaddr to pud_pgtable and make it return pmd_t *")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Tested-by: Daniel Palmer <daniel@thingy.jp>
Acked-by: Rob Landley <rob@landley.net>
Cc: Yoshinori Sato <ysato@users.osdn.me>
Cc: Rich Felker <dalias@libc.org>
Cc: "Aneesh Kumar K . V" <aneesh.kumar@linux.ibm.com>
Cc: Jacopo Mondi <jacopo+renesas@jmondi.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 arch/sh/include/asm/pgtable-3level.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/arch/sh/include/asm/pgtable-3level.h~sh-pgtable-3level-fix-cast-to-pointer-from-integer-of-different-size
+++ a/arch/sh/include/asm/pgtable-3level.h
@@ -34,7 +34,7 @@ typedef struct { unsigned long long pmd;
 
 static inline pmd_t *pud_pgtable(pud_t pud)
 {
-	return (pmd_t *)pud_val(pud);
+	return (pmd_t *)(unsigned long)pud_val(pud);
 }
 
 /* only used by the stubbed out hugetlb gup code, should never be called */
_

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

* [patch 14/16] kasan: always respect CONFIG_KASAN_STACK
  2021-09-24 22:42 incoming Andrew Morton
                   ` (12 preceding siblings ...)
  2021-09-24 22:43 ` [patch 13/16] sh: pgtable-3level: fix cast to pointer from integer of different size Andrew Morton
@ 2021-09-24 22:44 ` Andrew Morton
  2021-09-24 22:44 ` [patch 15/16] mm/memory_failure: fix the missing pte_unmap() call Andrew Morton
  2021-09-24 22:44 ` [patch 16/16] mm: fix uninitialized use in overcommit_policy_handler Andrew Morton
  15 siblings, 0 replies; 17+ messages in thread
From: Andrew Morton @ 2021-09-24 22:44 UTC (permalink / raw)
  To: akpm, andreyknvl, arnd, dvyukov, elver, glider, linux-mm,
	mm-commits, nathan, ndesaulniers, ryabinin.a.a, torvalds

From: Nathan Chancellor <nathan@kernel.org>
Subject: kasan: always respect CONFIG_KASAN_STACK

Currently, the asan-stack parameter is only passed along if
CFLAGS_KASAN_SHADOW is not empty, which requires KASAN_SHADOW_OFFSET to be
defined in Kconfig so that the value can be checked.  In RISC-V's case,
KASAN_SHADOW_OFFSET is not defined in Kconfig, which means that asan-stack
does not get disabled with clang even when CONFIG_KASAN_STACK is disabled,
resulting in large stack warnings with allmodconfig:

drivers/video/fbdev/omap2/omapfb/displays/panel-lgphilips-lb035q02.c:117:12:
error: stack frame size (14400) exceeds limit (2048) in function
'lb035q02_connect' [-Werror,-Wframe-larger-than]
static int lb035q02_connect(struct omap_dss_device *dssdev)
           ^
1 error generated.

Ensure that the value of CONFIG_KASAN_STACK is always passed along to the
compiler so that these warnings do not happen when CONFIG_KASAN_STACK is
disabled.

Link: https://github.com/ClangBuiltLinux/linux/issues/1453
References: 6baec880d7a5 ("kasan: turn off asan-stack for clang-8 and earlier")
Link: https://lkml.kernel.org/r/20210922205525.570068-1-nathan@kernel.org
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Reviewed-by: Marco Elver <elver@google.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andrey Konovalov <andreyknvl@gmail.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 scripts/Makefile.kasan |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

--- a/scripts/Makefile.kasan~kasan-always-respect-config_kasan_stack
+++ a/scripts/Makefile.kasan
@@ -33,10 +33,11 @@ else
 	CFLAGS_KASAN := $(CFLAGS_KASAN_SHADOW) \
 	 $(call cc-param,asan-globals=1) \
 	 $(call cc-param,asan-instrumentation-with-call-threshold=$(call_threshold)) \
-	 $(call cc-param,asan-stack=$(stack_enable)) \
 	 $(call cc-param,asan-instrument-allocas=1)
 endif
 
+CFLAGS_KASAN += $(call cc-param,asan-stack=$(stack_enable))
+
 endif # CONFIG_KASAN_GENERIC
 
 ifdef CONFIG_KASAN_SW_TAGS
_

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

* [patch 15/16] mm/memory_failure: fix the missing pte_unmap() call
  2021-09-24 22:42 incoming Andrew Morton
                   ` (13 preceding siblings ...)
  2021-09-24 22:44 ` [patch 14/16] kasan: always respect CONFIG_KASAN_STACK Andrew Morton
@ 2021-09-24 22:44 ` Andrew Morton
  2021-09-24 22:44 ` [patch 16/16] mm: fix uninitialized use in overcommit_policy_handler Andrew Morton
  15 siblings, 0 replies; 17+ messages in thread
From: Andrew Morton @ 2021-09-24 22:44 UTC (permalink / raw)
  To: akpm, david, linux-mm, mm-commits, naoya.horiguchi, songmuchun,
	torvalds, zhengqi.arch

From: Qi Zheng <zhengqi.arch@bytedance.com>
Subject: mm/memory_failure: fix the missing pte_unmap() call

The paired pte_unmap() call is missing before the
dev_pagemap_mapping_shift() returns.  So fix it.

Davidsaid "I guess this code never runs on 32bit / highmem, that's why we
didn't notice so far".

[akpm@linux-foundation.org: cleanup]
Link: https://lkml.kernel.org/r/20210923122642.4999-1-zhengqi.arch@bytedance.com
Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Cc: Naoya Horiguchi <naoya.horiguchi@nec.com>
Cc: Muchun Song <songmuchun@bytedance.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 mm/memory-failure.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

--- a/mm/memory-failure.c~mm-memory_failure-fix-the-missing-pte_unmap-call
+++ a/mm/memory-failure.c
@@ -306,6 +306,7 @@ static unsigned long dev_pagemap_mapping
 		struct vm_area_struct *vma)
 {
 	unsigned long address = vma_address(page, vma);
+	unsigned long ret = 0;
 	pgd_t *pgd;
 	p4d_t *p4d;
 	pud_t *pud;
@@ -329,11 +330,10 @@ static unsigned long dev_pagemap_mapping
 	if (pmd_devmap(*pmd))
 		return PMD_SHIFT;
 	pte = pte_offset_map(pmd, address);
-	if (!pte_present(*pte))
-		return 0;
-	if (pte_devmap(*pte))
-		return PAGE_SHIFT;
-	return 0;
+	if (pte_present(*pte) && pte_devmap(*pte))
+		ret = PAGE_SHIFT;
+	pte_unmap(pte);
+	return ret;
 }
 
 /*
_

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

* [patch 16/16] mm: fix uninitialized use in overcommit_policy_handler
  2021-09-24 22:42 incoming Andrew Morton
                   ` (14 preceding siblings ...)
  2021-09-24 22:44 ` [patch 15/16] mm/memory_failure: fix the missing pte_unmap() call Andrew Morton
@ 2021-09-24 22:44 ` Andrew Morton
  15 siblings, 0 replies; 17+ messages in thread
From: Andrew Morton @ 2021-09-24 22:44 UTC (permalink / raw)
  To: akpm, chenjun102, feng.tang, linux-mm, mhocko, mm-commits,
	rui.xiang, stable, torvalds, wangkefeng.wang

From: Chen Jun <chenjun102@huawei.com>
Subject: mm: fix uninitialized use in overcommit_policy_handler

We get an unexpected value of /proc/sys/vm/overcommit_memory after running
the following program:

int main()
{
    int fd = open("/proc/sys/vm/overcommit_memory", O_RDWR);
    write(fd, "1", 1);
    write(fd, "2", 1);
    close(fd);
}

write(fd, "2", 1) will pass *ppos = 1 to proc_dointvec_minmax. 
proc_dointvec_minmax will return 0 without setting new_policy.

t.data = &new_policy;
ret = proc_dointvec_minmax(&t, write, buffer, lenp, ppos)
      -->do_proc_dointvec
         -->__do_proc_dointvec
              if (write) {
                if (proc_first_pos_non_zero_ignore(ppos, table))
                  goto out;

sysctl_overcommit_memory = new_policy;

so sysctl_overcommit_memory will be set to an uninitialized value.

Check whether new_policy has been changed by proc_dointvec_minmax.

Link: https://lkml.kernel.org/r/20210923020524.13289-1-chenjun102@huawei.com
Fixes: 56f3547bfa4d ("mm: adjust vm_committed_as_batch according to vm overcommit policy")
Signed-off-by: Chen Jun <chenjun102@huawei.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Reviewed-by: Feng Tang <feng.tang@intel.com>
Reviewed-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: Rui Xiang <rui.xiang@huawei.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 mm/util.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- a/mm/util.c~mm-fix-the-uninitialized-use-in-overcommit_policy_handler
+++ a/mm/util.c
@@ -787,7 +787,7 @@ int overcommit_policy_handler(struct ctl
 		size_t *lenp, loff_t *ppos)
 {
 	struct ctl_table t;
-	int new_policy;
+	int new_policy = -1;
 	int ret;
 
 	/*
@@ -805,7 +805,7 @@ int overcommit_policy_handler(struct ctl
 		t = *table;
 		t.data = &new_policy;
 		ret = proc_dointvec_minmax(&t, write, buffer, lenp, ppos);
-		if (ret)
+		if (ret || new_policy == -1)
 			return ret;
 
 		mm_compute_batch(new_policy);
_

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

end of thread, other threads:[~2021-09-24 22:44 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-24 22:42 incoming Andrew Morton
2021-09-24 22:43 ` [patch 01/16] mm, hwpoison: add is_free_buddy_page() in HWPoisonHandlable() Andrew Morton
2021-09-24 22:43 ` [patch 02/16] kasan: fix Kconfig check of CC_HAS_WORKING_NOSANITIZE_ADDRESS Andrew Morton
2021-09-24 22:43 ` [patch 03/16] mm/damon: don't use strnlen() with known-bogus source length Andrew Morton
2021-09-24 22:43 ` [patch 04/16] xtensa: increase size of gcc stack frame check Andrew Morton
2021-09-24 22:43 ` [patch 05/16] mm/shmem.c: fix judgment error in shmem_is_huge() Andrew Morton
2021-09-24 22:43 ` [patch 06/16] ocfs2: drop acl cache for directories too Andrew Morton
2021-09-24 22:43 ` [patch 07/16] scripts/sorttable: riscv: fix undeclared identifier 'EM_RISCV' error Andrew Morton
2021-09-24 22:43 ` [patch 08/16] tools/vm/page-types: remove dependency on opt_file for idle page tracking Andrew Morton
2021-09-24 22:43 ` [patch 09/16] lib/zlib_inflate/inffast: check config in C to avoid unused function warning Andrew Morton
2021-09-24 22:43 ` [patch 10/16] mm: fs: invalidate bh_lrus for only cold path Andrew Morton
2021-09-24 22:43 ` [patch 11/16] mm/debug: sync up MR_CONTIG_RANGE and MR_LONGTERM_PIN Andrew Morton
2021-09-24 22:43 ` [patch 12/16] mm/debug: sync up latest migrate_reason to migrate_reason_names Andrew Morton
2021-09-24 22:43 ` [patch 13/16] sh: pgtable-3level: fix cast to pointer from integer of different size Andrew Morton
2021-09-24 22:44 ` [patch 14/16] kasan: always respect CONFIG_KASAN_STACK Andrew Morton
2021-09-24 22:44 ` [patch 15/16] mm/memory_failure: fix the missing pte_unmap() call Andrew Morton
2021-09-24 22:44 ` [patch 16/16] mm: fix uninitialized use in overcommit_policy_handler 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.