Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'riscv-for-linus-6.15-mw1' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux

Pull RISC-V updates from Palmer Dabbelt:

- The sub-architecture selection Kconfig system has been cleaned up,
the documentation has been improved, and various detections have been
fixed

- The vector-related extensions dependencies are now validated when
parsing from device tree and in the DT bindings

- Misaligned access probing can be overridden via a kernel command-line
parameter, along with various fixes to misalign access handling

- Support for relocatable !MMU kernels builds

- Support for hpge pfnmaps, which should improve TLB utilization

- Support for runtime constants, which improves the d_hash()
performance

- Support for bfloat16, Zicbom, Zaamo, Zalrsc, Zicntr, Zihpm

- Various fixes, including:
- We were missing a secondary mmu notifier call when flushing the
tlb which is required for IOMMU
- Fix ftrace panics by saving the registers as expected by ftrace
- Fix a couple of stimecmp usage related to cpu hotplug
- purgatory_start is now aligned as per the STVEC requirements
- A fix for hugetlb when calculating the size of non-present PTEs

* tag 'riscv-for-linus-6.15-mw1' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux: (65 commits)
riscv: Add norvc after .option arch in runtime const
riscv: Make sure toolchain supports zba before using zba instructions
riscv/purgatory: 4B align purgatory_start
riscv/kexec_file: Handle R_RISCV_64 in purgatory relocator
selftests: riscv: fix v_exec_initval_nolibc.c
riscv: Fix hugetlb retrieval of number of ptes in case of !present pte
riscv: print hartid on bringup
riscv: Add norvc after .option arch in runtime const
riscv: Remove CONFIG_PAGE_OFFSET
riscv: Support CONFIG_RELOCATABLE on riscv32
asm-generic: Always define Elf_Rel and Elf_Rela
riscv: Support CONFIG_RELOCATABLE on NOMMU
riscv: Allow NOMMU kernels to access all of RAM
riscv: Remove duplicate CONFIG_PAGE_OFFSET definition
RISC-V: errata: Use medany for relocatable builds
dt-bindings: riscv: document vector crypto requirements
dt-bindings: riscv: add vector sub-extension dependencies
dt-bindings: riscv: d requires f
RISC-V: add f & d extension validation checks
RISC-V: add vector crypto extension validation checks
...

+1255 -404
+16
Documentation/admin-guide/kernel-parameters.txt
··· 7535 7535 Note that genuine overcurrent events won't be 7536 7536 reported either. 7537 7537 7538 + unaligned_scalar_speed= 7539 + [RISCV] 7540 + Format: {slow | fast | unsupported} 7541 + Allow skipping scalar unaligned access speed tests. This 7542 + is useful for testing alternative code paths and to skip 7543 + the tests in environments where they run too slowly. All 7544 + CPUs must have the same scalar unaligned access speed. 7545 + 7546 + unaligned_vector_speed= 7547 + [RISCV] 7548 + Format: {slow | fast | unsupported} 7549 + Allow skipping vector unaligned access speed tests. This 7550 + is useful for testing alternative code paths and to skip 7551 + the tests in environments where they run too slowly. All 7552 + CPUs must have the same vector unaligned access speed. 7553 + 7538 7554 unknown_nmi_panic 7539 7555 [X86] Cause panic on unknown NMI. 7540 7556
+32
Documentation/arch/riscv/hwprobe.rst
··· 183 183 defined in the Atomic Compare-and-Swap (CAS) instructions manual starting 184 184 from commit 5059e0ca641c ("update to ratified"). 185 185 186 + * :c:macro:`RISCV_HWPROBE_EXT_ZICNTR`: The Zicntr extension version 2.0 187 + is supported as defined in the RISC-V ISA manual. 188 + 186 189 * :c:macro:`RISCV_HWPROBE_EXT_ZICOND`: The Zicond extension is supported as 187 190 defined in the RISC-V Integer Conditional (Zicond) operations extension 188 191 manual starting from commit 95cf1f9 ("Add changes requested by Ved ··· 194 191 * :c:macro:`RISCV_HWPROBE_EXT_ZIHINTPAUSE`: The Zihintpause extension is 195 192 supported as defined in the RISC-V ISA manual starting from commit 196 193 d8ab5c78c207 ("Zihintpause is ratified"). 194 + 195 + * :c:macro:`RISCV_HWPROBE_EXT_ZIHPM`: The Zihpm extension version 2.0 196 + is supported as defined in the RISC-V ISA manual. 197 197 198 198 * :c:macro:`RISCV_HWPROBE_EXT_ZVE32X`: The Vector sub-extension Zve32x is 199 199 supported, as defined by version 1.0 of the RISC-V Vector extension manual. ··· 245 239 ratified in commit 98918c844281 ("Merge pull request #1217 from 246 240 riscv/zawrs") of riscv-isa-manual. 247 241 242 + * :c:macro:`RISCV_HWPROBE_EXT_ZAAMO`: The Zaamo extension is supported as 243 + defined in the in the RISC-V ISA manual starting from commit e87412e621f1 244 + ("integrate Zaamo and Zalrsc text (#1304)"). 245 + 246 + * :c:macro:`RISCV_HWPROBE_EXT_ZALRSC`: The Zalrsc extension is supported as 247 + defined in the in the RISC-V ISA manual starting from commit e87412e621f1 248 + ("integrate Zaamo and Zalrsc text (#1304)"). 249 + 248 250 * :c:macro:`RISCV_HWPROBE_EXT_SUPM`: The Supm extension is supported as 249 251 defined in version 1.0 of the RISC-V Pointer Masking extensions. 252 + 253 + * :c:macro:`RISCV_HWPROBE_EXT_ZFBFMIN`: The Zfbfmin extension is supported as 254 + defined in the RISC-V ISA manual starting from commit 4dc23d6229de 255 + ("Added Chapter title to BF16"). 256 + 257 + * :c:macro:`RISCV_HWPROBE_EXT_ZVFBFMIN`: The Zvfbfmin extension is supported as 258 + defined in the RISC-V ISA manual starting from commit 4dc23d6229de 259 + ("Added Chapter title to BF16"). 260 + 261 + * :c:macro:`RISCV_HWPROBE_EXT_ZVFBFWMA`: The Zvfbfwma extension is supported as 262 + defined in the RISC-V ISA manual starting from commit 4dc23d6229de 263 + ("Added Chapter title to BF16"). 264 + 265 + * :c:macro:`RISCV_HWPROBE_EXT_ZICBOM`: The Zicbom extension is supported, as 266 + ratified in commit 3dd606f ("Create cmobase-v1.0.pdf") of riscv-CMOs. 250 267 251 268 * :c:macro:`RISCV_HWPROBE_KEY_CPUPERF_0`: Deprecated. Returns similar values to 252 269 :c:macro:`RISCV_HWPROBE_KEY_MISALIGNED_SCALAR_PERF`, but the key was ··· 332 303 * :c:macro:`RISCV_HWPROBE_VENDOR_EXT_XTHEADVECTOR`: The xtheadvector vendor 333 304 extension is supported in the T-Head ISA extensions spec starting from 334 305 commit a18c801634 ("Add T-Head VECTOR vendor extension. "). 306 + 307 + * :c:macro:`RISCV_HWPROBE_KEY_ZICBOM_BLOCK_SIZE`: An unsigned int which 308 + represents the size of the Zicbom block in bytes.
+149
Documentation/devicetree/bindings/riscv/extensions.yaml
··· 224 224 as ratified at commit 4a69197e5617 ("Update to ratified state") of 225 225 riscv-svvptc. 226 226 227 + - const: zaamo 228 + description: | 229 + The standard Zaamo extension for atomic memory operations as 230 + ratified at commit e87412e621f1 ("integrate Zaamo and Zalrsc text 231 + (#1304)") of the unprivileged ISA specification. 232 + 227 233 - const: zabha 228 234 description: | 229 235 The Zabha extension for Byte and Halfword Atomic Memory Operations ··· 241 235 The Zacas extension for Atomic Compare-and-Swap (CAS) instructions 242 236 is supported as ratified at commit 5059e0ca641c ("update to 243 237 ratified") of the riscv-zacas. 238 + 239 + - const: zalrsc 240 + description: | 241 + The standard Zalrsc extension for load-reserved/store-conditional as 242 + ratified at commit e87412e621f1 ("integrate Zaamo and Zalrsc text 243 + (#1304)") of the unprivileged ISA specification. 244 244 245 245 - const: zawrs 246 246 description: | ··· 340 328 The standard Zfa extension for additional floating point 341 329 instructions, as ratified in commit 056b6ff ("Zfa is ratified") of 342 330 riscv-isa-manual. 331 + 332 + - const: zfbfmin 333 + description: 334 + The standard Zfbfmin extension which provides minimal support for 335 + 16-bit half-precision brain floating-point instructions, as ratified 336 + in commit 4dc23d62 ("Added Chapter title to BF16") of riscv-isa-manual. 343 337 344 338 - const: zfh 345 339 description: ··· 543 525 in commit 6f702a2 ("Vector extensions are now ratified") of 544 526 riscv-v-spec. 545 527 528 + - const: zvfbfmin 529 + description: 530 + The standard Zvfbfmin extension for minimal support for vectored 531 + 16-bit half-precision brain floating-point instructions, as ratified 532 + in commit 4dc23d62 ("Added Chapter title to BF16") of riscv-isa-manual. 533 + 534 + - const: zvfbfwma 535 + description: 536 + The standard Zvfbfwma extension for vectored half-precision brain 537 + floating-point widening multiply-accumulate instructions, as ratified 538 + in commit 4dc23d62 ("Added Chapter title to BF16") of riscv-isa-manual. 539 + 546 540 - const: zvfh 547 541 description: 548 542 The standard Zvfh extension for vectored half-precision ··· 669 639 https://github.com/T-head-Semi/thead-extension-spec/blob/95358cb2cca9489361c61d335e03d3134b14133f/xtheadvector.adoc. 670 640 671 641 allOf: 642 + - if: 643 + contains: 644 + const: d 645 + then: 646 + contains: 647 + const: f 672 648 # Zcb depends on Zca 673 649 - if: 674 650 contains: ··· 709 673 then: 710 674 contains: 711 675 const: zca 676 + # Zfbfmin depends on F 677 + - if: 678 + contains: 679 + const: zfbfmin 680 + then: 681 + contains: 682 + const: f 683 + # Zvfbfmin depends on V or Zve32f 684 + - if: 685 + contains: 686 + const: zvfbfmin 687 + then: 688 + oneOf: 689 + - contains: 690 + const: v 691 + - contains: 692 + const: zve32f 693 + # Zvfbfwma depends on Zfbfmin and Zvfbfmin 694 + - if: 695 + contains: 696 + const: zvfbfwma 697 + then: 698 + allOf: 699 + - contains: 700 + const: zfbfmin 701 + - contains: 702 + const: zvfbfmin 703 + # Zacas depends on Zaamo 704 + - if: 705 + contains: 706 + const: zacas 707 + then: 708 + contains: 709 + const: zaamo 710 + 711 + - if: 712 + contains: 713 + const: zve32x 714 + then: 715 + contains: 716 + const: zicsr 717 + 718 + - if: 719 + contains: 720 + const: zve32f 721 + then: 722 + allOf: 723 + - contains: 724 + const: f 725 + - contains: 726 + const: zve32x 727 + 728 + - if: 729 + contains: 730 + const: zve64x 731 + then: 732 + contains: 733 + const: zve32x 734 + 735 + - if: 736 + contains: 737 + const: zve64f 738 + then: 739 + allOf: 740 + - contains: 741 + const: f 742 + - contains: 743 + const: zve32f 744 + - contains: 745 + const: zve64x 746 + 747 + - if: 748 + contains: 749 + const: zve64d 750 + then: 751 + allOf: 752 + - contains: 753 + const: d 754 + - contains: 755 + const: zve64f 756 + 757 + - if: 758 + contains: 759 + anyOf: 760 + - const: zvbc 761 + - const: zvkn 762 + - const: zvknc 763 + - const: zvkng 764 + - const: zvknhb 765 + - const: zvksc 766 + then: 767 + contains: 768 + anyOf: 769 + - const: v 770 + - const: zve64x 771 + 772 + - if: 773 + contains: 774 + anyOf: 775 + - const: zvbb 776 + - const: zvkb 777 + - const: zvkg 778 + - const: zvkned 779 + - const: zvknha 780 + - const: zvksed 781 + - const: zvksh 782 + - const: zvks 783 + - const: zvkt 784 + then: 785 + contains: 786 + anyOf: 787 + - const: v 788 + - const: zve32x 712 789 713 790 allOf: 714 791 # Zcf extension does not exist on rv64
-1
arch/riscv/Kbuild
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 2 3 3 obj-y += kernel/ mm/ net/ 4 - obj-$(CONFIG_BUILTIN_DTB) += boot/dts/ 5 4 obj-$(CONFIG_CRYPTO) += crypto/ 6 5 obj-y += errata/ 7 6 obj-$(CONFIG_KVM) += kvm/
+56 -28
arch/riscv/Kconfig
··· 65 65 select ARCH_SUPPORTS_ATOMIC_RMW 66 66 select ARCH_SUPPORTS_CFI_CLANG 67 67 select ARCH_SUPPORTS_DEBUG_PAGEALLOC if MMU 68 + select ARCH_SUPPORTS_HUGE_PFNMAP if TRANSPARENT_HUGEPAGE 68 69 select ARCH_SUPPORTS_HUGETLBFS if MMU 69 70 # LLD >= 14: https://github.com/llvm/llvm-project/issues/50505 70 71 select ARCH_SUPPORTS_LTO_CLANG if LLD_VERSION >= 140000 ··· 154 153 select HAVE_DYNAMIC_FTRACE_WITH_ARGS if HAVE_DYNAMIC_FTRACE 155 154 select HAVE_FTRACE_GRAPH_FUNC 156 155 select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL 157 - select HAVE_FUNCTION_GRAPH_TRACER 156 + select HAVE_FUNCTION_GRAPH_TRACER if HAVE_DYNAMIC_FTRACE_WITH_ARGS 158 157 select HAVE_FUNCTION_GRAPH_FREGS 159 158 select HAVE_FUNCTION_TRACER if !XIP_KERNEL && !PREEMPTION 160 159 select HAVE_EBPF_JIT if MMU ··· 206 205 select PCI_DOMAINS_GENERIC if PCI 207 206 select PCI_ECAM if (ACPI && PCI) 208 207 select PCI_MSI if PCI 208 + select RELOCATABLE if !MMU && !PHYS_RAM_BASE_FIXED 209 209 select RISCV_ALTERNATIVE if !XIP_KERNEL 210 210 select RISCV_APLIC 211 211 select RISCV_IMSIC ··· 293 291 help 294 292 Select if you want MMU-based virtualised addressing space 295 293 support by paged memory management. If unsure, say 'Y'. 296 - 297 - config PAGE_OFFSET 298 - hex 299 - default 0x80000000 if !MMU && RISCV_M_MODE 300 - default 0x80200000 if !MMU 301 - default 0xc0000000 if 32BIT 302 - default 0xff60000000000000 if 64BIT 303 294 304 295 config KASAN_SHADOW_OFFSET 305 296 hex ··· 565 570 help 566 571 Adds "C" to the ISA subsets that the toolchain is allowed to emit 567 572 when building Linux, which results in compressed instructions in the 568 - Linux binary. 573 + Linux binary. This option produces a kernel that will not run on 574 + systems that do not support compressed instructions. 569 575 570 576 If you don't know what to do here, say Y. 571 577 ··· 587 591 depends on RISCV_ALTERNATIVE 588 592 default y 589 593 help 590 - Allow kernel to detect the Svnapot ISA-extension dynamically at boot 591 - time and enable its usage. 594 + Enable support for the Svnapot ISA-extension when it is detected 595 + at boot. 592 596 593 597 The Svnapot extension is used to mark contiguous PTEs as a range 594 598 of contiguous virtual-to-physical translations for a naturally ··· 606 610 depends on RISCV_ALTERNATIVE 607 611 default y 608 612 help 609 - Adds support to dynamically detect the presence of the Svpbmt 610 - ISA-extension (Supervisor-mode: page-based memory types) and 611 - enable its usage. 613 + Add support for the Svpbmt ISA-extension (Supervisor-mode: 614 + page-based memory types) in the kernel when it is detected at boot. 612 615 613 616 The memory type for a page contains a combination of attributes 614 617 that indicate the cacheability, idempotency, and ordering ··· 626 631 depends on AS_HAS_OPTION_ARCH 627 632 628 633 config RISCV_ISA_V 629 - bool "VECTOR extension support" 634 + bool "Vector extension support" 630 635 depends on TOOLCHAIN_HAS_V 631 636 depends on FPU 632 637 select DYNAMIC_SIGFRAME 633 638 default y 634 639 help 635 - Say N here if you want to disable all vector related procedure 636 - in the kernel. 640 + Add support for the Vector extension when it is detected at boot. 641 + When this option is disabled, neither the kernel nor userspace may 642 + use vector procedures. 637 643 638 644 If you don't know what to do here, say Y. 639 645 ··· 733 737 def_bool $(as-instr, .option arch$(comma) +v$(comma) +zvkb) 734 738 depends on AS_HAS_OPTION_ARCH 735 739 740 + config TOOLCHAIN_HAS_ZBA 741 + bool 742 + default y 743 + depends on !64BIT || $(cc-option,-mabi=lp64 -march=rv64ima_zba) 744 + depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zba) 745 + depends on LLD_VERSION >= 150000 || LD_VERSION >= 23900 746 + depends on AS_HAS_OPTION_ARCH 747 + 736 748 config RISCV_ISA_ZBA 737 749 bool "Zba extension support for bit manipulation instructions" 738 750 default y ··· 755 751 756 752 config RISCV_ISA_ZBB 757 753 bool "Zbb extension support for bit manipulation instructions" 758 - depends on TOOLCHAIN_HAS_ZBB 759 754 depends on RISCV_ALTERNATIVE 760 755 default y 761 756 help 762 - Adds support to dynamically detect the presence of the ZBB 763 - extension (basic bit manipulation) and enable its usage. 757 + Add support for enabling optimisations in the kernel when the 758 + Zbb extension is detected at boot. Some optimisations may 759 + additionally depend on toolchain support for Zbb. 764 760 765 761 The Zbb extension provides instructions to accelerate a number 766 762 of bit-specific operations (count bit population, sign extending, ··· 791 787 792 788 If you don't know what to do here, say Y. 793 789 790 + config TOOLCHAIN_HAS_ZBKB 791 + bool 792 + default y 793 + depends on !64BIT || $(cc-option,-mabi=lp64 -march=rv64ima_zbkb) 794 + depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zbkb) 795 + depends on LLD_VERSION >= 150000 || LD_VERSION >= 23900 796 + depends on AS_HAS_OPTION_ARCH 797 + 798 + config RISCV_ISA_ZBKB 799 + bool "Zbkb extension support for bit manipulation instructions" 800 + depends on TOOLCHAIN_HAS_ZBKB 801 + depends on RISCV_ALTERNATIVE 802 + default y 803 + help 804 + Adds support to dynamically detect the presence of the ZBKB 805 + extension (bit manipulation for cryptography) and enable its usage. 806 + 807 + The Zbkb extension provides instructions to accelerate a number 808 + of common cryptography operations (pack, zip, etc). 809 + 810 + If you don't know what to do here, say Y. 811 + 794 812 config RISCV_ISA_ZICBOM 795 813 bool "Zicbom extension support for non-coherent DMA operation" 796 814 depends on MMU ··· 821 795 select RISCV_DMA_NONCOHERENT 822 796 select DMA_DIRECT_REMAP 823 797 help 824 - Adds support to dynamically detect the presence of the ZICBOM 825 - extension (Cache Block Management Operations) and enable its 826 - usage. 798 + Add support for the Zicbom extension (Cache Block Management 799 + Operations) and enable its use in the kernel when it is detected 800 + at boot. 827 801 828 802 The Zicbom extension can be used to handle for example 829 803 non-coherent DMA support on devices that need it. ··· 836 810 default y 837 811 help 838 812 Enable the use of the Zicboz extension (cbo.zero instruction) 839 - when available. 813 + in the kernel when it is detected at boot. 840 814 841 815 The Zicboz extension is used for faster zeroing of memory. 842 816 ··· 874 848 bool "FPU support" 875 849 default y 876 850 help 877 - Say N here if you want to disable all floating-point related procedure 878 - in the kernel. 851 + Add support for floating point operations when an FPU is detected at 852 + boot. When this option is disabled, neither the kernel nor userspace 853 + may use the floating point unit. 879 854 880 855 If you don't know what to do here, say Y. 881 856 ··· 1106 1079 1107 1080 config RELOCATABLE 1108 1081 bool "Build a relocatable kernel" 1109 - depends on MMU && 64BIT && !XIP_KERNEL 1082 + depends on !XIP_KERNEL 1110 1083 select MODULE_SECTIONS if MODULES 1111 1084 help 1112 1085 This builds a kernel as a Position Independent Executable (PIE), ··· 1300 1273 config BUILTIN_DTB 1301 1274 bool "Built-in device tree" 1302 1275 depends on OF && NONPORTABLE 1276 + select GENERIC_BUILTIN_DTB 1303 1277 help 1304 1278 Build a device tree into the Linux image. 1305 1279 This option should be selected if no bootloader is being used. 1306 1280 If unsure, say N. 1307 1281 1308 1282 1309 - config BUILTIN_DTB_SOURCE 1283 + config BUILTIN_DTB_NAME 1310 1284 string "Built-in device tree source" 1311 1285 depends on BUILTIN_DTB 1312 1286 help
-2
arch/riscv/Kconfig.socs
··· 59 59 60 60 config ARCH_VIRT 61 61 bool "QEMU Virt Machine" 62 - select CLINT_TIMER if RISCV_M_MODE 63 62 select POWER_RESET 64 63 select POWER_RESET_SYSCON 65 64 select POWER_RESET_SYSCON_POWEROFF ··· 78 79 config SOC_CANAAN_K210 79 80 bool "Canaan Kendryte K210 SoC" 80 81 depends on !MMU && ARCH_CANAAN 81 - select CLINT_TIMER if RISCV_M_MODE 82 82 select ARCH_HAS_RESET_CONTROLLER 83 83 select PINCTRL 84 84 select COMMON_CLK
-1
arch/riscv/Makefile
··· 98 98 CC_FLAGS_FPU := -march=$(shell echo $(riscv-march-y) | sed -E 's/(rv32ima|rv64ima)([^v_]*)v?/\1\2/') 99 99 100 100 KBUILD_CFLAGS += -mno-save-restore 101 - KBUILD_CFLAGS += -DCONFIG_PAGE_OFFSET=$(CONFIG_PAGE_OFFSET) 102 101 103 102 ifeq ($(CONFIG_CMODEL_MEDLOW),y) 104 103 KBUILD_CFLAGS += -mcmodel=medlow
-2
arch/riscv/boot/dts/Makefile
··· 8 8 subdir-y += spacemit 9 9 subdir-y += starfive 10 10 subdir-y += thead 11 - 12 - obj-$(CONFIG_BUILTIN_DTB) := $(addsuffix .dtb.o, $(CONFIG_BUILTIN_DTB_SOURCE))
-2
arch/riscv/configs/defconfig
··· 26 26 # CONFIG_SYSFS_SYSCALL is not set 27 27 CONFIG_PROFILING=y 28 28 CONFIG_ARCH_MICROCHIP=y 29 - CONFIG_ARCH_RENESAS=y 30 29 CONFIG_ARCH_SIFIVE=y 31 30 CONFIG_ARCH_SOPHGO=y 32 31 CONFIG_ARCH_SPACEMIT=y ··· 201 202 CONFIG_USB_OTG=y 202 203 CONFIG_USB_XHCI_HCD=y 203 204 CONFIG_USB_XHCI_PLATFORM=y 204 - # CONFIG_USB_XHCI_RCAR is not set 205 205 CONFIG_USB_EHCI_HCD=y 206 206 CONFIG_USB_EHCI_HCD_PLATFORM=y 207 207 CONFIG_USB_OHCI_HCD=y
+1 -1
arch/riscv/configs/nommu_k210_defconfig
··· 35 35 CONFIG_CMDLINE="earlycon console=ttySIF0" 36 36 CONFIG_CMDLINE_FORCE=y 37 37 CONFIG_BUILTIN_DTB=y 38 - CONFIG_BUILTIN_DTB_SOURCE="canaan/k210_generic" 38 + CONFIG_BUILTIN_DTB_NAME="canaan/k210_generic" 39 39 # CONFIG_SECCOMP is not set 40 40 # CONFIG_STACKPROTECTOR is not set 41 41 # CONFIG_GCC_PLUGINS is not set
+1 -1
arch/riscv/configs/nommu_k210_sdcard_defconfig
··· 27 27 CONFIG_CMDLINE="earlycon console=ttySIF0 root=/dev/mmcblk0p1 rootwait ro" 28 28 CONFIG_CMDLINE_FORCE=y 29 29 CONFIG_BUILTIN_DTB=y 30 - CONFIG_BUILTIN_DTB_SOURCE="canaan/k210_generic" 30 + CONFIG_BUILTIN_DTB_NAME="canaan/k210_generic" 31 31 # CONFIG_SECCOMP is not set 32 32 # CONFIG_STACKPROTECTOR is not set 33 33 # CONFIG_GCC_PLUGINS is not set
+5 -1
arch/riscv/errata/Makefile
··· 1 1 ifdef CONFIG_RELOCATABLE 2 - KBUILD_CFLAGS += -fno-pie 2 + # We can't use PIC/PIE when handling early-boot errata parsing, as the kernel 3 + # doesn't have a GOT setup at that point. So instead just use medany: it's 4 + # usually position-independent, so it should be good enough for the errata 5 + # handling. 6 + KBUILD_CFLAGS += -fno-pie -mcmodel=medany 3 7 endif 4 8 5 9 ifdef CONFIG_RISCV_ALTERNATIVE_EARLY
+3 -3
arch/riscv/include/asm/arch_hweight.h
··· 19 19 20 20 static __always_inline unsigned int __arch_hweight32(unsigned int w) 21 21 { 22 - #ifdef CONFIG_RISCV_ISA_ZBB 22 + #if defined(CONFIG_RISCV_ISA_ZBB) && defined(CONFIG_TOOLCHAIN_HAS_ZBB) 23 23 asm goto(ALTERNATIVE("j %l[legacy]", "nop", 0, 24 24 RISCV_ISA_EXT_ZBB, 1) 25 25 : : : : legacy); ··· 50 50 #if BITS_PER_LONG == 64 51 51 static __always_inline unsigned long __arch_hweight64(__u64 w) 52 52 { 53 - # ifdef CONFIG_RISCV_ISA_ZBB 53 + #if defined(CONFIG_RISCV_ISA_ZBB) && defined(CONFIG_TOOLCHAIN_HAS_ZBB) 54 54 asm goto(ALTERNATIVE("j %l[legacy]", "nop", 0, 55 55 RISCV_ISA_EXT_ZBB, 1) 56 56 : : : : legacy); ··· 64 64 return w; 65 65 66 66 legacy: 67 - # endif 67 + #endif 68 68 return __sw_hweight64(w); 69 69 } 70 70 #else /* BITS_PER_LONG == 64 */
+1
arch/riscv/include/asm/asm.h
··· 27 27 #define REG_ASM __REG_SEL(.dword, .word) 28 28 #define SZREG __REG_SEL(8, 4) 29 29 #define LGREG __REG_SEL(3, 2) 30 + #define SRLI __REG_SEL(srliw, srli) 30 31 31 32 #if __SIZEOF_POINTER__ == 8 32 33 #ifdef __ASSEMBLY__
+2 -2
arch/riscv/include/asm/bitops.h
··· 15 15 #include <asm/barrier.h> 16 16 #include <asm/bitsperlong.h> 17 17 18 - #if !defined(CONFIG_RISCV_ISA_ZBB) || defined(NO_ALTERNATIVE) 18 + #if !(defined(CONFIG_RISCV_ISA_ZBB) && defined(CONFIG_TOOLCHAIN_HAS_ZBB)) || defined(NO_ALTERNATIVE) 19 19 #include <asm-generic/bitops/__ffs.h> 20 20 #include <asm-generic/bitops/__fls.h> 21 21 #include <asm-generic/bitops/ffs.h> ··· 175 175 variable_fls(x_); \ 176 176 }) 177 177 178 - #endif /* !defined(CONFIG_RISCV_ISA_ZBB) || defined(NO_ALTERNATIVE) */ 178 + #endif /* !(defined(CONFIG_RISCV_ISA_ZBB) && defined(CONFIG_TOOLCHAIN_HAS_ZBB)) || defined(NO_ALTERNATIVE) */ 179 179 180 180 #include <asm-generic/bitops/ffz.h> 181 181 #include <asm-generic/bitops/fls64.h>
+1 -2
arch/riscv/include/asm/checksum.h
··· 49 49 * ZBB only saves three instructions on 32-bit and five on 64-bit so not 50 50 * worth checking if supported without Alternatives. 51 51 */ 52 - if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && 53 - IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) { 52 + if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && IS_ENABLED(CONFIG_TOOLCHAIN_HAS_ZBB)) { 54 53 unsigned long fold_temp; 55 54 56 55 asm goto(ALTERNATIVE("j %l[no_zbb]", "nop", 0,
+35 -3
arch/riscv/include/asm/cmpxchg.h
··· 365 365 { 366 366 unsigned long tmp; 367 367 368 + u32 *__ptr32b; 369 + ulong __s, __val, __mask; 370 + 368 371 asm goto(ALTERNATIVE("j %l[no_zawrs]", "nop", 369 372 0, RISCV_ISA_EXT_ZAWRS, 1) 370 373 : : : : no_zawrs); 371 374 372 375 switch (size) { 373 376 case 1: 374 - fallthrough; 377 + __ptr32b = (u32 *)((ulong)(ptr) & ~0x3); 378 + __s = ((ulong)(ptr) & 0x3) * BITS_PER_BYTE; 379 + __val = val << __s; 380 + __mask = 0xff << __s; 381 + 382 + asm volatile( 383 + " lr.w %0, %1\n" 384 + " and %0, %0, %3\n" 385 + " xor %0, %0, %2\n" 386 + " bnez %0, 1f\n" 387 + ZAWRS_WRS_NTO "\n" 388 + "1:" 389 + : "=&r" (tmp), "+A" (*(__ptr32b)) 390 + : "r" (__val), "r" (__mask) 391 + : "memory"); 392 + break; 375 393 case 2: 376 - /* RISC-V doesn't have lr instructions on byte and half-word. */ 377 - goto no_zawrs; 394 + __ptr32b = (u32 *)((ulong)(ptr) & ~0x3); 395 + __s = ((ulong)(ptr) & 0x2) * BITS_PER_BYTE; 396 + __val = val << __s; 397 + __mask = 0xffff << __s; 398 + 399 + asm volatile( 400 + " lr.w %0, %1\n" 401 + " and %0, %0, %3\n" 402 + " xor %0, %0, %2\n" 403 + " bnez %0, 1f\n" 404 + ZAWRS_WRS_NTO "\n" 405 + "1:" 406 + : "=&r" (tmp), "+A" (*(__ptr32b)) 407 + : "r" (__val), "r" (__mask) 408 + : "memory"); 409 + break; 378 410 case 4: 379 411 asm volatile( 380 412 " lr.w %0, %1\n"
+5 -2
arch/riscv/include/asm/cpufeature.h
··· 56 56 #define __RISCV_ISA_EXT_BUNDLE(_name, _bundled_exts) \ 57 57 _RISCV_ISA_EXT_DATA(_name, RISCV_ISA_EXT_INVALID, _bundled_exts, \ 58 58 ARRAY_SIZE(_bundled_exts), NULL) 59 + #define __RISCV_ISA_EXT_BUNDLE_VALIDATE(_name, _bundled_exts, _validate) \ 60 + _RISCV_ISA_EXT_DATA(_name, RISCV_ISA_EXT_INVALID, _bundled_exts, \ 61 + ARRAY_SIZE(_bundled_exts), _validate) 59 62 60 63 /* Used to declare extensions that are a superset of other extensions (Zvbb for instance) */ 61 64 #define __RISCV_ISA_EXT_SUPERSET(_name, _id, _sub_exts) \ ··· 66 63 #define __RISCV_ISA_EXT_SUPERSET_VALIDATE(_name, _id, _sub_exts, _validate) \ 67 64 _RISCV_ISA_EXT_DATA(_name, _id, _sub_exts, ARRAY_SIZE(_sub_exts), _validate) 68 65 69 - bool check_unaligned_access_emulated_all_cpus(void); 66 + bool __init check_unaligned_access_emulated_all_cpus(void); 70 67 #if defined(CONFIG_RISCV_SCALAR_MISALIGNED) 71 68 void check_unaligned_access_emulated(struct work_struct *work __always_unused); 72 69 void unaligned_emulation_finish(void); ··· 79 76 } 80 77 #endif 81 78 82 - bool check_vector_unaligned_access_emulated_all_cpus(void); 79 + bool __init check_vector_unaligned_access_emulated_all_cpus(void); 83 80 #if defined(CONFIG_RISCV_VECTOR_MISALIGNED) 84 81 void check_vector_unaligned_access_emulated(struct work_struct *work __always_unused); 85 82 DECLARE_PER_CPU(long, vector_misaligned_access);
+3 -4
arch/riscv/include/asm/ftrace.h
··· 79 79 #define AUIPC_RA (0x00000097) 80 80 #define JALR_T0 (0x000282e7) 81 81 #define AUIPC_T0 (0x00000297) 82 - #define NOP4 (0x00000013) 83 82 84 83 #define to_jalr_t0(offset) \ 85 84 (((offset & JALR_OFFSET_MASK) << JALR_SHIFT) | JALR_T0) ··· 91 92 #define make_call_t0(caller, callee, call) \ 92 93 do { \ 93 94 unsigned int offset = \ 94 - (unsigned long) callee - (unsigned long) caller; \ 95 + (unsigned long) (callee) - (unsigned long) (caller); \ 95 96 call[0] = to_auipc_t0(offset); \ 96 97 call[1] = to_jalr_t0(offset); \ 97 98 } while (0) ··· 107 108 #define make_call_ra(caller, callee, call) \ 108 109 do { \ 109 110 unsigned int offset = \ 110 - (unsigned long) callee - (unsigned long) caller; \ 111 + (unsigned long) (callee) - (unsigned long) (caller); \ 111 112 call[0] = to_auipc_ra(offset); \ 112 113 call[1] = to_jalr_ra(offset); \ 113 114 } while (0) ··· 206 207 { 207 208 struct __arch_ftrace_regs *afregs = arch_ftrace_regs(fregs); 208 209 209 - memcpy(&regs->a0, afregs->args, sizeof(afregs->args)); 210 + memcpy(&regs->a_regs, afregs->args, sizeof(afregs->args)); 210 211 regs->epc = afregs->epc; 211 212 regs->ra = afregs->ra; 212 213 regs->sp = afregs->sp;
+5
arch/riscv/include/asm/hwcap.h
··· 100 100 #define RISCV_ISA_EXT_ZICCRSE 91 101 101 #define RISCV_ISA_EXT_SVADE 92 102 102 #define RISCV_ISA_EXT_SVADU 93 103 + #define RISCV_ISA_EXT_ZFBFMIN 94 104 + #define RISCV_ISA_EXT_ZVFBFMIN 95 105 + #define RISCV_ISA_EXT_ZVFBFWMA 96 106 + #define RISCV_ISA_EXT_ZAAMO 97 107 + #define RISCV_ISA_EXT_ZALRSC 98 103 108 104 109 #define RISCV_ISA_EXT_XLINUXENVCFG 127 105 110
+1 -1
arch/riscv/include/asm/hwprobe.h
··· 8 8 9 9 #include <uapi/asm/hwprobe.h> 10 10 11 - #define RISCV_HWPROBE_MAX_KEY 11 11 + #define RISCV_HWPROBE_MAX_KEY 12 12 12 13 13 static inline bool riscv_hwprobe_key_is_valid(__s64 key) 14 14 {
+3
arch/riscv/include/asm/insn-def.h
··· 199 199 #define RISCV_PAUSE ".4byte 0x100000f" 200 200 #define ZAWRS_WRS_NTO ".4byte 0x00d00073" 201 201 #define ZAWRS_WRS_STO ".4byte 0x01d00073" 202 + #define RISCV_NOP4 ".4byte 0x00000013" 203 + 204 + #define RISCV_INSN_NOP4 _AC(0x00000013, U) 202 205 203 206 #endif /* __ASM_INSN_DEF_H */
+12 -15
arch/riscv/include/asm/page.h
··· 24 24 * When not using MMU this corresponds to the first free page in 25 25 * physical memory (aligned on a page boundary). 26 26 */ 27 - #ifdef CONFIG_64BIT 28 27 #ifdef CONFIG_MMU 29 - #define PAGE_OFFSET kernel_map.page_offset 30 - #else 31 - #define PAGE_OFFSET _AC(CONFIG_PAGE_OFFSET, UL) 32 - #endif 33 - /* 34 - * By default, CONFIG_PAGE_OFFSET value corresponds to SV57 address space so 35 - * define the PAGE_OFFSET value for SV48 and SV39. 36 - */ 28 + #ifdef CONFIG_64BIT 29 + #define PAGE_OFFSET_L5 _AC(0xff60000000000000, UL) 37 30 #define PAGE_OFFSET_L4 _AC(0xffffaf8000000000, UL) 38 31 #define PAGE_OFFSET_L3 _AC(0xffffffd600000000, UL) 32 + #ifdef CONFIG_XIP_KERNEL 33 + #define PAGE_OFFSET PAGE_OFFSET_L3 39 34 #else 40 - #define PAGE_OFFSET _AC(CONFIG_PAGE_OFFSET, UL) 35 + #define PAGE_OFFSET kernel_map.page_offset 36 + #endif /* CONFIG_XIP_KERNEL */ 37 + #else 38 + #define PAGE_OFFSET _AC(0xc0000000, UL) 41 39 #endif /* CONFIG_64BIT */ 40 + #else 41 + #define PAGE_OFFSET ((unsigned long)phys_ram_base) 42 + #endif /* CONFIG_MMU */ 42 43 43 44 #ifndef __ASSEMBLY__ 44 45 ··· 96 95 #define MIN_MEMBLOCK_ADDR 0 97 96 #endif 98 97 99 - #ifdef CONFIG_MMU 100 98 #define ARCH_PFN_OFFSET (PFN_DOWN((unsigned long)phys_ram_base)) 101 - #else 102 - #define ARCH_PFN_OFFSET (PAGE_OFFSET >> PAGE_SHIFT) 103 - #endif /* CONFIG_MMU */ 104 99 105 100 struct kernel_mapping { 106 - unsigned long page_offset; 107 101 unsigned long virt_addr; 108 102 unsigned long virt_offset; 109 103 uintptr_t phys_addr; ··· 112 116 uintptr_t xiprom; 113 117 uintptr_t xiprom_sz; 114 118 #else 119 + unsigned long page_offset; 115 120 unsigned long va_kernel_pa_offset; 116 121 #endif 117 122 };
+54 -1
arch/riscv/include/asm/pgtable.h
··· 12 12 #include <asm/pgtable-bits.h> 13 13 14 14 #ifndef CONFIG_MMU 15 - #define KERNEL_LINK_ADDR PAGE_OFFSET 15 + #ifdef CONFIG_RELOCATABLE 16 + #define KERNEL_LINK_ADDR UL(0) 17 + #else 18 + #define KERNEL_LINK_ADDR _AC(CONFIG_PHYS_RAM_BASE, UL) 19 + #endif 16 20 #define KERN_VIRT_SIZE (UL(-1)) 17 21 #else 18 22 ··· 344 340 } 345 341 346 342 #define mk_pte(page, prot) pfn_pte(page_to_pfn(page), prot) 343 + 344 + #define pte_pgprot pte_pgprot 345 + static inline pgprot_t pte_pgprot(pte_t pte) 346 + { 347 + unsigned long pfn = pte_pfn(pte); 348 + 349 + return __pgprot(pte_val(pfn_pte(pfn, __pgprot(0))) ^ pte_val(pte)); 350 + } 347 351 348 352 static inline int pte_present(pte_t pte) 349 353 { ··· 686 674 return __pmd(pte_val(pte)); 687 675 } 688 676 677 + static inline pud_t pte_pud(pte_t pte) 678 + { 679 + return __pud(pte_val(pte)); 680 + } 681 + 689 682 static inline pmd_t pmd_mkhuge(pmd_t pmd) 690 683 { 691 684 return pmd; ··· 714 697 static inline unsigned long pud_pfn(pud_t pud) 715 698 { 716 699 return ((__pud_to_phys(pud) & PUD_MASK) >> PAGE_SHIFT); 700 + } 701 + 702 + #define pmd_pgprot pmd_pgprot 703 + static inline pgprot_t pmd_pgprot(pmd_t pmd) 704 + { 705 + return pte_pgprot(pmd_pte(pmd)); 706 + } 707 + 708 + #define pud_pgprot pud_pgprot 709 + static inline pgprot_t pud_pgprot(pud_t pud) 710 + { 711 + return pte_pgprot(pud_pte(pud)); 717 712 } 718 713 719 714 static inline pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot) ··· 796 767 { 797 768 return pte_pmd(pte_mkdevmap(pmd_pte(pmd))); 798 769 } 770 + 771 + #ifdef CONFIG_ARCH_SUPPORTS_PMD_PFNMAP 772 + static inline bool pmd_special(pmd_t pmd) 773 + { 774 + return pte_special(pmd_pte(pmd)); 775 + } 776 + 777 + static inline pmd_t pmd_mkspecial(pmd_t pmd) 778 + { 779 + return pte_pmd(pte_mkspecial(pmd_pte(pmd))); 780 + } 781 + #endif 782 + 783 + #ifdef CONFIG_ARCH_SUPPORTS_PUD_PFNMAP 784 + static inline bool pud_special(pud_t pud) 785 + { 786 + return pte_special(pud_pte(pud)); 787 + } 788 + 789 + static inline pud_t pud_mkspecial(pud_t pud) 790 + { 791 + return pte_pud(pte_mkspecial(pud_pte(pud))); 792 + } 793 + #endif 799 794 800 795 static inline void set_pmd_at(struct mm_struct *mm, unsigned long addr, 801 796 pmd_t *pmdp, pmd_t pmd)
+10 -8
arch/riscv/include/asm/ptrace.h
··· 23 23 unsigned long t2; 24 24 unsigned long s0; 25 25 unsigned long s1; 26 - unsigned long a0; 27 - unsigned long a1; 28 - unsigned long a2; 29 - unsigned long a3; 30 - unsigned long a4; 31 - unsigned long a5; 32 - unsigned long a6; 33 - unsigned long a7; 26 + struct_group(a_regs, 27 + unsigned long a0; 28 + unsigned long a1; 29 + unsigned long a2; 30 + unsigned long a3; 31 + unsigned long a4; 32 + unsigned long a5; 33 + unsigned long a6; 34 + unsigned long a7; 35 + ); 34 36 unsigned long s2; 35 37 unsigned long s3; 36 38 unsigned long s4;
+268
arch/riscv/include/asm/runtime-const.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _ASM_RISCV_RUNTIME_CONST_H 3 + #define _ASM_RISCV_RUNTIME_CONST_H 4 + 5 + #include <asm/asm.h> 6 + #include <asm/alternative.h> 7 + #include <asm/cacheflush.h> 8 + #include <asm/insn-def.h> 9 + #include <linux/memory.h> 10 + #include <asm/text-patching.h> 11 + 12 + #include <linux/uaccess.h> 13 + 14 + #ifdef CONFIG_32BIT 15 + #define runtime_const_ptr(sym) \ 16 + ({ \ 17 + typeof(sym) __ret; \ 18 + asm_inline(".option push\n\t" \ 19 + ".option norvc\n\t" \ 20 + "1:\t" \ 21 + "lui %[__ret],0x89abd\n\t" \ 22 + "addi %[__ret],%[__ret],-0x211\n\t" \ 23 + ".option pop\n\t" \ 24 + ".pushsection runtime_ptr_" #sym ",\"a\"\n\t" \ 25 + ".long 1b - .\n\t" \ 26 + ".popsection" \ 27 + : [__ret] "=r" (__ret)); \ 28 + __ret; \ 29 + }) 30 + #else 31 + /* 32 + * Loading 64-bit constants into a register from immediates is a non-trivial 33 + * task on riscv64. To get it somewhat performant, load 32 bits into two 34 + * different registers and then combine the results. 35 + * 36 + * If the processor supports the Zbkb extension, we can combine the final 37 + * "slli,slli,srli,add" into the single "pack" instruction. If the processor 38 + * doesn't support Zbkb but does support the Zbb extension, we can 39 + * combine the final "slli,srli,add" into one instruction "add.uw". 40 + */ 41 + #define RISCV_RUNTIME_CONST_64_PREAMBLE \ 42 + ".option push\n\t" \ 43 + ".option norvc\n\t" \ 44 + "1:\t" \ 45 + "lui %[__ret],0x89abd\n\t" \ 46 + "lui %[__tmp],0x1234\n\t" \ 47 + "addiw %[__ret],%[__ret],-0x211\n\t" \ 48 + "addiw %[__tmp],%[__tmp],0x567\n\t" \ 49 + 50 + #define RISCV_RUNTIME_CONST_64_BASE \ 51 + "slli %[__tmp],%[__tmp],32\n\t" \ 52 + "slli %[__ret],%[__ret],32\n\t" \ 53 + "srli %[__ret],%[__ret],32\n\t" \ 54 + "add %[__ret],%[__ret],%[__tmp]\n\t" \ 55 + 56 + #define RISCV_RUNTIME_CONST_64_ZBA \ 57 + ".option push\n\t" \ 58 + ".option arch,+zba\n\t" \ 59 + ".option norvc\n\t" \ 60 + "slli %[__tmp],%[__tmp],32\n\t" \ 61 + "add.uw %[__ret],%[__ret],%[__tmp]\n\t" \ 62 + "nop\n\t" \ 63 + "nop\n\t" \ 64 + ".option pop\n\t" \ 65 + 66 + #define RISCV_RUNTIME_CONST_64_ZBKB \ 67 + ".option push\n\t" \ 68 + ".option arch,+zbkb\n\t" \ 69 + ".option norvc\n\t" \ 70 + "pack %[__ret],%[__ret],%[__tmp]\n\t" \ 71 + "nop\n\t" \ 72 + "nop\n\t" \ 73 + "nop\n\t" \ 74 + ".option pop\n\t" \ 75 + 76 + #define RISCV_RUNTIME_CONST_64_POSTAMBLE(sym) \ 77 + ".option pop\n\t" \ 78 + ".pushsection runtime_ptr_" #sym ",\"a\"\n\t" \ 79 + ".long 1b - .\n\t" \ 80 + ".popsection" \ 81 + 82 + #if defined(CONFIG_RISCV_ISA_ZBA) && defined(CONFIG_TOOLCHAIN_HAS_ZBA) \ 83 + && defined(CONFIG_RISCV_ISA_ZBKB) 84 + #define runtime_const_ptr(sym) \ 85 + ({ \ 86 + typeof(sym) __ret, __tmp; \ 87 + asm_inline(RISCV_RUNTIME_CONST_64_PREAMBLE \ 88 + ALTERNATIVE_2( \ 89 + RISCV_RUNTIME_CONST_64_BASE, \ 90 + RISCV_RUNTIME_CONST_64_ZBA, \ 91 + 0, RISCV_ISA_EXT_ZBA, 1, \ 92 + RISCV_RUNTIME_CONST_64_ZBKB, \ 93 + 0, RISCV_ISA_EXT_ZBKB, 1 \ 94 + ) \ 95 + RISCV_RUNTIME_CONST_64_POSTAMBLE(sym) \ 96 + : [__ret] "=r" (__ret), [__tmp] "=r" (__tmp)); \ 97 + __ret; \ 98 + }) 99 + #elif defined(CONFIG_RISCV_ISA_ZBA) && defined(CONFIG_TOOLCHAIN_HAS_ZBA) 100 + #define runtime_const_ptr(sym) \ 101 + ({ \ 102 + typeof(sym) __ret, __tmp; \ 103 + asm_inline(RISCV_RUNTIME_CONST_64_PREAMBLE \ 104 + ALTERNATIVE( \ 105 + RISCV_RUNTIME_CONST_64_BASE, \ 106 + RISCV_RUNTIME_CONST_64_ZBA, \ 107 + 0, RISCV_ISA_EXT_ZBA, 1 \ 108 + ) \ 109 + RISCV_RUNTIME_CONST_64_POSTAMBLE(sym) \ 110 + : [__ret] "=r" (__ret), [__tmp] "=r" (__tmp)); \ 111 + __ret; \ 112 + }) 113 + #elif defined(CONFIG_RISCV_ISA_ZBKB) 114 + #define runtime_const_ptr(sym) \ 115 + ({ \ 116 + typeof(sym) __ret, __tmp; \ 117 + asm_inline(RISCV_RUNTIME_CONST_64_PREAMBLE \ 118 + ALTERNATIVE( \ 119 + RISCV_RUNTIME_CONST_64_BASE, \ 120 + RISCV_RUNTIME_CONST_64_ZBKB, \ 121 + 0, RISCV_ISA_EXT_ZBKB, 1 \ 122 + ) \ 123 + RISCV_RUNTIME_CONST_64_POSTAMBLE(sym) \ 124 + : [__ret] "=r" (__ret), [__tmp] "=r" (__tmp)); \ 125 + __ret; \ 126 + }) 127 + #else 128 + #define runtime_const_ptr(sym) \ 129 + ({ \ 130 + typeof(sym) __ret, __tmp; \ 131 + asm_inline(RISCV_RUNTIME_CONST_64_PREAMBLE \ 132 + RISCV_RUNTIME_CONST_64_BASE \ 133 + RISCV_RUNTIME_CONST_64_POSTAMBLE(sym) \ 134 + : [__ret] "=r" (__ret), [__tmp] "=r" (__tmp)); \ 135 + __ret; \ 136 + }) 137 + #endif 138 + #endif 139 + 140 + #define runtime_const_shift_right_32(val, sym) \ 141 + ({ \ 142 + u32 __ret; \ 143 + asm_inline(".option push\n\t" \ 144 + ".option norvc\n\t" \ 145 + "1:\t" \ 146 + SRLI " %[__ret],%[__val],12\n\t" \ 147 + ".option pop\n\t" \ 148 + ".pushsection runtime_shift_" #sym ",\"a\"\n\t" \ 149 + ".long 1b - .\n\t" \ 150 + ".popsection" \ 151 + : [__ret] "=r" (__ret) \ 152 + : [__val] "r" (val)); \ 153 + __ret; \ 154 + }) 155 + 156 + #define runtime_const_init(type, sym) do { \ 157 + extern s32 __start_runtime_##type##_##sym[]; \ 158 + extern s32 __stop_runtime_##type##_##sym[]; \ 159 + \ 160 + runtime_const_fixup(__runtime_fixup_##type, \ 161 + (unsigned long)(sym), \ 162 + __start_runtime_##type##_##sym, \ 163 + __stop_runtime_##type##_##sym); \ 164 + } while (0) 165 + 166 + static inline void __runtime_fixup_caches(void *where, unsigned int insns) 167 + { 168 + /* On riscv there are currently only cache-wide flushes so va is ignored. */ 169 + __always_unused uintptr_t va = (uintptr_t)where; 170 + 171 + flush_icache_range(va, va + 4 * insns); 172 + } 173 + 174 + /* 175 + * The 32-bit immediate is stored in a lui+addi pairing. 176 + * lui holds the upper 20 bits of the immediate in the first 20 bits of the instruction. 177 + * addi holds the lower 12 bits of the immediate in the first 12 bits of the instruction. 178 + */ 179 + static inline void __runtime_fixup_32(__le16 *lui_parcel, __le16 *addi_parcel, unsigned int val) 180 + { 181 + unsigned int lower_immediate, upper_immediate; 182 + u32 lui_insn, addi_insn, addi_insn_mask; 183 + __le32 lui_res, addi_res; 184 + 185 + /* Mask out upper 12 bit of addi */ 186 + addi_insn_mask = 0x000fffff; 187 + 188 + lui_insn = (u32)le16_to_cpu(lui_parcel[0]) | (u32)le16_to_cpu(lui_parcel[1]) << 16; 189 + addi_insn = (u32)le16_to_cpu(addi_parcel[0]) | (u32)le16_to_cpu(addi_parcel[1]) << 16; 190 + 191 + lower_immediate = sign_extend32(val, 11); 192 + upper_immediate = (val - lower_immediate); 193 + 194 + if (upper_immediate & 0xfffff000) { 195 + /* replace upper 20 bits of lui with upper immediate */ 196 + lui_insn &= 0x00000fff; 197 + lui_insn |= upper_immediate & 0xfffff000; 198 + } else { 199 + /* replace lui with nop if immediate is small enough to fit in addi */ 200 + lui_insn = RISCV_INSN_NOP4; 201 + /* 202 + * lui is being skipped, so do a load instead of an add. A load 203 + * is performed by adding with the x0 register. Setting rs to 204 + * zero with the following mask will accomplish this goal. 205 + */ 206 + addi_insn_mask &= 0x07fff; 207 + } 208 + 209 + if (lower_immediate & 0x00000fff) { 210 + /* replace upper 12 bits of addi with lower 12 bits of val */ 211 + addi_insn &= addi_insn_mask; 212 + addi_insn |= (lower_immediate & 0x00000fff) << 20; 213 + } else { 214 + /* replace addi with nop if lower_immediate is empty */ 215 + addi_insn = RISCV_INSN_NOP4; 216 + } 217 + 218 + addi_res = cpu_to_le32(addi_insn); 219 + lui_res = cpu_to_le32(lui_insn); 220 + mutex_lock(&text_mutex); 221 + patch_insn_write(addi_parcel, &addi_res, sizeof(addi_res)); 222 + patch_insn_write(lui_parcel, &lui_res, sizeof(lui_res)); 223 + mutex_unlock(&text_mutex); 224 + } 225 + 226 + static inline void __runtime_fixup_ptr(void *where, unsigned long val) 227 + { 228 + #ifdef CONFIG_32BIT 229 + __runtime_fixup_32(where, where + 4, val); 230 + __runtime_fixup_caches(where, 2); 231 + #else 232 + __runtime_fixup_32(where, where + 8, val); 233 + __runtime_fixup_32(where + 4, where + 12, val >> 32); 234 + __runtime_fixup_caches(where, 4); 235 + #endif 236 + } 237 + 238 + /* 239 + * Replace the least significant 5 bits of the srli/srliw immediate that is 240 + * located at bits 20-24 241 + */ 242 + static inline void __runtime_fixup_shift(void *where, unsigned long val) 243 + { 244 + __le16 *parcel = where; 245 + __le32 res; 246 + u32 insn; 247 + 248 + insn = (u32)le16_to_cpu(parcel[0]) | (u32)le16_to_cpu(parcel[1]) << 16; 249 + 250 + insn &= 0xfe0fffff; 251 + insn |= (val & 0b11111) << 20; 252 + 253 + res = cpu_to_le32(insn); 254 + mutex_lock(&text_mutex); 255 + patch_text_nosync(where, &res, sizeof(insn)); 256 + mutex_unlock(&text_mutex); 257 + } 258 + 259 + static inline void runtime_const_fixup(void (*fn)(void *, unsigned long), 260 + unsigned long val, s32 *start, s32 *end) 261 + { 262 + while (start < end) { 263 + fn(*start + (void *)start, val); 264 + start++; 265 + } 266 + } 267 + 268 + #endif /* _ASM_RISCV_RUNTIME_CONST_H */
+4
arch/riscv/include/asm/suspend.h
··· 18 18 unsigned long ie; 19 19 #ifdef CONFIG_MMU 20 20 unsigned long satp; 21 + unsigned long stimecmp; 22 + #if __riscv_xlen < 64 23 + unsigned long stimecmph; 24 + #endif 21 25 #endif 22 26 }; 23 27
+9
arch/riscv/include/uapi/asm/hwprobe.h
··· 73 73 #define RISCV_HWPROBE_EXT_ZCMOP (1ULL << 47) 74 74 #define RISCV_HWPROBE_EXT_ZAWRS (1ULL << 48) 75 75 #define RISCV_HWPROBE_EXT_SUPM (1ULL << 49) 76 + #define RISCV_HWPROBE_EXT_ZICNTR (1ULL << 50) 77 + #define RISCV_HWPROBE_EXT_ZIHPM (1ULL << 51) 78 + #define RISCV_HWPROBE_EXT_ZFBFMIN (1ULL << 52) 79 + #define RISCV_HWPROBE_EXT_ZVFBFMIN (1ULL << 53) 80 + #define RISCV_HWPROBE_EXT_ZVFBFWMA (1ULL << 54) 81 + #define RISCV_HWPROBE_EXT_ZICBOM (1ULL << 55) 82 + #define RISCV_HWPROBE_EXT_ZAAMO (1ULL << 56) 83 + #define RISCV_HWPROBE_EXT_ZALRSC (1ULL << 57) 76 84 #define RISCV_HWPROBE_KEY_CPUPERF_0 5 77 85 #define RISCV_HWPROBE_MISALIGNED_UNKNOWN (0 << 0) 78 86 #define RISCV_HWPROBE_MISALIGNED_EMULATED (1 << 0) ··· 103 95 #define RISCV_HWPROBE_MISALIGNED_VECTOR_FAST 3 104 96 #define RISCV_HWPROBE_MISALIGNED_VECTOR_UNSUPPORTED 4 105 97 #define RISCV_HWPROBE_KEY_VENDOR_EXT_THEAD_0 11 98 + #define RISCV_HWPROBE_KEY_ZICBOM_BLOCK_SIZE 12 106 99 /* Increase RISCV_HWPROBE_MAX_KEY when adding items. */ 107 100 108 101 /* Flags */
+2
arch/riscv/include/uapi/asm/kvm.h
··· 182 182 KVM_RISCV_ISA_EXT_SVVPTC, 183 183 KVM_RISCV_ISA_EXT_ZABHA, 184 184 KVM_RISCV_ISA_EXT_ZICCRSE, 185 + KVM_RISCV_ISA_EXT_ZAAMO, 186 + KVM_RISCV_ISA_EXT_ZALRSC, 185 187 KVM_RISCV_ISA_EXT_MAX, 186 188 }; 187 189
-1
arch/riscv/kernel/asm-offsets.c
··· 36 36 OFFSET(TASK_THREAD_S11, task_struct, thread.s[11]); 37 37 38 38 OFFSET(TASK_TI_CPU, task_struct, thread_info.cpu); 39 - OFFSET(TASK_TI_FLAGS, task_struct, thread_info.flags); 40 39 OFFSET(TASK_TI_PREEMPT_COUNT, task_struct, thread_info.preempt_count); 41 40 OFFSET(TASK_TI_KERNEL_SP, task_struct, thread_info.kernel_sp); 42 41 OFFSET(TASK_TI_USER_SP, task_struct, thread_info.user_sp);
+154 -43
arch/riscv/kernel/cpufeature.c
··· 32 32 #define NUM_ALPHA_EXTS ('z' - 'a' + 1) 33 33 34 34 static bool any_cpu_has_zicboz; 35 + static bool any_cpu_has_zicbom; 35 36 36 37 unsigned long elf_hwcap __read_mostly; 37 38 ··· 54 53 */ 55 54 unsigned long riscv_isa_extension_base(const unsigned long *isa_bitmap) 56 55 { 57 - if (!isa_bitmap) 58 - return riscv_isa[0]; 59 - return isa_bitmap[0]; 56 + return !isa_bitmap ? riscv_isa[0] : isa_bitmap[0]; 60 57 } 61 58 EXPORT_SYMBOL_GPL(riscv_isa_extension_base); 62 59 ··· 75 76 if (bit >= RISCV_ISA_EXT_MAX) 76 77 return false; 77 78 78 - return test_bit(bit, bmap) ? true : false; 79 + return test_bit(bit, bmap); 79 80 } 80 81 EXPORT_SYMBOL_GPL(__riscv_isa_extension_available); 82 + 83 + static int riscv_ext_f_depends(const struct riscv_isa_ext_data *data, 84 + const unsigned long *isa_bitmap) 85 + { 86 + if (__riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_f)) 87 + return 0; 88 + 89 + return -EPROBE_DEFER; 90 + } 81 91 82 92 static int riscv_ext_zicbom_validate(const struct riscv_isa_ext_data *data, 83 93 const unsigned long *isa_bitmap) ··· 99 91 pr_err("Zicbom disabled as cbom-block-size present, but is not a power-of-2\n"); 100 92 return -EINVAL; 101 93 } 94 + 95 + any_cpu_has_zicbom = true; 102 96 return 0; 103 97 } 104 98 ··· 116 106 return -EINVAL; 117 107 } 118 108 any_cpu_has_zicboz = true; 109 + return 0; 110 + } 111 + 112 + static int riscv_ext_f_validate(const struct riscv_isa_ext_data *data, 113 + const unsigned long *isa_bitmap) 114 + { 115 + if (!IS_ENABLED(CONFIG_FPU)) 116 + return -EINVAL; 117 + 118 + /* 119 + * Due to extension ordering, d is checked before f, so no deferral 120 + * is required. 121 + */ 122 + if (!__riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_d)) { 123 + pr_warn_once("This kernel does not support systems with F but not D\n"); 124 + return -EINVAL; 125 + } 126 + 127 + return 0; 128 + } 129 + 130 + static int riscv_ext_d_validate(const struct riscv_isa_ext_data *data, 131 + const unsigned long *isa_bitmap) 132 + { 133 + if (!IS_ENABLED(CONFIG_FPU)) 134 + return -EINVAL; 135 + 136 + return 0; 137 + } 138 + 139 + static int riscv_ext_vector_x_validate(const struct riscv_isa_ext_data *data, 140 + const unsigned long *isa_bitmap) 141 + { 142 + if (!IS_ENABLED(CONFIG_RISCV_ISA_V)) 143 + return -EINVAL; 144 + 145 + return 0; 146 + } 147 + 148 + static int riscv_ext_vector_float_validate(const struct riscv_isa_ext_data *data, 149 + const unsigned long *isa_bitmap) 150 + { 151 + if (!IS_ENABLED(CONFIG_RISCV_ISA_V)) 152 + return -EINVAL; 153 + 154 + if (!IS_ENABLED(CONFIG_FPU)) 155 + return -EINVAL; 156 + 157 + /* 158 + * The kernel doesn't support systems that don't implement both of 159 + * F and D, so if any of the vector extensions that do floating point 160 + * are to be usable, both floating point extensions need to be usable. 161 + * 162 + * Since this function validates vector only, and v/Zve* are probed 163 + * after f/d, there's no need for a deferral here. 164 + */ 165 + if (!__riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_d)) 166 + return -EINVAL; 167 + 168 + return 0; 169 + } 170 + 171 + static int riscv_ext_vector_crypto_validate(const struct riscv_isa_ext_data *data, 172 + const unsigned long *isa_bitmap) 173 + { 174 + if (!IS_ENABLED(CONFIG_RISCV_ISA_V)) 175 + return -EINVAL; 176 + 177 + /* 178 + * It isn't the kernel's job to check that the binding is correct, so 179 + * it should be enough to check that any of the vector extensions are 180 + * enabled, which in-turn means that vector is usable in this kernel 181 + */ 182 + if (!__riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_ZVE32X)) 183 + return -EPROBE_DEFER; 184 + 119 185 return 0; 120 186 } 121 187 ··· 226 140 return -EPROBE_DEFER; 227 141 } 228 142 143 + static int riscv_vector_f_validate(const struct riscv_isa_ext_data *data, 144 + const unsigned long *isa_bitmap) 145 + { 146 + if (!IS_ENABLED(CONFIG_RISCV_ISA_V)) 147 + return -EINVAL; 148 + 149 + if (__riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_ZVE32F)) 150 + return 0; 151 + 152 + return -EPROBE_DEFER; 153 + } 154 + 155 + static int riscv_ext_zvfbfwma_validate(const struct riscv_isa_ext_data *data, 156 + const unsigned long *isa_bitmap) 157 + { 158 + if (__riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_ZFBFMIN) && 159 + __riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_ZVFBFMIN)) 160 + return 0; 161 + 162 + return -EPROBE_DEFER; 163 + } 164 + 229 165 static int riscv_ext_svadu_validate(const struct riscv_isa_ext_data *data, 230 166 const unsigned long *isa_bitmap) 231 167 { ··· 257 149 258 150 return 0; 259 151 } 152 + 153 + static const unsigned int riscv_a_exts[] = { 154 + RISCV_ISA_EXT_ZAAMO, 155 + RISCV_ISA_EXT_ZALRSC, 156 + }; 260 157 261 158 static const unsigned int riscv_zk_bundled_exts[] = { 262 159 RISCV_ISA_EXT_ZBKB, ··· 434 321 const struct riscv_isa_ext_data riscv_isa_ext[] = { 435 322 __RISCV_ISA_EXT_DATA(i, RISCV_ISA_EXT_i), 436 323 __RISCV_ISA_EXT_DATA(m, RISCV_ISA_EXT_m), 437 - __RISCV_ISA_EXT_DATA(a, RISCV_ISA_EXT_a), 438 - __RISCV_ISA_EXT_DATA(f, RISCV_ISA_EXT_f), 439 - __RISCV_ISA_EXT_DATA(d, RISCV_ISA_EXT_d), 324 + __RISCV_ISA_EXT_SUPERSET(a, RISCV_ISA_EXT_a, riscv_a_exts), 325 + __RISCV_ISA_EXT_DATA_VALIDATE(f, RISCV_ISA_EXT_f, riscv_ext_f_validate), 326 + __RISCV_ISA_EXT_DATA_VALIDATE(d, RISCV_ISA_EXT_d, riscv_ext_d_validate), 440 327 __RISCV_ISA_EXT_DATA(q, RISCV_ISA_EXT_q), 441 328 __RISCV_ISA_EXT_SUPERSET(c, RISCV_ISA_EXT_c, riscv_c_exts), 442 - __RISCV_ISA_EXT_SUPERSET(v, RISCV_ISA_EXT_v, riscv_v_exts), 329 + __RISCV_ISA_EXT_SUPERSET_VALIDATE(v, RISCV_ISA_EXT_v, riscv_v_exts, riscv_ext_vector_float_validate), 443 330 __RISCV_ISA_EXT_DATA(h, RISCV_ISA_EXT_h), 444 - __RISCV_ISA_EXT_SUPERSET_VALIDATE(zicbom, RISCV_ISA_EXT_ZICBOM, riscv_xlinuxenvcfg_exts, 445 - riscv_ext_zicbom_validate), 446 - __RISCV_ISA_EXT_SUPERSET_VALIDATE(zicboz, RISCV_ISA_EXT_ZICBOZ, riscv_xlinuxenvcfg_exts, 447 - riscv_ext_zicboz_validate), 331 + __RISCV_ISA_EXT_SUPERSET_VALIDATE(zicbom, RISCV_ISA_EXT_ZICBOM, riscv_xlinuxenvcfg_exts, riscv_ext_zicbom_validate), 332 + __RISCV_ISA_EXT_SUPERSET_VALIDATE(zicboz, RISCV_ISA_EXT_ZICBOZ, riscv_xlinuxenvcfg_exts, riscv_ext_zicboz_validate), 448 333 __RISCV_ISA_EXT_DATA(ziccrse, RISCV_ISA_EXT_ZICCRSE), 449 334 __RISCV_ISA_EXT_DATA(zicntr, RISCV_ISA_EXT_ZICNTR), 450 335 __RISCV_ISA_EXT_DATA(zicond, RISCV_ISA_EXT_ZICOND), ··· 452 341 __RISCV_ISA_EXT_DATA(zihintpause, RISCV_ISA_EXT_ZIHINTPAUSE), 453 342 __RISCV_ISA_EXT_DATA(zihpm, RISCV_ISA_EXT_ZIHPM), 454 343 __RISCV_ISA_EXT_DATA(zimop, RISCV_ISA_EXT_ZIMOP), 344 + __RISCV_ISA_EXT_DATA(zaamo, RISCV_ISA_EXT_ZAAMO), 455 345 __RISCV_ISA_EXT_DATA(zabha, RISCV_ISA_EXT_ZABHA), 456 346 __RISCV_ISA_EXT_DATA(zacas, RISCV_ISA_EXT_ZACAS), 347 + __RISCV_ISA_EXT_DATA(zalrsc, RISCV_ISA_EXT_ZALRSC), 457 348 __RISCV_ISA_EXT_DATA(zawrs, RISCV_ISA_EXT_ZAWRS), 458 349 __RISCV_ISA_EXT_DATA(zfa, RISCV_ISA_EXT_ZFA), 350 + __RISCV_ISA_EXT_DATA_VALIDATE(zfbfmin, RISCV_ISA_EXT_ZFBFMIN, riscv_ext_f_depends), 459 351 __RISCV_ISA_EXT_DATA(zfh, RISCV_ISA_EXT_ZFH), 460 352 __RISCV_ISA_EXT_DATA(zfhmin, RISCV_ISA_EXT_ZFHMIN), 461 353 __RISCV_ISA_EXT_DATA(zca, RISCV_ISA_EXT_ZCA), ··· 484 370 __RISCV_ISA_EXT_DATA(zksed, RISCV_ISA_EXT_ZKSED), 485 371 __RISCV_ISA_EXT_DATA(zksh, RISCV_ISA_EXT_ZKSH), 486 372 __RISCV_ISA_EXT_DATA(ztso, RISCV_ISA_EXT_ZTSO), 487 - __RISCV_ISA_EXT_SUPERSET(zvbb, RISCV_ISA_EXT_ZVBB, riscv_zvbb_exts), 488 - __RISCV_ISA_EXT_DATA(zvbc, RISCV_ISA_EXT_ZVBC), 489 - __RISCV_ISA_EXT_SUPERSET(zve32f, RISCV_ISA_EXT_ZVE32F, riscv_zve32f_exts), 490 - __RISCV_ISA_EXT_DATA(zve32x, RISCV_ISA_EXT_ZVE32X), 491 - __RISCV_ISA_EXT_SUPERSET(zve64d, RISCV_ISA_EXT_ZVE64D, riscv_zve64d_exts), 492 - __RISCV_ISA_EXT_SUPERSET(zve64f, RISCV_ISA_EXT_ZVE64F, riscv_zve64f_exts), 493 - __RISCV_ISA_EXT_SUPERSET(zve64x, RISCV_ISA_EXT_ZVE64X, riscv_zve64x_exts), 373 + __RISCV_ISA_EXT_SUPERSET_VALIDATE(zvbb, RISCV_ISA_EXT_ZVBB, riscv_zvbb_exts, riscv_ext_vector_crypto_validate), 374 + __RISCV_ISA_EXT_DATA_VALIDATE(zvbc, RISCV_ISA_EXT_ZVBC, riscv_ext_vector_crypto_validate), 375 + __RISCV_ISA_EXT_SUPERSET_VALIDATE(zve32f, RISCV_ISA_EXT_ZVE32F, riscv_zve32f_exts, riscv_ext_vector_float_validate), 376 + __RISCV_ISA_EXT_DATA_VALIDATE(zve32x, RISCV_ISA_EXT_ZVE32X, riscv_ext_vector_x_validate), 377 + __RISCV_ISA_EXT_SUPERSET_VALIDATE(zve64d, RISCV_ISA_EXT_ZVE64D, riscv_zve64d_exts, riscv_ext_vector_float_validate), 378 + __RISCV_ISA_EXT_SUPERSET_VALIDATE(zve64f, RISCV_ISA_EXT_ZVE64F, riscv_zve64f_exts, riscv_ext_vector_float_validate), 379 + __RISCV_ISA_EXT_SUPERSET_VALIDATE(zve64x, RISCV_ISA_EXT_ZVE64X, riscv_zve64x_exts, riscv_ext_vector_x_validate), 380 + __RISCV_ISA_EXT_DATA_VALIDATE(zvfbfmin, RISCV_ISA_EXT_ZVFBFMIN, riscv_vector_f_validate), 381 + __RISCV_ISA_EXT_DATA_VALIDATE(zvfbfwma, RISCV_ISA_EXT_ZVFBFWMA, riscv_ext_zvfbfwma_validate), 494 382 __RISCV_ISA_EXT_DATA(zvfh, RISCV_ISA_EXT_ZVFH), 495 383 __RISCV_ISA_EXT_DATA(zvfhmin, RISCV_ISA_EXT_ZVFHMIN), 496 - __RISCV_ISA_EXT_DATA(zvkb, RISCV_ISA_EXT_ZVKB), 497 - __RISCV_ISA_EXT_DATA(zvkg, RISCV_ISA_EXT_ZVKG), 498 - __RISCV_ISA_EXT_BUNDLE(zvkn, riscv_zvkn_bundled_exts), 499 - __RISCV_ISA_EXT_BUNDLE(zvknc, riscv_zvknc_bundled_exts), 500 - __RISCV_ISA_EXT_DATA(zvkned, RISCV_ISA_EXT_ZVKNED), 501 - __RISCV_ISA_EXT_BUNDLE(zvkng, riscv_zvkng_bundled_exts), 502 - __RISCV_ISA_EXT_DATA(zvknha, RISCV_ISA_EXT_ZVKNHA), 503 - __RISCV_ISA_EXT_DATA(zvknhb, RISCV_ISA_EXT_ZVKNHB), 504 - __RISCV_ISA_EXT_BUNDLE(zvks, riscv_zvks_bundled_exts), 505 - __RISCV_ISA_EXT_BUNDLE(zvksc, riscv_zvksc_bundled_exts), 506 - __RISCV_ISA_EXT_DATA(zvksed, RISCV_ISA_EXT_ZVKSED), 507 - __RISCV_ISA_EXT_DATA(zvksh, RISCV_ISA_EXT_ZVKSH), 508 - __RISCV_ISA_EXT_BUNDLE(zvksg, riscv_zvksg_bundled_exts), 509 - __RISCV_ISA_EXT_DATA(zvkt, RISCV_ISA_EXT_ZVKT), 384 + __RISCV_ISA_EXT_DATA_VALIDATE(zvkb, RISCV_ISA_EXT_ZVKB, riscv_ext_vector_crypto_validate), 385 + __RISCV_ISA_EXT_DATA_VALIDATE(zvkg, RISCV_ISA_EXT_ZVKG, riscv_ext_vector_crypto_validate), 386 + __RISCV_ISA_EXT_BUNDLE_VALIDATE(zvkn, riscv_zvkn_bundled_exts, riscv_ext_vector_crypto_validate), 387 + __RISCV_ISA_EXT_BUNDLE_VALIDATE(zvknc, riscv_zvknc_bundled_exts, riscv_ext_vector_crypto_validate), 388 + __RISCV_ISA_EXT_DATA_VALIDATE(zvkned, RISCV_ISA_EXT_ZVKNED, riscv_ext_vector_crypto_validate), 389 + __RISCV_ISA_EXT_BUNDLE_VALIDATE(zvkng, riscv_zvkng_bundled_exts, riscv_ext_vector_crypto_validate), 390 + __RISCV_ISA_EXT_DATA_VALIDATE(zvknha, RISCV_ISA_EXT_ZVKNHA, riscv_ext_vector_crypto_validate), 391 + __RISCV_ISA_EXT_DATA_VALIDATE(zvknhb, RISCV_ISA_EXT_ZVKNHB, riscv_ext_vector_crypto_validate), 392 + __RISCV_ISA_EXT_BUNDLE_VALIDATE(zvks, riscv_zvks_bundled_exts, riscv_ext_vector_crypto_validate), 393 + __RISCV_ISA_EXT_BUNDLE_VALIDATE(zvksc, riscv_zvksc_bundled_exts, riscv_ext_vector_crypto_validate), 394 + __RISCV_ISA_EXT_DATA_VALIDATE(zvksed, RISCV_ISA_EXT_ZVKSED, riscv_ext_vector_crypto_validate), 395 + __RISCV_ISA_EXT_DATA_VALIDATE(zvksh, RISCV_ISA_EXT_ZVKSH, riscv_ext_vector_crypto_validate), 396 + __RISCV_ISA_EXT_BUNDLE_VALIDATE(zvksg, riscv_zvksg_bundled_exts, riscv_ext_vector_crypto_validate), 397 + __RISCV_ISA_EXT_DATA_VALIDATE(zvkt, RISCV_ISA_EXT_ZVKT, riscv_ext_vector_crypto_validate), 510 398 __RISCV_ISA_EXT_DATA(smaia, RISCV_ISA_EXT_SMAIA), 511 399 __RISCV_ISA_EXT_DATA(smmpm, RISCV_ISA_EXT_SMMPM), 512 400 __RISCV_ISA_EXT_SUPERSET(smnpm, RISCV_ISA_EXT_SMNPM, riscv_xlinuxenvcfg_exts), ··· 1076 960 riscv_v_setup_vsize(); 1077 961 } 1078 962 1079 - if (elf_hwcap & COMPAT_HWCAP_ISA_V) { 1080 - /* 1081 - * ISA string in device tree might have 'v' flag, but 1082 - * CONFIG_RISCV_ISA_V is disabled in kernel. 1083 - * Clear V flag in elf_hwcap if CONFIG_RISCV_ISA_V is disabled. 1084 - */ 1085 - if (!IS_ENABLED(CONFIG_RISCV_ISA_V)) 1086 - elf_hwcap &= ~COMPAT_HWCAP_ISA_V; 1087 - } 1088 - 1089 963 memset(print_str, 0, sizeof(print_str)); 1090 964 for (i = 0, j = 0; i < NUM_ALPHA_EXTS; i++) 1091 965 if (riscv_isa[0] & BIT_MASK(i)) ··· 1107 1001 current->thread.envcfg |= ENVCFG_CBZE; 1108 1002 else if (any_cpu_has_zicboz) 1109 1003 pr_warn("Zicboz disabled as it is unavailable on some harts\n"); 1004 + 1005 + if (riscv_has_extension_unlikely(RISCV_ISA_EXT_ZICBOM)) 1006 + current->thread.envcfg |= ENVCFG_CBCFE; 1007 + else if (any_cpu_has_zicbom) 1008 + pr_warn("Zicbom disabled as it is unavailable on some harts\n"); 1110 1009 } 1111 1010 1112 1011 #ifdef CONFIG_RISCV_ALTERNATIVE
+3
arch/riscv/kernel/elf_kexec.c
··· 468 468 case R_RISCV_ALIGN: 469 469 case R_RISCV_RELAX: 470 470 break; 471 + case R_RISCV_64: 472 + *(u64 *)loc = val; 473 + break; 471 474 default: 472 475 pr_err("Unknown rela relocation: %d\n", r_type); 473 476 return -ENOEXEC;
+3 -3
arch/riscv/kernel/ftrace.c
··· 36 36 unsigned int *expected) 37 37 { 38 38 unsigned int replaced[2]; 39 - unsigned int nops[2] = {NOP4, NOP4}; 39 + unsigned int nops[2] = {RISCV_INSN_NOP4, RISCV_INSN_NOP4}; 40 40 41 41 /* we expect nops at the hook position */ 42 42 if (!expected) ··· 68 68 bool enable, bool ra) 69 69 { 70 70 unsigned int call[2]; 71 - unsigned int nops[2] = {NOP4, NOP4}; 71 + unsigned int nops[2] = {RISCV_INSN_NOP4, RISCV_INSN_NOP4}; 72 72 73 73 if (ra) 74 74 make_call_ra(hook_pos, target, call); ··· 97 97 int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec, 98 98 unsigned long addr) 99 99 { 100 - unsigned int nops[2] = {NOP4, NOP4}; 100 + unsigned int nops[2] = {RISCV_INSN_NOP4, RISCV_INSN_NOP4}; 101 101 102 102 if (patch_insn_write((void *)rec->ip, nops, MCOUNT_INSN_SIZE)) 103 103 return -EPERM;
+2 -2
arch/riscv/kernel/jump_label.c
··· 11 11 #include <asm/bug.h> 12 12 #include <asm/cacheflush.h> 13 13 #include <asm/text-patching.h> 14 + #include <asm/insn-def.h> 14 15 15 - #define RISCV_INSN_NOP 0x00000013U 16 16 #define RISCV_INSN_JAL 0x0000006fU 17 17 18 18 bool arch_jump_label_transform_queue(struct jump_entry *entry, ··· 33 33 (((u32)offset & GENMASK(10, 1)) << (21 - 1)) | 34 34 (((u32)offset & GENMASK(20, 20)) << (31 - 20)); 35 35 } else { 36 - insn = RISCV_INSN_NOP; 36 + insn = RISCV_INSN_NOP4; 37 37 } 38 38 39 39 if (early_boot_irqs_disabled) {
+11 -13
arch/riscv/kernel/mcount.S
··· 12 12 #include <asm/asm-offsets.h> 13 13 #include <asm/ftrace.h> 14 14 15 - #define ABI_SIZE_ON_STACK 80 16 - 17 15 .text 18 16 19 17 .macro SAVE_ABI_STATE ··· 26 28 * register if a0 was not saved. 27 29 */ 28 30 .macro SAVE_RET_ABI_STATE 29 - addi sp, sp, -ABI_SIZE_ON_STACK 30 - REG_S ra, 1*SZREG(sp) 31 - REG_S s0, 8*SZREG(sp) 32 - REG_S a0, 10*SZREG(sp) 33 - REG_S a1, 11*SZREG(sp) 34 - addi s0, sp, ABI_SIZE_ON_STACK 31 + addi sp, sp, -FREGS_SIZE_ON_STACK 32 + REG_S ra, FREGS_RA(sp) 33 + REG_S s0, FREGS_S0(sp) 34 + REG_S a0, FREGS_A0(sp) 35 + REG_S a1, FREGS_A1(sp) 36 + addi s0, sp, FREGS_SIZE_ON_STACK 35 37 .endm 36 38 37 39 .macro RESTORE_ABI_STATE ··· 41 43 .endm 42 44 43 45 .macro RESTORE_RET_ABI_STATE 44 - REG_L ra, 1*SZREG(sp) 45 - REG_L s0, 8*SZREG(sp) 46 - REG_L a0, 10*SZREG(sp) 47 - REG_L a1, 11*SZREG(sp) 48 - addi sp, sp, ABI_SIZE_ON_STACK 46 + REG_L ra, FREGS_RA(sp) 47 + REG_L s0, FREGS_S0(sp) 48 + REG_L a0, FREGS_A0(sp) 49 + REG_L a1, FREGS_A1(sp) 50 + addi sp, sp, FREGS_SIZE_ON_STACK 49 51 .endm 50 52 51 53 SYM_TYPED_FUNC_START(ftrace_stub)
-5
arch/riscv/kernel/setup.c
··· 235 235 } else { 236 236 pr_err("No DTB passed to the kernel\n"); 237 237 } 238 - 239 - #ifdef CONFIG_CMDLINE_FORCE 240 - strscpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE); 241 - pr_info("Forcing kernel command line to: %s\n", boot_command_line); 242 - #endif 243 238 } 244 239 245 240 #if defined(CONFIG_RISCV_COMBO_SPINLOCKS)
+2
arch/riscv/kernel/smp.c
··· 48 48 void __init smp_setup_processor_id(void) 49 49 { 50 50 cpuid_to_hartid_map(0) = boot_cpu_hartid; 51 + 52 + pr_info("Booting Linux on hartid %lu\n", boot_cpu_hartid); 51 53 } 52 54 53 55 static DEFINE_PER_CPU_READ_MOSTLY(int, ipi_dummy_dev);
+4
arch/riscv/kernel/smpboot.c
··· 231 231 riscv_ipi_enable(); 232 232 233 233 numa_add_cpu(curr_cpuid); 234 + 235 + pr_debug("CPU%u: Booted secondary hartid %lu\n", curr_cpuid, 236 + cpuid_to_hartid_map(curr_cpuid)); 237 + 234 238 set_cpu_online(curr_cpuid, true); 235 239 236 240 /*
+1 -1
arch/riscv/kernel/stacktrace.c
··· 74 74 &frame->ra); 75 75 if (pc >= (unsigned long)handle_exception && 76 76 pc < (unsigned long)&ret_from_exception_end) { 77 - if (unlikely(!__kernel_text_address(pc) || !fn(arg, pc))) 77 + if (unlikely(!fn(arg, pc))) 78 78 break; 79 79 80 80 pc = ((struct pt_regs *)sp)->epc;
+14
arch/riscv/kernel/suspend.c
··· 30 30 */ 31 31 32 32 #ifdef CONFIG_MMU 33 + if (riscv_has_extension_unlikely(RISCV_ISA_EXT_SSTC)) { 34 + context->stimecmp = csr_read(CSR_STIMECMP); 35 + #if __riscv_xlen < 64 36 + context->stimecmph = csr_read(CSR_STIMECMPH); 37 + #endif 38 + } 39 + 33 40 context->satp = csr_read(CSR_SATP); 34 41 #endif 35 42 } ··· 50 43 csr_write(CSR_IE, context->ie); 51 44 52 45 #ifdef CONFIG_MMU 46 + if (riscv_has_extension_unlikely(RISCV_ISA_EXT_SSTC)) { 47 + csr_write(CSR_STIMECMP, context->stimecmp); 48 + #if __riscv_xlen < 64 49 + csr_write(CSR_STIMECMPH, context->stimecmph); 50 + #endif 51 + } 52 + 53 53 csr_write(CSR_SATP, context->satp); 54 54 #endif 55 55 }
+14 -1
arch/riscv/kernel/sys_hwprobe.c
··· 95 95 * regardless of the kernel's configuration, as no other checks, besides 96 96 * presence in the hart_isa bitmap, are made. 97 97 */ 98 + EXT_KEY(ZAAMO); 98 99 EXT_KEY(ZACAS); 100 + EXT_KEY(ZALRSC); 99 101 EXT_KEY(ZAWRS); 100 102 EXT_KEY(ZBA); 101 103 EXT_KEY(ZBB); ··· 109 107 EXT_KEY(ZCA); 110 108 EXT_KEY(ZCB); 111 109 EXT_KEY(ZCMOP); 110 + EXT_KEY(ZICBOM); 112 111 EXT_KEY(ZICBOZ); 112 + EXT_KEY(ZICNTR); 113 113 EXT_KEY(ZICOND); 114 114 EXT_KEY(ZIHINTNTL); 115 115 EXT_KEY(ZIHINTPAUSE); 116 + EXT_KEY(ZIHPM); 116 117 EXT_KEY(ZIMOP); 117 118 EXT_KEY(ZKND); 118 119 EXT_KEY(ZKNE); ··· 137 132 EXT_KEY(ZVE64D); 138 133 EXT_KEY(ZVE64F); 139 134 EXT_KEY(ZVE64X); 135 + EXT_KEY(ZVFBFMIN); 136 + EXT_KEY(ZVFBFWMA); 140 137 EXT_KEY(ZVFH); 141 138 EXT_KEY(ZVFHMIN); 142 139 EXT_KEY(ZVKB); ··· 155 148 EXT_KEY(ZCD); 156 149 EXT_KEY(ZCF); 157 150 EXT_KEY(ZFA); 151 + EXT_KEY(ZFBFMIN); 158 152 EXT_KEY(ZFH); 159 153 EXT_KEY(ZFHMIN); 160 154 } ··· 169 161 pair->value &= ~missing; 170 162 } 171 163 172 - static bool hwprobe_ext0_has(const struct cpumask *cpus, unsigned long ext) 164 + static bool hwprobe_ext0_has(const struct cpumask *cpus, u64 ext) 173 165 { 174 166 struct riscv_hwprobe pair; 175 167 ··· 286 278 pair->value = 0; 287 279 if (hwprobe_ext0_has(cpus, RISCV_HWPROBE_EXT_ZICBOZ)) 288 280 pair->value = riscv_cboz_block_size; 281 + break; 282 + case RISCV_HWPROBE_KEY_ZICBOM_BLOCK_SIZE: 283 + pair->value = 0; 284 + if (hwprobe_ext0_has(cpus, RISCV_HWPROBE_EXT_ZICBOM)) 285 + pair->value = riscv_cbom_block_size; 289 286 break; 290 287 case RISCV_HWPROBE_KEY_HIGHEST_VIRT_ADDRESS: 291 288 pair->value = user_max_virt_addr();
+4 -10
arch/riscv/kernel/traps_misaligned.c
··· 605 605 kernel_vector_end(); 606 606 } 607 607 608 - bool check_vector_unaligned_access_emulated_all_cpus(void) 608 + bool __init check_vector_unaligned_access_emulated_all_cpus(void) 609 609 { 610 610 int cpu; 611 - 612 - if (!has_vector()) { 613 - for_each_online_cpu(cpu) 614 - per_cpu(vector_misaligned_access, cpu) = RISCV_HWPROBE_MISALIGNED_VECTOR_UNSUPPORTED; 615 - return false; 616 - } 617 611 618 612 schedule_on_each_cpu(check_vector_unaligned_access_emulated); 619 613 ··· 619 625 return true; 620 626 } 621 627 #else 622 - bool check_vector_unaligned_access_emulated_all_cpus(void) 628 + bool __init check_vector_unaligned_access_emulated_all_cpus(void) 623 629 { 624 630 return false; 625 631 } ··· 653 659 } 654 660 } 655 661 656 - bool check_unaligned_access_emulated_all_cpus(void) 662 + bool __init check_unaligned_access_emulated_all_cpus(void) 657 663 { 658 664 int cpu; 659 665 ··· 678 684 return unaligned_ctl; 679 685 } 680 686 #else 681 - bool check_unaligned_access_emulated_all_cpus(void) 687 + bool __init check_unaligned_access_emulated_all_cpus(void) 682 688 { 683 689 return false; 684 690 }
+156 -98
arch/riscv/kernel/unaligned_access_speed.c
··· 24 24 DEFINE_PER_CPU(long, misaligned_access_speed) = RISCV_HWPROBE_MISALIGNED_SCALAR_UNKNOWN; 25 25 DEFINE_PER_CPU(long, vector_misaligned_access) = RISCV_HWPROBE_MISALIGNED_VECTOR_UNSUPPORTED; 26 26 27 - #ifdef CONFIG_RISCV_PROBE_UNALIGNED_ACCESS 27 + static long unaligned_scalar_speed_param = RISCV_HWPROBE_MISALIGNED_SCALAR_UNKNOWN; 28 + static long unaligned_vector_speed_param = RISCV_HWPROBE_MISALIGNED_VECTOR_UNKNOWN; 29 + 28 30 static cpumask_t fast_misaligned_access; 31 + 32 + #ifdef CONFIG_RISCV_PROBE_UNALIGNED_ACCESS 29 33 static int check_unaligned_access(void *param) 30 34 { 31 35 int cpu = smp_processor_id(); ··· 125 121 return 0; 126 122 } 127 123 128 - static void check_unaligned_access_nonboot_cpu(void *param) 124 + static void __init check_unaligned_access_nonboot_cpu(void *param) 129 125 { 130 126 unsigned int cpu = smp_processor_id(); 131 127 struct page **pages = param; ··· 133 129 if (smp_processor_id() != 0) 134 130 check_unaligned_access(pages[cpu]); 135 131 } 132 + 133 + /* Measure unaligned access speed on all CPUs present at boot in parallel. */ 134 + static void __init check_unaligned_access_speed_all_cpus(void) 135 + { 136 + unsigned int cpu; 137 + unsigned int cpu_count = num_possible_cpus(); 138 + struct page **bufs = kcalloc(cpu_count, sizeof(*bufs), GFP_KERNEL); 139 + 140 + if (!bufs) { 141 + pr_warn("Allocation failure, not measuring misaligned performance\n"); 142 + return; 143 + } 144 + 145 + /* 146 + * Allocate separate buffers for each CPU so there's no fighting over 147 + * cache lines. 148 + */ 149 + for_each_cpu(cpu, cpu_online_mask) { 150 + bufs[cpu] = alloc_pages(GFP_KERNEL, MISALIGNED_BUFFER_ORDER); 151 + if (!bufs[cpu]) { 152 + pr_warn("Allocation failure, not measuring misaligned performance\n"); 153 + goto out; 154 + } 155 + } 156 + 157 + /* Check everybody except 0, who stays behind to tend jiffies. */ 158 + on_each_cpu(check_unaligned_access_nonboot_cpu, bufs, 1); 159 + 160 + /* Check core 0. */ 161 + smp_call_on_cpu(0, check_unaligned_access, bufs[0], true); 162 + 163 + out: 164 + for_each_cpu(cpu, cpu_online_mask) { 165 + if (bufs[cpu]) 166 + __free_pages(bufs[cpu], MISALIGNED_BUFFER_ORDER); 167 + } 168 + 169 + kfree(bufs); 170 + } 171 + #else /* CONFIG_RISCV_PROBE_UNALIGNED_ACCESS */ 172 + static void __init check_unaligned_access_speed_all_cpus(void) 173 + { 174 + } 175 + #endif 136 176 137 177 DEFINE_STATIC_KEY_FALSE(fast_unaligned_access_speed_key); 138 178 ··· 223 175 modify_unaligned_access_branches(&fast_and_online, num_online_cpus()); 224 176 } 225 177 226 - static int lock_and_set_unaligned_access_static_branch(void) 178 + static int __init lock_and_set_unaligned_access_static_branch(void) 227 179 { 228 180 cpus_read_lock(); 229 181 set_unaligned_access_static_branches(); ··· 236 188 237 189 static int riscv_online_cpu(unsigned int cpu) 238 190 { 239 - static struct page *buf; 240 - 241 191 /* We are already set since the last check */ 242 - if (per_cpu(misaligned_access_speed, cpu) != RISCV_HWPROBE_MISALIGNED_SCALAR_UNKNOWN) 192 + if (per_cpu(misaligned_access_speed, cpu) != RISCV_HWPROBE_MISALIGNED_SCALAR_UNKNOWN) { 243 193 goto exit; 244 - 245 - check_unaligned_access_emulated(NULL); 246 - buf = alloc_pages(GFP_KERNEL, MISALIGNED_BUFFER_ORDER); 247 - if (!buf) { 248 - pr_warn("Allocation failure, not measuring misaligned performance\n"); 249 - return -ENOMEM; 194 + } else if (unaligned_scalar_speed_param != RISCV_HWPROBE_MISALIGNED_SCALAR_UNKNOWN) { 195 + per_cpu(misaligned_access_speed, cpu) = unaligned_scalar_speed_param; 196 + goto exit; 250 197 } 251 198 252 - check_unaligned_access(buf); 253 - __free_pages(buf, MISALIGNED_BUFFER_ORDER); 199 + #ifdef CONFIG_RISCV_PROBE_UNALIGNED_ACCESS 200 + { 201 + static struct page *buf; 202 + 203 + check_unaligned_access_emulated(NULL); 204 + buf = alloc_pages(GFP_KERNEL, MISALIGNED_BUFFER_ORDER); 205 + if (!buf) { 206 + pr_warn("Allocation failure, not measuring misaligned performance\n"); 207 + return -ENOMEM; 208 + } 209 + 210 + check_unaligned_access(buf); 211 + __free_pages(buf, MISALIGNED_BUFFER_ORDER); 212 + } 213 + #endif 254 214 255 215 exit: 256 216 set_unaligned_access_static_branches(); ··· 272 216 273 217 return 0; 274 218 } 275 - 276 - /* Measure unaligned access speed on all CPUs present at boot in parallel. */ 277 - static int check_unaligned_access_speed_all_cpus(void) 278 - { 279 - unsigned int cpu; 280 - unsigned int cpu_count = num_possible_cpus(); 281 - struct page **bufs = kcalloc(cpu_count, sizeof(*bufs), GFP_KERNEL); 282 - 283 - if (!bufs) { 284 - pr_warn("Allocation failure, not measuring misaligned performance\n"); 285 - return 0; 286 - } 287 - 288 - /* 289 - * Allocate separate buffers for each CPU so there's no fighting over 290 - * cache lines. 291 - */ 292 - for_each_cpu(cpu, cpu_online_mask) { 293 - bufs[cpu] = alloc_pages(GFP_KERNEL, MISALIGNED_BUFFER_ORDER); 294 - if (!bufs[cpu]) { 295 - pr_warn("Allocation failure, not measuring misaligned performance\n"); 296 - goto out; 297 - } 298 - } 299 - 300 - /* Check everybody except 0, who stays behind to tend jiffies. */ 301 - on_each_cpu(check_unaligned_access_nonboot_cpu, bufs, 1); 302 - 303 - /* Check core 0. */ 304 - smp_call_on_cpu(0, check_unaligned_access, bufs[0], true); 305 - 306 - /* 307 - * Setup hotplug callbacks for any new CPUs that come online or go 308 - * offline. 309 - */ 310 - cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "riscv:online", 311 - riscv_online_cpu, riscv_offline_cpu); 312 - 313 - out: 314 - for_each_cpu(cpu, cpu_online_mask) { 315 - if (bufs[cpu]) 316 - __free_pages(bufs[cpu], MISALIGNED_BUFFER_ORDER); 317 - } 318 - 319 - kfree(bufs); 320 - return 0; 321 - } 322 - #else /* CONFIG_RISCV_PROBE_UNALIGNED_ACCESS */ 323 - static int check_unaligned_access_speed_all_cpus(void) 324 - { 325 - return 0; 326 - } 327 - #endif 328 219 329 220 #ifdef CONFIG_RISCV_PROBE_VECTOR_UNALIGNED_ACCESS 330 221 static void check_vector_unaligned_access(struct work_struct *work __always_unused) ··· 352 349 pr_warn("cpu%d: rdtime lacks granularity needed to measure unaligned vector access speed\n", 353 350 cpu); 354 351 355 - return; 352 + goto free; 356 353 } 357 354 358 355 if (word_cycles < byte_cycles) ··· 366 363 (speed == RISCV_HWPROBE_MISALIGNED_VECTOR_FAST) ? "fast" : "slow"); 367 364 368 365 per_cpu(vector_misaligned_access, cpu) = speed; 366 + 367 + free: 368 + __free_pages(page, MISALIGNED_BUFFER_ORDER); 369 369 } 370 + 371 + /* Measure unaligned access speed on all CPUs present at boot in parallel. */ 372 + static int __init vec_check_unaligned_access_speed_all_cpus(void *unused __always_unused) 373 + { 374 + schedule_on_each_cpu(check_vector_unaligned_access); 375 + 376 + return 0; 377 + } 378 + #else /* CONFIG_RISCV_PROBE_VECTOR_UNALIGNED_ACCESS */ 379 + static int __init vec_check_unaligned_access_speed_all_cpus(void *unused __always_unused) 380 + { 381 + return 0; 382 + } 383 + #endif 370 384 371 385 static int riscv_online_cpu_vec(unsigned int cpu) 372 386 { 373 - if (!has_vector()) 387 + if (unaligned_vector_speed_param != RISCV_HWPROBE_MISALIGNED_VECTOR_UNKNOWN) { 388 + per_cpu(vector_misaligned_access, cpu) = unaligned_vector_speed_param; 374 389 return 0; 390 + } 375 391 376 - if (per_cpu(vector_misaligned_access, cpu) != RISCV_HWPROBE_MISALIGNED_VECTOR_UNSUPPORTED) 392 + #ifdef CONFIG_RISCV_PROBE_VECTOR_UNALIGNED_ACCESS 393 + if (per_cpu(vector_misaligned_access, cpu) != RISCV_HWPROBE_MISALIGNED_VECTOR_UNKNOWN) 377 394 return 0; 378 395 379 396 check_vector_unaligned_access_emulated(NULL); 380 397 check_vector_unaligned_access(NULL); 398 + #endif 399 + 381 400 return 0; 382 401 } 383 402 384 - /* Measure unaligned access speed on all CPUs present at boot in parallel. */ 385 - static int vec_check_unaligned_access_speed_all_cpus(void *unused __always_unused) 403 + static const char * const speed_str[] __initconst = { NULL, NULL, "slow", "fast", "unsupported" }; 404 + 405 + static int __init set_unaligned_scalar_speed_param(char *str) 386 406 { 387 - schedule_on_each_cpu(check_vector_unaligned_access); 407 + if (!strcmp(str, speed_str[RISCV_HWPROBE_MISALIGNED_SCALAR_SLOW])) 408 + unaligned_scalar_speed_param = RISCV_HWPROBE_MISALIGNED_SCALAR_SLOW; 409 + else if (!strcmp(str, speed_str[RISCV_HWPROBE_MISALIGNED_SCALAR_FAST])) 410 + unaligned_scalar_speed_param = RISCV_HWPROBE_MISALIGNED_SCALAR_FAST; 411 + else if (!strcmp(str, speed_str[RISCV_HWPROBE_MISALIGNED_SCALAR_UNSUPPORTED])) 412 + unaligned_scalar_speed_param = RISCV_HWPROBE_MISALIGNED_SCALAR_UNSUPPORTED; 413 + else 414 + return -EINVAL; 415 + 416 + return 1; 417 + } 418 + __setup("unaligned_scalar_speed=", set_unaligned_scalar_speed_param); 419 + 420 + static int __init set_unaligned_vector_speed_param(char *str) 421 + { 422 + if (!strcmp(str, speed_str[RISCV_HWPROBE_MISALIGNED_VECTOR_SLOW])) 423 + unaligned_vector_speed_param = RISCV_HWPROBE_MISALIGNED_VECTOR_SLOW; 424 + else if (!strcmp(str, speed_str[RISCV_HWPROBE_MISALIGNED_VECTOR_FAST])) 425 + unaligned_vector_speed_param = RISCV_HWPROBE_MISALIGNED_VECTOR_FAST; 426 + else if (!strcmp(str, speed_str[RISCV_HWPROBE_MISALIGNED_VECTOR_UNSUPPORTED])) 427 + unaligned_vector_speed_param = RISCV_HWPROBE_MISALIGNED_VECTOR_UNSUPPORTED; 428 + else 429 + return -EINVAL; 430 + 431 + return 1; 432 + } 433 + __setup("unaligned_vector_speed=", set_unaligned_vector_speed_param); 434 + 435 + static int __init check_unaligned_access_all_cpus(void) 436 + { 437 + int cpu; 438 + 439 + if (unaligned_scalar_speed_param == RISCV_HWPROBE_MISALIGNED_SCALAR_UNKNOWN && 440 + !check_unaligned_access_emulated_all_cpus()) { 441 + check_unaligned_access_speed_all_cpus(); 442 + } else { 443 + pr_info("scalar unaligned access speed set to '%s' by command line\n", 444 + speed_str[unaligned_scalar_speed_param]); 445 + for_each_online_cpu(cpu) 446 + per_cpu(misaligned_access_speed, cpu) = unaligned_scalar_speed_param; 447 + } 448 + 449 + if (!has_vector()) 450 + unaligned_vector_speed_param = RISCV_HWPROBE_MISALIGNED_VECTOR_UNSUPPORTED; 451 + 452 + if (unaligned_vector_speed_param == RISCV_HWPROBE_MISALIGNED_VECTOR_UNKNOWN && 453 + !check_vector_unaligned_access_emulated_all_cpus() && 454 + IS_ENABLED(CONFIG_RISCV_PROBE_VECTOR_UNALIGNED_ACCESS)) { 455 + kthread_run(vec_check_unaligned_access_speed_all_cpus, 456 + NULL, "vec_check_unaligned_access_speed_all_cpus"); 457 + } else { 458 + pr_info("vector unaligned access speed set to '%s' by command line\n", 459 + speed_str[unaligned_vector_speed_param]); 460 + for_each_online_cpu(cpu) 461 + per_cpu(vector_misaligned_access, cpu) = unaligned_vector_speed_param; 462 + } 388 463 389 464 /* 390 465 * Setup hotplug callbacks for any new CPUs that come online or go 391 466 * offline. 392 467 */ 393 468 cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "riscv:online", 469 + riscv_online_cpu, riscv_offline_cpu); 470 + cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "riscv:online", 394 471 riscv_online_cpu_vec, NULL); 395 - 396 - return 0; 397 - } 398 - #else /* CONFIG_RISCV_PROBE_VECTOR_UNALIGNED_ACCESS */ 399 - static int vec_check_unaligned_access_speed_all_cpus(void *unused __always_unused) 400 - { 401 - return 0; 402 - } 403 - #endif 404 - 405 - static int check_unaligned_access_all_cpus(void) 406 - { 407 - bool all_cpus_emulated, all_cpus_vec_unsupported; 408 - 409 - all_cpus_emulated = check_unaligned_access_emulated_all_cpus(); 410 - all_cpus_vec_unsupported = check_vector_unaligned_access_emulated_all_cpus(); 411 - 412 - if (!all_cpus_vec_unsupported && 413 - IS_ENABLED(CONFIG_RISCV_PROBE_VECTOR_UNALIGNED_ACCESS)) { 414 - kthread_run(vec_check_unaligned_access_speed_all_cpus, 415 - NULL, "vec_check_unaligned_access_speed_all_cpus"); 416 - } 417 - 418 - if (!all_cpus_emulated) 419 - return check_unaligned_access_speed_all_cpus(); 420 472 421 473 return 0; 422 474 }
+1 -1
arch/riscv/kernel/vec-copy-unaligned.S
··· 11 11 12 12 #define WORD_SEW CONCATENATE(e, WORD_EEW) 13 13 #define VEC_L CONCATENATE(vle, WORD_EEW).v 14 - #define VEC_S CONCATENATE(vle, WORD_EEW).v 14 + #define VEC_S CONCATENATE(vse, WORD_EEW).v 15 15 16 16 /* void __riscv_copy_vec_words_unaligned(void *, const void *, size_t) */ 17 17 /* Performs a memcpy without aligning buffers, using word loads and stores. */
+1 -1
arch/riscv/kernel/vendor_extensions.c
··· 61 61 if (bit >= RISCV_ISA_VENDOR_EXT_MAX) 62 62 return false; 63 63 64 - return test_bit(bit, bmap->isa) ? true : false; 64 + return test_bit(bit, bmap->isa); 65 65 } 66 66 EXPORT_SYMBOL_GPL(__riscv_isa_vendor_extension_available);
+3
arch/riscv/kernel/vmlinux.lds.S
··· 97 97 { 98 98 EXIT_DATA 99 99 } 100 + 101 + RUNTIME_CONST_VARIABLES 102 + 100 103 PERCPU_SECTION(L1_CACHE_BYTES) 101 104 102 105 .rel.dyn : {
+4
arch/riscv/kvm/vcpu_onereg.c
··· 47 47 KVM_ISA_EXT_ARR(SVNAPOT), 48 48 KVM_ISA_EXT_ARR(SVPBMT), 49 49 KVM_ISA_EXT_ARR(SVVPTC), 50 + KVM_ISA_EXT_ARR(ZAAMO), 50 51 KVM_ISA_EXT_ARR(ZABHA), 51 52 KVM_ISA_EXT_ARR(ZACAS), 53 + KVM_ISA_EXT_ARR(ZALRSC), 52 54 KVM_ISA_EXT_ARR(ZAWRS), 53 55 KVM_ISA_EXT_ARR(ZBA), 54 56 KVM_ISA_EXT_ARR(ZBB), ··· 151 149 case KVM_RISCV_ISA_EXT_SVINVAL: 152 150 case KVM_RISCV_ISA_EXT_SVNAPOT: 153 151 case KVM_RISCV_ISA_EXT_SVVPTC: 152 + case KVM_RISCV_ISA_EXT_ZAAMO: 154 153 case KVM_RISCV_ISA_EXT_ZABHA: 155 154 case KVM_RISCV_ISA_EXT_ZACAS: 155 + case KVM_RISCV_ISA_EXT_ZALRSC: 156 156 case KVM_RISCV_ISA_EXT_ZAWRS: 157 157 case KVM_RISCV_ISA_EXT_ZBA: 158 158 case KVM_RISCV_ISA_EXT_ZBB:
+3 -18
arch/riscv/lib/csum.c
··· 40 40 uproto = (__force unsigned int)htonl(proto); 41 41 sum += uproto; 42 42 43 - /* 44 - * Zbb support saves 4 instructions, so not worth checking without 45 - * alternatives if supported 46 - */ 47 - if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && 48 - IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) { 43 + if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && IS_ENABLED(CONFIG_TOOLCHAIN_HAS_ZBB)) { 49 44 unsigned long fold_temp; 50 45 51 46 /* ··· 152 157 csum = do_csum_common(ptr, end, data); 153 158 154 159 #ifdef CC_HAS_ASM_GOTO_TIED_OUTPUT 155 - /* 156 - * Zbb support saves 6 instructions, so not worth checking without 157 - * alternatives if supported 158 - */ 159 - if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && 160 - IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) { 160 + if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && IS_ENABLED(CONFIG_TOOLCHAIN_HAS_ZBB)) { 161 161 unsigned long fold_temp; 162 162 163 163 /* ··· 234 244 end = (const unsigned long *)(buff + len); 235 245 csum = do_csum_common(ptr, end, data); 236 246 237 - /* 238 - * Zbb support saves 6 instructions, so not worth checking without 239 - * alternatives if supported 240 - */ 241 - if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && 242 - IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) { 247 + if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && IS_ENABLED(CONFIG_TOOLCHAIN_HAS_ZBB)) { 243 248 unsigned long fold_temp; 244 249 245 250 /*
+3 -2
arch/riscv/lib/strcmp.S
··· 8 8 /* int strcmp(const char *cs, const char *ct) */ 9 9 SYM_FUNC_START(strcmp) 10 10 11 - ALTERNATIVE("nop", "j strcmp_zbb", 0, RISCV_ISA_EXT_ZBB, CONFIG_RISCV_ISA_ZBB) 11 + __ALTERNATIVE_CFG("nop", "j strcmp_zbb", 0, RISCV_ISA_EXT_ZBB, 12 + IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && IS_ENABLED(CONFIG_TOOLCHAIN_HAS_ZBB)) 12 13 13 14 /* 14 15 * Returns ··· 44 43 * The code was published as part of the bitmanip manual 45 44 * in Appendix A. 46 45 */ 47 - #ifdef CONFIG_RISCV_ISA_ZBB 46 + #if defined(CONFIG_RISCV_ISA_ZBB) && defined(CONFIG_TOOLCHAIN_HAS_ZBB) 48 47 strcmp_zbb: 49 48 50 49 .option push
+3 -2
arch/riscv/lib/strlen.S
··· 8 8 /* int strlen(const char *s) */ 9 9 SYM_FUNC_START(strlen) 10 10 11 - ALTERNATIVE("nop", "j strlen_zbb", 0, RISCV_ISA_EXT_ZBB, CONFIG_RISCV_ISA_ZBB) 11 + __ALTERNATIVE_CFG("nop", "j strlen_zbb", 0, RISCV_ISA_EXT_ZBB, 12 + IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && IS_ENABLED(CONFIG_TOOLCHAIN_HAS_ZBB)) 12 13 13 14 /* 14 15 * Returns ··· 34 33 /* 35 34 * Variant of strlen using the ZBB extension if available 36 35 */ 37 - #ifdef CONFIG_RISCV_ISA_ZBB 36 + #if defined(CONFIG_RISCV_ISA_ZBB) && defined(CONFIG_TOOLCHAIN_HAS_ZBB) 38 37 strlen_zbb: 39 38 40 39 #ifdef CONFIG_CPU_BIG_ENDIAN
+3 -2
arch/riscv/lib/strncmp.S
··· 8 8 /* int strncmp(const char *cs, const char *ct, size_t count) */ 9 9 SYM_FUNC_START(strncmp) 10 10 11 - ALTERNATIVE("nop", "j strncmp_zbb", 0, RISCV_ISA_EXT_ZBB, CONFIG_RISCV_ISA_ZBB) 11 + __ALTERNATIVE_CFG("nop", "j strncmp_zbb", 0, RISCV_ISA_EXT_ZBB, 12 + IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && IS_ENABLED(CONFIG_TOOLCHAIN_HAS_ZBB)) 12 13 13 14 /* 14 15 * Returns ··· 47 46 /* 48 47 * Variant of strncmp using the ZBB extension if available 49 48 */ 50 - #ifdef CONFIG_RISCV_ISA_ZBB 49 + #if defined(CONFIG_RISCV_ISA_ZBB) && defined(CONFIG_TOOLCHAIN_HAS_ZBB) 51 50 strncmp_zbb: 52 51 53 52 .option push
+1 -1
arch/riscv/mm/context.c
··· 158 158 * 159 159 * - We get a zero back from the cmpxchg and end up waiting on the 160 160 * lock. Taking the lock synchronises with the rollover and so 161 - * we are forced to see the updated verion. 161 + * we are forced to see the updated version. 162 162 * 163 163 * - We get a valid context back from the cmpxchg then we continue 164 164 * using old ASID because __flush_context() would have marked ASID
+44 -30
arch/riscv/mm/hugetlbpage.c
··· 148 148 static pte_t get_clear_contig(struct mm_struct *mm, 149 149 unsigned long addr, 150 150 pte_t *ptep, 151 - unsigned long pte_num) 151 + unsigned long ncontig) 152 152 { 153 - pte_t orig_pte = ptep_get(ptep); 154 - unsigned long i; 153 + pte_t pte, tmp_pte; 154 + bool present; 155 155 156 - for (i = 0; i < pte_num; i++, addr += PAGE_SIZE, ptep++) { 157 - pte_t pte = ptep_get_and_clear(mm, addr, ptep); 158 - 159 - if (pte_dirty(pte)) 160 - orig_pte = pte_mkdirty(orig_pte); 161 - 162 - if (pte_young(pte)) 163 - orig_pte = pte_mkyoung(orig_pte); 156 + pte = ptep_get_and_clear(mm, addr, ptep); 157 + present = pte_present(pte); 158 + while (--ncontig) { 159 + ptep++; 160 + addr += PAGE_SIZE; 161 + tmp_pte = ptep_get_and_clear(mm, addr, ptep); 162 + if (present) { 163 + if (pte_dirty(tmp_pte)) 164 + pte = pte_mkdirty(pte); 165 + if (pte_young(tmp_pte)) 166 + pte = pte_mkyoung(pte); 167 + } 164 168 } 165 - 166 - return orig_pte; 169 + return pte; 167 170 } 168 171 169 172 static pte_t get_clear_contig_flush(struct mm_struct *mm, ··· 215 212 flush_tlb_range(&vma, saddr, addr); 216 213 } 217 214 215 + static int num_contig_ptes_from_size(unsigned long sz, size_t *pgsize) 216 + { 217 + unsigned long hugepage_shift; 218 + 219 + if (sz >= PGDIR_SIZE) 220 + hugepage_shift = PGDIR_SHIFT; 221 + else if (sz >= P4D_SIZE) 222 + hugepage_shift = P4D_SHIFT; 223 + else if (sz >= PUD_SIZE) 224 + hugepage_shift = PUD_SHIFT; 225 + else if (sz >= PMD_SIZE) 226 + hugepage_shift = PMD_SHIFT; 227 + else 228 + hugepage_shift = PAGE_SHIFT; 229 + 230 + *pgsize = 1 << hugepage_shift; 231 + 232 + return sz >> hugepage_shift; 233 + } 234 + 218 235 /* 219 236 * When dealing with NAPOT mappings, the privileged specification indicates that 220 237 * "if an update needs to be made, the OS generally should first mark all of the ··· 249 226 pte_t pte, 250 227 unsigned long sz) 251 228 { 252 - unsigned long hugepage_shift, pgsize; 229 + size_t pgsize; 253 230 int i, pte_num; 254 231 255 - if (sz >= PGDIR_SIZE) 256 - hugepage_shift = PGDIR_SHIFT; 257 - else if (sz >= P4D_SIZE) 258 - hugepage_shift = P4D_SHIFT; 259 - else if (sz >= PUD_SIZE) 260 - hugepage_shift = PUD_SHIFT; 261 - else if (sz >= PMD_SIZE) 262 - hugepage_shift = PMD_SHIFT; 263 - else 264 - hugepage_shift = PAGE_SHIFT; 265 - 266 - pte_num = sz >> hugepage_shift; 267 - pgsize = 1 << hugepage_shift; 232 + pte_num = num_contig_ptes_from_size(sz, &pgsize); 268 233 269 234 if (!pte_present(pte)) { 270 235 for (i = 0; i < pte_num; i++, ptep++, addr += pgsize) ··· 306 295 unsigned long addr, 307 296 pte_t *ptep, unsigned long sz) 308 297 { 298 + size_t pgsize; 309 299 pte_t orig_pte = ptep_get(ptep); 310 300 int pte_num; 311 301 312 302 if (!pte_napot(orig_pte)) 313 303 return ptep_get_and_clear(mm, addr, ptep); 314 304 315 - pte_num = napot_pte_num(napot_cont_order(orig_pte)); 305 + pte_num = num_contig_ptes_from_size(sz, &pgsize); 316 306 317 307 return get_clear_contig(mm, addr, ptep, pte_num); 318 308 } ··· 363 351 pte_t *ptep, 364 352 unsigned long sz) 365 353 { 354 + size_t pgsize; 366 355 pte_t pte = ptep_get(ptep); 367 356 int i, pte_num; 368 357 ··· 372 359 return; 373 360 } 374 361 375 - pte_num = napot_pte_num(napot_cont_order(pte)); 376 - for (i = 0; i < pte_num; i++, addr += PAGE_SIZE, ptep++) 362 + pte_num = num_contig_ptes_from_size(sz, &pgsize); 363 + 364 + for (i = 0; i < pte_num; i++, addr += pgsize, ptep++) 377 365 pte_clear(mm, addr, ptep); 378 366 } 379 367
+49 -48
arch/riscv/mm/init.c
··· 20 20 #include <linux/dma-map-ops.h> 21 21 #include <linux/crash_dump.h> 22 22 #include <linux/hugetlb.h> 23 - #ifdef CONFIG_RELOCATABLE 24 - #include <linux/elf.h> 25 - #endif 26 23 #include <linux/kfence.h> 27 24 #include <linux/execmem.h> 28 25 29 26 #include <asm/fixmap.h> 30 27 #include <asm/io.h> 31 28 #include <asm/kasan.h> 29 + #include <asm/module.h> 32 30 #include <asm/numa.h> 33 31 #include <asm/pgtable.h> 34 32 #include <asm/sections.h> ··· 317 319 if (IS_ENABLED(CONFIG_64BIT)) 318 320 hugetlb_cma_reserve(PUD_SHIFT - PAGE_SHIFT); 319 321 } 322 + 323 + #ifdef CONFIG_RELOCATABLE 324 + extern unsigned long __rela_dyn_start, __rela_dyn_end; 325 + 326 + static void __init relocate_kernel(void) 327 + { 328 + Elf_Rela *rela = (Elf_Rela *)&__rela_dyn_start; 329 + /* 330 + * This holds the offset between the linked virtual address and the 331 + * relocated virtual address. 332 + */ 333 + uintptr_t reloc_offset = kernel_map.virt_addr - KERNEL_LINK_ADDR; 334 + /* 335 + * This holds the offset between kernel linked virtual address and 336 + * physical address. 337 + */ 338 + uintptr_t va_kernel_link_pa_offset = KERNEL_LINK_ADDR - kernel_map.phys_addr; 339 + 340 + for ( ; rela < (Elf_Rela *)&__rela_dyn_end; rela++) { 341 + Elf_Addr addr = (rela->r_offset - va_kernel_link_pa_offset); 342 + Elf_Addr relocated_addr = rela->r_addend; 343 + 344 + if (rela->r_info != R_RISCV_RELATIVE) 345 + continue; 346 + 347 + /* 348 + * Make sure to not relocate vdso symbols like rt_sigreturn 349 + * which are linked from the address 0 in vmlinux since 350 + * vdso symbol addresses are actually used as an offset from 351 + * mm->context.vdso in VDSO_OFFSET macro. 352 + */ 353 + if (relocated_addr >= KERNEL_LINK_ADDR) 354 + relocated_addr += reloc_offset; 355 + 356 + *(Elf_Addr *)addr = relocated_addr; 357 + } 358 + } 359 + #endif /* CONFIG_RELOCATABLE */ 320 360 321 361 #ifdef CONFIG_MMU 322 362 struct pt_alloc_ops pt_ops __meminitdata; ··· 856 820 uintptr_t set_satp_mode_pmd = ((unsigned long)set_satp_mode) & PMD_MASK; 857 821 u64 satp_mode_cmdline = __pi_set_satp_mode_from_cmdline(dtb_pa); 858 822 823 + kernel_map.page_offset = PAGE_OFFSET_L5; 824 + 859 825 if (satp_mode_cmdline == SATP_MODE_57) { 860 826 disable_pgtable_l5(); 861 827 } else if (satp_mode_cmdline == SATP_MODE_48) { ··· 927 889 #ifndef __riscv_cmodel_medany 928 890 #error "setup_vm() is called from head.S before relocate so it should not use absolute addressing." 929 891 #endif 930 - 931 - #ifdef CONFIG_RELOCATABLE 932 - extern unsigned long __rela_dyn_start, __rela_dyn_end; 933 - 934 - static void __init relocate_kernel(void) 935 - { 936 - Elf64_Rela *rela = (Elf64_Rela *)&__rela_dyn_start; 937 - /* 938 - * This holds the offset between the linked virtual address and the 939 - * relocated virtual address. 940 - */ 941 - uintptr_t reloc_offset = kernel_map.virt_addr - KERNEL_LINK_ADDR; 942 - /* 943 - * This holds the offset between kernel linked virtual address and 944 - * physical address. 945 - */ 946 - uintptr_t va_kernel_link_pa_offset = KERNEL_LINK_ADDR - kernel_map.phys_addr; 947 - 948 - for ( ; rela < (Elf64_Rela *)&__rela_dyn_end; rela++) { 949 - Elf64_Addr addr = (rela->r_offset - va_kernel_link_pa_offset); 950 - Elf64_Addr relocated_addr = rela->r_addend; 951 - 952 - if (rela->r_info != R_RISCV_RELATIVE) 953 - continue; 954 - 955 - /* 956 - * Make sure to not relocate vdso symbols like rt_sigreturn 957 - * which are linked from the address 0 in vmlinux since 958 - * vdso symbol addresses are actually used as an offset from 959 - * mm->context.vdso in VDSO_OFFSET macro. 960 - */ 961 - if (relocated_addr >= KERNEL_LINK_ADDR) 962 - relocated_addr += reloc_offset; 963 - 964 - *(Elf64_Addr *)addr = relocated_addr; 965 - } 966 - } 967 - #endif /* CONFIG_RELOCATABLE */ 968 892 969 893 #ifdef CONFIG_XIP_KERNEL 970 894 static void __init create_kernel_page_table(pgd_t *pgdir, ··· 1105 1105 kernel_map.virt_addr = KERNEL_LINK_ADDR + kernel_map.virt_offset; 1106 1106 1107 1107 #ifdef CONFIG_XIP_KERNEL 1108 - #ifdef CONFIG_64BIT 1109 - kernel_map.page_offset = PAGE_OFFSET_L3; 1110 - #else 1111 - kernel_map.page_offset = _AC(CONFIG_PAGE_OFFSET, UL); 1112 - #endif 1113 1108 kernel_map.xiprom = (uintptr_t)CONFIG_XIP_PHYS_ADDR; 1114 1109 kernel_map.xiprom_sz = (uintptr_t)(&_exiprom) - (uintptr_t)(&_xiprom); 1115 1110 ··· 1119 1124 kernel_map.va_kernel_xip_data_pa_offset = kernel_map.virt_addr - kernel_map.phys_addr 1120 1125 + (uintptr_t)&_sdata - (uintptr_t)&_start; 1121 1126 #else 1122 - kernel_map.page_offset = _AC(CONFIG_PAGE_OFFSET, UL); 1123 1127 kernel_map.phys_addr = (uintptr_t)(&_start); 1124 1128 kernel_map.size = (uintptr_t)(&_end) - kernel_map.phys_addr; 1125 1129 kernel_map.va_kernel_pa_offset = kernel_map.virt_addr - kernel_map.phys_addr; ··· 1165 1171 * makes the kernel cross over a PUD_SIZE boundary, raise a bug 1166 1172 * since a part of the kernel would not get mapped. 1167 1173 */ 1168 - BUG_ON(PUD_SIZE - (kernel_map.virt_addr & (PUD_SIZE - 1)) < kernel_map.size); 1174 + if (IS_ENABLED(CONFIG_64BIT)) 1175 + BUG_ON(PUD_SIZE - (kernel_map.virt_addr & (PUD_SIZE - 1)) < kernel_map.size); 1169 1176 relocate_kernel(); 1170 1177 #endif 1171 1178 ··· 1370 1375 { 1371 1376 dtb_early_va = (void *)dtb_pa; 1372 1377 dtb_early_pa = dtb_pa; 1378 + 1379 + #ifdef CONFIG_RELOCATABLE 1380 + kernel_map.virt_addr = (uintptr_t)_start; 1381 + kernel_map.phys_addr = (uintptr_t)_start; 1382 + relocate_kernel(); 1383 + #endif 1373 1384 } 1374 1385 1375 1386 static inline void setup_vm_final(void)
+1 -1
arch/riscv/mm/physaddr.c
··· 12 12 * Boundary checking aginst the kernel linear mapping space. 13 13 */ 14 14 WARN(!is_linear_mapping(x) && !is_kernel_mapping(x), 15 - "virt_to_phys used for non-linear address: %pK (%pS)\n", 15 + "virt_to_phys used for non-linear address: %p (%pS)\n", 16 16 (void *)x, (void *)x); 17 17 18 18 return __va_to_pa_nodebug(x);
+20 -15
arch/riscv/mm/tlbflush.c
··· 4 4 #include <linux/smp.h> 5 5 #include <linux/sched.h> 6 6 #include <linux/hugetlb.h> 7 + #include <linux/mmu_notifier.h> 7 8 #include <asm/sbi.h> 8 9 #include <asm/mmu_context.h> 9 10 ··· 79 78 local_flush_tlb_range_asid(d->start, d->size, d->stride, d->asid); 80 79 } 81 80 82 - static void __flush_tlb_range(const struct cpumask *cmask, unsigned long asid, 81 + static inline unsigned long get_mm_asid(struct mm_struct *mm) 82 + { 83 + return mm ? cntx2asid(atomic_long_read(&mm->context.id)) : FLUSH_TLB_NO_ASID; 84 + } 85 + 86 + static void __flush_tlb_range(struct mm_struct *mm, 87 + const struct cpumask *cmask, 83 88 unsigned long start, unsigned long size, 84 89 unsigned long stride) 85 90 { 91 + unsigned long asid = get_mm_asid(mm); 86 92 unsigned int cpu; 87 93 88 94 if (cpumask_empty(cmask)) ··· 113 105 } 114 106 115 107 put_cpu(); 116 - } 117 108 118 - static inline unsigned long get_mm_asid(struct mm_struct *mm) 119 - { 120 - return cntx2asid(atomic_long_read(&mm->context.id)); 109 + if (mm) 110 + mmu_notifier_arch_invalidate_secondary_tlbs(mm, start, start + size); 121 111 } 122 112 123 113 void flush_tlb_mm(struct mm_struct *mm) 124 114 { 125 - __flush_tlb_range(mm_cpumask(mm), get_mm_asid(mm), 126 - 0, FLUSH_TLB_MAX_SIZE, PAGE_SIZE); 115 + __flush_tlb_range(mm, mm_cpumask(mm), 0, FLUSH_TLB_MAX_SIZE, PAGE_SIZE); 127 116 } 128 117 129 118 void flush_tlb_mm_range(struct mm_struct *mm, 130 119 unsigned long start, unsigned long end, 131 120 unsigned int page_size) 132 121 { 133 - __flush_tlb_range(mm_cpumask(mm), get_mm_asid(mm), 134 - start, end - start, page_size); 122 + __flush_tlb_range(mm, mm_cpumask(mm), start, end - start, page_size); 135 123 } 136 124 137 125 void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr) 138 126 { 139 - __flush_tlb_range(mm_cpumask(vma->vm_mm), get_mm_asid(vma->vm_mm), 127 + __flush_tlb_range(vma->vm_mm, mm_cpumask(vma->vm_mm), 140 128 addr, PAGE_SIZE, PAGE_SIZE); 141 129 } 142 130 ··· 165 161 } 166 162 } 167 163 168 - __flush_tlb_range(mm_cpumask(vma->vm_mm), get_mm_asid(vma->vm_mm), 164 + __flush_tlb_range(vma->vm_mm, mm_cpumask(vma->vm_mm), 169 165 start, end - start, stride_size); 170 166 } 171 167 172 168 void flush_tlb_kernel_range(unsigned long start, unsigned long end) 173 169 { 174 - __flush_tlb_range(cpu_online_mask, FLUSH_TLB_NO_ASID, 170 + __flush_tlb_range(NULL, cpu_online_mask, 175 171 start, end - start, PAGE_SIZE); 176 172 } 177 173 ··· 179 175 void flush_pmd_tlb_range(struct vm_area_struct *vma, unsigned long start, 180 176 unsigned long end) 181 177 { 182 - __flush_tlb_range(mm_cpumask(vma->vm_mm), get_mm_asid(vma->vm_mm), 178 + __flush_tlb_range(vma->vm_mm, mm_cpumask(vma->vm_mm), 183 179 start, end - start, PMD_SIZE); 184 180 } 185 181 #endif ··· 193 189 struct mm_struct *mm, unsigned long start, unsigned long end) 194 190 { 195 191 cpumask_or(&batch->cpumask, &batch->cpumask, mm_cpumask(mm)); 192 + mmu_notifier_arch_invalidate_secondary_tlbs(mm, start, end); 196 193 } 197 194 198 195 void arch_flush_tlb_batched_pending(struct mm_struct *mm) ··· 203 198 204 199 void arch_tlbbatch_flush(struct arch_tlbflush_unmap_batch *batch) 205 200 { 206 - __flush_tlb_range(&batch->cpumask, FLUSH_TLB_NO_ASID, 0, 207 - FLUSH_TLB_MAX_SIZE, PAGE_SIZE); 201 + __flush_tlb_range(NULL, &batch->cpumask, 202 + 0, FLUSH_TLB_MAX_SIZE, PAGE_SIZE); 208 203 cpumask_clear(&batch->cpumask); 209 204 }
+1
arch/riscv/purgatory/entry.S
··· 12 12 13 13 .text 14 14 15 + .align 2 15 16 SYM_CODE_START(purgatory_start) 16 17 17 18 lla sp, .Lstack
+6
drivers/clocksource/timer-riscv.c
··· 126 126 127 127 static int riscv_timer_dying_cpu(unsigned int cpu) 128 128 { 129 + /* 130 + * Stop the timer when the cpu is going to be offline otherwise 131 + * the timer interrupt may be pending while performing power-down. 132 + */ 133 + riscv_clock_event_stop(); 129 134 disable_percpu_irq(riscv_clock_event_irq); 135 + 130 136 return 0; 131 137 } 132 138
-8
include/asm-generic/module.h
··· 19 19 #define Elf_Dyn Elf64_Dyn 20 20 #define Elf_Ehdr Elf64_Ehdr 21 21 #define Elf_Addr Elf64_Addr 22 - #ifdef CONFIG_MODULES_USE_ELF_REL 23 22 #define Elf_Rel Elf64_Rel 24 - #endif 25 - #ifdef CONFIG_MODULES_USE_ELF_RELA 26 23 #define Elf_Rela Elf64_Rela 27 - #endif 28 24 #define ELF_R_TYPE(X) ELF64_R_TYPE(X) 29 25 #define ELF_R_SYM(X) ELF64_R_SYM(X) 30 26 ··· 32 36 #define Elf_Dyn Elf32_Dyn 33 37 #define Elf_Ehdr Elf32_Ehdr 34 38 #define Elf_Addr Elf32_Addr 35 - #ifdef CONFIG_MODULES_USE_ELF_REL 36 39 #define Elf_Rel Elf32_Rel 37 - #endif 38 - #ifdef CONFIG_MODULES_USE_ELF_RELA 39 40 #define Elf_Rela Elf32_Rela 40 - #endif 41 41 #define ELF_R_TYPE(X) ELF32_R_TYPE(X) 42 42 #define ELF_R_SYM(X) ELF32_R_SYM(X) 43 43 #endif
+8
tools/testing/selftests/kvm/riscv/get-reg-list.c
··· 53 53 case KVM_REG_RISCV_ISA_EXT | KVM_REG_RISCV_ISA_SINGLE | KVM_RISCV_ISA_EXT_SVNAPOT: 54 54 case KVM_REG_RISCV_ISA_EXT | KVM_REG_RISCV_ISA_SINGLE | KVM_RISCV_ISA_EXT_SVPBMT: 55 55 case KVM_REG_RISCV_ISA_EXT | KVM_REG_RISCV_ISA_SINGLE | KVM_RISCV_ISA_EXT_SVVPTC: 56 + case KVM_REG_RISCV_ISA_EXT | KVM_REG_RISCV_ISA_SINGLE | KVM_RISCV_ISA_EXT_ZAAMO: 56 57 case KVM_REG_RISCV_ISA_EXT | KVM_REG_RISCV_ISA_SINGLE | KVM_RISCV_ISA_EXT_ZABHA: 57 58 case KVM_REG_RISCV_ISA_EXT | KVM_REG_RISCV_ISA_SINGLE | KVM_RISCV_ISA_EXT_ZACAS: 59 + case KVM_REG_RISCV_ISA_EXT | KVM_REG_RISCV_ISA_SINGLE | KVM_RISCV_ISA_EXT_ZALRSC: 58 60 case KVM_REG_RISCV_ISA_EXT | KVM_REG_RISCV_ISA_SINGLE | KVM_RISCV_ISA_EXT_ZAWRS: 59 61 case KVM_REG_RISCV_ISA_EXT | KVM_REG_RISCV_ISA_SINGLE | KVM_RISCV_ISA_EXT_ZBA: 60 62 case KVM_REG_RISCV_ISA_EXT | KVM_REG_RISCV_ISA_SINGLE | KVM_RISCV_ISA_EXT_ZBB: ··· 436 434 KVM_ISA_EXT_ARR(SVNAPOT), 437 435 KVM_ISA_EXT_ARR(SVPBMT), 438 436 KVM_ISA_EXT_ARR(SVVPTC), 437 + KVM_ISA_EXT_ARR(ZAAMO), 439 438 KVM_ISA_EXT_ARR(ZABHA), 440 439 KVM_ISA_EXT_ARR(ZACAS), 440 + KVM_ISA_EXT_ARR(ZALRSC), 441 441 KVM_ISA_EXT_ARR(ZAWRS), 442 442 KVM_ISA_EXT_ARR(ZBA), 443 443 KVM_ISA_EXT_ARR(ZBB), ··· 978 974 KVM_ISA_EXT_SIMPLE_CONFIG(svnapot, SVNAPOT); 979 975 KVM_ISA_EXT_SIMPLE_CONFIG(svpbmt, SVPBMT); 980 976 KVM_ISA_EXT_SIMPLE_CONFIG(svvptc, SVVPTC); 977 + KVM_ISA_EXT_SIMPLE_CONFIG(zaamo, ZAAMO); 981 978 KVM_ISA_EXT_SIMPLE_CONFIG(zabha, ZABHA); 982 979 KVM_ISA_EXT_SIMPLE_CONFIG(zacas, ZACAS); 980 + KVM_ISA_EXT_SIMPLE_CONFIG(zalrsc, ZALRSC); 983 981 KVM_ISA_EXT_SIMPLE_CONFIG(zawrs, ZAWRS); 984 982 KVM_ISA_EXT_SIMPLE_CONFIG(zba, ZBA); 985 983 KVM_ISA_EXT_SIMPLE_CONFIG(zbb, ZBB); ··· 1051 1045 &config_svnapot, 1052 1046 &config_svpbmt, 1053 1047 &config_svvptc, 1048 + &config_zaamo, 1054 1049 &config_zabha, 1055 1050 &config_zacas, 1051 + &config_zalrsc, 1056 1052 &config_zawrs, 1057 1053 &config_zba, 1058 1054 &config_zbb,
+55 -11
tools/testing/selftests/riscv/hwprobe/cbo.c
··· 50 50 static void cbo_flush(char *base) { cbo_insn(base, 2); } 51 51 static void cbo_zero(char *base) { cbo_insn(base, 4); } 52 52 53 + static void test_no_cbo_inval(void *arg) 54 + { 55 + ksft_print_msg("Testing cbo.inval instruction remain privileged\n"); 56 + illegal_insn = false; 57 + cbo_inval(&mem[0]); 58 + ksft_test_result(illegal_insn, "No cbo.inval\n"); 59 + } 60 + 53 61 static void test_no_zicbom(void *arg) 54 62 { 55 63 ksft_print_msg("Testing Zicbom instructions remain privileged\n"); ··· 69 61 illegal_insn = false; 70 62 cbo_flush(&mem[0]); 71 63 ksft_test_result(illegal_insn, "No cbo.flush\n"); 72 - 73 - illegal_insn = false; 74 - cbo_inval(&mem[0]); 75 - ksft_test_result(illegal_insn, "No cbo.inval\n"); 76 64 } 77 65 78 66 static void test_no_zicboz(void *arg) ··· 83 79 static bool is_power_of_2(__u64 n) 84 80 { 85 81 return n != 0 && (n & (n - 1)) == 0; 82 + } 83 + 84 + static void test_zicbom(void *arg) 85 + { 86 + struct riscv_hwprobe pair = { 87 + .key = RISCV_HWPROBE_KEY_ZICBOM_BLOCK_SIZE, 88 + }; 89 + cpu_set_t *cpus = (cpu_set_t *)arg; 90 + __u64 block_size; 91 + long rc; 92 + 93 + rc = riscv_hwprobe(&pair, 1, sizeof(cpu_set_t), (unsigned long *)cpus, 0); 94 + block_size = pair.value; 95 + ksft_test_result(rc == 0 && pair.key == RISCV_HWPROBE_KEY_ZICBOM_BLOCK_SIZE && 96 + is_power_of_2(block_size), "Zicbom block size\n"); 97 + ksft_print_msg("Zicbom block size: %llu\n", block_size); 98 + 99 + illegal_insn = false; 100 + cbo_clean(&mem[block_size]); 101 + ksft_test_result(!illegal_insn, "cbo.clean\n"); 102 + 103 + illegal_insn = false; 104 + cbo_flush(&mem[block_size]); 105 + ksft_test_result(!illegal_insn, "cbo.flush\n"); 86 106 } 87 107 88 108 static void test_zicboz(void *arg) ··· 157 129 ksft_test_result_pass("cbo.zero check\n"); 158 130 } 159 131 160 - static void check_no_zicboz_cpus(cpu_set_t *cpus) 132 + static void check_no_zicbo_cpus(cpu_set_t *cpus, __u64 cbo) 161 133 { 162 134 struct riscv_hwprobe pair = { 163 135 .key = RISCV_HWPROBE_KEY_IMA_EXT_0, ··· 165 137 cpu_set_t one_cpu; 166 138 int i = 0, c = 0; 167 139 long rc; 140 + char *cbostr; 168 141 169 142 while (i++ < CPU_COUNT(cpus)) { 170 143 while (!CPU_ISSET(c, cpus)) ··· 177 148 rc = riscv_hwprobe(&pair, 1, sizeof(cpu_set_t), (unsigned long *)&one_cpu, 0); 178 149 assert(rc == 0 && pair.key == RISCV_HWPROBE_KEY_IMA_EXT_0); 179 150 180 - if (pair.value & RISCV_HWPROBE_EXT_ZICBOZ) 181 - ksft_exit_fail_msg("Zicboz is only present on a subset of harts.\n" 182 - "Use taskset to select a set of harts where Zicboz\n" 183 - "presence (present or not) is consistent for each hart\n"); 151 + cbostr = cbo == RISCV_HWPROBE_EXT_ZICBOZ ? "Zicboz" : "Zicbom"; 152 + 153 + if (pair.value & cbo) 154 + ksft_exit_fail_msg("%s is only present on a subset of harts.\n" 155 + "Use taskset to select a set of harts where %s\n" 156 + "presence (present or not) is consistent for each hart\n", 157 + cbostr, cbostr); 184 158 ++c; 185 159 } 186 160 } ··· 191 159 enum { 192 160 TEST_ZICBOZ, 193 161 TEST_NO_ZICBOZ, 162 + TEST_ZICBOM, 194 163 TEST_NO_ZICBOM, 164 + TEST_NO_CBO_INVAL, 195 165 }; 196 166 197 167 static struct test_info { ··· 203 169 } tests[] = { 204 170 [TEST_ZICBOZ] = { .nr_tests = 3, test_zicboz }, 205 171 [TEST_NO_ZICBOZ] = { .nr_tests = 1, test_no_zicboz }, 206 - [TEST_NO_ZICBOM] = { .nr_tests = 3, test_no_zicbom }, 172 + [TEST_ZICBOM] = { .nr_tests = 3, test_zicbom }, 173 + [TEST_NO_ZICBOM] = { .nr_tests = 2, test_no_zicbom }, 174 + [TEST_NO_CBO_INVAL] = { .nr_tests = 1, test_no_cbo_inval }, 207 175 }; 208 176 209 177 int main(int argc, char **argv) ··· 225 189 assert(rc == 0); 226 190 tests[TEST_NO_ZICBOZ].enabled = true; 227 191 tests[TEST_NO_ZICBOM].enabled = true; 192 + tests[TEST_NO_CBO_INVAL].enabled = true; 228 193 } 229 194 230 195 rc = sched_getaffinity(0, sizeof(cpu_set_t), &cpus); ··· 243 206 tests[TEST_ZICBOZ].enabled = true; 244 207 tests[TEST_NO_ZICBOZ].enabled = false; 245 208 } else { 246 - check_no_zicboz_cpus(&cpus); 209 + check_no_zicbo_cpus(&cpus, RISCV_HWPROBE_EXT_ZICBOZ); 210 + } 211 + 212 + if (pair.value & RISCV_HWPROBE_EXT_ZICBOM) { 213 + tests[TEST_ZICBOM].enabled = true; 214 + tests[TEST_NO_ZICBOM].enabled = false; 215 + } else { 216 + check_no_zicbo_cpus(&cpus, RISCV_HWPROBE_EXT_ZICBOM); 247 217 } 248 218 249 219 for (i = 0; i < ARRAY_SIZE(tests); ++i)
+3 -7
tools/testing/selftests/riscv/vector/v_exec_initval_nolibc.c
··· 6 6 * the values. To further ensure consistency, this file is compiled without 7 7 * libc and without auto-vectorization. 8 8 * 9 - * To be "clean" all values must be either all ones or all zeroes. 9 + * To be "clean" all values must be all zeroes. 10 10 */ 11 11 12 12 #define __stringify_1(x...) #x ··· 14 14 15 15 int main(int argc, char **argv) 16 16 { 17 - char prev_value = 0, value; 17 + char value = 0; 18 18 unsigned long vl; 19 - int first = 1; 20 19 21 20 if (argc > 2 && strcmp(argv[2], "x")) 22 21 asm volatile ( ··· 43 44 "vsrl.vi " __stringify(register) ", " __stringify(register) ", 8\n\t" \ 44 45 ".option pop\n\t" \ 45 46 : "=r" (value)); \ 46 - if (first) { \ 47 - first = 0; \ 48 - } else if (value != prev_value || !(value == 0x00 || value == 0xff)) { \ 47 + if (value != 0x00) { \ 49 48 printf("Register " __stringify(register) \ 50 49 " values not clean! value: %u\n", value); \ 51 50 exit(-1); \ 52 51 } \ 53 - prev_value = value; \ 54 52 } \ 55 53 }) 56 54