From: Marc Zyngier <maz@kernel.org>
To: kvmarm@lists.linux.dev, kvm@vger.kernel.org,
linux-arm-kernel@lists.infradead.org
Cc: Catalin Marinas <catalin.marinas@arm.com>,
Eric Auger <eric.auger@redhat.com>,
Mark Brown <broonie@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Will Deacon <will@kernel.org>,
Alexandru Elisei <alexandru.elisei@arm.com>,
Andre Przywara <andre.przywara@arm.com>,
Chase Conklin <chase.conklin@arm.com>,
Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com>,
Darren Hart <darren@os.amperecomputing.com>,
Miguel Luis <miguel.luis@oracle.com>,
Jing Zhang <jingzhangos@google.com>,
James Morse <james.morse@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Oliver Upton <oliver.upton@linux.dev>,
Zenghui Yu <yuzenghui@huawei.com>
Subject: [PATCH v4 19/28] KVM: arm64: nv: Add fine grained trap forwarding infrastructure
Date: Tue, 15 Aug 2023 19:38:53 +0100 [thread overview]
Message-ID: <20230815183903.2735724-20-maz@kernel.org> (raw)
In-Reply-To: <20230815183903.2735724-1-maz@kernel.org>
Fine Grained Traps are fun. Not.
Implement the fine grained trap forwarding, reusing the Coarse Grained
Traps infrastructure previously implemented.
Each sysreg/instruction inserted in the xarray gets a FGT group
(vaguely equivalent to a register number), a bit number in that register,
and a polarity.
It is then pretty easy to check the FGT state at handling time, just
like we do for the coarse version (it is just faster).
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
arch/arm64/kvm/emulate-nested.c | 90 +++++++++++++++++++++++++++++++--
1 file changed, 87 insertions(+), 3 deletions(-)
diff --git a/arch/arm64/kvm/emulate-nested.c b/arch/arm64/kvm/emulate-nested.c
index 860910386b5b..0da9d92ed921 100644
--- a/arch/arm64/kvm/emulate-nested.c
+++ b/arch/arm64/kvm/emulate-nested.c
@@ -423,16 +423,23 @@ static const complex_condition_check ccc[] = {
* following layout for each trapped sysreg:
*
* [9:0] enum cgt_group_id (10 bits)
- * [62:10] Unused (53 bits)
+ * [13:10] enum fgt_group_id (4 bits)
+ * [19:14] bit number in the FGT register (6 bits)
+ * [20] trap polarity (1 bit)
+ * [62:21] Unused (42 bits)
* [63] RES0 - Must be zero, as lost on insertion in the xarray
*/
#define TC_CGT_BITS 10
+#define TC_FGT_BITS 4
union trap_config {
u64 val;
struct {
unsigned long cgt:TC_CGT_BITS; /* Coarse Grained Trap id */
- unsigned long unused:53; /* Unused, should be zero */
+ unsigned long fgt:TC_FGT_BITS; /* Fine Grained Trap id */
+ unsigned long bit:6; /* Bit number */
+ unsigned long pol:1; /* Polarity */
+ unsigned long unused:42; /* Unused, should be zero */
unsigned long mbz:1; /* Must Be Zero */
};
};
@@ -929,6 +936,28 @@ static const struct encoding_to_trap_config encoding_to_cgt[] __initconst = {
static DEFINE_XARRAY(sr_forward_xa);
+enum fgt_group_id {
+ __NO_FGT_GROUP__,
+
+ /* Must be last */
+ __NR_FGT_GROUP_IDS__
+};
+
+#define SR_FGT(sr, g, b, p) \
+ { \
+ .encoding = sr, \
+ .end = sr, \
+ .tc = { \
+ .fgt = g ## _GROUP, \
+ .bit = g ## _EL2_ ## b ## _SHIFT, \
+ .pol = p, \
+ }, \
+ .line = __LINE__, \
+ }
+
+static const struct encoding_to_trap_config encoding_to_fgt[] __initconst = {
+};
+
static union trap_config get_trap_config(u32 sysreg)
{
return (union trap_config) {
@@ -957,6 +986,7 @@ int __init populate_nv_trap_config(void)
BUILD_BUG_ON(sizeof(union trap_config) != sizeof(void *));
BUILD_BUG_ON(__NR_CGT_GROUP_IDS__ > BIT(TC_CGT_BITS));
+ BUILD_BUG_ON(__NR_FGT_GROUP_IDS__ > BIT(TC_FGT_BITS));
for (int i = 0; i < ARRAY_SIZE(encoding_to_cgt); i++) {
const struct encoding_to_trap_config *cgt = &encoding_to_cgt[i];
@@ -990,6 +1020,34 @@ int __init populate_nv_trap_config(void)
kvm_info("nv: %ld coarse grained trap handlers\n",
ARRAY_SIZE(encoding_to_cgt));
+ if (!cpus_have_final_cap(ARM64_HAS_FGT))
+ goto check_mcb;
+
+ for (int i = 0; i < ARRAY_SIZE(encoding_to_fgt); i++) {
+ const struct encoding_to_trap_config *fgt = &encoding_to_fgt[i];
+ union trap_config tc;
+
+ if (fgt->tc.fgt >= __NR_FGT_GROUP_IDS__) {
+ ret = -EINVAL;
+ print_nv_trap_error(fgt, "Invalid FGT", ret);
+ }
+
+ tc = get_trap_config(fgt->encoding);
+
+ if (tc.fgt) {
+ ret = -EINVAL;
+ print_nv_trap_error(fgt, "Duplicate FGT", ret);
+ }
+
+ tc.val |= fgt->tc.val;
+ xa_store(&sr_forward_xa, fgt->encoding,
+ xa_mk_value(tc.val), GFP_KERNEL);
+ }
+
+ kvm_info("nv: %ld fine grained trap handlers\n",
+ ARRAY_SIZE(encoding_to_fgt));
+
+check_mcb:
for (int id = __MULTIPLE_CONTROL_BITS__; id < __COMPLEX_CONDITIONS__; id++) {
const enum cgt_group_id *cgids;
@@ -1056,13 +1114,26 @@ static enum trap_behaviour compute_trap_behaviour(struct kvm_vcpu *vcpu,
return __compute_trap_behaviour(vcpu, tc.cgt, b);
}
+static bool check_fgt_bit(u64 val, const union trap_config tc)
+{
+ return ((val >> tc.bit) & 1) == tc.pol;
+}
+
+#define sanitised_sys_reg(vcpu, reg) \
+ ({ \
+ u64 __val; \
+ __val = __vcpu_sys_reg(vcpu, reg); \
+ __val &= ~__ ## reg ## _RES0; \
+ (__val); \
+ })
+
bool __check_nv_sr_forward(struct kvm_vcpu *vcpu)
{
union trap_config tc;
enum trap_behaviour b;
bool is_read;
u32 sysreg;
- u64 esr;
+ u64 esr, val;
if (!vcpu_has_nv(vcpu) || is_hyp_ctxt(vcpu))
return false;
@@ -1085,6 +1156,19 @@ bool __check_nv_sr_forward(struct kvm_vcpu *vcpu)
if (!tc.val)
return false;
+ switch ((enum fgt_group_id)tc.fgt) {
+ case __NO_FGT_GROUP__:
+ break;
+
+ case __NR_FGT_GROUP_IDS__:
+ /* Something is really wrong, bail out */
+ WARN_ONCE(1, "__NR_FGT_GROUP_IDS__");
+ return false;
+ }
+
+ if (tc.fgt != __NO_FGT_GROUP__ && check_fgt_bit(val, tc))
+ goto inject;
+
b = compute_trap_behaviour(vcpu, tc);
if (((b & BEHAVE_FORWARD_READ) && is_read) ||
--
2.34.1
_______________________________________________
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-08-15 18:48 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-15 18:38 [PATCH v4 00/28] KVM: arm64: NV trap forwarding infrastructure Marc Zyngier
2023-08-15 18:38 ` [PATCH v4 01/28] arm64: Add missing VA CMO encodings Marc Zyngier
2023-08-15 18:38 ` [PATCH v4 02/28] arm64: Add missing ERX*_EL1 encodings Marc Zyngier
2023-08-15 18:38 ` [PATCH v4 03/28] arm64: Add missing DC ZVA/GVA/GZVA encodings Marc Zyngier
2023-08-15 18:38 ` [PATCH v4 04/28] arm64: Add TLBI operation encodings Marc Zyngier
2023-08-15 18:38 ` [PATCH v4 05/28] arm64: Add AT " Marc Zyngier
2023-08-15 18:38 ` [PATCH v4 06/28] arm64: Add debug registers affected by HDFGxTR_EL2 Marc Zyngier
2023-08-15 18:38 ` [PATCH v4 07/28] arm64: Add missing BRB/CFP/DVP/CPP instructions Marc Zyngier
2023-08-15 18:38 ` [PATCH v4 08/28] arm64: Add HDFGRTR_EL2 and HDFGWTR_EL2 layouts Marc Zyngier
2023-08-15 18:38 ` [PATCH v4 09/28] arm64: Add feature detection for fine grained traps Marc Zyngier
2023-08-15 18:38 ` [PATCH v4 10/28] KVM: arm64: Correctly handle ACCDATA_EL1 traps Marc Zyngier
2023-08-15 18:38 ` [PATCH v4 11/28] KVM: arm64: Add missing HCR_EL2 trap bits Marc Zyngier
2023-08-15 18:38 ` [PATCH v4 12/28] KVM: arm64: nv: Add FGT registers Marc Zyngier
2023-08-15 18:38 ` [PATCH v4 13/28] KVM: arm64: Restructure FGT register switching Marc Zyngier
2023-08-15 18:38 ` [PATCH v4 14/28] KVM: arm64: nv: Add trap forwarding infrastructure Marc Zyngier
2023-08-15 21:34 ` Jing Zhang
2023-08-16 9:34 ` Miguel Luis
2023-08-15 18:38 ` [PATCH v4 15/28] KVM: arm64: nv: Add trap forwarding for HCR_EL2 Marc Zyngier
2023-08-15 21:37 ` Jing Zhang
2023-08-17 11:05 ` Miguel Luis
2023-08-21 17:47 ` Marc Zyngier
2023-08-22 11:12 ` Miguel Luis
2023-08-15 18:38 ` [PATCH v4 16/28] KVM: arm64: nv: Expose FEAT_EVT to nested guests Marc Zyngier
2023-08-15 18:38 ` [PATCH v4 17/28] KVM: arm64: nv: Add trap forwarding for MDCR_EL2 Marc Zyngier
2023-08-15 22:33 ` Jing Zhang
2023-08-15 18:38 ` [PATCH v4 18/28] KVM: arm64: nv: Add trap forwarding for CNTHCTL_EL2 Marc Zyngier
2023-08-15 22:42 ` Jing Zhang
2023-08-15 18:38 ` Marc Zyngier [this message]
2023-08-15 22:44 ` [PATCH v4 19/28] KVM: arm64: nv: Add fine grained trap forwarding infrastructure Jing Zhang
2023-08-15 18:38 ` [PATCH v4 20/28] KVM: arm64: nv: Add trap forwarding for HFGxTR_EL2 Marc Zyngier
2023-08-15 22:51 ` Jing Zhang
2023-08-15 18:38 ` [PATCH v4 21/28] KVM: arm64: nv: Add trap forwarding for HFGITR_EL2 Marc Zyngier
2023-08-15 22:55 ` Jing Zhang
2023-08-15 18:38 ` [PATCH v4 22/28] KVM: arm64: nv: Add trap forwarding for HDFGxTR_EL2 Marc Zyngier
2023-08-15 23:10 ` Jing Zhang
2023-08-15 18:38 ` [PATCH v4 23/28] KVM: arm64: nv: Add SVC trap forwarding Marc Zyngier
2023-08-15 23:24 ` Jing Zhang
2023-08-15 18:38 ` [PATCH v4 24/28] KVM: arm64: nv: Expand ERET trap forwarding to handle FGT Marc Zyngier
2023-08-15 23:28 ` Jing Zhang
2023-08-15 18:38 ` [PATCH v4 25/28] KVM: arm64: nv: Add switching support for HFGxTR/HDFGxTR Marc Zyngier
2023-08-15 23:37 ` Jing Zhang
2023-08-15 18:39 ` [PATCH v4 26/28] KVM: arm64: nv: Expose FGT to nested guests Marc Zyngier
2023-08-16 0:02 ` Jing Zhang
2023-08-15 18:39 ` [PATCH v4 27/28] KVM: arm64: Move HCRX_EL2 switch to load/put on VHE systems Marc Zyngier
2023-08-16 0:17 ` Jing Zhang
2023-08-15 18:39 ` [PATCH v4 28/28] KVM: arm64: nv: Add support for HCRX_EL2 Marc Zyngier
2023-08-16 0:18 ` Jing Zhang
2023-08-17 9:29 ` [PATCH v4 00/28] KVM: arm64: NV trap forwarding infrastructure 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=20230815183903.2735724-20-maz@kernel.org \
--to=maz@kernel.org \
--cc=alexandru.elisei@arm.com \
--cc=andre.przywara@arm.com \
--cc=broonie@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=chase.conklin@arm.com \
--cc=darren@os.amperecomputing.com \
--cc=eric.auger@redhat.com \
--cc=gankulkarni@os.amperecomputing.com \
--cc=james.morse@arm.com \
--cc=jingzhangos@google.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=mark.rutland@arm.com \
--cc=miguel.luis@oracle.com \
--cc=oliver.upton@linux.dev \
--cc=suzuki.poulose@arm.com \
--cc=will@kernel.org \
--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).