From: Oliver Upton <oliver.upton@linux.dev>
To: Marc Zyngier <maz@kernel.org>
Cc: James Morse <james.morse@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
kvmarm@lists.linux.dev, Akihiko Odaki <akihiko.odaki@daynix.com>,
Zenghui Yu <yuzenghui@huawei.com>,
Raghavendra Rao Ananta <rananta@google.com>,
linux-arm-kernel@lists.infradead.org,
Salil Mehta <salil.mehta@huawei.com>,
Oliver Upton <oliver.upton@linux.dev>
Subject: [RFC PATCH v2 3/6] KVM: arm64: Refactor hvc filtering to support different actions
Date: Sat, 11 Feb 2023 01:37:56 +0000 [thread overview]
Message-ID: <20230211013759.3556016-4-oliver.upton@linux.dev> (raw)
In-Reply-To: <20230211013759.3556016-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.
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
---
arch/arm64/include/uapi/asm/kvm.h | 9 +++++++++
arch/arm64/kvm/hypercalls.c | 19 +++++++++++++++----
2 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/arch/arm64/include/uapi/asm/kvm.h b/arch/arm64/include/uapi/asm/kvm.h
index a7a857f1784d..e298574a45ea 100644
--- a/arch/arm64/include/uapi/asm/kvm.h
+++ b/arch/arm64/include/uapi/asm/kvm.h
@@ -468,6 +468,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_ALLOW = 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 c9f401fa01a9..980546b295b3 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_call(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,19 +117,30 @@ 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_hvc_get_action(struct kvm_vcpu *vcpu, u32 func_id)
+{
+ if (kvm_smccc_default_call(func_id) ||
+ kvm_smccc_test_fw_bmap(vcpu, func_id))
+ return KVM_SMCCC_FILTER_ALLOW;
+
+ return KVM_SMCCC_FILTER_DENY;
+}
+
int kvm_hvc_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_hvc_get_action(vcpu, func_id);
+ if (action == KVM_SMCCC_FILTER_DENY)
goto out;
switch (func_id) {
--
2.39.1.581.gbfd45094c4-goog
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2023-02-11 1:40 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-11 1:37 [RFC PATCH v2 0/6] KVM: arm64: Userspace SMCCC call filtering Oliver Upton
2023-02-11 1:37 ` [RFC PATCH v2 1/6] KVM: arm64: Add a helper to check if a VM has ran once Oliver Upton
2023-02-13 15:36 ` Sean Christopherson
2023-02-13 15:49 ` Marc Zyngier
2023-02-11 1:37 ` [RFC PATCH v2 2/6] KVM: arm64: Add vm fd device attribute accessors Oliver Upton
2023-02-11 1:37 ` Oliver Upton [this message]
2023-02-11 1:37 ` [RFC PATCH v2 4/6] KVM: arm64: Use a maple tree to represent the SMCCC filter Oliver Upton
2023-02-11 1:37 ` [RFC PATCH v2 5/6] KVM: arm64: Add support for KVM_EXIT_HYPERCALL Oliver Upton
2023-02-13 16:01 ` Sean Christopherson
2023-02-13 19:24 ` Oliver Upton
2023-02-24 15:12 ` James Morse
2023-02-24 21:42 ` Oliver Upton
2023-02-11 1:37 ` [RFC PATCH v2 6/6] KVM: arm64: Indroduce support for userspace SMCCC filtering Oliver Upton
2023-02-17 18:35 ` Oliver Upton
2023-02-24 15:12 ` [RFC PATCH v2 0/6] KVM: arm64: Userspace SMCCC call filtering James Morse
2023-02-24 21:32 ` Oliver Upton
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=20230211013759.3556016-4-oliver.upton@linux.dev \
--to=oliver.upton@linux.dev \
--cc=akihiko.odaki@daynix.com \
--cc=james.morse@arm.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=maz@kernel.org \
--cc=rananta@google.com \
--cc=salil.mehta@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).