From patchwork Wed Sep 26 16:18:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Hellstrom X-Patchwork-Id: 10616165 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 988EF14BD for ; Wed, 26 Sep 2018 16:20:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8803E2B3FE for ; Wed, 26 Sep 2018 16:20:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 863AC2B441; Wed, 26 Sep 2018 16:20:41 +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=-5.2 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 243C22B3FE for ; Wed, 26 Sep 2018 16:20:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 289FF6E4C7; Wed, 26 Sep 2018 16:19:48 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM03-DM3-obe.outbound.protection.outlook.com (mail-dm3nam03on060a.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe49::60a]) by gabe.freedesktop.org (Postfix) with ESMTPS id 915656E4B7 for ; Wed, 26 Sep 2018 16:19:24 +0000 (UTC) Received: from localhost.localdomain (155.4.205.56) by DM6PR05MB4588.namprd05.prod.outlook.com (2603:10b6:5:9f::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1185.14; Wed, 26 Sep 2018 16:19:22 +0000 From: Thomas Hellstrom To: dri-devel@lists.freedesktop.org Subject: [PATCH -next 14/18] drm/vmwgfx: Look up user buffer objects without taking a reference Date: Wed, 26 Sep 2018 18:18:35 +0200 Message-Id: <20180926161839.4549-14-thellstrom@vmware.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180926161839.4549-1-thellstrom@vmware.com> References: <20180926161839.4549-1-thellstrom@vmware.com> MIME-Version: 1.0 X-Originating-IP: [155.4.205.56] X-ClientProxiedBy: VI1PR0601CA0020.eurprd06.prod.outlook.com (2603:10a6:800:1e::30) To DM6PR05MB4588.namprd05.prod.outlook.com (2603:10b6:5:9f::25) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d3cc96e4-0daa-472a-f9d2-08d623cbd291 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:DM6PR05MB4588; X-Microsoft-Exchange-Diagnostics: 1; DM6PR05MB4588; 3:/GIJFVEbcUpLlThYdjS0bVgRjfqgMyqseqMyw9G2UQRtaPhuynPHkHHwIHHPek9NQMfQsM4RSCjauCC70DizjzEv1d0fnQE8wL/822EpFPcg3cEyS4VhbJTtyomxsudPtyLsyLksClPnoWRNWkTQLjw2MK2Nz+gFqnZMh/zLpkONm1FX2pXLXOaX8CfHO+70Qzu62Ol9ANN+3iTJR8o+l0XPg9b/020VEOqFILZu7A05i0fgCAKWUJa/QyJk/Nkz; 25:WmvcmdBsAl0JmnjDJzkXeOzHCDhzZYVrmRAxd7vYkS4vD4C2mVNeOK5JnicQSz8PjiBq0YfZPhrYSw1W7K8FBiSOqLiN2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cj4klGswZk4y1LE76CapWd6zFxV/gcW42JVEwKAxuFWfRuRtYkxSMDOPBBsNm4RHoPe02nIJfUnsnZgR0KGUbNyWzJCJt7NL7vKpl3SDZ0hIoqaSSyus=; 4:dbhvskOTSNzoJefQpCZg0jqyRk724gJjGErnvV3r2mV56wifqEYQiGLUpIW95Bk/fE6j1jpKn3bu3bq3Nv2/gQv2fcRq3sOkeHP7QdDVRafL7d4uxesowNfs8C479jDGGI9nnJlmMcwUhvCmfhUTE8qAhiyv72llqjQBy99KL22BYVXH7aHnlZeGP5dNghXe2oMnw7H30MAtJOT0fvr1GtY8IO+rDkDEAdnIimLZp9TnLZBxj0ofM2wh+FNiuEFRQAv2SUtuPWwowcs0ws2tFxDRA6PfEXd7UKCbTJD3+5mrsOPPsyXHGEIOWmNmXu9A X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(61668805478150); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(10201501046)(93006095)(93001095)(3231355)(944501410)(52105095)(3002001)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123558120)(20161123560045)(20161123562045)(201708071742011)(7699051)(76991041); SRVR:DM6PR05MB4588; BCL:0; PCL:0; RULEID:; SRVR:DM6PR05MB4588; X-Forefront-PRVS: 08076ABC99 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6069001)(1496009)(346002)(376002)(366004)(396003)(136003)(39860400002)(199004)(189003)(11346002)(186003)(105586002)(36756003)(47776003)(26005)(66066001)(6512007)(2351001)(305945005)(14444005)(446003)(2361001)(486006)(16526019)(106356001)(7736002)(5660300001)(476003)(6666003)(53936002)(86362001)(6486002)(97736004)(69590400006)(478600001)(68736007)(50466002)(25786009)(8936002)(316002)(16586007)(48376002)(956004)(2616005)(386003)(76176011)(6506007)(3846002)(6916009)(51416003)(1076002)(4326008)(8676002)(81166006)(50226002)(6116002)(107886003)(2906002)(81156014)(52116002)(34290500001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM6PR05MB4588; H:localhost.localdomain; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: vmware.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM6PR05MB4588; 23:TJUjXvU9n4rA1Lkb0h8aGNcEZb+8TUgDfr3J19eIJ?= JWEvWR7tjoBUzh9d6HmkFsxWz9IN3ahhauGyPc+FTXiuAUz4nggjuDGxvJUnqZP7K6lqrxGzCmaCoHlnYeAJs7D23cVYnL/vnGlTfixt6ium6YaGoTZ7k4swX95VxV8Uoh4OZo+srr9WBjpTupn2J6XFjSKmtZ+oT5kXud1oOeztSwylXuEBTxYgcRf8/JkY9TlVZy5zCDn3i/kEFVX59dwBsJDQPvVd5pTO4n7NrvdDoJdWeOAvQa21Wfe3fw80yr+xM7h2tfy2FedO/ad4Du1aTA2Xx8fsA5lcHJ2vUr5naSKYu7KGBV3FuDP2tx6fXZg7U41FRhCFJjEDZZOdPTX38g6t3OkvT2E/Qqb8611zV8zMaEw9auNLHf1iT+xhOZF+X2tPPROHYoG2WF9SsgoqGKmvNOV2ZZ/m+5utDBNvmKQmG/DX8LYQg0CmggtlQXElsdYWnYBtUqS28iTNRIKmRlNFlT+RzaNcDTTVafnqhvuxvXvmodjjUrcU6d7+2/qCFcjnr9XWmrqCAMrP5LlHpdb5j/r8wzTGkYlRNWXlA4rZcgBYrg/tI/ilFyEI7RykU2N5HUdek0olPvcKI3GHsY0fT3hCl9lvoASKwb2j1Cv2YZgDZxTTcglHuL8U1sGq3iRXJ+L1dy+d84Wwjss0/vs9XVuTIfpgKgkzljiyNkXu0NMGIxnHomzkpe/sLZhuQecm2F6okiNqTfzWNDuGhaMWvezKwKHmxLy7d/eHnPWmuWT6QQTwxhATuWvD0OB6E0ZiscTGaP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ThwF9z+LWQ3WEYWOTJe1ecI22ydI2zAue0O9scj5g4LXrB9ppzT3HuxldkwZfBUtnsAs7rJx5pzhz9K1f6zRQDO0uuOQKo79ROjwFlKBhnybqqDyhU7yYWcuHGbv4TOaAVKhcMSYX+DsyXOSUPJi/enc8XbOJFVo4yT4Q6Dnx5AirhPBZ/JK0fgEMFYmUqVYPbtSUHa9grTHA+YDdystMY+Qz22B2TEcGdyp82UTqYu2NqJn+46j9Q/I/kaVLg+ARrdokADqP0PNBoQEk7c9T00S4WbLeq7PR6Ij/sAMYNc6KSG1p5fasfdZupXm88pn8usjotycCIHX01tDGNMKpkJnLpU4F7J9K5CQLtt57g/YSx2PA==; 5:VL6+e2tbOk1wlva3vbpVMmuwXCthoSynC7gs/Qk3lIoX6j/Dij1L1ZHTJ6MxOwCUQdHnABMhWWl2gKTy4qctl1yJz9yk5UNOYkpnhUtxzlKmVSVnjD6J2WBFDhfuSK5kROxd3wsa2XCln7es1RfUTSIXAtSBplETrOikPrDjxyM=; 7:MY/7NtO0xpOA2Iu48683pnISMcuaxP1s5VU7HvBuxkASW46Y+p2IzbfD16/ojr2CC+W+7G7zcMWgDQnjLDDKn6eZ6M1a0ravql9mgD3YOls5FDH6lObI88QtOtpyG8G+tTj2J52vc+KvYB68hlvCaPPeGTND/903DG06nrIpKRpww3nqu72UAbkWxQMcpohfgQ0NDSUF8Hq+oJkTeZYLrdocIzTO3ELG79tyLWiNhD2jporlVnHPknpe8ZlmTI4u SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM6PR05MB4588; 20:sAcsIwm42IAkINF/XfyG+hOGJdztCGTss5nZ7rMU6FD7EwXpdf/qTsJeXpdqTBWB77PRry9zP8MfphBTmXVFTMJ/juAFZusS1Wg0itJhJz/t2R10nF8OSbClSNknCBhrSrhQZKbqwB9du5Xw1uYdXXTCFkSjxy7U3I4wDS1fvSw= X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Sep 2018 16:19:22.9223 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d3cc96e4-0daa-472a-f9d2-08d623cbd291 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR05MB4588 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Hellstrom , linux-graphics-maintainer@vmware.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Identically to how we look up ttm base objects witout reference, provide the same functionality to vmw user buffer objects which derive from them. Signed-off-by: Thomas Hellstrom Reviewed-by: Sinclair Yeh --- drivers/gpu/drm/vmwgfx/vmwgfx_bo.c | 41 +++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 12 +++++++++++ 2 files changed, 53 insertions(+) diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c index d80801d41f69..2defb8b751ae 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c @@ -921,6 +921,47 @@ int vmw_user_bo_lookup(struct ttm_object_file *tfile, return 0; } +/** + * vmw_user_bo_noref_lookup - Look up a vmw user buffer object without reference + * @tfile: The TTM object file the handle is registered with. + * @handle: The user buffer object handle. + * + * This function looks up a struct vmw_user_bo and returns a pointer to the + * struct vmw_buffer_object it derives from without refcounting the pointer. + * The returned pointer is only valid until vmw_user_bo_noref_release() is + * called, and the object pointed to by the returned pointer may be doomed. + * Any persistent usage of the object requires a refcount to be taken using + * ttm_bo_reference_unless_doomed(). Iff this function returns successfully it + * needs to be paired with vmw_user_bo_noref_release() and no sleeping- + * or scheduling functions may be called inbetween these function calls. + * + * Return: A struct vmw_buffer_object pointer if successful or negative + * error pointer on failure. + */ +struct vmw_buffer_object * +vmw_user_bo_noref_lookup(struct ttm_object_file *tfile, u32 handle) +{ + struct vmw_user_buffer_object *vmw_user_bo; + struct ttm_base_object *base; + + base = ttm_base_object_noref_lookup(tfile, handle); + if (!base) { + DRM_ERROR("Invalid buffer object handle 0x%08lx.\n", + (unsigned long)handle); + return ERR_PTR(-ESRCH); + } + + if (unlikely(ttm_base_object_type(base) != ttm_buffer_type)) { + ttm_base_object_noref_release(); + DRM_ERROR("Invalid buffer object handle 0x%08lx.\n", + (unsigned long)handle); + return ERR_PTR(-EINVAL); + } + + vmw_user_bo = container_of(base, struct vmw_user_buffer_object, + prime.base); + return &vmw_user_bo->vbo; +} /** * vmw_user_bo_reference - Open a handle to a vmw user buffer object. diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h index dc6a3151fb06..ebb2ae86d900 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h @@ -772,6 +772,18 @@ extern void vmw_bo_unmap(struct vmw_buffer_object *vbo); extern void vmw_bo_move_notify(struct ttm_buffer_object *bo, struct ttm_mem_reg *mem); extern void vmw_bo_swap_notify(struct ttm_buffer_object *bo); +extern struct vmw_buffer_object * +vmw_user_bo_noref_lookup(struct ttm_object_file *tfile, u32 handle); + +/** + * vmw_user_bo_noref_release - release a buffer object pointer looked up + * without reference + */ +static inline void vmw_user_bo_noref_release(void) +{ + ttm_base_object_noref_release(); +} + /** * Misc Ioctl functionality - vmwgfx_ioctl.c