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 A46A915E8B for ; Thu, 7 May 2026 14:41:13 +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=1778164875; cv=none; b=Iy4FtlqRYkEgwEk+j7xRtn5ofHiqs1kB92xDoO4S1KF1v7ei34H/lO+liv1et5yeI1Rzp4G5AwlotOuRBfk+pVI82YsTP5/JT+pX4sp7zT7zHfJSVaaOHicfkA2Ke/1Dofd1ZZNHzvw3IYyU540mz4B5DVemwgA5kTFYD0xfzd4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164875; c=relaxed/simple; bh=8kVPsXdniYZDTNOnHTAwlUonJF1lf9qwfcC7sIAE9/8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=soBxN8rz2LCPcLwDGGWfZrzWYU/kHD2Rw3oGmMYPJFMFEwfJ+ZINGvX3CsRTNFrGWBTdg5kQJtw20T07yUnOdN+1/QE99VxTQ1+0iVoslgzWw8vXMNaQuPmn7nMScfCA4Awt8xFUAV20fa2f8h/OvJv3khXsNudX4hJxOuGEzbc= 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=awdXDIrK; 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="awdXDIrK" 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 C24FE315F for ; Thu, 7 May 2026 07:41:07 -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 DA5183F763 for ; Thu, 7 May 2026 07:41:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1778164873; bh=8kVPsXdniYZDTNOnHTAwlUonJF1lf9qwfcC7sIAE9/8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=awdXDIrKyY+JSyCtCc7LCMwtIHDtXYdDIIaT7qd5jidD8cxD82RdHZ0zaI7DUYXUB ngZbgeyEQEILcRBR/Z+baSdhcwCTNHquLRMoYz8p4JRvrAbD/w34p7pgbVztjaWXCk 1qZnbenZMpsp4DY+3AgB4hsSL0R0GcK4RaDKC5cI= Date: Thu, 7 May 2026 15:40:51 +0100 From: Liviu Dudau To: Boris Brezillon Cc: dri-devel@lists.freedesktop.org, 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, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/3] drm/panthor: Don't use the racy drm_gem_lru_remove() helper Message-ID: References: <20260506-panthor-shrinker-fixes-v1-0-e7721526de96@collabora.com> <20260506-panthor-shrinker-fixes-v1-1-e7721526de96@collabora.com> <20260507141027.166ab00d@fedora> 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: <20260507141027.166ab00d@fedora> On Thu, May 07, 2026 at 02:10:27PM +0200, Boris Brezillon wrote: > On Thu, 7 May 2026 11:01:25 +0100 > Liviu Dudau wrote: > > > On Wed, May 06, 2026 at 02:16:26PM +0200, Boris Brezillon wrote: > > > drm_gem_lru_remove() dereference stores drm_gem_object::lru in a local > > > variable that's then dereferenced to acquire the LRU lock. Because this > > > assignment in done without the LRU lock held, it can race with > > > drm_gem_lru_scan() where drm_gem_object::lru is temporarily assigned > > > a stack-allcated LRU that goes away when leaving the function. By > > > the time we dereference this local lru variable, the object might already > > > be gone. > > > > > > It feels like drm_gem_lru_move_tail() was never meant to be used this > > > way, because there's no easy way we can avoid this race unless we defer > > > the locking to the caller. Let's add an explicit LRU for unreclaimable > > > BOs instead, and have all BOs added to this LRU at creation time. > > > > I would argue that drm_gem_lru_scan() is broken by design. If you're going > > to release the LRU lock in the middle of a loop you can expect that someone > > will get hold of your stack-allocated LRU and end up picking the pieces. > > I think it's fine as long as you always use the drm_gem_lru helpers to > manipulate the lru field, which is true of a lot of kernel constructs. I think drm_gem_lru_scan() should never set an object's lru field to still_in_lru. It should set it to NULL when the object's node is removed from its lru and add it into still_in_lru without making the drm_gem_object->lru to point back to it. At the very end when we splice back the still_in_lru list back into lru's list we can then update obj->lru. > > > This patch is fine in itself by trying to avoid stepping into the fight, > > but I think we should also add a warning in drm_gem_lru_scan() for future > > users to be aware of the dangers. > > Warning the user about what? There's nothing they can do about it, and > I don't even think it's unsafe per-se, unless someone goes off and > stores the drm_gem_object::lru value somewhere else while their shrink() > callback is called, and accesses it later, outside the shrinker path. > Given drm_gem_lru is not refcounted, there's no way one could safely > hold on the LRU they saw in the shrink() callback anyway, so I don't > think that's fair to blame the drm_gem_lru API for this kind of misuse. Yeah, that would be the warning: don't store the object's lru as you might get a temporary one that will become invalid after the shrinker has run. Best regards, Liviu -- ==================== | I would like to | | fix the world, | | but they're not | | giving me the | \ source code! / --------------- ¯\_(ツ)_/¯