Commit Graph

1230775 Commits

Author SHA1 Message Date
Jianping Liu 73d0b4372d Merge OCK linux-6.6/devel branch into TK5 release branch 2024-11-14 09:31:00 +08:00
chinaljp030 448decb3e6
!267 [linux-6.6/devel] dist: spec: Include bpftool man pages with correct extension in bpftool RPM
Merge pull request !267 from Ming Wang/linux-6.6/devel
2024-11-14 01:27:29 +00:00
Ming Wang b3d1694a02 dist: spec: Include bpftool man pages with correct extension in bpftool RPM
The previous kernel RPM spec file did not accurately specify the extension for
bpftool man pages. This could lead to build errors on certain architectures where
the generated man pages might use a different extension than the expected `.gz`.

For example, on LoongArch, building a kernel RPM could result in the following errors:
Error: File not found: ... /loongarch64/usr/share/man/man8/bpftool.8.gz
Error: File not found: ... /loongarch64/usr/share/man/man8/bpftool-*.8.gz

This is because the bpftool man pages are actually generated with the `.zst`
extension on LoongArch:
bpftool.8.zst      bpftool-cgroup.8.zst   bpftool-gen.8.zst   bpftool-link.8.zst
...

This commit modifies the kernel.template.spec file to use a wildcard extension
when including bpftool man pages. This ensures that all generated man pages are
included in the RPM package, regardless of their extension.

Signed-off-by: Ming Wang <wangming01@loongson.cn>
2024-11-14 08:58:53 +08:00
Jianping Liu 9e51d2580d Merge OCK linux-6.6/devel branch into TK5 release branch 2024-11-13 15:59:05 +08:00
chinaljp030 d6e9d09029
!266 LoongArch: Update Loongson-3 default config file
Merge pull request !266 from Ming Wang/linux-6.6/devel
2024-11-13 07:53:18 +00:00
Ming Wang d276b18c7b LoongArch: Update Loongson-3 default config file
Upstream: no
Conflict: none
Checkpatch: pass

Enable BPF_JIT
Enable PSI
Enable ARCH_IOREMAP
Enable CPU_HAS_LBT
Enable SCSI_SAS_ATA
Enable CRYPTO_SM4_GENERIC
Enable CRYPTO_SM3_GENERIC
Enable HARDLOCKUP_DETECTOR
Enable FTRACE_SYSCALLS
Enable BLK_DEV_IO_TRACE

By the way, as part of general housekeeping, we're changing the defconfig
files to sort lines based on the 'make savedefconfig' output. This will
make it easier to make additional changes in the future.

Signed-off-by: Ming Wang <wangming01@loongson.cn>
2024-11-13 15:36:08 +08:00
chinaljp030 9e657f9a9a
!262 Support Hygon Trusted Key Management run on CSV
Merge pull request !262 from xisme/6.6_dev_tkm_support_csv
2024-11-13 07:32:45 +00:00
chinaljp030 7e663a02ba
!263 [linux-6.6/devel] Add objtool, orc and livepatch support for LoongArch
Merge pull request !263 from Tiezhu Yang/linux-6.6/devel
2024-11-13 07:29:18 +00:00
niuyongwen 9baada0c80 drivers/crypto/ccp: fix the increase in page references caused by gfn_to_pfn
gfn_to_pfn causes the refcount to increment atomically by one,
which needs to be released.

Signed-off-by: niuyongwen <niuyongwen@hygon.cn>
2024-11-13 11:05:16 +08:00
niuyongwen 85449db351 drivers/crypto/ccp: memmove is used instead of memcpy in overlapped memmory for tkm
When QEMU exits, the context information for the corresponding
VID is removed from an array.

However, memcpy was incorrectly used to overwrite invalid data
on overlapping memory.

memmove should be used instead to handle overlapping memory
regions correctly.

Signed-off-by: niuyongwen <niuyongwen@hygon.cn>
2024-11-13 11:03:08 +08:00
xiongmengbiao 8e1f6da2fd drivers/crypto/ccp: add ioctl API to pin TKM hugepage
A new set of ioctl interfaces for pinning memory
pages has been added.

These interfaces allow user-space drivers to prevent
large memory pages from being unexpectedly migrated.

Signed-off-by: xiongmengbiao <xiongmengbiao@hygon.cn>
2024-11-13 10:59:47 +08:00
xiongmengbiao c0c4c54954 driver/crypto/ccp: fix vtkm without C-bit when host SME deactivate
CSV guests can run without SME enabled.
Regardless of the host's SME status,
the C-bit must be set for the physical address.
Memory will be encrypted with a different key than SME.

Signed-off-by: xiongmengbiao <xiongmengbiao@hygon.cn>
2024-11-13 10:57:48 +08:00
xiongmengbiao 430f1f4354 crypto: ccp: support TKM run on CSV
In the CSV VM, data is encrypted in the host machine.
To support running TKM in the CSV VM, a new
KVM_HC_PSP_FORWARD_OP operation was introduced.

In this mode, all TKM request data is converted
from GPA to HPA and directly sent to PSP for processing.

PSP can decrypt the encrypted data on HPA using the
correct ASID.

Signed-off-by: xiongmengbiao <xiongmengbiao@hygon.cn>
2024-11-13 10:56:14 +08:00
xiongmengbiao ec92e554e7 crypto: ccp: remove multi-level pointers processing for vpsp
In the past, running TKM on a regular VM required copying
TKM request data to the kernel buffer.

However, in the CSV VM, all data is encrypted. If TKM requests
contain pointers, the data pointed to by the pointers cannot be
correctly parsed.

Therefore, we have removed the handling of multi-level pointers
in TKM requests.

Now, all TKM commands must follow an offset-based model and
cannot include pointers.

Signed-off-by: xiongmengbiao <xiongmengbiao@hygon.cn>
2024-11-13 10:42:55 +08:00
Huacai Chen 4efaa85c03 LoongArch: Update Loongson-3 default config file
commit 9cc1df421f00453afdcaf78b105d8e7fd03cce78 upstream.

Enable ORC stack unwinder.
Enable livepatch.

Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
[only enable configs of orc, ftrace and livepatch - yangtiezhu]
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2024-11-12 17:00:11 +08:00
Tiezhu Yang 79379d1629 compiler.h: specify correct attribute for .rodata..c_jump_table
commit c5b1184decc819756ae549ba54c63b6790c4ddfd upstream.

Currently, there is an assembler message when generating kernel/bpf/core.o
under CONFIG_OBJTOOL with LoongArch compiler toolchain:

  Warning: setting incorrect section attributes for .rodata..c_jump_table

This is because the section ".rodata..c_jump_table" should be readonly,
but there is a "W" (writable) part of the flags:

  $ readelf -S kernel/bpf/core.o | grep -A 1 "rodata..c"
  [34] .rodata..c_j[...] PROGBITS         0000000000000000  0000d2e0
       0000000000000800  0000000000000000  WA       0     0     8

There is no above issue on x86 due to the generated section flag is only
"A" (allocatable). In order to silence the warning on LoongArch, specify
the attribute like ".rodata..c_jump_table,\"a\",@progbits #" explicitly,
then the section attribute of ".rodata..c_jump_table" must be readonly
in the kernel/bpf/core.o file.

Before:

  $ objdump -h kernel/bpf/core.o | grep -A 1 "rodata..c"
   21 .rodata..c_jump_table 00000800  0000000000000000  0000000000000000  0000d2e0  2**3
                  CONTENTS, ALLOC, LOAD, RELOC, DATA

After:

  $ objdump -h kernel/bpf/core.o | grep -A 1 "rodata..c"
   21 .rodata..c_jump_table 00000800  0000000000000000  0000000000000000  0000d2e0  2**3
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA

By the way, AFAICT, maybe the root cause is related with the different
compiler behavior of various archs, so to some extent this change is a
workaround for LoongArch, and also there is no effect for x86 which is the
only port supported by objtool before LoongArch with this patch.

Link: https://lkml.kernel.org/r/20240924062710.1243-1-yangtiezhu@loongson.cn
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Cc: Josh Poimboeuf <jpoimboe@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: <stable@vger.kernel.org>	[6.9+]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2024-11-12 17:00:09 +08:00
Tiezhu Yang e0c69abdc4 LoongArch: Set AS_HAS_THIN_ADD_SUB as y if AS_IS_LLVM
commit a7e0837724562ea8c1d869dd1a5cb1119ef651c3 upstream.

When building kernel with "make CC=clang defconfig", LLVM Assembler is
used due to LLVM_IAS=0 is not specified, then AS_HAS_THIN_ADD_SUB is not
set, thus objtool can not be built after enable it for Clang.

config AS_HAS_THIN_ADD_SUB is to check whether -mthin-add-sub option is
available to know R_LARCH_{32,64}_PCREL are supported for GNU Assembler,
there is no such an option for LLVM Assembler. The minimal version of
Clang is 18 for building LoongArch kernel, and Clang >= 17 has already
supported R_LARCH_{32,64}_PCREL, that is to say, there is no need to
depend on AS_HAS_THIN_ADD_SUB for Clang, so just set AS_HAS_THIN_ADD_SUB
as y if AS_IS_LLVM.

Fixes: 120dd4118e58 ("LoongArch: Only allow OBJTOOL & ORC unwinder if toolchain supports -mthin-add-sub")
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
2024-11-12 17:00:06 +08:00
Tiezhu Yang 8c47f2b29a LoongArch: Enable objtool for Clang
commit b8468bd92ae19939d4844899fa05147888732519 upstream.

For now, it can enable objtool for Clang, just remove !CC_IS_CLANG for
HAVE_OBJTOOL in arch/loongarch/Kconfig.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
2024-11-12 17:00:04 +08:00
Tiezhu Yang 83c79d19b0 objtool: Handle frame pointer related instructions
commit da5b2ad1c2f18834cb1ce429e2e5a5cf5cbdf21b upstream.

After commit a0f7085f6a63 ("LoongArch: Add RANDOMIZE_KSTACK_OFFSET
support"), there are three new instructions "addi.d $fp, $sp, 32",
"sub.d $sp, $sp, $t0" and "addi.d $sp, $fp, -32" for the secondary
stack in do_syscall(), then there is a objtool warning "return with
modified stack frame" and no handle_syscall() which is the previous
frame of do_syscall() in the call trace when executing the command
"echo l > /proc/sysrq-trigger".

objdump shows something like this:

0000000000000000 <do_syscall>:
   0:   02ff8063        addi.d          $sp, $sp, -32
   4:   29c04076        st.d            $fp, $sp, 16
   8:   29c02077        st.d            $s0, $sp, 8
   c:   29c06061        st.d            $ra, $sp, 24
  10:   02c08076        addi.d          $fp, $sp, 32
  ...
  74:   0011b063        sub.d           $sp, $sp, $t0
  ...
  a8:   4c000181        jirl            $ra, $t0, 0
  ...
  dc:   02ff82c3        addi.d          $sp, $fp, -32
  e0:   28c06061        ld.d            $ra, $sp, 24
  e4:   28c04076        ld.d            $fp, $sp, 16
  e8:   28c02077        ld.d            $s0, $sp, 8
  ec:   02c08063        addi.d          $sp, $sp, 32
  f0:   4c000020        jirl            $zero, $ra, 0

The instruction "sub.d $sp, $sp, $t0" changes the stack bottom and the
new stack size is a random value, in order to find the return address of
do_syscall() which is stored in the original stack frame after executing
"jirl $ra, $t0, 0", it should use fp which points to the original stack
top.

At the beginning, the thought is tended to decode the secondary stack
instruction "sub.d $sp, $sp, $t0" and set it as a label, then check this
label for the two frame pointer instructions to change the cfa base and
cfa offset during the period of secondary stack in update_cfi_state().
This is valid for GCC but invalid for Clang due to there are different
secondary stack instructions for ClangBuiltLinux on LoongArch, something
like this:

0000000000000000 <do_syscall>:
  ...
  88:   00119064        sub.d           $a0, $sp, $a0
  8c:   00150083        or              $sp, $a0, $zero
  ...

Actually, it equals to a single instruction "sub.d $sp, $sp, $a0", but
there is no proper condition to check it as a label like GCC, and so the
beginning thought is not a good way.

Essentially, there are two special frame pointer instructions which are
"addi.d $fp, $sp, imm" and "addi.d $sp, $fp, imm", the first one points
fp to the original stack top and the second one restores the original
stack bottom from fp.

Based on the above analysis, in order to avoid adding an arch-specific
update_cfi_state(), we just add a member "frame_pointer" in the "struct
symbol" as a label to avoid affecting the current normal case, then set
it as true only if there is "addi.d $sp, $fp, imm". The last is to check
this label for the two frame pointer instructions to change the cfa base
and cfa offset in update_cfi_state().

Tested with the following two configs:
(1) CONFIG_RANDOMIZE_KSTACK_OFFSET=y &&
    CONFIG_RANDOMIZE_KSTACK_OFFSET_DEFAULT=n
(2) CONFIG_RANDOMIZE_KSTACK_OFFSET=y &&
    CONFIG_RANDOMIZE_KSTACK_OFFSET_DEFAULT=y

By the way, there is no effect for x86 with this patch, tested on the
x86 machine with Fedora 40 system.

Cc: stable@vger.kernel.org # 6.9+
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
2024-11-12 17:00:02 +08:00
Tiezhu Yang 65294a2d3e LoongArch: Add ifdefs to fix LSX and LASX related warnings
commit 80376323e2b6a4559f86b2b4d864848ac25cb054 upstream.

There exist some warnings when building kernel if CONFIG_CPU_HAS_LBT is
set but CONFIG_CPU_HAS_LSX and CONFIG_CPU_HAS_LASX are not set. In this
case, there are no definitions of _restore_lsx & _restore_lasx and there
are also no definitions of kvm_restore_lsx & kvm_restore_lasx in fpu.S
and switch.S respectively, just add some ifdefs to fix these warnings.

  AS      arch/loongarch/kernel/fpu.o
arch/loongarch/kernel/fpu.o: warning: objtool: unexpected relocation symbol type in .rela.discard.func_stack_frame_non_standard: 0
arch/loongarch/kernel/fpu.o: warning: objtool: unexpected relocation symbol type in .rela.discard.func_stack_frame_non_standard: 0

  AS [M]  arch/loongarch/kvm/switch.o
arch/loongarch/kvm/switch.o: warning: objtool: unexpected relocation symbol type in .rela.discard.func_stack_frame_non_standard: 0
arch/loongarch/kvm/switch.o: warning: objtool: unexpected relocation symbol type in .rela.discard.func_stack_frame_non_standard: 0

  MODPOST Module.symvers
ERROR: modpost: "kvm_restore_lsx" [arch/loongarch/kvm/kvm.ko] undefined!
ERROR: modpost: "kvm_restore_lasx" [arch/loongarch/kvm/kvm.ko] undefined!

Cc: stable@vger.kernel.org # 6.9+
Fixes: cb8a2ef0848c ("LoongArch: Add ORC stack unwinder support")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202408120955.qls5oNQY-lkp@intel.com/
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
2024-11-12 16:59:59 +08:00
Xi Ruoyao c681137e0e LoongArch: Only allow OBJTOOL & ORC unwinder if toolchain supports -mthin-add-sub
commit 120dd4118e58dbda2ddb1dcf55f3c56cdfe8cee0 upstream.

GAS <= 2.41 does not support generating R_LARCH_{32,64}_PCREL for
"label - ." and it generates R_LARCH_{ADD,SUB}{32,64} pairs instead.
Objtool cannot handle R_LARCH_{ADD,SUB}{32,64} pair in __jump_table
(static key implementation) and etc. so it will produce some warnings.
This is causing the kernel CI systems to complain everywhere.

For GAS we can check if -mthin-add-sub option is available to know if
R_LARCH_{32,64}_PCREL are supported.

For Clang, we require Clang >= 18 and Clang >= 17 already supports
R_LARCH_{32,64}_PCREL. But unfortunately Clang has some other issues,
so we disable objtool for Clang at present.

Note that __jump_table here is not generated by the compiler, so
-fno-jump-table is completely irrelevant for this issue.

Fixes: cb8a2ef0848c ("LoongArch: Add ORC stack unwinder support")
Closes: https://lore.kernel.org/loongarch/Zl5m1ZlVmGKitAof@yujie-X299/
Closes: https://lore.kernel.org/loongarch/ZlY1gDDPi_mNrwJ1@slm.duckdns.org/
Closes: https://lore.kernel.org/loongarch/1717478006.038663-1-hengqi@linux.alibaba.com/
Link: https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=816029e06768
Link: https://github.com/llvm/llvm-project/commit/42cb3c6346fc
Signed-off-by: Xi Ruoyao <xry111@xry111.site>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2024-11-12 16:59:57 +08:00
Jinyang He 53d2b63952 LoongArch: Add kernel livepatching support
commit 199cc14cb4f1cb8668be45f67af41755ed5f0175 upstream.

The arch-specified function ftrace_regs_set_instruction_pointer() has
been implemented in arch/loongarch/include/asm/ftrace.h, so here only
implement arch_stack_walk_reliable() function.

Here are the test logs:

[root@linux fedora]# cat /proc/cmdline
BOOT_IMAGE=/vmlinuz-6.8.0-rc2 root=/dev/sda3

[root@linux fedora]# modprobe livepatch-sample
[root@linux fedora]# cat /proc/cmdline
this has been live patched

[root@linux fedora]# echo 0 > /sys/kernel/livepatch/livepatch_sample/enabled
[root@linux fedora]# rmmod livepatch_sample
[root@linux fedora]# cat /proc/cmdline
BOOT_IMAGE=/vmlinuz-6.8.0-rc2 root=/dev/sda3

[root@linux fedora]# dmesg -t | tail -5
livepatch: enabling patch 'livepatch_sample'
livepatch: 'livepatch_sample': starting patching transition
livepatch: 'livepatch_sample': patching complete
livepatch: 'livepatch_sample': starting unpatching transition
livepatch: 'livepatch_sample': unpatching complete

Signed-off-by: Jinyang He <hejinyang@loongson.cn>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
2024-11-12 16:59:54 +08:00
Tiezhu Yang 2d905626ca LoongArch: Fix definition of ftrace_regs_set_instruction_pointer()
commit 91af17cd7d03db8836554c91ba7c38b0817aa980 upstream.

The current definition of ftrace_regs_set_instruction_pointer() is not
correct. Obviously, this function is used to set instruction pointer but
not return value, so it should call instruction_pointer_set() instead of
regs_set_return_value().

There is no side effect by now because it is only used for kernel live-
patching which is not supported, so fix it to avoid failure when testing
livepatch in the future.

Fixes: 6fbff14a63 ("LoongArch: ftrace: Abstract DYNAMIC_FTRACE_WITH_ARGS accesses")
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
2024-11-12 16:59:51 +08:00
Tiezhu Yang 559ae71cef LoongArch: Add ORC stack unwinder support
commit cb8a2ef0848ca80d67d6d56e2df757cfdf6b3355 upstream.

The kernel CONFIG_UNWINDER_ORC option enables the ORC unwinder, which is
similar in concept to a DWARF unwinder. The difference is that the format
of the ORC data is much simpler than DWARF, which in turn allows the ORC
unwinder to be much simpler and faster.

The ORC data consists of unwind tables which are generated by objtool.
After analyzing all the code paths of a .o file, it determines information
about the stack state at each instruction address in the file and outputs
that information to the .orc_unwind and .orc_unwind_ip sections.

The per-object ORC sections are combined at link time and are sorted and
post-processed at boot time. The unwinder uses the resulting data to
correlate instruction addresses with their stack states at run time.

Most of the logic are similar with x86, in order to get ra info before ra
is saved into stack, add ra_reg and ra_offset into orc_entry. At the same
time, modify some arch-specific code to silence the objtool warnings.

Co-developed-by: Jinyang He <hejinyang@loongson.cn>
Signed-off-by: Jinyang He <hejinyang@loongson.cn>
Co-developed-by: Youling Tang <tangyouling@loongson.cn>
Signed-off-by: Youling Tang <tangyouling@loongson.cn>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
2024-11-12 16:59:49 +08:00
Tiezhu Yang 69b3f5cd6e objtool: Check local label in read_unwind_hints()
commit e91c5e4c21b0339376ee124cda5c9b27d41f2cbc upstream.

When update the latest upstream gcc and binutils, it generates some
objtool warnings on LoongArch, like this:

  arch/loongarch/kernel/entry.o: warning: objtool: ret_from_fork+0x0: unreachable instruction

We can see that the reloc sym name is local label instead of section
in relocation section '.rela.discard.unwind_hints', in this case, the
reloc sym type is STT_NOTYPE instead of STT_SECTION. Let us check it
to not return -1, then use reloc->sym->offset instead of reloc addend
which is 0 to find the corresponding instruction.

Here are some detailed info:
[fedora@linux 6.8.test]$ gcc --version
gcc (GCC) 14.0.1 20240129 (experimental)
[fedora@linux 6.8.test]$ as --version
GNU assembler (GNU Binutils) 2.42.50.20240129
[fedora@linux 6.8.test]$ readelf -r arch/loongarch/kernel/entry.o | grep -A 3 "rela.discard.unwind_hints"
Relocation section '.rela.discard.unwind_hints' at offset 0x3a8 contains 7 entries:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000000000  000a00000063 R_LARCH_32_PCREL  0000000000000000 .Lhere_1 + 0
00000000000c  000b00000063 R_LARCH_32_PCREL  00000000000000a8 .Lhere_50 + 0

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
2024-11-12 16:59:46 +08:00
Tiezhu Yang 1218e5151e objtool: Check local label in add_dead_ends()
commit d5ab2bc36c6b0ce2f3409f934ff9cdf6d6768fa2 upstream.

When update the latest upstream gcc and binutils, it generates more
objtool warnings on LoongArch, like this:

  init/main.o: warning: objtool: unexpected relocation symbol type in .rela.discard.unreachable

We can see that the reloc sym name is local label instead of section in
relocation section '.rela.discard.unreachable', in this case, the reloc
sym type is STT_NOTYPE instead of STT_SECTION.

As suggested by Peter Zijlstra, we add a "local_label" member in struct
symbol, then set it as true if symbol type is STT_NOTYPE and symbol name
starts with ".L" string in classify_symbols().

Let's check reloc->sym->local_label to not return -1 in add_dead_ends(),
and also use reloc->sym->offset instead of reloc addend which is 0 to
find the corresponding instruction. At the same time, let's replace the
variable "addend" with "offset" to reflect the reality.

Here are some detailed info:
[fedora@linux 6.8.test]$ gcc --version
gcc (GCC) 14.0.1 20240129 (experimental)
[fedora@linux 6.8.test]$ as --version
GNU assembler (GNU Binutils) 2.42.50.20240129
[fedora@linux 6.8.test]$ readelf -r init/main.o | grep -A 2 "rela.discard.unreachable"
Relocation section '.rela.discard.unreachable' at offset 0x6028 contains 1 entry:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000000000  00d900000063 R_LARCH_32_PCREL  00000000000002c4 .L500^B1 + 0

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
2024-11-12 16:59:44 +08:00
Tiezhu Yang a2265ff398 objtool/LoongArch: Enable orc to be built
commit 3c7266cd7bc5e7843b631fea73cb0e82111e3158 upstream.

Implement arch-specific init_orc_entry(), write_orc_entry(), reg_name(),
orc_type_name(), print_reg() and orc_print_dump(), then set BUILD_ORC as
y to build the orc related files.

Co-developed-by: Jinyang He <hejinyang@loongson.cn>
Signed-off-by: Jinyang He <hejinyang@loongson.cn>
Co-developed-by: Youling Tang <tangyouling@loongson.cn>
Signed-off-by: Youling Tang <tangyouling@loongson.cn>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
2024-11-12 16:59:42 +08:00
Tiezhu Yang 70146607e5 objtool/x86: Separate arch-specific and generic parts
commit b8e85e6f3a09fc56b0ff574887798962ef8a8f80 upstream.

Move init_orc_entry(), write_orc_entry(), reg_name(), orc_type_name()
and print_reg() from generic orc_gen.c and orc_dump.c to arch-specific
orc.c, then introduce a new function orc_print_dump() to print info.

This is preparation for later patch, no functionality change.

Co-developed-by: Jinyang He <hejinyang@loongson.cn>
Signed-off-by: Jinyang He <hejinyang@loongson.cn>
Co-developed-by: Youling Tang <tangyouling@loongson.cn>
Signed-off-by: Youling Tang <tangyouling@loongson.cn>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
2024-11-12 16:59:39 +08:00
Tiezhu Yang fd40028d8b objtool/LoongArch: Implement instruction decoder
commit b2d23158e6c881326321c2351b92568be4e57030 upstream.

Only copy the minimal definitions of instruction opcodes and formats
in inst.h from arch/loongarch to tools/arch/loongarch, and also copy
the definition of sign_extend64() to tools/include/linux/bitops.h to
decode the following kinds of instructions:

(1) stack pointer related instructions
addi.d, ld.d, st.d, ldptr.d and stptr.d

(2) branch and jump related instructions
beq, bne, blt, bge, bltu, bgeu, beqz, bnez, bceqz, bcnez, b, bl and jirl

(3) other instructions
break, nop and ertn

See more info about instructions in LoongArch Reference Manual:
https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html

Co-developed-by: Jinyang He <hejinyang@loongson.cn>
Signed-off-by: Jinyang He <hejinyang@loongson.cn>
Co-developed-by: Youling Tang <tangyouling@loongson.cn>
Signed-off-by: Youling Tang <tangyouling@loongson.cn>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
2024-11-12 16:59:37 +08:00
Tiezhu Yang eca6a54791 objtool/LoongArch: Enable objtool to be built
commit e8aff71ca93026209dd0eab9b285e6808cd87d05 upstream.

Add the minimal changes to enable objtool build on LoongArch,
most of the functions are stubs to only fix the build errors
when make -C tools/objtool.

This is similar with commit e52ec98c5a ("objtool/powerpc:
Enable objtool to be built on ppc").

Co-developed-by: Jinyang He <hejinyang@loongson.cn>
Signed-off-by: Jinyang He <hejinyang@loongson.cn>
Co-developed-by: Youling Tang <tangyouling@loongson.cn>
Signed-off-by: Youling Tang <tangyouling@loongson.cn>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
2024-11-12 16:59:32 +08:00
Jianping Liu 681c35f961 Merge ock linux-6.6/devel branch into tk5 release branch 2024-11-12 14:24:07 +08:00
frankjpliu 0e0e4c7e53 Merge branch 'leonylgao/support_kill_block_2' into 'release' (merge request !229)
tkernel: support kill block feature

If the kill signal match the block rule, it will be blocked.
This feature is useful to some k8s user who don't allow k8s
kill user process.

Signed-off-by: Hongbo Li <herberthbli@tencent.com>
Signed-off-by: Yongliang Gao <leonylgao@tencent.com>
Reviewed-by: Jianping Liu <frankjpliu@tencent.com>
2024-11-12 06:16:32 +00:00
Yongliang Gao 757f8aaf97 tkernel: make the code for the kill block feature cleaner
No functional changes, just making the code cleaner.

Signed-off-by: Yongliang Gao <leonylgao@tencent.com>
Reviewed-by: Jianping Liu <frankjpliu@tencent.com>
2024-11-12 12:56:14 +08:00
Yongliang Gao 3cc17b97d8 tkernel: support kill block feature
If the kill signal match the block rule, it will be blocked.
This feature is useful to some k8s user who don't allow k8s
kill user process.

Signed-off-by: Hongbo Li <herberthbli@tencent.com>
Signed-off-by: Yongliang Gao <leonylgao@tencent.com>
Reviewed-by: Jianping Liu <frankjpliu@tencent.com>
2024-11-12 12:56:08 +08:00
Yongliang Gao 2eff4717b8 tkernel: export some symbols for the kill block feature
The kill block feature whil compile as a module, and requires
the following symbols:
 - cpu_cgrp_subsys
 - kernfs_name

Signed-off-by: Yongliang Gao <leonylgao@tencent.com>
Reviewed-by: Jianping Liu <frankjpliu@tencent.com>
2024-11-12 12:56:04 +08:00
Yongliang Gao a415b16b7a tkernel: support kill hook interface
Add a kill hook callback in check_kill_permission to support
kill interception.

Signed-off-by: Yongliang Gao <leonylgao@tencent.com>
Reviewed-by: Jianping Liu <frankjpliu@tencent.com>
2024-11-12 12:55:00 +08:00
frankjpliu 76fa8434e2 Merge branch 'leonylgao/support_irqlatency' into 'release' (merge request !227)
tkernel: add irq latency tool

A tool of detecting irq/softirq latency. The principle is
base of whether the timer is triggered regulartly or not.

Signed-off-by: Liu Hua <shookliu@tencent.com>
Signed-off-by: Jianping Liu <frankjpliu@tencent.com>
Signed-off-by: Yongliang Gao <leonylgao@tencent.com>
2024-11-12 03:41:21 +00:00
frankjpliu 55b4e68fd5 Merge branch 'haisu/release-s9' into 'release' (merge request !224)
Fix block/fs CVE CVE list(3):
CVE-2024-46733
CVE-2024-49934
CVE-2024-49994
2024-11-12 02:04:28 +00:00
Jianping Liu a8ddb8040e config: enable CONFIG_DEBUG_VM_PGFLAGS in debug.config
CONFIG_DEBUG_VM_PGFLAGS is used to check the page Flags operation to
ensure there are no abnormalities (such as misuse of large pages,
page lock issues, etc).

Signed-off-by: Jianping Liu <frankjpliu@tencent.com>
Reviewed-by: Yongliang Gao <leonylgao@tencent.com>
2024-11-12 10:00:11 +08:00
chinaljp030 bb33b91fa9
!260 Sync upstream patch for loongarch64
Merge pull request !260 from lixianglai/linux-6.6-local
2024-11-08 02:48:57 +00:00
Yongliang Gao b1e66f19d1 tkernel: add irq latency tool
A tool of detecting irq/softirq latency. The principle is
base of whether the timer is triggered regulartly or not.

Signed-off-by: Liu Hua <shookliu@tencent.com>
Signed-off-by: Jianping Liu <frankjpliu@tencent.com>
Signed-off-by: Yongliang Gao <leonylgao@tencent.com>
2024-11-07 19:49:32 +08:00
Jianping Liu 2062f089a2 dist: release 6.6.58-15
Upstream: no

Signed-off-by: Jianping Liu <frankjpliu@tencent.com>
2024-11-07 11:43:51 +08:00
Xianglai Li 364b05f0da LoongArch: add iommu support
Upstream: no

Added iommu support for loongarch

Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
2024-11-06 19:40:31 +08:00
Xianglai Li 013ea94d74 LoongArch: Fix cpu hotplug issue
Upstream: no

On LoongArch system, there are two places to set cpu numa node. One
is in arch specified function smp_prepare_boot_cpu(), the other is
in generic function early_numa_node_init(). The latter will overwrite
the numa node information.

With hot-added cpu without numa information, cpu_logical_map() fails
to its physical cpuid at beginning since it is not enabled in ACPI
MADT table. So function early_cpu_to_node() also fails to get its
numa node for hot-added cpu, and generic function
early_numa_node_init() will overwrite with incorrect numa node.

APIs topo_get_cpu() and topo_add_cpu() is added here, like other
architectures logic cpu is allocated when parsing MADT table. When
parsing SRAT table or hot-add cpu, logic cpu is acquired by searching
all allocated logical cpu with matched physical id. It solves such
problems such as:
  1. Boot cpu is not the first entry in MADT table, the first entry
will be overwritten with later boot cpu.
  2. Physical cpu id not presented in MADT table is invalid, in later
SRAT/hot-add cpu parsing, invalid physical cpu detected is added
  3. For hot-add cpu, its logic cpu is allocated in MADT table parsing,
so early_cpu_to_node() can be used for hot-add cpu and cpu_to_node()
is correct for hot-add cpu.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
2024-11-06 19:36:40 +08:00
Bibo Mao 85d529bdda LoongArch: KVM: Remove unnecessary CSR register saving during enter guest
commit b99f783106ea ("LoongArch: KVM: Remove unnecessary CSR register saving during enter guest")
Conflict: none
Backport-reason: Synchronize upstream linux loongarch kvm
patch to support loongarch virtualization.
Checkpatch: no, to be consistent with upstream commit.

Some CSR registers like CRMD/PRMD are saved during enter VM mode now.
However they are not restored for actual use, so saving for these CSR
registers can be removed.

Reviewed-by: Tianrui Zhao <zhaotianrui@loongson.cn>
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
2024-11-06 19:36:40 +08:00
Dandan Zhang f51f26150c LoongArch: KVM: Remove undefined a6 argument comment for kvm_hypercall()
commit 494b0792d962 ("LoongArch: KVM: Remove undefined a6 argument comment for kvm_hypercall()")
Conflict: none
Backport-reason: Synchronize upstream linux loongarch kvm
patch to support loongarch virtualization.
Checkpatch: no, to be consistent with upstream commit.

The kvm_hypercall() set for LoongArch is limited to a1-a5. So the
mention of a6 in the comment is undefined that needs to be rectified.

Reviewed-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
Signed-off-by: Dandan Zhang <zhangdandan@uniontech.com>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
2024-11-06 19:36:40 +08:00
Bibo Mao 4d103268f6 LoongArch: KVM: Add vcpu mapping from physical cpuid
commit 73516e9da512 ("LoongArch: KVM: Add vcpu mapping from physical cpuid")
Conflict: none
Backport-reason: Synchronize upstream linux loongarch kvm
patch to support loongarch virtualization.
Checkpatch: no, to be consistent with upstream commit.

Physical CPUID is used for interrupt routing for irqchips such as ipi,
msgint and eiointc interrupt controllers. Physical CPUID is stored at
the CSR register LOONGARCH_CSR_CPUID, it can not be changed once vcpu
is created and the physical CPUIDs of two vcpus cannot be the same.

Different irqchips have different size declaration about physical CPUID,
the max CPUID value for CSR LOONGARCH_CSR_CPUID on Loongson-3A5000 is
512, the max CPUID supported by IPI hardware is 1024, while for eiointc
irqchip is 256, and for msgint irqchip is 65536.

The smallest value from all interrupt controllers is selected now, and
the max cpuid size is defines as 256 by KVM which comes from the eiointc
irqchip.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
2024-11-06 19:36:40 +08:00
Yuli Wang 8f1ab9b3ef LoongArch: KVM: Remove unnecessary definition of KVM_PRIVATE_MEM_SLOTS
commit 296b03ce389b ("LoongArch: KVM: Remove unnecessary definition of KVM_PRIVATE_MEM_SLOTS")
Conflict: none
Backport-reason: Synchronize upstream linux loongarch kvm
patch to support loongarch virtualization.
Checkpatch: no, to be consistent with upstream commit.

1. "KVM_PRIVATE_MEM_SLOTS" is renamed as "KVM_INTERNAL_MEM_SLOTS".

2. "KVM_INTERNAL_MEM_SLOTS" defaults to zero, so it is not necessary to
define it in LoongArch's asm/kvm_host.h.

Link: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=bdd1c37a315bc50ab14066c4852bc8dcf070451e
Link: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=b075450868dbc0950f0942617f222eeb989cad10
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
Signed-off-by: Yuli Wang <wangyuli@uniontech.com>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
2024-11-06 19:36:40 +08:00
Bibo Mao cac819dfa1 LoongArch: KVM: Add cpucfg area for kvm hypervisor
commit 9753d3037964 ("LoongArch: KVM: Add cpucfg area for kvm hypervisor")
Conflict: none
Backport-reason: Synchronize upstream linux loongarch kvm
patch to support loongarch virtualization.
Checkpatch: no, to be consistent with upstream commit.

Instruction cpucfg can be used to get processor features. And there
is a trap exception when it is executed in VM mode, and also it can be
used to provide cpu features to VM. On real hardware cpucfg area 0 - 20
is used by now. Here one specified area 0x40000000 -- 0x400000ff is used
for KVM hypervisor to provide PV features, and the area can be extended
for other hypervisors in future. This area will never be used for real
HW, it is only used by software.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
2024-11-06 19:36:40 +08:00
Bibo Mao bffc45fd59 LoongArch: KVM: Add KVM hypercalls documentation for LoongArch
commit e5ba90abb2eb ("LoongArch: KVM: Add KVM hypercalls documentation for LoongArch")
Conflict: none
Backport-reason: Synchronize upstream linux loongarch kvm
patch to support loongarch virtualization.
Checkpatch: no, to be consistent with upstream commit.

Add documentation topic for using pv_virt when running as a guest
on KVM hypervisor.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
Co-developed-by: Mingcong Bai <jeffbai@aosc.io>
Signed-off-by: Mingcong Bai <jeffbai@aosc.io>
Link: https://lore.kernel.org/all/5c338084b1bcccc1d57dce9ddb1e7081@aosc.io/
Signed-off-by: Dandan Zhang <zhangdandan@uniontech.com>
[jc: fixed htmldocs build error]
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Link: https://lore.kernel.org/r/4769C036576F8816+20240828045950.3484113-1-zhangdandan@uniontech.com
2024-11-06 19:36:40 +08:00