Skip to content

Commit 56d428a

Browse files
committed
Merge tag 'riscv-for-linus-6.7-mw2' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux
Pull more RISC-V updates from Palmer Dabbelt: - Support for handling misaligned accesses in S-mode - Probing for misaligned access support is now properly cached and handled in parallel - PTDUMP now reflects the SW reserved bits, as well as the PBMT and NAPOT extensions - Performance improvements for TLB flushing - Support for many new relocations in the module loader - Various bug fixes and cleanups * tag 'riscv-for-linus-6.7-mw2' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux: (51 commits) riscv: Optimize bitops with Zbb extension riscv: Rearrange hwcap.h and cpufeature.h drivers: perf: Do not broadcast to other cpus when starting a counter drivers: perf: Check find_first_bit() return value of: property: Add fw_devlink support for msi-parent RISC-V: Don't fail in riscv_of_parent_hartid() for disabled HARTs riscv: Fix set_memory_XX() and set_direct_map_XX() by splitting huge linear mappings riscv: Don't use PGD entries for the linear mapping RISC-V: Probe misaligned access speed in parallel RISC-V: Remove __init on unaligned_emulation_finish() RISC-V: Show accurate per-hart isa in /proc/cpuinfo RISC-V: Don't rely on positional structure initialization riscv: Add tests for riscv module loading riscv: Add remaining module relocations riscv: Avoid unaligned access when relocating modules riscv: split cache ops out of dma-noncoherent.c riscv: Improve flush_tlb_kernel_range() riscv: Make __flush_tlb_range() loop over pte instead of flushing the whole tlb riscv: Improve flush_tlb_range() for hugetlb pages riscv: Improve tlb_flush() ...
2 parents 656d88c + 457926b commit 56d428a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+2541
-690
lines changed

Documentation/arch/riscv/uabi.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,26 @@ An example string following the order is::
4242

4343
rv64imadc_zifoo_zigoo_zafoo_sbar_scar_zxmbaz_xqux_xrux
4444

45+
"isa" and "hart isa" lines in /proc/cpuinfo
46+
-------------------------------------------
47+
48+
The "isa" line in /proc/cpuinfo describes the lowest common denominator of
49+
RISC-V ISA extensions recognized by the kernel and implemented on all harts. The
50+
"hart isa" line, in contrast, describes the set of extensions recognized by the
51+
kernel on the particular hart being described, even if those extensions may not
52+
be present on all harts in the system.
53+
54+
In both lines, the presence of an extension guarantees only that the hardware
55+
has the described capability. Additional kernel support or policy changes may be
56+
required before an extension's capability is fully usable by userspace programs.
57+
Similarly, for S-mode extensions, presence in one of these lines does not
58+
guarantee that the kernel is taking advantage of the extension, or that the
59+
feature will be visible in guest VMs managed by this kernel.
60+
61+
Inversely, the absence of an extension in these lines does not necessarily mean
62+
the hardware does not support that feature. The running kernel may not recognize
63+
the extension, or may have deliberately removed it from the listing.
64+
4565
Misaligned accesses
4666
-------------------
4767

arch/riscv/Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,15 @@ config THREAD_SIZE_ORDER
642642
Specify the Pages of thread stack size (from 4KB to 64KB), which also
643643
affects irq stack size, which is equal to thread stack size.
644644

645+
config RISCV_MISALIGNED
646+
bool "Support misaligned load/store traps for kernel and userspace"
647+
select SYSCTL_ARCH_UNALIGN_ALLOW
648+
default y
649+
help
650+
Say Y here if you want the kernel to embed support for misaligned
651+
load/store for both kernel and userspace. When disable, misaligned
652+
accesses will generate SIGBUS in userspace and panic in kernel.
653+
645654
endmenu # "Platform type"
646655

647656
menu "Kernel features"
@@ -909,6 +918,9 @@ config PORTABLE
909918
select MMU
910919
select OF
911920

921+
config ARCH_PROC_KCORE_TEXT
922+
def_bool y
923+
912924
menu "Power management options"
913925

914926
source "kernel/power/Kconfig"

arch/riscv/Kconfig.debug

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
source "arch/riscv/kernel/tests/Kconfig.debug"

arch/riscv/boot/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
KCOV_INSTRUMENT := n
1818

1919
OBJCOPYFLAGS_Image :=-O binary -R .note -R .note.gnu.build-id -R .comment -S
20+
OBJCOPYFLAGS_loader.bin :=-O binary
2021
OBJCOPYFLAGS_xipImage :=-O binary -R .note -R .note.gnu.build-id -R .comment -S
2122

2223
targets := Image Image.* loader loader.o loader.lds loader.bin

arch/riscv/configs/defconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ CONFIG_MMC_SDHCI=y
215215
CONFIG_MMC_SDHCI_PLTFM=y
216216
CONFIG_MMC_SDHCI_CADENCE=y
217217
CONFIG_MMC_SPI=y
218+
CONFIG_MMC_DW=y
219+
CONFIG_MMC_DW_STARFIVE=y
218220
CONFIG_MMC_SDHI=y
219221
CONFIG_MMC_SUNXI=y
220222
CONFIG_RTC_CLASS=y

arch/riscv/include/asm/bitops.h

Lines changed: 251 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,261 @@
1515
#include <asm/barrier.h>
1616
#include <asm/bitsperlong.h>
1717

18+
#if !defined(CONFIG_RISCV_ISA_ZBB) || defined(NO_ALTERNATIVE)
1819
#include <asm-generic/bitops/__ffs.h>
19-
#include <asm-generic/bitops/ffz.h>
20-
#include <asm-generic/bitops/fls.h>
2120
#include <asm-generic/bitops/__fls.h>
21+
#include <asm-generic/bitops/ffs.h>
22+
#include <asm-generic/bitops/fls.h>
23+
24+
#else
25+
#include <asm/alternative-macros.h>
26+
#include <asm/hwcap.h>
27+
28+
#if (BITS_PER_LONG == 64)
29+
#define CTZW "ctzw "
30+
#define CLZW "clzw "
31+
#elif (BITS_PER_LONG == 32)
32+
#define CTZW "ctz "
33+
#define CLZW "clz "
34+
#else
35+
#error "Unexpected BITS_PER_LONG"
36+
#endif
37+
38+
static __always_inline unsigned long variable__ffs(unsigned long word)
39+
{
40+
int num;
41+
42+
asm_volatile_goto(ALTERNATIVE("j %l[legacy]", "nop", 0,
43+
RISCV_ISA_EXT_ZBB, 1)
44+
: : : : legacy);
45+
46+
asm volatile (".option push\n"
47+
".option arch,+zbb\n"
48+
"ctz %0, %1\n"
49+
".option pop\n"
50+
: "=r" (word) : "r" (word) :);
51+
52+
return word;
53+
54+
legacy:
55+
num = 0;
56+
#if BITS_PER_LONG == 64
57+
if ((word & 0xffffffff) == 0) {
58+
num += 32;
59+
word >>= 32;
60+
}
61+
#endif
62+
if ((word & 0xffff) == 0) {
63+
num += 16;
64+
word >>= 16;
65+
}
66+
if ((word & 0xff) == 0) {
67+
num += 8;
68+
word >>= 8;
69+
}
70+
if ((word & 0xf) == 0) {
71+
num += 4;
72+
word >>= 4;
73+
}
74+
if ((word & 0x3) == 0) {
75+
num += 2;
76+
word >>= 2;
77+
}
78+
if ((word & 0x1) == 0)
79+
num += 1;
80+
return num;
81+
}
82+
83+
/**
84+
* __ffs - find first set bit in a long word
85+
* @word: The word to search
86+
*
87+
* Undefined if no set bit exists, so code should check against 0 first.
88+
*/
89+
#define __ffs(word) \
90+
(__builtin_constant_p(word) ? \
91+
(unsigned long)__builtin_ctzl(word) : \
92+
variable__ffs(word))
93+
94+
static __always_inline unsigned long variable__fls(unsigned long word)
95+
{
96+
int num;
97+
98+
asm_volatile_goto(ALTERNATIVE("j %l[legacy]", "nop", 0,
99+
RISCV_ISA_EXT_ZBB, 1)
100+
: : : : legacy);
101+
102+
asm volatile (".option push\n"
103+
".option arch,+zbb\n"
104+
"clz %0, %1\n"
105+
".option pop\n"
106+
: "=r" (word) : "r" (word) :);
107+
108+
return BITS_PER_LONG - 1 - word;
109+
110+
legacy:
111+
num = BITS_PER_LONG - 1;
112+
#if BITS_PER_LONG == 64
113+
if (!(word & (~0ul << 32))) {
114+
num -= 32;
115+
word <<= 32;
116+
}
117+
#endif
118+
if (!(word & (~0ul << (BITS_PER_LONG - 16)))) {
119+
num -= 16;
120+
word <<= 16;
121+
}
122+
if (!(word & (~0ul << (BITS_PER_LONG - 8)))) {
123+
num -= 8;
124+
word <<= 8;
125+
}
126+
if (!(word & (~0ul << (BITS_PER_LONG - 4)))) {
127+
num -= 4;
128+
word <<= 4;
129+
}
130+
if (!(word & (~0ul << (BITS_PER_LONG - 2)))) {
131+
num -= 2;
132+
word <<= 2;
133+
}
134+
if (!(word & (~0ul << (BITS_PER_LONG - 1))))
135+
num -= 1;
136+
return num;
137+
}
138+
139+
/**
140+
* __fls - find last set bit in a long word
141+
* @word: the word to search
142+
*
143+
* Undefined if no set bit exists, so code should check against 0 first.
144+
*/
145+
#define __fls(word) \
146+
(__builtin_constant_p(word) ? \
147+
(unsigned long)(BITS_PER_LONG - 1 - __builtin_clzl(word)) : \
148+
variable__fls(word))
149+
150+
static __always_inline int variable_ffs(int x)
151+
{
152+
int r;
153+
154+
if (!x)
155+
return 0;
156+
157+
asm_volatile_goto(ALTERNATIVE("j %l[legacy]", "nop", 0,
158+
RISCV_ISA_EXT_ZBB, 1)
159+
: : : : legacy);
160+
161+
asm volatile (".option push\n"
162+
".option arch,+zbb\n"
163+
CTZW "%0, %1\n"
164+
".option pop\n"
165+
: "=r" (r) : "r" (x) :);
166+
167+
return r + 1;
168+
169+
legacy:
170+
r = 1;
171+
if (!(x & 0xffff)) {
172+
x >>= 16;
173+
r += 16;
174+
}
175+
if (!(x & 0xff)) {
176+
x >>= 8;
177+
r += 8;
178+
}
179+
if (!(x & 0xf)) {
180+
x >>= 4;
181+
r += 4;
182+
}
183+
if (!(x & 3)) {
184+
x >>= 2;
185+
r += 2;
186+
}
187+
if (!(x & 1)) {
188+
x >>= 1;
189+
r += 1;
190+
}
191+
return r;
192+
}
193+
194+
/**
195+
* ffs - find first set bit in a word
196+
* @x: the word to search
197+
*
198+
* This is defined the same way as the libc and compiler builtin ffs routines.
199+
*
200+
* ffs(value) returns 0 if value is 0 or the position of the first set bit if
201+
* value is nonzero. The first (least significant) bit is at position 1.
202+
*/
203+
#define ffs(x) (__builtin_constant_p(x) ? __builtin_ffs(x) : variable_ffs(x))
204+
205+
static __always_inline int variable_fls(unsigned int x)
206+
{
207+
int r;
208+
209+
if (!x)
210+
return 0;
211+
212+
asm_volatile_goto(ALTERNATIVE("j %l[legacy]", "nop", 0,
213+
RISCV_ISA_EXT_ZBB, 1)
214+
: : : : legacy);
215+
216+
asm volatile (".option push\n"
217+
".option arch,+zbb\n"
218+
CLZW "%0, %1\n"
219+
".option pop\n"
220+
: "=r" (r) : "r" (x) :);
221+
222+
return 32 - r;
223+
224+
legacy:
225+
r = 32;
226+
if (!(x & 0xffff0000u)) {
227+
x <<= 16;
228+
r -= 16;
229+
}
230+
if (!(x & 0xff000000u)) {
231+
x <<= 8;
232+
r -= 8;
233+
}
234+
if (!(x & 0xf0000000u)) {
235+
x <<= 4;
236+
r -= 4;
237+
}
238+
if (!(x & 0xc0000000u)) {
239+
x <<= 2;
240+
r -= 2;
241+
}
242+
if (!(x & 0x80000000u)) {
243+
x <<= 1;
244+
r -= 1;
245+
}
246+
return r;
247+
}
248+
249+
/**
250+
* fls - find last set bit in a word
251+
* @x: the word to search
252+
*
253+
* This is defined in a similar way as ffs, but returns the position of the most
254+
* significant set bit.
255+
*
256+
* fls(value) returns 0 if value is 0 or the position of the last set bit if
257+
* value is nonzero. The last (most significant) bit is at position 32.
258+
*/
259+
#define fls(x) \
260+
({ \
261+
typeof(x) x_ = (x); \
262+
__builtin_constant_p(x_) ? \
263+
(int)((x_ != 0) ? (32 - __builtin_clz(x_)) : 0) \
264+
: \
265+
variable_fls(x_); \
266+
})
267+
268+
#endif /* !defined(CONFIG_RISCV_ISA_ZBB) || defined(NO_ALTERNATIVE) */
269+
270+
#include <asm-generic/bitops/ffz.h>
22271
#include <asm-generic/bitops/fls64.h>
23272
#include <asm-generic/bitops/sched.h>
24-
#include <asm-generic/bitops/ffs.h>
25273

26274
#include <asm-generic/bitops/hweight.h>
27275

0 commit comments

Comments
 (0)