Skip to content

[PW_SID:1122773] [v5] mm/sparse-vmemmap: flush_cache_vmap() after hotplugging vmemmap#2232

Closed
linux-riscv-bot wants to merge 3 commits into
workflow__riscv__fixesfrom
pw1122773
Closed

[PW_SID:1122773] [v5] mm/sparse-vmemmap: flush_cache_vmap() after hotplugging vmemmap#2232
linux-riscv-bot wants to merge 3 commits into
workflow__riscv__fixesfrom
pw1122773

Conversation

@linux-riscv-bot

Copy link
Copy Markdown

PR for series 1122773 applied to workflow__riscv__fixes

Name: [v5] mm/sparse-vmemmap: flush_cache_vmap() after hotplugging vmemmap
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=1122773
Version: 5

liutgnu and others added 3 commits July 6, 2026 18:24
A NULL pointer dereference issue is noticed in riscv's machine_kexec_prepare(),
where image->segment[i].buf might be NULL and copied unchecked.

The NULL buf comes from ima_add_kexec_buffer(), where kbuf is added by
kexec_add_buffer(), but kbuf.buffer is NULL, then it is copied without
a check in machine_kexec_prepare():

  kexec_file_load
    -> kimage_file_alloc_init()
       -> kimage_file_prepare_segments()
          -> ima_add_kexec_buffer()
             -> kexec_add_buffer()
    -> machine_kexec_prepare()
       -> memcpy()

Address this by adding a check before the data copy attempt.

Fixes: b7fb4d7 ("RISC-V: use memcpy for kexec_file mode")
Cc: stable@vger.kernel.org
Closes: https://lore.kernel.org/kexec/CAO7dBbVftLUhd2qrh7hmijTB3PEPfZAhykCGqEfrPoOcSrrj-w@mail.gmail.com/
Acked-by: Baoquan He <bhe@redhat.com>
Acked-by: Pratyush Yadav <pratyush@kernel.org>
Reviewed-by: Nutty Liu <nutty.liu@hotmail.com>
Signed-off-by: Tao Liu <ltao@redhat.com>
Link: https://patch.msgid.link/20260705232706.30265-2-ltao@redhat.com
Signed-off-by: Paul Walmsley <pjw@kernel.org>
section_activate() does not flush TLB after populating new vmemmap
pages. On most architectures, this is okay. However it is a problem on
RISC-V since there the TLB caching non-present entries is permitted,
which causes spurious faults on some hardwares.

This seems to be most easily reproduced with DEBUG_VM=y and
PAGE_POISONING=y, which causes these newly mapped struct pages to be
poisoned i.e. written to immediately after mapping.

Extend the RISC-V flush_cache_vmap() to also handle the vmemmap range,
and call it after hotplugging vmemmap, which gets the possible spurious
fault handled in the exception handler.

At least for now, the only other architecture with both
SPARSEMEM_VMEMMAP and flush_cache_vmap() is PowerPC, which has a similar
problem with newly valid PTEs. But there flush_cache_vmap() is just a
ptesync. So it should be safe to do this for generic code while having
minimal performance impact.

Suggested-by: Muchun Song <muchun.song@linux.dev>
Signed-off-by: Vivian Wang <wangruikang@iscas.ac.cn>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v5] mm/sparse-vmemmap: flush_cache_vmap() after hotplugging vmemmap"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 145.21 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v5] mm/sparse-vmemmap: flush_cache_vmap() after hotplugging vmemmap"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 2035.98 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v5] mm/sparse-vmemmap: flush_cache_vmap() after hotplugging vmemmap"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 2543.80 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v5] mm/sparse-vmemmap: flush_cache_vmap() after hotplugging vmemmap"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 12.09 seconds
Result: ERROR
Output:

Full log:
W: Support for running offline not available (unshare: unshare failed: Operation not permitted)
I: config: PASS in 0:00:05.037012
I: default: FAIL in 0:00:02.243984
I: kernel: SKIP in 0:00:00.000008
I: xipkernel: SKIP in 0:00:00.000004
I: modules: SKIP in 0:00:00.003088
I: dtbs: PASS in 0:00:01.335971
I: dtbs-legacy: SKIP in 0:00:00.003746
I: debugkernel: SKIP in 0:00:00.000004
I: headers: PASS in 0:00:01.121646
I: build output in /build/tmp.4y29aC0L9T
tuxmake --download-all-korg-gcc-toolchains --target-arch=riscv --kconfig=nommu_k210_defconfig --toolchain=gcc --wrapper=ccache --environment=KBUILD_BUILD_TIMESTAMP=@1621270510 --environment=KBUILD_BUILD_USER=tuxmake --environment=KBUILD_BUILD_HOST=tuxmake --environment=KCFLAGS=-ffile-prefix-map=/build/tmp.4y29aC0L9T/build/= --runtime=null --image=docker.io/tuxmake/riscv_gcc CROSS_COMPILE=riscv64-linux- config default kernel xipkernel modules dtbs dtbs-legacy debugkernel headers
make --silent --keep-going --jobs=48 O=/build/tmp.4y29aC0L9T/build ARCH=riscv CROSS_COMPILE=riscv64-linux- 'CC=ccache riscv64-linux-gcc' 'HOSTCC=ccache gcc' nommu_k210_defconfig
make --silent --keep-going --jobs=48 O=/build/tmp.4y29aC0L9T/build ARCH=riscv CROSS_COMPILE=riscv64-linux- 'CC=ccache riscv64-linux-gcc' 'HOSTCC=ccache gcc'
In file included from /build/tmp8rz2wt53/include/linux/cacheflush.h:5,
                 from /build/tmp8rz2wt53/include/linux/highmem.h:8,
                 from /build/tmp8rz2wt53/include/linux/bvec.h:10,
                 from /build/tmp8rz2wt53/include/linux/blk_types.h:10,
                 from /build/tmp8rz2wt53/include/linux/writeback.h:13,
                 from /build/tmp8rz2wt53/include/linux/memcontrol.h:23,
                 from /build/tmp8rz2wt53/include/linux/swap.h:9,
                 from /build/tmp8rz2wt53/include/linux/suspend.h:5,
                 from /build/tmp8rz2wt53/arch/riscv/kernel/asm-offsets.c:12:
/build/tmp8rz2wt53/arch/riscv/include/asm/cacheflush.h: In function 'flush_cache_vmap':
/build/tmp8rz2wt53/arch/riscv/include/asm/cacheflush.h:60:23: error: 'VMEMMAP_START' undeclared (first use in this function)
   60 |             (start >= VMEMMAP_START && end <= VMEMMAP_END))
      |                       ^~~~~~~~~~~~~
/build/tmp8rz2wt53/arch/riscv/include/asm/cacheflush.h:60:23: note: each undeclared identifier is reported only once for each function it appears in
/build/tmp8rz2wt53/arch/riscv/include/asm/cacheflush.h:60:47: error: 'VMEMMAP_END' undeclared (first use in this function); did you mean 'MEMREMAP_ENC'?
   60 |             (start >= VMEMMAP_START && end <= VMEMMAP_END))
      |                                               ^~~~~~~~~~~
      |                                               MEMREMAP_ENC
make[3]: *** [/build/tmp8rz2wt53/scripts/Makefile.build:184: arch/riscv/kernel/asm-offsets.s] Error 1
make[3]: Target 'prepare' not remade because of errors.
make[2]: *** [/build/tmp8rz2wt53/Makefile:1405: prepare0] Error 2
make[2]: Target '__all' not remade because of errors.
make[1]: *** [/build/tmp8rz2wt53/Makefile:248: __sub-make] Error 2
make[1]: Target '__all' not remade because of errors.
make: *** [Makefile:248: __sub-make] Error 2
make: Target '__all' not remade because of errors.
make --silent --keep-going --jobs=48 O=/build/tmp.4y29aC0L9T/build INSTALL_DTBS_PATH=/build/tmp.4y29aC0L9T/build/dtbsinstall/dtbs ARCH=riscv CROSS_COMPILE=riscv64-linux- 'CC=ccache riscv64-linux-gcc' 'HOSTCC=ccache gcc' dtbs
rm -rf /build/tmp.4y29aC0L9T/build/dtbsinstall
mkdir -p /build/tmp.4y29aC0L9T/build/dtbsinstall/dtbs
make --silent --keep-going --jobs=48 O=/build/tmp.4y29aC0L9T/build INSTALL_DTBS_PATH=/build/tmp.4y29aC0L9T/build/dtbsinstall/dtbs ARCH=riscv CROSS_COMPILE=riscv64-linux- 'CC=ccache riscv64-linux-gcc' 'HOSTCC=ccache gcc' dtbs_install
tar --sort=name --owner=tuxmake:1000 --group=tuxmake:1000 --mtime=@1783408069 --clamp-mtime -caf /build/tmp.4y29aC0L9T/build/dtbs.tar -C /build/tmp.4y29aC0L9T/build/dtbsinstall dtbs
rm -rf /build/tmp.4y29aC0L9T/build/install_hdr
make --silent --keep-going --jobs=48 O=/build/tmp.4y29aC0L9T/build INSTALL_HDR_PATH=/build/tmp.4y29aC0L9T/build/install_hdr/ ARCH=riscv CROSS_COMPILE=riscv64-linux- 'CC=ccache riscv64-linux-gcc' 'HOSTCC=ccache gcc' headers_install
tar --sort=name --owner=tuxmake:1000 --group=tuxmake:1000 --mtime=@1783408069 --clamp-mtime -caf /build/tmp.4y29aC0L9T/build/headers.tar -C /build/tmp.4y29aC0L9T/build/install_hdr .
warnings/errors:
/build/tmp8rz2wt53/arch/riscv/include/asm/cacheflush.h:60:23: error: 'VMEMMAP_START' undeclared (first use in this function)
/build/tmp8rz2wt53/arch/riscv/include/asm/cacheflush.h:60:47: error: 'VMEMMAP_END' undeclared (first use in this function); did you mean 'MEMREMAP_ENC'?


@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v5] mm/sparse-vmemmap: flush_cache_vmap() after hotplugging vmemmap"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 12.01 seconds
Result: ERROR
Output:

Full log:
W: Support for running offline not available (unshare: unshare failed: Operation not permitted)
I: config: PASS in 0:00:05.126148
I: default: FAIL in 0:00:02.225264
I: kernel: SKIP in 0:00:00.000008
I: xipkernel: SKIP in 0:00:00.000004
I: modules: SKIP in 0:00:00.001837
I: dtbs: PASS in 0:00:01.315081
I: dtbs-legacy: SKIP in 0:00:00.004518
I: debugkernel: SKIP in 0:00:00.000003
I: headers: PASS in 0:00:01.121027
I: build output in /build/tmp.H02NsXu7ZS
tuxmake --download-all-korg-gcc-toolchains --target-arch=riscv --kconfig=nommu_virt_defconfig --toolchain=gcc --wrapper=ccache --environment=KBUILD_BUILD_TIMESTAMP=@1621270510 --environment=KBUILD_BUILD_USER=tuxmake --environment=KBUILD_BUILD_HOST=tuxmake --environment=KCFLAGS=-ffile-prefix-map=/build/tmp.H02NsXu7ZS/build/= --runtime=null --image=docker.io/tuxmake/riscv_gcc CROSS_COMPILE=riscv64-linux- config default kernel xipkernel modules dtbs dtbs-legacy debugkernel headers
make --silent --keep-going --jobs=48 O=/build/tmp.H02NsXu7ZS/build ARCH=riscv CROSS_COMPILE=riscv64-linux- 'CC=ccache riscv64-linux-gcc' 'HOSTCC=ccache gcc' nommu_virt_defconfig
make --silent --keep-going --jobs=48 O=/build/tmp.H02NsXu7ZS/build ARCH=riscv CROSS_COMPILE=riscv64-linux- 'CC=ccache riscv64-linux-gcc' 'HOSTCC=ccache gcc'
In file included from /build/tmp8rz2wt53/include/linux/cacheflush.h:5,
                 from /build/tmp8rz2wt53/include/linux/highmem.h:8,
                 from /build/tmp8rz2wt53/include/linux/bvec.h:10,
                 from /build/tmp8rz2wt53/include/linux/blk_types.h:10,
                 from /build/tmp8rz2wt53/include/linux/writeback.h:13,
                 from /build/tmp8rz2wt53/include/linux/memcontrol.h:23,
                 from /build/tmp8rz2wt53/include/linux/swap.h:9,
                 from /build/tmp8rz2wt53/include/linux/suspend.h:5,
                 from /build/tmp8rz2wt53/arch/riscv/kernel/asm-offsets.c:12:
/build/tmp8rz2wt53/arch/riscv/include/asm/cacheflush.h: In function 'flush_cache_vmap':
/build/tmp8rz2wt53/arch/riscv/include/asm/cacheflush.h:60:23: error: 'VMEMMAP_START' undeclared (first use in this function)
   60 |             (start >= VMEMMAP_START && end <= VMEMMAP_END))
      |                       ^~~~~~~~~~~~~
/build/tmp8rz2wt53/arch/riscv/include/asm/cacheflush.h:60:23: note: each undeclared identifier is reported only once for each function it appears in
/build/tmp8rz2wt53/arch/riscv/include/asm/cacheflush.h:60:47: error: 'VMEMMAP_END' undeclared (first use in this function); did you mean 'MEMREMAP_ENC'?
   60 |             (start >= VMEMMAP_START && end <= VMEMMAP_END))
      |                                               ^~~~~~~~~~~
      |                                               MEMREMAP_ENC
make[3]: *** [/build/tmp8rz2wt53/scripts/Makefile.build:184: arch/riscv/kernel/asm-offsets.s] Error 1
make[3]: Target 'prepare' not remade because of errors.
make[2]: *** [/build/tmp8rz2wt53/Makefile:1405: prepare0] Error 2
make[2]: Target '__all' not remade because of errors.
make[1]: *** [/build/tmp8rz2wt53/Makefile:248: __sub-make] Error 2
make[1]: Target '__all' not remade because of errors.
make: *** [Makefile:248: __sub-make] Error 2
make: Target '__all' not remade because of errors.
make --silent --keep-going --jobs=48 O=/build/tmp.H02NsXu7ZS/build INSTALL_DTBS_PATH=/build/tmp.H02NsXu7ZS/build/dtbsinstall/dtbs ARCH=riscv CROSS_COMPILE=riscv64-linux- 'CC=ccache riscv64-linux-gcc' 'HOSTCC=ccache gcc' dtbs
rm -rf /build/tmp.H02NsXu7ZS/build/dtbsinstall
mkdir -p /build/tmp.H02NsXu7ZS/build/dtbsinstall/dtbs
make --silent --keep-going --jobs=48 O=/build/tmp.H02NsXu7ZS/build INSTALL_DTBS_PATH=/build/tmp.H02NsXu7ZS/build/dtbsinstall/dtbs ARCH=riscv CROSS_COMPILE=riscv64-linux- 'CC=ccache riscv64-linux-gcc' 'HOSTCC=ccache gcc' dtbs_install
tar --sort=name --owner=tuxmake:1000 --group=tuxmake:1000 --mtime=@1783408069 --clamp-mtime -caf /build/tmp.H02NsXu7ZS/build/dtbs.tar -C /build/tmp.H02NsXu7ZS/build/dtbsinstall dtbs
rm -rf /build/tmp.H02NsXu7ZS/build/install_hdr
make --silent --keep-going --jobs=48 O=/build/tmp.H02NsXu7ZS/build INSTALL_HDR_PATH=/build/tmp.H02NsXu7ZS/build/install_hdr/ ARCH=riscv CROSS_COMPILE=riscv64-linux- 'CC=ccache riscv64-linux-gcc' 'HOSTCC=ccache gcc' headers_install
tar --sort=name --owner=tuxmake:1000 --group=tuxmake:1000 --mtime=@1783408069 --clamp-mtime -caf /build/tmp.H02NsXu7ZS/build/headers.tar -C /build/tmp.H02NsXu7ZS/build/install_hdr .
warnings/errors:
/build/tmp8rz2wt53/arch/riscv/include/asm/cacheflush.h:60:23: error: 'VMEMMAP_START' undeclared (first use in this function)
/build/tmp8rz2wt53/arch/riscv/include/asm/cacheflush.h:60:47: error: 'VMEMMAP_END' undeclared (first use in this function); did you mean 'MEMREMAP_ENC'?


@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v5] mm/sparse-vmemmap: flush_cache_vmap() after hotplugging vmemmap"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 2.18 seconds
Result: WARNING
Output:

WARNING: A patch subject line should describe the change not the tool that found it
#4: 
Subject: [PATCH] mm/sparse-vmemmap: flush_cache_vmap() after hotplugging

CHECK: Consider using #include <linux/cacheflush.h> instead of <asm/cacheflush.h>
#57: FILE: arch/riscv/mm/init.c:27:
+#include <asm/cacheflush.h>

total: 0 errors, 1 warnings, 1 checks, 24 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

Commit a82a3f157863 ("mm/sparse-vmemmap: flush_cache_vmap() after hotplugging vmemmap") has style problems, please review.

NOTE: Ignored message types: ALLOC_SIZEOF_STRUCT CAMELCASE COMMIT_LOG_LONG_LINE GIT_COMMIT_ID MACRO_ARG_REUSE NO_AUTHOR_SIGN_OFF

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.
total: 0 errors, 1 warnings, 1 checks, 24 lines checked
CHECK: Consider using #include <linux/cacheflush.h> instead of <asm/cacheflush.h>
WARNING: A patch subject line should describe the change not the tool that found it


@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v5] mm/sparse-vmemmap: flush_cache_vmap() after hotplugging vmemmap"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 85.33 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v5] mm/sparse-vmemmap: flush_cache_vmap() after hotplugging vmemmap"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.25 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v5] mm/sparse-vmemmap: flush_cache_vmap() after hotplugging vmemmap"
kdoc
Desc: Detects for kdoc errors
Duration: 0.87 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v5] mm/sparse-vmemmap: flush_cache_vmap() after hotplugging vmemmap"
module-param
Desc: Detect module_param changes
Duration: 0.28 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v5] mm/sparse-vmemmap: flush_cache_vmap() after hotplugging vmemmap"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.24 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v5] mm/sparse-vmemmap: flush_cache_vmap() after hotplugging vmemmap"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.35 seconds
Result: PASS

@linux-riscv-bot
linux-riscv-bot force-pushed the workflow__riscv__fixes branch 4 times, most recently from 2b6a725 to da477a6 Compare July 11, 2026 01:54
@linux-riscv-bot
linux-riscv-bot deleted the pw1122773 branch July 13, 2026 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants