On Mon, Oct 04, 2021 at 06:48:40PM +0100, Marc Zyngier wrote: > Plumb in the hypercall interface to allow a guest to discover, > enroll, map and unmap MMIO regions. > > Signed-off-by: Marc Zyngier <maz@xxxxxxxxxx> > --- > arch/arm64/kvm/hypercalls.c | 28 ++++++++++++++++++++++++++++ > include/linux/arm-smccc.h | 28 ++++++++++++++++++++++++++++ > 2 files changed, 56 insertions(+) > > diff --git a/arch/arm64/kvm/hypercalls.c b/arch/arm64/kvm/hypercalls.c > index 30da78f72b3b..c39aab55ecae 100644 > --- a/arch/arm64/kvm/hypercalls.c > +++ b/arch/arm64/kvm/hypercalls.c > @@ -5,6 +5,7 @@ > #include <linux/kvm_host.h> > > #include <asm/kvm_emulate.h> > +#include <asm/kvm_mmu.h> > > #include <kvm/arm_hypercalls.h> > #include <kvm/arm_psci.h> > @@ -129,10 +130,37 @@ int kvm_hvc_call_handler(struct kvm_vcpu *vcpu) > case ARM_SMCCC_VENDOR_HYP_KVM_FEATURES_FUNC_ID: > val[0] = BIT(ARM_SMCCC_KVM_FUNC_FEATURES); > val[0] |= BIT(ARM_SMCCC_KVM_FUNC_PTP); > + /* Only advertise MMIO guard to 64bit guests */ > + if (!vcpu_mode_is_32bit(vcpu)) { > + val[0] |= BIT(ARM_SMCCC_KVM_FUNC_MMIO_GUARD_INFO); > + val[0] |= BIT(ARM_SMCCC_KVM_FUNC_MMIO_GUARD_ENROLL); > + val[0] |= BIT(ARM_SMCCC_KVM_FUNC_MMIO_GUARD_MAP); > + val[0] |= BIT(ARM_SMCCC_KVM_FUNC_MMIO_GUARD_UNMAP); > + } > break; > case ARM_SMCCC_VENDOR_HYP_KVM_PTP_FUNC_ID: > kvm_ptp_get_time(vcpu, val); > break; > + case ARM_SMCCC_VENDOR_HYP_KVM_MMIO_GUARD_INFO_FUNC_ID: > + if (!vcpu_mode_is_32bit(vcpu)) > + val[0] = PAGE_SIZE; > + break; > + case ARM_SMCCC_VENDOR_HYP_KVM_MMIO_GUARD_ENROLL_FUNC_ID: > + if (!vcpu_mode_is_32bit(vcpu)) { > + set_bit(KVM_ARCH_FLAG_MMIO_GUARD, &vcpu->kvm->arch.flags); > + val[0] = SMCCC_RET_SUCCESS; > + } > + break; > + case ARM_SMCCC_VENDOR_HYP_KVM_MMIO_GUARD_MAP_FUNC_ID: > + if (!vcpu_mode_is_32bit(vcpu) && > + kvm_install_ioguard_page(vcpu, vcpu_get_reg(vcpu, 1))) > + val[0] = SMCCC_RET_SUCCESS; > + break; > + case ARM_SMCCC_VENDOR_HYP_KVM_MMIO_GUARD_UNMAP_FUNC_ID: > + if (!vcpu_mode_is_32bit(vcpu) && > + kvm_remove_ioguard_page(vcpu, vcpu_get_reg(vcpu, 1))) > + val[0] = SMCCC_RET_SUCCESS; > + break; Since these are all ARM_SMCCC_SMC_64 calls, can we do some sort of refactoring first, similar to Oliver's "KVM: arm64: Clean up SMC64 PSCI filtering for AArch32 guests", which would avoid the need for all the !vcpu_mode_is_32bit's? > case ARM_SMCCC_TRNG_VERSION: > case ARM_SMCCC_TRNG_FEATURES: > case ARM_SMCCC_TRNG_GET_UUID: > diff --git a/include/linux/arm-smccc.h b/include/linux/arm-smccc.h > index 7d1cabe15262..4aab2078d8d3 100644 > --- a/include/linux/arm-smccc.h > +++ b/include/linux/arm-smccc.h > @@ -107,6 +107,10 @@ > /* KVM "vendor specific" services */ > #define ARM_SMCCC_KVM_FUNC_FEATURES 0 > #define ARM_SMCCC_KVM_FUNC_PTP 1 > +#define ARM_SMCCC_KVM_FUNC_MMIO_GUARD_INFO 2 > +#define ARM_SMCCC_KVM_FUNC_MMIO_GUARD_ENROLL 3 > +#define ARM_SMCCC_KVM_FUNC_MMIO_GUARD_MAP 4 > +#define ARM_SMCCC_KVM_FUNC_MMIO_GUARD_UNMAP 5 > #define ARM_SMCCC_KVM_FUNC_FEATURES_2 127 > #define ARM_SMCCC_KVM_NUM_FUNCS 128 > > @@ -133,6 +137,30 @@ > #define KVM_PTP_VIRT_COUNTER 0 > #define KVM_PTP_PHYS_COUNTER 1 > > +#define ARM_SMCCC_VENDOR_HYP_KVM_MMIO_GUARD_INFO_FUNC_ID \ > + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ > + ARM_SMCCC_SMC_64, \ > + ARM_SMCCC_OWNER_VENDOR_HYP, \ > + ARM_SMCCC_KVM_FUNC_MMIO_GUARD_INFO) > + > +#define ARM_SMCCC_VENDOR_HYP_KVM_MMIO_GUARD_ENROLL_FUNC_ID \ > + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ > + ARM_SMCCC_SMC_64, \ > + ARM_SMCCC_OWNER_VENDOR_HYP, \ > + ARM_SMCCC_KVM_FUNC_MMIO_GUARD_ENROLL) > + > +#define ARM_SMCCC_VENDOR_HYP_KVM_MMIO_GUARD_MAP_FUNC_ID \ > + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ > + ARM_SMCCC_SMC_64, \ > + ARM_SMCCC_OWNER_VENDOR_HYP, \ > + ARM_SMCCC_KVM_FUNC_MMIO_GUARD_MAP) > + > +#define ARM_SMCCC_VENDOR_HYP_KVM_MMIO_GUARD_UNMAP_FUNC_ID \ > + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ > + ARM_SMCCC_SMC_64, \ > + ARM_SMCCC_OWNER_VENDOR_HYP, \ > + ARM_SMCCC_KVM_FUNC_MMIO_GUARD_UNMAP) > + > /* Paravirtualised time calls (defined by ARM DEN0057A) */ > #define ARM_SMCCC_HV_PV_TIME_FEATURES \ > ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ > -- > 2.30.2 > Besides the refactoring suggestion, Reviewed-by: Andrew Jones <drjones@xxxxxxxxxx> Thanks, drew