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 <jean-philippe@linaro.org>
Signed-off-by: Mostafa Saleh <smostafa@google.com>
This commit is contained in:
Jean-Philippe Brucker
2024-12-12 18:03:47 +00:00
committed by Mostafa Saleh
parent 220be80770
commit 09b0f24506
2 changed files with 35 additions and 1 deletions
+32 -1
View File
@@ -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);
}
+3
View File
@@ -3,6 +3,7 @@
#define __KVM_IOMMU_H
#include <asm/kvm_host.h>
#include <kvm/power_domain.h>
#include <linux/io-pgtable.h>
#ifdef __KVM_NVHE_HYPERVISOR__
#include <nvhe/spinlock.h>
@@ -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 */