* [PATCH V2 10/17] riscv: compat: syscall: Add entry.S implementation
From: guoren @ 2021-12-28 14:39 UTC (permalink / raw)
To: guoren, palmer, arnd, anup.patel, gregkh, liush, wefu, drew,
wangjunqiang, hch
Cc: linux-s390, Guo Ren, x86, linux-kernel, linux-csky, linux-mips,
sparclinux, linux-riscv, linuxppc-dev, inux-parisc,
linux-arm-kernel
In-Reply-To: <20211228143958.3409187-1-guoren@kernel.org>
From: Guo Ren <guoren@linux.alibaba.com>
Implement the entry of compat_sys_call_table[] in asm. Ref to
riscv-privileged spec 4.1.1 Supervisor Status Register (sstatus):
BIT[32:33] = UXL[1:0]:
- 1:32
- 2:64
- 3:128
Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Guo Ren <guoren@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
---
arch/riscv/include/asm/csr.h | 7 +++++++
arch/riscv/kernel/entry.S | 18 ++++++++++++++++--
2 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h
index 5046f431645c..7dac12366833 100644
--- a/arch/riscv/include/asm/csr.h
+++ b/arch/riscv/include/asm/csr.h
@@ -36,6 +36,13 @@
#define SR_SD _AC(0x8000000000000000, UL) /* FS/XS dirty */
#endif
+#ifdef CONFIG_COMPAT
+#define SR_UXL _AC(0x300000000, UL) /* XLEN mask for U-mode */
+#define SR_UXL_32 _AC(0x100000000, UL) /* XLEN = 32 for U-mode */
+#define SR_UXL_64 _AC(0x200000000, UL) /* XLEN = 64 for U-mode */
+#define SR_UXL_SHIFT 32
+#endif
+
/* SATP flags */
#ifndef CONFIG_64BIT
#define SATP_PPN _AC(0x003FFFFF, UL)
diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S
index ed29e9c8f660..1951743f09b3 100644
--- a/arch/riscv/kernel/entry.S
+++ b/arch/riscv/kernel/entry.S
@@ -207,13 +207,27 @@ check_syscall_nr:
* Syscall number held in a7.
* If syscall number is above allowed value, redirect to ni_syscall.
*/
- bgeu a7, t0, 1f
+ bgeu a7, t0, 3f
+#ifdef CONFIG_COMPAT
+ REG_L s0, PT_STATUS(sp)
+ srli s0, s0, SR_UXL_SHIFT
+ andi s0, s0, (SR_UXL >> SR_UXL_SHIFT)
+ li t0, (SR_UXL_32 >> SR_UXL_SHIFT)
+ sub t0, s0, t0
+ bnez t0, 1f
+
+ /* Call compat_syscall */
+ la s0, compat_sys_call_table
+ j 2f
+1:
+#endif
/* Call syscall */
la s0, sys_call_table
+2:
slli t0, a7, RISCV_LGPTR
add s0, s0, t0
REG_L s0, 0(s0)
-1:
+3:
jalr s0
ret_from_syscall:
--
2.25.1
^ permalink raw reply related
* [PATCH V2 11/17] riscv: compat: Add elf.h implementation
From: guoren @ 2021-12-28 14:39 UTC (permalink / raw)
To: guoren, palmer, arnd, anup.patel, gregkh, liush, wefu, drew,
wangjunqiang, hch
Cc: linux-s390, Guo Ren, x86, linux-kernel, linux-csky, linux-mips,
sparclinux, linux-riscv, linuxppc-dev, inux-parisc,
linux-arm-kernel
In-Reply-To: <20211228143958.3409187-1-guoren@kernel.org>
From: Guo Ren <guoren@linux.alibaba.com>
Implement necessary type and macro for compat elf. See the code
comment for detail.
Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Guo Ren <guoren@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
---
arch/riscv/include/asm/elf.h | 49 +++++++++++++++++++++++++++++++++++-
1 file changed, 48 insertions(+), 1 deletion(-)
diff --git a/arch/riscv/include/asm/elf.h b/arch/riscv/include/asm/elf.h
index f53c40026c7a..91b372d4e13b 100644
--- a/arch/riscv/include/asm/elf.h
+++ b/arch/riscv/include/asm/elf.h
@@ -8,6 +8,8 @@
#ifndef _ASM_RISCV_ELF_H
#define _ASM_RISCV_ELF_H
+#include <uapi/linux/elf.h>
+#include <linux/compat.h>
#include <uapi/asm/elf.h>
#include <asm/auxvec.h>
#include <asm/byteorder.h>
@@ -18,11 +20,13 @@
*/
#define ELF_ARCH EM_RISCV
+#ifndef ELF_CLASS
#ifdef CONFIG_64BIT
#define ELF_CLASS ELFCLASS64
#else
#define ELF_CLASS ELFCLASS32
#endif
+#endif
#define ELF_DATA ELFDATA2LSB
@@ -31,6 +35,15 @@
*/
#define elf_check_arch(x) ((x)->e_machine == EM_RISCV)
+#ifdef CONFIG_COMPAT
+/*
+ * Use the same code with elf_check_arch, because elf32_hdr &
+ * elf64_hdr e_machine's offset are different. The checker is
+ * a little bit simple compare to other architectures.
+ */
+#define compat_elf_check_arch(x) ((x)->e_machine == EM_RISCV)
+#endif
+
#define CORE_DUMP_USE_REGSET
#define ELF_EXEC_PAGESIZE (PAGE_SIZE)
@@ -43,8 +56,14 @@
#define ELF_ET_DYN_BASE ((TASK_SIZE / 3) * 2)
#ifdef CONFIG_64BIT
+#ifdef CONFIG_COMPAT
+#define STACK_RND_MASK (test_thread_flag(TIF_32BIT) ? \
+ 0x7ff >> (PAGE_SHIFT - 12) : \
+ 0x3ffff >> (PAGE_SHIFT - 12))
+#else
#define STACK_RND_MASK (0x3ffff >> (PAGE_SHIFT - 12))
#endif
+#endif
/*
* This yields a mask that user programs can use to figure out what
* instruction set this CPU supports. This could be done in user space,
@@ -60,11 +79,19 @@ extern unsigned long elf_hwcap;
*/
#define ELF_PLATFORM (NULL)
+#define COMPAT_ELF_PLATFORM (NULL)
+
#ifdef CONFIG_MMU
#define ARCH_DLINFO \
do { \
+ /* \
+ * Note that we add ulong after elf_addr_t because \
+ * casting current->mm->context.vdso triggers a cast \
+ * warning of cast from pointer to integer for \
+ * COMPAT ELFCLASS32. \
+ */ \
NEW_AUX_ENT(AT_SYSINFO_EHDR, \
- (elf_addr_t)current->mm->context.vdso); \
+ (elf_addr_t)(ulong)current->mm->context.vdso); \
NEW_AUX_ENT(AT_L1I_CACHESIZE, \
get_cache_size(1, CACHE_TYPE_INST)); \
NEW_AUX_ENT(AT_L1I_CACHEGEOMETRY, \
@@ -90,4 +117,24 @@ do { \
*(struct user_regs_struct *)regs; \
} while (0);
+#ifdef CONFIG_COMPAT
+
+/*
+ * FIXME: not sure SET_PERSONALITY for compat process is right!
+ */
+#define SET_PERSONALITY(ex) \
+do { if ((ex).e_ident[EI_CLASS] == ELFCLASS32) \
+ set_thread_flag(TIF_32BIT); \
+ else \
+ clear_thread_flag(TIF_32BIT); \
+ set_personality(PER_LINUX | (current->personality & (~PER_MASK))); \
+} while (0)
+
+#define COMPAT_ELF_ET_DYN_BASE ((TASK_SIZE_32 / 3) * 2)
+
+/* rv32 registers */
+typedef compat_ulong_t compat_elf_greg_t;
+typedef compat_elf_greg_t compat_elf_gregset_t[ELF_NGREG];
+
+#endif /* CONFIG_COMPAT */
#endif /* _ASM_RISCV_ELF_H */
--
2.25.1
^ permalink raw reply related
* [PATCH V2 12/17] riscv: compat: vdso: Add rv32 VDSO base code implementation
From: guoren @ 2021-12-28 14:39 UTC (permalink / raw)
To: guoren, palmer, arnd, anup.patel, gregkh, liush, wefu, drew,
wangjunqiang, hch
Cc: linux-s390, Guo Ren, x86, linux-kernel, linux-csky, linux-mips,
sparclinux, linux-riscv, linuxppc-dev, inux-parisc,
linux-arm-kernel
In-Reply-To: <20211228143958.3409187-1-guoren@kernel.org>
From: Guo Ren <guoren@linux.alibaba.com>
There is no vgettimeofday supported in rv32 that makes simple to
generate rv32 vdso code which only needs riscv64 compiler. Other
architectures need change compiler or -m (machine parameter) to
support vdso32 compiling. If rv32 support vgettimeofday (which
cause C compile) in future, we would add CROSS_COMPILE to support
that makes more requirement on compiler enviornment.
linux-rv64/arch/riscv/kernel/compat_vdso/compat_vdso.so.dbg:
file format elf64-littleriscv
Disassembly of section .text:
0000000000000800 <__vdso_rt_sigreturn>:
800: 08b00893 li a7,139
804: 00000073 ecall
808: 0000 unimp
...
000000000000080c <__vdso_getcpu>:
80c: 0a800893 li a7,168
810: 00000073 ecall
814: 8082 ret
...
0000000000000818 <__vdso_flush_icache>:
818: 10300893 li a7,259
81c: 00000073 ecall
820: 8082 ret
linux-rv32/arch/riscv/kernel/vdso/vdso.so.dbg:
file format elf32-littleriscv
Disassembly of section .text:
00000800 <__vdso_rt_sigreturn>:
800: 08b00893 li a7,139
804: 00000073 ecall
808: 0000 unimp
...
0000080c <__vdso_getcpu>:
80c: 0a800893 li a7,168
810: 00000073 ecall
814: 8082 ret
...
00000818 <__vdso_flush_icache>:
818: 10300893 li a7,259
81c: 00000073 ecall
820: 8082 ret
Finally, reuse all *.S from vdso in compat_vdso that makes
implementation clear and readable.
Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Guo Ren <guoren@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
---
arch/riscv/Makefile | 5 ++
arch/riscv/include/asm/vdso.h | 9 +++
arch/riscv/kernel/Makefile | 1 +
arch/riscv/kernel/compat_vdso/.gitignore | 2 +
arch/riscv/kernel/compat_vdso/Makefile | 68 +++++++++++++++++++
arch/riscv/kernel/compat_vdso/compat_vdso.S | 8 +++
.../kernel/compat_vdso/compat_vdso.lds.S | 3 +
arch/riscv/kernel/compat_vdso/flush_icache.S | 3 +
.../compat_vdso/gen_compat_vdso_offsets.sh | 5 ++
arch/riscv/kernel/compat_vdso/getcpu.S | 3 +
arch/riscv/kernel/compat_vdso/note.S | 3 +
arch/riscv/kernel/compat_vdso/rt_sigreturn.S | 3 +
arch/riscv/kernel/vdso/vdso.S | 6 +-
13 files changed, 118 insertions(+), 1 deletion(-)
create mode 100644 arch/riscv/kernel/compat_vdso/.gitignore
create mode 100644 arch/riscv/kernel/compat_vdso/Makefile
create mode 100644 arch/riscv/kernel/compat_vdso/compat_vdso.S
create mode 100644 arch/riscv/kernel/compat_vdso/compat_vdso.lds.S
create mode 100644 arch/riscv/kernel/compat_vdso/flush_icache.S
create mode 100755 arch/riscv/kernel/compat_vdso/gen_compat_vdso_offsets.sh
create mode 100644 arch/riscv/kernel/compat_vdso/getcpu.S
create mode 100644 arch/riscv/kernel/compat_vdso/note.S
create mode 100644 arch/riscv/kernel/compat_vdso/rt_sigreturn.S
diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
index a02e588c4947..f73d50552e09 100644
--- a/arch/riscv/Makefile
+++ b/arch/riscv/Makefile
@@ -106,12 +106,17 @@ libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
PHONY += vdso_install
vdso_install:
$(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso $@
+ $(if $(CONFIG_COMPAT),$(Q)$(MAKE) \
+ $(build)=arch/riscv/kernel/compat_vdso $@)
ifeq ($(KBUILD_EXTMOD),)
ifeq ($(CONFIG_MMU),y)
prepare: vdso_prepare
vdso_prepare: prepare0
$(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso include/generated/vdso-offsets.h
+ $(if $(CONFIG_COMPAT),$(Q)$(MAKE) \
+ $(build)=arch/riscv/kernel/compat_vdso include/generated/compat_vdso-offsets.h)
+
endif
endif
diff --git a/arch/riscv/include/asm/vdso.h b/arch/riscv/include/asm/vdso.h
index bc6f75f3a199..af981426fe0f 100644
--- a/arch/riscv/include/asm/vdso.h
+++ b/arch/riscv/include/asm/vdso.h
@@ -21,6 +21,15 @@
#define VDSO_SYMBOL(base, name) \
(void __user *)((unsigned long)(base) + __vdso_##name##_offset)
+
+#ifdef CONFIG_COMPAT
+#include <generated/compat_vdso-offsets.h>
+
+#define COMPAT_VDSO_SYMBOL(base, name) \
+ (void __user *)((unsigned long)(base) + compat__vdso_##name##_offset)
+
+#endif /* CONFIG_COMPAT */
+
#endif /* !__ASSEMBLY__ */
#endif /* CONFIG_MMU */
diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile
index 1f2111179615..59cf97faddae 100644
--- a/arch/riscv/kernel/Makefile
+++ b/arch/riscv/kernel/Makefile
@@ -66,3 +66,4 @@ obj-$(CONFIG_JUMP_LABEL) += jump_label.o
obj-$(CONFIG_EFI) += efi.o
obj-$(CONFIG_COMPAT) += compat_syscall_table.o
+obj-$(CONFIG_COMPAT) += compat_vdso/
diff --git a/arch/riscv/kernel/compat_vdso/.gitignore b/arch/riscv/kernel/compat_vdso/.gitignore
new file mode 100644
index 000000000000..19d83d846c1e
--- /dev/null
+++ b/arch/riscv/kernel/compat_vdso/.gitignore
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+compat_vdso.lds
diff --git a/arch/riscv/kernel/compat_vdso/Makefile b/arch/riscv/kernel/compat_vdso/Makefile
new file mode 100644
index 000000000000..7bbbbf94307f
--- /dev/null
+++ b/arch/riscv/kernel/compat_vdso/Makefile
@@ -0,0 +1,68 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before
+# the inclusion of generic Makefile.
+ARCH_REL_TYPE_ABS := R_RISCV_32|R_RISCV_64|R_RISCV_JUMP_SLOT
+include $(srctree)/lib/vdso/Makefile
+# Symbols present in the compat_vdso
+compat_vdso-syms = rt_sigreturn
+compat_vdso-syms += getcpu
+compat_vdso-syms += flush_icache
+
+# Files to link into the compat_vdso
+obj-compat_vdso = $(patsubst %, %.o, $(compat_vdso-syms)) note.o
+
+ccflags-y := -fno-stack-protector
+
+# Build rules
+targets := $(obj-compat_vdso) compat_vdso.so compat_vdso.so.dbg compat_vdso.lds
+obj-compat_vdso := $(addprefix $(obj)/, $(obj-compat_vdso))
+
+obj-y += compat_vdso.o
+CPPFLAGS_compat_vdso.lds += -P -C -U$(ARCH)
+
+# Disable profiling and instrumentation for VDSO code
+GCOV_PROFILE := n
+KCOV_INSTRUMENT := n
+KASAN_SANITIZE := n
+UBSAN_SANITIZE := n
+
+# Force dependency
+$(obj)/compat_vdso.o: $(obj)/compat_vdso.so
+
+# link rule for the .so file, .lds has to be first
+$(obj)/compat_vdso.so.dbg: $(obj)/compat_vdso.lds $(obj-compat_vdso) FORCE
+ $(call if_changed,compat_vdsold)
+LDFLAGS_compat_vdso.so.dbg = -shared -S -soname=linux-compat_vdso.so.1 \
+ --build-id=sha1 --hash-style=both --eh-frame-hdr
+
+# strip rule for the .so file
+$(obj)/%.so: OBJCOPYFLAGS := -S
+$(obj)/%.so: $(obj)/%.so.dbg FORCE
+ $(call if_changed,objcopy)
+
+# Generate VDSO offsets using helper script
+gen-compat_vdsosym := $(srctree)/$(src)/gen_compat_vdso_offsets.sh
+quiet_cmd_compat_vdsosym = VDSOSYM $@
+ cmd_compat_vdsosym = $(NM) $< | $(gen-compat_vdsosym) | LC_ALL=C sort > $@
+
+include/generated/compat_vdso-offsets.h: $(obj)/compat_vdso.so.dbg FORCE
+ $(call if_changed,compat_vdsosym)
+
+# actual build commands
+# The DSO images are built using a special linker script
+# Make sure only to export the intended __compat_vdso_xxx symbol offsets.
+quiet_cmd_compat_vdsold = VDSOLD $@
+ cmd_compat_vdsold = $(LD) $(ld_flags) -T $(filter-out FORCE,$^) -o $@.tmp && \
+ $(OBJCOPY) $(patsubst %, -G __compat_vdso_%, $(compat_vdso-syms)) $@.tmp $@ && \
+ rm $@.tmp
+
+# install commands for the unstripped file
+quiet_cmd_compat_vdso_install = INSTALL $@
+ cmd_compat_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/compat_vdso/$@
+
+compat_vdso.so: $(obj)/compat_vdso.so.dbg
+ @mkdir -p $(MODLIB)/compat_vdso
+ $(call cmd,compat_vdso_install)
+
+compat_vdso_install: compat_vdso.so
diff --git a/arch/riscv/kernel/compat_vdso/compat_vdso.S b/arch/riscv/kernel/compat_vdso/compat_vdso.S
new file mode 100644
index 000000000000..fea4a8b0c45d
--- /dev/null
+++ b/arch/riscv/kernel/compat_vdso/compat_vdso.S
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#define vdso_start compat_vdso_start
+#define vdso_end compat_vdso_end
+
+#define __VDSO_PATH "arch/riscv/kernel/compat_vdso/compat_vdso.so"
+
+#include <../vdso/vdso.S>
diff --git a/arch/riscv/kernel/compat_vdso/compat_vdso.lds.S b/arch/riscv/kernel/compat_vdso/compat_vdso.lds.S
new file mode 100644
index 000000000000..02a9ec5dc7f6
--- /dev/null
+++ b/arch/riscv/kernel/compat_vdso/compat_vdso.lds.S
@@ -0,0 +1,3 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <../vdso/vdso.lds.S>
diff --git a/arch/riscv/kernel/compat_vdso/flush_icache.S b/arch/riscv/kernel/compat_vdso/flush_icache.S
new file mode 100644
index 000000000000..88e21a84a974
--- /dev/null
+++ b/arch/riscv/kernel/compat_vdso/flush_icache.S
@@ -0,0 +1,3 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <../vdso/flush_icache.S>
diff --git a/arch/riscv/kernel/compat_vdso/gen_compat_vdso_offsets.sh b/arch/riscv/kernel/compat_vdso/gen_compat_vdso_offsets.sh
new file mode 100755
index 000000000000..8ac070c783b3
--- /dev/null
+++ b/arch/riscv/kernel/compat_vdso/gen_compat_vdso_offsets.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+
+LC_ALL=C
+sed -n -e 's/^[0]\+\(0[0-9a-fA-F]*\) . \(__vdso_[a-zA-Z0-9_]*\)$/\#define compat\2_offset\t0x\1/p'
diff --git a/arch/riscv/kernel/compat_vdso/getcpu.S b/arch/riscv/kernel/compat_vdso/getcpu.S
new file mode 100644
index 000000000000..946449a15a94
--- /dev/null
+++ b/arch/riscv/kernel/compat_vdso/getcpu.S
@@ -0,0 +1,3 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <../vdso/getcpu.S>
diff --git a/arch/riscv/kernel/compat_vdso/note.S b/arch/riscv/kernel/compat_vdso/note.S
new file mode 100644
index 000000000000..67c50898b8e5
--- /dev/null
+++ b/arch/riscv/kernel/compat_vdso/note.S
@@ -0,0 +1,3 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <../vdso/note.S>
diff --git a/arch/riscv/kernel/compat_vdso/rt_sigreturn.S b/arch/riscv/kernel/compat_vdso/rt_sigreturn.S
new file mode 100644
index 000000000000..f4c98f18c053
--- /dev/null
+++ b/arch/riscv/kernel/compat_vdso/rt_sigreturn.S
@@ -0,0 +1,3 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <../vdso/rt_sigreturn.S>
diff --git a/arch/riscv/kernel/vdso/vdso.S b/arch/riscv/kernel/vdso/vdso.S
index df222245be05..83f1c899e8d8 100644
--- a/arch/riscv/kernel/vdso/vdso.S
+++ b/arch/riscv/kernel/vdso/vdso.S
@@ -7,12 +7,16 @@
#include <linux/linkage.h>
#include <asm/page.h>
+#ifndef __VDSO_PATH
+#define __VDSO_PATH "arch/riscv/kernel/vdso/vdso.so"
+#endif
+
__PAGE_ALIGNED_DATA
.globl vdso_start, vdso_end
.balign PAGE_SIZE
vdso_start:
- .incbin "arch/riscv/kernel/vdso/vdso.so"
+ .incbin __VDSO_PATH
.balign PAGE_SIZE
vdso_end:
--
2.25.1
^ permalink raw reply related
* [PATCH V2 13/17] riscv: compat: vdso: Add setup additional pages implementation
From: guoren @ 2021-12-28 14:39 UTC (permalink / raw)
To: guoren, palmer, arnd, anup.patel, gregkh, liush, wefu, drew,
wangjunqiang, hch
Cc: linux-s390, Guo Ren, x86, linux-kernel, linux-csky, linux-mips,
sparclinux, linux-riscv, linuxppc-dev, inux-parisc,
linux-arm-kernel
In-Reply-To: <20211228143958.3409187-1-guoren@kernel.org>
From: Guo Ren <guoren@linux.alibaba.com>
Reconstruct __setup_additional_pages() by appending vdso info
pointer argument to meet compat_vdso_info requirement. And change
vm_special_mapping *dm, *cm initialization into static.
Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Guo Ren <guoren@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
---
arch/riscv/include/asm/elf.h | 5 ++
arch/riscv/include/asm/mmu.h | 1 +
arch/riscv/kernel/vdso.c | 104 +++++++++++++++++++++++++----------
3 files changed, 81 insertions(+), 29 deletions(-)
diff --git a/arch/riscv/include/asm/elf.h b/arch/riscv/include/asm/elf.h
index 91b372d4e13b..9d108cf84b99 100644
--- a/arch/riscv/include/asm/elf.h
+++ b/arch/riscv/include/asm/elf.h
@@ -136,5 +136,10 @@ do { if ((ex).e_ident[EI_CLASS] == ELFCLASS32) \
typedef compat_ulong_t compat_elf_greg_t;
typedef compat_elf_greg_t compat_elf_gregset_t[ELF_NGREG];
+extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
+ int uses_interp);
+#define compat_arch_setup_additional_pages \
+ compat_arch_setup_additional_pages
+
#endif /* CONFIG_COMPAT */
#endif /* _ASM_RISCV_ELF_H */
diff --git a/arch/riscv/include/asm/mmu.h b/arch/riscv/include/asm/mmu.h
index 0099dc116168..cedcf8ea3c76 100644
--- a/arch/riscv/include/asm/mmu.h
+++ b/arch/riscv/include/asm/mmu.h
@@ -16,6 +16,7 @@ typedef struct {
atomic_long_t id;
#endif
void *vdso;
+ void *vdso_info;
#ifdef CONFIG_SMP
/* A local icache flush is needed before user execution can resume. */
cpumask_t icache_stale_mask;
diff --git a/arch/riscv/kernel/vdso.c b/arch/riscv/kernel/vdso.c
index a9436a65161a..deca69524799 100644
--- a/arch/riscv/kernel/vdso.c
+++ b/arch/riscv/kernel/vdso.c
@@ -23,6 +23,9 @@ struct vdso_data {
#endif
extern char vdso_start[], vdso_end[];
+#ifdef CONFIG_COMPAT
+extern char compat_vdso_start[], compat_vdso_end[];
+#endif
enum vvar_pages {
VVAR_DATA_PAGE_OFFSET,
@@ -30,6 +33,11 @@ enum vvar_pages {
VVAR_NR_PAGES,
};
+enum rv_vdso_map {
+ RV_VDSO_MAP_VVAR,
+ RV_VDSO_MAP_VDSO,
+};
+
#define VVAR_SIZE (VVAR_NR_PAGES << PAGE_SHIFT)
/*
@@ -52,12 +60,6 @@ struct __vdso_info {
struct vm_special_mapping *cm;
};
-static struct __vdso_info vdso_info __ro_after_init = {
- .name = "vdso",
- .vdso_code_start = vdso_start,
- .vdso_code_end = vdso_end,
-};
-
static int vdso_mremap(const struct vm_special_mapping *sm,
struct vm_area_struct *new_vma)
{
@@ -66,35 +68,35 @@ static int vdso_mremap(const struct vm_special_mapping *sm,
return 0;
}
-static int __init __vdso_init(void)
+static int __init __vdso_init(struct __vdso_info *vdso_info)
{
unsigned int i;
struct page **vdso_pagelist;
unsigned long pfn;
- if (memcmp(vdso_info.vdso_code_start, "\177ELF", 4)) {
+ if (memcmp(vdso_info->vdso_code_start, "\177ELF", 4)) {
pr_err("vDSO is not a valid ELF object!\n");
return -EINVAL;
}
- vdso_info.vdso_pages = (
- vdso_info.vdso_code_end -
- vdso_info.vdso_code_start) >>
+ vdso_info->vdso_pages = (
+ vdso_info->vdso_code_end -
+ vdso_info->vdso_code_start) >>
PAGE_SHIFT;
- vdso_pagelist = kcalloc(vdso_info.vdso_pages,
+ vdso_pagelist = kcalloc(vdso_info->vdso_pages,
sizeof(struct page *),
GFP_KERNEL);
if (vdso_pagelist == NULL)
return -ENOMEM;
/* Grab the vDSO code pages. */
- pfn = sym_to_pfn(vdso_info.vdso_code_start);
+ pfn = sym_to_pfn(vdso_info->vdso_code_start);
- for (i = 0; i < vdso_info.vdso_pages; i++)
+ for (i = 0; i < vdso_info->vdso_pages; i++)
vdso_pagelist[i] = pfn_to_page(pfn + i);
- vdso_info.cm->pages = vdso_pagelist;
+ vdso_info->cm->pages = vdso_pagelist;
return 0;
}
@@ -116,13 +118,14 @@ int vdso_join_timens(struct task_struct *task, struct time_namespace *ns)
{
struct mm_struct *mm = task->mm;
struct vm_area_struct *vma;
+ struct __vdso_info *vdso_info = mm->context.vdso_info;
mmap_read_lock(mm);
for (vma = mm->mmap; vma; vma = vma->vm_next) {
unsigned long size = vma->vm_end - vma->vm_start;
- if (vma_is_special_mapping(vma, vdso_info.dm))
+ if (vma_is_special_mapping(vma, vdso_info->dm))
zap_page_range(vma, vma->vm_start, size);
}
@@ -187,11 +190,6 @@ static vm_fault_t vvar_fault(const struct vm_special_mapping *sm,
return vmf_insert_pfn(vma, vmf->address, pfn);
}
-enum rv_vdso_map {
- RV_VDSO_MAP_VVAR,
- RV_VDSO_MAP_VDSO,
-};
-
static struct vm_special_mapping rv_vdso_maps[] __ro_after_init = {
[RV_VDSO_MAP_VVAR] = {
.name = "[vvar]",
@@ -203,25 +201,53 @@ static struct vm_special_mapping rv_vdso_maps[] __ro_after_init = {
},
};
+static struct __vdso_info vdso_info __ro_after_init = {
+ .name = "vdso",
+ .vdso_code_start = vdso_start,
+ .vdso_code_end = vdso_end,
+ .dm = &rv_vdso_maps[RV_VDSO_MAP_VVAR],
+ .cm = &rv_vdso_maps[RV_VDSO_MAP_VDSO],
+};
+
+#ifdef CONFIG_COMPAT
+static struct __vdso_info compat_vdso_info __ro_after_init = {
+ .name = "compat_vdso",
+ .vdso_code_start = compat_vdso_start,
+ .vdso_code_end = compat_vdso_end,
+ .dm = &rv_vdso_maps[RV_VDSO_MAP_VVAR],
+ .cm = &rv_vdso_maps[RV_VDSO_MAP_VDSO],
+};
+#endif
+
static int __init vdso_init(void)
{
- vdso_info.dm = &rv_vdso_maps[RV_VDSO_MAP_VVAR];
- vdso_info.cm = &rv_vdso_maps[RV_VDSO_MAP_VDSO];
+ int ret;
+
+ ret = __vdso_init(&vdso_info);
+ if (ret)
+ goto out;
- return __vdso_init();
+#ifdef CONFIG_COMPAT
+ ret = __vdso_init(&compat_vdso_info);
+ if (ret)
+ goto out;
+#endif
+out:
+ return ret;
}
arch_initcall(vdso_init);
static int __setup_additional_pages(struct mm_struct *mm,
struct linux_binprm *bprm,
- int uses_interp)
+ int uses_interp,
+ struct __vdso_info *vdso_info)
{
unsigned long vdso_base, vdso_text_len, vdso_mapping_len;
void *ret;
BUILD_BUG_ON(VVAR_NR_PAGES != __VVAR_PAGES);
- vdso_text_len = vdso_info.vdso_pages << PAGE_SHIFT;
+ vdso_text_len = vdso_info->vdso_pages << PAGE_SHIFT;
/* Be sure to map the data page */
vdso_mapping_len = vdso_text_len + VVAR_SIZE;
@@ -232,16 +258,18 @@ static int __setup_additional_pages(struct mm_struct *mm,
}
ret = _install_special_mapping(mm, vdso_base, VVAR_SIZE,
- (VM_READ | VM_MAYREAD | VM_PFNMAP), vdso_info.dm);
+ (VM_READ | VM_MAYREAD | VM_PFNMAP), vdso_info->dm);
if (IS_ERR(ret))
goto up_fail;
vdso_base += VVAR_SIZE;
mm->context.vdso = (void *)vdso_base;
+ mm->context.vdso_info = (void *)vdso_info;
+
ret =
_install_special_mapping(mm, vdso_base, vdso_text_len,
(VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC),
- vdso_info.cm);
+ vdso_info->cm);
if (IS_ERR(ret))
goto up_fail;
@@ -253,6 +281,24 @@ static int __setup_additional_pages(struct mm_struct *mm,
return PTR_ERR(ret);
}
+#ifdef CONFIG_COMPAT
+int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
+ int uses_interp)
+{
+ struct mm_struct *mm = current->mm;
+ int ret;
+
+ if (mmap_write_lock_killable(mm))
+ return -EINTR;
+
+ ret = __setup_additional_pages(mm, bprm, uses_interp,
+ &compat_vdso_info);
+ mmap_write_unlock(mm);
+
+ return ret;
+}
+#endif
+
int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
{
struct mm_struct *mm = current->mm;
@@ -261,7 +307,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
if (mmap_write_lock_killable(mm))
return -EINTR;
- ret = __setup_additional_pages(mm, bprm, uses_interp);
+ ret = __setup_additional_pages(mm, bprm, uses_interp, &vdso_info);
mmap_write_unlock(mm);
return ret;
--
2.25.1
^ permalink raw reply related
* [PATCH V2 14/17] riscv: compat: signal: Add rt_frame implementation
From: guoren @ 2021-12-28 14:39 UTC (permalink / raw)
To: guoren, palmer, arnd, anup.patel, gregkh, liush, wefu, drew,
wangjunqiang, hch
Cc: linux-s390, Guo Ren, x86, linux-kernel, linux-csky, linux-mips,
sparclinux, linux-riscv, linuxppc-dev, inux-parisc,
linux-arm-kernel
In-Reply-To: <20211228143958.3409187-1-guoren@kernel.org>
From: Guo Ren <guoren@linux.alibaba.com>
Implement compat_setup_rt_frame for sigcontext save & restore. The
main process is the same with signal, but the rv32 pt_regs' size
is different from rv64's, so we needs convert them.
Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Guo Ren <guoren@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
---
arch/riscv/kernel/Makefile | 1 +
arch/riscv/kernel/compat_signal.c | 243 ++++++++++++++++++++++++++++++
arch/riscv/kernel/signal.c | 13 +-
3 files changed, 256 insertions(+), 1 deletion(-)
create mode 100644 arch/riscv/kernel/compat_signal.c
diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile
index 59cf97faddae..ef47f7d5843f 100644
--- a/arch/riscv/kernel/Makefile
+++ b/arch/riscv/kernel/Makefile
@@ -66,4 +66,5 @@ obj-$(CONFIG_JUMP_LABEL) += jump_label.o
obj-$(CONFIG_EFI) += efi.o
obj-$(CONFIG_COMPAT) += compat_syscall_table.o
+obj-$(CONFIG_COMPAT) += compat_signal.o
obj-$(CONFIG_COMPAT) += compat_vdso/
diff --git a/arch/riscv/kernel/compat_signal.c b/arch/riscv/kernel/compat_signal.c
new file mode 100644
index 000000000000..7041742ded08
--- /dev/null
+++ b/arch/riscv/kernel/compat_signal.c
@@ -0,0 +1,243 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <linux/compat.h>
+#include <linux/signal.h>
+#include <linux/uaccess.h>
+#include <linux/syscalls.h>
+#include <linux/tracehook.h>
+#include <linux/linkage.h>
+
+#include <asm/ucontext.h>
+#include <asm/vdso.h>
+#include <asm/switch_to.h>
+#include <asm/csr.h>
+
+#define COMPAT_DEBUG_SIG 0
+
+struct compat_sigcontext {
+ struct compat_user_regs_struct sc_regs;
+ union __riscv_fp_state sc_fpregs;
+};
+
+struct compat_ucontext {
+ compat_ulong_t uc_flags;
+ struct compat_ucontext *uc_link;
+ compat_stack_t uc_stack;
+ sigset_t uc_sigmask;
+ /* There's some padding here to allow sigset_t to be expanded in the
+ * future. Though this is unlikely, other architectures put uc_sigmask
+ * at the end of this structure and explicitly state it can be
+ * expanded, so we didn't want to box ourselves in here. */
+ __u8 __unused[1024 / 8 - sizeof(sigset_t)];
+ /* We can't put uc_sigmask at the end of this structure because we need
+ * to be able to expand sigcontext in the future. For example, the
+ * vector ISA extension will almost certainly add ISA state. We want
+ * to ensure all user-visible ISA state can be saved and restored via a
+ * ucontext, so we're putting this at the end in order to allow for
+ * infinite extensibility. Since we know this will be extended and we
+ * assume sigset_t won't be extended an extreme amount, we're
+ * prioritizing this. */
+ struct compat_sigcontext uc_mcontext;
+};
+
+struct compat_rt_sigframe {
+ struct compat_siginfo info;
+ struct compat_ucontext uc;
+};
+
+#ifdef CONFIG_FPU
+static long compat_restore_fp_state(struct pt_regs *regs,
+ union __riscv_fp_state __user *sc_fpregs)
+{
+ long err;
+ struct __riscv_d_ext_state __user *state = &sc_fpregs->d;
+ size_t i;
+
+ err = __copy_from_user(¤t->thread.fstate, state, sizeof(*state));
+ if (unlikely(err))
+ return err;
+
+ fstate_restore(current, regs);
+
+ /* We support no other extension state at this time. */
+ for (i = 0; i < ARRAY_SIZE(sc_fpregs->q.reserved); i++) {
+ u32 value;
+
+ err = __get_user(value, &sc_fpregs->q.reserved[i]);
+ if (unlikely(err))
+ break;
+ if (value != 0)
+ return -EINVAL;
+ }
+
+ return err;
+}
+
+static long compat_save_fp_state(struct pt_regs *regs,
+ union __riscv_fp_state __user *sc_fpregs)
+{
+ long err;
+ struct __riscv_d_ext_state __user *state = &sc_fpregs->d;
+ size_t i;
+
+ fstate_save(current, regs);
+ err = __copy_to_user(state, ¤t->thread.fstate, sizeof(*state));
+ if (unlikely(err))
+ return err;
+
+ /* We support no other extension state at this time. */
+ for (i = 0; i < ARRAY_SIZE(sc_fpregs->q.reserved); i++) {
+ err = __put_user(0, &sc_fpregs->q.reserved[i]);
+ if (unlikely(err))
+ break;
+ }
+
+ return err;
+}
+#else
+#define compat_save_fp_state(task, regs) (0)
+#define compat_restore_fp_state(task, regs) (0)
+#endif
+
+static long compat_restore_sigcontext(struct pt_regs *regs,
+ struct compat_sigcontext __user *sc)
+{
+ long err;
+ struct compat_user_regs_struct cregs;
+
+ /* sc_regs is structured the same as the start of pt_regs */
+ err = __copy_from_user(&cregs, &sc->sc_regs, sizeof(sc->sc_regs));
+
+ cregs_to_regs(&cregs, regs);
+
+ /* Restore the floating-point state. */
+ if (has_fpu())
+ err |= compat_restore_fp_state(regs, &sc->sc_fpregs);
+ return err;
+}
+
+COMPAT_SYSCALL_DEFINE0(rt_sigreturn)
+{
+ struct pt_regs *regs = current_pt_regs();
+ struct compat_rt_sigframe __user *frame;
+ struct task_struct *task;
+ sigset_t set;
+
+ /* Always make any pending restarted system calls return -EINTR */
+ current->restart_block.fn = do_no_restart_syscall;
+
+ frame = (struct compat_rt_sigframe __user *)regs->sp;
+
+ if (!access_ok(frame, sizeof(*frame)))
+ goto badframe;
+
+ if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
+ goto badframe;
+
+ set_current_blocked(&set);
+
+ if (compat_restore_sigcontext(regs, &frame->uc.uc_mcontext))
+ goto badframe;
+
+ if (compat_restore_altstack(&frame->uc.uc_stack))
+ goto badframe;
+
+ return regs->a0;
+
+badframe:
+ task = current;
+ if (show_unhandled_signals) {
+ pr_info_ratelimited(
+ "%s[%d]: bad frame in %s: frame=%p pc=%p sp=%p\n",
+ task->comm, task_pid_nr(task), __func__,
+ frame, (void *)regs->epc, (void *)regs->sp);
+ }
+ force_sig(SIGSEGV);
+ return 0;
+}
+
+static long compat_setup_sigcontext(struct compat_rt_sigframe __user *frame,
+ struct pt_regs *regs)
+{
+ struct compat_sigcontext __user *sc = &frame->uc.uc_mcontext;
+ struct compat_user_regs_struct cregs;
+ long err;
+
+ regs_to_cregs(&cregs, regs);
+
+ /* sc_regs is structured the same as the start of pt_regs */
+ err = __copy_to_user(&sc->sc_regs, &cregs, sizeof(sc->sc_regs));
+ /* Save the floating-point state. */
+ if (has_fpu())
+ err |= compat_save_fp_state(regs, &sc->sc_fpregs);
+ return err;
+}
+
+static inline void __user *compat_get_sigframe(struct ksignal *ksig,
+ struct pt_regs *regs, size_t framesize)
+{
+ unsigned long sp;
+ /* Default to using normal stack */
+ sp = regs->sp;
+
+ /*
+ * If we are on the alternate signal stack and would overflow it, don't.
+ * Return an always-bogus address instead so we will die with SIGSEGV.
+ */
+ if (on_sig_stack(sp) && !likely(on_sig_stack(sp - framesize)))
+ return (void __user __force *)(-1UL);
+
+ /* This is the X/Open sanctioned signal stack switching. */
+ sp = sigsp(sp, ksig) - framesize;
+
+ /* Align the stack frame. */
+ sp &= ~0xfUL;
+
+ return (void __user *)sp;
+}
+
+int compat_setup_rt_frame(struct ksignal *ksig, sigset_t *set,
+ struct pt_regs *regs)
+{
+ struct compat_rt_sigframe __user *frame;
+ long err = 0;
+
+ frame = compat_get_sigframe(ksig, regs, sizeof(*frame));
+ if (!access_ok(frame, sizeof(*frame)))
+ return -EFAULT;
+
+ err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
+
+ /* Create the ucontext. */
+ err |= __put_user(0, &frame->uc.uc_flags);
+ err |= __put_user(NULL, &frame->uc.uc_link);
+ err |= __compat_save_altstack(&frame->uc.uc_stack, regs->sp);
+ err |= compat_setup_sigcontext(frame, regs);
+ err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
+ if (err)
+ return -EFAULT;
+
+ regs->ra = (unsigned long)COMPAT_VDSO_SYMBOL(
+ current->mm->context.vdso, rt_sigreturn);
+
+ /*
+ * Set up registers for signal handler.
+ * Registers that we don't modify keep the value they had from
+ * user-space at the time we took the signal.
+ * We always pass siginfo and mcontext, regardless of SA_SIGINFO,
+ * since some things rely on this (e.g. glibc's debug/segfault.c).
+ */
+ regs->epc = (unsigned long)ksig->ka.sa.sa_handler;
+ regs->sp = (unsigned long)frame;
+ regs->a0 = ksig->sig; /* a0: signal number */
+ regs->a1 = (unsigned long)(&frame->info); /* a1: siginfo pointer */
+ regs->a2 = (unsigned long)(&frame->uc); /* a2: ucontext pointer */
+
+#if COMPAT_DEBUG_SIG
+ pr_info("SIG deliver (%s:%d): sig=%d pc=%p ra=%p sp=%p\n",
+ current->comm, task_pid_nr(current), ksig->sig,
+ (void *)regs->epc, (void *)regs->ra, frame);
+#endif
+
+ return 0;
+}
diff --git a/arch/riscv/kernel/signal.c b/arch/riscv/kernel/signal.c
index c2d5ecbe5526..27d8f39228c4 100644
--- a/arch/riscv/kernel/signal.c
+++ b/arch/riscv/kernel/signal.c
@@ -6,6 +6,7 @@
* Copyright (C) 2012 Regents of the University of California
*/
+#include <linux/compat.h>
#include <linux/signal.h>
#include <linux/uaccess.h>
#include <linux/syscalls.h>
@@ -229,6 +230,11 @@ static int setup_rt_frame(struct ksignal *ksig, sigset_t *set,
return 0;
}
+#ifdef CONFIG_COMPAT
+extern int compat_setup_rt_frame(struct ksignal *ksig, sigset_t *set,
+ struct pt_regs *regs);
+#endif
+
static void handle_signal(struct ksignal *ksig, struct pt_regs *regs)
{
sigset_t *oldset = sigmask_to_save();
@@ -258,8 +264,13 @@ static void handle_signal(struct ksignal *ksig, struct pt_regs *regs)
}
}
+#ifdef CONFIG_COMPAT
/* Set up the stack frame */
- ret = setup_rt_frame(ksig, oldset, regs);
+ if (is_compat_task())
+ ret = compat_setup_rt_frame(ksig, oldset, regs);
+ else
+#endif
+ ret = setup_rt_frame(ksig, oldset, regs);
signal_setup_done(ret, ksig, 0);
}
--
2.25.1
^ permalink raw reply related
* [PATCH V2 15/17] riscv: compat: ptrace: Add compat_arch_ptrace implement
From: guoren @ 2021-12-28 14:39 UTC (permalink / raw)
To: guoren, palmer, arnd, anup.patel, gregkh, liush, wefu, drew,
wangjunqiang, hch
Cc: linux-s390, Guo Ren, x86, linux-kernel, linux-csky, linux-mips,
sparclinux, linux-riscv, linuxppc-dev, inux-parisc,
linux-arm-kernel
In-Reply-To: <20211228143958.3409187-1-guoren@kernel.org>
From: Guo Ren <guoren@linux.alibaba.com>
Now, you can use native gdb on riscv64 for rv32 app debugging.
$ uname -a
Linux buildroot 5.16.0-rc4-00036-gbef6b82fdf23-dirty #53 SMP Mon Dec 20 23:06:53 CST 2021 riscv64 GNU/Linux
$ cat /proc/cpuinfo
processor : 0
hart : 0
isa : rv64imafdcsuh
mmu : sv48
$ file /bin/busybox
/bin/busybox: setuid ELF 32-bit LSB shared object, UCB RISC-V, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-riscv32-ilp32d.so.1, for GNU/Linux 5.15.0, stripped
$ file /usr/bin/gdb
/usr/bin/gdb: ELF 32-bit LSB shared object, UCB RISC-V, version 1 (GNU/Linux), dynamically linked, interpreter /lib/ld-linux-riscv32-ilp32d.so.1, for GNU/Linux 5.15.0, stripped
$ /usr/bin/gdb /bin/busybox
GNU gdb (GDB) 10.2
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
...
Reading symbols from /bin/busybox...
(No debugging symbols found in /bin/busybox)
(gdb) b main
Breakpoint 1 at 0x8ddc
(gdb) r
Starting program: /bin/busybox
Failed to read a valid object file image from memory.
Breakpoint 1, 0x555a8ddc in main ()
(gdb) i r
ra 0x77df0b74 0x77df0b74
sp 0x7fdd3d10 0x7fdd3d10
gp 0x5567e800 0x5567e800 <bb_common_bufsiz1+160>
tp 0x77f64280 0x77f64280
t0 0x0 0
t1 0x555a6fac 1431990188
t2 0x77dd8db4 2011008436
fp 0x7fdd3e34 0x7fdd3e34
s1 0x7fdd3e34 2145205812
a0 0xffffffff -1
a1 0x2000 8192
a2 0x7fdd3e3c 2145205820
a3 0x0 0
a4 0x7fdd3d30 2145205552
a5 0x555a8dc0 1431997888
a6 0x77f2c170 2012397936
a7 0x6a7c7a2f 1786542639
s2 0x0 0
s3 0x0 0
s4 0x555a8dc0 1431997888
s5 0x77f8a3a8 2012783528
s6 0x7fdd3e3c 2145205820
s7 0x5567cecc 1432866508
--Type <RET> for more, q to quit, c to continue without paging--
s8 0x1 1
s9 0x0 0
s10 0x55634448 1432568904
s11 0x0 0
t3 0x77df0bb8 2011106232
t4 0x42fc 17148
t5 0x0 0
t6 0x40 64
pc 0x555a8ddc 0x555a8ddc <main+28>
(gdb) si
0x555a78f0 in mallopt@plt ()
(gdb) c
Continuing.
BusyBox v1.34.1 (2021-12-19 22:39:48 CST) multi-call binary.
BusyBox is copyrighted by many authors between 1998-2015.
Licensed under GPLv2. See source distribution for detailed
copyright notices.
Usage: busybox [function [arguments]...]
or: busybox --list[-full]
...
[Inferior 1 (process 107) exited normally]
(gdb) q
Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Guo Ren <guoren@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
---
arch/riscv/kernel/ptrace.c | 87 +++++++++++++++++++++++++++++++++++---
1 file changed, 82 insertions(+), 5 deletions(-)
diff --git a/arch/riscv/kernel/ptrace.c b/arch/riscv/kernel/ptrace.c
index 9c0511119bad..76042ed861a3 100644
--- a/arch/riscv/kernel/ptrace.c
+++ b/arch/riscv/kernel/ptrace.c
@@ -12,6 +12,7 @@
#include <asm/thread_info.h>
#include <asm/switch_to.h>
#include <linux/audit.h>
+#include <linux/compat.h>
#include <linux/ptrace.h>
#include <linux/elf.h>
#include <linux/regset.h>
@@ -113,11 +114,6 @@ static const struct user_regset_view riscv_user_native_view = {
.n = ARRAY_SIZE(riscv_user_regset),
};
-const struct user_regset_view *task_user_regset_view(struct task_struct *task)
-{
- return &riscv_user_native_view;
-}
-
struct pt_regs_offset {
const char *name;
int offset;
@@ -275,3 +271,84 @@ __visible void do_syscall_trace_exit(struct pt_regs *regs)
trace_sys_exit(regs, regs_return_value(regs));
#endif
}
+
+#ifdef CONFIG_COMPAT
+static int compat_riscv_gpr_get(struct task_struct *target,
+ const struct user_regset *regset,
+ struct membuf to)
+{
+ struct compat_user_regs_struct cregs;
+
+ regs_to_cregs(&cregs, task_pt_regs(target));
+
+ return membuf_write(&to, &cregs,
+ sizeof(struct compat_user_regs_struct));
+}
+
+static int compat_riscv_gpr_set(struct task_struct *target,
+ const struct user_regset *regset,
+ unsigned int pos, unsigned int count,
+ const void *kbuf, const void __user *ubuf)
+{
+ int ret;
+ struct compat_user_regs_struct cregs;
+
+ ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &cregs, 0, -1);
+
+ cregs_to_regs(&cregs, task_pt_regs(target));
+
+ return ret;
+}
+
+static const struct user_regset compat_riscv_user_regset[] = {
+ [REGSET_X] = {
+ .core_note_type = NT_PRSTATUS,
+ .n = ELF_NGREG,
+ .size = sizeof(compat_elf_greg_t),
+ .align = sizeof(compat_elf_greg_t),
+ .regset_get = compat_riscv_gpr_get,
+ .set = compat_riscv_gpr_set,
+ },
+#ifdef CONFIG_FPU
+ [REGSET_F] = {
+ .core_note_type = NT_PRFPREG,
+ .n = ELF_NFPREG,
+ .size = sizeof(elf_fpreg_t),
+ .align = sizeof(elf_fpreg_t),
+ .regset_get = riscv_fpr_get,
+ .set = riscv_fpr_set,
+ },
+#endif
+};
+
+static const struct user_regset_view compat_riscv_user_native_view = {
+ .name = "riscv",
+ .e_machine = EM_RISCV,
+ .regsets = compat_riscv_user_regset,
+ .n = ARRAY_SIZE(compat_riscv_user_regset),
+};
+
+long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
+ compat_ulong_t caddr, compat_ulong_t cdata)
+{
+ long ret = -EIO;
+
+ switch (request) {
+ default:
+ ret = compat_ptrace_request(child, request, caddr, cdata);
+ break;
+ }
+
+ return ret;
+}
+#endif /* CONFIG_COMPAT */
+
+const struct user_regset_view *task_user_regset_view(struct task_struct *task)
+{
+#ifdef CONFIG_COMPAT
+ if (test_tsk_thread_flag(task, TIF_32BIT))
+ return &compat_riscv_user_native_view;
+ else
+#endif
+ return &riscv_user_native_view;
+}
--
2.25.1
^ permalink raw reply related
* [PATCH V2 16/17] riscv: compat: Add UXL_32 support in start_thread
From: guoren @ 2021-12-28 14:39 UTC (permalink / raw)
To: guoren, palmer, arnd, anup.patel, gregkh, liush, wefu, drew,
wangjunqiang, hch
Cc: linux-s390, Guo Ren, x86, linux-kernel, linux-csky, linux-mips,
sparclinux, linux-riscv, linuxppc-dev, inux-parisc,
linux-arm-kernel
In-Reply-To: <20211228143958.3409187-1-guoren@kernel.org>
From: Guo Ren <guoren@linux.alibaba.com>
If the current task is in COMPAT mode, set SR_UXL_32 in status for
returning userspace.
Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Guo Ren <guoren@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
---
arch/riscv/kernel/process.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/arch/riscv/kernel/process.c b/arch/riscv/kernel/process.c
index 03ac3aa611f5..1a666ad299b4 100644
--- a/arch/riscv/kernel/process.c
+++ b/arch/riscv/kernel/process.c
@@ -97,6 +97,11 @@ void start_thread(struct pt_regs *regs, unsigned long pc,
}
regs->epc = pc;
regs->sp = sp;
+
+#ifdef CONFIG_COMPAT
+ if (is_compat_task())
+ regs->status |= SR_UXL_32;
+#endif
}
void flush_thread(void)
--
2.25.1
^ permalink raw reply related
* [PATCH V2 17/17] riscv: compat: Add COMPAT Kbuild skeletal support
From: guoren @ 2021-12-28 14:39 UTC (permalink / raw)
To: guoren, palmer, arnd, anup.patel, gregkh, liush, wefu, drew,
wangjunqiang, hch
Cc: linux-s390, Guo Ren, x86, linux-kernel, linux-csky, linux-mips,
sparclinux, linux-riscv, linuxppc-dev, inux-parisc,
linux-arm-kernel
In-Reply-To: <20211228143958.3409187-1-guoren@kernel.org>
From: Guo Ren <guoren@linux.alibaba.com>
Adds initial skeletal COMPAT Kbuild (Runing 32bit U-mode on 64bit
S-mode) support.
- Setup kconfig & dummy functions for compiling.
- Implement compat_start_thread by the way.
Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Guo Ren <guoren@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
---
arch/riscv/Kconfig | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index 821252b65f89..08f1f3ba3d77 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -72,6 +72,7 @@ config RISCV
select HAVE_ARCH_KGDB if !XIP_KERNEL
select HAVE_ARCH_KGDB_QXFER_PKT
select HAVE_ARCH_MMAP_RND_BITS if MMU
+ select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT
select HAVE_ARCH_SECCOMP_FILTER
select HAVE_ARCH_TRACEHOOK
select HAVE_ARCH_TRANSPARENT_HUGEPAGE if 64BIT && MMU
@@ -122,12 +123,18 @@ config ARCH_MMAP_RND_BITS_MIN
default 18 if 64BIT
default 8
+config ARCH_MMAP_RND_COMPAT_BITS_MIN
+ default 8
+
# max bits determined by the following formula:
# VA_BITS - PAGE_SHIFT - 3
config ARCH_MMAP_RND_BITS_MAX
default 24 if 64BIT # SV39 based
default 17
+config ARCH_MMAP_RND_COMPAT_BITS_MAX
+ default 17
+
# set if we run in machine mode, cleared if we run in supervisor mode
config RISCV_M_MODE
bool
@@ -427,6 +434,18 @@ config CRASH_DUMP
For more details see Documentation/admin-guide/kdump/kdump.rst
+config COMPAT
+ bool "Kernel support for 32-bit U-mode"
+ default 64BIT
+ depends on 64BIT && MMU
+ help
+ This option enables support for a 32-bit U-mode running under a 64-bit
+ kernel at S-mode. riscv32-specific components such as system calls,
+ the user helper functions (vdso), signal rt_frame functions and the
+ ptrace interface are handled appropriately by the kernel.
+
+ If you want to execute 32-bit userspace applications, say Y.
+
endmenu
menu "Boot options"
--
2.25.1
^ permalink raw reply related
* [powerpc:next-test 44/179] arch/powerpc/platforms/85xx/smp.c:218:28: sparse: sparse: incorrect type in assignment (different address spaces)
From: kernel test robot @ 2021-12-28 15:10 UTC (permalink / raw)
To: Michael Ellerman; +Cc: linuxppc-dev, kbuild-all
Hi Michael,
First bad commit (maybe != root cause):
tree: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next-test
head: beeac538c366cd2828092adecd1edab28326c55b
commit: 84a61fb43fdfc528a3a7ff00e0b14ba91f5eb745 [44/179] powerpc/85xx: Make mpc85xx_smp_kexec_cpu_down() static
config: powerpc64-randconfig-s031-20211228 (https://download.01.org/0day-ci/archive/20211228/202112282327.YOTtEkGX-lkp@intel.com/config)
compiler: powerpc64-linux-gcc (GCC) 11.2.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# apt-get install sparse
# sparse version: v0.6.4-dirty
# https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git/commit/?id=84a61fb43fdfc528a3a7ff00e0b14ba91f5eb745
git remote add powerpc https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git
git fetch --no-tags powerpc next-test
git checkout 84a61fb43fdfc528a3a7ff00e0b14ba91f5eb745
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=powerpc SHELL=/bin/bash arch/powerpc/mm/nohash/ arch/powerpc/platforms/85xx/
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
sparse warnings: (new ones prefixed by >>)
>> arch/powerpc/platforms/85xx/smp.c:218:28: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct epapr_spin_table [noderef] __iomem *[assigned] spin_table @@ got void * @@
arch/powerpc/platforms/85xx/smp.c:218:28: sparse: expected struct epapr_spin_table [noderef] __iomem *[assigned] spin_table
arch/powerpc/platforms/85xx/smp.c:218:28: sparse: got void *
>> arch/powerpc/platforms/85xx/smp.c:227:36: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected void *spin_table @@ got struct epapr_spin_table [noderef] __iomem *[assigned] spin_table @@
arch/powerpc/platforms/85xx/smp.c:227:36: sparse: expected void *spin_table
arch/powerpc/platforms/85xx/smp.c:227:36: sparse: got struct epapr_spin_table [noderef] __iomem *[assigned] spin_table
arch/powerpc/platforms/85xx/smp.c:239:22: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected void *spin_table @@ got struct epapr_spin_table [noderef] __iomem *[assigned] spin_table @@
arch/powerpc/platforms/85xx/smp.c:239:22: sparse: expected void *spin_table
arch/powerpc/platforms/85xx/smp.c:239:22: sparse: got struct epapr_spin_table [noderef] __iomem *[assigned] spin_table
arch/powerpc/platforms/85xx/smp.c:239:22: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected void *spin_table @@ got struct epapr_spin_table [noderef] __iomem *[assigned] spin_table @@
arch/powerpc/platforms/85xx/smp.c:239:22: sparse: expected void *spin_table
arch/powerpc/platforms/85xx/smp.c:239:22: sparse: got struct epapr_spin_table [noderef] __iomem *[assigned] spin_table
arch/powerpc/platforms/85xx/smp.c:239:22: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected void *spin_table @@ got struct epapr_spin_table [noderef] __iomem *[assigned] spin_table @@
arch/powerpc/platforms/85xx/smp.c:239:22: sparse: expected void *spin_table
arch/powerpc/platforms/85xx/smp.c:239:22: sparse: got struct epapr_spin_table [noderef] __iomem *[assigned] spin_table
arch/powerpc/platforms/85xx/smp.c:239:22: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected void *spin_table @@ got struct epapr_spin_table [noderef] __iomem *[assigned] spin_table @@
arch/powerpc/platforms/85xx/smp.c:239:22: sparse: expected void *spin_table
arch/powerpc/platforms/85xx/smp.c:239:22: sparse: got struct epapr_spin_table [noderef] __iomem *[assigned] spin_table
arch/powerpc/platforms/85xx/smp.c:249:26: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected void *spin_table @@ got struct epapr_spin_table [noderef] __iomem *[assigned] spin_table @@
arch/powerpc/platforms/85xx/smp.c:249:26: sparse: expected void *spin_table
arch/powerpc/platforms/85xx/smp.c:249:26: sparse: got struct epapr_spin_table [noderef] __iomem *[assigned] spin_table
>> arch/powerpc/platforms/85xx/smp.c:252:19: sparse: sparse: cast removes address space '__iomem' of expression
>> arch/powerpc/platforms/85xx/smp.c:252:19: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected unsigned long long volatile [noderef] [usertype] __iomem *addr @@ got unsigned long long [usertype] * @@
arch/powerpc/platforms/85xx/smp.c:252:19: sparse: expected unsigned long long volatile [noderef] [usertype] __iomem *addr
arch/powerpc/platforms/85xx/smp.c:252:19: sparse: got unsigned long long [usertype] *
arch/powerpc/platforms/85xx/smp.c:266:26: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected void *spin_table @@ got struct epapr_spin_table [noderef] __iomem *[assigned] spin_table @@
arch/powerpc/platforms/85xx/smp.c:266:26: sparse: expected void *spin_table
arch/powerpc/platforms/85xx/smp.c:266:26: sparse: got struct epapr_spin_table [noderef] __iomem *[assigned] spin_table
>> arch/powerpc/platforms/85xx/smp.c:173:27: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected unsigned int const volatile [noderef] [usertype] __iomem *addr @@ got unsigned int * @@
arch/powerpc/platforms/85xx/smp.c:173:27: sparse: expected unsigned int const volatile [noderef] [usertype] __iomem *addr
arch/powerpc/platforms/85xx/smp.c:173:27: sparse: got unsigned int *
>> arch/powerpc/platforms/85xx/smp.c:173:27: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected unsigned int const volatile [noderef] [usertype] __iomem *addr @@ got unsigned int * @@
arch/powerpc/platforms/85xx/smp.c:173:27: sparse: expected unsigned int const volatile [noderef] [usertype] __iomem *addr
arch/powerpc/platforms/85xx/smp.c:173:27: sparse: got unsigned int *
>> arch/powerpc/platforms/85xx/smp.c:173:27: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected unsigned int const volatile [noderef] [usertype] __iomem *addr @@ got unsigned int * @@
arch/powerpc/platforms/85xx/smp.c:173:27: sparse: expected unsigned int const volatile [noderef] [usertype] __iomem *addr
arch/powerpc/platforms/85xx/smp.c:173:27: sparse: got unsigned int *
>> arch/powerpc/platforms/85xx/smp.c:173:27: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected unsigned int const volatile [noderef] [usertype] __iomem *addr @@ got unsigned int * @@
arch/powerpc/platforms/85xx/smp.c:173:27: sparse: expected unsigned int const volatile [noderef] [usertype] __iomem *addr
arch/powerpc/platforms/85xx/smp.c:173:27: sparse: got unsigned int *
vim +218 arch/powerpc/platforms/85xx/smp.c
bc15236fbed1e0 York Sun 2012-09-29 168
bc15236fbed1e0 York Sun 2012-09-29 169 static inline u32 read_spin_table_addr_l(void *spin_table)
bc15236fbed1e0 York Sun 2012-09-29 170 {
bc15236fbed1e0 York Sun 2012-09-29 171 flush_dcache_range((ulong)spin_table,
bc15236fbed1e0 York Sun 2012-09-29 172 (ulong)spin_table + sizeof(struct epapr_spin_table));
bc15236fbed1e0 York Sun 2012-09-29 @173 return in_be32(&((struct epapr_spin_table *)spin_table)->addr_l);
bc15236fbed1e0 York Sun 2012-09-29 174 }
bc15236fbed1e0 York Sun 2012-09-29 175
e16c8765533a15 Andy Fleming 2011-12-08 176 #ifdef CONFIG_PPC64
e16c8765533a15 Andy Fleming 2011-12-08 177 static void wake_hw_thread(void *info)
e16c8765533a15 Andy Fleming 2011-12-08 178 {
e16c8765533a15 Andy Fleming 2011-12-08 179 void fsl_secondary_thread_init(void);
6becef7ea04a69 chenhui zhao 2015-11-20 180 unsigned long inia;
6becef7ea04a69 chenhui zhao 2015-11-20 181 int cpu = *(const int *)info;
e16c8765533a15 Andy Fleming 2011-12-08 182
01c593d749f476 Scott Wood 2015-10-06 183 inia = *(unsigned long *)fsl_secondary_thread_init;
6becef7ea04a69 chenhui zhao 2015-11-20 184 book3e_start_thread(cpu_thread_in_core(cpu), inia);
e16c8765533a15 Andy Fleming 2011-12-08 185 }
e16c8765533a15 Andy Fleming 2011-12-08 186 #endif
e16c8765533a15 Andy Fleming 2011-12-08 187
2f4f1f815bc6d0 chenhui zhao 2015-11-20 188 static int smp_85xx_start_cpu(int cpu)
d5b26db2cfcf09 Kumar Gala 2008-11-19 189 {
2f4f1f815bc6d0 chenhui zhao 2015-11-20 190 int ret = 0;
d5b26db2cfcf09 Kumar Gala 2008-11-19 191 struct device_node *np;
2f4f1f815bc6d0 chenhui zhao 2015-11-20 192 const u64 *cpu_rel_addr;
2f4f1f815bc6d0 chenhui zhao 2015-11-20 193 unsigned long flags;
d1d47ec6e62ab0 Peter Tyser 2009-12-18 194 int ioremappable;
2f4f1f815bc6d0 chenhui zhao 2015-11-20 195 int hw_cpu = get_hard_smp_processor_id(cpu);
2f4f1f815bc6d0 chenhui zhao 2015-11-20 196 struct epapr_spin_table __iomem *spin_table;
e16c8765533a15 Andy Fleming 2011-12-08 197
2f4f1f815bc6d0 chenhui zhao 2015-11-20 198 np = of_get_cpu_node(cpu, NULL);
d5b26db2cfcf09 Kumar Gala 2008-11-19 199 cpu_rel_addr = of_get_property(np, "cpu-release-addr", NULL);
2f4f1f815bc6d0 chenhui zhao 2015-11-20 200 if (!cpu_rel_addr) {
2f4f1f815bc6d0 chenhui zhao 2015-11-20 201 pr_err("No cpu-release-addr for cpu %d\n", cpu);
de300974761d92 Michael Ellerman 2011-04-11 202 return -ENOENT;
d5b26db2cfcf09 Kumar Gala 2008-11-19 203 }
d5b26db2cfcf09 Kumar Gala 2008-11-19 204
d1d47ec6e62ab0 Peter Tyser 2009-12-18 205 /*
d1d47ec6e62ab0 Peter Tyser 2009-12-18 206 * A secondary core could be in a spinloop in the bootpage
d1d47ec6e62ab0 Peter Tyser 2009-12-18 207 * (0xfffff000), somewhere in highmem, or somewhere in lowmem.
d1d47ec6e62ab0 Peter Tyser 2009-12-18 208 * The bootpage and highmem can be accessed via ioremap(), but
d1d47ec6e62ab0 Peter Tyser 2009-12-18 209 * we need to directly access the spinloop if its in lowmem.
d1d47ec6e62ab0 Peter Tyser 2009-12-18 210 */
d1d47ec6e62ab0 Peter Tyser 2009-12-18 211 ioremappable = *cpu_rel_addr > virt_to_phys(high_memory);
d1d47ec6e62ab0 Peter Tyser 2009-12-18 212
d5b26db2cfcf09 Kumar Gala 2008-11-19 213 /* Map the spin table */
d1d47ec6e62ab0 Peter Tyser 2009-12-18 214 if (ioremappable)
aa91796ec46339 Christophe Leroy 2018-10-09 215 spin_table = ioremap_coherent(*cpu_rel_addr,
aa91796ec46339 Christophe Leroy 2018-10-09 216 sizeof(struct epapr_spin_table));
d1d47ec6e62ab0 Peter Tyser 2009-12-18 217 else
15f34eb12340b2 Zhao Chenhui 2012-07-20 @218 spin_table = phys_to_virt(*cpu_rel_addr);
d5b26db2cfcf09 Kumar Gala 2008-11-19 219
cb1ffb6204712b Kumar Gala 2009-06-19 220 local_irq_save(flags);
2f4f1f815bc6d0 chenhui zhao 2015-11-20 221 hard_irq_disable();
d0832a75075b11 Zhao Chenhui 2012-07-20 222
2f4f1f815bc6d0 chenhui zhao 2015-11-20 223 if (qoriq_pm_ops)
2f4f1f815bc6d0 chenhui zhao 2015-11-20 224 qoriq_pm_ops->cpu_up_prepare(cpu);
cb1ffb6204712b Kumar Gala 2009-06-19 225
2f4f1f815bc6d0 chenhui zhao 2015-11-20 226 /* if cpu is not spinning, reset it */
2f4f1f815bc6d0 chenhui zhao 2015-11-20 @227 if (read_spin_table_addr_l(spin_table) != 1) {
d0832a75075b11 Zhao Chenhui 2012-07-20 228 /*
d0832a75075b11 Zhao Chenhui 2012-07-20 229 * We don't set the BPTR register here since it already points
d0832a75075b11 Zhao Chenhui 2012-07-20 230 * to the boot page properly.
d0832a75075b11 Zhao Chenhui 2012-07-20 231 */
2f4f1f815bc6d0 chenhui zhao 2015-11-20 232 mpic_reset_core(cpu);
d0832a75075b11 Zhao Chenhui 2012-07-20 233
bc15236fbed1e0 York Sun 2012-09-29 234 /*
bc15236fbed1e0 York Sun 2012-09-29 235 * wait until core is ready...
bc15236fbed1e0 York Sun 2012-09-29 236 * We need to invalidate the stale data, in case the boot
bc15236fbed1e0 York Sun 2012-09-29 237 * loader uses a cache-inhibited spin table.
bc15236fbed1e0 York Sun 2012-09-29 238 */
bc15236fbed1e0 York Sun 2012-09-29 @239 if (!spin_event_timeout(
bc15236fbed1e0 York Sun 2012-09-29 240 read_spin_table_addr_l(spin_table) == 1,
d0832a75075b11 Zhao Chenhui 2012-07-20 241 10000, 100)) {
2f4f1f815bc6d0 chenhui zhao 2015-11-20 242 pr_err("timeout waiting for cpu %d to reset\n",
2f4f1f815bc6d0 chenhui zhao 2015-11-20 243 hw_cpu);
2f4f1f815bc6d0 chenhui zhao 2015-11-20 244 ret = -EAGAIN;
2f4f1f815bc6d0 chenhui zhao 2015-11-20 245 goto err;
d0832a75075b11 Zhao Chenhui 2012-07-20 246 }
d0832a75075b11 Zhao Chenhui 2012-07-20 247 }
decbb280bb8e3b Kumar Gala 2011-02-14 248
bc15236fbed1e0 York Sun 2012-09-29 @249 flush_spin_table(spin_table);
d0832a75075b11 Zhao Chenhui 2012-07-20 250 out_be32(&spin_table->pir, hw_cpu);
2f4f1f815bc6d0 chenhui zhao 2015-11-20 251 #ifdef CONFIG_PPC64
15f34eb12340b2 Zhao Chenhui 2012-07-20 @252 out_be64((u64 *)(&spin_table->addr_h),
2751b628c97e66 Anton Blanchard 2014-03-11 253 __pa(ppc_function_entry(generic_secondary_smp_init)));
2f4f1f815bc6d0 chenhui zhao 2015-11-20 254 #else
eeb09917c138cc Bai Yingjie 2020-01-06 255 #ifdef CONFIG_PHYS_ADDR_T_64BIT
eeb09917c138cc Bai Yingjie 2020-01-06 256 /*
eeb09917c138cc Bai Yingjie 2020-01-06 257 * We need also to write addr_h to spin table for systems
eeb09917c138cc Bai Yingjie 2020-01-06 258 * in which their physical memory start address was configured
eeb09917c138cc Bai Yingjie 2020-01-06 259 * to above 4G, otherwise the secondary core can not get
eeb09917c138cc Bai Yingjie 2020-01-06 260 * correct entry to start from.
eeb09917c138cc Bai Yingjie 2020-01-06 261 */
eeb09917c138cc Bai Yingjie 2020-01-06 262 out_be32(&spin_table->addr_h, __pa(__early_start) >> 32);
eeb09917c138cc Bai Yingjie 2020-01-06 263 #endif
2f4f1f815bc6d0 chenhui zhao 2015-11-20 264 out_be32(&spin_table->addr_l, __pa(__early_start));
5b8544c38e6fde Kumar Gala 2010-10-08 265 #endif
2f4f1f815bc6d0 chenhui zhao 2015-11-20 266 flush_spin_table(spin_table);
2f4f1f815bc6d0 chenhui zhao 2015-11-20 267 err:
d5b26db2cfcf09 Kumar Gala 2008-11-19 268 local_irq_restore(flags);
d5b26db2cfcf09 Kumar Gala 2008-11-19 269
d1d47ec6e62ab0 Peter Tyser 2009-12-18 270 if (ioremappable)
15f34eb12340b2 Zhao Chenhui 2012-07-20 271 iounmap(spin_table);
cb1ffb6204712b Kumar Gala 2009-06-19 272
d0832a75075b11 Zhao Chenhui 2012-07-20 273 return ret;
d5b26db2cfcf09 Kumar Gala 2008-11-19 274 }
d5b26db2cfcf09 Kumar Gala 2008-11-19 275
:::::: The code at line 218 was first introduced by commit
:::::: 15f34eb12340b2c2e0cd90c5987ad6b5f73b79b7 powerpc/85xx: Replace epapr spin table macros/defines with a struct
:::::: TO: Zhao Chenhui <chenhui.zhao@freescale.com>
:::::: CC: Kumar Gala <galak@kernel.crashing.org>
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
^ permalink raw reply
* Re: [PATCH v2 3/3] x86: Support huge vmalloc mappings
From: Dave Hansen @ 2021-12-28 16:14 UTC (permalink / raw)
To: Kefeng Wang, Jonathan Corbet, Andrew Morton, linuxppc-dev,
linux-doc, linux-kernel, linux-mm, x86, linux-arm-kernel
Cc: Matthew Wilcox, Catalin Marinas, Dave Hansen, Nicholas Piggin,
Ingo Molnar, Borislav Petkov, H. Peter Anvin, Paul Mackerras,
Thomas Gleixner, Will Deacon
In-Reply-To: <3858de1f-cdbc-ff52-2890-4254d0f48b0a@huawei.com>
On 12/28/21 2:26 AM, Kefeng Wang wrote:
>>> There are some disadvantages about this feature[2], one of the main
>>> concerns is the possible memory fragmentation/waste in some scenarios,
>>> also archs must ensure that any arch specific vmalloc allocations that
>>> require PAGE_SIZE mappings(eg, module alloc with STRICT_MODULE_RWX)
>>> use the VM_NO_HUGE_VMAP flag to inhibit larger mappings.
>> That just says that x86 *needs* PAGE_SIZE allocations. But, what
>> happens if VM_NO_HUGE_VMAP is not passed (like it was in v1)? Will the
>> subsequent permission changes just fragment the 2M mapping?
>
> Yes, without VM_NO_HUGE_VMAP, it could fragment the 2M mapping.
>
> When module alloc with STRICT_MODULE_RWX on x86, it calls
> __change_page_attr()
>
> from set_memory_ro/rw/nx which will split large page, so there is no
> need to make
>
> module alloc with HUGE_VMALLOC.
This all sounds very fragile to me. Every time a new architecture would
get added for huge vmalloc() support, the developer needs to know to go
find that architecture's module_alloc() and add this flag. They next
guy is going to forget, just like you did.
Considering that this is not a hot path, a weak function would be a nice
choice:
/* vmalloc() flags used for all module allocations. */
unsigned long __weak arch_module_vm_flags()
{
/*
* Modules use a single, large vmalloc(). Different
* permissions are applied later and will fragment
* huge mappings. Avoid using huge pages for modules.
*/
return VM_NO_HUGE_VMAP;
}
Stick that in some the common module code, next to:
> void * __weak module_alloc(unsigned long size)
> {
> return __vmalloc_node_range(size, 1, VMALLOC_START, VMALLOC_END,
...
Then, put arch_module_vm_flags() in *all* of the module_alloc()
implementations, including the generic one. That way (even with a new
architecture) whoever copies-and-pastes their module_alloc()
implementation is likely to get it right. The next guy who just does a
"select HAVE_ARCH_HUGE_VMALLOC" will hopefully just work.
VM_FLUSH_RESET_PERMS could probably be dealt with in the same way.
^ permalink raw reply
* [powerpc:next-test 46/179] arch/powerpc/mm/nohash/fsl_book3e.c:61:3: sparse: sparse: symbol 'tlbcam_addrs' was not declared. Should it be static?
From: kernel test robot @ 2021-12-28 16:53 UTC (permalink / raw)
To: Michael Ellerman; +Cc: linuxppc-dev, kbuild-all
tree: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next-test
head: beeac538c366cd2828092adecd1edab28326c55b
commit: ff47a95d1a67477e9bc2049a840d93b68508e079 [46/179] powerpc/mm: Move tlbcam_sz() and make it static
config: powerpc64-randconfig-s031-20211228 (https://download.01.org/0day-ci/archive/20211229/202112290015.xhdzgVU5-lkp@intel.com/config)
compiler: powerpc64-linux-gcc (GCC) 11.2.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# apt-get install sparse
# sparse version: v0.6.4-dirty
# https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git/commit/?id=ff47a95d1a67477e9bc2049a840d93b68508e079
git remote add powerpc https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git
git fetch --no-tags powerpc next-test
git checkout ff47a95d1a67477e9bc2049a840d93b68508e079
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=powerpc SHELL=/bin/bash arch/powerpc/mm/nohash/
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
sparse warnings: (new ones prefixed by >>)
>> arch/powerpc/mm/nohash/fsl_book3e.c:61:3: sparse: sparse: symbol 'tlbcam_addrs' was not declared. Should it be static?
vim +/tlbcam_addrs +61 arch/powerpc/mm/nohash/fsl_book3e.c
14cf11af6cf608 arch/powerpc/mm/fsl_booke_mmu.c Paul Mackerras 2005-09-26 53
78f622377f7d31 arch/powerpc/mm/fsl_booke_mmu.c Kumar Gala 2010-05-13 54 #define NUM_TLBCAMS (64)
78f622377f7d31 arch/powerpc/mm/fsl_booke_mmu.c Kumar Gala 2010-05-13 @55 struct tlbcam TLBCAM[NUM_TLBCAMS];
14cf11af6cf608 arch/powerpc/mm/fsl_booke_mmu.c Paul Mackerras 2005-09-26 56
14cf11af6cf608 arch/powerpc/mm/fsl_booke_mmu.c Paul Mackerras 2005-09-26 57 struct tlbcamrange {
14cf11af6cf608 arch/powerpc/mm/fsl_booke_mmu.c Paul Mackerras 2005-09-26 58 unsigned long start;
14cf11af6cf608 arch/powerpc/mm/fsl_booke_mmu.c Paul Mackerras 2005-09-26 59 unsigned long limit;
14cf11af6cf608 arch/powerpc/mm/fsl_booke_mmu.c Paul Mackerras 2005-09-26 60 phys_addr_t phys;
14cf11af6cf608 arch/powerpc/mm/fsl_booke_mmu.c Paul Mackerras 2005-09-26 @61 } tlbcam_addrs[NUM_TLBCAMS];
14cf11af6cf608 arch/powerpc/mm/fsl_booke_mmu.c Paul Mackerras 2005-09-26 62
:::::: The code at line 61 was first introduced by commit
:::::: 14cf11af6cf608eb8c23e989ddb17a715ddce109 powerpc: Merge enough to start building in arch/powerpc.
:::::: TO: Paul Mackerras <paulus@samba.org>
:::::: CC: Paul Mackerras <paulus@samba.org>
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
^ permalink raw reply
* Re: [PATCH V3 5/8] sched: s390: Remove unused TASK_SIZE_OF
From: Heiko Carstens @ 2021-12-28 17:00 UTC (permalink / raw)
To: guoren
Cc: juri.lelli, linux-s390, x86, arnd, peterz, linuxppc-dev, Guo Ren,
linux-kernel, inux-parisc, mingo, sparclinux, tglx, linux-mips,
will, linux-riscv, linux-arm-kernel
In-Reply-To: <20211228064730.2882351-6-guoren@kernel.org>
On Tue, Dec 28, 2021 at 02:47:26PM +0800, guoren@kernel.org wrote:
> From: Guo Ren <guoren@linux.alibaba.com>
>
> This macro isn't used in Linux sched, now. Delete in
> include/linux/sched.h and arch's include/asm.
>
> Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
> Signed-off-by: Guo Ren <guoren@kernel.org>
> Reviewed-by: Arnd Bergmann <arnd@arndb.de>
> ---
> arch/s390/include/asm/processor.h | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
Applied, thanks!
^ permalink raw reply
* Re: [GIT PULL] Please pull powerpc/linux.git powerpc-5.16-5 tag
From: pr-tracker-bot @ 2021-12-28 20:10 UTC (permalink / raw)
To: Michael Ellerman; +Cc: linuxppc-dev, Linus Torvalds, linux-kernel
In-Reply-To: <87v8z90y7t.fsf@mpe.ellerman.id.au>
The pull request you sent on Tue, 28 Dec 2021 22:23:50 +1100:
> https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git tags/powerpc-5.16-5
has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/f651faaaba5f41ffac195e64f58483721e60eafc
Thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/prtracker.html
^ permalink raw reply
* Re: [PATCH v2] powerpc/32s: Fix kasan_init_region() for KASAN
From: Michael Ellerman @ 2021-12-28 22:45 UTC (permalink / raw)
To: Christophe Leroy, Benjamin Herrenschmidt, Paul Mackerras
Cc: Maxime Bizon, stable@vger.kernel.org,
linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
In-Reply-To: <90826d123e3e28b840f284412b150a1e13ed62fb.1638799954.git.christophe.leroy@csgroup.eu>
Christophe Leroy <christophe.leroy@csgroup.eu> writes:
> It has been reported some configuration where the kernel doesn't
> boot with KASAN enabled.
>
> This is due to wrong BAT allocation for the KASAN area:
>
> ---[ Data Block Address Translation ]---
> 0: 0xc0000000-0xcfffffff 0x00000000 256M Kernel rw m
> 1: 0xd0000000-0xdfffffff 0x10000000 256M Kernel rw m
> 2: 0xe0000000-0xefffffff 0x20000000 256M Kernel rw m
> 3: 0xf8000000-0xf9ffffff 0x2a000000 32M Kernel rw m
> 4: 0xfa000000-0xfdffffff 0x2c000000 64M Kernel rw m
>
> A BAT must have both virtual and physical addresses alignment matching
> the size of the BAT. This is not the case for BAT 4 above.
>
> Fix kasan_init_region() by using block_size() function that is in
> book3s32/mmu.c. To be able to reuse it here, make it non static and
> change its name to bat_block_size() in order to avoid name conflict
> with block_size() defined in <linux/blkdev.h>
>
> Also reuse find_free_bat() to avoid an error message from setbat()
> when no BAT is available.
>
> And allocate memory outside of linear memory mapping to avoid
> wasting that precious space.
>
> With this change we get correct alignment for BATs and KASAN shadow
> memory is allocated outside the linear memory space.
>
> ---[ Data Block Address Translation ]---
> 0: 0xc0000000-0xcfffffff 0x00000000 256M Kernel rw
> 1: 0xd0000000-0xdfffffff 0x10000000 256M Kernel rw
> 2: 0xe0000000-0xefffffff 0x20000000 256M Kernel rw
> 3: 0xf8000000-0xfbffffff 0x7c000000 64M Kernel rw
> 4: 0xfc000000-0xfdffffff 0x7a000000 32M Kernel rw
>
> Reported-by: Maxime Bizon <mbizon@freebox.fr>
> Fixes: 7974c4732642 ("powerpc/32s: Implement dedicated kasan_init_region()")
> Cc: stable@vger.kernel.org
> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
> ---
> v2:
> - Allocate kasan shadow memory outside precious kernel linear memory
> - Properly zeroise kasan shadow memory
> ---
> arch/powerpc/include/asm/book3s/32/mmu-hash.h | 2 +
> arch/powerpc/mm/book3s32/mmu.c | 10 ++--
> arch/powerpc/mm/kasan/book3s_32.c | 58 ++++++++++---------
> 3 files changed, 38 insertions(+), 32 deletions(-)
Sorry this now conflicts with other changes in next. Can you rebase it please?
cheers
^ permalink raw reply
* Re: [PATCH] tpm: Fix kexec crash due to access to ops NULL pointer (powerpc)
From: Jarkko Sakkinen @ 2021-12-29 0:10 UTC (permalink / raw)
To: Stefan Berger
Cc: Korrapati.Likhitha, pavrampu, linux-kernel, jgg,
linux-security-module, gcwilson, peterhuewe, linuxppc-dev,
linux-integrity
In-Reply-To: <8b0c9683-d29b-38a2-8dfe-8f47db6544f2@linux.ibm.com>
On Tue, Dec 21, 2021 at 09:01:06AM -0500, Stefan Berger wrote:
>
> On 12/21/21 03:47, Jarkko Sakkinen wrote:
> > On Sat, Dec 11, 2021 at 08:28:04PM -0500, Stefan Berger wrote:
> > > Fix the following crash on kexec by checking chip->ops for a NULL pointer
> > > in tpm_chip_start() and returning an error code if this is the case.
> > >
> > > BUG: Kernel NULL pointer dereference on read at 0x00000060
> > > Faulting instruction address: 0xc00000000099a06c
> > > Oops: Kernel access of bad area, sig: 11 [#1]
> > > ...
> > > NIP [c00000000099a06c] tpm_chip_start+0x2c/0x140
> > > LR [c00000000099a808] tpm_chip_unregister+0x108/0x170
> > > Call Trace:
> > > [c0000000188bfa00] [c000000002b03930] fw_devlink_strict+0x0/0x8 (unreliable)
> > > [c0000000188bfa30] [c00000000099a808] tpm_chip_unregister+0x108/0x170
> > > [c0000000188bfa70] [c0000000009a3874] tpm_ibmvtpm_remove+0x34/0x130
> > > [c0000000188bfae0] [c000000000110dbc] vio_bus_remove+0x5c/0xb0
> > > [c0000000188bfb20] [c0000000009bc154] device_shutdown+0x1d4/0x3a8
> > > [c0000000188bfbc0] [c000000000196e14] kernel_restart_prepare+0x54/0x70
> > >
> > > The referenced patch below introduced a function to shut down the VIO bus.
> > > The bus shutdown now calls tpm_del_char_device (via tpm_chip_unregister)
> > > after a call to tpm_class_shutdown, which already set chip->ops to NULL.
> > > The crash occurrs when tpm_del_char_device calls tpm_chip_start with the
> > > chip->ops NULL pointer.
> > >
> > > Fixes: 39d0099f9439 ("powerpc/pseries: Add shutdown() to vio_driver and vio_bus")
> > > Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
> > > ---
> > > drivers/char/tpm/tpm-chip.c | 3 +++
> > > 1 file changed, 3 insertions(+)
> > >
> > > diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
> > > index ddaeceb7e109..cca1bde296ee 100644
> > > --- a/drivers/char/tpm/tpm-chip.c
> > > +++ b/drivers/char/tpm/tpm-chip.c
> > > @@ -101,6 +101,9 @@ int tpm_chip_start(struct tpm_chip *chip)
> > > {
> > > int ret;
> > > + if (!chip->ops)
> > > + return -EINVAL;
> > This triggers to all drivers, not just tpm_ibmvtpm, i.e. the fix has
> > side-effects.
>
> What are those side-effects?
It does change behaviour for all drivers, which is not acceptable for a
bug fix.
/Jarkko
^ permalink raw reply
* Re: [PATCH kernel v4] KVM: PPC: Merge powerpc's debugfs entry content into generic entry
From: kernel test robot @ 2021-12-29 9:39 UTC (permalink / raw)
To: Alexey Kardashevskiy, linuxppc-dev
Cc: kvm-ppc, kbuild-all, kvm, Fabiano Rosas, Alexey Kardashevskiy,
Nicholas Piggin, Cédric Le Goater, David Stevens
In-Reply-To: <20211220012351.2719879-1-aik@ozlabs.ru>
Hi Alexey,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on powerpc/topic/ppc-kvm]
[also build test ERROR on v5.16-rc7]
[cannot apply to next-20211224]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Alexey-Kardashevskiy/KVM-PPC-Merge-powerpc-s-debugfs-entry-content-into-generic-entry/20211220-092433
base: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git topic/ppc-kvm
config: powerpc64-randconfig-s031-20211228 (https://download.01.org/0day-ci/archive/20211229/202112291710.E7bImDlB-lkp@intel.com/config)
compiler: powerpc64-linux-gcc (GCC) 11.2.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# apt-get install sparse
# sparse version: v0.6.4-dirty
# https://github.com/0day-ci/linux/commit/3d3a1a5e82517f5f1a5dd3d7131afb3aa4312d82
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Alexey-Kardashevskiy/KVM-PPC-Merge-powerpc-s-debugfs-entry-content-into-generic-entry/20211220-092433
git checkout 3d3a1a5e82517f5f1a5dd3d7131afb3aa4312d82
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=powerpc SHELL=/bin/bash arch/powerpc/kvm/
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All errors (new ones prefixed by >>):
>> arch/powerpc/kvm/e500mc.c:384:32: error: initialization of 'int (*)(struct kvm_vcpu *, struct dentry *)' from incompatible pointer type 'void (*)(struct kvm_vcpu *, struct dentry *)' [-Werror=incompatible-pointer-types]
384 | .create_vcpu_debugfs = kvmppc_create_vcpu_debugfs_e500,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/powerpc/kvm/e500mc.c:384:32: note: (near initialization for 'kvm_ops_e500mc.create_vcpu_debugfs')
cc1: all warnings being treated as errors
vim +384 arch/powerpc/kvm/e500mc.c
369
370 static struct kvmppc_ops kvm_ops_e500mc = {
371 .get_sregs = kvmppc_core_get_sregs_e500mc,
372 .set_sregs = kvmppc_core_set_sregs_e500mc,
373 .get_one_reg = kvmppc_get_one_reg_e500mc,
374 .set_one_reg = kvmppc_set_one_reg_e500mc,
375 .vcpu_load = kvmppc_core_vcpu_load_e500mc,
376 .vcpu_put = kvmppc_core_vcpu_put_e500mc,
377 .vcpu_create = kvmppc_core_vcpu_create_e500mc,
378 .vcpu_free = kvmppc_core_vcpu_free_e500mc,
379 .init_vm = kvmppc_core_init_vm_e500mc,
380 .destroy_vm = kvmppc_core_destroy_vm_e500mc,
381 .emulate_op = kvmppc_core_emulate_op_e500,
382 .emulate_mtspr = kvmppc_core_emulate_mtspr_e500,
383 .emulate_mfspr = kvmppc_core_emulate_mfspr_e500,
> 384 .create_vcpu_debugfs = kvmppc_create_vcpu_debugfs_e500,
385 };
386
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
^ permalink raw reply
* Re: [PATCH v2 3/3] x86: Support huge vmalloc mappings
From: Kefeng Wang @ 2021-12-29 11:01 UTC (permalink / raw)
To: Dave Hansen, Jonathan Corbet, Andrew Morton, linuxppc-dev,
linux-doc, linux-kernel, linux-mm, x86, linux-arm-kernel
Cc: Matthew Wilcox, Catalin Marinas, Dave Hansen, Nicholas Piggin,
Ingo Molnar, Borislav Petkov, H. Peter Anvin, Paul Mackerras,
Thomas Gleixner, Will Deacon
In-Reply-To: <31a75f95-6e6e-b640-2d95-08a95ea8cf51@intel.com>
On 2021/12/29 0:14, Dave Hansen wrote:
> On 12/28/21 2:26 AM, Kefeng Wang wrote:
>>>> There are some disadvantages about this feature[2], one of the main
>>>> concerns is the possible memory fragmentation/waste in some scenarios,
>>>> also archs must ensure that any arch specific vmalloc allocations that
>>>> require PAGE_SIZE mappings(eg, module alloc with STRICT_MODULE_RWX)
>>>> use the VM_NO_HUGE_VMAP flag to inhibit larger mappings.
>>> That just says that x86 *needs* PAGE_SIZE allocations. But, what
>>> happens if VM_NO_HUGE_VMAP is not passed (like it was in v1)? Will the
>>> subsequent permission changes just fragment the 2M mapping?
>> Yes, without VM_NO_HUGE_VMAP, it could fragment the 2M mapping.
>>
>> When module alloc with STRICT_MODULE_RWX on x86, it calls
>> __change_page_attr()
>>
>> from set_memory_ro/rw/nx which will split large page, so there is no
>> need to make
>>
>> module alloc with HUGE_VMALLOC.
> This all sounds very fragile to me. Every time a new architecture would
> get added for huge vmalloc() support, the developer needs to know to go
> find that architecture's module_alloc() and add this flag. They next
> guy is going to forget, just like you did.
>
> Considering that this is not a hot path, a weak function would be a nice
> choice:
>
> /* vmalloc() flags used for all module allocations. */
> unsigned long __weak arch_module_vm_flags()
> {
> /*
> * Modules use a single, large vmalloc(). Different
> * permissions are applied later and will fragment
> * huge mappings. Avoid using huge pages for modules.
> */
> return VM_NO_HUGE_VMAP;
For x86, it only fragment, but for arm64, due to apply_to_page_range() in
set_memory_*, without this flag maybe crash. Whatever, we need this
flag for module.
> }
>
> Stick that in some the common module code, next to:
>
>> void * __weak module_alloc(unsigned long size)
>> {
>> return __vmalloc_node_range(size, 1, VMALLOC_START, VMALLOC_END,
> ...
>
> Then, put arch_module_vm_flags() in *all* of the module_alloc()
> implementations, including the generic one. That way (even with a new
> architecture) whoever copies-and-pastes their module_alloc()
> implementation is likely to get it right. The next guy who just does a
> "select HAVE_ARCH_HUGE_VMALLOC" will hopefully just work.
OK, Let me check the VM_FLUSH_RESET_PERMS and try about this way.
Thanks.
>
> VM_FLUSH_RESET_PERMS could probably be dealt with in the same way.
> .
^ permalink raw reply
* The PA6T is still vulnerable
From: Christian Zigotzky @ 2021-12-29 16:06 UTC (permalink / raw)
To: linuxppc-dev, Olof Johansson; +Cc: R.T.Dickinson, Matthew Leaman
Hi All,
The P.A. Semi PA6T is still vulnerable.
Architecture: ppc64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Big Endian
CPU(s): 2
On-line CPU(s) list: 0,1
Thread(s) per core: 1
Core(s) per socket: 2
Socket(s): 1
Model: 1.2 (pvr 0090 0102)
Model name: PA6T, altivec supported
L1d cache: 128 KiB
L1i cache: 128 KiB
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Vulnerable
Vulnerability Mds: Not affected
Vulnerability Meltdown: Vulnerable
Vulnerability Spec store bypass: Vulnerable
Vulnerability Spectre v1: Mitigation; __user pointer sanitization
Vulnerability Spectre v2: Vulnerable
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Not affected
Could you please check this issue?
Thanks,
Christian
^ permalink raw reply
* [PATCH] soc: fsl: qe: Check of ioremap return value
From: Jiasheng Jiang @ 2021-12-30 1:45 UTC (permalink / raw)
To: qiang.zhao, leoyang.li
Cc: Jiasheng Jiang, linuxppc-dev, linux-kernel, linux-arm-kernel
As the possible failure of the ioremap(), the par_io could be NULL.
Therefore it should be better to check it and return error in order to
guarantee the success of the initiation.
But, I also notice that all the caller like mpc85xx_qe_par_io_init() in
`arch/powerpc/platforms/85xx/common.c` don't check the return value of
the par_io_init().
Actually, par_io_init() needs to check to handle the potential error.
I will submit another patch to fix that.
Anyway, par_io_init() itsely should be fixed.
Fixes: 7aa1aa6ecec2 ("QE: Move QE from arch/powerpc to drivers/soc")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
drivers/soc/fsl/qe/qe_io.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/soc/fsl/qe/qe_io.c b/drivers/soc/fsl/qe/qe_io.c
index e277c827bdf3..a5e2d0e5ab51 100644
--- a/drivers/soc/fsl/qe/qe_io.c
+++ b/drivers/soc/fsl/qe/qe_io.c
@@ -35,6 +35,8 @@ int par_io_init(struct device_node *np)
if (ret)
return ret;
par_io = ioremap(res.start, resource_size(&res));
+ if (!par_io)
+ return -ENOMEM;
if (!of_property_read_u32(np, "num-ports", &num_ports))
num_par_io_ports = num_ports;
--
2.25.1
^ permalink raw reply related
* Re: [BISECTED] power8: watchdog: CPU 3 self-detected hard LOCKUP @ queued_spin_lock_slowpath+0x154/0x2d0
From: Stijn Tintel @ 2021-12-28 8:55 UTC (permalink / raw)
To: Nicholas Piggin, Benjamin Herrenschmidt, Christophe Leroy,
Davidlohr Bueso, linuxppc-dev, Michael Ellerman, Paul Mackerras
In-Reply-To: <1640427851.k47q6y3qjb.astroid@bobo.none>
[-- Attachment #1: Type: text/plain, Size: 17425 bytes --]
On 25/12/2021 12:31, Nicholas Piggin wrote:
> Excerpts from Stijn Tintel's message of December 22, 2021 11:20 am:
>> Hi,
>>
>> After upgrading my Power8 server from 5.10 LTS to 5.15 LTS, I started
>> experiencing CPU hard lockups, usually rather quickly after boot:
>>
>>
>> watchdog: CPU 3 self-detected hard LOCKUP @
>> queued_spin_lock_slowpath+0x154/0x2d0
>> watchdog: CPU 3 TB:265651929071, last heartbeat TB:259344820187 (12318ms
>> ago)
snip
>> Bisecting lead to the following commit:
>>
>> deb9b13eb2571fbde164ae012c77985fd14f2f02 is the first bad commit
>> commit deb9b13eb2571fbde164ae012c77985fd14f2f02
>> Author: Davidlohr Bueso<dave@stgolabs.net>
>> Date: Mon Mar 8 17:59:50 2021 -0800
>>
>> powerpc/qspinlock: Use generic smp_cond_load_relaxed
> Thanks for bisecting and reporting this.
Thanks for your response, much appreciated.
> As far as I can see, the code should be functionally identical,
> the difference is slightly in loop structure and priority nops
> but that shouldn't cause complete lock ups.
>
> I suspect possibly something is getting miscompiled. What distro
> do you use, what gcc version? And would you be able to send the
> output of objdump --disassemble=queued_spin_lock_slowpath vmlinux
> for your bad kernel?
>
Gentoo hardened musl, both gcc 10.3.0 and 11.2.0 exhibit the lockups.
/boot/disable/vmlinuz-5.12.0-rc3-ppc64le-00024-gdeb9b13eb257: file
format elf64-powerpcle
Disassembly of section .head.text:
Disassembly of section .text:
c00000000010d0d4 <queued_spin_lock_slowpath>:
c00000000010d0d4: e9 00 4c 3c addis r2,r12,233
c00000000010d0d8: 2c f3 42 38 addi r2,r2,-3284
c00000000010d0dc: 00 01 04 28 cmplwi r4,256
c00000000010d0e0: 2c 00 82 40 bne c00000000010d10c
<queued_spin_lock_slowpath+0x38>
c00000000010d0e4: 01 02 20 39 li r9,513
c00000000010d0e8: a6 03 29 7d mtctr r9
c00000000010d0ec: 02 00 83 e8 lwa r4,0(r3)
c00000000010d0f0: 00 01 04 2c cmpwi r4,256
c00000000010d0f4: 14 00 82 40 bne c00000000010d108
<queued_spin_lock_slowpath+0x34>
c00000000010d0f8: 10 00 40 42 bdz c00000000010d108
<queued_spin_lock_slowpath+0x34>
c00000000010d0fc: 78 0b 21 7c mr r1,r1
c00000000010d100: 78 13 42 7c mr r2,r2
c00000000010d104: e8 ff ff 4b b c00000000010d0ec
<queued_spin_lock_slowpath+0x18>
c00000000010d108: 20 00 84 78 clrldi r4,r4,32
c00000000010d10c: 2e 00 84 54 rlwinm r4,r4,0,0,23
c00000000010d110: 00 00 04 2c cmpwi r4,0
c00000000010d114: 38 00 82 40 bne c00000000010d14c
<queued_spin_lock_slowpath+0x78>
c00000000010d118: 00 01 40 39 li r10,256
c00000000010d11c: 28 18 20 7d lwarx r9,0,r3
c00000000010d120: 78 4b 48 7d or r8,r10,r9
c00000000010d124: 2d 19 00 7d stwcx. r8,0,r3
c00000000010d128: f4 ff c2 40 bne- c00000000010d11c
<queued_spin_lock_slowpath+0x48>
c00000000010d12c: 2c 01 00 4c isync
c00000000010d130: 2e 00 28 55 rlwinm r8,r9,0,0,23
c00000000010d134: 20 00 2a 79 clrldi r10,r9,32
c00000000010d138: 00 00 08 2c cmpwi r8,0
c00000000010d13c: e4 00 82 41 beq c00000000010d220
<queued_spin_lock_slowpath+0x14c>
c00000000010d140: 00 ff 29 71 andi. r9,r9,65280
c00000000010d144: 08 00 82 40 bne c00000000010d14c
<queued_spin_lock_slowpath+0x78>
c00000000010d148: 01 00 23 99 stb r9,1(r3)
c00000000010d14c: 28 00 2d e9 ld r9,40(r13)
c00000000010d150: cf ff 42 3d addis r10,r2,-49
c00000000010d154: 01 00 00 39 li r8,1
c00000000010d158: 80 15 4a 39 addi r10,r10,5504
c00000000010d15c: 78 53 46 7d mr r6,r10
c00000000010d160: 14 4a c6 7c add r6,r6,r9
c00000000010d164: 0e 00 26 e9 lwa r9,12(r6)
c00000000010d168: 01 00 e9 38 addi r7,r9,1
c00000000010d16c: 03 00 09 2c cmpwi r9,3
c00000000010d170: 0c 00 e6 90 stw r7,12(r6)
c00000000010d174: 00 00 ed a0 lhz r7,0(r13)
c00000000010d178: e4 00 81 41 bgt c00000000010d25c
<queued_spin_lock_slowpath+0x188>
c00000000010d17c: e4 26 20 79 rldicr r0,r9,4,59
c00000000010d180: 14 02 66 7d add r11,r6,r0
c00000000010d184: 00 00 00 39 li r8,0
c00000000010d188: 08 00 0b 91 stw r8,8(r11)
c00000000010d18c: 00 00 00 39 li r8,0
c00000000010d190: 2a 01 06 7d stdx r8,r6,r0
c00000000010d194: 00 00 03 81 lwz r8,0(r3)
c00000000010d198: b5 07 08 7d extsw. r8,r8
c00000000010d19c: 04 01 82 41 beq c00000000010d2a0
<queued_spin_lock_slowpath+0x1cc>
c00000000010d1a0: 01 00 e7 38 addi r7,r7,1
c00000000010d1a4: 1e 80 29 55 rlwinm r9,r9,16,0,15
c00000000010d1a8: f8 ff e1 fb std r31,-8(r1)
c00000000010d1ac: 1a 90 e7 54 rlwinm r7,r7,18,0,13
c00000000010d1b0: 78 3b 27 7d or r7,r9,r7
c00000000010d1b4: ac 04 20 7c lwsync
c00000000010d1b8: 00 00 80 38 li r4,0
c00000000010d1bc: 02 00 03 39 addi r8,r3,2
c00000000010d1c0: f8 1e 0c 55 rlwinm r12,r8,3,27,28
c00000000010d1c4: 3e 84 e5 54 rlwinm r5,r7,16,16,31
c00000000010d1c8: ff ff 84 60 ori r4,r4,65535
c00000000010d1cc: 64 07 08 79 rldicr r8,r8,0,61
c00000000010d1d0: 30 60 a5 7c slw r5,r5,r12
c00000000010d1d4: 30 60 84 7c slw r4,r4,r12
c00000000010d1d8: 28 40 20 7d lwarx r9,0,r8
c00000000010d1dc: 78 20 3f 7d andc r31,r9,r4
c00000000010d1e0: 78 2b ff 7f or r31,r31,r5
c00000000010d1e4: 2d 41 e0 7f stwcx. r31,0,r8
c00000000010d1e8: f0 ff c2 40 bne- c00000000010d1d8
<queued_spin_lock_slowpath+0x104>
c00000000010d1ec: 30 64 29 7d srw r9,r9,r12
c00000000010d1f0: 29 80 25 79 rldic. r5,r9,16,32
c00000000010d1f4: 1e 80 28 55 rlwinm r8,r9,16,0,15
c00000000010d1f8: d0 00 82 40 bne c00000000010d2c8
<queued_spin_lock_slowpath+0x1f4>
c00000000010d1fc: 00 00 20 39 li r9,0
c00000000010d200: 02 00 c3 e8 lwa r6,0(r3)
c00000000010d204: 00 00 03 81 lwz r8,0(r3)
c00000000010d208: 3e 04 05 55 clrlwi r5,r8,16
c00000000010d20c: 00 00 05 2c cmpwi r5,0
c00000000010d210: 10 01 82 41 beq c00000000010d320
<queued_spin_lock_slowpath+0x24c>
c00000000010d214: 78 0b 21 7c mr r1,r1
c00000000010d218: 78 13 42 7c mr r2,r2
c00000000010d21c: e4 ff ff 4b b c00000000010d200
<queued_spin_lock_slowpath+0x12c>
c00000000010d220: 00 00 2a 2c cmpdi r10,0
c00000000010d224: 24 00 82 41 beq c00000000010d248
<queued_spin_lock_slowpath+0x174>
c00000000010d228: 02 00 23 e9 lwa r9,0(r3)
c00000000010d22c: 3e 06 29 55 clrlwi r9,r9,24
c00000000010d230: 00 00 09 2c cmpwi r9,0
c00000000010d234: 10 00 82 41 beq c00000000010d244
<queued_spin_lock_slowpath+0x170>
c00000000010d238: 78 0b 21 7c mr r1,r1
c00000000010d23c: 78 13 42 7c mr r2,r2
c00000000010d240: e8 ff ff 4b b c00000000010d228
<queued_spin_lock_slowpath+0x154>
c00000000010d244: ac 04 20 7c lwsync
c00000000010d248: 01 00 20 39 li r9,1
c00000000010d24c: 00 00 23 b1 sth r9,0(r3)
c00000000010d250: 20 00 80 4e blr
c00000000010d254: 78 0b 21 7c mr r1,r1
c00000000010d258: 78 13 42 7c mr r2,r2
c00000000010d25c: 00 00 23 81 lwz r9,0(r3)
c00000000010d260: b5 07 29 7d extsw. r9,r9
c00000000010d264: f0 ff 82 40 bne c00000000010d254
<queued_spin_lock_slowpath+0x180>
c00000000010d268: 28 18 e0 7c lwarx r7,0,r3
c00000000010d26c: 00 48 07 7c cmpw r7,r9
c00000000010d270: 10 00 c2 40 bne- c00000000010d280
<queued_spin_lock_slowpath+0x1ac>
c00000000010d274: 2d 19 00 7d stwcx. r8,0,r3
c00000000010d278: f0 ff c2 40 bne- c00000000010d268
<queued_spin_lock_slowpath+0x194>
c00000000010d27c: 2c 01 00 4c isync
c00000000010d280: 00 00 07 2c cmpwi r7,0
c00000000010d284: d0 ff 82 40 bne c00000000010d254
<queued_spin_lock_slowpath+0x180>
c00000000010d288: 28 00 0d e9 ld r8,40(r13)
c00000000010d28c: 0c 00 2a 39 addi r9,r10,12
c00000000010d290: 2e 40 49 7d lwzx r10,r9,r8
c00000000010d294: ff ff 4a 39 addi r10,r10,-1
c00000000010d298: 2e 41 49 7d stwx r10,r9,r8
c00000000010d29c: 20 00 80 4e blr
c00000000010d2a0: 01 00 a0 38 li r5,1
c00000000010d2a4: 28 18 80 7c lwarx r4,0,r3
c00000000010d2a8: 00 40 04 7c cmpw r4,r8
c00000000010d2ac: 10 00 c2 40 bne- c00000000010d2bc
<queued_spin_lock_slowpath+0x1e8>
c00000000010d2b0: 2d 19 a0 7c stwcx. r5,0,r3
c00000000010d2b4: f0 ff c2 40 bne- c00000000010d2a4
<queued_spin_lock_slowpath+0x1d0>
c00000000010d2b8: 2c 01 00 4c isync
c00000000010d2bc: 00 00 04 2c cmpwi r4,0
c00000000010d2c0: c8 ff 82 41 beq c00000000010d288
<queued_spin_lock_slowpath+0x1b4>
c00000000010d2c4: dc fe ff 4b b c00000000010d1a0
<queued_spin_lock_slowpath+0xcc>
c00000000010d2c8: be 74 08 55 rlwinm r8,r8,14,18,31
c00000000010d2cc: 04 00 a2 3c addis r5,r2,4
c00000000010d2d0: f0 cf a5 38 addi r5,r5,-12304
c00000000010d2d4: a8 26 29 79 rldic r9,r9,4,58
c00000000010d2d8: ff ff 08 39 addi r8,r8,-1
c00000000010d2dc: 14 4a 2a 7d add r9,r10,r9
c00000000010d2e0: b4 07 08 7d extsw r8,r8
c00000000010d2e4: 24 1f 08 79 rldicr r8,r8,3,60
c00000000010d2e8: 2a 40 05 7d ldx r8,r5,r8
c00000000010d2ec: 2a 41 69 7d stdx r11,r9,r8
c00000000010d2f0: 0a 00 2b e9 lwa r9,8(r11)
c00000000010d2f4: 00 00 29 2c cmpdi r9,0
c00000000010d2f8: 10 00 82 40 bne c00000000010d308
<queued_spin_lock_slowpath+0x234>
c00000000010d2fc: 78 0b 21 7c mr r1,r1
c00000000010d300: 78 13 42 7c mr r2,r2
c00000000010d304: ec ff ff 4b b c00000000010d2f0
<queued_spin_lock_slowpath+0x21c>
c00000000010d308: ac 04 20 7c lwsync
c00000000010d30c: 2a 00 26 7d ldx r9,r6,r0
c00000000010d310: 00 00 29 2c cmpdi r9,0
c00000000010d314: ec fe 82 41 beq c00000000010d200
<queued_spin_lock_slowpath+0x12c>
c00000000010d318: ec 49 00 7c dcbtstct 0,r9
c00000000010d31c: e4 fe ff 4b b c00000000010d200
<queued_spin_lock_slowpath+0x12c>
c00000000010d320: ac 04 20 7c lwsync
c00000000010d324: 1e 00 08 55 rlwinm r8,r8,0,0,15
c00000000010d328: 00 38 08 7c cmpw r8,r7
c00000000010d32c: 2c 00 82 41 beq c00000000010d358
<queued_spin_lock_slowpath+0x284>
c00000000010d330: 00 00 29 2c cmpdi r9,0
c00000000010d334: 01 00 00 39 li r8,1
c00000000010d338: 00 00 03 99 stb r8,0(r3)
c00000000010d33c: 58 00 82 40 bne c00000000010d394
<queued_spin_lock_slowpath+0x2c0>
c00000000010d340: 00 00 2b e9 ld r9,0(r11)
c00000000010d344: 00 00 29 2c cmpdi r9,0
c00000000010d348: 4c 00 82 40 bne c00000000010d394
<queued_spin_lock_slowpath+0x2c0>
c00000000010d34c: 78 0b 21 7c mr r1,r1
c00000000010d350: 78 13 42 7c mr r2,r2
c00000000010d354: ec ff ff 4b b c00000000010d340
<queued_spin_lock_slowpath+0x26c>
c00000000010d358: 01 00 00 39 li r8,1
c00000000010d35c: 28 18 e0 7c lwarx r7,0,r3
c00000000010d360: 00 30 07 7c cmpw r7,r6
c00000000010d364: 0c 00 c2 40 bne- c00000000010d370
<queued_spin_lock_slowpath+0x29c>
c00000000010d368: 2d 19 00 7d stwcx. r8,0,r3
c00000000010d36c: f0 ff c2 40 bne- c00000000010d35c
<queued_spin_lock_slowpath+0x288>
c00000000010d370: 00 38 06 7c cmpw r6,r7
c00000000010d374: bc ff 82 40 bne c00000000010d330
<queued_spin_lock_slowpath+0x25c>
c00000000010d378: 28 00 0d e9 ld r8,40(r13)
c00000000010d37c: 0c 00 2a 39 addi r9,r10,12
c00000000010d380: 2e 40 49 7d lwzx r10,r9,r8
c00000000010d384: ff ff 4a 39 addi r10,r10,-1
c00000000010d388: 2e 41 49 7d stwx r10,r9,r8
c00000000010d38c: f8 ff e1 eb ld r31,-8(r1)
c00000000010d390: 20 00 80 4e blr
c00000000010d394: ac 04 20 7c lwsync
c00000000010d398: 01 00 00 39 li r8,1
c00000000010d39c: 08 00 09 91 stw r8,8(r9)
c00000000010d3a0: d8 ff ff 4b b c00000000010d378
<queued_spin_lock_slowpath+0x2a4>
Disassembly of section .init.text:
Disassembly of section .exit.text:
>
>>
>>
>> The problem persists in 2f47a9a4dfa3674fad19a49b40c5103a9a8e1589 and
>> goes away if I revert deb9b13eb2571fbde164ae012c77985fd14f2f02 on top of
>> that. As deb9b13eb2571fbde164ae012c77985fd14f2f02 seems to be a revert
>> of 49a7d46a06c30c7beabbf9d1a8ea1de0f9e4fdfe, I suspect this problem
>> might have existed before 49a7d46a06c30c7beabbf9d1a8ea1de0f9e4fdfe. I
>> therefore tried to build 49a7d46a06c30c7beabbf9d1a8ea1de0f9e4fdfe and
>> 49a7d46a06c30c7beabbf9d1a8ea1de0f9e4fdfe^1 to verify if the problem
>> exists there as well, unfortunately these commits don't build due to the
>> following compile error:
>>
>> kernel/smp.c:In function 'smp_init':
>> ./include/linux/compiler.h:392:38:error: call to
>> '__compiletime_assert_150' declared with attribute error: BUILD_BUG_ON
>> failed: offsetof(struct task_struct, wake_entry_type) - offsetof(struct
>> task_struct, wake_entry) != offsetof(struct __call_single_data, flags) -
>> offsetof(struct __call_single_data, llist)
>> 392 | _compiletime_assert(condition, msg, __compiletime_assert_,
>> __COUNTER__)
>> | ^
>>
Switching from gcc 10.3.0 to gcc 11.2.0 made the above compile error go
away, and as expected, 49a7d46a06c30c7beabbf9d1a8ea1de0f9e4fdfe boots
fine and 49a7d46a06c30c7beabbf9d1a8ea1de0f9e4fdfe^1 exhibits the same
problem. I started bisecting the 2nd part but I'll pause that effort for
now.
Thanks,
Stijn
[-- Attachment #2: Type: text/html, Size: 23380 bytes --]
^ permalink raw reply
* Re: [RFC 02/32] Kconfig: introduce HAS_IOPORT option and select it as necessary
From: Geert Uytterhoeven @ 2021-12-28 10:08 UTC (permalink / raw)
To: Niklas Schnelle
Cc: Rich Felker, linux-sh, Catalin Marinas, Dave Hansen, linux-pci,
linux-mips, James E.J. Bottomley, sparclinux, Guo Ren,
H. Peter Anvin, Borislav Petkov, linux-ia64, linux-riscv,
Vincent Chen, Will Deacon, Greg Ungerer, Karol Gugala, linux-arch,
linux-s390, Yoshinori Sato, Helge Deller, x86, Russell King,
linux-csky, Ingo Molnar, linux-parisc, Vineet Gupta, Matt Turner,
linux-snps-arc, Heiko Carstens, linux-xtensa, Albert Ou,
Chris Zankel, Jeff Dike, John Garry, linux-m68k, openrisc,
Ivan Kokshaysky, Greentime Hu, Paul Walmsley, Bjorn Helgaas,
Thomas Gleixner, linux-arm-kernel, Richard Henderson,
Michael Schmitz, Arnd Bergmann, Michal Simek, Thomas Bogendoerfer,
Brian Cain, Nick Hu, linux-kernel, Dinh Nguyen, Palmer Dabbelt,
linux-alpha, Paul Mackerras, linuxppc-dev, David S. Miller
In-Reply-To: <20211227164317.4146918-3-schnelle@linux.ibm.com>
Hi Niklas,
On Mon, Dec 27, 2021 at 5:44 PM Niklas Schnelle <schnelle@linux.ibm.com> wrote:
> We introduce a new HAS_IOPORT Kconfig option to gate support for
> I/O port access. In a future patch HAS_IOPORT=n will disable compilation
> of the I/O accessor functions inb()/outb() and friends on architectures
> which can not meaningfully support legacy I/O spaces. On these platforms
> inb()/outb() etc are currently just stubs in asm-generic/io.h which when
> called will cause a NULL pointer access which some compilers actually
> detect and warn about.
>
> The dependencies on HAS_IOPORT in drivers as well as ifdefs for
> HAS_IOPORT specific sections will be added in subsequent patches on
> a per subsystem basis. Then a final patch will ifdef the I/O access
> functions on HAS_IOPORT thus turning any use not gated by HAS_IOPORT
> into a compile-time warning.
>
> Link: https://lore.kernel.org/lkml/CAHk-=wg80je=K7madF4e7WrRNp37e3qh6y10Svhdc7O8SZ_-8g@mail.gmail.com/
> Co-developed-by: Arnd Bergmann <arnd@kernel.org>
> Signed-off-by: Arnd Bergmann <arnd@kernel.org>
> Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
Thanks for your patch!
> --- a/arch/m68k/Kconfig
> +++ b/arch/m68k/Kconfig
> @@ -16,6 +16,7 @@ config M68K
> select GENERIC_CPU_DEVICES
> select GENERIC_IOMAP
> select GENERIC_IRQ_SHOW
> + select HAS_IOPORT
> select HAVE_AOUT if MMU
> select HAVE_ASM_MODVERSIONS
> select HAVE_DEBUG_BUGVERBOSE
This looks way too broad to me: most m68k platform do not have I/O
port access support.
My gut feeling says:
select HAS_IOPORT if PCI || ISA
but that might miss some intricate details...
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply
* Re: [RFC 02/32] Kconfig: introduce HAS_IOPORT option and select it as necessary
From: Mauro Carvalho Chehab @ 2021-12-28 16:32 UTC (permalink / raw)
To: Niklas Schnelle
Cc: Rich Felker, linux-sh, Catalin Marinas, Dave Hansen, linux-pci,
linux-mips, James E.J. Bottomley, sparclinux, Guo Ren,
H. Peter Anvin, Borislav Petkov, linux-ia64, linux-riscv,
Vincent Chen, Will Deacon, Karol Gugala, linux-arch, linux-s390,
Yoshinori Sato, Helge Deller, x86, Russell King, linux-csky,
Ingo Molnar, Geert Uytterhoeven, linux-parisc, Vineet Gupta,
Matt Turner, linux-snps-arc, Heiko Carstens, linux-xtensa,
Albert Ou, Chris Zankel, Jeff Dike, John Garry, linux-m68k,
openrisc, Ivan Kokshaysky, Greentime Hu, Paul Walmsley,
Bjorn Helgaas, Thomas Gleixner, linux-arm-kernel,
Richard Henderson, Arnd Bergmann, Michal Simek,
Thomas Bogendoerfer, Brian Cain, Nick Hu, linux-kernel,
Dinh Nguyen, Palmer Dabbelt, linux-alpha, Paul Mackerras,
linuxppc-dev, David S. Miller
In-Reply-To: <20211227164317.4146918-3-schnelle@linux.ibm.com>
Em Mon, 27 Dec 2021 17:42:47 +0100
Niklas Schnelle <schnelle@linux.ibm.com> escreveu:
> We introduce a new HAS_IOPORT Kconfig option to gate support for
> I/O port access. In a future patch HAS_IOPORT=n will disable compilation
> of the I/O accessor functions inb()/outb() and friends on architectures
> which can not meaningfully support legacy I/O spaces. On these platforms
> inb()/outb() etc are currently just stubs in asm-generic/io.h which when
> called will cause a NULL pointer access which some compilers actually
> detect and warn about.
>
> The dependencies on HAS_IOPORT in drivers as well as ifdefs for
> HAS_IOPORT specific sections will be added in subsequent patches on
> a per subsystem basis. Then a final patch will ifdef the I/O access
> functions on HAS_IOPORT thus turning any use not gated by HAS_IOPORT
> into a compile-time warning.
>
> Link: https://lore.kernel.org/lkml/CAHk-=wg80je=K7madF4e7WrRNp37e3qh6y10Svhdc7O8SZ_-8g@mail.gmail.com/
> Co-developed-by: Arnd Bergmann <arnd@kernel.org>
> Signed-off-by: Arnd Bergmann <arnd@kernel.org>
> Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
...
> @@ -486,6 +487,9 @@ config HAS_IOMEM
> depends on !NO_IOMEM
> default y
>
> +config HAS_IOPORT
> + def_bool ISA || LEGACY_PCI
> +
That doesn't sound right.
The only dependency for LEGACY_PCI is PCI. If one selects LEGACY_PCI
on an architecture that doesn't support it, this will cause problems.
Instead, HAS_IOPORT should be selected at architecture level, and
the dependency here should be just the opposite: LEGACY_API should
depends on HAS_IOPORT.
Thanks,
Mauro
^ permalink raw reply
* Re: [RFC 02/32] Kconfig: introduce HAS_IOPORT option and select it as necessary
From: Michael Schmitz @ 2021-12-29 1:20 UTC (permalink / raw)
To: Geert Uytterhoeven, Niklas Schnelle
Cc: Rich Felker, linux-sh, Catalin Marinas, Dave Hansen, linux-pci,
linux-mips, James E.J. Bottomley, sparclinux, Guo Ren,
H. Peter Anvin, Borislav Petkov, linux-ia64, linux-riscv,
Vincent Chen, Will Deacon, Greg Ungerer, Karol Gugala, linux-arch,
linux-s390, Yoshinori Sato, Helge Deller, x86, Russell King,
linux-csky, Ingo Molnar, linux-parisc, Vineet Gupta, Matt Turner,
linux-snps-arc, Heiko Carstens, linux-xtensa, Albert Ou,
Chris Zankel, Jeff Dike, John Garry, linux-m68k, openrisc,
Ivan Kokshaysky, Greentime Hu, Paul Walmsley, Bjorn Helgaas,
Thomas Gleixner, linux-arm-kernel, Richard Henderson,
Arnd Bergmann, Michal Simek, Thomas Bogendoerfer, Brian Cain,
Nick Hu, linux-kernel, Dinh Nguyen, Palmer Dabbelt, linux-alpha,
Paul Mackerras, linuxppc-dev, David S. Miller
In-Reply-To: <CAMuHMdXk6VcDryekkMJ3aGFnw4LLWOWMi8M2PwjT81PsOsOBMQ@mail.gmail.com>
Hi Geert, Niklas,
Am 28.12.2021 um 23:08 schrieb Geert Uytterhoeven:
> Hi Niklas,
>
> On Mon, Dec 27, 2021 at 5:44 PM Niklas Schnelle <schnelle@linux.ibm.com> wrote:
>> We introduce a new HAS_IOPORT Kconfig option to gate support for
>> I/O port access. In a future patch HAS_IOPORT=n will disable compilation
>> of the I/O accessor functions inb()/outb() and friends on architectures
>> which can not meaningfully support legacy I/O spaces. On these platforms
>> inb()/outb() etc are currently just stubs in asm-generic/io.h which when
>> called will cause a NULL pointer access which some compilers actually
>> detect and warn about.
>>
>> The dependencies on HAS_IOPORT in drivers as well as ifdefs for
>> HAS_IOPORT specific sections will be added in subsequent patches on
>> a per subsystem basis. Then a final patch will ifdef the I/O access
>> functions on HAS_IOPORT thus turning any use not gated by HAS_IOPORT
>> into a compile-time warning.
>>
>> Link: https://lore.kernel.org/lkml/CAHk-=wg80je=K7madF4e7WrRNp37e3qh6y10Svhdc7O8SZ_-8g@mail.gmail.com/
>> Co-developed-by: Arnd Bergmann <arnd@kernel.org>
>> Signed-off-by: Arnd Bergmann <arnd@kernel.org>
>> Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
>
> Thanks for your patch!
>
>> --- a/arch/m68k/Kconfig
>> +++ b/arch/m68k/Kconfig
>> @@ -16,6 +16,7 @@ config M68K
>> select GENERIC_CPU_DEVICES
>> select GENERIC_IOMAP
>> select GENERIC_IRQ_SHOW
>> + select HAS_IOPORT
>> select HAVE_AOUT if MMU
>> select HAVE_ASM_MODVERSIONS
>> select HAVE_DEBUG_BUGVERBOSE
>
> This looks way too broad to me: most m68k platform do not have I/O
> port access support.
>
> My gut feeling says:
>
> select HAS_IOPORT if PCI || ISA
>
> but that might miss some intricate details...
In particular, this misses the Atari ROM port ISA adapter case -
select HAS_IOPORT if PCI || ISA || ATARI_ROM_ISA
might do instead.
Cheers,
Michael
>
> Gr{oetje,eeting}s,
>
> Geert
>
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
>
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
> -- Linus Torvalds
>
^ permalink raw reply
* Re: [RFC 02/32] Kconfig: introduce HAS_IOPORT option and select it as necessary
From: Arnd Bergmann @ 2021-12-29 3:41 UTC (permalink / raw)
To: Michael Schmitz
Cc: Rich Felker, linux-sh, Catalin Marinas, Dave Hansen, linux-pci,
linux-mips, James E.J. Bottomley, sparclinux, Guo Ren,
H. Peter Anvin, Borislav Petkov, linux-ia64, linux-riscv,
Vincent Chen, Will Deacon, Greg Ungerer, Karol Gugala, linux-arch,
linux-s390, Yoshinori Sato, Helge Deller, x86, Russell King,
linux-csky, Ingo Molnar, Geert Uytterhoeven, linux-parisc,
Vineet Gupta, Matt Turner, linux-snps-arc, Heiko Carstens,
linux-xtensa, Albert Ou, Niklas Schnelle, Jeff Dike, John Garry,
linux-m68k, openrisc, Ivan Kokshaysky, Greentime Hu,
Paul Walmsley, Bjorn Helgaas, Thomas Gleixner, linux-arm-kernel,
Richard Henderson, Chris Zankel, Michal Simek,
Thomas Bogendoerfer, Brian Cain, Nick Hu, linux-kernel,
Dinh Nguyen, Palmer Dabbelt, linux-alpha, Paul Mackerras,
linuxppc-dev, David S. Miller
In-Reply-To: <d406b93a-0f76-d056-3380-65d459d05ea9@gmail.com>
On Tue, Dec 28, 2021 at 8:20 PM Michael Schmitz <schmitzmic@gmail.com> wrote:
> Am 28.12.2021 um 23:08 schrieb Geert Uytterhoeven:
> > On Mon, Dec 27, 2021 at 5:44 PM Niklas Schnelle <schnelle@linux.ibm.com> wrote:
> >> We introduce a new HAS_IOPORT Kconfig option to gate support for
> >> I/O port access. In a future patch HAS_IOPORT=n will disable compilation
> >> of the I/O accessor functions inb()/outb() and friends on architectures
> >> which can not meaningfully support legacy I/O spaces. On these platforms
> >> inb()/outb() etc are currently just stubs in asm-generic/io.h which when
> >> called will cause a NULL pointer access which some compilers actually
> >> detect and warn about.
> >>
> >> The dependencies on HAS_IOPORT in drivers as well as ifdefs for
> >> HAS_IOPORT specific sections will be added in subsequent patches on
> >> a per subsystem basis. Then a final patch will ifdef the I/O access
> >> functions on HAS_IOPORT thus turning any use not gated by HAS_IOPORT
> >> into a compile-time warning.
> >>
> >> Link: https://lore.kernel.org/lkml/CAHk-=wg80je=K7madF4e7WrRNp37e3qh6y10Svhdc7O8SZ_-8g@mail.gmail.com/
> >> Co-developed-by: Arnd Bergmann <arnd@kernel.org>
> >> Signed-off-by: Arnd Bergmann <arnd@kernel.org>
> >> Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
> >
> > Thanks for your patch!
> >
> >> --- a/arch/m68k/Kconfig
> >> +++ b/arch/m68k/Kconfig
> >> @@ -16,6 +16,7 @@ config M68K
> >> select GENERIC_CPU_DEVICES
> >> select GENERIC_IOMAP
> >> select GENERIC_IRQ_SHOW
> >> + select HAS_IOPORT
> >> select HAVE_AOUT if MMU
> >> select HAVE_ASM_MODVERSIONS
> >> select HAVE_DEBUG_BUGVERBOSE
> >
> > This looks way too broad to me: most m68k platform do not have I/O
> > port access support.
> >
> > My gut feeling says:
> >
> > select HAS_IOPORT if PCI || ISA
> >
> > but that might miss some intricate details...
>
> In particular, this misses the Atari ROM port ISA adapter case -
>
> select HAS_IOPORT if PCI || ISA || ATARI_ROM_ISA
>
> might do instead.
Right, makes sense. I had suggested to go the easy way and assume that
each architecture would select HAS_IOPORT if any configuration supports
it, but it looks like for m68k there is a clearly defined set of platforms that
do.
Note that for the platforms that don't set any of the three symbols, the
fallback makes inb() an alias for readb() with a different argument type,
so there may be m68k specific drivers that rely on this, but those would
already be broken if ATARI_ROM_ISA is set.
Arnd
^ permalink raw reply
* [PATCH] powerpc/kasan: Fix early region not updated correctly
From: Chen Jingwen @ 2021-12-29 3:52 UTC (permalink / raw)
To: Chen Jingwen, Michael Ellerman, Benjamin Herrenschmidt,
Paul Mackerras, Christophe Leroy, linuxppc-dev, linux-kernel,
kasan-dev
The shadow's page table is not updated when PTE_RPN_SHIFT is 24
and PAGE_SHIFT is 12. It not only causes false positives but
also false negative as shown the following text.
Fix it by bringing the logic of kasan_early_shadow_page_entry here.
1. False Positive:
==================================================================
BUG: KASAN: vmalloc-out-of-bounds in pcpu_alloc+0x508/0xa50
Write of size 16 at addr f57f3be0 by task swapper/0/1
CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.15.0-12267-gdebe436e77c7 #1
Call Trace:
[c80d1c20] [c07fe7b8] dump_stack_lvl+0x4c/0x6c (unreliable)
[c80d1c40] [c02ff668] print_address_description.constprop.0+0x88/0x300
[c80d1c70] [c02ff45c] kasan_report+0x1ec/0x200
[c80d1cb0] [c0300b20] kasan_check_range+0x160/0x2f0
[c80d1cc0] [c03018a4] memset+0x34/0x90
[c80d1ce0] [c0280108] pcpu_alloc+0x508/0xa50
[c80d1d40] [c02fd7bc] __kmem_cache_create+0xfc/0x570
[c80d1d70] [c0283d64] kmem_cache_create_usercopy+0x274/0x3e0
[c80d1db0] [c2036580] init_sd+0xc4/0x1d0
[c80d1de0] [c00044a0] do_one_initcall+0xc0/0x33c
[c80d1eb0] [c2001624] kernel_init_freeable+0x2c8/0x384
[c80d1ef0] [c0004b14] kernel_init+0x24/0x170
[c80d1f10] [c001b26c] ret_from_kernel_thread+0x5c/0x64
Memory state around the buggy address:
f57f3a80: f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8
f57f3b00: f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8
>f57f3b80: f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8
^
f57f3c00: f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8
f57f3c80: f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8
==================================================================
2. False Negative (with KASAN tests):
==================================================================
Before fix:
ok 45 - kmalloc_double_kzfree
# vmalloc_oob: EXPECTATION FAILED at lib/test_kasan.c:1039
KASAN failure expected in "((volatile char *)area)[3100]", but none occurred
not ok 46 - vmalloc_oob
not ok 1 - kasan
==================================================================
After fix:
ok 1 - kasan
Fixes: cbd18991e24fe ("powerpc/mm: Fix an Oops in kasan_mmu_init()")
Cc: stable@vger.kernel.org # 5.4.x
Signed-off-by: Chen Jingwen <chenjingwen6@huawei.com>
---
arch/powerpc/mm/kasan/kasan_init_32.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/arch/powerpc/mm/kasan/kasan_init_32.c b/arch/powerpc/mm/kasan/kasan_init_32.c
index cf8770b1a692e..f3e4d069e0ba7 100644
--- a/arch/powerpc/mm/kasan/kasan_init_32.c
+++ b/arch/powerpc/mm/kasan/kasan_init_32.c
@@ -83,13 +83,12 @@ void __init
kasan_update_early_region(unsigned long k_start, unsigned long k_end, pte_t pte)
{
unsigned long k_cur;
- phys_addr_t pa = __pa(kasan_early_shadow_page);
for (k_cur = k_start; k_cur != k_end; k_cur += PAGE_SIZE) {
pmd_t *pmd = pmd_off_k(k_cur);
pte_t *ptep = pte_offset_kernel(pmd, k_cur);
- if ((pte_val(*ptep) & PTE_RPN_MASK) != pa)
+ if (pte_page(*ptep) != virt_to_page(lm_alias(kasan_early_shadow_page)))
continue;
__set_pte_at(&init_mm, k_cur, ptep, pte, 0);
--
2.19.1
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox