From patchwork Wed Sep 27 14:01:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Price X-Patchwork-Id: 9975415 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4F259603F2 for ; Thu, 28 Sep 2017 07:30:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4028328470 for ; Thu, 28 Sep 2017 07:30:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 34BC6294BD; Thu, 28 Sep 2017 07:30:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9410E28470 for ; Thu, 28 Sep 2017 07:30:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6EDDA6E861; Thu, 28 Sep 2017 07:30:09 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org X-Greylist: delayed 4710 seconds by postgrey-1.35 at gabe; Wed, 27 Sep 2017 15:35:13 UTC Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-eopbgr40040.outbound.protection.outlook.com [40.107.4.40]) by gabe.freedesktop.org (Postfix) with ESMTPS id B00328921D for ; Wed, 27 Sep 2017 15:35:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=0bBfmLKifxAHY2rz+O4W+jUyZsNSwRiIpyOvs+LIw6g=; b=WU8JRuRigHzTHXnKC0lEvyzL+5akjSmqpocNi7f8SUEAO/TyFTF7EAm/wOF05T6I5b5gA5bx/by3ezcvrn4MA9w97018MXKbjd4wlpYZJainam3Js3d/UvtwdBEIaqXRrmo7DIQi8kZU2RuXqynWI0DfE+at2AY06Wjv2aNyndE= Received: from AM4PR0802MB2194.eurprd08.prod.outlook.com (10.172.217.20) by AM4PR0802MB2196.eurprd08.prod.outlook.com (10.172.217.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.77.7; Wed, 27 Sep 2017 14:01:31 +0000 Received: from AM4PR0802MB2194.eurprd08.prod.outlook.com ([fe80::60cb:e81c:76cf:e706]) by AM4PR0802MB2194.eurprd08.prod.outlook.com ([fe80::60cb:e81c:76cf:e706%16]) with mapi id 15.20.0077.016; Wed, 27 Sep 2017 14:01:31 +0000 From: Steven Price To: Daniel Vetter , Jani Nikula , Sean Paul , "David Airlie" , "dri-devel@lists.freedesktop.org" Subject: [PATCH] drm/cma: correctly handle non-zero offset for mmap Thread-Topic: [PATCH] drm/cma: correctly handle non-zero offset for mmap Thread-Index: AdM3mHu9YHGDVE6mTHqBEh0fShk60g== Date: Wed, 27 Sep 2017 14:01:31 +0000 Message-ID: Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Steven.Price@arm.com; x-originating-ip: [217.140.96.140] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; AM4PR0802MB2196; 6:S+H2WhQI3RsMfBltq+WLiiY7XxU37AOEaBqmwcu8SALZ2uKT2FjJ8vfaH88UQKuVkt45UwWV3bfIPX3SFaxJfPcLLNmQ0or89Lg3Q8xs9fQsxVjugCimkI+4XKVqK/QdQWNMmHjn9AQkENyMVrw+gx67PtBy1z0YHgYKK/iwORJTI04zh3NPlow6D7Iw+OsNU9AFOsiIMo6TDEqDDaOLvw8PT1z2Q/qkSaNiTbV1vXxpRunJ9+89yjvU2p6wZX/MB747LsNQu953nTp3bMoXx45taPCqNrO27hCiPbO3CwukWWnDYD0AJyK45+XAUT0hMSR1DMm3k0ujQvWY3B5ZhQ==; 5:3rXs6U7JofB4yJuYIP1UjScyq18toTGUlsL4QbRjZrq6YjpcENHGAggXk6suFdXbhN3LUab2aYAj6NnqUUZADpXcIEEFZTaH11Fo/9FhiE1tj9XTDasLGSbrPZ2udz4ujOt2hQdaLxQmRFiLkAsCkA==; 24:GNjnX5GgFsOB4RCOu32/8ROX1heW3xViXMWkCpqHGRhxl9ffdAzGctPpyoeamN5D34qBo3SP8LMC/ljqJXGLBgqpM6rUttxPG1yXNoV1AZA=; 7:fIdrsSjeKK+6PTGztFz+hYt5861uJrTvAcSqHB7y0WkWDrl3Mxl5twi1EDuHBAWIy/ok/ByQOKzgPbQ4rKv6ImVSYFI7cSZCmynufMdbkcrFGsfrjGUZOrXF5nQK271Fm0+zh1AdIfX8kh3KK9gT2AH2FFUbT6sH2xahRJQhb1eihSFvDIaV72Idc+bQia2JLqUwgdHnWd1huEydK4ulJzn/P57GNITBO8YphPERyCI= x-ms-exchange-antispam-srfa-diagnostics: SSOS;SSOR; x-ms-office365-filtering-correlation-id: f826f3c6-a96b-47e2-c156-08d505b0417d x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254152)(48565401081)(2017052603199)(201703131423075)(201703031133081)(201702281549075); SRVR:AM4PR0802MB2196; x-ms-traffictypediagnostic: AM4PR0802MB2196: nodisclaimer: True x-exchange-antispam-report-test: UriScan:(180628864354917); x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(5005006)(8121501046)(3002001)(100000703101)(100105400095)(10201501046)(93006095)(93001095)(6055026)(6041248)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(20161123558100)(20161123564025)(20161123562025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:AM4PR0802MB2196; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:AM4PR0802MB2196; x-forefront-prvs: 04433051BF x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(979002)(6009001)(376002)(346002)(199003)(189002)(8936002)(9686003)(110136005)(99286003)(74316002)(2900100001)(106356001)(33656002)(86362001)(189998001)(97736004)(105586002)(5250100002)(7736002)(54356999)(50986999)(14454004)(305945005)(68736007)(8676002)(81156014)(101416001)(55016002)(2501003)(81166006)(25786009)(3280700002)(7696004)(3660700001)(2906002)(5660300001)(4326008)(72206003)(6436002)(6506006)(53936002)(478600001)(54906003)(3846002)(316002)(66066001)(6116002)(102836003)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1101; SCL:1; SRVR:AM4PR0802MB2196; H:AM4PR0802MB2194.eurprd08.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Sep 2017 14:01:31.2374 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR0802MB2196 X-Mailman-Approved-At: Thu, 28 Sep 2017 07:30:08 +0000 Cc: nd , Liviu Dudau , Steven Price , Tu Vuong X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Tu Vuong When a CMA GEM object is exported via DRM PRIME it should be possible to mmap the object using an offset. However drm_gem_cma_mmap_obj always zeroed vm_pgoff. Fix this by moving the zeroing of vm_pgoff to drm_gem_cma_mmap (which is only used for non-PRIME mmap) and correct the size parameter in the call to dma_mmap_wc as the offset may not be non-zero. Signed-off-by: Tu Vuong Signed-off-by: Steven Price Reviewed-by: Brian Starkey CC: Brian Starkey CC: Liviu Dudau --- drivers/gpu/drm/drm_gem_cma_helper.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/drm_gem_cma_helper.c b/drivers/gpu/drm/drm_gem_cma_helper.c index 373e33f22be4..25828b33c5be 100644 --- a/drivers/gpu/drm/drm_gem_cma_helper.c +++ b/drivers/gpu/drm/drm_gem_cma_helper.c @@ -276,15 +276,12 @@ static int drm_gem_cma_mmap_obj(struct drm_gem_cma_object *cma_obj, int ret; /* - * Clear the VM_PFNMAP flag that was set by drm_gem_mmap(), and set the - * vm_pgoff (used as a fake buffer offset by DRM) to 0 as we want to map - * the whole buffer. + * Clear the VM_PFNMAP flag that was set by drm_gem_mmap() */ vma->vm_flags &= ~VM_PFNMAP; - vma->vm_pgoff = 0; ret = dma_mmap_wc(cma_obj->base.dev->dev, vma, cma_obj->vaddr, - cma_obj->paddr, vma->vm_end - vma->vm_start); + cma_obj->paddr, cma_obj->base.size); if (ret) drm_gem_vm_close(vma); @@ -322,6 +319,12 @@ int drm_gem_cma_mmap(struct file *filp, struct vm_area_struct *vma) gem_obj = vma->vm_private_data; cma_obj = to_drm_gem_cma_obj(gem_obj); + /* + * Set the vm_pgoff (used as a fake buffer offset by DRM) to 0 as we + * want to map the whole buffer. + */ + vma->vm_pgoff = 0; + return drm_gem_cma_mmap_obj(cma_obj, vma); } EXPORT_SYMBOL_GPL(drm_gem_cma_mmap);