From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE7D9C64ED8 for ; Mon, 27 Feb 2023 18:37:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 171A36B007E; Mon, 27 Feb 2023 13:37:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1231E6B0080; Mon, 27 Feb 2023 13:37:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F2BB06B0081; Mon, 27 Feb 2023 13:37:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id E31B26B007E for ; Mon, 27 Feb 2023 13:37:11 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 87C6A160B3D for ; Mon, 27 Feb 2023 18:37:11 +0000 (UTC) X-FDA: 80513929062.22.5E9D196 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf10.hostedemail.com (Postfix) with ESMTP id 6CED8C0021 for ; Mon, 27 Feb 2023 18:37:07 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=DYZiatxM; spf=none (imf10.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677523027; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=jYT+cGJBvQcrrjhbci0ohC6UHJhkTcwfc27DUKpdpjo=; b=0aj8sNR7bHfJJv+E6U5akqkq7NEu1p+kh5pC/NFf6e52gwLrdBO3syBvmpx2YjE75vulVM s0MYrVyNN8X1vnQn15h2tHUevgX1u38tWxTJSl9pH9O3AzpqL9wABlhz364vk8m/Us1laB HqyTlHuoJ50g/fH4I9qqn455WhFh7Ks= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=DYZiatxM; spf=none (imf10.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677523027; a=rsa-sha256; cv=none; b=Mm3iPulsviB3k4LR+S0rtzyN2mlGhNgT72TOuHYLeJeLA/UnBdmHYE9evQGyE9VGFuSxby lUoPL0sXOIT4egBt6RJofM5bAz9L6UtV/VUVcbljUrDsqS1qXHAR+KaYTrL7QnHhVqEE4I oG6WBkFmPzIdxi3e58FtvgfwQM4cg3c= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=jYT+cGJBvQcrrjhbci0ohC6UHJhkTcwfc27DUKpdpjo=; b=DYZiatxMcGzMStxHrkjOwq1K3C tSf8vNX+Z9nv50rokR5GAdnOs9ehEfqo6HT16BCOr/D7Qw678un7eK9IvP7AZUI4PSjmQC5vGs/6e i4MNwKGONuiZB89KQYE8FJOmqwLEGJrOyLEeXpxMK5MOErpyQNinxWNY06mEtRA81ojSQMLJgJax/ FCkMOylQgSg7TepXBGpoWBilkjiAnckITPS124OWuMV/f8tfETAkxHC3YCTuXXpwm7FCBhKFQWn+X EjT1SPnMy8IzDGwfW6ujMPWMprMba8gkcVh2oerkNgYxV6FX08XNhLHEh3N3B1pqhhJyTevC/CL2Q C93Lx7Tw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pWiMi-000Jv6-NK; Mon, 27 Feb 2023 18:36:48 +0000 Date: Mon, 27 Feb 2023 18:36:48 +0000 From: Matthew Wilcox To: Danilo Krummrich Cc: matthew.brost@intel.com, dri-devel@lists.freedesktop.org, corbet@lwn.net, nouveau@lists.freedesktop.org, ogabbay@kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, boris.brezillon@collabora.com, bskeggs@redhat.com, tzimmermann@suse.de, Liam.Howlett@oracle.com, bagasdotme@gmail.com, christian.koenig@amd.com, jason@jlekstrand.net Subject: Re: [PATCH drm-next v2 04/16] maple_tree: add flag MT_FLAGS_LOCK_NONE Message-ID: References: <20230217134422.14116-1-dakr@redhat.com> <20230217134422.14116-5-dakr@redhat.com> <3bb02ec3-4d19-9135-cabc-26ed210f7396@redhat.com> <67942a68-2ae7-8883-25d7-c6d595c3587e@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <67942a68-2ae7-8883-25d7-c6d595c3587e@redhat.com> X-Rspamd-Queue-Id: 6CED8C0021 X-Stat-Signature: yiybmj5qyscsfu4fx51jpdceddx5c3ja X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1677523027-967221 X-HE-Meta: U2FsdGVkX1/WtoruPwVzjP72AaaqRvGSD7q1Nns8YS5pz4LY1asUeOZh06qXNkmAY3pN4r/sALqBy1AWaWBeSVkDisHdjlcm860etM6VDJxLI3Y4nJT6P7ldtOjMAV8mTY0GtVbAeEVwaPL7B0OEn0BIlheKxxJf21O4pHQ9ULezQ7YH8PfON1RnYvVtl38sOq9gTO9l9Ht9LEWZ3OFXlnuuCiYfutJU9Sdi0UUwu5nK4DIqV2cDaL3WXPeOif7JuP1pLmpGYiM51WxV4mXRDUq0mI3ZYUncPmWEccqKv0laY4bFaoqLEU4PQIfZLSAOsfSqn03ZiFQV5tPkbNv/GBcxQevjlj/y/u40lIw52mmQ7rrQy+6hHb0HsN0hQfdAcYcVZ30Rex1JWteSr2O9TQpChIkj2aExGKJZ6NbgrM9/WOgqAtxKp9f0FpIOCijYfpj6iM45n1hSJLVRKHagt/ds0oELe+MTFjd8Ae9SAl/VWVSRR85t6tbKT1nAL2IFJ/jx0a/SfmoVxqokJNDpgczH0QGvmgBSaHu53e4UpSZtgQ2lTUt41C9vnMtOoLt/BQ30kYrv+i5EBgojqHHhCQdFEdJZvbjRoLrAqhvN/hXsr3lejxB8Bcba+JK64Vq8lasLnjYizj28zOnVmF377XFYTV2Qh3MKcx1FBbJOfaarro6+quOMzf3/EFGX79ZKu2Q+LV5s7ZdVvAe8NZncRwdg0tmSioPU0+7tuY01piZoLH0UH7x069ue/GRjmTRg64hYdIiYhoQzz6Dss/SL3V9Iau6Yevibz4PddJrDAUKEAYf/kpHuMos1wZVaZwswkwTbBYkhRz/gf9PB8fbP7nPYiObtLE04hzmf8/an90voze2B90aembdUgsDmfP6dcdlUt1OQisArq/nytjCXk0v9PbGYrwsWobE+nJcEKXkpcxX8R+JOcSDALdWgj4tO92qbwWCQexuGBA1nXNQ /H26J6Lf LFxaeCR1I/9/UWQHZYQXPlxwkxKT++IfmB5fYuHy3JpE9vmodU36xQA6rcBdmqS29RjFHoPD5qEV70VngT1t0hVFPXRyviD1jFLNjRSWOAS23fSOtiZ33YeM3XimeD66bk+t++SgbKZBJ1rysI1fxZTJjloomnN35o/SVdYeEURu0P5WPohD2V8S2NLgEvrct2akUuht7FW32+MA= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Feb 27, 2023 at 06:39:33PM +0100, Danilo Krummrich wrote: > On 2/21/23 19:31, Matthew Wilcox wrote: > > Lockdep will shout at you if you get it wrong ;-) But you can safely > > take the spinlock before calling mas_store_gfp(GFP_KERNEL) because > > mas_nomem() knows to drop the lock before doing a sleeping allocation. > > Essentially you're open-coding mtree_store_range() but doing your own > > thing in addition to the store. > > As already mentioned, I went with your advice to just take the maple tree's > internal spinlock within the GPUVA manager and leave all the other locking > to the drivers as intended. > > However, I run into the case that lockdep shouts at me for not taking the > spinlock before calling mas_find() in the iterator macros. > > Now, I definitely don't want to let the drivers take the maple tree's > spinlock before they use the iterator macro. Of course, drivers shouldn't > even know about the underlying maple tree of the GPUVA manager. > > One way to make lockdep happy in this case seems to be taking the spinlock > right before mas_find() and drop it right after for each iteration. While we don't have any lockdep checking of this, you really shouldn't be using an iterator if you're going to drop the lock between invocations. The iterator points into the tree, so you need to invalidate the iterator any time you drop the lock. You don't have to use a spinlock to do a read iteration. You can just take the rcu_read_lock() around your iteration, as long as you can tolerate the mild inconsistencies that RCU permits.