Skip to content

Commit a26f2e4

Browse files
siwliu-kernelmstsirkin
authored andcommitted
vdpa: introduce .compat_reset operation callback
Some device specific IOMMU parent drivers have long standing bogus behaviour that mistakenly clean up the maps during .reset. By definition, this is violation to the on-chip IOMMU ops (i.e. .set_map, or .dma_map & .dma_unmap) in those offending drivers, as the removal of internal maps is completely agnostic to the upper layer, causing inconsistent view between the userspace and the kernel. Some userspace app like QEMU gets around of this brokenness by proactively removing and adding back all the maps around vdpa device reset, but such workaround actually penaltize other well-behaved driver setup, where vdpa reset always comes with the associated mapping cost, especially for kernel vDPA devices (use_va=false) that have high cost on pinning. It's imperative to rectify this behaviour and remove the problematic code from all those non-compliant parent drivers. However, we cannot unconditionally remove the bogus map-cleaning code from the buggy .reset implementation, as there might exist userspace apps that already rely on the behaviour on some setup. Introduce a .compat_reset driver op to keep compatibility with older userspace. New and well behaved parent driver should not bother to implement such op, but only those drivers that are doing or used to do non-compliant map-cleaning reset will have to. Signed-off-by: Si-Wei Liu <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Tested-by: Lei Yang <[email protected]>
1 parent 4398776 commit a26f2e4

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

include/linux/vdpa.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,17 @@ struct vdpa_map_file {
252252
* @reset: Reset device
253253
* @vdev: vdpa device
254254
* Returns integer: success (0) or error (< 0)
255+
* @compat_reset: Reset device with compatibility quirks to
256+
* accommodate older userspace. Only needed by
257+
* parent driver which used to have bogus reset
258+
* behaviour, and has to maintain such behaviour
259+
* for compatibility with older userspace.
260+
* Historically compliant driver only has to
261+
* implement .reset, Historically non-compliant
262+
* driver should implement both.
263+
* @vdev: vdpa device
264+
* @flags: compatibility quirks for reset
265+
* Returns integer: success (0) or error (< 0)
255266
* @suspend: Suspend the device (optional)
256267
* @vdev: vdpa device
257268
* Returns integer: success (0) or error (< 0)
@@ -393,6 +404,8 @@ struct vdpa_config_ops {
393404
u8 (*get_status)(struct vdpa_device *vdev);
394405
void (*set_status)(struct vdpa_device *vdev, u8 status);
395406
int (*reset)(struct vdpa_device *vdev);
407+
int (*compat_reset)(struct vdpa_device *vdev, u32 flags);
408+
#define VDPA_RESET_F_CLEAN_MAP 1
396409
int (*suspend)(struct vdpa_device *vdev);
397410
int (*resume)(struct vdpa_device *vdev);
398411
size_t (*get_config_size)(struct vdpa_device *vdev);

0 commit comments

Comments
 (0)