Commit 0286300
iommu: iommu_group_claim_dma_owner() must always assign a domain
Once the group enters 'owned' mode it can never be assigned back to the
default_domain or to a NULL domain. It must always be actively assigned to
a current domain. If the caller hasn't provided a domain then the core
must provide an explicit DMA blocking domain that has no DMA map.
Lazily create a group-global blocking DMA domain when
iommu_group_claim_dma_owner is first called and immediately assign the
group to it. This ensures that DMA is immediately fully isolated on all
IOMMU drivers.
If the user attaches/detaches while owned then detach will set the group
back to the blocking domain.
Slightly reorganize the call chains so that
__iommu_group_set_core_domain() is the function that removes any caller
configured domain and sets the domains back a core owned domain with an
appropriate lifetime.
__iommu_group_set_domain() is the worker function that can change the
domain assigned to a group to any target domain, including NULL.
Add comments clarifying how the NULL vs detach_dev vs default_domain works
based on Robin's remarks.
This fixes an oops with VFIO and SMMUv3 because VFIO will call
iommu_detach_group() and then immediately iommu_domain_free(), but
SMMUv3 has no way to know that the domain it is holding a pointer to
has been freed. Now the iommu_detach_group() will assign the blocking
domain and SMMUv3 will no longer hold a stale domain reference.
Fixes: 1ea2a07 ("iommu: Add DMA ownership management interfaces")
Reported-by: Qian Cai <quic_qiancai@quicinc.com>
Tested-by: Baolu Lu <baolu.lu@linux.intel.com>
Tested-by: Nicolin Chen <nicolinc@nvidia.com>
Co-developed-by: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
--
Just minor polishing as discussed
v3:
- Change names to __iommu_group_set_domain() /
__iommu_group_set_core_domain()
- Clarify comments
- Call __iommu_group_set_domain() directly in
iommu_group_release_dma_owner() since we know it is always selecting
the default_domain
- Remove redundant detach_dev ops check in __iommu_detach_device and
make the added WARN_ON fail instead
- Check for blocking_domain in __iommu_attach_group() so VFIO can
actually attach a new group
- Update comments and spelling
- Fix missed change to new_domain in iommu_group_do_detach_device()
v2: https://lore.kernel.org/r/0-v2-f62259511ac0+6-iommu_dma_block_jgg@nvidia.com
v1: https://lore.kernel.org/r/0-v1-6e9d2d0a759d+11b-iommu_dma_block_jgg@nvidia.com
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Link: https://lore.kernel.org/r/0-v3-db7f0785022b+149-iommu_dma_block_jgg@nvidia.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>1 parent a5f1bd1 commit 0286300
1 file changed
Lines changed: 91 additions & 36 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
| |||
82 | 83 | | |
83 | 84 | | |
84 | 85 | | |
85 | | - | |
86 | | - | |
| 86 | + | |
| 87 | + | |
87 | 88 | | |
88 | 89 | | |
89 | 90 | | |
| |||
596 | 597 | | |
597 | 598 | | |
598 | 599 | | |
| 600 | + | |
| 601 | + | |
599 | 602 | | |
600 | 603 | | |
601 | 604 | | |
| |||
1907 | 1910 | | |
1908 | 1911 | | |
1909 | 1912 | | |
| 1913 | + | |
| 1914 | + | |
| 1915 | + | |
| 1916 | + | |
| 1917 | + | |
| 1918 | + | |
| 1919 | + | |
| 1920 | + | |
| 1921 | + | |
| 1922 | + | |
| 1923 | + | |
| 1924 | + | |
| 1925 | + | |
| 1926 | + | |
| 1927 | + | |
| 1928 | + | |
| 1929 | + | |
| 1930 | + | |
1910 | 1931 | | |
1911 | 1932 | | |
1912 | 1933 | | |
| |||
1963 | 1984 | | |
1964 | 1985 | | |
1965 | 1986 | | |
1966 | | - | |
1967 | | - | |
1968 | | - | |
1969 | 1987 | | |
1970 | 1988 | | |
1971 | 1989 | | |
| |||
1979 | 1997 | | |
1980 | 1998 | | |
1981 | 1999 | | |
1982 | | - | |
1983 | | - | |
| 2000 | + | |
| 2001 | + | |
1984 | 2002 | | |
1985 | | - | |
1986 | | - | |
1987 | | - | |
| 2003 | + | |
1988 | 2004 | | |
1989 | 2005 | | |
1990 | 2006 | | |
| |||
2040 | 2056 | | |
2041 | 2057 | | |
2042 | 2058 | | |
2043 | | - | |
| 2059 | + | |
| 2060 | + | |
2044 | 2061 | | |
2045 | 2062 | | |
2046 | 2063 | | |
| |||
2072 | 2089 | | |
2073 | 2090 | | |
2074 | 2091 | | |
2075 | | - | |
2076 | | - | |
| 2092 | + | |
| 2093 | + | |
2077 | 2094 | | |
2078 | 2095 | | |
2079 | 2096 | | |
| 2097 | + | |
| 2098 | + | |
| 2099 | + | |
2080 | 2100 | | |
2081 | | - | |
2082 | | - | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
2083 | 2104 | | |
2084 | | - | |
2085 | | - | |
| 2105 | + | |
| 2106 | + | |
| 2107 | + | |
| 2108 | + | |
2086 | 2109 | | |
2087 | 2110 | | |
2088 | | - | |
| 2111 | + | |
2089 | 2112 | | |
2090 | 2113 | | |
2091 | | - | |
2092 | | - | |
2093 | | - | |
2094 | | - | |
2095 | | - | |
| 2114 | + | |
| 2115 | + | |
| 2116 | + | |
| 2117 | + | |
| 2118 | + | |
| 2119 | + | |
| 2120 | + | |
| 2121 | + | |
| 2122 | + | |
| 2123 | + | |
2096 | 2124 | | |
2097 | | - | |
2098 | | - | |
2099 | | - | |
2100 | | - | |
| 2125 | + | |
| 2126 | + | |
| 2127 | + | |
| 2128 | + | |
2101 | 2129 | | |
2102 | 2130 | | |
2103 | 2131 | | |
2104 | 2132 | | |
2105 | 2133 | | |
2106 | | - | |
| 2134 | + | |
2107 | 2135 | | |
2108 | 2136 | | |
2109 | 2137 | | |
| |||
3088 | 3116 | | |
3089 | 3117 | | |
3090 | 3118 | | |
| 3119 | + | |
| 3120 | + | |
| 3121 | + | |
| 3122 | + | |
| 3123 | + | |
| 3124 | + | |
| 3125 | + | |
| 3126 | + | |
| 3127 | + | |
| 3128 | + | |
| 3129 | + | |
| 3130 | + | |
| 3131 | + | |
| 3132 | + | |
| 3133 | + | |
| 3134 | + | |
| 3135 | + | |
| 3136 | + | |
| 3137 | + | |
| 3138 | + | |
| 3139 | + | |
| 3140 | + | |
| 3141 | + | |
3091 | 3142 | | |
3092 | 3143 | | |
3093 | 3144 | | |
| |||
3111 | 3162 | | |
3112 | 3163 | | |
3113 | 3164 | | |
| 3165 | + | |
| 3166 | + | |
| 3167 | + | |
| 3168 | + | |
| 3169 | + | |
| 3170 | + | |
| 3171 | + | |
3114 | 3172 | | |
3115 | | - | |
3116 | | - | |
3117 | 3173 | | |
3118 | 3174 | | |
3119 | 3175 | | |
| |||
3132 | 3188 | | |
3133 | 3189 | | |
3134 | 3190 | | |
| 3191 | + | |
| 3192 | + | |
3135 | 3193 | | |
3136 | 3194 | | |
3137 | 3195 | | |
3138 | 3196 | | |
3139 | 3197 | | |
3140 | | - | |
3141 | | - | |
3142 | | - | |
3143 | | - | |
3144 | | - | |
3145 | | - | |
3146 | 3198 | | |
| 3199 | + | |
| 3200 | + | |
| 3201 | + | |
3147 | 3202 | | |
3148 | 3203 | | |
3149 | 3204 | | |
| |||
0 commit comments