Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp514294rdb; Fri, 26 Jan 2024 02:35:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IHjrSRx+K5f8hbqiMYPKcJPT4Um82K0mn4WBxf9iURqXw0K28b3ibdRQ3945wHjxJhnm4I0 X-Received: by 2002:a05:6214:4111:b0:682:24b1:4e34 with SMTP id kc17-20020a056214411100b0068224b14e34mr1168862qvb.64.1706265343727; Fri, 26 Jan 2024 02:35:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706265343; cv=pass; d=google.com; s=arc-20160816; b=R5gatn/qn43rXTqL++MVg4cg5Wu3lskmi9L25xKl4A91dZCRhSVTeg3jr9NNMbXIT9 8aIzKUo5WPzPuGsWw0XM4Hj1OvV6Zk9trVV8Oo9Nf1kRncW6EaK69tIynfEsvzWWcuhg xtBKRXzdegg7pq2qmrf6ZGz/446k3tif65e1PipLRxfE7orF/cc073MhoJj/dWLTwuw4 FaMkZWowPvRZUsyuXvknwaWC6H8PftB1jAG3looqz/mm+oObCmbIi2MB571vyTQ3eT8Y 5lE16GGFlU+Qej9UIk7wwIS/qcDaDvEntJhYCLVbFSBtEs2h295DRkGk675BbvlVXwfp 7HlQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:organization:references :in-reply-to:message-id:subject:cc:to:from:date:dkim-signature; bh=EZlaeRmvvgdjWcI6yI5UuHe9ZwT1hMYqKQ69FNFPkOU=; fh=YRbtOGJj27IcZTpfa2kmsNwRQgyCW2hxMiEIrmCqiJY=; b=p190nnHZjf51VLydl22+r5xKXwJm5kc64PmPteYLT0Apj9CQFmvVDhczlM0AgqTXqE 38rAD5CHIuJ20payRVBhjqjIk83zLv19+ueKat05hg8+sFow2yR49kzwO7BNOiaZo7cW Cx/bPtA8oNGxihM5ZtQ/97BgFfVQuKr2ZMP+FkMBBloRBr4z7K/hIS6vjKhShVVKwDXA 8fE0DZAC895rE1MQmsZZBJAtIjwt1ShYj6ebrBa5dQNLuDL9vu8f0aWmdSrkaN/lKDt5 B/TfIZuKhkoGAMoU5bywsb8ga6zPP0dsYbR+WMwACehnRfEhVLOmdHdrYaclOsmGyLS0 lDcg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=ionVzzYU; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-39993-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39993-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id iu2-20020ad45cc2000000b0067ed2267b72si1010574qvb.275.2024.01.26.02.35.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 02:35:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-39993-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=ionVzzYU; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-39993-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39993-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 9E9531C288B2 for ; Fri, 26 Jan 2024 10:32:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1E4791EA71; Fri, 26 Jan 2024 10:18:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="ionVzzYU" Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 95B331DFFB for ; Fri, 26 Jan 2024 10:18:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706264315; cv=none; b=jIxY1/Xd46k0Z4tjm+e5RoegJx6L9WMhTXcum+IzdTl1DbkRrq7D309WB3cJaSyRQ8UglpEgQYN/povRE7edEGkdP3h7Q3zWxqC6AqDLL5oOp0vwpEFlou+IAF0jycGxB7s87O5YeyAiq74FS8B/GHRb4D9rRtKWDYfktDKbXpI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706264315; c=relaxed/simple; bh=hqYTK0EsC3o/io3T1zeWVHK+9pLIv8eop9reCP1H12I=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ExWa2ZpeU98QR8YYyM6fqMTDDfJxmGwSuIbjQZQj/JBdpLoFXm2rg/Olck1kRFgp9paqlDnImKexccveAf1sp/BjsBgtYR9RmsEsZL6zVfZvAAM8ZyBt3xIFQVygpEJus791JnIKUjmCkX44PYyGy5lS8FW4zHYr1PHS24uzGds= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=ionVzzYU; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706264310; bh=hqYTK0EsC3o/io3T1zeWVHK+9pLIv8eop9reCP1H12I=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=ionVzzYUVohq/prvhL2Jplfp6RkWMX6N92pnga5WmXEKfX3WWE3wisdops+KV3ifp Uy5+PNmkF5un43C8farXeu6d+mw/XXMFTa98cPOyEm3NUm+NQKX+R0usEfm+yjMQH7 khbw3xEeIDeVPaZKmrCynwWqSZpQ8Oc02kg3PrHM1X2oQ8dpeIENT27v27zWpVX2i/ WQroAxJl0yGuCyjeLxf+oFMJh6VulBj4FrURTI1vV2T8AWII+/P76KkX9I5zEaC6P4 zYwV4SGEyo23NTgEBHBcWqv359YkS3edA2waZUh4Gg+h+o2W0wxJH43MTurEDDpU2u SOvR1OO9/OPJw== 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 madrid.collaboradmins.com (Postfix) with ESMTPSA id 420D63782072; Fri, 26 Jan 2024 10:18:29 +0000 (UTC) Date: Fri, 26 Jan 2024 11:18:27 +0100 From: Boris Brezillon To: Daniel Vetter Cc: Dmitry Osipenko , David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Maarten Lankhorst , Maxime Ripard , 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 v19 09/30] drm/shmem-helper: Add and use lockless drm_gem_shmem_get_pages() Message-ID: <20240126111827.70f8726c@collabora.com> In-Reply-To: References: <20240105184624.508603-1-dmitry.osipenko@collabora.com> <20240105184624.508603-10-dmitry.osipenko@collabora.com> Organization: Collabora X-Mailer: Claws Mail 4.2.0 (GTK 3.24.38; x86_64-redhat-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 25 Jan 2024 18:24:04 +0100 Daniel Vetter wrote: > On Fri, Jan 05, 2024 at 09:46:03PM +0300, Dmitry Osipenko wrote: > > Add lockless drm_gem_shmem_get_pages() helper that skips taking reservation > > lock if pages_use_count is non-zero, leveraging from atomicity of the > > refcount_t. Make drm_gem_shmem_mmap() to utilize the new helper. > > > > Acked-by: Maxime Ripard > > Reviewed-by: Boris Brezillon > > Suggested-by: Boris Brezillon > > Signed-off-by: Dmitry Osipenko > > --- > > drivers/gpu/drm/drm_gem_shmem_helper.c | 19 +++++++++++++++---- > > 1 file changed, 15 insertions(+), 4 deletions(-) > > > > diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c > > index cacf0f8c42e2..1c032513abf1 100644 > > --- a/drivers/gpu/drm/drm_gem_shmem_helper.c > > +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c > > @@ -226,6 +226,20 @@ void drm_gem_shmem_put_pages_locked(struct drm_gem_shmem_object *shmem) > > } > > EXPORT_SYMBOL_GPL(drm_gem_shmem_put_pages_locked); > > > > +static int drm_gem_shmem_get_pages(struct drm_gem_shmem_object *shmem) > > +{ > > + int ret; > > Just random drive-by comment: a might_lock annotation here might be good, > or people could hit some really interesting bugs that are rather hard to > reproduce ... Actually, being able to acquire a ref in a dma-signalling path on an object we know for sure already has refcount >= 1 (because we previously acquired a ref in a path where dma_resv_lock() was allowed), was the primary reason I suggested moving to this atomic-refcount approach. In the meantime, drm_gpuvm has evolved in a way that allows me to not take the ref in the dma-signalling path (the gpuvm_bo object now holds the ref, and it's acquired/released outside the dma-signalling path). Not saying we shouldn't add this might_lock(), but others might have good reasons to have this function called in a path where locking is not allowed.