Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2574605rdb; Fri, 22 Sep 2023 02:41:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGwi8pYF7h6b2lA5Gil8wJym4DuJv6VQJOZNbQqkO/d2IneyXTtIvpEWKyM4SzvAoPhye64 X-Received: by 2002:a05:6a21:272f:b0:121:e573:3680 with SMTP id rm47-20020a056a21272f00b00121e5733680mr6306193pzb.62.1695375665293; Fri, 22 Sep 2023 02:41:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695375665; cv=none; d=google.com; s=arc-20160816; b=pJKAtrfrBlQNT9XIeuy8xZobe7hDdMlX1mCyAH2k00Qhys5P9K1IMHV/Jv77IgugzY V0xam9ygv64ed7Qw/d8wT2f+iA7LeYDmISel0rslHD8s5B95958JoE1c7ZscGYP550pR St7/kWTS3MRWWw16qheldEvY1T4iG7JJzDt2j/3WplN6oR/3U3K4xjaNqAuXwCvXieMl wGJZsDejxJ41Uch0AmE50CwE3k2+im0QWEFP9Wzmalat54LH6SnCnL1k2R4bdh2A9Fg3 hdnX9iMRdkIyjpeo1nOSe4DhRf481wKYrC0Oinr0jLc9iKRS2PLweRNNmwvVtfrAQ7SA UgbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ohYDm2mSv3aoMbVy0elFn8CLLNU3TquHG1G+wR/c3NY=; fh=efbNbptNhbD3foczTZf5UTdQGTI/0Ud9virqYphOI9o=; b=lt3Fj0q5bjDa10zqmNJzm6X9N8OXtYmF+Lw1PdvxKdnvn6Mra8dJyFdscPUEWGEFap 94sRfpC/mXC+1uMs2bAruO2bv650Ixv2GiVwQ1S35918gTos8D13Byik15LALhVVdBDJ 6kNGrg5Um2Y+8nJ6EBWCGdK3kwUKe4lK6Q1/6xNUhkKK9xEIxTosLnWZ3Q/k6lck75A8 f9V6O8cYbnI42Hg0Jd3LJRXBRo77amswoTeV89BDGHVcXvLddVP9+hlfLM0Lyiuc9gMU xXANE4n+gf/vg9HYScMooodNJwC5GW558bpJqxjbKdliVJv1wRrsfEq2O7KGqG2jl8bo HsuA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id b26-20020a63931a000000b00578e662d9b3si3352778pge.486.2023.09.22.02.41.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 02:41:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id E6FC4837CF24; Fri, 22 Sep 2023 02:31:08 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233284AbjIVJan (ORCPT + 99 others); Fri, 22 Sep 2023 05:30:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233046AbjIVJ3y (ORCPT ); Fri, 22 Sep 2023 05:29:54 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EEC3197; Fri, 22 Sep 2023 02:29:39 -0700 (PDT) Received: from kwepemm000012.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4RsRhY54jBzGpqB; Fri, 22 Sep 2023 17:25:49 +0800 (CST) Received: from build.huawei.com (10.175.101.6) by kwepemm000012.china.huawei.com (7.193.23.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Fri, 22 Sep 2023 17:29:36 +0800 From: Wenchao Hao To: "James E . J . Bottomley" , "Martin K . Petersen" , Douglas Gilbert , , CC: , , Wenchao Hao Subject: [PATCH v5 07/10] scsi: scsi_debug: Add new error injection abort failed Date: Fri, 22 Sep 2023 17:29:03 +0800 Message-ID: <20230922092906.2645265-8-haowenchao2@huawei.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20230922092906.2645265-1-haowenchao2@huawei.com> References: <20230922092906.2645265-1-haowenchao2@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemm000012.china.huawei.com (7.193.23.142) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Fri, 22 Sep 2023 02:31:09 -0700 (PDT) Add error injection type 3 to make scsi_debug_abort() return FAILED. Fail abort command foramt: +--------+------+-------------------------------------------------------+ | Column | Type | Description | +--------+------+-------------------------------------------------------+ | 1 | u8 | Error type, fixed to 0x3 | +--------+------+-------------------------------------------------------+ | 2 | s32 | Error count | | | | 0: this rule will be ignored | | | | positive: the rule will always take effect | | | | negative: the rule takes effect n times where -n is | | | | the value given. Ignored after n times | +--------+------+-------------------------------------------------------+ | 3 | x8 | SCSI command opcode, 0xff for all commands | +--------+------+-------------------------------------------------------+ Examples: error=/sys/kernel/debug/scsi_debug/0:0:0:1/error echo "0 -10 0x12" > ${error} will make the device return FAILED when abort inquiry command 10 times. Signed-off-by: Wenchao Hao --- drivers/scsi/scsi_debug.c | 40 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index fe1f7421f617..8a16cb9642a6 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -293,6 +293,8 @@ enum sdebug_err_type { ERR_FAIL_CMD = 2, /* make specific scsi command's */ /* queuecmd return succeed but */ /* with errors set in scsi_cmnd */ + ERR_ABORT_CMD_FAILED = 3, /* control return FAILED from */ + /* scsi_debug_abort() */ }; struct sdebug_err_inject { @@ -970,6 +972,7 @@ static int sdebug_error_show(struct seq_file *m, void *p) list_for_each_entry_rcu(err, &devip->inject_err_list, list) { switch (err->type) { case ERR_TMOUT_CMD: + case ERR_ABORT_CMD_FAILED: seq_printf(m, "%d\t%d\t0x%x\n", err->type, err->cnt, err->cmd); break; @@ -1031,6 +1034,7 @@ static ssize_t sdebug_error_write(struct file *file, const char __user *ubuf, switch (inject_type) { case ERR_TMOUT_CMD: + case ERR_ABORT_CMD_FAILED: if (sscanf(buf, "%d %d %hhx", &inject->type, &inject->cnt, &inject->cmd) != 3) goto out_error; @@ -5504,9 +5508,39 @@ static void stop_all_queued(void) mutex_unlock(&sdebug_host_list_mutex); } +static int sdebug_fail_abort(struct scsi_cmnd *cmnd) +{ + struct scsi_device *sdp = cmnd->device; + struct sdebug_dev_info *devip = (struct sdebug_dev_info *)sdp->hostdata; + struct sdebug_err_inject *err; + unsigned char *cmd = cmnd->cmnd; + int ret = 0; + + if (devip == NULL) + return 0; + + rcu_read_lock(); + list_for_each_entry_rcu(err, &devip->inject_err_list, list) { + if (err->type == ERR_ABORT_CMD_FAILED && + (err->cmd == cmd[0] || err->cmd == 0xff)) { + ret = !!err->cnt; + if (err->cnt < 0) + err->cnt++; + + rcu_read_unlock(); + return ret; + } + } + rcu_read_unlock(); + + return 0; +} + static int scsi_debug_abort(struct scsi_cmnd *SCpnt) { bool ok = scsi_debug_abort_cmnd(SCpnt); + u8 *cmd = SCpnt->cmnd; + u8 opcode = cmd[0]; ++num_aborts; @@ -5515,6 +5549,12 @@ static int scsi_debug_abort(struct scsi_cmnd *SCpnt) "%s: command%s found\n", __func__, ok ? "" : " not"); + if (sdebug_fail_abort(SCpnt)) { + scmd_printk(KERN_INFO, SCpnt, "fail abort command 0x%x\n", + opcode); + return FAILED; + } + return SUCCESS; } -- 2.32.0