From patchwork Tue Jun 30 10:47:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bodo Stroesser X-Patchwork-Id: 213642 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63AC9C433E1 for ; Tue, 30 Jun 2020 10:47:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4264720780 for ; Tue, 30 Jun 2020 10:47:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ts.fujitsu.com header.i=@ts.fujitsu.com header.b="Au12siZ4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732656AbgF3Krt (ORCPT ); Tue, 30 Jun 2020 06:47:49 -0400 Received: from mail1.bemta26.messagelabs.com ([85.158.142.1]:39493 "EHLO mail1.bemta26.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732646AbgF3Kro (ORCPT ); Tue, 30 Jun 2020 06:47:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ts.fujitsu.com; s=200619tsfj; t=1593514060; i=@ts.fujitsu.com; bh=2Frq/UoMo2ZmRBbp04/5Qkl6kYBSP2A4sdzcLM8oql8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=Au12siZ4349DOc/1jbL71c0AY+J/NfEK4Dtt3ngk/jZ32Oica8Kg61cj4wtymLs0B DZOsclbFnswcfurRlk2U7/YnzFK35LkCoAJBhw9OB3lFkhPGyOeDxGUhQNBEghtar7 qeU9vZJLe+xdOZbLAj+bDjl9JJXBH0aT2J3DWaJ4jb/s1Y5nz7VIw0Ma6/zWPds34W ZPRmuRaqBQiZMz7eQwajqAuxLBjdgoqv7PrgsIclpvK8VRqjBt8yKxpCLQZ/A0Pnos UYlkjFJ45XrYPMQ2AnRCPd9Bgl7q9DGo/YsMx8btzq/wBReBNqY8ZhIRcb9wc9RE2x VwnxeVwO9HtYQ== Received: from [100.113.1.80] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-1.bemta.az-a.eu-central-1.aws.symcld.net id F3/E4-07993-C481BFE5; Tue, 30 Jun 2020 10:47:40 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrLLMWRWlGSWpSXmKPExsViZ8MRqusj8Tv O4EyfrEX39R1sFsuP/2Oy+DvpBqtF69K3TA4sHh+f3mLx+LxJLoApijUzLym/IoE1Y+OPxWwF v4QqHrZeYG1g3CrQxcjFISQwmVHi7fzn7BDOdEaJ2W8vsHUxcnKwCRhIrJh0nwUkISKwhlFi5 Z15zCAJZgE9iWn/1rGD2MICzhLf5t9jBLFZBFQl7hx6zQJi8wrYSRxZ8AmsXkJAXqLjwGSwOK eAvcTaw6fBbCGgmrWbZ7JNYORewMiwitEyqSgzPaMkNzEzR9fQwEDX0NBYF0gaG+glVukm6qW W6ian5pUUJQJl9RLLi/WKK3OTc1L08lJLNjECQyWlkKFpB+O7Vx/0DjFKcjApifLe+/crTogv KT+lMiOxOCO+qDQntfgQowwHh5IE71Px33FCgkWp6akVaZk5wLCFSUtw8CiJ8O4HSfMWFyTmF memQ6ROMSpKifOuFANKCIAkMkrz4NpgsXKJUVZKmJeRgYFBiKcgtSg3swRV/hWjOAejkjBvAs h4nsy8Erjpr4AWMwEtvqb1C2RxSSJCSqqBaZ3jy/MxLhtY9RPdDa/E2e7ni1n8Yi//yXWFAhf TGl61b3l32ON/kmPk/zRJ3+8ub3mdNz2aHLzjbUxM3tS2xdYLb97+XSqiyJHk/OuNo4gf14r2 NU9enYjLdps694Ha/hS1ui3165r52rY9WGnw9t/exIUXUz1rtqf1bNKamRo5M09yowmbTZb3t fOBH0VOFriy3hI3rzhzdGrZjqt9fx/VMTJzBxwsOlSmu3ifz9+7zLk38k6vfC+6YKLcj8fP32 zjzPBkn6DbnTUpMNLqQdfUrCDN+9dvfL0b+/3Xm7Cm+C0qlSV6Fu4KJkwZexSluzcnnl5to7v V7ehtV/vm59POR2fMn/t1WcHKhs6V/UosxRmJhlrMRcWJAIl4Z94QAwAA X-Env-Sender: bstroesser@ts.fujitsu.com X-Msg-Ref: server-32.tower-228.messagelabs.com!1593514059!1397082!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 7440 invoked from network); 30 Jun 2020 10:47:40 -0000 Received: from unknown (HELO mailhost4.uk.fujitsu.com) (62.60.8.85) by server-32.tower-228.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 30 Jun 2020 10:47:40 -0000 Received: from x-serv01 ([172.17.38.52]) by mailhost4.uk.fujitsu.com (8.14.5/8.14.5) with SMTP id 05UAlVgw003349; Tue, 30 Jun 2020 11:47:31 +0100 Received: from VTC.emeia.fujitsu.local (unknown [172.17.38.7]) by x-serv01 (Postfix) with ESMTP id 35A85205E2; Tue, 30 Jun 2020 12:47:27 +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: [RFC PATCH 1/8] scsi: target: Modify core_tmr_abort_task() Date: Tue, 30 Jun 2020 12:47:02 +0200 Message-Id: <20200630104709.23066-2-bstroesser@ts.fujitsu.com> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20200630104709.23066-1-bstroesser@ts.fujitsu.com> References: <20200630104709.23066-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..b65d7a0a5df1 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_irqsave(&se_sess->sess_cmd_lock, flags); + rc = __target_check_io_state(se_cmd, se_sess, 0); + spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); + 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 Tue Jun 30 10:47: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: 213645 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4205AC433DF for ; Tue, 30 Jun 2020 10:47:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 19D9120780 for ; Tue, 30 Jun 2020 10:47:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ts.fujitsu.com header.i=@ts.fujitsu.com header.b="HGkB7o5/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732640AbgF3Krk (ORCPT ); Tue, 30 Jun 2020 06:47:40 -0400 Received: from mail1.bemta25.messagelabs.com ([195.245.230.4]:12828 "EHLO mail1.bemta25.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732634AbgF3Krj (ORCPT ); Tue, 30 Jun 2020 06:47:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ts.fujitsu.com; s=200619tsfj; t=1593514056; i=@ts.fujitsu.com; bh=auLvn4X425miopBdp5iT9LE/FP7mM4u482ghwkUczNw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=HGkB7o5/q//VjsD613Z6k83RMBky/U6No3x5LQY8wifIDhmQetDJdw81FHAdNag2S xGMiEVL0G57cHiePdRf3PKX+Tp5pVgg3mrblmyccPiDJXT+of+zMaa+MbW2I5tKerd WFbtoc++gE8zRYpWH5zwEoVcepAS2/w+3NETVCcM5EgubR8r9XjyqL1MIK3qThdmEh ZaYNnqQn4fjAUYGMJKhK1LplgWen74LiRIfSOw23lPOiM3kl7s76Pn52I1l/6wYIjo 7Sfayy43hvq+0rf//X3m8pGiNs3EwNfBp7TTwohmAFth0s75mTDNnkuM/HdmRAR67m xhvGKQ4cIzkvA== 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 0E/9E-17694-8481BFE5; Tue, 30 Jun 2020 10:47:36 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrFLMWRWlGSWpSXmKPExsViZ8MxRddd4ne cwaeXNhbd13ewWSw//o/J4u+kG6wWrUvfMjmweHx8eovF4/MmuQCmKNbMvKT8igTWjOe37jIX HJSq6Fj3lqWB8YhYFyMXh5DAZEaJX/1XWCCc6YwSzx92MHcxcnKwCRhIrJh0HywhIrCGUWLln XlgCWYBPYlp/9axdzFycAgLhEncXWYKYrIIqEpseS4HUsErYCex4OlxNhBbQkBeouPAZBYQm1 PAXmLt4dNgthBQzdrNM9kmMHIvYGRYxWiRVJSZnlGSm5iZo2toYKBraGika2gJxCYmeolVuol 6qaW65anFJbqGeonlxXrFlbnJOSl6eaklmxiBQZJScGDCDsb9rz/oHWKU5GBSEuW99+9XnBBf Un5KZUZicUZ8UWlOavEhRhkODiUJ3nax33FCgkWp6akVaZk5wICFSUtw8CiJ8LYLAaV5iwsSc 4sz0yFSpxgVpcR5V4L0CYAkMkrz4NpgUXKJUVZKmJeRgYFBiKcgtSg3swRV/hWjOAejkjBvgj jQFJ7MvBK46a+AFjMBLb6m9QtkcUkiQkqqgSnFdJOXT/ms/IIq814J3dcq+Y/vvVC//a3t6Gn z55P6J8637Y18/WzZ29ZnPmU2yWc2bV1y9oHY85yPFxSnG8S9btZY/Dj049RtatM85Q3TT15e bvHtd9PFe9ZrZWewvf5yla17XqHPEuHnc07V1ypsMU2empu/0FNYeEVHKof3/+OOU76nqReyN OhUXOFe+17wdUb7xQOtUYpGP14U6BWzxBxa90Zs/52/HcXzrLNavOWSV9nv2pbZ4ef6/aetn4 yYm/dXnr37r0w5FBm+qfig5rFyr/oL/es1rtp8KWXh+6hpF+SdUl97ecWJG1+feNg1ZTWEhlv IaCdLf+X/qfPks9CULZcPMfev0fJ3vKbEUpyRaKjFXFScCACEXqmXDQMAAA== X-Env-Sender: bstroesser@ts.fujitsu.com X-Msg-Ref: server-14.tower-265.messagelabs.com!1593514055!1391470!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 23178 invoked from network); 30 Jun 2020 10:47:35 -0000 Received: from unknown (HELO mailhost1.uk.fujitsu.com) (62.60.8.148) by server-14.tower-265.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 30 Jun 2020 10:47:35 -0000 Received: from x-serv01 ([172.17.38.52]) by mailhost1.uk.fujitsu.com (8.14.5/8.14.5) with SMTP id 05UAlYsR025927; Tue, 30 Jun 2020 11:47:35 +0100 Received: from VTC.emeia.fujitsu.local (unknown [172.17.38.7]) by x-serv01 (Postfix) with ESMTP id 7861220954; Tue, 30 Jun 2020 12:47:32 +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: [RFC PATCH 5/8] scsi: target: tcmu: Factor out new helper ring_insert_padding Date: Tue, 30 Jun 2020 12:47:06 +0200 Message-Id: <20200630104709.23066-6-bstroesser@ts.fujitsu.com> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20200630104709.23066-1-bstroesser@ts.fujitsu.com> References: <20200630104709.23066-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 be95518a31dd..f10d8d182ed9 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 *dev, size_t cmd_size) +{ + struct tcmu_cmd_entry_hdr *hdr; + struct tcmu_mailbox *mb = dev->mb_addr; + uint32_t cmd_head = mb->cmd_head % dev->cmdr_size; /* UAM */ + + /* Insert a PAD if end-of-ring space is too small */ + if (head_to_end(cmd_head, dev->cmdr_size) < cmd_size) { + size_t pad_size = head_to_end(cmd_head, dev->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, dev->cmdr_size); + tcmu_flush_dcache_range(mb, sizeof(*mb)); + + cmd_head = mb->cmd_head % dev->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 Tue Jun 30 10:47: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: 213641 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ADECBC433E3 for ; Tue, 30 Jun 2020 10:47:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 83D7A207E8 for ; Tue, 30 Jun 2020 10:47: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="kZrVo/5i" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732660AbgF3Kru (ORCPT ); Tue, 30 Jun 2020 06:47:50 -0400 Received: from mail1.bemta26.messagelabs.com ([85.158.142.113]:15403 "EHLO mail1.bemta26.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732583AbgF3Krr (ORCPT ); Tue, 30 Jun 2020 06:47:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ts.fujitsu.com; s=200619tsfj; t=1593514060; i=@ts.fujitsu.com; bh=pYNo6yKo57bY/EY4E2BdwIp9O/+3AvXWNSsi/zzHTFg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=kZrVo/5i1YACpZU/NkIsnLPSS0X6MYaCXl7OcZ20iwIP3jRXotZoDqJrYJd95uu6v /UtTU/XEkgYtOVfpk6Eu3xV6hd3E/hiaJggoBifFohkVYd8mt72sU5U1jrTN8/yeoZ 3CSCVt8JYGCQmMKMFL4QlAj/cXeAFN0cK8/IhWab9Wjd7Kuy/9H1QAXgGkOxBFOQEx Y17Y7G/iU3moUf9BUKa+pjQze/rwhfHVrt+kkDS6b2wvgbf7pRyKXwErkhFR9EcYfe otxkp2aPlj38c9/WwnX2TYzi5ACRN+G43gMWaID23FHkJWhwRVQYfetQBM+V4JsVG/ O8lD/WzaoOxMw== Received: from [100.113.4.241] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-2.bemta.az-b.eu-central-1.aws.symcld.net id 30/2D-49188-C481BFE5; Tue, 30 Jun 2020 10:47:40 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrDLMWRWlGSWpSXmKPExsViZ8MxVddb4ne cwevbVhbd13ewWSw//o/J4u+kG6wWrUvfMjmweHx8eovF4/MmuQCmKNbMvKT8igTWjKdb37EV rFStePTlDFMD42H5LkZODiGByYwSu7YWdjFyAdnTGSWm/H/JBJJgEzCQWDHpPgtIQkRgDaPEy jvzmEESzAJ6EtP+rWMHsYUF/CS23HnECmKzCKhK7HrznQ3E5hWwk5jec4kFxJYQkJfoODAZzO YUsJdYe/g0C8RmO4m1m2eyTWDkXsDIsIrRMqkoMz2jJDcxM0fX0MBA19DQWNdU18jEUC+xSjd JL7VUNzk1r6QoESirl1herFdcmZuck6KXl1qyiREYKCmFrB93MB56/UHvEKMkB5OSKO+9f7/i hPiS8lMqMxKLM+KLSnNSiw8xynBwKEnwPhX/HSckWJSanlqRlpkDDFqYtAQHj5II736QNG9xQ WJucWY6ROoUo6KUOO9KMaCEAEgiozQPrg0WKZcYZaWEeRkZGBiEeApSi3IzS1DlXzGKczAqCf MmgIznycwrgZv+CmgxE9Dia1q/QBaXJCKkpBqY5t879Xvrjz01Wv4xSekfzTx9myQKf2V2mz5 Ubz16TrDg7L0V+jG/Ts2YdGmrxNIYvdNHjq/h6e9kXP16l4/g1i6bIPmd1+dueHhSUk7i+KNM 7fc8NzyU6l9bPuZbdE4k285QaA7D7MuidzyPMy9ar5Ejnn/uf+t3/fqlL6rrO9qkCxOC1G+md l6p2Jp3Oqnfe/MLvSNiKmwN/k4KcxsE5WIO1HQq3eM5ZyJx3N9Hgm39tl3dzpsTVlrdN53Zk3 b2iEryJ3XnPwGqy5SY937hstvMMffAyr/BS2bemTm1cF4jR5SRitpllxydjZs5i+fWVi3VqTu xb67f1qBpHdOK1x+4Fm2pxyG20ciMY4eKEktxRqKhFnNRcSIA8evLdQ8DAAA= X-Env-Sender: bstroesser@ts.fujitsu.com X-Msg-Ref: server-24.tower-238.messagelabs.com!1593514059!1349444!1 X-Originating-IP: [62.60.8.149] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.50.2; banners=-,-,- X-VirusChecked: Checked Received: (qmail 27593 invoked from network); 30 Jun 2020 10:47:39 -0000 Received: from unknown (HELO mailhost2.uk.fujitsu.com) (62.60.8.149) by server-24.tower-238.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 30 Jun 2020 10:47:39 -0000 Received: from x-serv01 ([172.17.38.52]) by mailhost2.uk.fujitsu.com (8.14.5/8.14.5) with SMTP id 05UAlYOx004488; Tue, 30 Jun 2020 11:47:35 +0100 Received: from VTC.emeia.fujitsu.local (unknown [172.17.38.7]) by x-serv01 (Postfix) with ESMTP id 77FEA20AD8; Tue, 30 Jun 2020 12:47:33 +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: [RFC PATCH 6/8] scsi: target: tcmu: Fix and simplify timeout handling Date: Tue, 30 Jun 2020 12:47:07 +0200 Message-Id: <20200630104709.23066-7-bstroesser@ts.fujitsu.com> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20200630104709.23066-1-bstroesser@ts.fujitsu.com> References: <20200630104709.23066-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 f10d8d182ed9..89f38355a2ab 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 Tue Jun 30 10:47: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: 213644 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 814A4C433E2 for ; Tue, 30 Jun 2020 10:47:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5EBB12065F for ; Tue, 30 Jun 2020 10:47:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ts.fujitsu.com header.i=@ts.fujitsu.com header.b="IjhHMDL7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732647AbgF3Krm (ORCPT ); Tue, 30 Jun 2020 06:47:42 -0400 Received: from mail1.bemta26.messagelabs.com ([85.158.142.4]:6067 "EHLO mail1.bemta26.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732635AbgF3Krj (ORCPT ); Tue, 30 Jun 2020 06:47:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ts.fujitsu.com; s=200619tsfj; t=1593514057; i=@ts.fujitsu.com; bh=GtsGqb8EjApcsskALx6PiG8OhUw/DlwarEoa/E44tAU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=IjhHMDL7/x+uIFud06b4n/kNDFziunr832czTHq2goLv64kMCTyT3IjDzGgbh5dto SXrvuUFoTYVSFD6y43NYhrQ7nZ5m8/5yYrQJQ82Y8Ns0iAis6Q5IJ+wh05d+NIDGq+ Zpkp/L4yWOidYO1sS89QppDDNQ4oFro88JZjGpMMerBFq8r15gpQ5nA1rjwh3IKBC1 2SKDl2eFY0uL6+9b9aW2sdPs538itSYfMpvs/cW+jek7aEjLL8sFp07g3+I0kLiezY /YnqODb0bDEmSgUyQNCPhHXA5290EEcHdq+PKZ5sR2klvmq4K2OIH06jluw7xGjPGU JNAOlUzWJPnlQ== Received: from [100.113.1.80] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-4.bemta.az-a.eu-central-1.aws.symcld.net id BE/F9-22706-8481BFE5; Tue, 30 Jun 2020 10:47:36 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrNLMWRWlGSWpSXmKPExsViZ8MxRddD4ne cwdVr2hbd13ewWSw//o/J4u+kG6wWrUvfMjmweHx8eovF4/MmuQCmKNbMvKT8igTWjI5vP9kL /otU3JlV0cA4WaiLkYtDSGAyo8SR+//YIZzpjBI3/x9l7WLk5GATMJBYMek+C0hCRGANo8TKO /OYQRLMAnoS0/6tYwexhQW8JU6/m8kEYrMIqErse3uGEcTmFbCTeDbpHViNhIC8RMeBySwgNq eAvcTaw6fBbCGgmrWbZ7JNYORewMiwitEiqSgzPaMkNzEzR9fQwEDX0NBY10jX1FAvsUo3US+ 1VDc5Na+kKBEoqZdYXqxXXJmbnJOil5dasokRGCYphUzGOxivvf6gd4hRkoNJSZT33r9fcUJ8 SfkplRmJxRnxRaU5qcWHGGU4OJQkeJ+K/44TEixKTU+tSMvMAYYsTFqCg0dJhHc/SJq3uCAxt zgzHSJ1ilFRSpx3pRhQQgAkkVGaB9cGi5NLjLJSwryMDAwMQjwFqUW5mSWo8q8YxTkYlYR5E0 DG82TmlcBNfwW0mAlo8TWtXyCLSxIRUlINTBbtT6oyzwnpfbdjvp669sVqfecfMxmXGkX9fc6 qdK1jyRLnXFaOB+8+39vs/Iqb4apNgXGrQuA0+ydMGv6eu0LPTzM8weTw/vi8PWwnbwd5zenk 6zzdNGGr5ZzTG2y9d7Lc3zWdcy7jF+4HjtXfNe0F/l1gXH5ULu64it1yJq38nJ/fN/NEJ4m/m vjspeAu9Qfhd7T7N/25sPHX1mkFEVKaPyflKShZe711O6nB5p6rKbfWPiaWZXl78c1zZh5/LE QjLEtelectnh8zSTnc906zSajp9s8bls16vNnubGiqqsCTlKBTSbuWeQv9OfVT42PUfEFdiV9 clz26fATtVJ6wWHf5R0T6ruvYv+mIkRJLcUaioRZzUXEiAHG1/JwOAwAA X-Env-Sender: bstroesser@ts.fujitsu.com X-Msg-Ref: server-5.tower-226.messagelabs.com!1593514056!1004467!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 14680 invoked from network); 30 Jun 2020 10:47:36 -0000 Received: from unknown (HELO mailhost1.uk.fujitsu.com) (62.60.8.148) by server-5.tower-226.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 30 Jun 2020 10:47:36 -0000 Received: from x-serv01 ([172.17.38.52]) by mailhost1.uk.fujitsu.com (8.14.5/8.14.5) with SMTP id 05UAlYsT025927; Tue, 30 Jun 2020 11:47:35 +0100 Received: from VTC.emeia.fujitsu.local (unknown [172.17.38.7]) by x-serv01 (Postfix) with ESMTP id 9D25820251; Tue, 30 Jun 2020 12:47:35 +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: [RFC PATCH 8/8] scsi: target: tcmu: Make TMR notification optional Date: Tue, 30 Jun 2020 12:47:09 +0200 Message-Id: <20200630104709.23066-9-bstroesser@ts.fujitsu.com> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20200630104709.23066-1-bstroesser@ts.fujitsu.com> References: <20200630104709.23066-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 | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c index 8d69cfa125b2..1082c5882dc6 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; @@ -1261,6 +1262,9 @@ tcmu_tmr_notify(struct se_device *se_dev, enum tcm_tmreq_table tmf, if (unqueued) tcmu_set_next_deadline(&dev->qfull_queue, &dev->qfull_timer); + if (!test_bit(TCMU_DEV_BIT_TMR_NOTIFY, &dev->flags)) + goto unlock; + pr_debug("TMR event %d on dev %s, aborted cmds %d, afflicted cmd_ids %d\n", tcmu_tmr_type(tmf), dev->name, i, cmd_cnt); @@ -2707,6 +2711,40 @@ 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 *dev = TCMU_DEV(da->da_dev); + + return snprintf(page, PAGE_SIZE, "%i\n", + test_bit(TCMU_DEV_BIT_TMR_NOTIFY, &dev->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 *dev = 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, &dev->flags); + else + clear_bit(TCMU_DEV_BIT_TMR_NOTIFY, &dev->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), @@ -2788,6 +2826,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, };