kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* RFC: (re-)binding the VFIO platform driver to a platform device
@ 2013-10-01 18:38 Kim Phillips
  2013-10-01 19:15 ` Scott Wood
  2013-10-01 20:00 ` Greg Kroah-Hartman
  0 siblings, 2 replies; 66+ messages in thread
From: Kim Phillips @ 2013-10-01 18:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Greg Kroah-Hartman, a.motakis, Alexander Graf, Alex Williamson,
	stuart.yoder, Wood Scott-B07421, Sethi Varun-B16395,
	Bhushan Bharat-R65777, Peter Maydell, Christoffer Dall,
	santosh.shukla, kvm

Hi,

Santosh and I are having a problem figuring out how to enable binding
(and re-binding) platform devices to a platform VFIO driver (see
Antonis' WIP: [1]) in an upstream-acceptable manner.

Binding platform drivers currently depends on a string match in the
device node's compatible entry.  On an arndale, one can currently
rebind the same device to the same driver like so:

echo 12ce0000.i2c > /sys/bus/platform/drivers/s3c-i2c/12ce0000.i2c/driver/unbind
echo 12ce0000.i2c > /sys/bus/platform/drivers/s3c-i2c/bind

And one can bind it to the vfio-dt driver, as Antonis instructs, by
appending a 'vfio-dt' string to the device tree compatible entry for
the device.  Then this would work:

echo 12ce0000.i2c > /sys/bus/platform/drivers/s3c-i2c/12ce0000.i2c/driver/unbind
echo 12ce0000.i2c > /sys/bus/platform/drivers/vfio-dt/bind

Consequently, the hack patch below [2] allows any platform device to be
bound to the vfio-dt driver, without making changes to the device
tree.  It's a hack because I don't see having any driver name specific
code in drivers/base/bus.c being upstream acceptable.

Alternately, device tree compatible entries may be made writeable after
boot, e.g.:

echo vfio-platform > /proc/device-tree/i2c\@12CE0000/compatible

[note s/vfio-dt/vfio-platform/]

but that would require the vfio-platform module be reloaded, thereby
unbinding it from any existing devices it was bound to: we're
seeking a more dynamic solution.

Alex Graf (cc'd) proposed an alternate approach: re-write the driver
name in the device's sysfs entry:

echo "vfio-platform" > /sys/bus/platform/devices/101e0000.rtc/driver/driver_name

The advantage of this approach is that we can achieve the re-bind
(unbind + bind) as an atomic operation, which alleviates userspace from
having to coordinate with other device operations (I think VM migration
is an example case here).

Note that driver_name currently doesn't exist in sysfs, so it would
either have to be added, or another means developed to rename the
driver symlink itself:

cd /sys/bus/platform/devices/12ce0000.i2c
ln -s ../../bus/platform/drivers/s5p-ehci /tmp/tmp-link
mv -Tf /tmp/tmp-link driver

So I guess the question is:  Is our understanding corret - are we on
the right track at all here?  Is the hack below definitely not
acceptable?  Is it correct to assume upstream maintainers are against
writing compatible entries to the device tree sysfs at runtime?  Would
a driver_name be acceptable to add to sysfs, or should we investigate
something like the atomic mv command above further?

Thanks,

Kim

[1] Note that in this RFC, 'vfio-dt' is the name for the driver (-dt for
device tree) which has already been pointed out as a misnomer and
should probably be rewritten as 'vfio-platform':

http://lists.linux-foundation.org/pipermail/iommu/2013-August/006284.html

[2]
>From 6fa383d3f7bb53eb5efbb324c07484191b29543d Mon Sep 17 00:00:00 2001
From: Kim Phillips <kim.phillips@linaro.org>
Date: Fri, 27 Sep 2013 14:36:04 -0500
Subject: [PATCH] hack/rfc: allow vfio-dt to bind to any platform device

---
 drivers/base/bus.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 4c289ab..1cf08d6 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -201,7 +201,8 @@ static ssize_t bind_store(struct device_driver *drv, const char *buf,
 	int err = -ENODEV;
 
 	dev = bus_find_device_by_name(bus, NULL, buf);
-	if (dev && dev->driver == NULL && driver_match_device(drv, dev)) {
+	if (dev && dev->driver == NULL && (driver_match_device(drv, dev) ||
+	    !strcmp(drv->name, "vfio-dt"))) {
 		if (dev->parent)	/* Needed for USB */
 			device_lock(dev->parent);
 		device_lock(dev);
-- 
1.8.4

^ permalink raw reply related	[flat|nested] 66+ messages in thread

end of thread, other threads:[~2013-10-29  6:39 UTC | newest]

Thread overview: 66+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-01 18:38 RFC: (re-)binding the VFIO platform driver to a platform device Kim Phillips
2013-10-01 19:15 ` Scott Wood
2013-10-01 19:17   ` Scott Wood
2013-10-01 22:01     ` Kim Phillips
2013-10-01 21:59   ` Kim Phillips
2013-10-01 22:44     ` Scott Wood
2013-10-01 20:00 ` Greg Kroah-Hartman
2013-10-01 22:02   ` Kim Phillips
2013-10-02  1:53     ` Christoffer Dall
2013-10-02  2:35       ` Alex Williamson
2013-10-02 15:14         ` Christoffer Dall
2013-10-02 15:29           ` Alex Williamson
2013-10-02 18:25           ` Yoder Stuart-B08248
2013-10-02 18:32             ` Scott Wood
2013-10-02 18:43               ` Christoffer Dall
2013-10-02 20:04                 ` Kim Phillips
2013-10-02 20:13                   ` Christoffer Dall
2013-10-02 20:19                     ` Scott Wood
2013-10-02 20:14                 ` Scott Wood
2013-10-02 20:27                   ` Christoffer Dall
2013-10-02 20:39                     ` gregkh
2013-10-02 20:44                       ` Christoffer Dall
2013-10-02 20:37                 ` gregkh
2013-10-02 20:42                   ` Christoffer Dall
2013-10-02 21:08                   ` Scott Wood
2013-10-02 21:16                     ` gregkh
2013-10-02 21:35                       ` Scott Wood
2013-10-02 23:40                         ` gregkh
2013-10-03 18:33                           ` Scott Wood
2013-10-03 18:54                             ` gregkh
2013-10-03 19:11                               ` Scott Wood
2013-10-03 20:32                                 ` gregkh
2013-10-09 19:02                                   ` Yoder Stuart-B08248
2013-10-09 19:16                                     ` gregkh
2013-10-09 19:49                                       ` Scott Wood
2013-10-09 19:21                                     ` Scott Wood
2013-10-09 19:44                                       ` Yoder Stuart-B08248
2013-10-09 20:03                                         ` Scott Wood
2013-10-10  3:05                                           ` Kim Phillips
2013-10-10  8:01                                             ` Bhushan Bharat-R65777
2013-10-10 15:27                                               ` Scott Wood
2013-10-11  6:27                                                 ` [PATCH 1/4] driver core: Add new device_driver flag to allow binding via sysfs only Kim Phillips
2013-10-11  6:27                                                   ` [PATCH 2/4] driver core: platform: allow platform drivers to bind to any device Kim Phillips
2013-10-11  6:27                                                   ` [PATCH 3/4] VFIO: pci: amend vfio-pci for explicit binding via sysfs only Kim Phillips
2013-10-11 20:43                                                     ` Scott Wood
2013-10-11 23:17                                                       ` Kim Phillips
2013-10-14 13:01                                                         ` Yoder Stuart-B08248
2013-10-14 17:13                                                           ` Scott Wood
2013-10-24 11:32                                                         ` Bhushan Bharat-R65777
2013-10-28 17:47                                                     ` Alex Williamson
2013-10-28 18:00                                                       ` Scott Wood
2013-10-28 18:09                                                         ` Scott Wood
2013-10-29  3:38                                                           ` Bhushan Bharat-R65777
2013-10-29  3:40                                                             ` Scott Wood
2013-10-29  3:52                                                               ` Bhushan Bharat-R65777
2013-10-29  4:29                                                                 ` Scott Wood
2013-10-29  4:31                                                                   ` Bhushan Bharat-R65777
2013-10-29  4:35                                                                     ` Scott Wood
2013-10-29  4:45                                                                       ` Bhushan Bharat-R65777
2013-10-29  4:54                                                                         ` Scott Wood
2013-10-29  6:39                                                                           ` Bhushan Bharat-R65777
2013-10-11  6:27                                                   ` [PATCH] VFIO: platform: allow the driver to bind to any device explicitly via sysfs Kim Phillips
2013-10-10  7:45                                           ` RFC: (re-)binding the VFIO platform driver to a platform device Bhushan Bharat-R65777
2013-10-10 13:43                                             ` Yoder Stuart-B08248
2013-10-10 15:23                                             ` Scott Wood
2013-10-10 15:25                                               ` Bhushan Bharat-R65777

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).