KVM: arm64: Reserve SMC64 arch range per SMCCC filter documentation
cover KVM: arm64: Reserve SMC64 arch range per SMCCC filter documentation
The intention of the SMCCC filter series was that the 'Arm architecture calls' range is reserved, meaning userspace cannot apply a filter to it. Though the documentation calls out both the SMC32 and presently unused SMC64 views, only the SMC32 view of this range was actually reserved.
Small series to align UAPI behavior with the documentation and adding a test case for the missed condition. Applies to kvmarm/next.
Oliver Upton (2):
KVM: arm64: Prevent userspace from handling SMC64 arch range
KVM: arm64: Test that SMC64 arch calls are reserved
arch/arm64/kvm/hypercalls.c | 25 ++++++++++++++----- .../selftests/kvm/aarch64/smccc_filter.c | 8 ++++++ 2 files changed, 27 insertions(+), 6 deletions(-)
base-commit: b87b85f845976e8d23e5f9fe7e399f6fc7360d26
Signature · 1 line
2.40.0.577.gac1e443424-goog
PATCH 1/2 KVM: arm64: Prevent userspace from handling SMC64 arch range
Though presently unused, there is an SMC64 view of the Arm architecture calls defined by the SMCCC. The documentation of the SMCCC filter states that the SMC64 range is reserved, but nothing actually prevents userspace from applying a filter to the range.
Insert a range with the HANDLE action for the SMC64 arch range, thereby preventing userspace from imposing filtering/forwarding on it.
--- arch/arm64/kvm/hypercalls.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
arch/arm64/kvm/hypercalls.c +19 -6
@@ -121,11 +121,17 @@ static bool kvm_smccc_test_fw_bmap(struct kvm_vcpu *vcpu, u32 func_id) } } -#define SMCCC_ARCH_RANGE_BEGIN ARM_SMCCC_VERSION_FUNC_ID -#define SMCCC_ARCH_RANGE_END \ - ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ - ARM_SMCCC_SMC_32, \ - 0, ARM_SMCCC_FUNC_MASK) +#define SMC32_ARCH_RANGE_BEGIN ARM_SMCCC_VERSION_FUNC_ID +#define SMC32_ARCH_RANGE_END ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_32, \ + 0, ARM_SMCCC_FUNC_MASK) + +#define SMC64_ARCH_RANGE_BEGIN ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_64, \ + 0, 0) +#define SMC64_ARCH_RANGE_END ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_64, \ + 0, ARM_SMCCC_FUNC_MASK)static void init_smccc_filter (struct kvm *kvm) {
@@ -139,10 +145,17 @@ static void init_smccc_filter(struct kvm *kvm)* to the guest. */ r =mtree_insert_range (&kvm->arch.smccc_filter, -SMCCC_ARCH_RANGE_BEGIN ,SMCCC_ARCH_RANGE_END , +SMC32_ARCH_RANGE_BEGIN ,SMC32_ARCH_RANGE_END ,xa_mk_value (KVM_SMCCC_FILTER_HANDLE ),GFP_KERNEL_ACCOUNT );WARN_ON_ONCE (r); + + r =mtree_insert_range (&kvm->arch.smccc_filter, +SMC64_ARCH_RANGE_BEGIN ,SMC64_ARCH_RANGE_END , +xa_mk_value (KVM_SMCCC_FILTER_HANDLE ), +GFP_KERNEL_ACCOUNT ); +WARN_ON_ONCE (r); + }static int kvm_smccc_set_filter (struct kvm *kvm,struct kvm_smccc_filter __user *uaddr)
Signature · 1 line
2.40.0.577.gac1e443424-goog
PATCH 2/2 KVM: arm64: Test that SMC64 arch calls are reserved
In reply to Oliver UptonAssert that the SMC64 view of the Arm architecture range is reserved by KVM and cannot be filtered by userspace.
--- tools/testing/selftests/kvm/aarch64/smccc_filter.c | 8 ++++++++ 1 file changed, 8 insertions(+)
tools/testing/selftests/kvm/aarch64/smccc_filter.c +8 -0
@@ -99,6 +99,7 @@ static void test_filter_reserved_range(void) {struct kvm_vcpu *vcpu;struct kvm_vm *vm =setup_vm (&vcpu); +uint32_t smc64_fn;int r; r = __set_smccc_filter(vm, ARM_SMCCC_ARCH_WORKAROUND_1,
@@ -106,6 +107,13 @@ static void test_filter_reserved_range(void)TEST_ASSERT (r <0 && errno ==EEXIST ,"Attempt to filter reserved range should return EEXIST" ); + smc64_fn =ARM_SMCCC_CALL_VAL (ARM_SMCCC_FAST_CALL ,ARM_SMCCC_SMC_64 , +0 ,0 ); + + r =__set_smccc_filter (vm, smc64_fn,1 ,KVM_SMCCC_FILTER_DENY ); +TEST_ASSERT (r <0 && errno ==EEXIST , +"Attempt to filter reserved range should return EEXIST" ); +kvm_vm_free (vm); }
Signature · 1 line
2.40.0.577.gac1e443424-goog
Quoted 9 lines · Oliver Upton
The intention of the SMCCC filter series was that the 'Arm architecture calls' range is reserved, meaning userspace cannot apply a filter to it. Though the documentation calls out both the SMC32 and presently unused SMC64 views, only the SMC32 view of this range was actually reserved.
Small series to align UAPI behavior with the documentation and adding a test case for the missed condition. Applies to kvmarm/next.
[...]
Applied to next, thanks!
[1/2] KVM: arm64: Prevent userspace from handling SMC64 arch range
commit: 5a23ad6510c82049f5ab3795841c30e8f3ca324d
[2/2] KVM: arm64: Test that SMC64 arch calls are reserved
commit: 00e0c947118f456b622c1f2ca316c116dfb4e12cCheers,
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.