Received: by 2002:ab2:7855:0:b0:1f9:5764:f03e with SMTP id m21csp928119lqp; Thu, 23 May 2024 04:33:30 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXHEae/3L0f/s0qO1aGRKXVuArWMHyRgefQ6e0WsTm2xJqxmO1AoCG3yzCNzx9JybBf/dQrroTgJCjxkvMB029uFurhN+vijKdmJaMSRQ== X-Google-Smtp-Source: AGHT+IHX/akIrBjytsA7uVdBTHyEjjwj7hNp3anRdlNwZOL/ing3cRDuqE7BwZebuR8ejYO8IsNg X-Received: by 2002:a17:90b:3d2:b0:2b2:c85f:a835 with SMTP id 98e67ed59e1d1-2bddcf03cffmr2878103a91.15.1716464010451; Thu, 23 May 2024 04:33:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716464010; cv=pass; d=google.com; s=arc-20160816; b=e7+jVGiHKTEXVAaW/37HLF3yqFsR/OSwnN002ppZOKUyUS2VKpIuvsFGUjeL5H0oEu dkLF9efagrS0UCRVzHo2OwszTqxeW533yNpz3EdyYyFctZC67f7zRt7cYl322mkI+vZ3 WPRGZLepAh053MbUfBGXnEJS/bZon9ObILv+rvRFWPoHKmpjKAzWMbSR6248JHkffnbv TVnNWb2vCqvuCkCX8cLrmyzsjq/MvZNeLIVW1ZpjaMu88/HQNZs2ucePEagxU8weUAmJ qCd8rwTHBh0ViFwVCXByoKFJp9bPnpbjdcD4spjB1oSEv6ccLoxFqSV01x7++O8wk3sG VXAA== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=0n7XqhMEv4NdaaGP/JzuoNxbN0W46N2TNHaQG4izHi8=; fh=Ghx6tcIzyVO5WF7aoLQ8kSAUDZ5XrKLfQq3Zu5A2d+E=; b=HF3bYxKCU9YpOYbAfNIkJ7Z+nKy9eWLx/PimI6QGLmj9CUfZPJNpoo4nMo9L+s/Y8z ygKq1/6a8BuMF/BnyUvZVV1h+dM2pla6OaNCAgDTcTPfkncxcjz/ptyGPhYaBVAbjKgN 3QgRkiel3f3ogfvDPCpnQwuIJerX3tXrWpZZAFLFd54+NvQADCd/Mbvyfji3loKLP85n Cdm8+nl0QqdDVQg+nEEv/Wyk2+EfBV354OY5+xH95cMG7N9ggVCaZHIocL9r9fzIBWaV 3SPDceMK3evMbkUfD+pNl26suBnVtVeRFvxjG81dSt9YDh50+VtsWdYxPT+38MTAj6CS 1kZg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=x4Y8JkMF; 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-187401-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187401-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 98e67ed59e1d1-2bdda34d139si1438787a91.176.2024.05.23.04.33.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 04:33:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-187401-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=x4Y8JkMF; 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-187401-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187401-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 00DE6B21A01 for ; Thu, 23 May 2024 11:33:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E52491487F5; Thu, 23 May 2024 11:32:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="x4Y8JkMF" 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 8CD4C13D2B8; Thu, 23 May 2024 11:32:50 +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=1716463972; cv=none; b=KsKubckLPJVZRAT9LaQdvvyfjzldDIfx79pPVLklLCP6/Dl7pGEqqGidrgcaGsA5HXLHiqxb1wC1K07ymji1Z+6LuZSmHUF3QvrbJLfOGtE6ZBkyWUyxkMQUJTDeNr514ys7ewnYMFDioJEZjVxhHqyhLEJO3Hywie04VNXYOFo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716463972; c=relaxed/simple; bh=B7CVT8mlKuRo1bPhSO+NfICxEbWVkkWyIjUuF91f8aw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GPy6820WSSVVeyusGxzosVrczCRCYkjMiWX2MhIZ7B+iA1Zdi7YLcdCzoZz4Zxp99KhVVWTIMSgmfXjFziOqQ1r9VgDnhtki/H9f7EDcQ7AsTmjhlLC8PhmZOikubpfwMnSG5bHfF25PhGXvhoLwU4nuoPzOqbPryEEaDPoWnvA= 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=x4Y8JkMF; 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=1716463968; bh=B7CVT8mlKuRo1bPhSO+NfICxEbWVkkWyIjUuF91f8aw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=x4Y8JkMFb8i8j7iYu+YrCshcbgAKeN6kjXyvCslJLxr7n9wvamyT17habbScqtHsa ogWa6mvRtaoeWZ0u/A/Ng0oqoYlXgW0Z58o2Gc6aJ9WKaI1uhIE8cBCKVHgo1U0sEI D2uYK//XHzPp/q4i9ZjN6sxcvOdNyHMgQhgIuEzWK9FqRn5Z6x3/9ZLx4Sym0HQAsU 0xc+BH5H9CBGrYiu7vYuhG7AFaG6MkOq0uxtHd8nZ5/MTJeQb7wUBUAGO/2Pyyxbn+ TuLnCgG+P8/2CnB0SdOYr9ERwzImkfOH5uor1E8bNnv2Pmx6PJGm1nefOJy+9zc2bx IlbCi+GjQ5mFQ== Received: from localhost.localdomain (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: alarumbe) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 00BB837821B9; Thu, 23 May 2024 11:32:47 +0000 (UTC) From: =?UTF-8?q?Adri=C3=A1n=20Larumbe?= To: Boris Brezillon , Rob Herring , Steven Price , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Sumit Semwal , =?UTF-8?q?Christian=20K=C3=B6nig?= , Dmitry Osipenko , Zack Rusin Cc: kernel@collabora.com, =?UTF-8?q?Adri=C3=A1n=20Larumbe?= , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org Subject: [PATCH v4 1/3] drm/panfrost: Fix dma_resv deadlock at drm object pin time Date: Thu, 23 May 2024 12:32:17 +0100 Message-ID: <20240523113236.432585-2-adrian.larumbe@collabora.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523113236.432585-1-adrian.larumbe@collabora.com> References: <20240523113236.432585-1-adrian.larumbe@collabora.com> 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=UTF-8 Content-Transfer-Encoding: 8bit When Panfrost must pin an object that is being prepared a dma-buf attachment for on behalf of another driver, the core drm gem object pinning code already takes a lock on the object's dma reservation. However, Panfrost GEM object's pinning callback would eventually try taking the lock on the same dma reservation when delegating pinning of the object onto the shmem subsystem, which led to a deadlock. This can be shown by enabling CONFIG_DEBUG_WW_MUTEX_SLOWPATH, which throws the following recursive locking situation: weston/3440 is trying to acquire lock: ffff000000e235a0 (reservation_ww_class_mutex){+.+.}-{3:3}, at: drm_gem_shmem_pin+0x34/0xb8 [drm_shmem_helper] but task is already holding lock: ffff000000e235a0 (reservation_ww_class_mutex){+.+.}-{3:3}, at: drm_gem_pin+0x2c/0x80 [drm] Fix it by replacing drm_gem_shmem_pin with its locked version, as the lock had already been taken by drm_gem_pin(). Cc: Thomas Zimmermann Cc: Dmitry Osipenko Cc: Boris Brezillon Cc: Steven Price Fixes: a78027847226 ("drm/gem: Acquire reservation lock in drm_gem_{pin/unpin}()") Signed-off-by: Adrián Larumbe --- drivers/gpu/drm/panfrost/panfrost_gem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.c b/drivers/gpu/drm/panfrost/panfrost_gem.c index d47b40b82b0b..8e0ff3efede7 100644 --- a/drivers/gpu/drm/panfrost/panfrost_gem.c +++ b/drivers/gpu/drm/panfrost/panfrost_gem.c @@ -192,7 +192,7 @@ static int panfrost_gem_pin(struct drm_gem_object *obj) if (bo->is_heap) return -EINVAL; - return drm_gem_shmem_pin(&bo->base); + return drm_gem_shmem_pin_locked(&bo->base); } static enum drm_gem_object_status panfrost_gem_status(struct drm_gem_object *obj) -- 2.45.1