]> git.baikalelectronics.ru Git - kernel.git/commitdiff
KVM: s390: pci: add basic kvm_zdev structure
authorMatthew Rosato <mjrosato@linux.ibm.com>
Mon, 6 Jun 2022 20:33:15 +0000 (16:33 -0400)
committerChristian Borntraeger <borntraeger@linux.ibm.com>
Mon, 11 Jul 2022 07:54:27 +0000 (09:54 +0200)
This structure will be used to carry kvm passthrough information related to
zPCI devices.

Reviewed-by: Niklas Schnelle <schnelle@linux.ibm.com>
Reviewed-by: Pierre Morel <pmorel@linux.ibm.com>
Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com>
Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
Link: https://lore.kernel.org/r/20220606203325.110625-12-mjrosato@linux.ibm.com
Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
arch/s390/include/asm/pci.h
arch/s390/kvm/Makefile
arch/s390/kvm/pci.c [new file with mode: 0644]
arch/s390/kvm/pci.h [new file with mode: 0644]

index 4c5b8fbc207921e938b8be6ef5d56af3f30e3953..50f1851edfbe1a0df46268138f2c493ed5949885 100644 (file)
@@ -97,6 +97,7 @@ struct zpci_bar_struct {
 };
 
 struct s390_domain;
+struct kvm_zdev;
 
 #define ZPCI_FUNCTIONS_PER_BUS 256
 struct zpci_bus {
@@ -189,7 +190,9 @@ struct zpci_dev {
 
        struct dentry   *debugfs_dev;
 
+       /* IOMMU and passthrough */
        struct s390_domain *s390_domain; /* s390 IOMMU domain data */
+       struct kvm_zdev *kzdev;
 };
 
 static inline bool zdev_enabled(struct zpci_dev *zdev)
index 26f4a74e5ce487caf28ffcce095c9a75ef98a01d..02217fb4ae10feef27696a293c5f27a07173e86d 100644 (file)
@@ -10,4 +10,5 @@ ccflags-y := -Ivirt/kvm -Iarch/s390/kvm
 kvm-y += kvm-s390.o intercept.o interrupt.o priv.o sigp.o
 kvm-y += diag.o gaccess.o guestdbg.o vsie.o pv.o
 
+kvm-$(CONFIG_VFIO_PCI_ZDEV_KVM) += pci.o
 obj-$(CONFIG_KVM) += kvm.o
diff --git a/arch/s390/kvm/pci.c b/arch/s390/kvm/pci.c
new file mode 100644 (file)
index 0000000..e27191e
--- /dev/null
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * s390 kvm PCI passthrough support
+ *
+ * Copyright IBM Corp. 2022
+ *
+ *    Author(s): Matthew Rosato <mjrosato@linux.ibm.com>
+ */
+
+#include <linux/kvm_host.h>
+#include <linux/pci.h>
+#include "pci.h"
+
+static int kvm_s390_pci_dev_open(struct zpci_dev *zdev)
+{
+       struct kvm_zdev *kzdev;
+
+       kzdev = kzalloc(sizeof(struct kvm_zdev), GFP_KERNEL);
+       if (!kzdev)
+               return -ENOMEM;
+
+       kzdev->zdev = zdev;
+       zdev->kzdev = kzdev;
+
+       return 0;
+}
+
+static void kvm_s390_pci_dev_release(struct zpci_dev *zdev)
+{
+       struct kvm_zdev *kzdev;
+
+       kzdev = zdev->kzdev;
+       WARN_ON(kzdev->zdev != zdev);
+       zdev->kzdev = NULL;
+       kfree(kzdev);
+}
diff --git a/arch/s390/kvm/pci.h b/arch/s390/kvm/pci.h
new file mode 100644 (file)
index 0000000..ce93978
--- /dev/null
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * s390 kvm PCI passthrough support
+ *
+ * Copyright IBM Corp. 2022
+ *
+ *    Author(s): Matthew Rosato <mjrosato@linux.ibm.com>
+ */
+
+#ifndef __KVM_S390_PCI_H
+#define __KVM_S390_PCI_H
+
+#include <linux/kvm_host.h>
+#include <linux/pci.h>
+
+struct kvm_zdev {
+       struct zpci_dev *zdev;
+       struct kvm *kvm;
+};
+
+#endif /* __KVM_S390_PCI_H */