History

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

Pull RISC-V updates from Palmer Dabbelt: - Support for the T-Head PMU via the perf subsystem - ftrace support for rv32 - Support for non-volatile memory devices - Various fixes and cleanups * tag 'riscv-for-linus-6.2-mw1' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux: (52 commits) Documentation: RISC-V: patch-acceptance: s/implementor/implementer Documentation: RISC-V: Mention the UEFI Standards Documentation: RISC-V: Allow patches for non-standard behavior Documentation: RISC-V: Fix a typo in patch-acceptance riscv: Fixup compile error with !MMU riscv: Fix P4D_SHIFT definition for 3-level page table mode riscv: Apply a static assert to riscv_isa_ext_id RISC-V: Add some comments about the shadow and overflow stacks RISC-V: Align the shadow stack RISC-V: Ensure Zicbom has a valid block size RISC-V: Introduce riscv_isa_extension_check RISC-V: Improve use of isa2hwcap[] riscv: Don't duplicate _ALTERNATIVE_CFG* macros riscv: alternatives: Drop the underscores from the assembly macro names riscv: alternatives: Don't name unused macro parameters riscv: Don't duplicate __ALTERNATIVE_CFG in __ALTERNATIVE_CFG_2 riscv: mm: call best_map_size many times during linear-mapping riscv: Move cast inside kernel_mapping_[pv]a_to_[vp]a riscv: Fix crash during early errata patching riscv: boot: add zstd support ...

Linus Torvalds committed 3 years ago

Commit eb67d232 parents 94a8551 6e66e9652 files · +619 −256Browse files

Unified · Split

52 files
  1. Documentation/admin-guide/kdump/vmcoreinfo.rst +29 −0
  2. Documentation/features/vm/huge-vmap/arch-support.txt +1 −1
  3. Documentation/riscv/patch-acceptance.rst +14 −8
  4. arch/riscv/Kconfig +13 −6
  5. arch/riscv/Kconfig.erratas +13 −0
  6. arch/riscv/Kconfig.socs +0 −5
  7. arch/riscv/boot/Makefile +3 −0
  8. arch/riscv/configs/defconfig +3 −0
  9. arch/riscv/errata/thead/errata.c +19 −0
  10. arch/riscv/include/asm/alternative-macros.h +30 −69
  11. arch/riscv/include/asm/cacheflush.h +7 −0
  12. arch/riscv/include/asm/errata_list.h +15 −1
  13. arch/riscv/include/asm/hugetlb.h +6 −0
  14. arch/riscv/include/asm/hwcap.h +2 −1
  15. arch/riscv/include/asm/io.h +5 −0
  16. arch/riscv/include/asm/kexec.h +5 −0
  17. arch/riscv/include/asm/kprobes.h +0 −2
  18. arch/riscv/include/asm/mmu.h +2 −0
  19. arch/riscv/include/asm/page.h +9 −9
  20. arch/riscv/include/asm/pgtable-64.h +5 −1
  21. arch/riscv/include/asm/pgtable.h +4 −1
  22. arch/riscv/include/asm/sbi.h +5 −0
  23. arch/riscv/include/asm/tlbflush.h +18 −0
  24. arch/riscv/include/asm/vdso.h +1 −1
  25. arch/riscv/include/asm/vmalloc.h +18 −0
  26. arch/riscv/include/uapi/asm/ucontext.h +8 −4
  27. arch/riscv/kernel/Makefile +1 −0
  28. arch/riscv/kernel/cpu.c +27 −3
  29. arch/riscv/kernel/cpufeature.c +33 −10
  30. arch/riscv/kernel/crash_core.c +21 −0
  31. arch/riscv/kernel/elf_kexec.c +14 −0
  32. arch/riscv/kernel/entry.S +7 −14
  33. arch/riscv/kernel/mcount.S +23 −21
  34. arch/riscv/kernel/probes/Makefile +1 −1
  35. arch/riscv/kernel/probes/kprobes.c +0 −13
  36. arch/riscv/kernel/probes/rethook.c +27 −0
  37. arch/riscv/kernel/probes/rethook.h +8 −0
  38. arch/riscv/kernel/probes/rethook_trampoline.S +3 −3
  39. arch/riscv/kernel/signal.c +21 −13
  40. arch/riscv/kernel/stacktrace.c +10 −1
  41. arch/riscv/kernel/traps.c +14 −8
  42. arch/riscv/mm/Makefile +2 −0
  43. arch/riscv/mm/cacheflush.c +7 −0
  44. arch/riscv/mm/context.c +10 −0
  45. arch/riscv/mm/init.c +13 −12
  46. arch/riscv/mm/pgtable.c +83 −0
  47. arch/riscv/mm/physaddr.c +1 −1
  48. arch/riscv/mm/pmem.c +21 −0
  49. arch/riscv/mm/tlbflush.c +11 −17
  50. drivers/irqchip/Kconfig +2 −19
  51. drivers/perf/riscv_pmu_sbi.c +24 −10
  52. scripts/head-object-list.txt +0 −1
Documentation/admin-guide/kdump/vmcoreinfo.rst+29−0
@@ -595,3 +595,32 @@ X2TLB · 594 unmodified lines
595595 -----
596596
597597 Indicates whether the crashed kernel enabled SH extended mode.
598+
599+RISCV64
600+=======
601+
602+VA_BITS
603+-------
604+
605+The maximum number of bits for virtual addresses. Used to compute the
606+virtual memory ranges.
607+
608+PAGE_OFFSET
609+-----------
610+
611+Indicates the virtual kernel start address of the direct-mapped RAM region.
612+
613+phys_ram_base
614+-------------
615+
616+Indicates the start physical RAM address.
617+
618+MODULES_VADDR|MODULES_END|VMALLOC_START|VMALLOC_END|VMEMMAP_START|VMEMMAP_END|KERNEL_LINK_ADDR
619+----------------------------------------------------------------------------------------------
620+
621+Used to get the correct ranges:
622+
623+ * MODULES_VADDR ~ MODULES_END : Kernel module space.
624+ * VMALLOC_START ~ VMALLOC_END : vmalloc() / ioremap() space.
625+ * VMEMMAP_START ~ VMEMMAP_END : vmemmap space, used for struct page array.
626+ * KERNEL_LINK_ADDR : start address of Kernel link and BPF
Documentation/features/vm/huge-vmap/arch-support.txt+1−1
@@ -21,7 +21,7 @@ · 20 unmodified lines
2121 | openrisc: | TODO |
2222 | parisc: | TODO |
2323 | powerpc: | ok |
24− | riscv: | TODO |
24+ | riscv: | ok |
2525 | s390: | TODO |
2626 | sh: | TODO |
2727 | sparc: | TODO |
Documentation/riscv/patch-acceptance.rst+14−8
@@ -20,16 +20,22 @@ Submit Checklist Addendum · 19 unmodified lines
2020 -------------------------
2121 We'll only accept patches for new modules or extensions if the
2222 specifications for those modules or extensions are listed as being
23−"Frozen" or "Ratified" by the RISC-V Foundation. (Developers may, of
24−course, maintain their own Linux kernel trees that contain code for
25−any draft extensions that they wish.)
23+unlikely to be incompatibly changed in the future. For
24+specifications from the RISC-V foundation this means "Frozen" or
25+"Ratified", for the UEFI forum specifications this means a published
26+ECR. (Developers may, of course, maintain their own Linux kernel trees
27+that contain code for any draft extensions that they wish.)
2628
27−Additionally, the RISC-V specification allows implementors to create
29+Additionally, the RISC-V specification allows implementers to create
2830 their own custom extensions. These custom extensions aren't required
2931 to go through any review or ratification process by the RISC-V
3032 Foundation. To avoid the maintenance complexity and potential
3133 performance impact of adding kernel code for implementor-specific
32−RISC-V extensions, we'll only to accept patches for extensions that
33−have been officially frozen or ratified by the RISC-V Foundation.
34−(Implementors, may, of course, maintain their own Linux kernel trees
35−containing code for any custom extensions that they wish.)
34+RISC-V extensions, we'll only consider patches for extensions that either:
35+
36+- Have been officially frozen or ratified by the RISC-V Foundation, or
37+- Have been implemented in hardware that is widely available, per standard
38+ Linux practice.
39+
40+(Implementers, may, of course, maintain their own Linux kernel trees containing
41+code for any custom extensions that they wish.)
arch/riscv/Kconfig+13−6
@@ -25,6 +25,7 @@ config RISCV · 24 unmodified lines
2525 select ARCH_HAS_GIGANTIC_PAGE
2626 select ARCH_HAS_KCOV
2727 select ARCH_HAS_MMIOWB
28+ select ARCH_HAS_PMEM_API
2829 select ARCH_HAS_PTE_SPECIAL
2930 select ARCH_HAS_SET_DIRECT_MAP if MMU
3031 select ARCH_HAS_SET_MEMORY if MMU
@@ -72,6 +73,8 @@ config RISCV · 41 unmodified lines
7273 select GENERIC_VDSO_TIME_NS if HAVE_GENERIC_VDSO
7374 select HARDIRQS_SW_RESEND
7475 select HAVE_ARCH_AUDITSYSCALL
76+ select HAVE_ARCH_HUGE_VMALLOC if HAVE_ARCH_HUGE_VMAP
77+ select HAVE_ARCH_HUGE_VMAP if MMU && 64BIT && !XIP_KERNEL
7578 select HAVE_ARCH_JUMP_LABEL if !XIP_KERNEL
7679 select HAVE_ARCH_JUMP_LABEL_RELATIVE if !XIP_KERNEL
7780 select HAVE_ARCH_KASAN if MMU && 64BIT
@@ -99,6 +102,7 @@ config RISCV · 21 unmodified lines
99102 select HAVE_KPROBES if !XIP_KERNEL
100103 select HAVE_KPROBES_ON_FTRACE if !XIP_KERNEL
101104 select HAVE_KRETPROBES if !XIP_KERNEL
105+ select HAVE_RETHOOK if !XIP_KERNEL
102106 select HAVE_MOVE_PMD
103107 select HAVE_MOVE_PUD
104108 select HAVE_PCI
@@ -123,12 +127,18 @@ config RISCV · 18 unmodified lines
123127 select PCI_MSI if PCI
124128 select RISCV_INTC
125129 select RISCV_TIMER if RISCV_SBI
130+ select SIFIVE_PLIC
126131 select SPARSE_IRQ
127132 select SYSCTL_EXCEPTION_TRACE
128133 select THREAD_INFO_IN_TASK
129134 select TRACE_IRQFLAGS_SUPPORT
130135 select UACCESS_MEMCPY if !MMU
131136 select ZONE_DMA32 if 64BIT
137+ select HAVE_DYNAMIC_FTRACE if !XIP_KERNEL && MMU && $(cc-option,-fpatchable-function-entry=8)
138+ select HAVE_DYNAMIC_FTRACE_WITH_REGS if HAVE_DYNAMIC_FTRACE
139+ select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL
140+ select HAVE_FUNCTION_GRAPH_TRACER
141+ select HAVE_FUNCTION_TRACER if !XIP_KERNEL
132142
133143 config ARCH_MMAP_RND_BITS_MIN
134144 default 18 if 64BIT
@@ -274,11 +284,6 @@ config ARCH_RV64I · 139 unmodified lines
274284 bool "RV64I"
275285 select 64BIT
276286 select ARCH_SUPPORTS_INT128 if CC_HAS_INT128
277− select HAVE_DYNAMIC_FTRACE if !XIP_KERNEL && MMU && $(cc-option,-fpatchable-function-entry=8)
278− select HAVE_DYNAMIC_FTRACE_WITH_REGS if HAVE_DYNAMIC_FTRACE
279− select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL
280− select HAVE_FUNCTION_GRAPH_TRACER
281− select HAVE_FUNCTION_TRACER if !XIP_KERNEL
282287 select SWIOTLB if MMU
283288
284289 endchoice
@@ -502,7 +507,7 @@ config KEXEC_FILE · 217 unmodified lines
502507 select KEXEC_CORE
503508 select KEXEC_ELF
504509 select HAVE_IMA_KEXEC if IMA
505− depends on 64BIT
510+ depends on 64BIT && MMU
506511 help
507512 This is new version of kexec system call. This system call is
508513 file based and takes file descriptors as system call argument
@@ -691,6 +696,8 @@ menu "CPU Power Management" · 182 unmodified lines
691696
692697 source "drivers/cpuidle/Kconfig"
693698
699+source "drivers/cpufreq/Kconfig"
700+
694701 endmenu # "CPU Power Management"
695702
696703 source "arch/riscv/kvm/Kconfig"
arch/riscv/Kconfig.erratas+13−0
@@ -66,4 +66,17 @@ config ERRATA_THEAD_CMO · 65 unmodified lines
6666
6767 If you don't know what to do here, say "Y".
6868
69+config ERRATA_THEAD_PMU
70+ bool "Apply T-Head PMU errata"
71+ depends on ERRATA_THEAD && RISCV_PMU_SBI
72+ default y
73+ help
74+ The T-Head C9xx cores implement a PMU overflow extension very
75+ similar to the core SSCOFPMF extension.
76+
77+ This will apply the overflow errata to handle the non-standard
78+ behaviour via the regular SBI PMU driver and interface.
79+
80+ If you don't know what to do here, say "Y".
81+
6982 endmenu # "CPU errata selection"
arch/riscv/Kconfig.socs+0−5
@@ -3,7 +3,6 @@ menu "SoC selection" · 2 unmodified lines
33 config SOC_MICROCHIP_POLARFIRE
44 bool "Microchip PolarFire SoCs"
55 select MCHP_CLK_MPFS
6− select SIFIVE_PLIC
76 help
87 This enables support for Microchip PolarFire SoC platforms.
98
@@ -18,7 +17,6 @@ config SOC_SIFIVE · 8 unmodified lines
1817 select SERIAL_SIFIVE_CONSOLE if TTY
1918 select CLK_SIFIVE
2019 select CLK_SIFIVE_PRCI
21− select SIFIVE_PLIC
2220 select ERRATA_SIFIVE if !XIP_KERNEL
2321 help
2422 This enables support for SiFive SoC platform hardware.
@@ -27,7 +25,6 @@ config SOC_STARFIVE · 2 unmodified lines
2725 bool "StarFive SoCs"
2826 select PINCTRL
2927 select RESET_CONTROLLER
30− select SIFIVE_PLIC
3128 help
3229 This enables support for StarFive SoC platform hardware.
3330
@@ -39,7 +36,6 @@ config SOC_VIRT · 5 unmodified lines
3936 select POWER_RESET_SYSCON_POWEROFF
4037 select GOLDFISH
4138 select RTC_DRV_GOLDFISH if RTC_CLASS
42− select SIFIVE_PLIC
4339 select PM_GENERIC_DOMAINS if PM
4440 select PM_GENERIC_DOMAINS_OF if PM && OF
4541 select RISCV_SBI_CPUIDLE if CPU_IDLE && RISCV_SBI
@@ -52,7 +48,6 @@ config SOC_CANAAN · 6 unmodified lines
5248 select CLINT_TIMER if RISCV_M_MODE
5349 select SERIAL_SIFIVE if TTY
5450 select SERIAL_SIFIVE_CONSOLE if TTY
55− select SIFIVE_PLIC
5651 select ARCH_HAS_RESET_CONTROLLER
5752 select PINCTRL
5853 select COMMON_CLK
arch/riscv/boot/Makefile+3−0
@@ -56,6 +56,9 @@ $(obj)/Image.lzma: $(obj)/Image FORCE · 55 unmodified lines
5656 $(obj)/Image.lzo: $(obj)/Image FORCE
5757 $(call if_changed,lzo)
5858
59+$(obj)/Image.zst: $(obj)/Image FORCE
60+ $(call if_changed,zstd)
61+
5962 $(obj)/loader.bin: $(obj)/loader FORCE
6063 $(call if_changed,objcopy)
6164
arch/riscv/configs/defconfig+3−0
@@ -39,6 +39,7 @@ CONFIG_KVM=m · 38 unmodified lines
3939 CONFIG_JUMP_LABEL=y
4040 CONFIG_MODULES=y
4141 CONFIG_MODULE_UNLOAD=y
42+CONFIG_SPARSEMEM_MANUAL=y
4243 CONFIG_BLK_DEV_THROTTLING=y
4344 CONFIG_NET=y
4445 CONFIG_PACKET=y
@@ -123,6 +124,7 @@ CONFIG_MICROSEMI_PHY=y · 78 unmodified lines
123124 CONFIG_INPUT_MOUSEDEV=y
124125 CONFIG_SERIAL_8250=y
125126 CONFIG_SERIAL_8250_CONSOLE=y
127+CONFIG_SERIAL_8250_DW=y
126128 CONFIG_SERIAL_OF_PLATFORM=y
127129 CONFIG_SERIAL_SH_SCI=y
128130 CONFIG_VIRTIO_CONSOLE=y
@@ -162,6 +164,7 @@ CONFIG_RPMSG_CHAR=y · 33 unmodified lines
162164 CONFIG_RPMSG_CTRL=y
163165 CONFIG_RPMSG_VIRTIO=y
164166 CONFIG_ARCH_R9A07G043=y
167+CONFIG_LIBNVDIMM=y
165168 CONFIG_EXT4_FS=y
166169 CONFIG_EXT4_FS_POSIX_ACL=y
167170 CONFIG_EXT4_FS_SECURITY=y
arch/riscv/errata/thead/errata.c+19−0
@@ -47,6 +47,22 @@ static bool errata_probe_cmo(unsigned int stage, · 46 unmodified lines
4747 return true;
4848 }
4949
50+static bool errata_probe_pmu(unsigned int stage,
51+ unsigned long arch_id, unsigned long impid)
52+{
53+ if (!IS_ENABLED(CONFIG_ERRATA_THEAD_PMU))
54+ return false;
55+
56+ /* target-c9xx cores report arch_id and impid as 0 */
57+ if (arch_id != 0 || impid != 0)
58+ return false;
59+
60+ if (stage == RISCV_ALTERNATIVES_EARLY_BOOT)
61+ return false;
62+
63+ return true;
64+}
65+
5066 static u32 thead_errata_probe(unsigned int stage,
5167 unsigned long archid, unsigned long impid)
5268 {
@@ -58,6 +74,9 @@ static u32 thead_errata_probe(unsigned int stage, · 5 unmodified lines
5874 if (errata_probe_cmo(stage, archid, impid))
5975 cpu_req_errata |= BIT(ERRATA_THEAD_CMO);
6076
77+ if (errata_probe_pmu(stage, archid, impid))
78+ cpu_req_errata |= BIT(ERRATA_THEAD_PMU);
79+
6180 return cpu_req_errata;
6281 }
6382
arch/riscv/include/asm/alternative-macros.h+30−69
@@ -33,7 +33,7 @@ · 32 unmodified lines
3333 .endif
3434 .endm
3535
36−.macro __ALTERNATIVE_CFG old_c, new_c, vendor_id, errata_id, enable
36+.macro ALTERNATIVE_CFG old_c, new_c, vendor_id, errata_id, enable
3737 886 :
3838 .option push
3939 .option norvc
@@ -44,30 +44,14 @@ · 4 unmodified lines
4444 ALT_NEW_CONTENT \vendor_id, \errata_id, \enable, \new_c
4545 .endm
4646
47−#define _ALTERNATIVE_CFG(old_c, new_c, vendor_id, errata_id, CONFIG_k) \
48− __ALTERNATIVE_CFG old_c, new_c, vendor_id, errata_id, IS_ENABLED(CONFIG_k)
49−
50−.macro __ALTERNATIVE_CFG_2 old_c, new_c_1, vendor_id_1, errata_id_1, enable_1, \
51− new_c_2, vendor_id_2, errata_id_2, enable_2
52−886 :
53− .option push
54− .option norvc
55− .option norelax
56− \old_c
57− .option pop
58−887 :
59− ALT_NEW_CONTENT \vendor_id_1, \errata_id_1, \enable_1, \new_c_1
47+.macro ALTERNATIVE_CFG_2 old_c, new_c_1, vendor_id_1, errata_id_1, enable_1, \
48+ new_c_2, vendor_id_2, errata_id_2, enable_2
49+ ALTERNATIVE_CFG \old_c, \new_c_1, \vendor_id_1, \errata_id_1, \enable_1
6050 ALT_NEW_CONTENT \vendor_id_2, \errata_id_2, \enable_2, \new_c_2
6151 .endm
6252
63−#define _ALTERNATIVE_CFG_2(old_c, new_c_1, vendor_id_1, errata_id_1, \
64− CONFIG_k_1, \
65− new_c_2, vendor_id_2, errata_id_2, \
66− CONFIG_k_2) \
67− __ALTERNATIVE_CFG_2 old_c, new_c_1, vendor_id_1, errata_id_1, \
68− IS_ENABLED(CONFIG_k_1), \
69− new_c_2, vendor_id_2, errata_id_2, \
70− IS_ENABLED(CONFIG_k_2)
53+#define __ALTERNATIVE_CFG(...) ALTERNATIVE_CFG __VA_ARGS__
54+#define __ALTERNATIVE_CFG_2(...) ALTERNATIVE_CFG_2 __VA_ARGS__
7155
7256 #else /* !__ASSEMBLY__ */
7357
@@ -109,63 +93,44 @@ · 35 unmodified lines
10993 "887 :\n" \
11094 ALT_NEW_CONTENT(vendor_id, errata_id, enable, new_c)
11195
112−#define _ALTERNATIVE_CFG(old_c, new_c, vendor_id, errata_id, CONFIG_k) \
113− __ALTERNATIVE_CFG(old_c, new_c, vendor_id, errata_id, IS_ENABLED(CONFIG_k))
114−
115−#define __ALTERNATIVE_CFG_2(old_c, new_c_1, vendor_id_1, errata_id_1, \
116− enable_1, \
117− new_c_2, vendor_id_2, errata_id_2, \
118− enable_2) \
119− "886 :\n" \
120− ".option push\n" \
121− ".option norvc\n" \
122− ".option norelax\n" \
123− old_c "\n" \
124− ".option pop\n" \
125− "887 :\n" \
126− ALT_NEW_CONTENT(vendor_id_1, errata_id_1, enable_1, new_c_1) \
96+#define __ALTERNATIVE_CFG_2(old_c, new_c_1, vendor_id_1, errata_id_1, enable_1, \
97+ new_c_2, vendor_id_2, errata_id_2, enable_2) \
98+ __ALTERNATIVE_CFG(old_c, new_c_1, vendor_id_1, errata_id_1, enable_1) \
12799 ALT_NEW_CONTENT(vendor_id_2, errata_id_2, enable_2, new_c_2)
128100
129−#define _ALTERNATIVE_CFG_2(old_c, new_c_1, vendor_id_1, errata_id_1, \
130− CONFIG_k_1, \
131− new_c_2, vendor_id_2, errata_id_2, \
132− CONFIG_k_2) \
133− __ALTERNATIVE_CFG_2(old_c, new_c_1, vendor_id_1, errata_id_1, \
134− IS_ENABLED(CONFIG_k_1), \
135− new_c_2, vendor_id_2, errata_id_2, \
136− IS_ENABLED(CONFIG_k_2))
137−
138101 #endif /* __ASSEMBLY__ */
139102
103+#define _ALTERNATIVE_CFG(old_c, new_c, vendor_id, errata_id, CONFIG_k) \
104+ __ALTERNATIVE_CFG(old_c, new_c, vendor_id, errata_id, IS_ENABLED(CONFIG_k))
105+
106+#define _ALTERNATIVE_CFG_2(old_c, new_c_1, vendor_id_1, errata_id_1, CONFIG_k_1, \
107+ new_c_2, vendor_id_2, errata_id_2, CONFIG_k_2) \
108+ __ALTERNATIVE_CFG_2(old_c, new_c_1, vendor_id_1, errata_id_1, IS_ENABLED(CONFIG_k_1), \
109+ new_c_2, vendor_id_2, errata_id_2, IS_ENABLED(CONFIG_k_2))
110+
140111 #else /* CONFIG_RISCV_ALTERNATIVE */
141112 #ifdef __ASSEMBLY__
142113
143−.macro __ALTERNATIVE_CFG old_c
114+.macro ALTERNATIVE_CFG old_c
144115 \old_c
145116 .endm
146117
147−#define _ALTERNATIVE_CFG(old_c, new_c, vendor_id, errata_id, CONFIG_k) \
148− __ALTERNATIVE_CFG old_c
118+#define _ALTERNATIVE_CFG(old_c, ...) \
119+ ALTERNATIVE_CFG old_c
149120
150−#define _ALTERNATIVE_CFG_2(old_c, new_c_1, vendor_id_1, errata_id_1, \
151− CONFIG_k_1, \
152− new_c_2, vendor_id_2, errata_id_2, \
153− CONFIG_k_2) \
154− __ALTERNATIVE_CFG old_c
121+#define _ALTERNATIVE_CFG_2(old_c, ...) \
122+ ALTERNATIVE_CFG old_c
155123
156124 #else /* !__ASSEMBLY__ */
157125
158−#define __ALTERNATIVE_CFG(old_c) \
126+#define __ALTERNATIVE_CFG(old_c) \
159127 old_c "\n"
160128
161−#define _ALTERNATIVE_CFG(old_c, new_c, vendor_id, errata_id, CONFIG_k) \
129+#define _ALTERNATIVE_CFG(old_c, ...) \
162130 __ALTERNATIVE_CFG(old_c)
163131
164−#define _ALTERNATIVE_CFG_2(old_c, new_c_1, vendor_id_1, errata_id_1, \
165− CONFIG_k_1, \
166− new_c_2, vendor_id_2, errata_id_2, \
167− CONFIG_k_2) \
168− __ALTERNATIVE_CFG(old_c)
132+#define _ALTERNATIVE_CFG_2(old_c, ...) \
133+ __ALTERNATIVE_CFG(old_c)
169134
170135 #endif /* __ASSEMBLY__ */
171136 #endif /* CONFIG_RISCV_ALTERNATIVE */
@@ -193,13 +158,9 @@ · 21 unmodified lines
193158 * on the following sample code and then replace ALTERNATIVE() with
194159 * ALTERNATIVE_2() to append its customized content.
195160 */
196−#define ALTERNATIVE_2(old_content, new_content_1, vendor_id_1, \
197− errata_id_1, CONFIG_k_1, \
198− new_content_2, vendor_id_2, \
199− errata_id_2, CONFIG_k_2) \
200− _ALTERNATIVE_CFG_2(old_content, new_content_1, vendor_id_1, \
201− errata_id_1, CONFIG_k_1, \
202− new_content_2, vendor_id_2, \
203− errata_id_2, CONFIG_k_2)
161+#define ALTERNATIVE_2(old_content, new_content_1, vendor_id_1, errata_id_1, CONFIG_k_1, \
162+ new_content_2, vendor_id_2, errata_id_2, CONFIG_k_2) \
163+ _ALTERNATIVE_CFG_2(old_content, new_content_1, vendor_id_1, errata_id_1, CONFIG_k_1, \
164+ new_content_2, vendor_id_2, errata_id_2, CONFIG_k_2)
204165
205166 #endif
arch/riscv/include/asm/cacheflush.h+7−0
@@ -17,6 +17,13 @@ static inline void local_flush_icache_all(void) · 16 unmodified lines
1717
1818 static inline void flush_dcache_page(struct page *page)
1919 {
20+ /*
21+ * HugeTLB pages are always fully mapped and only head page will be
22+ * set PG_dcache_clean (see comments in flush_icache_pte()).
23+ */
24+ if (PageHuge(page))
25+ page = compound_head(page);
26+
2027 if (test_bit(PG_dcache_clean, &page->flags))
2128 clear_bit(PG_dcache_clean, &page->flags);
2229 }
arch/riscv/include/asm/errata_list.h+15−1
@@ -6,6 +6,7 @@ · 5 unmodified lines
66 #define ASM_ERRATA_LIST_H
77
88 #include <asm/alternative.h>
9+#include <asm/csr.h>
910 #include <asm/vendorid_list.h>
1011
1112 #ifdef CONFIG_ERRATA_SIFIVE
@@ -17,7 +18,8 @@ · 5 unmodified lines
1718 #ifdef CONFIG_ERRATA_THEAD
1819 #define ERRATA_THEAD_PBMT 0
1920 #define ERRATA_THEAD_CMO 1
20−#define ERRATA_THEAD_NUMBER 2
21+#define ERRATA_THEAD_PMU 2
22+#define ERRATA_THEAD_NUMBER 3
2123 #endif
2224
2325 #define CPUFEATURE_SVPBMT 0
@@ -142,6 +144,18 @@ asm volatile(ALTERNATIVE_2( \ · 118 unmodified lines
142144 "r"((unsigned long)(_start) + (_size)) \
143145 : "a0")
144146
147+#define THEAD_C9XX_RV_IRQ_PMU 17
148+#define THEAD_C9XX_CSR_SCOUNTEROF 0x5c5
149+
150+#define ALT_SBI_PMU_OVERFLOW(__ovl) \
151+asm volatile(ALTERNATIVE( \
152+ "csrr %0, " __stringify(CSR_SSCOUNTOVF), \
153+ "csrr %0, " __stringify(THEAD_C9XX_CSR_SCOUNTEROF), \
154+ THEAD_VENDOR_ID, ERRATA_THEAD_PMU, \
155+ CONFIG_ERRATA_THEAD_PMU) \
156+ : "=r" (__ovl) : \
157+ : "memory")
158+
145159 #endif /* __ASSEMBLY__ */
146160
147161 #endif
arch/riscv/include/asm/hugetlb.h+6−0
@@ -5,4 +5,10 @@ · 4 unmodified lines
55 #include <asm-generic/hugetlb.h>
66 #include <asm/page.h>
77
8+static inline void arch_clear_hugepage_flags(struct page *page)
9+{
10+ clear_bit(PG_dcache_clean, &page->flags);
11+}
12+#define arch_clear_hugepage_flags arch_clear_hugepage_flags
13+
814 #endif /* _ASM_RISCV_HUGETLB_H */
arch/riscv/include/asm/hwcap.h+2−1
@@ -59,8 +59,9 @@ enum riscv_isa_ext_id { · 58 unmodified lines
5959 RISCV_ISA_EXT_ZIHINTPAUSE,
6060 RISCV_ISA_EXT_SSTC,
6161 RISCV_ISA_EXT_SVINVAL,
62− RISCV_ISA_EXT_ID_MAX = RISCV_ISA_EXT_MAX,
62+ RISCV_ISA_EXT_ID_MAX
6363 };
64+static_assert(RISCV_ISA_EXT_ID_MAX <= RISCV_ISA_EXT_MAX);
6465
6566 /*
6667 * This enum represents the logical ID for each RISC-V ISA extension static
arch/riscv/include/asm/io.h+5−0
@@ -135,4 +135,9 @@ __io_writes_outs(outs, u64, q, __io_pbr(), __io_paw()) · 134 unmodified lines
135135
136136 #include <asm-generic/io.h>
137137
138+#ifdef CONFIG_MMU
139+#define arch_memremap_wb(addr, size) \
140+ ((__force void *)ioremap_prot((addr), (size), _PAGE_KERNEL))
141+#endif
142+
138143 #endif /* _ASM_RISCV_IO_H */
arch/riscv/include/asm/kexec.h+5−0
@@ -39,6 +39,7 @@ crash_setup_regs(struct pt_regs *newregs, · 38 unmodified lines
3939 #define ARCH_HAS_KIMAGE_ARCH
4040
4141 struct kimage_arch {
42+ void *fdt; /* For CONFIG_KEXEC_FILE */
4243 unsigned long fdt_addr;
4344 };
4445
@@ -62,6 +63,10 @@ int arch_kexec_apply_relocations_add(struct purgatory_info *pi, · 17 unmodified lines
6263 const Elf_Shdr *relsec,
6364 const Elf_Shdr *symtab);
6465 #define arch_kexec_apply_relocations_add arch_kexec_apply_relocations_add
66+
67+struct kimage;
68+int arch_kimage_file_post_load_cleanup(struct kimage *image);
69+#define arch_kimage_file_post_load_cleanup arch_kimage_file_post_load_cleanup
6570 #endif
6671
6772 #endif
arch/riscv/include/asm/kprobes.h+0−2
@@ -40,8 +40,6 @@ void arch_remove_kprobe(struct kprobe *p); · 39 unmodified lines
4040 int kprobe_fault_handler(struct pt_regs *regs, unsigned int trapnr);
4141 bool kprobe_breakpoint_handler(struct pt_regs *regs);
4242 bool kprobe_single_step_handler(struct pt_regs *regs);
43−void __kretprobe_trampoline(void);
44−void __kprobes *trampoline_probe_handler(struct pt_regs *regs);
4543
4644 #endif /* CONFIG_KPROBES */
4745 #endif /* _ASM_RISCV_KPROBES_H */
arch/riscv/include/asm/mmu.h+2−0
@@ -19,6 +19,8 @@ typedef struct { · 18 unmodified lines
1919 #ifdef CONFIG_SMP
2020 /* A local icache flush is needed before user execution can resume. */
2121 cpumask_t icache_stale_mask;
22+ /* A local tlb flush is needed before user execution can resume. */
23+ cpumask_t tlb_stale_mask;
2224 #endif
2325 } mm_context_t;
2426
arch/riscv/include/asm/page.h+9−9
@@ -123,20 +123,20 @@ extern phys_addr_t phys_ram_base; · 122 unmodified lines
123123 ((x) >= PAGE_OFFSET && (!IS_ENABLED(CONFIG_64BIT) || (x) < PAGE_OFFSET + KERN_VIRT_SIZE))
124124
125125 #define linear_mapping_pa_to_va(x) ((void *)((unsigned long)(x) + kernel_map.va_pa_offset))
126−#define kernel_mapping_pa_to_va(y) ({ \
127− unsigned long _y = y; \
128− (IS_ENABLED(CONFIG_XIP_KERNEL) && _y < phys_ram_base) ? \
129− (void *)((unsigned long)(_y) + kernel_map.va_kernel_xip_pa_offset) : \
130− (void *)((unsigned long)(_y) + kernel_map.va_kernel_pa_offset + XIP_OFFSET); \
126+#define kernel_mapping_pa_to_va(y) ({ \
127+ unsigned long _y = (unsigned long)(y); \
128+ (IS_ENABLED(CONFIG_XIP_KERNEL) && _y < phys_ram_base) ? \
129+ (void *)(_y + kernel_map.va_kernel_xip_pa_offset) : \
130+ (void *)(_y + kernel_map.va_kernel_pa_offset + XIP_OFFSET); \
131131 })
132132 #define __pa_to_va_nodebug(x) linear_mapping_pa_to_va(x)
133133
134134 #define linear_mapping_va_to_pa(x) ((unsigned long)(x) - kernel_map.va_pa_offset)
135135 #define kernel_mapping_va_to_pa(y) ({ \
136− unsigned long _y = y; \
137− (IS_ENABLED(CONFIG_XIP_KERNEL) && _y < kernel_map.virt_addr + XIP_OFFSET) ? \
138− ((unsigned long)(_y) - kernel_map.va_kernel_xip_pa_offset) : \
139− ((unsigned long)(_y) - kernel_map.va_kernel_pa_offset - XIP_OFFSET); \
136+ unsigned long _y = (unsigned long)(y); \
137+ (IS_ENABLED(CONFIG_XIP_KERNEL) && _y < kernel_map.virt_addr + XIP_OFFSET) ? \
138+ (_y - kernel_map.va_kernel_xip_pa_offset) : \
139+ (_y - kernel_map.va_kernel_pa_offset - XIP_OFFSET); \
140140 })
141141
142142 #define __va_to_pa_nodebug(x) ({ \
arch/riscv/include/asm/pgtable-64.h+5−1
@@ -25,7 +25,11 @@ extern bool pgtable_l5_enabled; · 24 unmodified lines
2525 #define PGDIR_MASK (~(PGDIR_SIZE - 1))
2626
2727 /* p4d is folded into pgd in case of 4-level page table */
28−#define P4D_SHIFT 39
28+#define P4D_SHIFT_L3 30
29+#define P4D_SHIFT_L4 39
30+#define P4D_SHIFT_L5 39
31+#define P4D_SHIFT (pgtable_l5_enabled ? P4D_SHIFT_L5 : \
32+ (pgtable_l4_enabled ? P4D_SHIFT_L4 : P4D_SHIFT_L3))
2933 #define P4D_SIZE (_AC(1, UL) << P4D_SHIFT)
3034 #define P4D_MASK (~(P4D_SIZE - 1))
3135
arch/riscv/include/asm/pgtable.h+4−1
@@ -415,9 +415,12 @@ static inline void update_mmu_cache(struct vm_area_struct *vma, · 414 unmodified lines
415415 * Relying on flush_tlb_fix_spurious_fault would suffice, but
416416 * the extra traps reduce performance. So, eagerly SFENCE.VMA.
417417 */
418− local_flush_tlb_page(address);
418+ flush_tlb_page(vma, address);
419419 }
420420
421+#define __HAVE_ARCH_UPDATE_MMU_TLB
422+#define update_mmu_tlb update_mmu_cache
423+
421424 static inline void update_mmu_cache_pmd(struct vm_area_struct *vma,
422425 unsigned long address, pmd_t *pmdp)
423426 {
arch/riscv/include/asm/sbi.h+5−0
@@ -327,4 +327,9 @@ int sbi_err_map_linux_errno(int err); · 326 unmodified lines
327327 static inline int sbi_remote_fence_i(const struct cpumask *cpu_mask) { return -1; }
328328 static inline void sbi_init(void) {}
329329 #endif /* CONFIG_RISCV_SBI */
330+
331+unsigned long riscv_cached_mvendorid(unsigned int cpu_id);
332+unsigned long riscv_cached_marchid(unsigned int cpu_id);
333+unsigned long riscv_cached_mimpid(unsigned int cpu_id);
334+
330335 #endif /* _ASM_RISCV_SBI_H */
arch/riscv/include/asm/tlbflush.h+18−0
@@ -22,6 +22,24 @@ static inline void local_flush_tlb_page(unsigned long addr) · 21 unmodified lines
2222 {
2323 ALT_FLUSH_TLB_PAGE(__asm__ __volatile__ ("sfence.vma %0" : : "r" (addr) : "memory"));
2424 }
25+
26+static inline void local_flush_tlb_all_asid(unsigned long asid)
27+{
28+ __asm__ __volatile__ ("sfence.vma x0, %0"
29+ :
30+ : "r" (asid)
31+ : "memory");
32+}
33+
34+static inline void local_flush_tlb_page_asid(unsigned long addr,
35+ unsigned long asid)
36+{
37+ __asm__ __volatile__ ("sfence.vma %0, %1"
38+ :
39+ : "r" (addr), "r" (asid)
40+ : "memory");
41+}
42+
2543 #else /* CONFIG_MMU */
2644 #define local_flush_tlb_all() do { } while (0)
2745 #define local_flush_tlb_page(addr) do { } while (0)
arch/riscv/include/asm/vdso.h+1−1
@@ -10,7 +10,7 @@ · 9 unmodified lines
1010
1111 /*
1212 * All systems with an MMU have a VDSO, but systems without an MMU don't
13− * support shared libraries and therefor don't have one.
13+ * support shared libraries and therefore don't have one.
1414 */
1515 #ifdef CONFIG_MMU
1616
arch/riscv/include/asm/vmalloc.h+18−0
@@ -1,4 +1,22 @@
11 #ifndef _ASM_RISCV_VMALLOC_H
22 #define _ASM_RISCV_VMALLOC_H
33
4+#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP
5+
6+#define IOREMAP_MAX_ORDER (PUD_SHIFT)
7+
8+#define arch_vmap_pud_supported arch_vmap_pud_supported
9+static inline bool arch_vmap_pud_supported(pgprot_t prot)
10+{
11+ return true;
12+}
13+
14+#define arch_vmap_pmd_supported arch_vmap_pmd_supported
15+static inline bool arch_vmap_pmd_supported(pgprot_t prot)
16+{
17+ return true;
18+}
19+
20+#endif
21+
422 #endif /* _ASM_RISCV_VMALLOC_H */
arch/riscv/include/uapi/asm/ucontext.h+8−4
@@ -15,19 +15,23 @@ struct ucontext { · 14 unmodified lines
1515 struct ucontext *uc_link;
1616 stack_t uc_stack;
1717 sigset_t uc_sigmask;
18− /* There's some padding here to allow sigset_t to be expanded in the
18+ /*
19+ * There's some padding here to allow sigset_t to be expanded in the
1920 * future. Though this is unlikely, other architectures put uc_sigmask
2021 * at the end of this structure and explicitly state it can be
21− * expanded, so we didn't want to box ourselves in here. */
22+ * expanded, so we didn't want to box ourselves in here.
23+ */
2224 __u8 __unused[1024 / 8 - sizeof(sigset_t)];
23− /* We can't put uc_sigmask at the end of this structure because we need
25+ /*
26+ * We can't put uc_sigmask at the end of this structure because we need
2427 * to be able to expand sigcontext in the future. For example, the
2528 * vector ISA extension will almost certainly add ISA state. We want
2629 * to ensure all user-visible ISA state can be saved and restored via a
2730 * ucontext, so we're putting this at the end in order to allow for
2831 * infinite extensibility. Since we know this will be extended and we
2932 * assume sigset_t won't be extended an extreme amount, we're
30− * prioritizing this. */
33+ * prioritizing this.
34+ */
3135 struct sigcontext uc_mcontext;
3236 };
3337
arch/riscv/kernel/Makefile+1−0
@@ -81,6 +81,7 @@ obj-$(CONFIG_KGDB) += kgdb.o · 80 unmodified lines
8181 obj-$(CONFIG_KEXEC_CORE) += kexec_relocate.o crash_save_regs.o machine_kexec.o
8282 obj-$(CONFIG_KEXEC_FILE) += elf_kexec.o machine_kexec_file.o
8383 obj-$(CONFIG_CRASH_DUMP) += crash_dump.o
84+obj-$(CONFIG_CRASH_CORE) += crash_core.o
8485
8586 obj-$(CONFIG_JUMP_LABEL) += jump_label.o
8687
arch/riscv/kernel/cpu.c+27−3
@@ -70,8 +70,6 @@ int riscv_of_parent_hartid(struct device_node *node, unsigned long *hartid) · 69 unmodified lines
7070 return -1;
7171 }
7272
73−#ifdef CONFIG_PROC_FS
74−
7573 struct riscv_cpuinfo {
7674 unsigned long mvendorid;
7775 unsigned long marchid;
@@ -79,6 +77,30 @@ struct riscv_cpuinfo { · 1 unmodified line
7977 };
8078 static DEFINE_PER_CPU(struct riscv_cpuinfo, riscv_cpuinfo);
8179
80+unsigned long riscv_cached_mvendorid(unsigned int cpu_id)
81+{
82+ struct riscv_cpuinfo *ci = per_cpu_ptr(&riscv_cpuinfo, cpu_id);
83+
84+ return ci->mvendorid;
85+}
86+EXPORT_SYMBOL(riscv_cached_mvendorid);
87+
88+unsigned long riscv_cached_marchid(unsigned int cpu_id)
89+{
90+ struct riscv_cpuinfo *ci = per_cpu_ptr(&riscv_cpuinfo, cpu_id);
91+
92+ return ci->marchid;
93+}
94+EXPORT_SYMBOL(riscv_cached_marchid);
95+
96+unsigned long riscv_cached_mimpid(unsigned int cpu_id)
97+{
98+ struct riscv_cpuinfo *ci = per_cpu_ptr(&riscv_cpuinfo, cpu_id);
99+
100+ return ci->mimpid;
101+}
102+EXPORT_SYMBOL(riscv_cached_mimpid);
103+
82104 static int riscv_cpuinfo_starting(unsigned int cpu)
83105 {
84106 struct riscv_cpuinfo *ci = this_cpu_ptr(&riscv_cpuinfo);
@@ -113,7 +135,9 @@ static int __init riscv_cpuinfo_init(void) · 28 unmodified lines
113135
114136 return 0;
115137 }
116−device_initcall(riscv_cpuinfo_init);
138+arch_initcall(riscv_cpuinfo_init);
139+
140+#ifdef CONFIG_PROC_FS
117141
118142 #define __RISCV_ISA_EXT_DATA(UPROP, EXTID) \
119143 { \
arch/riscv/kernel/cpufeature.c+33−10
@@ -9,6 +9,7 @@ · 8 unmodified lines
99 #include <linux/bitmap.h>
1010 #include <linux/ctype.h>
1111 #include <linux/libfdt.h>
12+#include <linux/log2.h>
1213 #include <linux/module.h>
1314 #include <linux/of.h>
1415 #include <asm/alternative.h>
@@ -68,21 +69,38 @@ bool __riscv_isa_extension_available(const unsigned long *isa_bitmap, int bit) · 53 unmodified lines
6869 }
6970 EXPORT_SYMBOL_GPL(__riscv_isa_extension_available);
7071
72+static bool riscv_isa_extension_check(int id)
73+{
74+ switch (id) {
75+ case RISCV_ISA_EXT_ZICBOM:
76+ if (!riscv_cbom_block_size) {
77+ pr_err("Zicbom detected in ISA string, but no cbom-block-size found\n");
78+ return false;
79+ } else if (!is_power_of_2(riscv_cbom_block_size)) {
80+ pr_err("cbom-block-size present, but is not a power-of-2\n");
81+ return false;
82+ }
83+ return true;
84+ }
85+
86+ return true;
87+}
88+
7189 void __init riscv_fill_hwcap(void)
7290 {
7391 struct device_node *node;
7492 const char *isa;
7593 char print_str[NUM_ALPHA_EXTS + 1];
7694 int i, j, rc;
77− static unsigned long isa2hwcap[256] = {0};
95+ unsigned long isa2hwcap[26] = {0};
7896 unsigned long hartid;
7997
80− isa2hwcap['i'] = isa2hwcap['I'] = COMPAT_HWCAP_ISA_I;
81− isa2hwcap['m'] = isa2hwcap['M'] = COMPAT_HWCAP_ISA_M;
82− isa2hwcap['a'] = isa2hwcap['A'] = COMPAT_HWCAP_ISA_A;
83− isa2hwcap['f'] = isa2hwcap['F'] = COMPAT_HWCAP_ISA_F;
84− isa2hwcap['d'] = isa2hwcap['D'] = COMPAT_HWCAP_ISA_D;
85− isa2hwcap['c'] = isa2hwcap['C'] = COMPAT_HWCAP_ISA_C;
98+ isa2hwcap['i' - 'a'] = COMPAT_HWCAP_ISA_I;
99+ isa2hwcap['m' - 'a'] = COMPAT_HWCAP_ISA_M;
100+ isa2hwcap['a' - 'a'] = COMPAT_HWCAP_ISA_A;
101+ isa2hwcap['f' - 'a'] = COMPAT_HWCAP_ISA_F;
102+ isa2hwcap['d' - 'a'] = COMPAT_HWCAP_ISA_D;
103+ isa2hwcap['c' - 'a'] = COMPAT_HWCAP_ISA_C;
86104
87105 elf_hwcap = 0;
88106
@@ -189,15 +207,20 @@ void __init riscv_fill_hwcap(void) · 100 unmodified lines
189207 #define SET_ISA_EXT_MAP(name, bit) \
190208 do { \
191209 if ((ext_end - ext == sizeof(name) - 1) && \
192− !memcmp(ext, name, sizeof(name) - 1)) \
210+ !memcmp(ext, name, sizeof(name) - 1) && \
211+ riscv_isa_extension_check(bit)) \
193212 set_bit(bit, this_isa); \
194213 } while (false) \
195214
196215 if (unlikely(ext_err))
197216 continue;
198217 if (!ext_long) {
199− this_hwcap |= isa2hwcap[(unsigned char)(*ext)];
200− set_bit(*ext - 'a', this_isa);
218+ int nr = *ext - 'a';
219+
220+ if (riscv_isa_extension_check(nr)) {
221+ this_hwcap |= isa2hwcap[nr];
222+ set_bit(nr, this_isa);
223+ }
201224 } else {
202225 SET_ISA_EXT_MAP("sscofpmf", RISCV_ISA_EXT_SSCOFPMF);
203226 SET_ISA_EXT_MAP("svpbmt", RISCV_ISA_EXT_SVPBMT);
arch/riscv/kernel/crash_core.c+21−0
@@ -0,0 +1,21 @@
1+// SPDX-License-Identifier: GPL-2.0-only
2+
3+#include <linux/crash_core.h>
4+#include <linux/pagemap.h>
5+
6+void arch_crash_save_vmcoreinfo(void)
7+{
8+ VMCOREINFO_NUMBER(VA_BITS);
9+ VMCOREINFO_NUMBER(phys_ram_base);
10+
11+ vmcoreinfo_append_str("NUMBER(PAGE_OFFSET)=0x%lx\n", PAGE_OFFSET);
12+ vmcoreinfo_append_str("NUMBER(VMALLOC_START)=0x%lx\n", VMALLOC_START);
13+ vmcoreinfo_append_str("NUMBER(VMALLOC_END)=0x%lx\n", VMALLOC_END);
14+ vmcoreinfo_append_str("NUMBER(VMEMMAP_START)=0x%lx\n", VMEMMAP_START);
15+ vmcoreinfo_append_str("NUMBER(VMEMMAP_END)=0x%lx\n", VMEMMAP_END);
16+#ifdef CONFIG_64BIT
17+ vmcoreinfo_append_str("NUMBER(MODULES_VADDR)=0x%lx\n", MODULES_VADDR);
18+ vmcoreinfo_append_str("NUMBER(MODULES_END)=0x%lx\n", MODULES_END);
19+#endif
20+ vmcoreinfo_append_str("NUMBER(KERNEL_LINK_ADDR)=0x%lx\n", KERNEL_LINK_ADDR);
21+}
arch/riscv/kernel/elf_kexec.c+14−0
@@ -21,6 +21,18 @@ · 20 unmodified lines
2121 #include <linux/memblock.h>
2222 #include <asm/setup.h>
2323
24+int arch_kimage_file_post_load_cleanup(struct kimage *image)
25+{
26+ kvfree(image->arch.fdt);
27+ image->arch.fdt = NULL;
28+
29+ vfree(image->elf_headers);
30+ image->elf_headers = NULL;
31+ image->elf_headers_sz = 0;
32+
33+ return kexec_image_post_load_cleanup_default(image);
34+}
35+
2436 static int riscv_kexec_elf_load(struct kimage *image, struct elfhdr *ehdr,
2537 struct kexec_elf_info *elf_info, unsigned long old_pbase,
2638 unsigned long new_pbase)
@@ -298,6 +310,8 @@ static void *elf_kexec_load(struct kimage *image, char *kernel_buf, · 271 unmodified lines
298310 pr_err("Error add DTB kbuf ret=%d\n", ret);
299311 goto out_free_fdt;
300312 }
313+ /* Cache the fdt buffer address for memory cleanup */
314+ image->arch.fdt = fdt;
301315 pr_notice("Loaded device tree at 0x%lx\n", kbuf.mem);
302316 goto out;
303317
arch/riscv/kernel/entry.S+7−14
@@ -248,7 +248,7 @@ ret_from_syscall_rejected: · 247 unmodified lines
248248 andi t0, t0, _TIF_SYSCALL_WORK
249249 bnez t0, handle_syscall_trace_exit
250250
251−ret_from_exception:
251+SYM_CODE_START_NOALIGN(ret_from_exception)
252252 REG_L s0, PT_STATUS(sp)
253253 csrc CSR_STATUS, SR_IE
254254 #ifdef CONFIG_TRACE_IRQFLAGS
@@ -262,13 +262,13 @@ ret_from_exception: · 7 unmodified lines
262262 andi s0, s0, SR_SPP
263263 #endif
264264 bnez s0, resume_kernel
265+SYM_CODE_END(ret_from_exception)
265266
266−resume_userspace:
267267 /* Interrupts must be disabled here so flags are checked atomically */
268268 REG_L s0, TASK_TI_FLAGS(tp) /* current_thread_info->flags */
269269 andi s1, s0, _TIF_WORK_MASK
270− bnez s1, work_pending
271−
270+ bnez s1, resume_userspace_slow
271+resume_userspace:
272272 #ifdef CONFIG_CONTEXT_TRACKING_USER
273273 call user_enter_callable
274274 #endif
@@ -368,19 +368,12 @@ resume_kernel: · 93 unmodified lines
368368 j restore_all
369369 #endif
370370
371−work_pending:
371+resume_userspace_slow:
372372 /* Enter slow path for supplementary processing */
373− la ra, ret_from_exception
374− andi s1, s0, _TIF_NEED_RESCHED
375− bnez s1, work_resched
376−work_notifysig:
377− /* Handle pending signals and notify-resume requests */
378− csrs CSR_STATUS, SR_IE /* Enable interrupts for do_notify_resume() */
379373 move a0, sp /* pt_regs */
380374 move a1, s0 /* current_thread_info->flags */
381− tail do_notify_resume
382−work_resched:
383− tail schedule
375+ call do_work_pending
376+ j resume_userspace
384377
385378 /* Slow paths for ptrace. */
386379 handle_syscall_trace_enter:
arch/riscv/kernel/mcount.S+23−21
@@ -15,8 +15,8 @@ · 14 unmodified lines
1515
1616 .macro SAVE_ABI_STATE
1717 addi sp, sp, -16
18− sd s0, 0(sp)
19− sd ra, 8(sp)
18+ REG_S s0, 0*SZREG(sp)
19+ REG_S ra, 1*SZREG(sp)
2020 addi s0, sp, 16
2121 .endm
2222
@@ -25,24 +25,26 @@ · 2 unmodified lines
2525 * register if a0 was not saved.
2626 */
2727 .macro SAVE_RET_ABI_STATE
28− addi sp, sp, -32
29− sd s0, 16(sp)
30− sd ra, 24(sp)
31− sd a0, 8(sp)
32− addi s0, sp, 32
28+ addi sp, sp, -4*SZREG
29+ REG_S s0, 2*SZREG(sp)
30+ REG_S ra, 3*SZREG(sp)
31+ REG_S a0, 1*SZREG(sp)
32+ REG_S a1, 0*SZREG(sp)
33+ addi s0, sp, 4*SZREG
3334 .endm
3435
3536 .macro RESTORE_ABI_STATE
36− ld ra, 8(sp)
37− ld s0, 0(sp)
37+ REG_L ra, 1*SZREG(sp)
38+ REG_L s0, 0*SZREG(sp)
3839 addi sp, sp, 16
3940 .endm
4041
4142 .macro RESTORE_RET_ABI_STATE
42− ld ra, 24(sp)
43− ld s0, 16(sp)
44− ld a0, 8(sp)
45− addi sp, sp, 32
43+ REG_L ra, 3*SZREG(sp)
44+ REG_L s0, 2*SZREG(sp)
45+ REG_L a0, 1*SZREG(sp)
46+ REG_L a1, 0*SZREG(sp)
47+ addi sp, sp, 4*SZREG
4648 .endm
4749
4850 ENTRY(ftrace_stub)
@@ -71,9 +73,9 @@ ENTRY(return_to_handler) · 22 unmodified lines
7173 mv a0, t6
7274 #endif
7375 call ftrace_return_to_handler
74− mv a1, a0
76+ mv a2, a0
7577 RESTORE_RET_ABI_STATE
76− jalr a1
78+ jalr a2
7779 ENDPROC(return_to_handler)
7880 #endif
7981
@@ -82,16 +84,16 @@ ENTRY(MCOUNT_NAME) · 2 unmodified lines
8284 la t4, ftrace_stub
8385 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8486 la t0, ftrace_graph_return
85− ld t1, 0(t0)
87+ REG_L t1, 0(t0)
8688 bne t1, t4, do_ftrace_graph_caller
8789
8890 la t3, ftrace_graph_entry
89− ld t2, 0(t3)
91+ REG_L t2, 0(t3)
9092 la t6, ftrace_graph_entry_stub
9193 bne t2, t6, do_ftrace_graph_caller
9294 #endif
9395 la t3, ftrace_trace_function
94− ld t5, 0(t3)
96+ REG_L t5, 0(t3)
9597 bne t5, t4, do_trace
9698 ret
9799
@@ -101,10 +103,10 @@ ENTRY(MCOUNT_NAME) · 3 unmodified lines
101103 * prepare_to_return(&ra_to_caller_of_caller, ra_to_caller)
102104 */
103105 do_ftrace_graph_caller:
104− addi a0, s0, -8
106+ addi a0, s0, -SZREG
105107 mv a1, ra
106108 #ifdef HAVE_FUNCTION_GRAPH_FP_TEST
107− ld a2, -16(s0)
109+ REG_L a2, -2*SZREG(s0)
108110 #endif
109111 SAVE_ABI_STATE
110112 call prepare_ftrace_return
@@ -117,7 +119,7 @@ do_ftrace_graph_caller: · 6 unmodified lines
117119 * (*ftrace_trace_function)(ra_to_caller, ra_to_caller_of_caller)
118120 */
119121 do_trace:
120− ld a1, -8(s0)
122+ REG_L a1, -SZREG(s0)
121123 mv a0, ra
122124
123125 SAVE_ABI_STATE
arch/riscv/kernel/probes/Makefile+1−1
@@ -1,6 +1,6 @@
11 # SPDX-License-Identifier: GPL-2.0
22 obj-$(CONFIG_KPROBES) += kprobes.o decode-insn.o simulate-insn.o
3−obj-$(CONFIG_KPROBES) += kprobes_trampoline.o
3+obj-$(CONFIG_RETHOOK) += rethook.o rethook_trampoline.o
44 obj-$(CONFIG_KPROBES_ON_FTRACE) += ftrace.o
55 obj-$(CONFIG_UPROBES) += uprobes.o decode-insn.o simulate-insn.o
66 CFLAGS_REMOVE_simulate-insn.o = $(CC_FLAGS_FTRACE)
arch/riscv/kernel/probes/kprobes.c+0−13
@@ -345,19 +345,6 @@ int __init arch_populate_kprobe_blacklist(void) · 344 unmodified lines
345345 return ret;
346346 }
347347
348−void __kprobes __used *trampoline_probe_handler(struct pt_regs *regs)
349−{
350− return (void *)kretprobe_trampoline_handler(regs, NULL);
351−}
352−
353−void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
354− struct pt_regs *regs)
355−{
356− ri->ret_addr = (kprobe_opcode_t *)regs->ra;
357− ri->fp = NULL;
358− regs->ra = (unsigned long) &__kretprobe_trampoline;
359−}
360−
361348 int __kprobes arch_trampoline_kprobe(struct kprobe *p)
362349 {
363350 return 0;
arch/riscv/kernel/probes/rethook.c+27−0
@@ -0,0 +1,27 @@
1+// SPDX-License-Identifier: GPL-2.0-only
2+/*
3+ * Generic return hook for riscv.
4+ */
5+
6+#include <linux/kprobes.h>
7+#include <linux/rethook.h>
8+#include "rethook.h"
9+
10+/* This is called from arch_rethook_trampoline() */
11+unsigned long __used arch_rethook_trampoline_callback(struct pt_regs *regs)
12+{
13+ return rethook_trampoline_handler(regs, regs->s0);
14+}
15+
16+NOKPROBE_SYMBOL(arch_rethook_trampoline_callback);
17+
18+void arch_rethook_prepare(struct rethook_node *rhn, struct pt_regs *regs, bool mcount)
19+{
20+ rhn->ret_addr = regs->ra;
21+ rhn->frame = regs->s0;
22+
23+ /* replace return addr with trampoline */
24+ regs->ra = (unsigned long)arch_rethook_trampoline;
25+}
26+
27+NOKPROBE_SYMBOL(arch_rethook_prepare);
arch/riscv/kernel/probes/rethook.h+8−0
@@ -0,0 +1,8 @@
1+/* SPDX-License-Identifier: GPL-2.0-only */
2+#ifndef __RISCV_RETHOOK_H
3+#define __RISCV_RETHOOK_H
4+
5+unsigned long arch_rethook_trampoline_callback(struct pt_regs *regs);
6+void arch_rethook_prepare(struct rethook_node *rhn, struct pt_regs *regs, bool mcount);
7+
8+#endif
arch/riscv/kernel/probes/rethook_trampoline.Srenamed from arch/riscv/kernel/probes/kprobes_trampoline.S+3−3
@@ -75,13 +75,13 @@ · 74 unmodified lines
7575 REG_L x31, PT_T6(sp)
7676 .endm
7777
78−ENTRY(__kretprobe_trampoline)
78+ENTRY(arch_rethook_trampoline)
7979 addi sp, sp, -(PT_SIZE_ON_STACK)
8080 save_all_base_regs
8181
8282 move a0, sp /* pt_regs */
8383
84− call trampoline_probe_handler
84+ call arch_rethook_trampoline_callback
8585
8686 /* use the result as the return-address */
8787 move ra, a0
@@ -90,4 +90,4 @@ ENTRY(__kretprobe_trampoline) · 2 unmodified lines
9090 addi sp, sp, PT_SIZE_ON_STACK
9191
9292 ret
93−ENDPROC(__kretprobe_trampoline)
93+ENDPROC(arch_rethook_trampoline)
arch/riscv/kernel/signal.c+21−13
@@ -313,19 +313,27 @@ static void do_signal(struct pt_regs *regs) · 312 unmodified lines
313313 }
314314
315315 /*
316− * notification of userspace execution resumption
317− * - triggered by the _TIF_WORK_MASK flags
316+ * Handle any pending work on the resume-to-userspace path, as indicated by
317+ * _TIF_WORK_MASK. Entered from assembly with IRQs off.
318318 */
319−asmlinkage __visible void do_notify_resume(struct pt_regs *regs,
320− unsigned long thread_info_flags)
319+asmlinkage __visible void do_work_pending(struct pt_regs *regs,
320+ unsigned long thread_info_flags)
321321 {
322− if (thread_info_flags & _TIF_UPROBE)
323− uprobe_notify_resume(regs);
324−
325− /* Handle pending signal delivery */
326− if (thread_info_flags & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL))
327− do_signal(regs);
328−
329− if (thread_info_flags & _TIF_NOTIFY_RESUME)
330− resume_user_mode_work(regs);
322+ do {
323+ if (thread_info_flags & _TIF_NEED_RESCHED) {
324+ schedule();
325+ } else {
326+ local_irq_enable();
327+ if (thread_info_flags & _TIF_UPROBE)
328+ uprobe_notify_resume(regs);
329+ /* Handle pending signal delivery */
330+ if (thread_info_flags & (_TIF_SIGPENDING |
331+ _TIF_NOTIFY_SIGNAL))
332+ do_signal(regs);
333+ if (thread_info_flags & _TIF_NOTIFY_RESUME)
334+ resume_user_mode_work(regs);
335+ }
336+ local_irq_disable();
337+ thread_info_flags = read_thread_flags();
338+ } while (thread_info_flags & _TIF_WORK_MASK);
331339 }
arch/riscv/kernel/stacktrace.c+10−1
@@ -16,6 +16,8 @@ · 15 unmodified lines
1616
1717 #ifdef CONFIG_FRAME_POINTER
1818
19+extern asmlinkage void ret_from_exception(void);
20+
1921 void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,
2022 bool (*fn)(void *, unsigned long), void *arg)
2123 {
@@ -58,7 +60,14 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs, · 36 unmodified lines
5860 } else {
5961 fp = frame->fp;
6062 pc = ftrace_graph_ret_addr(current, NULL, frame->ra,
61− (unsigned long *)(fp - 8));
63+ &frame->ra);
64+ if (pc == (unsigned long)ret_from_exception) {
65+ if (unlikely(!__kernel_text_address(pc) || !fn(arg, pc)))
66+ break;
67+
68+ pc = ((struct pt_regs *)sp)->epc;
69+ fp = ((struct pt_regs *)sp)->s0;
70+ }
6271 }
6372
6473 }
arch/riscv/kernel/traps.c+14−8
@@ -208,18 +208,18 @@ int is_valid_bugaddr(unsigned long pc) · 207 unmodified lines
208208 #endif /* CONFIG_GENERIC_BUG */
209209
210210 #ifdef CONFIG_VMAP_STACK
211+/*
212+ * Extra stack space that allows us to provide panic messages when the kernel
213+ * has overflowed its stack.
214+ */
211215 static DEFINE_PER_CPU(unsigned long [OVERFLOW_STACK_SIZE/sizeof(long)],
212216 overflow_stack)__aligned(16);
213217 /*
214− * shadow stack, handled_ kernel_ stack_ overflow(in kernel/entry.S) is used
215− * to get per-cpu overflow stack(get_overflow_stack).
218+ * A temporary stack for use by handle_kernel_stack_overflow. This is used so
219+ * we can call into C code to get the per-hart overflow stack. Usage of this
220+ * stack must be protected by spin_shadow_stack.
216221 */
217−long shadow_stack[SHADOW_OVERFLOW_STACK_SIZE/sizeof(long)];
218−asmlinkage unsigned long get_overflow_stack(void)
219−{
220− return (unsigned long)this_cpu_ptr(overflow_stack) +
221− OVERFLOW_STACK_SIZE;
222−}
222+long shadow_stack[SHADOW_OVERFLOW_STACK_SIZE/sizeof(long)] __aligned(16);
223223
224224 /*
225225 * A pseudo spinlock to protect the shadow stack from being used by multiple
@@ -230,6 +230,12 @@ asmlinkage unsigned long get_overflow_stack(void) · 4 unmodified lines
230230 */
231231 unsigned long spin_shadow_stack;
232232
233+asmlinkage unsigned long get_overflow_stack(void)
234+{
235+ return (unsigned long)this_cpu_ptr(overflow_stack) +
236+ OVERFLOW_STACK_SIZE;
237+}
238+
233239 asmlinkage void handle_bad_stack(struct pt_regs *regs)
234240 {
235241 unsigned long tsk_stk = (unsigned long)current->stack;
arch/riscv/mm/Makefile+2−0
@@ -13,6 +13,8 @@ obj-y += extable.o · 12 unmodified lines
1313 obj-$(CONFIG_MMU) += fault.o pageattr.o
1414 obj-y += cacheflush.o
1515 obj-y += context.o
16+obj-y += pgtable.o
17+obj-y += pmem.o
1618
1719 ifeq ($(CONFIG_MMU),y)
1820 obj-$(CONFIG_SMP) += tlbflush.o
arch/riscv/mm/cacheflush.c+7−0
@@ -83,6 +83,13 @@ void flush_icache_pte(pte_t pte) · 82 unmodified lines
8383 {
8484 struct page *page = pte_page(pte);
8585
86+ /*
87+ * HugeTLB pages are always fully mapped, so only setting head page's
88+ * PG_dcache_clean flag is enough.
89+ */
90+ if (PageHuge(page))
91+ page = compound_head(page);
92+
8693 if (!test_and_set_bit(PG_dcache_clean, &page->flags))
8794 flush_icache_all();
8895 }
arch/riscv/mm/context.c+10−0
@@ -196,6 +196,16 @@ switch_mm_fast: · 195 unmodified lines
196196
197197 if (need_flush_tlb)
198198 local_flush_tlb_all();
199+#ifdef CONFIG_SMP
200+ else {
201+ cpumask_t *mask = &mm->context.tlb_stale_mask;
202+
203+ if (cpumask_test_cpu(cpu, mask)) {
204+ cpumask_clear_cpu(cpu, mask);
205+ local_flush_tlb_all_asid(cntx & asid_mask);
206+ }
207+ }
208+#endif
199209 }
200210
201211 static void set_mm_noasid(struct mm_struct *mm)
arch/riscv/mm/init.c+13−12
@@ -672,10 +672,11 @@ void __init create_pgd_mapping(pgd_t *pgdp, · 671 unmodified lines
672672 static uintptr_t __init best_map_size(phys_addr_t base, phys_addr_t size)
673673 {
674674 /* Upgrade to PMD_SIZE mappings whenever possible */
675− if ((base & (PMD_SIZE - 1)) || (size & (PMD_SIZE - 1)))
676− return PAGE_SIZE;
675+ base &= PMD_SIZE - 1;
676+ if (!base && size >= PMD_SIZE)
677+ return PMD_SIZE;
677678
678− return PMD_SIZE;
679+ return PAGE_SIZE;
679680 }
680681
681682 #ifdef CONFIG_XIP_KERNEL
@@ -926,15 +927,15 @@ static void __init pt_ops_set_early(void) · 244 unmodified lines
926927 */
927928 static void __init pt_ops_set_fixmap(void)
928929 {
929− pt_ops.alloc_pte = kernel_mapping_pa_to_va((uintptr_t)alloc_pte_fixmap);
930− pt_ops.get_pte_virt = kernel_mapping_pa_to_va((uintptr_t)get_pte_virt_fixmap);
930+ pt_ops.alloc_pte = kernel_mapping_pa_to_va(alloc_pte_fixmap);
931+ pt_ops.get_pte_virt = kernel_mapping_pa_to_va(get_pte_virt_fixmap);
931932 #ifndef __PAGETABLE_PMD_FOLDED
932− pt_ops.alloc_pmd = kernel_mapping_pa_to_va((uintptr_t)alloc_pmd_fixmap);
933− pt_ops.get_pmd_virt = kernel_mapping_pa_to_va((uintptr_t)get_pmd_virt_fixmap);
934− pt_ops.alloc_pud = kernel_mapping_pa_to_va((uintptr_t)alloc_pud_fixmap);
935− pt_ops.get_pud_virt = kernel_mapping_pa_to_va((uintptr_t)get_pud_virt_fixmap);
936− pt_ops.alloc_p4d = kernel_mapping_pa_to_va((uintptr_t)alloc_p4d_fixmap);
937− pt_ops.get_p4d_virt = kernel_mapping_pa_to_va((uintptr_t)get_p4d_virt_fixmap);
933+ pt_ops.alloc_pmd = kernel_mapping_pa_to_va(alloc_pmd_fixmap);
934+ pt_ops.get_pmd_virt = kernel_mapping_pa_to_va(get_pmd_virt_fixmap);
935+ pt_ops.alloc_pud = kernel_mapping_pa_to_va(alloc_pud_fixmap);
936+ pt_ops.get_pud_virt = kernel_mapping_pa_to_va(get_pud_virt_fixmap);
937+ pt_ops.alloc_p4d = kernel_mapping_pa_to_va(alloc_p4d_fixmap);
938+ pt_ops.get_p4d_virt = kernel_mapping_pa_to_va(get_p4d_virt_fixmap);
938939 #endif
939940 }
940941
@@ -1110,9 +1111,9 @@ static void __init setup_vm_final(void) · 169 unmodified lines
11101111 if (end >= __pa(PAGE_OFFSET) + memory_limit)
11111112 end = __pa(PAGE_OFFSET) + memory_limit;
11121113
1113− map_size = best_map_size(start, end - start);
11141114 for (pa = start; pa < end; pa += map_size) {
11151115 va = (uintptr_t)__va(pa);
1116+ map_size = best_map_size(pa, end - pa);
11161117
11171118 create_pgd_mapping(swapper_pg_dir, va, pa, map_size,
11181119 pgprot_from_va(va));
arch/riscv/mm/pgtable.c+83−0
@@ -0,0 +1,83 @@
1+// SPDX-License-Identifier: GPL-2.0
2+
3+#include <asm/pgalloc.h>
4+#include <linux/gfp.h>
5+#include <linux/kernel.h>
6+#include <linux/pgtable.h>
7+
8+#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP
9+int p4d_set_huge(p4d_t *p4d, phys_addr_t addr, pgprot_t prot)
10+{
11+ return 0;
12+}
13+
14+void p4d_clear_huge(p4d_t *p4d)
15+{
16+}
17+
18+int pud_set_huge(pud_t *pud, phys_addr_t phys, pgprot_t prot)
19+{
20+ pud_t new_pud = pfn_pud(__phys_to_pfn(phys), prot);
21+
22+ set_pud(pud, new_pud);
23+ return 1;
24+}
25+
26+int pud_clear_huge(pud_t *pud)
27+{
28+ if (!pud_leaf(READ_ONCE(*pud)))
29+ return 0;
30+ pud_clear(pud);
31+ return 1;
32+}
33+
34+int pud_free_pmd_page(pud_t *pud, unsigned long addr)
35+{
36+ pmd_t *pmd = pud_pgtable(*pud);
37+ int i;
38+
39+ pud_clear(pud);
40+
41+ flush_tlb_kernel_range(addr, addr + PUD_SIZE);
42+
43+ for (i = 0; i < PTRS_PER_PMD; i++) {
44+ if (!pmd_none(pmd[i])) {
45+ pte_t *pte = (pte_t *)pmd_page_vaddr(pmd[i]);
46+
47+ pte_free_kernel(NULL, pte);
48+ }
49+ }
50+
51+ pmd_free(NULL, pmd);
52+
53+ return 1;
54+}
55+
56+int pmd_set_huge(pmd_t *pmd, phys_addr_t phys, pgprot_t prot)
57+{
58+ pmd_t new_pmd = pfn_pmd(__phys_to_pfn(phys), prot);
59+
60+ set_pmd(pmd, new_pmd);
61+ return 1;
62+}
63+
64+int pmd_clear_huge(pmd_t *pmd)
65+{
66+ if (!pmd_leaf(READ_ONCE(*pmd)))
67+ return 0;
68+ pmd_clear(pmd);
69+ return 1;
70+}
71+
72+int pmd_free_pte_page(pmd_t *pmd, unsigned long addr)
73+{
74+ pte_t *pte = (pte_t *)pmd_page_vaddr(*pmd);
75+
76+ pmd_clear(pmd);
77+
78+ flush_tlb_kernel_range(addr, addr + PMD_SIZE);
79+ pte_free_kernel(NULL, pte);
80+ return 1;
81+}
82+
83+#endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */
arch/riscv/mm/physaddr.c+1−1
@@ -22,7 +22,7 @@ EXPORT_SYMBOL(__virt_to_phys); · 21 unmodified lines
2222 phys_addr_t __phys_addr_symbol(unsigned long x)
2323 {
2424 unsigned long kernel_start = kernel_map.virt_addr;
25− unsigned long kernel_end = (unsigned long)_end;
25+ unsigned long kernel_end = kernel_start + kernel_map.size;
2626
2727 /*
2828 * Boundary checking aginst the kernel image mapping.
arch/riscv/mm/pmem.c+21−0
@@ -0,0 +1,21 @@
1+// SPDX-License-Identifier: GPL-2.0
2+/*
3+ * Copyright (C) 2022 Ventana Micro Systems Inc.
4+ */
5+
6+#include <linux/export.h>
7+#include <linux/libnvdimm.h>
8+
9+#include <asm/cacheflush.h>
10+
11+void arch_wb_cache_pmem(void *addr, size_t size)
12+{
13+ ALT_CMO_OP(clean, addr, size, riscv_cbom_block_size);
14+}
15+EXPORT_SYMBOL_GPL(arch_wb_cache_pmem);
16+
17+void arch_invalidate_pmem(void *addr, size_t size)
18+{
19+ ALT_CMO_OP(inval, addr, size, riscv_cbom_block_size);
20+}
21+EXPORT_SYMBOL_GPL(arch_invalidate_pmem);
arch/riscv/mm/tlbflush.c+11−17
@@ -5,23 +5,7 @@ · 4 unmodified lines
55 #include <linux/sched.h>
66 #include <asm/sbi.h>
77 #include <asm/mmu_context.h>
8−
9−static inline void local_flush_tlb_all_asid(unsigned long asid)
10−{
11− __asm__ __volatile__ ("sfence.vma x0, %0"
12− :
13− : "r" (asid)
14− : "memory");
15−}
16−
17−static inline void local_flush_tlb_page_asid(unsigned long addr,
18− unsigned long asid)
19−{
20− __asm__ __volatile__ ("sfence.vma %0, %1"
21− :
22− : "r" (addr), "r" (asid)
23− : "memory");
24−}
8+#include <asm/tlbflush.h>
259
2610 void flush_tlb_all(void)
2711 {
@@ -31,6 +15,7 @@ void flush_tlb_all(void) · 3 unmodified lines
3115 static void __sbi_tlb_flush_range(struct mm_struct *mm, unsigned long start,
3216 unsigned long size, unsigned long stride)
3317 {
18+ struct cpumask *pmask = &mm->context.tlb_stale_mask;
3419 struct cpumask *cmask = mm_cpumask(mm);
3520 unsigned int cpuid;
3621 bool broadcast;
@@ -44,6 +29,15 @@ static void __sbi_tlb_flush_range(struct mm_struct *mm, unsigned long start, · 7 unmodified lines
4429 if (static_branch_unlikely(&use_asid_allocator)) {
4530 unsigned long asid = atomic_long_read(&mm->context.id);
4631
32+ /*
33+ * TLB will be immediately flushed on harts concurrently
34+ * executing this MM context. TLB flush on other harts
35+ * is deferred until this MM context migrates there.
36+ */
37+ cpumask_setall(pmask);
38+ cpumask_clear_cpu(cpuid, pmask);
39+ cpumask_andnot(pmask, pmask, cmask);
40+
4741 if (broadcast) {
4842 sbi_remote_sfence_vma_asid(cmask, start, size, asid);
4943 } else if (size <= stride) {
drivers/irqchip/Kconfig+2−19
@@ -538,31 +538,14 @@ config TI_PRUSS_INTC · 537 unmodified lines
538538 different processors within the SoC.
539539
540540 config RISCV_INTC
541− bool "RISC-V Local Interrupt Controller"
541+ bool
542542 depends on RISCV
543− default y
544− help
545− This enables support for the per-HART local interrupt controller
546− found in standard RISC-V systems. The per-HART local interrupt
547− controller handles timer interrupts, software interrupts, and
548− hardware interrupts. Without a per-HART local interrupt controller,
549− a RISC-V system will be unable to handle any interrupts.
550−
551− If you don't know what to do here, say Y.
552543
553544 config SIFIVE_PLIC
554− bool "SiFive Platform-Level Interrupt Controller"
545+ bool
555546 depends on RISCV
556547 select IRQ_DOMAIN_HIERARCHY
557548 select GENERIC_IRQ_EFFECTIVE_AFF_MASK if SMP
558− help
559− This enables support for the PLIC chip found in SiFive (and
560− potentially other) RISC-V systems. The PLIC controls devices
561− interrupts and connects them to each core's local interrupt
562− controller. Aside from timer and software interrupts, all other
563− interrupt sources are subordinate to the PLIC.
564−
565− If you don't know what to do here, say Y.
566549
567550 config EXYNOS_IRQ_COMBINER
568551 bool "Samsung Exynos IRQ combiner support" if COMPILE_TEST
drivers/perf/riscv_pmu_sbi.c+24−10
@@ -20,6 +20,7 @@ · 19 unmodified lines
2020 #include <linux/cpu_pm.h>
2121 #include <linux/sched/clock.h>
2222
23+#include <asm/errata_list.h>
2324 #include <asm/sbi.h>
2425 #include <asm/hwcap.h>
2526
@@ -47,6 +48,8 @@ static const struct attribute_group *riscv_pmu_attr_groups[] = { · 21 unmodified lines
4748 * per_cpu in case of harts with different pmu counters
4849 */
4950 static union sbi_pmu_ctr_info *pmu_ctr_list;
51+static bool riscv_pmu_use_irq;
52+static unsigned int riscv_pmu_irq_num;
5053 static unsigned int riscv_pmu_irq;
5154
5255 struct sbi_pmu_event_data {
@@ -580,7 +583,7 @@ static irqreturn_t pmu_sbi_ovf_handler(int irq, void *dev) · 527 unmodified lines
580583 fidx = find_first_bit(cpu_hw_evt->used_hw_ctrs, RISCV_MAX_COUNTERS);
581584 event = cpu_hw_evt->events[fidx];
582585 if (!event) {
583− csr_clear(CSR_SIP, SIP_LCOFIP);
586+ csr_clear(CSR_SIP, BIT(riscv_pmu_irq_num));
584587 return IRQ_NONE;
585588 }
586589
@@ -588,13 +591,13 @@ static irqreturn_t pmu_sbi_ovf_handler(int irq, void *dev) · 1 unmodified line
588591 pmu_sbi_stop_hw_ctrs(pmu);
589592
590593 /* Overflow status register should only be read after counter are stopped */
591− overflow = csr_read(CSR_SSCOUNTOVF);
594+ ALT_SBI_PMU_OVERFLOW(overflow);
592595
593596 /*
594597 * Overflow interrupt pending bit should only be cleared after stopping
595598 * all the counters to avoid any race condition.
596599 */
597− csr_clear(CSR_SIP, SIP_LCOFIP);
600+ csr_clear(CSR_SIP, BIT(riscv_pmu_irq_num));
598601
599602 /* No overflow bit is set */
600603 if (!overflow)
@@ -661,10 +664,10 @@ static int pmu_sbi_starting_cpu(unsigned int cpu, struct hlist_node *node) · 60 unmodified lines
661664 /* Stop all the counters so that they can be enabled from perf */
662665 pmu_sbi_stop_all(pmu);
663666
664− if (riscv_isa_extension_available(NULL, SSCOFPMF)) {
667+ if (riscv_pmu_use_irq) {
665668 cpu_hw_evt->irq = riscv_pmu_irq;
666− csr_clear(CSR_IP, BIT(RV_IRQ_PMU));
667− csr_set(CSR_IE, BIT(RV_IRQ_PMU));
669+ csr_clear(CSR_IP, BIT(riscv_pmu_irq_num));
670+ csr_set(CSR_IE, BIT(riscv_pmu_irq_num));
668671 enable_percpu_irq(riscv_pmu_irq, IRQ_TYPE_NONE);
669672 }
670673
@@ -673,9 +676,9 @@ static int pmu_sbi_starting_cpu(unsigned int cpu, struct hlist_node *node) · 2 unmodified lines
673676
674677 static int pmu_sbi_dying_cpu(unsigned int cpu, struct hlist_node *node)
675678 {
676− if (riscv_isa_extension_available(NULL, SSCOFPMF)) {
679+ if (riscv_pmu_use_irq) {
677680 disable_percpu_irq(riscv_pmu_irq);
678− csr_clear(CSR_IE, BIT(RV_IRQ_PMU));
681+ csr_clear(CSR_IE, BIT(riscv_pmu_irq_num));
679682 }
680683
681684 /* Disable all counters access for user mode now */
@@ -691,7 +694,18 @@ static int pmu_sbi_setup_irqs(struct riscv_pmu *pmu, struct platform_device *pde · 9 unmodified lines
691694 struct device_node *cpu, *child;
692695 struct irq_domain *domain = NULL;
693696
694− if (!riscv_isa_extension_available(NULL, SSCOFPMF))
697+ if (riscv_isa_extension_available(NULL, SSCOFPMF)) {
698+ riscv_pmu_irq_num = RV_IRQ_PMU;
699+ riscv_pmu_use_irq = true;
700+ } else if (IS_ENABLED(CONFIG_ERRATA_THEAD_PMU) &&
701+ riscv_cached_mvendorid(0) == THEAD_VENDOR_ID &&
702+ riscv_cached_marchid(0) == 0 &&
703+ riscv_cached_mimpid(0) == 0) {
704+ riscv_pmu_irq_num = THEAD_C9XX_RV_IRQ_PMU;
705+ riscv_pmu_use_irq = true;
706+ }
707+
708+ if (!riscv_pmu_use_irq)
695709 return -EOPNOTSUPP;
696710
697711 for_each_of_cpu_node(cpu) {
@@ -713,7 +727,7 @@ static int pmu_sbi_setup_irqs(struct riscv_pmu *pmu, struct platform_device *pde · 15 unmodified lines
713727 return -ENODEV;
714728 }
715729
716− riscv_pmu_irq = irq_create_mapping(domain, RV_IRQ_PMU);
730+ riscv_pmu_irq = irq_create_mapping(domain, riscv_pmu_irq_num);
717731 if (!riscv_pmu_irq) {
718732 pr_err("Failed to map PMU interrupt for node\n");
719733 return -ENODEV;
scripts/head-object-list.txt+0−1
@@ -38,7 +38,6 @@ arch/powerpc/kernel/entry_64.o · 37 unmodified lines
3838 arch/powerpc/kernel/fpu.o
3939 arch/powerpc/kernel/vector.o
4040 arch/powerpc/kernel/prom_init.o
41−arch/riscv/kernel/head.o
4241 arch/s390/kernel/head64.o
4342 arch/sh/kernel/head_32.o
4443 arch/sparc/kernel/head_32.o