Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Ceraolo Spurio, Daniele" <daniele.ceraolospurio@intel.com>
To: Gustavo Sousa <gustavo.sousa@intel.com>,
	<intel-xe@lists.freedesktop.org>
Cc: Stuart Summers <stuart.summers@intel.com>,
	Julia Filipchuk <julia.filipchuk@intel.com>,
	Alan Previn <alan.previn.teres.alexis@intel.com>
Subject: Re: [PATCH] drm/xe: Add GuC FW path configfs overrides
Date: Fri, 20 Nov 2026 10:58:45 -0800	[thread overview]
Message-ID: <749bb0ce-e077-4b76-9cca-b3c5faad9552@intel.com> (raw)
In-Reply-To: <87bj7jr078.fsf@intel.com>



On 11/20/2026 7:28 AM, Gustavo Sousa wrote:
> Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com> writes:
>
>> Some platforms (e.g. NVL-P) use different GuC binaries for the primary
>> and media GTs, which means that the guc_firmware_path modparam that we
>> use to override the FW on all GTs for testing can't be used on those
>> platforms.
>> This patch adds separate configfs overrides for the 2 GTs, which can be
>> used to tweak their GuC FW paths independently. Note that the modparam
>> is still supported and takes precedence over the configfs.
>> Since the allocation containing the user-provided config is only
>> guaranteed to exist while we hold a reference to the config group, we
>> need to take a copy instead of pointing uc_fw->path directly to it. To
>> keep things simple on the cleanup side, we use a drmm allocation.
>>
>> Signed-off-by: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
>> Cc: Stuart Summers <stuart.summers@intel.com>
>> Cc: Julia Filipchuk <julia.filipchuk@intel.com>
>> Cc: Alan Previn <alan.previn.teres.alexis@intel.com>
>> ---
>>   drivers/gpu/drm/xe/xe_configfs.c | 150 +++++++++++++++++++++++++++++++
>>   drivers/gpu/drm/xe/xe_configfs.h |   2 +
>>   drivers/gpu/drm/xe/xe_uc_fw.c    |   7 +-
>>   3 files changed, 158 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/xe/xe_configfs.c b/drivers/gpu/drm/xe/xe_configfs.c
>> index 2ddd707a6dbd..b6b544c3bc9d 100644
>> --- a/drivers/gpu/drm/xe/xe_configfs.c
>> +++ b/drivers/gpu/drm/xe/xe_configfs.c
>> @@ -13,6 +13,8 @@
>>   #include <linux/pci.h>
>>   #include <linux/string.h>
>>   
>> +#include <drm/drm_managed.h>
>> +
>>   #include "instructions/xe_mi_commands.h"
>>   #include "xe_configfs.h"
>>   #include "xe_defaults.h"
>> @@ -277,6 +279,24 @@
>>    *
>>    * This attribute can only be set before binding to the device.
>>    *
>> + * GuC firmware override
>> + * ---------------------
>> + *
>> + * Override the GuC firmware path for the primary and/or media GT. This is
>> + * useful for testing a newer GuC firmware version without having to update the
>> + * driver. The specified path must be relative to the /lib/firmware directory::
> The path /lib/firmware is not the only base directory that the kernel
> uses for finding firmware.
>
> The documentation at
> Documentation/driver-api/firmware/fw_search_path.rst shows the other possibilities.

Thanks, I'll update the documentation.

>
>> + *
>> + *	# echo 'path/to/guc_firmware' > /sys/kernel/config/xe/0000:03:00.0/primary_gt_guc_override
>> + *	# echo 'path/to/guc_firmware' > /sys/kernel/config/xe/0000:03:00.0/media_gt_guc_override
>> + *
>> + * Writing an empty string disables the override::
>> + *
>> + *	# echo '' > /sys/kernel/config/xe/0000:03:00.0/primary_gt_guc_override
>> + *	# echo '' > /sys/kernel/config/xe/0000:03:00.0/media_gt_guc_override
>> + *
> We probably want to taint the kernel if an override is applied, no? And
> then document that a taint will be added when these options are used.

Good point, I'll add it.

>
>> + * A modparam is also available to override the GuC firmware path for all GTs,
>> + * which takes precedence over the configfs override.
> This is unrelated to this specific patch, but I wonder if it makes sense
> to have the module parameter apply override only to the primary GT if
> the current platform requires different GuCs for the different IPs?

That'd require a meaningful rework since one IP has no idea of which GuC 
FW the other IP is (or would be) using. I don't think it's worth the effort.

>
> Another thing that comes to mind: is it okay to load different GuCs on
> platforms that use the same GuC binary for both IPs?

Theoretically it is ok to load different GuCs even if a platform 
normally uses the same binary on both IPs, but I don't think anyone has 
done any in depth testing for this (I did try it on PTL when preparing 
this patch, but I only ran xe_exec_basic as testing).

>
>> + *
>>    * Remove devices
>>    * ==============
>>    *
>> @@ -309,6 +329,11 @@ struct xe_config_group_device {
>>   			unsigned int max_vfs;
>>   			bool admin_only_pf;
>>   		} sriov;
>> +
>> +		struct {
>> +			char *primary_gt;
>> +			char *media_gt;
>> +		} guc_overrides;
>>   	} config;
>>   
>>   	/* protects attributes */
>> @@ -331,6 +356,10 @@ static const struct xe_config_device device_defaults = {
>>   		.max_vfs = XE_DEFAULT_MAX_VFS,
>>   		.admin_only_pf = XE_DEFAULT_ADMIN_ONLY_PF,
>>   	},
>> +	.guc_overrides = {
>> +		.primary_gt = NULL,
>> +		.media_gt = NULL,
>> +	},
>>   };
>>   
>>   static void set_device_defaults(struct xe_config_device *config)
>> @@ -937,6 +966,84 @@ static ssize_t ctx_restore_post_bb_store(struct config_item *item,
>>   	return wa_bb_store(dev->config.ctx_restore_post_bb, dev, data, sz);
>>   }
>>   
>> +static ssize_t __gt_guc_override_show(struct xe_config_group_device *dev,
>> +				      char **override, char *page)
>> +{
>> +	guard(mutex)(&dev->lock);
>> +
>> +	return sprintf(page, "%s\n", *override ? *override : "no override");
>> +}
>> +
>> +static ssize_t __gt_guc_override_store(struct xe_config_group_device *dev,
>> +				       char **override, const char *page, size_t len)
>> +{
>> +	char *path;
>> +
>> +	if (len > PATH_MAX)
>> +		return -EINVAL;
>> +
>> +	guard(mutex)(&dev->lock);
>> +	if (is_bound(dev))
>> +		return -EBUSY;
>> +
>> +	/*
>> +	 * An empty string disables the override. Some bash commands can add a
>> +	 * '\n' or '\0 ' at the end of the string, so consider a string of
>> +	 * length 1 containing one of those characters as empty.
>> +	 */
>> +	if (!len || (len == 1 && (page[0] == '\n' || page[0] == '\0'))) {
>> +		kfree(*override);
>> +		*override = NULL;
>> +	} else {
>> +		path = krealloc(*override, len + 1, GFP_KERNEL);
>> +		if (!path)
>> +			return -ENOMEM;
>> +
>> +		memcpy(path, page, len);
>> +
>> +		/*
>> +		 * the echo command adds a trailing newline unless the -n option
>> +		 * is used, so replace it if present.
>> +		 */
>> +		if (path[len - 1] == '\n')
>> +			path[len - 1] = '\0';
>> +		else
>> +			path[len] = '\0';
> I think we could handle the trailing chars stuff in a single place with
> something like below.  What do you think?

Looks reasonable, let me test it out.

Daniele

>
>      |diff --git a/drivers/gpu/drm/xe/xe_configfs.c b/drivers/gpu/drm/xe/xe_configfs.c
>      |index b6b544c3bc9d..1a763d9f241c 100644
>      |--- a/drivers/gpu/drm/xe/xe_configfs.c
>      |+++ b/drivers/gpu/drm/xe/xe_configfs.c
>      |@@ -978,6 +978,7 @@ static ssize_t __gt_guc_override_store(struct xe_config_group_device *dev,
>      | 				       char **override, const char *page, size_t len)
>      | {
>      | 	char *path;
>      |+	size_t path_len;
>      |
>      | 	if (len > PATH_MAX)
>      | 		return -EINVAL;
>      |@@ -987,28 +988,27 @@ static ssize_t __gt_guc_override_store(struct xe_config_group_device *dev,
>      | 		return -EBUSY;
>      |
>      | 	/*
>      |-	 * An empty string disables the override. Some bash commands can add a
>      |-	 * '\n' or '\0 ' at the end of the string, so consider a string of
>      |-	 * length 1 containing one of those characters as empty.
>      |+	 * Some bash commands can add a trailing '\n' or '\0'.  Use
>      |+	 * path_len as the normalized length.
>      | 	 */
>      |-	if (!len || (len == 1 && (page[0] == '\n' || page[0] == '\0'))) {
>      |+	path_len = len;
>      |+	if (path_len && (page[path_len - 1] == '\n' || page[path_len - 1] == '\0'))
>      |+		path_len--;
>      |+
>      |+	/*
>      |+	 * An empty string disables the override.
>      |+	 */
>      |+	if (!path_len) {
>      | 		kfree(*override);
>      | 		*override = NULL;
>      | 	} else {
>      |-		path = krealloc(*override, len + 1, GFP_KERNEL);
>      |+		path = krealloc(*override, path_len + 1, GFP_KERNEL);
>      | 		if (!path)
>      | 			return -ENOMEM;
>      |
>      |-		memcpy(path, page, len);
>      |+		memcpy(path, page, path_len);
>      |
>      |-		/*
>      |-		 * the echo command adds a trailing newline unless the -n option
>      |-		 * is used, so replace it if present.
>      |-		 */
>      |-		if (path[len - 1] == '\n')
>      |-			path[len - 1] = '\0';
>      |-		else
>      |-			path[len] = '\0';
>      |+		path[path_len] = '\0';
>      |
>      | 		*override = path;
>      | 	}
>
> --
> Gustavo Sousa
>
>> +
>> +		*override = path;
>> +	}
>> +
>> +	return len;
>> +}
>> +
>> +static ssize_t primary_gt_guc_override_show(struct config_item *item, char *page)
>> +{
>> +	struct xe_config_group_device *dev = to_xe_config_group_device(item);
>> +
>> +	return __gt_guc_override_show(dev, &dev->config.guc_overrides.primary_gt, page);
>> +}
>> +
>> +static ssize_t primary_gt_guc_override_store(struct config_item *item, const char *page, size_t len)
>> +{
>> +	struct xe_config_group_device *dev = to_xe_config_group_device(item);
>> +
>> +	return __gt_guc_override_store(dev, &dev->config.guc_overrides.primary_gt, page, len);
>> +}
>> +
>> +static ssize_t media_gt_guc_override_show(struct config_item *item, char *page)
>> +{
>> +	struct xe_config_group_device *dev = to_xe_config_group_device(item);
>> +
>> +	return __gt_guc_override_show(dev, &dev->config.guc_overrides.media_gt, page);
>> +}
>> +
>> +static ssize_t media_gt_guc_override_store(struct config_item *item, const char *page, size_t len)
>> +{
>> +	struct xe_config_group_device *dev = to_xe_config_group_device(item);
>> +
>> +	return __gt_guc_override_store(dev, &dev->config.guc_overrides.media_gt, page, len);
>> +}
>> +
>>   CONFIGFS_ATTR(, ctx_restore_mid_bb);
>>   CONFIGFS_ATTR(, ctx_restore_post_bb);
>>   CONFIGFS_ATTR(, enable_multi_queue);
>> @@ -945,6 +1052,8 @@ CONFIGFS_ATTR(, enable_psmi);
>>   CONFIGFS_ATTR(, disable_vram_page_offline);
>>   CONFIGFS_ATTR(, engines_allowed);
>>   CONFIGFS_ATTR(, gt_types_allowed);
>> +CONFIGFS_ATTR(, media_gt_guc_override);
>> +CONFIGFS_ATTR(, primary_gt_guc_override);
>>   CONFIGFS_ATTR(, survivability_mode);
>>   
>>   static struct configfs_attribute *xe_config_device_attrs[] = {
>> @@ -956,6 +1065,8 @@ static struct configfs_attribute *xe_config_device_attrs[] = {
>>   	&attr_disable_vram_page_offline,
>>   	&attr_engines_allowed,
>>   	&attr_gt_types_allowed,
>> +	&attr_media_gt_guc_override,
>> +	&attr_primary_gt_guc_override,
>>   	&attr_survivability_mode,
>>   	NULL,
>>   };
>> @@ -966,6 +1077,8 @@ static void xe_config_device_release(struct config_item *item)
>>   
>>   	mutex_destroy(&dev->lock);
>>   
>> +	kfree(dev->config.guc_overrides.primary_gt);
>> +	kfree(dev->config.guc_overrides.media_gt);
>>   	kfree(dev->config.ctx_restore_mid_bb[0].cs);
>>   	kfree(dev->config.ctx_restore_post_bb[0].cs);
>>   	kfree(dev);
>> @@ -1479,6 +1592,43 @@ u32 xe_configfs_get_ctx_restore_post_bb(struct pci_dev *pdev,
>>   	return len;
>>   }
>>   
>> +/**
>> + * xe_configfs_guc_override - get configfs guc override path
>> + * @pdev: pci device
>> + * @gt_type: type of the GT for which to get the guc override path
>> + *
>> + * Return: A new drmm-managed allocation containing the path to the specified GT
>> + * guc override if set, NULL otherwise
>> + */
>> +const char *xe_configfs_guc_override(struct pci_dev *pdev, enum xe_gt_type gt_type)
>> +{
>> +	struct xe_config_group_device *dev = find_xe_config_group_device(pdev);
>> +	struct drm_device *drm = pci_get_drvdata(pdev);
>> +	const char *override, *path = NULL;
>> +
>> +	if (!dev)
>> +		return NULL;
>> +
>> +	if (!drm)
>> +		goto out_put;
>> +
>> +	scoped_guard(mutex, &dev->lock) {
>> +		if (gt_type == XE_GT_TYPE_MAIN)
>> +			override = dev->config.guc_overrides.primary_gt;
>> +		else if (gt_type == XE_GT_TYPE_MEDIA)
>> +			override = dev->config.guc_overrides.media_gt;
>> +		else
>> +			override = NULL;
>> +
>> +		if (override)
>> +			path = drmm_kstrdup(drm, override, GFP_KERNEL);
>> +	}
>> +
>> +out_put:
>> +	config_group_put(&dev->group);
>> +	return path;
>> +}
>> +
>>   #ifdef CONFIG_PCI_IOV
>>   /**
>>    * xe_configfs_admin_only_pf() - Get PF's operational mode.
>> diff --git a/drivers/gpu/drm/xe/xe_configfs.h b/drivers/gpu/drm/xe/xe_configfs.h
>> index d726800de26a..514f115e1977 100644
>> --- a/drivers/gpu/drm/xe/xe_configfs.h
>> +++ b/drivers/gpu/drm/xe/xe_configfs.h
>> @@ -9,6 +9,7 @@
>>   #include <linux/types.h>
>>   
>>   #include "xe_defaults.h"
>> +#include "xe_gt_types.h"
>>   #include "xe_hw_engine_types.h"
>>   #include "xe_module.h"
>>   
>> @@ -31,6 +32,7 @@ u32 xe_configfs_get_ctx_restore_mid_bb(struct pci_dev *pdev,
>>   u32 xe_configfs_get_ctx_restore_post_bb(struct pci_dev *pdev,
>>   					enum xe_engine_class class,
>>   					const u32 **cs);
>> +const char *xe_configfs_guc_override(struct pci_dev *pdev, enum xe_gt_type gt_type);
>>   #ifdef CONFIG_PCI_IOV
>>   unsigned int xe_configfs_get_max_vfs(struct pci_dev *pdev);
>>   bool xe_configfs_admin_only_pf(struct pci_dev *pdev);
>> diff --git a/drivers/gpu/drm/xe/xe_uc_fw.c b/drivers/gpu/drm/xe/xe_uc_fw.c
>> index c042075a36e5..98cf7f658b8e 100644
>> --- a/drivers/gpu/drm/xe/xe_uc_fw.c
>> +++ b/drivers/gpu/drm/xe/xe_uc_fw.c
>> @@ -10,7 +10,9 @@
>>   #include <drm/drm_managed.h>
>>   
>>   #include "regs/xe_guc_regs.h"
>> +#include "xe_any.h"
>>   #include "xe_bo.h"
>> +#include "xe_configfs.h"
>>   #include "xe_device_types.h"
>>   #include "xe_force_wake.h"
>>   #include "xe_gsc.h"
>> @@ -291,13 +293,16 @@ uc_fw_auto_select(struct xe_device *xe, struct xe_uc_fw *uc_fw)
>>   static void
>>   uc_fw_override(struct xe_uc_fw *uc_fw)
>>   {
>> -	char *path_override = NULL;
>> +	struct xe_gt *gt = uc_fw_to_gt(uc_fw);
>> +	const char *path_override = NULL;
>>   
>>   	/* empty string disables, but it's not allowed for GuC */
>>   	switch (uc_fw->type) {
>>   	case XE_UC_FW_TYPE_GUC:
>>   		if (xe_modparam.guc_firmware_path && *xe_modparam.guc_firmware_path)
>>   			path_override = xe_modparam.guc_firmware_path;
>> +		else
>> +			path_override = xe_configfs_guc_override(xe_any_to_pdev(gt), gt->info.type);
>>   		break;
>>   	case XE_UC_FW_TYPE_HUC:
>>   		path_override = xe_modparam.huc_firmware_path;
>> -- 
>> 2.53.0


      reply	other threads:[~2026-11-20 18:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19  1:46 [PATCH] drm/xe: Add GuC FW path configfs overrides Daniele Ceraolo Spurio
2026-11-19  2:00 ` sashiko-bot
2026-11-19  6:49 ` ✓ CI.KUnit: success for " Patchwork
2026-11-19  7:25 ` ✓ Xe.CI.BAT: " Patchwork
2026-11-20 11:00 ` ✗ Xe.CI.FULL: failure " Patchwork
2026-11-20 15:28 ` [PATCH] " Gustavo Sousa
2026-11-20 18:58   ` Ceraolo Spurio, Daniele [this message]

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=749bb0ce-e077-4b76-9cca-b3c5faad9552@intel.com \
    --to=daniele.ceraolospurio@intel.com \
    --cc=alan.previn.teres.alexis@intel.com \
    --cc=gustavo.sousa@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=julia.filipchuk@intel.com \
    --cc=stuart.summers@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox