History

vfio: ccw: register vfio_ccw to the mediated device framework

To make vfio support subchannel devices, we need to leverage the mediated device framework to create a mediated device for the subchannel device. This registers the subchannel device to the mediated device framework during probe to enable mediated device creation.

Dong Jia Shi committed 9 years ago

Commit 84cd8fc1 parent 0a19e615 files · +171 −3Browse files

Unified · Split

5 files
  1. arch/s390/Kconfig +1 −1
  2. drivers/s390/cio/Makefile +1 −1
  3. drivers/s390/cio/vfio_ccw_drv.c +11 −1
  4. drivers/s390/cio/vfio_ccw_ops.c +147 −0
  5. drivers/s390/cio/vfio_ccw_private.h +11 −0
arch/s390/Kconfig+1−1
@@ -675,7 +675,7 @@ config EADM_SCH · 674 unmodified lines
675675 config VFIO_CCW
676676 def_tristate n
677677 prompt "Support for VFIO-CCW subchannels"
678− depends on S390_CCW_IOMMU && VFIO
678+ depends on S390_CCW_IOMMU && VFIO_MDEV
679679 help
680680 This driver allows usage of I/O subchannels via VFIO-CCW.
681681
drivers/s390/cio/Makefile+1−1
@@ -18,5 +18,5 @@ obj-$(CONFIG_CCWGROUP) += ccwgroup.o · 17 unmodified lines
1818 qdio-objs := qdio_main.o qdio_thinint.o qdio_debug.o qdio_setup.o
1919 obj-$(CONFIG_QDIO) += qdio.o
2020
21−vfio_ccw-objs += vfio_ccw_drv.o vfio_ccw_cp.o
21+vfio_ccw-objs += vfio_ccw_drv.o vfio_ccw_cp.o vfio_ccw_ops.o
2222 obj-$(CONFIG_VFIO_CCW) += vfio_ccw.o
drivers/s390/cio/vfio_ccw_drv.c+11−1
@@ -19,7 +19,7 @@ · 18 unmodified lines
1919 /*
2020 * Helpers
2121 */
22−static int vfio_ccw_sch_quiesce(struct subchannel *sch)
22+int vfio_ccw_sch_quiesce(struct subchannel *sch)
2323 {
2424 struct vfio_ccw_private *private = dev_get_drvdata(&sch->dev);
2525 DECLARE_COMPLETION_ONSTACK(completion);
@@ -152,8 +152,16 @@ static int vfio_ccw_sch_probe(struct subchannel *sch) · 126 unmodified lines
152152 if (ret)
153153 goto out_disable;
154154
155+ ret = vfio_ccw_mdev_reg(sch);
156+ if (ret)
157+ goto out_rm_group;
158+
159+ atomic_set(&private->avail, 1);
160+
155161 return 0;
156162
163+out_rm_group:
164+ sysfs_remove_group(&sch->dev.kobj, &vfio_subchannel_attr_group);
157165 out_disable:
158166 cio_disable_subchannel(sch);
159167 out_free:
@@ -168,6 +176,8 @@ static int vfio_ccw_sch_remove(struct subchannel *sch) · 8 unmodified lines
168176
169177 vfio_ccw_sch_quiesce(sch);
170178
179+ vfio_ccw_mdev_unreg(sch);
180+
171181 sysfs_remove_group(&sch->dev.kobj, &vfio_subchannel_attr_group);
172182
173183 dev_set_drvdata(&sch->dev, NULL);
drivers/s390/cio/vfio_ccw_ops.c+147−0
@@ -0,0 +1,147 @@
1+/*
2+ * Physical device callbacks for vfio_ccw
3+ *
4+ * Copyright IBM Corp. 2017
5+ *
6+ * Author(s): Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
7+ * Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
8+ */
9+
10+#include <linux/vfio.h>
11+#include <linux/mdev.h>
12+
13+#include "vfio_ccw_private.h"
14+
15+static int vfio_ccw_mdev_notifier(struct notifier_block *nb,
16+ unsigned long action,
17+ void *data)
18+{
19+ struct vfio_ccw_private *private =
20+ container_of(nb, struct vfio_ccw_private, nb);
21+
22+ if (!private)
23+ return NOTIFY_STOP;
24+
25+ /*
26+ * TODO:
27+ * Vendor drivers MUST unpin pages in response to an
28+ * invalidation.
29+ */
30+ if (action == VFIO_IOMMU_NOTIFY_DMA_UNMAP)
31+ return NOTIFY_BAD;
32+
33+ return NOTIFY_DONE;
34+}
35+
36+static ssize_t name_show(struct kobject *kobj, struct device *dev, char *buf)
37+{
38+ return sprintf(buf, "I/O subchannel (Non-QDIO)\n");
39+}
40+MDEV_TYPE_ATTR_RO(name);
41+
42+static ssize_t device_api_show(struct kobject *kobj, struct device *dev,
43+ char *buf)
44+{
45+ return sprintf(buf, "%s\n", VFIO_DEVICE_API_CCW_STRING);
46+}
47+MDEV_TYPE_ATTR_RO(device_api);
48+
49+static ssize_t available_instances_show(struct kobject *kobj,
50+ struct device *dev, char *buf)
51+{
52+ struct vfio_ccw_private *private = dev_get_drvdata(dev);
53+
54+ return sprintf(buf, "%d\n", atomic_read(&private->avail));
55+}
56+MDEV_TYPE_ATTR_RO(available_instances);
57+
58+static struct attribute *mdev_types_attrs[] = {
59+ &mdev_type_attr_name.attr,
60+ &mdev_type_attr_device_api.attr,
61+ &mdev_type_attr_available_instances.attr,
62+ NULL,
63+};
64+
65+static struct attribute_group mdev_type_group = {
66+ .name = "io",
67+ .attrs = mdev_types_attrs,
68+};
69+
70+struct attribute_group *mdev_type_groups[] = {
71+ &mdev_type_group,
72+ NULL,
73+};
74+
75+static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device *mdev)
76+{
77+ struct vfio_ccw_private *private =
78+ dev_get_drvdata(mdev_parent_dev(mdev));
79+
80+ if (atomic_dec_if_positive(&private->avail) < 0)
81+ return -EPERM;
82+
83+ private->mdev = mdev;
84+
85+ return 0;
86+}
87+
88+static int vfio_ccw_mdev_remove(struct mdev_device *mdev)
89+{
90+ struct vfio_ccw_private *private;
91+ struct subchannel *sch;
92+ int ret;
93+
94+ private = dev_get_drvdata(mdev_parent_dev(mdev));
95+ sch = private->sch;
96+ ret = vfio_ccw_sch_quiesce(sch);
97+ if (ret)
98+ return ret;
99+ ret = cio_enable_subchannel(sch, (u32)(unsigned long)sch);
100+ if (ret)
101+ return ret;
102+
103+ private->mdev = NULL;
104+ atomic_inc(&private->avail);
105+
106+ return 0;
107+}
108+
109+static int vfio_ccw_mdev_open(struct mdev_device *mdev)
110+{
111+ struct vfio_ccw_private *private =
112+ dev_get_drvdata(mdev_parent_dev(mdev));
113+ unsigned long events = VFIO_IOMMU_NOTIFY_DMA_UNMAP;
114+
115+ private->nb.notifier_call = vfio_ccw_mdev_notifier;
116+
117+ return vfio_register_notifier(mdev_dev(mdev), VFIO_IOMMU_NOTIFY,
118+ &events, &private->nb);
119+}
120+
121+void vfio_ccw_mdev_release(struct mdev_device *mdev)
122+{
123+ struct vfio_ccw_private *private =
124+ dev_get_drvdata(mdev_parent_dev(mdev));
125+
126+ vfio_unregister_notifier(mdev_dev(mdev), VFIO_IOMMU_NOTIFY,
127+ &private->nb);
128+}
129+
130+static const struct mdev_parent_ops vfio_ccw_mdev_ops = {
131+ .owner = THIS_MODULE,
132+ .supported_type_groups = mdev_type_groups,
133+ .create = vfio_ccw_mdev_create,
134+ .remove = vfio_ccw_mdev_remove,
135+ .open = vfio_ccw_mdev_open,
136+ .release = vfio_ccw_mdev_release,
137+};
138+
139+int vfio_ccw_mdev_reg(struct subchannel *sch)
140+{
141+ return mdev_register_device(&sch->dev, &vfio_ccw_mdev_ops);
142+}
143+
144+void vfio_ccw_mdev_unreg(struct subchannel *sch)
145+{
146+ mdev_unregister_device(&sch->dev);
147+}
drivers/s390/cio/vfio_ccw_private.h+11−0
@@ -16,10 +16,21 @@ · 15 unmodified lines
1616 * struct vfio_ccw_private
1717 * @sch: pointer to the subchannel
1818 * @completion: synchronization helper of the I/O completion
19+ * @avail: available for creating a mediated device
20+ * @mdev: pointer to the mediated device
21+ * @nb: notifier for vfio events
1922 */
2023 struct vfio_ccw_private {
2124 struct subchannel *sch;
2225 struct completion *completion;
26+ atomic_t avail;
27+ struct mdev_device *mdev;
28+ struct notifier_block nb;
2329 } __aligned(8);
2430
31+extern int vfio_ccw_mdev_reg(struct subchannel *sch);
32+extern void vfio_ccw_mdev_unreg(struct subchannel *sch);
33+
34+extern int vfio_ccw_sch_quiesce(struct subchannel *sch);
35+
2536 #endif

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t