Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp319734rdb; Fri, 5 Jan 2024 10:50:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IGNyreXmZ6eIiUoCw9J/o3MEKhTpe5cmd/pjQQ+0dombErIS6kOXHs8CBb5pSHNAwk4nwS2 X-Received: by 2002:a05:651c:b2a:b0:2cc:c794:57c2 with SMTP id b42-20020a05651c0b2a00b002ccc79457c2mr1842483ljr.14.1704480650310; Fri, 05 Jan 2024 10:50:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704480650; cv=none; d=google.com; s=arc-20160816; b=H7eYwoBr4ezj2JxpP3BcLpfvPIUIhMDenEKZhRnmazbMu4w7Q19x1KwuwgqgYzhlYA emdY526FoJ/8EEKxoa3Mu9HGlKZ9cdW3rCeS9xHsP4gaIhnJiA1snNVZIOuzB7pR890z 00gSmH7CL/A1F2mhFSYPcs1XQx8zj0rRYbl9NKVQYruITlsXfUdUCifzk+qNAbb2Kx83 +WMJqQIt07BbgaJnFchXQo5JxQoseUKJ1mbUwWBfwvpPKiYn1qaxfch8FvZn3v9xumVG FybTv5bd+FsobOyVJpGK9QCfH9fUNhYHYB5gVYIop4WhHyiySIMdAzwRTUoEoOIgYhqU VlVQ== ARC-Message-Signature: i=1; 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=hBrlWznzXpVboti4vw0bHHVz5zMt+VnrcxP2WUIIuY8=; fh=5cel2jD5h+yPMXVwxbomyVhwojHUqATy6nFjd4aOh4o=; b=buZ069IuXDYqR5c2XbOJnk5A6Gw2u+jE6U+IElfDL3KmEstL3lxEw6O47tvnGEVh9E e1xVtfvfL5WFwS/p+MadPkNI5m1P+wDphlQckSJNp0ZyZ0dA85G24F0jyZ0mCZFCz6cO Wlk/Vyc156y5hrQY8ybWLmYJFu9M3/VTJIzR7222DE5ykHXN0A3fWfXfkRpTw4yQ3fEQ npTBRpWyEidyNPjgTCZee7m5w+Tf5s0ujUe8Bop/XEsurIOqBJNxEd48okBu4fB0xGFY rZ8U9ZWynfXE0EhImRQTaSq1QCuXK5DSkgekd2VpFEZWNJPEi0hB6Dt3qiorOehMO4uc V4OQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=HYfbKWsO; spf=pass (google.com: domain of linux-kernel+bounces-18253-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18253-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id di11-20020a056402318b00b0054cfed181d5si877736edb.595.2024.01.05.10.50.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 10:50:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-18253-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=HYfbKWsO; spf=pass (google.com: domain of linux-kernel+bounces-18253-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18253-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 1239A1F24548 for ; Fri, 5 Jan 2024 18:50:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0071839877; Fri, 5 Jan 2024 18:47:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="HYfbKWsO" X-Original-To: linux-kernel@vger.kernel.org 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 E73C438FAF for ; Fri, 5 Jan 2024 18:47:09 +0000 (UTC) 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=1704480428; bh=tpJP8aUfkvakUPIRIDPJWRInC6tt5GQtcS8InGkdO1c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HYfbKWsOORxwVSeGsBruwzoIrfH9HktyzFNW0jMXbWXqEQkTjCbpZsndScMrWW09M T7gQhPY8U51XeIxeWj+GRsVQSCh8ogIg4SQuEERDKXAOLNs78Yi1454KAIox07MShF rlk4BYMQ+lOapPf7Dvp9+56o8g6rLI63w9CFh/5MYVtXkGk/uvIKW9R7ErUKWzWer0 4+GaUiAy34d4w5iPNh4HQX1u6JiWMFNgAP5y5ixbzfo1gaKdQNoxf3w8qCHPkWD+Q6 u/bK8sl5peQRSfn1ZzL4Lr1OADocg2OFUcLkCZR9t1INpZ9aZoXbUhSCCiHiQt/hM8 nyqubNWPN4X0A== Received: from workpc.. (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: dmitry.osipenko) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 37097378203D; Fri, 5 Jan 2024 18:47:07 +0000 (UTC) From: Dmitry Osipenko To: David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , =?UTF-8?q?Christian=20K=C3=B6nig?= , Qiang Yu , Steven Price , Boris Brezillon , Emma Anholt , Melissa Wen Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel@collabora.com, virtualization@lists.linux-foundation.org Subject: [PATCH v19 15/30] drm/shmem-helper: Avoid lockdep warning when pages are released Date: Fri, 5 Jan 2024 21:46:09 +0300 Message-ID: <20240105184624.508603-16-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240105184624.508603-1-dmitry.osipenko@collabora.com> References: <20240105184624.508603-1-dmitry.osipenko@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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); -- 2.43.0