From patchwork Mon Jan 11 15:29:58 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: 12011003 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 BE610C433E6 for ; Mon, 11 Jan 2021 15:30:30 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5836E229CA for ; Mon, 11 Jan 2021 15:30:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5836E229CA Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.64977.114954 (Exim 4.92) (envelope-from ) id 1kyz99-0005D4-A9; Mon, 11 Jan 2021 15:30:19 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 64977.114954; Mon, 11 Jan 2021 15:30:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kyz99-0005Cx-6q; Mon, 11 Jan 2021 15:30:19 +0000 Received: by outflank-mailman (input) for mailman id 64977; Mon, 11 Jan 2021 15:30:18 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kyz98-0005Cs-Ja for xen-devel@lists.xenproject.org; Mon, 11 Jan 2021 15:30:18 +0000 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 4b656d6c-178e-49cb-910b-9821ac510742; Mon, 11 Jan 2021 15:30:17 +0000 (UTC) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4b656d6c-178e-49cb-910b-9821ac510742 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1610379017; h=from:to:cc:subject:date:message-id: content-transfer-encoding:mime-version; bh=Rt2LzJOvPFMD+7Yw3EKRh4qiQ7pcKwrXD4R9KU3JgbE=; b=Oxmv36PjAQ61hV+lN8Z5wph3uTIkHcqXJAENbegqxHWQwuxB4/GYIjkI oqAbrn02dotoly2gNnBHTRtTq+lWQWaqqGCyEOva+JqD9tKJW85M2otPU j1Pm/wyzdwhR6lH3YITo1Ud9sdlY2q4YUW3FZBAkZ2uWFc2k5gj6XrFE2 U=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: Qcsklfd+gK2LhOdJ7tNk0t/2RUZU1pXQLFnqI8I4SAH0sLlYFfdpmVVlNaYl9tA7FMcASKziun 2A0BSB2McHmLbTiycnhr/IM1izb+B7fm/QP0I00z07CNKpkHElAvcxCi+UxRwQVo+N7kU2HUBl bwY+kneOGotFmUp5CErF0eEcxMjrGcDWiajsxdWRgm8Nc8wBvfQFDV3sh2iIRONNUMvXr0v8ht 440B7SGC3zvRbEEQKl+y9jOBZHO8VTXLTgYiZH10QzwDgiweAyxCe3dSNmltGJjTUyY6vVHt4U ZDY= X-SBRS: 5.2 X-MesageID: 34875826 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.79,338,1602561600"; d="scan'208";a="34875826" 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== 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-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=GMv+D5XNXaUs7jlSi3vF8u/xKZa1WRXWQ+kXGL1O4rw=; b=jH65inIfaW+FPoj0ivQApSlApYp4n0i6ndH+qGKlJiNbAp/2nbZ0nlILd6mOkb15n5zB3SDtgk/nLHFRRb5aVAi1WsyG28962LAU/USfM/Lfe6b065ffomDT4ifBawr0pSfF83tsPv6B/UOezz9qdhceESfy9SEmUXeEQObR3mA= From: Roger Pau Monne To: CC: Roger Pau Monne , Boris Ostrovsky , Juergen Gross , Stefano Stabellini , Paul Durrant , Subject: [PATCH] xen/privcmd: allow fetching resource sizes Date: Mon, 11 Jan 2021 16:29:58 +0100 Message-ID: <20210111152958.7166-1-roger.pau@citrix.com> X-Mailer: git-send-email 2.29.2 X-ClientProxiedBy: MR2P264CA0091.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:32::31) 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: 40583e6c-0543-4618-5abf-08d8b645ca88 X-MS-TrafficTypeDiagnostic: DS7PR03MB5445: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DlqyfIfcs7wZnmdzi/K3eVPJCF88nTDxRSGGSxrdxyHrNSRiovh0ynIJAQkYenlAzd+Ctec3Vh5hpS9o//mVrsD04AWnG1q/vubzJiOQmU4pUAeApyUSR3A3WBxD81wwuNwaDzWSt276qgd86BXt2oq8OrKmDZ+BFiYjwCPKPA7h0K34vFFSaC0iOUv8H2LmiusIgO7o3XP9R0C6e1KED5O/NFfjLG86ZxWN+loXXPUz/bAw0iv1DJfLxruBbS4WyCKE9PYBDPgirCMkJ4Zy+vWDafi3XeFx7GAW1VPkapMQURlMRTsvZ/S45CaNvWbgs7XeWbXGxRJ8y+FnBTa7CvVoBeq0F36rdkkh8qrcObFXa9NzoIoCHloZ+032qbEE/P1oGovWVVq4eJjQB36S5g== 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)(346002)(376002)(136003)(366004)(39860400002)(396003)(6916009)(6496006)(956004)(4326008)(316002)(2616005)(66946007)(66476007)(26005)(6486002)(478600001)(1076003)(66556008)(83380400001)(86362001)(8936002)(2906002)(186003)(16526019)(36756003)(54906003)(6666004)(8676002)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?EV4LK/pUiJiTJF/LJJKIMIwmnlWWai?= =?utf-8?q?Q9B7yk9YOcf2LTaaP61isY6v1wJrBNkkQ7nb7Koy5ZWbzP9WMn6NK8LSAwYhqacsp?= =?utf-8?q?1cyTlLmfwi7mGnlVyl/hAN/iXP4qiBB7rWpq1CEsEli8Xlna1xf7s1ok572X71SJf?= =?utf-8?q?1cG4AqpvpM5SoX76kqkcNhJNI855Mc9nh5QdSN/otCKtZ0i7Lvi50DMW80psG5Y8V?= =?utf-8?q?l8upolLBENlLsh8zCzuBZ9+ELIlJF787N85SS77vpSlpO+0Eyvl3rrrFeVlLf3Lod?= =?utf-8?q?1t2LLdKnxnQ/TIG4AqbPXWE5dlv7P6QXnTOgQiOT2ZQGPOv+NkVFpAKXQRxQkoHu5?= =?utf-8?q?7AnYwd8V+qO7LtlIveXSMgGlFigfnDWDhOPcDQw3/bd1FvsjyAgxu9Iltmu2gugUK?= =?utf-8?q?cqPKrbuKFx5DSZafpbvwx2kI2Ih0YpSvcSfKpSiTEYvmk4BhkPgpPem2t0++xtHBJ?= =?utf-8?q?H1/Vw4iGBrQ9PfKJ9wmLRxLJVI40RjFnMSDK9cukO4xCVbsV5SXp3IQYnt/z/DPZp?= =?utf-8?q?/3M4GjQvjG0AmQmwF+RMxIF7G1RDUR2ns7j/kJQpJ27wsf19x+iMSLMpHa2eoKgq3?= =?utf-8?q?D1PnIBre0YbustI4JWGE1cCqqhOxY7FBKPAt9Kzno9JvWcCKxJIjbc1d0NGfdTw3x?= =?utf-8?q?uP+y2h8q23U4iwWLO56ReUZ5fHUjsHR8CRURYaJ34lwmI5CWM4VSUz/IVyxZOLKku?= =?utf-8?q?Xtgq75HoxhQq87eC2Tw6zRteL30DlZnp+nDqxbAf5M8kA6MEFKWPxbs7In3sy+6Gr?= =?utf-8?q?lL+ZWgMId1i2TLYLRhmMcbfvg3N/AC+gNkaQcZl1rY8+U1tlZXhqTQkHFRY9s5EKq?= =?utf-8?q?D4n1d8QdT7AszIDuwoMcQlG+S1n4MOe/pUWuold4mcDd2Po7iB0oDZeIGOV2O/aOR?= =?utf-8?q?BtJ7E+NiHgO1uqEtz8L6jP/dHW9C9VBHSzUKTwBxvkIu6vbhQgnVny3zW267jKHqR?= =?utf-8?q?xCef3XG6d0d205GkbYQ?= X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jan 2021 15:30:13.8861 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-Network-Message-Id: 40583e6c-0543-4618-5abf-08d8b645ca88 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: xd0gq8wMWFODL27AZFjUwk949HEdj3zNezyti4ZTv/fIwCoLw5KcNZGSYeKGlcYGoJxhYsvcda9F2glL2jJ3zA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR03MB5445 X-OriginatorOrg: citrix.com 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é --- NB: fetching the size of a resource shouldn't trigger an hypercall preemption, and hence I've dropped the preempt indications. --- Cc: Boris Ostrovsky Cc: Juergen Gross Cc: Stefano Stabellini Cc: Paul Durrant Cc: xen-devel@lists.xenproject.org --- 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);