If KVM has enabled LPA2 support then check that the RMM also supports it. If there is a mismatch then disable support for realm guests as the VMM may attempt to create a guest which is incompatible with the RMM. Signed-off-by: Steven Price --- New patch for v13 --- arch/arm64/kvm/rmi.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/arch/arm64/kvm/rmi.c b/arch/arm64/kvm/rmi.c index 482dc542451a..9590dff9a2c1 100644 --- a/arch/arm64/kvm/rmi.c +++ b/arch/arm64/kvm/rmi.c @@ -5,12 +5,18 @@ #include +#include #include #include static unsigned long rmm_feat_reg0; static unsigned long rmm_feat_reg1; +static bool rmi_has_feature(unsigned long feature) +{ + return !!u64_get_bits(rmm_feat_reg0, feature); +} + static int rmi_check_version(void) { struct arm_smccc_res res; @@ -89,6 +95,16 @@ static int rmi_configure(void) return 0; } +static int rmm_check_features(void) +{ + if (kvm_lpa2_is_enabled() && !rmi_has_feature(RMI_FEATURE_REGISTER_0_LPA2)) { + kvm_err("RMM doesn't support LPA2"); + return -ENXIO; + } + + return 0; +} + void kvm_init_rmi(void) { /* Continue without realm support if we can't agree on a version */ @@ -100,6 +116,8 @@ void kvm_init_rmi(void) if (WARN_ON(rmi_features(1, &rmm_feat_reg1))) return; + if (rmm_check_features()) + return; if (rmi_configure()) return; -- 2.43.0