[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] xen/privcmd: allow fetching resource sizes


  • To: <linux-kernel@xxxxxxxxxxxxxxx>
  • From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Date: Mon, 11 Jan 2021 16:29:58 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GMv+D5XNXaUs7jlSi3vF8u/xKZa1WRXWQ+kXGL1O4rw=; b=W80ogAYczVifSzSXjz22UguUcPBd+30yBixwRuAzYrBnYm9wyIYH6/AtqDdVfKEejrvqzR0oFF70e55cGIMziX2Pb8krPPLwmDA/6dhojwDukn1MbEt2V1uY+VkAF2TM+HTb69tZM+2st+VOH9J5nUUJgt3bx/uQcLPsiAOWdOBdEQ5OEsRaJO7ZtsM4eeIbMajbTYRuNtex+4ewJ1POEjCqRUUDTNAPkwSMasPvYTxJABKcc7spWj/TbMxuk4gHIGeYDuTJlqcmaeh+GuWktK9I7xDuXWi4QVtsKH5vKwHKSsooSH4cwWh6rKQ9NAIesb2pNVbYhqNNKfTzhtuf/Q==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YB3gLsSWaFL8isb9tw97LvCzFfyhjP7eHUtj0+oG0XVYRdGe0eEYvqC9GO1/tkvTIT33+uHZsEurDwhD+Mf04/zaQwJWKciJNzbqdop+OdFf10hVX5Ni+AK6kRMsCLh2OzI5iJUVq6GJ9RjKCqIFjyY6wg/8+7jdvZ/kAb7zuTuhPXIoHL9Q0hd44C8y/WGARHWnn59ngFma5DJvVQzbUZvQV5uadwev4S5C5pRgPcmOlUjyWpLDQzmMCc3lQcTVcwcjqANff4BWd+J+TZQMZxEWw0bkMwH6stE7a+xtJLVZKVmLIROvMX23g9z4jjhtV5C+iVWPkds+TYgg7F60lA==
  • Authentication-results: esa2.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: Roger Pau Monne <roger.pau@xxxxxxxxxx>, Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Paul Durrant <paul.durrant@xxxxxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Mon, 11 Jan 2021 15:30:19 +0000
  • Ironport-sdr: Qcsklfd+gK2LhOdJ7tNk0t/2RUZU1pXQLFnqI8I4SAH0sLlYFfdpmVVlNaYl9tA7FMcASKziun 2A0BSB2McHmLbTiycnhr/IM1izb+B7fm/QP0I00z07CNKpkHElAvcxCi+UxRwQVo+N7kU2HUBl bwY+kneOGotFmUp5CErF0eEcxMjrGcDWiajsxdWRgm8Nc8wBvfQFDV3sh2iIRONNUMvXr0v8ht 440B7SGC3zvRbEEQKl+y9jOBZHO8VTXLTgYiZH10QzwDgiweAyxCe3dSNmltGJjTUyY6vVHt4U ZDY=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Allow issuing an IOCTL_PRIVCMD_MMAP_RESOURCE ioctl with num = 0 and
addr = 0 in order to fetch the size of a specific resource.

Add a shortcut to the default map resource path, since fetching the
size requires no address to be passed in, and thus no VMA to setup.

Fixes: 3ad0876554caf ('xen/privcmd: add IOCTL_PRIVCMD_MMAP_RESOURCE')
Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
NB: fetching the size of a resource shouldn't trigger an hypercall
preemption, and hence I've dropped the preempt indications.
---
Cc: Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>
Cc: Juergen Gross <jgross@xxxxxxxx>
Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>
Cc: Paul Durrant <paul.durrant@xxxxxxxxxx>
Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx
---
 drivers/xen/privcmd.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c
index b0c73c58f987..a6e7e6e4286f 100644
--- a/drivers/xen/privcmd.c
+++ b/drivers/xen/privcmd.c
@@ -717,14 +717,15 @@ static long privcmd_ioctl_restrict(struct file *file, 
void __user *udata)
        return 0;
 }
 
-static long privcmd_ioctl_mmap_resource(struct file *file, void __user *udata)
+static long privcmd_ioctl_mmap_resource(struct file *file,
+                               struct privcmd_mmap_resource __user *udata)
 {
        struct privcmd_data *data = file->private_data;
        struct mm_struct *mm = current->mm;
        struct vm_area_struct *vma;
        struct privcmd_mmap_resource kdata;
        xen_pfn_t *pfns = NULL;
-       struct xen_mem_acquire_resource xdata;
+       struct xen_mem_acquire_resource xdata = { };
        int rc;
 
        if (copy_from_user(&kdata, udata, sizeof(kdata)))
@@ -734,6 +735,18 @@ static long privcmd_ioctl_mmap_resource(struct file *file, 
void __user *udata)
        if (data->domid != DOMID_INVALID && data->domid != kdata.dom)
                return -EPERM;
 
+       xdata.domid = kdata.dom;
+       xdata.type = kdata.type;
+       xdata.id = kdata.id;
+
+       if (!kdata.addr && !kdata.num) {
+               /* Query the size of the resource. */
+               rc = HYPERVISOR_memory_op(XENMEM_acquire_resource, &xdata);
+               if (rc)
+                       return rc;
+               return __put_user(xdata.nr_frames, &udata->num);
+       }
+
        mmap_write_lock(mm);
 
        vma = find_vma(mm, kdata.addr);
@@ -768,10 +781,6 @@ static long privcmd_ioctl_mmap_resource(struct file *file, 
void __user *udata)
        } else
                vma->vm_private_data = PRIV_VMA_LOCKED;
 
-       memset(&xdata, 0, sizeof(xdata));
-       xdata.domid = kdata.dom;
-       xdata.type = kdata.type;
-       xdata.id = kdata.id;
        xdata.frame = kdata.idx;
        xdata.nr_frames = kdata.num;
        set_xen_guest_handle(xdata.frame_list, pfns);
-- 
2.29.2




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.