drm/i915/kvmgt: Sanitize PCI bar emulation
[linux-block.git] / drivers / gpu / drm / i915 / gvt / kvmgt.c
index fd0c85f9ef3c369390abe200f8511f184c5c257a..9201db0892f1ee7d3a799cbad1ff000c47de327c 100644 (file)
@@ -661,7 +661,6 @@ static ssize_t intel_vgpu_rw(struct mdev_device *mdev, char *buf,
                                                buf, count);
                break;
        case VFIO_PCI_BAR0_REGION_INDEX:
-       case VFIO_PCI_BAR1_REGION_INDEX:
                if (is_write) {
                        uint64_t bar0_start = intel_vgpu_get_bar0_addr(vgpu);
 
@@ -674,6 +673,7 @@ static ssize_t intel_vgpu_rw(struct mdev_device *mdev, char *buf,
                                                bar0_start + pos, buf, count);
                }
                break;
+       case VFIO_PCI_BAR1_REGION_INDEX:
        case VFIO_PCI_BAR2_REGION_INDEX:
        case VFIO_PCI_BAR3_REGION_INDEX:
        case VFIO_PCI_BAR4_REGION_INDEX:
@@ -1170,10 +1170,27 @@ vgpu_id_show(struct device *dev, struct device_attribute *attr,
        return sprintf(buf, "\n");
 }
 
+static ssize_t
+hw_id_show(struct device *dev, struct device_attribute *attr,
+          char *buf)
+{
+       struct mdev_device *mdev = mdev_from_dev(dev);
+
+       if (mdev) {
+               struct intel_vgpu *vgpu = (struct intel_vgpu *)
+                       mdev_get_drvdata(mdev);
+               return sprintf(buf, "%u\n",
+                              vgpu->shadow_ctx->hw_id);
+       }
+       return sprintf(buf, "\n");
+}
+
 static DEVICE_ATTR_RO(vgpu_id);
+static DEVICE_ATTR_RO(hw_id);
 
 static struct attribute *intel_vgpu_attrs[] = {
        &dev_attr_vgpu_id.attr,
+       &dev_attr_hw_id.attr,
        NULL
 };