Skip to content

sync: rvck #92: riscv: Add qspinlock support #162

Merged
xmzzz merged 7 commits into
OLK-6.6from
sync/rvck-pr-92
Apr 8, 2026
Merged

sync: rvck #92: riscv: Add qspinlock support #162
xmzzz merged 7 commits into
OLK-6.6from
sync/rvck-pr-92

Conversation

@xmzzz
Copy link
Copy Markdown
Contributor

@xmzzz xmzzz commented Apr 8, 2026

Sync commits from rvck PR #92.

Source PR: RVCK-Project/rvck#92

Commits

  • 6c746e0f8853 asm-generic: ticket-lock: Optimize arch_spin_value_unlocked()
  • 95a449ca6557 riscv: Improve zacas fully-ordered cmpxchg()
  • e5c918ea9ece riscv: Implement arch_cmpxchg128() using Zacas
  • 990811b35f1f riscv: Implement xchg8/16() using Zabha
  • b481f8fe2e2e asm-generic: ticket-lock: Reuse arch_spinlock_t of qspinlock
  • 13c093c6c4d4 asm-generic: ticket-lock: Add separate ticket-lock.h
  • ce9aec88eefa riscv: Add qspinlock support

guoren83 and others added 7 commits April 8, 2026 14:55
mainline inclusion
from mainline-v6.6-rc2
commit c6f4a90022524d06f6d9de323b1757031dcf0c26
category: feature
bugzilla: RVCK-Project/rvck#90

--------------------------------

The arch_spin_value_unlocked() of ticket-lock would cause the compiler to
generate inefficient asm code in riscv architecture because of
unnecessary memory access to the contended value.
Before the patch:
	void lockref_get(struct lockref *lockref)
	{
	  78:   fd010113                add     sp,sp,-48
	  7c:   02813023                sd      s0,32(sp)
	  80:   02113423                sd      ra,40(sp)
	  84:   03010413                add     s0,sp,48
	0000000000000088 <.LBB296>:
		CMPXCHG_LOOP(
	  88:   00053783                ld      a5,0(a0)
After the patch:
	void lockref_get(struct lockref *lockref)
	{
		CMPXCHG_LOOP(
	  78:   00053783                ld      a5,0(a0)
After the patch, the lockref_get() could get in a fast path instead of the
function's prologue. This is because ticket lock complex logic would
limit compiler optimization for the spinlock fast path, and qspinlock
won't.
The caller of arch_spin_value_unlocked() could benefit from this
change. Currently, the only caller is lockref.

Signed-off-by: Guo Ren <guoren@kernel.org>
Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Gao Rui <gao.rui@zte.com.cn>
Signed-off-by: Yanteng Si <si.yanteng@linux.dev>
Signed-off-by: Mingzheng Xing <xingmingzheng@iscas.ac.cn>
(cherry picked from commit 6c746e0)
mainline inclusion
from mainline-v6.12
commit 6116e22ef33a8239f3d53bb25377e9ed733c4176
category: feature
bugzilla: RVCK-Project/rvck#90

--------------------------------

The current fully-ordered cmpxchgXX() implementation results in:
  amocas.X.rl     a5,a4,(s1)
  fence           rw,rw
This provides enough sync but we can actually use the following better
mapping instead:
  amocas.X.aqrl   a5,a4,(s1)
Suggested-by: Andrea Parri <andrea@rivosinc.com>

Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
Signed-off-by: Gao Rui <gao.rui@zte.com.cn>
Signed-off-by: Yanteng Si <si.yanteng@linux.dev>
Signed-off-by: Mingzheng Xing <xingmingzheng@iscas.ac.cn>
(cherry picked from commit 95a449c)
mainline inclusion
from mainline-v6.12
commit f7bd2be7663c7de1dde27dadd352b2c3f4e19106
category: feature
bugzilla: RVCK-Project/rvck#90

--------------------------------

Now that Zacas is supported in the kernel, let's use the double word
atomic version of amocas to improve the SLUB allocator.
Note that we have to select fixed registers, otherwise gcc fails to pick
even registers and then produces a reserved encoding which fails to
assemble.

Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
Signed-off-by: Gao Rui <gao.rui@zte.com.cn>
Signed-off-by: Yanteng Si <si.yanteng@linux.dev>
Signed-off-by: Mingzheng Xing <xingmingzheng@iscas.ac.cn>
(cherry picked from commit e5c918e)
mainline inclusion
from mainline-v6.12
commit 97ddab7fbea8fceb044108b64ba2ee2c96ff8dab
category: feature
bugzilla: RVCK-Project/rvck#90

--------------------------------

This adds runtime support for Zabha in xchg8/16() operations.

Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
Signed-off-by: Gao Rui <gao.rui@zte.com.cn>
Signed-off-by: Yanteng Si <si.yanteng@linux.dev>
Signed-off-by: Mingzheng Xing <xingmingzheng@iscas.ac.cn>
(cherry picked from commit 990811b)
mainline inclusion
from mainline-v6.12
commit cbe82e140bb76e1aa9f808cc841654a25b70d4e5
category: feature
bugzilla: RVCK-Project/rvck#90

--------------------------------

The arch_spinlock_t of qspinlock has contained the atomic_t val, which
satisfies the ticket-lock requirement. Thus, unify the arch_spinlock_t
into qspinlock_types.h. This is the preparation for the next combo
spinlock.

Signed-off-by: Guo Ren <guoren@kernel.org>
Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
Signed-off-by: Gao Rui <gao.rui@zte.com.cn>
Signed-off-by: Yanteng Si <si.yanteng@linux.dev>
Signed-off-by: Mingzheng Xing <xingmingzheng@iscas.ac.cn>
(cherry picked from commit b481f8f)
mainline inclusion
from mainline-v6.12
commit 22c33321e260c8b4c1877b2cc0c4e26a0c74c23f
category: feature
bugzilla: RVCK-Project/rvck#90

--------------------------------

Add a separate ticket-lock.h to include multiple spinlock versions and
select one at compile time or runtime.

Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Guo Ren <guoren@kernel.org>
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
Signed-off-by: Gao Rui <gao.rui@zte.com.cn>
Signed-off-by: Yanteng Si <si.yanteng@linux.dev>
Signed-off-by: Mingzheng Xing <xingmingzheng@iscas.ac.cn>
(cherry picked from commit 13c093c)
mainline inclusion
from mainline-v6.12
commit ab83647fadae2f1f723119dc066b39a461d6d288
category: feature
bugzilla: RVCK-Project/rvck#90

--------------------------------

In order to produce a generic kernel, a user can select
CONFIG_COMBO_SPINLOCKS which will fallback at runtime to the ticket
spinlock implementation if Zabha or Ziccrse are not present.
Note that we can't use alternatives here because the discovery of
extensions is done too late and we need to start with the qspinlock
implementation because the ticket spinlock implementation would pollute
the spinlock value, so let's use static keys.
This is largely based on Guo's work and Leonardo reviews at [1].
Link: https://lore.kernel.org/linux-riscv/20231225125847.2778638-1-guoren@kernel.org/ [1]

Signed-off-by: Guo Ren <guoren@kernel.org>
Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
Signed-off-by: Gao Rui <gao.rui@zte.com.cn>
Signed-off-by: Yanteng Si <si.yanteng@linux.dev>
Signed-off-by: Mingzheng Xing <xingmingzheng@iscas.ac.cn>
(cherry picked from commit ce9aec8)
@xmzzz xmzzz merged commit ddc8edc into OLK-6.6 Apr 8, 2026
@xmzzz xmzzz deleted the sync/rvck-pr-92 branch April 8, 2026 06:55
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 8, 2026


开始测试 log: https://github.com/RVCK-Project/rvck-olk/actions/runs/24122241762

参数解析结果
args value
repository RVCK-Project/rvck-olk
head ref pull/162/head
base ref OLK-6.6
LAVA repo RVCK-Project/lavaci
LAVA Template lava-job-template/qemu/qemu-ltp.yaml
Testcase path lava-testcases/common-test/ltp/ltp.yaml
need run job kunit-test,kernel-build,check-patch,lava-trigger

测试完成

详细结果:

RVCK result

check result
kunit-test success
kernel-build success
lava-trigger success
check-patch failure

Kunit Test Result

[07:01:00] Testing complete. Ran 454 tests: passed: 442, skipped: 12

Kernel Build Result

Kernel build succeeded: RVCK-Project/rvck-olk/162__1/

bfa6cb9900580c44f721aaecc0a6e482 /srv/guix_result/7d1f8d8252f54c58b4724148388fa733aaef0edb/Image
5eb05f8de8329e51d4e2e7614155ee6c /root/initramfs.img

LAVA Check

args:

result:

Lava check done! lava log: https://lava.oerv.ac.cn/scheduler/job/1752

lava result count: [fail]: 19, [pass]: 1587, [skip]: 293

Check Patch Result

Total Errors 1
Total Warnings 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants