From patchwork Tue Jan 12 11:53: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: 12013323 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 E7E3DC433E0 for ; Tue, 12 Jan 2021 11:59:28 +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 9383922226 for ; Tue, 12 Jan 2021 11:59:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9383922226 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.65656.116349 (Exim 4.92) (envelope-from ) id 1kzIKW-0000fN-7t; Tue, 12 Jan 2021 11:59:20 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 65656.116349; Tue, 12 Jan 2021 11:59:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kzIKW-0000fG-4w; Tue, 12 Jan 2021 11:59:20 +0000 Received: by outflank-mailman (input) for mailman id 65656; Tue, 12 Jan 2021 11:59:19 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kzIKV-0000fA-23 for xen-devel@lists.xenproject.org; Tue, 12 Jan 2021 11:59:19 +0000 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e1616035-ed48-4864-af00-17d479447de1; Tue, 12 Jan 2021 11:59: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: e1616035-ed48-4864-af00-17d479447de1 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1610452757; h=from:to:cc:subject:date:message-id: content-transfer-encoding:mime-version; bh=GVEOGe6HOBcUN3W05uXHIu3680KaoPV1ahJI63NieNI=; b=VtVrLAIjAUfsU97IsSd3+HZu07xy8kpi3EFcZhZ6Sdauv4AaRzve4WhT fSJV3CMWATPnILu8JC1dXTK2dHZXLeffcMsW84UAVIjCljQ4CtZkE6He4 6pLPI0xJPd73zFSDB2tRJMvMstKGLliarf9jrZdrsEGlG+Nfdoka6C9Di o=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: oJ+WmsQtwSEea3wZ3PHvu1LgnixfhLWSBP/az/mcrIwRUeu8d4x6Bg48rmra/2bpEQbLwrBa7s 4IteRKJoStDgtjYjAsnTLaO7v7u1Z+zgoiI3sSBYIogIFHVJUEk+pwrwHGBJGr+XmonZ1PRb7M 4jDePZqsGzPfbY/JA8YNOUIogw8n6RPPa6Ps5UhG97qsksL+2Q4crzIf85oJ25zcGZ24rImJrT zcOYlmoNeokBEV8TqxCRZTOC4sM77pa5unETVJ888vMJpb/89x6HrCu+jVJWS8WMoRRyVmCEAc 0bI= X-SBRS: 5.2 X-MesageID: 34948028 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,341,1602561600"; d="scan'208";a="34948028" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Cha5r0oLiV1yOpam4G/YSwOqNyddN8H6bZgywWLIMb789GHRs1rhAgKkxM5PwenpTe/pp4D0YUDNQLv2SGstUzPOrKyX4V8Q7AC1uZFz5raZ7q3Dd45ER5vufWNwj39i+n3S/2DQwDxhNrd9v3ytSCxrkr4svcmVUWY/p2gw53w+YB11GZdrjpnOIVYPiHADgI4brNtQi9cAau7QqhAiIjbylftGArxniMvitEZd208ydBaLlT4VJbS9m7j6RtcP1LEbuDG0hjNOtjzPzLobHpGUElsbKSsIdo2eR76MeWkaguJ9nVmCciXZLE3/J9oxXRbzhrdTJoMUGA7BBMjQyQ== 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-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=ExJaXQE/thjDWVx76HSE5KvzYwprp3LimsMovnDmkqA=; b=WkFcRfhr8fhvvbXIO9Z0GPCg/n8QOvlgCBDyot0UTkdib4TPfYjAIOEydHGxry+PvPSeLG+1wNlx5u/673eTdK8+Fm47pnXg6waqH/Mesinm2gzsov52yxond5MnQ8wKppXKfK6H7qVvS2dmFEyBtBbcrbcesqum79IX8QdJq+g= From: Roger Pau Monne To: CC: Roger Pau Monne , , Boris Ostrovsky , Juergen Gross , Stefano Stabellini , Paul Durrant , , , Subject: [PATCH v2] xen/privcmd: allow fetching resource sizes Date: Tue, 12 Jan 2021 12:53:58 +0100 Message-ID: <20210112115358.23346-1-roger.pau@citrix.com> X-Mailer: git-send-email 2.29.2 X-ClientProxiedBy: PR3PR09CA0017.eurprd09.prod.outlook.com (2603:10a6:102:b7::22) 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: d8cd1e1a-8dcd-422c-b965-08d8b6f179a4 X-MS-TrafficTypeDiagnostic: DM6PR03MB4604: X-LD-Processed: 335836de-42ef-43a2-b145-348c2ee9ca5b,ExtAddr X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wkEI7WyUVPS8gn+DGPs4ZNtkzsiiYp4WF9zJA5LdFmTJ8i5CD5rbhRxhI1AMbA8nTyKZ/QxXH0C5LHmVWe1PCr/F9pOiX+usSGhIhBVE67HtQdmgLCnE4+jk/ijwBzyl2rm2yfwieUdwnDNBxMiTEY1yqnDNG5wjYxEPI9UVdWTz7Lb+ftGaRrUwe6EJXPx36VqyCMF9pF6vxOxGUyIq6Wx8vaBq6RBWQzftT41oFLaKtN4R6KdKAvhsFUcCCE1wED1G9/ZKxIdng40xgVxUPwZhCw+zwC0/TBBToQuvQbDuxRXkdw9N6dnOX8jpSrn6v7GK4aBbQ4qTErTfu2LDkYAaUxVaMIaHi9LApsdeqagPqWpkW3M3LAFo92iYjVp8B7xq/etgitHkBiPOwOMp7AGgr+0ijcOZ23Haq9B0gFXp7L7DRMpq4a1X+WN9SOP4 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)(346002)(366004)(396003)(39860400002)(136003)(478600001)(26005)(2616005)(186003)(956004)(1076003)(5660300002)(54906003)(2906002)(6486002)(316002)(8676002)(16526019)(83380400001)(66946007)(6666004)(8936002)(86362001)(6916009)(36756003)(66476007)(4326008)(6496006)(66556008)(309714004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?0dkvXtNkmhFJIWdX7fiM1dPX8WWsNF?= =?utf-8?q?2pohGvzugF1h65RWWIkyrcNXXX4zwMeLZ/W84alUnNd5PB5Je9o9HGblEQPz/BrXE?= =?utf-8?q?fZSbJTgqWxXd2kcvX0GQiE50pDy6H9weUnvGWXXG4JDCyT3RxLFZ9ddYPjGqPEUR2?= =?utf-8?q?/1BewsvjDRKqPW+Smf2ulhgXevpX+Ld7Pgec/EKjD0RGgkSmqkuiSj26W04pyHMYf?= =?utf-8?q?CtUZQJYquPNloYjarD93d8/U3gJnlw9DNZy5yfhxYCLNrtsDxV5/C3RTkrhZ9Qmyk?= =?utf-8?q?AobBoJSqB1hxMiKsrO3YJV8MxiUv4hyJnqqHfWAOe2MssOyjZwA1eA+YNbRWWq0kR?= =?utf-8?q?k9Zys4qeV1vHwM5D33iZ7OIKLuUmg3rgBBJwaBkKrcXTsFF/Oq5oOwg898wA82Ytd?= =?utf-8?q?Cuy8TyOiUWbjMJYzij42rlwlXVIa70N355bhgXZu3QHSlf49xRhByz503vLA4eH5x?= =?utf-8?q?Z33tWJGfD+O2PodiqRq8gnLuIrio4xYUu0NzPNYYrtEBh6LkUjbckHwKbOvKeuQFI?= =?utf-8?q?vvUqGIPU6WqPTuuA6oZYfOp7F1GAch46D5nBTFIB9F98zxiHSgZ92kC1rxJVXDIqK?= =?utf-8?q?6S4dR7kSEg0otrDs/93Jpn7Joxz6he22+YOqq8g155CpQ/2yfieQIoi9tVNuu1XY6?= =?utf-8?q?1NUX6IIReLY9OJ83NB3e0cLOuGrv1SQcnkFMNVUDwT/ZzGA0qobNSeE7758DYEh5h?= =?utf-8?q?3PbH3pxovQQMrS/4c1SleCe0G0QHkp0KDWfHR5f6+YBBFSlIY3rA6kx9Hxo5yRcs7?= =?utf-8?q?brXwIyRTzE6r5QYODZUobvNqXf6YO68gd51Q3PaInib6U19l08NU5XUYqeSIViC4Z?= =?utf-8?q?oIynI/xEx+mF/6du50MQQiGh7GQwFMMGwg9pVUj7oSogZcFjimy1oKfp7kBwTSTsg?= =?utf-8?q?JRXus3+bvzTC+MHWA6VdxoGUx2Ei+BgCZcpETvmHVzyonqsXkFfIY5pguhibR2JIH?= =?utf-8?q?61KfZet4MNEfXU1G+uL?= X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jan 2021 11:59:11.6370 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-Network-Message-Id: d8cd1e1a-8dcd-422c-b965-08d8b6f179a4 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: IoBsu6DA4x7D7n0GE/0rCilqq8ybEhClL4/W6FAJzyz/0OCm3pnJWyYlJt/iQwlOqtQx2OJiSVH3pmbloInc+g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR03MB4604 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. 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é Cc: stable@vger.kernel.org # >= 4.18 Reviewed-by: Juergen Gross Tested-by: Andrew Cooper --- 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: amc96@cam.ac.uk Cc: andrew.cooper3@citrix.com Cc: xen-devel@lists.xenproject.org --- 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);