From patchwork Fri Aug 23 02:12:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 172082 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1920ily; Thu, 22 Aug 2019 19:12:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqzE9EMMFptesSA4UG9ivrSuxuQyH7I+U63da9ATUyur6znfnE0ySHQd2a+m+EtMaWDPnwQS X-Received: by 2002:a17:902:ab96:: with SMTP id f22mr2053949plr.147.1566526370120; Thu, 22 Aug 2019 19:12:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566526370; cv=none; d=google.com; s=arc-20160816; b=WJ0MWTNIzoQkywTy/18AaSCOqNXONUcPuumxjNyJ+scoFACgiHZxHstEvXmwpp42Ei bxWqY2+tkdghO9oeyDEBciDuCYduTzposLoX9MIQSdv3HZR5/uNoc+Hi3JVAwMnYgjol gJOVDnlRbC55N9vY0pn6a/eaLvTXq/YTr3A04/etY8o0/iDhHVOQu1kxIELByFA+zfKl 8C2ubjEhIhKGOdhsLEBWyqy8ota1ddWULUqEomyfiRCO41ePNeHnkdT1XpSnTBC5kswF 89zzF1hQdLBaAt088Tj5Q/NbLrxGCYi4AX3J9q6bGN52qtSrKeU4EmGGh98AnpvbtVIG U+yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:references:in-reply-to:message-id:date :subject:to:from:delivered-to; bh=k7UAEiWVoGZ53f9h4aGJsHk3JMTFkB7T41YcQ7ntxTE=; b=QcG+uMil9IOU97nYiz94wa0RHQdqdgMJIo6R0qRt4pra1v07QfdX0kMAPztmPID4WU QTSdhjvCBhUfeMQf2StXz0/o8/23s4Oe6J8TxlbQmjnZSQ98gzb1dsIyqrik4gb0yIBm bCNovRKhrEAtQYEDE6EHf179turip/LvkE+fCAK5815n1kXcB22CZe/CTynhYWy/G7xi b2BcJJBAN0xSF9tLPKo3r+h7wkO3Yza4osjjLWXGerix+JPRixIyCKXuD8uQtEMZE+ik HlioHdnDyEO42MkAfOusFKotkPNAeJ9owqTxMQ8o0yLrQv9ZwD4gwbcAArqq7vBgvnlg WeOg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [2610:10:20:722:a800:ff:fe36:1795]) by mx.google.com with ESMTPS id 61si1036899plb.270.2019.08.22.19.12.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 22 Aug 2019 19:12:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) client-ip=2610:10:20:722:a800:ff:fe36:1795; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1EE5D6EBAB; Fri, 23 Aug 2019 02:12:49 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-oi1-f194.google.com (mail-oi1-f194.google.com [209.85.167.194]) by gabe.freedesktop.org (Postfix) with ESMTPS id A74D96EBA5 for ; Fri, 23 Aug 2019 02:12:27 +0000 (UTC) Received: by mail-oi1-f194.google.com with SMTP id h21so5915851oie.7 for ; Thu, 22 Aug 2019 19:12:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FUX/60RPleBNc8rEUfe9ndSh2CQRzsgZWa6X5GDs078=; b=rI8V7W0c5Y2IQKZFN2p7LW3p6zogvDApJ8F5ysThcxz3IAdxYdVkBVjegAdfCNS+2Q vSmg9cfwv0rkaeMjvopwecZBwhttFMl8vHEewyiTlg1FHgYl5QG6wJr8IvgjC5XD7xtv Nd9NybCrBdFlVSaMO61BQ97gg0MEqfpLZOyQfq1FyTg7+jy0VgfkjZuluKtKpTkDBf/s dZiH+rjJ+VUHaZCQme+MIyAkt7OSF+akMK3GGxZBpiEWJ6Q2uKdWxGcmLLiUbJdyrqfR VO9pXh3nyFqlcmmETQgTgVVqaGV0ss/EpYwMuDUqruG7r0IIq6ijY28659Xa2rqnJEbK YBDA== X-Gm-Message-State: APjAAAUWdqzzYs1dcoB8c6WImZGNmM6A24yXLSvxLRySfBWZLkQnUR4t EJ2ZexKLZjMAhjxI26ftnFZy6c8= X-Received: by 2002:aca:ead7:: with SMTP id i206mr1487367oih.8.1566526346137; Thu, 22 Aug 2019 19:12:26 -0700 (PDT) Received: from xps15.herring.priv (24-155-109-49.dyn.grandenetworks.net. [24.155.109.49]) by smtp.googlemail.com with ESMTPSA id c1sm457747oic.31.2019.08.22.19.12.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2019 19:12:25 -0700 (PDT) From: Rob Herring To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 6/8] drm/panfrost: Use mutex_trylock in panfrost_gem_purge Date: Thu, 22 Aug 2019 21:12:14 -0500 Message-Id: <20190823021216.5862-7-robh@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190823021216.5862-1-robh@kernel.org> References: <20190823021216.5862-1-robh@kernel.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Maxime Ripard , Tomeu Vizoso , David Airlie , Sean Paul , Steven Price , Boris Brezillon , Alyssa Rosenzweig , Robin Murphy Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Lockdep reports a circular locking dependency with pages_lock taken in the shrinker callback. The deadlock can't actually happen with current users at least as a BO will never be purgeable when pages_lock is held. To be safe, let's use mutex_trylock() instead and bail if a BO is locked already. Cc: Tomeu Vizoso Cc: Steven Price Cc: Alyssa Rosenzweig Cc: David Airlie Cc: Daniel Vetter Signed-off-by: Rob Herring Reviewed-by: Steven Price --- v2: new patch drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c b/drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c index d191632b6197..458f0fa68111 100644 --- a/drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c +++ b/drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c @@ -36,15 +36,18 @@ panfrost_gem_shrinker_count(struct shrinker *shrinker, struct shrink_control *sc return count; } -static void panfrost_gem_purge(struct drm_gem_object *obj) +static bool panfrost_gem_purge(struct drm_gem_object *obj) { struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj); - mutex_lock(&shmem->pages_lock); + + if (!mutex_trylock(&shmem->pages_lock)) + return false; panfrost_mmu_unmap(to_panfrost_bo(obj)); drm_gem_shmem_purge_locked(obj); mutex_unlock(&shmem->pages_lock); + return true; } static unsigned long @@ -61,8 +64,8 @@ panfrost_gem_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc) list_for_each_entry_safe(shmem, tmp, &pfdev->shrinker_list, madv_list) { if (freed >= sc->nr_to_scan) break; - if (drm_gem_shmem_is_purgeable(shmem)) { - panfrost_gem_purge(&shmem->base); + if (drm_gem_shmem_is_purgeable(shmem) && + panfrost_gem_purge(&shmem->base)) { freed += shmem->base.size >> PAGE_SHIFT; list_del_init(&shmem->madv_list); }