PF: Improve VF control
Subsystems (2)
cover PF: Improve VF control
Our initial VF control implementation was focused on providing a very minimal support for the VF_STATE_NOTIFY events just to meet GuC requirements, without tracking a VF state or doing any expected actions (like cleanup in case of the FLR notification).
Michal Wajdeczko (12):
drm/xe/pf: Add function to sanitize VF resources drm/xe/pf: Fix documentation formatting
drm/xe/pf: Drop GuC notifications for non-existing VF drm/xe/pf: Improve VF control
drm/xe/tests: Allow deferred function call during KUnit test drm/xe/tests: Add helper macro to detect if KUnit is running drm/xe/tests: Add helpers to call stubs out of KUnit context drm/xe/guc: Define stub for xe_guc_ct_send_recv() drm/xe/pf: Define stub for pf_sanitize_vf_resources() drm/xe/pf: Define stub for pf_send_vf_control_cmd() drm/xe/tests: Add KUnit tests for VF control state machines drm/xe/tests: Add KUnit tests for VF control GuC messages
.../xe/tests/xe_gt_sriov_pf_control_kunit.c | 1554 +++++++++++++++++ drivers/gpu/drm/xe/tests/xe_kunit_helpers.c | 148 ++ drivers/gpu/drm/xe/tests/xe_kunit_helpers.h | 38 + drivers/gpu/drm/xe/tests/xe_test.h | 77 + drivers/gpu/drm/xe/xe_gt_sriov_pf.c | 6 + drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c | 86 + drivers/gpu/drm/xe/xe_gt_sriov_pf_config.h | 1 + .../gpu/drm/xe/xe_gt_sriov_pf_config_types.h | 5 + drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c | 1271 +++++++++++++- drivers/gpu/drm/xe/xe_gt_sriov_pf_control.h | 3 + .../gpu/drm/xe/xe_gt_sriov_pf_control_types.h | 114 ++ drivers/gpu/drm/xe/xe_gt_sriov_pf_types.h | 6 + drivers/gpu/drm/xe/xe_guc_ct.c | 2 + drivers/gpu/drm/xe/xe_guc_ct_types.h | 5 + 14 files changed, 3275 insertions(+), 41 deletions(-) create mode 100644 drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c create mode 100644 drivers/gpu/drm/xe/xe_gt_sriov_pf_control_types.h
Signature · 1 line
2.43.0
PATCH 1/12 drm/xe/pf: Add function to sanitize VF resources
On current platforms it is a PF driver responsibility to clear some of the VF's resources during a VF FLR. Add simple function that will clear configured VF resources (GGTT, LMEM). We will start using this function soon.
--- drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c | 84 ++++++++++++++++++++++ drivers/gpu/drm/xe/xe_gt_sriov_pf_config.h | 1 + 2 files changed, 85 insertions(+)
drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c +84 -0
@@ -29,6 +29,7 @@#include "xe_guc_submit.h" #include "xe_lmtt.h" #include "xe_map.h" +#include "xe_migrate.h" #include "xe_sriov.h" #include "xe_ttm_vram_mgr.h" #include "xe_wopcm.h"
@@ -1893,6 +1894,89 @@ int xe_gt_sriov_pf_config_release(struct xe_gt *gt, unsigned int vfid, bool forcreturn force ?0 : err; } +static void pf_sanitize_ggtt (struct xe_tile *tile,struct drm_mm_node *node,unsigned int vfid) +{ +struct xe_ggtt *ggtt = tile->mem.ggtt; + +if (drm_mm_node_allocated (node)) +xe_ggtt_assign (ggtt, node, vfid); +} + +static int pf_sanitize_lmem (struct xe_tile *tile,struct xe_bo *bo,long timeout) +{ +struct xe_migrate *m = tile->migrate; +struct dma_fence *fence; +int err; + +if (!bo) +return 0 ; + +xe_bo_lock (bo, false); + fence =xe_migrate_clear (m, bo, bo->ttm.resource); +if (IS_ERR (fence)) { + err =PTR_ERR (fence); + }else if (!fence) { + err = -ENOMEM ; + }else { +long ret =dma_fence_wait_timeout (fence, false, timeout); + + err = ret >0 ?0 : ret <0 ? ret : -ETIMEDOUT ; +dma_fence_put (fence); +if (!err) +xe_gt_sriov_dbg_verbose (tile->primary_gt,"LMEM cleared in %dms\n" , +jiffies_to_msecs (timeout - ret)); + } +xe_bo_unlock (bo); + +return err; +} + +static int pf_sanitize_vf_resources (struct xe_gt *gt,u32 vfid,long timeout) +{ +struct xe_gt_sriov_config *config =pf_pick_vf_config (gt, vfid); +struct xe_tile *tile =gt_to_tile (gt); +struct xe_device *xe =gt_to_xe (gt); +int err =0 ; + +/* +* Only GGTT and LMEM requires to be cleared by the PF. +* GuC doorbell IDs and context IDs do not need any clearing. +*/ +if (!xe_gt_is_media_type (gt)) { +pf_sanitize_ggtt (tile, &config->ggtt_region, vfid); +if (IS_DGFX (xe)) + err =pf_sanitize_lmem (tile, config->lmem_obj, timeout); + } + +return err; +} + +/** +* xe_gt_sriov_pf_config_sanitize() - Sanitize VF's resources. +* @gt: the &xe_gt +* @vfid: the VF identifier (can't be PF) +* @timeout: maximum timeout to wait for completion in jiffies +* +* This function can only be called on PF. +* +* Return: 0 on success or a negative error code on failure. +*/ +int xe_gt_sriov_pf_config_sanitize (struct xe_gt *gt,unsigned int vfid,long timeout) +{ +int err; + +xe_gt_assert (gt, vfid !=PFID ); + +mutex_lock (xe_gt_sriov_pf_master_mutex (gt)); + err =pf_sanitize_vf_resources (gt, vfid, timeout); +mutex_unlock (xe_gt_sriov_pf_master_mutex (gt)); + +if (unlikely (err)) +xe_gt_sriov_notice (gt,"VF%u resource sanitizing failed (%pe)\n" , + vfid,ERR_PTR (err)); +return err; +} +/** * xe_gt_sriov_pf_config_push - Reprovision VF's configuration. * @gt: the &xe_gt
drivers/gpu/drm/xe/xe_gt_sriov_pf_config.h +1 -0
@@ -50,6 +50,7 @@ int xe_gt_sriov_pf_config_set_threshold(struct xe_gt *gt, unsigned int vfid, enum xe_guc_klv_threshold_index index, u32 value);int xe_gt_sriov_pf_config_set_fair (struct xe_gt *gt,unsigned int vfid,unsigned int num_vfs); +int xe_gt_sriov_pf_config_sanitize (struct xe_gt *gt,unsigned int vfid,long timeout);int xe_gt_sriov_pf_config_release (struct xe_gt *gt,unsigned int vfid,bool force);int xe_gt_sriov_pf_config_push (struct xe_gt *gt,unsigned int vfid,bool refresh);
Signature · 1 line
2.43.0
Re: [PATCH 01/12] drm/xe/pf: Add function to sanitize VF resources
Michal Wajdeczko <[email protected]> wrote on pią [2024-sie-09 18:51:48 +0200]:
Quoted 128 lines
On current platforms it is a PF driver responsibility to clear some of the VF's resources during a VF FLR. Add simple function that will clear configured VF resources (GGTT, LMEM). We will start using this function soon.
Signed-off-by Michal Wajdeczko <[email protected]>--- drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c | 84 ++++++++++++++++++++++ drivers/gpu/drm/xe/xe_gt_sriov_pf_config.h | 1 + 2 files changed, 85 insertions(+)drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c +84
-0@@ -29,6 +29,7 @@#include "xe_guc_submit.h" #include "xe_lmtt.h" #include "xe_map.h" +#include "xe_migrate.h" #include "xe_sriov.h" #include "xe_ttm_vram_mgr.h" #include "xe_wopcm.h" @@ -1893,6 +1894,89 @@ int xe_gt_sriov_pf_config_release(struct xe_gt *gt, unsigned int vfid, bool forcreturn force ?0 : err; } +static void pf_sanitize_ggtt (struct xe_tile *tile,struct drm_mm_node *node,unsigned int vfid) +{ +struct xe_ggtt *ggtt = tile->mem.ggtt; + +if (drm_mm_node_allocated (node)) +xe_ggtt_assign (ggtt, node, vfid); +} + +static int pf_sanitize_lmem (struct xe_tile *tile,struct xe_bo *bo,long timeout) +{ +struct xe_migrate *m = tile->migrate; +struct dma_fence *fence; +int err; + +if (!bo) +return 0 ; + +xe_bo_lock (bo, false); + fence =xe_migrate_clear (m, bo, bo->ttm.resource); +if (IS_ERR (fence)) { + err =PTR_ERR (fence); + }else if (!fence) { + err = -ENOMEM ; + }else { +long ret =dma_fence_wait_timeout (fence, false, timeout); + + err = ret >0 ?0 : ret <0 ? ret : -ETIMEDOUT ; +dma_fence_put (fence); +if (!err) +xe_gt_sriov_dbg_verbose (tile->primary_gt,"LMEM cleared in %dms\n" , +jiffies_to_msecs (timeout - ret)); + } +xe_bo_unlock (bo); + +return err; +} + +static int pf_sanitize_vf_resources (struct xe_gt *gt,u32 vfid,long timeout) +{ +struct xe_gt_sriov_config *config =pf_pick_vf_config (gt, vfid); +struct xe_tile *tile =gt_to_tile (gt); +struct xe_device *xe =gt_to_xe (gt); +int err =0 ; + +/* +* Only GGTT and LMEM requires to be cleared by the PF. +* GuC doorbell IDs and context IDs do not need any clearing. +*/ +if (!xe_gt_is_media_type (gt)) { +pf_sanitize_ggtt (tile, &config->ggtt_region, vfid); +if (IS_DGFX (xe)) + err =pf_sanitize_lmem (tile, config->lmem_obj, timeout); + } + +return err; +} + +/** +* xe_gt_sriov_pf_config_sanitize() - Sanitize VF's resources. +* @gt: the &xe_gt +* @vfid: the VF identifier (can't be PF) +* @timeout: maximum timeout to wait for completion in jiffies +* +* This function can only be called on PF. +* +* Return: 0 on success or a negative error code on failure. +*/ +int xe_gt_sriov_pf_config_sanitize (struct xe_gt *gt,unsigned int vfid,long timeout) +{ +int err; + +xe_gt_assert (gt, vfid !=PFID ); + +mutex_lock (xe_gt_sriov_pf_master_mutex (gt)); + err =pf_sanitize_vf_resources (gt, vfid, timeout); +mutex_unlock (xe_gt_sriov_pf_master_mutex (gt)); + +if (unlikely (err)) +xe_gt_sriov_notice (gt,"VF%u resource sanitizing failed (%pe)\n" , + vfid,ERR_PTR (err)); +return err; +} +/** * xe_gt_sriov_pf_config_push - Reprovision VF's configuration. * @gt: the &xe_gt drivers/gpu/drm/xe/xe_gt_sriov_pf_config.h +1
-0@@ -50,6 +50,7 @@ int xe_gt_sriov_pf_config_set_threshold(struct xe_gt *gt, unsigned int vfid, enum xe_guc_klv_threshold_index index, u32 value);int xe_gt_sriov_pf_config_set_fair (struct xe_gt *gt,unsigned int vfid,unsigned int num_vfs); +int xe_gt_sriov_pf_config_sanitize (struct xe_gt *gt,unsigned int vfid,long timeout);int xe_gt_sriov_pf_config_release (struct xe_gt *gt,unsigned int vfid,bool force);int xe_gt_sriov_pf_config_push (struct xe_gt *gt,unsigned int vfid,bool refresh);Signature · 1 line
2.43.0
LGTM:
Re: [PATCH 01/12] drm/xe/pf: Add function to sanitize VF resources
In reply to Michal WajdeczkoQuoted 1 line · Michal Wajdeczko
+static int
pf_sanitize_lmem(struct xe_tile *tile, struct xe_bo *bo, long timeout)
it took a while to make xe use "vram"... now we are back with lmem in several places :(
Lucas De Marchi
Re: [PATCH 01/12] drm/xe/pf: Add function to sanitize VF resources
Quoted 7 lines · Lucas De Marchi
Quoted 2 lines · Michal Wajdeczko
+static int
pf_sanitize_lmem(struct xe_tile *tile, struct xe_bo *bo, long timeout)it took a while to make xe use "vram"... now we are back with lmem in several places :(
it's because GuC ABI is using LMEM terminology
if you really want then I can try to rename implementation side to use 'vram' instead, but question is what to do with debugfs entries that reflects GuC ABI almost 1:1, should it also be named with vram ?
gt0/pf/lmem_spare -> gt0/pf/vram_spare
gt0/vf1/lmem_quota -> gt0/vf1/vram_quota
Re: [PATCH 01/12] drm/xe/pf: Add function to sanitize VF resources
Quoted 11 lines · Michal Wajdeczko
Quoted 7 lines · Lucas De Marchi
Quoted 2 lines · Michal Wajdeczko
+static int
pf_sanitize_lmem(struct xe_tile *tile, struct xe_bo *bo, long timeout)it took a while to make xe use "vram"... now we are back with lmem in several places :(
Quoted 8 lines
it's because GuC ABI is using LMEM terminology
if you really want then I can try to rename implementation side to use 'vram' instead, but question is what to do with debugfs entries that reflects GuC ABI almost 1:1, should it also be named with vram ?
gt0/pf/lmem_spare -> gt0/pf/vram_spare
gt0/vf1/lmem_quota -> gt0/vf1/vram_quota
+Rodrigo, +Thomas
Lucas De Marchi
Rodrigo Vivi
maintainerRe: [PATCH 01/12] drm/xe/pf: Add function to sanitize VF resources
Quoted 14 lines · Lucas De Marchi
Quoted 13 lines · Michal Wajdeczko
Quoted 7 lines · Lucas De Marchi
Quoted 2 lines · Michal Wajdeczko
+static int
pf_sanitize_lmem(struct xe_tile *tile, struct xe_bo *bo, long timeout)it took a while to make xe use "vram"... now we are back with lmem in several places :(
it's because GuC ABI is using LMEM terminology
Quoted 8 lines
Quoted 6 lines
if you really want then I can try to rename implementation side to use 'vram' instead, but question is what to do with debugfs entries that reflects GuC ABI almost 1:1, should it also be named with vram ?
gt0/pf/lmem_spare -> gt0/pf/vram_spare
gt0/vf1/lmem_quota -> gt0/vf1/vram_quota+Rodrigo, +Thomas
Sorry for taking so long here.
I believe we should keep 'lmem' here. It matches guc, sriov, and gt design.
In the past, when i915 was introducing device-memory-ram support, instead of calling it vram to align with everyone else, we decided to go with the name 'local memory' that we were seeing a lot in internal docs.
It is good that in Xe we are now aligned with 'vram' to refer for these device memory (ram). But by spec, 'local memory' is something else.
'Local memory' in general is the memory from VRAM which is not managed by OS, but only managed by our device driver. However it could also be carved out from the system ram. And then it can be used by SRIOV and managed with LMTT (local memory translation table).
So, with this in mind and to avoid the sysfs breakage, I'm in favor of keeping 'lmem' term where it applies. But maybe worth some documentation page?
Quoted 2 lines
Lucas De Marchi
PATCH 2/12 drm/xe/pf: Fix documentation formatting
In reply to Michal WajdeczkoCurrent formatting of "The VF FLR Flow with GuC" only looks fine, but it will not render properly when included in htmldocs due to:
WARNING: Block quote ends without a blank line; unexpected unindent.
CRITICAL: Missing matching underline for section title overline.
Fix that by adding proper indent and using list markup.
--- drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c | 54 +++++++++++---------- 1 file changed, 28 insertions(+), 26 deletions(-)
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +28 -26
@@ -153,33 +153,35 @@ int xe_gt_sriov_pf_control_trigger_flr(struct xe_gt *gt, unsigned int vfid)/** * DOC: The VF FLR Flow with GuC * -* PF GUC PCI -* ======================================================== -* | | | -* (1) | [ ] <----- FLR --| -* | [ ] : -* (2) [ ] <-------- NOTIFY FLR --[ ] -* [ ] | -* (3) [ ] | -* [ ] | -* [ ]-- START FLR ---------> [ ] -* | [ ] -* (4) | [ ] -* | [ ] -* [ ] <--------- FLR DONE -- [ ] -* [ ] | -* (5) [ ] | -* [ ] | -* [ ]-- FINISH FLR --------> [ ] -* | | +* The VF FLR flow includes several steps:: * -* Step 1: PCI HW generates interrupt to the GuC about VF FLR -* Step 2: GuC FW sends G2H notification to the PF about VF FLR -* Step 2a: on some platforms G2H is only received from root GuC -* Step 3: PF sends H2G request to the GuC to start VF FLR sequence -* Step 3a: on some platforms PF must send H2G to all other GuCs -* Step 4: GuC FW performs VF FLR cleanups and notifies the PF when done -* Step 5: PF performs VF FLR cleanups and notifies the GuC FW when finished +* PF GUC PCI +* ======================================================== +* | | | +* (1) | [ ] <----- FLR --| +* | [ ] : +* (2) [ ] <-------- NOTIFY FLR --[ ] +* [ ] | +* (3) [ ] | +* [ ] | +* [ ]-- START FLR ---------> [ ] +* | [ ] +* (4) | [ ] +* | [ ] +* [ ] <--------- FLR DONE -- [ ] +* [ ] | +* (5) [ ] | +* [ ] | +* [ ]-- FINISH FLR --------> [ ] +* | | +* +* * Step 1: PCI HW generates interrupt to the GuC about VF FLR +* * Step 2: GuC FW sends G2H notification to the PF about VF FLR +* * Step 2a: on some platforms G2H is only received from root GuC +* * Step 3: PF sends H2G request to the GuC to start VF FLR sequence +* * Step 3a: on some platforms PF must send H2G to all other GuCs +* * Step 4: GuC FW performs VF FLR cleanups and notifies the PF when done +* * Step 5: PF performs VF FLR cleanups and notifies the GuC FW when finished */ static bool needs_dispatch_flr (struct xe_device *xe)
Signature · 1 line
2.43.0
Re: [PATCH 02/12] drm/xe/pf: Fix documentation formatting
Michal Wajdeczko <[email protected]> wrote on pią [2024-sie-09 18:51:49 +0200]:
Quoted 81 lines
Current formatting of "The VF FLR Flow with GuC" only looks fine, but it will not render properly when included in htmldocs due to:
WARNING: Block quote ends without a blank line; unexpected unindent.
CRITICAL: Missing matching underline for section title overline.Fix that by adding proper indent and using list markup.
Signed-off-by Michal Wajdeczko <[email protected]>--- drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c | 54 +++++++++++---------- 1 file changed, 28 insertions(+), 26 deletions(-)drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +28
-26@@ -153,33 +153,35 @@ int xe_gt_sriov_pf_control_trigger_flr(struct xe_gt *gt, unsigned int vfid)/** * DOC: The VF FLR Flow with GuC * -* PF GUC PCI -* ======================================================== -* | | | -* (1) | [ ] <----- FLR --| -* | [ ] : -* (2) [ ] <-------- NOTIFY FLR --[ ] -* [ ] | -* (3) [ ] | -* [ ] | -* [ ]-- START FLR ---------> [ ] -* | [ ] -* (4) | [ ] -* | [ ] -* [ ] <--------- FLR DONE -- [ ] -* [ ] | -* (5) [ ] | -* [ ] | -* [ ]-- FINISH FLR --------> [ ] -* | | +* The VF FLR flow includes several steps:: * -* Step 1: PCI HW generates interrupt to the GuC about VF FLR -* Step 2: GuC FW sends G2H notification to the PF about VF FLR -* Step 2a: on some platforms G2H is only received from root GuC -* Step 3: PF sends H2G request to the GuC to start VF FLR sequence -* Step 3a: on some platforms PF must send H2G to all other GuCs -* Step 4: GuC FW performs VF FLR cleanups and notifies the PF when done -* Step 5: PF performs VF FLR cleanups and notifies the GuC FW when finished +* PF GUC PCI +* ======================================================== +* | | | +* (1) | [ ] <----- FLR --| +* | [ ] : +* (2) [ ] <-------- NOTIFY FLR --[ ] +* [ ] | +* (3) [ ] | +* [ ] | +* [ ]-- START FLR ---------> [ ] +* | [ ] +* (4) | [ ] +* | [ ] +* [ ] <--------- FLR DONE -- [ ] +* [ ] | +* (5) [ ] | +* [ ] | +* [ ]-- FINISH FLR --------> [ ] +* | | +* +* * Step 1: PCI HW generates interrupt to the GuC about VF FLR +* * Step 2: GuC FW sends G2H notification to the PF about VF FLR +* * Step 2a: on some platforms G2H is only received from root GuC +* * Step 3: PF sends H2G request to the GuC to start VF FLR sequence +* * Step 3a: on some platforms PF must send H2G to all other GuCs +* * Step 4: GuC FW performs VF FLR cleanups and notifies the PF when done +* * Step 5: PF performs VF FLR cleanups and notifies the GuC FW when finished */ static bool needs_dispatch_flr (struct xe_device *xe)Signature · 1 line
2.43.0
LGTM:
Quoted 1 line
PATCH 3/12 drm/xe/pf: Drop GuC notifications for non-existing VF
In reply to Michal WajdeczkoIt is unlikely that GuC will ever send a G2H notification with an invalid VFID and it is currently harmless if that actually happen. But in upcoming patches we will start using that VFID as an index and we must be sure it is a valid to avoid a crash due to a buggy firmware or a currupted G2H message.
--- drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +6 -0
@@ -8,6 +8,7 @@#include "xe_device.h" #include "xe_gt.h" #include "xe_gt_sriov_pf_control.h" +#include "xe_gt_sriov_pf_helpers.h" #include "xe_gt_sriov_printk.h" #include "xe_guc_ct.h" #include "xe_sriov.h"
@@ -212,6 +213,11 @@ static void pf_handle_vf_flr_done(struct xe_gt *gt, u32 vfid)static int pf_handle_vf_event (struct xe_gt *gt,u32 vfid,u32 eventid) { +xe_gt_sriov_dbg_verbose (gt,"received VF%u event %#x\n" , vfid, eventid); + +if (vfid >xe_gt_sriov_pf_get_totalvfs (gt)) +return -EPROTO ; +switch (eventid) {case GUC_PF_NOTIFY_VF_FLR :pf_handle_vf_flr (gt, vfid);
Signature · 1 line
2.43.0
Re: [PATCH 03/12] drm/xe/pf: Drop GuC notifications for non-existing VF
Michal Wajdeczko <[email protected]> wrote on pią [2024-sie-09 18:51:50 +0200]:
Quoted 24 lines
It is unlikely that GuC will ever send a G2H notification with an invalid VFID and it is currently harmless if that actually happen. But in upcoming patches we will start using that VFID as an index and we must be sure it is a valid to avoid a crash due to a buggy firmware or a currupted G2H message.
Signed-off-by Michal Wajdeczko <[email protected]>--- drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +1
-0@@ -8,6 +8,7 @@#include "xe_device.h" #include "xe_gt.h" #include "xe_gt_sriov_pf_control.h" +#include "xe_gt_sriov_pf_helpers.h" #include "xe_gt_sriov_printk.h" #include "xe_guc_ct.h" #include "xe_sriov.h"
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c static void pf_handle_vf_flr_done(struct xe_gt *gt, u32 vfid) · line 219
Quoted 7 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +4
-0@@ -212,6 +213,11 @@ static void pf_handle_vf_flr_done(struct xe_gt *gt, u32 vfid)static int pf_handle_vf_event (struct xe_gt *gt,u32 vfid,u32 eventid) { +xe_gt_sriov_dbg_verbose (gt,"received VF%u event %#x\n" , vfid, eventid); + +if (vfid >xe_gt_sriov_pf_get_totalvfs (gt)) +return -EPROTO ;
I would probably add some log here.
I'm afraid that during debug the information about the last event is not enough
Thanks,
Piotr
Quoted 7 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +1
-0+switch (eventid) {case GUC_PF_NOTIFY_VF_FLR :pf_handle_vf_flr (gt, vfid);Signature · 1 line
2.43.0
Re: [PATCH 03/12] drm/xe/pf: Drop GuC notifications for non-existing VF
Quoted 26 lines · Piotr Piórkowski
Michal Wajdeczko <[email protected]> wrote on pią [2024-sie-09 18:51:50 +0200]:
Quoted 25 lines
It is unlikely that GuC will ever send a G2H notification with an invalid VFID and it is currently harmless if that actually happen. But in upcoming patches we will start using that VFID as an index and we must be sure it is a valid to avoid a crash due to a buggy firmware or a currupted G2H message.
Signed-off-by Michal Wajdeczko <[email protected]>--- drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +1
-0@@ -8,6 +8,7 @@#include "xe_device.h" #include "xe_gt.h" #include "xe_gt_sriov_pf_control.h" +#include "xe_gt_sriov_pf_helpers.h" #include "xe_gt_sriov_printk.h" #include "xe_guc_ct.h" #include "xe_sriov.h" @@ -212,6 +213,11 @@ static void pf_handle_vf_flr_done(struct xe_gt *gt, u32 vfid)
Quoted 9 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c static void pf_handle_vf_flr_done(struct xe_gt *gt, u32 vfid) · line 219
Quoted 6 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +4
-0static int pf_handle_vf_event (struct xe_gt *gt,u32 vfid,u32 eventid) { +xe_gt_sriov_dbg_verbose (gt,"received VF%u event %#x\n" , vfid, eventid); + +if (vfid >xe_gt_sriov_pf_get_totalvfs (gt)) +return -EPROTO ;I would probably add some log here.
I'm afraid that during debug the information about the last event is not enough
it should be the CTB layer responsibility to print an error message and dump this invalid or corrupted or unexpected G2H message, no point in doing this in every possible G2H message handler; note that 'silent' return is aligned with the existing code in this file.
for now CTB will just report:
xe_gt_err(gt, "G2H action 0x%04x failed (%pe)\n", action, ERR_PTR(ret));
but it should be easy to add (what we had in i915) full dump of the problematic G2H message in case of at least the EPROTO error
Quoted 11 lines
Thanks,
PiotrQuoted 7 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +1
-0+switch (eventid) {case GUC_PF_NOTIFY_VF_FLR :pf_handle_vf_flr (gt, vfid);Signature · 1 line
2.43.0
Piotr Piórkowski
Reviewed-byRe: [PATCH 03/12] drm/xe/pf: Drop GuC notifications for non-existing VF
Michal Wajdeczko <[email protected]> wrote on pon [2024-sie-19 19:51:28 +0200]:
Quoted 44 lines · Piotr Piórkowski
Quoted 26 lines
Michal Wajdeczko <[email protected]> wrote on pią [2024-sie-09 18:51:50 +0200]:
Quoted 25 lines
It is unlikely that GuC will ever send a G2H notification with an invalid VFID and it is currently harmless if that actually happen. But in upcoming patches we will start using that VFID as an index and we must be sure it is a valid to avoid a crash due to a buggy firmware or a currupted G2H message.
Signed-off-by Michal Wajdeczko <[email protected]>--- drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +1
-0@@ -8,6 +8,7 @@#include "xe_device.h" #include "xe_gt.h" #include "xe_gt_sriov_pf_control.h" +#include "xe_gt_sriov_pf_helpers.h" #include "xe_gt_sriov_printk.h" #include "xe_guc_ct.h" #include "xe_sriov.h" @@ -212,6 +213,11 @@ static void pf_handle_vf_flr_done(struct xe_gt *gt, u32 vfid)Quoted 9 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c static void pf_handle_vf_flr_done(struct xe_gt *gt, u32 vfid) · line 219
Quoted 6 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +4
-0static int pf_handle_vf_event (struct xe_gt *gt,u32 vfid,u32 eventid) { +xe_gt_sriov_dbg_verbose (gt,"received VF%u event %#x\n" , vfid, eventid); + +if (vfid >xe_gt_sriov_pf_get_totalvfs (gt)) +return -EPROTO ;I would probably add some log here.
I'm afraid that during debug the information about the last event is not enoughit should be the CTB layer responsibility to print an error message and dump this invalid or corrupted or unexpected G2H message, no point in doing this in every possible G2H message handler; note that 'silent' return is aligned with the existing code in this file.
Quoted 7 lines
for now CTB will just report:
xe_gt_err(gt, "G2H action 0x%04x failed (%pe)\n", action, ERR_PTR(ret));but it should be easy to add (what we had in i915) full dump of the problematic G2H message in case of at least the EPROTO error
This sounds reasonable to me:
Quoted 12 lines
Quoted 12 lines
Thanks,
PiotrQuoted 7 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +1
-0+switch (eventid) {case GUC_PF_NOTIFY_VF_FLR :pf_handle_vf_flr (gt, vfid);Signature · 1 line
2.43.0
PATCH 4/12 drm/xe/pf: Improve VF control
In reply to Michal WajdeczkoOur initial VF control implementation was focused on providing a very minimal support for the VF_STATE_NOTIFY events just to meet GuC requirements, without tracking a VF state or doing any expected actions (like cleanup in case of the FLR notification).
Try to improve this by defining set of VF state machines, each responsible for processing one activity (PAUSE, RESUME, STOP or FLR). All required steps defined by the VF state machine are then executed by the PF worker from the dedicated workqueue.
Any external requests or notifications simply try to transition between the states to trigger a work and then wait for that work to finish. Some predefined default timeouts are used to avoid changing existing API calls, but it should be easy to extend the control API to also accept specific timeout values.
--- drivers/gpu/drm/xe/xe_gt_sriov_pf.c | 6 + drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c | 1203 ++++++++++++++++- drivers/gpu/drm/xe/xe_gt_sriov_pf_control.h | 3 + .../gpu/drm/xe/xe_gt_sriov_pf_control_types.h | 107 ++ drivers/gpu/drm/xe/xe_gt_sriov_pf_types.h | 6 + 5 files changed, 1310 insertions(+), 15 deletions(-) create mode 100644 drivers/gpu/drm/xe/xe_gt_sriov_pf_control_types.h
drivers/gpu/drm/xe/xe_gt_sriov_pf.c +6 -0
@@ -9,6 +9,7 @@#include "xe_gt_sriov_pf.h" #include "xe_gt_sriov_pf_config.h" +#include "xe_gt_sriov_pf_control.h" #include "xe_gt_sriov_pf_helpers.h" #include "xe_gt_sriov_pf_service.h" #include "xe_mmio.h"
@@ -57,6 +58,10 @@ int xe_gt_sriov_pf_init_early(struct xe_gt *gt)if (err)return err; + err =xe_gt_sriov_pf_control_init (gt); +if (err) +return err; +return 0 ; }
@@ -93,4 +98,5 @@ void xe_gt_sriov_pf_init_hw(struct xe_gt *gt)void xe_gt_sriov_pf_restart (struct xe_gt *gt) {xe_gt_sriov_pf_config_restart (gt); +xe_gt_sriov_pf_control_restart (gt); }
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +1188 -15
1,281 lines not on this page · raw message
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.h +3 -0
@@ -11,6 +11,9 @@struct xe_gt ; +int xe_gt_sriov_pf_control_init (struct xe_gt *gt); +void xe_gt_sriov_pf_control_restart (struct xe_gt *gt); +int xe_gt_sriov_pf_control_pause_vf (struct xe_gt *gt,unsigned int vfid);int xe_gt_sriov_pf_control_resume_vf (struct xe_gt *gt,unsigned int vfid);int xe_gt_sriov_pf_control_stop_vf (struct xe_gt *gt,unsigned int vfid);
drivers/gpu/drm/xe/xe_gt_sriov_pf_control_types.h new file +107 -0
107 lines not on this page · raw message
drivers/gpu/drm/xe/xe_gt_sriov_pf_types.h +6 -0
@@ -9,6 +9,7 @@#include <linux/types.h> #include "xe_gt_sriov_pf_config_types.h" +#include "xe_gt_sriov_pf_control_types.h" #include "xe_gt_sriov_pf_monitor_types.h" #include "xe_gt_sriov_pf_policy_types.h" #include "xe_gt_sriov_pf_service_types.h"
@@ -23,6 +24,9 @@ struct xe_gt_sriov_metadata {/** @monitor: per-VF monitoring data. */ struct xe_gt_sriov_monitor monitor; +/** @control: per-VF control data. */ +struct xe_gt_sriov_control_state control; +/** @version: negotiated VF/PF ABI version */ struct xe_gt_sriov_pf_service_version version; };
@@ -30,12 +34,14 @@ struct xe_gt_sriov_metadata {/** * struct xe_gt_sriov_pf - GT level PF virtualization data. * @service: service data. +* @control: control data. * @policy: policy data. * @spare: PF-only provisioning configuration. * @vfs: metadata for all VFs. */ struct xe_gt_sriov_pf {struct xe_gt_sriov_pf_service service; +struct xe_gt_sriov_pf_control control;struct xe_gt_sriov_pf_policy policy;struct xe_gt_sriov_spare_config spare;struct xe_gt_sriov_metadata *vfs;
Signature · 1 line
2.43.0
Re: [PATCH 04/12] drm/xe/pf: Improve VF control
Michal Wajdeczko <[email protected]> wrote on pią [2024-sie-09 18:51:51 +0200]:
Quoted 27 lines
Our initial VF control implementation was focused on providing a very minimal support for the
VF_STATE_NOTIFYevents just to meet GuC requirements, without tracking a VF state or doing any expected actions (like cleanup in case of the FLR notification).Try to improve this by defining set of VF state machines, each responsible for processing one activity (PAUSE, RESUME, STOP or FLR). All required steps defined by the VF state machine are then executed by the PF worker from the dedicated workqueue.
Any external requests or notifications simply try to transition between the states to trigger a work and then wait for that work to finish. Some predefined default timeouts are used to avoid changing existing API calls, but it should be easy to extend the control API to also accept specific timeout values.
Signed-off-by Michal Wajdeczko <[email protected]>Cc Piotr Piórkowski <[email protected]>--- drivers/gpu/drm/xe/xe_gt_sriov_pf.c | 6 + drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c | 1203 ++++++++++++++++- drivers/gpu/drm/xe/xe_gt_sriov_pf_control.h | 3 + .../gpu/drm/xe/xe_gt_sriov_pf_control_types.h | 107 ++ drivers/gpu/drm/xe/xe_gt_sriov_pf_types.h | 6 + 5 files changed, 1310 insertions(+), 15 deletions(-) create mode 100644 drivers/gpu/drm/xe/xe_gt_sriov_pf_control_types.h
<snip>
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c int xe_gt_sriov_pf_control_process_guc2pf(struct xe_gt *gt, const u32 *msg, u32 · line 1305
Quoted 12 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +8
-0@@ -284,3 +1295,165 @@ int xe_gt_sriov_pf_control_process_guc2pf(struct xe_gt *gt, const u32 *msg, u32return vfid ?pf_handle_vf_event (gt, vfid, eventid) :pf_handle_pf_event (gt, eventid); } + +static bool pf_process_vf_machine (struct xe_gt *gt,unsigned int vfid) +{ +if (pf_exit_vf_flr_send_start (gt, vfid)) +return true; + +if (pf_exit_vf_flr_send_start (gt, vfid)) +return true;
hmmm... Should we call out this function twice here ?
Thanks,
Piotr
Quoted 3 lines
Signature · 1 line
2.43.0
Re: [PATCH 04/12] drm/xe/pf: Improve VF control
Quoted 34 lines · Piotr Piórkowski
Michal Wajdeczko <[email protected]> wrote on pią [2024-sie-09 18:51:51 +0200]:
Quoted 27 lines
Our initial VF control implementation was focused on providing a very minimal support for the
VF_STATE_NOTIFYevents just to meet GuC requirements, without tracking a VF state or doing any expected actions (like cleanup in case of the FLR notification).Try to improve this by defining set of VF state machines, each responsible for processing one activity (PAUSE, RESUME, STOP or FLR). All required steps defined by the VF state machine are then executed by the PF worker from the dedicated workqueue.
Any external requests or notifications simply try to transition between the states to trigger a work and then wait for that work to finish. Some predefined default timeouts are used to avoid changing existing API calls, but it should be easy to extend the control API to also accept specific timeout values.
Signed-off-by Michal Wajdeczko <[email protected]>Cc Piotr Piórkowski <[email protected]>--- drivers/gpu/drm/xe/xe_gt_sriov_pf.c | 6 + drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c | 1203 ++++++++++++++++- drivers/gpu/drm/xe/xe_gt_sriov_pf_control.h | 3 + .../gpu/drm/xe/xe_gt_sriov_pf_control_types.h | 107 ++ drivers/gpu/drm/xe/xe_gt_sriov_pf_types.h | 6 + 5 files changed, 1310 insertions(+), 15 deletions(-) create mode 100644 drivers/gpu/drm/xe/xe_gt_sriov_pf_control_types.h<snip>
Quoted 2 lines
(quoted diff) +0
-0@@ -284,3 +1295,165 @@ int xe_gt_sriov_pf_control_process_guc2pf(struct xe_gt *gt, const u32 *msg, u32
Quoted 13 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c int xe_gt_sriov_pf_control_process_guc2pf(struct xe_gt *gt, const u32 *msg, u32 · line 1305
Quoted 10 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +8
-0return vfid ?pf_handle_vf_event (gt, vfid, eventid) :pf_handle_pf_event (gt, eventid); } + +static bool pf_process_vf_machine (struct xe_gt *gt,unsigned int vfid) +{ +if (pf_exit_vf_flr_send_start (gt, vfid)) +return true; + +if (pf_exit_vf_flr_send_start (gt, vfid)) +return true;hmmm... Should we call out this function twice here ?
no, it's a typo (and one more, also harmless, later on)
Quoted 10 lines
Thanks,
PiotrQuoted 3 lines
Signature · 1 line
2.43.0
Re: [PATCH 04/12] drm/xe/pf: Improve VF control
In reply to Michal WajdeczkoMichal Wajdeczko <[email protected]> wrote on pią [2024-sie-09 18:51:51 +0200]:
Quoted 155 lines
Our initial VF control implementation was focused on providing a very minimal support for the
VF_STATE_NOTIFYevents just to meet GuC requirements, without tracking a VF state or doing any expected actions (like cleanup in case of the FLR notification).Try to improve this by defining set of VF state machines, each responsible for processing one activity (PAUSE, RESUME, STOP or FLR). All required steps defined by the VF state machine are then executed by the PF worker from the dedicated workqueue.
Any external requests or notifications simply try to transition between the states to trigger a work and then wait for that work to finish. Some predefined default timeouts are used to avoid changing existing API calls, but it should be easy to extend the control API to also accept specific timeout values.
Signed-off-by Michal Wajdeczko <[email protected]>Cc Piotr Piórkowski <[email protected]>--- drivers/gpu/drm/xe/xe_gt_sriov_pf.c | 6 + drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c | 1203 ++++++++++++++++- drivers/gpu/drm/xe/xe_gt_sriov_pf_control.h | 3 + .../gpu/drm/xe/xe_gt_sriov_pf_control_types.h | 107 ++ drivers/gpu/drm/xe/xe_gt_sriov_pf_types.h | 6 + 5 files changed, 1310 insertions(+), 15 deletions(-) create mode 100644 drivers/gpu/drm/xe/xe_gt_sriov_pf_control_types.hdrivers/gpu/drm/xe/xe_gt_sriov_pf.c +6
-0@@ -9,6 +9,7 @@#include "xe_gt_sriov_pf.h" #include "xe_gt_sriov_pf_config.h" +#include "xe_gt_sriov_pf_control.h" #include "xe_gt_sriov_pf_helpers.h" #include "xe_gt_sriov_pf_service.h" #include "xe_mmio.h" @@ -57,6 +58,10 @@ int xe_gt_sriov_pf_init_early(struct xe_gt *gt)if (err)return err; + err =xe_gt_sriov_pf_control_init (gt); +if (err) +return err; +return 0 ; }@@ -93,4 +98,5 @@ void xe_gt_sriov_pf_init_hw(struct xe_gt *gt)void xe_gt_sriov_pf_restart (struct xe_gt *gt) {xe_gt_sriov_pf_config_restart (gt); +xe_gt_sriov_pf_control_restart (gt); }drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +60
-4@@ -3,12 +3,17 @@* Copyright © 2023-2024 Intel Corporation */ +#include <drm/drm_managed.h> +#include "abi/guc_actions_sriov_abi.h" #include "xe_device.h" #include "xe_gt.h" +#include "xe_gt_sriov_pf_config.h" #include "xe_gt_sriov_pf_control.h" #include "xe_gt_sriov_pf_helpers.h" +#include "xe_gt_sriov_pf_monitor.h" +#include "xe_gt_sriov_pf_service.h" #include "xe_gt_sriov_printk.h" #include "xe_guc_ct.h" #include "xe_sriov.h" @@ -42,10 +47,6 @@ static int guc_action_vf_control_cmd(struct xe_guc *guc, u32 vfid, u32 cmd) };int ret; -/* XXX those two commands are now sent from the G2H handler */ -if (cmd ==GUC_PF_TRIGGER_VF_FLR_START || cmd ==GUC_PF_TRIGGER_VF_FLR_FINISH ) -return xe_guc_ct_send_g2h_handler (&guc->ct, request,ARRAY_SIZE (request)); - ret =xe_guc_ct_send_block (&guc->ct, request,ARRAY_SIZE (request));return ret >0 ? -EPROTO : ret; }@@ -55,6 +56,8 @@ static int pf_send_vf_control_cmd(struct xe_gt *gt, unsigned int vfid, u32 cmd)int err;xe_gt_assert (gt, vfid !=PFID ); +xe_gt_sriov_dbg_verbose (gt,"sending VF%u control command %s\n" , + vfid,control_cmd_to_string (cmd)); err =guc_action_vf_control_cmd (>->uc.guc, vfid, cmd);if (unlikely (err))@@ -88,6 +91,457 @@ static int pf_send_vf_flr_finish(struct xe_gt *gt, unsigned int vfid)return pf_send_vf_control_cmd (gt, vfid,GUC_PF_TRIGGER_VF_FLR_FINISH ); } +/** +* DOC: The VF state machine +* +* The simplified VF state machine could be presented as:: +* +* pause--------------------------o +* / | +* / v +* (READY)<------------------resume-----(PAUSED) +* ^ \ / / +* | \ / / +* | stop---->(STOPPED)<----stop / +* | / / +* | / / +* o--------<-----flr / +* \ / +* o------<--------------------flr +* +* Where: +* +* * READY - represents a state in which VF is fully operable +* * PAUSED - represents a state in which VF activity is temporarily suspended +* * STOPPED - represents a state in which VF activity is definitely halted +* * pause - represents a request to temporarily suspend VF activity +* * resume - represents a request to resume VF activity +* * stop - represents a request to definitely halt VF activity +* * flr - represents a request to perform VF FLR to restore VF activity +* +* However, each state transition requires additional steps that involves +* communication with GuC that might fail or be interrupted by other requests:: +* +* .................................WIP.... +* : : +* pause--------------------->PAUSE_WIP----------------------------o +* / : / \ : | +* / : o----<---stop flr--o : | +* / : | \ / | : V +* (READY)<---------------+------------RESUME_WIP<----+--<-----resume--(PAUSED) +* ^ \ \ : | | : / / +* | \ \ : | | : / / +* | \ \ : | | : / / +* | \ \ : o----<----------------------+--<-------stop / +* | \ \ : | | : / +* | \ \ : V | : / +* | \ stop----->STOP_WIP---------flr--->-----o : / +* | \ : | | : / +* | \ : | V : / +* | flr--------+----->----------------->FLR_WIP<-----flr +* | : | / ^ : +* | : | / | : +* o--------<-------:----+-----<----------------o | : +* : | | : +* :....|...........................|.....:
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c static int pf_send_vf_flr_finish(struct xe_gt *gt, unsigned int vfid) · line 156
Quoted 10 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +10
-0+* | | +* V | +* (STOPPED)--------------------flr +* +* For details about each internal WIP state machine see: +* +* * `The VF PAUSE state machine`_ +* * `The VF RESUME state machine`_ +* * `The VF STOP state machine`_ +* * `The VF FLR state machine`_
Later in the code there is one state that is not obvious when you look at the first two drawings of the state machine - it is the resumed state. It appears in subsequent drawings but in my opinion it is not obvious. I have already talked to Michal about it and he explained to me why he introduced it in the code, but it seems to me that it should be included at least in this drawing.
Quoted 50 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +50
-0+*/ + +#ifdef CONFIG_DRM_XE_DEBUG_SRIOV +static const char *control_bit_to_string (enum xe_gt_sriov_control_bits bit) +{ +switch (bit) { +#define CASE2STR (_X) \ + case XE_GT_SRIOV_STATE_##_X: return #_X +CASE2STR (WIP ); +CASE2STR (FLR_WIP ); +CASE2STR (FLR_SEND_START ); +CASE2STR (FLR_WAIT_GUC ); +CASE2STR (FLR_GUC_DONE ); +CASE2STR (FLR_RESET_CONFIG ); +CASE2STR (FLR_RESET_DATA ); +CASE2STR (FLR_RESET_MMIO ); +CASE2STR (FLR_SEND_FINISH ); +CASE2STR (FLR_FAILED ); +CASE2STR (PAUSE_WIP ); +CASE2STR (PAUSE_SEND_PAUSE ); +CASE2STR (PAUSE_WAIT_GUC ); +CASE2STR (PAUSE_GUC_DONE ); +CASE2STR (PAUSE_FAILED ); +CASE2STR (PAUSED ); +CASE2STR (RESUME_WIP ); +CASE2STR (RESUME_SEND_RESUME ); +CASE2STR (RESUME_FAILED ); +CASE2STR (RESUMED ); +CASE2STR (STOP_WIP ); +CASE2STR (STOP_SEND_STOP ); +CASE2STR (STOP_FAILED ); +CASE2STR (STOPPED ); +CASE2STR (MISMATCH ); +#undef CASE2STR +default :return "?" ; + } +} +#endif + +static unsigned long pf_get_default_timeout (enum xe_gt_sriov_control_bits bit) +{ +switch (bit) { +case XE_GT_SRIOV_STATE_FLR_WAIT_GUC : +case XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC : +return HZ /2 ; +case XE_GT_SRIOV_STATE_FLR_WIP : +case XE_GT_SRIOV_STATE_FLR_RESET_CONFIG : +return 5 *HZ ; +default : +return HZ ;
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c static int pf_send_vf_flr_finish(struct xe_gt *gt, unsigned int vfid) · line 216
Quoted 10 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +10
-0+ } +} + +static unsigned long *pf_peek_vf_state (struct xe_gt *gt,unsigned int vfid) +{ +xe_gt_assert (gt,IS_SRIOV_PF (gt_to_xe (gt))); +xe_gt_assert (gt, vfid <=xe_gt_sriov_pf_get_totalvfs (gt)); + +return >->sriov.pf.vfs[vfid].control.state; +}
NIT: Later in the code you define such a function as pf_peek_vf_control.
Maybe you define it earlier and use it in pf_peek_vf_state ? The code will reduce by two asserts
Quoted 481 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +465
-2+ +static bool pf_check_vf_state (struct xe_gt *gt,unsigned int vfid, +enum xe_gt_sriov_control_bits bit) +{ +return test_bit (bit,pf_peek_vf_state (gt, vfid)); +} + +static void pf_dump_vf_state (struct xe_gt *gt,unsigned int vfid) +{ +unsigned long state = *pf_peek_vf_state (gt, vfid); +enum xe_gt_sriov_control_bits bit; + +if (state) { +xe_gt_sriov_dbg_verbose (gt,"VF%u state %#lx%s%*pbl\n" , + vfid, state, state ?" bits " :"" , + (int )BITS_PER_LONG , &state); +for_each_set_bit (bit, &state,BITS_PER_LONG ) +xe_gt_sriov_dbg_verbose (gt,"VF%u state %s(%d)\n" , + vfid,control_bit_to_string (bit), bit); + }else { +xe_gt_sriov_dbg_verbose (gt,"VF%u state READY\n" , vfid); + } +} + +static bool pf_expect_vf_state (struct xe_gt *gt,unsigned int vfid, +enum xe_gt_sriov_control_bits bit) +{ +bool result =pf_check_vf_state (gt, vfid, bit); + +if (unlikely (!result)) +pf_dump_vf_state (gt, vfid); + +return result; +} + +static bool pf_expect_vf_not_state (struct xe_gt *gt,unsigned int vfid, +enum xe_gt_sriov_control_bits bit) +{ +bool result = !pf_check_vf_state (gt, vfid, bit); + +if (unlikely (!result)) +pf_dump_vf_state (gt, vfid); + +return result; +} + +static bool pf_enter_vf_state (struct xe_gt *gt,unsigned int vfid, +enum xe_gt_sriov_control_bits bit) +{ +if (!test_and_set_bit (bit,pf_peek_vf_state (gt, vfid))) { +xe_gt_sriov_dbg_verbose (gt,"VF%u state %s(%d) enter\n" , + vfid,control_bit_to_string (bit), bit); +return true; + } +return false; +} + +static bool pf_exit_vf_state (struct xe_gt *gt,unsigned int vfid, +enum xe_gt_sriov_control_bits bit) +{ +if (test_and_clear_bit (bit,pf_peek_vf_state (gt, vfid))) { +xe_gt_sriov_dbg_verbose (gt,"VF%u state %s(%d) exit\n" , + vfid,control_bit_to_string (bit), bit); +return true; + } +return false; +} + +static void pf_escape_vf_state (struct xe_gt *gt,unsigned int vfid, +enum xe_gt_sriov_control_bits bit) +{ +if (pf_exit_vf_state (gt, vfid, bit)) +xe_gt_sriov_dbg_verbose (gt,"VF%u state %s(%d) escaped by %ps\n" , + vfid,control_bit_to_string (bit), bit, +__builtin_return_address (0 )); +} + +static void pf_enter_vf_mismatch (struct xe_gt *gt,unsigned int vfid) +{ +if (pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_MISMATCH )) { +xe_gt_sriov_dbg (gt,"VF%u state mismatch detected by %ps\n" , + vfid,__builtin_return_address (0 )); +pf_dump_vf_state (gt, vfid); + } +} + +static void pf_exit_vf_mismatch (struct xe_gt *gt,unsigned int vfid) +{ +if (pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_MISMATCH )) +xe_gt_sriov_dbg (gt,"VF%u state mismatch cleared by %ps\n" , + vfid,__builtin_return_address (0 )); + +pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_STOP_FAILED ); +pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSE_FAILED ); +pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_RESUME_FAILED ); +pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_FAILED ); +} + +#define pf_enter_vf_state_machine_bug (gt, vfid) ({ \ + pf_enter_vf_mismatch((gt), (vfid)); \ +}) + +static struct xe_gt_sriov_control_state *pf_pick_vf_control (struct xe_gt *gt,unsigned int vfid) +{ +xe_gt_assert (gt,IS_SRIOV_PF (gt_to_xe (gt))); +xe_gt_assert (gt, vfid <=xe_gt_sriov_pf_get_totalvfs (gt)); + +return >->sriov.pf.vfs[vfid].control; +} + +static void pf_queue_control_worker (struct xe_gt *gt) +{ +struct xe_device *xe =gt_to_xe (gt); + +xe_gt_assert (gt,IS_SRIOV_PF (xe)); + +queue_work (xe->sriov.wq, >->sriov.pf.control.worker); +} + +static void pf_queue_vf (struct xe_gt *gt,unsigned int vfid) +{ +struct xe_gt_sriov_pf_control *pfc = >->sriov.pf.control; + +xe_gt_assert (gt,IS_SRIOV_PF (gt_to_xe (gt))); + +spin_lock (&pfc->lock); +list_move_tail (>->sriov.pf.vfs[vfid].control.link, &pfc->list); +spin_unlock (&pfc->lock); + +pf_queue_control_worker (gt); +} + +static void pf_exit_vf_flr_wip (struct xe_gt *gt,unsigned int vfid); +static void pf_exit_vf_stop_wip (struct xe_gt *gt,unsigned int vfid); +static void pf_exit_vf_pause_wip (struct xe_gt *gt,unsigned int vfid); +static void pf_exit_vf_resume_wip (struct xe_gt *gt,unsigned int vfid); + +static bool pf_enter_vf_wip (struct xe_gt *gt,unsigned int vfid) +{ +if (pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_WIP )) { +struct xe_gt_sriov_control_state *cs =pf_pick_vf_control (gt, vfid); + +reinit_completion (&cs->done); +return true; + } +return false; +} + +static void pf_exit_vf_wip (struct xe_gt *gt,unsigned int vfid) +{ +if (pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_WIP )) { +struct xe_gt_sriov_control_state *cs =pf_pick_vf_control (gt, vfid); + +pf_exit_vf_flr_wip (gt, vfid); +pf_exit_vf_stop_wip (gt, vfid); +pf_exit_vf_pause_wip (gt, vfid); +pf_exit_vf_resume_wip (gt, vfid); + +complete_all (&cs->done); + } +} + +static int pf_wait_vf_wip_done (struct xe_gt *gt,unsigned int vfid,unsigned long timeout) +{ +struct xe_gt_sriov_control_state *cs =pf_pick_vf_control (gt, vfid); + +return wait_for_completion_timeout (&cs->done, timeout) ?0 : -ETIMEDOUT ; +} + +static void pf_enter_vf_ready (struct xe_gt *gt,unsigned int vfid) +{ +pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSED ); +pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_STOPPED ); +pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_RESUMED ); +pf_exit_vf_mismatch (gt, vfid); +pf_exit_vf_wip (gt, vfid); +} + +/** +* DOC: The VF PAUSE state machine +* +* The VF PAUSE state machine looks like:: +* +* (READY,RESUMED)<-------------<---------------------o---------o +* | \ \ +* pause \ \ +* | \ \ +* ....V...........................PAUSE_WIP........ \ \ +* : \ : o \ +* : \ o------<-----busy : | \ +* : \ / / : | | +* : PAUSE_SEND_PAUSE ---failed--->----------o--->(PAUSE_FAILED) | +* : | \ : | | +* : acked rejected---->----------o--->(MISMATCH) / +* : | : / +* : v : / +* : PAUSE_WAIT_GUC : / +* : | : / +* : done : / +* : | : / +* : v : / +* : PAUSE_GUC_DONE o-----restart +* : / : +* : / : +* :....o..............o...............o...........: +* | | | +* completed flr stop +* | | | +* V .....V..... ......V..... +* (PAUSED) : FLR_WIP : : STOP_WIP : +* :.........: :..........: +* +* For the full state machine view, see `The VF state machine`_. +*/ + +static void pf_exit_vf_pause_wip (struct xe_gt *gt,unsigned int vfid) +{ +if (pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSE_WIP )) { +pf_escape_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSE_SEND_PAUSE ); +pf_escape_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC ); +pf_escape_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSE_GUC_DONE ); + } +} + +static void pf_enter_vf_paused (struct xe_gt *gt,unsigned int vfid) +{ +if (!pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSED )) +pf_enter_vf_state_machine_bug (gt, vfid); + +pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_RESUMED ); +pf_exit_vf_mismatch (gt, vfid); +pf_exit_vf_wip (gt, vfid); +} + +static void pf_enter_vf_pause_completed (struct xe_gt *gt,unsigned int vfid) +{ +pf_enter_vf_paused (gt, vfid); +} + +static void pf_enter_vf_pause_failed (struct xe_gt *gt,unsigned int vfid) +{ +pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSE_FAILED ); +pf_exit_vf_wip (gt, vfid); +} + +static void pf_enter_vf_pause_rejected (struct xe_gt *gt,unsigned int vfid) +{ +pf_enter_vf_mismatch (gt, vfid); +pf_enter_vf_pause_failed (gt, vfid); +} + +static bool pf_exit_vf_pause_guc_done (struct xe_gt *gt,unsigned int vfid) +{ +if (!pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSE_GUC_DONE )) +return false; + +pf_enter_vf_pause_completed (gt, vfid); +return true; +} + +static void pf_enter_vf_pause_guc_done (struct xe_gt *gt,unsigned int vfid) +{ +if (pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSE_GUC_DONE )) +pf_queue_vf (gt, vfid); +} + +static void pf_enter_pause_wait_guc (struct xe_gt *gt,unsigned int vfid) +{ +if (!pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC )) +pf_enter_vf_state_machine_bug (gt, vfid); +} + +static bool pf_exit_pause_wait_guc (struct xe_gt *gt,unsigned int vfid) +{ +return pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC ); +} + +static void pf_enter_vf_pause_send_pause (struct xe_gt *gt,unsigned int vfid) +{ +if (!pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSE_SEND_PAUSE )) +pf_enter_vf_state_machine_bug (gt, vfid); + +pf_queue_vf (gt, vfid); +} + +static bool pf_exit_vf_pause_send_pause (struct xe_gt *gt,unsigned int vfid) +{ +int err; + +if (!pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSE_SEND_PAUSE )) +return false; + +/* GuC may actually send a PAUSE_DONE before we get a RESPONSE */ +pf_enter_pause_wait_guc (gt, vfid); + + err =pf_send_vf_pause (gt, vfid); +if (err) { +/* send failed, so we shouldn't expect PAUSE_DONE from GuC */ +pf_exit_pause_wait_guc (gt, vfid); + +if (err == -EBUSY ) +pf_enter_vf_pause_send_pause (gt, vfid); +else if (err == -EIO ) +pf_enter_vf_pause_rejected (gt, vfid); +else +pf_enter_vf_pause_failed (gt, vfid); + }else { +/* +* we have already moved to WAIT_GUC, maybe even to GUC_DONE +* but since GuC didn't complain, we may clear MISMATCH +*/ +pf_exit_vf_mismatch (gt, vfid); + } + +return true; +} + +static bool pf_enter_vf_pause_wip (struct xe_gt *gt,unsigned int vfid) +{ +if (pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSE_WIP )) { +pf_enter_vf_wip (gt, vfid); +pf_enter_vf_pause_send_pause (gt, vfid); +return true; + } + +return false; +} +/** * xe_gt_sriov_pf_control_pause_vf - Pause a VF. * @gt: the &xe_gt @@ -99,7 +553,140 @@ static int pf_send_vf_flr_finish(struct xe_gt *gt, unsigned int vfid)*/ int xe_gt_sriov_pf_control_pause_vf (struct xe_gt *gt,unsigned int vfid) { -return pf_send_vf_pause (gt, vfid); +unsigned long timeout =pf_get_default_timeout (XE_GT_SRIOV_STATE_PAUSE_WIP ); +int err; + +if (pf_check_vf_state (gt, vfid,XE_GT_SRIOV_STATE_STOPPED )) { +xe_gt_sriov_dbg (gt,"VF%u is stopped!\n" , vfid); +return -EPERM ; + } + +if (pf_check_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSED )) { +xe_gt_sriov_dbg (gt,"VF%u was already paused!\n" , vfid); +return -ESTALE ; + } + +if (!pf_enter_vf_pause_wip (gt, vfid)) { +xe_gt_sriov_dbg (gt,"VF%u pause already in progress!\n" , vfid); +return -EALREADY ; + } + + err =pf_wait_vf_wip_done (gt, vfid, timeout); +if (err) { +xe_gt_sriov_dbg (gt,"VF%u pause didn't finish in %u ms (%pe)\n" , + vfid,jiffies_to_msecs (timeout),ERR_PTR (err)); +return err; + } + +if (pf_expect_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSED )) { +xe_gt_sriov_info (gt,"VF%u paused!\n" , vfid); +return 0 ; + } + +if (pf_check_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSE_FAILED )) { +xe_gt_sriov_dbg (gt,"VF%u pause failed!\n" , vfid); +return -EIO ; + } + +xe_gt_sriov_dbg (gt,"VF%u pause was canceled!\n" , vfid); +return -ECANCELED ; +} + +/** +* DOC: The VF RESUME state machine +* +* The VF RESUME state machine looks like:: +* +* (PAUSED)<-----------------<------------------------o +* | \ +* resume \ +* | \ +* ....V............................RESUME_WIP...... \ +* : \ : o +* : \ o-------<-----busy : | +* : \ / / : | +* : RESUME_SEND_RESUME ---failed--->--------o--->(RESUME_FAILED) +* : / \ : | +* : acked rejected---->---------o--->(MISMATCH) +* : / : +* :....o..............o...............o.....o.....: +* | | | \ +* completed flr stop restart-->(READY) +* | | | +* V .....V..... ......V..... +* (RESUMED) : FLR_WIP : : STOP_WIP : +* :.........: :..........: +* +* For the full state machine view, see `The VF state machine`_. +*/ + +static void pf_exit_vf_resume_wip (struct xe_gt *gt,unsigned int vfid) +{ +if (pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_RESUME_WIP )) +pf_escape_vf_state (gt, vfid,XE_GT_SRIOV_STATE_RESUME_SEND_RESUME ); +} + +static void pf_enter_vf_resumed (struct xe_gt *gt,unsigned int vfid) +{ +pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_RESUMED ); +pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSED ); +pf_exit_vf_mismatch (gt, vfid); +pf_exit_vf_wip (gt, vfid); +} + +static void pf_enter_vf_resume_completed (struct xe_gt *gt,unsigned int vfid) +{ +pf_enter_vf_resumed (gt, vfid); +} + +static void pf_enter_vf_resume_failed (struct xe_gt *gt,unsigned int vfid) +{ +pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_RESUME_FAILED ); +pf_exit_vf_wip (gt, vfid); +} + +static void pf_enter_vf_resume_rejected (struct xe_gt *gt,unsigned int vfid) +{ +pf_enter_vf_mismatch (gt, vfid); +pf_enter_vf_resume_failed (gt, vfid); +} + +static void pf_enter_vf_resume_send_resume (struct xe_gt *gt,unsigned int vfid) +{ +if (!pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_RESUME_SEND_RESUME )) +pf_enter_vf_state_machine_bug (gt, vfid); + +pf_queue_vf (gt, vfid); +} + +static bool pf_exit_vf_resume_send_resume (struct xe_gt *gt,unsigned int vfid) +{ +int err; + +if (!pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_RESUME_SEND_RESUME )) +return false; + + err =pf_send_vf_resume (gt, vfid); +if (err == -EBUSY ) +pf_enter_vf_resume_send_resume (gt, vfid); +else if (err == -EIO ) +pf_enter_vf_resume_rejected (gt, vfid); +else if (err) +pf_enter_vf_resume_failed (gt, vfid); +else +pf_enter_vf_resume_completed (gt, vfid); +return true; +} + +static bool pf_enter_vf_resume_wip (struct xe_gt *gt,unsigned int vfid) +{ +if (pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_RESUME_WIP )) { +pf_enter_vf_wip (gt, vfid); +pf_enter_vf_resume_send_resume (gt, vfid); +return true; + } + +return false; }/** @@ -113,7 +700,133 @@ int xe_gt_sriov_pf_control_pause_vf(struct xe_gt *gt, unsigned int vfid)*/ int xe_gt_sriov_pf_control_resume_vf (struct xe_gt *gt,unsigned int vfid) { -return pf_send_vf_resume (gt, vfid); +int err; + +if (!pf_check_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSED )) {
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c int xe_gt_sriov_pf_control_pause_vf(struct xe_gt *gt, unsigned int vfid) · line 715
Quoted 10 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +10
-0+xe_gt_sriov_dbg (gt,"VF%u is not paused!\n" , vfid); +return -EPERM ; + } + +if (!pf_enter_vf_resume_wip (gt, vfid)) { +xe_gt_sriov_dbg (gt,"VF%u resume already in progress!\n" , vfid); +return -EALREADY ; + } + + err =pf_wait_vf_wip_done (gt, vfid,2 *HZ );
use define, or pf_get_default_timeout for this timeout
Quoted 125 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +117
-1+if (err) +return err; + +if (pf_expect_vf_state (gt, vfid,XE_GT_SRIOV_STATE_RESUMED )) { +xe_gt_sriov_info (gt,"VF%u resumed!\n" , vfid); +return 0 ; + } + +if (pf_check_vf_state (gt, vfid,XE_GT_SRIOV_STATE_RESUME_FAILED )) { +xe_gt_sriov_dbg (gt,"VF%u resume failed!\n" , vfid); +return -EIO ; + } + +xe_gt_sriov_dbg (gt,"VF%u resume was canceled!\n" , vfid); +return -ECANCELED ; +} + +/** +* DOC: The VF STOP state machine +* +* The VF STOP state machine looks like:: +* +* (READY,PAUSED,RESUMED)<-------<--------------------o +* | \ +* stop \ +* | \ +* ....V..............................STOP_WIP...... \ +* : \ : o +* : \ o----<----busy : | +* : \ / / : | +* : STOP_SEND_STOP--------failed--->--------o--->(STOP_FAILED) +* : / \ : | +* : acked rejected-------->--------o--->(MISMATCH) +* : / : +* :....o..............o...............o...........: +* | | | +* completed flr restart +* | | | +* V .....V..... V +* (STOPPED) : FLR_WIP : (READY) +* :.........: +* +* For the full state machine view, see `The VF state machine`_. +*/ + +static void pf_exit_vf_stop_wip (struct xe_gt *gt,unsigned int vfid) +{ +if (pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_STOP_WIP )) +pf_escape_vf_state (gt, vfid,XE_GT_SRIOV_STATE_STOP_SEND_STOP ); +} + +static void pf_enter_vf_stopped (struct xe_gt *gt,unsigned int vfid) +{ +if (!pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_STOPPED )) +pf_enter_vf_state_machine_bug (gt, vfid); + +pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_RESUMED ); +pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSED ); +pf_exit_vf_mismatch (gt, vfid); +pf_exit_vf_wip (gt, vfid); +} + +static void pf_enter_vf_stop_completed (struct xe_gt *gt,unsigned int vfid) +{ +pf_enter_vf_stopped (gt, vfid); +} + +static void pf_enter_vf_stop_failed (struct xe_gt *gt,unsigned int vfid) +{ +pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_STOP_FAILED ); +pf_exit_vf_wip (gt, vfid); +} + +static void pf_enter_vf_stop_rejected (struct xe_gt *gt,unsigned int vfid) +{ +pf_enter_vf_mismatch (gt, vfid); +pf_enter_vf_stop_failed (gt, vfid); +} + +static void pf_enter_vf_stop_send_stop (struct xe_gt *gt,unsigned int vfid) +{ +if (!pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_STOP_SEND_STOP )) +pf_enter_vf_state_machine_bug (gt, vfid); + +pf_queue_vf (gt, vfid); +} + +static bool pf_exit_vf_stop_send_stop (struct xe_gt *gt,unsigned int vfid) +{ +int err; + +if (!pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_STOP_SEND_STOP )) +return false; + + err =pf_send_vf_stop (gt, vfid); +if (err == -EBUSY ) +pf_enter_vf_stop_send_stop (gt, vfid); +else if (err == -EIO ) +pf_enter_vf_stop_rejected (gt, vfid); +else if (err) +pf_enter_vf_stop_failed (gt, vfid); +else +pf_enter_vf_stop_completed (gt, vfid); +return true; +} + +static bool pf_enter_vf_stop_wip (struct xe_gt *gt,unsigned int vfid) +{ +if (pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_STOP_WIP )) { +pf_enter_vf_wip (gt, vfid); +pf_enter_vf_stop_send_stop (gt, vfid); +return true; + } +return false; }/** @@ -127,7 +840,279 @@ int xe_gt_sriov_pf_control_resume_vf(struct xe_gt *gt, unsigned int vfid)*/ int xe_gt_sriov_pf_control_stop_vf (struct xe_gt *gt,unsigned int vfid) { -return pf_send_vf_stop (gt, vfid); +int err; + +if (pf_check_vf_state (gt, vfid,XE_GT_SRIOV_STATE_STOPPED )) {
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c int xe_gt_sriov_pf_control_resume_vf(struct xe_gt *gt, unsigned int vfid) · line 855
Quoted 10 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +10
-0+xe_gt_sriov_dbg (gt,"VF%u was already stopped!\n" , vfid); +return -ESTALE ; + } + +if (!pf_enter_vf_stop_wip (gt, vfid)) { +xe_gt_sriov_dbg (gt,"VF%u stop already in progress!\n" , vfid); +return -EALREADY ; + } + + err =pf_wait_vf_wip_done (gt, vfid,2 *HZ );
use define, or pf_get_default_timeout for this timeout
Quoted 271 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +261
-1+if (err) +return err; + +if (pf_expect_vf_state (gt, vfid,XE_GT_SRIOV_STATE_STOPPED )) { +xe_gt_sriov_info (gt,"VF%u stopped!\n" , vfid); +return 0 ; + } + +if (pf_check_vf_state (gt, vfid,XE_GT_SRIOV_STATE_STOP_FAILED )) { +xe_gt_sriov_dbg (gt,"VF%u stop failed!\n" , vfid); +return -EIO ; + } + +xe_gt_sriov_dbg (gt,"VF%u stop was canceled!\n" , vfid); +return -ECANCELED ; +} + +/** +* DOC: The VF FLR state machine +* +* The VF FLR state machine looks like:: +* +* (READY,PAUSED,STOPPED)<------------<--------------o +* | \ +* flr \ +* | \ +* ....V..........................FLR_WIP........... \ +* : \ : \ +* : \ o----<----busy : | +* : \ / / : | +* : FLR_SEND_START---failed----->-----------o--->(FLR_FAILED)<---o +* : | \ : | | +* : acked rejected----->-----------o--->(MISMATCH) | +* : | : ^ | +* : v : | | +* : FLR_WAIT_GUC : | | +* : | : | | +* : done : | | +* : | : | | +* : v : | | +* : FLR_GUC_DONE : | | +* : | : | | +* : FLR_RESET_CONFIG---failed--->-----------o--------+-----------o +* : | : | | +* : FLR_RESET_DATA : | | +* : | : | | +* : FLR_RESET_MMIO : | | +* : | : | | +* : | o----<----busy : | | +* : |/ / : | | +* : FLR_SEND_FINISH----failed--->-----------o--------+-----------o +* : / \ : | +* : acked rejected----->-----------o--------o +* : / : +* :....o..............................o...........: +* | | +* completed restart +* | / +* V / +* (READY)<----------<------------o +* +* For the full state machine view, see `The VF state machine`_. +*/ + +static void pf_enter_vf_flr_send_start (struct xe_gt *gt,unsigned int vfid) +{ +if (!pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_SEND_START )) +pf_enter_vf_state_machine_bug (gt, vfid); + +pf_queue_vf (gt, vfid); +} + +static void pf_enter_vf_flr_wip (struct xe_gt *gt,unsigned int vfid) +{ +if (!pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_WIP )) { +xe_gt_sriov_dbg (gt,"VF%u FLR is already in progress\n" , vfid); +return ; + } + +pf_enter_vf_wip (gt, vfid); +pf_enter_vf_flr_send_start (gt, vfid); +} + +static void pf_exit_vf_flr_wip (struct xe_gt *gt,unsigned int vfid) +{ +if (pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_WIP )) { +pf_escape_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_SEND_FINISH ); +pf_escape_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_RESET_MMIO ); +pf_escape_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_RESET_DATA ); +pf_escape_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_RESET_CONFIG ); +pf_escape_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_GUC_DONE ); +pf_escape_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_WAIT_GUC ); +pf_escape_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_SEND_START ); + } +} + +static void pf_enter_vf_flr_completed (struct xe_gt *gt,unsigned int vfid) +{ +pf_enter_vf_ready (gt, vfid); +} + +static void pf_enter_vf_flr_failed (struct xe_gt *gt,unsigned int vfid) +{ +if (pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_FAILED )) +xe_gt_sriov_notice (gt,"VF%u FLR failed!\n" , vfid); +pf_exit_vf_wip (gt, vfid); +} + +static void pf_enter_vf_flr_rejected (struct xe_gt *gt,unsigned int vfid) +{ +pf_enter_vf_mismatch (gt, vfid); +pf_enter_vf_flr_failed (gt, vfid); +} + +static void pf_enter_vf_flr_send_finish (struct xe_gt *gt,unsigned int vfid) +{ +if (!pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_SEND_FINISH )) +pf_enter_vf_state_machine_bug (gt, vfid); + +pf_queue_vf (gt, vfid); +} + +static bool pf_exit_vf_flr_send_finish (struct xe_gt *gt,unsigned int vfid) +{ +int err; + +if (!pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_SEND_FINISH )) +return false; + + err =pf_send_vf_flr_finish (gt, vfid); +if (err == -EBUSY ) +pf_enter_vf_flr_send_finish (gt, vfid); +else if (err == -EIO ) +pf_enter_vf_flr_rejected (gt, vfid); +else if (err) +pf_enter_vf_flr_failed (gt, vfid); +else +pf_enter_vf_flr_completed (gt, vfid); +return true; +} + +static void pf_enter_vf_flr_reset_mmio (struct xe_gt *gt,unsigned int vfid) +{ +if (!pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_RESET_MMIO )) +pf_enter_vf_state_machine_bug (gt, vfid); + +pf_queue_vf (gt, vfid); +} + +static bool pf_exit_vf_flr_reset_mmio (struct xe_gt *gt,unsigned int vfid) +{ +if (!pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_RESET_MMIO )) +return false; + +/* XXX: placeholder */ + +pf_enter_vf_flr_send_finish (gt, vfid); +return true; +} + +static void pf_enter_vf_flr_reset_data (struct xe_gt *gt,unsigned int vfid) +{ +if (!pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_RESET_DATA )) +pf_enter_vf_state_machine_bug (gt, vfid); + +pf_queue_vf (gt, vfid); +} + +static bool pf_exit_vf_flr_reset_data (struct xe_gt *gt,unsigned int vfid) +{ +if (!pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_RESET_DATA )) +return false; + +xe_gt_sriov_pf_service_reset (gt, vfid); +xe_gt_sriov_pf_monitor_flr (gt, vfid); + +pf_enter_vf_flr_reset_mmio (gt, vfid); +return true; +} + +static void pf_enter_vf_flr_reset_config (struct xe_gt *gt,unsigned int vfid) +{ +if (!pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_RESET_CONFIG )) +pf_enter_vf_state_machine_bug (gt, vfid); + +pf_queue_vf (gt, vfid); +} + +static bool pf_exit_vf_flr_reset_config (struct xe_gt *gt,unsigned int vfid) +{ +unsigned long timeout =pf_get_default_timeout (XE_GT_SRIOV_STATE_FLR_RESET_CONFIG ); +int err; + +if (!pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_RESET_CONFIG )) +return false; + + err =xe_gt_sriov_pf_config_sanitize (gt, vfid, timeout); +if (err) +pf_enter_vf_flr_failed (gt, vfid); +else +pf_enter_vf_flr_reset_data (gt, vfid); +return true; +} + +static void pf_enter_vf_flr_wait_guc (struct xe_gt *gt,unsigned int vfid) +{ +if (!pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_WAIT_GUC )) +pf_enter_vf_state_machine_bug (gt, vfid); +} + +static bool pf_exit_vf_flr_wait_guc (struct xe_gt *gt,unsigned int vfid) +{ +return pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_WAIT_GUC ); +} + +static bool pf_exit_vf_flr_send_start (struct xe_gt *gt,unsigned int vfid) +{ +int err; + +if (!pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_SEND_START )) +return false; + +/* GuC may actually send a FLR_DONE before we get a RESPONSE */ +pf_enter_vf_flr_wait_guc (gt, vfid); + + err =pf_send_vf_flr_start (gt, vfid); +if (err) { +/* send failed, so we shouldn't expect FLR_DONE from GuC */ +pf_exit_vf_flr_wait_guc (gt, vfid); + +if (err == -EBUSY ) +pf_enter_vf_flr_send_start (gt, vfid); +else if (err == -EIO ) +pf_enter_vf_flr_rejected (gt, vfid); +else +pf_enter_vf_flr_failed (gt, vfid); + }else { +/* +* we have already moved to WAIT_GUC, maybe even to GUC_DONE +* but since GuC didn't complain, we may clear MISMATCH +*/ +pf_exit_vf_mismatch (gt, vfid); + } + +return true; +} + +static bool pf_exit_vf_flr_guc_done (struct xe_gt *gt,unsigned int vfid) +{ +if (!pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_GUC_DONE )) +return false; + +pf_enter_vf_flr_reset_config (gt, vfid); +return true; +} + +static void pf_enter_vf_flr_guc_done (struct xe_gt *gt,unsigned int vfid) +{ +if (pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_GUC_DONE )) +pf_queue_vf (gt, vfid); }/** @@ -141,14 +1126,22 @@ int xe_gt_sriov_pf_control_stop_vf(struct xe_gt *gt, unsigned int vfid)*/ int xe_gt_sriov_pf_control_trigger_flr (struct xe_gt *gt,unsigned int vfid) { +unsigned long timeout =pf_get_default_timeout (XE_GT_SRIOV_STATE_FLR_WIP );int err; -/* XXX pf_send_vf_flr_start() expects ct->lock */
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c int xe_gt_sriov_pf_control_stop_vf(struct xe_gt *gt, unsigned int vfid) · line 1137
Quoted 10 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +5
-4-mutex_lock (>->uc.guc.ct.lock); - err =pf_send_vf_flr_start (gt, vfid); -mutex_unlock (>->uc.guc.ct.lock); +pf_enter_vf_flr_wip (gt, vfid); -return err; + err =pf_wait_vf_wip_done (gt, vfid, timeout); +if (err) { +xe_gt_sriov_dbg (gt,"VF%u FLR didn't finish in %u ms (%pe)\n" , + vfid,jiffies_to_msecs (timeout),ERR_PTR (err));
I would increase the level of this log, dbg IMO is not enough,
Quoted 55 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +28
-3+return err; + } + +if (!pf_expect_vf_not_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_FAILED )) +return -EIO ; + +return 0 ; }/** @@ -200,15 +1193,32 @@ static void pf_handle_vf_flr(struct xe_gt *gt, u32 vfid)if (needs_dispatch_flr (xe)) {for_each_gt (gtit, xe, gtid) -pf_send_vf_flr_start (gtit, vfid); +pf_enter_vf_flr_wip (gtit, vfid); }else { -pf_send_vf_flr_start (gt, vfid); +pf_enter_vf_flr_wip (gt, vfid); } }static void pf_handle_vf_flr_done (struct xe_gt *gt,u32 vfid) { -pf_send_vf_flr_finish (gt, vfid); +if (!pf_exit_vf_flr_wait_guc (gt, vfid)) { +xe_gt_sriov_dbg (gt,"Received out of order 'VF%u FLR done'\n" , vfid); +pf_enter_vf_mismatch (gt, vfid); +return ; + } + +pf_enter_vf_flr_guc_done (gt, vfid); +} + +static void pf_handle_vf_pause_done (struct xe_gt *gt,u32 vfid) +{ +if (!pf_exit_pause_wait_guc (gt, vfid)) { +xe_gt_sriov_dbg (gt,"Received out of order 'VF%u PAUSE done'\n" , vfid); +pf_enter_vf_mismatch (gt, vfid); +return ; + } + +pf_enter_vf_pause_guc_done (gt, vfid); }static int pf_handle_vf_event (struct xe_gt *gt,u32 vfid,u32 eventid)@@ -226,6 +1236,7 @@ static int pf_handle_vf_event(struct xe_gt *gt, u32 vfid, u32 eventid)pf_handle_vf_flr_done (gt, vfid);break ;case GUC_PF_NOTIFY_VF_PAUSE_DONE : +pf_handle_vf_pause_done (gt, vfid);break ;case GUC_PF_NOTIFY_VF_FIXUP_DONE :break ;
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c int xe_gt_sriov_pf_control_process_guc2pf(struct xe_gt *gt, const u32 *msg, u32 · line 1299
Quoted 5 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +2
-0@@ -284,3 +1295,165 @@ int xe_gt_sriov_pf_control_process_guc2pf(struct xe_gt *gt, const u32 *msg, u32return vfid ?pf_handle_vf_event (gt, vfid, eventid) :pf_handle_pf_event (gt, eventid); } + +static bool pf_process_vf_machine (struct xe_gt *gt,unsigned int vfid)
NIT: rename to pf_process_vf_state_machine ?
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c int xe_gt_sriov_pf_control_process_guc2pf(struct xe_gt *gt, const u32 *msg, u32 · line 1305
Quoted 6 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +6
-0+{ +if (pf_exit_vf_flr_send_start (gt, vfid)) +return true; + +if (pf_exit_vf_flr_send_start (gt, vfid)) +return true;
Mentioned in a previous email, but as a reminder:
function called twice
Quoted 10 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +10
-0+if (pf_check_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_WAIT_GUC )) { +xe_gt_sriov_dbg_verbose (gt,"VF%u in %s\n" , vfid, +control_bit_to_string (XE_GT_SRIOV_STATE_FLR_WAIT_GUC )); +return false; + } + +if (pf_exit_vf_flr_guc_done (gt, vfid)) +return true; + +if (pf_exit_vf_flr_reset_config (gt, vfid))
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c int xe_gt_sriov_pf_control_process_guc2pf(struct xe_gt *gt, const u32 *msg, u32 · line 1326
Quoted 10 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +10
-0+return true; + +if (pf_exit_vf_flr_reset_data (gt, vfid)) +return true; + +if (pf_exit_vf_flr_reset_mmio (gt, vfid)) +return true; + +if (pf_exit_vf_flr_reset_mmio (gt, vfid)) +return true;
function called twice
Quoted 287 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +133
-0+ +if (pf_exit_vf_flr_send_finish (gt, vfid)) +return true; + +if (pf_exit_vf_stop_send_stop (gt, vfid)) +return true; + +if (pf_exit_vf_pause_send_pause (gt, vfid)) +return true; + +if (pf_check_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC )) { +xe_gt_sriov_dbg_verbose (gt,"VF%u in %s\n" , vfid, +control_bit_to_string (XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC )); +return true; + } + +if (pf_exit_vf_pause_guc_done (gt, vfid)) +return true; + +if (pf_exit_vf_resume_send_resume (gt, vfid)) +return true; + +return false; +} + +static unsigned int pf_control_state_index (struct xe_gt *gt, +struct xe_gt_sriov_control_state *cs) +{ + return container_of(cs, struct xe_gt_sriov_metadata, control) - gt->sriov.pf.vfs; +} + +static void pf_worker_find_work (struct xe_gt *gt) +{ +struct xe_gt_sriov_pf_control *pfc = >->sriov.pf.control; +struct xe_gt_sriov_control_state *cs; +unsigned int vfid; +bool empty; +bool more; + +spin_lock (&pfc->lock); + cs = list_first_entry_or_null(&pfc->list, struct xe_gt_sriov_control_state, link); +if (cs) +list_del_init (&cs->link); + empty =list_empty (&pfc->list); +spin_unlock (&pfc->lock); + +if (!cs) +return ; + +/* VF metadata structures are indexed by the VFID */ + vfid =pf_control_state_index (gt, cs); +xe_gt_assert (gt, vfid <=xe_gt_sriov_pf_get_totalvfs (gt)); + + more =pf_process_vf_machine (gt, vfid); +if (more) +pf_queue_vf (gt, vfid); +else if (!empty) +pf_queue_control_worker (gt); +} + +static void control_worker_func (struct work_struct *w) +{ + struct xe_gt *gt = container_of(w, struct xe_gt, sriov.pf.control.worker); + +xe_gt_assert (gt,IS_SRIOV_PF (gt_to_xe (gt))); +pf_worker_find_work (gt); +} + +static void pf_stop_worker (struct xe_gt *gt) +{ +xe_gt_assert (gt,IS_SRIOV_PF (gt_to_xe (gt))); +cancel_work_sync (>->sriov.pf.control.worker); +} + +static void control_fini_action (struct drm_device *dev,void *data) +{ +struct xe_gt *gt = data; + +pf_stop_worker (gt); +} + +/** +* xe_gt_sriov_pf_control_init() - Initialize PF's control data. +* @gt: the &xe_gt +* +* This function is for PF only. +* +* Return: 0 on success or a negative error code on failure. +*/ +int xe_gt_sriov_pf_control_init (struct xe_gt *gt) +{ +struct xe_device *xe =gt_to_xe (gt); +unsigned int n, totalvfs; + +xe_gt_assert (gt,IS_SRIOV_PF (xe)); + + totalvfs =xe_sriov_pf_get_totalvfs (xe); +for (n =0 ; n <= totalvfs; n++) { +struct xe_gt_sriov_control_state *cs =pf_pick_vf_control (gt, n); + +init_completion (&cs->done); +INIT_LIST_HEAD (&cs->link); + } + +spin_lock_init (>->sriov.pf.control.lock); +INIT_LIST_HEAD (>->sriov.pf.control.list); +INIT_WORK (>->sriov.pf.control.worker, control_worker_func); + +return drmm_add_action_or_reset (&xe->drm, control_fini_action, gt); +} + +/** +* xe_gt_sriov_pf_control_restart() - Restart SR-IOV control data after a GT reset. +* @gt: the &xe_gt +* +* Any per-VF status maintained by the PF or any ongoing VF control activity +* performed by the PF must be reset or cancelled when the GT is reset. +* +* This function is for PF only. +*/ +void xe_gt_sriov_pf_control_restart (struct xe_gt *gt) +{ +struct xe_device *xe =gt_to_xe (gt); +unsigned int n, totalvfs; + +xe_gt_assert (gt,IS_SRIOV_PF (xe)); + +pf_stop_worker (gt); + + totalvfs =xe_sriov_pf_get_totalvfs (xe); +for (n =1 ; n <= totalvfs; n++) +pf_enter_vf_ready (gt, n); +}drivers/gpu/drm/xe/xe_gt_sriov_pf_control.h +3
-0@@ -11,6 +11,9 @@struct xe_gt ; +int xe_gt_sriov_pf_control_init (struct xe_gt *gt); +void xe_gt_sriov_pf_control_restart (struct xe_gt *gt); +int xe_gt_sriov_pf_control_pause_vf (struct xe_gt *gt,unsigned int vfid);int xe_gt_sriov_pf_control_resume_vf (struct xe_gt *gt,unsigned int vfid);int xe_gt_sriov_pf_control_stop_vf (struct xe_gt *gt,unsigned int vfid);drivers/gpu/drm/xe/xe_gt_sriov_pf_control_types.h new file +107
-0@@ -0,0 +1,107 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2024 Intel Corporation +*/ + +#ifndef _XE_GT_SRIOV_PF_CONTROL_TYPES_H_ +#define _XE_GT_SRIOV_PF_CONTROL_TYPES_H_ + +#include <linux/completion.h> +#include <linux/spinlock.h> +#include <linux/workqueue_types.h> + +/** +* enum xe_gt_sriov_control_bits - Various bits used by the PF to represent a VF state +* +* @XE_GT_SRIOV_STATE_WIP: indicates that some operations are in progress. +* @XE_GT_SRIOV_STATE_FLR_WIP: indicates that a VF FLR is in progress. +* @XE_GT_SRIOV_STATE_FLR_SEND_START: indicates that the PF wants to send a FLR START command. +* @XE_GT_SRIOV_STATE_FLR_WAIT_GUC: indicates that the PF awaits for a response from the GuC. +* @XE_GT_SRIOV_STATE_FLR_GUC_DONE: indicates that the PF has received a response from the GuC. +* @XE_GT_SRIOV_STATE_FLR_RESET_CONFIG: indicates that the PF needs to clear VF's resources. +* @XE_GT_SRIOV_STATE_FLR_RESET_DATA: indicates that the PF needs to clear VF's data. +* @XE_GT_SRIOV_STATE_FLR_RESET_MMIO: indicates that the PF needs to reset VF's registers. +* @XE_GT_SRIOV_STATE_FLR_SEND_FINISH: indicates that the PF wants to send a FLR FINISH message. +* @XE_GT_SRIOV_STATE_FLR_FAILED: indicates that VF FLR sequence failed. +* @XE_GT_SRIOV_STATE_PAUSE_WIP: indicates that a VF pause operation is in progress. +* @XE_GT_SRIOV_STATE_PAUSE_SEND_PAUSE: indicates that the PF is about to send a PAUSE command. +* @XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC: indicates that the PF awaits for a response from the GuC. +* @XE_GT_SRIOV_STATE_PAUSE_GUC_DONE: indicates that the PF has received a response from the GuC. +* @XE_GT_SRIOV_STATE_PAUSE_FAILED: indicates that a VF pause operation has failed. +* @XE_GT_SRIOV_STATE_PAUSED: indicates that the VF is paused. +* @XE_GT_SRIOV_STATE_RESUME_WIP: indicates the a VF resume operation is in progress. +* @XE_GT_SRIOV_STATE_RESUME_SEND_RESUME: indicates that the PF is about to send RESUME command. +* @XE_GT_SRIOV_STATE_RESUME_FAILED: indicates that a VF resume operation has failed. +* @XE_GT_SRIOV_STATE_RESUMED: indicates that the VF was resumed. +* @XE_GT_SRIOV_STATE_STOP_WIP: indicates that a VF stop operation is in progress. +* @XE_GT_SRIOV_STATE_STOP_SEND_STOP: indicates that the PF wants to send a STOP command. +* @XE_GT_SRIOV_STATE_STOP_FAILED: indicates that the VF stop operation has failed +* @XE_GT_SRIOV_STATE_STOPPED: indicates that the VF was stopped. +* @XE_GT_SRIOV_STATE_MISMATCH: indicates that the PF has detected a VF state mismatch. +*/ +enum xe_gt_sriov_control_bits { +XE_GT_SRIOV_STATE_WIP =1 , + +XE_GT_SRIOV_STATE_FLR_WIP , +XE_GT_SRIOV_STATE_FLR_SEND_START , +XE_GT_SRIOV_STATE_FLR_WAIT_GUC , +XE_GT_SRIOV_STATE_FLR_GUC_DONE , +XE_GT_SRIOV_STATE_FLR_RESET_CONFIG , +XE_GT_SRIOV_STATE_FLR_RESET_DATA , +XE_GT_SRIOV_STATE_FLR_RESET_MMIO , +XE_GT_SRIOV_STATE_FLR_SEND_FINISH , +XE_GT_SRIOV_STATE_FLR_FAILED , + +XE_GT_SRIOV_STATE_PAUSE_WIP , +XE_GT_SRIOV_STATE_PAUSE_SEND_PAUSE , +XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC , +XE_GT_SRIOV_STATE_PAUSE_GUC_DONE , +XE_GT_SRIOV_STATE_PAUSE_FAILED , +XE_GT_SRIOV_STATE_PAUSED , + +XE_GT_SRIOV_STATE_RESUME_WIP , +XE_GT_SRIOV_STATE_RESUME_SEND_RESUME , +XE_GT_SRIOV_STATE_RESUME_FAILED , +XE_GT_SRIOV_STATE_RESUMED , + +XE_GT_SRIOV_STATE_STOP_WIP , +XE_GT_SRIOV_STATE_STOP_SEND_STOP , +XE_GT_SRIOV_STATE_STOP_FAILED , +XE_GT_SRIOV_STATE_STOPPED , + +XE_GT_SRIOV_STATE_MISMATCH =BITS_PER_LONG -1 , +}; + +/** +* struct xe_gt_sriov_control_state - GT-level per-VF control state. +* +* Used by the PF driver to maintain per-VF control data. +*/ +struct xe_gt_sriov_control_state { +/** @state: VF state bits */ +unsigned long state; + +/** @done: completion of async operations */ +struct completion done; + +/** @link: link into worker list */ +struct list_head link; +}; + +/** +* struct xe_gt_sriov_pf_control - GT-level control data. +* +* Used by the PF driver to maintain its data. +*/ +struct xe_gt_sriov_pf_control { +/** @worker: worker that executes a VF operations */ +struct work_struct worker; + +/** @list: list of VF entries that have a pending work */ +struct list_head list; + +/** @lock: protects VF pending list */ +spinlock_t lock; +}; + +#endif drivers/gpu/drm/xe/xe_gt_sriov_pf_types.h +5
-0@@ -9,6 +9,7 @@#include <linux/types.h> #include "xe_gt_sriov_pf_config_types.h" +#include "xe_gt_sriov_pf_control_types.h" #include "xe_gt_sriov_pf_monitor_types.h" #include "xe_gt_sriov_pf_policy_types.h" #include "xe_gt_sriov_pf_service_types.h" @@ -23,6 +24,9 @@ struct xe_gt_sriov_metadata {/** @monitor: per-VF monitoring data. */ struct xe_gt_sriov_monitor monitor; +/** @control: per-VF control data. */ +struct xe_gt_sriov_control_state control; +/** @version: negotiated VF/PF ABI version */ struct xe_gt_sriov_pf_service_version version; };@@ -30,12 +34,14 @@ struct xe_gt_sriov_metadata {/** * struct xe_gt_sriov_pf - GT level PF virtualization data. * @service: service data. +* @control: control data.
drivers/gpu/drm/xe/xe_gt_sriov_pf_types.h struct xe_gt_sriov_metadata { · line 47
Quoted 10 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_types.h +1
-0* @policy: policy data. * @spare: PF-only provisioning configuration. * @vfs: metadata for all VFs. */ struct xe_gt_sriov_pf {struct xe_gt_sriov_pf_service service; +struct xe_gt_sriov_pf_control control;struct xe_gt_sriov_pf_policy policy;struct xe_gt_sriov_spare_config spare;struct xe_gt_sriov_metadata *vfs;
Functionally, it's a good idea to introduce a state machine here. I believe that if this code is well tested, this code will be reliable and will handle all assumed states, including errors.
However, I have a few general comments in addition to those I left above
in the code.
While the drawings indicate a certain hierarchy of states (we have main and intermediate states), in the code this structure is flat.
The code itself is difficult to understand (thanks to drawings it is a bit easier) but it takes some time to analyze and understand it sensibly. I am afraid that the code will be difficult to debug and an inexperienced person will have a problem with extending the functionality of the code.
Thanks,
Piotr
Quoted 3 lines
Signature · 1 line
2.43.0
Re: [PATCH 04/12] drm/xe/pf: Improve VF control
Quoted 165 lines · Piotr Piórkowski
Michal Wajdeczko <[email protected]> wrote on pią [2024-sie-09 18:51:51 +0200]:
Quoted 164 lines
Our initial VF control implementation was focused on providing a very minimal support for the
VF_STATE_NOTIFYevents just to meet GuC requirements, without tracking a VF state or doing any expected actions (like cleanup in case of the FLR notification).Try to improve this by defining set of VF state machines, each responsible for processing one activity (PAUSE, RESUME, STOP or FLR). All required steps defined by the VF state machine are then executed by the PF worker from the dedicated workqueue.
Any external requests or notifications simply try to transition between the states to trigger a work and then wait for that work to finish. Some predefined default timeouts are used to avoid changing existing API calls, but it should be easy to extend the control API to also accept specific timeout values.
Signed-off-by Michal Wajdeczko <[email protected]>Cc Piotr Piórkowski <[email protected]>--- drivers/gpu/drm/xe/xe_gt_sriov_pf.c | 6 + drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c | 1203 ++++++++++++++++- drivers/gpu/drm/xe/xe_gt_sriov_pf_control.h | 3 + .../gpu/drm/xe/xe_gt_sriov_pf_control_types.h | 107 ++ drivers/gpu/drm/xe/xe_gt_sriov_pf_types.h | 6 + 5 files changed, 1310 insertions(+), 15 deletions(-) create mode 100644 drivers/gpu/drm/xe/xe_gt_sriov_pf_control_types.hdrivers/gpu/drm/xe/xe_gt_sriov_pf.c +6
-0@@ -9,6 +9,7 @@#include "xe_gt_sriov_pf.h" #include "xe_gt_sriov_pf_config.h" +#include "xe_gt_sriov_pf_control.h" #include "xe_gt_sriov_pf_helpers.h" #include "xe_gt_sriov_pf_service.h" #include "xe_mmio.h" @@ -57,6 +58,10 @@ int xe_gt_sriov_pf_init_early(struct xe_gt *gt)if (err)return err; + err =xe_gt_sriov_pf_control_init (gt); +if (err) +return err; +return 0 ; }@@ -93,4 +98,5 @@ void xe_gt_sriov_pf_init_hw(struct xe_gt *gt)void xe_gt_sriov_pf_restart (struct xe_gt *gt) {xe_gt_sriov_pf_config_restart (gt); +xe_gt_sriov_pf_control_restart (gt); }drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +69
-4@@ -3,12 +3,17 @@* Copyright © 2023-2024 Intel Corporation */ +#include <drm/drm_managed.h> +#include "abi/guc_actions_sriov_abi.h" #include "xe_device.h" #include "xe_gt.h" +#include "xe_gt_sriov_pf_config.h" #include "xe_gt_sriov_pf_control.h" #include "xe_gt_sriov_pf_helpers.h" +#include "xe_gt_sriov_pf_monitor.h" +#include "xe_gt_sriov_pf_service.h" #include "xe_gt_sriov_printk.h" #include "xe_guc_ct.h" #include "xe_sriov.h" @@ -42,10 +47,6 @@ static int guc_action_vf_control_cmd(struct xe_guc *guc, u32 vfid, u32 cmd) };int ret; -/* XXX those two commands are now sent from the G2H handler */ -if (cmd ==GUC_PF_TRIGGER_VF_FLR_START || cmd ==GUC_PF_TRIGGER_VF_FLR_FINISH ) -return xe_guc_ct_send_g2h_handler (&guc->ct, request,ARRAY_SIZE (request)); - ret =xe_guc_ct_send_block (&guc->ct, request,ARRAY_SIZE (request));return ret >0 ? -EPROTO : ret; }@@ -55,6 +56,8 @@ static int pf_send_vf_control_cmd(struct xe_gt *gt, unsigned int vfid, u32 cmd)int err;xe_gt_assert (gt, vfid !=PFID ); +xe_gt_sriov_dbg_verbose (gt,"sending VF%u control command %s\n" , + vfid,control_cmd_to_string (cmd)); err =guc_action_vf_control_cmd (>->uc.guc, vfid, cmd);if (unlikely (err))@@ -88,6 +91,457 @@ static int pf_send_vf_flr_finish(struct xe_gt *gt, unsigned int vfid)return pf_send_vf_control_cmd (gt, vfid,GUC_PF_TRIGGER_VF_FLR_FINISH ); } +/** +* DOC: The VF state machine +* +* The simplified VF state machine could be presented as:: +* +* pause--------------------------o +* / | +* / v +* (READY)<------------------resume-----(PAUSED) +* ^ \ / / +* | \ / / +* | stop---->(STOPPED)<----stop / +* | / / +* | / / +* o--------<-----flr / +* \ / +* o------<--------------------flr +* +* Where: +* +* * READY - represents a state in which VF is fully operable +* * PAUSED - represents a state in which VF activity is temporarily suspended +* * STOPPED - represents a state in which VF activity is definitely halted +* * pause - represents a request to temporarily suspend VF activity +* * resume - represents a request to resume VF activity +* * stop - represents a request to definitely halt VF activity +* * flr - represents a request to perform VF FLR to restore VF activity +* +* However, each state transition requires additional steps that involves +* communication with GuC that might fail or be interrupted by other requests:: +* +* .................................WIP.... +* : : +* pause--------------------->PAUSE_WIP----------------------------o +* / : / \ : | +* / : o----<---stop flr--o : | +* / : | \ / | : V +* (READY)<---------------+------------RESUME_WIP<----+--<-----resume--(PAUSED) +* ^ \ \ : | | : / / +* | \ \ : | | : / / +* | \ \ : | | : / / +* | \ \ : o----<----------------------+--<-------stop / +* | \ \ : | | : / +* | \ \ : V | : / +* | \ stop----->STOP_WIP---------flr--->-----o : / +* | \ : | | : / +* | \ : | V : / +* | flr--------+----->----------------->FLR_WIP<-----flr +* | : | / ^ : +* | : | / | : +* o--------<-------:----+-----<----------------o | : +* : | | : +* :....|...........................|.....: +* | | +* V | +* (STOPPED)--------------------flr +* +* For details about each internal WIP state machine see: +* +* * `The VF PAUSE state machine`_ +* * `The VF RESUME state machine`_ +* * `The VF STOP state machine`_
Quoted 8 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c static int pf_send_vf_flr_finish(struct xe_gt *gt, unsigned int vfid) · line 156
Quoted 1 line
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +1
-0+* * `The VF FLR state machine`_ Later in the code there is one state that is not obvious when you look at the first two drawings of the state machine - it is the resumed state. It appears in subsequent drawings but in my opinion it is not obvious. I have already talked to Michal about it and he explained to me why he introduced it in the code, but it seems to me that it should be included at least in this drawing.
sure, will try to put it to above diagram as (READY/RESUMED)
Quoted 56 lines
Quoted 56 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +55
-0+*/ + +#ifdef CONFIG_DRM_XE_DEBUG_SRIOV +static const char *control_bit_to_string (enum xe_gt_sriov_control_bits bit) +{ +switch (bit) { +#define CASE2STR (_X) \ + case XE_GT_SRIOV_STATE_##_X: return #_X +CASE2STR (WIP ); +CASE2STR (FLR_WIP ); +CASE2STR (FLR_SEND_START ); +CASE2STR (FLR_WAIT_GUC ); +CASE2STR (FLR_GUC_DONE ); +CASE2STR (FLR_RESET_CONFIG ); +CASE2STR (FLR_RESET_DATA ); +CASE2STR (FLR_RESET_MMIO ); +CASE2STR (FLR_SEND_FINISH ); +CASE2STR (FLR_FAILED ); +CASE2STR (PAUSE_WIP ); +CASE2STR (PAUSE_SEND_PAUSE ); +CASE2STR (PAUSE_WAIT_GUC ); +CASE2STR (PAUSE_GUC_DONE ); +CASE2STR (PAUSE_FAILED ); +CASE2STR (PAUSED ); +CASE2STR (RESUME_WIP ); +CASE2STR (RESUME_SEND_RESUME ); +CASE2STR (RESUME_FAILED ); +CASE2STR (RESUMED ); +CASE2STR (STOP_WIP ); +CASE2STR (STOP_SEND_STOP ); +CASE2STR (STOP_FAILED ); +CASE2STR (STOPPED ); +CASE2STR (MISMATCH ); +#undef CASE2STR +default :return "?" ; + } +} +#endif + +static unsigned long pf_get_default_timeout (enum xe_gt_sriov_control_bits bit) +{ +switch (bit) { +case XE_GT_SRIOV_STATE_FLR_WAIT_GUC : +case XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC : +return HZ /2 ; +case XE_GT_SRIOV_STATE_FLR_WIP : +case XE_GT_SRIOV_STATE_FLR_RESET_CONFIG : +return 5 *HZ ; +default : +return HZ ; + } +} + +static unsigned long *pf_peek_vf_state (struct xe_gt *gt,unsigned int vfid) +{
Quoted 8 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c static int pf_send_vf_flr_finish(struct xe_gt *gt, unsigned int vfid) · line 216
Quoted 5 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +5
-0+xe_gt_assert (gt,IS_SRIOV_PF (gt_to_xe (gt))); +xe_gt_assert (gt, vfid <=xe_gt_sriov_pf_get_totalvfs (gt)); + +return >->sriov.pf.vfs[vfid].control.state; +}NIT: Later in the code you define such a function as
pf_peek_vf_control.
Maybe you define it earlier and use it inpf_peek_vf_state? The code will reduce by two asserts
you likely mean pf_pick_vf_control()
yeah, will give it a try
Quoted 485 lines
Quoted 485 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +469
-2+ +static bool pf_check_vf_state (struct xe_gt *gt,unsigned int vfid, +enum xe_gt_sriov_control_bits bit) +{ +return test_bit (bit,pf_peek_vf_state (gt, vfid)); +} + +static void pf_dump_vf_state (struct xe_gt *gt,unsigned int vfid) +{ +unsigned long state = *pf_peek_vf_state (gt, vfid); +enum xe_gt_sriov_control_bits bit; + +if (state) { +xe_gt_sriov_dbg_verbose (gt,"VF%u state %#lx%s%*pbl\n" , + vfid, state, state ?" bits " :"" , + (int )BITS_PER_LONG , &state); +for_each_set_bit (bit, &state,BITS_PER_LONG ) +xe_gt_sriov_dbg_verbose (gt,"VF%u state %s(%d)\n" , + vfid,control_bit_to_string (bit), bit); + }else { +xe_gt_sriov_dbg_verbose (gt,"VF%u state READY\n" , vfid); + } +} + +static bool pf_expect_vf_state (struct xe_gt *gt,unsigned int vfid, +enum xe_gt_sriov_control_bits bit) +{ +bool result =pf_check_vf_state (gt, vfid, bit); + +if (unlikely (!result)) +pf_dump_vf_state (gt, vfid); + +return result; +} + +static bool pf_expect_vf_not_state (struct xe_gt *gt,unsigned int vfid, +enum xe_gt_sriov_control_bits bit) +{ +bool result = !pf_check_vf_state (gt, vfid, bit); + +if (unlikely (!result)) +pf_dump_vf_state (gt, vfid); + +return result; +} + +static bool pf_enter_vf_state (struct xe_gt *gt,unsigned int vfid, +enum xe_gt_sriov_control_bits bit) +{ +if (!test_and_set_bit (bit,pf_peek_vf_state (gt, vfid))) { +xe_gt_sriov_dbg_verbose (gt,"VF%u state %s(%d) enter\n" , + vfid,control_bit_to_string (bit), bit); +return true; + } +return false; +} + +static bool pf_exit_vf_state (struct xe_gt *gt,unsigned int vfid, +enum xe_gt_sriov_control_bits bit) +{ +if (test_and_clear_bit (bit,pf_peek_vf_state (gt, vfid))) { +xe_gt_sriov_dbg_verbose (gt,"VF%u state %s(%d) exit\n" , + vfid,control_bit_to_string (bit), bit); +return true; + } +return false; +} + +static void pf_escape_vf_state (struct xe_gt *gt,unsigned int vfid, +enum xe_gt_sriov_control_bits bit) +{ +if (pf_exit_vf_state (gt, vfid, bit)) +xe_gt_sriov_dbg_verbose (gt,"VF%u state %s(%d) escaped by %ps\n" , + vfid,control_bit_to_string (bit), bit, +__builtin_return_address (0 )); +} + +static void pf_enter_vf_mismatch (struct xe_gt *gt,unsigned int vfid) +{ +if (pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_MISMATCH )) { +xe_gt_sriov_dbg (gt,"VF%u state mismatch detected by %ps\n" , + vfid,__builtin_return_address (0 )); +pf_dump_vf_state (gt, vfid); + } +} + +static void pf_exit_vf_mismatch (struct xe_gt *gt,unsigned int vfid) +{ +if (pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_MISMATCH )) +xe_gt_sriov_dbg (gt,"VF%u state mismatch cleared by %ps\n" , + vfid,__builtin_return_address (0 )); + +pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_STOP_FAILED ); +pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSE_FAILED ); +pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_RESUME_FAILED ); +pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_FAILED ); +} + +#define pf_enter_vf_state_machine_bug (gt, vfid) ({ \ + pf_enter_vf_mismatch((gt), (vfid)); \ +}) + +static struct xe_gt_sriov_control_state *pf_pick_vf_control (struct xe_gt *gt,unsigned int vfid) +{ +xe_gt_assert (gt,IS_SRIOV_PF (gt_to_xe (gt))); +xe_gt_assert (gt, vfid <=xe_gt_sriov_pf_get_totalvfs (gt)); + +return >->sriov.pf.vfs[vfid].control; +} + +static void pf_queue_control_worker (struct xe_gt *gt) +{ +struct xe_device *xe =gt_to_xe (gt); + +xe_gt_assert (gt,IS_SRIOV_PF (xe)); + +queue_work (xe->sriov.wq, >->sriov.pf.control.worker); +} + +static void pf_queue_vf (struct xe_gt *gt,unsigned int vfid) +{ +struct xe_gt_sriov_pf_control *pfc = >->sriov.pf.control; + +xe_gt_assert (gt,IS_SRIOV_PF (gt_to_xe (gt))); + +spin_lock (&pfc->lock); +list_move_tail (>->sriov.pf.vfs[vfid].control.link, &pfc->list); +spin_unlock (&pfc->lock); + +pf_queue_control_worker (gt); +} + +static void pf_exit_vf_flr_wip (struct xe_gt *gt,unsigned int vfid); +static void pf_exit_vf_stop_wip (struct xe_gt *gt,unsigned int vfid); +static void pf_exit_vf_pause_wip (struct xe_gt *gt,unsigned int vfid); +static void pf_exit_vf_resume_wip (struct xe_gt *gt,unsigned int vfid); + +static bool pf_enter_vf_wip (struct xe_gt *gt,unsigned int vfid) +{ +if (pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_WIP )) { +struct xe_gt_sriov_control_state *cs =pf_pick_vf_control (gt, vfid); + +reinit_completion (&cs->done); +return true; + } +return false; +} + +static void pf_exit_vf_wip (struct xe_gt *gt,unsigned int vfid) +{ +if (pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_WIP )) { +struct xe_gt_sriov_control_state *cs =pf_pick_vf_control (gt, vfid); + +pf_exit_vf_flr_wip (gt, vfid); +pf_exit_vf_stop_wip (gt, vfid); +pf_exit_vf_pause_wip (gt, vfid); +pf_exit_vf_resume_wip (gt, vfid); + +complete_all (&cs->done); + } +} + +static int pf_wait_vf_wip_done (struct xe_gt *gt,unsigned int vfid,unsigned long timeout) +{ +struct xe_gt_sriov_control_state *cs =pf_pick_vf_control (gt, vfid); + +return wait_for_completion_timeout (&cs->done, timeout) ?0 : -ETIMEDOUT ; +} + +static void pf_enter_vf_ready (struct xe_gt *gt,unsigned int vfid) +{ +pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSED ); +pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_STOPPED ); +pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_RESUMED ); +pf_exit_vf_mismatch (gt, vfid); +pf_exit_vf_wip (gt, vfid); +} + +/** +* DOC: The VF PAUSE state machine +* +* The VF PAUSE state machine looks like:: +* +* (READY,RESUMED)<-------------<---------------------o---------o +* | \ \ +* pause \ \ +* | \ \ +* ....V...........................PAUSE_WIP........ \ \ +* : \ : o \ +* : \ o------<-----busy : | \ +* : \ / / : | | +* : PAUSE_SEND_PAUSE ---failed--->----------o--->(PAUSE_FAILED) | +* : | \ : | | +* : acked rejected---->----------o--->(MISMATCH) / +* : | : / +* : v : / +* : PAUSE_WAIT_GUC : / +* : | : / +* : done : / +* : | : / +* : v : / +* : PAUSE_GUC_DONE o-----restart +* : / : +* : / : +* :....o..............o...............o...........: +* | | | +* completed flr stop +* | | | +* V .....V..... ......V..... +* (PAUSED) : FLR_WIP : : STOP_WIP : +* :.........: :..........: +* +* For the full state machine view, see `The VF state machine`_. +*/ + +static void pf_exit_vf_pause_wip (struct xe_gt *gt,unsigned int vfid) +{ +if (pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSE_WIP )) { +pf_escape_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSE_SEND_PAUSE ); +pf_escape_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC ); +pf_escape_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSE_GUC_DONE ); + } +} + +static void pf_enter_vf_paused (struct xe_gt *gt,unsigned int vfid) +{ +if (!pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSED )) +pf_enter_vf_state_machine_bug (gt, vfid); + +pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_RESUMED ); +pf_exit_vf_mismatch (gt, vfid); +pf_exit_vf_wip (gt, vfid); +} + +static void pf_enter_vf_pause_completed (struct xe_gt *gt,unsigned int vfid) +{ +pf_enter_vf_paused (gt, vfid); +} + +static void pf_enter_vf_pause_failed (struct xe_gt *gt,unsigned int vfid) +{ +pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSE_FAILED ); +pf_exit_vf_wip (gt, vfid); +} + +static void pf_enter_vf_pause_rejected (struct xe_gt *gt,unsigned int vfid) +{ +pf_enter_vf_mismatch (gt, vfid); +pf_enter_vf_pause_failed (gt, vfid); +} + +static bool pf_exit_vf_pause_guc_done (struct xe_gt *gt,unsigned int vfid) +{ +if (!pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSE_GUC_DONE )) +return false; + +pf_enter_vf_pause_completed (gt, vfid); +return true; +} + +static void pf_enter_vf_pause_guc_done (struct xe_gt *gt,unsigned int vfid) +{ +if (pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSE_GUC_DONE )) +pf_queue_vf (gt, vfid); +} + +static void pf_enter_pause_wait_guc (struct xe_gt *gt,unsigned int vfid) +{ +if (!pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC )) +pf_enter_vf_state_machine_bug (gt, vfid); +} + +static bool pf_exit_pause_wait_guc (struct xe_gt *gt,unsigned int vfid) +{ +return pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC ); +} + +static void pf_enter_vf_pause_send_pause (struct xe_gt *gt,unsigned int vfid) +{ +if (!pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSE_SEND_PAUSE )) +pf_enter_vf_state_machine_bug (gt, vfid); + +pf_queue_vf (gt, vfid); +} + +static bool pf_exit_vf_pause_send_pause (struct xe_gt *gt,unsigned int vfid) +{ +int err; + +if (!pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSE_SEND_PAUSE )) +return false; + +/* GuC may actually send a PAUSE_DONE before we get a RESPONSE */ +pf_enter_pause_wait_guc (gt, vfid); + + err =pf_send_vf_pause (gt, vfid); +if (err) { +/* send failed, so we shouldn't expect PAUSE_DONE from GuC */ +pf_exit_pause_wait_guc (gt, vfid); + +if (err == -EBUSY ) +pf_enter_vf_pause_send_pause (gt, vfid); +else if (err == -EIO ) +pf_enter_vf_pause_rejected (gt, vfid); +else +pf_enter_vf_pause_failed (gt, vfid); + }else { +/* +* we have already moved to WAIT_GUC, maybe even to GUC_DONE +* but since GuC didn't complain, we may clear MISMATCH +*/ +pf_exit_vf_mismatch (gt, vfid); + } + +return true; +} + +static bool pf_enter_vf_pause_wip (struct xe_gt *gt,unsigned int vfid) +{ +if (pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSE_WIP )) { +pf_enter_vf_wip (gt, vfid); +pf_enter_vf_pause_send_pause (gt, vfid); +return true; + } + +return false; +} +/** * xe_gt_sriov_pf_control_pause_vf - Pause a VF. * @gt: the &xe_gt @@ -99,7 +553,140 @@ static int pf_send_vf_flr_finish(struct xe_gt *gt, unsigned int vfid)*/ int xe_gt_sriov_pf_control_pause_vf (struct xe_gt *gt,unsigned int vfid) { -return pf_send_vf_pause (gt, vfid); +unsigned long timeout =pf_get_default_timeout (XE_GT_SRIOV_STATE_PAUSE_WIP ); +int err; + +if (pf_check_vf_state (gt, vfid,XE_GT_SRIOV_STATE_STOPPED )) { +xe_gt_sriov_dbg (gt,"VF%u is stopped!\n" , vfid); +return -EPERM ; + } + +if (pf_check_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSED )) { +xe_gt_sriov_dbg (gt,"VF%u was already paused!\n" , vfid); +return -ESTALE ; + } + +if (!pf_enter_vf_pause_wip (gt, vfid)) { +xe_gt_sriov_dbg (gt,"VF%u pause already in progress!\n" , vfid); +return -EALREADY ; + } + + err =pf_wait_vf_wip_done (gt, vfid, timeout); +if (err) { +xe_gt_sriov_dbg (gt,"VF%u pause didn't finish in %u ms (%pe)\n" , + vfid,jiffies_to_msecs (timeout),ERR_PTR (err)); +return err; + } + +if (pf_expect_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSED )) { +xe_gt_sriov_info (gt,"VF%u paused!\n" , vfid); +return 0 ; + } + +if (pf_check_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSE_FAILED )) { +xe_gt_sriov_dbg (gt,"VF%u pause failed!\n" , vfid); +return -EIO ; + } + +xe_gt_sriov_dbg (gt,"VF%u pause was canceled!\n" , vfid); +return -ECANCELED ; +} + +/** +* DOC: The VF RESUME state machine +* +* The VF RESUME state machine looks like:: +* +* (PAUSED)<-----------------<------------------------o +* | \ +* resume \ +* | \ +* ....V............................RESUME_WIP...... \ +* : \ : o +* : \ o-------<-----busy : | +* : \ / / : | +* : RESUME_SEND_RESUME ---failed--->--------o--->(RESUME_FAILED) +* : / \ : | +* : acked rejected---->---------o--->(MISMATCH) +* : / : +* :....o..............o...............o.....o.....: +* | | | \ +* completed flr stop restart-->(READY) +* | | | +* V .....V..... ......V..... +* (RESUMED) : FLR_WIP : : STOP_WIP : +* :.........: :..........: +* +* For the full state machine view, see `The VF state machine`_. +*/ + +static void pf_exit_vf_resume_wip (struct xe_gt *gt,unsigned int vfid) +{ +if (pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_RESUME_WIP )) +pf_escape_vf_state (gt, vfid,XE_GT_SRIOV_STATE_RESUME_SEND_RESUME ); +} + +static void pf_enter_vf_resumed (struct xe_gt *gt,unsigned int vfid) +{ +pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_RESUMED ); +pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSED ); +pf_exit_vf_mismatch (gt, vfid); +pf_exit_vf_wip (gt, vfid); +} + +static void pf_enter_vf_resume_completed (struct xe_gt *gt,unsigned int vfid) +{ +pf_enter_vf_resumed (gt, vfid); +} + +static void pf_enter_vf_resume_failed (struct xe_gt *gt,unsigned int vfid) +{ +pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_RESUME_FAILED ); +pf_exit_vf_wip (gt, vfid); +} + +static void pf_enter_vf_resume_rejected (struct xe_gt *gt,unsigned int vfid) +{ +pf_enter_vf_mismatch (gt, vfid); +pf_enter_vf_resume_failed (gt, vfid); +} + +static void pf_enter_vf_resume_send_resume (struct xe_gt *gt,unsigned int vfid) +{ +if (!pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_RESUME_SEND_RESUME )) +pf_enter_vf_state_machine_bug (gt, vfid); + +pf_queue_vf (gt, vfid); +} + +static bool pf_exit_vf_resume_send_resume (struct xe_gt *gt,unsigned int vfid) +{ +int err; + +if (!pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_RESUME_SEND_RESUME )) +return false; + + err =pf_send_vf_resume (gt, vfid); +if (err == -EBUSY ) +pf_enter_vf_resume_send_resume (gt, vfid); +else if (err == -EIO ) +pf_enter_vf_resume_rejected (gt, vfid); +else if (err) +pf_enter_vf_resume_failed (gt, vfid); +else +pf_enter_vf_resume_completed (gt, vfid); +return true; +} + +static bool pf_enter_vf_resume_wip (struct xe_gt *gt,unsigned int vfid) +{ +if (pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_RESUME_WIP )) { +pf_enter_vf_wip (gt, vfid); +pf_enter_vf_resume_send_resume (gt, vfid); +return true; + } + +return false; }/** @@ -113,7 +700,133 @@ int xe_gt_sriov_pf_control_pause_vf(struct xe_gt *gt, unsigned int vfid)*/ int xe_gt_sriov_pf_control_resume_vf (struct xe_gt *gt,unsigned int vfid) { -return pf_send_vf_resume (gt, vfid); +int err; + +if (!pf_check_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSED )) { +xe_gt_sriov_dbg (gt,"VF%u is not paused!\n" , vfid); +return -EPERM ; + } +
Quoted 8 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c int xe_gt_sriov_pf_control_pause_vf(struct xe_gt *gt, unsigned int vfid) · line 715
Quoted 6 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +6
-0+if (!pf_enter_vf_resume_wip (gt, vfid)) { +xe_gt_sriov_dbg (gt,"VF%u resume already in progress!\n" , vfid); +return -EALREADY ; + } + + err =pf_wait_vf_wip_done (gt, vfid,2 *HZ );use define, or
pf_get_default_timeoutfor this timeout
good catch, it supposed to be pf_get_default_timeout() here
Quoted 131 lines
Quoted 131 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +121
-1+if (err) +return err; + +if (pf_expect_vf_state (gt, vfid,XE_GT_SRIOV_STATE_RESUMED )) { +xe_gt_sriov_info (gt,"VF%u resumed!\n" , vfid); +return 0 ; + } + +if (pf_check_vf_state (gt, vfid,XE_GT_SRIOV_STATE_RESUME_FAILED )) { +xe_gt_sriov_dbg (gt,"VF%u resume failed!\n" , vfid); +return -EIO ; + } + +xe_gt_sriov_dbg (gt,"VF%u resume was canceled!\n" , vfid); +return -ECANCELED ; +} + +/** +* DOC: The VF STOP state machine +* +* The VF STOP state machine looks like:: +* +* (READY,PAUSED,RESUMED)<-------<--------------------o +* | \ +* stop \ +* | \ +* ....V..............................STOP_WIP...... \ +* : \ : o +* : \ o----<----busy : | +* : \ / / : | +* : STOP_SEND_STOP--------failed--->--------o--->(STOP_FAILED) +* : / \ : | +* : acked rejected-------->--------o--->(MISMATCH) +* : / : +* :....o..............o...............o...........: +* | | | +* completed flr restart +* | | | +* V .....V..... V +* (STOPPED) : FLR_WIP : (READY) +* :.........: +* +* For the full state machine view, see `The VF state machine`_. +*/ + +static void pf_exit_vf_stop_wip (struct xe_gt *gt,unsigned int vfid) +{ +if (pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_STOP_WIP )) +pf_escape_vf_state (gt, vfid,XE_GT_SRIOV_STATE_STOP_SEND_STOP ); +} + +static void pf_enter_vf_stopped (struct xe_gt *gt,unsigned int vfid) +{ +if (!pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_STOPPED )) +pf_enter_vf_state_machine_bug (gt, vfid); + +pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_RESUMED ); +pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSED ); +pf_exit_vf_mismatch (gt, vfid); +pf_exit_vf_wip (gt, vfid); +} + +static void pf_enter_vf_stop_completed (struct xe_gt *gt,unsigned int vfid) +{ +pf_enter_vf_stopped (gt, vfid); +} + +static void pf_enter_vf_stop_failed (struct xe_gt *gt,unsigned int vfid) +{ +pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_STOP_FAILED ); +pf_exit_vf_wip (gt, vfid); +} + +static void pf_enter_vf_stop_rejected (struct xe_gt *gt,unsigned int vfid) +{ +pf_enter_vf_mismatch (gt, vfid); +pf_enter_vf_stop_failed (gt, vfid); +} + +static void pf_enter_vf_stop_send_stop (struct xe_gt *gt,unsigned int vfid) +{ +if (!pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_STOP_SEND_STOP )) +pf_enter_vf_state_machine_bug (gt, vfid); + +pf_queue_vf (gt, vfid); +} + +static bool pf_exit_vf_stop_send_stop (struct xe_gt *gt,unsigned int vfid) +{ +int err; + +if (!pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_STOP_SEND_STOP )) +return false; + + err =pf_send_vf_stop (gt, vfid); +if (err == -EBUSY ) +pf_enter_vf_stop_send_stop (gt, vfid); +else if (err == -EIO ) +pf_enter_vf_stop_rejected (gt, vfid); +else if (err) +pf_enter_vf_stop_failed (gt, vfid); +else +pf_enter_vf_stop_completed (gt, vfid); +return true; +} + +static bool pf_enter_vf_stop_wip (struct xe_gt *gt,unsigned int vfid) +{ +if (pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_STOP_WIP )) { +pf_enter_vf_wip (gt, vfid); +pf_enter_vf_stop_send_stop (gt, vfid); +return true; + } +return false; }/** @@ -127,7 +840,279 @@ int xe_gt_sriov_pf_control_resume_vf(struct xe_gt *gt, unsigned int vfid)*/ int xe_gt_sriov_pf_control_stop_vf (struct xe_gt *gt,unsigned int vfid) { -return pf_send_vf_stop (gt, vfid); +int err; + +if (pf_check_vf_state (gt, vfid,XE_GT_SRIOV_STATE_STOPPED )) { +xe_gt_sriov_dbg (gt,"VF%u was already stopped!\n" , vfid); +return -ESTALE ; + } +
Quoted 8 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c int xe_gt_sriov_pf_control_resume_vf(struct xe_gt *gt, unsigned int vfid) · line 855
Quoted 6 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +6
-0+if (!pf_enter_vf_stop_wip (gt, vfid)) { +xe_gt_sriov_dbg (gt,"VF%u stop already in progress!\n" , vfid); +return -EALREADY ; + } + + err =pf_wait_vf_wip_done (gt, vfid,2 *HZ );use define, or
pf_get_default_timeoutfor this timeout
yup
Quoted 277 lines
Quoted 277 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +262
-4+if (err) +return err; + +if (pf_expect_vf_state (gt, vfid,XE_GT_SRIOV_STATE_STOPPED )) { +xe_gt_sriov_info (gt,"VF%u stopped!\n" , vfid); +return 0 ; + } + +if (pf_check_vf_state (gt, vfid,XE_GT_SRIOV_STATE_STOP_FAILED )) { +xe_gt_sriov_dbg (gt,"VF%u stop failed!\n" , vfid); +return -EIO ; + } + +xe_gt_sriov_dbg (gt,"VF%u stop was canceled!\n" , vfid); +return -ECANCELED ; +} + +/** +* DOC: The VF FLR state machine +* +* The VF FLR state machine looks like:: +* +* (READY,PAUSED,STOPPED)<------------<--------------o +* | \ +* flr \ +* | \ +* ....V..........................FLR_WIP........... \ +* : \ : \ +* : \ o----<----busy : | +* : \ / / : | +* : FLR_SEND_START---failed----->-----------o--->(FLR_FAILED)<---o +* : | \ : | | +* : acked rejected----->-----------o--->(MISMATCH) | +* : | : ^ | +* : v : | | +* : FLR_WAIT_GUC : | | +* : | : | | +* : done : | | +* : | : | | +* : v : | | +* : FLR_GUC_DONE : | | +* : | : | | +* : FLR_RESET_CONFIG---failed--->-----------o--------+-----------o +* : | : | | +* : FLR_RESET_DATA : | | +* : | : | | +* : FLR_RESET_MMIO : | | +* : | : | | +* : | o----<----busy : | | +* : |/ / : | | +* : FLR_SEND_FINISH----failed--->-----------o--------+-----------o +* : / \ : | +* : acked rejected----->-----------o--------o +* : / : +* :....o..............................o...........: +* | | +* completed restart +* | / +* V / +* (READY)<----------<------------o +* +* For the full state machine view, see `The VF state machine`_. +*/ + +static void pf_enter_vf_flr_send_start (struct xe_gt *gt,unsigned int vfid) +{ +if (!pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_SEND_START )) +pf_enter_vf_state_machine_bug (gt, vfid); + +pf_queue_vf (gt, vfid); +} + +static void pf_enter_vf_flr_wip (struct xe_gt *gt,unsigned int vfid) +{ +if (!pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_WIP )) { +xe_gt_sriov_dbg (gt,"VF%u FLR is already in progress\n" , vfid); +return ; + } + +pf_enter_vf_wip (gt, vfid); +pf_enter_vf_flr_send_start (gt, vfid); +} + +static void pf_exit_vf_flr_wip (struct xe_gt *gt,unsigned int vfid) +{ +if (pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_WIP )) { +pf_escape_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_SEND_FINISH ); +pf_escape_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_RESET_MMIO ); +pf_escape_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_RESET_DATA ); +pf_escape_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_RESET_CONFIG ); +pf_escape_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_GUC_DONE ); +pf_escape_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_WAIT_GUC ); +pf_escape_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_SEND_START ); + } +} + +static void pf_enter_vf_flr_completed (struct xe_gt *gt,unsigned int vfid) +{ +pf_enter_vf_ready (gt, vfid); +} + +static void pf_enter_vf_flr_failed (struct xe_gt *gt,unsigned int vfid) +{ +if (pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_FAILED )) +xe_gt_sriov_notice (gt,"VF%u FLR failed!\n" , vfid); +pf_exit_vf_wip (gt, vfid); +} + +static void pf_enter_vf_flr_rejected (struct xe_gt *gt,unsigned int vfid) +{ +pf_enter_vf_mismatch (gt, vfid); +pf_enter_vf_flr_failed (gt, vfid); +} + +static void pf_enter_vf_flr_send_finish (struct xe_gt *gt,unsigned int vfid) +{ +if (!pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_SEND_FINISH )) +pf_enter_vf_state_machine_bug (gt, vfid); + +pf_queue_vf (gt, vfid); +} + +static bool pf_exit_vf_flr_send_finish (struct xe_gt *gt,unsigned int vfid) +{ +int err; + +if (!pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_SEND_FINISH )) +return false; + + err =pf_send_vf_flr_finish (gt, vfid); +if (err == -EBUSY ) +pf_enter_vf_flr_send_finish (gt, vfid); +else if (err == -EIO ) +pf_enter_vf_flr_rejected (gt, vfid); +else if (err) +pf_enter_vf_flr_failed (gt, vfid); +else +pf_enter_vf_flr_completed (gt, vfid); +return true; +} + +static void pf_enter_vf_flr_reset_mmio (struct xe_gt *gt,unsigned int vfid) +{ +if (!pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_RESET_MMIO )) +pf_enter_vf_state_machine_bug (gt, vfid); + +pf_queue_vf (gt, vfid); +} + +static bool pf_exit_vf_flr_reset_mmio (struct xe_gt *gt,unsigned int vfid) +{ +if (!pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_RESET_MMIO )) +return false; + +/* XXX: placeholder */ + +pf_enter_vf_flr_send_finish (gt, vfid); +return true; +} + +static void pf_enter_vf_flr_reset_data (struct xe_gt *gt,unsigned int vfid) +{ +if (!pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_RESET_DATA )) +pf_enter_vf_state_machine_bug (gt, vfid); + +pf_queue_vf (gt, vfid); +} + +static bool pf_exit_vf_flr_reset_data (struct xe_gt *gt,unsigned int vfid) +{ +if (!pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_RESET_DATA )) +return false; + +xe_gt_sriov_pf_service_reset (gt, vfid); +xe_gt_sriov_pf_monitor_flr (gt, vfid); + +pf_enter_vf_flr_reset_mmio (gt, vfid); +return true; +} + +static void pf_enter_vf_flr_reset_config (struct xe_gt *gt,unsigned int vfid) +{ +if (!pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_RESET_CONFIG )) +pf_enter_vf_state_machine_bug (gt, vfid); + +pf_queue_vf (gt, vfid); +} + +static bool pf_exit_vf_flr_reset_config (struct xe_gt *gt,unsigned int vfid) +{ +unsigned long timeout =pf_get_default_timeout (XE_GT_SRIOV_STATE_FLR_RESET_CONFIG ); +int err; + +if (!pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_RESET_CONFIG )) +return false; + + err =xe_gt_sriov_pf_config_sanitize (gt, vfid, timeout); +if (err) +pf_enter_vf_flr_failed (gt, vfid); +else +pf_enter_vf_flr_reset_data (gt, vfid); +return true; +} + +static void pf_enter_vf_flr_wait_guc (struct xe_gt *gt,unsigned int vfid) +{ +if (!pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_WAIT_GUC )) +pf_enter_vf_state_machine_bug (gt, vfid); +} + +static bool pf_exit_vf_flr_wait_guc (struct xe_gt *gt,unsigned int vfid) +{ +return pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_WAIT_GUC ); +} + +static bool pf_exit_vf_flr_send_start (struct xe_gt *gt,unsigned int vfid) +{ +int err; + +if (!pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_SEND_START )) +return false; + +/* GuC may actually send a FLR_DONE before we get a RESPONSE */ +pf_enter_vf_flr_wait_guc (gt, vfid); + + err =pf_send_vf_flr_start (gt, vfid); +if (err) { +/* send failed, so we shouldn't expect FLR_DONE from GuC */ +pf_exit_vf_flr_wait_guc (gt, vfid); + +if (err == -EBUSY ) +pf_enter_vf_flr_send_start (gt, vfid); +else if (err == -EIO ) +pf_enter_vf_flr_rejected (gt, vfid); +else +pf_enter_vf_flr_failed (gt, vfid); + }else { +/* +* we have already moved to WAIT_GUC, maybe even to GUC_DONE +* but since GuC didn't complain, we may clear MISMATCH +*/ +pf_exit_vf_mismatch (gt, vfid); + } + +return true; +} + +static bool pf_exit_vf_flr_guc_done (struct xe_gt *gt,unsigned int vfid) +{ +if (!pf_exit_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_GUC_DONE )) +return false; + +pf_enter_vf_flr_reset_config (gt, vfid); +return true; +} + +static void pf_enter_vf_flr_guc_done (struct xe_gt *gt,unsigned int vfid) +{ +if (pf_enter_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_GUC_DONE )) +pf_queue_vf (gt, vfid); }/** @@ -141,14 +1126,22 @@ int xe_gt_sriov_pf_control_stop_vf(struct xe_gt *gt, unsigned int vfid)*/ int xe_gt_sriov_pf_control_trigger_flr (struct xe_gt *gt,unsigned int vfid) { +unsigned long timeout =pf_get_default_timeout (XE_GT_SRIOV_STATE_FLR_WIP );int err; -/* XXX pf_send_vf_flr_start() expects ct->lock */ -mutex_lock (>->uc.guc.ct.lock); - err =pf_send_vf_flr_start (gt, vfid); -mutex_unlock (>->uc.guc.ct.lock); +pf_enter_vf_flr_wip (gt, vfid);
Quoted 7 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c int xe_gt_sriov_pf_control_stop_vf(struct xe_gt *gt, unsigned int vfid) · line 1137
Quoted 5 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +4
-1-return err; + err =pf_wait_vf_wip_done (gt, vfid, timeout); +if (err) { +xe_gt_sriov_dbg (gt,"VF%u FLR didn't finish in %u ms (%pe)\n" , + vfid,jiffies_to_msecs (timeout),ERR_PTR (err));I would increase the level of this log, dbg IMO is not enough,
will bump to xe_gt_sriov_notice() like done for some other SRIOV related errors
Quoted 57 lines
Quoted 57 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +28
-3+return err; + } + +if (!pf_expect_vf_not_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_FAILED )) +return -EIO ; + +return 0 ; }/** @@ -200,15 +1193,32 @@ static void pf_handle_vf_flr(struct xe_gt *gt, u32 vfid)if (needs_dispatch_flr (xe)) {for_each_gt (gtit, xe, gtid) -pf_send_vf_flr_start (gtit, vfid); +pf_enter_vf_flr_wip (gtit, vfid); }else { -pf_send_vf_flr_start (gt, vfid); +pf_enter_vf_flr_wip (gt, vfid); } }static void pf_handle_vf_flr_done (struct xe_gt *gt,u32 vfid) { -pf_send_vf_flr_finish (gt, vfid); +if (!pf_exit_vf_flr_wait_guc (gt, vfid)) { +xe_gt_sriov_dbg (gt,"Received out of order 'VF%u FLR done'\n" , vfid); +pf_enter_vf_mismatch (gt, vfid); +return ; + } + +pf_enter_vf_flr_guc_done (gt, vfid); +} + +static void pf_handle_vf_pause_done (struct xe_gt *gt,u32 vfid) +{ +if (!pf_exit_pause_wait_guc (gt, vfid)) { +xe_gt_sriov_dbg (gt,"Received out of order 'VF%u PAUSE done'\n" , vfid); +pf_enter_vf_mismatch (gt, vfid); +return ; + } + +pf_enter_vf_pause_guc_done (gt, vfid); }static int pf_handle_vf_event (struct xe_gt *gt,u32 vfid,u32 eventid)@@ -226,6 +1236,7 @@ static int pf_handle_vf_event(struct xe_gt *gt, u32 vfid, u32 eventid)pf_handle_vf_flr_done (gt, vfid);break ;case GUC_PF_NOTIFY_VF_PAUSE_DONE : +pf_handle_vf_pause_done (gt, vfid);break ;case GUC_PF_NOTIFY_VF_FIXUP_DONE :break ;@@ -284,3 +1295,165 @@ int xe_gt_sriov_pf_control_process_guc2pf(struct xe_gt *gt, const u32 *msg, u32
Quoted 6 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c int xe_gt_sriov_pf_control_process_guc2pf(struct xe_gt *gt, const u32 *msg, u32 · line 1299
Quoted 4 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +2
-0return vfid ?pf_handle_vf_event (gt, vfid, eventid) :pf_handle_pf_event (gt, eventid); } + +static bool pf_process_vf_machine (struct xe_gt *gt,unsigned int vfid)NIT: rename to
pf_process_vf_state_machine?
ok
Quoted 334 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c int xe_gt_sriov_pf_control_process_guc2pf(struct xe_gt *gt, const u32 *msg, u32 · line 1305
Quoted 6 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +6
-0+{ +if (pf_exit_vf_flr_send_start (gt, vfid)) +return true; + +if (pf_exit_vf_flr_send_start (gt, vfid)) +return true;Mentioned in a previous email, but as a reminder:
function called twiceQuoted 10 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +10
-0+if (pf_check_vf_state (gt, vfid,XE_GT_SRIOV_STATE_FLR_WAIT_GUC )) { +xe_gt_sriov_dbg_verbose (gt,"VF%u in %s\n" , vfid, +control_bit_to_string (XE_GT_SRIOV_STATE_FLR_WAIT_GUC )); +return false; + } + +if (pf_exit_vf_flr_guc_done (gt, vfid)) +return true; + +if (pf_exit_vf_flr_reset_config (gt, vfid))drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c int xe_gt_sriov_pf_control_process_guc2pf(struct xe_gt *gt, const u32 *msg, u32 · line 1326
Quoted 10 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +10
-0+return true; + +if (pf_exit_vf_flr_reset_data (gt, vfid)) +return true; + +if (pf_exit_vf_flr_reset_mmio (gt, vfid)) +return true; + +if (pf_exit_vf_flr_reset_mmio (gt, vfid)) +return true;function called twice
Quoted 287 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +133
-0+ +if (pf_exit_vf_flr_send_finish (gt, vfid)) +return true; + +if (pf_exit_vf_stop_send_stop (gt, vfid)) +return true; + +if (pf_exit_vf_pause_send_pause (gt, vfid)) +return true; + +if (pf_check_vf_state (gt, vfid,XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC )) { +xe_gt_sriov_dbg_verbose (gt,"VF%u in %s\n" , vfid, +control_bit_to_string (XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC )); +return true; + } + +if (pf_exit_vf_pause_guc_done (gt, vfid)) +return true; + +if (pf_exit_vf_resume_send_resume (gt, vfid)) +return true; + +return false; +} + +static unsigned int pf_control_state_index (struct xe_gt *gt, +struct xe_gt_sriov_control_state *cs) +{ + return container_of(cs, struct xe_gt_sriov_metadata, control) - gt->sriov.pf.vfs; +} + +static void pf_worker_find_work (struct xe_gt *gt) +{ +struct xe_gt_sriov_pf_control *pfc = >->sriov.pf.control; +struct xe_gt_sriov_control_state *cs; +unsigned int vfid; +bool empty; +bool more; + +spin_lock (&pfc->lock); + cs = list_first_entry_or_null(&pfc->list, struct xe_gt_sriov_control_state, link); +if (cs) +list_del_init (&cs->link); + empty =list_empty (&pfc->list); +spin_unlock (&pfc->lock); + +if (!cs) +return ; + +/* VF metadata structures are indexed by the VFID */ + vfid =pf_control_state_index (gt, cs); +xe_gt_assert (gt, vfid <=xe_gt_sriov_pf_get_totalvfs (gt)); + + more =pf_process_vf_machine (gt, vfid); +if (more) +pf_queue_vf (gt, vfid); +else if (!empty) +pf_queue_control_worker (gt); +} + +static void control_worker_func (struct work_struct *w) +{ + struct xe_gt *gt = container_of(w, struct xe_gt, sriov.pf.control.worker); + +xe_gt_assert (gt,IS_SRIOV_PF (gt_to_xe (gt))); +pf_worker_find_work (gt); +} + +static void pf_stop_worker (struct xe_gt *gt) +{ +xe_gt_assert (gt,IS_SRIOV_PF (gt_to_xe (gt))); +cancel_work_sync (>->sriov.pf.control.worker); +} + +static void control_fini_action (struct drm_device *dev,void *data) +{ +struct xe_gt *gt = data; + +pf_stop_worker (gt); +} + +/** +* xe_gt_sriov_pf_control_init() - Initialize PF's control data. +* @gt: the &xe_gt +* +* This function is for PF only. +* +* Return: 0 on success or a negative error code on failure. +*/ +int xe_gt_sriov_pf_control_init (struct xe_gt *gt) +{ +struct xe_device *xe =gt_to_xe (gt); +unsigned int n, totalvfs; + +xe_gt_assert (gt,IS_SRIOV_PF (xe)); + + totalvfs =xe_sriov_pf_get_totalvfs (xe); +for (n =0 ; n <= totalvfs; n++) { +struct xe_gt_sriov_control_state *cs =pf_pick_vf_control (gt, n); + +init_completion (&cs->done); +INIT_LIST_HEAD (&cs->link); + } + +spin_lock_init (>->sriov.pf.control.lock); +INIT_LIST_HEAD (>->sriov.pf.control.list); +INIT_WORK (>->sriov.pf.control.worker, control_worker_func); + +return drmm_add_action_or_reset (&xe->drm, control_fini_action, gt); +} + +/** +* xe_gt_sriov_pf_control_restart() - Restart SR-IOV control data after a GT reset. +* @gt: the &xe_gt +* +* Any per-VF status maintained by the PF or any ongoing VF control activity +* performed by the PF must be reset or cancelled when the GT is reset. +* +* This function is for PF only. +*/ +void xe_gt_sriov_pf_control_restart (struct xe_gt *gt) +{ +struct xe_device *xe =gt_to_xe (gt); +unsigned int n, totalvfs; + +xe_gt_assert (gt,IS_SRIOV_PF (xe)); + +pf_stop_worker (gt); + + totalvfs =xe_sriov_pf_get_totalvfs (xe); +for (n =1 ; n <= totalvfs; n++) +pf_enter_vf_ready (gt, n); +}drivers/gpu/drm/xe/xe_gt_sriov_pf_control.h +3
-0@@ -11,6 +11,9 @@struct xe_gt ; +int xe_gt_sriov_pf_control_init (struct xe_gt *gt); +void xe_gt_sriov_pf_control_restart (struct xe_gt *gt); +int xe_gt_sriov_pf_control_pause_vf (struct xe_gt *gt,unsigned int vfid);int xe_gt_sriov_pf_control_resume_vf (struct xe_gt *gt,unsigned int vfid);int xe_gt_sriov_pf_control_stop_vf (struct xe_gt *gt,unsigned int vfid);drivers/gpu/drm/xe/xe_gt_sriov_pf_control_types.h new file +107
-0@@ -0,0 +1,107 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2024 Intel Corporation +*/ + +#ifndef _XE_GT_SRIOV_PF_CONTROL_TYPES_H_ +#define _XE_GT_SRIOV_PF_CONTROL_TYPES_H_ + +#include <linux/completion.h> +#include <linux/spinlock.h> +#include <linux/workqueue_types.h> + +/** +* enum xe_gt_sriov_control_bits - Various bits used by the PF to represent a VF state +* +* @XE_GT_SRIOV_STATE_WIP: indicates that some operations are in progress. +* @XE_GT_SRIOV_STATE_FLR_WIP: indicates that a VF FLR is in progress. +* @XE_GT_SRIOV_STATE_FLR_SEND_START: indicates that the PF wants to send a FLR START command. +* @XE_GT_SRIOV_STATE_FLR_WAIT_GUC: indicates that the PF awaits for a response from the GuC. +* @XE_GT_SRIOV_STATE_FLR_GUC_DONE: indicates that the PF has received a response from the GuC. +* @XE_GT_SRIOV_STATE_FLR_RESET_CONFIG: indicates that the PF needs to clear VF's resources. +* @XE_GT_SRIOV_STATE_FLR_RESET_DATA: indicates that the PF needs to clear VF's data. +* @XE_GT_SRIOV_STATE_FLR_RESET_MMIO: indicates that the PF needs to reset VF's registers. +* @XE_GT_SRIOV_STATE_FLR_SEND_FINISH: indicates that the PF wants to send a FLR FINISH message. +* @XE_GT_SRIOV_STATE_FLR_FAILED: indicates that VF FLR sequence failed. +* @XE_GT_SRIOV_STATE_PAUSE_WIP: indicates that a VF pause operation is in progress. +* @XE_GT_SRIOV_STATE_PAUSE_SEND_PAUSE: indicates that the PF is about to send a PAUSE command. +* @XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC: indicates that the PF awaits for a response from the GuC. +* @XE_GT_SRIOV_STATE_PAUSE_GUC_DONE: indicates that the PF has received a response from the GuC. +* @XE_GT_SRIOV_STATE_PAUSE_FAILED: indicates that a VF pause operation has failed. +* @XE_GT_SRIOV_STATE_PAUSED: indicates that the VF is paused. +* @XE_GT_SRIOV_STATE_RESUME_WIP: indicates the a VF resume operation is in progress. +* @XE_GT_SRIOV_STATE_RESUME_SEND_RESUME: indicates that the PF is about to send RESUME command. +* @XE_GT_SRIOV_STATE_RESUME_FAILED: indicates that a VF resume operation has failed. +* @XE_GT_SRIOV_STATE_RESUMED: indicates that the VF was resumed. +* @XE_GT_SRIOV_STATE_STOP_WIP: indicates that a VF stop operation is in progress. +* @XE_GT_SRIOV_STATE_STOP_SEND_STOP: indicates that the PF wants to send a STOP command. +* @XE_GT_SRIOV_STATE_STOP_FAILED: indicates that the VF stop operation has failed +* @XE_GT_SRIOV_STATE_STOPPED: indicates that the VF was stopped. +* @XE_GT_SRIOV_STATE_MISMATCH: indicates that the PF has detected a VF state mismatch. +*/ +enum xe_gt_sriov_control_bits { +XE_GT_SRIOV_STATE_WIP =1 , + +XE_GT_SRIOV_STATE_FLR_WIP , +XE_GT_SRIOV_STATE_FLR_SEND_START , +XE_GT_SRIOV_STATE_FLR_WAIT_GUC , +XE_GT_SRIOV_STATE_FLR_GUC_DONE , +XE_GT_SRIOV_STATE_FLR_RESET_CONFIG , +XE_GT_SRIOV_STATE_FLR_RESET_DATA , +XE_GT_SRIOV_STATE_FLR_RESET_MMIO , +XE_GT_SRIOV_STATE_FLR_SEND_FINISH , +XE_GT_SRIOV_STATE_FLR_FAILED , + +XE_GT_SRIOV_STATE_PAUSE_WIP , +XE_GT_SRIOV_STATE_PAUSE_SEND_PAUSE , +XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC , +XE_GT_SRIOV_STATE_PAUSE_GUC_DONE , +XE_GT_SRIOV_STATE_PAUSE_FAILED , +XE_GT_SRIOV_STATE_PAUSED , + +XE_GT_SRIOV_STATE_RESUME_WIP , +XE_GT_SRIOV_STATE_RESUME_SEND_RESUME , +XE_GT_SRIOV_STATE_RESUME_FAILED , +XE_GT_SRIOV_STATE_RESUMED , + +XE_GT_SRIOV_STATE_STOP_WIP , +XE_GT_SRIOV_STATE_STOP_SEND_STOP , +XE_GT_SRIOV_STATE_STOP_FAILED , +XE_GT_SRIOV_STATE_STOPPED , + +XE_GT_SRIOV_STATE_MISMATCH =BITS_PER_LONG -1 , +}; + +/** +* struct xe_gt_sriov_control_state - GT-level per-VF control state. +* +* Used by the PF driver to maintain per-VF control data. +*/ +struct xe_gt_sriov_control_state { +/** @state: VF state bits */ +unsigned long state; + +/** @done: completion of async operations */ +struct completion done; + +/** @link: link into worker list */ +struct list_head link; +}; + +/** +* struct xe_gt_sriov_pf_control - GT-level control data. +* +* Used by the PF driver to maintain its data. +*/ +struct xe_gt_sriov_pf_control { +/** @worker: worker that executes a VF operations */ +struct work_struct worker; + +/** @list: list of VF entries that have a pending work */ +struct list_head list; + +/** @lock: protects VF pending list */ +spinlock_t lock; +}; + +#endif drivers/gpu/drm/xe/xe_gt_sriov_pf_types.h +5
-0@@ -9,6 +9,7 @@#include <linux/types.h> #include "xe_gt_sriov_pf_config_types.h" +#include "xe_gt_sriov_pf_control_types.h" #include "xe_gt_sriov_pf_monitor_types.h" #include "xe_gt_sriov_pf_policy_types.h" #include "xe_gt_sriov_pf_service_types.h" @@ -23,6 +24,9 @@ struct xe_gt_sriov_metadata {/** @monitor: per-VF monitoring data. */ struct xe_gt_sriov_monitor monitor; +/** @control: per-VF control data. */ +struct xe_gt_sriov_control_state control; +/** @version: negotiated VF/PF ABI version */ struct xe_gt_sriov_pf_service_version version; };@@ -30,12 +34,14 @@ struct xe_gt_sriov_metadata {/** * struct xe_gt_sriov_pf - GT level PF virtualization data. * @service: service data. +* @control: control data. drivers/gpu/drm/xe/xe_gt_sriov_pf_types.h struct xe_gt_sriov_metadata { · line 47
Quoted 10 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_types.h +1
-0* @policy: policy data. * @spare: PF-only provisioning configuration. * @vfs: metadata for all VFs. */ struct xe_gt_sriov_pf {struct xe_gt_sriov_pf_service service; +struct xe_gt_sriov_pf_control control;struct xe_gt_sriov_pf_policy policy;struct xe_gt_sriov_spare_config spare;struct xe_gt_sriov_metadata *vfs;Functionally, it's a good idea to introduce a state machine here. I believe that if this code is well tested, this code will be reliable and will handle all assumed states, including errors.
Quoted 4 lines
However, I have a few general comments in addition to those I left above
in the code.
While the drawings indicate a certain hierarchy of states (we have main and intermediate states), in the code this structure is flat.
idea of splitting into smaller state machines was tempting but without introducing some kind of the better FSM infrastructure it could just create even more code that would be harder to consume ...
for now, the split into hierarchy of states is, as you said, in diagrams, but also by using some common naming pattern
Quoted 4 lines
The code itself is difficult to understand (thanks to drawings it is a bit easier) but it takes some time to analyze and understand it sensibly. I am afraid that the code will be difficult to debug and an inexperienced person will have a problem with extending the functionality of the code.
I was trying to put some extra verbose diagnostic into the code to allow viewing what's happening there and I've also prepared set of tests to make sure any future changes could be easily tested offline
besides, we don't expect any big changes to the VF state machine as this what current GuC ABI defines, and if there will be new state machine then maybe we could think about preparing more solid FSM framework
Quoted 9 lines
Thanks,
PiotrQuoted 3 lines
Signature · 1 line
2.43.0
PATCH 5/12 drm/xe/tests: Allow deferred function call during KUnit test
In reply to Michal WajdeczkoFor some advanced test cases we might want to simulate external activity that will stimulate function under test. Add set of helper functions to implement such requirement. Usage example:
static void foo(struct xe_device *xe)
{
WRITE_ONCE(xe->foo, 1);
}
static void foo_test(struct kunit *test)
{
struct xe_device *xe = test->priv; xe_kunit_helper_delayed_call(test, HZ / 2, foo, xe);
KUNIT_EXPECT_EQ(test, 0, READ_ONCE(xe->foo));
schedule_timeout_uninterruptible(HZ);
KUNIT_EXPECT_EQ(test, 1, READ_ONCE(xe->foo));}
--- drivers/gpu/drm/xe/tests/xe_kunit_helpers.c | 148 ++++++++++++++++++++ drivers/gpu/drm/xe/tests/xe_kunit_helpers.h | 38 +++++ 2 files changed, 186 insertions(+)
drivers/gpu/drm/xe/tests/xe_kunit_helpers.c +148 -0
@@ -127,3 +127,151 @@ int xe_kunit_helper_xe_device_live_test_init(struct kunit *test)return 0 ; }EXPORT_SYMBOL_IF_KUNIT (xe_kunit_helper_xe_device_live_test_init); + +struct xe_kunit_call { +struct delayed_work work; +struct kunit *test; +struct { +int (*int_gt)(struct xe_gt *gt); +int (*int_gt_uint)(struct xe_gt *gt,unsigned int n); +void (*void_gt)(struct xe_gt *gt); +void (*void_gt_uint)(struct xe_gt *gt,unsigned int n); +void (*void_xe)(struct xe_device *xe); + } func; +struct { +struct xe_device *xe; +struct xe_gt *gt; +unsigned int n; + } args; +}; + +static void call_work_func (struct work_struct *work) +{ +struct xe_kunit_call *call =container_of (work,typeof (*call), work.work); + +if (call->func.void_xe) { +kunit_info (call->test,"calling %ps(xe)\n" , call->func.void_xe); + call->func.void_xe (call->args.xe); +kunit_info (call->test,"%ps(xe) completed\n" , call->func.void_xe); + }else if (call->func.void_gt) { +kunit_info (call->test,"%ps(gt)\n" , call->func.void_gt); + call->func.void_gt (call->args.gt); +kunit_info (call->test,"%ps(gt) completed\n" , call->func.void_gt); + }else if (call->func.int_gt_uint) { +int ret; + +kunit_info (call->test,"calling %ps(gt,%u)\n" , + call->func.int_gt_uint, call->args.n); + ret = call->func.int_gt_uint (call->args.gt, call->args.n); +if (ret <0 ) { +kunit_info (call->test,"%ps(gt,%u) reported error %pe\n" , + call->func.int_gt_uint, call->args.n,ERR_PTR (ret)); + }else { +kunit_info (call->test,"%ps(gt,%u) returned %d\n" , + call->func.int_gt_uint, call->args.n, ret); + } + } +} + +static struct xe_kunit_call *prepare_call (struct kunit *test) +{ +struct xe_kunit_call *call; + + call =kunit_kzalloc (test,sizeof (*call),GFP_KERNEL ); +KUNIT_ASSERT_NOT_NULL (test, call); + +INIT_DELAYED_WORK (&call->work, call_work_func); + call->test = test; + +return call; +} + +KUNIT_DEFINE_ACTION_WRAPPER(cancel_call, cancel_delayed_work_sync, struct delayed_work *); + +static void queue_call (struct kunit *test,struct xe_kunit_call *call,unsigned long delay) +{ +queue_delayed_work (system_wq, &call->work, delay); +KUNIT_ASSERT_EQ (test,0 ,kunit_add_action_or_reset (test, cancel_call, &call->work)); +} + +/** +* xe_kunit_helper_delayed_call_void_xe_device - Queue a function call during KUnit test +* @test: the &kunit test case +* @delay: number of jiffies to wait before queueing +* @func: the &xe_device function to call +* @xe: the &xe_device argument +* +* This function uses KUNIT_ASSERT to detect any failures. +*/ +void xe_kunit_helper_delayed_call_void_xe_device (struct kunit *test, +unsigned long delay, +void (*func)(struct xe_device *xe), +struct xe_device *xe) +{ +struct xe_kunit_call *call =prepare_call (test); + +KUNIT_ASSERT_NOT_NULL (test, func); +KUNIT_ASSERT_NOT_NULL (test, xe); + + call->func.void_xe = func; + call->args.xe = xe; + +return queue_call (test, call, delay); +} +EXPORT_SYMBOL_IF_KUNIT (xe_kunit_helper_delayed_call_void_xe_device); + +/** +* xe_kunit_helper_delayed_call_void_xe_gt - Queue a function call during KUnit test +* @test: the &kunit test case +* @delay: number of jiffies to wait before queueing +* @func: the &xe_gt function to call +* @gt: the &xe_gt function argument +* +* This function uses KUNIT_ASSERT to detect any failures. +*/ +void xe_kunit_helper_delayed_call_void_xe_gt (struct kunit *test, +unsigned long delay, +void (*func)(struct xe_gt *gt), +struct xe_gt *gt) +{ +struct xe_kunit_call *call =prepare_call (test); + +KUNIT_ASSERT_NOT_NULL (test, func); +KUNIT_ASSERT_NOT_NULL (test, gt); + + call->func.void_gt = func; + call->args.gt = gt; + +return queue_call (test, call, delay); +} +EXPORT_SYMBOL_IF_KUNIT (xe_kunit_helper_delayed_call_void_xe_gt); + +/** +* xe_kunit_helper_delayed_call_int_xe_gt_uint - Queue a function call during KUnit test +* @test: the &kunit test case +* @delay: number of jiffies to wait before queueing +* @func: the &xe_gt function to call +* @gt: the &xe_gt function argument +* @n: the function argument +* +* This function uses KUNIT_ASSERT to detect any failures. +*/ +void xe_kunit_helper_delayed_call_int_xe_gt_uint (struct kunit *test, +unsigned long delay, +int (*func)(struct xe_gt *gt, +unsigned int vfid), +struct xe_gt *gt, +unsigned int n) +{ +struct xe_kunit_call *call =prepare_call (test); + +KUNIT_ASSERT_NOT_NULL (test, func); +KUNIT_ASSERT_NOT_NULL (test, gt); + + call->func.int_gt_uint = func; + call->args.gt = gt; + call->args.n = n; + +return queue_call (test, call, delay); +} +EXPORT_SYMBOL_IF_KUNIT (xe_kunit_helper_delayed_call_int_xe_gt_uint);
drivers/gpu/drm/xe/tests/xe_kunit_helpers.h +38 -0
@@ -9,6 +9,7 @@struct device ;struct kunit ;struct xe_device ; +struct xe_gt ;struct xe_device *xe_kunit_helper_alloc_xe_device (struct kunit *test,struct device *dev);
@@ -16,4 +17,41 @@ int xe_kunit_helper_xe_device_test_init(struct kunit *test);int xe_kunit_helper_xe_device_live_test_init (struct kunit *test); +void xe_kunit_helper_delayed_call_void_xe_device (struct kunit *test, +unsigned long delay, +void (*func)(struct xe_device *xe), +struct xe_device *xe); + +void xe_kunit_helper_delayed_call_void_xe_gt (struct kunit *test, +unsigned long delay, +void (*func)(struct xe_gt *gt), +struct xe_gt *gt); + +void xe_kunit_helper_delayed_call_int_xe_gt_uint (struct kunit *test, +unsigned long delay, +int (*func)(struct xe_gt *gt, +unsigned int vfid), +struct xe_gt *gt, +unsigned int n); + +/** +* xe_kunit_helper_delayed_call - Queue a function call during KUnit test +* @test: the &kunit test case +* @delay: number of jiffies to wait before queueing +* @func: the &xe_device or &xe_gt function to call +* @args: the &xe_device or &xe_gt and other function arguments +* +* This is a helper macro that compiles into dedicated function call based on +* the provided argument types. +*/ +#define xe_kunit_helper_delayed_call(test, delay, func, args...) \ + _Generic(func, \ + void (*)(struct xe_device *) : \ + xe_kunit_helper_delayed_call_void_xe_device, \ + void (*)(struct xe_gt *) : \ + xe_kunit_helper_delayed_call_void_xe_gt, \ + int (*)(struct xe_gt *, unsigned int) : \ + xe_kunit_helper_delayed_call_int_xe_gt_uint \ + )(test, delay, func, args) +#endif
Signature · 1 line
2.43.0
Re: [PATCH 05/12] drm/xe/tests: Allow deferred function call during KUnit test
Quoted 35 lines · Michal Wajdeczko
For some advanced test cases we might want to simulate external activity that will stimulate function under test. Add set of helper functions to implement such requirement. Usage example:
static void
foo(struct xe_device *xe){ WRITE_ONCE(xe->foo, 1);}
static void
foo_test(struct kunit *test){ struct xe_device *xe = test->priv; xe_kunit_helper_delayed_call(test, HZ / 2, foo, xe); KUNIT_EXPECT_EQ(test, 0, READ_ONCE(xe->foo)); schedule_timeout_uninterruptible(HZ); KUNIT_EXPECT_EQ(test, 1, READ_ONCE(xe->foo));}
Signed-off-by Michal Wajdeczko <[email protected]>Cc Lucas De Marchi <[email protected]>---
drivers/gpu/drm/xe/tests/xe_kunit_helpers.c| 148 ++++++++++++++++++++drivers/gpu/drm/xe/tests/xe_kunit_helpers.h| 38 +++++2 files changed, 186 insertions(+)drivers/gpu/drm/xe/tests/xe_kunit_helpers.c +0
-0@@ -127,3 +127,151 @@ int xe_kunit_helper_xe_device_live_test_init(struct kunit *test)return 0 ; }EXPORT_SYMBOL_IF_KUNIT (xe_kunit_helper_xe_device_live_test_init);
drivers/gpu/drm/xe/tests/xe_kunit_helpers.c int xe_kunit_helper_xe_device_live_test_init(struct kunit *test) · line 139
Quoted 10 lines
drivers/gpu/drm/xe/tests/xe_kunit_helpers.c +10
-0+ +struct xe_kunit_call { +struct delayed_work work; +struct kunit *test; +struct { +int (*int_gt)(struct xe_gt *gt); +int (*int_gt_uint)(struct xe_gt *gt,unsigned int n); +void (*void_gt)(struct xe_gt *gt); +void (*void_gt_uint)(struct xe_gt *gt,unsigned int n); +void (*void_xe)(struct xe_device *xe);
I think the only reason why you're adding this in xe is because you are using xe-specific types. This could rather be done generically by always using int delayed_func(void *data). Then you can simply add it to kunit and get it reviewed there.
Also thinking that the example you added in the commit message is likely suggesting the wrong type of test, that a) sleep too much and b) tend to be noisy
Lucas De Marchi
Quoted 195 lines
drivers/gpu/drm/xe/tests/xe_kunit_helpers.c +138
-0+ } func; +struct { +struct xe_device *xe; +struct xe_gt *gt; +unsigned int n; + } args; +}; + +static void call_work_func (struct work_struct *work) +{ +struct xe_kunit_call *call =container_of (work,typeof (*call), work.work); + +if (call->func.void_xe) { +kunit_info (call->test,"calling %ps(xe)\n" , call->func.void_xe); + call->func.void_xe (call->args.xe); +kunit_info (call->test,"%ps(xe) completed\n" , call->func.void_xe); + }else if (call->func.void_gt) { +kunit_info (call->test,"%ps(gt)\n" , call->func.void_gt); + call->func.void_gt (call->args.gt); +kunit_info (call->test,"%ps(gt) completed\n" , call->func.void_gt); + }else if (call->func.int_gt_uint) { +int ret; + +kunit_info (call->test,"calling %ps(gt,%u)\n" , + call->func.int_gt_uint, call->args.n); + ret = call->func.int_gt_uint (call->args.gt, call->args.n); +if (ret <0 ) { +kunit_info (call->test,"%ps(gt,%u) reported error %pe\n" , + call->func.int_gt_uint, call->args.n,ERR_PTR (ret)); + }else { +kunit_info (call->test,"%ps(gt,%u) returned %d\n" , + call->func.int_gt_uint, call->args.n, ret); + } + } +} + +static struct xe_kunit_call *prepare_call (struct kunit *test) +{ +struct xe_kunit_call *call; + + call =kunit_kzalloc (test,sizeof (*call),GFP_KERNEL ); +KUNIT_ASSERT_NOT_NULL (test, call); + +INIT_DELAYED_WORK (&call->work, call_work_func); + call->test = test; + +return call; +} + +KUNIT_DEFINE_ACTION_WRAPPER(cancel_call, cancel_delayed_work_sync, struct delayed_work *); + +static void queue_call (struct kunit *test,struct xe_kunit_call *call,unsigned long delay) +{ +queue_delayed_work (system_wq, &call->work, delay); +KUNIT_ASSERT_EQ (test,0 ,kunit_add_action_or_reset (test, cancel_call, &call->work)); +} + +/** +* xe_kunit_helper_delayed_call_void_xe_device - Queue a function call during KUnit test +* @test: the &kunit test case +* @delay: number of jiffies to wait before queueing +* @func: the &xe_device function to call +* @xe: the &xe_device argument +* +* This function uses KUNIT_ASSERT to detect any failures. +*/ +void xe_kunit_helper_delayed_call_void_xe_device (struct kunit *test, +unsigned long delay, +void (*func)(struct xe_device *xe), +struct xe_device *xe) +{ +struct xe_kunit_call *call =prepare_call (test); + +KUNIT_ASSERT_NOT_NULL (test, func); +KUNIT_ASSERT_NOT_NULL (test, xe); + + call->func.void_xe = func; + call->args.xe = xe; + +return queue_call (test, call, delay); +} +EXPORT_SYMBOL_IF_KUNIT (xe_kunit_helper_delayed_call_void_xe_device); + +/** +* xe_kunit_helper_delayed_call_void_xe_gt - Queue a function call during KUnit test +* @test: the &kunit test case +* @delay: number of jiffies to wait before queueing +* @func: the &xe_gt function to call +* @gt: the &xe_gt function argument +* +* This function uses KUNIT_ASSERT to detect any failures. +*/ +void xe_kunit_helper_delayed_call_void_xe_gt (struct kunit *test, +unsigned long delay, +void (*func)(struct xe_gt *gt), +struct xe_gt *gt) +{ +struct xe_kunit_call *call =prepare_call (test); + +KUNIT_ASSERT_NOT_NULL (test, func); +KUNIT_ASSERT_NOT_NULL (test, gt); + + call->func.void_gt = func; + call->args.gt = gt; + +return queue_call (test, call, delay); +} +EXPORT_SYMBOL_IF_KUNIT (xe_kunit_helper_delayed_call_void_xe_gt); + +/** +* xe_kunit_helper_delayed_call_int_xe_gt_uint - Queue a function call during KUnit test +* @test: the &kunit test case +* @delay: number of jiffies to wait before queueing +* @func: the &xe_gt function to call +* @gt: the &xe_gt function argument +* @n: the function argument +* +* This function uses KUNIT_ASSERT to detect any failures. +*/ +void xe_kunit_helper_delayed_call_int_xe_gt_uint (struct kunit *test, +unsigned long delay, +int (*func)(struct xe_gt *gt, +unsigned int vfid), +struct xe_gt *gt, +unsigned int n) +{ +struct xe_kunit_call *call =prepare_call (test); + +KUNIT_ASSERT_NOT_NULL (test, func); +KUNIT_ASSERT_NOT_NULL (test, gt); + + call->func.int_gt_uint = func; + call->args.gt = gt; + call->args.n = n; + +return queue_call (test, call, delay); +} +EXPORT_SYMBOL_IF_KUNIT (xe_kunit_helper_delayed_call_int_xe_gt_uint);drivers/gpu/drm/xe/tests/xe_kunit_helpers.h +38
-0@@ -9,6 +9,7 @@struct device ;struct kunit ;struct xe_device ; +struct xe_gt ;struct xe_device *xe_kunit_helper_alloc_xe_device (struct kunit *test,struct device *dev);@@ -16,4 +17,41 @@ int xe_kunit_helper_xe_device_test_init(struct kunit *test);int xe_kunit_helper_xe_device_live_test_init (struct kunit *test); +void xe_kunit_helper_delayed_call_void_xe_device (struct kunit *test, +unsigned long delay, +void (*func)(struct xe_device *xe), +struct xe_device *xe); + +void xe_kunit_helper_delayed_call_void_xe_gt (struct kunit *test, +unsigned long delay, +void (*func)(struct xe_gt *gt), +struct xe_gt *gt); + +void xe_kunit_helper_delayed_call_int_xe_gt_uint (struct kunit *test, +unsigned long delay, +int (*func)(struct xe_gt *gt, +unsigned int vfid), +struct xe_gt *gt, +unsigned int n); + +/** +* xe_kunit_helper_delayed_call - Queue a function call during KUnit test +* @test: the &kunit test case +* @delay: number of jiffies to wait before queueing +* @func: the &xe_device or &xe_gt function to call +* @args: the &xe_device or &xe_gt and other function arguments +* +* This is a helper macro that compiles into dedicated function call based on +* the provided argument types. +*/ +#define xe_kunit_helper_delayed_call(test, delay, func, args...) \ + _Generic(func, \ + void (*)(struct xe_device *) : \ + xe_kunit_helper_delayed_call_void_xe_device, \ + void (*)(struct xe_gt *) : \ + xe_kunit_helper_delayed_call_void_xe_gt, \ + int (*)(struct xe_gt *, unsigned int) : \ + xe_kunit_helper_delayed_call_int_xe_gt_uint \ + )(test, delay, func, args) +#endif Signature · 1 line
2.43.0
Re: [PATCH 05/12] drm/xe/tests: Allow deferred function call during KUnit test
Quoted 45 lines · Lucas De Marchi
Quoted 44 lines · Michal Wajdeczko
For some advanced test cases we might want to simulate external activity that will stimulate function under test. Add set of helper functions to implement such requirement. Usage example:
static void
foo(struct xe_device *xe)
{
WRITE_ONCE(xe->foo, 1);
}static void
foo_test(struct kunit *test)
{
structxe_device*xe =test->priv;
xe_kunit_helper_delayed_call(test, HZ / 2, foo, xe);
KUNIT_EXPECT_EQ(test, 0, READ_ONCE(xe->foo));schedule_timeout_uninterruptible(HZ);KUNIT_EXPECT_EQ(test, 1, READ_ONCE(xe->foo)); }Signed-off-by Michal Wajdeczko <[email protected]>Cc Lucas De Marchi <[email protected]>---
drivers/gpu/drm/xe/tests/xe_kunit_helpers.c| 148 ++++++++++++++++++++drivers/gpu/drm/xe/tests/xe_kunit_helpers.h| 38 +++++2 files changed, 186 insertions(+)drivers/gpu/drm/xe/tests/xe_kunit_helpers.c +0
-0@@ -127,3 +127,151 @@ int xe_kunit_helper_xe_device_live_test_init(struct kunit *test) return 0; }
EXPORT_SYMBOL_IF_KUNIT(xe_kunit_helper_xe_device_live_test_init);drivers/gpu/drm/xe/tests/xe_kunit_helpers.c +7
-0+ +struct xe_kunit_call { + struct delayed_work work; + struct kunit *test; + struct { + int (*int_gt)(struct xe_gt *gt); + int (*int_gt_uint)(struct xe_gt *gt, unsigned int n);
Quoted 8 lines
Quoted 3 lines
+ void (*void_gt)(struct
xe_gt*gt);
+ void (*void_gt_uint)(structxe_gt*gt, unsigned int n); + void (*void_xe)(structxe_device*xe);I think the only reason why you're adding this in xe is because you are using xe-specific types. This could rather be done generically by always using int
delayed_func(void *data). Then you can simply add it to kunit and get it reviewed there.
while some generic functionality could be always extracted and moved to the kunit, for easier use in Xe tests likely we will still need some wrappers with xe-specific types, so do we really always need to start with trying enhance generic kunit first and then wait for acceptance until we can use such extension in our test code?
IMO this could be in parallel, so in kunit review we can point how this is already being used..
anyway, will try to split that feature into 'generic' and 'xe'
Quoted 4 lines
Also thinking that the example you added in the commit message is likely suggesting the wrong type of test, that a) sleep too much and b) tend to be noisy
only tests longer than 2s are considered SLOW ;)
and HZ was just picked to have an example small
and you will not see any noise if test PASSES
Quoted 211 lines
Lucas De Marchi
Quoted 208 lines
+ } func;
+ struct {
+ structxe_device*xe;
+ structxe_gt*gt;
+ unsigned int n;
+ } args;drivers/gpu/drm/xe/tests/xe_kunit_helpers.c +5
-0+}; + +static void call_work_func (struct work_struct *work) +{ + struct xe_kunit_call *call = container_of(work, typeof(*call),work.work);
+
+ if (call->func.void_xe) {
+kunit_info(call->test, "calling %ps(xe)\n", call->func.void_xe); +call->func.void_xe(call->args.xe);
+kunit_info(call->test, "%ps(xe) completed\n", call->func.void_xe);
+ } else if (call->func.void_gt) {
+kunit_info(call->test, "%ps(gt)\n", call->func.void_gt); +call->func.void_gt(call->args.gt);
+kunit_info(call->test, "%ps(gt) completed\n", call->func.void_gt);
+ } else if (call->func.int_gt_uint) {
+ int ret;drivers/gpu/drm/xe/tests/xe_kunit_helpers.c +28
-0+ + kunit_info(call->test, "calling %ps(gt,%u)\n", + call->func.int_gt_uint, call->args.n); + ret = call->func.int_gt_uint(call->args.gt, call->args.n); + if (ret < 0) { + kunit_info(call->test, "%ps(gt,%u) reported error %pe\n", + call->func.int_gt_uint, call->args.n, ERR_PTR(ret)); + } else { + kunit_info(call->test, "%ps(gt,%u) returned %d\n", + call->func.int_gt_uint, call->args.n, ret); + } + } +} + +static struct xe_kunit_call *prepare_call (struct kunit *test) +{ + struct xe_kunit_call *call; + + call = kunit_kzalloc(test, sizeof(*call), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, call); + + INIT_DELAYED_WORK(&call->work, call_work_func); + call->test = test; + + return call; +} + +KUNIT_DEFINE_ACTION_WRAPPER(cancel_call, cancel_delayed_work_sync,struct
delayed_work*);drivers/gpu/drm/xe/tests/xe_kunit_helpers.c +2
-0+ +static void queue_call(struct kunit *test, struct xe_kunit_call*call, unsigned long delay)
+{
+queue_delayed_work(system_wq, &call->work, delay); +KUNIT_ASSERT_EQ(test, 0, kunit_add_action_or_reset(test, cancel_call, &call->work));drivers/gpu/drm/xe/tests/xe_kunit_helpers.c +4
-0+} + +/** +* xe_kunit_helper_delayed_call_void_xe_device - Queue a function call during KUnit test
+ * @test: the &kunit test case
+ * @delay: number of jiffies to wait before queueing
+ * @func: the&xe_devicefunction to call
+ * @xe: the&xe_deviceargument
+ *
+ * This function usesKUNIT_ASSERTto detect any failures.
+ */drivers/gpu/drm/xe/tests/xe_kunit_helpers.c +19
-0+void xe_kunit_helper_delayed_call_void_xe_device (struct kunit *test, + unsigned long delay, + void (*func)(struct xe_device *xe), + struct xe_device *xe) +{ + struct xe_kunit_call *call = prepare_call(test); + + KUNIT_ASSERT_NOT_NULL(test, func); + KUNIT_ASSERT_NOT_NULL(test, xe); + + call->func.void_xe = func; + call->args.xe = xe; + + return queue_call(test, call, delay); +} +EXPORT_SYMBOL_IF_KUNIT (xe_kunit_helper_delayed_call_void_xe_device); + +/** +* xe_kunit_helper_delayed_call_void_xe_gt - Queue a function call during KUnit test
+ * @test: the &kunit test case
+ * @delay: number of jiffies to wait before queueing
+ * @func: the&xe_gtfunction to call
+ * @gt: the&xe_gtfunction argument
+ *
+ * This function usesKUNIT_ASSERTto detect any failures.
+ */drivers/gpu/drm/xe/tests/xe_kunit_helpers.c +19
-0+void xe_kunit_helper_delayed_call_void_xe_gt (struct kunit *test, + unsigned long delay, + void (*func)(struct xe_gt *gt), + struct xe_gt *gt) +{ + struct xe_kunit_call *call = prepare_call(test); + + KUNIT_ASSERT_NOT_NULL(test, func); + KUNIT_ASSERT_NOT_NULL(test, gt); + + call->func.void_gt = func; + call->args.gt = gt; + + return queue_call(test, call, delay); +} +EXPORT_SYMBOL_IF_KUNIT (xe_kunit_helper_delayed_call_void_xe_gt); + +/** +* xe_kunit_helper_delayed_call_int_xe_gt_uint - Queue a function call during KUnit test
+ * @test: the &kunit test case
+ * @delay: number of jiffies to wait before queueing
+ * @func: the&xe_gtfunction to call
+ * @gt: the&xe_gtfunction argument
+ * @n: the function argument
+ *
+ * This function usesKUNIT_ASSERTto detect any failures.
+ */drivers/gpu/drm/xe/tests/xe_kunit_helpers.c +19
-0+void xe_kunit_helper_delayed_call_int_xe_gt_uint (struct kunit *test, + unsigned long delay, + int (*func)(struct xe_gt *gt, + unsigned int vfid), + struct xe_gt *gt, + unsigned int n) +{ + struct xe_kunit_call *call = prepare_call(test); + + KUNIT_ASSERT_NOT_NULL(test, func); + KUNIT_ASSERT_NOT_NULL(test, gt); + + call->func.int_gt_uint = func; + call->args.gt = gt; + call->args.n = n; + + return queue_call(test, call, delay); +} +EXPORT_SYMBOL_IF_KUNIT (xe_kunit_helper_delayed_call_int_xe_gt_uint);drivers/gpu/drm/xe/tests/xe_kunit_helpers.h +20
-0@@ -9,6 +9,7 @@struct device ;struct kunit ;struct xe_device ; +struct xe_gt ;struct xe_device *xe_kunit_helper_alloc_xe_device (struct kunit *test, struct device *dev);@@ -16,4 +17,41 @@ int xe_kunit_helper_xe_device_test_init(struct kunit *test);int xe_kunit_helper_xe_device_live_test_init (struct kunit *test); +void xe_kunit_helper_delayed_call_void_xe_device (struct kunit *test, + unsigned long delay, + void (*func)(struct xe_device *xe), + struct xe_device *xe); + +void xe_kunit_helper_delayed_call_void_xe_gt (struct kunit *test, + unsigned long delay, + void (*func)(struct xe_gt *gt), + struct xe_gt *gt); + +void xe_kunit_helper_delayed_call_int_xe_gt_uint (struct kunit *test, + unsigned long delay, + int (*func)(struct xe_gt *gt, + unsigned int vfid), + struct xe_gt *gt, + unsigned int n); + +/** +* xe_kunit_helper_delayed_call - Queue a function call during KUnit test
+ * @test: the &kunit test case
+ * @delay: number of jiffies to wait before queueing
+ * @func: the&xe_deviceor&xe_gtfunction to call
+ * @args: the&xe_deviceor&xe_gtand other function arguments
+ *
+ * This is a helper macro that compiles into dedicated function call based on
+ * the provided argument types.
+ */drivers/gpu/drm/xe/tests/xe_kunit_helpers.h +10
-0+#define xe_kunit_helper_delayed_call(test, delay, func, args...) \ + _Generic(func, \ + void (*)(struct xe_device *) : \ + xe_kunit_helper_delayed_call_void_xe_device, \ + void (*)(struct xe_gt *) : \ + xe_kunit_helper_delayed_call_void_xe_gt, \ + int (*)(struct xe_gt *, unsigned int) : \ + xe_kunit_helper_delayed_call_int_xe_gt_uint \ + )(test, delay, func, args) +#endif
--
2.43.0
Re: [PATCH 05/12] drm/xe/tests: Allow deferred function call during KUnit test
Quoted 73 lines · Michal Wajdeczko
Quoted 45 lines · Lucas De Marchi
Quoted 44 lines · Michal Wajdeczko
For some advanced test cases we might want to simulate external activity that will stimulate function under test. Add set of helper functions to implement such requirement. Usage example:
static void
foo(struct xe_device *xe)
{
WRITE_ONCE(xe->foo, 1);
}static void
foo_test(struct kunit *test)
{
structxe_device*xe =test->priv;
xe_kunit_helper_delayed_call(test, HZ / 2, foo, xe);
KUNIT_EXPECT_EQ(test, 0, READ_ONCE(xe->foo));schedule_timeout_uninterruptible(HZ);KUNIT_EXPECT_EQ(test, 1, READ_ONCE(xe->foo)); }Signed-off-by Michal Wajdeczko <[email protected]>Cc Lucas De Marchi <[email protected]>---
drivers/gpu/drm/xe/tests/xe_kunit_helpers.c| 148 ++++++++++++++++++++drivers/gpu/drm/xe/tests/xe_kunit_helpers.h| 38 +++++2 files changed, 186 insertions(+)drivers/gpu/drm/xe/tests/xe_kunit_helpers.c +0
-0@@ -127,3 +127,151 @@ int xe_kunit_helper_xe_device_live_test_init(struct kunit *test) return 0; }
EXPORT_SYMBOL_IF_KUNIT(xe_kunit_helper_xe_device_live_test_init);drivers/gpu/drm/xe/tests/xe_kunit_helpers.c +7
-0+ +struct xe_kunit_call { + struct delayed_work work; + struct kunit *test; + struct { + int (*int_gt)(struct xe_gt *gt); + int (*int_gt_uint)(struct xe_gt *gt, unsigned int n);Quoted 8 lines
Quoted 3 lines
+ void (*void_gt)(struct
xe_gt*gt);
+ void (*void_gt_uint)(structxe_gt*gt, unsigned int n); + void (*void_xe)(structxe_device*xe);I think the only reason why you're adding this in xe is because you are using xe-specific types. This could rather be done generically by always using int
delayed_func(void *data). Then you can simply add it to kunit and get it reviewed there.while some generic functionality could be always extracted and moved to the kunit, for easier use in Xe tests likely we will still need some wrappers with xe-specific types, so do we really always need to start with trying enhance generic kunit first and then wait for acceptance until we can use such extension in our test code?
IMO this could be in parallel, so in kunit review we can point how this is already being used..
anyway, will try to split that feature into 'generic' and 'xe'
Quoted 4 lines
Also thinking that the example you added in the commit message is likely suggesting the wrong type of test, that a) sleep too much and b) tend to be noisy
Quoted 5 lines
only tests longer than 2s are considered SLOW ;)
and HZ was just picked to have an example small
and you will not see any noise if test PASSES
any test we add that follows the pattern "fire something to do X, sleep, assert it did X" falls in one of the 2 categories: either sleep too much (in this example you're using 2x) and/or created noise because the time slept wasn't sufficient.
Lucas De Marchi
Quoted 212 lines
Quoted 212 lines
Lucas De Marchi
Quoted 208 lines
+ } func;
+ struct {
+ structxe_device*xe;
+ structxe_gt*gt;
+ unsigned int n;
+ } args;drivers/gpu/drm/xe/tests/xe_kunit_helpers.c +5
-0+}; + +static void call_work_func (struct work_struct *work) +{ + struct xe_kunit_call *call = container_of(work, typeof(*call),work.work);
+
+ if (call->func.void_xe) {
+kunit_info(call->test, "calling %ps(xe)\n", call->func.void_xe); +call->func.void_xe(call->args.xe);
+kunit_info(call->test, "%ps(xe) completed\n", call->func.void_xe);
+ } else if (call->func.void_gt) {
+kunit_info(call->test, "%ps(gt)\n", call->func.void_gt); +call->func.void_gt(call->args.gt);
+kunit_info(call->test, "%ps(gt) completed\n", call->func.void_gt);
+ } else if (call->func.int_gt_uint) {
+ int ret;drivers/gpu/drm/xe/tests/xe_kunit_helpers.c +28
-0+ + kunit_info(call->test, "calling %ps(gt,%u)\n", + call->func.int_gt_uint, call->args.n); + ret = call->func.int_gt_uint(call->args.gt, call->args.n); + if (ret < 0) { + kunit_info(call->test, "%ps(gt,%u) reported error %pe\n", + call->func.int_gt_uint, call->args.n, ERR_PTR(ret)); + } else { + kunit_info(call->test, "%ps(gt,%u) returned %d\n", + call->func.int_gt_uint, call->args.n, ret); + } + } +} + +static struct xe_kunit_call *prepare_call (struct kunit *test) +{ + struct xe_kunit_call *call; + + call = kunit_kzalloc(test, sizeof(*call), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, call); + + INIT_DELAYED_WORK(&call->work, call_work_func); + call->test = test; + + return call; +} + +KUNIT_DEFINE_ACTION_WRAPPER(cancel_call, cancel_delayed_work_sync,struct
delayed_work*);drivers/gpu/drm/xe/tests/xe_kunit_helpers.c +2
-0+ +static void queue_call(struct kunit *test, struct xe_kunit_call*call, unsigned long delay)
+{
+queue_delayed_work(system_wq, &call->work, delay); +KUNIT_ASSERT_EQ(test, 0, kunit_add_action_or_reset(test, cancel_call, &call->work));drivers/gpu/drm/xe/tests/xe_kunit_helpers.c +4
-0+} + +/** +* xe_kunit_helper_delayed_call_void_xe_device - Queue a function call during KUnit test
+ * @test: the &kunit test case
+ * @delay: number of jiffies to wait before queueing
+ * @func: the&xe_devicefunction to call
+ * @xe: the&xe_deviceargument
+ *
+ * This function usesKUNIT_ASSERTto detect any failures.
+ */drivers/gpu/drm/xe/tests/xe_kunit_helpers.c +19
-0+void xe_kunit_helper_delayed_call_void_xe_device (struct kunit *test, + unsigned long delay, + void (*func)(struct xe_device *xe), + struct xe_device *xe) +{ + struct xe_kunit_call *call = prepare_call(test); + + KUNIT_ASSERT_NOT_NULL(test, func); + KUNIT_ASSERT_NOT_NULL(test, xe); + + call->func.void_xe = func; + call->args.xe = xe; + + return queue_call(test, call, delay); +} +EXPORT_SYMBOL_IF_KUNIT (xe_kunit_helper_delayed_call_void_xe_device); + +/** +* xe_kunit_helper_delayed_call_void_xe_gt - Queue a function call during KUnit test
+ * @test: the &kunit test case
+ * @delay: number of jiffies to wait before queueing
+ * @func: the&xe_gtfunction to call
+ * @gt: the&xe_gtfunction argument
+ *
+ * This function usesKUNIT_ASSERTto detect any failures.
+ */drivers/gpu/drm/xe/tests/xe_kunit_helpers.c +19
-0+void xe_kunit_helper_delayed_call_void_xe_gt (struct kunit *test, + unsigned long delay, + void (*func)(struct xe_gt *gt), + struct xe_gt *gt) +{ + struct xe_kunit_call *call = prepare_call(test); + + KUNIT_ASSERT_NOT_NULL(test, func); + KUNIT_ASSERT_NOT_NULL(test, gt); + + call->func.void_gt = func; + call->args.gt = gt; + + return queue_call(test, call, delay); +} +EXPORT_SYMBOL_IF_KUNIT (xe_kunit_helper_delayed_call_void_xe_gt); + +/** +* xe_kunit_helper_delayed_call_int_xe_gt_uint - Queue a function call during KUnit test
+ * @test: the &kunit test case
+ * @delay: number of jiffies to wait before queueing
+ * @func: the&xe_gtfunction to call
+ * @gt: the&xe_gtfunction argument
+ * @n: the function argument
+ *
+ * This function usesKUNIT_ASSERTto detect any failures.
+ */drivers/gpu/drm/xe/tests/xe_kunit_helpers.c +19
-0+void xe_kunit_helper_delayed_call_int_xe_gt_uint (struct kunit *test, + unsigned long delay, + int (*func)(struct xe_gt *gt, + unsigned int vfid), + struct xe_gt *gt, + unsigned int n) +{ + struct xe_kunit_call *call = prepare_call(test); + + KUNIT_ASSERT_NOT_NULL(test, func); + KUNIT_ASSERT_NOT_NULL(test, gt); + + call->func.int_gt_uint = func; + call->args.gt = gt; + call->args.n = n; + + return queue_call(test, call, delay); +} +EXPORT_SYMBOL_IF_KUNIT (xe_kunit_helper_delayed_call_int_xe_gt_uint);drivers/gpu/drm/xe/tests/xe_kunit_helpers.h +20
-0@@ -9,6 +9,7 @@struct device ;struct kunit ;struct xe_device ; +struct xe_gt ;struct xe_device *xe_kunit_helper_alloc_xe_device (struct kunit *test, struct device *dev);@@ -16,4 +17,41 @@ int xe_kunit_helper_xe_device_test_init(struct kunit *test);int xe_kunit_helper_xe_device_live_test_init (struct kunit *test); +void xe_kunit_helper_delayed_call_void_xe_device (struct kunit *test, + unsigned long delay, + void (*func)(struct xe_device *xe), + struct xe_device *xe); + +void xe_kunit_helper_delayed_call_void_xe_gt (struct kunit *test, + unsigned long delay, + void (*func)(struct xe_gt *gt), + struct xe_gt *gt); + +void xe_kunit_helper_delayed_call_int_xe_gt_uint (struct kunit *test, + unsigned long delay, + int (*func)(struct xe_gt *gt, + unsigned int vfid), + struct xe_gt *gt, + unsigned int n); + +/** +* xe_kunit_helper_delayed_call - Queue a function call during KUnit test
+ * @test: the &kunit test case
+ * @delay: number of jiffies to wait before queueing
+ * @func: the&xe_deviceor&xe_gtfunction to call
+ * @args: the&xe_deviceor&xe_gtand other function arguments
+ *
+ * This is a helper macro that compiles into dedicated function call based on
+ * the provided argument types.
+ */drivers/gpu/drm/xe/tests/xe_kunit_helpers.h +10
-0+#define xe_kunit_helper_delayed_call(test, delay, func, args...) \ + _Generic(func, \ + void (*)(struct xe_device *) : \ + xe_kunit_helper_delayed_call_void_xe_device, \ + void (*)(struct xe_gt *) : \ + xe_kunit_helper_delayed_call_void_xe_gt, \ + int (*)(struct xe_gt *, unsigned int) : \ + xe_kunit_helper_delayed_call_int_xe_gt_uint \ + )(test, delay, func, args) +#endif
--
2.43.0
Re: [PATCH 05/12] drm/xe/tests: Allow deferred function call during KUnit test
In reply to Michal WajdeczkoQuoted 57 lines · Michal Wajdeczko
Quoted 45 lines · Lucas De Marchi
Quoted 44 lines · Michal Wajdeczko
For some advanced test cases we might want to simulate external activity that will stimulate function under test. Add set of helper functions to implement such requirement. Usage example:
static void
foo(struct xe_device *xe)
{
WRITE_ONCE(xe->foo, 1);
}static void
foo_test(struct kunit *test)
{
structxe_device*xe =test->priv;
xe_kunit_helper_delayed_call(test, HZ / 2, foo, xe);
KUNIT_EXPECT_EQ(test, 0, READ_ONCE(xe->foo));schedule_timeout_uninterruptible(HZ);KUNIT_EXPECT_EQ(test, 1, READ_ONCE(xe->foo)); }Signed-off-by Michal Wajdeczko <[email protected]>Cc Lucas De Marchi <[email protected]>---
drivers/gpu/drm/xe/tests/xe_kunit_helpers.c| 148 ++++++++++++++++++++drivers/gpu/drm/xe/tests/xe_kunit_helpers.h| 38 +++++2 files changed, 186 insertions(+)drivers/gpu/drm/xe/tests/xe_kunit_helpers.c +0
-0@@ -127,3 +127,151 @@ int xe_kunit_helper_xe_device_live_test_init(struct kunit *test) return 0; }
EXPORT_SYMBOL_IF_KUNIT(xe_kunit_helper_xe_device_live_test_init);drivers/gpu/drm/xe/tests/xe_kunit_helpers.c +7
-0+ +struct xe_kunit_call { + struct delayed_work work; + struct kunit *test; + struct { + int (*int_gt)(struct xe_gt *gt); + int (*int_gt_uint)(struct xe_gt *gt, unsigned int n);Quoted 8 lines
Quoted 3 lines
+ void (*void_gt)(struct
xe_gt*gt);
+ void (*void_gt_uint)(structxe_gt*gt, unsigned int n); + void (*void_xe)(structxe_device*xe);I think the only reason why you're adding this in xe is because you are using xe-specific types. This could rather be done generically by always using int
delayed_func(void *data). Then you can simply add it to kunit and get it reviewed there.
Quoted 5 lines
while some generic functionality could be always extracted and moved to the kunit, for easier use in Xe tests likely we will still need some wrappers with xe-specific types, so do we really always need to start with trying enhance generic kunit first and then wait for acceptance until we can use such extension in our test code?
the other option is that we keep creating a mini-subsystem inside xe and if we don't push back, the generic part is never done as people move on to other tasks.
Quoted 3 lines
IMO this could be in parallel, so in kunit review we can point how this is already being used..
Yes, sometimes it's better to do the concrete thing and
use that to advocate for the generic feature, but we should balance on how much we want to maintain in the mid/long term.
Quoted 2 lines
anyway, will try to split that feature into 'generic' and 'xe'
if the generic part is acceptable to kunit maintainers, we can always ask to merge that via drm-xe with their acks.
Lucas De Marchi
Quoted 223 lines
Quoted 5 lines
Also thinking that the example you added in the commit message is likely suggesting the wrong type of test, that a) sleep too much and b) tend to be noisy
only tests longer than 2s are considered SLOW ;)
and HZ was just picked to have an example small
and you will not see any noise if test PASSES
Quoted 211 lines
Lucas De Marchi
Quoted 208 lines
+ } func;
+ struct {
+ structxe_device*xe;
+ structxe_gt*gt;
+ unsigned int n;
+ } args;drivers/gpu/drm/xe/tests/xe_kunit_helpers.c +5
-0+}; + +static void call_work_func (struct work_struct *work) +{ + struct xe_kunit_call *call = container_of(work, typeof(*call),work.work);
+
+ if (call->func.void_xe) {
+kunit_info(call->test, "calling %ps(xe)\n", call->func.void_xe); +call->func.void_xe(call->args.xe);
+kunit_info(call->test, "%ps(xe) completed\n", call->func.void_xe);
+ } else if (call->func.void_gt) {
+kunit_info(call->test, "%ps(gt)\n", call->func.void_gt); +call->func.void_gt(call->args.gt);
+kunit_info(call->test, "%ps(gt) completed\n", call->func.void_gt);
+ } else if (call->func.int_gt_uint) {
+ int ret;drivers/gpu/drm/xe/tests/xe_kunit_helpers.c +28
-0+ + kunit_info(call->test, "calling %ps(gt,%u)\n", + call->func.int_gt_uint, call->args.n); + ret = call->func.int_gt_uint(call->args.gt, call->args.n); + if (ret < 0) { + kunit_info(call->test, "%ps(gt,%u) reported error %pe\n", + call->func.int_gt_uint, call->args.n, ERR_PTR(ret)); + } else { + kunit_info(call->test, "%ps(gt,%u) returned %d\n", + call->func.int_gt_uint, call->args.n, ret); + } + } +} + +static struct xe_kunit_call *prepare_call (struct kunit *test) +{ + struct xe_kunit_call *call; + + call = kunit_kzalloc(test, sizeof(*call), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, call); + + INIT_DELAYED_WORK(&call->work, call_work_func); + call->test = test; + + return call; +} + +KUNIT_DEFINE_ACTION_WRAPPER(cancel_call, cancel_delayed_work_sync,struct
delayed_work*);drivers/gpu/drm/xe/tests/xe_kunit_helpers.c +2
-0+ +static void queue_call(struct kunit *test, struct xe_kunit_call*call, unsigned long delay)
+{
+queue_delayed_work(system_wq, &call->work, delay); +KUNIT_ASSERT_EQ(test, 0, kunit_add_action_or_reset(test, cancel_call, &call->work));drivers/gpu/drm/xe/tests/xe_kunit_helpers.c +4
-0+} + +/** +* xe_kunit_helper_delayed_call_void_xe_device - Queue a function call during KUnit test
+ * @test: the &kunit test case
+ * @delay: number of jiffies to wait before queueing
+ * @func: the&xe_devicefunction to call
+ * @xe: the&xe_deviceargument
+ *
+ * This function usesKUNIT_ASSERTto detect any failures.
+ */drivers/gpu/drm/xe/tests/xe_kunit_helpers.c +19
-0+void xe_kunit_helper_delayed_call_void_xe_device (struct kunit *test, + unsigned long delay, + void (*func)(struct xe_device *xe), + struct xe_device *xe) +{ + struct xe_kunit_call *call = prepare_call(test); + + KUNIT_ASSERT_NOT_NULL(test, func); + KUNIT_ASSERT_NOT_NULL(test, xe); + + call->func.void_xe = func; + call->args.xe = xe; + + return queue_call(test, call, delay); +} +EXPORT_SYMBOL_IF_KUNIT (xe_kunit_helper_delayed_call_void_xe_device); + +/** +* xe_kunit_helper_delayed_call_void_xe_gt - Queue a function call during KUnit test
+ * @test: the &kunit test case
+ * @delay: number of jiffies to wait before queueing
+ * @func: the&xe_gtfunction to call
+ * @gt: the&xe_gtfunction argument
+ *
+ * This function usesKUNIT_ASSERTto detect any failures.
+ */drivers/gpu/drm/xe/tests/xe_kunit_helpers.c +19
-0+void xe_kunit_helper_delayed_call_void_xe_gt (struct kunit *test, + unsigned long delay, + void (*func)(struct xe_gt *gt), + struct xe_gt *gt) +{ + struct xe_kunit_call *call = prepare_call(test); + + KUNIT_ASSERT_NOT_NULL(test, func); + KUNIT_ASSERT_NOT_NULL(test, gt); + + call->func.void_gt = func; + call->args.gt = gt; + + return queue_call(test, call, delay); +} +EXPORT_SYMBOL_IF_KUNIT (xe_kunit_helper_delayed_call_void_xe_gt); + +/** +* xe_kunit_helper_delayed_call_int_xe_gt_uint - Queue a function call during KUnit test
+ * @test: the &kunit test case
+ * @delay: number of jiffies to wait before queueing
+ * @func: the&xe_gtfunction to call
+ * @gt: the&xe_gtfunction argument
+ * @n: the function argument
+ *
+ * This function usesKUNIT_ASSERTto detect any failures.
+ */drivers/gpu/drm/xe/tests/xe_kunit_helpers.c +19
-0+void xe_kunit_helper_delayed_call_int_xe_gt_uint (struct kunit *test, + unsigned long delay, + int (*func)(struct xe_gt *gt, + unsigned int vfid), + struct xe_gt *gt, + unsigned int n) +{ + struct xe_kunit_call *call = prepare_call(test); + + KUNIT_ASSERT_NOT_NULL(test, func); + KUNIT_ASSERT_NOT_NULL(test, gt); + + call->func.int_gt_uint = func; + call->args.gt = gt; + call->args.n = n; + + return queue_call(test, call, delay); +} +EXPORT_SYMBOL_IF_KUNIT (xe_kunit_helper_delayed_call_int_xe_gt_uint);drivers/gpu/drm/xe/tests/xe_kunit_helpers.h +20
-0@@ -9,6 +9,7 @@struct device ;struct kunit ;struct xe_device ; +struct xe_gt ;struct xe_device *xe_kunit_helper_alloc_xe_device (struct kunit *test, struct device *dev);@@ -16,4 +17,41 @@ int xe_kunit_helper_xe_device_test_init(struct kunit *test);int xe_kunit_helper_xe_device_live_test_init (struct kunit *test); +void xe_kunit_helper_delayed_call_void_xe_device (struct kunit *test, + unsigned long delay, + void (*func)(struct xe_device *xe), + struct xe_device *xe); + +void xe_kunit_helper_delayed_call_void_xe_gt (struct kunit *test, + unsigned long delay, + void (*func)(struct xe_gt *gt), + struct xe_gt *gt); + +void xe_kunit_helper_delayed_call_int_xe_gt_uint (struct kunit *test, + unsigned long delay, + int (*func)(struct xe_gt *gt, + unsigned int vfid), + struct xe_gt *gt, + unsigned int n); + +/** +* xe_kunit_helper_delayed_call - Queue a function call during KUnit test
+ * @test: the &kunit test case
+ * @delay: number of jiffies to wait before queueing
+ * @func: the&xe_deviceor&xe_gtfunction to call
+ * @args: the&xe_deviceor&xe_gtand other function arguments
+ *
+ * This is a helper macro that compiles into dedicated function call based on
+ * the provided argument types.
+ */drivers/gpu/drm/xe/tests/xe_kunit_helpers.h +10
-0+#define xe_kunit_helper_delayed_call(test, delay, func, args...) \ + _Generic(func, \ + void (*)(struct xe_device *) : \ + xe_kunit_helper_delayed_call_void_xe_device, \ + void (*)(struct xe_gt *) : \ + xe_kunit_helper_delayed_call_void_xe_gt, \ + int (*)(struct xe_gt *, unsigned int) : \ + xe_kunit_helper_delayed_call_int_xe_gt_uint \ + )(test, delay, func, args) +#endif
--
2.43.0
PATCH 6/12 drm/xe/tests: Add helper macro to detect if KUnit is running
In reply to Michal WajdeczkoIn upcoming patch we will add some functionality that will be used by the KUnit test code but outside of the KUnit context, while still should be activated only when the KUnit test is running. Add simple helper to hide implementation details.
--- drivers/gpu/drm/xe/tests/xe_test.h | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpu/drm/xe/tests/xe_test.h +3 -0
@@ -31,6 +31,7 @@ struct xe_test_priv {#define XE_TEST_DECLARE (x) x#define XE_TEST_ONLY (x) unlikely(x) +#define XE_TEST_RUNNING () static_branch_unlikely(&kunit_running)/** * xe_cur_kunit_priv - Obtain the struct xe_test_priv pointed to by
@@ -57,6 +58,8 @@ xe_cur_kunit_priv(enum xe_test_priv_id id)#define XE_TEST_DECLARE (x)#define XE_TEST_ONLY (x) 0 +#define XE_TEST_RUNNING () false +#define xe_cur_kunit_priv (_id) NULL#endif
Signature · 1 line
2.43.0
PATCH 7/12 drm/xe/tests: Add helpers to call stubs out of KUnit context
In reply to Michal WajdeczkoThe KUNIT_STATIC_STUB_REDIRECT() allows to redirect function call but will work only if the caller is in a KUnit context. To allow implementation of the more complex test cases, add helpers that allow calling stubs also out of a KUnit context.
--- drivers/gpu/drm/xe/tests/xe_test.h | 74 ++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+)
drivers/gpu/drm/xe/tests/xe_test.h +74 -0
@@ -54,11 +54,85 @@ xe_cur_kunit_priv(enum xe_test_priv_id id) return priv->id == id ? priv : NULL; } +/** +* XE_TEST_REDIRECT() - Call a function stub if one exists. +* @stub: The pointer to the function stub +* @args: All of the arguments passed to this stub +* +* This is a function prologue which is used to allow calls to the current +* function to be redirected if a KUnit is running. If the stub is NULL or +* the KUnit is not running the function will continue execution as normal. +* +* Unlikely the KUNIT_STATIC_STUB_REDIRECT(), this redirection will work +* even if the caller is not in a KUnit context (like a worker thread). +* +* Example: +* +* .. code-block:: c +* +* int (*stub)(int n); +* +* int real_func(int n) +* { +* XE_TEST_REDIRECT(stub, n); +* return n + 1; +* } +* +* int replacement_func(int n) +* { +* return n + 100; +* } +* +* void example_test(struct kunit *test) +* { +* stub = replacement_func; +* KUNIT_EXPECT_EQ(test, real_func(1), 101); +* KUNIT_EXPECT_EQ(test, real_func(1), 101); +* } +*/ +#define XE_TEST_REDIRECT(stub, args...) \ +do { \ + typeof(stub) replacement = (stub); \ + if (XE_TEST_RUNNING()) { \ + if (unlikely(replacement)) { \ + pr_info(KUNIT_SUBTEST_INDENT "# %s: calling stub %ps\n", \ + __func__, replacement); \ + return replacement(args); \ + } \ + } \ +} while (0) + +static inline void __nullify_pointer (void *data) +{ +void **ptr = data; + + *ptr =NULL ; +} + +/** +* XE_TEST_ACTIVATE_STUB() - Setup a function stub. +* @test: Test case that wants to setup a function stub +* @stub: The function stub pointer +* @replacement: The replacement function +* +* This helper setups a function stub with the replacement function. +* It will also automatically restore stub to NULL at the test end. +*/ +#define XE_TEST_ACTIVATE_STUB (test, stub, replacement) ({ \ + typeof(test) __test = (test); \ + typeof(stub) *__ptr = &(stub); \ + typecheck_pointer(*__ptr); \ + *__ptr = (replacement); \ + kunit_info(__test, "activated stub %s with %ps\n", __stringify(stub), *__ptr); \ + kunit_add_action_or_reset(__test, __nullify_pointer, __ptr); \ +}) +#else /* if IS_ENABLED(CONFIG_DRM_XE_KUNIT_TEST) */ #define XE_TEST_DECLARE (x)#define XE_TEST_ONLY (x) 0#define XE_TEST_RUNNING () false +#define XE_TEST_REDIRECT (...) do { } while (0)#define xe_cur_kunit_priv (_id) NULL
Signature · 1 line
2.43.0
Re: [PATCH 07/12] drm/xe/tests: Add helpers to call stubs out of KUnit context
Quoted 46 lines · Michal Wajdeczko
The
KUNIT_STATIC_STUB_REDIRECT()allows to redirect function call but will work only if the caller is in a KUnit context. To allow implementation of the more complex test cases, add helpers that allow calling stubs also out of a KUnit context.Signed-off-by Michal Wajdeczko <[email protected]>Cc Lucas De Marchi <[email protected]>---
drivers/gpu/drm/xe/tests/xe_test.h| 74 ++++++++++++++++++++++++++++++1 file changed, 74 insertions(+)drivers/gpu/drm/xe/tests/xe_test.h +27
-0@@ -54,11 +54,85 @@ xe_cur_kunit_priv(enum xe_test_priv_id id)return priv->id == id ? priv :NULL ; } +/** +* XE_TEST_REDIRECT() - Call a function stub if one exists. +* @stub: The pointer to the function stub +* @args: All of the arguments passed to this stub +* +* This is a function prologue which is used to allow calls to the current +* function to be redirected if a KUnit is running. If the stub is NULL or +* the KUnit is not running the function will continue execution as normal. +* +* Unlikely the KUNIT_STATIC_STUB_REDIRECT(), this redirection will work +* even if the caller is not in a KUnit context (like a worker thread). +* +* Example: +* +* .. code-block:: c +* +* int (*stub)(int n); +* +* int real_func(int n) +* { +* XE_TEST_REDIRECT(stub, n); +* return n + 1; +* } +* +* int replacement_func(int n) +* { +* return n + 100;
drivers/gpu/drm/xe/tests/xe_test.h xe_cur_kunit_priv(enum xe_test_priv_id id) · line 93
Quoted 10 lines
drivers/gpu/drm/xe/tests/xe_test.h +10
-0+* } +* +* void example_test(struct kunit *test) +* { +* stub = replacement_func; +* KUNIT_EXPECT_EQ(test, real_func(1), 101); +* KUNIT_EXPECT_EQ(test, real_func(1), 101); +* } +*/ +#define XE_TEST_REDIRECT(stub, args...) \
this seems another one that should rather be in the kunit layer, not in xe
drivers/gpu/drm/xe/tests/xe_test.h xe_cur_kunit_priv(enum xe_test_priv_id id) · line 99
Quoted 6 lines
drivers/gpu/drm/xe/tests/xe_test.h +6
-0+do { \ + typeof(stub) replacement = (stub); \ + if (XE_TEST_RUNNING()) { \ + if (unlikely(replacement)) { \ + pr_info(KUNIT_SUBTEST_INDENT "# %s: calling stub %ps\n", \ + __func__, replacement); \
KUNIT_STATIC_STUB_REDIRECT() silently calls the stub without pr_info(). Why does this version need to be extra-verbose?
Lucas De Marchi
Quoted 42 lines
drivers/gpu/drm/xe/tests/xe_test.h +31
-0+ return replacement(args); \ + } \ + } \ +}while (0 ) + +static inline void __nullify_pointer(void *data) +{ +void **ptr = data; + + *ptr =NULL ; +} + +/** +* XE_TEST_ACTIVATE_STUB() - Setup a function stub. +* @test: Test case that wants to setup a function stub +* @stub: The function stub pointer +* @replacement: The replacement function +* +* This helper setups a function stub with the replacement function. +* It will also automatically restore stub to NULL at the test end. +*/ +#define XE_TEST_ACTIVATE_STUB (test, stub, replacement) ({ \ + typeof(test) __test = (test); \ + typeof(stub) *__ptr = &(stub); \ + typecheck_pointer(*__ptr); \ + *__ptr = (replacement); \ + kunit_info(__test, "activated stub %s with %ps\n", __stringify(stub), *__ptr); \ + kunit_add_action_or_reset(__test, __nullify_pointer, __ptr); \ +}) +#else /* if IS_ENABLED(CONFIG_DRM_XE_KUNIT_TEST) */ #define XE_TEST_DECLARE (x)#define XE_TEST_ONLY (x) 0#define XE_TEST_RUNNING () false +#define XE_TEST_REDIRECT (...) do { } while (0)#define xe_cur_kunit_priv (_id) NULLSignature · 1 line
2.43.0
Re: [PATCH 07/12] drm/xe/tests: Add helpers to call stubs out of KUnit context
Quoted 58 lines · Lucas De Marchi
Quoted 57 lines · Michal Wajdeczko
The
KUNIT_STATIC_STUB_REDIRECT()allows to redirect function call but will
work only if the caller is in a KUnit context. To allow implementation of the more complex test cases, add helpers that allow calling stubs also out
of a KUnit context.Signed-off-by Michal Wajdeczko <[email protected]>Cc Lucas De Marchi <[email protected]>---
drivers/gpu/drm/xe/tests/xe_test.h| 74 ++++++++++++++++++++++++++++++1 file changed, 74 insertions(+)drivers/gpu/drm/xe/tests/xe_test.h +6
-0@@ -54,11 +54,85 @@ xe_cur_kunit_priv(enum xe_test_priv_id id) return priv->id == id ? priv : NULL; } +/** +* XE_TEST_REDIRECT() - Call a function stub if one exists. +* @stub: The pointer to the function stub +* @args: All of the arguments passed to this stub +* +* This is a function prologue which is used to allow calls to the current
+ * function to be redirected if a KUnit is running. If the stub is NULL or
+ * the KUnit is not running the function will continue execution as normal.
+ *
+ * Unlikely theKUNIT_STATIC_STUB_REDIRECT(), this redirection will work
+ * even if the caller is not in a KUnit context (like a worker thread).
+ *
+ * Example:
+ *
+ * .. code-block:: c
+ *
+ * int (*stub)(int n);
+ *
+ * intreal_func(int n)
+ * {
+ *XE_TEST_REDIRECT(stub, n);
+ * return n + 1;
+ * }
+ *
+ * intreplacement_func(int n)
+ * {
+ * return n + 100;
+ * }
+ *
+ * voidexample_test(struct kunit *test)
+ * {
+ * stub =replacement_func;
Quoted 8 lines
Quoted 5 lines
+ *
KUNIT_EXPECT_EQ(test, real_func(1), 101);
+ *KUNIT_EXPECT_EQ(test, real_func(1), 101);
+ * }
+ */
+#defineXE_TEST_REDIRECT(stub, args...)\this seems another one that should rather be in the kunit layer, not in xe
will try to prepare generic kunit patch, but I was just hoping that we can have/use something sooner without waiting until it will accepted there
Quoted 11 lines
Quoted 8 lines
+do { \
+ typeof(stub) replacement = (stub); \
+ if (XE_TEST_RUNNING()) { \
+ if (unlikely(replacement)) { \
+ pr_info(KUNIT_SUBTEST_INDENT "# %s: calling stub %ps\n", \
+__func__, replacement); \
KUNIT_STATIC_STUB_REDIRECT()silently calls the stub withoutpr_info(). Why does this version need to be extra-verbose?
KUNIT_STATIC_STUB_REDIRECT() only works in kunit context so likely your test is almost directly exercise that redirection, while here replacement function will used for any code that executes during the test, so this will help identify any unexpected redirections
and this extra-verbose 'noise' will not be seen unless your test fails (unless you will use --raw_output)
Quoted 49 lines
Lucas De Marchi
Quoted 45 lines
+ return replacement(args); \
+ } \
+ } \drivers/gpu/drm/xe/tests/xe_test.h +19
-0+}while (0 ) + +static inline void __nullify_pointer(void *data) +{ + void **ptr = data; + + *ptr = NULL; +} + +/** +* XE_TEST_ACTIVATE_STUB() - Setup a function stub. +* @test: Test case that wants to setup a function stub +* @stub: The function stub pointer +* @replacement: The replacement function +* +* This helper setups a function stub with the replacement function. +* It will also automatically restore stub to NULL at the test end. +*/ +#define XE_TEST_ACTIVATE_STUB (test, stub, replacement)({ \
+ typeof(test)__test= (test); \
+ typeof(stub)*__ptr= &(stub); \
+ typecheck_pointer(*__ptr); \
+*__ptr= (replacement); \
+kunit_info(__test, "activated stub %s with %ps\n", __stringify(stub), *__ptr); \
+kunit_add_action_or_reset(__test, __nullify_pointer, __ptr); \drivers/gpu/drm/xe/tests/xe_test.h +2
-0+}) +#else /* if
IS_ENABLED(CONFIG_DRM_XE_KUNIT_TEST)*/#define
XE_TEST_DECLARE(x)
#defineXE_TEST_ONLY(x)0
#defineXE_TEST_RUNNING()false
+#defineXE_TEST_REDIRECT(...)do { } while (0)#define
xe_cur_kunit_priv(_id)NULL--
2.43.0
PATCH 8/12 drm/xe/guc: Define stub for xe_guc_ct_send_recv()
In reply to Michal WajdeczkoFor some advanced KUnit test cases we may want to use replacement function instead of the real xe_guc_ct_send_recv().
--- drivers/gpu/drm/xe/xe_guc_ct.c | 2 ++ drivers/gpu/drm/xe/xe_guc_ct_types.h | 5 +++++ 2 files changed, 7 insertions(+)
drivers/gpu/drm/xe/xe_guc_ct.c +2 -0
@@ -938,6 +938,8 @@ int xe_guc_ct_send_recv(struct xe_guc_ct *ct, const u32 *action, u32 len, u32 *response_buffer) {KUNIT_STATIC_STUB_REDIRECT (xe_guc_ct_send_recv, ct, action, len, response_buffer); +XE_TEST_REDIRECT (ct->send_recv, ct, action, len, response_buffer); +return guc_ct_send_recv (ct, action, len, response_buffer, false); }
drivers/gpu/drm/xe/xe_guc_ct_types.h +5 -0
@@ -13,6 +13,7 @@#include <linux/xarray.h> #include "abi/guc_communication_ctb_abi.h" +#include "tests/xe_test.h" struct xe_bo ;
@@ -128,6 +129,10 @@ struct xe_guc_ct {u32 msg[GUC_CTB_MSG_MAX_LEN ];/** @fast_msg: Message buffer */ u32 fast_msg[GUC_CTB_MSG_MAX_LEN ]; + + XE_TEST_DECLARE(int (*send_recv)(struct xe_guc_ct *ct, + const u32 *action, u32 len, + u32 *response_buffer)); };#endif
Signature · 1 line
2.43.0
PATCH 9/12 drm/xe/pf: Define stub for pf_sanitize_vf_resources()
In reply to Michal WajdeczkoFor some advanced KUnit test cases we may want to use replacement function instead of the pf_sanitize_vf_resources() which actually implements the exported xe_gt_sriov_pf_config_sanitize() function.
--- drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c | 2 ++ drivers/gpu/drm/xe/xe_gt_sriov_pf_config_types.h | 5 +++++ 2 files changed, 7 insertions(+)
drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c +2 -0
@@ -1938,6 +1938,8 @@ static int pf_sanitize_vf_resources(struct xe_gt *gt, u32 vfid, long timeout)struct xe_device *xe =gt_to_xe (gt);int err =0 ; +XE_TEST_REDIRECT (config->sanitize, gt, vfid, timeout); +/* * Only GGTT and LMEM requires to be cleared by the PF. * GuC doorbell IDs and context IDs do not need any clearing.
drivers/gpu/drm/xe/xe_gt_sriov_pf_config_types.h +5 -0
@@ -8,9 +8,11 @@#include <drm/drm_mm.h> +#include "tests/xe_test.h" #include "xe_guc_klv_thresholds_set_types.h" struct xe_bo ; +struct xe_gt ;/** * struct xe_gt_sriov_config - GT level per-VF configuration data.
@@ -36,6 +38,9 @@ struct xe_gt_sriov_config {u32 preempt_timeout;/** @thresholds: GuC thresholds for adverse events notifications. */ u32 thresholds[XE_GUC_KLV_NUM_THRESHOLDS ]; + +/* private: */ + XE_TEST_DECLARE(int (*sanitize)(struct xe_gt *gt, unsigned int vfid, long timeout)); };/**
Signature · 1 line
2.43.0
PATCH 10/12 drm/xe/pf: Define stub for pf_send_vf_control_cmd()
In reply to Michal WajdeczkoFor some advanced KUnit test cases we may want to use replacement function instead of the real pf_send_vf_control_cmd().
--- drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c | 1 + drivers/gpu/drm/xe/xe_gt_sriov_pf_control_types.h | 7 +++++++ 2 files changed, 8 insertions(+)
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +1 -0
@@ -58,6 +58,7 @@ static int pf_send_vf_control_cmd(struct xe_gt *gt, unsigned int vfid, u32 cmd)xe_gt_assert (gt, vfid !=PFID );xe_gt_sriov_dbg_verbose (gt,"sending VF%u control command %s\n" , vfid,control_cmd_to_string (cmd)); +XE_TEST_REDIRECT (gt->sriov.pf.control.send_vf_control_cmd, gt, vfid, cmd); err =guc_action_vf_control_cmd (>->uc.guc, vfid, cmd);if (unlikely (err))
drivers/gpu/drm/xe/xe_gt_sriov_pf_control_types.h +7 -0
@@ -10,6 +10,10 @@#include <linux/spinlock.h> #include <linux/workqueue_types.h> +#include "tests/xe_test.h" + +struct xe_gt ; +/** * enum xe_gt_sriov_control_bits - Various bits used by the PF to represent a VF state *
@@ -102,6 +106,9 @@ struct xe_gt_sriov_pf_control {/** @lock: protects VF pending list */ spinlock_t lock; + +/* private: */ + XE_TEST_DECLARE(int (*send_vf_control_cmd)(struct xe_gt *gt, unsigned int vfid, u32 cmd)); };#endif
Signature · 1 line
2.43.0
PATCH 11/12 drm/xe/tests: Add KUnit tests for VF control state machines
In reply to Michal WajdeczkoAdd KUnit tests (~200) for all VF control state machines (FLR, PAUSE, STOP and RESUME) to make sure they work as expected and will not be broken while extending them with new functionality.
---
Test file named according to the new best practices [1]
[1] https://lore.kernel.org/linux-hardening/[email protected]/
--- .../xe/tests/xe_gt_sriov_pf_control_kunit.c | 1360 +++++++++++++++++ drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c | 7 + 2 files changed, 1367 insertions(+) create mode 100644 drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c
drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c new file +1360 -0
@@ -0,0 +1,1360 @@ +// SPDX-License-Identifier: GPL-2.0 AND MIT +/* +* Copyright © 2024 Intel Corporation +*/ + +#include <kunit/test.h> +#include <kunit/static_stub.h> + +#include "tests/xe_kunit_helpers.h" +#include "tests/xe_pci_test.h" + +#include "xe_gt_sriov_pf.h" + +static const unsigned int DUT_NUM_VFS =2 ; +static const unsigned int VFUT1 =VFID (1 ); +static const unsigned int VFUT2 =VFID (2 ); + +static void dump_state (void *arg) +{ +struct xe_gt *gt = arg; + +pf_dump_vf_state (gt,VFUT1 ); +} + +static unsigned long replacement_timeout (enum xe_gt_sriov_control_bits bit) +{ +return HZ ; +} + +static int pf_control_test_init (struct kunit *test) +{ +struct xe_pci_fake_data fake = { + .sriov_mode =XE_SRIOV_MODE_PF , + .platform =XE_TIGERLAKE ,/* some random platform */ + .subplatform =XE_SUBPLATFORM_NONE , + }; +struct xe_device *xe; +struct xe_gt *gt; + + test->priv = &fake; +xe_kunit_helper_xe_device_test_init (test); + + xe = test->priv; +KUNIT_ASSERT_EQ (test,xe_sriov_init (xe),0 ); + + xe->sriov.pf.driver_max_vfs =DUT_NUM_VFS ; +KUNIT_EXPECT_NE (test,xe_sriov_pf_get_totalvfs (xe),0 ); + + gt =xe_device_get_gt (xe,0 ); +KUNIT_ASSERT_EQ (test,xe_gt_sriov_pf_init_early (gt),0 ); + +KUNIT_ASSERT_EQ (test,0ul , *__pf_peek_vf_state (gt,VFUT1 )); +KUNIT_ASSERT_EQ (test,0ul , *__pf_peek_vf_state (gt,VFUT2 )); + +KUNIT_EXPECT_EQ (test,0 ,kunit_add_action_or_reset (test, dump_state, gt)); + +kunit_activate_static_stub (test, pf_get_default_timeout, replacement_timeout); + + test->priv = gt; +return 0 ; +} + +static int sanitize_vf_resources_fail (struct xe_gt *gt,u32 vfid,long timeout) +{ +return -ETIMEDOUT ; +} + +static int send_vf_control_cmd_reject (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +return -EIO ; +} + +static int send_vf_control_cmd_fail (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +return -ENODEV ; +} + +static int send_vf_control_cmd_pass_no_reply (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +return 0 ; +} + +static int send_vf_control_cmd_pass_and_reply (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +switch (cmd) { +case GUC_PF_TRIGGER_VF_PAUSE : +pf_handle_vf_event (gt, vfid,GUC_PF_NOTIFY_VF_PAUSE_DONE ); +break ; +case GUC_PF_TRIGGER_VF_FLR_START : +pf_handle_vf_event (gt, vfid,GUC_PF_NOTIFY_VF_FLR_DONE ); +break ; +case GUC_PF_TRIGGER_VF_RESUME : +case GUC_PF_TRIGGER_VF_STOP : +case GUC_PF_TRIGGER_VF_FLR_FINISH : +break ; +default : +return -EPROTO ; + } +return 0 ; +} + +static int send_vf_control_cmd_busy_wait (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +schedule_timeout_interruptible (HZ /20 ); +return -EBUSY ; +} + +static int send_vf_control_cmd_pass_but_reply_flr_only (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +return cmd ==GUC_PF_TRIGGER_VF_FLR_START ? +send_vf_control_cmd_pass_and_reply (gt, vfid, cmd) : +send_vf_control_cmd_pass_no_reply (gt, vfid, cmd); +} + +static int send_vf_control_cmd_busy_except_flr (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +return cmd ==GUC_PF_TRIGGER_VF_FLR_START || cmd ==GUC_PF_TRIGGER_VF_FLR_FINISH ? +send_vf_control_cmd_pass_and_reply (gt, vfid, cmd) : +send_vf_control_cmd_busy_wait (gt, vfid, cmd); +} + +static int send_vf_control_cmd_busy_except_stop (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +return cmd ==GUC_PF_TRIGGER_VF_STOP ? +send_vf_control_cmd_pass_and_reply (gt, vfid, cmd) : +send_vf_control_cmd_busy_wait (gt, vfid, cmd); +} + +static int BUSY_MAGIC =3 ; + +static int send_vf_control_cmd_busy_no_reply (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +static int counter; + +return ++counter %BUSY_MAGIC ? -EBUSY :0 ; +} + +static int send_vf_control_cmd_busy_and_reply (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +static int counter; + +return ++counter %BUSY_MAGIC ? -EBUSY : +send_vf_control_cmd_pass_and_reply (gt, vfid, cmd); +} + +static const enum xe_gt_sriov_control_bits ready[] = { +}; + +static const enum xe_gt_sriov_control_bits flr_starting[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_FLR_WIP , +XE_GT_SRIOV_STATE_FLR_SEND_START , +}; + +static const enum xe_gt_sriov_control_bits flr_starting_paused[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_FLR_WIP , +XE_GT_SRIOV_STATE_FLR_SEND_START , +XE_GT_SRIOV_STATE_PAUSED , +}; + +static const enum xe_gt_sriov_control_bits flr_starting_stopped[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_FLR_WIP , +XE_GT_SRIOV_STATE_FLR_SEND_START , +XE_GT_SRIOV_STATE_STOPPED , +}; + +static const enum xe_gt_sriov_control_bits flr_waiting[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_FLR_WIP , +XE_GT_SRIOV_STATE_FLR_WAIT_GUC , +}; + +static const enum xe_gt_sriov_control_bits flr_guc_done[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_FLR_WIP , +XE_GT_SRIOV_STATE_FLR_GUC_DONE , +}; + +static const enum xe_gt_sriov_control_bits flr_resetting[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_FLR_WIP , +XE_GT_SRIOV_STATE_FLR_RESET_CONFIG , +}; + +static const enum xe_gt_sriov_control_bits flr_finishing[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_FLR_WIP , +XE_GT_SRIOV_STATE_FLR_SEND_FINISH , +}; + +static const enum xe_gt_sriov_control_bits flr_failed[] = { +XE_GT_SRIOV_STATE_FLR_FAILED , +}; + +static const enum xe_gt_sriov_control_bits stopping[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_STOP_WIP , +XE_GT_SRIOV_STATE_STOP_SEND_STOP , +}; + +static const enum xe_gt_sriov_control_bits stopping_paused[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_STOP_WIP , +XE_GT_SRIOV_STATE_STOP_SEND_STOP , +XE_GT_SRIOV_STATE_PAUSED , +}; + +static const enum xe_gt_sriov_control_bits stop_failed[] = { +XE_GT_SRIOV_STATE_STOP_FAILED , +}; + +static const enum xe_gt_sriov_control_bits stop_rejected[] = { +XE_GT_SRIOV_STATE_STOP_FAILED , +XE_GT_SRIOV_STATE_MISMATCH , +}; + +static const enum xe_gt_sriov_control_bits stopped[] = { +XE_GT_SRIOV_STATE_STOPPED , +}; + +static const enum xe_gt_sriov_control_bits pausing[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_PAUSE_WIP , +XE_GT_SRIOV_STATE_PAUSE_SEND_PAUSE , +}; + +static const enum xe_gt_sriov_control_bits pausing_wait_guc[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_PAUSE_WIP , +XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC , +}; + +static const enum xe_gt_sriov_control_bits pausing_guc_done[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_PAUSE_WIP , +XE_GT_SRIOV_STATE_PAUSE_GUC_DONE , +}; + +static const enum xe_gt_sriov_control_bits pause_failed[] = { +XE_GT_SRIOV_STATE_PAUSE_FAILED , +}; + +static const enum xe_gt_sriov_control_bits pause_rejected[] = { +XE_GT_SRIOV_STATE_PAUSE_FAILED , +XE_GT_SRIOV_STATE_MISMATCH , +}; + +static const enum xe_gt_sriov_control_bits paused[] = { +XE_GT_SRIOV_STATE_PAUSED , +}; + +static const enum xe_gt_sriov_control_bits resuming[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_PAUSED , +XE_GT_SRIOV_STATE_RESUME_WIP , +XE_GT_SRIOV_STATE_RESUME_SEND_RESUME , +}; + +static const enum xe_gt_sriov_control_bits resume_failed[] = { +XE_GT_SRIOV_STATE_PAUSED , +XE_GT_SRIOV_STATE_RESUME_FAILED , +}; + +static const enum xe_gt_sriov_control_bits resume_rejected[] = { +XE_GT_SRIOV_STATE_PAUSED , +XE_GT_SRIOV_STATE_RESUME_FAILED , +XE_GT_SRIOV_STATE_MISMATCH , +}; + +static const enum xe_gt_sriov_control_bits resumed[] = { +XE_GT_SRIOV_STATE_RESUMED , +}; + +static const enum xe_gt_sriov_control_bits mismatch[] = { +XE_GT_SRIOV_STATE_MISMATCH , +}; + +struct state_param { +const char *name; +const enum xe_gt_sriov_control_bits *bits; +size_t num_bits; +}; + +static void state_param_get_desc (struct state_param *p,char *desc) +{ +snprintf (desc,KUNIT_PARAM_DESC_SIZE ,"%s" , p->name); +} + +#define MAKE_STATE_PARAM (X ) { .name = #X, .bits = X, .num_bits = ARRAY_SIZE(X) } + +/* +* Due to the test case logic the all "must_pass" params include "_rejected" states +* since our "GuC" calls by default will not complain again about the INVALID_STATE +* thus our state machine is able to fully recover. +*/ + +static struct state_param flr_must_pass_from[] = { +MAKE_STATE_PARAM (ready), +MAKE_STATE_PARAM (flr_starting), +MAKE_STATE_PARAM (flr_starting_paused), +MAKE_STATE_PARAM (flr_starting_stopped), +MAKE_STATE_PARAM (flr_waiting), +MAKE_STATE_PARAM (flr_guc_done), +MAKE_STATE_PARAM (flr_resetting), +MAKE_STATE_PARAM (flr_finishing), +MAKE_STATE_PARAM (flr_failed), +MAKE_STATE_PARAM (stopping), +MAKE_STATE_PARAM (stop_failed), +MAKE_STATE_PARAM (stop_rejected), +MAKE_STATE_PARAM (stopped), +MAKE_STATE_PARAM (pausing), +MAKE_STATE_PARAM (pausing_wait_guc), +MAKE_STATE_PARAM (pausing_guc_done), +MAKE_STATE_PARAM (pause_failed), +MAKE_STATE_PARAM (pause_rejected), +MAKE_STATE_PARAM (paused), +MAKE_STATE_PARAM (resuming), +MAKE_STATE_PARAM (resume_failed), +MAKE_STATE_PARAM (resume_rejected), +MAKE_STATE_PARAM (resumed), +MAKE_STATE_PARAM (mismatch), +}; + +static struct state_param stop_must_pass_from[] = { +MAKE_STATE_PARAM (ready), +MAKE_STATE_PARAM (stop_failed), +MAKE_STATE_PARAM (stop_rejected), +MAKE_STATE_PARAM (pausing), +MAKE_STATE_PARAM (pausing_wait_guc), +MAKE_STATE_PARAM (pausing_guc_done), +MAKE_STATE_PARAM (pause_failed), +MAKE_STATE_PARAM (pause_rejected), +MAKE_STATE_PARAM (paused), +MAKE_STATE_PARAM (resuming), +MAKE_STATE_PARAM (resume_failed), +MAKE_STATE_PARAM (resume_rejected), +MAKE_STATE_PARAM (resumed), +MAKE_STATE_PARAM (mismatch), +MAKE_STATE_PARAM (flr_failed), +}; + +static struct state_param stop_must_cancel_from[] = { +MAKE_STATE_PARAM (flr_starting), +MAKE_STATE_PARAM (flr_starting_paused), +MAKE_STATE_PARAM (flr_waiting), +MAKE_STATE_PARAM (flr_guc_done), +MAKE_STATE_PARAM (flr_resetting), +MAKE_STATE_PARAM (flr_finishing), +}; + +static struct state_param stop_must_fail_from[] = { +MAKE_STATE_PARAM (stopping), +MAKE_STATE_PARAM (stopping_paused), +MAKE_STATE_PARAM (stopped), +MAKE_STATE_PARAM (flr_starting_stopped), +}; + +static struct state_param pause_must_pass_from[] = { +MAKE_STATE_PARAM (ready), +MAKE_STATE_PARAM (pause_failed), +MAKE_STATE_PARAM (pause_rejected), +MAKE_STATE_PARAM (resumed), +MAKE_STATE_PARAM (mismatch), +MAKE_STATE_PARAM (stop_failed), +MAKE_STATE_PARAM (stop_rejected), +MAKE_STATE_PARAM (flr_failed), +}; + +static struct state_param pause_must_cancel_from[] = { +MAKE_STATE_PARAM (flr_starting), +MAKE_STATE_PARAM (flr_waiting), +MAKE_STATE_PARAM (flr_guc_done), +MAKE_STATE_PARAM (flr_resetting), +MAKE_STATE_PARAM (flr_finishing), +MAKE_STATE_PARAM (stopping), +}; + +static struct state_param pause_must_fail_from[] = { +MAKE_STATE_PARAM (pausing), +MAKE_STATE_PARAM (pausing_wait_guc), +MAKE_STATE_PARAM (pausing_guc_done), +MAKE_STATE_PARAM (paused), +MAKE_STATE_PARAM (resuming), +MAKE_STATE_PARAM (resume_failed), +MAKE_STATE_PARAM (resume_rejected), +MAKE_STATE_PARAM (stopped), +}; + +static struct state_param resume_must_pass_from[] = { +MAKE_STATE_PARAM (paused), +MAKE_STATE_PARAM (resume_failed), +MAKE_STATE_PARAM (resume_rejected), +}; + +static struct state_param resume_must_cancel_from[] = { +MAKE_STATE_PARAM (flr_starting_paused), +MAKE_STATE_PARAM (stopping_paused), +}; + +static struct state_param resume_must_fail_from[] = { +MAKE_STATE_PARAM (ready), +MAKE_STATE_PARAM (pausing), +MAKE_STATE_PARAM (pausing_wait_guc), +MAKE_STATE_PARAM (pausing_guc_done), +MAKE_STATE_PARAM (pause_failed), +MAKE_STATE_PARAM (pause_rejected), +MAKE_STATE_PARAM (resuming), +MAKE_STATE_PARAM (resumed), +MAKE_STATE_PARAM (stopping), +MAKE_STATE_PARAM (stop_failed), +MAKE_STATE_PARAM (stop_rejected), +MAKE_STATE_PARAM (stopped), +MAKE_STATE_PARAM (flr_starting), +MAKE_STATE_PARAM (flr_waiting), +MAKE_STATE_PARAM (flr_guc_done), +MAKE_STATE_PARAM (flr_resetting), +MAKE_STATE_PARAM (flr_finishing), +MAKE_STATE_PARAM (flr_failed), +MAKE_STATE_PARAM (mismatch), +}; + +KUNIT_ARRAY_PARAM (flr_must_pass_from, flr_must_pass_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (stop_must_pass_from, stop_must_pass_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (stop_must_fail_from, stop_must_fail_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (stop_must_cancel_from, stop_must_cancel_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (pause_must_pass_from, pause_must_pass_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (pause_must_fail_from, pause_must_fail_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (pause_must_cancel_from, pause_must_cancel_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (resume_must_pass_from, resume_must_pass_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (resume_must_fail_from, resume_must_fail_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (resume_must_cancel_from, resume_must_cancel_from, state_param_get_desc); + +static int mimic_pf_handle_vf_flr_done (struct xe_gt *gt,unsigned int vfid) +{ +pf_handle_vf_flr_done (gt, vfid); +return 0 ; +} + +static int mimic_pf_handle_vf_pause_done (struct xe_gt *gt,unsigned int vfid) +{ +pf_handle_vf_pause_done (gt, vfid); +return 0 ; +} + +static void prepare_state (struct kunit *test,unsigned int vfid, +const enum xe_gt_sriov_control_bits *bits,size_t num_bits) +{ +struct xe_gt *gt = test->priv; +size_t n; + +for (n =0 ; n < num_bits; n++) { +enum xe_gt_sriov_control_bits bit = bits[n]; + +KUNIT_ASSERT_TRUE (test,pf_enter_vf_state (gt, vfid, bit)); + +if (bit ==XE_GT_SRIOV_STATE_WIP ) { +pf_queue_vf (gt, vfid); + }else if (bit ==XE_GT_SRIOV_STATE_FLR_WAIT_GUC ) { +xe_kunit_helper_delayed_call (test,HZ /100 , + mimic_pf_handle_vf_flr_done, gt, vfid); + }else if (bit ==XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC ) { +xe_kunit_helper_delayed_call (test,HZ /100 , + mimic_pf_handle_vf_pause_done, gt, vfid); + } + } +} + +static void prepare_state_from_param (struct kunit *test) +{ +const struct state_param *p = test->param_value; + +prepare_state (test,VFUT1 , p->bits, p->num_bits); +} + +static void expect_not_pausing (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_WIP )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_SEND_PAUSE )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_GUC_DONE )); +} + +static void expect_not_in_pause (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +expect_not_pausing (test); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_FAILED )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSED )); +} + +static void expect_not_resuming (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_WIP )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_SEND_RESUME )); +} + +static void expect_not_in_resume (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +expect_not_resuming (test); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_FAILED )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUMED )); +} + +static void expect_not_stopping (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOP_WIP )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOP_SEND_STOP )); +} + +static void expect_not_in_stop (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +expect_not_stopping (test); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOP_FAILED )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOPPED )); +} + +static void expect_not_in_flr (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_SEND_START )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WAIT_GUC )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_GUC_DONE )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_SEND_FINISH )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +} + +static void expect_not_in_wip (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void expect_not_in_mismatch (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +} + +static void try_flr_vf (struct kunit *test,bool mimic_busy,bool late_reply) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + mimic_busy ? late_reply ? send_vf_control_cmd_busy_no_reply : + send_vf_control_cmd_busy_and_reply : + late_reply ? send_vf_control_cmd_pass_no_reply : + send_vf_control_cmd_pass_and_reply); + +if (late_reply) +xe_kunit_helper_delayed_call (test,HZ /10 , + mimic_pf_handle_vf_flr_done, gt,VFUT1 ); + +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); + +expect_not_in_flr (test); +expect_not_in_pause (test); +expect_not_in_resume (test); +expect_not_in_stop (test); +expect_not_in_mismatch (test); +expect_not_in_wip (test); +} + +static void flr_vf_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_flr_vf (test, false, false); +} + +static void flr_vf_needs_retry_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_flr_vf (test, true, false); +} + +static void flr_vf_needs_retry_late_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_flr_vf (test, true, true); +} + +static void flr_vf_fails_on_send (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_fail); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +KUNIT_EXPECT_NE (test, err, -ETIMEDOUT ); +KUNIT_EXPECT_NE (test, err, -ECANCELED ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void flr_vf_fails_on_reset (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.vfs[VFUT1 ].config.sanitize, + sanitize_vf_resources_fail); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +KUNIT_EXPECT_NE (test, err, -ETIMEDOUT ); +KUNIT_EXPECT_NE (test, err, -ECANCELED ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void flr_vf_rejected_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_reject); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +KUNIT_EXPECT_NE (test, err, -ETIMEDOUT ); +KUNIT_EXPECT_NE (test, err, -ECANCELED ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void flr_vf_unconfirmed_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_no_reply); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +KUNIT_EXPECT_EQ (test, err, -ETIMEDOUT ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +} + +static void flr_vf_confirmed_early_continue_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , flr_starting,ARRAY_SIZE (flr_starting)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_no_reply); + +pf_handle_vf_flr_done (gt,VFUT1 ); + +/* +* make sure SEND_START completes; +* successful reply from cmd_pass_no_reply should exit mismatch state +*/ +flush_work (>->sriov.pf.control.worker); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +} + +static void flr_vf_confirmed_early_reject_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , flr_starting,ARRAY_SIZE (flr_starting)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_reject); + +pf_handle_vf_flr_done (gt,VFUT1 ); + +/* +* make sure SEND_START completes; +* error from send_vf_control_cmd_reject should keep mismatch state +*/ +flush_work (>->sriov.pf.control.worker); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void flr_vf_confirmed_twice_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , flr_guc_done,ARRAY_SIZE (flr_guc_done)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_no_reply); + +pf_handle_vf_flr_done (gt,VFUT1 ); + +/* this is fully recoverable */ +KUNIT_EXPECT_EQ (test,0 ,pf_wait_vf_wip_done (gt,VFUT1 ,HZ )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +} + +static void flr_vf_confirmed_too_late_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , flr_failed,ARRAY_SIZE (flr_failed)); + +pf_handle_vf_flr_done (gt,VFUT1 ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void flr_vf_unsolicited_confirmation_from_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); + +pf_handle_vf_flr_done (gt,VFUT1 ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +} + +static void flr_vf_wrong_confirmation_from_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , flr_waiting,ARRAY_SIZE (flr_waiting)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +pf_handle_vf_pause_done (gt,VFUT1 ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +} + +static void flr_vf_canceled_by_restart (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_busy_wait); + +xe_kunit_helper_delayed_call (test,HZ /10 , xe_gt_sriov_pf_control_restart, gt); + +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +expect_not_in_flr (test); +} + +static void try_stop_vf (struct kunit *test,bool mimic_busy) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + mimic_busy ? send_vf_control_cmd_busy_and_reply : + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOPPED )); +expect_not_stopping (test); +expect_not_in_pause (test); +expect_not_in_resume (test); +expect_not_in_mismatch (test); +} + +static void stop_vf_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_stop_vf (test, false); +} + +static void stop_vf_needs_retry_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_stop_vf (test, true); +} + +static void stop_vf_refused_from (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +prepare_state_from_param (test); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); +KUNIT_EXPECT_NE (test, err, -ECANCELED ); + +KUNIT_EXPECT_TRUE (test, err == -EALREADY || +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOP_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOP_FAILED )); +} + +static void stop_vf_fails_on_send (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_fail); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); +KUNIT_EXPECT_NE (test, err, -ETIMEDOUT ); +KUNIT_EXPECT_NE (test, err, -ECANCELED ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOP_FAILED )); +expect_not_stopping (test); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOPPED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void stop_vf_rejected_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_reject); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); +KUNIT_EXPECT_NE (test, err, -ETIMEDOUT ); +KUNIT_EXPECT_NE (test, err, -ECANCELED ); + +expect_not_stopping (test); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOP_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOPPED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void stop_vf_canceled_from (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state_from_param (test); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOP_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOPPED )); +} + +static void stop_vf_canceled_by_restart (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_busy_except_flr); + +xe_kunit_helper_delayed_call (test,HZ /10 , xe_gt_sriov_pf_control_restart, gt); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); +expect_not_in_stop (test); +} + +static void stop_vf_canceled_by_flr (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_busy_except_flr); + +xe_kunit_helper_delayed_call (test,HZ /10 , + xe_gt_sriov_pf_control_trigger_flr, gt,VFUT1 ); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); +expect_not_in_stop (test); +} + +static void try_pause_vf (struct kunit *test,bool mimic_busy) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + mimic_busy ? send_vf_control_cmd_busy_and_reply : + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSED )); +expect_not_pausing (test); +expect_not_in_mismatch (test); +} + +static void pause_vf_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_pause_vf (test, false); +} + +static void pause_vf_needs_retry_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_pause_vf (test, true); +} + +static void pause_vf_canceled_from (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state_from_param (test); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +expect_not_in_pause (test); +} + +static void pause_vf_refused_from (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +prepare_state_from_param (test); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +KUNIT_EXPECT_NE (test, err, -ECANCELED ); + +KUNIT_EXPECT_TRUE (test, err == -EALREADY || +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_FAILED )); +} + +static void pause_vf_rejected_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_reject); + +KUNIT_EXPECT_NE (test,0 ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void pause_vf_fails_on_send (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_fail); + +KUNIT_EXPECT_NE (test,0 ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void pause_vf_unconfirmed_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_no_reply); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +KUNIT_EXPECT_EQ (test, err, -ETIMEDOUT ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_FAILED )); +} + +static void pause_vf_canceled_by_restart (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_no_reply); + +xe_kunit_helper_delayed_call (test,HZ /10 , xe_gt_sriov_pf_control_restart, gt); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +expect_not_in_pause (test); +} + +static void pause_vf_canceled_by_flr (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_but_reply_flr_only); + +xe_kunit_helper_delayed_call (test,HZ /10 , + xe_gt_sriov_pf_control_trigger_flr, gt,VFUT1 ); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +expect_not_in_pause (test); +} + +static void pause_vf_canceled_by_stop (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_no_reply); + +xe_kunit_helper_delayed_call (test,HZ /10 , + xe_gt_sriov_pf_control_stop_vf, gt,VFUT1 ); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +expect_not_in_pause (test); +} + +static void try_resume_vf (struct kunit *test,bool mimic_busy) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + mimic_busy ? send_vf_control_cmd_busy_and_reply : + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUMED )); +expect_not_resuming (test); +expect_not_in_pause (test); +expect_not_in_mismatch (test); +expect_not_in_wip (test); +} + +static void resume_vf_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_resume_vf (test, false); +} + +static void resume_vf_needs_retry_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_resume_vf (test, true); +} + +static void resume_vf_fails_on_send (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , paused,ARRAY_SIZE (paused)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_fail); + +KUNIT_EXPECT_NE (test,0 ,xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_FAILED )); + +expect_not_resuming (test); +expect_not_in_mismatch (test); +expect_not_in_wip (test); +} + +static void resume_vf_rejected_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , paused,ARRAY_SIZE (paused)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_reject); + +KUNIT_EXPECT_NE (test,0 ,xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_FAILED )); + +expect_not_resuming (test); +expect_not_in_wip (test); +} + +static void resume_vf_canceled_from (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state_from_param (test); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUMED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_FAILED )); +expect_not_resuming (test); +} + +static void resume_vf_refused_from (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +prepare_state_from_param (test); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); +KUNIT_EXPECT_NE (test, err, -EIO ); + +KUNIT_EXPECT_TRUE (test, err == -EALREADY || +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_FAILED )); +} + +static void resume_vf_canceled_by_restart (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , paused,ARRAY_SIZE (paused)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_busy_except_flr); + +xe_kunit_helper_delayed_call (test,HZ /10 , xe_gt_sriov_pf_control_restart, gt); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUMED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_WIP )); +} + +static void resume_vf_canceled_by_flr (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , paused,ARRAY_SIZE (paused)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_busy_except_flr); + +xe_kunit_helper_delayed_call (test,HZ /10 , + xe_gt_sriov_pf_control_trigger_flr, gt,VFUT1 ); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUMED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_WIP )); +} + +static void resume_vf_canceled_by_stop (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , paused,ARRAY_SIZE (paused)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_busy_except_stop); + +xe_kunit_helper_delayed_call (test,HZ /10 , + xe_gt_sriov_pf_control_stop_vf, gt,VFUT1 ); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUMED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_WIP )); +} + +static void basic_pause_and_resume_vf (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_ASSERT_EQ (test,0 ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); +} + +static void basic_pause_and_stop_vf (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_ASSERT_EQ (test,0 ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); +} + +static void basic_stop_and_flr_vf (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +} + +static void basic_flr_and_flr_vf (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +} + +static void basic_flr_vfs (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_trigger_flr (gt,VFUT2 )); +} + +static struct kunit_case pf_control_test_cases[] = { +KUNIT_CASE (basic_pause_and_resume_vf), +KUNIT_CASE (basic_pause_and_stop_vf), +KUNIT_CASE (basic_stop_and_flr_vf), +KUNIT_CASE (basic_flr_and_flr_vf), +KUNIT_CASE (basic_flr_vfs), + +KUNIT_CASE_PARAM (flr_vf_from, flr_must_pass_from_gen_params), +KUNIT_CASE_PARAM (flr_vf_needs_retry_from, flr_must_pass_from_gen_params), +KUNIT_CASE_PARAM (flr_vf_needs_retry_late_from, flr_must_pass_from_gen_params), +KUNIT_CASE (flr_vf_fails_on_send), +KUNIT_CASE (flr_vf_fails_on_reset), +KUNIT_CASE (flr_vf_rejected_by_guc), +KUNIT_CASE_SLOW (flr_vf_unconfirmed_by_guc), +KUNIT_CASE (flr_vf_confirmed_early_continue_by_guc), +KUNIT_CASE (flr_vf_confirmed_early_reject_by_guc), +KUNIT_CASE (flr_vf_confirmed_twice_by_guc), +KUNIT_CASE (flr_vf_confirmed_too_late_by_guc), +KUNIT_CASE (flr_vf_wrong_confirmation_from_guc), +KUNIT_CASE (flr_vf_unsolicited_confirmation_from_guc), +KUNIT_CASE (flr_vf_canceled_by_restart), + +KUNIT_CASE_PARAM (stop_vf_from, stop_must_pass_from_gen_params), +KUNIT_CASE_PARAM (stop_vf_needs_retry_from, stop_must_pass_from_gen_params), +KUNIT_CASE_PARAM (stop_vf_refused_from, stop_must_fail_from_gen_params), +KUNIT_CASE_PARAM (stop_vf_canceled_from, stop_must_cancel_from_gen_params), +KUNIT_CASE (stop_vf_fails_on_send), +KUNIT_CASE (stop_vf_rejected_by_guc), +KUNIT_CASE (stop_vf_canceled_by_flr), +KUNIT_CASE (stop_vf_canceled_by_restart), + +KUNIT_CASE_PARAM (pause_vf_from, pause_must_pass_from_gen_params), +KUNIT_CASE_PARAM (pause_vf_needs_retry_from, pause_must_pass_from_gen_params), +KUNIT_CASE_PARAM (pause_vf_refused_from, pause_must_fail_from_gen_params), +KUNIT_CASE_PARAM (pause_vf_canceled_from, pause_must_cancel_from_gen_params), +KUNIT_CASE (pause_vf_fails_on_send), +KUNIT_CASE (pause_vf_rejected_by_guc), +KUNIT_CASE_SLOW (pause_vf_unconfirmed_by_guc), +KUNIT_CASE (pause_vf_canceled_by_flr), +KUNIT_CASE (pause_vf_canceled_by_stop), +KUNIT_CASE (pause_vf_canceled_by_restart), + +KUNIT_CASE_PARAM (resume_vf_from, resume_must_pass_from_gen_params), +KUNIT_CASE_PARAM (resume_vf_needs_retry_from, resume_must_pass_from_gen_params), +KUNIT_CASE_PARAM (resume_vf_refused_from, resume_must_fail_from_gen_params), +KUNIT_CASE_PARAM (resume_vf_canceled_from, resume_must_cancel_from_gen_params), +KUNIT_CASE (resume_vf_fails_on_send), +KUNIT_CASE (resume_vf_rejected_by_guc), +KUNIT_CASE (resume_vf_canceled_by_flr), +KUNIT_CASE (resume_vf_canceled_by_stop), +KUNIT_CASE (resume_vf_canceled_by_restart), + + {} +}; + +static struct kunit_suite pf_control_suite = { + .name ="pf_control" , + .test_cases = pf_control_test_cases, + .init = pf_control_test_init, +}; + +kunit_test_suite (pf_control_suite);
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +7 -0
@@ -4,6 +4,7 @@*/ #include <drm/drm_managed.h> +#include <kunit/static_stub.h> #include "abi/guc_actions_sriov_abi.h"
@@ -196,6 +197,8 @@ static const char *control_bit_to_string(enum xe_gt_sriov_control_bits bit)static unsigned long pf_get_default_timeout (enum xe_gt_sriov_control_bits bit) { +KUNIT_STATIC_STUB_REDIRECT (pf_get_default_timeout, bit); +switch (bit) {case XE_GT_SRIOV_STATE_FLR_WAIT_GUC :case XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC :
@@ -1458,3 +1461,7 @@ void xe_gt_sriov_pf_control_restart(struct xe_gt *gt)for (n =1 ; n <= totalvfs; n++)pf_enter_vf_ready (gt, n); } + +#if IS_BUILTIN (CONFIG_DRM_XE_KUNIT_TEST ) +#include "tests/xe_gt_sriov_pf_control_kunit.c" +#endif
Signature · 1 line
2.43.0
PATCH v2 11/12 drm/xe/tests: Add KUnit tests for VF control state machines
Add KUnit tests (~200) for all VF control state machines (FLR, PAUSE, STOP and RESUME) to make sure they work as expected and will not be broken while extending them with new functionality.
---
Test file named according to the new best practices [1]
[1] https://lore.kernel.org/linux-hardening/[email protected]/
---
v2: fix kunit build break due last-minute change in .c
--- .../xe/tests/xe_gt_sriov_pf_control_kunit.c | 1360 +++++++++++++++++ drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c | 7 + 2 files changed, 1367 insertions(+) create mode 100644 drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c
drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c new file +1360 -0
@@ -0,0 +1,1360 @@ +// SPDX-License-Identifier: GPL-2.0 AND MIT +/* +* Copyright © 2024 Intel Corporation +*/ + +#include <kunit/test.h> +#include <kunit/static_stub.h> + +#include "tests/xe_kunit_helpers.h" +#include "tests/xe_pci_test.h" + +#include "xe_gt_sriov_pf.h" + +static const unsigned int DUT_NUM_VFS =2 ; +static const unsigned int VFUT1 =VFID (1 ); +static const unsigned int VFUT2 =VFID (2 ); + +static void dump_state (void *arg) +{ +struct xe_gt *gt = arg; + +pf_dump_vf_state (gt,VFUT1 ); +} + +static unsigned long replacement_timeout (enum xe_gt_sriov_control_bits bit) +{ +return HZ ; +} + +static int pf_control_test_init (struct kunit *test) +{ +struct xe_pci_fake_data fake = { + .sriov_mode =XE_SRIOV_MODE_PF , + .platform =XE_TIGERLAKE ,/* some random platform */ + .subplatform =XE_SUBPLATFORM_NONE , + }; +struct xe_device *xe; +struct xe_gt *gt; + + test->priv = &fake; +xe_kunit_helper_xe_device_test_init (test); + + xe = test->priv; +KUNIT_ASSERT_EQ (test,xe_sriov_init (xe),0 ); + + xe->sriov.pf.driver_max_vfs =DUT_NUM_VFS ; +KUNIT_EXPECT_NE (test,xe_sriov_pf_get_totalvfs (xe),0 ); + + gt =xe_device_get_gt (xe,0 ); +KUNIT_ASSERT_EQ (test,xe_gt_sriov_pf_init_early (gt),0 ); + +KUNIT_ASSERT_EQ (test,0ul , *pf_peek_vf_state (gt,VFUT1 )); +KUNIT_ASSERT_EQ (test,0ul , *pf_peek_vf_state (gt,VFUT2 )); + +KUNIT_EXPECT_EQ (test,0 ,kunit_add_action_or_reset (test, dump_state, gt)); + +kunit_activate_static_stub (test, pf_get_default_timeout, replacement_timeout); + + test->priv = gt; +return 0 ; +} + +static int sanitize_vf_resources_fail (struct xe_gt *gt,u32 vfid,long timeout) +{ +return -ETIMEDOUT ; +} + +static int send_vf_control_cmd_reject (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +return -EIO ; +} + +static int send_vf_control_cmd_fail (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +return -ENODEV ; +} + +static int send_vf_control_cmd_pass_no_reply (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +return 0 ; +} + +static int send_vf_control_cmd_pass_and_reply (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +switch (cmd) { +case GUC_PF_TRIGGER_VF_PAUSE : +pf_handle_vf_event (gt, vfid,GUC_PF_NOTIFY_VF_PAUSE_DONE ); +break ; +case GUC_PF_TRIGGER_VF_FLR_START : +pf_handle_vf_event (gt, vfid,GUC_PF_NOTIFY_VF_FLR_DONE ); +break ; +case GUC_PF_TRIGGER_VF_RESUME : +case GUC_PF_TRIGGER_VF_STOP : +case GUC_PF_TRIGGER_VF_FLR_FINISH : +break ; +default : +return -EPROTO ; + } +return 0 ; +} + +static int send_vf_control_cmd_busy_wait (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +schedule_timeout_interruptible (HZ /20 ); +return -EBUSY ; +} + +static int send_vf_control_cmd_pass_but_reply_flr_only (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +return cmd ==GUC_PF_TRIGGER_VF_FLR_START ? +send_vf_control_cmd_pass_and_reply (gt, vfid, cmd) : +send_vf_control_cmd_pass_no_reply (gt, vfid, cmd); +} + +static int send_vf_control_cmd_busy_except_flr (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +return cmd ==GUC_PF_TRIGGER_VF_FLR_START || cmd ==GUC_PF_TRIGGER_VF_FLR_FINISH ? +send_vf_control_cmd_pass_and_reply (gt, vfid, cmd) : +send_vf_control_cmd_busy_wait (gt, vfid, cmd); +} + +static int send_vf_control_cmd_busy_except_stop (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +return cmd ==GUC_PF_TRIGGER_VF_STOP ? +send_vf_control_cmd_pass_and_reply (gt, vfid, cmd) : +send_vf_control_cmd_busy_wait (gt, vfid, cmd); +} + +static int BUSY_MAGIC =3 ; + +static int send_vf_control_cmd_busy_no_reply (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +static int counter; + +return ++counter %BUSY_MAGIC ? -EBUSY :0 ; +} + +static int send_vf_control_cmd_busy_and_reply (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +static int counter; + +return ++counter %BUSY_MAGIC ? -EBUSY : +send_vf_control_cmd_pass_and_reply (gt, vfid, cmd); +} + +static const enum xe_gt_sriov_control_bits ready[] = { +}; + +static const enum xe_gt_sriov_control_bits flr_starting[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_FLR_WIP , +XE_GT_SRIOV_STATE_FLR_SEND_START , +}; + +static const enum xe_gt_sriov_control_bits flr_starting_paused[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_FLR_WIP , +XE_GT_SRIOV_STATE_FLR_SEND_START , +XE_GT_SRIOV_STATE_PAUSED , +}; + +static const enum xe_gt_sriov_control_bits flr_starting_stopped[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_FLR_WIP , +XE_GT_SRIOV_STATE_FLR_SEND_START , +XE_GT_SRIOV_STATE_STOPPED , +}; + +static const enum xe_gt_sriov_control_bits flr_waiting[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_FLR_WIP , +XE_GT_SRIOV_STATE_FLR_WAIT_GUC , +}; + +static const enum xe_gt_sriov_control_bits flr_guc_done[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_FLR_WIP , +XE_GT_SRIOV_STATE_FLR_GUC_DONE , +}; + +static const enum xe_gt_sriov_control_bits flr_resetting[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_FLR_WIP , +XE_GT_SRIOV_STATE_FLR_RESET_CONFIG , +}; + +static const enum xe_gt_sriov_control_bits flr_finishing[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_FLR_WIP , +XE_GT_SRIOV_STATE_FLR_SEND_FINISH , +}; + +static const enum xe_gt_sriov_control_bits flr_failed[] = { +XE_GT_SRIOV_STATE_FLR_FAILED , +}; + +static const enum xe_gt_sriov_control_bits stopping[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_STOP_WIP , +XE_GT_SRIOV_STATE_STOP_SEND_STOP , +}; + +static const enum xe_gt_sriov_control_bits stopping_paused[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_STOP_WIP , +XE_GT_SRIOV_STATE_STOP_SEND_STOP , +XE_GT_SRIOV_STATE_PAUSED , +}; + +static const enum xe_gt_sriov_control_bits stop_failed[] = { +XE_GT_SRIOV_STATE_STOP_FAILED , +}; + +static const enum xe_gt_sriov_control_bits stop_rejected[] = { +XE_GT_SRIOV_STATE_STOP_FAILED , +XE_GT_SRIOV_STATE_MISMATCH , +}; + +static const enum xe_gt_sriov_control_bits stopped[] = { +XE_GT_SRIOV_STATE_STOPPED , +}; + +static const enum xe_gt_sriov_control_bits pausing[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_PAUSE_WIP , +XE_GT_SRIOV_STATE_PAUSE_SEND_PAUSE , +}; + +static const enum xe_gt_sriov_control_bits pausing_wait_guc[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_PAUSE_WIP , +XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC , +}; + +static const enum xe_gt_sriov_control_bits pausing_guc_done[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_PAUSE_WIP , +XE_GT_SRIOV_STATE_PAUSE_GUC_DONE , +}; + +static const enum xe_gt_sriov_control_bits pause_failed[] = { +XE_GT_SRIOV_STATE_PAUSE_FAILED , +}; + +static const enum xe_gt_sriov_control_bits pause_rejected[] = { +XE_GT_SRIOV_STATE_PAUSE_FAILED , +XE_GT_SRIOV_STATE_MISMATCH , +}; + +static const enum xe_gt_sriov_control_bits paused[] = { +XE_GT_SRIOV_STATE_PAUSED , +}; + +static const enum xe_gt_sriov_control_bits resuming[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_PAUSED , +XE_GT_SRIOV_STATE_RESUME_WIP , +XE_GT_SRIOV_STATE_RESUME_SEND_RESUME , +}; + +static const enum xe_gt_sriov_control_bits resume_failed[] = { +XE_GT_SRIOV_STATE_PAUSED , +XE_GT_SRIOV_STATE_RESUME_FAILED , +}; + +static const enum xe_gt_sriov_control_bits resume_rejected[] = { +XE_GT_SRIOV_STATE_PAUSED , +XE_GT_SRIOV_STATE_RESUME_FAILED , +XE_GT_SRIOV_STATE_MISMATCH , +}; + +static const enum xe_gt_sriov_control_bits resumed[] = { +XE_GT_SRIOV_STATE_RESUMED , +}; + +static const enum xe_gt_sriov_control_bits mismatch[] = { +XE_GT_SRIOV_STATE_MISMATCH , +}; + +struct state_param { +const char *name; +const enum xe_gt_sriov_control_bits *bits; +size_t num_bits; +}; + +static void state_param_get_desc (struct state_param *p,char *desc) +{ +snprintf (desc,KUNIT_PARAM_DESC_SIZE ,"%s" , p->name); +} + +#define MAKE_STATE_PARAM (X ) { .name = #X, .bits = X, .num_bits = ARRAY_SIZE(X) } + +/* +* Due to the test case logic the all "must_pass" params include "_rejected" states +* since our "GuC" calls by default will not complain again about the INVALID_STATE +* thus our state machine is able to fully recover. +*/ + +static struct state_param flr_must_pass_from[] = { +MAKE_STATE_PARAM (ready), +MAKE_STATE_PARAM (flr_starting), +MAKE_STATE_PARAM (flr_starting_paused), +MAKE_STATE_PARAM (flr_starting_stopped), +MAKE_STATE_PARAM (flr_waiting), +MAKE_STATE_PARAM (flr_guc_done), +MAKE_STATE_PARAM (flr_resetting), +MAKE_STATE_PARAM (flr_finishing), +MAKE_STATE_PARAM (flr_failed), +MAKE_STATE_PARAM (stopping), +MAKE_STATE_PARAM (stop_failed), +MAKE_STATE_PARAM (stop_rejected), +MAKE_STATE_PARAM (stopped), +MAKE_STATE_PARAM (pausing), +MAKE_STATE_PARAM (pausing_wait_guc), +MAKE_STATE_PARAM (pausing_guc_done), +MAKE_STATE_PARAM (pause_failed), +MAKE_STATE_PARAM (pause_rejected), +MAKE_STATE_PARAM (paused), +MAKE_STATE_PARAM (resuming), +MAKE_STATE_PARAM (resume_failed), +MAKE_STATE_PARAM (resume_rejected), +MAKE_STATE_PARAM (resumed), +MAKE_STATE_PARAM (mismatch), +}; + +static struct state_param stop_must_pass_from[] = { +MAKE_STATE_PARAM (ready), +MAKE_STATE_PARAM (stop_failed), +MAKE_STATE_PARAM (stop_rejected), +MAKE_STATE_PARAM (pausing), +MAKE_STATE_PARAM (pausing_wait_guc), +MAKE_STATE_PARAM (pausing_guc_done), +MAKE_STATE_PARAM (pause_failed), +MAKE_STATE_PARAM (pause_rejected), +MAKE_STATE_PARAM (paused), +MAKE_STATE_PARAM (resuming), +MAKE_STATE_PARAM (resume_failed), +MAKE_STATE_PARAM (resume_rejected), +MAKE_STATE_PARAM (resumed), +MAKE_STATE_PARAM (mismatch), +MAKE_STATE_PARAM (flr_failed), +}; + +static struct state_param stop_must_cancel_from[] = { +MAKE_STATE_PARAM (flr_starting), +MAKE_STATE_PARAM (flr_starting_paused), +MAKE_STATE_PARAM (flr_waiting), +MAKE_STATE_PARAM (flr_guc_done), +MAKE_STATE_PARAM (flr_resetting), +MAKE_STATE_PARAM (flr_finishing), +}; + +static struct state_param stop_must_fail_from[] = { +MAKE_STATE_PARAM (stopping), +MAKE_STATE_PARAM (stopping_paused), +MAKE_STATE_PARAM (stopped), +MAKE_STATE_PARAM (flr_starting_stopped), +}; + +static struct state_param pause_must_pass_from[] = { +MAKE_STATE_PARAM (ready), +MAKE_STATE_PARAM (pause_failed), +MAKE_STATE_PARAM (pause_rejected), +MAKE_STATE_PARAM (resumed), +MAKE_STATE_PARAM (mismatch), +MAKE_STATE_PARAM (stop_failed), +MAKE_STATE_PARAM (stop_rejected), +MAKE_STATE_PARAM (flr_failed), +}; + +static struct state_param pause_must_cancel_from[] = { +MAKE_STATE_PARAM (flr_starting), +MAKE_STATE_PARAM (flr_waiting), +MAKE_STATE_PARAM (flr_guc_done), +MAKE_STATE_PARAM (flr_resetting), +MAKE_STATE_PARAM (flr_finishing), +MAKE_STATE_PARAM (stopping), +}; + +static struct state_param pause_must_fail_from[] = { +MAKE_STATE_PARAM (pausing), +MAKE_STATE_PARAM (pausing_wait_guc), +MAKE_STATE_PARAM (pausing_guc_done), +MAKE_STATE_PARAM (paused), +MAKE_STATE_PARAM (resuming), +MAKE_STATE_PARAM (resume_failed), +MAKE_STATE_PARAM (resume_rejected), +MAKE_STATE_PARAM (stopped), +}; + +static struct state_param resume_must_pass_from[] = { +MAKE_STATE_PARAM (paused), +MAKE_STATE_PARAM (resume_failed), +MAKE_STATE_PARAM (resume_rejected), +}; + +static struct state_param resume_must_cancel_from[] = { +MAKE_STATE_PARAM (flr_starting_paused), +MAKE_STATE_PARAM (stopping_paused), +}; + +static struct state_param resume_must_fail_from[] = { +MAKE_STATE_PARAM (ready), +MAKE_STATE_PARAM (pausing), +MAKE_STATE_PARAM (pausing_wait_guc), +MAKE_STATE_PARAM (pausing_guc_done), +MAKE_STATE_PARAM (pause_failed), +MAKE_STATE_PARAM (pause_rejected), +MAKE_STATE_PARAM (resuming), +MAKE_STATE_PARAM (resumed), +MAKE_STATE_PARAM (stopping), +MAKE_STATE_PARAM (stop_failed), +MAKE_STATE_PARAM (stop_rejected), +MAKE_STATE_PARAM (stopped), +MAKE_STATE_PARAM (flr_starting), +MAKE_STATE_PARAM (flr_waiting), +MAKE_STATE_PARAM (flr_guc_done), +MAKE_STATE_PARAM (flr_resetting), +MAKE_STATE_PARAM (flr_finishing), +MAKE_STATE_PARAM (flr_failed), +MAKE_STATE_PARAM (mismatch), +}; + +KUNIT_ARRAY_PARAM (flr_must_pass_from, flr_must_pass_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (stop_must_pass_from, stop_must_pass_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (stop_must_fail_from, stop_must_fail_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (stop_must_cancel_from, stop_must_cancel_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (pause_must_pass_from, pause_must_pass_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (pause_must_fail_from, pause_must_fail_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (pause_must_cancel_from, pause_must_cancel_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (resume_must_pass_from, resume_must_pass_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (resume_must_fail_from, resume_must_fail_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (resume_must_cancel_from, resume_must_cancel_from, state_param_get_desc); + +static int mimic_pf_handle_vf_flr_done (struct xe_gt *gt,unsigned int vfid) +{ +pf_handle_vf_flr_done (gt, vfid); +return 0 ; +} + +static int mimic_pf_handle_vf_pause_done (struct xe_gt *gt,unsigned int vfid) +{ +pf_handle_vf_pause_done (gt, vfid); +return 0 ; +} + +static void prepare_state (struct kunit *test,unsigned int vfid, +const enum xe_gt_sriov_control_bits *bits,size_t num_bits) +{ +struct xe_gt *gt = test->priv; +size_t n; + +for (n =0 ; n < num_bits; n++) { +enum xe_gt_sriov_control_bits bit = bits[n]; + +KUNIT_ASSERT_TRUE (test,pf_enter_vf_state (gt, vfid, bit)); + +if (bit ==XE_GT_SRIOV_STATE_WIP ) { +pf_queue_vf (gt, vfid); + }else if (bit ==XE_GT_SRIOV_STATE_FLR_WAIT_GUC ) { +xe_kunit_helper_delayed_call (test,HZ /100 , + mimic_pf_handle_vf_flr_done, gt, vfid); + }else if (bit ==XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC ) { +xe_kunit_helper_delayed_call (test,HZ /100 , + mimic_pf_handle_vf_pause_done, gt, vfid); + } + } +} + +static void prepare_state_from_param (struct kunit *test) +{ +const struct state_param *p = test->param_value; + +prepare_state (test,VFUT1 , p->bits, p->num_bits); +} + +static void expect_not_pausing (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_WIP )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_SEND_PAUSE )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_GUC_DONE )); +} + +static void expect_not_in_pause (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +expect_not_pausing (test); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_FAILED )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSED )); +} + +static void expect_not_resuming (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_WIP )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_SEND_RESUME )); +} + +static void expect_not_in_resume (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +expect_not_resuming (test); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_FAILED )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUMED )); +} + +static void expect_not_stopping (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOP_WIP )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOP_SEND_STOP )); +} + +static void expect_not_in_stop (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +expect_not_stopping (test); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOP_FAILED )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOPPED )); +} + +static void expect_not_in_flr (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_SEND_START )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WAIT_GUC )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_GUC_DONE )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_SEND_FINISH )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +} + +static void expect_not_in_wip (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void expect_not_in_mismatch (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +} + +static void try_flr_vf (struct kunit *test,bool mimic_busy,bool late_reply) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + mimic_busy ? late_reply ? send_vf_control_cmd_busy_no_reply : + send_vf_control_cmd_busy_and_reply : + late_reply ? send_vf_control_cmd_pass_no_reply : + send_vf_control_cmd_pass_and_reply); + +if (late_reply) +xe_kunit_helper_delayed_call (test,HZ /10 , + mimic_pf_handle_vf_flr_done, gt,VFUT1 ); + +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); + +expect_not_in_flr (test); +expect_not_in_pause (test); +expect_not_in_resume (test); +expect_not_in_stop (test); +expect_not_in_mismatch (test); +expect_not_in_wip (test); +} + +static void flr_vf_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_flr_vf (test, false, false); +} + +static void flr_vf_needs_retry_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_flr_vf (test, true, false); +} + +static void flr_vf_needs_retry_late_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_flr_vf (test, true, true); +} + +static void flr_vf_fails_on_send (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_fail); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +KUNIT_EXPECT_NE (test, err, -ETIMEDOUT ); +KUNIT_EXPECT_NE (test, err, -ECANCELED ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void flr_vf_fails_on_reset (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.vfs[VFUT1 ].config.sanitize, + sanitize_vf_resources_fail); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +KUNIT_EXPECT_NE (test, err, -ETIMEDOUT ); +KUNIT_EXPECT_NE (test, err, -ECANCELED ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void flr_vf_rejected_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_reject); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +KUNIT_EXPECT_NE (test, err, -ETIMEDOUT ); +KUNIT_EXPECT_NE (test, err, -ECANCELED ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void flr_vf_unconfirmed_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_no_reply); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +KUNIT_EXPECT_EQ (test, err, -ETIMEDOUT ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +} + +static void flr_vf_confirmed_early_continue_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , flr_starting,ARRAY_SIZE (flr_starting)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_no_reply); + +pf_handle_vf_flr_done (gt,VFUT1 ); + +/* +* make sure SEND_START completes; +* successful reply from cmd_pass_no_reply should exit mismatch state +*/ +flush_work (>->sriov.pf.control.worker); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +} + +static void flr_vf_confirmed_early_reject_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , flr_starting,ARRAY_SIZE (flr_starting)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_reject); + +pf_handle_vf_flr_done (gt,VFUT1 ); + +/* +* make sure SEND_START completes; +* error from send_vf_control_cmd_reject should keep mismatch state +*/ +flush_work (>->sriov.pf.control.worker); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void flr_vf_confirmed_twice_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , flr_guc_done,ARRAY_SIZE (flr_guc_done)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_no_reply); + +pf_handle_vf_flr_done (gt,VFUT1 ); + +/* this is fully recoverable */ +KUNIT_EXPECT_EQ (test,0 ,pf_wait_vf_wip_done (gt,VFUT1 ,HZ )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +} + +static void flr_vf_confirmed_too_late_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , flr_failed,ARRAY_SIZE (flr_failed)); + +pf_handle_vf_flr_done (gt,VFUT1 ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void flr_vf_unsolicited_confirmation_from_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); + +pf_handle_vf_flr_done (gt,VFUT1 ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +} + +static void flr_vf_wrong_confirmation_from_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , flr_waiting,ARRAY_SIZE (flr_waiting)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +pf_handle_vf_pause_done (gt,VFUT1 ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +} + +static void flr_vf_canceled_by_restart (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_busy_wait); + +xe_kunit_helper_delayed_call (test,HZ /10 , xe_gt_sriov_pf_control_restart, gt); + +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +expect_not_in_flr (test); +} + +static void try_stop_vf (struct kunit *test,bool mimic_busy) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + mimic_busy ? send_vf_control_cmd_busy_and_reply : + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOPPED )); +expect_not_stopping (test); +expect_not_in_pause (test); +expect_not_in_resume (test); +expect_not_in_mismatch (test); +} + +static void stop_vf_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_stop_vf (test, false); +} + +static void stop_vf_needs_retry_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_stop_vf (test, true); +} + +static void stop_vf_refused_from (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +prepare_state_from_param (test); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); +KUNIT_EXPECT_NE (test, err, -ECANCELED ); + +KUNIT_EXPECT_TRUE (test, err == -EALREADY || +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOP_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOP_FAILED )); +} + +static void stop_vf_fails_on_send (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_fail); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); +KUNIT_EXPECT_NE (test, err, -ETIMEDOUT ); +KUNIT_EXPECT_NE (test, err, -ECANCELED ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOP_FAILED )); +expect_not_stopping (test); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOPPED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void stop_vf_rejected_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_reject); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); +KUNIT_EXPECT_NE (test, err, -ETIMEDOUT ); +KUNIT_EXPECT_NE (test, err, -ECANCELED ); + +expect_not_stopping (test); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOP_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOPPED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void stop_vf_canceled_from (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state_from_param (test); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOP_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOPPED )); +} + +static void stop_vf_canceled_by_restart (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_busy_except_flr); + +xe_kunit_helper_delayed_call (test,HZ /10 , xe_gt_sriov_pf_control_restart, gt); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); +expect_not_in_stop (test); +} + +static void stop_vf_canceled_by_flr (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_busy_except_flr); + +xe_kunit_helper_delayed_call (test,HZ /10 , + xe_gt_sriov_pf_control_trigger_flr, gt,VFUT1 ); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); +expect_not_in_stop (test); +} + +static void try_pause_vf (struct kunit *test,bool mimic_busy) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + mimic_busy ? send_vf_control_cmd_busy_and_reply : + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSED )); +expect_not_pausing (test); +expect_not_in_mismatch (test); +} + +static void pause_vf_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_pause_vf (test, false); +} + +static void pause_vf_needs_retry_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_pause_vf (test, true); +} + +static void pause_vf_canceled_from (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state_from_param (test); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +expect_not_in_pause (test); +} + +static void pause_vf_refused_from (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +prepare_state_from_param (test); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +KUNIT_EXPECT_NE (test, err, -ECANCELED ); + +KUNIT_EXPECT_TRUE (test, err == -EALREADY || +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_FAILED )); +} + +static void pause_vf_rejected_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_reject); + +KUNIT_EXPECT_NE (test,0 ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void pause_vf_fails_on_send (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_fail); + +KUNIT_EXPECT_NE (test,0 ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void pause_vf_unconfirmed_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_no_reply); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +KUNIT_EXPECT_EQ (test, err, -ETIMEDOUT ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_FAILED )); +} + +static void pause_vf_canceled_by_restart (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_no_reply); + +xe_kunit_helper_delayed_call (test,HZ /10 , xe_gt_sriov_pf_control_restart, gt); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +expect_not_in_pause (test); +} + +static void pause_vf_canceled_by_flr (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_but_reply_flr_only); + +xe_kunit_helper_delayed_call (test,HZ /10 , + xe_gt_sriov_pf_control_trigger_flr, gt,VFUT1 ); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +expect_not_in_pause (test); +} + +static void pause_vf_canceled_by_stop (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_no_reply); + +xe_kunit_helper_delayed_call (test,HZ /10 , + xe_gt_sriov_pf_control_stop_vf, gt,VFUT1 ); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +expect_not_in_pause (test); +} + +static void try_resume_vf (struct kunit *test,bool mimic_busy) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + mimic_busy ? send_vf_control_cmd_busy_and_reply : + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUMED )); +expect_not_resuming (test); +expect_not_in_pause (test); +expect_not_in_mismatch (test); +expect_not_in_wip (test); +} + +static void resume_vf_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_resume_vf (test, false); +} + +static void resume_vf_needs_retry_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_resume_vf (test, true); +} + +static void resume_vf_fails_on_send (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , paused,ARRAY_SIZE (paused)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_fail); + +KUNIT_EXPECT_NE (test,0 ,xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_FAILED )); + +expect_not_resuming (test); +expect_not_in_mismatch (test); +expect_not_in_wip (test); +} + +static void resume_vf_rejected_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , paused,ARRAY_SIZE (paused)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_reject); + +KUNIT_EXPECT_NE (test,0 ,xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_FAILED )); + +expect_not_resuming (test); +expect_not_in_wip (test); +} + +static void resume_vf_canceled_from (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state_from_param (test); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUMED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_FAILED )); +expect_not_resuming (test); +} + +static void resume_vf_refused_from (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +prepare_state_from_param (test); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); +KUNIT_EXPECT_NE (test, err, -EIO ); + +KUNIT_EXPECT_TRUE (test, err == -EALREADY || +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_FAILED )); +} + +static void resume_vf_canceled_by_restart (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , paused,ARRAY_SIZE (paused)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_busy_except_flr); + +xe_kunit_helper_delayed_call (test,HZ /10 , xe_gt_sriov_pf_control_restart, gt); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUMED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_WIP )); +} + +static void resume_vf_canceled_by_flr (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , paused,ARRAY_SIZE (paused)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_busy_except_flr); + +xe_kunit_helper_delayed_call (test,HZ /10 , + xe_gt_sriov_pf_control_trigger_flr, gt,VFUT1 ); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUMED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_WIP )); +} + +static void resume_vf_canceled_by_stop (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , paused,ARRAY_SIZE (paused)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_busy_except_stop); + +xe_kunit_helper_delayed_call (test,HZ /10 , + xe_gt_sriov_pf_control_stop_vf, gt,VFUT1 ); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUMED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_WIP )); +} + +static void basic_pause_and_resume_vf (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_ASSERT_EQ (test,0 ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); +} + +static void basic_pause_and_stop_vf (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_ASSERT_EQ (test,0 ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); +} + +static void basic_stop_and_flr_vf (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +} + +static void basic_flr_and_flr_vf (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +} + +static void basic_flr_vfs (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_trigger_flr (gt,VFUT2 )); +} + +static struct kunit_case pf_control_test_cases[] = { +KUNIT_CASE (basic_pause_and_resume_vf), +KUNIT_CASE (basic_pause_and_stop_vf), +KUNIT_CASE (basic_stop_and_flr_vf), +KUNIT_CASE (basic_flr_and_flr_vf), +KUNIT_CASE (basic_flr_vfs), + +KUNIT_CASE_PARAM (flr_vf_from, flr_must_pass_from_gen_params), +KUNIT_CASE_PARAM (flr_vf_needs_retry_from, flr_must_pass_from_gen_params), +KUNIT_CASE_PARAM (flr_vf_needs_retry_late_from, flr_must_pass_from_gen_params), +KUNIT_CASE (flr_vf_fails_on_send), +KUNIT_CASE (flr_vf_fails_on_reset), +KUNIT_CASE (flr_vf_rejected_by_guc), +KUNIT_CASE_SLOW (flr_vf_unconfirmed_by_guc), +KUNIT_CASE (flr_vf_confirmed_early_continue_by_guc), +KUNIT_CASE (flr_vf_confirmed_early_reject_by_guc), +KUNIT_CASE (flr_vf_confirmed_twice_by_guc), +KUNIT_CASE (flr_vf_confirmed_too_late_by_guc), +KUNIT_CASE (flr_vf_wrong_confirmation_from_guc), +KUNIT_CASE (flr_vf_unsolicited_confirmation_from_guc), +KUNIT_CASE (flr_vf_canceled_by_restart), + +KUNIT_CASE_PARAM (stop_vf_from, stop_must_pass_from_gen_params), +KUNIT_CASE_PARAM (stop_vf_needs_retry_from, stop_must_pass_from_gen_params), +KUNIT_CASE_PARAM (stop_vf_refused_from, stop_must_fail_from_gen_params), +KUNIT_CASE_PARAM (stop_vf_canceled_from, stop_must_cancel_from_gen_params), +KUNIT_CASE (stop_vf_fails_on_send), +KUNIT_CASE (stop_vf_rejected_by_guc), +KUNIT_CASE (stop_vf_canceled_by_flr), +KUNIT_CASE (stop_vf_canceled_by_restart), + +KUNIT_CASE_PARAM (pause_vf_from, pause_must_pass_from_gen_params), +KUNIT_CASE_PARAM (pause_vf_needs_retry_from, pause_must_pass_from_gen_params), +KUNIT_CASE_PARAM (pause_vf_refused_from, pause_must_fail_from_gen_params), +KUNIT_CASE_PARAM (pause_vf_canceled_from, pause_must_cancel_from_gen_params), +KUNIT_CASE (pause_vf_fails_on_send), +KUNIT_CASE (pause_vf_rejected_by_guc), +KUNIT_CASE_SLOW (pause_vf_unconfirmed_by_guc), +KUNIT_CASE (pause_vf_canceled_by_flr), +KUNIT_CASE (pause_vf_canceled_by_stop), +KUNIT_CASE (pause_vf_canceled_by_restart), + +KUNIT_CASE_PARAM (resume_vf_from, resume_must_pass_from_gen_params), +KUNIT_CASE_PARAM (resume_vf_needs_retry_from, resume_must_pass_from_gen_params), +KUNIT_CASE_PARAM (resume_vf_refused_from, resume_must_fail_from_gen_params), +KUNIT_CASE_PARAM (resume_vf_canceled_from, resume_must_cancel_from_gen_params), +KUNIT_CASE (resume_vf_fails_on_send), +KUNIT_CASE (resume_vf_rejected_by_guc), +KUNIT_CASE (resume_vf_canceled_by_flr), +KUNIT_CASE (resume_vf_canceled_by_stop), +KUNIT_CASE (resume_vf_canceled_by_restart), + + {} +}; + +static struct kunit_suite pf_control_suite = { + .name ="pf_control" , + .test_cases = pf_control_test_cases, + .init = pf_control_test_init, +}; + +kunit_test_suite (pf_control_suite);
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +7 -0
@@ -4,6 +4,7 @@*/ #include <drm/drm_managed.h> +#include <kunit/static_stub.h> #include "abi/guc_actions_sriov_abi.h"
@@ -196,6 +197,8 @@ static const char *control_bit_to_string(enum xe_gt_sriov_control_bits bit)static unsigned long pf_get_default_timeout (enum xe_gt_sriov_control_bits bit) { +KUNIT_STATIC_STUB_REDIRECT (pf_get_default_timeout, bit); +switch (bit) {case XE_GT_SRIOV_STATE_FLR_WAIT_GUC :case XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC :
@@ -1458,3 +1461,7 @@ void xe_gt_sriov_pf_control_restart(struct xe_gt *gt)for (n =1 ; n <= totalvfs; n++)pf_enter_vf_ready (gt, n); } + +#if IS_BUILTIN (CONFIG_DRM_XE_KUNIT_TEST ) +#include "tests/xe_gt_sriov_pf_control_kunit.c" +#endif
Signature · 1 line
2.43.0
Re: [PATCH v2 11/12] drm/xe/tests: Add KUnit tests for VF control state machines
Michal Wajdeczko <[email protected]> wrote on pią [2024-sie-09 19:23:15 +0200]:
Quoted 1,405 lines
Add KUnit tests (~200) for all VF control state machines (FLR, PAUSE, STOP and RESUME) to make sure they work as expected and will not be broken while extending them with new functionality.
Signed-off-by Michal Wajdeczko <[email protected]>Cc Lucas De Marchi <[email protected]>---
Test file named according to the new best practices [1]
[1] https://lore.kernel.org/linux-hardening/[email protected]/
---
v2: fix kunit build break due last-minute change in .c--- .../xe/tests/xe_gt_sriov_pf_control_kunit.c | 1360 +++++++++++++++++ drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c | 7 + 2 files changed, 1367 insertions(+) create mode 100644 drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.cdrivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c new file +1360
-0@@ -0,0 +1,1360 @@ +// SPDX-License-Identifier: GPL-2.0 AND MIT +/* +* Copyright © 2024 Intel Corporation +*/ + +#include <kunit/test.h> +#include <kunit/static_stub.h> + +#include "tests/xe_kunit_helpers.h" +#include "tests/xe_pci_test.h" + +#include "xe_gt_sriov_pf.h" + +static const unsigned int DUT_NUM_VFS =2 ; +static const unsigned int VFUT1 =VFID (1 ); +static const unsigned int VFUT2 =VFID (2 ); + +static void dump_state (void *arg) +{ +struct xe_gt *gt = arg; + +pf_dump_vf_state (gt,VFUT1 ); +} + +static unsigned long replacement_timeout (enum xe_gt_sriov_control_bits bit) +{ +return HZ ; +} + +static int pf_control_test_init (struct kunit *test) +{ +struct xe_pci_fake_data fake = { + .sriov_mode =XE_SRIOV_MODE_PF , + .platform =XE_TIGERLAKE ,/* some random platform */ + .subplatform =XE_SUBPLATFORM_NONE , + }; +struct xe_device *xe; +struct xe_gt *gt; + + test->priv = &fake; +xe_kunit_helper_xe_device_test_init (test); + + xe = test->priv; +KUNIT_ASSERT_EQ (test,xe_sriov_init (xe),0 ); + + xe->sriov.pf.driver_max_vfs =DUT_NUM_VFS ; +KUNIT_EXPECT_NE (test,xe_sriov_pf_get_totalvfs (xe),0 ); + + gt =xe_device_get_gt (xe,0 ); +KUNIT_ASSERT_EQ (test,xe_gt_sriov_pf_init_early (gt),0 ); + +KUNIT_ASSERT_EQ (test,0ul , *pf_peek_vf_state (gt,VFUT1 )); +KUNIT_ASSERT_EQ (test,0ul , *pf_peek_vf_state (gt,VFUT2 )); + +KUNIT_EXPECT_EQ (test,0 ,kunit_add_action_or_reset (test, dump_state, gt)); + +kunit_activate_static_stub (test, pf_get_default_timeout, replacement_timeout); + + test->priv = gt; +return 0 ; +} + +static int sanitize_vf_resources_fail (struct xe_gt *gt,u32 vfid,long timeout) +{ +return -ETIMEDOUT ; +} + +static int send_vf_control_cmd_reject (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +return -EIO ; +} + +static int send_vf_control_cmd_fail (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +return -ENODEV ; +} + +static int send_vf_control_cmd_pass_no_reply (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +return 0 ; +} + +static int send_vf_control_cmd_pass_and_reply (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +switch (cmd) { +case GUC_PF_TRIGGER_VF_PAUSE : +pf_handle_vf_event (gt, vfid,GUC_PF_NOTIFY_VF_PAUSE_DONE ); +break ; +case GUC_PF_TRIGGER_VF_FLR_START : +pf_handle_vf_event (gt, vfid,GUC_PF_NOTIFY_VF_FLR_DONE ); +break ; +case GUC_PF_TRIGGER_VF_RESUME : +case GUC_PF_TRIGGER_VF_STOP : +case GUC_PF_TRIGGER_VF_FLR_FINISH : +break ; +default : +return -EPROTO ; + } +return 0 ; +} + +static int send_vf_control_cmd_busy_wait (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +schedule_timeout_interruptible (HZ /20 ); +return -EBUSY ; +} + +static int send_vf_control_cmd_pass_but_reply_flr_only (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +return cmd ==GUC_PF_TRIGGER_VF_FLR_START ? +send_vf_control_cmd_pass_and_reply (gt, vfid, cmd) : +send_vf_control_cmd_pass_no_reply (gt, vfid, cmd); +} + +static int send_vf_control_cmd_busy_except_flr (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +return cmd ==GUC_PF_TRIGGER_VF_FLR_START || cmd ==GUC_PF_TRIGGER_VF_FLR_FINISH ? +send_vf_control_cmd_pass_and_reply (gt, vfid, cmd) : +send_vf_control_cmd_busy_wait (gt, vfid, cmd); +} + +static int send_vf_control_cmd_busy_except_stop (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +return cmd ==GUC_PF_TRIGGER_VF_STOP ? +send_vf_control_cmd_pass_and_reply (gt, vfid, cmd) : +send_vf_control_cmd_busy_wait (gt, vfid, cmd); +} + +static int BUSY_MAGIC =3 ; + +static int send_vf_control_cmd_busy_no_reply (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +static int counter; + +return ++counter %BUSY_MAGIC ? -EBUSY :0 ; +} + +static int send_vf_control_cmd_busy_and_reply (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +static int counter; + +return ++counter %BUSY_MAGIC ? -EBUSY : +send_vf_control_cmd_pass_and_reply (gt, vfid, cmd); +} + +static const enum xe_gt_sriov_control_bits ready[] = { +}; + +static const enum xe_gt_sriov_control_bits flr_starting[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_FLR_WIP , +XE_GT_SRIOV_STATE_FLR_SEND_START , +}; + +static const enum xe_gt_sriov_control_bits flr_starting_paused[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_FLR_WIP , +XE_GT_SRIOV_STATE_FLR_SEND_START , +XE_GT_SRIOV_STATE_PAUSED , +}; + +static const enum xe_gt_sriov_control_bits flr_starting_stopped[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_FLR_WIP , +XE_GT_SRIOV_STATE_FLR_SEND_START , +XE_GT_SRIOV_STATE_STOPPED , +}; + +static const enum xe_gt_sriov_control_bits flr_waiting[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_FLR_WIP , +XE_GT_SRIOV_STATE_FLR_WAIT_GUC , +}; + +static const enum xe_gt_sriov_control_bits flr_guc_done[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_FLR_WIP , +XE_GT_SRIOV_STATE_FLR_GUC_DONE , +}; + +static const enum xe_gt_sriov_control_bits flr_resetting[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_FLR_WIP , +XE_GT_SRIOV_STATE_FLR_RESET_CONFIG , +}; + +static const enum xe_gt_sriov_control_bits flr_finishing[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_FLR_WIP , +XE_GT_SRIOV_STATE_FLR_SEND_FINISH , +}; + +static const enum xe_gt_sriov_control_bits flr_failed[] = { +XE_GT_SRIOV_STATE_FLR_FAILED , +}; + +static const enum xe_gt_sriov_control_bits stopping[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_STOP_WIP , +XE_GT_SRIOV_STATE_STOP_SEND_STOP , +}; + +static const enum xe_gt_sriov_control_bits stopping_paused[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_STOP_WIP , +XE_GT_SRIOV_STATE_STOP_SEND_STOP , +XE_GT_SRIOV_STATE_PAUSED , +}; + +static const enum xe_gt_sriov_control_bits stop_failed[] = { +XE_GT_SRIOV_STATE_STOP_FAILED , +}; + +static const enum xe_gt_sriov_control_bits stop_rejected[] = { +XE_GT_SRIOV_STATE_STOP_FAILED , +XE_GT_SRIOV_STATE_MISMATCH , +}; + +static const enum xe_gt_sriov_control_bits stopped[] = { +XE_GT_SRIOV_STATE_STOPPED , +}; + +static const enum xe_gt_sriov_control_bits pausing[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_PAUSE_WIP , +XE_GT_SRIOV_STATE_PAUSE_SEND_PAUSE , +}; + +static const enum xe_gt_sriov_control_bits pausing_wait_guc[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_PAUSE_WIP , +XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC , +}; + +static const enum xe_gt_sriov_control_bits pausing_guc_done[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_PAUSE_WIP , +XE_GT_SRIOV_STATE_PAUSE_GUC_DONE , +}; + +static const enum xe_gt_sriov_control_bits pause_failed[] = { +XE_GT_SRIOV_STATE_PAUSE_FAILED , +}; + +static const enum xe_gt_sriov_control_bits pause_rejected[] = { +XE_GT_SRIOV_STATE_PAUSE_FAILED , +XE_GT_SRIOV_STATE_MISMATCH , +}; + +static const enum xe_gt_sriov_control_bits paused[] = { +XE_GT_SRIOV_STATE_PAUSED , +}; + +static const enum xe_gt_sriov_control_bits resuming[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_PAUSED , +XE_GT_SRIOV_STATE_RESUME_WIP , +XE_GT_SRIOV_STATE_RESUME_SEND_RESUME , +}; + +static const enum xe_gt_sriov_control_bits resume_failed[] = { +XE_GT_SRIOV_STATE_PAUSED , +XE_GT_SRIOV_STATE_RESUME_FAILED , +}; + +static const enum xe_gt_sriov_control_bits resume_rejected[] = { +XE_GT_SRIOV_STATE_PAUSED , +XE_GT_SRIOV_STATE_RESUME_FAILED , +XE_GT_SRIOV_STATE_MISMATCH , +}; + +static const enum xe_gt_sriov_control_bits resumed[] = { +XE_GT_SRIOV_STATE_RESUMED , +}; + +static const enum xe_gt_sriov_control_bits mismatch[] = { +XE_GT_SRIOV_STATE_MISMATCH , +}; + +struct state_param { +const char *name; +const enum xe_gt_sriov_control_bits *bits; +size_t num_bits; +}; + +static void state_param_get_desc (struct state_param *p,char *desc) +{ +snprintf (desc,KUNIT_PARAM_DESC_SIZE ,"%s" , p->name); +} + +#define MAKE_STATE_PARAM (X ) { .name = #X, .bits = X, .num_bits = ARRAY_SIZE(X) } + +/* +* Due to the test case logic the all "must_pass" params include "_rejected" states +* since our "GuC" calls by default will not complain again about the INVALID_STATE +* thus our state machine is able to fully recover. +*/ + +static struct state_param flr_must_pass_from[] = { +MAKE_STATE_PARAM (ready), +MAKE_STATE_PARAM (flr_starting), +MAKE_STATE_PARAM (flr_starting_paused), +MAKE_STATE_PARAM (flr_starting_stopped), +MAKE_STATE_PARAM (flr_waiting), +MAKE_STATE_PARAM (flr_guc_done), +MAKE_STATE_PARAM (flr_resetting), +MAKE_STATE_PARAM (flr_finishing), +MAKE_STATE_PARAM (flr_failed), +MAKE_STATE_PARAM (stopping), +MAKE_STATE_PARAM (stop_failed), +MAKE_STATE_PARAM (stop_rejected), +MAKE_STATE_PARAM (stopped), +MAKE_STATE_PARAM (pausing), +MAKE_STATE_PARAM (pausing_wait_guc), +MAKE_STATE_PARAM (pausing_guc_done), +MAKE_STATE_PARAM (pause_failed), +MAKE_STATE_PARAM (pause_rejected), +MAKE_STATE_PARAM (paused), +MAKE_STATE_PARAM (resuming), +MAKE_STATE_PARAM (resume_failed), +MAKE_STATE_PARAM (resume_rejected), +MAKE_STATE_PARAM (resumed), +MAKE_STATE_PARAM (mismatch), +}; + +static struct state_param stop_must_pass_from[] = { +MAKE_STATE_PARAM (ready), +MAKE_STATE_PARAM (stop_failed), +MAKE_STATE_PARAM (stop_rejected), +MAKE_STATE_PARAM (pausing), +MAKE_STATE_PARAM (pausing_wait_guc), +MAKE_STATE_PARAM (pausing_guc_done), +MAKE_STATE_PARAM (pause_failed), +MAKE_STATE_PARAM (pause_rejected), +MAKE_STATE_PARAM (paused), +MAKE_STATE_PARAM (resuming), +MAKE_STATE_PARAM (resume_failed), +MAKE_STATE_PARAM (resume_rejected), +MAKE_STATE_PARAM (resumed), +MAKE_STATE_PARAM (mismatch), +MAKE_STATE_PARAM (flr_failed), +}; + +static struct state_param stop_must_cancel_from[] = { +MAKE_STATE_PARAM (flr_starting), +MAKE_STATE_PARAM (flr_starting_paused), +MAKE_STATE_PARAM (flr_waiting), +MAKE_STATE_PARAM (flr_guc_done), +MAKE_STATE_PARAM (flr_resetting), +MAKE_STATE_PARAM (flr_finishing), +}; + +static struct state_param stop_must_fail_from[] = { +MAKE_STATE_PARAM (stopping), +MAKE_STATE_PARAM (stopping_paused), +MAKE_STATE_PARAM (stopped), +MAKE_STATE_PARAM (flr_starting_stopped), +}; + +static struct state_param pause_must_pass_from[] = { +MAKE_STATE_PARAM (ready), +MAKE_STATE_PARAM (pause_failed), +MAKE_STATE_PARAM (pause_rejected), +MAKE_STATE_PARAM (resumed), +MAKE_STATE_PARAM (mismatch), +MAKE_STATE_PARAM (stop_failed), +MAKE_STATE_PARAM (stop_rejected), +MAKE_STATE_PARAM (flr_failed), +}; + +static struct state_param pause_must_cancel_from[] = { +MAKE_STATE_PARAM (flr_starting), +MAKE_STATE_PARAM (flr_waiting), +MAKE_STATE_PARAM (flr_guc_done), +MAKE_STATE_PARAM (flr_resetting), +MAKE_STATE_PARAM (flr_finishing), +MAKE_STATE_PARAM (stopping), +}; + +static struct state_param pause_must_fail_from[] = { +MAKE_STATE_PARAM (pausing), +MAKE_STATE_PARAM (pausing_wait_guc), +MAKE_STATE_PARAM (pausing_guc_done), +MAKE_STATE_PARAM (paused), +MAKE_STATE_PARAM (resuming), +MAKE_STATE_PARAM (resume_failed), +MAKE_STATE_PARAM (resume_rejected), +MAKE_STATE_PARAM (stopped), +}; + +static struct state_param resume_must_pass_from[] = { +MAKE_STATE_PARAM (paused), +MAKE_STATE_PARAM (resume_failed), +MAKE_STATE_PARAM (resume_rejected), +}; + +static struct state_param resume_must_cancel_from[] = { +MAKE_STATE_PARAM (flr_starting_paused), +MAKE_STATE_PARAM (stopping_paused), +}; + +static struct state_param resume_must_fail_from[] = { +MAKE_STATE_PARAM (ready), +MAKE_STATE_PARAM (pausing), +MAKE_STATE_PARAM (pausing_wait_guc), +MAKE_STATE_PARAM (pausing_guc_done), +MAKE_STATE_PARAM (pause_failed), +MAKE_STATE_PARAM (pause_rejected), +MAKE_STATE_PARAM (resuming), +MAKE_STATE_PARAM (resumed), +MAKE_STATE_PARAM (stopping), +MAKE_STATE_PARAM (stop_failed), +MAKE_STATE_PARAM (stop_rejected), +MAKE_STATE_PARAM (stopped), +MAKE_STATE_PARAM (flr_starting), +MAKE_STATE_PARAM (flr_waiting), +MAKE_STATE_PARAM (flr_guc_done), +MAKE_STATE_PARAM (flr_resetting), +MAKE_STATE_PARAM (flr_finishing), +MAKE_STATE_PARAM (flr_failed), +MAKE_STATE_PARAM (mismatch), +}; + +KUNIT_ARRAY_PARAM (flr_must_pass_from, flr_must_pass_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (stop_must_pass_from, stop_must_pass_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (stop_must_fail_from, stop_must_fail_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (stop_must_cancel_from, stop_must_cancel_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (pause_must_pass_from, pause_must_pass_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (pause_must_fail_from, pause_must_fail_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (pause_must_cancel_from, pause_must_cancel_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (resume_must_pass_from, resume_must_pass_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (resume_must_fail_from, resume_must_fail_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (resume_must_cancel_from, resume_must_cancel_from, state_param_get_desc); + +static int mimic_pf_handle_vf_flr_done (struct xe_gt *gt,unsigned int vfid) +{ +pf_handle_vf_flr_done (gt, vfid); +return 0 ; +} + +static int mimic_pf_handle_vf_pause_done (struct xe_gt *gt,unsigned int vfid) +{ +pf_handle_vf_pause_done (gt, vfid); +return 0 ; +} + +static void prepare_state (struct kunit *test,unsigned int vfid, +const enum xe_gt_sriov_control_bits *bits,size_t num_bits) +{ +struct xe_gt *gt = test->priv; +size_t n; + +for (n =0 ; n < num_bits; n++) { +enum xe_gt_sriov_control_bits bit = bits[n]; + +KUNIT_ASSERT_TRUE (test,pf_enter_vf_state (gt, vfid, bit)); + +if (bit ==XE_GT_SRIOV_STATE_WIP ) { +pf_queue_vf (gt, vfid); + }else if (bit ==XE_GT_SRIOV_STATE_FLR_WAIT_GUC ) { +xe_kunit_helper_delayed_call (test,HZ /100 , + mimic_pf_handle_vf_flr_done, gt, vfid); + }else if (bit ==XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC ) { +xe_kunit_helper_delayed_call (test,HZ /100 , + mimic_pf_handle_vf_pause_done, gt, vfid); + } + } +} + +static void prepare_state_from_param (struct kunit *test) +{ +const struct state_param *p = test->param_value; + +prepare_state (test,VFUT1 , p->bits, p->num_bits); +} + +static void expect_not_pausing (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_WIP )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_SEND_PAUSE )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_GUC_DONE )); +} + +static void expect_not_in_pause (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +expect_not_pausing (test); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_FAILED )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSED )); +} + +static void expect_not_resuming (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_WIP )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_SEND_RESUME )); +} + +static void expect_not_in_resume (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +expect_not_resuming (test); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_FAILED )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUMED )); +} + +static void expect_not_stopping (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOP_WIP )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOP_SEND_STOP )); +} + +static void expect_not_in_stop (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +expect_not_stopping (test); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOP_FAILED )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOPPED )); +} + +static void expect_not_in_flr (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_SEND_START )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WAIT_GUC )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_GUC_DONE )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_SEND_FINISH )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +} + +static void expect_not_in_wip (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void expect_not_in_mismatch (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +} + +static void try_flr_vf (struct kunit *test,bool mimic_busy,bool late_reply) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + mimic_busy ? late_reply ? send_vf_control_cmd_busy_no_reply : + send_vf_control_cmd_busy_and_reply : + late_reply ? send_vf_control_cmd_pass_no_reply : + send_vf_control_cmd_pass_and_reply); + +if (late_reply) +xe_kunit_helper_delayed_call (test,HZ /10 , + mimic_pf_handle_vf_flr_done, gt,VFUT1 ); + +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); + +expect_not_in_flr (test); +expect_not_in_pause (test); +expect_not_in_resume (test); +expect_not_in_stop (test); +expect_not_in_mismatch (test); +expect_not_in_wip (test); +} + +static void flr_vf_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_flr_vf (test, false, false); +} + +static void flr_vf_needs_retry_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_flr_vf (test, true, false); +} + +static void flr_vf_needs_retry_late_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_flr_vf (test, true, true); +} + +static void flr_vf_fails_on_send (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_fail); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +KUNIT_EXPECT_NE (test, err, -ETIMEDOUT ); +KUNIT_EXPECT_NE (test, err, -ECANCELED ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void flr_vf_fails_on_reset (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.vfs[VFUT1 ].config.sanitize, + sanitize_vf_resources_fail); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +KUNIT_EXPECT_NE (test, err, -ETIMEDOUT ); +KUNIT_EXPECT_NE (test, err, -ECANCELED ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void flr_vf_rejected_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_reject); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +KUNIT_EXPECT_NE (test, err, -ETIMEDOUT ); +KUNIT_EXPECT_NE (test, err, -ECANCELED ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void flr_vf_unconfirmed_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_no_reply); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +KUNIT_EXPECT_EQ (test, err, -ETIMEDOUT ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +} + +static void flr_vf_confirmed_early_continue_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , flr_starting,ARRAY_SIZE (flr_starting)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_no_reply); + +pf_handle_vf_flr_done (gt,VFUT1 ); + +/* +* make sure SEND_START completes; +* successful reply from cmd_pass_no_reply should exit mismatch state +*/ +flush_work (>->sriov.pf.control.worker); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +} + +static void flr_vf_confirmed_early_reject_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , flr_starting,ARRAY_SIZE (flr_starting)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_reject); + +pf_handle_vf_flr_done (gt,VFUT1 ); + +/* +* make sure SEND_START completes; +* error from send_vf_control_cmd_reject should keep mismatch state +*/ +flush_work (>->sriov.pf.control.worker); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void flr_vf_confirmed_twice_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , flr_guc_done,ARRAY_SIZE (flr_guc_done)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_no_reply); + +pf_handle_vf_flr_done (gt,VFUT1 ); + +/* this is fully recoverable */ +KUNIT_EXPECT_EQ (test,0 ,pf_wait_vf_wip_done (gt,VFUT1 ,HZ )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +} + +static void flr_vf_confirmed_too_late_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , flr_failed,ARRAY_SIZE (flr_failed)); + +pf_handle_vf_flr_done (gt,VFUT1 ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void flr_vf_unsolicited_confirmation_from_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); + +pf_handle_vf_flr_done (gt,VFUT1 ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +} + +static void flr_vf_wrong_confirmation_from_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , flr_waiting,ARRAY_SIZE (flr_waiting)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +pf_handle_vf_pause_done (gt,VFUT1 ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +} + +static void flr_vf_canceled_by_restart (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_busy_wait); + +xe_kunit_helper_delayed_call (test,HZ /10 , xe_gt_sriov_pf_control_restart, gt); + +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +expect_not_in_flr (test); +} + +static void try_stop_vf (struct kunit *test,bool mimic_busy) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + mimic_busy ? send_vf_control_cmd_busy_and_reply : + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOPPED )); +expect_not_stopping (test); +expect_not_in_pause (test); +expect_not_in_resume (test); +expect_not_in_mismatch (test); +} + +static void stop_vf_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_stop_vf (test, false); +} + +static void stop_vf_needs_retry_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_stop_vf (test, true); +} + +static void stop_vf_refused_from (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +prepare_state_from_param (test); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); +KUNIT_EXPECT_NE (test, err, -ECANCELED ); + +KUNIT_EXPECT_TRUE (test, err == -EALREADY || +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOP_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOP_FAILED )); +} + +static void stop_vf_fails_on_send (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_fail); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); +KUNIT_EXPECT_NE (test, err, -ETIMEDOUT ); +KUNIT_EXPECT_NE (test, err, -ECANCELED ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOP_FAILED )); +expect_not_stopping (test); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOPPED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void stop_vf_rejected_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_reject); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); +KUNIT_EXPECT_NE (test, err, -ETIMEDOUT ); +KUNIT_EXPECT_NE (test, err, -ECANCELED ); + +expect_not_stopping (test); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOP_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOPPED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void stop_vf_canceled_from (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state_from_param (test); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOP_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOPPED )); +} + +static void stop_vf_canceled_by_restart (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_busy_except_flr); + +xe_kunit_helper_delayed_call (test,HZ /10 , xe_gt_sriov_pf_control_restart, gt); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); +expect_not_in_stop (test); +} + +static void stop_vf_canceled_by_flr (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_busy_except_flr); + +xe_kunit_helper_delayed_call (test,HZ /10 , + xe_gt_sriov_pf_control_trigger_flr, gt,VFUT1 ); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); +expect_not_in_stop (test); +} + +static void try_pause_vf (struct kunit *test,bool mimic_busy) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + mimic_busy ? send_vf_control_cmd_busy_and_reply : + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSED )); +expect_not_pausing (test); +expect_not_in_mismatch (test); +} + +static void pause_vf_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_pause_vf (test, false); +} + +static void pause_vf_needs_retry_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_pause_vf (test, true); +} + +static void pause_vf_canceled_from (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state_from_param (test); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +expect_not_in_pause (test); +} + +static void pause_vf_refused_from (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +prepare_state_from_param (test); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +KUNIT_EXPECT_NE (test, err, -ECANCELED ); + +KUNIT_EXPECT_TRUE (test, err == -EALREADY || +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_FAILED )); +} + +static void pause_vf_rejected_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_reject); + +KUNIT_EXPECT_NE (test,0 ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void pause_vf_fails_on_send (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_fail); + +KUNIT_EXPECT_NE (test,0 ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void pause_vf_unconfirmed_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_no_reply); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +KUNIT_EXPECT_EQ (test, err, -ETIMEDOUT ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_FAILED )); +} + +static void pause_vf_canceled_by_restart (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_no_reply); + +xe_kunit_helper_delayed_call (test,HZ /10 , xe_gt_sriov_pf_control_restart, gt); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +expect_not_in_pause (test); +} + +static void pause_vf_canceled_by_flr (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_but_reply_flr_only); + +xe_kunit_helper_delayed_call (test,HZ /10 , + xe_gt_sriov_pf_control_trigger_flr, gt,VFUT1 ); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +expect_not_in_pause (test); +} + +static void pause_vf_canceled_by_stop (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_no_reply); + +xe_kunit_helper_delayed_call (test,HZ /10 , + xe_gt_sriov_pf_control_stop_vf, gt,VFUT1 ); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +expect_not_in_pause (test); +} + +static void try_resume_vf (struct kunit *test,bool mimic_busy) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + mimic_busy ? send_vf_control_cmd_busy_and_reply : + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUMED )); +expect_not_resuming (test); +expect_not_in_pause (test); +expect_not_in_mismatch (test); +expect_not_in_wip (test); +} + +static void resume_vf_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_resume_vf (test, false); +} + +static void resume_vf_needs_retry_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_resume_vf (test, true); +} + +static void resume_vf_fails_on_send (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , paused,ARRAY_SIZE (paused)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_fail); + +KUNIT_EXPECT_NE (test,0 ,xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_FAILED )); + +expect_not_resuming (test); +expect_not_in_mismatch (test); +expect_not_in_wip (test); +} + +static void resume_vf_rejected_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , paused,ARRAY_SIZE (paused)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_reject); + +KUNIT_EXPECT_NE (test,0 ,xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_FAILED )); + +expect_not_resuming (test); +expect_not_in_wip (test); +} + +static void resume_vf_canceled_from (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state_from_param (test); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUMED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_FAILED )); +expect_not_resuming (test); +} + +static void resume_vf_refused_from (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +prepare_state_from_param (test); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); +KUNIT_EXPECT_NE (test, err, -EIO ); + +KUNIT_EXPECT_TRUE (test, err == -EALREADY || +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_FAILED )); +} + +static void resume_vf_canceled_by_restart (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , paused,ARRAY_SIZE (paused)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_busy_except_flr); + +xe_kunit_helper_delayed_call (test,HZ /10 , xe_gt_sriov_pf_control_restart, gt); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUMED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_WIP )); +} + +static void resume_vf_canceled_by_flr (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , paused,ARRAY_SIZE (paused)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_busy_except_flr); + +xe_kunit_helper_delayed_call (test,HZ /10 , + xe_gt_sriov_pf_control_trigger_flr, gt,VFUT1 ); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUMED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_WIP )); +} + +static void resume_vf_canceled_by_stop (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , paused,ARRAY_SIZE (paused)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_busy_except_stop); + +xe_kunit_helper_delayed_call (test,HZ /10 , + xe_gt_sriov_pf_control_stop_vf, gt,VFUT1 ); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUMED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_WIP )); +} + +static void basic_pause_and_resume_vf (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_ASSERT_EQ (test,0 ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); +} + +static void basic_pause_and_stop_vf (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_ASSERT_EQ (test,0 ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); +} + +static void basic_stop_and_flr_vf (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +} + +static void basic_flr_and_flr_vf (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +} + +static void basic_flr_vfs (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_trigger_flr (gt,VFUT2 )); +} + +static struct kunit_case pf_control_test_cases[] = { +KUNIT_CASE (basic_pause_and_resume_vf), +KUNIT_CASE (basic_pause_and_stop_vf), +KUNIT_CASE (basic_stop_and_flr_vf), +KUNIT_CASE (basic_flr_and_flr_vf), +KUNIT_CASE (basic_flr_vfs), + +KUNIT_CASE_PARAM (flr_vf_from, flr_must_pass_from_gen_params), +KUNIT_CASE_PARAM (flr_vf_needs_retry_from, flr_must_pass_from_gen_params), +KUNIT_CASE_PARAM (flr_vf_needs_retry_late_from, flr_must_pass_from_gen_params), +KUNIT_CASE (flr_vf_fails_on_send), +KUNIT_CASE (flr_vf_fails_on_reset), +KUNIT_CASE (flr_vf_rejected_by_guc), +KUNIT_CASE_SLOW (flr_vf_unconfirmed_by_guc), +KUNIT_CASE (flr_vf_confirmed_early_continue_by_guc), +KUNIT_CASE (flr_vf_confirmed_early_reject_by_guc), +KUNIT_CASE (flr_vf_confirmed_twice_by_guc), +KUNIT_CASE (flr_vf_confirmed_too_late_by_guc), +KUNIT_CASE (flr_vf_wrong_confirmation_from_guc), +KUNIT_CASE (flr_vf_unsolicited_confirmation_from_guc), +KUNIT_CASE (flr_vf_canceled_by_restart), + +KUNIT_CASE_PARAM (stop_vf_from, stop_must_pass_from_gen_params), +KUNIT_CASE_PARAM (stop_vf_needs_retry_from, stop_must_pass_from_gen_params), +KUNIT_CASE_PARAM (stop_vf_refused_from, stop_must_fail_from_gen_params), +KUNIT_CASE_PARAM (stop_vf_canceled_from, stop_must_cancel_from_gen_params), +KUNIT_CASE (stop_vf_fails_on_send), +KUNIT_CASE (stop_vf_rejected_by_guc), +KUNIT_CASE (stop_vf_canceled_by_flr), +KUNIT_CASE (stop_vf_canceled_by_restart), + +KUNIT_CASE_PARAM (pause_vf_from, pause_must_pass_from_gen_params), +KUNIT_CASE_PARAM (pause_vf_needs_retry_from, pause_must_pass_from_gen_params), +KUNIT_CASE_PARAM (pause_vf_refused_from, pause_must_fail_from_gen_params), +KUNIT_CASE_PARAM (pause_vf_canceled_from, pause_must_cancel_from_gen_params), +KUNIT_CASE (pause_vf_fails_on_send), +KUNIT_CASE (pause_vf_rejected_by_guc), +KUNIT_CASE_SLOW (pause_vf_unconfirmed_by_guc), +KUNIT_CASE (pause_vf_canceled_by_flr), +KUNIT_CASE (pause_vf_canceled_by_stop), +KUNIT_CASE (pause_vf_canceled_by_restart), + +KUNIT_CASE_PARAM (resume_vf_from, resume_must_pass_from_gen_params), +KUNIT_CASE_PARAM (resume_vf_needs_retry_from, resume_must_pass_from_gen_params), +KUNIT_CASE_PARAM (resume_vf_refused_from, resume_must_fail_from_gen_params), +KUNIT_CASE_PARAM (resume_vf_canceled_from, resume_must_cancel_from_gen_params), +KUNIT_CASE (resume_vf_fails_on_send), +KUNIT_CASE (resume_vf_rejected_by_guc), +KUNIT_CASE (resume_vf_canceled_by_flr), +KUNIT_CASE (resume_vf_canceled_by_stop), +KUNIT_CASE (resume_vf_canceled_by_restart), + + {} +}; + +static struct kunit_suite pf_control_suite = { + .name ="pf_control" , + .test_cases = pf_control_test_cases, + .init = pf_control_test_init, +}; + +kunit_test_suite (pf_control_suite);drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +3
-0@@ -4,6 +4,7 @@*/ #include <drm/drm_managed.h> +#include <kunit/static_stub.h> #include "abi/guc_actions_sriov_abi.h" @@ -196,6 +197,8 @@ static const char *control_bit_to_string(enum xe_gt_sriov_control_bits bit)static unsigned long pf_get_default_timeout (enum xe_gt_sriov_control_bits bit) { +KUNIT_STATIC_STUB_REDIRECT (pf_get_default_timeout, bit); +switch (bit) {case XE_GT_SRIOV_STATE_FLR_WAIT_GUC :case XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC :
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c void xe_gt_sriov_pf_control_restart(struct xe_gt *gt) · line 1467
Quoted 7 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +4
-0@@ -1458,3 +1461,7 @@ void xe_gt_sriov_pf_control_restart(struct xe_gt *gt)for (n =1 ; n <= totalvfs; n++)pf_enter_vf_ready (gt, n); } + +#if IS_BUILTIN (CONFIG_DRM_XE_KUNIT_TEST ) +#include "tests/xe_gt_sriov_pf_control_kunit.c" +#endif
I sent a review to the wrong patch revision, I will re-paste and send again:
The tests look fine. I tried to verify the states according to the available drawings of the state machine and I did not find any incorrectness. It seems to me that the tests could be expanded to include an additional basic test: basic_pause_and_flr_vf
But still:
Quoted 3 lines
Signature · 1 line
2.43.0
Re: [PATCH 11/12] drm/xe/tests: Add KUnit tests for VF control state machines
In reply to Michal WajdeczkoMichal Wajdeczko <[email protected]> wrote on pią [2024-sie-09 18:51:58 +0200]:
Quoted 1,403 lines
Add KUnit tests (~200) for all VF control state machines (FLR, PAUSE, STOP and RESUME) to make sure they work as expected and will not be broken while extending them with new functionality.
Signed-off-by Michal Wajdeczko <[email protected]>Cc Lucas De Marchi <[email protected]>---
Test file named according to the new best practices [1]
[1] https://lore.kernel.org/linux-hardening/[email protected]/--- .../xe/tests/xe_gt_sriov_pf_control_kunit.c | 1360 +++++++++++++++++ drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c | 7 + 2 files changed, 1367 insertions(+) create mode 100644 drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.cdrivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c new file +1360
-0@@ -0,0 +1,1360 @@ +// SPDX-License-Identifier: GPL-2.0 AND MIT +/* +* Copyright © 2024 Intel Corporation +*/ + +#include <kunit/test.h> +#include <kunit/static_stub.h> + +#include "tests/xe_kunit_helpers.h" +#include "tests/xe_pci_test.h" + +#include "xe_gt_sriov_pf.h" + +static const unsigned int DUT_NUM_VFS =2 ; +static const unsigned int VFUT1 =VFID (1 ); +static const unsigned int VFUT2 =VFID (2 ); + +static void dump_state (void *arg) +{ +struct xe_gt *gt = arg; + +pf_dump_vf_state (gt,VFUT1 ); +} + +static unsigned long replacement_timeout (enum xe_gt_sriov_control_bits bit) +{ +return HZ ; +} + +static int pf_control_test_init (struct kunit *test) +{ +struct xe_pci_fake_data fake = { + .sriov_mode =XE_SRIOV_MODE_PF , + .platform =XE_TIGERLAKE ,/* some random platform */ + .subplatform =XE_SUBPLATFORM_NONE , + }; +struct xe_device *xe; +struct xe_gt *gt; + + test->priv = &fake; +xe_kunit_helper_xe_device_test_init (test); + + xe = test->priv; +KUNIT_ASSERT_EQ (test,xe_sriov_init (xe),0 ); + + xe->sriov.pf.driver_max_vfs =DUT_NUM_VFS ; +KUNIT_EXPECT_NE (test,xe_sriov_pf_get_totalvfs (xe),0 ); + + gt =xe_device_get_gt (xe,0 ); +KUNIT_ASSERT_EQ (test,xe_gt_sriov_pf_init_early (gt),0 ); + +KUNIT_ASSERT_EQ (test,0ul , *__pf_peek_vf_state (gt,VFUT1 )); +KUNIT_ASSERT_EQ (test,0ul , *__pf_peek_vf_state (gt,VFUT2 )); + +KUNIT_EXPECT_EQ (test,0 ,kunit_add_action_or_reset (test, dump_state, gt)); + +kunit_activate_static_stub (test, pf_get_default_timeout, replacement_timeout); + + test->priv = gt; +return 0 ; +} + +static int sanitize_vf_resources_fail (struct xe_gt *gt,u32 vfid,long timeout) +{ +return -ETIMEDOUT ; +} + +static int send_vf_control_cmd_reject (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +return -EIO ; +} + +static int send_vf_control_cmd_fail (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +return -ENODEV ; +} + +static int send_vf_control_cmd_pass_no_reply (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +return 0 ; +} + +static int send_vf_control_cmd_pass_and_reply (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +switch (cmd) { +case GUC_PF_TRIGGER_VF_PAUSE : +pf_handle_vf_event (gt, vfid,GUC_PF_NOTIFY_VF_PAUSE_DONE ); +break ; +case GUC_PF_TRIGGER_VF_FLR_START : +pf_handle_vf_event (gt, vfid,GUC_PF_NOTIFY_VF_FLR_DONE ); +break ; +case GUC_PF_TRIGGER_VF_RESUME : +case GUC_PF_TRIGGER_VF_STOP : +case GUC_PF_TRIGGER_VF_FLR_FINISH : +break ; +default : +return -EPROTO ; + } +return 0 ; +} + +static int send_vf_control_cmd_busy_wait (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +schedule_timeout_interruptible (HZ /20 ); +return -EBUSY ; +} + +static int send_vf_control_cmd_pass_but_reply_flr_only (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +return cmd ==GUC_PF_TRIGGER_VF_FLR_START ? +send_vf_control_cmd_pass_and_reply (gt, vfid, cmd) : +send_vf_control_cmd_pass_no_reply (gt, vfid, cmd); +} + +static int send_vf_control_cmd_busy_except_flr (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +return cmd ==GUC_PF_TRIGGER_VF_FLR_START || cmd ==GUC_PF_TRIGGER_VF_FLR_FINISH ? +send_vf_control_cmd_pass_and_reply (gt, vfid, cmd) : +send_vf_control_cmd_busy_wait (gt, vfid, cmd); +} + +static int send_vf_control_cmd_busy_except_stop (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +return cmd ==GUC_PF_TRIGGER_VF_STOP ? +send_vf_control_cmd_pass_and_reply (gt, vfid, cmd) : +send_vf_control_cmd_busy_wait (gt, vfid, cmd); +} + +static int BUSY_MAGIC =3 ; + +static int send_vf_control_cmd_busy_no_reply (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +static int counter; + +return ++counter %BUSY_MAGIC ? -EBUSY :0 ; +} + +static int send_vf_control_cmd_busy_and_reply (struct xe_gt *gt,unsigned int vfid,u32 cmd) +{ +static int counter; + +return ++counter %BUSY_MAGIC ? -EBUSY : +send_vf_control_cmd_pass_and_reply (gt, vfid, cmd); +} + +static const enum xe_gt_sriov_control_bits ready[] = { +}; + +static const enum xe_gt_sriov_control_bits flr_starting[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_FLR_WIP , +XE_GT_SRIOV_STATE_FLR_SEND_START , +}; + +static const enum xe_gt_sriov_control_bits flr_starting_paused[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_FLR_WIP , +XE_GT_SRIOV_STATE_FLR_SEND_START , +XE_GT_SRIOV_STATE_PAUSED , +}; + +static const enum xe_gt_sriov_control_bits flr_starting_stopped[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_FLR_WIP , +XE_GT_SRIOV_STATE_FLR_SEND_START , +XE_GT_SRIOV_STATE_STOPPED , +}; + +static const enum xe_gt_sriov_control_bits flr_waiting[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_FLR_WIP , +XE_GT_SRIOV_STATE_FLR_WAIT_GUC , +}; + +static const enum xe_gt_sriov_control_bits flr_guc_done[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_FLR_WIP , +XE_GT_SRIOV_STATE_FLR_GUC_DONE , +}; + +static const enum xe_gt_sriov_control_bits flr_resetting[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_FLR_WIP , +XE_GT_SRIOV_STATE_FLR_RESET_CONFIG , +}; + +static const enum xe_gt_sriov_control_bits flr_finishing[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_FLR_WIP , +XE_GT_SRIOV_STATE_FLR_SEND_FINISH , +}; + +static const enum xe_gt_sriov_control_bits flr_failed[] = { +XE_GT_SRIOV_STATE_FLR_FAILED , +}; + +static const enum xe_gt_sriov_control_bits stopping[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_STOP_WIP , +XE_GT_SRIOV_STATE_STOP_SEND_STOP , +}; + +static const enum xe_gt_sriov_control_bits stopping_paused[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_STOP_WIP , +XE_GT_SRIOV_STATE_STOP_SEND_STOP , +XE_GT_SRIOV_STATE_PAUSED , +}; + +static const enum xe_gt_sriov_control_bits stop_failed[] = { +XE_GT_SRIOV_STATE_STOP_FAILED , +}; + +static const enum xe_gt_sriov_control_bits stop_rejected[] = { +XE_GT_SRIOV_STATE_STOP_FAILED , +XE_GT_SRIOV_STATE_MISMATCH , +}; + +static const enum xe_gt_sriov_control_bits stopped[] = { +XE_GT_SRIOV_STATE_STOPPED , +}; + +static const enum xe_gt_sriov_control_bits pausing[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_PAUSE_WIP , +XE_GT_SRIOV_STATE_PAUSE_SEND_PAUSE , +}; + +static const enum xe_gt_sriov_control_bits pausing_wait_guc[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_PAUSE_WIP , +XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC , +}; + +static const enum xe_gt_sriov_control_bits pausing_guc_done[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_PAUSE_WIP , +XE_GT_SRIOV_STATE_PAUSE_GUC_DONE , +}; + +static const enum xe_gt_sriov_control_bits pause_failed[] = { +XE_GT_SRIOV_STATE_PAUSE_FAILED , +}; + +static const enum xe_gt_sriov_control_bits pause_rejected[] = { +XE_GT_SRIOV_STATE_PAUSE_FAILED , +XE_GT_SRIOV_STATE_MISMATCH , +}; + +static const enum xe_gt_sriov_control_bits paused[] = { +XE_GT_SRIOV_STATE_PAUSED , +}; + +static const enum xe_gt_sriov_control_bits resuming[] = { +XE_GT_SRIOV_STATE_WIP , +XE_GT_SRIOV_STATE_PAUSED , +XE_GT_SRIOV_STATE_RESUME_WIP , +XE_GT_SRIOV_STATE_RESUME_SEND_RESUME , +}; + +static const enum xe_gt_sriov_control_bits resume_failed[] = { +XE_GT_SRIOV_STATE_PAUSED , +XE_GT_SRIOV_STATE_RESUME_FAILED , +}; + +static const enum xe_gt_sriov_control_bits resume_rejected[] = { +XE_GT_SRIOV_STATE_PAUSED , +XE_GT_SRIOV_STATE_RESUME_FAILED , +XE_GT_SRIOV_STATE_MISMATCH , +}; + +static const enum xe_gt_sriov_control_bits resumed[] = { +XE_GT_SRIOV_STATE_RESUMED , +}; + +static const enum xe_gt_sriov_control_bits mismatch[] = { +XE_GT_SRIOV_STATE_MISMATCH , +}; + +struct state_param { +const char *name; +const enum xe_gt_sriov_control_bits *bits; +size_t num_bits; +}; + +static void state_param_get_desc (struct state_param *p,char *desc) +{ +snprintf (desc,KUNIT_PARAM_DESC_SIZE ,"%s" , p->name); +} + +#define MAKE_STATE_PARAM (X ) { .name = #X, .bits = X, .num_bits = ARRAY_SIZE(X) } + +/* +* Due to the test case logic the all "must_pass" params include "_rejected" states +* since our "GuC" calls by default will not complain again about the INVALID_STATE +* thus our state machine is able to fully recover. +*/ + +static struct state_param flr_must_pass_from[] = { +MAKE_STATE_PARAM (ready), +MAKE_STATE_PARAM (flr_starting), +MAKE_STATE_PARAM (flr_starting_paused), +MAKE_STATE_PARAM (flr_starting_stopped), +MAKE_STATE_PARAM (flr_waiting), +MAKE_STATE_PARAM (flr_guc_done), +MAKE_STATE_PARAM (flr_resetting), +MAKE_STATE_PARAM (flr_finishing), +MAKE_STATE_PARAM (flr_failed), +MAKE_STATE_PARAM (stopping), +MAKE_STATE_PARAM (stop_failed), +MAKE_STATE_PARAM (stop_rejected), +MAKE_STATE_PARAM (stopped), +MAKE_STATE_PARAM (pausing), +MAKE_STATE_PARAM (pausing_wait_guc), +MAKE_STATE_PARAM (pausing_guc_done), +MAKE_STATE_PARAM (pause_failed), +MAKE_STATE_PARAM (pause_rejected), +MAKE_STATE_PARAM (paused), +MAKE_STATE_PARAM (resuming), +MAKE_STATE_PARAM (resume_failed), +MAKE_STATE_PARAM (resume_rejected), +MAKE_STATE_PARAM (resumed), +MAKE_STATE_PARAM (mismatch), +}; + +static struct state_param stop_must_pass_from[] = { +MAKE_STATE_PARAM (ready), +MAKE_STATE_PARAM (stop_failed), +MAKE_STATE_PARAM (stop_rejected), +MAKE_STATE_PARAM (pausing), +MAKE_STATE_PARAM (pausing_wait_guc), +MAKE_STATE_PARAM (pausing_guc_done), +MAKE_STATE_PARAM (pause_failed), +MAKE_STATE_PARAM (pause_rejected), +MAKE_STATE_PARAM (paused), +MAKE_STATE_PARAM (resuming), +MAKE_STATE_PARAM (resume_failed), +MAKE_STATE_PARAM (resume_rejected), +MAKE_STATE_PARAM (resumed), +MAKE_STATE_PARAM (mismatch), +MAKE_STATE_PARAM (flr_failed), +}; + +static struct state_param stop_must_cancel_from[] = { +MAKE_STATE_PARAM (flr_starting), +MAKE_STATE_PARAM (flr_starting_paused), +MAKE_STATE_PARAM (flr_waiting), +MAKE_STATE_PARAM (flr_guc_done), +MAKE_STATE_PARAM (flr_resetting), +MAKE_STATE_PARAM (flr_finishing), +}; + +static struct state_param stop_must_fail_from[] = { +MAKE_STATE_PARAM (stopping), +MAKE_STATE_PARAM (stopping_paused), +MAKE_STATE_PARAM (stopped), +MAKE_STATE_PARAM (flr_starting_stopped), +}; + +static struct state_param pause_must_pass_from[] = { +MAKE_STATE_PARAM (ready), +MAKE_STATE_PARAM (pause_failed), +MAKE_STATE_PARAM (pause_rejected), +MAKE_STATE_PARAM (resumed), +MAKE_STATE_PARAM (mismatch), +MAKE_STATE_PARAM (stop_failed), +MAKE_STATE_PARAM (stop_rejected), +MAKE_STATE_PARAM (flr_failed), +}; + +static struct state_param pause_must_cancel_from[] = { +MAKE_STATE_PARAM (flr_starting), +MAKE_STATE_PARAM (flr_waiting), +MAKE_STATE_PARAM (flr_guc_done), +MAKE_STATE_PARAM (flr_resetting), +MAKE_STATE_PARAM (flr_finishing), +MAKE_STATE_PARAM (stopping), +}; + +static struct state_param pause_must_fail_from[] = { +MAKE_STATE_PARAM (pausing), +MAKE_STATE_PARAM (pausing_wait_guc), +MAKE_STATE_PARAM (pausing_guc_done), +MAKE_STATE_PARAM (paused), +MAKE_STATE_PARAM (resuming), +MAKE_STATE_PARAM (resume_failed), +MAKE_STATE_PARAM (resume_rejected), +MAKE_STATE_PARAM (stopped), +}; + +static struct state_param resume_must_pass_from[] = { +MAKE_STATE_PARAM (paused), +MAKE_STATE_PARAM (resume_failed), +MAKE_STATE_PARAM (resume_rejected), +}; + +static struct state_param resume_must_cancel_from[] = { +MAKE_STATE_PARAM (flr_starting_paused), +MAKE_STATE_PARAM (stopping_paused), +}; + +static struct state_param resume_must_fail_from[] = { +MAKE_STATE_PARAM (ready), +MAKE_STATE_PARAM (pausing), +MAKE_STATE_PARAM (pausing_wait_guc), +MAKE_STATE_PARAM (pausing_guc_done), +MAKE_STATE_PARAM (pause_failed), +MAKE_STATE_PARAM (pause_rejected), +MAKE_STATE_PARAM (resuming), +MAKE_STATE_PARAM (resumed), +MAKE_STATE_PARAM (stopping), +MAKE_STATE_PARAM (stop_failed), +MAKE_STATE_PARAM (stop_rejected), +MAKE_STATE_PARAM (stopped), +MAKE_STATE_PARAM (flr_starting), +MAKE_STATE_PARAM (flr_waiting), +MAKE_STATE_PARAM (flr_guc_done), +MAKE_STATE_PARAM (flr_resetting), +MAKE_STATE_PARAM (flr_finishing), +MAKE_STATE_PARAM (flr_failed), +MAKE_STATE_PARAM (mismatch), +}; + +KUNIT_ARRAY_PARAM (flr_must_pass_from, flr_must_pass_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (stop_must_pass_from, stop_must_pass_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (stop_must_fail_from, stop_must_fail_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (stop_must_cancel_from, stop_must_cancel_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (pause_must_pass_from, pause_must_pass_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (pause_must_fail_from, pause_must_fail_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (pause_must_cancel_from, pause_must_cancel_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (resume_must_pass_from, resume_must_pass_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (resume_must_fail_from, resume_must_fail_from, state_param_get_desc); +KUNIT_ARRAY_PARAM (resume_must_cancel_from, resume_must_cancel_from, state_param_get_desc); + +static int mimic_pf_handle_vf_flr_done (struct xe_gt *gt,unsigned int vfid) +{ +pf_handle_vf_flr_done (gt, vfid); +return 0 ; +} + +static int mimic_pf_handle_vf_pause_done (struct xe_gt *gt,unsigned int vfid) +{ +pf_handle_vf_pause_done (gt, vfid); +return 0 ; +} + +static void prepare_state (struct kunit *test,unsigned int vfid, +const enum xe_gt_sriov_control_bits *bits,size_t num_bits) +{ +struct xe_gt *gt = test->priv; +size_t n; + +for (n =0 ; n < num_bits; n++) { +enum xe_gt_sriov_control_bits bit = bits[n]; + +KUNIT_ASSERT_TRUE (test,pf_enter_vf_state (gt, vfid, bit)); + +if (bit ==XE_GT_SRIOV_STATE_WIP ) { +pf_queue_vf (gt, vfid); + }else if (bit ==XE_GT_SRIOV_STATE_FLR_WAIT_GUC ) { +xe_kunit_helper_delayed_call (test,HZ /100 , + mimic_pf_handle_vf_flr_done, gt, vfid); + }else if (bit ==XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC ) { +xe_kunit_helper_delayed_call (test,HZ /100 , + mimic_pf_handle_vf_pause_done, gt, vfid); + } + } +} + +static void prepare_state_from_param (struct kunit *test) +{ +const struct state_param *p = test->param_value; + +prepare_state (test,VFUT1 , p->bits, p->num_bits); +} + +static void expect_not_pausing (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_WIP )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_SEND_PAUSE )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_GUC_DONE )); +} + +static void expect_not_in_pause (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +expect_not_pausing (test); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_FAILED )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSED )); +} + +static void expect_not_resuming (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_WIP )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_SEND_RESUME )); +} + +static void expect_not_in_resume (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +expect_not_resuming (test); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_FAILED )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUMED )); +} + +static void expect_not_stopping (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOP_WIP )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOP_SEND_STOP )); +} + +static void expect_not_in_stop (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +expect_not_stopping (test); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOP_FAILED )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOPPED )); +} + +static void expect_not_in_flr (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_SEND_START )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WAIT_GUC )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_GUC_DONE )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_SEND_FINISH )); +KUNIT_EXPECT_TRUE (test, +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +} + +static void expect_not_in_wip (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void expect_not_in_mismatch (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +} + +static void try_flr_vf (struct kunit *test,bool mimic_busy,bool late_reply) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + mimic_busy ? late_reply ? send_vf_control_cmd_busy_no_reply : + send_vf_control_cmd_busy_and_reply : + late_reply ? send_vf_control_cmd_pass_no_reply : + send_vf_control_cmd_pass_and_reply); + +if (late_reply) +xe_kunit_helper_delayed_call (test,HZ /10 , + mimic_pf_handle_vf_flr_done, gt,VFUT1 ); + +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); + +expect_not_in_flr (test); +expect_not_in_pause (test); +expect_not_in_resume (test); +expect_not_in_stop (test); +expect_not_in_mismatch (test); +expect_not_in_wip (test); +} + +static void flr_vf_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_flr_vf (test, false, false); +} + +static void flr_vf_needs_retry_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_flr_vf (test, true, false); +} + +static void flr_vf_needs_retry_late_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_flr_vf (test, true, true); +} + +static void flr_vf_fails_on_send (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_fail); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +KUNIT_EXPECT_NE (test, err, -ETIMEDOUT ); +KUNIT_EXPECT_NE (test, err, -ECANCELED ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void flr_vf_fails_on_reset (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.vfs[VFUT1 ].config.sanitize, + sanitize_vf_resources_fail); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +KUNIT_EXPECT_NE (test, err, -ETIMEDOUT ); +KUNIT_EXPECT_NE (test, err, -ECANCELED ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void flr_vf_rejected_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_reject); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +KUNIT_EXPECT_NE (test, err, -ETIMEDOUT ); +KUNIT_EXPECT_NE (test, err, -ECANCELED ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void flr_vf_unconfirmed_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_no_reply); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +KUNIT_EXPECT_EQ (test, err, -ETIMEDOUT ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +} + +static void flr_vf_confirmed_early_continue_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , flr_starting,ARRAY_SIZE (flr_starting)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_no_reply); + +pf_handle_vf_flr_done (gt,VFUT1 ); + +/* +* make sure SEND_START completes; +* successful reply from cmd_pass_no_reply should exit mismatch state +*/ +flush_work (>->sriov.pf.control.worker); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +} + +static void flr_vf_confirmed_early_reject_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , flr_starting,ARRAY_SIZE (flr_starting)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_reject); + +pf_handle_vf_flr_done (gt,VFUT1 ); + +/* +* make sure SEND_START completes; +* error from send_vf_control_cmd_reject should keep mismatch state +*/ +flush_work (>->sriov.pf.control.worker); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void flr_vf_confirmed_twice_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , flr_guc_done,ARRAY_SIZE (flr_guc_done)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_no_reply); + +pf_handle_vf_flr_done (gt,VFUT1 ); + +/* this is fully recoverable */ +KUNIT_EXPECT_EQ (test,0 ,pf_wait_vf_wip_done (gt,VFUT1 ,HZ )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +} + +static void flr_vf_confirmed_too_late_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , flr_failed,ARRAY_SIZE (flr_failed)); + +pf_handle_vf_flr_done (gt,VFUT1 ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void flr_vf_unsolicited_confirmation_from_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); + +pf_handle_vf_flr_done (gt,VFUT1 ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_FLR_FAILED )); +} + +static void flr_vf_wrong_confirmation_from_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , flr_waiting,ARRAY_SIZE (flr_waiting)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +pf_handle_vf_pause_done (gt,VFUT1 ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +} + +static void flr_vf_canceled_by_restart (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_busy_wait); + +xe_kunit_helper_delayed_call (test,HZ /10 , xe_gt_sriov_pf_control_restart, gt); + +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +expect_not_in_flr (test); +} + +static void try_stop_vf (struct kunit *test,bool mimic_busy) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + mimic_busy ? send_vf_control_cmd_busy_and_reply : + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOPPED )); +expect_not_stopping (test); +expect_not_in_pause (test); +expect_not_in_resume (test); +expect_not_in_mismatch (test); +} + +static void stop_vf_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_stop_vf (test, false); +} + +static void stop_vf_needs_retry_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_stop_vf (test, true); +} + +static void stop_vf_refused_from (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +prepare_state_from_param (test); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); +KUNIT_EXPECT_NE (test, err, -ECANCELED ); + +KUNIT_EXPECT_TRUE (test, err == -EALREADY || +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOP_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOP_FAILED )); +} + +static void stop_vf_fails_on_send (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_fail); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); +KUNIT_EXPECT_NE (test, err, -ETIMEDOUT ); +KUNIT_EXPECT_NE (test, err, -ECANCELED ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOP_FAILED )); +expect_not_stopping (test); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOPPED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void stop_vf_rejected_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_reject); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); +KUNIT_EXPECT_NE (test, err, -ETIMEDOUT ); +KUNIT_EXPECT_NE (test, err, -ECANCELED ); + +expect_not_stopping (test); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOP_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOPPED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void stop_vf_canceled_from (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state_from_param (test); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOP_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_STOPPED )); +} + +static void stop_vf_canceled_by_restart (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_busy_except_flr); + +xe_kunit_helper_delayed_call (test,HZ /10 , xe_gt_sriov_pf_control_restart, gt); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); +expect_not_in_stop (test); +} + +static void stop_vf_canceled_by_flr (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_busy_except_flr); + +xe_kunit_helper_delayed_call (test,HZ /10 , + xe_gt_sriov_pf_control_trigger_flr, gt,VFUT1 ); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); +expect_not_in_stop (test); +} + +static void try_pause_vf (struct kunit *test,bool mimic_busy) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + mimic_busy ? send_vf_control_cmd_busy_and_reply : + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSED )); +expect_not_pausing (test); +expect_not_in_mismatch (test); +} + +static void pause_vf_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_pause_vf (test, false); +} + +static void pause_vf_needs_retry_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_pause_vf (test, true); +} + +static void pause_vf_canceled_from (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state_from_param (test); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +expect_not_in_pause (test); +} + +static void pause_vf_refused_from (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +prepare_state_from_param (test); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +KUNIT_EXPECT_NE (test, err, -ECANCELED ); + +KUNIT_EXPECT_TRUE (test, err == -EALREADY || +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_FAILED )); +} + +static void pause_vf_rejected_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_reject); + +KUNIT_EXPECT_NE (test,0 ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void pause_vf_fails_on_send (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_fail); + +KUNIT_EXPECT_NE (test,0 ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_FAILED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_WIP )); +} + +static void pause_vf_unconfirmed_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_no_reply); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +KUNIT_EXPECT_EQ (test, err, -ETIMEDOUT ); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSE_FAILED )); +} + +static void pause_vf_canceled_by_restart (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_no_reply); + +xe_kunit_helper_delayed_call (test,HZ /10 , xe_gt_sriov_pf_control_restart, gt); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +expect_not_in_pause (test); +} + +static void pause_vf_canceled_by_flr (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_but_reply_flr_only); + +xe_kunit_helper_delayed_call (test,HZ /10 , + xe_gt_sriov_pf_control_trigger_flr, gt,VFUT1 ); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +expect_not_in_pause (test); +} + +static void pause_vf_canceled_by_stop (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_no_reply); + +xe_kunit_helper_delayed_call (test,HZ /10 , + xe_gt_sriov_pf_control_stop_vf, gt,VFUT1 ); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +expect_not_in_pause (test); +} + +static void try_resume_vf (struct kunit *test,bool mimic_busy) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + mimic_busy ? send_vf_control_cmd_busy_and_reply : + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUMED )); +expect_not_resuming (test); +expect_not_in_pause (test); +expect_not_in_mismatch (test); +expect_not_in_wip (test); +} + +static void resume_vf_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_resume_vf (test, false); +} + +static void resume_vf_needs_retry_from (struct kunit *test) +{ +prepare_state_from_param (test); +try_resume_vf (test, true); +} + +static void resume_vf_fails_on_send (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , paused,ARRAY_SIZE (paused)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_fail); + +KUNIT_EXPECT_NE (test,0 ,xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_FAILED )); + +expect_not_resuming (test); +expect_not_in_mismatch (test); +expect_not_in_wip (test); +} + +static void resume_vf_rejected_by_guc (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , paused,ARRAY_SIZE (paused)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_reject); + +KUNIT_EXPECT_NE (test,0 ,xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_PAUSED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_MISMATCH )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_FAILED )); + +expect_not_resuming (test); +expect_not_in_wip (test); +} + +static void resume_vf_canceled_from (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state_from_param (test); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUMED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_FAILED )); +expect_not_resuming (test); +} + +static void resume_vf_refused_from (struct kunit *test) +{ +struct xe_gt *gt = test->priv; +int err; + +prepare_state_from_param (test); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_NE (test,0 , err =xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); +KUNIT_EXPECT_NE (test, err, -EIO ); + +KUNIT_EXPECT_TRUE (test, err == -EALREADY || +pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_WIP )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_FAILED )); +} + +static void resume_vf_canceled_by_restart (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , paused,ARRAY_SIZE (paused)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_busy_except_flr); + +xe_kunit_helper_delayed_call (test,HZ /10 , xe_gt_sriov_pf_control_restart, gt); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUMED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_WIP )); +} + +static void resume_vf_canceled_by_flr (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , paused,ARRAY_SIZE (paused)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_busy_except_flr); + +xe_kunit_helper_delayed_call (test,HZ /10 , + xe_gt_sriov_pf_control_trigger_flr, gt,VFUT1 ); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUMED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_WIP )); +} + +static void resume_vf_canceled_by_stop (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +prepare_state (test,VFUT1 , paused,ARRAY_SIZE (paused)); + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_busy_except_stop); + +xe_kunit_helper_delayed_call (test,HZ /10 , + xe_gt_sriov_pf_control_stop_vf, gt,VFUT1 ); + +KUNIT_EXPECT_EQ (test, -ECANCELED ,xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); + +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUMED )); +KUNIT_EXPECT_TRUE (test,pf_expect_vf_not_state (gt,VFUT1 ,XE_GT_SRIOV_STATE_RESUME_WIP )); +} + +static void basic_pause_and_resume_vf (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_ASSERT_EQ (test,0 ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_resume_vf (gt,VFUT1 )); +} + +static void basic_pause_and_stop_vf (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_ASSERT_EQ (test,0 ,xe_gt_sriov_pf_control_pause_vf (gt,VFUT1 )); +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); +} + +static void basic_stop_and_flr_vf (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_stop_vf (gt,VFUT1 )); +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +} + +static void basic_flr_and_flr_vf (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +} + +static void basic_flr_vfs (struct kunit *test) +{ +struct xe_gt *gt = test->priv; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_and_reply); + +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_trigger_flr (gt,VFUT1 )); +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_trigger_flr (gt,VFUT2 )); +} + +static struct kunit_case pf_control_test_cases[] = { +KUNIT_CASE (basic_pause_and_resume_vf), +KUNIT_CASE (basic_pause_and_stop_vf), +KUNIT_CASE (basic_stop_and_flr_vf), +KUNIT_CASE (basic_flr_and_flr_vf), +KUNIT_CASE (basic_flr_vfs), + +KUNIT_CASE_PARAM (flr_vf_from, flr_must_pass_from_gen_params), +KUNIT_CASE_PARAM (flr_vf_needs_retry_from, flr_must_pass_from_gen_params), +KUNIT_CASE_PARAM (flr_vf_needs_retry_late_from, flr_must_pass_from_gen_params), +KUNIT_CASE (flr_vf_fails_on_send), +KUNIT_CASE (flr_vf_fails_on_reset), +KUNIT_CASE (flr_vf_rejected_by_guc), +KUNIT_CASE_SLOW (flr_vf_unconfirmed_by_guc), +KUNIT_CASE (flr_vf_confirmed_early_continue_by_guc), +KUNIT_CASE (flr_vf_confirmed_early_reject_by_guc), +KUNIT_CASE (flr_vf_confirmed_twice_by_guc), +KUNIT_CASE (flr_vf_confirmed_too_late_by_guc), +KUNIT_CASE (flr_vf_wrong_confirmation_from_guc), +KUNIT_CASE (flr_vf_unsolicited_confirmation_from_guc), +KUNIT_CASE (flr_vf_canceled_by_restart), + +KUNIT_CASE_PARAM (stop_vf_from, stop_must_pass_from_gen_params), +KUNIT_CASE_PARAM (stop_vf_needs_retry_from, stop_must_pass_from_gen_params), +KUNIT_CASE_PARAM (stop_vf_refused_from, stop_must_fail_from_gen_params), +KUNIT_CASE_PARAM (stop_vf_canceled_from, stop_must_cancel_from_gen_params), +KUNIT_CASE (stop_vf_fails_on_send), +KUNIT_CASE (stop_vf_rejected_by_guc), +KUNIT_CASE (stop_vf_canceled_by_flr), +KUNIT_CASE (stop_vf_canceled_by_restart), + +KUNIT_CASE_PARAM (pause_vf_from, pause_must_pass_from_gen_params), +KUNIT_CASE_PARAM (pause_vf_needs_retry_from, pause_must_pass_from_gen_params), +KUNIT_CASE_PARAM (pause_vf_refused_from, pause_must_fail_from_gen_params), +KUNIT_CASE_PARAM (pause_vf_canceled_from, pause_must_cancel_from_gen_params), +KUNIT_CASE (pause_vf_fails_on_send), +KUNIT_CASE (pause_vf_rejected_by_guc), +KUNIT_CASE_SLOW (pause_vf_unconfirmed_by_guc), +KUNIT_CASE (pause_vf_canceled_by_flr), +KUNIT_CASE (pause_vf_canceled_by_stop), +KUNIT_CASE (pause_vf_canceled_by_restart), + +KUNIT_CASE_PARAM (resume_vf_from, resume_must_pass_from_gen_params), +KUNIT_CASE_PARAM (resume_vf_needs_retry_from, resume_must_pass_from_gen_params), +KUNIT_CASE_PARAM (resume_vf_refused_from, resume_must_fail_from_gen_params), +KUNIT_CASE_PARAM (resume_vf_canceled_from, resume_must_cancel_from_gen_params), +KUNIT_CASE (resume_vf_fails_on_send), +KUNIT_CASE (resume_vf_rejected_by_guc), +KUNIT_CASE (resume_vf_canceled_by_flr), +KUNIT_CASE (resume_vf_canceled_by_stop), +KUNIT_CASE (resume_vf_canceled_by_restart), + + {} +}; + +static struct kunit_suite pf_control_suite = { + .name ="pf_control" , + .test_cases = pf_control_test_cases, + .init = pf_control_test_init, +}; + +kunit_test_suite (pf_control_suite);drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +3
-0@@ -4,6 +4,7 @@*/ #include <drm/drm_managed.h> +#include <kunit/static_stub.h> #include "abi/guc_actions_sriov_abi.h" @@ -196,6 +197,8 @@ static const char *control_bit_to_string(enum xe_gt_sriov_control_bits bit)static unsigned long pf_get_default_timeout (enum xe_gt_sriov_control_bits bit) { +KUNIT_STATIC_STUB_REDIRECT (pf_get_default_timeout, bit); +switch (bit) {case XE_GT_SRIOV_STATE_FLR_WAIT_GUC :case XE_GT_SRIOV_STATE_PAUSE_WAIT_GUC :
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c void xe_gt_sriov_pf_control_restart(struct xe_gt *gt) · line 1467
Quoted 7 lines
drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c +4
-0@@ -1458,3 +1461,7 @@ void xe_gt_sriov_pf_control_restart(struct xe_gt *gt)for (n =1 ; n <= totalvfs; n++)pf_enter_vf_ready (gt, n); } + +#if IS_BUILTIN (CONFIG_DRM_XE_KUNIT_TEST ) +#include "tests/xe_gt_sriov_pf_control_kunit.c" +#endif
The tests look fine. I tried to verify the states according to the available drawings of the state machine and I did not find any incorrectness. It seems to me that the tests could be expanded to include an additional basic test: basic_pause_and_flr_vf
But still:
Quoted 3 lines
Signature · 1 line
2.43.0
PATCH 12/12 drm/xe/tests: Add KUnit tests for VF control GuC messages
In reply to Michal WajdeczkoAdd KUnit tests (~50) to cover all possible VF control messages that could be seen by the PF, either expected or corrupted.
--- .../xe/tests/xe_gt_sriov_pf_control_kunit.c | 194 ++++++++++++++++++ 1 file changed, 194 insertions(+)
drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c +194 -0
@@ -1358,3 +1358,197 @@ static struct kunit_suite pf_control_suite = { };kunit_test_suite (pf_control_suite); + +#define PREP_MSG_0_VF_STATE_NOTIFY (mbz) \ + FIELD_PREP_CONST(GUC_HXG_MSG_0_ORIGIN, GUC_HXG_ORIGIN_GUC) | \ + FIELD_PREP_CONST(GUC_HXG_MSG_0_TYPE, GUC_HXG_TYPE_EVENT) | \ + FIELD_PREP_CONST(GUC_HXG_EVENT_MSG_0_DATA0, (mbz)) | \ + FIELD_PREP_CONST(GUC_HXG_EVENT_MSG_0_ACTION, GUC_ACTION_GUC2PF_VF_STATE_NOTIFY) + +#define PREP_MSG_VF_STATE_NOTIFY (mbz, vfid, e) \ + PREP_MSG_0_VF_STATE_NOTIFY(mbz), \ + FIELD_PREP_CONST(GUC2PF_VF_STATE_NOTIFY_EVENT_MSG_1_VFID, (vfid)), \ + FIELD_PREP_CONST(GUC2PF_VF_STATE_NOTIFY_EVENT_MSG_2_EVENT, (e)) + +static const u32 msg_pf_enable[] = { +PREP_MSG_VF_STATE_NOTIFY (0 ,0 ,GUC_PF_NOTIFY_VF_ENABLE ), +}; + +static const u32 msg_vf_flr[] = { +PREP_MSG_VF_STATE_NOTIFY (0 ,VFUT1 ,GUC_PF_NOTIFY_VF_FLR ), +}; + +static const u32 msg_vf_flr_done[] = { +PREP_MSG_VF_STATE_NOTIFY (0 ,VFUT1 ,GUC_PF_NOTIFY_VF_FLR_DONE ), +}; + +static const u32 msg_vf_pause_done[] = { +PREP_MSG_VF_STATE_NOTIFY (0 ,VFUT1 ,GUC_PF_NOTIFY_VF_PAUSE_DONE ), +}; + +static const u32 msg_vf_fixup[] = { +PREP_MSG_VF_STATE_NOTIFY (0 ,VFUT1 ,GUC_PF_NOTIFY_VF_FIXUP_DONE ), +}; + +static const u32 msg_pf_bad_mbz[] = { +PREP_MSG_VF_STATE_NOTIFY (1 ,0 ,GUC_PF_NOTIFY_VF_ENABLE ), +}; + +static const u32 msg_pf_invalid_event[] = { +PREP_MSG_VF_STATE_NOTIFY (0 ,0 ,0 ), +}; + +static const u32 msg_pf_unknown_event[] = { +PREP_MSG_VF_STATE_NOTIFY (0 ,0 ,GUC_PF_NOTIFY_VF_ENABLE +1 ), +}; + +static const u32 msg_vf_bad_mbz[] = { +PREP_MSG_VF_STATE_NOTIFY (1 ,VFUT1 ,GUC_PF_NOTIFY_VF_FLR ), +}; + +static const u32 msg_vf_bad_vfid[] = { +PREP_MSG_VF_STATE_NOTIFY (0 ,VFID (DUT_NUM_VFS +1 ),GUC_PF_NOTIFY_VF_FLR ), +}; + +static const u32 msg_vf_invalid_event[] = { +PREP_MSG_VF_STATE_NOTIFY (0 ,VFUT1 ,0 ), +}; + +static const u32 msg_vf_unknown_event[] = { +PREP_MSG_VF_STATE_NOTIFY (0 ,VFUT1 ,GUC_PF_NOTIFY_VF_FIXUP_DONE +1 ), +}; + +static const u32 msg_no_data[GUC_HXG_EVENT_MSG_MIN_LEN ] = { +PREP_MSG_0_VF_STATE_NOTIFY (0 ), +/* only header, missing both VFID and EVENT data */ +}; + +static const u32 msg_pf_too_short[GUC2PF_VF_STATE_NOTIFY_EVENT_MSG_LEN -1 ] = { +PREP_MSG_0_VF_STATE_NOTIFY (0 ), +PFID , +/* missing EVENT data */ +}; + +static const u32 msg_pf_too_long[GUC2PF_VF_STATE_NOTIFY_EVENT_MSG_LEN +1 ] = { +PREP_MSG_VF_STATE_NOTIFY (0 ,0 ,GUC_PF_NOTIFY_VF_ENABLE ), +0 ,/* unexpected extra DATA */ +}; + +static const u32 msg_vf_too_short[GUC2PF_VF_STATE_NOTIFY_EVENT_MSG_LEN -1 ] = { +PREP_MSG_0_VF_STATE_NOTIFY (0 ), +VFUT1 , +/* missing EVENT data */ +}; + +static const u32 msg_vf_too_long[GUC2PF_VF_STATE_NOTIFY_EVENT_MSG_LEN +1 ] = { +PREP_MSG_VF_STATE_NOTIFY (0 ,VFUT1 ,GUC_PF_NOTIFY_VF_FLR ), +0 ,/* unexpected extra DATA */ +}; + +struct msg_param { +const char *name; +const u32 *msg; +size_t len; +}; + +static void msg_param_get_desc (struct msg_param *p,char *desc) +{ +snprintf (desc,KUNIT_PARAM_DESC_SIZE ,"%s" , p->name); +} + +#define MAKE_MSG_PARAM (X ) { .name = #X, .msg = X, .len = ARRAY_SIZE(X) } + +#define LIST_MSG_PARAM_VALID \ + MAKE_MSG_PARAM(msg_pf_enable), \ + MAKE_MSG_PARAM(msg_vf_flr), \ + MAKE_MSG_PARAM(msg_vf_flr_done), \ + MAKE_MSG_PARAM(msg_vf_pause_done), \ + MAKE_MSG_PARAM(msg_vf_fixup) + +#define LIST_MSG_PARAM_INVALID \ + MAKE_MSG_PARAM(msg_no_data), \ + MAKE_MSG_PARAM(msg_pf_too_long), \ + MAKE_MSG_PARAM(msg_pf_too_short), \ + MAKE_MSG_PARAM(msg_pf_bad_mbz), \ + MAKE_MSG_PARAM(msg_pf_invalid_event), \ + MAKE_MSG_PARAM(msg_pf_unknown_event), \ + MAKE_MSG_PARAM(msg_vf_too_long), \ + MAKE_MSG_PARAM(msg_vf_too_short), \ + MAKE_MSG_PARAM(msg_vf_bad_mbz), \ + MAKE_MSG_PARAM(msg_vf_bad_vfid), \ + MAKE_MSG_PARAM(msg_vf_invalid_event), \ + MAKE_MSG_PARAM(msg_vf_unknown_event) + +static struct msg_param valid_messages[] = { +LIST_MSG_PARAM_VALID , +}; + +static struct msg_param invalid_messages[] = { +LIST_MSG_PARAM_INVALID , +}; + +static struct msg_param all_messages[] = { +LIST_MSG_PARAM_VALID , +LIST_MSG_PARAM_INVALID , +}; + +KUNIT_ARRAY_PARAM (valid_messages, valid_messages, msg_param_get_desc); +KUNIT_ARRAY_PARAM (invalid_messages, invalid_messages, msg_param_get_desc); +KUNIT_ARRAY_PARAM (all_messages, all_messages, msg_param_get_desc); + +static void xe_rejects_all_g2h (struct kunit *test) +{ +struct xe_device *xe = (xe_kunit_helper_xe_device_test_init (test), test->priv); +struct xe_gt *gt =xe_device_get_gt (xe,0 ); +const struct msg_param *p = test->param_value; + +KUNIT_EXPECT_FALSE (test,IS_SRIOV_PF (xe)); +KUNIT_EXPECT_EQ (test, -EPROTO ,xe_gt_sriov_pf_control_process_guc2pf (gt, p->msg, p->len)); +} + +static void vf_rejects_all_g2h (struct kunit *test) +{ +struct xe_device *xe = (xe_kunit_helper_xe_device_test_init (test), test->priv); +struct xe_gt *gt =xe_device_get_gt (xe,0 ); +const struct msg_param *p = test->param_value; + +KUNIT_EXPECT_FALSE (test,IS_SRIOV (xe)); + xe->sriov.__mode =XE_SRIOV_MODE_VF ; + +KUNIT_EXPECT_TRUE (test,IS_SRIOV_VF (xe)); +KUNIT_EXPECT_EQ (test, -EPROTO ,xe_gt_sriov_pf_control_process_guc2pf (gt, p->msg, p->len)); +} + +static void pf_rejects_malformed_g2h (struct kunit *test) +{ +struct xe_gt *gt = (pf_control_test_init (test), test->priv); +const struct msg_param *p = test->param_value; + +KUNIT_EXPECT_NE (test,0 ,xe_gt_sriov_pf_control_process_guc2pf (gt, p->msg, p->len)); +} + +static void pf_accepts_valid_g2h (struct kunit *test) +{ +struct xe_gt *gt = (pf_control_test_init (test), test->priv); +const struct msg_param *p = test->param_value; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_no_reply); + +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_process_guc2pf (gt, p->msg, p->len)); +} + +static struct kunit_case pf_control_guc_test_cases[] = { +KUNIT_CASE_PARAM (xe_rejects_all_g2h, all_messages_gen_params), +KUNIT_CASE_PARAM (vf_rejects_all_g2h, all_messages_gen_params), +KUNIT_CASE_PARAM (pf_rejects_malformed_g2h, invalid_messages_gen_params), +KUNIT_CASE_PARAM (pf_accepts_valid_g2h, valid_messages_gen_params), + {} +}; + +static struct kunit_suite pf_control_guc_suite = { + .name ="pf_control_guc" , + .test_cases = pf_control_guc_test_cases, +}; + +kunit_test_suite (pf_control_guc_suite);
Signature · 1 line
2.43.0
Re: [PATCH 12/12] drm/xe/tests: Add KUnit tests for VF control GuC messages
Michal Wajdeczko <[email protected]> wrote on pią [2024-sie-09 18:51:59 +0200]:
Quoted 201 lines
Add KUnit tests (~50) to cover all possible VF control messages that could be seen by the PF, either expected or corrupted.
Signed-off-by Michal Wajdeczko <[email protected]>Cc Lucas De Marchi <[email protected]>--- .../xe/tests/xe_gt_sriov_pf_control_kunit.c | 194 ++++++++++++++++++ 1 file changed, 194 insertions(+)drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c +184
-0@@ -1358,3 +1358,197 @@ static struct kunit_suite pf_control_suite = { };kunit_test_suite (pf_control_suite); + +#define PREP_MSG_0_VF_STATE_NOTIFY (mbz) \ + FIELD_PREP_CONST(GUC_HXG_MSG_0_ORIGIN, GUC_HXG_ORIGIN_GUC) | \ + FIELD_PREP_CONST(GUC_HXG_MSG_0_TYPE, GUC_HXG_TYPE_EVENT) | \ + FIELD_PREP_CONST(GUC_HXG_EVENT_MSG_0_DATA0, (mbz)) | \ + FIELD_PREP_CONST(GUC_HXG_EVENT_MSG_0_ACTION, GUC_ACTION_GUC2PF_VF_STATE_NOTIFY) + +#define PREP_MSG_VF_STATE_NOTIFY (mbz, vfid, e) \ + PREP_MSG_0_VF_STATE_NOTIFY(mbz), \ + FIELD_PREP_CONST(GUC2PF_VF_STATE_NOTIFY_EVENT_MSG_1_VFID, (vfid)), \ + FIELD_PREP_CONST(GUC2PF_VF_STATE_NOTIFY_EVENT_MSG_2_EVENT, (e)) + +static const u32 msg_pf_enable[] = { +PREP_MSG_VF_STATE_NOTIFY (0 ,0 ,GUC_PF_NOTIFY_VF_ENABLE ), +}; + +static const u32 msg_vf_flr[] = { +PREP_MSG_VF_STATE_NOTIFY (0 ,VFUT1 ,GUC_PF_NOTIFY_VF_FLR ), +}; + +static const u32 msg_vf_flr_done[] = { +PREP_MSG_VF_STATE_NOTIFY (0 ,VFUT1 ,GUC_PF_NOTIFY_VF_FLR_DONE ), +}; + +static const u32 msg_vf_pause_done[] = { +PREP_MSG_VF_STATE_NOTIFY (0 ,VFUT1 ,GUC_PF_NOTIFY_VF_PAUSE_DONE ), +}; + +static const u32 msg_vf_fixup[] = { +PREP_MSG_VF_STATE_NOTIFY (0 ,VFUT1 ,GUC_PF_NOTIFY_VF_FIXUP_DONE ), +}; + +static const u32 msg_pf_bad_mbz[] = { +PREP_MSG_VF_STATE_NOTIFY (1 ,0 ,GUC_PF_NOTIFY_VF_ENABLE ), +}; + +static const u32 msg_pf_invalid_event[] = { +PREP_MSG_VF_STATE_NOTIFY (0 ,0 ,0 ), +}; + +static const u32 msg_pf_unknown_event[] = { +PREP_MSG_VF_STATE_NOTIFY (0 ,0 ,GUC_PF_NOTIFY_VF_ENABLE +1 ), +}; + +static const u32 msg_vf_bad_mbz[] = { +PREP_MSG_VF_STATE_NOTIFY (1 ,VFUT1 ,GUC_PF_NOTIFY_VF_FLR ), +}; + +static const u32 msg_vf_bad_vfid[] = { +PREP_MSG_VF_STATE_NOTIFY (0 ,VFID (DUT_NUM_VFS +1 ),GUC_PF_NOTIFY_VF_FLR ), +}; + +static const u32 msg_vf_invalid_event[] = { +PREP_MSG_VF_STATE_NOTIFY (0 ,VFUT1 ,0 ), +}; + +static const u32 msg_vf_unknown_event[] = { +PREP_MSG_VF_STATE_NOTIFY (0 ,VFUT1 ,GUC_PF_NOTIFY_VF_FIXUP_DONE +1 ), +}; + +static const u32 msg_no_data[GUC_HXG_EVENT_MSG_MIN_LEN ] = { +PREP_MSG_0_VF_STATE_NOTIFY (0 ), +/* only header, missing both VFID and EVENT data */ +}; + +static const u32 msg_pf_too_short[GUC2PF_VF_STATE_NOTIFY_EVENT_MSG_LEN -1 ] = { +PREP_MSG_0_VF_STATE_NOTIFY (0 ), +PFID , +/* missing EVENT data */ +}; + +static const u32 msg_pf_too_long[GUC2PF_VF_STATE_NOTIFY_EVENT_MSG_LEN +1 ] = { +PREP_MSG_VF_STATE_NOTIFY (0 ,0 ,GUC_PF_NOTIFY_VF_ENABLE ), +0 ,/* unexpected extra DATA */ +}; + +static const u32 msg_vf_too_short[GUC2PF_VF_STATE_NOTIFY_EVENT_MSG_LEN -1 ] = { +PREP_MSG_0_VF_STATE_NOTIFY (0 ), +VFUT1 , +/* missing EVENT data */ +}; + +static const u32 msg_vf_too_long[GUC2PF_VF_STATE_NOTIFY_EVENT_MSG_LEN +1 ] = { +PREP_MSG_VF_STATE_NOTIFY (0 ,VFUT1 ,GUC_PF_NOTIFY_VF_FLR ), +0 ,/* unexpected extra DATA */ +}; + +struct msg_param { +const char *name; +const u32 *msg; +size_t len; +}; + +static void msg_param_get_desc (struct msg_param *p,char *desc) +{ +snprintf (desc,KUNIT_PARAM_DESC_SIZE ,"%s" , p->name); +} + +#define MAKE_MSG_PARAM (X ) { .name = #X, .msg = X, .len = ARRAY_SIZE(X) } + +#define LIST_MSG_PARAM_VALID \ + MAKE_MSG_PARAM(msg_pf_enable), \ + MAKE_MSG_PARAM(msg_vf_flr), \ + MAKE_MSG_PARAM(msg_vf_flr_done), \ + MAKE_MSG_PARAM(msg_vf_pause_done), \ + MAKE_MSG_PARAM(msg_vf_fixup) + +#define LIST_MSG_PARAM_INVALID \ + MAKE_MSG_PARAM(msg_no_data), \ + MAKE_MSG_PARAM(msg_pf_too_long), \ + MAKE_MSG_PARAM(msg_pf_too_short), \ + MAKE_MSG_PARAM(msg_pf_bad_mbz), \ + MAKE_MSG_PARAM(msg_pf_invalid_event), \ + MAKE_MSG_PARAM(msg_pf_unknown_event), \ + MAKE_MSG_PARAM(msg_vf_too_long), \ + MAKE_MSG_PARAM(msg_vf_too_short), \ + MAKE_MSG_PARAM(msg_vf_bad_mbz), \ + MAKE_MSG_PARAM(msg_vf_bad_vfid), \ + MAKE_MSG_PARAM(msg_vf_invalid_event), \ + MAKE_MSG_PARAM(msg_vf_unknown_event) + +static struct msg_param valid_messages[] = { +LIST_MSG_PARAM_VALID , +}; + +static struct msg_param invalid_messages[] = { +LIST_MSG_PARAM_INVALID , +}; + +static struct msg_param all_messages[] = { +LIST_MSG_PARAM_VALID , +LIST_MSG_PARAM_INVALID , +}; + +KUNIT_ARRAY_PARAM (valid_messages, valid_messages, msg_param_get_desc); +KUNIT_ARRAY_PARAM (invalid_messages, invalid_messages, msg_param_get_desc); +KUNIT_ARRAY_PARAM (all_messages, all_messages, msg_param_get_desc); + +static void xe_rejects_all_g2h (struct kunit *test) +{ +struct xe_device *xe = (xe_kunit_helper_xe_device_test_init (test), test->priv); +struct xe_gt *gt =xe_device_get_gt (xe,0 ); +const struct msg_param *p = test->param_value; + +KUNIT_EXPECT_FALSE (test,IS_SRIOV_PF (xe)); +KUNIT_EXPECT_EQ (test, -EPROTO ,xe_gt_sriov_pf_control_process_guc2pf (gt, p->msg, p->len)); +} + +static void vf_rejects_all_g2h (struct kunit *test) +{ +struct xe_device *xe = (xe_kunit_helper_xe_device_test_init (test), test->priv); +struct xe_gt *gt =xe_device_get_gt (xe,0 ); +const struct msg_param *p = test->param_value; + +KUNIT_EXPECT_FALSE (test,IS_SRIOV (xe)); + xe->sriov.__mode =XE_SRIOV_MODE_VF ; + +KUNIT_EXPECT_TRUE (test,IS_SRIOV_VF (xe)); +KUNIT_EXPECT_EQ (test, -EPROTO ,xe_gt_sriov_pf_control_process_guc2pf (gt, p->msg, p->len)); +} + +static void pf_rejects_malformed_g2h (struct kunit *test) +{ +struct xe_gt *gt = (pf_control_test_init (test), test->priv); +const struct msg_param *p = test->param_value; + +KUNIT_EXPECT_NE (test,0 ,xe_gt_sriov_pf_control_process_guc2pf (gt, p->msg, p->len)); +} + +static void pf_accepts_valid_g2h (struct kunit *test) +{ +struct xe_gt *gt = (pf_control_test_init (test), test->priv); +const struct msg_param *p = test->param_value; + +XE_TEST_ACTIVATE_STUB (test, gt->sriov.pf.control.send_vf_control_cmd, + send_vf_control_cmd_pass_no_reply); + +KUNIT_EXPECT_EQ (test,0 ,xe_gt_sriov_pf_control_process_guc2pf (gt, p->msg, p->len)); +} + +static struct kunit_case pf_control_guc_test_cases[] = { +KUNIT_CASE_PARAM (xe_rejects_all_g2h, all_messages_gen_params), +KUNIT_CASE_PARAM (vf_rejects_all_g2h, all_messages_gen_params), +KUNIT_CASE_PARAM (pf_rejects_malformed_g2h, invalid_messages_gen_params),
drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c static struct kunit_suite pf_control_suite = { · line 1554
Quoted 10 lines
drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c +10
-0+ KUNIT_CASE_PARAM(pf_accepts_valid_g2h, valid_messages_gen_params), + {} +}; + +static struct kunit_suite pf_control_guc_suite = { + .name ="pf_control_guc" , + .test_cases = pf_control_guc_test_cases, +}; + +kunit_test_suite (pf_control_guc_suite);
LGTM:
Quoted 3 lines
Signature · 1 line
2.43.0
Patchwork
CI✓ CI.Patch_applied: success for PF: Improve VF control
In reply to Michal Wajdeczko== Series Details ==
== Series Details ==
Series: PF: Improve VF control
URL : https://patchwork.freedesktop.org/series/137095/
State : success
== Summary ==
=== Applying kernel patches on branch 'drm-tip' with base: ===
Base commit: fecad563ec6f drm-tip: 2024y-08m-09d-16h-02m-57s UTC integration manifest === git am output follows ===
Applying: drm/xe/pf: Add function to sanitize VF resources
Applying: drm/xe/pf: Fix documentation formatting
Applying: drm/xe/pf: Drop GuC notifications for non-existing VF
Applying: drm/xe/pf: Improve VF control
Applying: drm/xe/tests: Allow deferred function call during KUnit test
Applying: drm/xe/tests: Add helper macro to detect if KUnit is running
Applying: drm/xe/tests: Add helpers to call stubs out of KUnit context
Applying: drm/xe/guc: Define stub for xe_guc_ct_send_recv()
Applying: drm/xe/pf: Define stub for pf_sanitize_vf_resources()
Applying: drm/xe/pf: Define stub for pf_send_vf_control_cmd()
Applying: drm/xe/tests: Add KUnit tests for VF control state machines
Applying: drm/xe/tests: Add KUnit tests for VF control GuC messages
Patchwork
CI✗ CI.checkpatch: warning for PF: Improve VF control
In reply to Michal Wajdeczko== Series Details ==
== Series Details ==
Series: PF: Improve VF control
URL : https://patchwork.freedesktop.org/series/137095/
State : warning
== Summary ==
+ KERNEL=/kernel
+ git clone https://gitlab.freedesktop.org/drm/maintainer-tools mt Cloning into 'mt'...
warning: redirecting to https://gitlab.freedesktop.org/drm/maintainer-tools.git/
+ git -C mt rev-list -n1 origin/master dc547930fbb1350eaf6bde84653b9ac973a411db
+ cd /kernel
+ git config --global --add safe.directory /kernel
+ git log -n1
commit fd73c71c97fffd2bec57fd1668b358dabbc67ba7
Author: Michal Wajdeczko <[email protected]> Date: Fri Aug 9 18:51:59 2024 +0200
drm/xe/tests: Add KUnit tests for VF control GuC messages
Add KUnit tests (~50) to cover all possible VF control messages that could be seen by the PF, either expected or corrupted.
+ /mt/dim checkpatch fecad563ec6fa0d6c38ecd36d660a663ad390ea1 drm-intel b5c32521ec62 drm/xe/pf: Add function to sanitize VF resources7a34bbd55e9b drm/xe/pf: Fix documentation formatting12c0de5efa95 drm/xe/pf: Drop GuC notifications for non-existing VF26c80196d378 drm/xe/pf: Improve VF control
-:1368: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #1368:
new file mode 100644
total: 0 errors, 1 warnings, 0 checks, 1449 lines checked 6badbd614dff drm/xe/tests: Allow deferred function call during KUnit test -:228: CHECK:MACRO_ARG_REUSE: Macro argument reuse 'func' - possible side-effects? #228: FILE: drivers/gpu/drm/xe/tests/xe_kunit_helpers.h:47:
+#define xe_kunit_helper_delayed_call(test, delay, func, args...) \
+ _Generic(func, \
+ void (*)(struct xe_device *) : \
+ xe_kunit_helper_delayed_call_void_xe_device, \
+ void (*)(struct xe_gt *) : \
+ xe_kunit_helper_delayed_call_void_xe_gt, \
+ int (*)(struct xe_gt *, unsigned int) : \
+ xe_kunit_helper_delayed_call_int_xe_gt_uint \
+ )(test, delay, func, args)
-:229: CHECK:CAMELCASE: Avoid CamelCase: <_Generic> #229: FILE: drivers/gpu/drm/xe/tests/xe_kunit_helpers.h:48:
+ _Generic(func, \
-:230: CHECK:SPACING: No space is necessary after a cast #230: FILE: drivers/gpu/drm/xe/tests/xe_kunit_helpers.h:49:
+ void (*)(struct xe_device *) : \
-:232: CHECK:SPACING: No space is necessary after a cast #232: FILE: drivers/gpu/drm/xe/tests/xe_kunit_helpers.h:51:
+ void (*)(struct xe_gt *) : \
total: 0 errors, 0 warnings, 4 checks, 199 lines checked4efcd1651e1e drm/xe/tests: Add helper macro to detect if KUnit is running 715a4af91bf4 drm/xe/tests: Add helpers to call stubs out of KUnit context -:58: WARNING:MACRO_WITH_FLOW_CONTROL: Macros with flow control statements should be avoided #58: FILE: drivers/gpu/drm/xe/tests/xe_test.h:93:
+#define XE_TEST_REDIRECT(stub, args...) \
+do { \
+ typeof(stub) replacement = (stub); \
+ if (XE_TEST_RUNNING()) { \
+ if (unlikely(replacement)) { \
+ pr_info(KUNIT_SUBTEST_INDENT "# %s: calling stub %ps\n", \
+ __func__, replacement); \
+ return replacement(args); \
+ } \
+ } \
+} while (0)
total: 0 errors, 1 warnings, 0 checks, 85 lines checked2155fe82e6cd drm/xe/guc: Define stub for xe_guc_ct_send_recv()d056743a5124 drm/xe/pf: Define stub for pf_sanitize_vf_resources()1dc5182fd47d drm/xe/pf: Define stub for pf_send_vf_control_cmd()a298f3076b50 drm/xe/tests: Add KUnit tests for VF control state machines
-:14: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #14:
new file mode 100644
-:309: CHECK:MACRO_ARG_REUSE: Macro argument reuse 'X' - possible side-effects? #309: FILE: drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c:291:
+#define MAKE_STATE_PARAM(X) { .name = #X, .bits = X, .num_bits = ARRAY_SIZE(X) }
total: 0 errors, 1 warnings, 1 checks, 1382 lines checkedfd73c71c97ff drm/xe/tests: Add KUnit tests for VF control GuC messages -:21: ERROR:COMPLEX_MACRO: Macros with complex values should be enclosed in parentheses #21: FILE: drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c:1362:
+#define PREP_MSG_0_VF_STATE_NOTIFY(mbz) \
+ FIELD_PREP_CONST(GUC_HXG_MSG_0_ORIGIN, GUC_HXG_ORIGIN_GUC) | \
+ FIELD_PREP_CONST(GUC_HXG_MSG_0_TYPE, GUC_HXG_TYPE_EVENT) | \
+ FIELD_PREP_CONST(GUC_HXG_EVENT_MSG_0_DATA0, (mbz)) | \
+ FIELD_PREP_CONST(GUC_HXG_EVENT_MSG_0_ACTION, GUC_ACTION_GUC2PF_VF_STATE_NOTIFY)
-:27: ERROR:COMPLEX_MACRO: Macros with complex values should be enclosed in parentheses #27: FILE: drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c:1368:
+#define PREP_MSG_VF_STATE_NOTIFY(mbz, vfid, e) \
+ PREP_MSG_0_VF_STATE_NOTIFY(mbz), \
+ FIELD_PREP_CONST(GUC2PF_VF_STATE_NOTIFY_EVENT_MSG_1_VFID, (vfid)), \
+ FIELD_PREP_CONST(GUC2PF_VF_STATE_NOTIFY_EVENT_MSG_2_EVENT, (e))
-:118: CHECK:MACRO_ARG_REUSE: Macro argument reuse 'X' - possible side-effects? #118: FILE: drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c:1459:
+#define MAKE_MSG_PARAM(X) { .name = #X, .msg = X, .len = ARRAY_SIZE(X) }
-:120: ERROR:COMPLEX_MACRO: Macros with complex values should be enclosed in parentheses #120: FILE: drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c:1461:
+#define LIST_MSG_PARAM_VALID \
+ MAKE_MSG_PARAM(msg_pf_enable), \
+ MAKE_MSG_PARAM(msg_vf_flr), \
+ MAKE_MSG_PARAM(msg_vf_flr_done), \
+ MAKE_MSG_PARAM(msg_vf_pause_done), \
+ MAKE_MSG_PARAM(msg_vf_fixup)
-:127: ERROR:COMPLEX_MACRO: Macros with complex values should be enclosed in parentheses #127: FILE: drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c:1468:
+#define LIST_MSG_PARAM_INVALID \
+ MAKE_MSG_PARAM(msg_no_data), \
+ MAKE_MSG_PARAM(msg_pf_too_long), \
+ MAKE_MSG_PARAM(msg_pf_too_short), \
+ MAKE_MSG_PARAM(msg_pf_bad_mbz), \
+ MAKE_MSG_PARAM(msg_pf_invalid_event), \
+ MAKE_MSG_PARAM(msg_pf_unknown_event), \
+ MAKE_MSG_PARAM(msg_vf_too_long), \
+ MAKE_MSG_PARAM(msg_vf_too_short), \
+ MAKE_MSG_PARAM(msg_vf_bad_mbz), \
+ MAKE_MSG_PARAM(msg_vf_bad_vfid), \
+ MAKE_MSG_PARAM(msg_vf_invalid_event), \
+ MAKE_MSG_PARAM(msg_vf_unknown_event)
total: 4 errors, 0 warnings, 1 checks, 197 lines checked
Patchwork
CI✗ CI.KUnit: failure for PF: Improve VF control
In reply to Michal Wajdeczko== Series Details ==
== Series Details ==
Series: PF: Improve VF control
URL : https://patchwork.freedesktop.org/series/137095/
State : failure
== Summary ==
+ trap cleanup EXIT
+ /kernel/tools/testing/kunit/kunit.py run --kunitconfig /kernel/drivers/gpu/drm/xe/.kunitconfig ERROR:root:../lib/iomap.c:156:5: warning: no previous prototype for ‘ioread64_lo_hi’ [-Wmissing-prototypes] 156 | u64 ioread64_lo_hi(const void __iomem *addr)
| ^~~~~~~~~~~~~~
../lib/iomap.c:163:5: warning: no previous prototype for ‘ioread64_hi_lo’ [-Wmissing-prototypes]
163 | u64 ioread64_hi_lo(const void __iomem *addr)
| ^~~~~~~~~~~~~~
../lib/iomap.c:170:5: warning: no previous prototype for ‘ioread64be_lo_hi’ [-Wmissing-prototypes]
170 | u64 ioread64be_lo_hi(const void __iomem *addr)
| ^~~~~~~~~~~~~~~~
../lib/iomap.c:178:5: warning: no previous prototype for ‘ioread64be_hi_lo’ [-Wmissing-prototypes]
178 | u64 ioread64be_hi_lo(const void __iomem *addr)
| ^~~~~~~~~~~~~~~~
../lib/iomap.c:264:6: warning: no previous prototype for ‘iowrite64_lo_hi’ [-Wmissing-prototypes]
264 | void iowrite64_lo_hi(u64 val, void __iomem *addr)
| ^~~~~~~~~~~~~~~
../lib/iomap.c:272:6: warning: no previous prototype for ‘iowrite64_hi_lo’ [-Wmissing-prototypes]
272 | void iowrite64_hi_lo(u64 val, void __iomem *addr)
| ^~~~~~~~~~~~~~~
../lib/iomap.c:280:6: warning: no previous prototype for ‘iowrite64be_lo_hi’ [-Wmissing-prototypes]
280 | void iowrite64be_lo_hi(u64 val, void __iomem *addr)
| ^~~~~~~~~~~~~~~~~
../lib/iomap.c:288:6: warning: no previous prototype for ‘iowrite64be_hi_lo’ [-Wmissing-prototypes]
288 | void iowrite64be_hi_lo(u64 val, void __iomem *addr)
| ^~~~~~~~~~~~~~~~~
In file included from ../include/kunit/static_stub.h:18,
from ../drivers/gpu/drm/xe/xe_gt_sriov_pf_control.c:7:
../drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c: In function ‘pf_control_test_init’:
../drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c:52:30: error: implicit declaration of function ‘__pf_peek_vf_state’; did you mean ‘pf_peek_vf_state’? [-Werror=implicit-function-declaration]
52 | KUNIT_ASSERT_EQ(test, 0ul, *__pf_peek_vf_state(gt, VFUT1));
| ^~~~~~~~~~~~~~~~~~
../include/kunit/test.h:725:15: note: in definition of macro ‘KUNIT_BASE_BINARY_ASSERTION’
725 | const typeof(right) __right = (right); \
| ^~~~~
../include/kunit/test.h:1299:2: note: in expansion of macro ‘KUNIT_BINARY_INT_ASSERTION’
1299 | KUNIT_BINARY_INT_ASSERTION(test, \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
../include/kunit/test.h:1296:2: note: in expansion of macro ‘KUNIT_ASSERT_EQ_MSG’
1296 | KUNIT_ASSERT_EQ_MSG(test, left, right, NULL)
| ^~~~~~~~~~~~~~~~~~~
../drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c:52:2: note: in expansion of macro ‘KUNIT_ASSERT_EQ’
52 | KUNIT_ASSERT_EQ(test, 0ul, *__pf_peek_vf_state(gt, VFUT1));
| ^~~~~~~~~~~~~~~
../drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c:52:29: error: invalid type argument of unary ‘*’ (have ‘int’)
52 | KUNIT_ASSERT_EQ(test, 0ul, *__pf_peek_vf_state(gt, VFUT1));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/kunit/test.h:725:15: note: in definition of macro ‘KUNIT_BASE_BINARY_ASSERTION’
725 | const typeof(right) __right = (right); \
| ^~~~~
../include/kunit/test.h:1299:2: note: in expansion of macro ‘KUNIT_BINARY_INT_ASSERTION’
1299 | KUNIT_BINARY_INT_ASSERTION(test, \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
../include/kunit/test.h:1296:2: note: in expansion of macro ‘KUNIT_ASSERT_EQ_MSG’
1296 | KUNIT_ASSERT_EQ_MSG(test, left, right, NULL)
| ^~~~~~~~~~~~~~~~~~~
../drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c:52:2: note: in expansion of macro ‘KUNIT_ASSERT_EQ’
52 | KUNIT_ASSERT_EQ(test, 0ul, *__pf_peek_vf_state(gt, VFUT1));
| ^~~~~~~~~~~~~~~
../drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c:52:29: error: invalid type argument of unary ‘*’ (have ‘int’)
52 | KUNIT_ASSERT_EQ(test, 0ul, *__pf_peek_vf_state(gt, VFUT1));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~../include/kunit/test.h:725:33: note: in definition of macro ‘KUNIT_BASE_BINARY_ASSERTION’
725 | const typeof(right) __right = (right); \
| ^~~~~../include/kunit/test.h:1299:2: note: in expansion of macro ‘KUNIT_BINARY_INT_ASSERTION’
1299 | KUNIT_BINARY_INT_ASSERTION(test, \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
../include/kunit/test.h:1296:2: note: in expansion of macro ‘KUNIT_ASSERT_EQ_MSG’
1296 | KUNIT_ASSERT_EQ_MSG(test, left, right, NULL)
| ^~~~~~~~~~~~~~~~~~~
../drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c:52:2: note: in expansion of macro ‘KUNIT_ASSERT_EQ’
52 | KUNIT_ASSERT_EQ(test, 0ul, *__pf_peek_vf_state(gt, VFUT1));
| ^~~~~~~~~~~~~~~
../drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c:53:29: error: invalid type argument of unary ‘*’ (have ‘int’)
53 | KUNIT_ASSERT_EQ(test, 0ul, *__pf_peek_vf_state(gt, VFUT2));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/kunit/test.h:725:15: note: in definition of macro ‘KUNIT_BASE_BINARY_ASSERTION’
725 | const typeof(right) __right = (right); \
| ^~~~~
../include/kunit/test.h:1299:2: note: in expansion of macro ‘KUNIT_BINARY_INT_ASSERTION’
1299 | KUNIT_BINARY_INT_ASSERTION(test, \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
../include/kunit/test.h:1296:2: note: in expansion of macro ‘KUNIT_ASSERT_EQ_MSG’
1296 | KUNIT_ASSERT_EQ_MSG(test, left, right, NULL)
| ^~~~~~~~~~~~~~~~~~~
../drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c:53:2: note: in expansion of macro ‘KUNIT_ASSERT_EQ’
53 | KUNIT_ASSERT_EQ(test, 0ul, *__pf_peek_vf_state(gt, VFUT2));
| ^~~~~~~~~~~~~~~
../drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c:53:29: error: invalid type argument of unary ‘*’ (have ‘int’)
53 | KUNIT_ASSERT_EQ(test, 0ul, *__pf_peek_vf_state(gt, VFUT2));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~../include/kunit/test.h:725:33: note: in definition of macro ‘KUNIT_BASE_BINARY_ASSERTION’
725 | const typeof(right) __right = (right); \
| ^~~~~../include/kunit/test.h:1299:2: note: in expansion of macro ‘KUNIT_BINARY_INT_ASSERTION’
1299 | KUNIT_BINARY_INT_ASSERTION(test, \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
../include/kunit/test.h:1296:2: note: in expansion of macro ‘KUNIT_ASSERT_EQ_MSG’
1296 | KUNIT_ASSERT_EQ_MSG(test, left, right, NULL)
| ^~~~~~~~~~~~~~~~~~~
../drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c:53:2: note: in expansion of macro ‘KUNIT_ASSERT_EQ’
53 | KUNIT_ASSERT_EQ(test, 0ul, *__pf_peek_vf_state(gt, VFUT2));
| ^~~~~~~~~~~~~~~cc1: some warnings being treated as errors
make[7]: *** [../scripts/Makefile.build:244: drivers/gpu/drm/xe/xe_gt_sriov_pf_control.o] Error 1 make[7]: *** Waiting for unfinished jobs....
make[6]: *** [../scripts/Makefile.build:485: drivers/gpu/drm/xe] Error 2
make[5]: *** [../scripts/Makefile.build:485: drivers/gpu/drm] Error 2
make[4]: *** [../scripts/Makefile.build:485: drivers/gpu] Error 2
make[3]: *** [../scripts/Makefile.build:485: drivers] Error 2
make[2]: *** [/kernel/Makefile:1925: .] Error 2
make[1]: *** [/kernel/Makefile:224: __sub-make] Error 2
make: *** [Makefile:224: __sub-make] Error 2
[16:58:13] Configuring KUnit Kernel ...
Generating .config ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig [16:58:17] Building KUnit Kernel ... Populating config with: $ make ARCH=um O=.kunit olddefconfig Building with: $ make ARCH=um O=.kunit --jobs=48 + cleanup ++ stat -c %u:%g /kernel + chown -R 1003:1003 /kernel
Patchwork
CI✓ CI.Patch_applied: success for PF: Improve VF control (rev2)
In reply to Michal Wajdeczko== Series Details ==
== Series Details ==
Series: PF: Improve VF control (rev2)
URL : https://patchwork.freedesktop.org/series/137095/
State : success
== Summary ==
=== Applying kernel patches on branch 'drm-tip' with base: ===
Base commit: 13384fb5b1e7 drm-tip: 2024y-08m-09d-16h-57m-03s UTC integration manifest === git am output follows ===
Applying: drm/xe/pf: Add function to sanitize VF resources
Applying: drm/xe/pf: Fix documentation formatting
Applying: drm/xe/pf: Drop GuC notifications for non-existing VF
Applying: drm/xe/pf: Improve VF control
Applying: drm/xe/tests: Allow deferred function call during KUnit test
Applying: drm/xe/tests: Add helper macro to detect if KUnit is running
Applying: drm/xe/tests: Add helpers to call stubs out of KUnit context
Applying: drm/xe/guc: Define stub for xe_guc_ct_send_recv()
Applying: drm/xe/pf: Define stub for pf_sanitize_vf_resources()
Applying: drm/xe/pf: Define stub for pf_send_vf_control_cmd()
Applying: drm/xe/tests: Add KUnit tests for VF control state machines
Applying: drm/xe/tests: Add KUnit tests for VF control GuC messages
Patchwork
CI✗ CI.checkpatch: warning for PF: Improve VF control (rev2)
In reply to Michal Wajdeczko== Series Details ==
== Series Details ==
Series: PF: Improve VF control (rev2)
URL : https://patchwork.freedesktop.org/series/137095/
State : warning
== Summary ==
+ KERNEL=/kernel
+ git clone https://gitlab.freedesktop.org/drm/maintainer-tools mt Cloning into 'mt'...
warning: redirecting to https://gitlab.freedesktop.org/drm/maintainer-tools.git/
+ git -C mt rev-list -n1 origin/master dc547930fbb1350eaf6bde84653b9ac973a411db
+ cd /kernel
+ git config --global --add safe.directory /kernel
+ git log -n1
commit 212c7364eedabdf4b150159217ed04cddfbe3938
Author: Michal Wajdeczko <[email protected]> Date: Fri Aug 9 18:51:59 2024 +0200
drm/xe/tests: Add KUnit tests for VF control GuC messages
Add KUnit tests (~50) to cover all possible VF control messages that could be seen by the PF, either expected or corrupted.
+ /mt/dim checkpatch 13384fb5b1e76e7012902cc10b1e49023358dc1d drm-intel 0a484014e46f drm/xe/pf: Add function to sanitize VF resources9f652709710d drm/xe/pf: Fix documentation formatting8578b29fcb67 drm/xe/pf: Drop GuC notifications for non-existing VFe279e187175d drm/xe/pf: Improve VF control
-:1368: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #1368:
new file mode 100644
total: 0 errors, 1 warnings, 0 checks, 1449 lines checked e040e86a370b drm/xe/tests: Allow deferred function call during KUnit test -:228: CHECK:MACRO_ARG_REUSE: Macro argument reuse 'func' - possible side-effects? #228: FILE: drivers/gpu/drm/xe/tests/xe_kunit_helpers.h:47:
+#define xe_kunit_helper_delayed_call(test, delay, func, args...) \
+ _Generic(func, \
+ void (*)(struct xe_device *) : \
+ xe_kunit_helper_delayed_call_void_xe_device, \
+ void (*)(struct xe_gt *) : \
+ xe_kunit_helper_delayed_call_void_xe_gt, \
+ int (*)(struct xe_gt *, unsigned int) : \
+ xe_kunit_helper_delayed_call_int_xe_gt_uint \
+ )(test, delay, func, args)
-:229: CHECK:CAMELCASE: Avoid CamelCase: <_Generic> #229: FILE: drivers/gpu/drm/xe/tests/xe_kunit_helpers.h:48:
+ _Generic(func, \
-:230: CHECK:SPACING: No space is necessary after a cast #230: FILE: drivers/gpu/drm/xe/tests/xe_kunit_helpers.h:49:
+ void (*)(struct xe_device *) : \
-:232: CHECK:SPACING: No space is necessary after a cast #232: FILE: drivers/gpu/drm/xe/tests/xe_kunit_helpers.h:51:
+ void (*)(struct xe_gt *) : \
total: 0 errors, 0 warnings, 4 checks, 199 lines checked98602ffea42f drm/xe/tests: Add helper macro to detect if KUnit is running 04c60e3bd72b drm/xe/tests: Add helpers to call stubs out of KUnit context -:58: WARNING:MACRO_WITH_FLOW_CONTROL: Macros with flow control statements should be avoided #58: FILE: drivers/gpu/drm/xe/tests/xe_test.h:93:
+#define XE_TEST_REDIRECT(stub, args...) \
+do { \
+ typeof(stub) replacement = (stub); \
+ if (XE_TEST_RUNNING()) { \
+ if (unlikely(replacement)) { \
+ pr_info(KUNIT_SUBTEST_INDENT "# %s: calling stub %ps\n", \
+ __func__, replacement); \
+ return replacement(args); \
+ } \
+ } \
+} while (0)
total: 0 errors, 1 warnings, 0 checks, 85 lines checkedc0262a6eb9dd drm/xe/guc: Define stub for xe_guc_ct_send_recv()d5ec33588fae drm/xe/pf: Define stub for pf_sanitize_vf_resources()9af0ff056bee drm/xe/pf: Define stub for pf_send_vf_control_cmd()218db1d2315c drm/xe/tests: Add KUnit tests for VF control state machines
-:14: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #14:
new file mode 100644
-:309: CHECK:MACRO_ARG_REUSE: Macro argument reuse 'X' - possible side-effects? #309: FILE: drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c:291:
+#define MAKE_STATE_PARAM(X) { .name = #X, .bits = X, .num_bits = ARRAY_SIZE(X) }
total: 0 errors, 1 warnings, 1 checks, 1382 lines checked212c7364eeda drm/xe/tests: Add KUnit tests for VF control GuC messages -:21: ERROR:COMPLEX_MACRO: Macros with complex values should be enclosed in parentheses #21: FILE: drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c:1362:
+#define PREP_MSG_0_VF_STATE_NOTIFY(mbz) \
+ FIELD_PREP_CONST(GUC_HXG_MSG_0_ORIGIN, GUC_HXG_ORIGIN_GUC) | \
+ FIELD_PREP_CONST(GUC_HXG_MSG_0_TYPE, GUC_HXG_TYPE_EVENT) | \
+ FIELD_PREP_CONST(GUC_HXG_EVENT_MSG_0_DATA0, (mbz)) | \
+ FIELD_PREP_CONST(GUC_HXG_EVENT_MSG_0_ACTION, GUC_ACTION_GUC2PF_VF_STATE_NOTIFY)
-:27: ERROR:COMPLEX_MACRO: Macros with complex values should be enclosed in parentheses #27: FILE: drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c:1368:
+#define PREP_MSG_VF_STATE_NOTIFY(mbz, vfid, e) \
+ PREP_MSG_0_VF_STATE_NOTIFY(mbz), \
+ FIELD_PREP_CONST(GUC2PF_VF_STATE_NOTIFY_EVENT_MSG_1_VFID, (vfid)), \
+ FIELD_PREP_CONST(GUC2PF_VF_STATE_NOTIFY_EVENT_MSG_2_EVENT, (e))
-:118: CHECK:MACRO_ARG_REUSE: Macro argument reuse 'X' - possible side-effects? #118: FILE: drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c:1459:
+#define MAKE_MSG_PARAM(X) { .name = #X, .msg = X, .len = ARRAY_SIZE(X) }
-:120: ERROR:COMPLEX_MACRO: Macros with complex values should be enclosed in parentheses #120: FILE: drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c:1461:
+#define LIST_MSG_PARAM_VALID \
+ MAKE_MSG_PARAM(msg_pf_enable), \
+ MAKE_MSG_PARAM(msg_vf_flr), \
+ MAKE_MSG_PARAM(msg_vf_flr_done), \
+ MAKE_MSG_PARAM(msg_vf_pause_done), \
+ MAKE_MSG_PARAM(msg_vf_fixup)
-:127: ERROR:COMPLEX_MACRO: Macros with complex values should be enclosed in parentheses #127: FILE: drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_control_kunit.c:1468:
+#define LIST_MSG_PARAM_INVALID \
+ MAKE_MSG_PARAM(msg_no_data), \
+ MAKE_MSG_PARAM(msg_pf_too_long), \
+ MAKE_MSG_PARAM(msg_pf_too_short), \
+ MAKE_MSG_PARAM(msg_pf_bad_mbz), \
+ MAKE_MSG_PARAM(msg_pf_invalid_event), \
+ MAKE_MSG_PARAM(msg_pf_unknown_event), \
+ MAKE_MSG_PARAM(msg_vf_too_long), \
+ MAKE_MSG_PARAM(msg_vf_too_short), \
+ MAKE_MSG_PARAM(msg_vf_bad_mbz), \
+ MAKE_MSG_PARAM(msg_vf_bad_vfid), \
+ MAKE_MSG_PARAM(msg_vf_invalid_event), \
+ MAKE_MSG_PARAM(msg_vf_unknown_event)
total: 4 errors, 0 warnings, 1 checks, 197 lines checked
Patchwork
CI✓ CI.KUnit: success for PF: Improve VF control (rev2)
In reply to Michal Wajdeczko== Series Details ==
== Series Details ==
Series: PF: Improve VF control (rev2)
URL : https://patchwork.freedesktop.org/series/137095/
State : success
== Summary ==
+ trap cleanup EXIT
+ /kernel/tools/testing/kunit/kunit.py run --kunitconfig /kernel/drivers/gpu/drm/xe/.kunitconfig [17:29:08] Configuring KUnit Kernel ...
Generating .config ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig
[17:29:12] Building KUnit Kernel ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig
Building with:
$ make ARCH=um O=.kunit --jobs=48
../lib/iomap.c:156:5: warning: no previous prototype for ‘ioread64_lo_hi’ [-Wmissing-prototypes]
156 | u64 ioread64_lo_hi(const void __iomem *addr)
| ^~~~~~~~~~~~~~
../lib/iomap.c:163:5: warning: no previous prototype for ‘ioread64_hi_lo’ [-Wmissing-prototypes]
163 | u64 ioread64_hi_lo(const void __iomem *addr)
| ^~~~~~~~~~~~~~
../lib/iomap.c:170:5: warning: no previous prototype for ‘ioread64be_lo_hi’ [-Wmissing-prototypes]
170 | u64 ioread64be_lo_hi(const void __iomem *addr)
| ^~~~~~~~~~~~~~~~
../lib/iomap.c:178:5: warning: no previous prototype for ‘ioread64be_hi_lo’ [-Wmissing-prototypes]
178 | u64 ioread64be_hi_lo(const void __iomem *addr)
| ^~~~~~~~~~~~~~~~
../lib/iomap.c:264:6: warning: no previous prototype for ‘iowrite64_lo_hi’ [-Wmissing-prototypes]
264 | void iowrite64_lo_hi(u64 val, void __iomem *addr)
| ^~~~~~~~~~~~~~~
../lib/iomap.c:272:6: warning: no previous prototype for ‘iowrite64_hi_lo’ [-Wmissing-prototypes]
272 | void iowrite64_hi_lo(u64 val, void __iomem *addr)
| ^~~~~~~~~~~~~~~
../lib/iomap.c:280:6: warning: no previous prototype for ‘iowrite64be_lo_hi’ [-Wmissing-prototypes]
280 | void iowrite64be_lo_hi(u64 val, void __iomem *addr)
| ^~~~~~~~~~~~~~~~~
../lib/iomap.c:288:6: warning: no previous prototype for ‘iowrite64be_hi_lo’ [-Wmissing-prototypes]
288 | void iowrite64be_hi_lo(u64 val, void __iomem *addr)
| ^~~~~~~~~~~~~~~~~[17:29:39] Starting KUnit Kernel (1/1)...
[17:29:39] ============================================================ Running tests with:
$ .kunit/linux kunit.enable=1 mem=1G console=tty kunit_shutdown=halt [17:29:39] =================== guc_dbm (7 subtests) =================== [17:29:39] [PASSED] test_empty [17:29:39] [PASSED] test_default [17:29:39] ======================== test_size ======================== [17:29:39] [PASSED] 4 [17:29:39] [PASSED] 8 [17:29:39] [PASSED] 32 [17:29:39] [PASSED] 256 [17:29:39] ==================== [PASSED] test_size ==================== [17:29:39] ======================= test_reuse ======================== [17:29:39] [PASSED] 4 [17:29:39] [PASSED] 8 [17:29:39] [PASSED] 32 [17:29:39] [PASSED] 256 [17:29:39] =================== [PASSED] test_reuse ==================== [17:29:39] =================== test_range_overlap ==================== [17:29:39] [PASSED] 4 [17:29:39] [PASSED] 8 [17:29:39] [PASSED] 32 [17:29:39] [PASSED] 256 [17:29:39] =============== [PASSED] test_range_overlap ================ [17:29:39] =================== test_range_compact ==================== [17:29:39] [PASSED] 4 [17:29:39] [PASSED] 8 [17:29:39] [PASSED] 32 [17:29:39] [PASSED] 256 [17:29:39] =============== [PASSED] test_range_compact ================ [17:29:39] ==================== test_range_spare ===================== [17:29:39] [PASSED] 4 [17:29:39] [PASSED] 8 [17:29:39] [PASSED] 32 [17:29:39] [PASSED] 256 [17:29:39] ================ [PASSED] test_range_spare ================= [17:29:39] ===================== [PASSED] guc_dbm ===================== [17:29:39] =================== guc_idm (6 subtests) =================== [17:29:39] [PASSED] bad_init [17:29:39] [PASSED] no_init [17:29:39] [PASSED] init_fini [17:29:39] [PASSED] check_used [17:29:39] [PASSED] check_quota [17:29:39] [PASSED] check_all [17:29:39] ===================== [PASSED] guc_idm ===================== [17:29:39] ================== no_relay (3 subtests) =================== [17:29:39] [PASSED] xe_drops_guc2pf_if_not_ready [17:29:39] [PASSED] xe_drops_guc2vf_if_not_ready [17:29:39] [PASSED] xe_rejects_send_if_not_ready [17:29:39] ==================== [PASSED] no_relay ===================== [17:29:39] ================== pf_relay (14 subtests) ================== [17:29:39] [PASSED] pf_rejects_guc2pf_too_short [17:29:39] [PASSED] pf_rejects_guc2pf_too_long [17:29:39] [PASSED] pf_rejects_guc2pf_no_payload [17:29:39] [PASSED] pf_fails_no_payload [17:29:39] [PASSED] pf_fails_bad_origin [17:29:39] [PASSED] pf_fails_bad_type [17:29:39] [PASSED] pf_txn_reports_error [17:29:39] [PASSED] pf_txn_sends_pf2guc [17:29:39] [PASSED] pf_sends_pf2guc [17:29:39] [SKIPPED] pf_loopback_nop [17:29:39] [SKIPPED] pf_loopback_echo [17:29:39] [SKIPPED] pf_loopback_fail [17:29:39] [SKIPPED] pf_loopback_busy [17:29:39] [SKIPPED] pf_loopback_retry [17:29:39] ==================== [PASSED] pf_relay ===================== [17:29:39] ================== vf_relay (3 subtests) =================== [17:29:39] [PASSED] vf_rejects_guc2vf_too_short [17:29:39] [PASSED] vf_rejects_guc2vf_too_long [17:29:39] [PASSED] vf_rejects_guc2vf_no_payload [17:29:39] ==================== [PASSED] vf_relay ===================== [17:29:39] =============== pf_control_guc (4 subtests) ================ [17:29:39] =================== xe_rejects_all_g2h ==================== [17:29:39] [PASSED] msg_pf_enable [17:29:39] [PASSED] msg_vf_flr [17:29:39] [PASSED] msg_vf_flr_done [17:29:39] [PASSED] msg_vf_pause_done [17:29:39] [PASSED] msg_vf_fixup [17:29:39] [PASSED] msg_no_data [17:29:39] [PASSED] msg_pf_too_long [17:29:39] [PASSED] msg_pf_too_short [17:29:39] [PASSED] msg_pf_bad_mbz [17:29:39] [PASSED] msg_pf_invalid_event [17:29:39] [PASSED] msg_pf_unknown_event [17:29:39] [PASSED] msg_vf_too_long [17:29:39] [PASSED] msg_vf_too_short [17:29:39] [PASSED] msg_vf_bad_mbz [17:29:39] [PASSED] msg_vf_bad_vfid [17:29:39] [PASSED] msg_vf_invalid_event [17:29:39] [PASSED] msg_vf_unknown_event [17:29:39] =============== [PASSED] xe_rejects_all_g2h ================ [17:29:39] =================== vf_rejects_all_g2h ==================== [17:29:39] [PASSED] msg_pf_enable [17:29:39] [PASSED] msg_vf_flr [17:29:39] [PASSED] msg_vf_flr_done [17:29:39] [PASSED] msg_vf_pause_done [17:29:39] [PASSED] msg_vf_fixup [17:29:39] [PASSED] msg_no_data [17:29:39] [PASSED] msg_pf_too_long [17:29:39] [PASSED] msg_pf_too_short [17:29:39] [PASSED] msg_pf_bad_mbz [17:29:39] [PASSED] msg_pf_invalid_event [17:29:39] [PASSED] msg_pf_unknown_event [17:29:39] [PASSED] msg_vf_too_long [17:29:39] [PASSED] msg_vf_too_short [17:29:39] [PASSED] msg_vf_bad_mbz [17:29:39] [PASSED] msg_vf_bad_vfid [17:29:39] [PASSED] msg_vf_invalid_event [17:29:39] [PASSED] msg_vf_unknown_event [17:29:39] =============== [PASSED] vf_rejects_all_g2h ================ [17:29:39] ================ pf_rejects_malformed_g2h ================= [17:29:39] [PASSED] msg_no_data [17:29:39] [PASSED] msg_pf_too_long [17:29:39] [PASSED] msg_pf_too_short [17:29:39] [PASSED] msg_pf_bad_mbz [17:29:39] [PASSED] msg_pf_invalid_event [17:29:39] [PASSED] msg_pf_unknown_event [17:29:39] [PASSED] msg_vf_too_long [17:29:39] [PASSED] msg_vf_too_short [17:29:39] [PASSED] msg_vf_bad_mbz [17:29:39] [PASSED] msg_vf_bad_vfid [17:29:39] [PASSED] msg_vf_invalid_event [17:29:39] [PASSED] msg_vf_unknown_event [17:29:39] ============ [PASSED] pf_rejects_malformed_g2h ============= [17:29:39] ================== pf_accepts_valid_g2h =================== [17:29:39] [PASSED] msg_pf_enable [17:29:39] [PASSED] msg_vf_flr [17:29:39] [PASSED] msg_vf_flr_done [17:29:39] [PASSED] msg_vf_pause_done [17:29:39] [PASSED] msg_vf_fixup [17:29:39] ============== [PASSED] pf_accepts_valid_g2h =============== [17:29:39] ================= [PASSED] pf_control_guc ================== [17:29:39] ================= pf_control (46 subtests) ================= [17:29:39] [PASSED] basic_pause_and_resume_vf [17:29:39] [PASSED] basic_pause_and_stop_vf [17:29:39] [PASSED] basic_stop_and_flr_vf [17:29:39] [PASSED] basic_flr_and_flr_vf [17:29:39] [PASSED] basic_flr_vfs [17:29:39] ======================= flr_vf_from ======================= [17:29:39] [PASSED] ready [17:29:39] [PASSED] flr_starting [17:29:39] [PASSED] flr_starting_paused [17:29:39] [PASSED] flr_starting_stopped [17:29:39] [PASSED] flr_waiting [17:29:39] [PASSED] flr_guc_done [17:29:39] [PASSED] flr_resetting [17:29:39] [PASSED] flr_finishing [17:29:39] [PASSED] flr_failed [17:29:39] [PASSED] stopping [17:29:39] [PASSED] stop_failed [17:29:39] [PASSED] stop_rejected [17:29:39] [PASSED] stopped [17:29:39] [PASSED] pausing [17:29:39] [PASSED] pausing_wait_guc [17:29:39] [PASSED] pausing_guc_done [17:29:39] [PASSED] pause_failed [17:29:39] [PASSED] pause_rejected [17:29:39] [PASSED] paused [17:29:39] [PASSED] resuming [17:29:39] [PASSED] resume_failed [17:29:39] [PASSED] resume_rejected [17:29:39] [PASSED] resumed [17:29:39] [PASSED] mismatch [17:29:39] =================== [PASSED] flr_vf_from =================== [17:29:39] ================= flr_vf_needs_retry_from ================= [17:29:39] [PASSED] ready [17:29:39] [PASSED] flr_starting [17:29:39] [PASSED] flr_starting_paused [17:29:39] [PASSED] flr_starting_stopped [17:29:39] [PASSED] flr_waiting [17:29:39] [PASSED] flr_guc_done [17:29:39] [PASSED] flr_resetting [17:29:39] [PASSED] flr_finishing [17:29:39] [PASSED] flr_failed [17:29:39] [PASSED] stopping [17:29:39] [PASSED] stop_failed [17:29:39] [PASSED] stop_rejected [17:29:39] [PASSED] stopped [17:29:39] [PASSED] pausing [17:29:39] [PASSED] pausing_wait_guc [17:29:39] [PASSED] pausing_guc_done [17:29:39] [PASSED] pause_failed [17:29:39] [PASSED] pause_rejected [17:29:39] [PASSED] paused [17:29:39] [PASSED] resuming [17:29:39] [PASSED] resume_failed [17:29:39] [PASSED] resume_rejected [17:29:39] [PASSED] resumed [17:29:39] [PASSED] mismatch [17:29:39] ============= [PASSED] flr_vf_needs_retry_from ============= [17:29:39] ============== flr_vf_needs_retry_late_from =============== [17:29:39] [PASSED] ready [17:29:39] [PASSED] flr_starting [17:29:39] [PASSED] flr_starting_paused [17:29:39] [PASSED] flr_starting_stopped [17:29:39] [PASSED] flr_waiting [17:29:39] [PASSED] flr_guc_done [17:29:39] [PASSED] flr_resetting [17:29:39] [PASSED] flr_finishing [17:29:39] [PASSED] flr_failed [17:29:40] [PASSED] stopping [17:29:40] [PASSED] stop_failed [17:29:40] [PASSED] stop_rejected [17:29:40] [PASSED] stopped [17:29:40] [PASSED] pausing [17:29:40] [PASSED] pausing_wait_guc [17:29:40] [PASSED] pausing_guc_done [17:29:40] [PASSED] pause_failed [17:29:40] [PASSED] pause_rejected [17:29:40] [PASSED] paused [17:29:41] [PASSED] resuming [17:29:41] [PASSED] resume_failed [17:29:41] [PASSED] resume_rejected [17:29:41] [PASSED] resumed [17:29:41] [PASSED] mismatch [17:29:41] ========== [PASSED] flr_vf_needs_retry_late_from =========== [17:29:41] [PASSED] flr_vf_fails_on_send [17:29:41] [PASSED] flr_vf_fails_on_reset [17:29:41] [PASSED] flr_vf_rejected_by_guc [17:29:42] [PASSED] flr_vf_unconfirmed_by_guc [17:29:42] [PASSED] flr_vf_confirmed_early_continue_by_guc [17:29:42] [PASSED] flr_vf_confirmed_early_reject_by_guc [17:29:42] [PASSED] flr_vf_confirmed_twice_by_guc [17:29:42] [PASSED] flr_vf_confirmed_too_late_by_guc [17:29:42] [PASSED] flr_vf_wrong_confirmation_from_guc [17:29:42] [PASSED] flr_vf_unsolicited_confirmation_from_guc [17:29:42] [PASSED] flr_vf_canceled_by_restart [17:29:42] ====================== stop_vf_from ======================= [17:29:42] [PASSED] ready [17:29:42] [PASSED] stop_failed [17:29:42] [PASSED] stop_rejected [17:29:42] [PASSED] pausing [17:29:42] [PASSED] pausing_wait_guc [17:29:42] [PASSED] pausing_guc_done [17:29:42] [PASSED] pause_failed [17:29:42] [PASSED] pause_rejected [17:29:42] [PASSED] paused [17:29:42] [PASSED] resuming [17:29:42] [PASSED] resume_failed [17:29:42] [PASSED] resume_rejected [17:29:42] [PASSED] resumed [17:29:42] [PASSED] mismatch [17:29:42] [PASSED] flr_failed [17:29:42] ================== [PASSED] stop_vf_from =================== [17:29:42] ================ stop_vf_needs_retry_from ================= [17:29:42] [PASSED] ready [17:29:42] [PASSED] stop_failed [17:29:42] [PASSED] stop_rejected [17:29:42] [PASSED] pausing [17:29:42] [PASSED] pausing_wait_guc [17:29:42] [PASSED] pausing_guc_done [17:29:42] [PASSED] pause_failed [17:29:42] [PASSED] pause_rejected [17:29:42] [PASSED] paused [17:29:42] [PASSED] resuming [17:29:42] [PASSED] resume_failed [17:29:42] [PASSED] resume_rejected [17:29:42] [PASSED] resumed [17:29:42] [PASSED] mismatch [17:29:42] [PASSED] flr_failed [17:29:42] ============ [PASSED] stop_vf_needs_retry_from ============= [17:29:42] ================== stop_vf_refused_from =================== [17:29:42] [PASSED] stopping [17:29:42] [PASSED] stopping_paused [17:29:42] [PASSED] stopped [17:29:42] [PASSED] flr_starting_stopped [17:29:42] ============== [PASSED] stop_vf_refused_from =============== [17:29:42] ================== stop_vf_canceled_from ================== [17:29:42] [PASSED] flr_starting [17:29:42] [PASSED] flr_starting_paused [17:29:42] [PASSED] flr_waiting [17:29:42] [PASSED] flr_guc_done [17:29:42] [PASSED] flr_resetting [17:29:42] [PASSED] flr_finishing [17:29:42] ============== [PASSED] stop_vf_canceled_from ============== [17:29:42] [PASSED] stop_vf_fails_on_send [17:29:42] [PASSED] stop_vf_rejected_by_guc [17:29:42] [PASSED] stop_vf_canceled_by_flr [17:29:42] [PASSED] stop_vf_canceled_by_restart [17:29:42] ====================== pause_vf_from ====================== [17:29:42] [PASSED] ready [17:29:42] [PASSED] pause_failed [17:29:42] [PASSED] pause_rejected [17:29:42] [PASSED] resumed [17:29:43] [PASSED] mismatch [17:29:43] [PASSED] stop_failed [17:29:43] [PASSED] stop_rejected [17:29:43] [PASSED] flr_failed [17:29:43] ================== [PASSED] pause_vf_from ================== [17:29:43] ================ pause_vf_needs_retry_from ================ [17:29:43] [PASSED] ready [17:29:43] [PASSED] pause_failed [17:29:43] [PASSED] pause_rejected [17:29:43] [PASSED] resumed [17:29:43] [PASSED] mismatch [17:29:43] [PASSED] stop_failed [17:29:43] [PASSED] stop_rejected [17:29:43] [PASSED] flr_failed [17:29:43] ============ [PASSED] pause_vf_needs_retry_from ============ [17:29:43] ================== pause_vf_refused_from ================== [17:29:43] [PASSED] pausing [17:29:43] [PASSED] pausing_wait_guc [17:29:43] [PASSED] pausing_guc_done [17:29:43] [PASSED] paused [17:29:43] [PASSED] resuming [17:29:43] [PASSED] resume_failed [17:29:43] [PASSED] resume_rejected [17:29:43] [PASSED] stopped [17:29:43] ============== [PASSED] pause_vf_refused_from ============== [17:29:43] ================= pause_vf_canceled_from ================== [17:29:43] [PASSED] flr_starting [17:29:43] [PASSED] flr_waiting [17:29:43] [PASSED] flr_guc_done [17:29:43] [PASSED] flr_resetting [17:29:43] [PASSED] flr_finishing [17:29:43] [PASSED] stopping [17:29:43] ============= [PASSED] pause_vf_canceled_from ============== [17:29:43] [PASSED] pause_vf_fails_on_send [17:29:43] [PASSED] pause_vf_rejected_by_guc [17:29:44] [PASSED] pause_vf_unconfirmed_by_guc [17:29:44] [PASSED] pause_vf_canceled_by_flr [17:29:44] [PASSED] pause_vf_canceled_by_stop [17:29:44] [PASSED] pause_vf_canceled_by_restart [17:29:44] ===================== resume_vf_from ====================== [17:29:44] [PASSED] paused [17:29:44] [PASSED] resume_failed [17:29:44] [PASSED] resume_rejected [17:29:44] ================= [PASSED] resume_vf_from ================== [17:29:44] =============== resume_vf_needs_retry_from ================ [17:29:44] [PASSED] paused [17:29:44] [PASSED] resume_failed [17:29:44] [PASSED] resume_rejected [17:29:44] =========== [PASSED] resume_vf_needs_retry_from ============ [17:29:44] ================= resume_vf_refused_from ================== [17:29:44] [PASSED] ready [17:29:44] [PASSED] pausing [17:29:44] [PASSED] pausing_wait_guc [17:29:44] [PASSED] pausing_guc_done [17:29:44] [PASSED] pause_failed [17:29:44] [PASSED] pause_rejected [17:29:44] [PASSED] resuming [17:29:44] [PASSED] resumed [17:29:44] [PASSED] stopping [17:29:44] [PASSED] stop_failed [17:29:44] [PASSED] stop_rejected [17:29:44] [PASSED] stopped [17:29:44] [PASSED] flr_starting [17:29:44] [PASSED] flr_waiting [17:29:44] [PASSED] flr_guc_done [17:29:44] [PASSED] flr_resetting [17:29:44] [PASSED] flr_finishing [17:29:44] [PASSED] flr_failed [17:29:44] [PASSED] mismatch [17:29:44] ============= [PASSED] resume_vf_refused_from ============== [17:29:44] ================= resume_vf_canceled_from ================= [17:29:44] [PASSED] flr_starting_paused stty: 'standard input': Inappropriate ioctl for device [17:29:44] [PASSED] stopping_paused [17:29:44] ============= [PASSED] resume_vf_canceled_from ============= [17:29:44] [PASSED] resume_vf_fails_on_send [17:29:44] [PASSED] resume_vf_rejected_by_guc [17:29:44] [PASSED] resume_vf_canceled_by_flr [17:29:44] [PASSED] resume_vf_canceled_by_stop [17:29:44] [PASSED] resume_vf_canceled_by_restart [17:29:44] =================== [PASSED] pf_control ==================== [17:29:44] ================= pf_service (11 subtests) ================= [17:29:44] [PASSED] pf_negotiate_any [17:29:44] [PASSED] pf_negotiate_base_match [17:29:44] [PASSED] pf_negotiate_base_newer [17:29:44] [PASSED] pf_negotiate_base_next [17:29:44] [SKIPPED] pf_negotiate_base_older [17:29:44] [PASSED] pf_negotiate_base_prev [17:29:44] [PASSED] pf_negotiate_latest_match [17:29:44] [PASSED] pf_negotiate_latest_newer [17:29:44] [PASSED] pf_negotiate_latest_next [17:29:44] [SKIPPED] pf_negotiate_latest_older [17:29:44] [SKIPPED] pf_negotiate_latest_prev [17:29:44] =================== [PASSED] pf_service ==================== [17:29:44] ===================== lmtt (1 subtest) ===================== [17:29:44] ======================== test_ops ========================= [17:29:44] [PASSED] 2-level [17:29:44] [PASSED] multi-level [17:29:44] ==================== [PASSED] test_ops ===================== [17:29:44] ====================== [PASSED] lmtt ======================= [17:29:44] =================== xe_mocs (2 subtests) =================== [17:29:44] ================ xe_live_mocs_kernel_kunit ================ [17:29:44] =========== [SKIPPED] xe_live_mocs_kernel_kunit ============ [17:29:44] ================ xe_live_mocs_reset_kunit ================= [17:29:44] ============ [SKIPPED] xe_live_mocs_reset_kunit ============ [17:29:44] ==================== [SKIPPED] xe_mocs ===================== [17:29:44] ================= xe_migrate (2 subtests) ================== [17:29:44] ================= xe_migrate_sanity_kunit ================= [17:29:44] ============ [SKIPPED] xe_migrate_sanity_kunit ============= [17:29:44] ================== xe_validate_ccs_kunit ================== [17:29:44] ============= [SKIPPED] xe_validate_ccs_kunit ============== [17:29:44] =================== [SKIPPED] xe_migrate =================== [17:29:44] ================== xe_dma_buf (1 subtest) ================== [17:29:44] ==================== xe_dma_buf_kunit ===================== [17:29:44] ================ [SKIPPED] xe_dma_buf_kunit ================ [17:29:44] =================== [SKIPPED] xe_dma_buf =================== [17:29:44] ==================== xe_bo (2 subtests) ==================== [17:29:44] ================== xe_ccs_migrate_kunit =================== [17:29:44] ============== [SKIPPED] xe_ccs_migrate_kunit ============== [17:29:44] ==================== xe_bo_evict_kunit ==================== [17:29:44] =============== [SKIPPED] xe_bo_evict_kunit ================ [17:29:44] ===================== [SKIPPED] xe_bo ====================== [17:29:44] ==================== args (11 subtests) ==================== [17:29:44] [PASSED] count_args_test [17:29:44] [PASSED] call_args_example [17:29:44] [PASSED] call_args_test [17:29:44] [PASSED] drop_first_arg_example [17:29:44] [PASSED] drop_first_arg_test [17:29:44] [PASSED] first_arg_example [17:29:44] [PASSED] first_arg_test [17:29:44] [PASSED] last_arg_example [17:29:44] [PASSED] last_arg_test [17:29:44] [PASSED] pick_arg_example [17:29:44] [PASSED] sep_comma_example [17:29:44] ====================== [PASSED] args ======================= [17:29:44] =================== xe_pci (2 subtests) ==================== [17:29:44] [PASSED] xe_gmdid_graphics_ip [17:29:44] [PASSED] xe_gmdid_media_ip [17:29:44] ===================== [PASSED] xe_pci ====================== [17:29:44] =================== xe_rtp (2 subtests) ==================== [17:29:44] =============== xe_rtp_process_to_sr_tests ================ [17:29:44] [PASSED] coalesce-same-reg [17:29:44] [PASSED] no-match-no-add [17:29:44] [PASSED] match-or [17:29:44] [PASSED] match-or-xfail [17:29:44] [PASSED] no-match-no-add-multiple-rules [17:29:44] [PASSED] two-regs-two-entries [17:29:44] [PASSED] clr-one-set-other [17:29:44] [PASSED] set-field [17:29:44] [PASSED] conflict-duplicate [17:29:44] [PASSED] conflict-not-disjoint [17:29:44] [PASSED] conflict-reg-type [17:29:44] =========== [PASSED] xe_rtp_process_to_sr_tests ============ [17:29:44] ================== xe_rtp_process_tests =================== [17:29:44] [PASSED] active1 [17:29:44] [PASSED] active2 [17:29:44] [PASSED] active-inactive [17:29:44] [PASSED] inactive-active [17:29:44] [PASSED] inactive-1st_or_active-inactive [17:29:44] [PASSED] inactive-2nd_or_active-inactive [17:29:44] [PASSED] inactive-last_or_active-inactive [17:29:44] [PASSED] inactive-no_or_active-inactive [17:29:44] ============== [PASSED] xe_rtp_process_tests =============== [17:29:44] ===================== [PASSED] xe_rtp ====================== [17:29:44] ==================== xe_wa (1 subtest) ===================== [17:29:44] ======================== xe_wa_gt ========================= [17:29:44] [PASSED] TIGERLAKE (B0) [17:29:44] [PASSED] DG1 (A0) [17:29:44] [PASSED] DG1 (B0) [17:29:44] [PASSED] ALDERLAKE_S (A0) [17:29:44] [PASSED] ALDERLAKE_S (B0) [17:29:44] [PASSED] ALDERLAKE_S (C0) [17:29:44] [PASSED] ALDERLAKE_S (D0) [17:29:44] [PASSED] ALDERLAKE_P (A0) [17:29:44] [PASSED] ALDERLAKE_P (B0) [17:29:44] [PASSED] ALDERLAKE_P (C0) [17:29:44] [PASSED] ALDERLAKE_S_RPLS (D0) [17:29:44] [PASSED] ALDERLAKE_P_RPLU (E0) [17:29:44] [PASSED] DG2_G10 (C0) [17:29:44] [PASSED] DG2_G11 (B1) [17:29:44] [PASSED] DG2_G12 (A1) [17:29:44] [PASSED] METEORLAKE (g:A0, m:A0) [17:29:44] [PASSED] METEORLAKE (g:A0, m:A0) [17:29:44] [PASSED] METEORLAKE (g:A0, m:A0) [17:29:44] [PASSED] LUNARLAKE (g:A0, m:A0) [17:29:44] [PASSED] LUNARLAKE (g:B0, m:A0) [17:29:44] [PASSED] BATTLEMAGE (g:A0, m:A1) [17:29:44] ==================== [PASSED] xe_wa_gt ===================== [17:29:44] ====================== [PASSED] xe_wa ====================== [17:29:44] ============================================================ [17:29:44] Testing complete. Ran 372 tests: passed: 357, skipped: 15 [17:29:44] Elapsed time: 36.531s total, 4.160s configuring, 26.484s building, 5.852s running
+ /kernel/tools/testing/kunit/kunit.py run --kunitconfig /kernel/drivers/gpu/drm/tests/.kunitconfig [17:29:44] Configuring KUnit Kernel ...
Regenerating .config ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig
[17:29:46] Building KUnit Kernel ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig
Building with:
$ make ARCH=um O=.kunit --jobs=48
../lib/iomap.c:156:5: warning: no previous prototype for ‘ioread64_lo_hi’ [-Wmissing-prototypes]
156 | u64 ioread64_lo_hi(const void __iomem *addr)
| ^~~~~~~~~~~~~~
../lib/iomap.c:163:5: warning: no previous prototype for ‘ioread64_hi_lo’ [-Wmissing-prototypes]
163 | u64 ioread64_hi_lo(const void __iomem *addr)
| ^~~~~~~~~~~~~~
../lib/iomap.c:170:5: warning: no previous prototype for ‘ioread64be_lo_hi’ [-Wmissing-prototypes]
170 | u64 ioread64be_lo_hi(const void __iomem *addr)
| ^~~~~~~~~~~~~~~~
../lib/iomap.c:178:5: warning: no previous prototype for ‘ioread64be_hi_lo’ [-Wmissing-prototypes]
178 | u64 ioread64be_hi_lo(const void __iomem *addr)
| ^~~~~~~~~~~~~~~~
../lib/iomap.c:264:6: warning: no previous prototype for ‘iowrite64_lo_hi’ [-Wmissing-prototypes]
264 | void iowrite64_lo_hi(u64 val, void __iomem *addr)
| ^~~~~~~~~~~~~~~
../lib/iomap.c:272:6: warning: no previous prototype for ‘iowrite64_hi_lo’ [-Wmissing-prototypes]
272 | void iowrite64_hi_lo(u64 val, void __iomem *addr)
| ^~~~~~~~~~~~~~~
../lib/iomap.c:280:6: warning: no previous prototype for ‘iowrite64be_lo_hi’ [-Wmissing-prototypes]
280 | void iowrite64be_lo_hi(u64 val, void __iomem *addr)
| ^~~~~~~~~~~~~~~~~
../lib/iomap.c:288:6: warning: no previous prototype for ‘iowrite64be_hi_lo’ [-Wmissing-prototypes]
288 | void iowrite64be_hi_lo(u64 val, void __iomem *addr)
| ^~~~~~~~~~~~~~~~~[17:30:08] Starting KUnit Kernel (1/1)...
[17:30:08] ============================================================ Running tests with:
$ .kunit/linux kunit.enable=1 mem=1G console=tty kunit_shutdown=halt [17:30:08] ============ drm_test_pick_cmdline (2 subtests) ============ [17:30:08] [PASSED] drm_test_pick_cmdline_res_1920_1080_60 [17:30:08] =============== drm_test_pick_cmdline_named =============== [17:30:08] [PASSED] NTSC [17:30:08] [PASSED] NTSC-J [17:30:08] [PASSED] PAL [17:30:08] [PASSED] PAL-M [17:30:08] =========== [PASSED] drm_test_pick_cmdline_named =========== [17:30:08] ============== [PASSED] drm_test_pick_cmdline ============== [17:30:08] ================== drm_buddy (7 subtests) ================== [17:30:08] [PASSED] drm_test_buddy_alloc_limit [17:30:08] [PASSED] drm_test_buddy_alloc_optimistic [17:30:08] [PASSED] drm_test_buddy_alloc_pessimistic [17:30:08] [PASSED] drm_test_buddy_alloc_pathological [17:30:08] [PASSED] drm_test_buddy_alloc_contiguous [17:30:08] [PASSED] drm_test_buddy_alloc_clear [17:30:08] [PASSED] drm_test_buddy_alloc_range_bias [17:30:08] ==================== [PASSED] drm_buddy ==================== [17:30:08] ============= drm_cmdline_parser (40 subtests) ============= [17:30:08] [PASSED] drm_test_cmdline_force_d_only [17:30:08] [PASSED] drm_test_cmdline_force_D_only_dvi [17:30:08] [PASSED] drm_test_cmdline_force_D_only_hdmi [17:30:08] [PASSED] drm_test_cmdline_force_D_only_not_digital [17:30:08] [PASSED] drm_test_cmdline_force_e_only [17:30:08] [PASSED] drm_test_cmdline_res [17:30:08] [PASSED] drm_test_cmdline_res_vesa [17:30:08] [PASSED] drm_test_cmdline_res_vesa_rblank [17:30:08] [PASSED] drm_test_cmdline_res_rblank [17:30:08] [PASSED] drm_test_cmdline_res_bpp [17:30:08] [PASSED] drm_test_cmdline_res_refresh [17:30:08] [PASSED] drm_test_cmdline_res_bpp_refresh [17:30:08] [PASSED] drm_test_cmdline_res_bpp_refresh_interlaced [17:30:08] [PASSED] drm_test_cmdline_res_bpp_refresh_margins [17:30:08] [PASSED] drm_test_cmdline_res_bpp_refresh_force_off [17:30:08] [PASSED] drm_test_cmdline_res_bpp_refresh_force_on [17:30:08] [PASSED] drm_test_cmdline_res_bpp_refresh_force_on_analog [17:30:08] [PASSED] drm_test_cmdline_res_bpp_refresh_force_on_digital [17:30:08] [PASSED] drm_test_cmdline_res_bpp_refresh_interlaced_margins_force_on [17:30:08] [PASSED] drm_test_cmdline_res_margins_force_on [17:30:08] [PASSED] drm_test_cmdline_res_vesa_margins [17:30:08] [PASSED] drm_test_cmdline_name [17:30:08] [PASSED] drm_test_cmdline_name_bpp [17:30:08] [PASSED] drm_test_cmdline_name_option [17:30:08] [PASSED] drm_test_cmdline_name_bpp_option [17:30:08] [PASSED] drm_test_cmdline_rotate_0 [17:30:08] [PASSED] drm_test_cmdline_rotate_90 [17:30:08] [PASSED] drm_test_cmdline_rotate_180 [17:30:08] [PASSED] drm_test_cmdline_rotate_270 [17:30:08] [PASSED] drm_test_cmdline_hmirror [17:30:08] [PASSED] drm_test_cmdline_vmirror [17:30:08] [PASSED] drm_test_cmdline_margin_options [17:30:08] [PASSED] drm_test_cmdline_multiple_options [17:30:08] [PASSED] drm_test_cmdline_bpp_extra_and_option [17:30:08] [PASSED] drm_test_cmdline_extra_and_option [17:30:08] [PASSED] drm_test_cmdline_freestanding_options [17:30:08] [PASSED] drm_test_cmdline_freestanding_force_e_and_options [17:30:08] [PASSED] drm_test_cmdline_panel_orientation [17:30:08] ================ drm_test_cmdline_invalid ================= [17:30:08] [PASSED] margin_only [17:30:08] [PASSED] interlace_only [17:30:08] [PASSED] res_missing_x [17:30:08] [PASSED] res_missing_y [17:30:08] [PASSED] res_bad_y [17:30:08] [PASSED] res_missing_y_bpp [17:30:08] [PASSED] res_bad_bpp [17:30:08] [PASSED] res_bad_refresh [17:30:08] [PASSED] res_bpp_refresh_force_on_off [17:30:08] [PASSED] res_invalid_mode [17:30:08] [PASSED] res_bpp_wrong_place_mode [17:30:08] [PASSED] name_bpp_refresh [17:30:08] [PASSED] name_refresh [17:30:08] [PASSED] name_refresh_wrong_mode [17:30:08] [PASSED] name_refresh_invalid_mode [17:30:08] [PASSED] rotate_multiple [17:30:08] [PASSED] rotate_invalid_val [17:30:08] [PASSED] rotate_truncated [17:30:08] [PASSED] invalid_option [17:30:08] [PASSED] invalid_tv_option [17:30:08] [PASSED] truncated_tv_option [17:30:08] ============ [PASSED] drm_test_cmdline_invalid ============= [17:30:08] =============== drm_test_cmdline_tv_options =============== [17:30:08] [PASSED] NTSC [17:30:08] [PASSED] NTSC_443 [17:30:08] [PASSED] NTSC_J [17:30:08] [PASSED] PAL [17:30:08] [PASSED] PAL_M [17:30:08] [PASSED] PAL_N [17:30:08] [PASSED] SECAM [17:30:08] [PASSED] MONO_525 [17:30:08] [PASSED] MONO_625 [17:30:08] =========== [PASSED] drm_test_cmdline_tv_options =========== [17:30:08] =============== [PASSED] drm_cmdline_parser ================ [17:30:08] ========== drmm_connector_hdmi_init (19 subtests) ========== [17:30:08] [PASSED] drm_test_connector_hdmi_init_valid [17:30:08] [PASSED] drm_test_connector_hdmi_init_bpc_8 [17:30:08] [PASSED] drm_test_connector_hdmi_init_bpc_10 [17:30:08] [PASSED] drm_test_connector_hdmi_init_bpc_12 [17:30:08] [PASSED] drm_test_connector_hdmi_init_bpc_invalid [17:30:08] [PASSED] drm_test_connector_hdmi_init_bpc_null [17:30:08] [PASSED] drm_test_connector_hdmi_init_formats_empty [17:30:08] [PASSED] drm_test_connector_hdmi_init_formats_no_rgb [17:30:08] [PASSED] drm_test_connector_hdmi_init_null_ddc [17:30:08] [PASSED] drm_test_connector_hdmi_init_null_product [17:30:08] [PASSED] drm_test_connector_hdmi_init_null_vendor [17:30:08] [PASSED] drm_test_connector_hdmi_init_product_length_exact [17:30:08] [PASSED] drm_test_connector_hdmi_init_product_length_too_long [17:30:08] [PASSED] drm_test_connector_hdmi_init_product_valid [17:30:08] [PASSED] drm_test_connector_hdmi_init_vendor_length_exact [17:30:08] [PASSED] drm_test_connector_hdmi_init_vendor_length_too_long [17:30:08] [PASSED] drm_test_connector_hdmi_init_vendor_valid [17:30:08] ========= drm_test_connector_hdmi_init_type_valid ========= [17:30:08] [PASSED] HDMI-A [17:30:08] [PASSED] HDMI-B [17:30:08] ===== [PASSED] drm_test_connector_hdmi_init_type_valid ===== [17:30:08] ======== drm_test_connector_hdmi_init_type_invalid ======== [17:30:08] [PASSED] Unknown [17:30:08] [PASSED] VGA [17:30:08] [PASSED] DVI-I [17:30:08] [PASSED] DVI-D [17:30:08] [PASSED] DVI-A [17:30:08] [PASSED] Composite [17:30:08] [PASSED] SVIDEO [17:30:08] [PASSED] LVDS [17:30:08] [PASSED] Component [17:30:08] [PASSED] DIN [17:30:08] [PASSED] DP [17:30:08] [PASSED] TV [17:30:08] [PASSED] eDP [17:30:08] [PASSED] Virtual [17:30:08] [PASSED] DSI [17:30:08] [PASSED] DPI [17:30:08] [PASSED] Writeback [17:30:08] [PASSED] SPI [17:30:08] [PASSED] USB [17:30:08] ==== [PASSED] drm_test_connector_hdmi_init_type_invalid ==== [17:30:08] ============ [PASSED] drmm_connector_hdmi_init ============= [17:30:08] ============= drmm_connector_init (3 subtests) ============= [17:30:08] [PASSED] drm_test_drmm_connector_init [17:30:08] [PASSED] drm_test_drmm_connector_init_null_ddc [17:30:08] ========= drm_test_drmm_connector_init_type_valid ========= [17:30:08] [PASSED] Unknown [17:30:08] [PASSED] VGA [17:30:08] [PASSED] DVI-I [17:30:08] [PASSED] DVI-D [17:30:08] [PASSED] DVI-A [17:30:08] [PASSED] Composite [17:30:08] [PASSED] SVIDEO [17:30:08] [PASSED] LVDS [17:30:08] [PASSED] Component [17:30:08] [PASSED] DIN [17:30:08] [PASSED] DP [17:30:08] [PASSED] HDMI-A [17:30:08] [PASSED] HDMI-B [17:30:08] [PASSED] TV [17:30:08] [PASSED] eDP [17:30:08] [PASSED] Virtual [17:30:08] [PASSED] DSI [17:30:08] [PASSED] DPI [17:30:08] [PASSED] Writeback [17:30:08] [PASSED] SPI [17:30:08] [PASSED] USB [17:30:08] ===== [PASSED] drm_test_drmm_connector_init_type_valid ===== [17:30:08] =============== [PASSED] drmm_connector_init =============== [17:30:08] = drm_connector_attach_broadcast_rgb_property (2 subtests) = [17:30:08] [PASSED] drm_test_drm_connector_attach_broadcast_rgb_property [17:30:08] [PASSED] drm_test_drm_connector_attach_broadcast_rgb_property_hdmi_connector [17:30:08] === [PASSED] drm_connector_attach_broadcast_rgb_property === [17:30:08] ========== drm_get_tv_mode_from_name (2 subtests) ========== [17:30:08] ========== drm_test_get_tv_mode_from_name_valid =========== [17:30:08] [PASSED] NTSC [17:30:08] [PASSED] NTSC-443 [17:30:08] [PASSED] NTSC-J [17:30:08] [PASSED] PAL [17:30:08] [PASSED] PAL-M [17:30:08] [PASSED] PAL-N [17:30:08] [PASSED] SECAM [17:30:08] [PASSED] Mono [17:30:08] ====== [PASSED] drm_test_get_tv_mode_from_name_valid ======= [17:30:08] [PASSED] drm_test_get_tv_mode_from_name_truncated [17:30:08] ============ [PASSED] drm_get_tv_mode_from_name ============ [17:30:08] = drm_test_connector_hdmi_compute_mode_clock (12 subtests) = [17:30:08] [PASSED] drm_test_drm_hdmi_compute_mode_clock_rgb [17:30:08] [PASSED] drm_test_drm_hdmi_compute_mode_clock_rgb_10bpc [17:30:08] [PASSED] drm_test_drm_hdmi_compute_mode_clock_rgb_10bpc_vic_1 [17:30:08] [PASSED] drm_test_drm_hdmi_compute_mode_clock_rgb_12bpc [17:30:08] [PASSED] drm_test_drm_hdmi_compute_mode_clock_rgb_12bpc_vic_1 [17:30:08] [PASSED] drm_test_drm_hdmi_compute_mode_clock_rgb_double [17:30:08] = drm_test_connector_hdmi_compute_mode_clock_yuv420_valid = [17:30:08] [PASSED] VIC 96 [17:30:08] [PASSED] VIC 97 [17:30:08] [PASSED] VIC 101 [17:30:08] [PASSED] VIC 102 [17:30:08] [PASSED] VIC 106 [17:30:08] [PASSED] VIC 107 [17:30:08] === [PASSED] drm_test_connector_hdmi_compute_mode_clock_yuv420_valid === [17:30:08] [PASSED] drm_test_connector_hdmi_compute_mode_clock_yuv420_10_bpc [17:30:08] [PASSED] drm_test_connector_hdmi_compute_mode_clock_yuv420_12_bpc [17:30:08] [PASSED] drm_test_connector_hdmi_compute_mode_clock_yuv422_8_bpc [17:30:08] [PASSED] drm_test_connector_hdmi_compute_mode_clock_yuv422_10_bpc [17:30:08] [PASSED] drm_test_connector_hdmi_compute_mode_clock_yuv422_12_bpc [17:30:08] === [PASSED] drm_test_connector_hdmi_compute_mode_clock ==== [17:30:08] == drm_hdmi_connector_get_broadcast_rgb_name (2 subtests) == [17:30:08] === drm_test_drm_hdmi_connector_get_broadcast_rgb_name ==== [17:30:08] [PASSED] Automatic [17:30:08] [PASSED] Full [17:30:08] [PASSED] Limited 16:235 [17:30:08] === [PASSED] drm_test_drm_hdmi_connector_get_broadcast_rgb_name === [17:30:08] [PASSED] drm_test_drm_hdmi_connector_get_broadcast_rgb_name_invalid [17:30:08] ==== [PASSED] drm_hdmi_connector_get_broadcast_rgb_name ==== [17:30:08] == drm_hdmi_connector_get_output_format_name (2 subtests) == [17:30:08] === drm_test_drm_hdmi_connector_get_output_format_name ==== [17:30:08] [PASSED] RGB [17:30:08] [PASSED] YUV 4:2:0 [17:30:08] [PASSED] YUV 4:2:2 [17:30:08] [PASSED] YUV 4:4:4 [17:30:08] === [PASSED] drm_test_drm_hdmi_connector_get_output_format_name === [17:30:08] [PASSED] drm_test_drm_hdmi_connector_get_output_format_name_invalid [17:30:08] ==== [PASSED] drm_hdmi_connector_get_output_format_name ==== [17:30:08] ============= drm_damage_helper (21 subtests) ============== [17:30:08] [PASSED] drm_test_damage_iter_no_damage [17:30:08] [PASSED] drm_test_damage_iter_no_damage_fractional_src [17:30:08] [PASSED] drm_test_damage_iter_no_damage_src_moved [17:30:08] [PASSED] drm_test_damage_iter_no_damage_fractional_src_moved [17:30:08] [PASSED] drm_test_damage_iter_no_damage_not_visible [17:30:08] [PASSED] drm_test_damage_iter_no_damage_no_crtc [17:30:08] [PASSED] drm_test_damage_iter_no_damage_no_fb [17:30:08] [PASSED] drm_test_damage_iter_simple_damage [17:30:08] [PASSED] drm_test_damage_iter_single_damage [17:30:08] [PASSED] drm_test_damage_iter_single_damage_intersect_src [17:30:08] [PASSED] drm_test_damage_iter_single_damage_outside_src [17:30:08] [PASSED] drm_test_damage_iter_single_damage_fractional_src [17:30:08] [PASSED] drm_test_damage_iter_single_damage_intersect_fractional_src [17:30:08] [PASSED] drm_test_damage_iter_single_damage_outside_fractional_src [17:30:08] [PASSED] drm_test_damage_iter_single_damage_src_moved [17:30:08] [PASSED] drm_test_damage_iter_single_damage_fractional_src_moved [17:30:08] [PASSED] drm_test_damage_iter_damage [17:30:08] [PASSED] drm_test_damage_iter_damage_one_intersect [17:30:08] [PASSED] drm_test_damage_iter_damage_one_outside [17:30:08] [PASSED] drm_test_damage_iter_damage_src_moved [17:30:08] [PASSED] drm_test_damage_iter_damage_not_visible [17:30:08] ================ [PASSED] drm_damage_helper ================ [17:30:08] ============== drm_dp_mst_helper (3 subtests) ============== [17:30:08] ============== drm_test_dp_mst_calc_pbn_mode ============== [17:30:08] [PASSED] Clock 154000 BPP 30 DSC disabled [17:30:08] [PASSED] Clock 234000 BPP 30 DSC disabled [17:30:08] [PASSED] Clock 297000 BPP 24 DSC disabled [17:30:08] [PASSED] Clock 332880 BPP 24 DSC enabled [17:30:08] [PASSED] Clock 324540 BPP 24 DSC enabled [17:30:08] ========== [PASSED] drm_test_dp_mst_calc_pbn_mode ========== [17:30:08] ============== drm_test_dp_mst_calc_pbn_div =============== [17:30:08] [PASSED] Link rate 2000000 lane count 4 [17:30:08] [PASSED] Link rate 2000000 lane count 2 [17:30:08] [PASSED] Link rate 2000000 lane count 1 [17:30:08] [PASSED] Link rate 1350000 lane count 4 [17:30:08] [PASSED] Link rate 1350000 lane count 2 [17:30:08] [PASSED] Link rate 1350000 lane count 1 [17:30:08] [PASSED] Link rate 1000000 lane count 4 [17:30:08] [PASSED] Link rate 1000000 lane count 2 [17:30:08] [PASSED] Link rate 1000000 lane count 1 [17:30:08] [PASSED] Link rate 810000 lane count 4 [17:30:08] [PASSED] Link rate 810000 lane count 2 [17:30:08] [PASSED] Link rate 810000 lane count 1 [17:30:08] [PASSED] Link rate 540000 lane count 4 [17:30:08] [PASSED] Link rate 540000 lane count 2 [17:30:08] [PASSED] Link rate 540000 lane count 1 [17:30:08] [PASSED] Link rate 270000 lane count 4 [17:30:08] [PASSED] Link rate 270000 lane count 2 [17:30:08] [PASSED] Link rate 270000 lane count 1 [17:30:08] [PASSED] Link rate 162000 lane count 4 [17:30:08] [PASSED] Link rate 162000 lane count 2 [17:30:08] [PASSED] Link rate 162000 lane count 1 [17:30:08] ========== [PASSED] drm_test_dp_mst_calc_pbn_div =========== [17:30:08] ========= drm_test_dp_mst_sideband_msg_req_decode ========= [17:30:08] [PASSED] DP_ENUM_PATH_RESOURCES with port number [17:30:08] [PASSED] DP_POWER_UP_PHY with port number [17:30:08] [PASSED] DP_POWER_DOWN_PHY with port number [17:30:08] [PASSED] DP_ALLOCATE_PAYLOAD with SDP stream sinks [17:30:08] [PASSED] DP_ALLOCATE_PAYLOAD with port number [17:30:08] [PASSED] DP_ALLOCATE_PAYLOAD with VCPI [17:30:08] [PASSED] DP_ALLOCATE_PAYLOAD with PBN [17:30:08] [PASSED] DP_QUERY_PAYLOAD with port number [17:30:08] [PASSED] DP_QUERY_PAYLOAD with VCPI [17:30:08] [PASSED] DP_REMOTE_DPCD_READ with port number [17:30:08] [PASSED] DP_REMOTE_DPCD_READ with DPCD address [17:30:08] [PASSED] DP_REMOTE_DPCD_READ with max number of bytes [17:30:08] [PASSED] DP_REMOTE_DPCD_WRITE with port number [17:30:08] [PASSED] DP_REMOTE_DPCD_WRITE with DPCD address [17:30:08] [PASSED] DP_REMOTE_DPCD_WRITE with data array [17:30:08] [PASSED] DP_REMOTE_I2C_READ with port number [17:30:08] [PASSED] DP_REMOTE_I2C_READ with I2C device ID [17:30:08] [PASSED] DP_REMOTE_I2C_READ with transactions array [17:30:08] [PASSED] DP_REMOTE_I2C_WRITE with port number [17:30:08] [PASSED] DP_REMOTE_I2C_WRITE with I2C device ID [17:30:08] [PASSED] DP_REMOTE_I2C_WRITE with data array [17:30:08] [PASSED] DP_QUERY_STREAM_ENC_STATUS with stream ID [17:30:08] [PASSED] DP_QUERY_STREAM_ENC_STATUS with client ID [17:30:08] [PASSED] DP_QUERY_STREAM_ENC_STATUS with stream event [17:30:08] [PASSED] DP_QUERY_STREAM_ENC_STATUS with valid stream event [17:30:08] [PASSED] DP_QUERY_STREAM_ENC_STATUS with stream behavior [17:30:08] [PASSED] DP_QUERY_STREAM_ENC_STATUS with a valid stream behavior [17:30:08] ===== [PASSED] drm_test_dp_mst_sideband_msg_req_decode ===== [17:30:08] ================ [PASSED] drm_dp_mst_helper ================ [17:30:08] ================== drm_exec (7 subtests) =================== [17:30:08] [PASSED] sanitycheck [17:30:08] [PASSED] test_lock [17:30:08] [PASSED] test_lock_unlock [17:30:08] [PASSED] test_duplicates [17:30:08] [PASSED] test_prepare [17:30:08] [PASSED] test_prepare_array [17:30:08] [PASSED] test_multiple_loops [17:30:08] ==================== [PASSED] drm_exec ===================== [17:30:08] =========== drm_format_helper_test (17 subtests) =========== [17:30:08] ============== drm_test_fb_xrgb8888_to_gray8 ============== [17:30:08] [PASSED] single_pixel_source_buffer [17:30:08] [PASSED] single_pixel_clip_rectangle [17:30:08] [PASSED] well_known_colors [17:30:08] [PASSED] destination_pitch [17:30:08] ========== [PASSED] drm_test_fb_xrgb8888_to_gray8 ========== [17:30:08] ============= drm_test_fb_xrgb8888_to_rgb332 ============== [17:30:08] [PASSED] single_pixel_source_buffer [17:30:08] [PASSED] single_pixel_clip_rectangle [17:30:08] [PASSED] well_known_colors [17:30:08] [PASSED] destination_pitch [17:30:08] ========= [PASSED] drm_test_fb_xrgb8888_to_rgb332 ========== [17:30:08] ============= drm_test_fb_xrgb8888_to_rgb565 ============== [17:30:08] [PASSED] single_pixel_source_buffer [17:30:08] [PASSED] single_pixel_clip_rectangle [17:30:08] [PASSED] well_known_colors [17:30:08] [PASSED] destination_pitch [17:30:08] ========= [PASSED] drm_test_fb_xrgb8888_to_rgb565 ========== [17:30:08] ============ drm_test_fb_xrgb8888_to_xrgb1555 ============= [17:30:08] [PASSED] single_pixel_source_buffer [17:30:08] [PASSED] single_pixel_clip_rectangle [17:30:08] [PASSED] well_known_colors [17:30:08] [PASSED] destination_pitch [17:30:08] ======== [PASSED] drm_test_fb_xrgb8888_to_xrgb1555 ========= [17:30:08] ============ drm_test_fb_xrgb8888_to_argb1555 ============= [17:30:08] [PASSED] single_pixel_source_buffer [17:30:08] [PASSED] single_pixel_clip_rectangle [17:30:08] [PASSED] well_known_colors [17:30:08] [PASSED] destination_pitch [17:30:08] ======== [PASSED] drm_test_fb_xrgb8888_to_argb1555 ========= [17:30:08] ============ drm_test_fb_xrgb8888_to_rgba5551 ============= [17:30:08] [PASSED] single_pixel_source_buffer [17:30:08] [PASSED] single_pixel_clip_rectangle [17:30:08] [PASSED] well_known_colors [17:30:08] [PASSED] destination_pitch [17:30:08] ======== [PASSED] drm_test_fb_xrgb8888_to_rgba5551 ========= [17:30:08] ============= drm_test_fb_xrgb8888_to_rgb888 ============== [17:30:08] [PASSED] single_pixel_source_buffer [17:30:08] [PASSED] single_pixel_clip_rectangle [17:30:08] [PASSED] well_known_colors [17:30:08] [PASSED] destination_pitch [17:30:08] ========= [PASSED] drm_test_fb_xrgb8888_to_rgb888 ========== [17:30:08] ============ drm_test_fb_xrgb8888_to_argb8888 ============= [17:30:08] [PASSED] single_pixel_source_buffer [17:30:08] [PASSED] single_pixel_clip_rectangle [17:30:08] [PASSED] well_known_colors [17:30:08] [PASSED] destination_pitch [17:30:08] ======== [PASSED] drm_test_fb_xrgb8888_to_argb8888 ========= [17:30:08] =========== drm_test_fb_xrgb8888_to_xrgb2101010 =========== [17:30:08] [PASSED] single_pixel_source_buffer [17:30:08] [PASSED] single_pixel_clip_rectangle [17:30:08] [PASSED] well_known_colors [17:30:08] [PASSED] destination_pitch [17:30:08] ======= [PASSED] drm_test_fb_xrgb8888_to_xrgb2101010 ======= [17:30:08] =========== drm_test_fb_xrgb8888_to_argb2101010 =========== [17:30:08] [PASSED] single_pixel_source_buffer [17:30:08] [PASSED] single_pixel_clip_rectangle [17:30:08] [PASSED] well_known_colors [17:30:08] [PASSED] destination_pitch [17:30:08] ======= [PASSED] drm_test_fb_xrgb8888_to_argb2101010 ======= [17:30:08] ============== drm_test_fb_xrgb8888_to_mono =============== [17:30:08] [PASSED] single_pixel_source_buffer [17:30:08] [PASSED] single_pixel_clip_rectangle [17:30:08] [PASSED] well_known_colors [17:30:08] [PASSED] destination_pitch [17:30:08] ========== [PASSED] drm_test_fb_xrgb8888_to_mono =========== [17:30:08] ==================== drm_test_fb_swab ===================== [17:30:08] [PASSED] single_pixel_source_buffer [17:30:08] [PASSED] single_pixel_clip_rectangle [17:30:08] [PASSED] well_known_colors [17:30:08] [PASSED] destination_pitch [17:30:08] ================ [PASSED] drm_test_fb_swab ================= [17:30:08] ============ drm_test_fb_xrgb8888_to_xbgr8888 ============= [17:30:08] [PASSED] single_pixel_source_buffer [17:30:08] [PASSED] single_pixel_clip_rectangle [17:30:08] [PASSED] well_known_colors [17:30:08] [PASSED] destination_pitch [17:30:08] ======== [PASSED] drm_test_fb_xrgb8888_to_xbgr8888 ========= [17:30:08] ============ drm_test_fb_xrgb8888_to_abgr8888 ============= [17:30:08] [PASSED] single_pixel_source_buffer [17:30:08] [PASSED] single_pixel_clip_rectangle [17:30:08] [PASSED] well_known_colors [17:30:08] [PASSED] destination_pitch [17:30:08] ======== [PASSED] drm_test_fb_xrgb8888_to_abgr8888 ========= [17:30:08] ================= drm_test_fb_clip_offset ================= [17:30:08] [PASSED] pass through [17:30:08] [PASSED] horizontal offset [17:30:08] [PASSED] vertical offset [17:30:08] [PASSED] horizontal and vertical offset [17:30:08] [PASSED] horizontal offset (custom pitch) [17:30:08] [PASSED] vertical offset (custom pitch) [17:30:08] [PASSED] horizontal and vertical offset (custom pitch) [17:30:08] ============= [PASSED] drm_test_fb_clip_offset ============= [17:30:08] ============== drm_test_fb_build_fourcc_list ============== [17:30:08] [PASSED] no native formats [17:30:08] [PASSED] XRGB8888 as native format [17:30:08] [PASSED] remove duplicates [17:30:08] [PASSED] convert alpha formats [17:30:08] [PASSED] random formats [17:30:08] ========== [PASSED] drm_test_fb_build_fourcc_list ========== [17:30:08] =================== drm_test_fb_memcpy ==================== [17:30:08] [PASSED] single_pixel_source_buffer: XR24 little-endian (0x34325258) [17:30:08] [PASSED] single_pixel_source_buffer: XRA8 little-endian (0x38415258) [17:30:08] [PASSED] single_pixel_source_buffer: YU24 little-endian (0x34325559) [17:30:08] [PASSED] single_pixel_clip_rectangle: XB24 little-endian (0x34324258) [17:30:08] [PASSED] single_pixel_clip_rectangle: XRA8 little-endian (0x38415258) [17:30:08] [PASSED] single_pixel_clip_rectangle: YU24 little-endian (0x34325559) [17:30:08] [PASSED] well_known_colors: XB24 little-endian (0x34324258) [17:30:08] [PASSED] well_known_colors: XRA8 little-endian (0x38415258) [17:30:08] [PASSED] well_known_colors: YU24 little-endian (0x34325559) [17:30:08] [PASSED] destination_pitch: XB24 little-endian (0x34324258) [17:30:08] [PASSED] destination_pitch: XRA8 little-endian (0x38415258) [17:30:08] [PASSED] destination_pitch: YU24 little-endian (0x34325559) [17:30:08] =============== [PASSED] drm_test_fb_memcpy ================ [17:30:08] ============= [PASSED] drm_format_helper_test ============== [17:30:08] ================= drm_format (18 subtests) ================= [17:30:08] [PASSED] drm_test_format_block_width_invalid [17:30:08] [PASSED] drm_test_format_block_width_one_plane [17:30:08] [PASSED] drm_test_format_block_width_two_plane [17:30:08] [PASSED] drm_test_format_block_width_three_plane [17:30:08] [PASSED] drm_test_format_block_width_tiled [17:30:08] [PASSED] drm_test_format_block_height_invalid [17:30:08] [PASSED] drm_test_format_block_height_one_plane [17:30:08] [PASSED] drm_test_format_block_height_two_plane [17:30:08] [PASSED] drm_test_format_block_height_three_plane [17:30:08] [PASSED] drm_test_format_block_height_tiled [17:30:08] [PASSED] drm_test_format_min_pitch_invalid [17:30:08] [PASSED] drm_test_format_min_pitch_one_plane_8bpp [17:30:08] [PASSED] drm_test_format_min_pitch_one_plane_16bpp [17:30:08] [PASSED] drm_test_format_min_pitch_one_plane_24bpp [17:30:08] [PASSED] drm_test_format_min_pitch_one_plane_32bpp [17:30:08] [PASSED] drm_test_format_min_pitch_two_plane [17:30:08] [PASSED] drm_test_format_min_pitch_three_plane_8bpp [17:30:08] [PASSED] drm_test_format_min_pitch_tiled [17:30:08] =================== [PASSED] drm_format ==================== [17:30:08] =============== drm_framebuffer (1 subtest) ================ [17:30:08] =============== drm_test_framebuffer_create =============== [17:30:08] [PASSED] ABGR8888 normal sizes [17:30:08] [PASSED] ABGR8888 max sizes [17:30:08] [PASSED] ABGR8888 pitch greater than min required [17:30:08] [PASSED] ABGR8888 pitch less than min required [17:30:08] [PASSED] ABGR8888 Invalid width [17:30:08] [PASSED] ABGR8888 Invalid buffer handle [17:30:08] [PASSED] No pixel format [17:30:08] [PASSED] ABGR8888 Width 0 [17:30:08] [PASSED] ABGR8888 Height 0 [17:30:08] [PASSED] ABGR8888 Out of bound height * pitch combination [17:30:08] [PASSED] ABGR8888 Large buffer offset [17:30:08] [PASSED] ABGR8888 Set DRM_MODE_FB_MODIFIERS without modifiers [17:30:08] [PASSED] ABGR8888 Valid buffer modifier [17:30:08] [PASSED] ABGR8888 Invalid buffer modifier(DRM_FORMAT_MOD_SAMSUNG_64_32_TILE) [17:30:08] [PASSED] ABGR8888 Extra pitches without DRM_MODE_FB_MODIFIERS [17:30:08] [PASSED] ABGR8888 Extra pitches with DRM_MODE_FB_MODIFIERS [17:30:08] [PASSED] NV12 Normal sizes [17:30:08] [PASSED] NV12 Max sizes [17:30:08] [PASSED] NV12 Invalid pitch [17:30:08] [PASSED] NV12 Invalid modifier/missing DRM_MODE_FB_MODIFIERS flag [17:30:08] [PASSED] NV12 different modifier per-plane [17:30:08] [PASSED] NV12 with DRM_FORMAT_MOD_SAMSUNG_64_32_TILE [17:30:08] [PASSED] NV12 Valid modifiers without DRM_MODE_FB_MODIFIERS [17:30:08] [PASSED] NV12 Modifier for inexistent plane [17:30:08] [PASSED] NV12 Handle for inexistent plane [17:30:08] [PASSED] NV12 Handle for inexistent plane without DRM_MODE_FB_MODIFIERS [17:30:08] [PASSED] YVU420 DRM_MODE_FB_MODIFIERS set without modifier [17:30:08] [PASSED] YVU420 Normal sizes [17:30:08] [PASSED] YVU420 Max sizes [17:30:08] [PASSED] YVU420 Invalid pitch [17:30:08] [PASSED] YVU420 Different pitches [17:30:08] [PASSED] YVU420 Different buffer offsets/pitches [17:30:08] [PASSED] YVU420 Modifier set just for plane 0, without DRM_MODE_FB_MODIFIERS [17:30:08] [PASSED] YVU420 Modifier set just for planes 0, 1, without DRM_MODE_FB_MODIFIERS [17:30:08] [PASSED] YVU420 Modifier set just for plane 0, 1, with DRM_MODE_FB_MODIFIERS [17:30:08] [PASSED] YVU420 Valid modifier [17:30:08] [PASSED] YVU420 Different modifiers per plane [17:30:08] [PASSED] YVU420 Modifier for inexistent plane [17:30:08] [PASSED] X0L2 Normal sizes [17:30:08] [PASSED] X0L2 Max sizes [17:30:08] [PASSED] X0L2 Invalid pitch [17:30:08] [PASSED] X0L2 Pitch greater than minimum required [17:30:08] [PASSED] X0L2 Handle for inexistent plane [17:30:08] [PASSED] X0L2 Offset for inexistent plane, without DRM_MODE_FB_MODIFIERS set [17:30:08] [PASSED] X0L2 Modifier without DRM_MODE_FB_MODIFIERS set [17:30:08] [PASSED] X0L2 Valid modifier [17:30:08] [PASSED] X0L2 Modifier for inexistent plane [17:30:08] =========== [PASSED] drm_test_framebuffer_create =========== [17:30:08] ================= [PASSED] drm_framebuffer ================= [17:30:08] ================ drm_gem_shmem (8 subtests) ================ [17:30:08] [PASSED] drm_gem_shmem_test_obj_create [17:30:08] [PASSED] drm_gem_shmem_test_obj_create_private [17:30:08] [PASSED] drm_gem_shmem_test_pin_pages [17:30:08] [PASSED] drm_gem_shmem_test_vmap [17:30:08] [PASSED] drm_gem_shmem_test_get_pages_sgt [17:30:08] [PASSED] drm_gem_shmem_test_get_sg_table [17:30:08] [PASSED] drm_gem_shmem_test_madvise [17:30:08] [PASSED] drm_gem_shmem_test_purge [17:30:08] ================== [PASSED] drm_gem_shmem ================== [17:30:08] === drm_atomic_helper_connector_hdmi_check (22 subtests) === [17:30:08] [PASSED] drm_test_check_broadcast_rgb_auto_cea_mode [17:30:08] [PASSED] drm_test_check_broadcast_rgb_auto_cea_mode_vic_1 [17:30:08] [PASSED] drm_test_check_broadcast_rgb_full_cea_mode [17:30:08] [PASSED] drm_test_check_broadcast_rgb_full_cea_mode_vic_1 [17:30:08] [PASSED] drm_test_check_broadcast_rgb_limited_cea_mode [17:30:08] [PASSED] drm_test_check_broadcast_rgb_limited_cea_mode_vic_1 [17:30:08] [PASSED] drm_test_check_broadcast_rgb_crtc_mode_changed [17:30:08] [PASSED] drm_test_check_broadcast_rgb_crtc_mode_not_changed [17:30:08] [PASSED] drm_test_check_hdmi_funcs_reject_rate [17:30:08] [PASSED] drm_test_check_max_tmds_rate_bpc_fallback [17:30:08] [PASSED] drm_test_check_max_tmds_rate_format_fallback [17:30:08] [PASSED] drm_test_check_output_bpc_crtc_mode_changed [17:30:08] [PASSED] drm_test_check_output_bpc_crtc_mode_not_changed [17:30:08] [PASSED] drm_test_check_output_bpc_dvi [17:30:08] [PASSED] drm_test_check_output_bpc_format_vic_1 [17:30:08] [PASSED] drm_test_check_output_bpc_format_display_8bpc_only [17:30:08] [PASSED] drm_test_check_output_bpc_format_display_rgb_only [17:30:08] [PASSED] drm_test_check_output_bpc_format_driver_8bpc_only [17:30:08] [PASSED] drm_test_check_output_bpc_format_driver_rgb_only [17:30:08] [PASSED] drm_test_check_tmds_char_rate_rgb_8bpc [17:30:08] [PASSED] drm_test_check_tmds_char_rate_rgb_10bpc [17:30:08] [PASSED] drm_test_check_tmds_char_rate_rgb_12bpc [17:30:08] ===== [PASSED] drm_atomic_helper_connector_hdmi_check ====== [17:30:08] === drm_atomic_helper_connector_hdmi_reset (6 subtests) ==== [17:30:08] [PASSED] drm_test_check_broadcast_rgb_value [17:30:08] [PASSED] drm_test_check_bpc_8_value [17:30:08] [PASSED] drm_test_check_bpc_10_value [17:30:08] [PASSED] drm_test_check_bpc_12_value [17:30:08] [PASSED] drm_test_check_format_value [17:30:08] [PASSED] drm_test_check_tmds_char_value [17:30:08] ===== [PASSED] drm_atomic_helper_connector_hdmi_reset ====== [17:30:08] ================= drm_managed (2 subtests) ================= [17:30:08] [PASSED] drm_test_managed_release_action [17:30:08] [PASSED] drm_test_managed_run_action [17:30:08] =================== [PASSED] drm_managed =================== [17:30:08] =================== drm_mm (6 subtests) ==================== [17:30:08] [PASSED] drm_test_mm_init [17:30:08] [PASSED] drm_test_mm_debug [17:30:08] [PASSED] drm_test_mm_align32 [17:30:08] [PASSED] drm_test_mm_align64 [17:30:08] [PASSED] drm_test_mm_lowest [17:30:08] [PASSED] drm_test_mm_highest [17:30:08] ===================== [PASSED] drm_mm ====================== [17:30:08] ============= drm_modes_analog_tv (5 subtests) ============= [17:30:08] [PASSED] drm_test_modes_analog_tv_mono_576i [17:30:08] [PASSED] drm_test_modes_analog_tv_ntsc_480i [17:30:08] [PASSED] drm_test_modes_analog_tv_ntsc_480i_inlined [17:30:08] [PASSED] drm_test_modes_analog_tv_pal_576i [17:30:08] [PASSED] drm_test_modes_analog_tv_pal_576i_inlined [17:30:08] =============== [PASSED] drm_modes_analog_tv =============== [17:30:08] ============== drm_plane_helper (2 subtests) =============== [17:30:08] =============== drm_test_check_plane_state ================ [17:30:08] [PASSED] clipping_simple [17:30:08] [PASSED] clipping_rotate_reflect [17:30:08] [PASSED] positioning_simple [17:30:08] [PASSED] upscaling [17:30:08] [PASSED] downscaling [17:30:08] [PASSED] rounding1 [17:30:08] [PASSED] rounding2 [17:30:08] [PASSED] rounding3 [17:30:08] [PASSED] rounding4 [17:30:08] =========== [PASSED] drm_test_check_plane_state ============ [17:30:08] =========== drm_test_check_invalid_plane_state ============ [17:30:08] [PASSED] positioning_invalid [17:30:08] [PASSED] upscaling_invalid stty: 'standard input': Inappropriate ioctl for device [17:30:08] [PASSED] downscaling_invalid [17:30:08] ======= [PASSED] drm_test_check_invalid_plane_state ======== [17:30:08] ================ [PASSED] drm_plane_helper ================= [17:30:08] ====== drm_connector_helper_tv_get_modes (1 subtest) ======= [17:30:08] ====== drm_test_connector_helper_tv_get_modes_check ======= [17:30:08] [PASSED] None [17:30:08] [PASSED] PAL [17:30:08] [PASSED] NTSC [17:30:08] [PASSED] Both, NTSC Default [17:30:08] [PASSED] Both, PAL Default [17:30:08] [PASSED] Both, NTSC Default, with PAL on command-line [17:30:08] [PASSED] Both, PAL Default, with NTSC on command-line [17:30:08] == [PASSED] drm_test_connector_helper_tv_get_modes_check === [17:30:08] ======== [PASSED] drm_connector_helper_tv_get_modes ======== [17:30:08] ================== drm_rect (9 subtests) =================== [17:30:08] [PASSED] drm_test_rect_clip_scaled_div_by_zero [17:30:08] [PASSED] drm_test_rect_clip_scaled_not_clipped [17:30:08] [PASSED] drm_test_rect_clip_scaled_clipped [17:30:08] [PASSED] drm_test_rect_clip_scaled_signed_vs_unsigned [17:30:08] ================= drm_test_rect_intersect ================= [17:30:08] [PASSED] top-left x bottom-right: 2x2+1+1 x 2x2+0+0 [17:30:08] [PASSED] top-right x bottom-left: 2x2+0+0 x 2x2+1-1 [17:30:08] [PASSED] bottom-left x top-right: 2x2+1-1 x 2x2+0+0 [17:30:08] [PASSED] bottom-right x top-left: 2x2+0+0 x 2x2+1+1 [17:30:08] [PASSED] right x left: 2x1+0+0 x 3x1+1+0 [17:30:08] [PASSED] left x right: 3x1+1+0 x 2x1+0+0 [17:30:08] [PASSED] up x bottom: 1x2+0+0 x 1x3+0-1 [17:30:08] [PASSED] bottom x up: 1x3+0-1 x 1x2+0+0 [17:30:08] [PASSED] touching corner: 1x1+0+0 x 2x2+1+1 [17:30:08] [PASSED] touching side: 1x1+0+0 x 1x1+1+0 [17:30:08] [PASSED] equal rects: 2x2+0+0 x 2x2+0+0 [17:30:08] [PASSED] inside another: 2x2+0+0 x 1x1+1+1 [17:30:08] [PASSED] far away: 1x1+0+0 x 1x1+3+6 [17:30:08] [PASSED] points intersecting: 0x0+5+10 x 0x0+5+10 [17:30:08] [PASSED] points not intersecting: 0x0+0+0 x 0x0+5+10 [17:30:08] ============= [PASSED] drm_test_rect_intersect ============= [17:30:08] ================ drm_test_rect_calc_hscale ================ [17:30:08] [PASSED] normal use [17:30:08] [PASSED] out of max range [17:30:08] [PASSED] out of min range [17:30:08] [PASSED] zero dst [17:30:08] [PASSED] negative src [17:30:08] [PASSED] negative dst [17:30:08] ============ [PASSED] drm_test_rect_calc_hscale ============ [17:30:08] ================ drm_test_rect_calc_vscale ================ [17:30:08] [PASSED] normal use [17:30:08] [PASSED] out of max range [17:30:08] [PASSED] out of min range [17:30:08] [PASSED] zero dst [17:30:08] [PASSED] negative src [17:30:08] [PASSED] negative dst [17:30:08] ============ [PASSED] drm_test_rect_calc_vscale ============ [17:30:08] ================== drm_test_rect_rotate =================== [17:30:08] [PASSED] reflect-x [17:30:08] [PASSED] reflect-y [17:30:08] [PASSED] rotate-0 [17:30:08] [PASSED] rotate-90 [17:30:08] [PASSED] rotate-180 [17:30:08] [PASSED] rotate-270 [17:30:08] ============== [PASSED] drm_test_rect_rotate =============== [17:30:08] ================ drm_test_rect_rotate_inv ================= [17:30:08] [PASSED] reflect-x [17:30:08] [PASSED] reflect-y [17:30:08] [PASSED] rotate-0 [17:30:08] [PASSED] rotate-90 [17:30:08] [PASSED] rotate-180 [17:30:08] [PASSED] rotate-270 [17:30:08] ============ [PASSED] drm_test_rect_rotate_inv ============= [17:30:08] ==================== [PASSED] drm_rect ===================== [17:30:08] ============================================================ [17:30:08] Testing complete. Ran 515 tests: passed: 515 [17:30:08] Elapsed time: 23.882s total, 1.758s configuring, 21.901s building, 0.193s running
+ /kernel/tools/testing/kunit/kunit.py run --kunitconfig /kernel/drivers/gpu/drm/ttm/tests/.kunitconfig [17:30:08] Configuring KUnit Kernel ...
Regenerating .config ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig [17:30:10] Building KUnit Kernel ... Populating config with: $ make ARCH=um O=.kunit olddefconfig Building with: $ make ARCH=um O=.kunit --jobs=48 [17:30:19] Starting KUnit Kernel (1/1)... [17:30:19] ============================================================ Running tests with: $ .kunit/linux kunit.enable=1 mem=1G console=tty kunit_shutdown=halt [17:30:19] ================= ttm_device (5 subtests) ================== [17:30:19] [PASSED] ttm_device_init_basic [17:30:19] [PASSED] ttm_device_init_multiple [17:30:19] [PASSED] ttm_device_fini_basic [17:30:19] [PASSED] ttm_device_init_no_vma_man [17:30:19] ================== ttm_device_init_pools ================== [17:30:19] [PASSED] No DMA allocations, no DMA32 required [17:30:19] [PASSED] DMA allocations, DMA32 required [17:30:19] [PASSED] No DMA allocations, DMA32 required [17:30:19] [PASSED] DMA allocations, no DMA32 required [17:30:19] ============== [PASSED] ttm_device_init_pools ============== [17:30:19] =================== [PASSED] ttm_device ==================== [17:30:19] ================== ttm_pool (8 subtests) =================== [17:30:19] ================== ttm_pool_alloc_basic =================== [17:30:19] [PASSED] One page [17:30:19] [PASSED] More than one page [17:30:19] [PASSED] Above the allocation limit [17:30:19] [PASSED] One page, with coherent DMA mappings enabled [17:30:19] [PASSED] Above the allocation limit, with coherent DMA mappings enabled [17:30:19] ============== [PASSED] ttm_pool_alloc_basic =============== [17:30:19] ============== ttm_pool_alloc_basic_dma_addr ============== [17:30:19] [PASSED] One page [17:30:19] [PASSED] More than one page [17:30:19] [PASSED] Above the allocation limit [17:30:19] [PASSED] One page, with coherent DMA mappings enabled [17:30:19] [PASSED] Above the allocation limit, with coherent DMA mappings enabled [17:30:19] ========== [PASSED] ttm_pool_alloc_basic_dma_addr ========== [17:30:19] [PASSED] ttm_pool_alloc_order_caching_match [17:30:19] [PASSED] ttm_pool_alloc_caching_mismatch [17:30:19] [PASSED] ttm_pool_alloc_order_mismatch [17:30:19] [PASSED] ttm_pool_free_dma_alloc [17:30:19] [PASSED] ttm_pool_free_no_dma_alloc [17:30:19] [PASSED] ttm_pool_fini_basic [17:30:19] ==================== [PASSED] ttm_pool ===================== [17:30:19] ================ ttm_resource (8 subtests) ================= [17:30:19] ================= ttm_resource_init_basic ================= [17:30:19] [PASSED] Init resource in TTM_PL_SYSTEM [17:30:19] [PASSED] Init resource in TTM_PL_VRAM [17:30:19] [PASSED] Init resource in a private placement [17:30:19] [PASSED] Init resource in TTM_PL_SYSTEM, set placement flags [17:30:19] ============= [PASSED] ttm_resource_init_basic ============= [17:30:19] [PASSED] ttm_resource_init_pinned [17:30:19] [PASSED] ttm_resource_fini_basic [17:30:19] [PASSED] ttm_resource_manager_init_basic [17:30:19] [PASSED] ttm_resource_manager_usage_basic [17:30:19] [PASSED] ttm_resource_manager_set_used_basic [17:30:19] [PASSED] ttm_sys_man_alloc_basic [17:30:19] [PASSED] ttm_sys_man_free_basic [17:30:19] ================== [PASSED] ttm_resource =================== [17:30:19] =================== ttm_tt (15 subtests) =================== [17:30:19] ==================== ttm_tt_init_basic ==================== [17:30:19] [PASSED] Page-aligned size [17:30:19] [PASSED] Extra pages requested [17:30:19] ================ [PASSED] ttm_tt_init_basic ================ [17:30:19] [PASSED] ttm_tt_init_misaligned [17:30:19] [PASSED] ttm_tt_fini_basic [17:30:19] [PASSED] ttm_tt_fini_sg [17:30:19] [PASSED] ttm_tt_fini_shmem [17:30:19] [PASSED] ttm_tt_create_basic [17:30:19] [PASSED] ttm_tt_create_invalid_bo_type [17:30:19] [PASSED] ttm_tt_create_ttm_exists [17:30:19] [PASSED] ttm_tt_create_failed [17:30:19] [PASSED] ttm_tt_destroy_basic [17:30:19] [PASSED] ttm_tt_populate_null_ttm [17:30:19] [PASSED] ttm_tt_populate_populated_ttm [17:30:19] [PASSED] ttm_tt_unpopulate_basic [17:30:19] [PASSED] ttm_tt_unpopulate_empty_ttm [17:30:19] [PASSED] ttm_tt_swapin_basic [17:30:19] ===================== [PASSED] ttm_tt ====================== [17:30:19] =================== ttm_bo (14 subtests) =================== [17:30:19] =========== ttm_bo_reserve_optimistic_no_ticket =========== [17:30:19] [PASSED] Cannot be interrupted and sleeps [17:30:19] [PASSED] Cannot be interrupted, locks straight away [17:30:19] [PASSED] Can be interrupted, sleeps [17:30:19] ======= [PASSED] ttm_bo_reserve_optimistic_no_ticket ======= [17:30:19] [PASSED] ttm_bo_reserve_locked_no_sleep [17:30:19] [PASSED] ttm_bo_reserve_no_wait_ticket [17:30:19] [PASSED] ttm_bo_reserve_double_resv [17:30:19] [PASSED] ttm_bo_reserve_interrupted [17:30:19] [PASSED] ttm_bo_reserve_deadlock [17:30:19] [PASSED] ttm_bo_unreserve_basic [17:30:19] [PASSED] ttm_bo_unreserve_pinned [17:30:19] [PASSED] ttm_bo_unreserve_bulk [17:30:19] [PASSED] ttm_bo_put_basic [17:30:19] [PASSED] ttm_bo_put_shared_resv [17:30:19] [PASSED] ttm_bo_pin_basic [17:30:19] [PASSED] ttm_bo_pin_unpin_resource [17:30:19] [PASSED] ttm_bo_multiple_pin_one_unpin [17:30:19] ===================== [PASSED] ttm_bo ====================== [17:30:19] ============== ttm_bo_validate (22 subtests) =============== [17:30:19] ============== ttm_bo_init_reserved_sys_man =============== [17:30:19] [PASSED] Buffer object for userspace [17:30:19] [PASSED] Kernel buffer object [17:30:19] [PASSED] Shared buffer object [17:30:19] ========== [PASSED] ttm_bo_init_reserved_sys_man =========== [17:30:19] ============== ttm_bo_init_reserved_mock_man ============== [17:30:19] [PASSED] Buffer object for userspace [17:30:19] [PASSED] Kernel buffer object [17:30:19] [PASSED] Shared buffer object [17:30:19] ========== [PASSED] ttm_bo_init_reserved_mock_man ========== [17:30:19] [PASSED] ttm_bo_init_reserved_resv [17:30:19] ================== ttm_bo_validate_basic ================== [17:30:19] [PASSED] Buffer object for userspace [17:30:19] [PASSED] Kernel buffer object [17:30:19] [PASSED] Shared buffer object [17:30:19] ============== [PASSED] ttm_bo_validate_basic ============== [17:30:19] [PASSED] ttm_bo_validate_invalid_placement [17:30:19] ============= ttm_bo_validate_same_placement ============== [17:30:19] [PASSED] System manager [17:30:19] [PASSED] VRAM manager [17:30:19] ========= [PASSED] ttm_bo_validate_same_placement ========== [17:30:19] [PASSED] ttm_bo_validate_failed_alloc [17:30:19] [PASSED] ttm_bo_validate_pinned [17:30:19] [PASSED] ttm_bo_validate_busy_placement [17:30:19] ================ ttm_bo_validate_multihop ================= [17:30:19] [PASSED] Buffer object for userspace [17:30:19] [PASSED] Kernel buffer object [17:30:19] [PASSED] Shared buffer object [17:30:19] ============ [PASSED] ttm_bo_validate_multihop ============= [17:30:19] ========== ttm_bo_validate_no_placement_signaled ========== [17:30:19] [PASSED] Buffer object in system domain, no page vector [17:30:19] [PASSED] Buffer object in system domain with an existing page vector [17:30:19] ====== [PASSED] ttm_bo_validate_no_placement_signaled ====== [17:30:19] ======== ttm_bo_validate_no_placement_not_signaled ======== [17:30:19] [PASSED] Buffer object for userspace [17:30:19] [PASSED] Kernel buffer object [17:30:19] [PASSED] Shared buffer object [17:30:19] ==== [PASSED] ttm_bo_validate_no_placement_not_signaled ==== [17:30:19] [PASSED] ttm_bo_validate_move_fence_signaled [17:30:19] ========= ttm_bo_validate_move_fence_not_signaled ========= [17:30:19] [PASSED] Waits for GPU [17:30:19] [PASSED] Tries to lock straight away [17:30:20] ===== [PASSED] ttm_bo_validate_move_fence_not_signaled ===== [17:30:20] [PASSED] ttm_bo_validate_swapout [17:30:20] [PASSED] ttm_bo_validate_happy_evict [17:30:20] [PASSED] ttm_bo_validate_all_pinned_evict [17:30:20] [PASSED] ttm_bo_validate_allowed_only_evict [17:30:20] [PASSED] ttm_bo_validate_deleted_evict [17:30:20] [PASSED] ttm_bo_validate_busy_domain_evict [17:30:20] [PASSED] ttm_bo_validate_evict_gutting [17:30:20] [PASSED] ttm_bo_validate_recrusive_evict stty: 'standard input': Inappropriate ioctl for device [17:30:20] ================= [PASSED] ttm_bo_validate ================= [17:30:20] ============================================================ [17:30:20] Testing complete. Ran 102 tests: passed: 102 [17:30:20] Elapsed time: 11.318s total, 1.763s configuring, 8.935s building, 0.514s running
+ cleanup
++ stat -c %u:%g /kernel
+ chown -R 1003:1003 /kernel
Patchwork
CI✓ CI.Build: success for PF: Improve VF control (rev2)
In reply to Michal Wajdeczko== Series Details ==
== Series Details ==
Series: PF: Improve VF control (rev2)
URL : https://patchwork.freedesktop.org/series/137095/
State : success
== Summary ==
lib/modules/6.11.0-rc2-xe/kernel/sound/core/seq/ lib/modules/6.11.0-rc2-xe/kernel/sound/core/seq/snd-seq.ko lib/modules/6.11.0-rc2-xe/kernel/sound/core/snd-seq-device.ko lib/modules/6.11.0-rc2-xe/kernel/sound/core/snd-hwdep.ko lib/modules/6.11.0-rc2-xe/kernel/sound/core/snd.ko lib/modules/6.11.0-rc2-xe/kernel/sound/core/snd-pcm.ko lib/modules/6.11.0-rc2-xe/kernel/sound/core/snd-compress.ko lib/modules/6.11.0-rc2-xe/kernel/sound/core/snd-timer.ko lib/modules/6.11.0-rc2-xe/kernel/sound/soundcore.ko lib/modules/6.11.0-rc2-xe/kernel/sound/soc/ lib/modules/6.11.0-rc2-xe/kernel/sound/soc/intel/ lib/modules/6.11.0-rc2-xe/kernel/sound/soc/intel/atom/ lib/modules/6.11.0-rc2-xe/kernel/sound/soc/intel/atom/snd-soc-sst-atom-hifi2-platform.ko lib/modules/6.11.0-rc2-xe/kernel/sound/soc/intel/atom/sst/ lib/modules/6.11.0-rc2-xe/kernel/sound/soc/intel/atom/sst/snd-intel-sst-acpi.ko lib/modules/6.11.0-rc2-xe/kernel/sound/soc/intel/atom/sst/snd-intel-sst-core.ko lib/modules/6.11.0-rc2-xe/kernel/sound/soc/intel/common/ lib/modules/6.11.0-rc2-xe/kernel/sound/soc/intel/common/snd-soc-acpi-intel-match.ko lib/modules/6.11.0-rc2-xe/kernel/sound/soc/amd/ lib/modules/6.11.0-rc2-xe/kernel/sound/soc/amd/snd-acp-config.ko lib/modules/6.11.0-rc2-xe/kernel/sound/soc/sof/ lib/modules/6.11.0-rc2-xe/kernel/sound/soc/sof/intel/ lib/modules/6.11.0-rc2-xe/kernel/sound/soc/sof/intel/snd-sof-pci-intel-tgl.ko lib/modules/6.11.0-rc2-xe/kernel/sound/soc/sof/intel/snd-sof-intel-hda-mlink.ko lib/modules/6.11.0-rc2-xe/kernel/sound/soc/sof/intel/snd-sof-pci-intel-cnl.ko lib/modules/6.11.0-rc2-xe/kernel/sound/soc/sof/intel/snd-sof-pci-intel-lnl.ko lib/modules/6.11.0-rc2-xe/kernel/sound/soc/sof/intel/snd-sof-intel-hda-common.ko lib/modules/6.11.0-rc2-xe/kernel/sound/soc/sof/intel/snd-sof-intel-hda-generic.ko lib/modules/6.11.0-rc2-xe/kernel/sound/soc/sof/intel/snd-sof-intel-hda.ko lib/modules/6.11.0-rc2-xe/kernel/sound/soc/sof/intel/snd-sof-pci-intel-mtl.ko lib/modules/6.11.0-rc2-xe/kernel/sound/soc/sof/amd/ lib/modules/6.11.0-rc2-xe/kernel/sound/soc/sof/amd/snd-sof-amd-renoir.ko lib/modules/6.11.0-rc2-xe/kernel/sound/soc/sof/amd/snd-sof-amd-acp.ko lib/modules/6.11.0-rc2-xe/kernel/sound/soc/sof/snd-sof-utils.ko lib/modules/6.11.0-rc2-xe/kernel/sound/soc/sof/snd-sof-pci.ko lib/modules/6.11.0-rc2-xe/kernel/sound/soc/sof/snd-sof.ko lib/modules/6.11.0-rc2-xe/kernel/sound/soc/sof/snd-sof-probes.ko lib/modules/6.11.0-rc2-xe/kernel/sound/soc/sof/xtensa/ lib/modules/6.11.0-rc2-xe/kernel/sound/soc/sof/xtensa/snd-sof-xtensa-dsp.ko lib/modules/6.11.0-rc2-xe/kernel/sound/soc/snd-soc-core.ko lib/modules/6.11.0-rc2-xe/kernel/sound/soc/snd-soc-acpi.ko lib/modules/6.11.0-rc2-xe/kernel/sound/soc/codecs/ lib/modules/6.11.0-rc2-xe/kernel/sound/soc/codecs/snd-soc-hdac-hda.ko lib/modules/6.11.0-rc2-xe/kernel/sound/hda/ lib/modules/6.11.0-rc2-xe/kernel/sound/hda/snd-intel-sdw-acpi.ko lib/modules/6.11.0-rc2-xe/kernel/sound/hda/ext/ lib/modules/6.11.0-rc2-xe/kernel/sound/hda/ext/snd-hda-ext-core.ko lib/modules/6.11.0-rc2-xe/kernel/sound/hda/snd-intel-dspcfg.ko lib/modules/6.11.0-rc2-xe/kernel/sound/hda/snd-hda-core.ko lib/modules/6.11.0-rc2-xe/kernel/arch/ lib/modules/6.11.0-rc2-xe/kernel/arch/x86/ lib/modules/6.11.0-rc2-xe/kernel/arch/x86/kernel/ lib/modules/6.11.0-rc2-xe/kernel/arch/x86/kernel/msr.ko lib/modules/6.11.0-rc2-xe/kernel/arch/x86/kernel/cpuid.ko lib/modules/6.11.0-rc2-xe/kernel/arch/x86/crypto/ lib/modules/6.11.0-rc2-xe/kernel/arch/x86/crypto/sha512-ssse3.ko lib/modules/6.11.0-rc2-xe/kernel/arch/x86/crypto/crct10dif-pclmul.ko lib/modules/6.11.0-rc2-xe/kernel/arch/x86/crypto/ghash-clmulni-intel.ko lib/modules/6.11.0-rc2-xe/kernel/arch/x86/crypto/sha1-ssse3.ko lib/modules/6.11.0-rc2-xe/kernel/arch/x86/crypto/crc32-pclmul.ko lib/modules/6.11.0-rc2-xe/kernel/arch/x86/crypto/sha256-ssse3.ko lib/modules/6.11.0-rc2-xe/kernel/arch/x86/crypto/aesni-intel.ko lib/modules/6.11.0-rc2-xe/kernel/arch/x86/crypto/polyval-clmulni.ko lib/modules/6.11.0-rc2-xe/kernel/arch/x86/events/ lib/modules/6.11.0-rc2-xe/kernel/arch/x86/events/intel/ lib/modules/6.11.0-rc2-xe/kernel/arch/x86/events/intel/intel-cstate.ko lib/modules/6.11.0-rc2-xe/kernel/arch/x86/events/rapl.ko lib/modules/6.11.0-rc2-xe/kernel/arch/x86/kvm/ lib/modules/6.11.0-rc2-xe/kernel/arch/x86/kvm/kvm.ko lib/modules/6.11.0-rc2-xe/kernel/arch/x86/kvm/kvm-intel.ko lib/modules/6.11.0-rc2-xe/kernel/crypto/ lib/modules/6.11.0-rc2-xe/kernel/crypto/crypto_simd.ko lib/modules/6.11.0-rc2-xe/kernel/crypto/cmac.ko lib/modules/6.11.0-rc2-xe/kernel/crypto/ccm.ko lib/modules/6.11.0-rc2-xe/kernel/crypto/cryptd.ko lib/modules/6.11.0-rc2-xe/kernel/crypto/polyval-generic.ko lib/modules/6.11.0-rc2-xe/kernel/crypto/async_tx/ lib/modules/6.11.0-rc2-xe/kernel/crypto/async_tx/async_xor.ko lib/modules/6.11.0-rc2-xe/kernel/crypto/async_tx/async_tx.ko lib/modules/6.11.0-rc2-xe/kernel/crypto/async_tx/async_memcpy.ko lib/modules/6.11.0-rc2-xe/kernel/crypto/async_tx/async_pq.ko lib/modules/6.11.0-rc2-xe/kernel/crypto/async_tx/async_raid6_recov.ko lib/modules/6.11.0-rc2-xe/build lib/modules/6.11.0-rc2-xe/modules.alias.bin lib/modules/6.11.0-rc2-xe/modules.builtin lib/modules/6.11.0-rc2-xe/modules.softdep lib/modules/6.11.0-rc2-xe/modules.alias lib/modules/6.11.0-rc2-xe/modules.order lib/modules/6.11.0-rc2-xe/modules.symbols lib/modules/6.11.0-rc2-xe/modules.dep.bin
+ mv kernel-nodebug.tar.gz ..
+ cd ..
+ rm -rf archive
++ date +%s
+ echo -e '\e[0Ksection_end:1723225330:package_x86_64_nodebug\r\e[0K'
+ sync
[0Ksection_end:1723225330:package_x86_64_nodebug
[0K
+ cleanup
++ stat -c %u:%g /kernel
+ chown -R 1003:1003 /kernel