Skip to content

Commit 91dbbe6

Browse files
committed
Merge tag 'riscv-for-linus-6.13-mw1' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux
Pull RISC-v updates from Palmer Dabbelt: - Support for pointer masking in userspace - Support for probing vector misaligned access performance - Support for qspinlock on systems with Zacas and Zabha * tag 'riscv-for-linus-6.13-mw1' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux: (38 commits) RISC-V: Remove unnecessary include from compat.h riscv: Fix default misaligned access trap riscv: Add qspinlock support dt-bindings: riscv: Add Ziccrse ISA extension description riscv: Add ISA extension parsing for Ziccrse asm-generic: ticket-lock: Add separate ticket-lock.h asm-generic: ticket-lock: Reuse arch_spinlock_t of qspinlock riscv: Implement xchg8/16() using Zabha riscv: Implement arch_cmpxchg128() using Zacas riscv: Improve zacas fully-ordered cmpxchg() riscv: Implement cmpxchg8/16() using Zabha dt-bindings: riscv: Add Zabha ISA extension description riscv: Implement cmpxchg32/64() using Zacas riscv: Do not fail to build on byte/halfword operations with Zawrs riscv: Move cpufeature.h macros into their own header KVM: riscv: selftests: Add Smnpm and Ssnpm to get-reg-list test RISC-V: KVM: Allow Smnpm and Ssnpm extensions for guests riscv: hwprobe: Export the Supm ISA extension riscv: selftests: Add a pointer masking test riscv: Allow ptrace control of the tagged address ABI ...
2 parents c946969 + 8d4f1e0 commit 91dbbe6

Some content is hidden

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

53 files changed

+1789
-282
lines changed

Documentation/arch/riscv/hwprobe.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ The following keys are defined:
239239
ratified in commit 98918c844281 ("Merge pull request #1217 from
240240
riscv/zawrs") of riscv-isa-manual.
241241

242+
* :c:macro:`RISCV_HWPROBE_EXT_SUPM`: The Supm extension is supported as
243+
defined in version 1.0 of the RISC-V Pointer Masking extensions.
244+
242245
* :c:macro:`RISCV_HWPROBE_KEY_CPUPERF_0`: Deprecated. Returns similar values to
243246
:c:macro:`RISCV_HWPROBE_KEY_MISALIGNED_SCALAR_PERF`, but the key was
244247
mistakenly classified as a bitmask rather than a value.
@@ -274,3 +277,19 @@ The following keys are defined:
274277
represent the highest userspace virtual address usable.
275278

276279
* :c:macro:`RISCV_HWPROBE_KEY_TIME_CSR_FREQ`: Frequency (in Hz) of `time CSR`.
280+
281+
* :c:macro:`RISCV_HWPROBE_KEY_MISALIGNED_VECTOR_PERF`: An enum value describing the
282+
performance of misaligned vector accesses on the selected set of processors.
283+
284+
* :c:macro:`RISCV_HWPROBE_MISALIGNED_VECTOR_UNKNOWN`: The performance of misaligned
285+
vector accesses is unknown.
286+
287+
* :c:macro:`RISCV_HWPROBE_MISALIGNED_VECTOR_SLOW`: 32-bit misaligned accesses using vector
288+
registers are slower than the equivalent quantity of byte accesses via vector registers.
289+
Misaligned accesses may be supported directly in hardware, or trapped and emulated by software.
290+
291+
* :c:macro:`RISCV_HWPROBE_MISALIGNED_VECTOR_FAST`: 32-bit misaligned accesses using vector
292+
registers are faster than the equivalent quantity of byte accesses via vector registers.
293+
294+
* :c:macro:`RISCV_HWPROBE_MISALIGNED_VECTOR_UNSUPPORTED`: Misaligned vector accesses are
295+
not supported at all and will generate a misaligned address fault.

Documentation/arch/riscv/uabi.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,19 @@ Misaligned accesses
6868
Misaligned scalar accesses are supported in userspace, but they may perform
6969
poorly. Misaligned vector accesses are only supported if the Zicclsm extension
7070
is supported.
71+
72+
Pointer masking
73+
---------------
74+
75+
Support for pointer masking in userspace (the Supm extension) is provided via
76+
the ``PR_SET_TAGGED_ADDR_CTRL`` and ``PR_GET_TAGGED_ADDR_CTRL`` ``prctl()``
77+
operations. Pointer masking is disabled by default. To enable it, userspace
78+
must call ``PR_SET_TAGGED_ADDR_CTRL`` with the ``PR_PMLEN`` field set to the
79+
number of mask/tag bits needed by the application. ``PR_PMLEN`` is interpreted
80+
as a lower bound; if the kernel is unable to satisfy the request, the
81+
``PR_SET_TAGGED_ADDR_CTRL`` operation will fail. The actual number of tag bits
82+
is returned in ``PR_PMLEN`` by the ``PR_GET_TAGGED_ADDR_CTRL`` operation.
83+
84+
Additionally, when pointer masking is enabled (``PR_PMLEN`` is greater than 0),
85+
a tagged address ABI is supported, with the same interface and behavior as
86+
documented for AArch64 (Documentation/arch/arm64/tagged-address-abi.rst).

Documentation/devicetree/bindings/riscv/extensions.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,18 @@ properties:
128128
changes to interrupts as frozen at commit ccbddab ("Merge pull
129129
request #42 from riscv/jhauser-2023-RC4") of riscv-aia.
130130
131+
- const: smmpm
132+
description: |
133+
The standard Smmpm extension for M-mode pointer masking as
134+
ratified at commit d70011dde6c2 ("Update to ratified state")
135+
of riscv-j-extension.
136+
137+
- const: smnpm
138+
description: |
139+
The standard Smnpm extension for next-mode pointer masking as
140+
ratified at commit d70011dde6c2 ("Update to ratified state")
141+
of riscv-j-extension.
142+
131143
- const: smstateen
132144
description: |
133145
The standard Smstateen extension for controlling access to CSRs
@@ -147,6 +159,12 @@ properties:
147159
and mode-based filtering as ratified at commit 01d1df0 ("Add ability
148160
to manually trigger workflow. (#2)") of riscv-count-overflow.
149161
162+
- const: ssnpm
163+
description: |
164+
The standard Ssnpm extension for next-mode pointer masking as
165+
ratified at commit d70011dde6c2 ("Update to ratified state")
166+
of riscv-j-extension.
167+
150168
- const: sstc
151169
description: |
152170
The standard Sstc supervisor-level extension for time compare as
@@ -178,6 +196,12 @@ properties:
178196
as ratified at commit 4a69197e5617 ("Update to ratified state") of
179197
riscv-svvptc.
180198

199+
- const: zabha
200+
description: |
201+
The Zabha extension for Byte and Halfword Atomic Memory Operations
202+
as ratified at commit 49f49c842ff9 ("Update to Rafified state") of
203+
riscv-zabha.
204+
181205
- const: zacas
182206
description: |
183207
The Zacas extension for Atomic Compare-and-Swap (CAS) instructions
@@ -290,6 +314,12 @@ properties:
290314
in commit 64074bc ("Update version numbers for Zfh/Zfinx") of
291315
riscv-isa-manual.
292316

317+
- const: ziccrse
318+
description:
319+
The standard Ziccrse extension which provides forward progress
320+
guarantee on LR/SC sequences, as ratified in commit b1d806605f87
321+
("Updated to ratified state.") of the riscv profiles specification.
322+
293323
- const: zk
294324
description:
295325
The standard Zk Standard Scalar cryptography extension as ratified

Documentation/features/locking/queued-spinlocks/arch-support.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
| openrisc: | ok |
2121
| parisc: | TODO |
2222
| powerpc: | ok |
23-
| riscv: | TODO |
23+
| riscv: | ok |
2424
| s390: | TODO |
2525
| sh: | TODO |
2626
| sparc: | ok |

arch/riscv/Kconfig

Lines changed: 136 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ config RISCV
8383
select ARCH_WANT_OPTIMIZE_HUGETLB_VMEMMAP
8484
select ARCH_WANTS_NO_INSTR
8585
select ARCH_WANTS_THP_SWAP if HAVE_ARCH_TRANSPARENT_HUGEPAGE
86+
select ARCH_WEAK_RELEASE_ACQUIRE if ARCH_USE_QUEUED_SPINLOCKS
8687
select BINFMT_FLAT_NO_DATA_START_OFFSET if !MMU
8788
select BUILDTIME_TABLE_SORT if MMU
8889
select CLINT_TIMER if RISCV_M_MODE
@@ -116,6 +117,7 @@ config RISCV
116117
select GENERIC_VDSO_TIME_NS if HAVE_GENERIC_VDSO
117118
select HARDIRQS_SW_RESEND
118119
select HAS_IOPORT if MMU
120+
select HAVE_ALIGNED_STRUCT_PAGE
119121
select HAVE_ARCH_AUDITSYSCALL
120122
select HAVE_ARCH_HUGE_VMALLOC if HAVE_ARCH_HUGE_VMAP
121123
select HAVE_ARCH_HUGE_VMAP if MMU && 64BIT
@@ -507,6 +509,39 @@ config NODES_SHIFT
507509
Specify the maximum number of NUMA Nodes available on the target
508510
system. Increases memory reserved to accommodate various tables.
509511

512+
choice
513+
prompt "RISC-V spinlock type"
514+
default RISCV_COMBO_SPINLOCKS
515+
516+
config RISCV_TICKET_SPINLOCKS
517+
bool "Using ticket spinlock"
518+
519+
config RISCV_QUEUED_SPINLOCKS
520+
bool "Using queued spinlock"
521+
depends on SMP && MMU && NONPORTABLE
522+
select ARCH_USE_QUEUED_SPINLOCKS
523+
help
524+
The queued spinlock implementation requires the forward progress
525+
guarantee of cmpxchg()/xchg() atomic operations: CAS with Zabha or
526+
LR/SC with Ziccrse provide such guarantee.
527+
528+
Select this if and only if Zabha or Ziccrse is available on your
529+
platform, RISCV_QUEUED_SPINLOCKS must not be selected for platforms
530+
without one of those extensions.
531+
532+
If unsure, select RISCV_COMBO_SPINLOCKS, which will use qspinlocks
533+
when supported and otherwise ticket spinlocks.
534+
535+
config RISCV_COMBO_SPINLOCKS
536+
bool "Using combo spinlock"
537+
depends on SMP && MMU
538+
select ARCH_USE_QUEUED_SPINLOCKS
539+
help
540+
Embed both queued spinlock and ticket lock so that the spinlock
541+
implementation can be chosen at runtime.
542+
543+
endchoice
544+
510545
config RISCV_ALTERNATIVE
511546
bool
512547
depends on !XIP_KERNEL
@@ -532,6 +567,17 @@ config RISCV_ISA_C
532567

533568
If you don't know what to do here, say Y.
534569

570+
config RISCV_ISA_SUPM
571+
bool "Supm extension for userspace pointer masking"
572+
depends on 64BIT
573+
default y
574+
help
575+
Add support for pointer masking in userspace (Supm) when the
576+
underlying hardware extension (Smnpm or Ssnpm) is detected at boot.
577+
578+
If this option is disabled, userspace will be unable to use
579+
the prctl(PR_{SET,GET}_TAGGED_ADDR_CTRL) API.
580+
535581
config RISCV_ISA_SVNAPOT
536582
bool "Svnapot extension support for supervisor mode NAPOT pages"
537583
depends on 64BIT && MMU
@@ -633,6 +679,40 @@ config RISCV_ISA_ZAWRS
633679
use of these instructions in the kernel when the Zawrs extension is
634680
detected at boot.
635681

682+
config TOOLCHAIN_HAS_ZABHA
683+
bool
684+
default y
685+
depends on !64BIT || $(cc-option,-mabi=lp64 -march=rv64ima_zabha)
686+
depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zabha)
687+
depends on AS_HAS_OPTION_ARCH
688+
689+
config RISCV_ISA_ZABHA
690+
bool "Zabha extension support for atomic byte/halfword operations"
691+
depends on TOOLCHAIN_HAS_ZABHA
692+
depends on RISCV_ALTERNATIVE
693+
default y
694+
help
695+
Enable the use of the Zabha ISA-extension to implement kernel
696+
byte/halfword atomic memory operations when it is detected at boot.
697+
698+
If you don't know what to do here, say Y.
699+
700+
config TOOLCHAIN_HAS_ZACAS
701+
bool
702+
default y
703+
depends on !64BIT || $(cc-option,-mabi=lp64 -march=rv64ima_zacas)
704+
depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zacas)
705+
depends on AS_HAS_OPTION_ARCH
706+
707+
config RISCV_ISA_ZACAS
708+
bool "Zacas extension support for atomic CAS"
709+
depends on TOOLCHAIN_HAS_ZACAS
710+
depends on RISCV_ALTERNATIVE
711+
default y
712+
help
713+
Enable the use of the Zacas ISA-extension to implement kernel atomic
714+
cmpxchg operations when it is detected at boot.
715+
636716
If you don't know what to do here, say Y.
637717

638718
config TOOLCHAIN_HAS_ZBB
@@ -786,10 +866,24 @@ config THREAD_SIZE_ORDER
786866

787867
config RISCV_MISALIGNED
788868
bool
869+
help
870+
Embed support for detecting and emulating misaligned
871+
scalar or vector loads and stores.
872+
873+
config RISCV_SCALAR_MISALIGNED
874+
bool
875+
select RISCV_MISALIGNED
789876
select SYSCTL_ARCH_UNALIGN_ALLOW
790877
help
791878
Embed support for emulating misaligned loads and stores.
792879

880+
config RISCV_VECTOR_MISALIGNED
881+
bool
882+
select RISCV_MISALIGNED
883+
depends on RISCV_ISA_V
884+
help
885+
Enable detecting support for vector misaligned loads and stores.
886+
793887
choice
794888
prompt "Unaligned Accesses Support"
795889
default RISCV_PROBE_UNALIGNED_ACCESS
@@ -801,7 +895,7 @@ choice
801895

802896
config RISCV_PROBE_UNALIGNED_ACCESS
803897
bool "Probe for hardware unaligned access support"
804-
select RISCV_MISALIGNED
898+
select RISCV_SCALAR_MISALIGNED
805899
help
806900
During boot, the kernel will run a series of tests to determine the
807901
speed of unaligned accesses. This probing will dynamically determine
@@ -812,7 +906,7 @@ config RISCV_PROBE_UNALIGNED_ACCESS
812906

813907
config RISCV_EMULATED_UNALIGNED_ACCESS
814908
bool "Emulate unaligned access where system support is missing"
815-
select RISCV_MISALIGNED
909+
select RISCV_SCALAR_MISALIGNED
816910
help
817911
If unaligned memory accesses trap into the kernel as they are not
818912
supported by the system, the kernel will emulate the unaligned
@@ -841,6 +935,46 @@ config RISCV_EFFICIENT_UNALIGNED_ACCESS
841935

842936
endchoice
843937

938+
choice
939+
prompt "Vector unaligned Accesses Support"
940+
depends on RISCV_ISA_V
941+
default RISCV_PROBE_VECTOR_UNALIGNED_ACCESS
942+
help
943+
This determines the level of support for vector unaligned accesses. This
944+
information is used by the kernel to perform optimizations. It is also
945+
exposed to user space via the hwprobe syscall. The hardware will be
946+
probed at boot by default.
947+
948+
config RISCV_PROBE_VECTOR_UNALIGNED_ACCESS
949+
bool "Probe speed of vector unaligned accesses"
950+
select RISCV_VECTOR_MISALIGNED
951+
depends on RISCV_ISA_V
952+
help
953+
During boot, the kernel will run a series of tests to determine the
954+
speed of vector unaligned accesses if they are supported. This probing
955+
will dynamically determine the speed of vector unaligned accesses on
956+
the underlying system if they are supported.
957+
958+
config RISCV_SLOW_VECTOR_UNALIGNED_ACCESS
959+
bool "Assume the system supports slow vector unaligned memory accesses"
960+
depends on NONPORTABLE
961+
help
962+
Assume that the system supports slow vector unaligned memory accesses. The
963+
kernel and userspace programs may not be able to run at all on systems
964+
that do not support unaligned memory accesses.
965+
966+
config RISCV_EFFICIENT_VECTOR_UNALIGNED_ACCESS
967+
bool "Assume the system supports fast vector unaligned memory accesses"
968+
depends on NONPORTABLE
969+
help
970+
Assume that the system supports fast vector unaligned memory accesses. When
971+
enabled, this option improves the performance of the kernel on such
972+
systems. However, the kernel and userspace programs will run much more
973+
slowly, or will not be able to run at all, on systems that do not
974+
support efficient unaligned memory accesses.
975+
976+
endchoice
977+
844978
source "arch/riscv/Kconfig.vendor"
845979

846980
endmenu # "Platform type"

arch/riscv/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ else
8282
riscv-march-$(CONFIG_TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI) := $(riscv-march-y)_zicsr_zifencei
8383
endif
8484

85+
# Check if the toolchain supports Zacas
86+
riscv-march-$(CONFIG_TOOLCHAIN_HAS_ZACAS) := $(riscv-march-y)_zacas
87+
88+
# Check if the toolchain supports Zabha
89+
riscv-march-$(CONFIG_TOOLCHAIN_HAS_ZABHA) := $(riscv-march-y)_zabha
90+
8591
# Remove F,D,V from isa string for all. Keep extensions between "fd" and "v" by
8692
# matching non-v and non-multi-letter extensions out with the filter ([^v_]*)
8793
KBUILD_CFLAGS += -march=$(shell echo $(riscv-march-y) | sed -E 's/(rv32ima|rv64ima)fd([^v_]*)v?/\1\2/')

arch/riscv/configs/defconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ CONFIG_PINCTRL_SOPHGO_CV1800B=y
167167
CONFIG_PINCTRL_SOPHGO_CV1812H=y
168168
CONFIG_PINCTRL_SOPHGO_SG2000=y
169169
CONFIG_PINCTRL_SOPHGO_SG2002=y
170+
CONFIG_GPIO_DWAPB=y
170171
CONFIG_GPIO_SIFIVE=y
171172
CONFIG_POWER_RESET_GPIO_RESTART=y
172173
CONFIG_SENSORS_SFCTEMP=m

arch/riscv/include/asm/Kbuild

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ generic-y += early_ioremap.h
66
generic-y += flat.h
77
generic-y += kvm_para.h
88
generic-y += mmzone.h
9+
generic-y += mcs_spinlock.h
910
generic-y += parport.h
10-
generic-y += spinlock.h
1111
generic-y += spinlock_types.h
12+
generic-y += ticket_spinlock.h
1213
generic-y += qrwlock.h
1314
generic-y += qrwlock_types.h
15+
generic-y += qspinlock.h
1416
generic-y += user.h
1517
generic-y += vmlinux.lds.h

0 commit comments

Comments
 (0)