@@ -31,6 +31,7 @@ struct kvm_zdev {
struct zpci_dev *zdev;
struct kvm *kvm;
u64 rpcit_count;
+ u64 iota;
struct kvm_zdev_ioat ioat;
struct zpci_fib fib;
struct notifier_block nb;
@@ -1176,6 +1176,8 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd,
return vfio_pci_zdev_feat_interp(vdev, feature, arg);
case VFIO_DEVICE_FEATURE_ZPCI_AIF:
return vfio_pci_zdev_feat_aif(vdev, feature, arg);
+ case VFIO_DEVICE_FEATURE_ZPCI_IOAT:
+ return vfio_pci_zdev_feat_ioat(vdev, feature, arg);
default:
return -ENOTTY;
}
@@ -292,6 +292,63 @@ int vfio_pci_zdev_feat_aif(struct vfio_pci_core_device *vdev,
return rc;
}
+int vfio_pci_zdev_feat_ioat(struct vfio_pci_core_device *vdev,
+ struct vfio_device_feature feature,
+ unsigned long arg)
+{
+ struct zpci_dev *zdev = to_zpci(vdev->pdev);
+ struct vfio_device_zpci_ioat *data;
+ struct vfio_device_feature *feat;
+ unsigned long minsz;
+ int size, rc = 0;
+
+ if (!zdev || !zdev->kzdev)
+ return -EINVAL;
+
+ /* If PROBE specified, return probe results immediately */
+ if (feature.flags & VFIO_DEVICE_FEATURE_PROBE)
+ return kvm_s390_pci_ioat_probe(zdev);
+
+ size = sizeof(*feat) + sizeof(*data);
+ feat = kzalloc(size, GFP_KERNEL);
+ if (!feat)
+ return -ENOMEM;
+
+ data = (struct vfio_device_zpci_ioat *)&feat->data;
+ minsz = offsetofend(struct vfio_device_feature, flags);
+
+ if (feature.argsz < minsz + sizeof(*data))
+ return -EINVAL;
+
+ /* Get the rest of the payload for GET/SET */
+ rc = copy_from_user(data, (void __user *)(arg + minsz),
+ sizeof(*data));
+ if (rc)
+ rc = -EINVAL;
+
+ if (feature.flags & VFIO_DEVICE_FEATURE_GET) {
+ data->iota = (u64)zdev->kzdev->iota;
+ if (copy_to_user((void __user *)arg, feat, size))
+ rc = -EFAULT;
+ } else if (feature.flags & VFIO_DEVICE_FEATURE_SET) {
+ if (data->iota != 0) {
+ rc = kvm_s390_pci_ioat_enable(zdev, data->iota);
+ if (!rc)
+ zdev->kzdev->iota = data->iota;
+ } else if (zdev->kzdev->iota != 0) {
+ rc = kvm_s390_pci_ioat_disable(zdev);
+ if (!rc)
+ zdev->kzdev->iota = 0;
+ }
+ } else {
+ /* Neither GET nor SET were specified */
+ rc = -EINVAL;
+ }
+
+ kfree(feat);
+ return rc;
+}
+
static int vfio_pci_zdev_group_notifier(struct notifier_block *nb,
unsigned long action, void *data)
{
@@ -341,6 +398,7 @@ void vfio_pci_zdev_release(struct vfio_pci_core_device *vdev)
*/
if (zdev->gisa != 0) {
kvm_s390_pci_aif_disable(zdev, true);
+ kvm_s390_pci_ioat_disable(zdev);
kvm_s390_pci_interp_disable(zdev, true);
}
@@ -204,6 +204,9 @@ int vfio_pci_zdev_feat_interp(struct vfio_pci_core_device *vdev,
int vfio_pci_zdev_feat_aif(struct vfio_pci_core_device *vdev,
struct vfio_device_feature feature,
unsigned long arg);
+int vfio_pci_zdev_feat_ioat(struct vfio_pci_core_device *vdev,
+ struct vfio_device_feature feature,
+ unsigned long arg);
void vfio_pci_zdev_open(struct vfio_pci_core_device *vdev);
void vfio_pci_zdev_release(struct vfio_pci_core_device *vdev);
#else
@@ -227,6 +230,13 @@ static inline int vfio_pci_zdev_feat_aif(struct vfio_pci_core_device *vdev,
return -ENOTTY;
}
+static inline int vfio_pci_zdev_feat_ioat(struct vfio_pci_core_device *vdev,
+ struct vfio_device_feature feature,
+ unsigned long arg)
+{
+ return -ENOTTY;
+}
+
static inline void vfio_pci_zdev_open(struct vfio_pci_core_device *vdev)
{
}
@@ -1016,6 +1016,14 @@ struct vfio_device_feature {
*/
#define VFIO_DEVICE_FEATURE_ZPCI_AIF (2)
+/*
+ * Provide support for enabling guest I/O address translation assistance for
+ * zPCI devices. This feature is only valid for s390x PCI devices. Data
+ * provided when setting and getting this feature is further described in
+ * vfio_zdev.h
+ */
+#define VFIO_DEVICE_FEATURE_ZPCI_IOAT (3)
+
/* -------- API for Type1 VFIO IOMMU -------- */
/**
@@ -110,4 +110,17 @@ struct vfio_device_zpci_aif {
__u8 sbo; /* Offset of guest summary bit vector */
};
+/**
+ * VFIO_DEVICE_FEATURE_ZPCI_IOAT
+ *
+ * This feature is used for enabling guest I/O translation assistance for
+ * passthrough zPCI devices using instruction interpretation. When setting
+ * this feature, the iota specifies a KVM guest I/O translation anchor. When
+ * getting this feature, the most recently set anchor (or 0) is returned in
+ * iota.
+ */
+struct vfio_device_zpci_ioat {
+ __u64 iota;
+};
+
#endif