1717#include <linux/list.h>
1818#include <linux/spinlock.h>
1919#include <linux/pci.h>
20+ #include <linux/iommufd.h>
2021#include <linux/irqreturn.h>
2122#include <linux/generic_pt/iommu.h>
2223
24+ #include <uapi/linux/iommufd.h>
25+
2326/*
2427 * Maximum number of IOMMUs supported
2528 */
108111
109112/* Extended Feature 2 Bits */
110113#define FEATURE_SEVSNPIO_SUP BIT_ULL(1)
114+ #define FEATURE_GCR3TRPMODE BIT_ULL(3)
111115#define FEATURE_SNPAVICSUP GENMASK_ULL(7, 5)
112116#define FEATURE_SNPAVICSUP_GAM (x ) \
113117 (FIELD_GET(FEATURE_SNPAVICSUP, x) == 0x1)
186190#define CONTROL_EPH_EN 45
187191#define CONTROL_XT_EN 50
188192#define CONTROL_INTCAPXT_EN 51
193+ #define CONTROL_GCR3TRPMODE 58
189194#define CONTROL_IRTCACHEDIS 59
190195#define CONTROL_SNPAVIC_EN 61
191196
350355#define DTE_FLAG_V BIT_ULL(0)
351356#define DTE_FLAG_TV BIT_ULL(1)
352357#define DTE_FLAG_HAD (3ULL << 7)
358+ #define DTE_MODE_MASK GENMASK_ULL(11, 9)
359+ #define DTE_HOST_TRP GENMASK_ULL(51, 12)
360+ #define DTE_FLAG_PPR BIT_ULL(52)
353361#define DTE_FLAG_GIOV BIT_ULL(54)
354362#define DTE_FLAG_GV BIT_ULL(55)
355363#define DTE_GLX GENMASK_ULL(57, 56)
358366
359367#define DTE_FLAG_IOTLB BIT_ULL(32)
360368#define DTE_FLAG_MASK (0x3ffULL << 32)
361- #define DEV_DOMID_MASK 0xffffULL
369+ #define DTE_DOMID_MASK GENMASK_ULL(15, 0)
362370
363371#define DTE_GCR3_14_12 GENMASK_ULL(60, 58)
364372#define DTE_GCR3_30_15 GENMASK_ULL(31, 16)
@@ -493,6 +501,38 @@ struct pdom_iommu_info {
493501 u32 refcnt ; /* Count of attached dev/pasid per domain/IOMMU */
494502};
495503
504+ struct amd_iommu_viommu {
505+ struct iommufd_viommu core ;
506+ struct protection_domain * parent ; /* nest parent domain for this viommu */
507+ struct list_head pdom_list ; /* For protection_domain->viommu_list */
508+
509+ /*
510+ * Per-vIOMMU guest domain ID to host domain ID mapping.
511+ * Indexed by guest domain ID.
512+ */
513+ struct xarray gdomid_array ;
514+ };
515+
516+ /*
517+ * Contains guest domain ID mapping info,
518+ * which is stored in the struct xarray gdomid_array.
519+ */
520+ struct guest_domain_mapping_info {
521+ refcount_t users ;
522+ u32 hdom_id ; /* Host domain ID */
523+ };
524+
525+ /*
526+ * Nested domain is specifically used for nested translation
527+ */
528+ struct nested_domain {
529+ struct iommu_domain domain ; /* generic domain handle used by iommu core code */
530+ u16 gdom_id ; /* domain ID from gDTE */
531+ struct guest_domain_mapping_info * gdom_info ;
532+ struct iommu_hwpt_amd_guest gdte ; /* Guest vIOMMU DTE */
533+ struct amd_iommu_viommu * viommu ; /* AMD hw-viommu this nested domain belong to */
534+ };
535+
496536/*
497537 * This structure contains generic data for IOMMU protection domains
498538 * independent of their use.
@@ -513,6 +553,12 @@ struct protection_domain {
513553
514554 struct mmu_notifier mn ; /* mmu notifier for the SVA domain */
515555 struct list_head dev_data_list ; /* List of pdom_dev_data */
556+
557+ /*
558+ * Store reference to list of vIOMMUs, which use this protection domain.
559+ * This will be used to look up host domain ID when flushing this domain.
560+ */
561+ struct list_head viommu_list ;
516562};
517563PT_IOMMU_CHECK_DOMAIN (struct protection_domain , iommu , domain );
518564PT_IOMMU_CHECK_DOMAIN (struct protection_domain , amdv1 .iommu , domain );
@@ -706,7 +752,7 @@ struct amd_iommu {
706752
707753 u32 flags ;
708754 volatile u64 * cmd_sem ;
709- atomic64_t cmd_sem_val ;
755+ u64 cmd_sem_val ;
710756 /*
711757 * Track physical address to directly use it in build_completion_wait()
712758 * and avoid adding any special checks and handling for kdump.
0 commit comments