From: Michal Wajdeczko <michal.wajdeczko@intel.com>
To: "Cavitt, Jonathan" <jonathan.cavitt@intel.com>,
"intel-xe@lists.freedesktop.org" <intel-xe@lists.freedesktop.org>
Cc: "De Marchi, Lucas" <lucas.demarchi@intel.com>
Subject: Re: [PATCH 2/5] drm/xe/configfs: Enforce canonical device names
Date: Fri, 18 Jul 2025 11:06:48 +0200 [thread overview]
Message-ID: <8741334c-1582-488f-82c7-41d1a998f879@intel.com> (raw)
In-Reply-To: <CH0PR11MB5444B56DB80D45010E720F8FE551A@CH0PR11MB5444.namprd11.prod.outlook.com>
On 17.07.2025 23:17, Cavitt, Jonathan wrote:
> -----Original Message-----
> From: Intel-xe <intel-xe-bounces@lists.freedesktop.org> On Behalf Of Michal Wajdeczko
> Sent: Thursday, July 17, 2025 11:48 AM
> To: intel-xe@lists.freedesktop.org
> Cc: Wajdeczko, Michal <Michal.Wajdeczko@intel.com>; De Marchi, Lucas <lucas.demarchi@intel.com>
> Subject: [PATCH 2/5] drm/xe/configfs: Enforce canonical device names
>>
>> While we expect config directory names to match PCI device name,
>> currently we are only scanning provided names for domain, bus,
>> device and function numbers, without checking their format.
>> This would pass slightly broken entries like:
>>
>> /sys/kernel/config/xe/
>> ├── 0000:00:02.0000000000000
>> │ └── ...
>> ├── 0000:00:02.0x
>> │ └── ...
>> ├── 0: 0: 2. 0
>> │ └── ...
>> └── 0:0:2.0
>> └── ...
>>
>> To avoid such mistakes, check if the name provided exactly matches
>> the canonical PCI device address format, which we recreated from
>> the parsed BDF data. Also simplify scanf format as it can't really
>> catch all formatting errors.
>>
>> Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
>> Cc: Lucas De Marchi <lucas.demarchi@intel.com>
>> ---
>> drivers/gpu/drm/xe/xe_configfs.c | 9 ++++++++-
>> 1 file changed, 8 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/xe/xe_configfs.c b/drivers/gpu/drm/xe/xe_configfs.c
>> index e9b46a2d0019..90b4fe92a611 100644
>> --- a/drivers/gpu/drm/xe/xe_configfs.c
>> +++ b/drivers/gpu/drm/xe/xe_configfs.c
>> @@ -259,12 +259,19 @@ static struct config_group *xe_config_make_device_group(struct config_group *gro
>> unsigned int domain, bus, slot, function;
>> struct xe_config_device *dev;
>> struct pci_dev *pdev;
>> + char canonical[16];
>> int ret;
>>
>> - ret = sscanf(name, "%04x:%02x:%02x.%x", &domain, &bus, &slot, &function);
>> + ret = sscanf(name, "%x:%x:%x.%d", &domain, &bus, &slot, &function);
>> if (ret != 4)
>> return ERR_PTR(-EINVAL);
>>
>> + ret = scnprintf(canonical, sizeof(canonical), "%04x:%02x:%02x.%d", domain, bus,
>> + PCI_SLOT(PCI_DEVFN(slot, function)),
>> + PCI_FUNC(PCI_DEVFN(slot, function)));
>
> Does this function have an external-facing interface? If so, I'm a bit worried this might
> break some customer tooling. It's probably not a big deal, as the tools should be passing
> the canonical addresses anyways, but I'm unfortunately somewhat familiar with even
> debug formatting changes breaking external tools, and they've causes endless
> headaches in the past that would be good to avoid.
even if there are tools that were passing non-canonical device names,
then they are already broken, as even if we allowed to create config
directory with with non-canonical name and let configure other
parameters, then driver will never use it as it uses canonical name
while doing lookup for device config, so all those config changes were
effectively silently ignored (without tool being aware of that)
now we will just error early to let the tool know that it is doing
something wrong, so owner of the tool have a chance to fix it
>
> We could probably fix that by using "canonical" instead of "name" later in this function,
> such that even the 'slightly broken' names can be parsed without introducing any new
> rejection cases.
after strcmp() we are rather certain that both 'name' and 'canonical'
are the same strings, so what could be more 'slightly broken' ?
>
> I'll leave that up to you to decide, though.
>
> Reviewed-by: Jonathan Cavitt <jonathan.cavitt@intel.com>
> -Jonathan Cavitt
>
>> + if (ret != 12 || strcmp(name, canonical))
>> + return ERR_PTR(-EINVAL);
>> +
>> pdev = pci_get_domain_bus_and_slot(domain, bus, PCI_DEVFN(slot, function));
>> if (!pdev)
>> return ERR_PTR(-ENODEV);
>> --
>> 2.47.1
>>
>>
next prev parent reply other threads:[~2025-07-18 9:06 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-17 18:48 [PATCH 0/5] Updates for drm/xe/configfs Michal Wajdeczko
2025-07-17 18:48 ` [PATCH 1/5] drm/xe/configfs: Fix pci_dev reference leak Michal Wajdeczko
2025-07-17 19:35 ` Lucas De Marchi
2025-07-17 21:16 ` Cavitt, Jonathan
2025-07-18 8:58 ` Michal Wajdeczko
2025-07-17 18:48 ` [PATCH 2/5] drm/xe/configfs: Enforce canonical device names Michal Wajdeczko
2025-07-17 19:43 ` Lucas De Marchi
2025-07-17 20:27 ` Michal Wajdeczko
2025-07-17 21:17 ` Cavitt, Jonathan
2025-07-18 9:06 ` Michal Wajdeczko [this message]
2025-07-18 14:16 ` Cavitt, Jonathan
2025-07-18 14:05 ` [PATCH v2 " Michal Wajdeczko
2025-07-18 20:52 ` Lucas De Marchi
2025-07-17 18:48 ` [PATCH 3/5] drm/xe/configfs: Use pci_name() for lookup Michal Wajdeczko
2025-07-17 19:44 ` Lucas De Marchi
2025-07-17 21:18 ` Cavitt, Jonathan
2025-07-18 9:23 ` Michal Wajdeczko
2025-07-17 18:48 ` [PATCH 4/5] drm/xe/configfs: Allow configurations only for Intel VGA devices Michal Wajdeczko
2025-07-17 19:52 ` Lucas De Marchi
2025-07-17 20:51 ` Michal Wajdeczko
2025-07-18 21:02 ` Lucas De Marchi
2025-07-17 21:19 ` Cavitt, Jonathan
2025-07-18 9:29 ` Michal Wajdeczko
2025-07-18 14:27 ` Cavitt, Jonathan
2025-07-18 14:33 ` Michal Wajdeczko
2025-07-18 17:28 ` Cavitt, Jonathan
2025-07-18 14:17 ` [PATCH v2 " Michal Wajdeczko
2025-07-17 18:48 ` [PATCH 5/5] drm/xe/configfs: Allow adding configurations for future VFs Michal Wajdeczko
2025-07-17 21:19 ` Cavitt, Jonathan
2025-07-17 19:06 ` ✓ CI.KUnit: success for Updates for drm/xe/configfs Patchwork
2025-07-17 20:13 ` ✓ Xe.CI.BAT: " Patchwork
2025-07-18 14:23 ` ✓ CI.KUnit: success for Updates for drm/xe/configfs (rev3) Patchwork
2025-07-18 15:15 ` ✓ Xe.CI.BAT: " Patchwork
2025-07-19 7:47 ` ✗ Xe.CI.Full: failure for Updates for drm/xe/configfs Patchwork
2025-07-21 10:53 ` ✗ Xe.CI.Full: failure for Updates for drm/xe/configfs (rev3) 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=8741334c-1582-488f-82c7-41d1a998f879@intel.com \
--to=michal.wajdeczko@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=jonathan.cavitt@intel.com \
--cc=lucas.demarchi@intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.