Skip to content

backport RISC-V TLB/ASID enhancements with mainline SSWI support - #394

Open
zhuzhenxxx-collab wants to merge 16 commits into
RVCK-Project:rvck-6.6from
zhuzhenxxx-collab:rvck-6.6-tlb-asid-enhancements
Open

zhuzhenxxx-collab wants to merge 16 commits into
RVCK-Project:rvck-6.6from
zhuzhenxxx-collab:rvck-6.6-tlb-asid-enhancements

Conversation

@zhuzhenxxx-collab

@zhuzhenxxx-collab zhuzhenxxx-collab commented Sep 16, 2026 •

Copy link
Copy Markdown

本 PR 将上游主线 RISC-V TLB/ASID 优化系列补丁 backport 到 rvck-6.6 基线,并同步完成 ACLINT SSWI 的主线化改造,使 TH1520 平台使用独立的 irq-thead-c900-aclint-sswi irqchip 驱动提供快速 IPI。

变更内容

  • TLB/ASID 优化系列 (https://lore.kernel.org/all/171569524205.4793.10651789416740480698.git-patchwork-notify@kernel.org/)

    • 引入 cntx2asid / cntx2version 辅助宏,统一管理 MM context ID 布局
    • 使用固定格式的 MM context ID,简化 ASID 与 version 的拆分逻辑
    • 将 asid_bits 改为局部变量,避免全局状态
    • 保留全局 TLB entry 切换上下文时不失效
    • 统一 SMP/UP TLB flush 代码路径
    • 使用 IPI 进行远程 cache/TLB flush
    • 仅在必要时广播 kernel TLB flush
    • 避免 SiFive CIP-1200 影响下的 TLB flush 循环
  • SSWI 主线化

    • Revert 嵌入在 sbi-ipi.c 中的厂商 SSWI 实现
    • 在 th1520.dtsi 中添加 thead,c900-aclint-sswi 设备节点
    • 启用 drivers/irqchip/irq-thead-c900-aclint-sswi.c 独立 irqchip 驱动提供 IPI

验证结果
场景一:SSWI 开启(CONFIG_THEAD_C900_ACLINT_SSWI=y)

root@light-a-val:~# dmesg | grep -i sswi
[    0.000000] thead-c900-aclint-sswi: interrupt-controller@ffdc00c000: register 4 CPUs
[    0.000000] thead-c900-aclint-sswi: providing IPIs using THEAD ACLINT SSWI
root@light-a-val:~# dmesg | grep -i "ASID allocator"
[    0.100516] ASID allocator using 16 bits (65536 entries)
root@light-a-val:~# zcat /proc/config.gz | grep CONFIG_THEAD_C900_ACLINT_SSWI
CONFIG_THEAD_C900_ACLINT_SSWI=y

场景二:SSWI 关闭(# CONFIG_THEAD_C900_ACLINT_SSWI is not set,同一份 DTB)

root@light-a-val:~# zcat /proc/config.gz | grep CONFIG_THEAD_C900_ACLINT_SSWI
# CONFIG_THEAD_C900_ACLINT_SSWI is not set
root@light-a-val:~# dmesg | head -1
[    0.000000] Linux version 6.6.155+ (o_zhuzx@docker-ubuntu20) (riscv64-unknown-linux-gnu-gcc (Xuantie-900 linux-6.6.36 glibc gcc Toolchain V3.3.0-rc0 B-20251223) 14.3.0, GNU ld (GNU Binutils) 2.42.50) #126 SMP Thu Sep 6
root@light-a-val:~# dmesg | grep -i "providing IPIs"
[    0.000000] riscv: providing IPIs using SBI IPI extension
root@light-a-val:~# dmesg | grep -i sswi
root@light-a-val:~# dmesg | grep -i "ASID allocator"
[    0.104244] ASID allocator using 16 bits (65536 entries)
root@light-a-val:~# cat /proc/interrupts | grep -i ipi
IPI0:       418        311        366        274  Rescheduling interrupts
IPI1:      1699       2634       2144       3037  Function call interrupts
IPI2:         0          0          0          0  CPU stop interrupts
IPI3:         0          0          0          0  CPU stop (for crash dump) interrupts
IPI4:         0          0          0          0  IRQ work interrupts
IPI5:         0          0          0          0  Timer broadcast interrupts
IPI6:         0          0          0          0  CPU backtrace interrupts
root@light-a-val:~# cat /proc/device-tree/model
Sipeed Lichee Pi 4A

fixes: #332

@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

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

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

测试完成

详细结果:
check result
kunit-test success
kernel-build success
check-patch success
lava-trigger-qemu success
lava-trigger-sg2042 skipped
lava-trigger-k1 skipped
lava-trigger-lpi4a skipped

Kunit Test Result

[03:47:00] Testing complete. Ran 482 tests: passed: 465, skipped: 17

Kernel Build Result

Check Patch Result

Total Errors 0
Total Warnings 14

LAVA Check (qemu)

args value
testcase_repo RVCK-Project/lavaci
lava_template lava-job-template/qemu/qemu-ltp.yaml
testcase_path lava-testcases/common-test/ltp/ltp.yaml
kernel_download_url http://10.30.190.110/openEuler-RISC-V/RVCK/OERV-RVCI/RVCK-Project/rvck/394_35052795989_1/Image
initramfs_download_url http://10.30.190.110/openEuler-RISC-V/RVCK/OERV-RVCI/RVCK-Project/rvck/394_35052795989_1/initramfs.img
rootfs_download_url https://fast-mirror.isrc.ac.cn/openeuler-sig-riscv/openEuler-RISC-V/RVCK/openEuler24.03-LTS-SP1/openeuler-rootfs.img.zst
testcase_ref main
testitem_name RVCK-Project_rvck_pull_request_target_394__common-test_qemu

result: Lava check done!

@uestc-gr uestc-gr left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1、从 PR 描述来看,irq ipi tlb三个功能点被放进了一个 PR,它们之间存在一定的技术关联。
看看是否能拆分成几个pr提交,如果不能需在pr中详细描述他们的依赖原因

2、类似riscv: Use IPIs for remote cache/TLB flushes by default,包含了很多非上游的代码,如果不能另外拆个补丁,需在commit message中详细说明。

3、tlb的修改需要长时间测试证明稳定性,如果只是为了厂商 SSWI 的支持代价似乎有点大

@zhuzhenxxx-collab
zhuzhenxxx-collab force-pushed the rvck-6.6-tlb-asid-enhancements branch from bea3d86 to d40186e Compare September 17, 2026 10:09
@github-actions

github-actions Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

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

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

测试完成

详细结果:
check result
kunit-test success
kernel-build success
check-patch success
lava-trigger-qemu success
lava-trigger-sg2042 skipped
lava-trigger-k1 skipped
lava-trigger-lpi4a skipped

Kunit Test Result

[10:14:01] Testing complete. Ran 482 tests: passed: 465, skipped: 17

Kernel Build Result

Check Patch Result

Total Errors 0
Total Warnings 14

LAVA Check (qemu)

args value
testcase_repo RVCK-Project/lavaci
lava_template lava-job-template/qemu/qemu-ltp.yaml
testcase_path lava-testcases/common-test/ltp/ltp.yaml
kernel_download_url http://10.30.190.110/openEuler-RISC-V/RVCK/OERV-RVCI/RVCK-Project/rvck/394_35209011751_1/Image
initramfs_download_url http://10.30.190.110/openEuler-RISC-V/RVCK/OERV-RVCI/RVCK-Project/rvck/394_35209011751_1/initramfs.img
rootfs_download_url https://fast-mirror.isrc.ac.cn/openeuler-sig-riscv/openEuler-RISC-V/RVCK/openEuler24.03-LTS-SP1/openeuler-rootfs.img.zst
testcase_ref main
testitem_name RVCK-Project_rvck_pull_request_target_394__common-test_qemu

result: Lava check done!

@zhuzhenxxx-collab

Copy link
Copy Markdown
Author

1、从 PR 描述来看,irq ipi tlb三个功能点被放进了一个 PR,它们之间存在一定的技术关联。 看看是否能拆分成几个pr提交,如果不能需在pr中详细描述他们的依赖原因

这个PR是按照同一个上游系列 riscv: ASID-related and UP-related TLB flush enhancements(Samuel Holland,v6.10)按原序的 backport,IPI 层和 TLB 层的改动在上游就是同一批代码、互相依赖。为了保持原提交的内容,在RVCK上又合入了3笔适配的提交。

  • commit 065f9a5:为了解决基线 vendor 嵌入在 sbi-ipi.c 的 SSWI 实现与系列第 3 笔在同一行 riscv_ipi_set_virq_range() 调用上的直接冲突,必须先 revert 才能让系列干净落入。
  • commit 21a588a:为了解决 revert 连带删除旧 binding(riscv,aclint-sswi)DTS 节点后 SSWI 能力丢失的问题,补上游 binding(thead,c900-aclint-sswi)节点,由树中已有的主线驱动接管。
  • commit d40186e:为了解决系列第 3 笔将 riscv_ipi_set_virq_range() 从 3 参改为 2 参后,SSWI 驱动 2 个调用点在 CONFIG_THEAD_C900_ACLINT_SSWI=y 时编译失败的问题。

2、类似riscv: Use IPIs for remote cache/TLB flushes by default,包含了很多非上游的代码,如果不能另外拆个补丁,需在commit message中详细说明。

已完成拆分了。riscv: Use IPIs for remote cache/TLB flushes by default 现在是与上游 dc892fb 完全一致的纯 cherry-pick(patch-id 相同),原混入其中的非上游代码4 行(SSWI 驱动 2 个调用点适配新 API 签名),已独立为末尾提交:irqchip: thead-c900-aclint-sswi: Fixup riscv_ipi_set_virq_range() conflict

该提交仿上游同类先例 46cad6c(上游在 API 变更后为 imsic 驱动补的 fixup),commit message 中已说明冲突原因和适配内容。

3、tlb的修改需要长时间测试证明稳定性,如果只是为了厂商 SSWI 的支持代价似乎有点大

这组PR是上游已合入的针对性优化,和SSWI本质上没有关系,在RVCK上支持为了适配修改到了SSWI的代码。

@unicornx

Copy link
Copy Markdown
Collaborator

@zhuzhenxxx-collab 我看到 rvck-6.6 昨天升级了,请更新时注意 rebase 一下,谢谢

dist inclusion
category: cleanup
Link: RVCK-Project#332

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

This reverts commit 3ea68e2 ("riscv: Add ACLINT SSWI support").

The embedded ACLINT SSWI support in sbi-ipi.c is a vendor-local
implementation that never went upstream. Mainline instead provides a
dedicated irqchip driver (drivers/irqchip/irq-thead-c900-aclint-sswi.c,
upstream 25caea9), which has already been backported into this tree.

Carrying the embedded SSWI forces downstream patches to add sswi_base-
specific adaptations that diverge from mainline. Remove it so that
sbi-ipi.c stays in the pure mainline form and the TLB/ASID backport
series applies without conflicts. The platform keeps using SBI IPIs;
the SSWI irqchip driver remains available in the tree for boards whose
device trees provide the upstream "thead,c900-aclint-sswi" node.

Signed-off-by: ZhenXing Zhu <zhenxing.zhu@linux.alibaba.com>
@zhuzhenxxx-collab
zhuzhenxxx-collab force-pushed the rvck-6.6-tlb-asid-enhancements branch from d40186e to 42ac8a0 Compare September 20, 2026 04:34
@github-actions

github-actions Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

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

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

测试完成

详细结果:
check result
kunit-test success
kernel-build success
check-patch success
lava-trigger-qemu success
lava-trigger-sg2042 skipped
lava-trigger-k1 skipped
lava-trigger-lpi4a skipped

Kunit Test Result

[04:38:25] Testing complete. Ran 482 tests: passed: 465, skipped: 17

Kernel Build Result

Check Patch Result

Total Errors 0
Total Warnings 14

LAVA Check (qemu)

args value
testcase_repo RVCK-Project/lavaci
lava_template lava-job-template/qemu/qemu-ltp.yaml
testcase_path lava-testcases/common-test/ltp/ltp.yaml
kernel_download_url http://10.30.190.110/openEuler-RISC-V/RVCK/OERV-RVCI/RVCK-Project/rvck/394_35489485754_1/Image
initramfs_download_url http://10.30.190.110/openEuler-RISC-V/RVCK/OERV-RVCI/RVCK-Project/rvck/394_35489485754_1/initramfs.img
rootfs_download_url https://fast-mirror.isrc.ac.cn/openeuler-sig-riscv/openEuler-RISC-V/RVCK/openEuler24.03-LTS-SP1/openeuler-rootfs.img.zst
testcase_ref main
testitem_name RVCK-Project_rvck_pull_request_target_394__common-test_qemu

result: Lava check done!

@zhuzhenxxx-collab

Copy link
Copy Markdown
Author

**unicornx **

done,麻烦再review一下

@unicornx
unicornx requested a review from uestc-gr September 20, 2026 09:28
@unicornx

Copy link
Copy Markdown
Collaborator

我有两个问题想问一下:

  • 上游系列 riscv: ASID-related and UP-related TLB flush enhancements(Samuel Holland,v6.10) 能否在 PR 中补充一下它的邮件列表链接

  • 这个补丁合入后影响的板卡主要有哪些?是不是只有 th1520?

@uestc-gr 请再 review 一下,谢谢

@zhuzhenxxx-collab

Copy link
Copy Markdown
Author

我有两个问题想问一下:

  • 上游系列 riscv: ASID-related and UP-related TLB flush enhancements(Samuel Holland,v6.10) 能否在 PR 中补充一下它的邮件列表链接
  • 这个补丁合入后影响的板卡主要有哪些?是不是只有 th1520?

@uestc-gr 请再 review 一下,谢谢

lore链接已补充

@zhuzhenxxx-collab

Copy link
Copy Markdown
Author

我有两个问题想问一下:

  • 上游系列 riscv: ASID-related and UP-related TLB flush enhancements(Samuel Holland,v6.10) 能否在 PR 中补充一下它的邮件列表链接
  • 这个补丁合入后影响的板卡主要有哪些?是不是只有 th1520?

@uestc-gr 请再 review 一下,谢谢

dts的修改只涉及1520

@uestc-gr uestc-gr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

riscv: dts: thead: add TH1520 ACLINT SSWI interrupt-controller node
commit message 缺少issues id 等字段

其它没有什么问题,tlb的修改建议多测试一下

Reviewed-by: Gao Rui gao.rui@zte.com.cn

@uestc-gr
uestc-gr self-requested a review September 21, 2026 01:51
ZhenXing Zhu and others added 11 commits September 21, 2026 02:16
dist inclusion
category: feature
Link: RVCK-Project#332

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

Add the device tree node for the T-HEAD C900 ACLINT SSWI device so that
the backported mainline irqchip driver (drivers/irqchip/irq-thead-c900-
aclint-sswi.c, upstream 25caea9) is probed and provides fast IPIs.

The embedded SSWI support added by commit 3ea68e2 ("riscv: Add
ACLINT SSWI support") has been reverted; this node uses the upstream
binding "thead,c900-aclint-sswi" and the required interrupts-extended
property pointing each hart at its supervisor software interrupt.

Signed-off-by: ZhenXing Zhu <zhenxing.zhu@linux.alibaba.com>
mainline inclusion
from mainline-6.10
commit 58661a3 ("riscv: Flush the instruction cache during SMP bringup")
category: feature
Link: RVCK-Project#332

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

Instruction cache flush IPIs are sent only to CPUs in cpu_online_mask,
so they will not target a CPU until it calls set_cpu_online() earlier in
smp_callin(). As a result, if instruction memory is modified between the
CPU coming out of reset and that point, then its instruction cache may
contain stale data. Therefore, the instruction cache must be flushed
after the set_cpu_online() synchronization point.

Fixes: 08f051e ("RISC-V: Flush I$ when making a dirty page executable")
Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Link: https://lore.kernel.org/r/20240327045035.368512-2-samuel.holland@sifive.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
Signed-off-by: ZhenXing Zhu <zhenxing.zhu@linux.alibaba.com>
mainline inclusion
from mainline-6.10
commit aaa56c8 ("riscv: Factor out page table TLB synchronization")
category: feature
Link: RVCK-Project#332

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

The logic is the same for all page table levels. See commit 69be3fb
("riscv: enable MMU_GATHER_RCU_TABLE_FREE for SMP && MMU").

Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Link: https://lore.kernel.org/r/20240327045035.368512-3-samuel.holland@sifive.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
Signed-off-by: ZhenXing Zhu <zhenxing.zhu@linux.alibaba.com>
mainline inclusion
from mainline-6.10
commit dc892fb ("riscv: Use IPIs for remote cache/TLB flushes by default")
category: feature
Link: RVCK-Project#332

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

An IPI backend is always required in an SMP configuration, but an SBI
implementation is not. For example, SBI will be unavailable when the
kernel runs in M mode. For this reason, consider IPI delivery of cache
and TLB flushes to be the base case, and any other implementation (such
as the SBI remote fence extension) to be an optimization.

Generally, if IPIs can be delivered without firmware assistance, they
are assumed to be faster than SBI calls due to the SBI context switch
overhead. However, when SBI is used as the IPI backend, then the context
switch cost must be paid anyway, and performing the cache/TLB flush
directly in the SBI implementation is more efficient than injecting an
interrupt to S-mode. This is the only existing scenario where
riscv_ipi_set_virq_range() is called with use_for_rfence set to false.

sbi_ipi_init() already checks riscv_ipi_have_virq_range(), so it only
calls riscv_ipi_set_virq_range() when no other IPI device is available.
This allows moving the static key and dropping the use_for_rfence
parameter. This decouples the static key from the irqchip driver probe
order.

Furthermore, the static branch only makes sense when CONFIG_RISCV_SBI is
enabled. Optherwise, IPIs must be used. Add a fallback definition of
riscv_use_sbi_for_rfence() which handles this case and removes the need
to check CONFIG_RISCV_SBI elsewhere, such as in cacheflush.c.

Reviewed-by: Anup Patel <anup@brainfault.org>
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Link: https://lore.kernel.org/r/20240327045035.368512-4-samuel.holland@sifive.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
Signed-off-by: ZhenXing Zhu <zhenxing.zhu@linux.alibaba.com>
mainline inclusion
from mainline-6.10
commit 038ac18 ("riscv: mm: Broadcast kernel TLB flushes only when needed")
category: feature
Link: RVCK-Project#332

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

__flush_tlb_range() avoids broadcasting TLB flushes when an mm context
is only active on the local CPU. Apply this same optimization to TLB
flushes of kernel memory when only one CPU is online. This check can be
constant-folded when SMP is disabled.

Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Link: https://lore.kernel.org/r/20240327045035.368512-5-samuel.holland@sifive.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
Signed-off-by: ZhenXing Zhu <zhenxing.zhu@linux.alibaba.com>
mainline inclusion
from mainline-6.10
commit 9546f00 ("riscv: Only send remote fences when some other CPU is online")
category: feature
Link: RVCK-Project#332

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

If no other CPU is online, a local cache or TLB flush is sufficient.
These checks can be constant-folded when SMP is disabled.

Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Link: https://lore.kernel.org/r/20240327045035.368512-6-samuel.holland@sifive.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
Signed-off-by: ZhenXing Zhu <zhenxing.zhu@linux.alibaba.com>
mainline inclusion
from mainline-6.10
commit c6026d3 ("riscv: mm: Combine the SMP and UP TLB flush code")
category: feature
Link: RVCK-Project#332

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

In SMP configurations, all TLB flushing narrower than flush_tlb_all()
goes through __flush_tlb_range(). Do the same in UP configurations.

This allows UP configurations to take advantage of recent improvements
to the code in tlbflush.c, such as support for huge pages and flushing
multiple-page ranges.

Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Reviewed-by: Yunhui Cui <cuiyunhui@bytedance.com>
Link: https://lore.kernel.org/r/20240327045035.368512-7-samuel.holland@sifive.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
Signed-off-by: ZhenXing Zhu <zhenxing.zhu@linux.alibaba.com>
mainline inclusion
from mainline-6.10
commit d6dcdab ("riscv: Avoid TLB flush loops when affected by SiFive CIP-1200")
category: feature
Link: RVCK-Project#332

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

Implementations affected by SiFive errata CIP-1200 have a bug which
forces the kernel to always use the global variant of the sfence.vma
instruction. When affected by this errata, do not attempt to flush a
range of addresses; each iteration of the loop would actually flush the
whole TLB instead. Instead, minimize the overall number of sfence.vma
instructions.

Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Reviewed-by: Yunhui Cui <cuiyunhui@bytedance.com>
Link: https://lore.kernel.org/r/20240327045035.368512-9-samuel.holland@sifive.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
Signed-off-by: ZhenXing Zhu <zhenxing.zhu@linux.alibaba.com>
mainline inclusion
from mainline-6.10
commit 74cd177 ("riscv: mm: Introduce cntx2asid/cntx2version helper macros")
category: feature
Link: RVCK-Project#332

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

When using the ASID allocator, the MM context ID contains two values:
the ASID in the lower bits, and the allocator version number in the
remaining bits. Use macros to make this separation more obvious.

Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Link: https://lore.kernel.org/r/20240327045035.368512-10-samuel.holland@sifive.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
Signed-off-by: ZhenXing Zhu <zhenxing.zhu@linux.alibaba.com>
mainline inclusion
from mainline-6.10
commit f58e5dc ("riscv: mm: Use a fixed layout for the MM context ID")
category: feature
Link: RVCK-Project#332

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

Currently, the size of the ASID field in the MM context ID dynamically
depends on the number of hardware-supported ASID bits. This requires
reading a global variable to extract either field from the context ID.
Instead, allocate the maximum possible number of bits to the ASID field,
so the layout of the context ID is known at compile-time.

Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Link: https://lore.kernel.org/r/20240327045035.368512-11-samuel.holland@sifive.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
Signed-off-by: ZhenXing Zhu <zhenxing.zhu@linux.alibaba.com>
mainline inclusion
from mainline-6.10
commit 8d3e761 ("riscv: mm: Make asid_bits a local variable")
category: feature
Link: RVCK-Project#332

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

This variable is only used inside asids_init().

Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Link: https://lore.kernel.org/r/20240327045035.368512-12-samuel.holland@sifive.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
Signed-off-by: ZhenXing Zhu <zhenxing.zhu@linux.alibaba.com>
SiFiveHolland and others added 4 commits September 21, 2026 02:16
mainline inclusion
from mainline-6.10
commit 8fc21cc ("riscv: mm: Preserve global TLB entries when switching contexts")
category: feature
Link: RVCK-Project#332

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

If the CPU does not support multiple ASIDs, all MM contexts use ASID 0.
In this case, it is still beneficial to flush the TLB by ASID, as the
single-ASID variant of the sfence.vma instruction preserves TLB entries
for global (kernel) pages.

This optimization is recommended by the RISC-V privileged specification:

  If the implementation does not provide ASIDs, or software chooses
  to always use ASID 0, then after every satp write, software should
  execute SFENCE.VMA with rs1=x0. In the common case that no global
  translations have been modified, rs2 should be set to a register
  other than x0 but which contains the value zero, so that global
  translations are not flushed.

It is not possible to apply this optimization when using the ASID
allocator, because that code must flush the TLB for all ASIDs at once
when incrementing the version number.

Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Link: https://lore.kernel.org/r/20240327045035.368512-13-samuel.holland@sifive.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
Signed-off-by: ZhenXing Zhu <zhenxing.zhu@linux.alibaba.com>
mainline inclusion
from mainline-6.10
commit daef192 ("riscv: mm: Always use an ASID to flush mm contexts")
category: feature
Link: RVCK-Project#332

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

Even if multiple ASIDs are not supported, using the single-ASID variant
of the sfence.vma instruction preserves TLB entries for global (kernel)
pages. So it is always more efficient to use the single-ASID code path.

Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Link: https://lore.kernel.org/r/20240327045035.368512-14-samuel.holland@sifive.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
Signed-off-by: ZhenXing Zhu <zhenxing.zhu@linux.alibaba.com>
mainline inclusion
from mainline-6.10
commit 46cad6c ("irqchip: riscv-imsic: Fixup riscv_ipi_set_virq_range() conflict")
category: feature
Link: RVCK-Project#332

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

There was a semantic conflict between 21a8f8a ("irqchip: Add RISC-V
incoming MSI controller early driver") and dc892fb ("riscv: Use
IPIs for remote cache/TLB flushes by default") due to an API change.
This manifests as a build failure post-merge.

Reported-by: Tomasz Jeznach <tjeznach@rivosinc.com>
Link: https://lore.kernel.org/all/mhng-10b71228-cf3e-42ca-9abf-5464b15093f1@palmer-ri-x1c9/
Fixes: 0bfbc91 ("Merge tag 'riscv-for-linus-6.10-mw1' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux")
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20240522184953.28531-3-palmer@rivosinc.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
Signed-off-by: ZhenXing Zhu <zhenxing.zhu@linux.alibaba.com>
…flict

dist inclusion
category: bugfix
Link: RVCK-Project#332

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

There is a semantic conflict between the backported T-HEAD SSWI driver
(upstream 25caea9) and dc892fb ("riscv: Use IPIs for remote
cache/TLB flushes by default") due to the riscv_ipi_set_virq_range()
API change that drops the use_for_rfence parameter. Adapt the two call
sites to the new 2-parameter signature, otherwise the driver fails to
build when CONFIG_THEAD_C900_ACLINT_SSWI is enabled.

This mirrors upstream 46cad6c ("irqchip: riscv-imsic: Fixup
riscv_ipi_set_virq_range() conflict"), which resolved the same class
of conflict for the IMSIC driver.

Signed-off-by: ZhenXing Zhu <zhenxing.zhu@linux.alibaba.com>
@zhuzhenxxx-collab
zhuzhenxxx-collab force-pushed the rvck-6.6-tlb-asid-enhancements branch from 42ac8a0 to dacebe5 Compare September 21, 2026 02:17
@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

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

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

测试完成

详细结果:
check result
kunit-test success
kernel-build success
check-patch success
lava-trigger-qemu success
lava-trigger-sg2042 skipped
lava-trigger-k1 skipped
lava-trigger-lpi4a skipped

Kunit Test Result

[02:22:31] Testing complete. Ran 482 tests: passed: 465, skipped: 17

Kernel Build Result

Check Patch Result

Total Errors 0
Total Warnings 14

LAVA Check (qemu)

args value
testcase_repo RVCK-Project/lavaci
lava_template lava-job-template/qemu/qemu-ltp.yaml
testcase_path lava-testcases/common-test/ltp/ltp.yaml
kernel_download_url http://10.30.190.110/openEuler-RISC-V/RVCK/OERV-RVCI/RVCK-Project/rvck/394_35553714724_1/Image
initramfs_download_url http://10.30.190.110/openEuler-RISC-V/RVCK/OERV-RVCI/RVCK-Project/rvck/394_35553714724_1/initramfs.img
rootfs_download_url https://fast-mirror.isrc.ac.cn/openeuler-sig-riscv/openEuler-RISC-V/RVCK/openEuler24.03-LTS-SP1/openeuler-rootfs.img.zst
testcase_ref main
testitem_name RVCK-Project_rvck_pull_request_target_394__common-test_qemu

result: Lava check done!

@zhuzhenxxx-collab

Copy link
Copy Markdown
Author

riscv: dts: thead: add TH1520 ACLINT SSWI interrupt-controller node commit message 缺少issues id 等字段

其它没有什么问题,tlb的修改建议多测试一下

Reviewed-by: Gao Rui gao.rui@zte.com.cn

已修改。

本地th1520 系统运行了几个小时没发现异常。

@uestc-gr uestc-gr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Reviewed-by: Gao Rui gao.rui@zte.com.cn

@unicornx unicornx left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Reviewed-by: Chen Wang wangchen20@iscas.ac.cn

@unicornx

Copy link
Copy Markdown
Collaborator

Built and Tested boot-up on QEMU/virt + Pioneerbox.

@sterling-teng 请帮忙在 th1520 上也验证一下,因为这个 PR 涉及该开发板,我手头没有这个硬件,谢谢。

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RISC-V: ASID-related and UP-related TLB flush enhancement

5 participants