From patchwork Wed Sep 26 16:18:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Hellstrom X-Patchwork-Id: 10616153 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 747E114BD for ; Wed, 26 Sep 2018 16:20:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 643AD2B461 for ; Wed, 26 Sep 2018 16:20:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 61E102B463; Wed, 26 Sep 2018 16:20:35 +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=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 B4C0528F89 for ; Wed, 26 Sep 2018 16:20:19 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D98B06E4BA; Wed, 26 Sep 2018 16:19:45 +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-dm3nam03on0087.outbound.protection.outlook.com [104.47.41.87]) by gabe.freedesktop.org (Postfix) with ESMTPS id F3A316E4AE for ; Wed, 26 Sep 2018 16:19:20 +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:18 +0000 From: Thomas Hellstrom To: dri-devel@lists.freedesktop.org Subject: [PATCH -next 11/18] drm/ttm: Look up objects without taking a reference Date: Wed, 26 Sep 2018 18:18:32 +0200 Message-Id: <20180926161839.4549-11-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: 236a849c-3e4a-4967-6c25-08d623cbcff2 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:76bQil8WgxqsI74TrkaIRXc8Eb/TGDIYIE0au6eMBJR/m2qvSrWzOvxO1EwSHPZdgfUBgmdlweW1ffhcQmQKXqBncoXNHtGJgc3EY7F/BCUUlbBvYCTdX+cUi5Ei6BiJUVLdcHXvittbjlGQcwvmNq9TB5MelyQLtb+1YWGYuOJHYjrBg0vsKNHFETciuuuJqJTult/wGP5NkbRvrSLGXEo9LhqUexan5tRN8pO08+ZMBIGtvpDO5IXkVIBx1BQq; 25:86LGmTYJTgA2aKmZ3tohkd9KU8Yjj5Z7AoRSLdcFyd9SB4t9ZZj7v95cHt2oijCdeM9N3zqUQRMpJncuT11GCikrxLMRIYUzyt28UC1ROdb/W9wQya8G3Btnxl29+TmK50jLZq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UeKjF5SGQ3vVM1gm34CFoTJx3k2wkt8zQkg+nFbYc487z6q5snW4zLqaajRO5pFJ/s= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110)(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-Microsoft-Exchange-Diagnostics: 1; DM6PR05MB4588; 4:fMK5EGr+25vNsVn1Kat6Uj7WQcIrnjhJkMhR0XbdDWdRrPfUjmuU2m+/rWe+JM7o6NSIHmaxhNY/84PzNRz74rkyQM7sQPvPG6LS+0Fc7RolMYQW0TMA1heFBs9We0SXFvTqDnfP/lLg5yb2A6z7pmxCFTaWAef8h5iSt4qsCOR8yxVO6VAb+ybBmddnTPJWIAMP1ZhiXWGR4un7oKe4YxvoyBQfbtAD1NrUBkO52mvfK+OO/+jWbLGs9lJnzfWfzfmpOHfl2XL9P46hvAbq3xsLXvWVx40dXdlgHlnlcG1LX/yyBuuIfmVnvwdn0XSRdpqvcgChy4htQbh/Z+Thtw== X-Forefront-PRVS: 08076ABC99 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6069001)(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)(575784001)(97736004)(478600001)(68736007)(54906003)(50466002)(25786009)(8936002)(316002)(956004)(2616005)(386003)(76176011)(6506007)(3846002)(6916009)(1076002)(4326008)(8676002)(81166006)(50226002)(6116002)(23676004)(2870700001)(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: =?utf-8?q?1=3BDM6PR05MB4588=3B23=3AcZ77HrL?= =?utf-8?q?rKnaXIN+flCr9Gt0Yz1EEbTYz866Os5veGkFoj/w7hca5ZsL+cepYNMByjOdUKvsq?= =?utf-8?q?eb5QEWVI9eiMbgjORcyyi3iw+fcGXmiK7SjJ3XXkDgxZHQNvm79uorXImMyySIt4F?= =?utf-8?q?/M9AERIpb8ACf1ufbXjlvyYN+r5tZWhSmyfMMD9IvBnbvqYU1bA4t4C3YC4pW3KbL?= =?utf-8?q?LEb06viQDeTML+/uSeFU9Z9akwBm2KG+H+PpaYiiuzXLgIqcl6cqcts87oeG7KrqL?= =?utf-8?q?vLlQf4l607AHaB1VMELgnFQvKhtq8P2CTTZhnErawzDoL5CoOU0EwHuABo6EDLA5E?= =?utf-8?q?htKy+32RWRvki5xR31aJdgzUgy5NGgQn4CwKccImgZs+Jz/8UaYqHXywHP4CEYfa4?= =?utf-8?q?kZtnmoWisM80GDWZs9plYoDjbBtdu4jJhy9IKRUJqZCU/VLixK2hkIxcWeqb2I1W/?= =?utf-8?q?8Cb8mfEj4KOpCSsB5biMDMdkQP+XtxFUSYDrtksqwvozTuWcGWGv8lo/8SeO2QjhB?= =?utf-8?q?vcFphfxO5eWxc3fzdFhzGl5BR66dQ1qloWS/FE1BDUhSHrBuA2RqDUOeNBn+plM5V?= =?utf-8?q?F/KrPNgf1wkOCDpwtrcTqpjVemm+cFtMjc3pK02NuUEdwq+5gl7jQBSYntXjXCcrH?= =?utf-8?q?vNJ0G1niBt39D56oL1wgCbo611rLxRSX0f5EdGPlFO7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YH6j+NQ2P5YOKzW1ikq0zxBM9Xrk8jRJHf5A= X-Microsoft-Exchange-Diagnostics: 1; DM6PR05MB4588; 6:+wi6ezNz53WuV0LQjvLywFe3yhR4RGCrLyn5x8FHNE2LJpwPpslol/YXRanGHSXD72n2R/diEfTDrGPFgFg+aInEUatvNPfySWu10P0Vw1i2xrPo7kHftQDHCJx1JD6lLTxZAAj/m2cj05eChcpF4+eOSABsmOGU5KjPm3sGCOtcxKpwDXxp7vDtRczeqoox+/rt6YW78q+in4quAJ7VvUZ0RaYGFi2+uHqKwPS59PNJ46aTm8aB61aglnzUXvshf92NWinw/I3fdhcyh56XWtEQc77MbD68tBlGzwOIDBEhnvY4Woqb6pLpCFAdJU0+7Lx7GsYp/FUTMHyzjAdPEa3SwwYJ/p1q1axhHxAv6QI0144tUoQrXFi5Y0k8iMRQFmU3aMyQS+r6hmMScJAJLryJ9GG1rnIH/hrnkuAty57kb5QwJzrm4xoZE51PVK0beiiqaajnMKcnmYmcG2rOnw==; 5:U6NloQts/kU55QIp1iQASbnl1SyIedjpDb0eGCtp00HieUBvd3766X8E86xGD7JUNXg1APcHq0cRWYM3yJ7S95C32WtRM+ciPHJnQTMxLHJjtx3rJG0T1lU3dvOB3u5lfhSNTQVNrn+q4ynyIHzsArrJHj1ydhMPxm6gD8Q4FFI=; 7:aJ317DPzHERZjWZp5QYq8Dkcwyi7QvG0pCYGpWSsHDLxUnrwM7i6sm4V2VdOTW7gU+2opeMrS6hKEpYdW/iEdN+TvfYSV1dd1XwCaXVH7gw2UYPFRDdakh/UNQCAqArQHYW3c+6oXPExI4fp5Tr7glYHcedkH9atAToS3o4oPFteliui7e8DyzR3WNDc9rHtKgAbHSLkfCUx+A6gq+kjwfp3X5yY4VMKTUXMFQMyxldGjFOcjVZ8+woxI/a0dQyY SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM6PR05MB4588; 20:MHGGwx82EnCPOmde2Y3KDg9eCGoMvMw50cszcGs4ivbryR4oe3I/yg1hljbfp2ultngN0FbExgAIhArIfc5c9lSVAzCBxu4Jj+AMCG3mgOxFWuqZTWcL6G68m3R0HwKaNEa/Xtix6bc59cS6wbwBY2pQhobeWiz9pXE+znx+6/k= X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Sep 2018 16:19:18.3581 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 236a849c-3e4a-4967-6c25-08d623cbcff2 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, =?utf-8?q?Christian_K=C3=B6nig?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Typically when we look up objects under the rcu lock, we take a reference to make sure the returned object pointer is valid. Now provide a function to look up an object and instead of taking a reference to it, keep the rcu lock held when returning the object pointer. This means that the object pointer is valid as long as the rcu lock is held, but the object may be doomed (its refcount may be zero). Any persistent usage of the object pointer outside of the rcu lock requires a reference to be taken using kref_get_unless_zero(). Cc: Christian König Signed-off-by: Thomas Hellstrom Reviewed-by: Sinclair Yeh --- drivers/gpu/drm/ttm/ttm_object.c | 35 +++++++++++++++++++++++++++++++++++ include/drm/ttm/ttm_object.h | 15 +++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/drivers/gpu/drm/ttm/ttm_object.c b/drivers/gpu/drm/ttm/ttm_object.c index 0782c6280d9b..f1a5ea0babef 100644 --- a/drivers/gpu/drm/ttm/ttm_object.c +++ b/drivers/gpu/drm/ttm/ttm_object.c @@ -228,6 +228,41 @@ void ttm_base_object_unref(struct ttm_base_object **p_base) } EXPORT_SYMBOL(ttm_base_object_unref); +/** + * ttm_base_object_noref_lookup - look up a base object without reference + * @tfile: The struct ttm_object_file the object is registered with. + * @key: The object handle. + * + * This function looks up a ttm base object and returns a pointer to it + * without refcounting the pointer. The returned pointer is only valid + * until ttm_base_object_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 kref_get_unless_zero(). + * Iff this function returns successfully it needs to be paired with + * ttm_base_object_noref_release() and no sleeping- or scheduling functions + * may be called inbetween these function callse. + * + * Return: A pointer to the object if successful or NULL otherwise. + */ +struct ttm_base_object * +ttm_base_object_noref_lookup(struct ttm_object_file *tfile, uint32_t key) +{ + struct drm_hash_item *hash; + struct drm_open_hash *ht = &tfile->ref_hash[TTM_REF_USAGE]; + int ret; + + rcu_read_lock(); + ret = drm_ht_find_item_rcu(ht, key, &hash); + if (ret) { + rcu_read_unlock(); + return NULL; + } + + __release(RCU); + return drm_hash_entry(hash, struct ttm_ref_object, hash)->obj; +} +EXPORT_SYMBOL(ttm_base_object_noref_lookup); + struct ttm_base_object *ttm_base_object_lookup(struct ttm_object_file *tfile, uint32_t key) { diff --git a/include/drm/ttm/ttm_object.h b/include/drm/ttm/ttm_object.h index 6204acc2ebf4..e35538475840 100644 --- a/include/drm/ttm/ttm_object.h +++ b/include/drm/ttm/ttm_object.h @@ -358,4 +358,19 @@ extern int ttm_prime_handle_to_fd(struct ttm_object_file *tfile, * per idr. */ #define TTM_OBJ_EXTRA_SIZE 128 + +struct ttm_base_object * +ttm_base_object_noref_lookup(struct ttm_object_file *tfile, uint32_t key); + +/** + * ttm_base_object_noref_release - release a base object pointer looked up + * without reference + * + * Releases a base object pointer looked up with ttm_base_object_noref_lookup(). + */ +static inline void ttm_base_object_noref_release(void) +{ + __acquire(RCU); + rcu_read_unlock(); +} #endif