Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1608475rdb; Thu, 25 Jan 2024 00:09:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IHB02xRK/6iOBe4LSf7WTido/EYd4s+Kz724XIAvUtAzjsZijEZW/0fHcAUHwJHl9jf57CA X-Received: by 2002:a05:6a20:1608:b0:19b:211c:56b3 with SMTP id l8-20020a056a20160800b0019b211c56b3mr667502pzj.70.1706170178558; Thu, 25 Jan 2024 00:09:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706170178; cv=pass; d=google.com; s=arc-20160816; b=CbOPGB2nbT8onKOkjYMds6kD4hlSP/uteuxN5C21giMPyksSmBAn/RtHGumauXEYHM Vd409wdy+5HEwZNuj6qtfQYlyYOyvKNhQtLGaep2jH8aie0OL6IJDiYHPRMMFGgzpP7u i0QWOW3mSenvQ2U96vRzN3079bRGYr/JGzfbphaQxU5sIkidufchyPdknAigYmCTQ4JV ISjiae5EgiBZvnN9jkwkH0B3Na4nVebkjbxnLUJACUvzNlM2ZvilRrIn5pW3hR78M++d SI/oF9zd8XQkar1YxM5/TftJiQWDcJOfOCUM7Bm6VDB48VlOrGuqOFju662wFG2j86lw bjIQ== 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=aE06B33UcbxoAzRQ4Zy61zuiJOuyPf+ImENnaiwH9KU=; fh=uxLNaPoPRUzmkUc1KOgGwCEU/bTSjK8Yed2Up6ovXLY=; b=RWdkVEk9q5SbkfyryWo0Rig37zKG3CNmm3md4IwLMGNkGc+QAafZ4sDzwz1L3W4PZl bgysO0esNTT3Y/gD02/+fZwMBTh5snkojVJguLzfDU9SnrafwNFFskhXcoMy4TR5ec41 6jHR1hLq/uWFhdHRySDSrE7dW4hnr806A5FvgCEWRnI0Nz1gA5QzEkXl5I+iEz49KSwC +mCnEK/PRnBujji3IJ6jR8G3NftHWCZRE3kEAn70GZk7swhrOt993eEItf8cVnwHmUjQ jKJJDhCPMSt3l70E87Um7xLt5jjkYm7F7kqxbsxXEPRAGFtFjxjbUcnw6ZF3RRIaNbD4 mICQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="SDYER/GQ"; 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-38132-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38132-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id i2-20020a17090a974200b0029058da5dc5si916563pjw.176.2024.01.25.00.09.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 00:09:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38132-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="SDYER/GQ"; 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-38132-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38132-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 3D3C2B27878 for ; Thu, 25 Jan 2024 08:03:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7928718EB2; Thu, 25 Jan 2024 08:02:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="SDYER/GQ" 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 3CBD513AD9 for ; Thu, 25 Jan 2024 08:02:53 +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=1706169774; cv=none; b=YRxdtWb7sKKdlEIfiQbPKmJHxYloj079kAgJyW4nN2O8BTw9FQsiW+0Ox6HeixbxtzdoHN1EcEaqb15xC8wqNQ7VazNwAYAq0x23Q+CqqH+xfAVfqL7F54GQnypYk1aee+wuSZCNO1HdrPH9djVNKa4kFa3b5bq7HyJVobONNI8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706169774; c=relaxed/simple; bh=KjWB9RCuIPpmEs3LKhKafBGiLd5pPNJQhI+Vkrsfhqw=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bbLnO7DIuUkksIM2feHFQpV9VpATQ2y48kjsvm+xhtwFXPc0aCZ5RTU6J26YOCgxzqCzSPAANPn1O7WJ1CAyI1Nx+O1BZMr0b4aWohjmYd/UObnfYYkyvdGHhPj7zY4wspbyVJPWUVGiNfKoCMenTG9oGTJ0nrMwAi5HPbGcyDU= 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=SDYER/GQ; 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=1706169771; bh=KjWB9RCuIPpmEs3LKhKafBGiLd5pPNJQhI+Vkrsfhqw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=SDYER/GQtO7GxHnYozVA17JhDttmQFnSL1vR+asI6U58wi16Yh10w0v0ecFTQCIvp nwAMz7eNLo+8tYXVeHr4JYp1Tc2JCqPIrunyrRd4lB7Kh9oVXtW2MfAf59g51J4qRJ Y1L4QgTNFxUu2+qjNglCzdN2fMqOHSaFZdeSRCM+O9T5zOydqF6eyedyPPg+tCnl5N Cn9i38v3IWQ3+NAgbfOuS2HqmLVEBe0BCGIfn+tDXqip/zPWTuECDXnJiFeWNO9ZPY PCygTJM7f9ewAlCXJdM9qLuabjB3g9oN9ALtq9a6S929QIhqXoiKIAIjrvHOs+nuhG kR0mWitbgaEjg== 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 AEEC937820C2; Thu, 25 Jan 2024 08:02:50 +0000 (UTC) Date: Thu, 25 Jan 2024 09:02:49 +0100 From: Boris Brezillon To: Dmitry Osipenko Cc: David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Daniel Vetter , 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 15/30] drm/shmem-helper: Avoid lockdep warning when pages are released Message-ID: <20240125090249.5f05959d@collabora.com> In-Reply-To: <20240105184624.508603-16-dmitry.osipenko@collabora.com> References: <20240105184624.508603-1-dmitry.osipenko@collabora.com> <20240105184624.508603-16-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 Fri, 5 Jan 2024 21:46:09 +0300 Dmitry Osipenko wrote: > All drivers will be moved to get/put pages explicitly and then the last > put_pages() will be invoked during gem_free() time by some drivers. > We can't touch reservation lock when GEM is freed because that will cause > a spurious warning from lockdep when shrinker support will be added. > Lockdep doesn't know that fs_reclaim isn't functioning for a freed object, > and thus, can't deadlock. Release pages directly without taking reservation > lock if GEM is freed and its refcount is zero. > > Signed-off-by: Dmitry Osipenko Reviewed-by: Boris Brezillon > --- > drivers/gpu/drm/drm_gem_shmem_helper.c | 16 ++++++++++++++++ > 1 file changed, 16 insertions(+) > > diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c > index f5ed64f78648..c7357110ca76 100644 > --- a/drivers/gpu/drm/drm_gem_shmem_helper.c > +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c > @@ -242,6 +242,22 @@ void drm_gem_shmem_put_pages(struct drm_gem_shmem_object *shmem) > if (refcount_dec_not_one(&shmem->pages_use_count)) > return; > > + /* > + * Destroying the object is a special case because acquiring > + * the obj lock can cause a locking order inversion between > + * reservation_ww_class_mutex and fs_reclaim. > + * > + * This deadlock is not actually possible, because no one should > + * be already holding the lock when GEM is released. Unfortunately > + * lockdep is not aware of this detail. So when the refcount drops > + * to zero, we pretend it is already locked. > + */ > + if (!kref_read(&shmem->base.refcount)) { > + if (refcount_dec_and_test(&shmem->pages_use_count)) > + drm_gem_shmem_free_pages(shmem); > + return; > + } > + > dma_resv_lock(shmem->base.resv, NULL); > drm_gem_shmem_put_pages_locked(shmem); > dma_resv_unlock(shmem->base.resv);