From patchwork Mon Mar 27 11:04:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Hellstrom X-Patchwork-Id: 9646437 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 0B6A7602C8 for ; Mon, 27 Mar 2017 11:20:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E51A928403 for ; Mon, 27 Mar 2017 11:20:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D9AF62841A; Mon, 27 Mar 2017 11:20:05 +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=BAD_ENC_HEADER,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 3885528409 for ; Mon, 27 Mar 2017 11:20:04 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 283926E1BE; Mon, 27 Mar 2017 11:20:03 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on0043.outbound.protection.outlook.com [104.47.38.43]) by gabe.freedesktop.org (Postfix) with ESMTPS id 249486E1BE for ; Mon, 27 Mar 2017 11:20:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=onevmw.onmicrosoft.com; s=selector1-vmware-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=IWO9vvgkX+YhS+7NRCmfqAWw5nVqpDcYf1ajBMpOxxk=; b=VndLVyOw8GIn2YNOQ4ntuhglR2ybeOAMHjS7MT1qyob5LRkPS97e0pZdi6dlOp5/pMJ8ltTSN0PynCjeGijLe4YKX9nt2V0y3otoRwA0qnUtmRGHL3+4kRb7/2P6IdHXLNcQ3icnRVSHBzqE4sd9fWB1ub65E5U9SdJqoJjKYeg= Authentication-Results: lists.freedesktop.org; dkim=none (message not signed) header.d=none; lists.freedesktop.org; dmarc=none action=none header.from=vmware.com; Received: from linvm2.localdomain (185.29.113.161) by BLUPR05MB755.namprd05.prod.outlook.com (10.141.208.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1005.2; Mon, 27 Mar 2017 11:05:27 +0000 From: Thomas Hellstrom To: Subject: [PATCH] drm/ttm, drm/vmwgfx: Relax permission checking when opening surfaces Date: Mon, 27 Mar 2017 13:04:51 +0200 Message-ID: <1490612691-2664-1-git-send-email-thellstrom@vmware.com> X-Mailer: git-send-email 2.5.0 MIME-Version: 1.0 X-Originating-IP: [185.29.113.161] X-ClientProxiedBy: CY4PR13CA0036.namprd13.prod.outlook.com (10.173.156.150) To BLUPR05MB755.namprd05.prod.outlook.com (10.141.208.145) X-MS-Office365-Filtering-Correlation-Id: 592c9e56-fa7d-4629-6d66-08d475012e0b X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131423043)(201703031133049); SRVR:BLUPR05MB755; X-Microsoft-Exchange-Diagnostics: 1; BLUPR05MB755; 3:dt9TseT4rALaeePfZ6njXiY/RPDbafc/4jxhcdEXFzboLS9LqUIFiBLFu74yHFvu9bjKdS72kfa1YUm3Gt4bJlWCubfRza0RMlp9RNkBO3R0QiSGmiryaT5L0n/EN3w/NNGaI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w0rOOIjznCwqCHeKTg+SK7nhngJnJDds0wPybW8ItnoPzZg12UjLAIBtdHSZFHS+tbJhNoY8sHDCJWKO80826BknETmLNmxusIazQ4xD7/mYluMJhTyS/J+aj5HgmJ2cO0geXG3L4o7ue1ZHh0HRPfq1QdEDvFJ2N705i+J7S95QWD7zt7CZ/FB1GX9rG9Uh7Oc8cMLGMGs/0VbCGVzBE8thydmkDdJ5IQ69lJ7pBPQcAceyejITdVA1eHbzhXGT0W8+1vNuS4RmitwnRDv2R6bjaAorvYipgg61jg7lRsDAMq0zDNctnSwY7wR47BvbSiEc8fwr1t53kUDR/mMXGjJef5UMn7v6E8VCmTtmfTCMnlXenND8UD30aosC5sbiWUbn7HZ+qD1kuwlmvpMYKBdc X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(61668805478150)(9452136761055); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040418)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6041248)(201703131423043)(201702281528043)(201703061421043)(201703061406043)(20161123558025)(20161123564025)(20161123562025)(20161123560025)(20161123555025)(6072148); SRVR:BLUPR05MB755; BCL:0; PCL:0; RULEID:; SRVR:BLUPR05MB755; X-Microsoft-Exchange-Diagnostics: 1; BLUPR05MB755; 4:uO523dmv4Cah8HklZx6z8h0UHvU8Wfqe8L0Kcaut65zjZBGRQpGTiLvaS+DtFDUdkOxVw/dYqPxjLL7nLSF8ebZgejyUALPDiY3yacf1Rw3SVwAJNYbfpDmY/cydK5tF92LmaeMVhfbV12xGiwBynJdy2Nf6E7uF3HI/1MKkpmosGmnVYzAaIZrEGlK9tGwrnoNEeS/9i9br5CpIFtfWn8JBL5wr9LY1p4mDKJATxJqFdU8lwTF1CAw2ydid0os1OmjKnrc+G/Xu86y6RhFHGMn0STBm4xPltAt/G6wUJwUvuJN3PXJsPa5hYMPeZYLHr4oA6ijpaOnCFBXkGRtOhYuWFK6uLca9HrPRXxhzWtw5mJ9NyaNY+isrn1JWfRaH4PCMoYW24vvn7pt+kgjlOTwOOyWsSlm96+0H9T77foOoJhyRSXihbcXYqCg5F7cft1mYJStFGgtRTqnghWDRY8qt1tQlpJCH2RDyoAd3gfSgOcMdNPjPoPHm9J0T4nATP3x0uyyH5HCGLhLjS1oiJQM0joODH0NmOFanBFELEq7hDfCg1RrcQj95OabdNxNwyPSkrZoIUj603AP/MVPS4Jf91E2tIy5EQFtsX+SbdU9nv8H5Ui1yCB0i8WXSc0fSvrge3Inzks00cgWMLNRRb6qRcbiZG02KbXehPqKTdZqjoQEHvSyycy4e1B7sLkUDuTe02g1W8BKnHMV3QY1zw/bgzB9MjfGWQPneRvds6c+j71VoJugx5+wpDS6c59m/PyHDT7NczIRqCzWVsH0FHR2du9xL5U3JI1itLFREWXns7qeNtRWJRbu9JLXdgH0t X-Forefront-PRVS: 02596AB7DA X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(39840400002)(39410400002)(39400400002)(39850400002)(39450400003)(6486002)(6666003)(6116002)(3846002)(6916009)(6506006)(7736002)(50226002)(36756003)(305945005)(54906002)(2351001)(8666007)(4326008)(86362001)(25786009)(33646002)(6512007)(42186005)(110136004)(38730400002)(48376002)(53936002)(2906002)(50466002)(5003940100001)(66066001)(8676002)(47776003)(5660300001)(50986999)(81166006)(189998001); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR05MB755; H:linvm2.localdomain; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BLUPR05MB755; 23:ZVoN7z+oItMQcvHme249DNvlbnsMEkGNDvizMj0P3M?= =?us-ascii?Q?xnstClx9Jc7rC2EuXPuZJmaZEqErOgFn3WJGwn4PVvhZP85STtkR+tr0Tsyb?= =?us-ascii?Q?HgCn2V7UmDLKq3f1YDtp+FahprDHUL3/CvQ4d7/tVNo6l0jhFzKIFepVpHtK?= =?us-ascii?Q?egzN5fVpInU9rNOBkB8LDa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w++/w==; 20:1GQqSL4+a3Pj4t0+ysRgMdUbWu/jIsUw8te2OLx7vJh2PurVuf69Hk5WtoWrChkxP3I8afNay7ni5G+ihtAw6kRpoM56xwlj9ZTebNbl3TVCym1drX477N6BEvHGG8YB6QfslUq1c+wfXsTEtOoLeXM7KDf1g6tOwo+OvkME3Qc= X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2017 11:05:27.9937 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR05MB755 Cc: Thomas Hellstrom , christian.koenig@amd.com, stable@vger.kernel.org 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 Previously, when a surface was opened using a legacy (non prime) handle, it was verified to have been created by a client in the same master realm. Relax this so that opening is also allowed recursively if the client already has the surface open. This works around a regression in svga mesa where opening of a shared surface is used recursively to obtain surface information. Cc: Signed-off-by: Thomas Hellstrom Reviewed-by: Sinclair Yeh --- drivers/gpu/drm/ttm/ttm_object.c | 10 +++++++--- drivers/gpu/drm/vmwgfx/vmwgfx_fence.c | 6 ++---- drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | 4 ++-- drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 22 +++++++++------------- include/drm/ttm/ttm_object.h | 5 ++++- 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_object.c b/drivers/gpu/drm/ttm/ttm_object.c index fdb451e..d750140 100644 --- a/drivers/gpu/drm/ttm/ttm_object.c +++ b/drivers/gpu/drm/ttm/ttm_object.c @@ -179,7 +179,7 @@ int ttm_base_object_init(struct ttm_object_file *tfile, if (unlikely(ret != 0)) goto out_err0; - ret = ttm_ref_object_add(tfile, base, TTM_REF_USAGE, NULL); + ret = ttm_ref_object_add(tfile, base, TTM_REF_USAGE, NULL, false); if (unlikely(ret != 0)) goto out_err1; @@ -318,7 +318,8 @@ EXPORT_SYMBOL(ttm_ref_object_exists); int ttm_ref_object_add(struct ttm_object_file *tfile, struct ttm_base_object *base, - enum ttm_ref_type ref_type, bool *existed) + enum ttm_ref_type ref_type, bool *existed, + bool require_existed) { struct drm_open_hash *ht = &tfile->ref_hash[ref_type]; struct ttm_ref_object *ref; @@ -345,6 +346,9 @@ int ttm_ref_object_add(struct ttm_object_file *tfile, } rcu_read_unlock(); + if (require_existed) + return -EPERM; + ret = ttm_mem_global_alloc(mem_glob, sizeof(*ref), false, false); if (unlikely(ret != 0)) @@ -635,7 +639,7 @@ int ttm_prime_fd_to_handle(struct ttm_object_file *tfile, prime = (struct ttm_prime_object *) dma_buf->priv; base = &prime->base; *handle = base->hash.key; - ret = ttm_ref_object_add(tfile, base, TTM_REF_USAGE, NULL); + ret = ttm_ref_object_add(tfile, base, TTM_REF_USAGE, NULL, false); dma_buf_put(dma_buf); diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c index 4076063..6b2708b 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c @@ -1075,10 +1075,8 @@ int vmw_fence_event_ioctl(struct drm_device *dev, void *data, (void) vmw_fence_obj_reference(fence); if (user_fence_rep != NULL) { - bool existed; - - ret = ttm_ref_object_add(tfile, base, - TTM_REF_USAGE, &existed); + ret = ttm_ref_object_add(vmw_fp->tfile, base, + TTM_REF_USAGE, NULL, false); if (unlikely(ret != 0)) { DRM_ERROR("Failed to reference a fence " "object.\n"); diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c index 65b3f03..bf23153 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c @@ -589,7 +589,7 @@ static int vmw_user_dmabuf_synccpu_grab(struct vmw_user_dma_buffer *user_bo, return ret; ret = ttm_ref_object_add(tfile, &user_bo->prime.base, - TTM_REF_SYNCCPU_WRITE, &existed); + TTM_REF_SYNCCPU_WRITE, &existed, false); if (ret != 0 || existed) ttm_bo_synccpu_write_release(&user_bo->dma.base); @@ -773,7 +773,7 @@ int vmw_user_dmabuf_reference(struct ttm_object_file *tfile, *handle = user_bo->prime.base.hash.key; return ttm_ref_object_add(tfile, &user_bo->prime.base, - TTM_REF_USAGE, NULL); + TTM_REF_USAGE, NULL, false); } /* diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c index f410502..adc023f 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c @@ -891,17 +891,16 @@ vmw_surface_handle_reference(struct vmw_private *dev_priv, uint32_t handle; struct ttm_base_object *base; int ret; + bool require_exist = false; if (handle_type == DRM_VMW_HANDLE_PRIME) { ret = ttm_prime_fd_to_handle(tfile, u_handle, &handle); if (unlikely(ret != 0)) return ret; } else { - if (unlikely(drm_is_render_client(file_priv))) { - DRM_ERROR("Render client refused legacy " - "surface reference.\n"); - return -EACCES; - } + if (unlikely(drm_is_render_client(file_priv))) + require_exist = true; + if (ACCESS_ONCE(vmw_fpriv(file_priv)->locked_master)) { DRM_ERROR("Locked master refused legacy " "surface reference.\n"); @@ -929,17 +928,14 @@ vmw_surface_handle_reference(struct vmw_private *dev_priv, /* * Make sure the surface creator has the same - * authenticating master. + * authenticating master, or is already registered with us. */ if (drm_is_primary_client(file_priv) && - user_srf->master != file_priv->master) { - DRM_ERROR("Trying to reference surface outside of" - " master domain.\n"); - ret = -EACCES; - goto out_bad_resource; - } + user_srf->master != file_priv->master) + require_exist = true; - ret = ttm_ref_object_add(tfile, base, TTM_REF_USAGE, NULL); + ret = ttm_ref_object_add(tfile, base, TTM_REF_USAGE, NULL, + require_exist); if (unlikely(ret != 0)) { DRM_ERROR("Could not add a reference to a surface.\n"); goto out_bad_resource; diff --git a/include/drm/ttm/ttm_object.h b/include/drm/ttm/ttm_object.h index ed953f9..1487011 100644 --- a/include/drm/ttm/ttm_object.h +++ b/include/drm/ttm/ttm_object.h @@ -229,6 +229,8 @@ extern void ttm_base_object_unref(struct ttm_base_object **p_base); * @ref_type: The type of reference. * @existed: Upon completion, indicates that an identical reference object * already existed, and the refcount was upped on that object instead. + * @require_existed: Fail with -EPERM if an identical ref object didn't + * already exist. * * Checks that the base object is shareable and adds a ref object to it. * @@ -243,7 +245,8 @@ extern void ttm_base_object_unref(struct ttm_base_object **p_base); */ extern int ttm_ref_object_add(struct ttm_object_file *tfile, struct ttm_base_object *base, - enum ttm_ref_type ref_type, bool *existed); + enum ttm_ref_type ref_type, bool *existed, + bool require_existed); extern bool ttm_ref_object_exists(struct ttm_object_file *tfile, struct ttm_base_object *base);