Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4676934rdh; Wed, 29 Nov 2023 07:47:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IEd8oqYpqIb5CCR/Cr7LJSpbZ4GTlwfxj3Blufg4q/dQSVeo43abtYOnGo+2u8MEQy3ij/2 X-Received: by 2002:a17:903:234c:b0:1cf:f624:a659 with SMTP id c12-20020a170903234c00b001cff624a659mr6850466plh.22.1701272842350; Wed, 29 Nov 2023 07:47:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701272842; cv=none; d=google.com; s=arc-20160816; b=dDwK64r6oCWiggVQJ+m410KdhuJ3Y9iiWiH4Ze1VqZ3u8rRPl4lky3OGwXSDNj9IIy Ra/vJ2740/PHqjEq10vo2jhOAOIiUh+kXfF+8Cd8p7ZLQT28LePD49Mf6/YIlxwX0DWh jsPN2iKN8XKIIKMjHNT34IJzHKbFPQQwulUSyafpIDVFcJ992Md0640pmWsSnENyi7/e gnLvKR0WjRw8MQw4F5o1xVfVXzeIfO6rcQadw/8c8tlWIh8/uxosvtDp2qhMCWeYn+cM kx1fR8GN4VIJpd+ac5YIdxAVXN4Ts8WomxAFcERu6CL2sX0N9b6nF/XWaVyBTJXS1slC hRWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=LDjfigxP7BGB77XL1UxmaZG6zEXFGl8wdO3iedVNxrk=; fh=rOQ1HqpWfZmnkgceeCAihfSg1Psee71TXRVGXaAZhes=; b=jdXA+CggWjW1kLRq1jRBkzYHmyJgqcOuV1HrLU8WlCHY/xiZq0ePi9IH5uQ1QBFOga +J2uex19bhj0laUIh6PEZu91K95u+gN5EeiZlZu+XniqpXYtn/7xAtu0NgaMWVAZ1dPc ebuKfHcXUtTJTxuqsAeqS8HVYrkVKthvbO36UxqZWCE0qKV6kgfbsgH05ytxXytiu12I 1Gx3k6fu7R6M2FcjqsuxSKtiFtQOikzlMln0vXTNyMK7pismB6MgiZ8L+482D00pcjbz 0iQUwR7Ke1HKaf0gOaxHvDKX/iyr7JwxStN8mjvZKn+8kty9R9xTFwVgFy0uKgrqOaBs Begg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=aUmILl2r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id i11-20020a17090332cb00b001cfc9894958si8280881plr.379.2023.11.29.07.47.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 07:47:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=aUmILl2r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id DF9CB802FB96; Wed, 29 Nov 2023 07:47:20 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235024AbjK2PrJ (ORCPT + 99 others); Wed, 29 Nov 2023 10:47:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235004AbjK2PrF (ORCPT ); Wed, 29 Nov 2023 10:47:05 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD21210D3 for ; Wed, 29 Nov 2023 07:47:11 -0800 (PST) Received: from localhost (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bbrezillon) by madras.collabora.co.uk (Postfix) with ESMTPSA id 1B8466602F24; Wed, 29 Nov 2023 15:47:09 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1701272830; bh=9UgtxghB5ZsKV/j1SgrmWTsqD9lNpLOncvoxfSi/wv0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=aUmILl2rTZ4ng0+NeRJ11u7hvQIAvX5CbKqyxTC/gDzr+OF8drVqd8JmJtlM0vLTB 8mKREqaa9vvPJp0a7ug5iVFBMSuxY/nvQiSd3fBNQoVP6SdBB2FwnYbh6U8aR6kszY AEb/xAJ1jtcs+ZWh5uSJOz8SMxc0EtfiFo8eA2Aq7CnV+057lYtef9n/Hxy81Ksxv8 gciTffEVC2xJ120AKYuN75FY6s1+fsTmkEuCoEJtsZ2cHDxnpqNeQwqQuZt2z2ToUe 9XbxNe+tEUsHOV2Z3t+wMi+U0kvbrr6Olt4iL6XArGnnSfzSQmmvCaK0Lgw9kukVDa MBngokkWdluvA== Date: Wed, 29 Nov 2023 16:47:05 +0100 From: Boris Brezillon To: Maxime Ripard Cc: Dmitry Osipenko , David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Daniel Vetter , Maarten Lankhorst , Thomas Zimmermann , Christian =?UTF-8?B?S8O2bmln?= , Qiang Yu , Steven Price , Emma Anholt , Melissa Wen , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel@collabora.com, virtualization@lists.linux-foundation.org Subject: Re: [PATCH v18 04/26] drm/shmem-helper: Refactor locked/unlocked functions Message-ID: <20231129164705.7461a294@collabora.com> In-Reply-To: <6da6mzwfzwbn5rhiebypo5e2v6rhtpn2fovwvfnoo333zjgobf@bgtuwhum3trp> References: <20231029230205.93277-1-dmitry.osipenko@collabora.com> <20231029230205.93277-5-dmitry.osipenko@collabora.com> <20231124115911.79ab24af@collabora.com> <20231128133712.53a6f6cb@collabora.com> <37208c72-7908-0a78-fc89-2fa9b8d756a5@collabora.com> <20231129085330.7ccb35d3@collabora.com> <20231129144609.7544e773@collabora.com> <6da6mzwfzwbn5rhiebypo5e2v6rhtpn2fovwvfnoo333zjgobf@bgtuwhum3trp> Organization: Collabora X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 29 Nov 2023 07:47:21 -0800 (PST) On Wed, 29 Nov 2023 16:15:27 +0100 Maxime Ripard wrote: > > Now, let's assume we drop the _locked() suffix on > > drm_gem_shmem_v[un]map(), but keep it on other helpers that need both > > variants. This results in an inconsistent naming scheme inside the > > same source file, which I find utterly confusing. > > > > Note that the initial reason I asked Dmitry if he could add the > > _locked suffix to drm_gem_shmem_vmap() is because I started using > > drm_gem_shmem_vmap() in powervr, before realizing this version wasn't > > taking the lock, and I should have used drm_gem_vmap_unlocked() > > instead, so this is not something I'm making up. > > Sorry if I gave you the impression I thought that you're making that up, > I'm not. > > Thanks for the explanation btw, I think I get what you're saying now: > > - drm_gem_shmem_vmap() is never taking the locks because the core > expects to take them before calling them. > > - drm_gem_shmem_vunmap() is never taking the locks because the core > expects to take them before calling them. Correct. > > - Some other code path can still call those helpers in drivers, and the > locking isn't handled by the core anymore. They can, if they want to v[un]map a BO and they already acquired the GEM resv lock. But I'm not sure anyone needs to do that yet. The main reason for exposing these helpers is if one driver needs to overload the default gem_shmem_funcs. > > - We now have _vmap/vunmap_unlocked functions to take those locks for > those code paths We don't have drm_gem_shmem_vmap/vunmap_unlocked(), we have drm_gem_shmem_vmap/vunmap_locked(), which can be called directly, but are mainly used to populate the drm_gem_object_funcs vtable. If drivers want to v[un]map in a path where the resv lock is not held, they should call drm_gem_vmap/vunmap_unlocked() (which are renamed drm_gem_vmap/vunmap() in patch 1 of this series). Mind the **drm_gem_** vs **drm_gem_shmem_** difference in the helper names. drm_gem_ helpers are provided by drm_gem.c and call drm_gem_object_funcs callback, which are supposed to be populated with drm_gem_shmem helpers. > > - And the variant names are now confusing, making people use the > lockless version in situations where they should have use the locked > one. That's what happened to me, at least. > > Is that a correct summary? Almost ;-). > > If so, then I agree that we need to change the name. Cool. > > We discussed it some more on IRC, and we agree that the "default" > function should handle the locking properly and that's what the most > common case should use. Agree if by 'default' you mean the lock is always acquired by the helper, not 'let's decide based on what users do most of the time with this specific helper', because otherwise we'd be back to a situation where the name doesn't clearly encode the function behavior. > > So that means than drm_gem_shmem_vmap/vunmap() should take the lock > itself, and drm_gem_shmem_vmap/vunmap_nolock/unlocked never does. Not sure we have a need for drm_gem_shmem_vmap/vunmap(), but if we ever add such helpers, they would acquire the resv lock, indeed. Just to be clear, _nolock == _locked in the current semantics :-). _nolock means 'don't take the lock', and _locked means 'lock is already held'. > > I think I'd prefer the nolock variant over unlocked still. Okay, that means s/_locked/_nolock/ in drm_gem_shmem_helpers.{c,h}, I guess. > > And I also think we can improve the documentation and add lockdep calls Lockdep asserts are already there, I think. > to make sure that the difference between variants is clear in the doc, > and if someone still get confused we can catch it. > > Does that sound like a plan? Assuming I understood it correctly, yes. Can you just confirm my understanding is correct though? Regards, Boris