Skip to content

Commit 0a4dfa5

Browse files
dgdegraafdtor
authored andcommitted
Input: xen-kbdfront - add grant reference for shared page
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@tycho.nsa.gov> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Acked-by: Ian Campbell <Ian.Campbell@eu.citrix.com> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
1 parent 8c3c283 commit 0a4dfa5

1 file changed

Lines changed: 28 additions & 11 deletions

File tree

‎drivers/input/xen-kbdfront.c‎

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111
* more details.
1212
*/
1313

14-
/*
15-
* TODO:
16-
*
17-
* Switch to grant tables together with xen-fbfront.c.
18-
*/
19-
2014
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
2115

2216
#include <linux/kernel.h>
@@ -30,6 +24,8 @@
3024
#include <xen/xen.h>
3125
#include <xen/events.h>
3226
#include <xen/page.h>
27+
#include <xen/grant_table.h>
28+
#include <xen/interface/grant_table.h>
3329
#include <xen/interface/io/fbif.h>
3430
#include <xen/interface/io/kbdif.h>
3531
#include <xen/xenbus.h>
@@ -38,6 +34,7 @@ struct xenkbd_info {
3834
struct input_dev *kbd;
3935
struct input_dev *ptr;
4036
struct xenkbd_page *page;
37+
int gref;
4138
int irq;
4239
struct xenbus_device *xbdev;
4340
char phys[32];
@@ -122,6 +119,7 @@ static int __devinit xenkbd_probe(struct xenbus_device *dev,
122119
dev_set_drvdata(&dev->dev, info);
123120
info->xbdev = dev;
124121
info->irq = -1;
122+
info->gref = -1;
125123
snprintf(info->phys, sizeof(info->phys), "xenbus/%s", dev->nodename);
126124

127125
info->page = (void *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
@@ -232,26 +230,34 @@ static int xenkbd_connect_backend(struct xenbus_device *dev,
232230
int ret, evtchn;
233231
struct xenbus_transaction xbt;
234232

233+
ret = gnttab_grant_foreign_access(dev->otherend_id,
234+
virt_to_mfn(info->page), 0);
235+
if (ret < 0)
236+
return ret;
237+
info->gref = ret;
238+
235239
ret = xenbus_alloc_evtchn(dev, &evtchn);
236240
if (ret)
237-
return ret;
241+
goto error_grant;
238242
ret = bind_evtchn_to_irqhandler(evtchn, input_handler,
239243
0, dev->devicetype, info);
240244
if (ret < 0) {
241-
xenbus_free_evtchn(dev, evtchn);
242245
xenbus_dev_fatal(dev, ret, "bind_evtchn_to_irqhandler");
243-
return ret;
246+
goto error_evtchan;
244247
}
245248
info->irq = ret;
246249

247250
again:
248251
ret = xenbus_transaction_start(&xbt);
249252
if (ret) {
250253
xenbus_dev_fatal(dev, ret, "starting transaction");
251-
return ret;
254+
goto error_irqh;
252255
}
253256
ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu",
254257
virt_to_mfn(info->page));
258+
if (ret)
259+
goto error_xenbus;
260+
ret = xenbus_printf(xbt, dev->nodename, "page-gref", "%u", info->gref);
255261
if (ret)
256262
goto error_xenbus;
257263
ret = xenbus_printf(xbt, dev->nodename, "event-channel", "%u",
@@ -263,7 +269,7 @@ static int xenkbd_connect_backend(struct xenbus_device *dev,
263269
if (ret == -EAGAIN)
264270
goto again;
265271
xenbus_dev_fatal(dev, ret, "completing transaction");
266-
return ret;
272+
goto error_irqh;
267273
}
268274

269275
xenbus_switch_state(dev, XenbusStateInitialised);
@@ -272,6 +278,14 @@ static int xenkbd_connect_backend(struct xenbus_device *dev,
272278
error_xenbus:
273279
xenbus_transaction_end(xbt, 1);
274280
xenbus_dev_fatal(dev, ret, "writing xenstore");
281+
error_irqh:
282+
unbind_from_irqhandler(info->irq, info);
283+
info->irq = -1;
284+
error_evtchan:
285+
xenbus_free_evtchn(dev, evtchn);
286+
error_grant:
287+
gnttab_end_foreign_access_ref(info->gref, 0);
288+
info->gref = -1;
275289
return ret;
276290
}
277291

@@ -280,6 +294,9 @@ static void xenkbd_disconnect_backend(struct xenkbd_info *info)
280294
if (info->irq >= 0)
281295
unbind_from_irqhandler(info->irq, info);
282296
info->irq = -1;
297+
if (info->gref >= 0)
298+
gnttab_end_foreign_access_ref(info->gref, 0);
299+
info->gref = -1;
283300
}
284301

285302
static void xenkbd_backend_changed(struct xenbus_device *dev,

0 commit comments

Comments
 (0)