From patchwork Mon Jan 18 14:04:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 366057 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B19FC433DB for ; Mon, 18 Jan 2021 14:13:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0A3BE22B4E for ; Mon, 18 Jan 2021 14:13:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392722AbhARONj (ORCPT ); Mon, 18 Jan 2021 09:13:39 -0500 Received: from esa4.hc3370-68.iphmx.com ([216.71.155.144]:16387 "EHLO esa4.hc3370-68.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404667AbhAROLJ (ORCPT ); Mon, 18 Jan 2021 09:11:09 -0500 X-Greylist: delayed 319 seconds by postgrey-1.27 at vger.kernel.org; Mon, 18 Jan 2021 09:11:08 EST DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1610979068; h=from:to:cc:subject:date:message-id: content-transfer-encoding:mime-version; bh=4+llK+Jo5SdFv0XsnDX/o3KrtrkiKMwH4a1jjot82Qg=; b=Aygvf7NyMEjlqp0qGAMgcq7UkdzJGC941Yz3LxQ1r2PRxmzT6bg0vqKw CFBZGbnmluq1uqbLBLkMk9jJYijT+Xff3u78eWpfgO5K4GHKcWzKqcUzP b/BT+XqfjIOasl5+jIeIMJXhiE1Ej5kHYQfyDWbBE2PimLwbg799gaRnn Y=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: IzLX3GaHMFf8heL747YE/TV+XH623qA5ryDCOEddOclXG48N4T8FJhh4BulF+3oIeaw5gD7A1G dv8Dz0ahvLLP99yTUrixhPTo4/G4aRUlYPTTLhavObVIv1NwhdhKSxl0DlDY48fdnnbRbMGsCH 5irbhO+Sn2Ys3RychPh0V8RN4woEIbG/N//TFNhR0vf9tpZKUkATHcu5L0m+wnQ6C3cbtjGyq0 VCr3mhOvjEVxsn/FevFmvC4HNI8FdZ1bXFZnaJHLn5lNJTOkNTxEdveAc8/U/AS0eOu8T6YyiL Si8= X-SBRS: 5.2 X-MesageID: 36598221 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.79,356,1602561600"; d="scan'208";a="36598221" 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== 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-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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.onmicrosoft.com; s=selector2-citrix-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VESoAKX4LWhpj4B/ROAWTl3XXCjTxLczp/u1C6ghlWE=; b=cbDZ2rny7sgF1RZmr+LvIfmB0rU++44La6JR2XdgTbX65/GLLjXX0N+gcXAOZFvWdPheDy42GuOPHL6QoaduDApxC9JsCwZMImhIe2r7tWSnC7quMcD3VVxB4UM68tAfVW9LpEAhUPs3sCcTtSaGNe2AC/HIDKlRmQgvgr7Im5U= From: Roger Pau Monne To: CC: Roger Pau Monne , Juergen Gross , Andrew Cooper , Boris Ostrovsky , Subject: [PATCH for <= 5.4] xen/privcmd: allow fetching resource sizes Date: Mon, 18 Jan 2021 15:04:26 +0100 Message-ID: <20210118140426.80458-1-roger.pau@citrix.com> X-Mailer: git-send-email 2.29.2 X-ClientProxiedBy: AS8PR04CA0001.eurprd04.prod.outlook.com (2603:10a6:20b:310::6) To DS7PR03MB5608.namprd03.prod.outlook.com (2603:10b6:5:2c9::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8e8ef517-78e3-4954-ad09-08d8bbb9fe4f X-MS-TrafficTypeDiagnostic: DM6PR03MB3948: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:962; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FCOHH0lo74iWpgMaeLdCOeOWlhcFSvoAAzJHlczGbdstIIkMQrkJ4dFBvLV3vgQmDCH5hlWquhOQRKH8WrxyBnKc6s+FxS8eLy0CEf+Ktq22pE+b+kNYdIB/EPgwoKksLcunkn5udwwQxiOnlewU1EFuj9vu4ZrJ/eH/etXXfdlqkgKBx3yKyWEISLSuVVb+Uxbg96pIuqkDoZCT2R7zhC7Nyl/J8HL8OCVJ9URsaUdkEeMsJ9bkEgY/RjcYpsNe55vgLI3S93kZKK74Q18r0YXxQP/8Ld+wBJvTb7SOrsQ4Zf2EKcSgWrudumZH4uhP/NxOl/VKf0a1gzWentnrj8SytdQjegkd3e9lf84qqvPkvDyikWCU1kTA9F9vmjTxuhohbMNe7cBetb5UXABfOpr8UrNnwfqREMhohYyFvFXrdRxv3RQUNHf+RQ6KIBC4QwI+p0B46vOyjz6k21o8Ij7QUwpxn05eUZaxzJamVrF01jrym41u1DOA/vfl6eGLUwzK29kiiZy7/0kLMxshx/nCqEhfKdbPutkAYUVOpqccDxYtXL2ElP4Mmb+G8BYHhZZTHSVlt2NAQWXbwToiYQQTblLpo3uK4Ex/MLObrK0jmL3QDg/l47DSQB8qpslLqZokm9Pbpc4rpePq853waw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS7PR03MB5608.namprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(39860400002)(366004)(396003)(136003)(346002)(6486002)(5660300002)(8936002)(66946007)(1076003)(83380400001)(2906002)(186003)(26005)(6666004)(6916009)(16526019)(2616005)(966005)(8676002)(86362001)(956004)(316002)(54906003)(4326008)(478600001)(36756003)(6496006)(66476007)(66556008)(309714004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?j4+FXFzRklkBAR9qa5UKOUY4alQ?= =?utf-8?q?17TJtiF5NOngu4oADtwON/7SSQZXRFSU0I2BKO+Zi2FvCz6q3IJrxBhF?= =?utf-8?q?4CLOh/u0HMgN39KiM1xjLfhTm3omUuk7BBz9YH7o8BaXywC28LBWj0yq?= =?utf-8?q?9VqNz+pHaaSSnitJqLBlI76jRb28gAkiQf+kB+1RSg5FXk2JHCEiPM1s?= =?utf-8?q?PtQQAa3rmPYwHqS3v/f7fsX0Nt5a9UcPzBYmR/nmdWma0U01OoH8T/YE?= =?utf-8?q?kDmONfydMBjUJJE6plAOyujW8tisJUqP3PdI1w29iyMFUU6s32McpGaw?= =?utf-8?q?LfMYx7f0SFZ60D3MQtsua89xTLNfxrlXuO5ipVSO6mbsJg0XOn9BEQH6?= =?utf-8?q?LU2x9XaVLGHS6sYv6m9rw4WtiR09VYtI/4PGgQW0McCyn9OaOFnL2Ifd?= =?utf-8?q?PMFLI2E7z+OxhG1pq1ls6uf6rD5kMgKhfgqhusAA1BVB6YHvRpS0+Nbm?= =?utf-8?q?tVSA8XC2jJXN1v06GVn1YuKKIGLj5ufdBKfTP9N799mcluu9G2kmffbl?= =?utf-8?q?HMjGAACItDHPqZN7EjlLaBt1CJBYq6VNV4hgSvMoGZ2Y5uGZST+7/z50?= =?utf-8?q?RDqjWYk7WrcZ7XkAj7EfzoiA6ofz3LF3jlT8zu+gMJy6m6+aZ08eAUHl?= =?utf-8?q?M0xNqKXhBz/Q4xuLhTgdHtOpV2Sa4E6YJLbLKv4c56mBymls8BKLW0Fy?= =?utf-8?q?Ve8WSUcIR2Ef0MviY+3yZa5/dPHQIXX4RL5ZcmS/M6vDzBdBiij3Wiiv?= =?utf-8?q?7dk62qHN7tkrcxDQ5WsCCK+Z/RWlg3yTGCXfoLYIda2djtyrT1+2Y6xQ?= =?utf-8?q?H66Wi6IGt2uOlcAuCoOcoAKe2H5sfnhISHWJ6txpvmGjqu2KlCguiuj5?= =?utf-8?q?BvYWW0oYsACvTWu8iwJ8cT6tjLN7Al4qf+vHb+fr2K46mssdQ56D9Hqt?= =?utf-8?q?ZTaJw3bHSII8ivWckKzY9JY4PsrTyWrny/1bghWUaRPmQfhcQHxavLBq?= =?utf-8?q?nlQRCd27NQuJc21Kz/L03t2oOJMFqJ3LtkrndPADu72Su?= X-MS-Exchange-CrossTenant-Network-Message-Id: 8e8ef517-78e3-4954-ad09-08d8bbb9fe4f X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jan 2021 14:04:38.5422 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: +4U9ICRBDTzGJeyBbPJ8CUEEH2AVIU/R9PXCx7ROz5swNgVh7C/Z0qr527Rp3wQfF7H19t/TtpluGrIRz1otrQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR03MB3948 X-OriginatorOrg: citrix.com Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.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é Reviewed-by: Juergen Gross Tested-by: Andrew Cooper Cc: stable@vger.kernel.org # >= 4.18 Link: https://lore.kernel.org/r/20210112115358.23346-1-roger.pau@citrix.com Signed-off-by: Juergen Gross --- Cc: Boris Ostrovsky Cc: xen-devel@lists.xenproject.org --- 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);