WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 3/3] xen-kbdfront: Add grant reference for shared pag

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 3/3] xen-kbdfront: Add grant reference for shared page
From: dgdegra@xxxxxxxxxxxxx
Date: Fri, 7 Jan 2011 11:12:59 -0500
Cc: Daniel De Graaf <dgdegra@xxxxxxxxxxxxx>
Delivery-date: Fri, 07 Jan 2011 08:17:36 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <1294416779-13833-1-git-send-email-dgdegra@xxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <1294416779-13833-1-git-send-email-dgdegra@xxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
From: Daniel De Graaf <dgdegra@xxxxxxxxxxxxx>

Without a grant reference, full access to the domain's memory is
required to use the shared page. Add an additional parameter in
xenstore to allow grant mapping to be used.

Signed-off-by: Daniel De Graaf <dgdegra@xxxxxxxxxxxxx>
---
 drivers/input/xen-kbdfront.c |   39 ++++++++++++++++++++++++++++-----------
 1 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/drivers/input/xen-kbdfront.c b/drivers/input/xen-kbdfront.c
index e0c024d..a5d0656 100644
--- a/drivers/input/xen-kbdfront.c
+++ b/drivers/input/xen-kbdfront.c
@@ -11,12 +11,6 @@
  *  more details.
  */
 
-/*
- * TODO:
- *
- * Switch to grant tables together with xen-fbfront.c.
- */
-
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/module.h>
@@ -28,6 +22,8 @@
 #include <xen/xen.h>
 #include <xen/events.h>
 #include <xen/page.h>
+#include <xen/grant_table.h>
+#include <xen/interface/grant_table.h>
 #include <xen/interface/io/fbif.h>
 #include <xen/interface/io/kbdif.h>
 #include <xen/xenbus.h>
@@ -36,6 +32,7 @@ struct xenkbd_info {
        struct input_dev *kbd;
        struct input_dev *ptr;
        struct xenkbd_page *page;
+       int gref;
        int irq;
        struct xenbus_device *xbdev;
        char phys[32];
@@ -121,6 +118,7 @@ static int __devinit xenkbd_probe(struct xenbus_device *dev,
        dev_set_drvdata(&dev->dev, info);
        info->xbdev = dev;
        info->irq = -1;
+       info->gref = -1;
        snprintf(info->phys, sizeof(info->phys), "xenbus/%s", dev->nodename);
 
        info->page = (void *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
@@ -217,15 +215,20 @@ static int xenkbd_connect_backend(struct xenbus_device 
*dev,
        int ret, evtchn;
        struct xenbus_transaction xbt;
 
+       ret = gnttab_grant_foreign_access(dev->otherend_id,
+                                         virt_to_mfn(info->page), 0);
+       if (ret < 0)
+               return ret;
+       info->gref = ret;
+
        ret = xenbus_alloc_evtchn(dev, &evtchn);
        if (ret)
-               return ret;
+               goto error_grant;
        ret = bind_evtchn_to_irqhandler(evtchn, input_handler,
                                        0, dev->devicetype, info);
        if (ret < 0) {
-               xenbus_free_evtchn(dev, evtchn);
                xenbus_dev_fatal(dev, ret, "bind_evtchn_to_irqhandler");
-               return ret;
+               goto error_evtchan;
        }
        info->irq = ret;
 
@@ -233,12 +236,15 @@ static int xenkbd_connect_backend(struct xenbus_device 
*dev,
        ret = xenbus_transaction_start(&xbt);
        if (ret) {
                xenbus_dev_fatal(dev, ret, "starting transaction");
-               return ret;
+               goto error_irqh;
        }
        ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu",
                            virt_to_mfn(info->page));
        if (ret)
                goto error_xenbus;
+       ret = xenbus_printf(xbt, dev->nodename, "page-gref", "%u", info->gref);
+       if (ret)
+               goto error_xenbus;
        ret = xenbus_printf(xbt, dev->nodename, "event-channel", "%u",
                            evtchn);
        if (ret)
@@ -248,7 +254,7 @@ static int xenkbd_connect_backend(struct xenbus_device *dev,
                if (ret == -EAGAIN)
                        goto again;
                xenbus_dev_fatal(dev, ret, "completing transaction");
-               return ret;
+               goto error_irqh;
        }
 
        xenbus_switch_state(dev, XenbusStateInitialised);
@@ -257,6 +263,14 @@ static int xenkbd_connect_backend(struct xenbus_device 
*dev,
  error_xenbus:
        xenbus_transaction_end(xbt, 1);
        xenbus_dev_fatal(dev, ret, "writing xenstore");
+ error_irqh:
+       unbind_from_irqhandler(info->irq, info);
+       info->irq = -1;
+ error_evtchan:
+       xenbus_free_evtchn(dev, evtchn);
+ error_grant:
+       gnttab_end_foreign_access_ref(info->gref, 0);
+       info->gref = -1;
        return ret;
 }
 
@@ -265,6 +279,9 @@ static void xenkbd_disconnect_backend(struct xenkbd_info 
*info)
        if (info->irq >= 0)
                unbind_from_irqhandler(info->irq, info);
        info->irq = -1;
+       if (info->gref >= 0)
+               gnttab_end_foreign_access_ref(info->gref, 0);
+       info->gref = -1;
 }
 
 static void xenkbd_backend_changed(struct xenbus_device *dev,
-- 
1.7.3.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel