[2/4] iommu/amd: Introduce structure amd_iommu_svm_ops.is_snp_guest()

Message ID 20230110143137.54517-3-suravee.suthikulpanit@amd.com
State New
Headers
Series iommu/amd: Force SNP-enabled VFIO domain to 4K page size |

Commit Message

Suravee Suthikulpanit Jan. 10, 2023, 2:31 p.m. UTC
  The structure can be used to provide call-back functions, which
are called by the AMD IOMMU driver when it needs to handle certain
operations.

SVM driver can define handler for each operation in the struct
amd_iommu_svm_ops and register the structure using the
amd_iommu_register_svm_ops() function.

Initially, it contains a function pointer is_snp_guest(), which
is used to check whether SNP is active for a KVM guest.

Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
---
 drivers/iommu/amd/iommu.c | 10 ++++++++++
 include/linux/amd-iommu.h |  6 ++++++
 2 files changed, 16 insertions(+)
  

Patch

diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index 681ab1fdb7d5..a03723930f70 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -754,6 +754,16 @@  static void iommu_poll_ppr_log(struct amd_iommu *iommu)
 	}
 }
 
+static const struct amd_iommu_svm_ops *amd_iommu_svm_ops;
+
+int amd_iommu_register_svm_ops(const struct amd_iommu_svm_ops *ops)
+{
+	amd_iommu_svm_ops = ops;
+
+	return 0;
+}
+EXPORT_SYMBOL(amd_iommu_register_svm_ops);
+
 #ifdef CONFIG_IRQ_REMAP
 static int (*iommu_ga_log_notifier)(u32);
 
diff --git a/include/linux/amd-iommu.h b/include/linux/amd-iommu.h
index 953e6f12fa1c..d4837af75550 100644
--- a/include/linux/amd-iommu.h
+++ b/include/linux/amd-iommu.h
@@ -11,6 +11,7 @@ 
 #include <linux/types.h>
 
 struct amd_iommu;
+struct kvm;
 
 /*
  * This is mainly used to communicate information back-and-forth
@@ -26,6 +27,10 @@  struct amd_iommu_pi_data {
 	void *ir_data;
 };
 
+struct amd_iommu_svm_ops {
+	bool (*is_snp_guest)(struct kvm *kvm);
+};
+
 #ifdef CONFIG_AMD_IOMMU
 
 struct task_struct;
@@ -205,6 +210,7 @@  int amd_iommu_pc_set_reg(struct amd_iommu *iommu, u8 bank, u8 cntr, u8 fxn,
 int amd_iommu_pc_get_reg(struct amd_iommu *iommu, u8 bank, u8 cntr, u8 fxn,
 		u64 *value);
 struct amd_iommu *get_amd_iommu(unsigned int idx);
+int amd_iommu_register_svm_ops(const struct amd_iommu_svm_ops *ops);
 
 #ifdef CONFIG_AMD_MEM_ENCRYPT
 int amd_iommu_snp_enable(void);