From patchwork Sun Jul 26 15:35:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bodo Stroesser X-Patchwork-Id: 11685913 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C37A614B7 for ; Sun, 26 Jul 2020 15:35:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 79D9B20773 for ; Sun, 26 Jul 2020 15:35:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ts.fujitsu.com header.i=@ts.fujitsu.com header.b="T+sfNelz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727945AbgGZPfv (ORCPT ); Sun, 26 Jul 2020 11:35:51 -0400 Received: from mail1.bemta25.messagelabs.com ([195.245.230.67]:49807 "EHLO mail1.bemta25.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727850AbgGZPfu (ORCPT ); Sun, 26 Jul 2020 11:35:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ts.fujitsu.com; s=200619tsfj; t=1595777748; i=@ts.fujitsu.com; bh=gMojHj+95hLqvtbTkDDjDCt2R6tZDFvbUuJbvcOIVYc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=T+sfNelzBNUXVBhqzOnVGpUVjroJMPf57Aqk4teXV9xHrDbjLGXQZTrRzlWuCCG2G xK4KrdFPtFVwYukDtAUTXmEj9pyA+zhYenqZXC70pepZH8olw7g0gfMcpulWurGvfO c2267c+lgaqOnxSRoy+HJO2P+bPhqK2eubBMyc7KksQ6QXsb9xGtpZh2jyYzgh9Djv LZAPOwZR0cH75VFoyd/m4KNbJr3uljk9zLrC+KyvevkkZVOVbc/2S/YU1XfEJmtUPR Il9WZkz/v91sSGneKKmTDCyP8HZPwEOXrFE/Id/umGvLDu8r8IQb5kyHaK2MOgy5eV lLSSLc+dP3vng== Received: from [100.112.197.40] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-3.bemta.az-b.eu-west-1.aws.symcld.net id E4/44-60645-3D2AD1F5; Sun, 26 Jul 2020 15:35:47 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrNLMWRWlGSWpSXmKPExsViZ8MRqntpkWy 8weI1Nhbd13ewWSw//o/J4u+kG6wWrUvfMjmweHx8eovF4/MmuQCmKNbMvKT8igTWjOaGC+wF N4Uqdj6fy9TAOE2gi5GLQ0hgMqPEvm+L2CCc6YwSu19fY+pi5ORgEzCQWDHpPgtIQkRgDaPEy jvzmEESzAJ6EtP+rWMHsYUFnCTWXNgE1sAioCrROeUGWJxXwE6iYeI3sLiEgLxEx4HJLCA2p4 C9xMa5H8DmCAHVLNt0gH0CI/cCRoZVjOZJRZnpGSW5iZk5uoYGBrqGhka6hpaWuoYWeolVukl 6qaW65anFJbqGeonlxXrFlbnJOSl6eaklmxiBYZJScFxoB+Ob1x/0DjFKcjApifIaTJGNF+JL yk+pzEgszogvKs1JLT7EKMPBoSTBe3UhUE6wKDU9tSItMwcYsjBpCQ4eJRHeOSBp3uKCxNziz HSI1ClGRSlx3n6QhABIIqM0D64NFieXGGWlhHkZGRgYhHgKUotyM0tQ5V8xinMwKgnzWoFM4c nMK4Gb/gpoMRPQYvdLkiCLSxIRUlINTLc3JcY4nHqydvtt/50taTZVAZM1I2VYPIvqNLYaHLl ivFd/9fJtHuzKETIMgjMz9or8fc9eZDPX5ezf6ysu5PCYZFspV/5+s6Bo1qPHar/v7/d9sl76 l6F2/sMTm9U5n2/LZd8YXC8yfw3P/c9PCzIc3v7O4tg0OcNq7YXce3mt11r+CzzTmVU69879e 8k1cg+f3f+rnLI56cBMFcNoyw+LGIwzAt8riLEabPpiMIHj2RJjng8rPEJSc3zf5F+K1p3Fz7 oxdd5WgYR4tcPe0btlNVp0Z0h3+4q3ZvaqF/tbz9ix8nNmwoPXfvfrIrP0m+NXp75aMvlOwZJ JIa9K3vU1+GQuZquST8qLe7KiTImlOCPRUIu5qDgRAMI5pF4OAwAA X-Env-Sender: bstroesser@ts.fujitsu.com X-Msg-Ref: server-28.tower-291.messagelabs.com!1595777746!937084!1 X-Originating-IP: [62.60.8.85] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.50.2; banners=-,-,- X-VirusChecked: Checked Received: (qmail 7545 invoked from network); 26 Jul 2020 15:35:46 -0000 Received: from unknown (HELO mailhost4.uk.fujitsu.com) (62.60.8.85) by server-28.tower-291.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 26 Jul 2020 15:35:46 -0000 Received: from x-serv01 ([172.17.38.52]) by mailhost4.uk.fujitsu.com (8.14.5/8.14.5) with SMTP id 06QFZdmc006421; Sun, 26 Jul 2020 16:35:40 +0100 Received: from VTC.emeia.fujitsu.local (unknown [172.17.38.7]) by x-serv01 (Postfix) with ESMTP id 27CCC204CE; Sun, 26 Jul 2020 17:35:37 +0200 (CEST) From: Bodo Stroesser To: "Martin K. Petersen" , Mike Christie , linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Cc: Bodo Stroesser Subject: [PATCH v3 1/8] scsi: target: Modify core_tmr_abort_task() Date: Sun, 26 Jul 2020 17:35:03 +0200 Message-Id: <20200726153510.13077-2-bstroesser@ts.fujitsu.com> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20200726153510.13077-1-bstroesser@ts.fujitsu.com> References: <20200726153510.13077-1-bstroesser@ts.fujitsu.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org This patch modifies core_tmr_abort_task() to use same looping and locking scheme as core_tmr_drain_state_list() does. This frees the state_list element in se_cmd for later use by tmr notification handling. Note: __target_check_io_state() now is called with param 0 instead of dev->dev_attrib.emulate_tas, because tas is not relevant since we always get ABRT on same session like the aborted command. Signed-off-by: Bodo Stroesser --- drivers/target/target_core_tmr.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c index 89c84d472cd7..73c4155f3c1e 100644 --- a/drivers/target/target_core_tmr.c +++ b/drivers/target/target_core_tmr.c @@ -116,14 +116,15 @@ void core_tmr_abort_task( struct se_tmr_req *tmr, struct se_session *se_sess) { - struct se_cmd *se_cmd; + struct se_cmd *se_cmd, *next; unsigned long flags; + bool rc; u64 ref_tag; - spin_lock_irqsave(&se_sess->sess_cmd_lock, flags); - list_for_each_entry(se_cmd, &se_sess->sess_cmd_list, se_cmd_list) { + spin_lock_irqsave(&dev->execute_task_lock, flags); + list_for_each_entry_safe(se_cmd, next, &dev->state_list, state_list) { - if (dev != se_cmd->se_dev) + if (se_sess != se_cmd->se_sess) continue; /* skip task management functions, including tmr->task_cmd */ @@ -137,11 +138,16 @@ void core_tmr_abort_task( printk("ABORT_TASK: Found referenced %s task_tag: %llu\n", se_cmd->se_tfo->fabric_name, ref_tag); - if (!__target_check_io_state(se_cmd, se_sess, - dev->dev_attrib.emulate_tas)) + spin_lock(&se_sess->sess_cmd_lock); + rc = __target_check_io_state(se_cmd, se_sess, 0); + spin_unlock(&se_sess->sess_cmd_lock); + if (!rc) continue; - spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); + list_del_init(&se_cmd->state_list); + se_cmd->state_active = false; + + spin_unlock_irqrestore(&dev->execute_task_lock, flags); /* * Ensure that this ABORT request is visible to the LU RESET @@ -159,7 +165,7 @@ void core_tmr_abort_task( atomic_long_inc(&dev->aborts_complete); return; } - spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); + spin_unlock_irqrestore(&dev->execute_task_lock, flags); printk("ABORT_TASK: Sending TMR_TASK_DOES_NOT_EXIST for ref_tag: %lld\n", tmr->ref_task_tag); From patchwork Sun Jul 26 15:35:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bodo Stroesser X-Patchwork-Id: 11685945 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D05EF1392 for ; Sun, 26 Jul 2020 15:35:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B37EC20714 for ; Sun, 26 Jul 2020 15:35:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ts.fujitsu.com header.i=@ts.fujitsu.com header.b="TZlFpxNL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727972AbgGZPf7 (ORCPT ); Sun, 26 Jul 2020 11:35:59 -0400 Received: from mail3.bemta25.messagelabs.com ([195.245.230.84]:25175 "EHLO mail3.bemta25.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727809AbgGZPfy (ORCPT ); Sun, 26 Jul 2020 11:35:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ts.fujitsu.com; s=200619tsfj; t=1595777750; i=@ts.fujitsu.com; bh=3mMSBbyuFhlgnc6RB4JBw6uOJpLIuiWRS6pGnKAuZ/M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=TZlFpxNLu9FariYc7TIYhitUXrMT3ZvzwobvrIQzhMmqR0nROU9O08brnNUuhSy4x IPezrs5oKncNwgNP4sHvkEgwPieUaTLmM3Up/jR+lqg70Uebu5he7NuUIinpJZtacs 53nJqxF0EPeEZoNVGljs0GP7OG4IRtNDt31GGdFPyrED+3Iupf/4DakBm/VHePVAFv c0G1YuL9DtSTK0uo5C0jFDMciiluwDR5Mm5cXgLaC7IHZx9JYEm/qOIuvIxLLFa713 SvDPQJcGl9GjECZlknp69hErBGg9PrCOUZW6JFYEpwap4JNJZTshXnfHHwrh9nJDbL +Qw2Qjmx96NFQ== Received: from [100.112.197.40] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-4.bemta.az-b.eu-west-1.aws.symcld.net id 37/F9-16187-6D2AD1F5; Sun, 26 Jul 2020 15:35:50 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrNLMWRWlGSWpSXmKPExsViZ8MxRffaItl 4gwspFt3Xd7BZLD/+j8ni76QbrBatS98yObB4fHx6i8Xj8ya5AKYo1sy8pPyKBNaMz7ueshc8 kq94M/MeWwPjOekuRi4OIYHJjBJ7P/5hg3CmM0q8+dLO2MXIycEmYCCxYtJ9FpCEiMAaRomVd +YxgySYBfQkpv1bxw5iCwu4Sizd/BKsgUVAVaKj8xWYzStgJ3HvzhSwGgkBeYmOA5NZQGxOAX uJjXM/gM0RAqpZtukA+wRG7gWMDKsYLZKKMtMzSnITM3N0DQ0MdA0NjXQNLc11DY3N9RKrdJP 0Ukt1y1OLS3QN9RLLi/WKK3OTc1L08lJLNjECwySl4GjnDsZfrz7oHWKU5GBSEuU1mCIbL8SX lJ9SmZFYnBFfVJqTWnyIUYaDQ0mC9+pCoJxgUWp6akVaZg4wZGHSEhw8SiK8c0DSvMUFibnFm ekQqVOMilLivP0gCQGQREZpHlwbLE4uMcpKCfMyMjAwCPEUpBblZpagyr9iFOdgVBLmtQKZwp OZVwI3/RXQYiagxe6XJEEWlyQipKQamCz6ryatXjP7SERiup4440SZ28tEV+9Z4/wnIrW/eXr lohfXReJKWd38Tx68wRs7neuQ+LUUXTOfpdOu32H+d8Z3vc2eiXsWZajaL5lQscDgYY7jz4gY 2ftLZBveT9SSZflULcBwe8ZPtfaAWXbsjmI2X2/cZdPv+DBxZYJpfLHSgp/BTLqWdgrbzPb5s p+YdPninYhpaQ0qD15mrD0btOr+pPdcFzl+eM3uuu/Ps/Oo6ufeFVcn5zJWsBZ4LF+72/8MW/ XCrztlGSWD65yuvbkcxrRwueOjFfXudxWO+phfaeotPHJs8XKVc0ftFnxPvZFzJdpV4Oeycvt liTsbj5rzrypc/ktQ4NC+pDZjph9KLMUZiYZazEXFiQBD0GKbDgMAAA== X-Env-Sender: bstroesser@ts.fujitsu.com X-Msg-Ref: server-16.tower-285.messagelabs.com!1595777749!1020530!1 X-Originating-IP: [62.60.8.148] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.50.2; banners=-,-,- X-VirusChecked: Checked Received: (qmail 6099 invoked from network); 26 Jul 2020 15:35:49 -0000 Received: from unknown (HELO mailhost1.uk.fujitsu.com) (62.60.8.148) by server-16.tower-285.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 26 Jul 2020 15:35:49 -0000 Received: from x-serv01 ([172.17.38.52]) by mailhost1.uk.fujitsu.com (8.14.5/8.14.5) with SMTP id 06QFZf1U009374; Sun, 26 Jul 2020 16:35:41 +0100 Received: from VTC.emeia.fujitsu.local (unknown [172.17.38.7]) by x-serv01 (Postfix) with ESMTP id 349452060A; Sun, 26 Jul 2020 17:35:37 +0200 (CEST) From: Bodo Stroesser To: "Martin K. Petersen" , Mike Christie , linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Cc: Bodo Stroesser Subject: [PATCH v3 2/8] scsi: target: Add tmr_notify backend function Date: Sun, 26 Jul 2020 17:35:04 +0200 Message-Id: <20200726153510.13077-3-bstroesser@ts.fujitsu.com> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20200726153510.13077-1-bstroesser@ts.fujitsu.com> References: <20200726153510.13077-1-bstroesser@ts.fujitsu.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Target core is modified to call an optional backend callback function if a TMR is received or commands are aborted implicitly after a PR command was received. The backend function takes as parameters the se_dev, the type of the TMR, and the list of aborted commands. If no commands were aborted, an empty list is supplied. Signed-off-by: Bodo Stroesser --- drivers/target/target_core_tmr.c | 16 +++++++++++++++- drivers/target/target_core_transport.c | 1 + include/target/target_core_backend.h | 2 ++ include/target/target_core_base.h | 1 + 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c index 73c4155f3c1e..e4513ef09159 100644 --- a/drivers/target/target_core_tmr.c +++ b/drivers/target/target_core_tmr.c @@ -116,6 +116,7 @@ void core_tmr_abort_task( struct se_tmr_req *tmr, struct se_session *se_sess) { + LIST_HEAD(aborted_list); struct se_cmd *se_cmd, *next; unsigned long flags; bool rc; @@ -144,7 +145,7 @@ void core_tmr_abort_task( if (!rc) continue; - list_del_init(&se_cmd->state_list); + list_move_tail(&se_cmd->state_list, &aborted_list); se_cmd->state_active = false; spin_unlock_irqrestore(&dev->execute_task_lock, flags); @@ -157,6 +158,11 @@ void core_tmr_abort_task( WARN_ON_ONCE(transport_lookup_tmr_lun(tmr->task_cmd) < 0); + if (dev->transport->tmr_notify) + dev->transport->tmr_notify(dev, TMR_ABORT_TASK, + &aborted_list); + + list_del_init(&se_cmd->state_list); target_put_cmd_and_wait(se_cmd); printk("ABORT_TASK: Sending TMR_FUNCTION_COMPLETE for" @@ -167,6 +173,9 @@ void core_tmr_abort_task( } spin_unlock_irqrestore(&dev->execute_task_lock, flags); + if (dev->transport->tmr_notify) + dev->transport->tmr_notify(dev, TMR_ABORT_TASK, &aborted_list); + printk("ABORT_TASK: Sending TMR_TASK_DOES_NOT_EXIST for ref_tag: %lld\n", tmr->ref_task_tag); tmr->response = TMR_TASK_DOES_NOT_EXIST; @@ -318,6 +327,11 @@ static void core_tmr_drain_state_list( } spin_unlock_irqrestore(&dev->execute_task_lock, flags); + if (dev->transport->tmr_notify) + dev->transport->tmr_notify(dev, preempt_and_abort_list ? + TMR_LUN_RESET_PRO : TMR_LUN_RESET, + &drain_task_list); + while (!list_empty(&drain_task_list)) { cmd = list_entry(drain_task_list.next, struct se_cmd, state_list); list_del_init(&cmd->state_list); diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index e6e1fa68de54..9fb0be0aa620 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -2946,6 +2946,7 @@ static const char *target_tmf_name(enum tcm_tmreq_table tmf) case TMR_LUN_RESET: return "LUN_RESET"; case TMR_TARGET_WARM_RESET: return "TARGET_WARM_RESET"; case TMR_TARGET_COLD_RESET: return "TARGET_COLD_RESET"; + case TMR_LUN_RESET_PRO: return "LUN_RESET_PRO"; case TMR_UNKNOWN: break; } return "(?)"; diff --git a/include/target/target_core_backend.h b/include/target/target_core_backend.h index f51452e3b984..6336780d83a7 100644 --- a/include/target/target_core_backend.h +++ b/include/target/target_core_backend.h @@ -40,6 +40,8 @@ struct target_backend_ops { ssize_t (*show_configfs_dev_params)(struct se_device *, char *); sense_reason_t (*parse_cdb)(struct se_cmd *cmd); + void (*tmr_notify)(struct se_device *se_dev, enum tcm_tmreq_table, + struct list_head *aborted_cmds); u32 (*get_device_type)(struct se_device *); sector_t (*get_blocks)(struct se_device *); sector_t (*get_alignment_offset_lbas)(struct se_device *); diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h index 18c3f277b770..549947d407cf 100644 --- a/include/target/target_core_base.h +++ b/include/target/target_core_base.h @@ -207,6 +207,7 @@ enum tcm_tmreq_table { TMR_LUN_RESET = 5, TMR_TARGET_WARM_RESET = 6, TMR_TARGET_COLD_RESET = 7, + TMR_LUN_RESET_PRO = 0x80, TMR_UNKNOWN = 0xff, }; From patchwork Sun Jul 26 15:35:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bodo Stroesser X-Patchwork-Id: 11685919 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 12F831746 for ; Sun, 26 Jul 2020 15:35:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EDC2320759 for ; Sun, 26 Jul 2020 15:35:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ts.fujitsu.com header.i=@ts.fujitsu.com header.b="UJJe4taX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727950AbgGZPfv (ORCPT ); Sun, 26 Jul 2020 11:35:51 -0400 Received: from mail1.bemta25.messagelabs.com ([195.245.230.5]:61357 "EHLO mail1.bemta25.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727809AbgGZPfv (ORCPT ); Sun, 26 Jul 2020 11:35:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ts.fujitsu.com; s=200619tsfj; t=1595777747; i=@ts.fujitsu.com; bh=3Dr9L1Lw9/CiK8afeg4DStkBmBuyCm8ZavaSMzq71do=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=UJJe4taXnXxBZkeqNJ+TWOiymOO3zGToK1y5BeXzwLe03SsZQAqwVYsn+Mja5BbBO ZXyY8kmLj7XXc0mT3SP6L3U0jd+c3yfmuy27z3N25WerQ2JMLkEraZAUdjLC50B+ef HTq6+FGWwcioRuV1v9f9gAHzmz+1K0AqN4gkmRIyoy12UNlcKpcFl7YMLxdepWnlyS U0F3scEuP9DaUz8sLJyJpofQoo4y3AWc1XdCKyJf01Os1xiJ/UFiHVpDWv1u4Ih8yP pFLBwswHUl8mYhVaeZhUcqtRp/7U2OIwD5mbkpd+1tA1mAClRTM8pG18EFAvq6WXSI 4VN8Mruggu5vg== Received: from [100.112.192.107] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-5.bemta.az-a.eu-west-1.aws.symcld.net id 69/7D-15309-3D2AD1F5; Sun, 26 Jul 2020 15:35:47 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrDLMWRWlGSWpSXmKPExsViZ8MRqntpkWy 8QdtzG4vu6zvYLJYf/8dk8XfSDVaL1qVvmRxYPD4+vcXi8XmTXABTFGtmXlJ+RQJrxrSvs9kL bvJW/Jm5hL2B8TN3FyMXh5DAZEaJxbNvMEM40xkljuzsZupi5ORgEzCQWDHpPgtIQkRgDaPEy jvzmEESzAJ6EtP+rWMHsYUF3CQeL9zBCGKzCKhKfHo2A6yZV8BO4v2qn2A1EgLyEh0HJrOA2J wC9hIb534AmyMEVLNs0wH2CYzcCxgZVjFaJBVlpmeU5CZm5ugaGhjoGhoa6RpaGukaGZjoJVb pJuqlluqWpxaX6BrqJZYX6xVX5ibnpOjlpZZsYgQGSkrBgTM7GE+9/qB3iFGSg0lJlNdgimy8 EF9SfkplRmJxRnxRaU5q8SFGGQ4OJQneqwuBcoJFqempFWmZOcCghUlLcPAoifDOAUnzFhck5 hZnpkOkTjEqSonz9oMkBEASGaV5cG2wSLnEKCslzMvIwMAgxFOQWpSbWYIq/4pRnINRSZjXCm QKT2ZeCdz0V0CLmYAWu1+SBFlckoiQkmpg0mhe9+PMsjjxFjYZIankenXd2uaMxtnpC/omvdr 9jUMi/Ez1GQ/n70/zwre6/94Zbc7N09c4RyCMY9OH8ByppFa2/N3njZI4Fp+Yz/b5TkWgvau5 1pl8nupehh13NV5Ou/Tlgd4z1lPenx/ETvVs4ap01/c551OeufTvoqAGrkVHJ2t89o55YSWif e7ch7KCWad7p7GyG8lcyYgqSczm81nf5/q/x6j2fosKm8SMFbVODx9vNs355M1+5PpCuRiWFz MfGmjEKW/VYn42q1GRz26GzamwrIoVNptEp88LfvWTv5T5Uuf+i7/nTNt88nmW0hL7nskLcmW nLoncFxRRvCe3+hDb4wWXt9/LbHquxFKckWioxVxUnAgAuRlB0Q8DAAA= X-Env-Sender: bstroesser@ts.fujitsu.com X-Msg-Ref: server-7.tower-271.messagelabs.com!1595777746!220568!1 X-Originating-IP: [62.60.8.85] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.50.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 5383 invoked from network); 26 Jul 2020 15:35:46 -0000 Received: from unknown (HELO mailhost4.uk.fujitsu.com) (62.60.8.85) by server-7.tower-271.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 26 Jul 2020 15:35:46 -0000 Received: from x-serv01 ([172.17.38.52]) by mailhost4.uk.fujitsu.com (8.14.5/8.14.5) with SMTP id 06QFZdE5006422; Sun, 26 Jul 2020 16:35:40 +0100 Received: from VTC.emeia.fujitsu.local (unknown [172.17.38.7]) by x-serv01 (Postfix) with ESMTP id 411802062A; Sun, 26 Jul 2020 17:35:37 +0200 (CEST) From: Bodo Stroesser To: "Martin K. Petersen" , Mike Christie , linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Cc: Bodo Stroesser Subject: [PATCH v3 3/8] scsi: target: tcmu: Use priv pointer in se_cmd Date: Sun, 26 Jul 2020 17:35:05 +0200 Message-Id: <20200726153510.13077-4-bstroesser@ts.fujitsu.com> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20200726153510.13077-1-bstroesser@ts.fujitsu.com> References: <20200726153510.13077-1-bstroesser@ts.fujitsu.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org We initialize and clean up the se_cmd's priv pointer under cmd_ring_lock to point to the corresponding tcmu_cmd. In the patch that implements tmr_notify callback in tcmu we will use the priv pointer. Signed-off-by: Bodo Stroesser --- drivers/target/target_core_user.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c index 366878b0b2fd..b06b18d1b135 100644 --- a/drivers/target/target_core_user.c +++ b/drivers/target/target_core_user.c @@ -541,6 +541,8 @@ tcmu_get_block_page(struct tcmu_dev *udev, uint32_t dbi) static inline void tcmu_free_cmd(struct tcmu_cmd *tcmu_cmd) { + if (tcmu_cmd->se_cmd) + tcmu_cmd->se_cmd->priv = NULL; kfree(tcmu_cmd->dbi); kmem_cache_free(tcmu_cmd_cache, tcmu_cmd); } @@ -1109,10 +1111,11 @@ tcmu_queue_cmd(struct se_cmd *se_cmd) return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; mutex_lock(&udev->cmdr_lock); + se_cmd->priv = tcmu_cmd; ret = queue_cmd_ring(tcmu_cmd, &scsi_ret); - mutex_unlock(&udev->cmdr_lock); if (ret < 0) tcmu_free_cmd(tcmu_cmd); + mutex_unlock(&udev->cmdr_lock); return scsi_ret; } @@ -1179,7 +1182,6 @@ static void tcmu_handle_completion(struct tcmu_cmd *cmd, struct tcmu_cmd_entry * target_complete_cmd(cmd->se_cmd, entry->rsp.scsi_status); out: - cmd->se_cmd = NULL; tcmu_cmd_free_data(cmd, cmd->dbi_cnt); tcmu_free_cmd(cmd); } @@ -1285,6 +1287,7 @@ static void tcmu_check_expired_ring_cmd(struct tcmu_cmd *cmd) set_bit(TCMU_CMD_BIT_EXPIRED, &cmd->flags); list_del_init(&cmd->queue_entry); se_cmd = cmd->se_cmd; + se_cmd->priv = NULL; cmd->se_cmd = NULL; pr_debug("Timing out inflight cmd %u on dev %s.\n", From patchwork Sun Jul 26 15:35:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bodo Stroesser X-Patchwork-Id: 11685929 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3DD1F1746 for ; Sun, 26 Jul 2020 15:35:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 229CA20714 for ; Sun, 26 Jul 2020 15:35:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ts.fujitsu.com header.i=@ts.fujitsu.com header.b="m6TCvm8x" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727970AbgGZPf4 (ORCPT ); Sun, 26 Jul 2020 11:35:56 -0400 Received: from mail1.bemta25.messagelabs.com ([195.245.230.4]:62491 "EHLO mail1.bemta25.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727956AbgGZPfw (ORCPT ); Sun, 26 Jul 2020 11:35:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ts.fujitsu.com; s=200619tsfj; t=1595777751; i=@ts.fujitsu.com; bh=tK3FIVROxYjkLrzhtoyLVijq5QAfznqa/3uJx7/8R3M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=m6TCvm8xiijc7CAU6Nt/4Xfw6XC81vBwv/qE0Hu4yCjYJR7GWC/CccnN9bOKwnY0u 0dFTjM+LVEsINuA8xpMOEGsc5DrpLbnC2mx8zEP7otljKlDZ4HySiFD8lXXwi/tVCR vFXx8zZETGOyhcsEoeMLS8ifzmESXKMAiQd0mBbZzRV1tYUb4gfqdXSrNd+onKAY6r oYsfEJ3gEFVz640Jqn+ZBg5UOvo5PyoTE+DdIOYEFEQST0TZwbTiuMWkkNR7Q/uIK1 hxsrxwqmtubh9OWhrGXHKnhe6B1qhLD/Yn+REM9I8/Ycfou22IJiM+3FyE4xU+7WDx ethnFOx3DM9fA== Received: from [100.112.192.107] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-4.bemta.az-a.eu-west-1.aws.symcld.net id 39/B7-17694-6D2AD1F5; Sun, 26 Jul 2020 15:35:50 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrFLMWRWlGSWpSXmKPExsViZ8MxRffaItl 4g61zGC26r+9gs1h+/B+Txd9JN1gtWpe+ZXJg8fj49BaLx+dNcgFMUayZeUn5FQmsGf9nHGMs +MpR0f+otIHxCXsXIxeHkMBkRolnJ68wQzjTGSWWrXwHlOHkYBMwkFgx6T4LSEJEYA2jxMo78 5hBEswCehLT/q0DKxIW8JS49O4VC4jNIqAqsbj9GhOIzStgJ3Gj4zNYvYSAvETHgclgNZwC9h Ib534AiwsB1SzbdIB9AiP3AkaGVYzmSUWZ6RkluYmZObqGBga6hoZGuoaWJroWxnqJVbqJeqm luuWpxSW6hnqJ5cV6xZW5yTkpenmpJZsYgUGSUnAoeAdj35sPeocYJTmYlER5DabIxgvxJeWn VGYkFmfEF5XmpBYfYpTh4FCS4L26ECgnWJSanlqRlpkDDFiYtAQHj5II7xyQNG9xQWJucWY6R OoUo6KUOG8/SEIAJJFRmgfXBouSS4yyUsK8jAwMDEI8BalFuZklqPKvGMU5GJWEea1ApvBk5p XATX8FtJgJaLH7JUmQxSWJCCmpBqYlVyd9jnu8Y5PiyvU7Z9wuXFIVnH9lbU2k5NRDm9z0Uu6 1eJ3IylO5pR9df7Ui2Mn769tZGvq3o8S2nr0v8Elx+9+9T3c8+GoV41Jz55bIB6XAMMnF+aWO t/T/L1h3bNqWZDPfJbnXn851eLzpTW8uzwPJ7qQ+qYotrKZevmvmf9sWc8vfTrZgyzw2p68yg o9SYwsbvQJ+FZ+b36898eJ5J7+rIetX8+1V3XL7p9FPrb6lYqzxYX6NrB9zd95U0zK//nV5Y9 a6+W3nuRY0+2W/CFfLv9PqcOKwQ/Z0tusfLsi/Vpq/0vBw9UarX1ftum6Gi33dXyM/U7A5q2W jmtiOqSdv//tou+785FXHGDbvUWIpzkg01GIuKk4EAAask/oNAwAA X-Env-Sender: bstroesser@ts.fujitsu.com X-Msg-Ref: server-7.tower-267.messagelabs.com!1595777749!466549!1 X-Originating-IP: [62.60.8.148] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.50.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 31289 invoked from network); 26 Jul 2020 15:35:49 -0000 Received: from unknown (HELO mailhost1.uk.fujitsu.com) (62.60.8.148) by server-7.tower-267.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 26 Jul 2020 15:35:49 -0000 Received: from x-serv01 ([172.17.38.52]) by mailhost1.uk.fujitsu.com (8.14.5/8.14.5) with SMTP id 06QFZf5R009375; Sun, 26 Jul 2020 16:35:41 +0100 Received: from VTC.emeia.fujitsu.local (unknown [172.17.38.7]) by x-serv01 (Postfix) with ESMTP id 4342420662; Sun, 26 Jul 2020 17:35:37 +0200 (CEST) From: Bodo Stroesser To: "Martin K. Petersen" , Mike Christie , linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Cc: Bodo Stroesser Subject: [PATCH v3 4/8] scsi: target: tcmu: Do not queue aborted commands Date: Sun, 26 Jul 2020 17:35:06 +0200 Message-Id: <20200726153510.13077-5-bstroesser@ts.fujitsu.com> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20200726153510.13077-1-bstroesser@ts.fujitsu.com> References: <20200726153510.13077-1-bstroesser@ts.fujitsu.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org If tcmu receives an already aborted command, tcmu_queue_cmd() should reject it. Signed-off-by: Bodo Stroesser --- drivers/target/target_core_user.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c index b06b18d1b135..25c480fde9ee 100644 --- a/drivers/target/target_core_user.c +++ b/drivers/target/target_core_user.c @@ -1103,8 +1103,8 @@ tcmu_queue_cmd(struct se_cmd *se_cmd) struct se_device *se_dev = se_cmd->se_dev; struct tcmu_dev *udev = TCMU_DEV(se_dev); struct tcmu_cmd *tcmu_cmd; - sense_reason_t scsi_ret; - int ret; + sense_reason_t scsi_ret = TCM_CHECK_CONDITION_ABORT_CMD; + int ret = -1; tcmu_cmd = tcmu_alloc_cmd(se_cmd); if (!tcmu_cmd) @@ -1112,7 +1112,8 @@ tcmu_queue_cmd(struct se_cmd *se_cmd) mutex_lock(&udev->cmdr_lock); se_cmd->priv = tcmu_cmd; - ret = queue_cmd_ring(tcmu_cmd, &scsi_ret); + if (!(se_cmd->transport_state & CMD_T_ABORTED)) + ret = queue_cmd_ring(tcmu_cmd, &scsi_ret); if (ret < 0) tcmu_free_cmd(tcmu_cmd); mutex_unlock(&udev->cmdr_lock); From patchwork Sun Jul 26 15:35:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bodo Stroesser X-Patchwork-Id: 11685943 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9817217C5 for ; Sun, 26 Jul 2020 15:35:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7DC1B2070B for ; Sun, 26 Jul 2020 15:35:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ts.fujitsu.com header.i=@ts.fujitsu.com header.b="X1wGinMF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727956AbgGZPf6 (ORCPT ); Sun, 26 Jul 2020 11:35:58 -0400 Received: from mail1.bemta25.messagelabs.com ([195.245.230.4]:60441 "EHLO mail1.bemta25.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727955AbgGZPfy (ORCPT ); Sun, 26 Jul 2020 11:35:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ts.fujitsu.com; s=200619tsfj; t=1595777751; i=@ts.fujitsu.com; bh=y9ylx5PwdzIjX0o5YrFnCMuaeiv73CouMTrYVHBkPDk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=X1wGinMF23kLdwFp7FbbSCWxPGZisqgt/kHTPqZ5wiwB53tGs2BPfXeUOiu1rf9Ma fzsZgzkdq+8vigI3R+4EkdWgr4QKb1E9IYLMS+FAiXlZ8AsKQfPff34BRbbj3PGGyS 0OaqBY+V5dKM7rl0ai1lT9XJ6IZsIQnHXXM71F8fkHw+1/zssRX5JhjhyIgEBcEThj xehOrYwj5mZc2g/FiR3auBoKdVzLzPFANcmxgRPqcngZB4uy0bbJAWHVanVtAmrc8v 5CF+wLhh/NpGWWDLdk1QyxIjQhSt9/OICMMUhQjjAenjWgqIIvKuuzQM6CK/hAEaqa C/FXbtUaP88/w== Received: from [100.112.192.163] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-4.bemta.az-a.eu-west-1.aws.symcld.net id 58/B7-17694-6D2AD1F5; Sun, 26 Jul 2020 15:35:50 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrNLMWRWlGSWpSXmKPExsViZ8MxRffaItl 4g446i+7rO9gslh//x2Txd9INVovWpW+ZHFg8Pj69xeLxeZNcAFMUa2ZeUn5FAmvG/dtbmQpO SFW8WTqLtYHxtFgXIxeHkMBkRolbF5azQDjTGSUOvNjN2sXIycEmYCCxYtJ9sISIwBpGiZV35 jGDJJgF9CSm/VvHDmILC4RKvJy4mBHEZhFQlZj+oxMszitgJ3H14EQ2EFtCQF6i48BkFhCbU8 BeYuPcD2BzhIBqlm06wD6BkXsBI8MqRoukosz0jJLcxMwcXUMDA11DQyNdQ0tTXUNTQ73EKt1 EvdRS3fLU4hJdILe8WK+4Mjc5J0UvL7VkEyMwTFIKDk/fwdj/5oPeIUZJDiYlUV6DKbLxQnxJ +SmVGYnFGfFFpTmpxYcYZTg4lCR4ry4EygkWpaanVqRl5gBDFiYtwcGjJMI7ByTNW1yQmFucm Q6ROsWoKCXO2w+SEABJZJTmwbXB4uQSo6yUMC8jAwODEE9BalFuZgmq/CtGcQ5GJWFeK5ApPJ l5JXDTXwEtZgJa7H5JEmRxSSJCSqqBSclRqYDl5sr6m77iormxvnaSZpynnBbYid9L4z6Ts3z JMtv7TbxzZyy6o9rlsnVdi+Uq5+d/Ln3a13oy8B7TFdbgpE+6qdoNqz0+6Myzl4jXrz8z8fsf t0ilrPonz557bV+1v+3Xdl2xZ1rvBA6e+xB2LKFyQeYlIfM1wnWJPmkPpjBtjZsUUKD//GM+V 3QX492GKpVn8/ODPzstuZp5oN347/WLuzalH4grsdKSfyT54M/jqEcM0/N1ubYtmbFp+tG/88 tLpn5Kn3VwWbue5JEJjMb2ycJvdXiVAh7bM09LPLI9zYghXeethJb1KqMJT35YLPuQ2/xn+hz r6tuqqkL7dgs1zNwuLdah/N3jtxJLcUaioRZzUXEiAKJqxI4OAwAA X-Env-Sender: bstroesser@ts.fujitsu.com X-Msg-Ref: server-4.tower-265.messagelabs.com!1595777749!468837!1 X-Originating-IP: [62.60.8.148] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.50.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 28489 invoked from network); 26 Jul 2020 15:35:49 -0000 Received: from unknown (HELO mailhost1.uk.fujitsu.com) (62.60.8.148) by server-4.tower-265.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 26 Jul 2020 15:35:49 -0000 Received: from x-serv01 ([172.17.38.52]) by mailhost1.uk.fujitsu.com (8.14.5/8.14.5) with SMTP id 06QFZkcm009400; Sun, 26 Jul 2020 16:35:46 +0100 Received: from VTC.emeia.fujitsu.local (unknown [172.17.38.7]) by x-serv01 (Postfix) with ESMTP id 4EEDA20699; Sun, 26 Jul 2020 17:35:37 +0200 (CEST) From: Bodo Stroesser To: "Martin K. Petersen" , Mike Christie , linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Cc: Bodo Stroesser Subject: [PATCH v3 5/8] scsi: target: tcmu: Factor out new helper ring_insert_padding Date: Sun, 26 Jul 2020 17:35:07 +0200 Message-Id: <20200726153510.13077-6-bstroesser@ts.fujitsu.com> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20200726153510.13077-1-bstroesser@ts.fujitsu.com> References: <20200726153510.13077-1-bstroesser@ts.fujitsu.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The new helper ring_insert_padding is split off from and then called by queue_cmd_ring. It inserts a padding if necessary. The new helper will in a further patch be used during writing of TMR notifications to command ring. Signed-off-by: Bodo Stroesser --- drivers/target/target_core_user.c | 51 +++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c index 25c480fde9ee..eb68c5fee7b7 100644 --- a/drivers/target/target_core_user.c +++ b/drivers/target/target_core_user.c @@ -926,6 +926,34 @@ static int add_to_qfull_queue(struct tcmu_cmd *tcmu_cmd) return 0; } +static uint32_t ring_insert_padding(struct tcmu_dev *udev, size_t cmd_size) +{ + struct tcmu_cmd_entry_hdr *hdr; + struct tcmu_mailbox *mb = udev->mb_addr; + uint32_t cmd_head = mb->cmd_head % udev->cmdr_size; /* UAM */ + + /* Insert a PAD if end-of-ring space is too small */ + if (head_to_end(cmd_head, udev->cmdr_size) < cmd_size) { + size_t pad_size = head_to_end(cmd_head, udev->cmdr_size); + + hdr = (void *) mb + CMDR_OFF + cmd_head; + tcmu_hdr_set_op(&hdr->len_op, TCMU_OP_PAD); + tcmu_hdr_set_len(&hdr->len_op, pad_size); + hdr->cmd_id = 0; /* not used for PAD */ + hdr->kflags = 0; + hdr->uflags = 0; + tcmu_flush_dcache_range(hdr, sizeof(*hdr)); + + UPDATE_HEAD(mb->cmd_head, pad_size, udev->cmdr_size); + tcmu_flush_dcache_range(mb, sizeof(*mb)); + + cmd_head = mb->cmd_head % udev->cmdr_size; /* UAM */ + WARN_ON(cmd_head != 0); + } + + return cmd_head; +} + /** * queue_cmd_ring - queue cmd to ring or internally * @tcmu_cmd: cmd to queue @@ -941,7 +969,7 @@ static int queue_cmd_ring(struct tcmu_cmd *tcmu_cmd, sense_reason_t *scsi_err) struct tcmu_dev *udev = tcmu_cmd->tcmu_dev; struct se_cmd *se_cmd = tcmu_cmd->se_cmd; size_t base_command_size, command_size; - struct tcmu_mailbox *mb; + struct tcmu_mailbox *mb = udev->mb_addr; struct tcmu_cmd_entry *entry; struct iovec *iov; int iov_cnt, cmd_id; @@ -980,8 +1008,6 @@ static int queue_cmd_ring(struct tcmu_cmd *tcmu_cmd, sense_reason_t *scsi_err) if (!list_empty(&udev->qfull_queue)) goto queue; - mb = udev->mb_addr; - cmd_head = mb->cmd_head % udev->cmdr_size; /* UAM */ if ((command_size > (udev->cmdr_size / 2)) || data_length > udev->data_size) { pr_warn("TCMU: Request of size %zu/%zu is too big for %u/%zu " @@ -1001,24 +1027,7 @@ static int queue_cmd_ring(struct tcmu_cmd *tcmu_cmd, sense_reason_t *scsi_err) goto queue; } - /* Insert a PAD if end-of-ring space is too small */ - if (head_to_end(cmd_head, udev->cmdr_size) < command_size) { - size_t pad_size = head_to_end(cmd_head, udev->cmdr_size); - - entry = (void *) mb + CMDR_OFF + cmd_head; - tcmu_hdr_set_op(&entry->hdr.len_op, TCMU_OP_PAD); - tcmu_hdr_set_len(&entry->hdr.len_op, pad_size); - entry->hdr.cmd_id = 0; /* not used for PAD */ - entry->hdr.kflags = 0; - entry->hdr.uflags = 0; - tcmu_flush_dcache_range(entry, sizeof(entry->hdr)); - - UPDATE_HEAD(mb->cmd_head, pad_size, udev->cmdr_size); - tcmu_flush_dcache_range(mb, sizeof(*mb)); - - cmd_head = mb->cmd_head % udev->cmdr_size; /* UAM */ - WARN_ON(cmd_head != 0); - } + cmd_head = ring_insert_padding(udev, command_size); entry = (void *) mb + CMDR_OFF + cmd_head; memset(entry, 0, command_size); From patchwork Sun Jul 26 15:35:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bodo Stroesser X-Patchwork-Id: 11685935 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C80AC17CB for ; Sun, 26 Jul 2020 15:35:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B0E8C2076A for ; Sun, 26 Jul 2020 15:35:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ts.fujitsu.com header.i=@ts.fujitsu.com header.b="U2QWPRO6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727962AbgGZPfz (ORCPT ); Sun, 26 Jul 2020 11:35:55 -0400 Received: from mail1.bemta26.messagelabs.com ([85.158.142.116]:53232 "EHLO mail1.bemta26.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727936AbgGZPfw (ORCPT ); Sun, 26 Jul 2020 11:35:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ts.fujitsu.com; s=200619tsfj; t=1595777748; i=@ts.fujitsu.com; bh=nFFQEN/Ep7H634q/N416zmClyutQqyDZoaXtEC5dMsk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=U2QWPRO6GoMD1O4sjsgcTeFRZQCpKG9TCyDkSzWsrdL8xroaXigepUS37g2cPq1mr gPLVczrkh0iSUb3Qnsbz7zHT1LFfqBySCxqcBZ6CVJZQHkfE4TjiDhPZVNBGhbegX6 3Q7el7uJ28bESpAuwqrX0zWlIxjQqOyrBFLCF3JRhnRpRiKwJV3bLND4Hiu7oQVy7+ pl4SChkZTbtfBs+RAeEr8/RazGMEHQkXyARLitPOARJZoHThDKf1zZYlXyQZf2WThr uHNzeVCDAtGAY4vvuW0KRElWSr147B+o4kamBRRyrX0r1nspWMX5NiFnnZlqmuwoKV MqS9VmT/NaJMQ== Received: from [100.113.7.116] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-5.bemta.az-b.eu-central-1.aws.symcld.net id D1/60-08547-3D2AD1F5; Sun, 26 Jul 2020 15:35:47 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrLLMWRWlGSWpSXmKPExsViZ8MRqnt5kWy 8wePHkhbd13ewWSw//o/J4u+kG6wWrUvfMjmweHx8eovF4/MmuQCmKNbMvKT8igTWjGc3PjEV rFStWP9zN2MD42H5LkYuDiGByYwS66//ZoJwpjNKrLk0l6WLkZODTcBAYsWk+ywgCRGBNYwSK +/MYwZJMAvoSUz7t44dxBYW8JXovvSBDcRmEVCVeHjvDxOIzStgJ7Hq0FxWEFtCQF6i48BksK GcAvYSG+d+AJsjBFSzbNMB9gmM3AsYGVYxWiYVZaZnlOQmZuboGhoY6BoaGuuaA1mmeolVukl 6qaW6yal5JUWJQFm9xPJiveLK3OScFL281JJNjMBQSSlkz9zBOPnNB71DjJIcTEqivAZTZOOF +JLyUyozEosz4otKc1KLDzHKcHAoSfBeXQiUEyxKTU+tSMvMAYYtTFqCg0dJhHcOSJq3uCAxt zgzHSJ1ilFRSpy3HyQhAJLIKM2Da4PFyiVGWSlhXkYGBgYhnoLUotzMElT5V4ziHIxKwrxWIF N4MvNK4Ka/AlrMBLTY/ZIkyOKSRISUVANTcf3PlrA37a9y7ZkaFXxPqnK2tjU2/1jH9NVpX1H RJPlGszv71+1ktpc8vO8S3wT1myri0bMTD13+t/xzU8Uy1e6WTJ+qMJdU1c55CWtftvUkGqe9 rets+SDb7yHz8cvxSRXREm+zL89mStjbdUj48tKU10GfO57/POLae3721eOTD11eGLbI0EUpt iczzX9XpPVdHYZaq8d7digbsbpafWFin/T8cusKhgdTmt47Pp9Xvet4x7/V2oaM0UJsTxyt64 6d55OdtbZS7EK1+eft0y78ZGfYZ3l98dyJUb92vvE6M0Wq/9P2zIMFj5act2p5KVfZUmHRs0I 34uLN8Jigo6u5a4/dOqFw69yDJh07JZbijERDLeai4kQAbuX3vRADAAA= X-Env-Sender: bstroesser@ts.fujitsu.com X-Msg-Ref: server-14.tower-238.messagelabs.com!1595777746!637983!1 X-Originating-IP: [62.60.8.85] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.50.2; banners=-,-,- X-VirusChecked: Checked Received: (qmail 3264 invoked from network); 26 Jul 2020 15:35:47 -0000 Received: from unknown (HELO mailhost4.uk.fujitsu.com) (62.60.8.85) by server-14.tower-238.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 26 Jul 2020 15:35:47 -0000 Received: from x-serv01 ([172.17.38.52]) by mailhost4.uk.fujitsu.com (8.14.5/8.14.5) with SMTP id 06QFZkRA006464; Sun, 26 Jul 2020 16:35:46 +0100 Received: from VTC.emeia.fujitsu.local (unknown [172.17.38.7]) by x-serv01 (Postfix) with ESMTP id 516F5206B3; Sun, 26 Jul 2020 17:35:37 +0200 (CEST) From: Bodo Stroesser To: "Martin K. Petersen" , Mike Christie , linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Cc: Bodo Stroesser Subject: [PATCH v3 6/8] scsi: target: tcmu: Fix and simplify timeout handling Date: Sun, 26 Jul 2020 17:35:08 +0200 Message-Id: <20200726153510.13077-7-bstroesser@ts.fujitsu.com> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20200726153510.13077-1-bstroesser@ts.fujitsu.com> References: <20200726153510.13077-1-bstroesser@ts.fujitsu.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org During cmd timeout handling in check_timedout_devices() due to a race it can happen, that tcmu_set_next_deadline() does not start a timer as expected: 1) Either tcmu_check_expired_ring_cmd() checks the inflight_queue or tcmu_check_expired_queue_cmd() checks the qfull_queue while jiffies has the value X 2) At the end of the check the queue contains one remaining command with deadline X (time_after(X, X) is false and thus the command is not handled as being timed out). 3) After tcmu_check_expired_xxxxx_cmd() a timer interrupt happens and jiffies is incremented to X+1. 4) Now tcmu_set_next_deadline() is called, but it skips the command, since time_after(X+1, X) is true. Therefore tcmu_set_next_deadline() finds no new deadline and stops the timer, which it shouldn't. Since commands that time out are removed from inflight_queue or qfull_queue, we don't need the check with time_after() in tcmu_set_next_deadline(), but can use the deadline from the first cmd in the queue. Additionally I replaced the remaining time_after() calls in tcmu_check_expired_xxxxx_cmd() with time_after_eq(), because it is not useful to set the timeout to deadline, but then check for jiffies being greater than deadline. Next I simplified the end of tcmu_handle_completions() and changed the check for no more pending commands from "mb->cmd_tail == mb->cmd_head" to "idr_is_empty(&udev->commands)" because the old check doesn't work correctly if paddings or in the future TMRs are in the ring. Finally tcmu_set_next_deadline() was shifted in the source as preparation for later implementation of tmr_notify callback. Signed-off-by: Bodo Stroesser --- drivers/target/target_core_user.c | 59 +++++++++++++++------------------------ 1 file changed, 23 insertions(+), 36 deletions(-) diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c index eb68c5fee7b7..bddd40f07929 100644 --- a/drivers/target/target_core_user.c +++ b/drivers/target/target_core_user.c @@ -1129,6 +1129,18 @@ tcmu_queue_cmd(struct se_cmd *se_cmd) return scsi_ret; } +static void tcmu_set_next_deadline(struct list_head *queue, + struct timer_list *timer) +{ + struct tcmu_cmd *cmd; + + if (!list_empty(queue)) { + cmd = list_first_entry(queue, struct tcmu_cmd, queue_entry); + mod_timer(timer, cmd->deadline); + } else + del_timer(timer); +} + static void tcmu_handle_completion(struct tcmu_cmd *cmd, struct tcmu_cmd_entry *entry) { struct se_cmd *se_cmd = cmd->se_cmd; @@ -1196,25 +1208,6 @@ static void tcmu_handle_completion(struct tcmu_cmd *cmd, struct tcmu_cmd_entry * tcmu_free_cmd(cmd); } -static void tcmu_set_next_deadline(struct list_head *queue, - struct timer_list *timer) -{ - struct tcmu_cmd *tcmu_cmd, *tmp_cmd; - unsigned long deadline = 0; - - list_for_each_entry_safe(tcmu_cmd, tmp_cmd, queue, queue_entry) { - if (!time_after(jiffies, tcmu_cmd->deadline)) { - deadline = tcmu_cmd->deadline; - break; - } - } - - if (deadline) - mod_timer(timer, deadline); - else - del_timer(timer); -} - static unsigned int tcmu_handle_completions(struct tcmu_dev *udev) { struct tcmu_mailbox *mb; @@ -1267,22 +1260,16 @@ static unsigned int tcmu_handle_completions(struct tcmu_dev *udev) handled++; } - if (mb->cmd_tail == mb->cmd_head) { - /* no more pending commands */ - del_timer(&udev->cmd_timer); - - if (list_empty(&udev->qfull_queue)) { - /* - * no more pending or waiting commands so try to - * reclaim blocks if needed. - */ - if (atomic_read(&global_db_count) > - tcmu_global_max_blocks) - schedule_delayed_work(&tcmu_unmap_work, 0); - } - } else if (udev->cmd_time_out) { - tcmu_set_next_deadline(&udev->inflight_queue, &udev->cmd_timer); + if (atomic_read(&global_db_count) > tcmu_global_max_blocks && + idr_is_empty(&udev->commands) && list_empty(&udev->qfull_queue)) { + /* + * Allocated blocks exceeded global block limit, currently no + * more pending or waiting commands so try to reclaim blocks. + */ + schedule_delayed_work(&tcmu_unmap_work, 0); } + if (udev->cmd_time_out) + tcmu_set_next_deadline(&udev->inflight_queue, &udev->cmd_timer); return handled; } @@ -1291,7 +1278,7 @@ static void tcmu_check_expired_ring_cmd(struct tcmu_cmd *cmd) { struct se_cmd *se_cmd; - if (!time_after(jiffies, cmd->deadline)) + if (!time_after_eq(jiffies, cmd->deadline)) return; set_bit(TCMU_CMD_BIT_EXPIRED, &cmd->flags); @@ -1310,7 +1297,7 @@ static void tcmu_check_expired_queue_cmd(struct tcmu_cmd *cmd) { struct se_cmd *se_cmd; - if (!time_after(jiffies, cmd->deadline)) + if (!time_after_eq(jiffies, cmd->deadline)) return; pr_debug("Timing out queued cmd %p on dev %s.\n", From patchwork Sun Jul 26 15:35:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bodo Stroesser X-Patchwork-Id: 11685951 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A1CA417C5 for ; Sun, 26 Jul 2020 15:36:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 83ECC20759 for ; Sun, 26 Jul 2020 15:36:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ts.fujitsu.com header.i=@ts.fujitsu.com header.b="obWYbZVC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727976AbgGZPgA (ORCPT ); Sun, 26 Jul 2020 11:36:00 -0400 Received: from mail1.bemta25.messagelabs.com ([195.245.230.65]:40336 "EHLO mail1.bemta25.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727939AbgGZPfx (ORCPT ); Sun, 26 Jul 2020 11:35:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ts.fujitsu.com; s=200619tsfj; t=1595777748; i=@ts.fujitsu.com; bh=I4n5Yal/ma5ywAUxz0gOPrNc0mxXygyPY1JRzOsStgI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=obWYbZVCZ9K3FGYYLXBg/RGqhUaJK0A9UPfU5+q9fHtL+tP/MJ/tM7To+Ba9wG62y ncUbkbZ+OvdUvHSiaP9LVRJxi82RjgBRSWzTbTwCQrV1Gg+Fv7idUmIdu/ids33yDn KtrvmRDeoA+HnoRon1sXDlgPTt25X1+KvvhTapgqPHgwYU0O27D8Xetu6uxfnXy/bn PDjZ65bu140bpKOgo19wRMuwctvyNznnoESN+VbBFnEiwIbLGSPAWiPuogu5btRxgT lpwFc7E+T+bCDSyZ9I024ru7DjHLUWZYuR3+w0KvemgmJ/ZM5g6NoBpNg5YkEyxCFY Vwnx1kpqg3Rpg== Received: from [100.112.199.31] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-1.bemta.az-b.eu-west-1.aws.symcld.net id 24/4F-01492-4D2AD1F5; Sun, 26 Jul 2020 15:35:48 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupgkeJIrShJLcpLzFFi42Kxs+EI0b28SDb e4PcRCYvu6zvYLJYf/8dk8XfSDVaL1qVvmRxYPD4+vcXi8XmTXABTFGtmXlJ+RQJrxpNJq9kK ujMqDr74zNLAOC2ii5GLQ0hgMqPEn6OLWCGc6YwSL68vZu9i5ORgEzCQWDHpPgtIQkRgDaPEy jvzmEESzAJ6EtP+rQMrEhbwlNi8+ygjiM0ioCqx8UwvG4jNK2An8e5NC1iNhIC8RMeBySwgNq eAvcTGuR/A5ggB1SzbdIB9AiP3AkaGVYwWSUWZ6RkluYmZObqGBga6hoZGuoaWFrqG5sZ6iVW 6SXqppbrlqcUluoZ6ieXFesWVuck5KXp5qSWbGIGBklJwbO0Oxp43H/QOMUpyMCmJ8hpMkY0X 4kvKT6nMSCzOiC8qzUktPsQow8GhJMF7dSFQTrAoNT21Ii0zBxi0MGkJDh4lEd45IGne4oLE3 OLMdIjUKUZdjs1zly5iFmLJy89LlRLn7QcpEgApyijNgxsBi6BLjLJSwryMDAwMQjwFqUW5mS Wo8q8YxTkYlYR5rUCm8GTmlcBtegV0BBPQEe6XJEGOKElESEk1MBWo8K6ZYiP1QDuZRXkjk11 JZNTZNNnvAt9frsuw+WLZVlex/VR30ft1cu96vMLso4XeS5m1J1+funNZhFTjmq65cZzGL/YL tM0PdTc2Cl0dsvnB7juca0wPp2+pWnwq7pHWNxMW+ZxN/fcvS8Zlbww9wHa0yG32y9dL2cMn/ 9y0Z5mWW7q60gfvzK9crxtc318/vKL1ZUHc3OgX5pevSP7WdzzfWnG2KOCrdTjjtJfPoljjV5 7f5W26bzbf7J6nO2ZPlGbn2FuTFruNqb/irVnWi/hHqYb7c6cGlvIYTPf/O79ikqZRi+tE6c7 CbpP3P2MPeVpNPWuvZ2Ox4faZFy5B0enCnpK+B1eEXItYo8RSnJFoqMVcVJwIAHsJw+8bAwAA X-Env-Sender: bstroesser@ts.fujitsu.com X-Msg-Ref: server-16.tower-291.messagelabs.com!1595777746!939733!1 X-Originating-IP: [62.60.8.84] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.50.2; banners=-,-,- X-VirusChecked: Checked Received: (qmail 26500 invoked from network); 26 Jul 2020 15:35:47 -0000 Received: from unknown (HELO mailhost3.uk.fujitsu.com) (62.60.8.84) by server-16.tower-291.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 26 Jul 2020 15:35:47 -0000 Received: from x-serv01 ([172.17.38.52]) by mailhost3.uk.fujitsu.com (8.14.5/8.14.5) with SMTP id 06QFZksN021578; Sun, 26 Jul 2020 16:35:46 +0100 Received: from VTC.emeia.fujitsu.local (unknown [172.17.38.7]) by x-serv01 (Postfix) with ESMTP id 5E7F22071F; Sun, 26 Jul 2020 17:35:37 +0200 (CEST) From: Bodo Stroesser To: "Martin K. Petersen" , Mike Christie , linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Cc: Bodo Stroesser Subject: [PATCH v3 7/8] scsi: target: tcmu: Implement tmr_notify callback Date: Sun, 26 Jul 2020 17:35:09 +0200 Message-Id: <20200726153510.13077-8-bstroesser@ts.fujitsu.com> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20200726153510.13077-1-bstroesser@ts.fujitsu.com> References: <20200726153510.13077-1-bstroesser@ts.fujitsu.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org This patch implements the tmr_notify callback for tcmu. When the callback is called, tcmu checks the list of aborted commands it received as parameter: - aborted commands in the qfull_queue are removed from the queue and target_complete_command is called - from the cmd_ids of aborted commands currently uncompleted in cmd ring it creates a list of aborted cmd_ids. Finally a TMR notification is written to cmd ring containing TMR type and cmd_id list. If there is no space in ring, the TMR notification is queued on a TMR specific queue. The TMR specific queue 'tmr_queue' can be seen as a extension of the cmd ring. At the end of each iexecution of tcmu_complete_commands() we check, whether tmr_queue contains TMRs and try to move them onto the ring. If tmr_queue is not empty after that, we don't call run_qfull_queue() because commands must not overtake TMRs. Operating that way we guarantee that cmd_ids in TMR notification received by userspace either match an active, not yet completed command or are no longer valid due to userspace having complete some cmd_ids meanwhile. New commands that were assigned to an aborted cmd_id will always appear on the cmd ring _after_ the TMR. Signed-off-by: Bodo Stroesser --- drivers/target/target_core_user.c | 225 ++++++++++++++++++++++++++++++++-- include/uapi/linux/target_core_user.h | 25 ++++ 2 files changed, 241 insertions(+), 9 deletions(-) diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c index bddd40f07929..cb5a561a46e8 100644 --- a/drivers/target/target_core_user.c +++ b/drivers/target/target_core_user.c @@ -137,6 +137,7 @@ struct tcmu_dev { struct mutex cmdr_lock; struct list_head qfull_queue; + struct list_head tmr_queue; uint32_t dbi_max; uint32_t dbi_thresh; @@ -183,6 +184,15 @@ struct tcmu_cmd { #define TCMU_CMD_BIT_EXPIRED 0 unsigned long flags; }; + +struct tcmu_tmr { + struct list_head queue_entry; + + uint8_t tmr_type; + uint32_t tmr_cmd_cnt; + int16_t tmr_cmd_ids[0]; +}; + /* * To avoid dead lock the mutex lock order should always be: * @@ -844,6 +854,9 @@ static bool is_ring_space_avail(struct tcmu_dev *udev, struct tcmu_cmd *cmd, return false; } + if (!data_needed) + return true; + /* try to check and get the data blocks as needed */ space = spc_bitmap_free(udev->data_bitmap, udev->dbi_thresh); if ((space * DATA_BLOCK_SIZE) < data_needed) { @@ -1106,6 +1119,60 @@ static int queue_cmd_ring(struct tcmu_cmd *tcmu_cmd, sense_reason_t *scsi_err) return 1; } +/** + * queue_tmr_ring - queue tmr info to ring or internally + * @udev: related tcmu_dev + * @tmr: tcmu_tmr containing tmr info to queue + * + * Returns: + * 0 success + * 1 internally queued to wait for ring memory to free. + */ +static int +queue_tmr_ring(struct tcmu_dev *udev, struct tcmu_tmr *tmr) +{ + struct tcmu_tmr_entry *entry; + int cmd_size; + int id_list_sz; + struct tcmu_mailbox *mb = udev->mb_addr; + uint32_t cmd_head; + + if (test_bit(TCMU_DEV_BIT_BROKEN, &udev->flags)) + goto out_free; + + id_list_sz = sizeof(tmr->tmr_cmd_ids[0]) * tmr->tmr_cmd_cnt; + cmd_size = round_up(sizeof(*entry) + id_list_sz, TCMU_OP_ALIGN_SIZE); + + if (!list_empty(&udev->tmr_queue) || + !is_ring_space_avail(udev, NULL, cmd_size, 0)) { + list_add_tail(&tmr->queue_entry, &udev->tmr_queue); + pr_debug("adding tmr %p on dev %s to TMR ring space wait queue\n", + tmr, udev->name); + return 1; + } + + cmd_head = ring_insert_padding(udev, cmd_size); + + entry = (void *)mb + CMDR_OFF + cmd_head; + memset(entry, 0, cmd_size); + tcmu_hdr_set_op(&entry->hdr.len_op, TCMU_OP_TMR); + tcmu_hdr_set_len(&entry->hdr.len_op, cmd_size); + entry->tmr_type = tmr->tmr_type; + entry->cmd_cnt = tmr->tmr_cmd_cnt; + memcpy(&entry->cmd_ids[0], &tmr->tmr_cmd_ids[0], id_list_sz); + tcmu_flush_dcache_range(entry, cmd_size); + + UPDATE_HEAD(mb->cmd_head, cmd_size, udev->cmdr_size); + tcmu_flush_dcache_range(mb, sizeof(*mb)); + + uio_event_notify(&udev->uio_info); + +out_free: + kfree(tmr); + + return 0; +} + static sense_reason_t tcmu_queue_cmd(struct se_cmd *se_cmd) { @@ -1141,6 +1208,85 @@ static void tcmu_set_next_deadline(struct list_head *queue, del_timer(timer); } +static int +tcmu_tmr_type(enum tcm_tmreq_table tmf) +{ + switch (tmf) { + case TMR_ABORT_TASK: return TCMU_TMR_ABORT_TASK; + case TMR_ABORT_TASK_SET: return TCMU_TMR_ABORT_TASK_SET; + case TMR_CLEAR_ACA: return TCMU_TMR_CLEAR_ACA; + case TMR_CLEAR_TASK_SET: return TCMU_TMR_CLEAR_TASK_SET; + case TMR_LUN_RESET: return TCMU_TMR_LUN_RESET; + case TMR_TARGET_WARM_RESET: return TCMU_TMR_TARGET_WARM_RESET; + case TMR_TARGET_COLD_RESET: return TCMU_TMR_TARGET_COLD_RESET; + case TMR_LUN_RESET_PRO: return TCMU_TMR_LUN_RESET_PRO; + default: return TCMU_TMR_UNKNOWN; + } +} + +static void +tcmu_tmr_notify(struct se_device *se_dev, enum tcm_tmreq_table tmf, + struct list_head *cmd_list) +{ + int i = 0, cmd_cnt = 0; + bool unqueued = false; + uint16_t *cmd_ids = NULL; + struct tcmu_cmd *cmd; + struct se_cmd *se_cmd; + struct tcmu_tmr *tmr; + struct tcmu_dev *udev = TCMU_DEV(se_dev); + + mutex_lock(&udev->cmdr_lock); + + /* First we check for aborted commands in qfull_queue */ + list_for_each_entry(se_cmd, cmd_list, state_list) { + i++; + if (!se_cmd->priv) + continue; + cmd = se_cmd->priv; + /* Commands on qfull queue have no id yet */ + if (cmd->cmd_id) { + cmd_cnt++; + continue; + } + pr_debug("Removing aborted command %p from queue on dev %s.\n", + cmd, udev->name); + + list_del_init(&cmd->queue_entry); + tcmu_free_cmd(cmd); + target_complete_cmd(se_cmd, SAM_STAT_TASK_ABORTED); + unqueued = true; + } + if (unqueued) + tcmu_set_next_deadline(&udev->qfull_queue, &udev->qfull_timer); + + pr_debug("TMR event %d on dev %s, aborted cmds %d, afflicted cmd_ids %d\n", + tcmu_tmr_type(tmf), udev->name, i, cmd_cnt); + + tmr = kmalloc(sizeof(*tmr) + cmd_cnt * sizeof(*cmd_ids), GFP_KERNEL); + if (!tmr) + goto unlock; + + tmr->tmr_type = tcmu_tmr_type(tmf); + tmr->tmr_cmd_cnt = cmd_cnt; + + if (cmd_cnt != 0) { + cmd_cnt = 0; + list_for_each_entry(se_cmd, cmd_list, state_list) { + if (!se_cmd->priv) + continue; + cmd = se_cmd->priv; + if (cmd->cmd_id) + tmr->tmr_cmd_ids[cmd_cnt++] = cmd->cmd_id; + } + } + + queue_tmr_ring(udev, tmr); + +unlock: + mutex_unlock(&udev->cmdr_lock); +} + static void tcmu_handle_completion(struct tcmu_cmd *cmd, struct tcmu_cmd_entry *entry) { struct se_cmd *se_cmd = cmd->se_cmd; @@ -1208,11 +1354,43 @@ static void tcmu_handle_completion(struct tcmu_cmd *cmd, struct tcmu_cmd_entry * tcmu_free_cmd(cmd); } +static int tcmu_run_tmr_queue(struct tcmu_dev *udev) +{ + struct tcmu_tmr *tmr, *tmp; + LIST_HEAD(tmrs); + + if (list_empty(&udev->tmr_queue)) + return 1; + + pr_debug("running %s's tmr queue\n", udev->name); + + list_splice_init(&udev->tmr_queue, &tmrs); + + list_for_each_entry_safe(tmr, tmp, &tmrs, queue_entry) { + list_del_init(&tmr->queue_entry); + + pr_debug("removing tmr %p on dev %s from queue\n", + tmr, udev->name); + + if (queue_tmr_ring(udev, tmr)) { + pr_debug("ran out of space during tmr queue run\n"); + /* + * tmr was requeued, so just put all tmrs back in + * the queue + */ + list_splice_tail(&tmrs, &udev->tmr_queue); + return 0; + } + } + + return 1; +} + static unsigned int tcmu_handle_completions(struct tcmu_dev *udev) { struct tcmu_mailbox *mb; struct tcmu_cmd *cmd; - int handled = 0; + bool free_space = false; if (test_bit(TCMU_DEV_BIT_BROKEN, &udev->flags)) { pr_err("ring broken, not handling completions\n"); @@ -1235,7 +1413,10 @@ static unsigned int tcmu_handle_completions(struct tcmu_dev *udev) tcmu_flush_dcache_range(entry, ring_left < sizeof(*entry) ? ring_left : sizeof(*entry)); - if (tcmu_hdr_get_op(entry->hdr.len_op) == TCMU_OP_PAD) { + free_space = true; + + if (tcmu_hdr_get_op(entry->hdr.len_op) == TCMU_OP_PAD || + tcmu_hdr_get_op(entry->hdr.len_op) == TCMU_OP_TMR) { UPDATE_HEAD(udev->cmdr_last_cleaned, tcmu_hdr_get_len(entry->hdr.len_op), udev->cmdr_size); @@ -1256,9 +1437,9 @@ static unsigned int tcmu_handle_completions(struct tcmu_dev *udev) UPDATE_HEAD(udev->cmdr_last_cleaned, tcmu_hdr_get_len(entry->hdr.len_op), udev->cmdr_size); - - handled++; } + if (free_space) + free_space = tcmu_run_tmr_queue(udev); if (atomic_read(&global_db_count) > tcmu_global_max_blocks && idr_is_empty(&udev->commands) && list_empty(&udev->qfull_queue)) { @@ -1271,7 +1452,7 @@ static unsigned int tcmu_handle_completions(struct tcmu_dev *udev) if (udev->cmd_time_out) tcmu_set_next_deadline(&udev->inflight_queue, &udev->cmd_timer); - return handled; + return free_space; } static void tcmu_check_expired_ring_cmd(struct tcmu_cmd *cmd) @@ -1381,6 +1562,7 @@ static struct se_device *tcmu_alloc_device(struct se_hba *hba, const char *name) INIT_LIST_HEAD(&udev->node); INIT_LIST_HEAD(&udev->timedout_entry); INIT_LIST_HEAD(&udev->qfull_queue); + INIT_LIST_HEAD(&udev->tmr_queue); INIT_LIST_HEAD(&udev->inflight_queue); idr_init(&udev->commands); @@ -1455,8 +1637,8 @@ static int tcmu_irqcontrol(struct uio_info *info, s32 irq_on) struct tcmu_dev *udev = container_of(info, struct tcmu_dev, uio_info); mutex_lock(&udev->cmdr_lock); - tcmu_handle_completions(udev); - run_qfull_queue(udev, false); + if (tcmu_handle_completions(udev)) + run_qfull_queue(udev, false); mutex_unlock(&udev->cmdr_lock); return 0; @@ -1609,6 +1791,16 @@ static void tcmu_blocks_release(struct radix_tree_root *blocks, } } +static void tcmu_remove_all_queued_tmr(struct tcmu_dev *udev) +{ + struct tcmu_tmr *tmr, *tmp; + + list_for_each_entry_safe(tmr, tmp, &udev->tmr_queue, queue_entry) { + list_del_init(&tmr->queue_entry); + kfree(tmr); + } +} + static void tcmu_dev_kref_release(struct kref *kref) { struct tcmu_dev *udev = container_of(kref, struct tcmu_dev, kref); @@ -1631,6 +1823,8 @@ static void tcmu_dev_kref_release(struct kref *kref) if (tcmu_check_and_free_pending_cmd(cmd) != 0) all_expired = false; } + /* There can be left over TMR cmds. Remove them. */ + tcmu_remove_all_queued_tmr(udev); if (!list_empty(&udev->qfull_queue)) all_expired = false; idr_destroy(&udev->commands); @@ -1885,7 +2079,9 @@ static int tcmu_configure_device(struct se_device *dev) /* Initialise the mailbox of the ring buffer */ mb = udev->mb_addr; mb->version = TCMU_MAILBOX_VERSION; - mb->flags = TCMU_MAILBOX_FLAG_CAP_OOOC | TCMU_MAILBOX_FLAG_CAP_READ_LEN; + mb->flags = TCMU_MAILBOX_FLAG_CAP_OOOC | + TCMU_MAILBOX_FLAG_CAP_READ_LEN | + TCMU_MAILBOX_FLAG_CAP_TMR; mb->cmdr_off = CMDR_OFF; mb->cmdr_size = udev->cmdr_size; @@ -2055,6 +2251,15 @@ static void tcmu_reset_ring(struct tcmu_dev *udev, u8 err_level) del_timer(&udev->cmd_timer); + /* + * ring is empty and qfull queue never contains aborted commands. + * So TMRs in tmr queue do not contain relevant cmd_ids. + * After a ring reset userspace should do a fresh start, so + * even LUN RESET message is no longer relevant. + * Therefore remove all TMRs from qfull queue + */ + tcmu_remove_all_queued_tmr(udev); + run_qfull_queue(udev, false); mutex_unlock(&udev->cmdr_lock); @@ -2607,6 +2812,7 @@ static struct target_backend_ops tcmu_ops = { .destroy_device = tcmu_destroy_device, .free_device = tcmu_free_device, .parse_cdb = tcmu_parse_cdb, + .tmr_notify = tcmu_tmr_notify, .set_configfs_dev_params = tcmu_set_configfs_dev_params, .show_configfs_dev_params = tcmu_show_configfs_dev_params, .get_device_type = sbc_get_device_type, @@ -2633,7 +2839,8 @@ static void find_free_blocks(void) } /* Try to complete the finished commands first */ - tcmu_handle_completions(udev); + if (tcmu_handle_completions(udev)) + run_qfull_queue(udev, false); /* Skip the udevs in idle */ if (!udev->dbi_thresh) { diff --git a/include/uapi/linux/target_core_user.h b/include/uapi/linux/target_core_user.h index b7b57967d90f..95b1597f16ae 100644 --- a/include/uapi/linux/target_core_user.h +++ b/include/uapi/linux/target_core_user.h @@ -45,6 +45,7 @@ #define ALIGN_SIZE 64 /* Should be enough for most CPUs */ #define TCMU_MAILBOX_FLAG_CAP_OOOC (1 << 0) /* Out-of-order completions */ #define TCMU_MAILBOX_FLAG_CAP_READ_LEN (1 << 1) /* Read data length */ +#define TCMU_MAILBOX_FLAG_CAP_TMR (1 << 2) /* TMR notifications */ struct tcmu_mailbox { __u16 version; @@ -62,6 +63,7 @@ struct tcmu_mailbox { enum tcmu_opcode { TCMU_OP_PAD = 0, TCMU_OP_CMD, + TCMU_OP_TMR, }; /* @@ -128,6 +130,29 @@ struct tcmu_cmd_entry { } __packed; +struct tcmu_tmr_entry { + struct tcmu_cmd_entry_hdr hdr; + +#define TCMU_TMR_UNKNOWN 0 +#define TCMU_TMR_ABORT_TASK 1 +#define TCMU_TMR_ABORT_TASK_SET 2 +#define TCMU_TMR_CLEAR_ACA 3 +#define TCMU_TMR_CLEAR_TASK_SET 4 +#define TCMU_TMR_LUN_RESET 5 +#define TCMU_TMR_TARGET_WARM_RESET 6 +#define TCMU_TMR_TARGET_COLD_RESET 7 +/* Pseudo reset due to received PR OUT */ +#define TCMU_TMR_LUN_RESET_PRO 128 + __u8 tmr_type; + + __u8 __pad1; + __u16 __pad2; + __u32 cmd_cnt; + __u64 __pad3; + __u64 __pad4; + __u16 cmd_ids[0]; +} __packed; + #define TCMU_OP_ALIGN_SIZE sizeof(__u64) enum tcmu_genl_cmd { From patchwork Sun Jul 26 15:35:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bodo Stroesser X-Patchwork-Id: 11685937 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 11EA617D5 for ; Sun, 26 Jul 2020 15:35:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ED90420759 for ; Sun, 26 Jul 2020 15:35:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ts.fujitsu.com header.i=@ts.fujitsu.com header.b="U1WUnzB7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726878AbgGZPfz (ORCPT ); Sun, 26 Jul 2020 11:35:55 -0400 Received: from mail1.bemta26.messagelabs.com ([85.158.142.112]:41720 "EHLO mail1.bemta26.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727905AbgGZPfw (ORCPT ); Sun, 26 Jul 2020 11:35:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ts.fujitsu.com; s=200619tsfj; t=1595777748; i=@ts.fujitsu.com; bh=RVa74JN/7E1sOtlG/xtrBRDEnUbmbOYmdPBQhTIohTc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=U1WUnzB72AnaqPqdMHxw88ON9q9oJM9gF4PSfz1GZtLp8dvfpmSrS37/GdFBqDneC GVkWDveo6F0olwBQKrPoPlFymSANmh5UMCpX1JQmpWyry9772vBTktYTT6zklnUSrU fyhZXs7DyI2i3URMlTEVM+yWq4ylNK6IstXEIIJ8FBSHuE3ZUkfrEh03wSep1EiDus MO8kkaLDmdd/2dxN1D5g0dUAwaSSRGSRAPvfmzO3XezSiJeN8Zwnv+UCEng0f8IqLz 5ooWxD6W4dt0aygNsBEWogWa/WC4psKsOAW3fCsp3R5CTTsjwnan7rnI27dJtXPV2d /7kodfftZNT0w== Received: from [100.113.7.116] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-1.bemta.az-b.eu-central-1.aws.symcld.net id 29/07-32390-3D2AD1F5; Sun, 26 Jul 2020 15:35:47 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrDLMWRWlGSWpSXmKPExsViZ8MRont5kWy 8wcKHEhbd13ewWSw//o/J4u+kG6wWrUvfMjmweHx8eovF4/MmuQCmKNbMvKT8igTWjPP//zEV /BGpmPn2AWMD4yyhLkYuDiGByYwSaz99ZIJwpjNKPJ09h7GLkZODTcBAYsWk+ywgCRGBNYwSK +/MYwZJMAvoSUz7t469i5GDQ1jAS+LUJVOQMIuAqsTCWU/YQGxeATuJ6Wu+soDYEgLyEh0HJo PZnAL2EhvnfgAbIwRUs2zTAfYJjNwLGBlWMVomFWWmZ5TkJmbm6BoaGOgaGhrrmusaGhnqJVb pJumlluomp+aVFCUCZfUSy4v1iitzk3NS9PJSSzYxAgMlpZC9cgfj2jcf9A4xSnIwKYnyGkyR jRfiS8pPqcxILM6ILyrNSS0+xCjDwaEkwXt1IVBOsCg1PbUiLTMHGLQwaQkOHiUR3jkgad7ig sTc4sx0iNQpRkUpcd5+kIQASCKjNA+uDRYplxhlpYR5GRkYGIR4ClKLcjNLUOVfMYpzMCoJ81 qBTOHJzCuBm/4KaDET0GL3S5Igi0sSEVJSDUze/dd38Hto8QdNK1/M6isceUjPRPOrnVz0pwq 9RfffGp1Y/IjhXric7K1Tp2qmLVByOT/ZpuRvSXvyAd0AezPm61NkV2wr9+uztz1RuYrxoWTv HMatAhLTHrbMdJ0keezOvpM6Z49tYkpb8Xi9Rkzc/J2trp0hZZ4z2oO4jR6ll19Z+emlnbj5n 0sHu/5Js1kkiHY+uWI58dYt86o72XNfrHdSPpLeedJNVuNC4ithDvfu9afD7Sry3y9VftbcHL pydmZ/nU9dne6OQ6mJ6wW0T8x3ev19Z/f59/sfSf2bm6W3oSXg7Gn+Bx+tFyjMNpVUb+99FmF vltB0dFWcXsd858fsp094CrP3/H3pG6fEUpyRaKjFXFScCACIPsLaDwMAAA== X-Env-Sender: bstroesser@ts.fujitsu.com X-Msg-Ref: server-17.tower-248.messagelabs.com!1595777746!197365!1 X-Originating-IP: [62.60.8.84] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.50.2; banners=-,-,- X-VirusChecked: Checked Received: (qmail 18185 invoked from network); 26 Jul 2020 15:35:47 -0000 Received: from unknown (HELO mailhost3.uk.fujitsu.com) (62.60.8.84) by server-17.tower-248.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 26 Jul 2020 15:35:47 -0000 Received: from x-serv01 ([172.17.38.52]) by mailhost3.uk.fujitsu.com (8.14.5/8.14.5) with SMTP id 06QFZkD6021579; Sun, 26 Jul 2020 16:35:46 +0100 Received: from VTC.emeia.fujitsu.local (unknown [172.17.38.7]) by x-serv01 (Postfix) with ESMTP id 6292020720; Sun, 26 Jul 2020 17:35:37 +0200 (CEST) From: Bodo Stroesser To: "Martin K. Petersen" , Mike Christie , linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Cc: Bodo Stroesser Subject: [PATCH v3 8/8] scsi: target: tcmu: Make TMR notification optional Date: Sun, 26 Jul 2020 17:35:10 +0200 Message-Id: <20200726153510.13077-9-bstroesser@ts.fujitsu.com> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20200726153510.13077-1-bstroesser@ts.fujitsu.com> References: <20200726153510.13077-1-bstroesser@ts.fujitsu.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add "tmr_notification" configFS attribute to tcmu devices. If default value 0 of the attribute is used, tcmu only removes aborted commands from qfull_queue. If user changes tmr_notification to 1, additionally TMR notifications will be written to the cmd ring. Signed-off-by: Bodo Stroesser --- drivers/target/target_core_user.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c index cb5a561a46e8..9b7592350502 100644 --- a/drivers/target/target_core_user.c +++ b/drivers/target/target_core_user.c @@ -118,6 +118,7 @@ struct tcmu_dev { #define TCMU_DEV_BIT_OPEN 0 #define TCMU_DEV_BIT_BROKEN 1 #define TCMU_DEV_BIT_BLOCKED 2 +#define TCMU_DEV_BIT_TMR_NOTIFY 3 unsigned long flags; struct uio_info uio_info; @@ -1260,6 +1261,9 @@ tcmu_tmr_notify(struct se_device *se_dev, enum tcm_tmreq_table tmf, if (unqueued) tcmu_set_next_deadline(&udev->qfull_queue, &udev->qfull_timer); + if (!test_bit(TCMU_DEV_BIT_TMR_NOTIFY, &udev->flags)) + goto unlock; + pr_debug("TMR event %d on dev %s, aborted cmds %d, afflicted cmd_ids %d\n", tcmu_tmr_type(tmf), udev->name, i, cmd_cnt); @@ -2706,6 +2710,39 @@ static ssize_t tcmu_emulate_write_cache_store(struct config_item *item, } CONFIGFS_ATTR(tcmu_, emulate_write_cache); +static ssize_t tcmu_tmr_notification_show(struct config_item *item, char *page) +{ + struct se_dev_attrib *da = container_of(to_config_group(item), + struct se_dev_attrib, da_group); + struct tcmu_dev *udev = TCMU_DEV(da->da_dev); + + return snprintf(page, PAGE_SIZE, "%i\n", + test_bit(TCMU_DEV_BIT_TMR_NOTIFY, &udev->flags)); +} + +static ssize_t tcmu_tmr_notification_store(struct config_item *item, + const char *page, size_t count) +{ + struct se_dev_attrib *da = container_of(to_config_group(item), + struct se_dev_attrib, da_group); + struct tcmu_dev *udev = TCMU_DEV(da->da_dev); + u8 val; + int ret; + + ret = kstrtou8(page, 0, &val); + if (ret < 0) + return ret; + if (val > 1) + return -EINVAL; + + if (val) + set_bit(TCMU_DEV_BIT_TMR_NOTIFY, &udev->flags); + else + clear_bit(TCMU_DEV_BIT_TMR_NOTIFY, &udev->flags); + return count; +} +CONFIGFS_ATTR(tcmu_, tmr_notification); + static ssize_t tcmu_block_dev_show(struct config_item *item, char *page) { struct se_device *se_dev = container_of(to_config_group(item), @@ -2787,6 +2824,7 @@ static struct configfs_attribute *tcmu_attrib_attrs[] = { &tcmu_attr_dev_config, &tcmu_attr_dev_size, &tcmu_attr_emulate_write_cache, + &tcmu_attr_tmr_notification, &tcmu_attr_nl_reply_supported, NULL, };