Skip to contentSkip to conversation

Decrease module reload fault injection time

PATCH Superseded Zbigniew Kempczyński 2 participants 5 messages Jul 13, 2022

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Decrease module reload fault injection time

Some tests can be affected by unresponsive driver when fault injection would leave loaded driver in fault state. Series decreases number of checkpoints (they are get randomly some during module reload) and ensures driver is unloaded when test completes.

v2: Addressing review comments (Kamil)

Chris Wilson (2):
i915/i915_module_load: Randomise fault injection i915/i915_module_load: Raise a fatal-error on failing to unload a
module

 tests/i915/i915_module_load.c | 56 ++++++++++++++++++++++++++++++-----
 1 file changed, 49 insertions(+), 7 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/2 i915/i915_module_load: Randomise fault injection

From: Chris Wilson <[email protected]>

Reduce the number of faults we inject during module reload to bring the test runtime back to a reasonable level, and rely on multiple CI runs to establish the full picture. This reduces the efficacy of testing (i.e. premerge will probably not prevent inclusion of a buggy patch), but error handling on module reload is not a critical factor for driver health -- a broken patch that explodes in an error path is unlikely to prevent CI from detecting critical issues, and with multiple runs we should still be able to detect and fix issues before merging.

---
v2: Reorganize fault_inject() loop (Kamil)

---
 tests/i915/i915_module_load.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
tests/i915/i915_module_load.c +13 -6
index 05863c4748..0ce433869d 100644
@@ -345,20 +345,27 @@ igt_main
 		     " with fault injection.");
 	igt_subtest("reload-with-fault-injection") {
 		const char *param;
-		int i = 0;
+		int i;
 
 		igt_i915_driver_unload();
 
+		i = 0;
+		param = getenv("IGT_SRANDOM");
+		if (param)
+			i = atoi(param);
+		if (!i)
+			i = time(NULL);
+		igt_info("Using IGT_SRANDOM=%d for randomised faults\n", i);
+		srandom(i);
+
 		param = "inject_probe_failure";
 		if (!igt_kmod_has_param("i915", param))
 			param = "inject_load_failure";
 		igt_require(igt_kmod_has_param("i915", param));
 
-		while (inject_fault("i915", param, ++i) == 0)
-			;
-
-		/* We expect to hit at least one fault! */
-		igt_assert(i > 1);
+		i = 1;
+		while (inject_fault("i915", param, i) == 0)
+			i += 1 + random() % 17;
 
 		/* inject_fault() leaves the module unloaded */
 	}
Signature · 1 line
2.34.1
Reviewed-by on v2 1/2
#2 lore raw

Re: [igt-dev] [PATCH i-g-t v2 1/2] i915/i915_module_load: Randomise fault injection

Quoted 11 lines · Zbigniew Kempczyński

From: Chris Wilson <[email protected]>

Reduce the number of faults we inject during module reload to bring the test runtime back to a reasonable level, and rely on multiple CI runs to establish the full picture. This reduces the efficacy of testing (i.e. premerge will probably not prevent inclusion of a buggy patch), but error handling on module reload is not a critical factor for driver health -- a broken patch that explodes in an error path is unlikely to prevent CI from detecting critical issues, and with multiple runs we should still be able to detect and fix issues before merging.

Quoted 7 lines

---
v2: Reorganize fault_inject() loop (Kamil)

Quoted 45 lines
---
 tests/i915/i915_module_load.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
tests/i915/i915_module_load.c +13 -6
index 05863c4748..0ce433869d 100644
@@ -345,20 +345,27 @@ igt_main
 		     " with fault injection.");
 	igt_subtest("reload-with-fault-injection") {
 		const char *param;
-		int i = 0;
+		int i;
 
 		igt_i915_driver_unload();
 
+		i = 0;
+		param = getenv("IGT_SRANDOM");
+		if (param)
+			i = atoi(param);
+		if (!i)
+			i = time(NULL);
+		igt_info("Using IGT_SRANDOM=%d for randomised faults\n", i);
+		srandom(i);
+
 		param = "inject_probe_failure";
 		if (!igt_kmod_has_param("i915", param))
 			param = "inject_load_failure";
 		igt_require(igt_kmod_has_param("i915", param));
 
-		while (inject_fault("i915", param, ++i) == 0)
-			;
-
-		/* We expect to hit at least one fault! */
-		igt_assert(i > 1);
+		i = 1;
+		while (inject_fault("i915", param, i) == 0)
+			i += 1 + random() % 17;
 
 		/* inject_fault() leaves the module unloaded */
 	}
Signature · 1 line
2.34.1
#3 lore raw

PATCH v2 2/2 i915/i915_module_load: Raise a fatal-error on failing to unload a module

In reply to Zbigniew Kempczyński

From: Chris Wilson <[email protected]>

If we fail to unload the module after the fault-injection test, we leave behind a dangerous modparam that will affect all subsequent tests. Better to declare the run void rather than have to triage all the bizarre bugs.

Sometimes the fault injection module load test timeouts out, causing igt_runner to cancel the test with a SIGQUIT. This unfortunately causes us to abort in the middle of the test leaving the module in a broken state. That broken module is then used for subsequent tests, causing a cascade of failures.

---
v2: Commit msg fix + remove unnecessay condition check (Kamil)

---
 tests/i915/i915_module_load.c | 37 ++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)
tests/i915/i915_module_load.c +36 -1
index 0ce433869d..4c72157c07 100644
@@ -166,6 +166,33 @@ static int open_parameters(const char *module_name)
 	return open(path, O_RDONLY);
 }
 
+static void unload_or_die(const char *module_name)
+{
+	int err, loop;
+
+	/* should be unloaded, so expect a no-op */
+	for (loop = 0;; loop++) {
+		err = igt_kmod_unload(module_name, 0);
+		if (err == -ENOENT) /* -ENOENT == unloaded already */
+			err = 0;
+		if (!err || loop >= 10)
+			break;
+
+		sleep(1); /* wait for external clients to drop */
+		if (!strcmp(module_name, "i915"))
+			igt_i915_driver_unload();
+	}
+
+	igt_abort_on_f(err,
+		       "Failed to unload '%s' err:%d after %ds, leaving dangerous modparams intact!\n",
+		       module_name, err, loop);
+}
+
+static void must_unload(int sig)
+{
+	unload_or_die("i915");
+}
+
 static int
 inject_fault(const char *module_name, const char *opt, int fault)
 {
@@ -349,6 +376,14 @@ igt_main
 
 		igt_i915_driver_unload();
 
+		/*
+		 * inject_fault() leaves the module unloaded, but if that fails
+		 * we must abort the run. Otherwise, we leave a dangerous
+		 * modparam affecting all subsequent tests causing bizarre
+		 * failures.
+		 */
+		igt_install_exit_handler(must_unload);
+
 		i = 0;
 		param = getenv("IGT_SRANDOM");
 		if (param)
@@ -367,7 +402,7 @@ igt_main
 		while (inject_fault("i915", param, i) == 0)
 			i += 1 + random() % 17;
 
-		/* inject_fault() leaves the module unloaded */
+		unload_or_die("i915");
 	}
 
 	igt_describe("Check whether lmem bar size can be resized to only supported sizes.");
Signature · 1 line
2.34.1
Reviewed-by on v2 2/2
#4 lore raw

Re: [igt-dev] [PATCH i-g-t v2 2/2] i915/i915_module_load: Raise a fatal-error on failing to unload a module

Quoted 13 lines · Zbigniew Kempczyński

From: Chris Wilson <[email protected]>

If we fail to unload the module after the fault-injection test, we leave behind a dangerous modparam that will affect all subsequent tests. Better to declare the run void rather than have to triage all the bizarre bugs.

Sometimes the fault injection module load test timeouts out, causing igt_runner to cancel the test with a SIGQUIT. This unfortunately causes us to abort in the middle of the test leaving the module in a broken state. That broken module is then used for subsequent tests, causing a cascade of failures.

Quoted 6 lines

---
v2: Commit msg fix + remove unnecessay condition check (Kamil)

Quoted 69 lines
---
 tests/i915/i915_module_load.c | 37 ++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)
tests/i915/i915_module_load.c +36 -1
index 0ce433869d..4c72157c07 100644
@@ -166,6 +166,33 @@ static int open_parameters(const char *module_name)
 	return open(path, O_RDONLY);
 }
 
+static void unload_or_die(const char *module_name)
+{
+	int err, loop;
+
+	/* should be unloaded, so expect a no-op */
+	for (loop = 0;; loop++) {
+		err = igt_kmod_unload(module_name, 0);
+		if (err == -ENOENT) /* -ENOENT == unloaded already */
+			err = 0;
+		if (!err || loop >= 10)
+			break;
+
+		sleep(1); /* wait for external clients to drop */
+		if (!strcmp(module_name, "i915"))
+			igt_i915_driver_unload();
+	}
+
+	igt_abort_on_f(err,
+		       "Failed to unload '%s' err:%d after %ds, leaving dangerous modparams intact!\n",
+		       module_name, err, loop);
+}
+
+static void must_unload(int sig)
+{
+	unload_or_die("i915");
+}
+
 static int
 inject_fault(const char *module_name, const char *opt, int fault)
 {
@@ -349,6 +376,14 @@ igt_main
 
 		igt_i915_driver_unload();
 
+		/*
+		 * inject_fault() leaves the module unloaded, but if that fails
+		 * we must abort the run. Otherwise, we leave a dangerous
+		 * modparam affecting all subsequent tests causing bizarre
+		 * failures.
+		 */
+		igt_install_exit_handler(must_unload);
+
 		i = 0;
 		param = getenv("IGT_SRANDOM");
 		if (param)
@@ -367,7 +402,7 @@ igt_main
 		while (inject_fault("i915", param, i) == 0)
 			i += 1 + random() % 17;
 
-		/* inject_fault() leaves the module unloaded */
+		unload_or_die("i915");
 	}
 
 	igt_describe("Check whether lmem bar size can be resized to only supported sizes.");
Signature · 1 line
2.34.1