From: Oliver Upton <oliver.upton@linux.dev>
To: kvmarm@lists.linux.dev
Cc: kvm@vger.kernel.org, Paolo Bonzini <pbonzini@redhat.com>,
Marc Zyngier <maz@kernel.org>, James Morse <james.morse@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
Sean Christopherson <seanjc@google.com>,
Salil Mehta <salil.mehta@huawei.com>,
Oliver Upton <oliver.upton@linux.dev>
Subject: [PATCH v3 06/13] KVM: arm64: Refactor hvc filtering to support different actions
Date: Tue, 4 Apr 2023 15:40:43 +0000 [thread overview]
Message-ID: <20230404154050.2270077-7-oliver.upton@linux.dev> (raw)
In-Reply-To: <20230404154050.2270077-1-oliver.upton@linux.dev>
KVM presently allows userspace to filter guest hypercalls with bitmaps
expressed via pseudo-firmware registers. These bitmaps have a narrow
scope and, of course, can only allow/deny a particular call. A
subsequent change to KVM will introduce a generalized UAPI for filtering
hypercalls, allowing functions to be forwarded to userspace.
Refactor the existing hypercall filtering logic to make room for more
than two actions. While at it, generalize the function names around
SMCCC as it is the basis for the upcoming UAPI.
No functional change intended.
Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
---
arch/arm64/include/uapi/asm/kvm.h | 9 +++++++++
arch/arm64/kvm/hypercalls.c | 26 ++++++++++++++++++++++----
2 files changed, 31 insertions(+), 4 deletions(-)
diff --git a/arch/arm64/include/uapi/asm/kvm.h b/arch/arm64/include/uapi/asm/kvm.h
index f8129c624b07..f9672ef1159a 100644
--- a/arch/arm64/include/uapi/asm/kvm.h
+++ b/arch/arm64/include/uapi/asm/kvm.h
@@ -469,6 +469,15 @@ enum {
/* run->fail_entry.hardware_entry_failure_reason codes. */
#define KVM_EXIT_FAIL_ENTRY_CPU_UNSUPPORTED (1ULL << 0)
+enum kvm_smccc_filter_action {
+ KVM_SMCCC_FILTER_HANDLE = 0,
+ KVM_SMCCC_FILTER_DENY,
+
+#ifdef __KERNEL__
+ NR_SMCCC_FILTER_ACTIONS
+#endif
+};
+
#endif
#endif /* __ARM_KVM_H__ */
diff --git a/arch/arm64/kvm/hypercalls.c b/arch/arm64/kvm/hypercalls.c
index 5ead6c6afff0..0be974e2f1fc 100644
--- a/arch/arm64/kvm/hypercalls.c
+++ b/arch/arm64/kvm/hypercalls.c
@@ -65,7 +65,7 @@ static void kvm_ptp_get_time(struct kvm_vcpu *vcpu, u64 *val)
val[3] = lower_32_bits(cycles);
}
-static bool kvm_hvc_call_default_allowed(u32 func_id)
+static bool kvm_smccc_default_allowed(u32 func_id)
{
switch (func_id) {
/*
@@ -93,7 +93,7 @@ static bool kvm_hvc_call_default_allowed(u32 func_id)
}
}
-static bool kvm_hvc_call_allowed(struct kvm_vcpu *vcpu, u32 func_id)
+static bool kvm_smccc_test_fw_bmap(struct kvm_vcpu *vcpu, u32 func_id)
{
struct kvm_smccc_features *smccc_feat = &vcpu->kvm->arch.smccc_feat;
@@ -117,20 +117,38 @@ static bool kvm_hvc_call_allowed(struct kvm_vcpu *vcpu, u32 func_id)
return test_bit(KVM_REG_ARM_VENDOR_HYP_BIT_PTP,
&smccc_feat->vendor_hyp_bmap);
default:
- return kvm_hvc_call_default_allowed(func_id);
+ return false;
}
}
+static u8 kvm_smccc_get_action(struct kvm_vcpu *vcpu, u32 func_id)
+{
+ if (kvm_smccc_test_fw_bmap(vcpu, func_id) ||
+ kvm_smccc_default_allowed(func_id))
+ return KVM_SMCCC_FILTER_HANDLE;
+
+ return KVM_SMCCC_FILTER_DENY;
+}
+
int kvm_smccc_call_handler(struct kvm_vcpu *vcpu)
{
struct kvm_smccc_features *smccc_feat = &vcpu->kvm->arch.smccc_feat;
u32 func_id = smccc_get_function(vcpu);
u64 val[4] = {SMCCC_RET_NOT_SUPPORTED};
u32 feature;
+ u8 action;
gpa_t gpa;
- if (!kvm_hvc_call_allowed(vcpu, func_id))
+ action = kvm_smccc_get_action(vcpu, func_id);
+ switch (action) {
+ case KVM_SMCCC_FILTER_HANDLE:
+ break;
+ case KVM_SMCCC_FILTER_DENY:
+ goto out;
+ default:
+ WARN_RATELIMIT(1, "Unhandled SMCCC filter action: %d\n", action);
goto out;
+ }
switch (func_id) {
case ARM_SMCCC_VERSION_FUNC_ID:
--
2.40.0.348.gf938b09366-goog
next prev parent reply other threads:[~2023-04-04 15:41 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-04 15:40 [PATCH v3 00/13] KVM: arm64: Userspace SMCCC call filtering Oliver Upton
2023-04-04 15:40 ` [PATCH v3 01/13] KVM: x86: Redefine 'longmode' as a flag for KVM_EXIT_HYPERCALL Oliver Upton
2023-04-04 15:40 ` [PATCH v3 02/13] KVM: arm64: Add a helper to check if a VM has ran once Oliver Upton
2023-04-04 15:40 ` [PATCH v3 03/13] KVM: arm64: Add vm fd device attribute accessors Oliver Upton
2023-04-04 15:40 ` [PATCH v3 04/13] KVM: arm64: Rename SMC/HVC call handler to reflect reality Oliver Upton
2023-04-04 15:40 ` [PATCH v3 05/13] KVM: arm64: Start handling SMCs from EL1 Oliver Upton
2023-04-04 15:40 ` Oliver Upton [this message]
2023-04-04 15:40 ` [PATCH v3 07/13] KVM: arm64: Use a maple tree to represent the SMCCC filter Oliver Upton
2023-04-04 15:40 ` [PATCH v3 08/13] KVM: arm64: Add support for KVM_EXIT_HYPERCALL Oliver Upton
2023-04-05 7:35 ` Marc Zyngier
2023-04-05 11:59 ` Marc Zyngier
2023-04-05 15:30 ` Oliver Upton
2023-05-17 18:00 ` Salil Mehta
2023-05-17 18:38 ` Oliver Upton
2023-05-18 8:06 ` Marc Zyngier
2023-05-18 9:08 ` Salil Mehta
2023-05-18 9:42 ` Marc Zyngier
2023-05-18 12:16 ` Salil Mehta
2023-05-18 8:54 ` Salil Mehta
2023-04-04 15:40 ` [PATCH v3 09/13] KVM: arm64: Introduce support for userspace SMCCC filtering Oliver Upton
2023-04-04 15:40 ` [PATCH v3 10/13] KVM: arm64: Return NOT_SUPPORTED to guest for unknown PSCI version Oliver Upton
2023-04-04 15:40 ` [PATCH v3 11/13] KVM: arm64: Let errors from SMCCC emulation to reach userspace Oliver Upton
2023-04-04 15:40 ` [PATCH v3 12/13] KVM: selftests: Add a helper for SMCCC calls with SMC instruction Oliver Upton
2023-04-04 15:40 ` [PATCH v3 13/13] KVM: selftests: Add test for SMCCC filter Oliver Upton
2023-04-05 18:45 ` [PATCH v3 00/13] KVM: arm64: Userspace SMCCC call filtering Marc Zyngier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230404154050.2270077-7-oliver.upton@linux.dev \
--to=oliver.upton@linux.dev \
--cc=james.morse@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=maz@kernel.org \
--cc=pbonzini@redhat.com \
--cc=salil.mehta@huawei.com \
--cc=seanjc@google.com \
--cc=suzuki.poulose@arm.com \
--cc=yuzenghui@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.