From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f50.google.com (mail-qv1-f50.google.com [209.85.219.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63691346E59 for ; Mon, 6 Jul 2026 11:40:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783338057; cv=none; b=fiEdX6k0PCoVNofsN32+ssBmrk2Uu2ekaOpYzsUyWZ+xpYQxEp1mG9de3iazIH+46ALcaVLH/w+WfsddI00AvcLa7Qaj++AbsraRGUlhCMPVA1xdHBKLH8PnaY/Nf6vT5Si0nuWe40JseAtxbGGcGVHNYaKzLIm+os+uZsTzQMk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783338057; c=relaxed/simple; bh=pHxB+lypBOejuIxki5damIHdGZ5nR0Ez62nlFNYIGEg=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=iH9bu+WZj8GTQi6AuaRRVwV+I4kBSJEwnBtuiZQvnNF0S+ZLjeE0n6t0t3AVZu1R3gqmOXxLsjgyWs2328j6pJBZyxsxY7Uh1W2ZA8Mkcdk2BzZEHdjQ7wKMabrGek/9fHwha/VENanu9eeNqz6VfML5bxSg8YuzponsIIYkuuI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=WLXLp44z; arc=none smtp.client-ip=209.85.219.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WLXLp44z" Received: by mail-qv1-f50.google.com with SMTP id 6a1803df08f44-8f23e851626so23559666d6.3 for ; Mon, 06 Jul 2026 04:40:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783338055; x=1783942855; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=BlzqRtlXbabh3QQlkX9Qesj3eyFizaZyJAzX8b4cN6E=; b=WLXLp44zDbvQgSCIfe8OcqZrTdE8e+gwMUdG87A23ynzyRJaE3Juuzz0JcccM3dclo /YnTVACwWCw4HXkTMX4j4q37zZJYA4I9sgBKJduuKku1GoVKdPUAP98kwniO7BI45Aju sqeWyeTIs1W/7HJ9njXo5a/cJiknHFQeVD8E3UYclPlcjqMI6o+E4q33AaSCHrQoux6X 5CPQSxsc0DYo2oxXA9vrNk3ZOdm6EaQktMRYzTRasN/RXMOeI064vl8ozIDBz2HOpRzd CdXZiIUYfyrHumsrsceP++/31z6i4N8t+5uwqYUiayQn8yOxNriXdp+7i2v6pzcbYPCf o2ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783338055; x=1783942855; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=BlzqRtlXbabh3QQlkX9Qesj3eyFizaZyJAzX8b4cN6E=; b=AmJQeF7fuJD7F47YaP7FlsN7kDv9VCY7HjF+rjYVJxKe+z9SbMRxm7ARknCOBwRSHs 1YyHKpleqSWhzGxHxIxFqfjoY3++FmpJUz5TLtvrFwbcUgBDGyVsKJa3AEiG0BRRlv5L zfeeoHYp1m5hUWs+/pcUIzG9VVLjrNabFC4wEZCsBAyUEEzHOKbCj7CBPkYQNEE27Omx s//8Xd032YQK8ZAhye0lshgFp0s9sAdqt+1dEawwkt9rf6FoiHhTN5WAVHFCnZq8CO67 hMMkPAyPSRBAh8gVHcYB5Bq5XJUWkLsu4/WOBNwWiJHoLnbAu3Kiy4VYMIkchjAinNHq uQgA== X-Forwarded-Encrypted: i=1; AHgh+Rppeub24S5emVghXLYYaxcmeoov5CJrJy+S1aBbOo5zjRBut2rJXkZucQ7b3uS0FL/JYFS8F1IxQZN4eRc=@vger.kernel.org X-Gm-Message-State: AOJu0YyZqFjZQdJ8pnBFMbNAmMu+aYKIZ4fGpYr74rcRvHdVmU8628fS SWJ3THpVHGT5dhP6HVFYUhv/UFgqE5TutEz2A74dkB7WbhcpF4T2HFqS X-Gm-Gg: AfdE7cmnCse69ivXUHyPJ5ikw5Cp0JMu1UTtxo1giYpDJlyxitEtmCQtS2df+uzSH+/ xfzr9RBYNaLTkOwmz+OIOsy77ZXnvdQ5dEZg7hCNXhWgaHtsQxPBmX0CQxSeQptqOMNUAUdehfB WtjbWtSbS6DatSELzBawufEQy62J/T201JcnWLhNqg/+WK/pXmRKpeI4zFO2UI0/JGJaQ7MKF7a pVtBZUc9GctGqXg5ulK1E/bP2adaP8IR0OSaUdEi0cbm0+J1GEbGNa/KBfrUgCIK4YQXuFcjUc3 EMZsbvgfANTo29dzxSBlG6Pe9Gkiw1eiVPcQbZvirR/0Bi4W5soivikBn5xvZ30Q5y3EfNTe893 VQc+Z0Hct8jYEpb0ugcuE3xlG+zQ7v7NcEcuATOa4FZfpPQ6VFNoZOOmhMT/x4obnP+XEuaogZn zif1mnmpfevQdNi9nzujiYtOy+GuTeO81psvmkzKVe5ma/ X-Received: by 2002:a05:6214:5348:b0:8ed:b644:c03c with SMTP id 6a1803df08f44-8f74d1b9807mr138872566d6.55.1783338055225; Mon, 06 Jul 2026 04:40:55 -0700 (PDT) Received: from [10.254.122.221] (mkmvpn.amd.com. [165.204.54.211]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8f471813d49sm131848996d6.27.2026.07.06.04.40.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Jul 2026 04:40:54 -0700 (PDT) Message-ID: <5acb8994-3076-452e-a95a-d3b0159c21b7@gmail.com> Date: Mon, 6 Jul 2026 13:40:50 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 01/10] drm/exec: Add helper to bypass IGNORE_DUPLICATES flag To: Natalie Vock , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , Christian Koenig , Huang Rui , Matthew Auld , Matthew Brost , =?UTF-8?Q?Thomas_Hellstr=C3=B6m?= , Alex Deucher Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org, amd-gfx@lists.freedesktop.org References: <20260706-ttm_2_drm_exec-v2-0-4bf6bfc0d320@pixelcluster.dev> <20260706-ttm_2_drm_exec-v2-1-4bf6bfc0d320@pixelcluster.dev> Content-Language: en-US From: =?UTF-8?Q?Christian_K=C3=B6nig?= In-Reply-To: <20260706-ttm_2_drm_exec-v2-1-4bf6bfc0d320@pixelcluster.dev> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 7/6/26 12:07, Natalie Vock wrote: > TTM is about to switch to drm_exec for locking objects > in the LRU list. When we're done processing the object, we want to > unlock it only if the caller doesn't already hold that lock. If > DRM_EXEC_IGNORE_DUPLICATES is set on the exec object (which callers may > require for unrelated reasons), we have no way of knowing whether the > lock is already held. > > To remedy this, add a separate helper that forcefully bypasses the > IGNORE_DUPLICATES flag for only a single locking operation. > > Signed-off-by: Natalie Vock Reviewed-by: Christian König > --- > drivers/gpu/drm/drm_exec.c | 54 ++++++++++++++++++++++++++++++++++------------ > include/drm/drm_exec.h | 2 ++ > 2 files changed, 42 insertions(+), 14 deletions(-) > > diff --git a/drivers/gpu/drm/drm_exec.c b/drivers/gpu/drm/drm_exec.c > index 7988f5e7d56a3..ec33ed4a523cc 100644 > --- a/drivers/gpu/drm/drm_exec.c > +++ b/drivers/gpu/drm/drm_exec.c > @@ -190,18 +190,9 @@ static int drm_exec_lock_contended(struct drm_exec *exec) > return ret; > } > > -/** > - * drm_exec_lock_obj - lock a GEM object for use > - * @exec: the drm_exec object with the state > - * @obj: the GEM object to lock > - * > - * Lock a GEM object for use and grab a reference to it. > - * > - * Returns: -EDEADLK if a contention is detected, -EALREADY when object is > - * already locked (can be suppressed by setting the DRM_EXEC_IGNORE_DUPLICATES > - * flag), -ENOMEM when memory allocation failed and zero for success. > - */ > -int drm_exec_lock_obj(struct drm_exec *exec, struct drm_gem_object *obj) > +static int __drm_exec_lock_obj(struct drm_exec *exec, > + struct drm_gem_object *obj, > + bool ignore_duplicates) > { > int ret; > > @@ -226,8 +217,7 @@ int drm_exec_lock_obj(struct drm_exec *exec, struct drm_gem_object *obj) > return -EDEADLK; > } > > - if (unlikely(ret == -EALREADY) && > - exec->flags & DRM_EXEC_IGNORE_DUPLICATES) > + if (unlikely(ret == -EALREADY) && ignore_duplicates) > return 0; > > if (unlikely(ret)) > @@ -243,8 +233,44 @@ int drm_exec_lock_obj(struct drm_exec *exec, struct drm_gem_object *obj) > dma_resv_unlock(obj->resv); > return ret; > } > + > +/** > + * drm_exec_lock_obj - lock a GEM object for use > + * @exec: the drm_exec object with the state > + * @obj: the GEM object to lock > + * > + * Lock a GEM object for use and grab a reference to it. > + * > + * Returns: -EDEADLK if a contention is detected, -EALREADY when object is > + * already locked (can be suppressed by setting the DRM_EXEC_IGNORE_DUPLICATES > + * flag), -ENOMEM when memory allocation failed and zero for success. > + */ > +int drm_exec_lock_obj(struct drm_exec *exec, struct drm_gem_object *obj) > +{ > + return __drm_exec_lock_obj(exec, obj, > + exec->flags & DRM_EXEC_IGNORE_DUPLICATES); > +} > EXPORT_SYMBOL(drm_exec_lock_obj); > > +/** > + * drm_exec_lock_obj_report_dup - lock a GEM object for use, but always report duplicates > + * @exec: the drm_exec object with the state > + * @obj: the GEM object to lock > + * > + * Like drm_exec_lock_obj, lock a GEM object for use and grab a reference to it. > + * Unlike drm_exec_lock_obj, DRM_EXEC_IGNORE_DUPLICATES is ignored and duplicates are > + * always reported. > + * > + * Returns: -EDEADLK if a contention is detected, -EALREADY when object is > + * already locked, -ENOMEM when memory allocation failed and zero for success. > + */ > +int drm_exec_lock_obj_report_dup(struct drm_exec *exec, > + struct drm_gem_object *obj) > +{ > + return __drm_exec_lock_obj(exec, obj, false); > +} > +EXPORT_SYMBOL(drm_exec_lock_obj_report_dup); > + > /** > * drm_exec_unlock_obj - unlock a GEM object in this exec context > * @exec: the drm_exec object with the state > diff --git a/include/drm/drm_exec.h b/include/drm/drm_exec.h > index 8725ba92ff916..ff80dd2b72240 100644 > --- a/include/drm/drm_exec.h > +++ b/include/drm/drm_exec.h > @@ -176,6 +176,8 @@ void drm_exec_init(struct drm_exec *exec, u32 flags, unsigned nr); > void drm_exec_fini(struct drm_exec *exec); > bool drm_exec_cleanup(struct drm_exec *exec); > int drm_exec_lock_obj(struct drm_exec *exec, struct drm_gem_object *obj); > +int drm_exec_lock_obj_report_dup(struct drm_exec *exec, > + struct drm_gem_object *obj); > void drm_exec_unlock_obj(struct drm_exec *exec, struct drm_gem_object *obj); > int drm_exec_prepare_obj(struct drm_exec *exec, struct drm_gem_object *obj, > unsigned int num_fences); >