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 DFA1ACE8347 for ; Mon, 30 Sep 2024 14:13:30 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9ABBA10E3F6; Mon, 30 Sep 2024 14:13:30 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="iM2nogkt"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5F33210E4FB for ; Mon, 30 Sep 2024 14:13:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1727705608; x=1759241608; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=J+2d6377+zNO/5iACoj3nYtNduyOFEqAxoj71+p/12Q=; b=iM2nogkthiw0c0oTt6HBLnhFvfaGNd6r7P9+O3vwCraywJRTjSqRXA5T 1xKpkeYULrMLzN7g2/MTjEIHPj9LK/o/sh1Zvvh/pjWkh9YNfoivwDYGP HgJpITcj/PaT+o47mMz+pKYSMeJ2gQt612ESaNP/y9uztlCXcB3c2VMbr RxWMyvz478uTlUTCNCZEFRj333HLHl/4e5pquBAvsWNeJaa+8hHu8YQQJ nHXNqQ5g9QLDQoGkkvTATL9XVh2ASgRXexIYicPq/v83e2e5Zmw0zAvra 71dT+4Bj6/zkwP2VLzmxBVv1Mstaa5yotwsY98I+O2pAc6PhCjRH1kyG7 A==; X-CSE-ConnectionGUID: WaZQCUnORZa+gkcccbzm+Q== X-CSE-MsgGUID: J/EHEGh8QIWSxbBbxwsoRA== X-IronPort-AV: E=McAfee;i="6700,10204,11211"; a="30591121" X-IronPort-AV: E=Sophos;i="6.11,165,1725346800"; d="scan'208";a="30591121" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2024 07:13:28 -0700 X-CSE-ConnectionGUID: QeRRJRMGQa+IymsPGpG/0A== X-CSE-MsgGUID: zwYef3stT9Ov2904Z4lLhQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,165,1725346800"; d="scan'208";a="96645254" Received: from kniemiec-mobl1.ger.corp.intel.com (HELO localhost.localdomain) ([10.245.246.99]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2024 07:13:26 -0700 From: Francois Dugast To: igt-dev@lists.freedesktop.org Cc: Francois Dugast , Lucas De Marchi , Matthew Brost , Rodrigo Vivi , Michal Wajdeczko Subject: [PATCH i-g-t, v4 2/2] tests/intel/xe_fault_injection: Add new test for fault injection Date: Mon, 30 Sep 2024 16:08:24 +0200 Message-ID: <20240930141248.810483-3-francois.dugast@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240930141248.810483-1-francois.dugast@intel.com> References: <20240930141248.810483-1-francois.dugast@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: igt-dev@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development mailing list for IGT GPU Tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" Use the kernel fault injection infrastructure to test error handling of xe at probe time. Add the following test: * "function-fault-injection" v2: Fix mismatch between test name and documentation v3: Use promoted function for bind, rework structure v4: Use igt_dynamic_f to have one subtest per tested function instead of a single test for all (Rodrigo Vivi) Signed-off-by: Francois Dugast Cc: Lucas De Marchi Cc: Matthew Brost Cc: Rodrigo Vivi Cc: Michal Wajdeczko --- tests/intel/xe_fault_injection.c | 191 +++++++++++++++++++++++++++++++ tests/meson.build | 1 + 2 files changed, 192 insertions(+) create mode 100644 tests/intel/xe_fault_injection.c diff --git a/tests/intel/xe_fault_injection.c b/tests/intel/xe_fault_injection.c new file mode 100644 index 000000000..d1c8b2530 --- /dev/null +++ b/tests/intel/xe_fault_injection.c @@ -0,0 +1,191 @@ +// SPDX-License-Identifier: MIT +/* + * Copyright © 2024 Intel Corporation + */ + +/** + * TEST: Check fault injection + * Category: Core + * Mega feature: General Core features + * Sub-category: driver + * Test category: fault injection + */ + +#include + +#include "igt.h" +#include "igt_device.h" +#include "igt_kmod.h" +#include "igt_sysfs.h" + +#define MAX_LINE_SIZE 1024 +#define PATH_FUNCTIONS_INJECTABLE "/sys/kernel/debug/fail_function/injectable" +#define PATH_FUNCTIONS_INJECT "/sys/kernel/debug/fail_function/inject" +#define PATH_FUNCTIONS_RETVAL "/sys/kernel/debug/fail_function/%s/retval" +#define REGEX_XE_FUNCTIONS "^(.+)\\[xe\\]" +#define INJECT_ERRNO -ENOMEM + +enum injection_list_action { + INJECTION_LIST_ADD, + INJECTION_LIST_REMOVE, +}; + +/* + * The injectable file requires CONFIG_FUNCTION_ERROR_INJECTION in kernel. + */ +static bool function_error_injection_enabled(void) +{ + FILE *file = fopen(PATH_FUNCTIONS_INJECTABLE, "rw"); + + if (file) { + fclose(file); + return true; + } + + return false; +} + +static void injection_list_do(enum injection_list_action action, char function_name[]) +{ + FILE *file_inject; + + file_inject = fopen(PATH_FUNCTIONS_INJECT, "w"); + igt_assert(file_inject); + + switch(action) { + case INJECTION_LIST_ADD: + fprintf(file_inject, "%s", function_name); + break; + case INJECTION_LIST_REMOVE: + fprintf(file_inject, "!%s", function_name); + break; + default: + igt_assert(!"missing"); + } + + fclose(file_inject); +} + +/* + * See https://docs.kernel.org/fault-injection/fault-injection.html#application-examples + */ +static void setup_injection_fault(void) +{ + FILE *file; + + file = fopen("/sys/kernel/debug/fail_function/task-filter", "w"); + igt_assert(file); + fprintf(file, "N"); + fclose(file); + + file = fopen("/sys/kernel/debug/fail_function/probability", "w"); + igt_assert(file); + fprintf(file, "100"); + fclose(file); + + file = fopen("/sys/kernel/debug/fail_function/interval", "w"); + igt_assert(file); + fprintf(file, "0"); + fclose(file); + + file = fopen("/sys/kernel/debug/fail_function/times", "w"); + igt_assert(file); + fprintf(file, "-1"); + fclose(file); + + file = fopen("/sys/kernel/debug/fail_function/space", "w"); + igt_assert(file); + fprintf(file, "0"); + fclose(file); + + file = fopen("/sys/kernel/debug/fail_function/verbose", "w"); + igt_assert(file); + fprintf(file, "1"); + fclose(file); +} + +static void cleanup_injection_fault(void) +{ + FILE *file; + + file = fopen(PATH_FUNCTIONS_INJECT, "w"); + igt_assert(file); + fprintf(file, "\n"); + fclose(file); +} + +static void set_retval(char function_name[], long long retval) +{ + FILE *file_retval; + char file_path[MAX_LINE_SIZE]; + + sprintf(file_path, PATH_FUNCTIONS_RETVAL, function_name); + + file_retval = fopen(file_path, "w"); + igt_assert(file_retval); + + fprintf(file_retval, "%#016llx", retval); + fclose(file_retval); +} + +/** + * SUBTEST: inject-fault-probe + * Description: inject an error in the injectable function then reprobe driver + * Functionality: fault + */ +static void +inject_fault_try_bind(int fd, char pci_slot[], char function_name[]) +{ + igt_info("Injecting error \"%s\" (%d) in function \"%s\"\n", + strerror(-INJECT_ERRNO), INJECT_ERRNO, function_name); + + injection_list_do(INJECTION_LIST_ADD, function_name); + set_retval(function_name, INJECT_ERRNO); + xe_sysfs_driver_do(fd, pci_slot, XE_SYSFS_DRIVER_TRY_BIND); + igt_assert_eq(-errno, INJECT_ERRNO); + injection_list_do(INJECTION_LIST_REMOVE, function_name); +} + +igt_main +{ + int fd; + FILE *file_injectable; + char line[MAX_LINE_SIZE]; + char function_name[64]; + char pci_slot[MAX_LINE_SIZE]; + regex_t regex; + regmatch_t pmatch[2]; + + igt_fixture { + igt_require(function_error_injection_enabled()); + fd = drm_open_driver(DRIVER_XE); + igt_device_get_pci_slot_name(fd, pci_slot); + setup_injection_fault(); + file_injectable = fopen(PATH_FUNCTIONS_INJECTABLE, "r"); + igt_assert(file_injectable); + xe_sysfs_driver_do(fd, pci_slot, XE_SYSFS_DRIVER_UNBIND); + igt_assert_eq(regcomp(®ex, REGEX_XE_FUNCTIONS, REG_EXTENDED), 0); + } + + /* + * Iterate over each error injectable function of the xe module + */ + igt_subtest_with_dynamic("inject-fault-probe") { + while ((fgets(line, MAX_LINE_SIZE, file_injectable)) != NULL) { + if (regexec(®ex, line, 2, pmatch, 0) == 0) { + strcpy(function_name, line); + function_name[pmatch[1].rm_eo - 1] = '\0'; + igt_dynamic_f("function-%s", function_name) + inject_fault_try_bind(fd, pci_slot, function_name); + } + } + } + + igt_fixture { + regfree(®ex); + fclose(file_injectable); + cleanup_injection_fault(); + drm_close_driver(fd); + xe_sysfs_driver_do(fd, pci_slot, XE_SYSFS_DRIVER_BIND); + } +} diff --git a/tests/meson.build b/tests/meson.build index 62bde353b..3ca62ff9b 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -293,6 +293,7 @@ intel_xe_progs = [ 'xe_exec_store', 'xe_exec_threads', 'xe_exercise_blt', + 'xe_fault_injection', 'xe_gpgpu_fill', 'xe_gt_freq', 'xe_huc_copy', -- 2.43.0