From: "Luca Ceresoli" <luca.ceresoli@bootlin.com>
To: "Louis Chauvet" <louis.chauvet@bootlin.com>,
"Haneen Mohammed" <hamohammed.sa@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Melissa Wen" <melissa.srw@gmail.com>,
"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"David Airlie" <airlied@gmail.com>, <jose.exposito89@gmail.com>,
"Jonathan Corbet" <corbet@lwn.net>
Cc: <victoria@system76.com>, <sebastian.wick@redhat.com>,
<thomas.petazzoni@bootlin.com>, <dri-devel@lists.freedesktop.org>,
<linux-kernel@vger.kernel.org>, <linux-doc@vger.kernel.org>
Subject: Re: [PATCH v3 18/33] drm/vkms: Introduce configfs for plane format
Date: Tue, 23 Dec 2025 14:58:41 +0100 [thread overview]
Message-ID: <DF5NE5WRSCYT.4NV0451K0SRU@bootlin.com> (raw)
In-Reply-To: <20251222-vkms-all-config-v3-18-ba42dc3fb9ff@bootlin.com>
On Mon Dec 22, 2025 at 11:11 AM CET, Louis Chauvet wrote:
> To allow the userspace to test many hardware configuration, introduce a
> new interface to configure the available formats per planes. VKMS supports
> multiple formats, so the userspace can choose any combination.
>
> The supported formats are configured by writing the fourcc code in
> supported_formats:
> # enable AR24 format
> echo '+AR24' > /config/vkms/DEVICE_1/planes/PLANE_1/supported_formats
> # disable AR24 format
> echo '-AR24' > /config/vkms/DEVICE_1/planes/PLANE_1/supported_formats
> # enable all format supported by VKMS
> echo '+*' > /config/vkms/DEVICE_1/planes/PLANE_1/supported_formats
> # disable all formats
> echo '-*' > /config/vkms/DEVICE_1/planes/PLANE_1/supported_formats
>
> Signed-off-by: Louis Chauvet <louis.chauvet@bootlin.com>
> --- a/Documentation/ABI/testing/configfs-vkms
> +++ b/Documentation/ABI/testing/configfs-vkms
> @@ -153,6 +153,15 @@ Description:
> Default color range presented to userspace, same
> values as supported_color_ranges.
>
> +What: /sys/kernel/config/vkms/<device>/planes/<plane>/supported_formats
> +Date: Nov 2025
Jan 2026.
> --- a/Documentation/gpu/vkms.rst
> +++ b/Documentation/gpu/vkms.rst
> @@ -87,7 +87,7 @@ Start by creating one or more planes::
>
> sudo mkdir /config/vkms/my-vkms/planes/plane0
>
> -Planes have 8 configurable attributes:
> +Planes have 9 configurable attributes:
>
> - type: Plane type: 0 overlay, 1 primary, 2 cursor (same values as those
> exposed by the "type" property of a plane)
> @@ -109,6 +109,11 @@ Planes have 8 configurable attributes:
> must be set too.
> - default_color_range: Default color range presented to the userspace, same
> values as supported_color_ranges
> +- supported_formats: List of supported formats for this plane. To add a new item in the
> + list, write it using a plus and fourcc code: +XR24
> + To remove a format, use a minus and its fourcc: -XR24
From the docs examples it's not obvious that you can add/remove multiple
formats in one write operation ("+XR24 -RG24"), but the implementation
allows it. So either add a more complete example or forbid multiple
operations in one write. I would consider the latter option seriously
because it would simplify the string parsing code, which is very tricky to
get right and robust.
> +++ b/drivers/gpu/drm/vkms/tests/vkms_configfs_test.c
> @@ -0,0 +1,102 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +
> +#include "linux/printk.h"
> +#include <kunit/test.h>
> +
> +#include "../vkms_configfs.h"
> +
> +MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING");
> +
> +/**
> + * struct vkms_configfs_parse_format_case - Store test case for format parsing
> + * @str: Contains the string to parse
> + * @str_len: str len
> + * @expected_len: expected len of the matched format
> + * @expected_offset: expected offset in the string for the parsed format
> + */
> +struct vkms_configfs_parse_format_case {
> + const char *str;
> + int str_len;
> + int expected_len;
> + int expected_offset;
> +};
> +
> +struct vkms_configfs_parse_format_case vkms_configfs_parse_format_test_cases[] = {
> + {
> + .str = "+RG24",
> + .str_len = 6,
> + .expected_len = 5,
> + .expected_offset = 0,
Thanks for having renamed 'data' to 'str'! However now I realize the
'str_len' name becomes misleading: the string length does not include the
training NUL character, while the value you need here does. I beg your
pardon... I guess 'str_len' should be renamed too, maybe to 'str_size' if
no better name comes to mind.
> + }, {
Based on the question I asked after v3,resend and on your answer, I'd add a
clarifying comment here about the following test:
/* ensure the algorithm stops at data_len and not \0 */
> + .str = "-R1111",
> + .str_len = 3,
> + .expected_len = 3,
> + .expected_offset = 0
> + }
Testing wrong and corner cases is more important than testing perfectly
clean cases. So it would be nice to add tests for not-obviously-wrong and
definitely-wrong cases, such as "+ RG24" (note the space), "fubar", "+**",
"*+", "++", "-+", "-A*42" (see below), ":-)" (dash after non-blank char)
and "(-o-)".
> --- a/drivers/gpu/drm/vkms/vkms_configfs.c
> +++ b/drivers/gpu/drm/vkms/vkms_configfs.c
> @@ -3,6 +3,8 @@
> #include <linux/configfs.h>
> #include <linux/mutex.h>
> #include <linux/slab.h>
> +#include <linux/string.h>
> +#include <kunit/visibility.h>
>
> #include "vkms_drv.h"
> #include "vkms_config.h"
> @@ -628,6 +630,120 @@ static ssize_t plane_default_color_encoding_store(struct config_item *item,
> return count;
> }
>
> +static ssize_t plane_supported_formats_show(struct config_item *item, char *page)
> +{
> + struct vkms_configfs_plane *plane;
> +
> + plane = plane_item_to_vkms_configfs_plane(item);
> +
> + page[0] = '\0';
> +
> + scoped_guard(mutex, &plane->dev->lock) {
> + u32 *formats = vkms_config_plane_get_supported_formats(plane->config);
> +
> + for (int i = 0;
> + i < vkms_config_plane_get_supported_formats_count(plane->config);
> + i++) {
> + char tmp[6] = { 0 };
> + const ssize_t ret = snprintf(tmp, ARRAY_SIZE(tmp), "%.*s\n",
> + (int)sizeof(*formats),
> + (char *)&formats[i]);
> + if (ret < 0)
> + return ret;
> + /*
> + * Limitation of ConfigFS attributes, an attribute can't be bigger
> + * than PAGE_SIZE. This will crop the result if this plane support
> + * more than ≈1000 formats.
Every format takes 5 chars, so about 800 formats, no?
> + */
> + if (ret + strlen(page) > PAGE_SIZE - 1)
> + return -ENOMEM;
> + strncat(page, tmp, ARRAY_SIZE(tmp));
> + }
> + }
> +
> + return strlen(page);
> +}
> +
> +/**
> + * parse_next_format() - Parse the next format in page, skipping all non fourcc-related characters
> + * @page: page to search into
> + * @page_end: last character of the page
> + * @out: Output pointer, will point inside page
> + *
> + * Returns: size of the matched format, @out will point to the + or -
> + */
> +VISIBLE_IF_KUNIT
> +int vkms_configfs_parse_next_format(const char *page, const char *page_end, char **out)
> +{
> + int count = page - page_end;
> + char *tmp_plus = strnchr(page, count, '+');
> + char *tmp_minus = strnchr(page, count, '-');
> +
> + if (!tmp_plus && !tmp_minus)
> + return 0;
> + if (!tmp_plus)
> + *out = tmp_minus;
> + else if (!tmp_minus)
> + *out = tmp_plus;
> + else
> + *out = min(tmp_plus, tmp_minus);
> +
> + char *end = *out + 1;
> +
> + while (end < page_end) {
> + if (!isalnum(*end) && *end != '*')
> + break;
> + end++;
> + }
I think this while loop will capture a string like "A*42", which is wrong.
Maybe you could change this function to be both stricter and simpler by not
trying to accept leading spaces, for example.
> +static ssize_t plane_supported_formats_store(struct config_item *item,
> + const char *page, size_t count)
> +{
> + struct vkms_configfs_plane *plane;
> +
> + plane = plane_item_to_vkms_configfs_plane(item);
> + int ret = 0;
> + const char *end_page = page + count;
> +
> + scoped_guard(mutex, &plane->dev->lock) {
> + while (1) {
> + char *tmp;
> + char fmt[4] = {' ', ' ', ' ', ' '};
> + int len = vkms_configfs_parse_next_format(page, end_page, &tmp);
> +
> + // No fourcc code found
> + if (len <= 1 || len > 5)
> + break;
> +
> + page = tmp + len;
> + memcpy(fmt, &tmp[1], min(len - 1, 4));
> + if (tmp[0] == '+') {
> + if (fmt[0] == '*') {
> + ret = vkms_config_plane_add_all_formats(plane->config);
> + if (ret)
> + return ret;
> + } else {
> + ret = vkms_config_plane_add_format(plane->config,
> + *(int *)fmt);
> + if (ret)
> + return ret;
> + }
Minor code simplification:
if (fmt[0] == '*')
ret = vkms_config_plane_add_all_formats(plane->config);
else
ret = vkms_config_plane_add_format(plane->config,
*(int *)fmt);
if (ret)
return ret;
Or, if you like the ternary operator:
ret = (fmt[0] == '*') ?
vkms_config_plane_add_all_formats(plane->config):
vkms_config_plane_add_format(plane->config, *(int *)fmt);
if (ret)
return ret;
I'm sorry some of these comments could have been written asof v2, but this
patch is really intricate and they came to mind only while re-thinking
about the code.
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
next prev parent reply other threads:[~2025-12-23 13:58 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-22 10:11 [PATCH v3 00/33] VKMS: Introduce multiple configFS attributes Louis Chauvet
2025-12-22 10:11 ` [PATCH v3 01/33] Documentation: ABI: vkms: Add current VKMS ABI documentation Louis Chauvet
2025-12-23 11:12 ` Luca Ceresoli
2025-12-22 10:11 ` [PATCH v3 02/33] drm/drm_mode_config: Add helper to get plane type name Louis Chauvet
2025-12-23 11:12 ` Luca Ceresoli
2025-12-22 10:11 ` [PATCH v3 03/33] drm/vkms: Explicitly display plane type Louis Chauvet
2025-12-22 10:11 ` [PATCH v3 04/33] drm/vkms: Use enabled/disabled instead of 1/0 for debug Louis Chauvet
2025-12-22 10:11 ` [PATCH v3 05/33] drm/vkms: Explicitly display connector status Louis Chauvet
2025-12-22 10:11 ` [PATCH v3 06/33] drm/vkms: Introduce config for plane name Louis Chauvet
2025-12-23 11:13 ` Luca Ceresoli
2025-12-22 10:11 ` [PATCH v3 07/33] drm/vkms: Introduce configfs " Louis Chauvet
2025-12-23 11:14 ` Luca Ceresoli
2025-12-29 14:40 ` Louis Chauvet
2025-12-29 16:01 ` José Expósito
2025-12-29 15:51 ` José Expósito
2025-12-22 10:11 ` [PATCH v3 08/33] drm/blend: Get a rotation name from it's bitfield Louis Chauvet
2025-12-22 10:11 ` [PATCH v3 09/33] drm/vkms: Introduce config for plane rotation Louis Chauvet
2025-12-22 10:11 ` [PATCH v3 10/33] drm/vkms: Introduce configfs " Louis Chauvet
2025-12-23 11:14 ` Luca Ceresoli
2025-12-22 10:11 ` [PATCH v3 11/33] drm/drm_color_mgmt: Expose drm_get_color_encoding_name Louis Chauvet
2025-12-22 10:11 ` [PATCH v3 12/33] drm/vkms: Introduce config for plane color encoding Louis Chauvet
2025-12-22 10:11 ` [PATCH v3 13/33] drm/vkms: Introduce configfs " Louis Chauvet
2025-12-23 12:56 ` Luca Ceresoli
2025-12-22 10:11 ` [PATCH v3 14/33] drm/drm_color_mgmt: Expose drm_get_color_range_name Louis Chauvet
2025-12-22 10:11 ` [PATCH v3 15/33] drm/vkms: Introduce config for plane color range Louis Chauvet
2025-12-22 10:11 ` [PATCH v3 16/33] drm/vkms: Introduce configfs " Louis Chauvet
2025-12-23 13:58 ` Luca Ceresoli
2025-12-22 10:11 ` [PATCH v3 17/33] drm/vkms: Introduce config for plane format Louis Chauvet
2025-12-23 13:58 ` Luca Ceresoli
2025-12-29 15:29 ` Louis Chauvet
2025-12-30 9:08 ` Luca Ceresoli
2025-12-22 10:11 ` [PATCH v3 18/33] drm/vkms: Introduce configfs " Louis Chauvet
2025-12-22 23:12 ` kernel test robot
2025-12-23 1:00 ` kernel test robot
2025-12-23 13:06 ` kernel test robot
2025-12-23 13:58 ` Luca Ceresoli [this message]
2025-12-25 0:59 ` Bagas Sanjaya
2025-12-29 15:33 ` Louis Chauvet
2025-12-30 4:37 ` Bagas Sanjaya
2025-12-29 16:09 ` José Expósito
2025-12-29 16:59 ` José Expósito
2025-12-22 10:11 ` [PATCH v3 19/33] drm/vkms: Properly render plane using their zpos Louis Chauvet
2025-12-22 10:11 ` [PATCH v3 20/33] drm/vkms: Introduce config for plane zpos property Louis Chauvet
2025-12-23 15:18 ` Luca Ceresoli
2025-12-22 10:11 ` [PATCH v3 21/33] drm/vkms: Introduce configfs " Louis Chauvet
2025-12-22 10:11 ` [PATCH v3 22/33] drm/vkms: Introduce config for connector type Louis Chauvet
2025-12-22 10:11 ` [PATCH v3 23/33] drm/vkms: Introduce configfs " Louis Chauvet
2025-12-22 10:11 ` [PATCH v3 24/33] drm/connector: Export drm_get_colorspace_name Louis Chauvet
2025-12-22 10:11 ` [PATCH v3 25/33] drm/vkms: Introduce config for connector supported colorspace Louis Chauvet
2025-12-22 10:11 ` [PATCH v3 26/33] drm/vkms: Introduce configfs " Louis Chauvet
2025-12-29 17:26 ` José Expósito
2025-12-22 10:11 ` [PATCH v3 27/33] drm/vkms: Introduce config for connector EDID Louis Chauvet
2025-12-22 10:11 ` [PATCH v3 28/33] drm/vkms: Introduce configfs " Louis Chauvet
2025-12-29 17:20 ` José Expósito
2025-12-29 17:24 ` José Expósito
2025-12-22 10:11 ` [PATCH v3 29/33] drm/vkms: Store the enabled/disabled status for connector Louis Chauvet
2025-12-22 10:11 ` [PATCH v3 30/33] drm/vkms: Rename vkms_connector_init to vkms_connector_init_static Louis Chauvet
2025-12-22 10:11 ` [PATCH v3 31/33] drm/vkms: Extract common code for connector initialization Louis Chauvet
2025-12-22 10:11 ` [PATCH v3 32/33] drm/vkms: Allow to hot-add connectors Louis Chauvet
2025-12-29 17:09 ` José Expósito
2025-12-22 10:11 ` [PATCH v3 33/33] drm/vkms: Introduce configfs for dynamic connector creation Louis Chauvet
2025-12-23 15:17 ` Luca Ceresoli
2025-12-29 17:14 ` José Expósito
2025-12-23 10:30 ` [PATCH v3 00/33] VKMS: Introduce multiple configFS attributes Luca Ceresoli
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=DF5NE5WRSCYT.4NV0451K0SRU@bootlin.com \
--to=luca.ceresoli@bootlin.com \
--cc=airlied@gmail.com \
--cc=corbet@lwn.net \
--cc=dri-devel@lists.freedesktop.org \
--cc=hamohammed.sa@gmail.com \
--cc=jose.exposito89@gmail.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=louis.chauvet@bootlin.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=melissa.srw@gmail.com \
--cc=mripard@kernel.org \
--cc=sebastian.wick@redhat.com \
--cc=simona@ffwll.ch \
--cc=thomas.petazzoni@bootlin.com \
--cc=tzimmermann@suse.de \
--cc=victoria@system76.com \
/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