Skip to content

[Backport] KVM: add 'vlenb' Vector CSR#264

Merged
sterling-teng merged 3 commits into
RVCK-Project:rvck-6.6from
yechao-w:vlenb
May 12, 2026
Merged

[Backport] KVM: add 'vlenb' Vector CSR#264
sterling-teng merged 3 commits into
RVCK-Project:rvck-6.6from
yechao-w:vlenb

Conversation

@yechao-w
Copy link
Copy Markdown
Contributor

@yechao-w yechao-w commented Apr 30, 2026

issues: #263

补丁来自upstream,未做修改。

kvm one reg 增加对vlenb的支持,解决kvm虚拟机启动失败问题。

测试命令:

/usr/bin/qemu-system-riscv64 \
        -nographic -enable-kvm \
        -machine virt,acpi=off,aia=aplic-imsic,accel=kvm \
        -smp 16,sockets=2,dies=1,clusters=1,cores=8,threads=1 \
        -m 4G \
        -object memory-backend-ram,size=2G,id=ram1 \
        -numa node,memdev=ram1 \
        -object memory-backend-ram,size=2G,id=ram2 \
        -numa node,memdev=ram2 \
        -kernel ./Image \
        -drive file="./rootfs.img",format=raw,id=hd0 \
        -append "root=/dev/vda rw earlycon=sbi console=tty0 console=ttyS0" \
        -object rng-random,filename=/dev/urandom,id=rng0 \
        -device virtio-rng-device,rng=rng0 \
        -cpu host \
        -device qemu-xhci \
        -usb -device usb-kbd \
        -device usb-tablet \
        -chardev socket,id=qmp,path=/var/lib/libvirt/qemu/riscv-test,server=on,wait=off \
        -mon mode=control,chardev=qmp

kvm虚拟机启动成功。

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 30, 2026


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

参数解析结果
args value
repository RVCK-Project/rvck
head ref pull/264/head
base ref rvck-6.6
LAVA repo RVCK-Project/lavaci
LAVA hardware
LAVA Testcase path
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 skipped
lava-trigger-sg2042 skipped
lava-trigger-k1 skipped
lava-trigger-lpi4a skipped

Kunit Test Result

[02:49:18] Testing complete. Ran 457 tests: passed: 445, skipped: 12

Kernel Build Result

Check Patch Result

Total Errors 0
Total Warnings 0

@sterling-teng
Copy link
Copy Markdown
Contributor

5月rebase后审阅。

danielhb and others added 3 commits May 6, 2026 16:36
mainline inclusion
from mainline-6.10-rc1
commit 197bd23
category: feature
bugzilla: RVCK-Project#263

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

'vlenb', added to riscv_v_ext_state by commit c35f3aa ("RISC-V:
vector: export VLENB csr in __sc_riscv_v_state"), isn't being
initialized in guest_context. If we export 'vlenb' as a KVM CSR,
something we want to do in the next patch, it'll always return 0.

Set 'vlenb' to riscv_v_size/32.

Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Signed-off-by: Anup Patel <anup@brainfault.org>
Signed-off-by: Wang Yechao <wang.yechao255@zte.com.cn>
mainline inclusion
from mainline-6.10-rc1
commit 2fa2903
category: feature
bugzilla: RVCK-Project#263

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

Userspace requires 'vlenb' to be able to encode it in reg ID. Otherwise
it is not possible to retrieve any vector reg since we're returning
EINVAL if reg_size isn't vlenb (see kvm_riscv_vcpu_vreg_addr()).

Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Signed-off-by: Anup Patel <anup@brainfault.org>
Signed-off-by: Wang Yechao <wang.yechao255@zte.com.cn>
mainline inclusion
from mainline-v6.17-rc4
commit 7997662
category: feature
bugzilla: RVCK-Project#263

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

The userspace load can put up to 2048 bits into an xlen bit stack
buffer.  We want only xlen bits, so check the size beforehand.

Fixes: 2fa2903 ("RISC-V: KVM: add 'vlenb' Vector CSR")
Cc: stable@vger.kernel.org
Signed-off-by: Radim Krčmář <rkrcmar@ventanamicro.com>
Reviewed-by: Nutty Liu <liujingqi@lanxincomputing.com>
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Link: https://lore.kernel.org/r/20250805104418.196023-4-rkrcmar@ventanamicro.com
Signed-off-by: Anup Patel <anup@brainfault.org>
Signed-off-by: Wang Yechao <wang.yechao255@zte.com.cn>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026


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

参数解析结果
args value
repository RVCK-Project/rvck
head ref pull/264/head
base ref rvck-6.6
LAVA repo RVCK-Project/lavaci
LAVA hardware
LAVA Testcase path
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 skipped
lava-trigger-sg2042 skipped
lava-trigger-k1 skipped
lava-trigger-lpi4a skipped

Kunit Test Result

[08:43:55] Testing complete. Ran 457 tests: passed: 445, skipped: 12

Kernel Build Result

Check Patch Result

Total Errors 0
Total Warnings 0

@yechao-w
Copy link
Copy Markdown
Contributor Author

yechao-w commented May 7, 2026

5月rebase后审阅。

已rebase,请审阅

@sterling-teng
Copy link
Copy Markdown
Contributor

5月rebase后审阅。

已rebase,请审阅

系上游补丁backport,boot测试通过,先合了。

@sterling-teng sterling-teng merged commit 8f5af31 into RVCK-Project:rvck-6.6 May 12, 2026
11 checks passed
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.

4 participants