Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1607895rdb; Thu, 25 Jan 2024 00:08:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IHJMcM/Hr8sya3rCXUD28YZUaSSNkYQa3qWLla5VPoNAX12GuBpjjpd4s38xBFDUPYEpzr6 X-Received: by 2002:a05:6870:6985:b0:210:b468:6a5d with SMTP id my5-20020a056870698500b00210b4686a5dmr597541oab.16.1706170092370; Thu, 25 Jan 2024 00:08:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706170092; cv=pass; d=google.com; s=arc-20160816; b=KhPMy/lwB0D6SWuXPwLc/o/Hp2Ag8KzHowo6cxkl4+pcEL6+i0kJJ5EhvkEOenzHG3 Zd/mXpUFENzmKRCZi31vCnZgyE1f/P8/EesyBKSodm9eFsOzxZ3mbGnXk9rpGNDaxkMZ I8rseV+OfBgNPtoeHbnrbglWVl3pBDUx/9Rd1K00pbEzqnutIZzYCStFeM0Sk65njq0s +Hb4WN3Q/cNcRJzBgafGQAqd1GPuPHHOv3Aevu7qOowba0DSxFFD2G+Bs3KQNzr5Qpkq y1HKm7Z75Xth+W54jChHghz/NN9SU0ZnKXGRV4g4c7LDDRIsZmpyBHWbWqjX5iNOdLYC U6XA== 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=msTZYJhaQ9+ffH3xdCX/qVe9X/Qfk9rc7HRwL64rgSw=; fh=uxLNaPoPRUzmkUc1KOgGwCEU/bTSjK8Yed2Up6ovXLY=; b=dEXDmStw7q/IKYvTZU+AgogHhavGm5aK3JctIMmyG04fgb78EjtLMQiS53VAX6u2x4 bZiFnQXiXkYxxLjQFBqWMqtjRuy/PeQvE3N6symOCvkWY2h/Gj0EaNUBd6QKkyGrDiMA Lmzum9W5YMH5eTMQtVx1GS7gk+diD+ZbCiSmSfWa55znZFBFdgpTmlWSzQEmSPsKsfcz 5M+lZHXKPTNCDdr770p9SSx76VANxPyd5PqGwVsfapUQArsHDdDF88UZ+QEmRkM9agNI 2ZpzLg6UwM8PKZkubGKtmdOPE7mc9L9lPdLZtatToqH+ACBzPGExmB3t2OUT2DMYOW5g ltZw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=CB11jswu; 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-38126-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38126-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 j9-20020a635949000000b005d5150c5b8esi2233586pgm.591.2024.01.25.00.08.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 00:08:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38126-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=CB11jswu; 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-38126-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38126-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 32232B270D0 for ; Thu, 25 Jan 2024 08:02:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0AA3B15AF9; Thu, 25 Jan 2024 08:01:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="CB11jswu" 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 6E7A613AEA for ; Thu, 25 Jan 2024 08:01:46 +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=1706169708; cv=none; b=WLqAlryyB/VAK4T7y+jo0J5Ob5mUg5ZuQIn9wXJ+AJenjHFQS2wGeHMQuAvcLJ++Tx5rxh67DbWxfdgxSGTrWKakU7mDtrX3bao4cUGQ52NXhOy5VtdNdU39nJ3uSdS0YD+i/LdRXYpHo2U2KdZfYnD1cZbvfgtIuBzCdINar9c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706169708; c=relaxed/simple; bh=bgYrY710zE0n7NaiomkjGwNqYaJh8yofMt9szROI5qc=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=c05EVDya/X6d4OUL0N/Srsb0gG+B7pMXWxMyNvdcsrmqLAPTyv6vn5UZikQyAH+mSXJZ2F4y72nBmiqI84H4I0UDtSPA9m7mnRVJeV3SwYbxBLO4J2pNkEYVu1iN+SNwoUt7fzU56KeIL3zoS03IxXrXJFT8kIvEdvNqh78RM94= 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=CB11jswu; 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=1706169704; bh=bgYrY710zE0n7NaiomkjGwNqYaJh8yofMt9szROI5qc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=CB11jswucIzbhJbBtZc3wkQYu5HWz8rE9Xyc0rQ/HRP2PNlZHsY+nX68ekWlmzUFY zc4t07YHF7fB48DJjJSYcOJam38/InXT1Iea+YaN7+xkcVN8Yk58OBB5BTDS7bQg0C pYiHpSHj2ttYcbeWStbOV1R5iTSiqWamVARXGLbKxNkKhG40pKIMjoj1xqQ9bDKTDh 4CiBLfA73FhEnPIRPAIel9cfOJtF7YV4cXaxYGBpV032AzeyyvS8zCu15fuH1Fg261 Pjypmy1q5BGeshI4evFF0rKew5zzNLy2Io/BxOAYoFXc512VK8JcW3sdQ8V3AsT7Ft lLyQD9fjZ/2Cg== 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 4CCB437820AF; Thu, 25 Jan 2024 08:01:43 +0000 (UTC) Date: Thu, 25 Jan 2024 09:01:41 +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 12/30] drm/shmem-helper: Prepare drm_gem_shmem_free() to shrinker addition Message-ID: <20240125090141.4e193d19@collabora.com> In-Reply-To: <20240105184624.508603-13-dmitry.osipenko@collabora.com> References: <20240105184624.508603-1-dmitry.osipenko@collabora.com> <20240105184624.508603-13-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:06 +0300 Dmitry Osipenko wrote: > Prepare drm_gem_shmem_free() to addition of memory shrinker support > to drm-shmem by adding and using variant of put_pages() that doesn't > touch reservation lock. Reservation shouldn't be touched because lockdep > will trigger a bogus warning about locking contention with fs_reclaim > code paths that can't happen during the time when GEM is freed and > lockdep doesn't know about that. > > Signed-off-by: Dmitry Osipenko Reviewed-by: Boris Brezillon > --- > drivers/gpu/drm/drm_gem_shmem_helper.c | 40 ++++++++++++++------------ > 1 file changed, 21 insertions(+), 19 deletions(-) > > diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c > index 3403700780c3..799a3c5015ad 100644 > --- a/drivers/gpu/drm/drm_gem_shmem_helper.c > +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c > @@ -128,6 +128,22 @@ struct drm_gem_shmem_object *drm_gem_shmem_create(struct drm_device *dev, size_t > } > EXPORT_SYMBOL_GPL(drm_gem_shmem_create); > > +static void > +drm_gem_shmem_free_pages(struct drm_gem_shmem_object *shmem) > +{ > + struct drm_gem_object *obj = &shmem->base; > + > +#ifdef CONFIG_X86 > + if (shmem->map_wc) > + set_pages_array_wb(shmem->pages, obj->size >> PAGE_SHIFT); > +#endif > + > + drm_gem_put_pages(obj, shmem->pages, > + shmem->pages_mark_dirty_on_put, > + shmem->pages_mark_accessed_on_put); > + shmem->pages = NULL; > +} > + > /** > * drm_gem_shmem_free - Free resources associated with a shmem GEM object > * @shmem: shmem GEM object to free > @@ -142,8 +158,6 @@ void drm_gem_shmem_free(struct drm_gem_shmem_object *shmem) > if (obj->import_attach) { > drm_prime_gem_destroy(obj, shmem->sgt); > } else { > - dma_resv_lock(shmem->base.resv, NULL); > - > drm_WARN_ON(obj->dev, refcount_read(&shmem->vmap_use_count)); > > if (shmem->sgt) { > @@ -152,13 +166,12 @@ void drm_gem_shmem_free(struct drm_gem_shmem_object *shmem) > sg_free_table(shmem->sgt); > kfree(shmem->sgt); > } > - if (shmem->pages) > - drm_gem_shmem_put_pages_locked(shmem); > + if (shmem->pages && > + refcount_dec_and_test(&shmem->pages_use_count)) > + drm_gem_shmem_free_pages(shmem); > > drm_WARN_ON(obj->dev, refcount_read(&shmem->pages_use_count)); > drm_WARN_ON(obj->dev, refcount_read(&shmem->pages_pin_count)); > - > - dma_resv_unlock(shmem->base.resv); > } > > drm_gem_object_release(obj); > @@ -208,21 +221,10 @@ static int drm_gem_shmem_get_pages_locked(struct drm_gem_shmem_object *shmem) > */ > void drm_gem_shmem_put_pages_locked(struct drm_gem_shmem_object *shmem) > { > - struct drm_gem_object *obj = &shmem->base; > - > dma_resv_assert_held(shmem->base.resv); > > - if (refcount_dec_and_test(&shmem->pages_use_count)) { > -#ifdef CONFIG_X86 > - if (shmem->map_wc) > - set_pages_array_wb(shmem->pages, obj->size >> PAGE_SHIFT); > -#endif > - > - drm_gem_put_pages(obj, shmem->pages, > - shmem->pages_mark_dirty_on_put, > - shmem->pages_mark_accessed_on_put); > - shmem->pages = NULL; > - } > + if (refcount_dec_and_test(&shmem->pages_use_count)) > + drm_gem_shmem_free_pages(shmem); > } > EXPORT_SYMBOL_GPL(drm_gem_shmem_put_pages_locked); >