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
675config VFIO_CCW675config VFIO_CCW
676 def_tristate n676 def_tristate n
677 prompt "Support for VFIO-CCW subchannels"677 prompt "Support for VFIO-CCW subchannels"
678 depends on S390_CCW_IOMMU && VFIO678 depends on S390_CCW_IOMMU && VFIO_MDEV
679 help679 help
680 This driver allows usage of I/O subchannels via VFIO-CCW.680 This driver allows usage of I/O subchannels via VFIO-CCW.
681 681
drivers/s390/cio/Makefile+1−1
@@ -18,5 +18,5 @@ obj-$(CONFIG_CCWGROUP) += ccwgroup.o · 17 unmodified lines
18qdio-objs := qdio_main.o qdio_thinint.o qdio_debug.o qdio_setup.o18qdio-objs := qdio_main.o qdio_thinint.o qdio_debug.o qdio_setup.o
19obj-$(CONFIG_QDIO) += qdio.o19obj-$(CONFIG_QDIO) += qdio.o
20 20
21vfio_ccw-objs += vfio_ccw_drv.o vfio_ccw_cp.o21vfio_ccw-objs += vfio_ccw_drv.o vfio_ccw_cp.o vfio_ccw_ops.o
22obj-$(CONFIG_VFIO_CCW) += vfio_ccw.o22obj-$(CONFIG_VFIO_CCW) += vfio_ccw.o
drivers/s390/cio/vfio_ccw_drv.c+11−1
@@ -19,7 +19,7 @@ · 18 unmodified lines
19/*19/*
20 * Helpers20 * Helpers
21 */21 */
22static int vfio_ccw_sch_quiesce(struct subchannel *sch)22int vfio_ccw_sch_quiesce(struct subchannel *sch)
23{23{
24 struct vfio_ccw_private *private = dev_get_drvdata(&sch->dev);24 struct vfio_ccw_private *private = dev_get_drvdata(&sch->dev);
25 DECLARE_COMPLETION_ONSTACK(completion);25 DECLARE_COMPLETION_ONSTACK(completion);
@@ -152,8 +152,16 @@ static int vfio_ccw_sch_probe(struct subchannel *sch) · 126 unmodified lines
152 if (ret)152 if (ret)
153 goto out_disable;153 goto out_disable;
154 154
155 ret = vfio_ccw_mdev_reg(sch);
156 if (ret)
157 goto out_rm_group;
158
159 atomic_set(&private->avail, 1);
160
155 return 0;161 return 0;
156 162
163out_rm_group:
164 sysfs_remove_group(&sch->dev.kobj, &vfio_subchannel_attr_group);
157out_disable:165out_disable:
158 cio_disable_subchannel(sch);166 cio_disable_subchannel(sch);
159out_free:167out_free:
@@ -168,6 +176,8 @@ static int vfio_ccw_sch_remove(struct subchannel *sch) · 8 unmodified lines
168 176
169 vfio_ccw_sch_quiesce(sch);177 vfio_ccw_sch_quiesce(sch);
170 178
179 vfio_ccw_mdev_unreg(sch);
180
171 sysfs_remove_group(&sch->dev.kobj, &vfio_subchannel_attr_group);181 sysfs_remove_group(&sch->dev.kobj, &vfio_subchannel_attr_group);
172 182
173 dev_set_drvdata(&sch->dev, NULL);183 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
15static 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
36static ssize_t name_show(struct kobject *kobj, struct device *dev, char *buf)
37{
38 return sprintf(buf, "I/O subchannel (Non-QDIO)\n");
39}
40MDEV_TYPE_ATTR_RO(name);
41
42static 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}
47MDEV_TYPE_ATTR_RO(device_api);
48
49static 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}
56MDEV_TYPE_ATTR_RO(available_instances);
57
58static 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
65static struct attribute_group mdev_type_group = {
66 .name = "io",
67 .attrs = mdev_types_attrs,
68};
69
70struct attribute_group *mdev_type_groups[] = {
71 &mdev_type_group,
72 NULL,
73};
74
75static 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
88static 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
109static 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
121void 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
130static 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
139int vfio_ccw_mdev_reg(struct subchannel *sch)
140{
141 return mdev_register_device(&sch->dev, &vfio_ccw_mdev_ops);
142}
143
144void 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
16 * struct vfio_ccw_private16 * struct vfio_ccw_private
17 * @sch: pointer to the subchannel17 * @sch: pointer to the subchannel
18 * @completion: synchronization helper of the I/O completion18 * @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
19 */22 */
20struct vfio_ccw_private {23struct vfio_ccw_private {
21 struct subchannel *sch;24 struct subchannel *sch;
22 struct completion *completion;25 struct completion *completion;
26 atomic_t avail;
27 struct mdev_device *mdev;
28 struct notifier_block nb;
23} __aligned(8);29} __aligned(8);
24 30
31extern int vfio_ccw_mdev_reg(struct subchannel *sch);
32extern void vfio_ccw_mdev_unreg(struct subchannel *sch);
33
34extern int vfio_ccw_sch_quiesce(struct subchannel *sch);
35
25#endif36#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