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

[PATCH for <= 5.4] xen/privcmd: allow fetching resource sizes


  • To: <stable@xxxxxxxxxxxxxxx>
  • From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Date: Mon, 18 Jan 2021 15:04:26 +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=VESoAKX4LWhpj4B/ROAWTl3XXCjTxLczp/u1C6ghlWE=; b=bs1WYXFQMt57p0gz0N/Kwhql15hE+nRCvLLkOBrGc71SA96GY4GCjdbXcW/iICBjeXvNd9rtQ9kkLPWC1CnUv7pnouWOhVUeFzCnbTU1b1ozhECBrfF3u8dI9m3aC3vt+LT2SChtcYCggW83ivJp6OfVdgFCZY3fqcUZnuGZTMIyGBRSvm1MK+GdfyvvZb7/ieAK0AgKqDvlK3j+lg/yz4kUYhj7JhUvbrjcnWiyft3j2MZ4sIMhywft4buLXQo0lkP2LEGPzGYosYP1sk0YiGJiPsxavPMaMxWmnO9epq5g05rbcUDfKXDP25Fkc6kFDzAnKuoFCrM3S827a4GdkQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EqYaj/Tt+z0kFeAVtyMl4KaoZ6L0KxtQTG8ILQrSz2qbpCK3sOXlXYrjOJBoIKHJNswO2zlDsbk8s4DIOXXDgaEx9o1NWZLaQd7P4b/LGya3mK7NLgV/xA0/Y42YBeDbd3srCdWyidufWmjK+6zyRWfEogQKmSOdMUPS8YKaOHbl/nY+7fXT0Jl8XCOjMFsPR7zZ7Lv2Lb+mzCWa2b63c4q22OmXxFhNtYv3yRRmpVX4jC/v7cW6aNAjfOPgaiplezI8OLLEO9cKB+6ttmRQ1zul6BfS7eVjRgFvVdHpr/09qA5GfVOKY+qh6jqlN+XtN94d9zayF1oAgCyj3hUJ/g==
  • Authentication-results: esa4.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: Roger Pau Monne <roger.pau@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Mon, 18 Jan 2021 14:04:54 +0000
  • Ironport-sdr: IzLX3GaHMFf8heL747YE/TV+XH623qA5ryDCOEddOclXG48N4T8FJhh4BulF+3oIeaw5gD7A1G dv8Dz0ahvLLP99yTUrixhPTo4/G4aRUlYPTTLhavObVIv1NwhdhKSxl0DlDY48fdnnbRbMGsCH 5irbhO+Sn2Ys3RychPh0V8RN4woEIbG/N//TFNhR0vf9tpZKUkATHcu5L0m+wnQ6C3cbtjGyq0 VCr3mhOvjEVxsn/FevFmvC4HNI8FdZ1bXFZnaJHLn5lNJTOkNTxEdveAc8/U/AS0eOu8T6YyiL Si8=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

commit ef3a575baf53571dc405ee4028e26f50856898e7 upstream

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.

This is missing from the initial implementation, and causes issues
when mapping resources that don't have fixed or known sizes.

Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
Reviewed-by: Juergen Gross <jgross@xxxxxxxx>
Tested-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx # >= 4.18
Link: https://lore.kernel.org/r/20210112115358.23346-1-roger.pau@xxxxxxxxxx
Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
---
Cc: Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>
Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx
---
 drivers/xen/privcmd.c | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c
index 7e6e682104dc..a8486432be05 100644
--- a/drivers/xen/privcmd.c
+++ b/drivers/xen/privcmd.c
@@ -743,14 +743,15 @@ static int remap_pfn_fn(pte_t *ptep, pgtable_t token, 
unsigned long addr,
        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)))
@@ -760,6 +761,22 @@ static long privcmd_ioctl_mmap_resource(struct file *file, 
void __user *udata)
        if (data->domid != DOMID_INVALID && data->domid != kdata.dom)
                return -EPERM;
 
+       /* Both fields must be set or unset */
+       if (!!kdata.addr != !!kdata.num)
+               return -EINVAL;
+
+       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);
+       }
+
        down_write(&mm->mmap_sem);
 
        vma = find_vma(mm, kdata.addr);
@@ -793,10 +810,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®.