Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp722765rdb; Fri, 26 Jan 2024 08:44:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IFG9QyZLkOXDf4UGMfFhWm/ek6BFYbwwOe0Lpxqw0cHveeWwshBZUj+SX221FNrWDN/DzYR X-Received: by 2002:a62:61c6:0:b0:6dd:a119:dca2 with SMTP id v189-20020a6261c6000000b006dda119dca2mr62668pfb.51.1706287456090; Fri, 26 Jan 2024 08:44:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706287456; cv=pass; d=google.com; s=arc-20160816; b=04nh93/DFeYYDtQASbKsczuUNL4LYG9UE9qUYwHi8jjsVY6MY94HoJ3pG0ooCFppNV CWm43nO+3Xc3x5RqGMkeUpvQzRKiXmtLbCKlPBuVDMqr9g56SroDjcWM6ZN/mke5S1PR FyGdn3t53Cgb2TE7GXQiH6UTCNZqBrBuLk0zT+iayjD+pggXkWuL9fxJqJBS+XOqVugf t6WFHxz5bzmHLvmZiYyU8ZzdSxm3MQvy3cBVTgEYM0XShFiINKIuHIIhJ9nSMF4QRNH8 LBVEoI3FjFLNZQfjHIDfGVcHfRrhGG3uMMh6C8YILo/TKLORSejmqxuKA90+N3CIPyQL s4Pw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=fsoujJJCZnEHSsAOWLqRb91f1Ri2fBpjc6OaUm47gek=; fh=mUS0I9sd7n8PQb4RDUIMUCm88ey1ZFqYqCJXuio7Evs=; b=JHFn4KVVv6Bp+OBEV16H/2uFAnb7IzK2PKO5bTcLd39FUCdwNuqscbk3RH5b7Xi5l6 UANhJO7tJwZ5IWLKuULAtWfmY85plGIsypRalzPtDqs5KeIHhirDRfr6ysTVKyVv+EOm kken4Y+HdijDWWigTomXHU/VM6nkJlCsWA+HMiMdTCsgnqBw+Zl1hd4MWycgJqetKDmu c/1tv2q4RDgxc9BiBW7on7j5OeFnGkndqE7wS/cM2KclkaTGReAgrGjj1gPrUx0WJojR renyMl251uPAdBIDkIw5JeehCQvhNQeHGA3J657PsHnAeldsfMwU6no+PoN2a7UP2+fx /bkQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=KeswJROh; 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-40366-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40366-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id v18-20020aa78512000000b006dd9e880040si1400255pfn.249.2024.01.26.08.44.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 08:44:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-40366-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=KeswJROh; 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-40366-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40366-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 603F62829B3 for ; Fri, 26 Jan 2024 16:44:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ACD071DFD2; Fri, 26 Jan 2024 16:43:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="KeswJROh" 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 3D4701DDEC for ; Fri, 26 Jan 2024 16:43:35 +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=1706287416; cv=none; b=P+vzovN7/dvz8hiCGD3ZdCne5b1pVgRhsl2E/U3j88irXG/U8ipKOGXQpyWIxp3mo034IuWOxHrzbtNXUS4FexFBCh1BnmQQfblxHIesgju9Q3ZWzHj8pw00yQTNr9HvLNillmtO6jHSrHrb/E/QXEUxun5+qpI9vfOlj4sj/Qg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706287416; c=relaxed/simple; bh=U6u3xgf4R+utqvmtwCD7pg1WXxuAovEW7noxe87GDmw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=RYEFT73SKWOgerOq8zFB1pUR6XSnTgm2hG3DK4A82OHnGKYcW3mEr9tX6s6dnabXS+W9io3ZWdkk9NT5n9q/ihHNjv4fMgohRQEl7cODVx42VOv9angDTadGryfpce3OADvsQRkoLqPKUtFQcg7LWoj+64uZ5bg8FtelLPcf/qI= 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=KeswJROh; 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=1706287413; bh=U6u3xgf4R+utqvmtwCD7pg1WXxuAovEW7noxe87GDmw=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=KeswJROhwGGRCE5tdZ1RC8zLadqOPmPE3UK2Yj5P5hgbG7FBPfNCxYkwMYNE+SKwd DX6GBQiHWaaIhiby6QrQjjW1qb01imlJGar0H58w0ZXPj4Ig74w7iN/dBhp+rCJMfp U1x8qHsm+S8XWiZe2bhGxGBqyOwVSlqtEjRf6THeYOgu8ceW/2h9FNH4SNQSYPgC2Q vCcyVSZzLEGNQ9Kz0Z1aRA19OxbfqZAcasBM+kXiB2wYcSGMwQcTvSXkvwS+pTKH1R Iove7Or8j6Dtwzb+a5PJc70/zZs8HnXriVfNq36SpeachhYK8w6V4KaLxjrNApzXXy 7oqzT/l5MaLNA== Received: from [100.109.49.129] (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dmitry.osipenko) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 0146F378201D; Fri, 26 Jan 2024 16:43:31 +0000 (UTC) Message-ID: Date: Fri, 26 Jan 2024 19:43:29 +0300 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v19 09/30] drm/shmem-helper: Add and use lockless drm_gem_shmem_get_pages() Content-Language: en-US To: Boris Brezillon , Daniel Vetter Cc: David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , =?UTF-8?Q?Christian_K=C3=B6nig?= , 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 References: <20240105184624.508603-1-dmitry.osipenko@collabora.com> <20240105184624.508603-10-dmitry.osipenko@collabora.com> <20240126111827.70f8726c@collabora.com> From: Dmitry Osipenko In-Reply-To: <20240126111827.70f8726c@collabora.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 1/26/24 13:18, Boris Brezillon wrote: > 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. For Panthor the might_lock indeed won't be a appropriate, thanks for reminding about it. I'll add explanatory comment to the code. -- Best regards, Dmitry