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

[PATCH v2] xen/privcmd: allow fetching resource sizes


  • To: <linux-kernel@xxxxxxxxxxxxxxx>
  • From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Date: Tue, 12 Jan 2021 12:53: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=ExJaXQE/thjDWVx76HSE5KvzYwprp3LimsMovnDmkqA=; b=c0Goza1eqEpGebqcs7P3nVRdC083p7drmpOp5Tryt4EA+t2RW7VAuCovTDDsFxQCfXfpqwh3dZ7GTyB95KrV7TS4Yh2pFdCdlRDPp3KVuCewKAtuvnXE/5oQo4Xl/Xsov+zMe+jmkNOsWPVSH6SKPEFIPFmn4wiRMql6On5ZThPak8lJSLDxi4xYtMHkTN6WZ57pAN6SSvJhLVYVkflMoLm+UtGSD3kOLdRYCIzBVknJ9fs2ROGNEvKD9tD9nyyG2Xv6GbUkAxh3E4on9xRpfR0LmGahJbacAvy4vA6jacne0tBaOLkkIUYQEG0d8nZhMG2FEMKokgoWgYRxDFgXeQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Cha5r0oLiV1yOpam4G/YSwOqNyddN8H6bZgywWLIMb789GHRs1rhAgKkxM5PwenpTe/pp4D0YUDNQLv2SGstUzPOrKyX4V8Q7AC1uZFz5raZ7q3Dd45ER5vufWNwj39i+n3S/2DQwDxhNrd9v3ytSCxrkr4svcmVUWY/p2gw53w+YB11GZdrjpnOIVYPiHADgI4brNtQi9cAau7QqhAiIjbylftGArxniMvitEZd208ydBaLlT4VJbS9m7j6RtcP1LEbuDG0hjNOtjzPzLobHpGUElsbKSsIdo2eR76MeWkaguJ9nVmCciXZLE3/J9oxXRbzhrdTJoMUGA7BBMjQyQ==
  • Authentication-results: esa2.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: Roger Pau Monne <roger.pau@xxxxxxxxxx>, <stable@xxxxxxxxxxxxxxx>, Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Paul Durrant <paul.durrant@xxxxxxxxxx>, <amc96@xxxxxxxxx>, <andrew.cooper3@xxxxxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Tue, 12 Jan 2021 11:59:20 +0000
  • Ironport-sdr: oJ+WmsQtwSEea3wZ3PHvu1LgnixfhLWSBP/az/mcrIwRUeu8d4x6Bg48rmra/2bpEQbLwrBa7s 4IteRKJoStDgtjYjAsnTLaO7v7u1Z+zgoiI3sSBYIogIFHVJUEk+pwrwHGBJGr+XmonZ1PRb7M 4jDePZqsGzPfbY/JA8YNOUIogw8n6RPPa6Ps5UhG97qsksL+2Q4crzIf85oJ25zcGZ24rImJrT zcOYlmoNeokBEV8TqxCRZTOC4sM77pa5unETVJ888vMJpb/89x6HrCu+jVJWS8WMoRRyVmCEAc 0bI=
  • 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.

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>
Cc: stable@xxxxxxxxxxxxxxx # >= 4.18
---
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: amc96@xxxxxxxxx
Cc: andrew.cooper3@xxxxxxxxxx
Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx
---
Changes since v1:
 - Remove Fixes tag, add backport.
 - Make sure both addr and num are set or unset.
---
 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 b0c73c58f987..720a7b7abd46 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,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);
+       }
+
        mmap_write_lock(mm);
 
        vma = find_vma(mm, kdata.addr);
@@ -768,10 +785,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®.