Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp953147lqm; Thu, 2 May 2024 00:09:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW5cMzp2q03m8pbstbJNsP/VpvaKpHCSqeYazGgmePox7CyW9ZDz3dLJ02aZIrr6kllgTrvTLeSxabVNpcFuIFhcc2/NNk6WoXNN+hQWw== X-Google-Smtp-Source: AGHT+IGYw2EScOSmV3tFCnbuzddJdzTlhRxvEX492rHqEosZ87vNErMcpMwy70zI9wNifHioxZAi X-Received: by 2002:a05:6870:9193:b0:23c:4a4b:ba97 with SMTP id b19-20020a056870919300b0023c4a4bba97mr5050518oaf.22.1714633790845; Thu, 02 May 2024 00:09:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714633790; cv=pass; d=google.com; s=arc-20160816; b=tefNnwVAVNr3lJjFTNgSANYU4G9z+200cuQqeJAiTihaq5oQznuLtLZa6STbRu59pW 90jrUTKxwEkCRF6OKBHKGelJDZVVr+vBh4vviM0eR3YjwCoXS4j6n9cfHuC/22PpWfLZ RVMroM5dqmWt0q5e5cYb13tURSpjbAymsO2+Y9QB2yL1ppRIunXAJ8criqqKOckkNEaI 8PZmaHged2+jv5qaNHI/mWy0Z9u9fxqX6z2N8BdljIhwIdacPufzQD4ieZEz3l6EDQiP cSG9lw7GYgg/NEuk5jo6ebLPXamnnsWolrPjDOFM1YjBtfP5vkTvnowuDCNq36+J5LCy 14Cg== 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=0/0Ql16k2nKFOqUdOde947U9vjVgFkmjRPvs57Ee0+c=; fh=m1MQwVFo3zz4IMvhePJntG85uPowMRmwb53EbKyxFjY=; b=OVWYkmc8KjwDT3SQlfni6yly1b32whbV0KV4XO5/3uU6p8m6g+gaTx/usOT/vYDJgd DxzoGCFfQ8iod6sjkQENCViyztZI2J6YWgbQ5nOGWg0b6kzZ3jQxu4mGKTZ4xeNg9kwx DzF34rtc8ShOuBP7LBWJF/r0R91LuVYCAiXswM9j2R6CxBM06a+WwaOnbCSrYnnd9f06 Gl/B4E654CMD1Aseubn2hAAcFEZ5jj9nHltmV9Eb+780QHLWk9EsLA9c8QRsfpHvcqiB A0P2RZwtLpkfnSBP3n3L/oe8yqixXz206R+yzKzY0wG8aTJi0pazYiIA8JpizIL715Mv HHnQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=jaUGu14h; 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-166039-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166039-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id k185-20020a6384c2000000b005f7e8584c6bsi465571pgd.263.2024.05.02.00.09.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 00:09:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-166039-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=jaUGu14h; 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-166039-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166039-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 45CCE282E18 for ; Thu, 2 May 2024 07:09:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 033AC224F2; Thu, 2 May 2024 07:09:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="jaUGu14h" 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 76B6C1CA96; Thu, 2 May 2024 07:09:40 +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=1714633782; cv=none; b=ftSBidOLG8vhi4Vy5uMJG4MjGNIIkuKbnpnNWC5gc5uy6jt+SdNQVugWVGI80YLK1Ut5Lg0DWLsTlzB5Hb/AYpE8gfP1jr6MeNAYUEsZaAXhsBOcOaT068dIDcvFOtyu2813ejlDYRXiqb0n0ydUaZQiIOxFqPcnrrTHkUFBC6Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714633782; c=relaxed/simple; bh=ADRmS8f5vU4gR759YBeJrW1kSqxBWwnLaBbxtr3BdyI=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qKESVSHqzfGrDvP1CqluW0d3QTudALD3n+3ICBODuZrbWNzIQ/VayPS1bF7fmr3a7YU2DQOReNL7RXwq2uE80GYs2OzIzMs0wYMwRcHN1dlkdnmFqKMOiMAq/mgeKlfH6Jk/O9AWiZnOzTGybp7YQ9mueJjsYrCGzvmDD1eNubs= 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=jaUGu14h; 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=1714633778; bh=ADRmS8f5vU4gR759YBeJrW1kSqxBWwnLaBbxtr3BdyI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=jaUGu14hawcP302lr4k1pmDYsIMtScgmJrmTM3oV8z5BRSe5xRJX5ocGShY45do0k gDq9AFrNCJYrXfYKal5XGxtqL0lFFBmgc4pUSoaGA74WFb/XiQRDDAtIgZt1Wqvo6t Qapry2plpOfsZoof4zhQBV2CUi5Xgz3tJe+eeZeyuxfuMtI/Qeiop+8KmISga7Rij2 X09JNsTZQx1/GCWEmcazxIKbS7+Xt2Vy9IAV+8oZ0qMGR8BV3dYVj4UJUyx+VJAGLh rWvlWtAV0chkeUQM3MWiMX4nIgTbwMaR9G+TQxLm5iSr9WpszLnEAQXrPHb5Qxz5po yB9XQVTPTvfKA== 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 67BD3378001E; Thu, 2 May 2024 07:09:37 +0000 (UTC) Date: Thu, 2 May 2024 09:09:36 +0200 From: Boris Brezillon To: =?UTF-8?B?QWRyacOhbg==?= Larumbe Cc: Qiang Yu , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Rob Herring , Steven Price , Sumit Semwal , Christian Koenig= , Dmitry Osipenko , Zack Rusin , kernel@collabora.com, dri-devel@lists.freedesktop.org, lima@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org Subject: Re: [PATCH v3 1/2] drm/panfrost: Fix dma_resv deadlock at drm object pin time Message-ID: <20240502090936.2156c025@collabora.com> In-Reply-To: <20240501065650.2809530-2-adrian.larumbe@collabora.com> References: <20240501065650.2809530-1-adrian.larumbe@collabora.com> <20240501065650.2809530-2-adrian.larumbe@collabora.com> Organization: Collabora X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; 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=UTF-8 Content-Transfer-Encoding: quoted-printable On Wed, 1 May 2024 07:55:59 +0100 Adri=C3=A1n Larumbe wrote: > 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 pinni= ng > code already takes a lock on the object's dma reservation. >=20 > However, Panfrost GEM object's pinning callback would eventually try taki= ng > the lock on the same dma reservation when delegating pinning of the object > onto the shmem subsystem, which led to a deadlock. >=20 > This can be shown by enabling CONFIG_DEBUG_WW_MUTEX_SLOWPATH, which throws > the following recursive locking situation: >=20 > weston/3440 is trying to acquire lock: > ffff000000e235a0 (reservation_ww_class_mutex){+.+.}-{3:3}, at: drm_gem_sh= mem_pin+0x34/0xb8 [drm_shmem_helper] > but task is already holding lock: > ffff000000e235a0 (reservation_ww_class_mutex){+.+.}-{3:3}, at: drm_gem_pi= n+0x2c/0x80 [drm] >=20 > Fix it by assuming the object's reservation had already been locked by the > time we reach panfrost_gem_pin. You should probably mention that drm_gem_shmem_object_pin() assumes the lock to be held, thus explaining the drm_gem_shmem_pin() -> drm_gem_shmem_object_pin() transition. Oh, and the commit message refers explicitly to Panfrost in a few places even though you're fixing Lima as well. >=20 > Do the same thing for the Lima driver, as it most likely suffers from the > same issue. >=20 > Cc: Thomas Zimmermann > Cc: Dmitry Osipenko > Cc: Boris Brezillon > Cc: Steven Price > Fixes: a78027847226 ("drm/gem: Acquire reservation lock in drm_gem_{pin/u= npin}()") > Signed-off-by: Adri=C3=A1n Larumbe With the commit message adjusted as suggested, Reviewed-by: Boris Brezillon > --- > drivers/gpu/drm/lima/lima_gem.c | 2 +- > drivers/gpu/drm/panfrost/panfrost_gem.c | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) >=20 > diff --git a/drivers/gpu/drm/lima/lima_gem.c b/drivers/gpu/drm/lima/lima_= gem.c > index 7ea244d876ca..c4e0f9faaa47 100644 > --- a/drivers/gpu/drm/lima/lima_gem.c > +++ b/drivers/gpu/drm/lima/lima_gem.c > @@ -185,7 +185,7 @@ static int lima_gem_pin(struct drm_gem_object *obj) > if (bo->heap_size) > return -EINVAL; > =20 > - return drm_gem_shmem_pin(&bo->base); > + return drm_gem_shmem_object_pin(obj); > } > =20 > static int lima_gem_vmap(struct drm_gem_object *obj, struct iosys_map *m= ap) > diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.c b/drivers/gpu/drm/pa= nfrost/panfrost_gem.c > index d47b40b82b0b..f268bd5c2884 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 *ob= j) > if (bo->is_heap) > return -EINVAL; > =20 > - return drm_gem_shmem_pin(&bo->base); > + return drm_gem_shmem_object_pin(obj); > } > =20 > static enum drm_gem_object_status panfrost_gem_status(struct drm_gem_obj= ect *obj)