[PW_SID:1053893] RISC-V: KVM: Validate SBI STA shmem alignment#1475
[PW_SID:1053893] RISC-V: KVM: Validate SBI STA shmem alignment#1475linux-riscv-bot wants to merge 4 commits intoworkflow__riscv__fixesfrom
Conversation
…reg() The RISC-V SBI Steal-Time Accounting (STA) extension requires the shared memory physical address to be 64-byte aligned, or set to all-ones to explicitly disable steal-time accounting. KVM exposes the SBI STA shared memory configuration to userspace via KVM_SET_ONE_REG. However, the current implementation of kvm_sbi_ext_sta_set_reg() does not validate the alignment of the configured shared memory address. As a result, userspace can install a misaligned shared memory address that violates the SBI specification. Such an invalid configuration may later reach runtime code paths that assume a valid and properly aligned shared memory region. In particular, KVM_RUN can trigger the following WARN_ON in kvm_riscv_vcpu_record_steal_time(): WARNING: arch/riscv/kvm/vcpu_sbi_sta.c:49 at kvm_riscv_vcpu_record_steal_time WARN_ON paths are not expected to be reachable during normal runtime execution, and may result in a kernel panic when panic_on_warn is enabled. Fix this by validating the computed shared memory GPA at the KVM_SET_ONE_REG boundary. A temporary GPA is constructed and checked before committing it to vcpu->arch.sta.shmem. The validation allows either a 64-byte aligned GPA or INVALID_GPA (all-ones), which disables STA as defined by the SBI specification. This prevents invalid userspace state from reaching runtime code paths that assume SBI STA invariants and avoids unexpected WARN_ON behavior. Fixes: f61ce89 ("RISC-V: KVM: Add support for SBI STA registers") Signed-off-by: Jiakai Xu <xujiakai2025@iscas.ac.cn> Signed-off-by: Jiakai Xu <jiakaiPeanut@gmail.com> Reviewed-by: Andrew Jones <andrew.jones@oss.qualcomm.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Move steal time UAPI tests from steal_time_init() into a separate
check_steal_time_uapi() function for better code organization and
maintainability.
Previously, x86 and ARM64 architectures performed UAPI validation
tests within steal_time_init(), mixing initialization logic with
uapi tests.
Changes by architecture:
x86_64:
- Extract MSR reserved bits test from steal_time_init()
- Move to check_steal_time_uapi() which tests that setting
MSR_KVM_STEAL_TIME with KVM_STEAL_RESERVED_MASK fails
ARM64:
- Extract three UAPI tests from steal_time_init():
Device attribute support check
Misaligned IPA rejection (EINVAL)
Duplicate IPA setting rejection (EEXIST)
- Move all tests to check_steal_time_uapi()
RISC-V:
- Add empty check_steal_time_uapi() stub for future use
- No changes to steal_time_init() (had no tests to extract)
The new check_steal_time_uapi() function:
- Is called once before the per-VCPU test loop
No functional change intended.
Signed-off-by: Jiakai Xu <xujiakai2025@iscas.ac.cn>
Signed-off-by: Jiakai Xu <jiakaiPeanut@gmail.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Add RISC-V KVM selftests to verify the SBI Steal-Time Accounting (STA) shared memory alignment requirements. The SBI specification requires the STA shared memory GPA to be 64-byte aligned, or set to all-ones to explicitly disable steal-time accounting. This test verifies that KVM enforces the expected behavior when configuring the SBI STA shared memory via KVM_SET_ONE_REG. Specifically, the test checks that: - misaligned GPAs are rejected with -EINVAL - 64-byte aligned GPAs are accepted - all-ones GPA is accepted Signed-off-by: Jiakai Xu <xujiakai2025@iscas.ac.cn> Signed-off-by: Jiakai Xu <jiakaiPeanut@gmail.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
|
Patch 1: "[v7,1/3] RISC-V: KVM: Validate SBI STA shmem alignment in kvm_sbi_ext_sta_set_reg()" |
|
Patch 1: "[v7,1/3] RISC-V: KVM: Validate SBI STA shmem alignment in kvm_sbi_ext_sta_set_reg()" |
|
Patch 1: "[v7,1/3] RISC-V: KVM: Validate SBI STA shmem alignment in kvm_sbi_ext_sta_set_reg()" |
|
Patch 1: "[v7,1/3] RISC-V: KVM: Validate SBI STA shmem alignment in kvm_sbi_ext_sta_set_reg()" |
|
Patch 1: "[v7,1/3] RISC-V: KVM: Validate SBI STA shmem alignment in kvm_sbi_ext_sta_set_reg()" |
|
Patch 1: "[v7,1/3] RISC-V: KVM: Validate SBI STA shmem alignment in kvm_sbi_ext_sta_set_reg()" |
|
Patch 1: "[v7,1/3] RISC-V: KVM: Validate SBI STA shmem alignment in kvm_sbi_ext_sta_set_reg()" |
|
Patch 1: "[v7,1/3] RISC-V: KVM: Validate SBI STA shmem alignment in kvm_sbi_ext_sta_set_reg()" |
|
Patch 1: "[v7,1/3] RISC-V: KVM: Validate SBI STA shmem alignment in kvm_sbi_ext_sta_set_reg()" |
|
Patch 1: "[v7,1/3] RISC-V: KVM: Validate SBI STA shmem alignment in kvm_sbi_ext_sta_set_reg()" |
|
Patch 1: "[v7,1/3] RISC-V: KVM: Validate SBI STA shmem alignment in kvm_sbi_ext_sta_set_reg()" |
|
Patch 1: "[v7,1/3] RISC-V: KVM: Validate SBI STA shmem alignment in kvm_sbi_ext_sta_set_reg()" |
|
Patch 2: "[v7,2/3] KVM: selftests: Refactor UAPI tests into dedicated function" |
|
Patch 2: "[v7,2/3] KVM: selftests: Refactor UAPI tests into dedicated function" |
|
Patch 2: "[v7,2/3] KVM: selftests: Refactor UAPI tests into dedicated function" |
|
Patch 2: "[v7,2/3] KVM: selftests: Refactor UAPI tests into dedicated function" |
|
Patch 2: "[v7,2/3] KVM: selftests: Refactor UAPI tests into dedicated function" |
|
Patch 2: "[v7,2/3] KVM: selftests: Refactor UAPI tests into dedicated function" |
|
Patch 2: "[v7,2/3] KVM: selftests: Refactor UAPI tests into dedicated function" |
|
Patch 2: "[v7,2/3] KVM: selftests: Refactor UAPI tests into dedicated function" |
|
Patch 2: "[v7,2/3] KVM: selftests: Refactor UAPI tests into dedicated function" |
|
Patch 2: "[v7,2/3] KVM: selftests: Refactor UAPI tests into dedicated function" |
|
Patch 2: "[v7,2/3] KVM: selftests: Refactor UAPI tests into dedicated function" |
|
Patch 2: "[v7,2/3] KVM: selftests: Refactor UAPI tests into dedicated function" |
|
Patch 3: "[v7,3/3] RISC-V: KVM: selftests: Add RISC-V SBI STA shmem alignment tests" |
|
Patch 3: "[v7,3/3] RISC-V: KVM: selftests: Add RISC-V SBI STA shmem alignment tests" |
|
Patch 3: "[v7,3/3] RISC-V: KVM: selftests: Add RISC-V SBI STA shmem alignment tests" |
|
Patch 3: "[v7,3/3] RISC-V: KVM: selftests: Add RISC-V SBI STA shmem alignment tests" |
|
Patch 3: "[v7,3/3] RISC-V: KVM: selftests: Add RISC-V SBI STA shmem alignment tests" |
|
Patch 3: "[v7,3/3] RISC-V: KVM: selftests: Add RISC-V SBI STA shmem alignment tests" |
|
Patch 3: "[v7,3/3] RISC-V: KVM: selftests: Add RISC-V SBI STA shmem alignment tests" |
|
Patch 3: "[v7,3/3] RISC-V: KVM: selftests: Add RISC-V SBI STA shmem alignment tests" |
|
Patch 3: "[v7,3/3] RISC-V: KVM: selftests: Add RISC-V SBI STA shmem alignment tests" |
|
Patch 3: "[v7,3/3] RISC-V: KVM: selftests: Add RISC-V SBI STA shmem alignment tests" |
|
Patch 3: "[v7,3/3] RISC-V: KVM: selftests: Add RISC-V SBI STA shmem alignment tests" |
|
Patch 3: "[v7,3/3] RISC-V: KVM: selftests: Add RISC-V SBI STA shmem alignment tests" |
42f6459 to
e3d6c9b
Compare
PR for series 1053893 applied to workflow__riscv__fixes
Name: RISC-V: KVM: Validate SBI STA shmem alignment
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=1053893
Version: 7