@@ -2008,59 +2008,44 @@ int vfio_unpin_pages(struct device *dev, unsigned long *user_pfn, int npage)
2008
2008
}
2009
2009
EXPORT_SYMBOL (vfio_unpin_pages );
2010
2010
2011
- int vfio_register_notifier (struct device * dev , struct notifier_block * nb )
2011
+ static int vfio_register_iommu_notifier (struct vfio_group * group ,
2012
+ unsigned long * events ,
2013
+ struct notifier_block * nb )
2012
2014
{
2013
2015
struct vfio_container * container ;
2014
- struct vfio_group * group ;
2015
2016
struct vfio_iommu_driver * driver ;
2016
2017
int ret ;
2017
2018
2018
- if (!dev || !nb )
2019
- return - EINVAL ;
2020
-
2021
- group = vfio_group_get_from_dev (dev );
2022
- if (!group )
2023
- return - ENODEV ;
2024
-
2025
2019
ret = vfio_group_add_container_user (group );
2026
2020
if (ret )
2027
- goto err_register_nb ;
2021
+ return - EINVAL ;
2028
2022
2029
2023
container = group -> container ;
2030
2024
down_read (& container -> group_lock );
2031
2025
2032
2026
driver = container -> iommu_driver ;
2033
2027
if (likely (driver && driver -> ops -> register_notifier ))
2034
- ret = driver -> ops -> register_notifier (container -> iommu_data , nb );
2028
+ ret = driver -> ops -> register_notifier (container -> iommu_data ,
2029
+ events , nb );
2035
2030
else
2036
2031
ret = - ENOTTY ;
2037
2032
2038
2033
up_read (& container -> group_lock );
2039
2034
vfio_group_try_dissolve_container (group );
2040
2035
2041
- err_register_nb :
2042
- vfio_group_put (group );
2043
2036
return ret ;
2044
2037
}
2045
- EXPORT_SYMBOL (vfio_register_notifier );
2046
2038
2047
- int vfio_unregister_notifier (struct device * dev , struct notifier_block * nb )
2039
+ static int vfio_unregister_iommu_notifier (struct vfio_group * group ,
2040
+ struct notifier_block * nb )
2048
2041
{
2049
2042
struct vfio_container * container ;
2050
- struct vfio_group * group ;
2051
2043
struct vfio_iommu_driver * driver ;
2052
2044
int ret ;
2053
2045
2054
- if (!dev || !nb )
2055
- return - EINVAL ;
2056
-
2057
- group = vfio_group_get_from_dev (dev );
2058
- if (!group )
2059
- return - ENODEV ;
2060
-
2061
2046
ret = vfio_group_add_container_user (group );
2062
2047
if (ret )
2063
- goto err_unregister_nb ;
2048
+ return - EINVAL ;
2064
2049
2065
2050
container = group -> container ;
2066
2051
down_read (& container -> group_lock );
@@ -2075,7 +2060,56 @@ int vfio_unregister_notifier(struct device *dev, struct notifier_block *nb)
2075
2060
up_read (& container -> group_lock );
2076
2061
vfio_group_try_dissolve_container (group );
2077
2062
2078
- err_unregister_nb :
2063
+ return ret ;
2064
+ }
2065
+
2066
+ int vfio_register_notifier (struct device * dev , enum vfio_notify_type type ,
2067
+ unsigned long * events , struct notifier_block * nb )
2068
+ {
2069
+ struct vfio_group * group ;
2070
+ int ret ;
2071
+
2072
+ if (!dev || !nb || !events || (* events == 0 ))
2073
+ return - EINVAL ;
2074
+
2075
+ group = vfio_group_get_from_dev (dev );
2076
+ if (!group )
2077
+ return - ENODEV ;
2078
+
2079
+ switch (type ) {
2080
+ case VFIO_IOMMU_NOTIFY :
2081
+ ret = vfio_register_iommu_notifier (group , events , nb );
2082
+ break ;
2083
+ default :
2084
+ ret = - EINVAL ;
2085
+ }
2086
+
2087
+ vfio_group_put (group );
2088
+ return ret ;
2089
+ }
2090
+ EXPORT_SYMBOL (vfio_register_notifier );
2091
+
2092
+ int vfio_unregister_notifier (struct device * dev , enum vfio_notify_type type ,
2093
+ struct notifier_block * nb )
2094
+ {
2095
+ struct vfio_group * group ;
2096
+ int ret ;
2097
+
2098
+ if (!dev || !nb )
2099
+ return - EINVAL ;
2100
+
2101
+ group = vfio_group_get_from_dev (dev );
2102
+ if (!group )
2103
+ return - ENODEV ;
2104
+
2105
+ switch (type ) {
2106
+ case VFIO_IOMMU_NOTIFY :
2107
+ ret = vfio_unregister_iommu_notifier (group , nb );
2108
+ break ;
2109
+ default :
2110
+ ret = - EINVAL ;
2111
+ }
2112
+
2079
2113
vfio_group_put (group );
2080
2114
return ret ;
2081
2115
}
0 commit comments