From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A874E3845BE for ; Thu, 7 May 2026 10:19:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778149164; cv=none; b=bSFW6SnF7GWcArTtQvvlb+vVlgwd/ohQ5CXU1SZYccX1W/sOn+T+K1yKn9+92ndlCfHuc2IskU6XaxkxRLbh94u37oOXo2fGYUHFCI9LS44Qitnn8GWMmZ4JKATYbIMsSUxEhYmNy+I/LsE++e7UaZYwfnokzNQSb7L52toFX2s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778149164; c=relaxed/simple; bh=TG08dbsdevsuUuKiOfCppaUESy80nCb00HkxvqnrU2A=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HQIFTNaGLdAVNCey/GmkWS9/YrAIJ+5iHiermOPBTVgqfMtmI8jN2DJ2iiaMnHw/Xpp41lShqQTQ1j7q10uH5FDx1t0xfwHGf+xKp/rHraGJpJK4UFpjvGvyIzlbkRP8L2ibsQT3o1EjxYKd1tgRWHwmaxxrLoiiHnx7Fy5ZYWY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=rRexDXJA; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="rRexDXJA" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8081B19F6 for ; Thu, 7 May 2026 03:19:17 -0700 (PDT) Received: from [192.168.0.1] (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 89B1D3F836 for ; Thu, 7 May 2026 03:19:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1778149162; bh=TG08dbsdevsuUuKiOfCppaUESy80nCb00HkxvqnrU2A=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=rRexDXJAY33clP2CGs8svqgdkyNsSTZrRNOGA/nUYvpeQMMZBoOExH8YbjoQdpIIu 9cVlLTURyGD4/X1/ppO+XQkLLdLW4+oj/n14OW9gr1Rq9cAzTP1/CaBGHLsMT2WuMU 5whfRZdirvlcuRXikT9ptN5ggL96t49EDXMdNKV8= Date: Thu, 7 May 2026 11:18:55 +0100 From: Liviu Dudau To: Boris Brezillon Cc: Steven Price , Dmitry Osipenko , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Akash Goel , Chia-I Wu , Rob Clark , Dmitry Baryshkov , Abhinav Kumar , Jessica Zhang , Sean Paul , Marijn Suijten , linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/3] drm/gem: Fix a race between drm_gem_lru_scan() and drm_gem_object_release() Message-ID: References: <20260506-panthor-shrinker-fixes-v1-0-e7721526de96@collabora.com> <20260506-panthor-shrinker-fixes-v1-2-e7721526de96@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-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20260506-panthor-shrinker-fixes-v1-2-e7721526de96@collabora.com> On Wed, May 06, 2026 at 02:16:27PM +0200, Boris Brezillon wrote: > The following race can currently happen: > > | Thread 0 in `drm_gem_lru_scan` | Thread 1 in `drm_gem_object_release` | > | - | - | > | move obj1 with refcount==0 to `still_in_lru` | | > | move obj2 with refcount!=0 to `still_in_lru` | | > | mutex_unlock | | > | shrink obj2 | | > | | lru = obj1->lru; // `still_in_lru` | > | mutex_lock | | > | move obj1 back to the original lru | | > | mutex_unlock | | > | return | | > | | dereference `still_in_lru` | > > Move the drm_gem_lru_move_tail_locked() after the > kref_get_unless_zero() check so that we don't end up with a > vanishing LRU when we hit drm_gem_object_release(). We also need to > remove the skipped object from its LRU, otherwise we'll keep hitting > it on subsequent loop iterations until it's actually removed from the > list in the drm_gem_release(). > > Fixes: e7c2af13f811 ("drm/gem: Add LRU/shrinker helper") > Reported-by: Chia-I Wu > Closes: https://gitlab.freedesktop.org/panfrost/linux/-/work_items/86 > Signed-off-by: Boris Brezillon > Reviewed-by: Chia-I Wu Reviewed-by: Liviu Dudau Best regards, Liviu > --- > drivers/gpu/drm/drm_gem.c | 14 +++++++++----- > 1 file changed, 9 insertions(+), 5 deletions(-) > > diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c > index fca42949eb2b..97cf63de0112 100644 > --- a/drivers/gpu/drm/drm_gem.c > +++ b/drivers/gpu/drm/drm_gem.c > @@ -1660,15 +1660,19 @@ drm_gem_lru_scan(struct drm_gem_lru *lru, > if (!obj) > break; > > - drm_gem_lru_move_tail_locked(&still_in_lru, obj); > - > /* > * If it's in the process of being freed, gem_object->free() > - * may be blocked on lock waiting to remove it. So just > - * skip it. > + * may be blocked on lock waiting to remove it. So just remove > + * it from its current LRU and skip it. > */ > - if (!kref_get_unless_zero(&obj->refcount)) > + if (!kref_get_unless_zero(&obj->refcount)) { > + if (obj->lru) > + drm_gem_lru_remove_locked(obj); > + > continue; > + } > + > + drm_gem_lru_move_tail_locked(&still_in_lru, obj); > > /* > * Now that we own a reference, we can drop the lock for the > > -- > 2.54.0 > -- ==================== | I would like to | | fix the world, | | but they're not | | giving me the | \ source code! / --------------- ¯\_(ツ)_/¯