Skip to content

Comments

[PW_SID:1053893] RISC-V: KVM: Validate SBI STA shmem alignment#1475

Closed
linux-riscv-bot wants to merge 4 commits intoworkflow__riscv__fixesfrom
pw1053893
Closed

[PW_SID:1053893] RISC-V: KVM: Validate SBI STA shmem alignment#1475
linux-riscv-bot wants to merge 4 commits intoworkflow__riscv__fixesfrom
pw1053893

Conversation

@linux-riscv-bot
Copy link

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

Linux RISC-V bot and others added 4 commits January 29, 2026 08:42
…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>
@linux-riscv-bot
Copy link
Author

Patch 1: "[v7,1/3] RISC-V: KVM: Validate SBI STA shmem alignment in kvm_sbi_ext_sta_set_reg()"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 113.74 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v7,1/3] RISC-V: KVM: Validate SBI STA shmem alignment in kvm_sbi_ext_sta_set_reg()"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 1140.59 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v7,1/3] RISC-V: KVM: Validate SBI STA shmem alignment in kvm_sbi_ext_sta_set_reg()"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 1451.81 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v7,1/3] RISC-V: KVM: Validate SBI STA shmem alignment in kvm_sbi_ext_sta_set_reg()"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 24.38 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v7,1/3] RISC-V: KVM: Validate SBI STA shmem alignment in kvm_sbi_ext_sta_set_reg()"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 25.95 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v7,1/3] RISC-V: KVM: Validate SBI STA shmem alignment in kvm_sbi_ext_sta_set_reg()"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 0.94 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v7,1/3] RISC-V: KVM: Validate SBI STA shmem alignment in kvm_sbi_ext_sta_set_reg()"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 81.39 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v7,1/3] RISC-V: KVM: Validate SBI STA shmem alignment in kvm_sbi_ext_sta_set_reg()"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.22 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v7,1/3] RISC-V: KVM: Validate SBI STA shmem alignment in kvm_sbi_ext_sta_set_reg()"
kdoc
Desc: Detects for kdoc errors
Duration: 0.87 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v7,1/3] RISC-V: KVM: Validate SBI STA shmem alignment in kvm_sbi_ext_sta_set_reg()"
module-param
Desc: Detect module_param changes
Duration: 0.24 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v7,1/3] RISC-V: KVM: Validate SBI STA shmem alignment in kvm_sbi_ext_sta_set_reg()"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.26 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v7,1/3] RISC-V: KVM: Validate SBI STA shmem alignment in kvm_sbi_ext_sta_set_reg()"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.30 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 2: "[v7,2/3] KVM: selftests: Refactor UAPI tests into dedicated function"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 113.46 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 2: "[v7,2/3] KVM: selftests: Refactor UAPI tests into dedicated function"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 1120.68 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 2: "[v7,2/3] KVM: selftests: Refactor UAPI tests into dedicated function"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 1416.31 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 2: "[v7,2/3] KVM: selftests: Refactor UAPI tests into dedicated function"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 24.73 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 2: "[v7,2/3] KVM: selftests: Refactor UAPI tests into dedicated function"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 26.03 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 2: "[v7,2/3] KVM: selftests: Refactor UAPI tests into dedicated function"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 0.99 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 2: "[v7,2/3] KVM: selftests: Refactor UAPI tests into dedicated function"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 80.99 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 2: "[v7,2/3] KVM: selftests: Refactor UAPI tests into dedicated function"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.22 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 2: "[v7,2/3] KVM: selftests: Refactor UAPI tests into dedicated function"
kdoc
Desc: Detects for kdoc errors
Duration: 0.97 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 2: "[v7,2/3] KVM: selftests: Refactor UAPI tests into dedicated function"
module-param
Desc: Detect module_param changes
Duration: 0.24 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 2: "[v7,2/3] KVM: selftests: Refactor UAPI tests into dedicated function"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.21 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 2: "[v7,2/3] KVM: selftests: Refactor UAPI tests into dedicated function"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.28 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 3: "[v7,3/3] RISC-V: KVM: selftests: Add RISC-V SBI STA shmem alignment tests"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 113.14 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 3: "[v7,3/3] RISC-V: KVM: selftests: Add RISC-V SBI STA shmem alignment tests"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 1123.14 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 3: "[v7,3/3] RISC-V: KVM: selftests: Add RISC-V SBI STA shmem alignment tests"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 1413.31 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 3: "[v7,3/3] RISC-V: KVM: selftests: Add RISC-V SBI STA shmem alignment tests"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 24.47 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 3: "[v7,3/3] RISC-V: KVM: selftests: Add RISC-V SBI STA shmem alignment tests"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 26.26 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 3: "[v7,3/3] RISC-V: KVM: selftests: Add RISC-V SBI STA shmem alignment tests"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 1.03 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 3: "[v7,3/3] RISC-V: KVM: selftests: Add RISC-V SBI STA shmem alignment tests"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 81.54 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 3: "[v7,3/3] RISC-V: KVM: selftests: Add RISC-V SBI STA shmem alignment tests"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.22 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 3: "[v7,3/3] RISC-V: KVM: selftests: Add RISC-V SBI STA shmem alignment tests"
kdoc
Desc: Detects for kdoc errors
Duration: 0.96 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 3: "[v7,3/3] RISC-V: KVM: selftests: Add RISC-V SBI STA shmem alignment tests"
module-param
Desc: Detect module_param changes
Duration: 0.24 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 3: "[v7,3/3] RISC-V: KVM: selftests: Add RISC-V SBI STA shmem alignment tests"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.21 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 3: "[v7,3/3] RISC-V: KVM: selftests: Add RISC-V SBI STA shmem alignment tests"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.29 seconds
Result: PASS

@linux-riscv-bot linux-riscv-bot deleted the pw1053893 branch February 21, 2026 01:18
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