From 09b0f24506cfbc7f4152746e93f99fa23746d7e1 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Brucker Date: Thu, 12 Dec 2024 18:03:47 +0000 Subject: [PATCH] BACKPORT: FROMLIST: KVM: arm64: iommu: Support power management Add power domain ops to the hypervisor IOMMU driver. We currently make these assumptions: * The register state is retained across power off. * The TLBs are clean on power on. * Another privileged software (EL3 or SCP FW) handles dependencies between SMMU and endpoints. So we just need to make sure that the CPU does not touch the SMMU registers while it is powered off. Link: https://lore.kernel.org/all/20241212180423.1578358-24-smostafa@google.com/ Bug: 357781595 Bug: 384432312 Change-Id: Iefe6f06b40510cbd5945cc8acf2bba7bd82a4564 Signed-off-by: Jean-Philippe Brucker Signed-off-by: Mostafa Saleh --- arch/arm64/kvm/hyp/nvhe/iommu/iommu.c | 33 ++++++++++++++++++++++++++- include/kvm/iommu.h | 3 +++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/nvhe/iommu/iommu.c b/arch/arm64/kvm/hyp/nvhe/iommu/iommu.c index a6e0f3634756..fbab335d3490 100644 --- a/arch/arm64/kvm/hyp/nvhe/iommu/iommu.c +++ b/arch/arm64/kvm/hyp/nvhe/iommu/iommu.c @@ -375,10 +375,41 @@ phys_addr_t kvm_iommu_iova_to_phys(pkvm_handle_t domain_id, unsigned long iova) return phys; } +static int iommu_power_on(struct kvm_power_domain *pd) +{ + struct kvm_hyp_iommu *iommu = container_of(pd, struct kvm_hyp_iommu, + power_domain); + + /* + * We currently assume that the device retains its architectural state + * across power off, hence no save/restore. + */ + kvm_iommu_lock(iommu); + iommu->power_is_off = false; + kvm_iommu_unlock(iommu); + return 0; +} + +static int iommu_power_off(struct kvm_power_domain *pd) +{ + struct kvm_hyp_iommu *iommu = container_of(pd, struct kvm_hyp_iommu, + power_domain); + + kvm_iommu_lock(iommu); + iommu->power_is_off = true; + kvm_iommu_unlock(iommu); + return 0; +} + +static const struct kvm_power_domain_ops iommu_power_ops = { + .power_on = iommu_power_on, + .power_off = iommu_power_off, +}; + /* Must be called from the IOMMU driver per IOMMU */ int kvm_iommu_init_device(struct kvm_hyp_iommu *iommu) { kvm_iommu_lock_init(iommu); - return 0; + return pkvm_init_power_domain(&iommu->power_domain, &iommu_power_ops); } diff --git a/include/kvm/iommu.h b/include/kvm/iommu.h index 6ff78d766466..c524ba84a9cf 100644 --- a/include/kvm/iommu.h +++ b/include/kvm/iommu.h @@ -3,6 +3,7 @@ #define __KVM_IOMMU_H #include +#include #include #ifdef __KVM_NVHE_HYPERVISOR__ #include @@ -51,6 +52,8 @@ struct kvm_hyp_iommu { #else u32 unused; #endif + struct kvm_power_domain power_domain; + bool power_is_off; }; #endif /* __KVM_IOMMU_H */