File tree Expand file tree Collapse file tree 3 files changed +36
-13
lines changed Expand file tree Collapse file tree 3 files changed +36
-13
lines changed Original file line number Diff line number Diff line change @@ -1701,11 +1701,35 @@ struct iommu_group *vfio_file_iommu_group(struct file *file)
1701
1701
}
1702
1702
EXPORT_SYMBOL_GPL (vfio_file_iommu_group );
1703
1703
1704
- long vfio_external_check_extension (struct vfio_group * group , unsigned long arg )
1704
+ /**
1705
+ * vfio_file_enforced_coherent - True if the DMA associated with the VFIO file
1706
+ * is always CPU cache coherent
1707
+ * @file: VFIO group file
1708
+ *
1709
+ * Enforced coherency means that the IOMMU ignores things like the PCIe no-snoop
1710
+ * bit in DMA transactions. A return of false indicates that the user has
1711
+ * rights to access additional instructions such as wbinvd on x86.
1712
+ */
1713
+ bool vfio_file_enforced_coherent (struct file * file )
1705
1714
{
1706
- return vfio_ioctl_check_extension (group -> container , arg );
1715
+ struct vfio_group * group = file -> private_data ;
1716
+ bool ret ;
1717
+
1718
+ if (file -> f_op != & vfio_group_fops )
1719
+ return true;
1720
+
1721
+ /*
1722
+ * Since the coherency state is determined only once a container is
1723
+ * attached the user must do so before they can prove they have
1724
+ * permission.
1725
+ */
1726
+ if (vfio_group_add_container_user (group ))
1727
+ return true;
1728
+ ret = vfio_ioctl_check_extension (group -> container , VFIO_DMA_CC_IOMMU );
1729
+ vfio_group_try_dissolve_container (group );
1730
+ return ret ;
1707
1731
}
1708
- EXPORT_SYMBOL_GPL (vfio_external_check_extension );
1732
+ EXPORT_SYMBOL_GPL (vfio_file_enforced_coherent );
1709
1733
1710
1734
/*
1711
1735
* Sub-module support
Original file line number Diff line number Diff line change @@ -139,8 +139,7 @@ int vfio_mig_get_next_state(struct vfio_device *device,
139
139
extern struct vfio_group * vfio_group_get_external_user (struct file * filep );
140
140
extern void vfio_group_put_external_user (struct vfio_group * group );
141
141
extern struct iommu_group * vfio_file_iommu_group (struct file * file );
142
- extern long vfio_external_check_extension (struct vfio_group * group ,
143
- unsigned long arg );
142
+ extern bool vfio_file_enforced_coherent (struct file * file );
144
143
145
144
#define VFIO_PIN_PAGES_MAX_ENTRIES (PAGE_SIZE/sizeof(unsigned long))
146
145
Original file line number Diff line number Diff line change @@ -75,20 +75,20 @@ static void kvm_vfio_group_set_kvm(struct vfio_group *group, struct kvm *kvm)
75
75
symbol_put (vfio_group_set_kvm );
76
76
}
77
77
78
- static bool kvm_vfio_group_is_coherent (struct vfio_group * vfio_group )
78
+ static bool kvm_vfio_file_enforced_coherent (struct file * file )
79
79
{
80
- long (* fn )(struct vfio_group * , unsigned long );
81
- long ret ;
80
+ bool (* fn )(struct file * file );
81
+ bool ret ;
82
82
83
- fn = symbol_get (vfio_external_check_extension );
83
+ fn = symbol_get (vfio_file_enforced_coherent );
84
84
if (!fn )
85
85
return false;
86
86
87
- ret = fn (vfio_group , VFIO_DMA_CC_IOMMU );
87
+ ret = fn (file );
88
88
89
- symbol_put (vfio_external_check_extension );
89
+ symbol_put (vfio_file_enforced_coherent );
90
90
91
- return ret > 0 ;
91
+ return ret ;
92
92
}
93
93
94
94
#ifdef CONFIG_SPAPR_TCE_IOMMU
@@ -136,7 +136,7 @@ static void kvm_vfio_update_coherency(struct kvm_device *dev)
136
136
mutex_lock (& kv -> lock );
137
137
138
138
list_for_each_entry (kvg , & kv -> group_list , node ) {
139
- if (!kvm_vfio_group_is_coherent (kvg -> vfio_group )) {
139
+ if (!kvm_vfio_file_enforced_coherent (kvg -> file )) {
140
140
noncoherent = true;
141
141
break ;
142
142
}
You can’t perform that action at this time.
0 commit comments