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

[PATCH for-4.19.y] xen/privcmd: allow fetching resource sizes


  • To: <stable@xxxxxxxxxxxxxxx>
  • From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Date: Fri, 29 Jan 2021 13:22:15 +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=WhAwqTfZDwNVzhA5n6mxxW2V7MHKr5x1qfYqt94dyMY=; b=VZWAQN7T4GjlaJzT7d8ccAW8idPMU+BAh3fADfO7g9xneqSbBRZW7DZqT/HBWuzQg3C2FHKw7jRfZ+iXcaAn5BKZgCuu2UoU9Z0dxaQySpS1zi3hjwj3Tij/5Dhaza1IhfY55rI/BgjvbV9npOP0DlKcy9gNWZadg3vXVjPjihe8qujXl1xuM6Ov5c/bA1CU+7At7oTTFJdIfi9GmL3AOmoAhEEU+MdcrSMHZwdEPR5GPgBGXB75Kqst7qrDQVgUlaFt/pmlO6QAXPKKtGZsVnWcjvdbE4wCYNHgie5f3+IlYFiRGeI7xBM1OW+AAfhDiAUAqKgZkA5RzKjKOiNmXg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ouh/P2qmpMzaZ6qp9POQYJsMZDubp+37nP+cqnVc8ZoO5fS+ja3B8ncN/uf6UO77c5lGpffOZz3Ufa3/jvuK9wBNprYYost8qaWt0fgk/wMiKng6hSN5n3hC2EGeprXUsLDMmbbIZL0DlQTQawc/B+N6k8uSNTbFr5tfDuPSL0LrFnFb+q5CCooiT31KfLLSj1km0liWzw52EIrhTjvziWvSjqcHdTWmIoJLSbWYoM6E7cpHqfLn2fBUQseAC+AtMDmzOP0qAI5I96+uJv+2yfLGj3XnDmCOTGkhPkmG8evivwBqNhKT3Nik+bgGsxIEz3SV1XYOSBhn8TI/X4VLdA==
  • Authentication-results: esa4.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Roger Pau Monne <roger.pau@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Fri, 29 Jan 2021 12:23:02 +0000
  • Ironport-sdr: NEEFk8A855YJ6QiqXulZTH5TsPoFi+qksjxAC8wswaJAY6kCYUUalEo4tm53M9ePHAwUgNxHkW vNRE7kU7eQYVJG/WSaM6vIzCfWnIOk0c31q3iah6a+viU82YBZFAgv5vaBX8E68vkMeGIRRoDR S0//zRXnBXQf3zne6/GiKIPu5ICEyrmyAQscuIge55sS/H4H/7517wZRDlT3aPHFAtZ/Gc+3en CRmkHqbGQIlTnZ6G5pmX5d7N4sf4KUUsj/SyyxHo5pYUR95rx7pompQmuZUiCBsjop0Q7hCvZh cfE=
  • 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>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
 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®.