From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 997F4CD1299 for ; Wed, 10 Apr 2024 04:17:33 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D483E10E054; Wed, 10 Apr 2024 04:17:30 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="Vd6WRZUx"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) by gabe.freedesktop.org (Postfix) with ESMTPS id 47D7589186; Wed, 10 Apr 2024 04:17:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712722642; x=1744258642; h=message-id:date:subject:to:cc:references:from: in-reply-to:mime-version; bh=/Hfqdy4dWuOcjeD7sx+z53njZArf24WtOBQw+L3nrt4=; b=Vd6WRZUxR8V9kCzX4bCuo4pSgQqC2NPlyM4M67nBRp7i3dRCyR6/yXEB yaBfyUKQvqFeTJq8B6kBIvNPx2I3oSezrjCEryvX1dwrEpq0ba2PWEHUO q2UOc4P+c2evKkeYhmaFVT6ahG26hCD6LqJzhdkl1+DDskYjJ2IZRTwKt hlITpkZTOtCn+z/DS/D4xjZGd9j6jF7y3t0C7v1w3s7bHFSyq7ECCmaE5 4/2uSDhk5kvPQgBWRprFuRjUYZVbowo1E7NpyJQnH1ZTleqlJCyibcvaZ nUbdB5trhYkrW1nBo4WY7DZn0T1q2w6VZh+8gRQOZl9phJWg7C/WMlmj9 Q==; X-CSE-ConnectionGUID: CewtOWjjTy2aw9ql9lYqaw== X-CSE-MsgGUID: s094+vvYRIa0UVPdlhCzEA== X-IronPort-AV: E=McAfee;i="6600,9927,11039"; a="7937277" X-IronPort-AV: E=Sophos;i="6.07,190,1708416000"; d="scan'208,217";a="7937277" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Apr 2024 21:17:21 -0700 X-CSE-ConnectionGUID: 58fB0EwvSLGKS01WJVyMow== X-CSE-MsgGUID: Q/CPlLRSSUypBz5AWk/R/A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,190,1708416000"; d="scan'208,217";a="25222370" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by orviesa005.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 09 Apr 2024 21:17:21 -0700 Received: from orsmsx612.amr.corp.intel.com (10.22.229.25) by ORSMSX603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 9 Apr 2024 21:17:20 -0700 Received: from orsmsx611.amr.corp.intel.com (10.22.229.24) by ORSMSX612.amr.corp.intel.com (10.22.229.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 9 Apr 2024 21:17:20 -0700 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx611.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35 via Frontend Transport; Tue, 9 Apr 2024 21:17:20 -0700 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (104.47.59.168) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Tue, 9 Apr 2024 21:17:19 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MmyjuGbS3AoeaZyIXAAed8sxR82gebw1QjyVPBeYOnFmuzRpOyH1d4cDcXBwmzpedq/zLJwCt7p7eFxrkiQXyiVL4xfnIi6nUJPjr0skbxJ6WC42AHDBEjrcJL6tcuiy2LL6fVFgYT484KOFKfAnW7D2ra0fszkltl3m3/Yo/WMSNZTvIc4TjhBFzqaN34r6Bsx/zoagNiY1zPaycr+HeORfW+3rP0ZncochmRtsVb1/KzVwNzrq5pUR6Veg6w2sn05mCdLX10PDJOBiAoE1Q89VSBf3BHrQ+titH+gXUIDRKD6HXZjayqou9lVt2nK6mI88AVdH2Zeeek9dEKNb6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=uf0tzbz4geeoY0WFHh937AFoiY2Rl7kTsWLzjbLX+wU=; b=LtPMt/5d8P88xyJycP9ZIT53RVUHDmlPN6GXAg9U51UbBvxA7hTlASofvIVeDfaag4ldZV5KNPkarI5b72VvXHGdF0vrv9ygPU+DPv9q+nbBVaB1ODG63PYTf9fwRWa7P92EK4HWnkZgBSO8yYyK30H0mvZ7iyq9kyy29k8hLHNL+ZQ1N7/eC6S2OcDnGoNV1dCKoEZBgoJvHV8bHHC93PPOTZAblWiV+7+/0EpLPddxNQ1sRcie1biX04b5K2R5NI5eaUkIdZHq+VVn9LjJvmajYrb1EmySoUEUL5jCLIZHKRDv37lwY3XNtwdSwn5+Apz9wWstMzRbjFljgJzJug== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from MW4PR11MB7056.namprd11.prod.outlook.com (2603:10b6:303:21a::12) by PH8PR11MB6732.namprd11.prod.outlook.com (2603:10b6:510:1c8::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.25; Wed, 10 Apr 2024 04:17:17 +0000 Received: from MW4PR11MB7056.namprd11.prod.outlook.com ([fe80::8664:8749:8357:f11a]) by MW4PR11MB7056.namprd11.prod.outlook.com ([fe80::8664:8749:8357:f11a%7]) with mapi id 15.20.7452.019; Wed, 10 Apr 2024 04:17:17 +0000 Content-Type: multipart/alternative; boundary="------------WMgQxHtq13EbiCRUTTpl0pce" Message-ID: <3bad0c70-7af7-4fb6-834f-4c51af945c41@intel.com> Date: Wed, 10 Apr 2024 09:47:11 +0530 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH i-g-t 1/3] tests/intel/xe_wedged: Introduce a new test for Xe device wedged state To: Rodrigo Vivi , CC: , Lucas De Marchi References: <20240409221908.1077893-1-rodrigo.vivi@intel.com> Content-Language: en-US From: "Ghimiray, Himal Prasad" In-Reply-To: <20240409221908.1077893-1-rodrigo.vivi@intel.com> X-ClientProxiedBy: PN3PR01CA0027.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c01:97::11) To MW4PR11MB7056.namprd11.prod.outlook.com (2603:10b6:303:21a::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MW4PR11MB7056:EE_|PH8PR11MB6732:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Z8AHIW0rMsV6CYFaPZyu1ctFgougZxHKJLBWnBt7vvGvkuYsn3ch2RPkSxXgnHOOO6CxZuZm1cj5Hb8gNb5ddrbPXmhlx4NgqSuzGRCXiePVKso8OQtpWJH0YKxmBOOLHtyzZ0zvUw77qcJEaoHQsbQIj+2yIAHpl2UN+8tXIDB0vfIdIkVrlcFpBTCmR9xCh/dluOMcDPgrxQaWFp1BRNOTifBZqpIb3e4o3rNqae7CZ128Lug437QS/zpFhqqey7Z4gwxubNWGrTGWINpyCoC3KIkEACdMawfrVSgJRohccrFuVtRWfGVTfm3raO7n6/l1sC+TiN5HzOdD7U1ukLFJVUCG8qhaDEvP1bEzrQwlgdxgM50UQFxie33DJzWGQmZwCr9r60sc7TXQ/n+1w1y+9zmOXpOOYkQnuPu2R91SBMLQXNbUWndgRYFmyDOVfL9Qnr4evammqCfXd5akKcIThCXsrmL3n5k1GvMW558Xytr4nHksmh+jh5ZWih00ECKaHrcGm+yo8+P5dUqirBH1xgYC3/Axlo/9Mp+77VdNKlhWrSU2NRUO8RCVJHjdaZIfcYMVbSR4TfpXxS2+Vt6X8mnJf5Qme8F2NZDM03fggYSIuTpFX1AlcqeRqLnRYP342TQbg3HIuE/23Bs8UC3Yn2n23WgDeawUpMjgqRM= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MW4PR11MB7056.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(376005)(1800799015)(366007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?eWFIdm5NMnNCSFhUM09BQkRYUFlIS2pWaG5mQU1rWlRmU3ByR2JRcWpyWm5E?= =?utf-8?B?T3VuTkQ2Y3FyUFJSRENPRHEwS3lhZjR1RFlXWG5aVGwvczlQeWNabC90V3Fx?= =?utf-8?B?RTNuZzFkeXlDVmVLblBOYUNwWjV0YjVOcnJBektCTWwxUmVrS2U0cFZhZnFJ?= =?utf-8?B?ZGh5dU5Nbm1URVBzRzNlYkhyTXRLK2lwZzlKaVlyWFMvcjloY0N2WHhaL1RP?= =?utf-8?B?MlNPQnF0bDBiUWJLVk0rNWkyM2N3Wk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3OWhENmo1VVRLV1ZibWFpWWxvT1FyZE9IdXhnTDVveUZYSmhaRi9h?= =?utf-8?B?WDhnd3VqYlE3eldtZWY0NkJIckRjNURnVmV5RmMxZHNOMEQ5TWdoeGhaMlhq?= =?utf-8?Q?/QtMNDMVmD2JDqKqAhU1qtY=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 481cb230-3610-4947-940d-08dc59151b8a X-MS-Exchange-CrossTenant-AuthSource: MW4PR11MB7056.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Apr 2024 04:17:17.4414 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: E7hKMK3XQim+U4uA7RkttMVJk6Fo83/jDGFMTPfzbcn55GvFUIPx22xiJcI8/ThKvcl4LJHMwmnojJBe4sjsM3/zJeQdofzknl6TJ59hPxk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR11MB6732 X-OriginatorOrg: intel.com X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-xe-bounces@lists.freedesktop.org Sender: "Intel-xe" --------------WMgQxHtq13EbiCRUTTpl0pce Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit On 10-04-2024 03:49, Rodrigo Vivi wrote: > Let's inject a gt_reset failure that will put Xe device in the > new wedged state, then we confirm the IOCTL is blocked and we > reload the driver to get back to a clean state for other test > execution, since wedged state in Xe is a final state that can only > be cleared with a device rebind/reprobe. > > The fault injection of this test is entirely based on xe_uevent > provided by Himal. > > v2: Use rebind instead of module reload (Lucas) > And other improvements also pointed out by Lucas. > > Cc: Lucas De Marchi > Cc: Himal Prasad Ghimiray > Signed-off-by: Rodrigo Vivi > --- > tests/intel/xe_wedged.c | 108 ++++++++++++++++++++++++++++++++++++++++ > tests/meson.build | 1 + > 2 files changed, 109 insertions(+) > create mode 100644 tests/intel/xe_wedged.c > > diff --git a/tests/intel/xe_wedged.c b/tests/intel/xe_wedged.c > new file mode 100644 > index 000000000..f2587cc43 > --- /dev/null > +++ b/tests/intel/xe_wedged.c > @@ -0,0 +1,108 @@ > +// SPDX-License-Identifier: MIT > +/* > + * Copyright © 2024 Intel Corporation > + */ > + > +/** > + * TEST: cause fake gt reset failure which put Xe device in wedged state > + * Category: Software building block > + * Sub-category: driver > + * Functionality: wedged > + * Test category: functionality test > + */ > + > +#include > +#include > + > +#include "igt.h" > +#include "igt_device.h" > +#include "igt_kmod.h" > +#include "igt_sysfs.h" > + > +#include "xe/xe_ioctl.h" > + > +static void force_wedged(int fd) > +{ > + igt_debugfs_write(fd, "fail_gt_reset/probability", "100"); > + igt_debugfs_write(fd, "fail_gt_reset/times", "2"); > + > + xe_force_gt_reset(fd, 0); > + sleep(1); > +} > + > +static int rebind_xe(int fd) > +{ > + char pci_slot[NAME_MAX]; > + int sysfs; > + > + igt_device_get_pci_slot_name(fd, pci_slot); > + > + sysfs = open("/sys/bus/pci/drivers/xe", O_DIRECTORY); > + igt_assert(sysfs); > + > + igt_assert(igt_sysfs_set(sysfs, "unbind", pci_slot)); > + > + /* > + * We need to close the client for a proper release, before > + * binding back again. > + */ > + close(fd); > + > + igt_assert(igt_sysfs_set(sysfs, "bind", pci_slot)); > + close(sysfs); > + > + /* Renew the client connection */ > + fd = drm_open_driver(DRIVER_XE); > + igt_assert(fd); > + > + return fd; > +} > + > +static int simple_ioctl(int fd) > +{ > + int ret; > + > + struct drm_xe_vm_create create = { > + .extensions = 0, > + .flags = 0, > + }; > + > + ret = igt_ioctl(fd, DRM_IOCTL_XE_VM_CREATE, &create); > + > + if (ret == 0) > + xe_vm_destroy(fd, create.vm_id); > + > + return ret; > +} > + > +/** > + * SUBTEST: basic-wedged > + * Description: Force Xe device wedged after injecting a failure in GT reset > + */ > +igt_main > +{ > + int fd; > + > + igt_fixture { > + fd = drm_open_driver(DRIVER_XE); > + } > + > + igt_subtest("basic-wedged") { > + igt_require(igt_debugfs_exists(fd, "fail_gt_reset/probability", > + O_RDWR)); > + > + igt_assert_eq(simple_ioctl(fd), 0); > + force_wedged(fd); > + igt_assert_neq(simple_ioctl(fd), 0); > + fd = rebind_xe(fd); > + igt_assert_eq(simple_ioctl(fd), 0); > + } > + > + igt_fixture { > + if (igt_debugfs_exists(fd, "fail_gt_reset/probability", O_RDWR)) { > + igt_debugfs_write(fd, "fail_gt_reset/probability", "0"); > + igt_debugfs_write(fd, "fail_gt_reset/times", "1"); > + } > + drm_close_driver(fd); > + } > +} > diff --git a/tests/meson.build b/tests/meson.build > index a856510fc..65b8bf23b 100644 > --- a/tests/meson.build > +++ b/tests/meson.build > @@ -274,6 +274,7 @@ intel_kms_progs = [ > ] > > intel_xe_progs = [ > + 'xe_wedged', > 'xe_ccs', > 'xe_create', > 'xe_compute', Acked-by: Himal Prasad Ghimiray --------------WMgQxHtq13EbiCRUTTpl0pce Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: 8bit


On 10-04-2024 03:49, Rodrigo Vivi wrote:
Let's inject a gt_reset failure that will put Xe device in the
new wedged state, then we confirm the IOCTL is blocked and we
reload the driver to get back to a clean state for other test
execution, since wedged state in Xe is a final state that can only
be cleared with a device rebind/reprobe.

The fault injection of this test is entirely based on xe_uevent
provided by Himal.

v2: Use rebind instead of module reload (Lucas)
    And other improvements also pointed out by Lucas.

Cc: Lucas De Marchi <lucas.demarchi@intel.com>
Cc:  Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
---
 tests/intel/xe_wedged.c | 108 ++++++++++++++++++++++++++++++++++++++++
 tests/meson.build       |   1 +
 2 files changed, 109 insertions(+)
 create mode 100644 tests/intel/xe_wedged.c

diff --git a/tests/intel/xe_wedged.c b/tests/intel/xe_wedged.c
new file mode 100644
index 000000000..f2587cc43
--- /dev/null
+++ b/tests/intel/xe_wedged.c
@@ -0,0 +1,108 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright © 2024 Intel Corporation
+ */
+
+/**
+ * TEST: cause fake gt reset failure which put Xe device in wedged state
+ * Category: Software building block
+ * Sub-category: driver
+ * Functionality: wedged
+ * Test category: functionality test
+ */
+
+#include <limits.h>
+#include <dirent.h>
+
+#include "igt.h"
+#include "igt_device.h"
+#include "igt_kmod.h"
+#include "igt_sysfs.h"
+
+#include "xe/xe_ioctl.h"
+
+static void force_wedged(int fd)
+{
+	igt_debugfs_write(fd, "fail_gt_reset/probability", "100");
+	igt_debugfs_write(fd, "fail_gt_reset/times", "2");
+
+	xe_force_gt_reset(fd, 0);
+	sleep(1);
+}
+
+static int rebind_xe(int fd)
+{
+	char pci_slot[NAME_MAX];
+	int sysfs;
+
+	igt_device_get_pci_slot_name(fd, pci_slot);
+
+	sysfs = open("/sys/bus/pci/drivers/xe", O_DIRECTORY);
+	igt_assert(sysfs);
+
+        igt_assert(igt_sysfs_set(sysfs, "unbind", pci_slot));
+
+	/*
+	 * We need to close the client for a proper release, before
+	 * binding back again.
+	 */
+	close(fd);
+
+        igt_assert(igt_sysfs_set(sysfs, "bind", pci_slot));
+	close(sysfs);
+
+	/* Renew the client connection */
+	fd = drm_open_driver(DRIVER_XE);
+	igt_assert(fd);
+
+	return fd;
+}
+
+static int simple_ioctl(int fd)
+{
+	int ret;
+
+	struct drm_xe_vm_create create = {
+		.extensions = 0,
+		.flags = 0,
+	};
+
+	ret = igt_ioctl(fd, DRM_IOCTL_XE_VM_CREATE, &create);
+
+	if (ret == 0)
+		xe_vm_destroy(fd, create.vm_id);
+
+	return ret;
+}
+
+/**
+ * SUBTEST: basic-wedged
+ * Description: Force Xe device wedged after injecting a failure in GT reset
+ */
+igt_main
+{
+	int fd;
+
+	igt_fixture {
+		fd = drm_open_driver(DRIVER_XE);
+	}
+
+	igt_subtest("basic-wedged") {
+		igt_require(igt_debugfs_exists(fd, "fail_gt_reset/probability",
+					       O_RDWR));
+
+		igt_assert_eq(simple_ioctl(fd), 0);
+		force_wedged(fd);
+		igt_assert_neq(simple_ioctl(fd), 0);
+		fd = rebind_xe(fd);
+		igt_assert_eq(simple_ioctl(fd), 0);
+	}
+
+	igt_fixture {
+		if (igt_debugfs_exists(fd, "fail_gt_reset/probability", O_RDWR)) {
+			igt_debugfs_write(fd, "fail_gt_reset/probability", "0");
+			igt_debugfs_write(fd, "fail_gt_reset/times", "1");
+		}
+		drm_close_driver(fd);
+	}
+}
diff --git a/tests/meson.build b/tests/meson.build
index a856510fc..65b8bf23b 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -274,6 +274,7 @@ intel_kms_progs = [
 ]
 
 intel_xe_progs = [
+	'xe_wedged',
 	'xe_ccs',
 	'xe_create',
 	'xe_compute',

Acked-by: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>


    
--------------WMgQxHtq13EbiCRUTTpl0pce--