From patchwork Tue Nov 6 17:17:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10670879 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0E96D17D4 for ; Tue, 6 Nov 2018 17:18:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E7A1C2AA73 for ; Tue, 6 Nov 2018 17:18:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DC55C2AA83; Tue, 6 Nov 2018 17:18:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 19A312AA73 for ; Tue, 6 Nov 2018 17:18:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389483AbeKGCpI (ORCPT ); Tue, 6 Nov 2018 21:45:08 -0500 Received: from out002.mailprotect.be ([83.217.72.86]:48983 "EHLO out002.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389309AbeKGCpI (ORCPT ); Tue, 6 Nov 2018 21:45:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=yWF5+NzcYaLyiKWg98mSp9F/1FQM6edO1yzazlO6fkw=; b=fGrPcRBxDA5i TC5vy7U3VZ7ViGavuTj5udvzwEYr2Gx2vynEU7UTOVT9KTBOvzfN3PvMD4BfUKUbpm4PZ/He38Djs LLQZdYTHe6ywCwvAYqxdSjN+vkTqiM5U/kEUcFZMsFNnxI5Qc2tQu6Fkmv4se7a7cShzVhvzQyhJr NLVutTsnCq/pviDcoWieVKyC6myIXqu1OuSj8tI//Mw9zcN5XqghEG81V4SZ73+kRm3EtgwmBl4iz jNhOb2O3mqRZUNx86tQXyq20LFVyQiHUNDxjhEb9JVIiPMyNwa39UoaYW9fQsuz/X+HesxRMKhbnO zbOGPEOFO3j7G8skBXSFEg==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out002.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gK502-0003KB-8U; Tue, 06 Nov 2018 18:18:47 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id 20858C030B; Tue, 6 Nov 2018 18:18:39 +0100 (CET) From: Bart Van Assche To: "Martin K . Petersen" Cc: Christoph Hellwig , target-devel@vger.kernel.org, Bart Van Assche , Nicholas Bellinger , Mike Christie , David Disseldorp , Hannes Reinecke Subject: [PATCH 08/10] target/core: Fix TAS handling for aborted commands Date: Tue, 6 Nov 2018 09:17:16 -0800 Message-Id: <20181106171718.89594-9-bvanassche@acm.org> X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-goog In-Reply-To: <20181106171718.89594-1-bvanassche@acm.org> References: <20181106171718.89594-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: SB/global_tokens (0.00634592035284) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5n8r70X09Xaud/87FEzDXLJ602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTagCTS5H5Pie2sCQ3gGSzr06cM7U7xDGmYwNG93LVnxwxjk yGQYCd08t3lHobjxX/OigDGQOIiVUN5rGO3B5zfVpnsdsF0/474T9aStD4uEKVG9P9yTThxC66Ku Xb0HO3W8nbMwgkUuW83PKbk25YSnvgtxKKcMIJ7ptgUxRg53TuCt4QJNIvyoxb4710Nl6KAZZ+9r UkyLOOkgJ9eTXvOC4trOptRiSOXsXUvIrRE5GvzrnIZnvex9ONaKBybTnm9I2C8QBYsWIMCVBHpa 7Qj+JYN6Crh9DXUDEtWWsjsNUfobM/P6vznYRdd5hfgiYzLMODodi5MLJiAvrVIiQFNhc8S+HKYI 1vbaqYoREZsvVKq8YZ9/SG1CqFB/T9oOuGliwtRkR+GX5UQPXdpKZF7ITlSXoP8r3OOc9CaULF46 7VT2rSAdw3oKkBNp3q2CTUjaBEkZvVwfNyBf8N9Cj3+++mTSKn34bbFRlO1kXUycpH0i0CUyLQvl 9O+c0636VhIifL76GD10kuo3nOZaoX+g3LKzgLvGn75f1GdWNx/7rKBnyF5Al8KyqkBC47VmroNn IKDFkcg0DoDn7tP2jpvLswQ+LrsRjP8UUIXm0+DPmv7PKPGj8NXeGCulL/QJEqN6EipRzMVZ5Lqw Tx7Vvn9S5OBZ87WmFyXBm/oIAtLmOrCBf5k3qwLPOJPnfDsxRzDQNyioppyJmMAgZEU7lOctlNXB CyoXqWZ9fgj+yLApDgeYUOp7A73HI6oJg7w/Vocy7+Ttx50kPf/opRnU1TyFH6IJwoZKvMkvY/jz 9IkVzN59uTrDo5OUYDGpGZVhMc74agj+RX0dbSrc5Jkf/lehMDRcCgYQIezXimM8MMGBqePpnOc1 Yjsvm51FfilkyeQh1W1MhmkBfqnHNZtJFrg2D22m1Led9vQBeL77Ic6CMOzAFWmAK6L8pLjYAyx9 cPRwc/tu2n0gQeKRgdo8fP/wbsmG5LlZyL0etItIQ47Q9ScHL8+lTGBIVE9xbEkX79tiWrQqR9OH b3+AhBHyQJhMoK6//HisH+Inv79AsPwENh1/rxbQicf/5tMwo2bfwwdcWaJjyTNTJd/rBV6qRhfQ Ewne7W7yM4pg5t5Ye8wOsvdQwaaQ0m5yz9ncfoPJBe4xL7hrJSk60SF3F6RYOYr2 X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The TASK ABORTED STATUS (TAS) bit is defined as follows in SAM: "TASK_ABORTED: this status shall be returned if a command is aborted by a command or task management function on another I_T nexus and the control mode page TAS bit is set to one". TAS handling is spread over the target core and the iSCSI target driver. If a LUN RESET is received, the target core will send the TASK_ABORTED response for all commands for which such a response has to be sent. If an ABORT TASK is received, only the iSCSI target driver will send the TASK_ABORTED response for the commands for which that response has to be sent. That is a bug since all target drivers have to honor the TAS bit. Fix this by moving the code that handles TAS from the iSCSI target driver into the target core. Additionally, if a command has been aborted, instead of sending the TASK_ABORTED status from the context that processes the SCSI command send it from the context of the ABORT TMF. The core_tmr_abort_task() change in this patch causes the CMD_T_TAS flag to be set if a TASK_ABORTED status has to be sent back to the initiator that submitted the command. If that flag has been set transport_cmd_finish_abort() will send the TASK_ABORTED response. Cc: Nicholas Bellinger Cc: Mike Christie Cc: Christoph Hellwig Cc: David Disseldorp Cc: Hannes Reinecke Signed-off-by: Bart Van Assche --- drivers/target/iscsi/iscsi_target.c | 11 ++--- drivers/target/iscsi/iscsi_target_erl1.c | 28 ++---------- drivers/target/target_core_tmr.c | 3 +- drivers/target/target_core_transport.c | 55 +----------------------- include/target/target_core_base.h | 1 - include/target/target_core_fabric.h | 1 - 6 files changed, 10 insertions(+), 89 deletions(-) diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c index c1d5a173553d..984941e036c8 100644 --- a/drivers/target/iscsi/iscsi_target.c +++ b/drivers/target/iscsi/iscsi_target.c @@ -1493,8 +1493,6 @@ __iscsit_check_dataout_hdr(struct iscsi_conn *conn, void *buf, if (hdr->flags & ISCSI_FLAG_CMD_FINAL) iscsit_stop_dataout_timer(cmd); - transport_check_aborted_status(se_cmd, - (hdr->flags & ISCSI_FLAG_CMD_FINAL)); return iscsit_dump_data_payload(conn, payload_length, 1); } } else { @@ -1509,12 +1507,9 @@ __iscsit_check_dataout_hdr(struct iscsi_conn *conn, void *buf, * TASK_ABORTED status. */ if (se_cmd->transport_state & CMD_T_ABORTED) { - if (hdr->flags & ISCSI_FLAG_CMD_FINAL) - if (--cmd->outstanding_r2ts < 1) { - iscsit_stop_dataout_timer(cmd); - transport_check_aborted_status( - se_cmd, 1); - } + if (hdr->flags & ISCSI_FLAG_CMD_FINAL && + --cmd->outstanding_r2ts < 1) + iscsit_stop_dataout_timer(cmd); return iscsit_dump_data_payload(conn, payload_length, 1); } diff --git a/drivers/target/iscsi/iscsi_target_erl1.c b/drivers/target/iscsi/iscsi_target_erl1.c index a211e8154f4c..1b54a9c70851 100644 --- a/drivers/target/iscsi/iscsi_target_erl1.c +++ b/drivers/target/iscsi/iscsi_target_erl1.c @@ -943,20 +943,8 @@ int iscsit_execute_cmd(struct iscsi_cmd *cmd, int ooo) return 0; } spin_unlock_bh(&cmd->istate_lock); - /* - * Determine if delayed TASK_ABORTED status for WRITEs - * should be sent now if no unsolicited data out - * payloads are expected, or if the delayed status - * should be sent after unsolicited data out with - * ISCSI_FLAG_CMD_FINAL set in iscsi_handle_data_out() - */ - if (transport_check_aborted_status(se_cmd, - (cmd->unsolicited_data == 0)) != 0) + if (cmd->se_cmd.transport_state & CMD_T_ABORTED) return 0; - /* - * Otherwise send CHECK_CONDITION and sense for - * exception - */ return transport_send_check_condition_and_sense(se_cmd, cmd->sense_reason, 0); } @@ -974,13 +962,7 @@ int iscsit_execute_cmd(struct iscsi_cmd *cmd, int ooo) if (!(cmd->cmd_flags & ICF_NON_IMMEDIATE_UNSOLICITED_DATA)) { - /* - * Send the delayed TASK_ABORTED status for - * WRITEs if no more unsolicitied data is - * expected. - */ - if (transport_check_aborted_status(se_cmd, 1) - != 0) + if (cmd->se_cmd.transport_state & CMD_T_ABORTED) return 0; iscsit_set_dataout_sequence_values(cmd); @@ -995,11 +977,7 @@ int iscsit_execute_cmd(struct iscsi_cmd *cmd, int ooo) if ((cmd->data_direction == DMA_TO_DEVICE) && !(cmd->cmd_flags & ICF_NON_IMMEDIATE_UNSOLICITED_DATA)) { - /* - * Send the delayed TASK_ABORTED status for WRITEs if - * no more nsolicitied data is expected. - */ - if (transport_check_aborted_status(se_cmd, 1) != 0) + if (cmd->se_cmd.transport_state & CMD_T_ABORTED) return 0; iscsit_set_unsoliticed_dataout(cmd); diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c index 6d1179a7f043..bca0f8a25f92 100644 --- a/drivers/target/target_core_tmr.c +++ b/drivers/target/target_core_tmr.c @@ -165,7 +165,8 @@ void core_tmr_abort_task( printk("ABORT_TASK: Found referenced %s task_tag: %llu\n", se_cmd->se_tfo->get_fabric_name(), ref_tag); - if (!__target_check_io_state(se_cmd, se_sess, 0)) + if (!__target_check_io_state(se_cmd, se_sess, + dev->dev_attrib.emulate_tas)) continue; spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 34cfd6a83505..b42187f69eea 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -1804,7 +1804,7 @@ void transport_generic_request_failure(struct se_cmd *cmd, if (cmd->transport_complete_callback) cmd->transport_complete_callback(cmd, false, &post_ret); - if (transport_check_aborted_status(cmd, 1)) + if (cmd->transport_state & CMD_T_ABORTED) return; switch (sense_reason) { @@ -2011,8 +2011,6 @@ static bool target_handle_task_attr(struct se_cmd *cmd) return true; } -static int __transport_check_aborted_status(struct se_cmd *, int); - void target_execute_cmd(struct se_cmd *cmd) { /* @@ -2022,7 +2020,7 @@ void target_execute_cmd(struct se_cmd *cmd) * If the received CDB has already been aborted stop processing it here. */ spin_lock_irq(&cmd->t_state_lock); - if (__transport_check_aborted_status(cmd, 1)) { + if (cmd->transport_state & CMD_T_ABORTED) { spin_unlock_irq(&cmd->t_state_lock); return; } @@ -3236,55 +3234,6 @@ transport_send_check_condition_and_sense(struct se_cmd *cmd, } EXPORT_SYMBOL(transport_send_check_condition_and_sense); -static int __transport_check_aborted_status(struct se_cmd *cmd, int send_status) - __releases(&cmd->t_state_lock) - __acquires(&cmd->t_state_lock) -{ - int ret; - - assert_spin_locked(&cmd->t_state_lock); - WARN_ON_ONCE(!irqs_disabled()); - - if (!(cmd->transport_state & CMD_T_ABORTED)) - return 0; - /* - * If cmd has been aborted but either no status is to be sent or it has - * already been sent, just return - */ - if (!send_status || !(cmd->se_cmd_flags & SCF_SEND_DELAYED_TAS)) { - if (send_status) - cmd->se_cmd_flags |= SCF_SEND_DELAYED_TAS; - return 1; - } - - pr_debug("Sending delayed SAM_STAT_TASK_ABORTED status for CDB:" - " 0x%02x ITT: 0x%08llx\n", cmd->t_task_cdb[0], cmd->tag); - - cmd->se_cmd_flags &= ~SCF_SEND_DELAYED_TAS; - cmd->scsi_status = SAM_STAT_TASK_ABORTED; - trace_target_cmd_complete(cmd); - - spin_unlock_irq(&cmd->t_state_lock); - ret = cmd->se_tfo->queue_status(cmd); - if (ret) - transport_handle_queue_full(cmd, cmd->se_dev, ret, false); - spin_lock_irq(&cmd->t_state_lock); - - return 1; -} - -int transport_check_aborted_status(struct se_cmd *cmd, int send_status) -{ - int ret; - - spin_lock_irq(&cmd->t_state_lock); - ret = __transport_check_aborted_status(cmd, send_status); - spin_unlock_irq(&cmd->t_state_lock); - - return ret; -} -EXPORT_SYMBOL(transport_check_aborted_status); - void transport_send_task_abort(struct se_cmd *cmd) { unsigned long flags; diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h index bff51baee7e0..31358b0403c8 100644 --- a/include/target/target_core_base.h +++ b/include/target/target_core_base.h @@ -134,7 +134,6 @@ enum se_cmd_flags_table { SCF_SENT_CHECK_CONDITION = 0x00000800, SCF_OVERFLOW_BIT = 0x00001000, SCF_UNDERFLOW_BIT = 0x00002000, - SCF_SEND_DELAYED_TAS = 0x00004000, SCF_ALUA_NON_OPTIMIZED = 0x00008000, SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC = 0x00020000, SCF_COMPARE_AND_WRITE = 0x00080000, diff --git a/include/target/target_core_fabric.h b/include/target/target_core_fabric.h index 6859277fc409..3c100c1f3173 100644 --- a/include/target/target_core_fabric.h +++ b/include/target/target_core_fabric.h @@ -161,7 +161,6 @@ void target_execute_cmd(struct se_cmd *cmd); int transport_generic_free_cmd(struct se_cmd *, int); bool transport_wait_for_tasks(struct se_cmd *); -int transport_check_aborted_status(struct se_cmd *, int); int transport_send_check_condition_and_sense(struct se_cmd *, sense_reason_t, int); int target_get_sess_cmd(struct se_cmd *, bool);