Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Mario Limonciello" <mario.limonciello@amd.com>
Cc: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org,
	intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH v8 05/14] drm: add DRM_CLIENT_CAP_LUMINANCE
Date: Tue, 08 Sep 2026 04:55:30 +0000	[thread overview]
Message-ID: <20260908045530.BCAEB1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260908044035.62093-6-mario.limonciello@amd.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] TOCTOU race between `drm_backlight_link()` and device-wide backlight inhibit/uninhibit iterations causes permanent count corruption.
- [High] The LUMINANCE property is unconditionally exposed to all atomic clients, violating the DRM_CLIENT_CAP_LUMINANCE capability contract.
- [Low] Clients cannot cleanly unset DRM_CLIENT_CAP_LUMINANCE if they have previously unset DRM_CLIENT_CAP_ATOMIC.
--

commit 3e9d95a8d4fc1bbb26ab6124a33c012ee7b1f848
Author: Mario Limonciello <mario.limonciello@amd.com>

drm: add DRM_CLIENT_CAP_LUMINANCE

This patch adds a DRIVER_CONNECTOR_LUMINANCE driver feature and a
DRM_CLIENT_CAP_LUMINANCE client capability. When a client sets this
capability, every DRM-connected backlight is marked as taken over, and
legacy sysfs writes return -EBUSY.

> diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
> index 9039a39c43243..de2c9d9ab5285 100644
> --- a/drivers/gpu/drm/drm_ioctl.c
> +++ b/drivers/gpu/drm/drm_ioctl.c

[ ... ]

> @@ -392,6 +394,28 @@ drm_setclientcap(struct drm_device *dev, void *data, struct drm_file *file_priv)
>  		file_priv->plane_color_pipeline = req->value;
>  		break;
>  	}
> +	case DRM_CLIENT_CAP_LUMINANCE:
> +		if (!drm_core_check_feature(dev, DRIVER_CONNECTOR_LUMINANCE))
> +			return -EOPNOTSUPP;
> +		if (!file_priv->atomic)
> +			return -EINVAL;

[Severity: Low]
Can this prevent clients from cleanly unsetting DRM_CLIENT_CAP_LUMINANCE if
they have previously unset DRM_CLIENT_CAP_ATOMIC?

If a client sets ATOMIC=1, LUMINANCE=1, ATOMIC=0, and then tries to unset
LUMINANCE=0, this unconditional atomic check will cause the last call to
return -EINVAL.

> +		if (req->value > 1)
> +			return -EINVAL;
> +
> +		/*
> +		 * Serialize the compare-and-act so concurrent ioctls on a shared
> +		 * fd cannot unbalance the device-wide inhibit count.
> +		 */
> +		mutex_lock(&dev->mode_config.mutex);
> +		if (req->value != file_priv->supports_luminance_control) {
> +			if (req->value)
> +				drm_backlight_inhibit_legacy_all(dev);

[Severity: High]
Does this call introduce a TOCTOU race between drm_backlight_link() and the
device-wide backlight inhibit iteration?

Looking at drm_backlight_inhibit_legacy_all() in
drivers/gpu/drm/drm_backlight.c, it drops drm_backlight_lock before
iterating connectors:

	scoped_guard(spinlock, &drm_backlight_lock)
		dev->mode_config.luminance_clients++;

	drm_connector_list_iter_begin(dev, &iter);

If a concurrent hotplug/probe thread calls drm_backlight_link(), it reads
the already-incremented dev->mode_config.luminance_clients and assigns it to
the new connector's b->luminance_clients.

Then the ioctl thread resumes, iterates the connector list, reaches this
newly linked connector, and calls drm_backlight_inhibit_legacy(), which
increments b->luminance_clients again. This causes the connector's count to
get permanently stuck at a non-zero value, locking out legacy sysfs backlight
control for the rest of the system uptime.

> +			else
> +				drm_backlight_uninhibit_legacy_all(dev);
> +			file_priv->supports_luminance_control = req->value;

[Severity: High]
Is the LUMINANCE property being unconditionally exposed to all atomic clients,
violating the DRM_CLIENT_CAP_LUMINANCE capability contract?

The UAPI behavior documented in include/uapi/drm/drm.h states: "The LUMINANCE
property becomes visible on supported connectors".

However, the capability tracked here (file_priv->supports_luminance_control)
is never utilized by the DRM core (e.g., in drm_mode_object_get_properties)
to filter property visibility. drm_mode_object_get_properties() only checks
if the client is atomic, but fails to check if the property is luminance and
if the client supports it:

	if ((prop->flags & DRM_MODE_PROP_ATOMIC) && !atomic)
		continue;

As a result, any generic atomic client (like a compositor restoring state)
will see and restore the LUMINANCE property without setting
DRM_CLIENT_CAP_LUMINANCE, bypassing the sysfs inhibition.

> +		}
> +		mutex_unlock(&dev->mode_config.mutex);
> +		break;
>  	default:
>  		return -EINVAL;
>  	}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260908044035.62093-1-mario.limonciello@amd.com?part=5

  reply	other threads:[~2026-09-08  4:55 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-08  4:40 [PATCH v8 00/14] Add support for a DRM backlight capability Mario Limonciello
2026-09-08  4:40 ` [PATCH v8 01/14] Revert "backlight: Remove notifier" Mario Limonciello
2026-09-08  4:51   ` sashiko-bot
2026-09-08  4:40 ` [PATCH v8 02/14] backlight: add kernel-internal backlight API Mario Limonciello
2026-09-08  4:52   ` sashiko-bot
2026-09-08 15:45   ` Jani Nikula
2026-09-08 16:00     ` Mario Limonciello
2026-09-08 16:33       ` Jani Nikula
2026-09-08  4:40 ` [PATCH v8 03/14] drm/property: add a per-connector luminance flag Mario Limonciello
2026-09-08  4:54   ` sashiko-bot
2026-09-08  4:40 ` [PATCH v8 04/14] drm: add connector backlight (LUMINANCE) infrastructure Mario Limonciello
2026-09-08  4:54   ` sashiko-bot
2026-09-08 15:48   ` Jani Nikula
2026-09-08  4:40 ` [PATCH v8 05/14] drm: add DRM_CLIENT_CAP_LUMINANCE Mario Limonciello
2026-09-08  4:55   ` sashiko-bot [this message]
2026-09-08  4:40 ` [PATCH v8 06/14] drm/amd/display: Pass up errors reading actual brightness Mario Limonciello
2026-09-08  4:40 ` [PATCH v8 07/14] drm/amd: Indicate driver supports luminance Mario Limonciello
2026-09-08  4:40 ` [PATCH v8 08/14] drm/amd/display: use drm backlight Mario Limonciello
2026-09-08  4:57   ` sashiko-bot
2026-09-08  4:40 ` [PATCH v8 09/14] drm/amdgpu: Check bios_scratch_reg_offset in backlight level helper Mario Limonciello
2026-09-08  4:51   ` sashiko-bot
2026-09-08  4:40 ` [PATCH v8 10/14] drm/amd/display: Update KUnit backlight tests for luminance property and fixtures Mario Limonciello
2026-09-08  4:54   ` sashiko-bot
2026-09-08  4:40 ` [PATCH v8 11/14] drm/bridge: auto-link panel backlight in bridge connector Mario Limonciello
2026-09-08  4:40 ` [PATCH v8 12/14] drm/xe: Indicate support for luminance on the connector Mario Limonciello
2026-09-08  4:57   ` sashiko-bot
2026-09-08  4:40 ` [PATCH v8 13/14] drm/i915: " Mario Limonciello
2026-09-08  4:40 ` [PATCH v8 14/14] drm/i915/display: use drm backlight Mario Limonciello
2026-09-08  5:03   ` sashiko-bot
2026-09-08  9:32 ` ✓ i915.CI.BAT: success for Add support for a DRM backlight capability (rev3) Patchwork
2026-09-08 18:45 ` ✗ i915.CI.Full: failure " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260908045530.BCAEB1F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=mario.limonciello@amd.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox