drm/xe: Improve wedged mode handling
Subsystems (2)
v4 cover drm/xe: Improve wedged mode handling
Prevent the VF from attempting to update the GuC reset policy when changing the wedged mode, as this operation is not supported on VFs.
Additionally, validate the wedged_mode module parameter input, update the internal wedged.mode state only on success, and allow setting wedged_mode=2 only in debug builds if running as PF.
v1: https://patchwork.freedesktop.org/series/148214/#rev1
v2: Replace magic numbers with definitions (Matt, Michal)
Use helper to sanitize wedged_mode (Michal)
Change debug messages (Michal)
Reorder patches (Michal)
Add fixes tag (Matt)
v3: Rename xe_device_wedged_mode_validate to
xe_device_validate_wedged_mode (Michal)
Make enum nameless (Michal)
Add default field in enum (Michal)
Change names of enum fields to match modparam description (Michal)
v4: Fix GuC reset policy update
Replace missing magic numbers with definitions
Update debug message
Lukasz Laguna (4):
drm/xe: Validate wedged_mode parameter and define enum for modes drm/xe: Don't update wedged mode in case of an error drm/xe/vf: Disallow setting wedged_mode=2
drm/xe/pf: Allow wedged_mode=2 only in debug config
drivers/gpu/drm/xe/xe_debugfs.c | 13 ++++++------ drivers/gpu/drm/xe/xe_device.c | 30 ++++++++++++++++++++++++++-- drivers/gpu/drm/xe/xe_device.h | 1 + drivers/gpu/drm/xe/xe_device_types.h | 7 ++++++- drivers/gpu/drm/xe/xe_guc_ads.c | 9 +++++---- drivers/gpu/drm/xe/xe_guc_ads.h | 3 ++- drivers/gpu/drm/xe/xe_guc_capture.c | 3 ++- drivers/gpu/drm/xe/xe_guc_submit.c | 6 +++--- drivers/gpu/drm/xe/xe_module.c | 5 +++-- drivers/gpu/drm/xe/xe_module.h | 2 +- 10 files changed, 58 insertions(+), 21 deletions(-)
Signature · 1 line
2.40.0
PATCH v4 1/4 drm/xe: Validate wedged_mode parameter and define enum for modes
Check correctness of the wedged_mode parameter input to ensure only supported values are accepted. Additionally, replace magic numbers with a clearly defined enum.
--- drivers/gpu/drm/xe/xe_debugfs.c | 5 +++-- drivers/gpu/drm/xe/xe_device.c | 25 +++++++++++++++++++++++-- drivers/gpu/drm/xe/xe_device.h | 1 + drivers/gpu/drm/xe/xe_device_types.h | 7 ++++++- drivers/gpu/drm/xe/xe_guc_ads.c | 4 ++-- drivers/gpu/drm/xe/xe_guc_capture.c | 3 ++- drivers/gpu/drm/xe/xe_guc_submit.c | 6 +++--- drivers/gpu/drm/xe/xe_module.c | 5 +++-- drivers/gpu/drm/xe/xe_module.h | 2 +- 9 files changed, 44 insertions(+), 14 deletions(-)
drivers/gpu/drm/xe/xe_debugfs.c +3 -2
@@ -163,8 +163,9 @@ static ssize_t wedged_mode_set(struct file *f, const char __user *ubuf,if (ret)return ret; -if (wedged_mode >2 ) -return -EINVAL ; + ret =xe_device_validate_wedged_mode (xe, wedged_mode); +if (ret) +return ret;if (xe->wedged.mode == wedged_mode)return size;
drivers/gpu/drm/xe/xe_device.c +23 -2
@@ -730,7 +730,9 @@ int xe_device_probe_early(struct xe_device *xe)if (err)return err; - xe->wedged.mode = xe_modparam.wedged_mode; + xe->wedged.mode =xe_device_validate_wedged_mode (xe, xe_modparam.wedged_mode) ? +XE_WEDGED_MODE_DEFAULT : xe_modparam.wedged_mode; +drm_dbg (&xe->drm,"wedged_mode: setting mode (%u)\n" , xe->wedged.mode);return 0 ; }
@@ -1144,7 +1146,7 @@ void xe_device_declare_wedged(struct xe_device *xe)struct xe_gt *gt;u8 id; -if (xe->wedged.mode ==0 ) { +if (xe->wedged.mode ==XE_WEDGED_MODE_NEVER ) {drm_dbg (&xe->drm,"Wedged mode is forcibly disabled\n" );return ; }
@@ -1172,3 +1174,22 @@ void xe_device_declare_wedged(struct xe_device *xe)for_each_gt (gt, xe, id)xe_gt_declare_wedged (gt); } + +/** +* xe_device_validate_wedged_mode() - Check if given mode is supported +* @xe: the &xe_device +* @mode: requested mode to validate +* +* Check whether the provided wedged mode is supported. +* +* Return: 0 if mode is supported, error code otherwise. +*/ +int xe_device_validate_wedged_mode (struct xe_device *xe,unsigned int mode) +{ +if (mode >XE_WEDGED_MODE_UPON_ANY_HANG ) { +drm_dbg (&xe->drm,"wedged_mode: invalid value (%u)\n" , mode); +return -EINVAL ; + } + +return 0 ; +}
drivers/gpu/drm/xe/xe_device.h +1 -0
@@ -191,6 +191,7 @@ static inline bool xe_device_wedged(struct xe_device *xe) }void xe_device_declare_wedged (struct xe_device *xe); +int xe_device_validate_wedged_mode (struct xe_device *xe,unsigned int mode);struct xe_file *xe_file_get (struct xe_file *xef);void xe_file_put (struct xe_file *xef);
drivers/gpu/drm/xe/xe_device_types.h +6 -1
@@ -558,7 +558,12 @@ struct xe_device {/** @wedged.flag: Xe device faced a critical error and is now blocked. */ atomic_t flag;/** @wedged.mode: Mode controlled by kernel parameter and debugfs */ -int mode; +enum xe_wedged_mode { +XE_WEDGED_MODE_NEVER =0 , +XE_WEDGED_MODE_UPON_CRITICAL_ERROR =1 , +XE_WEDGED_MODE_UPON_ANY_HANG =2 , +XE_WEDGED_MODE_DEFAULT =XE_WEDGED_MODE_UPON_CRITICAL_ERROR , + } mode; } wedged;/** @bo_device: Struct to control async free of BOs */
drivers/gpu/drm/xe/xe_guc_ads.c +2 -2
@@ -469,7 +469,7 @@ static void guc_policies_init(struct xe_guc_ads *ads)ads_blob_write (ads, policies.max_num_work_items,GLOBAL_POLICY_MAX_NUM_WI ); -if (xe->wedged.mode ==2 ) +if (xe->wedged.mode ==XE_WEDGED_MODE_UPON_ANY_HANG ) global_flags |=GLOBAL_POLICY_DISABLE_ENGINE_RESET ;ads_blob_write (ads, policies.global_flags, global_flags);
@@ -1018,7 +1018,7 @@ int xe_guc_ads_scheduler_policy_toggle_reset(struct xe_guc_ads *ads) policies->dpc_promote_time =ads_blob_read (ads, policies.dpc_promote_time); policies->max_num_work_items =ads_blob_read (ads, policies.max_num_work_items); policies->is_valid =1 ; -if (xe->wedged.mode ==2 ) +if (xe->wedged.mode ==XE_WEDGED_MODE_UPON_ANY_HANG ) policies->global_flags |=GLOBAL_POLICY_DISABLE_ENGINE_RESET ;else policies->global_flags &= ~GLOBAL_POLICY_DISABLE_ENGINE_RESET ;
drivers/gpu/drm/xe/xe_guc_capture.c +2 -1
@@ -1856,7 +1856,8 @@ xe_guc_capture_get_matching_and_lock(struct xe_exec_queue *q)return NULL ; xe =gt_to_xe (q->gt); -if (xe->wedged.mode >=2 || !xe_device_uc_enabled (xe) ||IS_SRIOV_VF (xe)) +if (xe->wedged.mode ==XE_WEDGED_MODE_UPON_ANY_HANG || !xe_device_uc_enabled (xe) || +IS_SRIOV_VF (xe))return NULL ; ss = &xe->devcoredump.snapshot;
drivers/gpu/drm/xe/xe_guc_submit.c +3 -3
@@ -863,8 +863,8 @@ void xe_guc_submit_wedge(struct xe_guc *guc) err =devm_add_action_or_reset (guc_to_xe (guc)->drm.dev, guc_submit_wedged_fini, guc);if (err) { -xe_gt_err (gt,"Failed to register clean-up on wedged.mode=2; " -"Although device is wedged.\n" ); +xe_gt_err (gt,"Failed to register clean-up on wedged.mode=%u; " +"Although device is wedged.\n" ,XE_WEDGED_MODE_UPON_ANY_HANG );return ; }
@@ -879,7 +879,7 @@ static bool guc_submit_hint_wedged(struct xe_guc *guc) {struct xe_device *xe =guc_to_xe (guc); -if (xe->wedged.mode !=2 ) +if (xe->wedged.mode !=XE_WEDGED_MODE_UPON_ANY_HANG )return false;if (xe_device_wedged (xe))
drivers/gpu/drm/xe/xe_module.c +3 -2
@@ -10,6 +10,7 @@#include <drm/drm_module.h> +#include "xe_device.h" #include "xe_drv.h" #include "xe_configfs.h" #include "xe_hw_fence.h"
@@ -25,7 +26,7 @@ struct xe_modparam xe_modparam = {#ifdef CONFIG_PCI_IOV .max_vfs = IS_ENABLED(CONFIG_DRM_XE_DEBUG) ? ~0 : 0, #endif - .wedged_mode = 1, + .wedged_mode = XE_WEDGED_MODE_DEFAULT, .svm_notifier_size = 512, /* the rest are 0 by default */ };
@@ -68,7 +69,7 @@ MODULE_PARM_DESC(max_vfs, "(0 = no VFs [default]; N = allow up to N VFs)");#endif -module_param_named_unsafe (wedged_mode, xe_modparam.wedged_mode, int,0600 ); +module_param_named_unsafe (wedged_mode, xe_modparam.wedged_mode, uint,0600 );MODULE_PARM_DESC (wedged_mode,"Module's default policy for the wedged mode - 0=never, 1=upon-critical-errors[default], 2=upon-any-hang" );
drivers/gpu/drm/xe/xe_module.h +1 -1
@@ -21,7 +21,7 @@ struct xe_modparam {#ifdef CONFIG_PCI_IOV unsigned int max_vfs;#endif -int wedged_mode; +unsigned int wedged_mode;u32 svm_notifier_size; };
Signature · 1 line
2.40.0
PATCH v4 2/4 drm/xe: Don't update wedged mode in case of an error
In reply to Lukasz LagunaUpdate driver's internal wedged.mode state only in case of a success to avoid inconsistent state.
--- drivers/gpu/drm/xe/xe_debugfs.c | 8 ++++---- drivers/gpu/drm/xe/xe_guc_ads.c | 7 ++++--- drivers/gpu/drm/xe/xe_guc_ads.h | 3 ++- 3 files changed, 10 insertions(+), 8 deletions(-)
drivers/gpu/drm/xe/xe_debugfs.c +4 -4
@@ -170,19 +170,19 @@ static ssize_t wedged_mode_set(struct file *f, const char __user *ubuf,if (xe->wedged.mode == wedged_mode)return size; - xe->wedged.mode = wedged_mode; -xe_pm_runtime_get (xe);for_each_gt (gt, xe, id) { - ret =xe_guc_ads_scheduler_policy_toggle_reset (>->uc.guc.ads); + ret =xe_guc_ads_scheduler_policy_toggle_reset (>->uc.guc.ads, wedged_mode);if (ret) { -xe_gt_err (gt,"Failed to update GuC ADS scheduler policy. GuC may still cause engine reset even with wedged_mode=2\n" ); +xe_gt_err (gt,"Failed to update GuC ADS scheduler policy\n" );xe_pm_runtime_put (xe);return -EIO ; } }xe_pm_runtime_put (xe); + xe->wedged.mode = wedged_mode; +return size; }
drivers/gpu/drm/xe/xe_guc_ads.c +4 -3
@@ -997,12 +997,13 @@ static int guc_ads_action_update_policies(struct xe_guc_ads *ads, u32 policy_off/** * xe_guc_ads_scheduler_policy_toggle_reset - Toggle reset policy * @ads: Additional data structures object +* @mode: The wedged mode * -* This function update the GuC's engine reset policy based on wedged.mode. +* This function update the GuC's engine reset policy based on wedged mode. * * Return: 0 on success, and negative error code otherwise. */ -int xe_guc_ads_scheduler_policy_toggle_reset (struct xe_guc_ads *ads) +int xe_guc_ads_scheduler_policy_toggle_reset (struct xe_guc_ads *ads,enum xe_wedged_mode mode) {struct xe_device *xe =ads_to_xe (ads);struct xe_gt *gt =ads_to_gt (ads);
@@ -1018,7 +1019,7 @@ int xe_guc_ads_scheduler_policy_toggle_reset(struct xe_guc_ads *ads) policies->dpc_promote_time =ads_blob_read (ads, policies.dpc_promote_time); policies->max_num_work_items =ads_blob_read (ads, policies.max_num_work_items); policies->is_valid =1 ; -if (xe->wedged.mode ==XE_WEDGED_MODE_UPON_ANY_HANG ) +if (mode ==XE_WEDGED_MODE_UPON_ANY_HANG ) policies->global_flags |=GLOBAL_POLICY_DISABLE_ENGINE_RESET ;else policies->global_flags &= ~GLOBAL_POLICY_DISABLE_ENGINE_RESET ;
drivers/gpu/drm/xe/xe_guc_ads.h +2 -1
@@ -7,12 +7,13 @@#define _XE_GUC_ADS_H_struct xe_guc_ads ; +enum xe_wedged_mode ;int xe_guc_ads_init (struct xe_guc_ads *ads);int xe_guc_ads_init_post_hwconfig (struct xe_guc_ads *ads);void xe_guc_ads_populate (struct xe_guc_ads *ads);void xe_guc_ads_populate_minimal (struct xe_guc_ads *ads);void xe_guc_ads_populate_post_load (struct xe_guc_ads *ads); -int xe_guc_ads_scheduler_policy_toggle_reset (struct xe_guc_ads *ads); +int xe_guc_ads_scheduler_policy_toggle_reset (struct xe_guc_ads *ads,enum xe_wedged_mode mode);#endif
Signature · 1 line
2.40.0
PATCH v4 3/4 drm/xe/vf: Disallow setting wedged_mode=2
In reply to Lukasz LagunaIn wedged_mode=2, engine resets need to be disabled, which requires changing the GuC reset policy. VFs are not permitted to do that.
--- drivers/gpu/drm/xe/xe_device.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/xe/xe_device.c +4 -0
@@ -1189,6 +1189,10 @@ int xe_device_validate_wedged_mode(struct xe_device *xe, unsigned int mode)if (mode >XE_WEDGED_MODE_UPON_ANY_HANG ) {drm_dbg (&xe->drm,"wedged_mode: invalid value (%u)\n" , mode);return -EINVAL ; + }else if (mode ==XE_WEDGED_MODE_UPON_ANY_HANG &&IS_SRIOV_VF (xe)) { +drm_dbg (&xe->drm,"wedged_mode: unsupported mode (%u) for %s\n" , mode, +xe_sriov_mode_to_string (xe_device_sriov_mode (xe))); +return -EPERM ; }return 0 ;
Signature · 1 line
2.40.0
PATCH v4 4/4 drm/xe/pf: Allow wedged_mode=2 only in debug config
In reply to Lukasz LagunaThe GuC reset policy is global, so changing it on PF can impact running VFs. To avoid unintended side effects, setting wedged_mode=2 on the PF is restricted to debug builds only.
--- drivers/gpu/drm/xe/xe_device.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_device.c +2 -1
@@ -1189,7 +1189,8 @@ int xe_device_validate_wedged_mode(struct xe_device *xe, unsigned int mode)if (mode >XE_WEDGED_MODE_UPON_ANY_HANG ) {drm_dbg (&xe->drm,"wedged_mode: invalid value (%u)\n" , mode);return -EINVAL ; - }else if (mode ==XE_WEDGED_MODE_UPON_ANY_HANG &&IS_SRIOV_VF (xe)) { + }else if (mode ==XE_WEDGED_MODE_UPON_ANY_HANG && (IS_SRIOV_VF (xe) || + (IS_SRIOV_PF (xe) && !IS_ENABLED (CONFIG_DRM_XE_DEBUG )))) {drm_dbg (&xe->drm,"wedged_mode: unsupported mode (%u) for %s\n" , mode,xe_sriov_mode_to_string (xe_device_sriov_mode (xe)));return -EPERM ;
Signature · 1 line
2.40.0