From patchwork Tue Nov 27 23:51:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10701631 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CC01F15A8 for ; Tue, 27 Nov 2018 23:52:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BBD7D2C967 for ; Tue, 27 Nov 2018 23:52:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B018A2C9D5; Tue, 27 Nov 2018 23:52:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 488FD2C9CC for ; Tue, 27 Nov 2018 23:52:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726354AbeK1KwD (ORCPT ); Wed, 28 Nov 2018 05:52:03 -0500 Received: from com-out001.mailprotect.be ([83.217.72.83]:60845 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726370AbeK1KwC (ORCPT ); Wed, 28 Nov 2018 05:52:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=khTYQJZUidADQSrRELiWl9iBWzy7w9jD7/phUCQNGps=; b=G2ehBMNTAtzk f6L/83q5LBHztc86qdoULalMPBiClGoKerugefGGWDx0zGj4vtgcX1g7yir3BPknjK0uBFUm+baZs ih1biyt3zufrcgugs+Zu5pdLAFP0Tef/Bz/Me7MB7R3rEfqSWHJO2ihwpIweThA5VzqL/8k9NW7oX kQ/Lpb+cDfEDr72GJ9aavEbSAcg8eUJMSg574th/FVwBSDbZhjc7DLmgX9s0HhKHV+NR8HQkShRai UbPgDAT3BtsJ6hM6O09JZyMzd9PGGLt2C0VsijUEibXVAYgAk+xwscJXpKbLt2lRW42xmPbY+4oaF 0E7WnQ60ynjJdRlmjxKuIQ==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gRn9R-0009yB-5v; Wed, 28 Nov 2018 00:52:21 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id 861D9C0511; Wed, 28 Nov 2018 00:52:16 +0100 (CET) From: Bart Van Assche To: "Martin K . Petersen" Cc: Christoph Hellwig , target-devel@vger.kernel.org, Bart Van Assche , David Disseldorp , Nicholas Bellinger , Mike Christie , Hannes Reinecke Subject: [PATCH v2 01/10] target/tcmu: Fix queue_cmd_ring() declaration Date: Tue, 27 Nov 2018 15:51:55 -0800 Message-Id: <20181127235204.186731-2-bvanassche@acm.org> X-Mailer: git-send-email 2.20.0.rc0.387.gc7a69e6b6c-goog In-Reply-To: <20181127235204.186731-1-bvanassche@acm.org> References: <20181127235204.186731-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: Combined (0.01) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5u9Vqlw/UeQ7ciKqBii8I6V602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTagCTS5H5Pie2sCQ3gGSzr06cM7U7xDGmYwNG93LVnxwxjk yGQYCd08t3lHobjxX/OigDGQOIiVUN5rGO3B5zfVpnsdsF0/474T9aStD4uEKVG9P9yTThxC66Ku Xb0HO3W8nbMwgkUuW83PKbk25YSnvgtxKKcMIJ7ptgUxRg53TuCt4QJNIvyoxb4710Nl6KAZZ+9r UkyLOOkgJ9eTXvOC4trOptRiSOXsXUvIrRE5GhLiTYWeQL1zmGv4EZML33RI2C8QBYsWIMCVBHpa 7Qj+JYN6Crh9DXUDEtWWsjsNUWDlGPaDR+Aes7asAZpVFyfMODodi5MLJiAvrVIiQFNhc8S+HKYI 1vbaqYoREZsvVKq8YZ9/SG1CqFB/T9oOuGkszjGcI+mbLJLuOAP016dVWgH88tf6uZ3Odz3W94Ik DCkIj7lUenMOpFxPb4a0gTxJECCYsMoByn2L5D4ESJJSPTtI2NWSXQ8+P45Rhlff/V8o9A8S4+tr vYumJM3atRPpj3GbeSYQbpjOFT4aGmRsFCWUldd4Zfx8AzM82qsIbx1/rxbQicf/5tMwo2bfwweZ +eEX1T91V5n3FsMEfdSIIO3fJ9DGWEJopzxygkVT7yk4xAm9D8KTeKJT7gNACPfxVynFIF3Xrs2K JHQMxL9Pga9lSGLsEntA55GTrob+bwU0pkWukw/5GtMnr6abkRmybh+RU5qiZ9xxcXIyXGew+Q6b sxuQVZm5U7pmBXbPvqqW2xg/HY4alqklDBtTqXGJI9CnVA3fjMGyg48sBVMwSw4LvlF4kd5XJtyi c4/Tu+J4YfXDApCFS5UnqSvzTBMZqJNdbvPaUyoCdu6Y7CHSkG34KkwBCHXe+q6DmHcPHOk5vhwe 3++KwtBF1xVh1/Dcv1JWvY1l1JlqgO5wFWhskgCIMo7V3eOzJJ/4nSzNzW4P2kDC4uGq3HDl7GPw DDt+pvlHhV6a5QjptwQBGybQnI83ChkUX8F6u4X0g9iAwvJfZx3lGs1VZ0iZG6egppXkjOrhVptJ 8gZRjxEnfx1IYQ/4lg9Ffvqg9IG0EE8tjDWZlB+G9Jc9fWekhCkYETsycmIe9DyBCzx4I5obgO+2 ucHiHFYFX/uMKqFwmrSG6vY4ocfmWv3Fe9Iziczdq+A= X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch does not change any functionality but avoids that sparse complains about the queue_cmd_ring() function and its callers. Fixes: 6fd0ce79724d ("tcmu: prep queue_cmd_ring to be used by unmap wq") Reviewed-by: David Disseldorp Cc: Nicholas Bellinger Cc: Mike Christie Cc: Christoph Hellwig Cc: Hannes Reinecke Signed-off-by: Bart Van Assche --- drivers/target/target_core_user.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c index 9cd404acdb82..1e6d24943565 100644 --- a/drivers/target/target_core_user.c +++ b/drivers/target/target_core_user.c @@ -958,7 +958,7 @@ static int add_to_cmdr_queue(struct tcmu_cmd *tcmu_cmd) * 0 success * 1 internally queued to wait for ring memory to free. */ -static sense_reason_t queue_cmd_ring(struct tcmu_cmd *tcmu_cmd, int *scsi_err) +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; From patchwork Tue Nov 27 23:51:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10701629 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 98F3C15A7 for ; Tue, 27 Nov 2018 23:52:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 89D922C967 for ; Tue, 27 Nov 2018 23:52:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7E50C2C9FB; Tue, 27 Nov 2018 23:52:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 15DDC2C967 for ; Tue, 27 Nov 2018 23:52:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726411AbeK1KwD (ORCPT ); Wed, 28 Nov 2018 05:52:03 -0500 Received: from com-out001.mailprotect.be ([83.217.72.83]:46657 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726354AbeK1KwC (ORCPT ); Wed, 28 Nov 2018 05:52:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=Q8njIXnRGutOgZnwMiOvJBH9gA1hmPiXK4aSoWA7yE0=; b=YXignuVrlx3u tIbycfNg+hZwVHE/tf65OGiGPn9EZqoM3K3ISkxvweibQAbqrqRn2gLMPkcA59yPFlJ+1X5RNaS6g 2v2rgW2m/ZlTCKehu5EEav+PHkK5b0uFYtpfO/1rvdKoTz0JRaXOZLpXhK62wBb7LxeIrobzwVHQv KGct9t2EuZ/scTDJzh8YvxrYZO5p1Ed510CbgT5pTQC32D6O37nAv4QwBA6aynQClszYQRV7Xb2EF VW5jRE4jQ53u3So36b01T4wEjT1a9KgB4RA2HdeK6S1CiKnLugQBJhmH6B1f8uouMH7iKtEFpywRS FHVSJZibOS0VqRO1vI0X3g==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gRn9S-0009yB-8U; Wed, 28 Nov 2018 00:52:22 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id E9D7AC03F9; Wed, 28 Nov 2018 00:52:18 +0100 (CET) From: Bart Van Assche To: "Martin K . Petersen" Cc: Christoph Hellwig , target-devel@vger.kernel.org, Bart Van Assche , David Disseldorp , Nicholas Bellinger , Mike Christie , Hannes Reinecke Subject: [PATCH v2 02/10] target/core: Use kvcalloc() instead of open-coding it Date: Tue, 27 Nov 2018 15:51:56 -0800 Message-Id: <20181127235204.186731-3-bvanassche@acm.org> X-Mailer: git-send-email 2.20.0.rc0.387.gc7a69e6b6c-goog In-Reply-To: <20181127235204.186731-1-bvanassche@acm.org> References: <20181127235204.186731-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: Combined (0.04) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5nh58zVqKtikRgYUAcxqA6d602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTagCTS5H5Pie2sCQ3gGSzr06cM7U7xDGmYwNG93LVnxwxjk yGQYCd08t3lHobjxX/OigDGQOIiVUN5rGO3B5zfVpnsdsF0/474T9aStD4uEKVG9P9yTThxC66Ku Xb0HO3W8nbMwgkUuW83PKbk25YSnvgtxKKcMIJ7ptgUxRg53TuCt4QJNIvyoxb4710Nl6KAZZ+9r UkyLOOkgJ9eTXvOC4trOptRiSOXsXUvIrRE5GtR2f9GQhcVj4nuKqgklPKxI2C8QBYsWIMCVBHpa 7Qj+JYN6Crh9DXUDEtWWsjsNUWDlGPaDR+Aes7asAZpVFyfMODodi5MLJiAvrVIiQFNhc8S+HKYI 1vbaqYoREZsvVKq8YZ9/SG1CqFB/T9oOuGkszjGcI+mbLJLuOAP016dVWgH88tf6uZ3Odz3W94Ik DCkIj7lUenMOpFxPb4a0gTxJECCYsMoByn2L5D4ESJJSPTtI2NWSXQ8+P45Rhlff/V8o9A8S4+tr vYumJM3atRPpj3GbeSYQbpjOFT4aGmRsFCWUldd4Zfx8AzM82qsIbx1/rxbQicf/5tMwo2bfwweZ +eEX1T91V5n3FsMEfdSIIO3fJ9DGWEJopzxygkVT7yk4xAm9D8KTeKJT7gNACPfxVynFIF3Xrs2K JHQMxL9Pga9lSGLsEntA55GTrob+bwU0pkWukw/5GtMnr6abkRnT2RWXS1Xw8VBOrRgbjZL3cXMc 5OuHzTuNGVkd3xcewqqW2xg/HY4alqklDBtTqXGJI9CnVA3fjMGyg48sBVMwSw4LvlF4kd5XJtyi c4/Tu+J4YfXDApCFS5UnqSvzTBMZqJNdbvPaUyoCdu6Y7CHSkG34KkwBCHXe+q6DmHcPHFmmrnkC qvF7gcLgF06v1HySINKAWNpZCnIiZo2FMLggkgCIMo7V3eOzJJ/4nSzNzW4P2kDC4uGq3HDl7GPw DDt+pvlHhV6a5QjptwQBGybQnI83ChkUX8F6u4X0g9iAwvJfZx3lGs1VZ0iZG6egppXkjOrhVptJ 8gZRjxEnfx1IYQ/4lg9Ffvqg9IG0EE8tjDWZlB+G9Jc9fWekhCkYETsycmIe9DyBCzx4I5obgO+2 ucHiHFYFX/uMKqFwmrSG6vY4ocfmWv3Fe9Iziczdq+A= X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch does not change any functionality. Note: the code that frees sess_cmd_map already uses kvfree() so that code does not need to be modified. Reviewed-by: David Disseldorp Cc: Nicholas Bellinger Cc: Mike Christie Cc: Christoph Hellwig Cc: Hannes Reinecke Signed-off-by: Bart Van Assche --- drivers/target/target_core_transport.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 2cfd61d62e97..d9e4b736312e 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -273,14 +273,11 @@ int transport_alloc_session_tags(struct se_session *se_sess, { int rc; - se_sess->sess_cmd_map = kcalloc(tag_size, tag_num, - GFP_KERNEL | __GFP_NOWARN | __GFP_RETRY_MAYFAIL); + se_sess->sess_cmd_map = kvcalloc(tag_size, tag_num, + GFP_KERNEL | __GFP_RETRY_MAYFAIL); if (!se_sess->sess_cmd_map) { - se_sess->sess_cmd_map = vzalloc(array_size(tag_size, tag_num)); - if (!se_sess->sess_cmd_map) { - pr_err("Unable to allocate se_sess->sess_cmd_map\n"); - return -ENOMEM; - } + pr_err("Unable to allocate se_sess->sess_cmd_map\n"); + return -ENOMEM; } rc = sbitmap_queue_init_node(&se_sess->sess_tag_pool, tag_num, -1, From patchwork Tue Nov 27 23:51:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10701633 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EF8F913BB for ; Tue, 27 Nov 2018 23:52:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DEF172C967 for ; Tue, 27 Nov 2018 23:52:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D304C2C9D5; Tue, 27 Nov 2018 23:52:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 56A142C967 for ; Tue, 27 Nov 2018 23:52:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726770AbeK1KwI (ORCPT ); Wed, 28 Nov 2018 05:52:08 -0500 Received: from com-out001.mailprotect.be ([83.217.72.83]:37107 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726370AbeK1KwH (ORCPT ); Wed, 28 Nov 2018 05:52:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=Swcy2cYErNU8CpB1PrDu9dwZbX6WDAwe8m7bPUXP3Zg=; b=uSDj3zJkNUsz B+D35FV7JJ8sCPnLrSTgqupq9U0B0+QaBanebvwgGMeV8T24WNdPshj7i1YESA8jvDVN0Pj5Loped cAd7PYdjtswxq/fYeQ6ksK5HOs1OXD19F6JhqwUgDTXKQMePxkG2gWlRpnEoZ2cPEQmL4hER35LT2 Ht6+voap4wgUi8Q221sK8E7JE2bxTha+Rt9S9Yqv6oRVkBFrl7oX5VdhTNsQzFmp054V7TQ5LMmIX saSaDC63e/fcFE31pGK4LYtc7v8dC+6IiNnyjHD8B8opfqsgfekSzrH68N2J0jPgbhXQTvOjHcUqu Iv7vu16qG608QBKw9JXcXw==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gRn9U-000A0F-8I; Wed, 28 Nov 2018 00:52:25 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id 8DE72C03F9; Wed, 28 Nov 2018 00:52:21 +0100 (CET) From: Bart Van Assche To: "Martin K . Petersen" Cc: Christoph Hellwig , target-devel@vger.kernel.org, Bart Van Assche , Nicholas Bellinger , Mike Christie , David Disseldorp , Hannes Reinecke Subject: [PATCH v2 03/10] target/core: Simplify transport_clear_lun_ref() Date: Tue, 27 Nov 2018 15:51:57 -0800 Message-Id: <20181127235204.186731-4-bvanassche@acm.org> X-Mailer: git-send-email 2.20.0.rc0.387.gc7a69e6b6c-goog In-Reply-To: <20181127235204.186731-1-bvanassche@acm.org> References: <20181127235204.186731-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: Combined (0.04) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5mor0YVb2OVbcJJPTAkmkZt602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTagCTS5H5Pie2sCQ3gGSzr06cM7U7xDGmYwNG93LVnxwxjk yGQYCd08t3lHobjxX/OigDGQOIiVUN5rGO3B5zfVpnsdsF0/474T9aStD4uEKVG9P9yTThxC66Ku Xb0HO3W8nbMwgkUuW83PKbk25YSnvgtxKKcMIJ7ptgUxRg53TuCt4QJNIvyoxb4710Nl6KAZZ+9r UkyLOOkgJ9eTXvOC4trOptRiSOXsXUvIrRE5Gm67jINC+YEE7xhwtpNGAXpI2C8QBYsWIMCVBHpa 7Qj+JYN6Crh9DXUDEtWWsjsNUWDlGPaDR+Aes7asAZpVFyfMODodi5MLJiAvrVIiQFNhc8S+HKYI 1vbaqYoREZsvVKq8YZ9/SG1CqFB/T9oOuGkszjGcI+mbLJLuOAP016dVWgH88tf6uZ3Odz3W94Ik DCkIj7lUenMOpFxPb4a0gTxJECCYsMoByn2L5D4ESJJSPTtI2NWSXQ8+P45Rhlff/V8o9A8S4+tr vYumJM3atRPpj3GbeSYQbpjOFT4aGmRsFCWUldd4Zfx8AzM82qsIbx1/rxbQicf/5tMwo2bfwweZ +eEX1T91V5n3FsMEfdSIIO3fJ9DGWEJopzxygkVT7yk4xAm9D8KTeKJT7gNACPfxVynFIF3Xrs2K JHQMxL9Pga9lSGLsEntA55GTrob+bwU0pkWukw/5GtMnr6abkRkpgkQUlPutI474zhMXQYPkD4he QHulQ78UyVYAqkOPE6qW2xg/HY4alqklDBtTqXGJI9CnVA3fjMGyg48sBVMwSw4LvlF4kd5XJtyi c4/Tu+J4YfXDApCFS5UnqSvzTBMZqJNdbvPaUyoCdu6Y7CHSkG34KkwBCHXe+q6DmHcPHDs1wsEZ jz0fAsM4x/JvNN8Bwvd7/eQYhrnXrwqCT+txkgCIMo7V3eOzJJ/4nSzNzW4P2kDC4uGq3HDl7GPw DDt+pvlHhV6a5QjptwQBGybQnI83ChkUX8F6u4X0g9iAwvJfZx3lGs1VZ0iZG6egppXkjOrhVptJ 8gZRjxEnfx1IYQ/4lg9Ffvqg9IG0EE8tjDWZlB+G9Jc9fWekhCkYETsycmIe9DyBCzx4I5obgO+2 ucHiHFYFX/uMKqFwmrSG6vY4ocfmWv3Fe9Iziczdq+A= X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Since transport_clear_lun_ref() already waits until the percpu-refcount .release() method is called, it is not necessary to wait first until percpu_ref_kill_and_confirm() has finished transitioning the refcount into atomic mode. Remove the code that waits for percpu_ref_kill_and_confirm() to complete and also the completion object that is used by that code. This patch does not change the behavior of the SCSI target code. Cc: Nicholas Bellinger Cc: Mike Christie Cc: Christoph Hellwig Cc: David Disseldorp Cc: Hannes Reinecke Signed-off-by: Bart Van Assche --- drivers/target/target_core_device.c | 1 - drivers/target/target_core_tpg.c | 1 - drivers/target/target_core_transport.c | 35 ++++---------------------- include/target/target_core_base.h | 1 - 4 files changed, 5 insertions(+), 33 deletions(-) diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c index 47b5ef153135..c6b1122ee097 100644 --- a/drivers/target/target_core_device.c +++ b/drivers/target/target_core_device.c @@ -822,7 +822,6 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name) xcopy_lun = &dev->xcopy_lun; rcu_assign_pointer(xcopy_lun->lun_se_dev, dev); - init_completion(&xcopy_lun->lun_ref_comp); init_completion(&xcopy_lun->lun_shutdown_comp); INIT_LIST_HEAD(&xcopy_lun->lun_deve_list); INIT_LIST_HEAD(&xcopy_lun->lun_dev_link); diff --git a/drivers/target/target_core_tpg.c b/drivers/target/target_core_tpg.c index 02e8a5d86658..0cfb9d7b31a3 100644 --- a/drivers/target/target_core_tpg.c +++ b/drivers/target/target_core_tpg.c @@ -577,7 +577,6 @@ struct se_lun *core_tpg_alloc_lun( } lun->unpacked_lun = unpacked_lun; atomic_set(&lun->lun_acl_count, 0); - init_completion(&lun->lun_ref_comp); init_completion(&lun->lun_shutdown_comp); INIT_LIST_HEAD(&lun->lun_deve_list); INIT_LIST_HEAD(&lun->lun_dev_link); diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index d9e4b736312e..3cd037558957 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -2911,38 +2911,13 @@ void target_wait_for_sess_cmds(struct se_session *se_sess) } EXPORT_SYMBOL(target_wait_for_sess_cmds); -static void target_lun_confirm(struct percpu_ref *ref) -{ - struct se_lun *lun = container_of(ref, struct se_lun, lun_ref); - - complete(&lun->lun_ref_comp); -} - +/* + * Prevent that new percpu_ref_tryget_live() calls succeed and wait until + * all references to the LUN have been released. Called during LUN shutdown. + */ void transport_clear_lun_ref(struct se_lun *lun) { - /* - * Mark the percpu-ref as DEAD, switch to atomic_t mode, drop - * the initial reference and schedule confirm kill to be - * executed after one full RCU grace period has completed. - */ - percpu_ref_kill_and_confirm(&lun->lun_ref, target_lun_confirm); - /* - * The first completion waits for percpu_ref_switch_to_atomic_rcu() - * to call target_lun_confirm after lun->lun_ref has been marked - * as __PERCPU_REF_DEAD on all CPUs, and switches to atomic_t - * mode so that percpu_ref_tryget_live() lookup of lun->lun_ref - * fails for all new incoming I/O. - */ - wait_for_completion(&lun->lun_ref_comp); - /* - * The second completion waits for percpu_ref_put_many() to - * invoke ->release() after lun->lun_ref has switched to - * atomic_t mode, and lun->lun_ref.count has reached zero. - * - * At this point all target-core lun->lun_ref references have - * been dropped via transport_lun_remove_cmd(), and it's safe - * to proceed with the remaining LUN shutdown. - */ + percpu_ref_kill(&lun->lun_ref); wait_for_completion(&lun->lun_shutdown_comp); } diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h index e3bdb0550a59..58a03a094257 100644 --- a/include/target/target_core_base.h +++ b/include/target/target_core_base.h @@ -731,7 +731,6 @@ struct se_lun { struct scsi_port_stats lun_stats; struct config_group lun_group; struct se_port_stat_grps port_stat_grps; - struct completion lun_ref_comp; struct completion lun_shutdown_comp; struct percpu_ref lun_ref; struct list_head lun_dev_link; From patchwork Tue Nov 27 23:51:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10701635 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 77AF415A7 for ; Tue, 27 Nov 2018 23:52:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 674752C967 for ; Tue, 27 Nov 2018 23:52:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5B5CC2C9D5; Tue, 27 Nov 2018 23:52:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B9672C967 for ; Tue, 27 Nov 2018 23:52:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726773AbeK1KwL (ORCPT ); Wed, 28 Nov 2018 05:52:11 -0500 Received: from com-out001.mailprotect.be ([83.217.72.83]:33203 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726370AbeK1KwL (ORCPT ); Wed, 28 Nov 2018 05:52:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=xo30/mZ/fgTNXSk+4g0iY9niS0+MmVC9CUBUHHfMWTU=; b=T7xPwmZ7mkyu YUDL+OryLtAxAWrmEUBBjaGEZaQrmQC8IN5JqO8+cBYTRxIOS/gAMWO12om2uVCrvzDg7J+uZYAFR 33Bw/y+OPG9YtnedmYK0Rk5o0hbkKKIPmf569ym58oVUPVG9JHjJLSketJkvsuXGlqPiNR5UNoh1z Vw7X2/kklrwyGYAoPz9/QAZNqeWbiKQHboiOaoYTansszAjt516UaIcrIjqkoFk9J2182JMSDMqwi bCQbH68VUMs4ldZ04DJZWF/eB7Jta+6itfT5K0sCLTm7DecngWPSDty2X2w2AT+Z+ptis6bBxMdx7 s2ab4lOx8z8Yj1+09fGzNg==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gRn9W-000A0F-Mi; Wed, 28 Nov 2018 00:52:26 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id 840ECC04BB; Wed, 28 Nov 2018 00:52:23 +0100 (CET) From: Bart Van Assche To: "Martin K . Petersen" Cc: Christoph Hellwig , target-devel@vger.kernel.org, Bart Van Assche , Nicholas Bellinger , Mike Christie , David Disseldorp , Hannes Reinecke Subject: [PATCH v2 04/10] target/core: Make sure that target_wait_for_sess_cmds() waits long enough Date: Tue, 27 Nov 2018 15:51:58 -0800 Message-Id: <20181127235204.186731-5-bvanassche@acm.org> X-Mailer: git-send-email 2.20.0.rc0.387.gc7a69e6b6c-goog In-Reply-To: <20181127235204.186731-1-bvanassche@acm.org> References: <20181127235204.186731-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: SB/global_tokens (0.00178204803706) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5v/iIviwYxYdF/sagmNWkoh602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTagCTS5H5Pie2sCQ3gGSzr06cM7U7xDGmYwNG93LVnxwxjk yGQYCd08t3lHobjxX/OigDGQOIiVUN5rGO3B5zfVpnsdsF0/474T9aStD4uEKVG9P9yTThxC66Ku Xb0HO3W8nbMwgkUuW83PKbk25YSnvgtxKKcMIJ7ptgUxRg53TuCt4QJNIvyoxb4710Nl6KAZZ+9r UkyLOOkgJ9eTXvOC4trOptRiSOXsXUvIrRE5GmsxU+wmouBr0dnEPgXyprVI2C8QBYsWIMCVBHpa 7Qj+JYN6Crh9DXUDEtWWsjsNUWDlGPaDR+Aes7asAZpVFyfMODodi5MLJiAvrVIiQFNhc8S+HKYI 1vbaqYoREZsvVKq8YZ9/SG1CqFB/T9oOuGkszjGcI+mbLJLuOAP016dVWgH88tf6uZ3Odz3W94Ik DCkIj7lUenMOpFxPb4a0gTxJECCYsMoByn2L5D4ESJJSPTtI2NWSXQ8+P45Rhlff/dnzpf4jUQPU su/un+Dgc451thv0hd9gZGlVL/SEDgzCn2QHoll2X5InL6dYibIoTL/MkTXVmMpAWIpXwTCeSh0y Myb8PasQ+c0C4IKe30H3UDH+6KBhyClAYMoUKs513yCv9TR+UxzLZWL8hwGBjhpUEpQA9BsGTyd9 ZPwtyPLKf1lID1iBLBCYtInCwWc7eVTGkXx1W/AJdj/iYTWr9z+VwEkOajFjFmqvkRWBM5AkiTtR +HnQyWqQe8Hpm/OGvZq30e6aHNF36RWZLKbFzPNfUqsUgOciGGUcMuG9HCBimKSOuMSxAdirM+Sx h6lCNBJ4/+uf5QH8Sat24Y/EeP90qxD5ZyDMvulM5hETbIS+UGszJ+li7JqcBmkxeyx+tXAusPyu ouDRKpAIOvjL/Zq6cBUeBhYc3R1dq9c7CA8r3Q/xlFvRIFwcPEwTojLrxtiEEpCtcWh35a9RQ/VT KzVIK7zBCZaWqBSFkpsp3Br8647lNwN4qOsSZg+fYhVZG191EemzZutM6S62m/Kt2a29tg70BJb3 HR3NbZv4gReBJXkVVPSc006zUgMG2KMDF/xcb3XRuJkRyiZZ6HPi7yzMODodi5MLJiAvrVIiQFNh KIIGqsHi8yYemObHrBMMHOTYQ/Lj3ueyyCegyQhvesx2PyW5cLuSbbpC1c/2zTYs X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A session must only be released after all code that accesses the session structure has finished. Make sure that this is the case by introducing a new command counter per session that is only decremented after the .release_cmd() callback has finished. This patch fixes the following crash: BUG: KASAN: use-after-free in do_raw_spin_lock+0x1c/0x130 Read of size 4 at addr ffff8801534b16e4 by task rmdir/14805 CPU: 16 PID: 14805 Comm: rmdir Not tainted 4.18.0-rc2-dbg+ #5 Call Trace: dump_stack+0xa4/0xf5 print_address_description+0x6f/0x270 kasan_report+0x241/0x360 __asan_load4+0x78/0x80 do_raw_spin_lock+0x1c/0x130 _raw_spin_lock_irqsave+0x52/0x60 srpt_set_ch_state+0x27/0x70 [ib_srpt] srpt_disconnect_ch+0x1b/0xc0 [ib_srpt] srpt_close_session+0xa8/0x260 [ib_srpt] target_shutdown_sessions+0x170/0x180 [target_core_mod] core_tpg_del_initiator_node_acl+0xf3/0x200 [target_core_mod] target_fabric_nacl_base_release+0x25/0x30 [target_core_mod] config_item_release+0x9c/0x110 [configfs] config_item_put+0x26/0x30 [configfs] configfs_rmdir+0x3b8/0x510 [configfs] vfs_rmdir+0xb3/0x1e0 do_rmdir+0x262/0x2c0 do_syscall_64+0x77/0x230 entry_SYSCALL_64_after_hwframe+0x49/0xbe Cc: Nicholas Bellinger Cc: Mike Christie Cc: Christoph Hellwig Cc: David Disseldorp Cc: Hannes Reinecke Signed-off-by: Bart Van Assche --- drivers/target/target_core_transport.c | 35 ++++++++++++++++++-------- drivers/target/target_core_xcopy.c | 6 ++++- include/target/target_core_base.h | 1 + include/target/target_core_fabric.h | 2 +- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 3cd037558957..f429eece950b 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -224,19 +224,28 @@ void transport_subsystem_check_init(void) sub_api_initialized = 1; } +static void target_release_sess_cmd_refcnt(struct percpu_ref *ref) +{ + struct se_session *sess = container_of(ref, typeof(*sess), cmd_count); + + wake_up(&sess->cmd_list_wq); +} + /** * transport_init_session - initialize a session object * @se_sess: Session object pointer. * * The caller must have zero-initialized @se_sess before calling this function. */ -void transport_init_session(struct se_session *se_sess) +int transport_init_session(struct se_session *se_sess) { INIT_LIST_HEAD(&se_sess->sess_list); INIT_LIST_HEAD(&se_sess->sess_acl_list); INIT_LIST_HEAD(&se_sess->sess_cmd_list); spin_lock_init(&se_sess->sess_cmd_lock); init_waitqueue_head(&se_sess->cmd_list_wq); + return percpu_ref_init(&se_sess->cmd_count, + target_release_sess_cmd_refcnt, 0, GFP_KERNEL); } EXPORT_SYMBOL(transport_init_session); @@ -247,6 +256,7 @@ EXPORT_SYMBOL(transport_init_session); struct se_session *transport_alloc_session(enum target_prot_op sup_prot_ops) { struct se_session *se_sess; + int ret; se_sess = kmem_cache_zalloc(se_sess_cache, GFP_KERNEL); if (!se_sess) { @@ -254,7 +264,11 @@ struct se_session *transport_alloc_session(enum target_prot_op sup_prot_ops) " se_sess_cache\n"); return ERR_PTR(-ENOMEM); } - transport_init_session(se_sess); + ret = transport_init_session(se_sess); + if (ret < 0) { + kfree(se_sess); + return ERR_PTR(ret); + } se_sess->sup_prot_ops = sup_prot_ops; return se_sess; @@ -578,6 +592,7 @@ void transport_free_session(struct se_session *se_sess) sbitmap_queue_free(&se_sess->sess_tag_pool); kvfree(se_sess->sess_cmd_map); } + percpu_ref_exit(&se_sess->cmd_count); kmem_cache_free(se_sess_cache, se_sess); } EXPORT_SYMBOL(transport_free_session); @@ -2716,6 +2731,7 @@ int target_get_sess_cmd(struct se_cmd *se_cmd, bool ack_kref) } se_cmd->transport_state |= CMD_T_PRE_EXECUTE; list_add_tail(&se_cmd->se_cmd_list, &se_sess->sess_cmd_list); + percpu_ref_get(&se_sess->cmd_count); out: spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); @@ -2746,8 +2762,6 @@ static void target_release_cmd_kref(struct kref *kref) if (se_sess) { spin_lock_irqsave(&se_sess->sess_cmd_lock, flags); list_del_init(&se_cmd->se_cmd_list); - if (se_sess->sess_tearing_down && list_empty(&se_sess->sess_cmd_list)) - wake_up(&se_sess->cmd_list_wq); spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); } @@ -2755,6 +2769,8 @@ static void target_release_cmd_kref(struct kref *kref) se_cmd->se_tfo->release_cmd(se_cmd); if (compl) complete(compl); + + percpu_ref_put(&se_sess->cmd_count); } /** @@ -2883,6 +2899,8 @@ void target_sess_cmd_list_set_waiting(struct se_session *se_sess) spin_lock_irqsave(&se_sess->sess_cmd_lock, flags); se_sess->sess_tearing_down = 1; spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); + + percpu_ref_kill(&se_sess->cmd_count); } EXPORT_SYMBOL(target_sess_cmd_list_set_waiting); @@ -2897,17 +2915,14 @@ void target_wait_for_sess_cmds(struct se_session *se_sess) WARN_ON_ONCE(!se_sess->sess_tearing_down); - spin_lock_irq(&se_sess->sess_cmd_lock); do { - ret = wait_event_lock_irq_timeout( - se_sess->cmd_list_wq, - list_empty(&se_sess->sess_cmd_list), - se_sess->sess_cmd_lock, 180 * HZ); + ret = wait_event_timeout(se_sess->cmd_list_wq, + percpu_ref_is_zero(&se_sess->cmd_count), + 180 * HZ); list_for_each_entry(cmd, &se_sess->sess_cmd_list, se_cmd_list) target_show_cmd("session shutdown: still waiting for ", cmd); } while (ret <= 0); - spin_unlock_irq(&se_sess->sess_cmd_lock); } EXPORT_SYMBOL(target_wait_for_sess_cmds); diff --git a/drivers/target/target_core_xcopy.c b/drivers/target/target_core_xcopy.c index 70adcfdca8d1..124495f953fa 100644 --- a/drivers/target/target_core_xcopy.c +++ b/drivers/target/target_core_xcopy.c @@ -479,6 +479,8 @@ static const struct target_core_fabric_ops xcopy_pt_tfo = { int target_xcopy_setup_pt(void) { + int ret; + xcopy_wq = alloc_workqueue("xcopy_wq", WQ_MEM_RECLAIM, 0); if (!xcopy_wq) { pr_err("Unable to allocate xcopy_wq\n"); @@ -496,7 +498,9 @@ int target_xcopy_setup_pt(void) INIT_LIST_HEAD(&xcopy_pt_nacl.acl_list); INIT_LIST_HEAD(&xcopy_pt_nacl.acl_sess_list); memset(&xcopy_pt_sess, 0, sizeof(struct se_session)); - transport_init_session(&xcopy_pt_sess); + ret = transport_init_session(&xcopy_pt_sess); + if (ret < 0) + return ret; xcopy_pt_nacl.se_tpg = &xcopy_pt_tpg; xcopy_pt_nacl.nacl_sess = &xcopy_pt_sess; diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h index 58a03a094257..067da330ed9c 100644 --- a/include/target/target_core_base.h +++ b/include/target/target_core_base.h @@ -601,6 +601,7 @@ struct se_session { struct se_node_acl *se_node_acl; struct se_portal_group *se_tpg; void *fabric_sess_ptr; + struct percpu_ref cmd_count; struct list_head sess_list; struct list_head sess_acl_list; struct list_head sess_cmd_list; diff --git a/include/target/target_core_fabric.h b/include/target/target_core_fabric.h index f4147b398431..eb9d0923c55c 100644 --- a/include/target/target_core_fabric.h +++ b/include/target/target_core_fabric.h @@ -116,7 +116,7 @@ struct se_session *target_setup_session(struct se_portal_group *, struct se_session *, void *)); void target_remove_session(struct se_session *); -void transport_init_session(struct se_session *); +int transport_init_session(struct se_session *se_sess); struct se_session *transport_alloc_session(enum target_prot_op); int transport_alloc_session_tags(struct se_session *, unsigned int, unsigned int); From patchwork Tue Nov 27 23:51:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10701637 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B750A13BB for ; Tue, 27 Nov 2018 23:52:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A7BAE2C967 for ; Tue, 27 Nov 2018 23:52:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9C0812C9D5; Tue, 27 Nov 2018 23:52:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1EDD62C967 for ; Tue, 27 Nov 2018 23:52:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726659AbeK1KwO (ORCPT ); Wed, 28 Nov 2018 05:52:14 -0500 Received: from com-out001.mailprotect.be ([83.217.72.83]:42213 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726370AbeK1KwN (ORCPT ); Wed, 28 Nov 2018 05:52:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=CIW4ca3J7tThMZAt5DVTaHtq1JHj3x1aBYzBVt8qX08=; b=o7DjLxB434+L 6P31iyyVULHGCN87pF7LiEwSAb7ZZP0Eg6AwfcZ4ukbQ2VqL4HN4bBfTSLXktPf8k7GeZ5fTK2awi TSNDUCIfvlwHMnHzOAxgm5tpA3qgDpRJPZgA6KsSg41z1cUeqYGoeAE7o7J5IYIHt2CJRTAD92X+A EN253ECLpGGKVZdRryu4zNbEBs46NOKM52epYdHBG4vC9Ww3M4u76kKC9gvT75cFTYFgxyDT9rt/F BaioTUjFX4zkCMVeBp2RFzZ348OHE05JVR79wb0n3M08B7uUzLrNLHohuRNpikRuiVYRGJTCXo7ov uwveXDuCHsPMt6wHe3VWEw==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gRn9a-000A1p-TB; Wed, 28 Nov 2018 00:52:31 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id 04BD2C03F9; Wed, 28 Nov 2018 00:52:25 +0100 (CET) From: Bart Van Assche To: "Martin K . Petersen" Cc: Christoph Hellwig , target-devel@vger.kernel.org, Bart Van Assche , Nicholas Bellinger , Mike Christie , David Disseldorp , Hannes Reinecke Subject: [PATCH v2 05/10] target/core: Use system workqueues for TMF Date: Tue, 27 Nov 2018 15:51:59 -0800 Message-Id: <20181127235204.186731-6-bvanassche@acm.org> X-Mailer: git-send-email 2.20.0.rc0.387.gc7a69e6b6c-goog In-Reply-To: <20181127235204.186731-1-bvanassche@acm.org> References: <20181127235204.186731-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: Combined (0.01) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5hABmM3gea5gOSz7nWl1cMd602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTagCTS5H5Pie2sCQ3gGSzr06cM7U7xDGmYwNG93LVnxwxjk yGQYCd08t3lHobjxX/OigDGQOIiVUN5rGO3B5zfVpnsdsF0/474T9aStD4uEKVG9P9yTThxC66Ku Xb0HO3W8nbMwgkUuW83PKbk25YSnvgtxKKcMIJ7ptgUxRg53TuCt4QJNIvyoxb4710Nl6KAZZ+9r UkyLOOkgJ9eTXvOC4trOptRiSOXsXUvIrRE5GvvvWJBNmCbFjwnxFiK3wvBI2C8QBYsWIMCVBHpa 7Qj+JYN6Crh9DXUDEtWWsjsNUWDlGPaDR+Aes7asAZpVFyfMODodi5MLJiAvrVIiQFNhc8S+HKYI 1vbaqYoREZsvVKq8YZ9/SG1CqFB/T9oOuGkszjGcI+mbLJLuOAP016dVWgH88tf6uZ3Odz3W94Ik DCkIj7lUenMOpFxPb4a0gTxJECCYsMoByn2L5D4ESJJSPTtI2NWSXQ8+P45Rhlff/V8o9A8S4+tr vYumJM3atRPpj3GbeSYQbpjOFT4aGmRsFCWUldd4Zfx8AzM82qsIbx1/rxbQicf/5tMwo2bfwweZ +eEX1T91V5n3FsMEfdSIIO3fJ9DGWEJopzxygkVT7yk4xAm9D8KTeKJT7gNACPfxVynFIF3Xrs2K JHQMxL9Pga9lSGLsEntA55GTrob+bwU0pkWukw/5GtMnr6abkRnGole9t63Xd7+C0fxeF9o+LOCQ TrSFM7snLE/cSYe0laqW2xg/HY4alqklDBtTqXGJI9CnVA3fjMGyg48sBVMwSw4LvlF4kd5XJtyi c4/Tu+J4YfXDApCFS5UnqSvzTBMZqJNdbvPaUyoCdu6Y7CHSkG34KkwBCHXe+q6DmHcPHCOANQpD Nj3hyAWLG/mWh9UtJEE8oUMEuPfGxBbNSZrpkgCIMo7V3eOzJJ/4nSzNzW4P2kDC4uGq3HDl7GPw DDt+pvlHhV6a5QjptwQBGybQnI83ChkUX8F6u4X0g9iAwvJfZx3lGs1VZ0iZG6egppXkjOrhVptJ 8gZRjxEnfx1IYQ/4lg9Ffvqg9IG0EE8tjDWZlB+G9Jc9fWekhCkYETsycmIe9DyBCzx4I5obgO+2 ucHiHFYFX/uMKqFwmrSG6vY4ocfmWv3Fe9Iziczdq+A= X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A quote from SAM-5: "The order in which task management requests are processed is not specified by the SCSI architecture model. The SCSI architecture model does not require in-order delivery of such task management requests or processing by the task manager in the order received. To guarantee the processing order of task management requests referencing sent to a specific logical unit, an application client should not have more than one such task management request pending to that logical unit." This means that it is safe to use the system workqueues instead of tmr_wq for processing TMFs. An intended side effect of this patch is that it enables concurrent processing of TMFs. Reviewed-by: Christoph Hellwig Cc: Nicholas Bellinger Cc: Mike Christie Cc: David Disseldorp Cc: Hannes Reinecke Signed-off-by: Bart Van Assche --- drivers/target/target_core_device.c | 16 ---------------- drivers/target/target_core_transport.c | 2 +- include/target/target_core_base.h | 1 - 3 files changed, 1 insertion(+), 18 deletions(-) diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c index c6b1122ee097..d452d2059946 100644 --- a/drivers/target/target_core_device.c +++ b/drivers/target/target_core_device.c @@ -985,18 +985,6 @@ int target_configure_device(struct se_device *dev) if (ret) goto out_destroy_device; - /* - * Startup the struct se_device processing thread - */ - dev->tmr_wq = alloc_workqueue("tmr-%s", WQ_MEM_RECLAIM | WQ_UNBOUND, 1, - dev->transport->name); - if (!dev->tmr_wq) { - pr_err("Unable to create tmr workqueue for %s\n", - dev->transport->name); - ret = -ENOMEM; - goto out_free_alua; - } - /* * Setup work_queue for QUEUE_FULL */ @@ -1025,8 +1013,6 @@ int target_configure_device(struct se_device *dev) return 0; -out_free_alua: - core_alua_free_lu_gp_mem(dev); out_destroy_device: dev->transport->destroy_device(dev); out_free_index: @@ -1045,8 +1031,6 @@ void target_free_device(struct se_device *dev) WARN_ON(!list_empty(&dev->dev_sep_list)); if (target_dev_configured(dev)) { - destroy_workqueue(dev->tmr_wq); - dev->transport->destroy_device(dev); mutex_lock(&device_mutex); diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index f429eece950b..eab5fa2248af 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -3412,7 +3412,7 @@ int transport_generic_handle_tmr( } INIT_WORK(&cmd->work, target_tmr_work); - queue_work(cmd->se_dev->tmr_wq, &cmd->work); + schedule_work(&cmd->work); return 0; } EXPORT_SYMBOL(transport_generic_handle_tmr); diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h index 067da330ed9c..67130841d421 100644 --- a/include/target/target_core_base.h +++ b/include/target/target_core_base.h @@ -794,7 +794,6 @@ struct se_device { struct t10_pr_registration *dev_pr_res_holder; struct list_head dev_sep_list; struct list_head dev_tmr_list; - struct workqueue_struct *tmr_wq; struct work_struct qf_work_queue; struct list_head delayed_cmd_list; struct list_head state_list; From patchwork Tue Nov 27 23:52:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10701639 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D6EAC13BB for ; Tue, 27 Nov 2018 23:52:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C3D352C967 for ; Tue, 27 Nov 2018 23:52:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B82A22C9D5; Tue, 27 Nov 2018 23:52:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 501232C967 for ; Tue, 27 Nov 2018 23:52:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726636AbeK1KwR (ORCPT ); Wed, 28 Nov 2018 05:52:17 -0500 Received: from out002.mailprotect.be ([83.217.72.86]:41709 "EHLO out002.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726370AbeK1KwR (ORCPT ); Wed, 28 Nov 2018 05:52:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=y2ypL7ieLiki8o2nXq+1lwB+0bCu7/oN9uz/SAygcrU=; b=NRmPhwwX0YpB O7CecEp+F1GoqZfU8ALoZcFdLwXuaZ4zpZ3EyjSgqvKovDSa7zg4fZuJEXPsarPc3/mLNUmn+VuW3 dwv6ft4WN7oE/7OqbqjTwhcFD6kNI9GFPgy46nitOrHPJuZSPP/BXT/rQSXylC8znlf0y6ZPvuq+s H4GxI7y+ShbCAHtYg6/Zz68MRTvsu5OCqMUmIID5U1gLrjlQmen6Dxn9jVVZXPKhGiSr1OuG36dN1 Gai0DKuz3BkG2gzOlsWhRM+HKPb7aAWItxeCm29Pq5NJIulRu/X+Bexhf/lpV5hFYPJFsc0XyRW/3 poxtyVen9aKvLCNCRssP3Q==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out002.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gRn9f-000H19-0t; Wed, 28 Nov 2018 00:52:36 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id 3977FC0504; Wed, 28 Nov 2018 00:52:30 +0100 (CET) From: Bart Van Assche To: "Martin K . Petersen" Cc: Christoph Hellwig , target-devel@vger.kernel.org, Bart Van Assche , Nicholas Bellinger , Mike Christie , David Disseldorp , Hannes Reinecke Subject: [PATCH v2 06/10] target/core: Make it possible to wait from more than one context for command completion Date: Tue, 27 Nov 2018 15:52:00 -0800 Message-Id: <20181127235204.186731-7-bvanassche@acm.org> X-Mailer: git-send-email 2.20.0.rc0.387.gc7a69e6b6c-goog In-Reply-To: <20181127235204.186731-1-bvanassche@acm.org> References: <20181127235204.186731-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: Combined (0.02) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5lq6OSk6IqYvYquldXUJab1602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTagCTS5H5Pie2sCQ3gGSzr06cM7U7xDGmYwNG93LVnxwxjk yGQYCd08t3lHobjxX/OigDGQOIiVUN5rGO3B5zfVpnsdsF0/474T9aStD4uEKVG9P9yTThxC66Ku Xb0HO3W8nbMwgkUuW83PKbk25YSnvgtxKKcMIJ7ptgUxRg53TuCt4QJNIvyoxb4710Nl6KAZZ+9r UkyLOOkgJ9eTXvOC4trOptRiSOXsXUvIrRE5Gl0wsTSpb6iistmx0RkrHp9I2C8QBYsWIMCVBHpa 7Qj+JYN6Crh9DXUDEtWWsjsNUfobM/P6vznYRdd5hfgiYzLMODodi5MLJiAvrVIiQFNhc8S+HKYI 1vbaqYoREZsvVKq8YZ9/SG1CqFB/T9oOuGkszjGcI+mbLJLuOAP016dVWgH88tf6uZ3Odz3W94Ik DCkIj7lUenMOpFxPb4a0gTxJECCYsMoByn2L5D4ESJJSPTtI2NWSXQ8+P45Rhlff/V8o9A8S4+tr vYumJM3atRPpj3GbeSYQbpjOFT4aGmRsFCWUldd4Zfx8AzM82qsIbx1/rxbQicf/5tMwo2bfwweZ +eEX1T91V5n3FsMEfdSIIO3fJ9DGWEJopzxygkVT7yk4xAm9D8KTeKJT7gNACPfxVynFIF3Xrs2K JHQMxL9Pga9lSGLsEntA55GTrob+byNGOCJ+97bCbn/3U0+mEu9c39164liLzMK1LsbsyvcHl7VA 242BtVanVE4zw/kGiKqW2xg/HY4alqklDBtTqXGJI9CnVA3fjMGyg48sBVMwSw4LvlF4kd5XJtyi c4/Tu+J4YfXDApCFS5UnqSvzTBMZqJNdbvPaUyoCdu6Y7CHSkG34KkwBCHXe+q6DmHcPHNlRRWai lqJeObOtfq2tLi4X12+DGvz+ZvGZ98+oGyY+kgCIMo7V3eOzJJ/4nSzNzW4P2kDC4uGq3HDl7GPw DDt+pvlHhV6a5QjptwQBGybQnI83ChkUX8F6u4X0g9iAwvJfZx3lGs1VZ0iZG6egppXkjOrhVptJ 8gZRjxEnfx1IYQ/4lg9Ffvqg9IG0EE8tjDWZlB+G9Jc9fWekhCkYETsycmIe9DyBCzx4I5obgO+2 ucHiHFYFX/uMKqFwmrSG6vY4ocfmWv3Fe9Iziczdq+A= X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch does not change any functionality but makes the patch that makes TMF handling synchronous easier to read. Cc: Nicholas Bellinger Cc: Mike Christie Cc: Christoph Hellwig Cc: David Disseldorp Cc: Hannes Reinecke Signed-off-by: Bart Van Assche --- drivers/target/target_core_transport.c | 14 +++++++++----- include/target/target_core_base.h | 3 ++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index eab5fa2248af..855135812f22 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -1328,7 +1328,8 @@ void transport_init_se_cmd( INIT_LIST_HEAD(&cmd->se_cmd_list); INIT_LIST_HEAD(&cmd->state_list); init_completion(&cmd->t_transport_stop_comp); - cmd->compl = NULL; + cmd->free_compl = NULL; + cmd->abrt_compl = NULL; spin_lock_init(&cmd->t_state_lock); INIT_WORK(&cmd->work, NULL); kref_init(&cmd->cmd_kref); @@ -2689,7 +2690,7 @@ int transport_generic_free_cmd(struct se_cmd *cmd, int wait_for_tasks) transport_lun_remove_cmd(cmd); } if (aborted) - cmd->compl = &compl; + cmd->free_compl = &compl; if (!aborted || tas) ret = target_put_sess_cmd(cmd); if (aborted) { @@ -2756,7 +2757,8 @@ static void target_release_cmd_kref(struct kref *kref) { struct se_cmd *se_cmd = container_of(kref, struct se_cmd, cmd_kref); struct se_session *se_sess = se_cmd->se_sess; - struct completion *compl = se_cmd->compl; + struct completion *free_compl = se_cmd->free_compl; + struct completion *abrt_compl = se_cmd->abrt_compl; unsigned long flags; if (se_sess) { @@ -2767,8 +2769,10 @@ static void target_release_cmd_kref(struct kref *kref) target_free_cmd_mem(se_cmd); se_cmd->se_tfo->release_cmd(se_cmd); - if (compl) - complete(compl); + if (free_compl) + complete(free_compl); + if (abrt_compl) + complete(abrt_compl); percpu_ref_put(&se_sess->cmd_count); } diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h index 67130841d421..bff51baee7e0 100644 --- a/include/target/target_core_base.h +++ b/include/target/target_core_base.h @@ -474,7 +474,8 @@ struct se_cmd { struct se_session *se_sess; struct se_tmr_req *se_tmr_req; struct list_head se_cmd_list; - struct completion *compl; + struct completion *free_compl; + struct completion *abrt_compl; const struct target_core_fabric_ops *se_tfo; sense_reason_t (*execute_cmd)(struct se_cmd *); sense_reason_t (*transport_complete_callback)(struct se_cmd *, bool, int *); From patchwork Tue Nov 27 23:52:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10701643 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9700815A7 for ; Tue, 27 Nov 2018 23:52:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 874A22C967 for ; Tue, 27 Nov 2018 23:52:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7BA7D2C9D5; Tue, 27 Nov 2018 23:52:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E41A02C9CC for ; Tue, 27 Nov 2018 23:52:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726570AbeK1KwT (ORCPT ); Wed, 28 Nov 2018 05:52:19 -0500 Received: from out002.mailprotect.be ([83.217.72.86]:53859 "EHLO out002.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726370AbeK1KwT (ORCPT ); Wed, 28 Nov 2018 05:52:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=9QmZQSMcDGmh37XhEPdL21MTWFj71ADnTSu+y56QXA4=; b=SoPzqJK21lkH T7HbATBD7zStreIbOV/RfvC7K9SSeMFX9iTH/q+USqi/Xv9ygHsGgVUmi0cPMQSHkE41DBKN7BWb9 i1SeIMerBWIf9IgKCQBtLnwgySsvRy5aNPq63ivfCMG2uku56GvTx2igILG3tpfJ3DGSAHFGR5Xe+ oWqGlQk3KXf7c9eM6he3kw3s4OpZ6l2KCuVO1JxJaYQri+umFT+h0A0b4dN4v5sbVHfXZVMjqecq0 KSu1Ia3mmtttw9N7yiopnHM+Yxm4V+TLfU+2YULaPwSbPIudDwko1BerUaZo7YS8li9MPYhF8mXiX SXh+OW0cNT4AEOenLoXckw==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out002.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gRn9f-000H1L-Et; Wed, 28 Nov 2018 00:52:36 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id B5645C03F9; Wed, 28 Nov 2018 00:52:32 +0100 (CET) From: Bart Van Assche To: "Martin K . Petersen" Cc: Christoph Hellwig , target-devel@vger.kernel.org, Bart Van Assche , Nicholas Bellinger , Mike Christie , David Disseldorp , Hannes Reinecke Subject: [PATCH v2 07/10] target/core: Simplify the code for aborting SCSI commands Date: Tue, 27 Nov 2018 15:52:01 -0800 Message-Id: <20181127235204.186731-8-bvanassche@acm.org> X-Mailer: git-send-email 2.20.0.rc0.387.gc7a69e6b6c-goog In-Reply-To: <20181127235204.186731-1-bvanassche@acm.org> References: <20181127235204.186731-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: Combined (0.04) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5ivUaUPRK67+K2bd+UlNtgl602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTagCTS5H5Pie2sCQ3gGSzr06cM7U7xDGmYwNG93LVnxwxjk yGQYCd08t3lHobjxX/OigDGQOIiVUN5rGO3B5zfVpnsdsF0/474T9aStD4uEKVG9P9yTThxC66Ku Xb0HO3W8nbMwgkUuW83PKbk25YSnvgtxKKcMIJ7ptgUxRg53TuCt4QJNIvyoxb4710Nl6KAZZ+9r UkyLOOkgJ9eTXvOC4trOptRiSOXsXUvIrRE5GsFuRHGp5PJU7dB5h6XsjFhI2C8QBYsWIMCVBHpa 7Qj+JYN6Crh9DXUDEtWWsjsNUfobM/P6vznYRdd5hfgiYzLMODodi5MLJiAvrVIiQFNhc8S+HKYI 1vbaqYoREZsvVKq8YZ9/SG1CqFB/T9oOuGkszjGcI+mbLJLuOAP016dVWgH88tf6uZ3Odz3W94Ik DCkIj7lUenMOpFxPb4a0gTxJECCYsMoByn2L5D4ESJJSPTtI2NWSXQ8+P45Rhlff/V8o9A8S4+tr vYumJM3atRPpj3GbeSYQbpjOFT4aGmRsFCWUldd4Zfx8AzM82qsIbx1/rxbQicf/5tMwo2bfwweZ +eEX1T91V5n3FsMEfdSIIO3fJ9DGWEJopzxygkVT7yk4xAm9D8KTeKJT7gNACPfxVynFIF3Xrs2K JHQMxL9Pga9lSGLsEntA55GTrob+byNGOCJ+97bCbn/3U0+mEu+sPyOC2+9nWrUregWUut1QvMd9 seUNa9bhlmIgWL3ZrqqW2xg/HY4alqklDBtTqXGJI9CnVA3fjMGyg48sBVMwSw4LvlF4kd5XJtyi c4/Tu+J4YfXDApCFS5UnqSvzTBMZqJNdbvPaUyoCdu6Y7CHSkG34KkwBCHXe+q6DmHcPHBbaxAtx B3STnJ4r+wWcr8okDbVh1BofvaqOTDKJdIdZkgCIMo7V3eOzJJ/4nSzNzW4P2kDC4uGq3HDl7GPw DDt+pvlHhV6a5QjptwQBGybQnI83ChkUX8F6u4X0g9iAwvJfZx3lGs1VZ0iZG6egppXkjOrhVptJ 8gZRjxEnfx1IYQ/4lg9Ffvqg9IG0EE8tjDWZlB+G9Jc9fWekhCkYETsycmIe9DyBCzx4I5obgO+2 ucHiHFYFX/uMKqFwmrSG6vY4ocfmWv3Fe9Iziczdq+A= X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Instead of allowing the code that aborts a SCSI command to finish before all iSCSI data frames have been received, make that code wait until all iSCSI data frames have been received. Introduce a new member variable in the target driver template to communicate that information from the iSCSI target driver to the target core. This change allows to leave out the check whether or not it is already safe to send the TASK_ABORTED reply from transport_send_task_abort(). Cc: Nicholas Bellinger Cc: Mike Christie Cc: Christoph Hellwig Cc: David Disseldorp Cc: Hannes Reinecke Signed-off-by: Bart Van Assche --- drivers/target/iscsi/iscsi_target_configfs.c | 2 ++ drivers/target/target_core_transport.c | 22 ++------------------ include/target/target_core_fabric.h | 7 +++++++ 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/drivers/target/iscsi/iscsi_target_configfs.c b/drivers/target/iscsi/iscsi_target_configfs.c index 95d0a22b2ad6..1a81386dd7f7 100644 --- a/drivers/target/iscsi/iscsi_target_configfs.c +++ b/drivers/target/iscsi/iscsi_target_configfs.c @@ -1596,4 +1596,6 @@ const struct target_core_fabric_ops iscsi_ops = { .tfc_tpg_nacl_attrib_attrs = lio_target_nacl_attrib_attrs, .tfc_tpg_nacl_auth_attrs = lio_target_nacl_auth_attrs, .tfc_tpg_nacl_param_attrs = lio_target_nacl_param_attrs, + + .write_pending_must_be_called = true, }; diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 855135812f22..05c3bef2b394 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -2584,7 +2584,8 @@ transport_generic_new_cmd(struct se_cmd *cmd) * Determine if frontend context caller is requesting the stopping of * this command for frontend exceptions. */ - if (cmd->transport_state & CMD_T_STOP) { + if (cmd->transport_state & CMD_T_STOP && + !cmd->se_tfo->write_pending_must_be_called) { pr_debug("%s:%d CMD_T_STOP for ITT: 0x%08llx\n", __func__, __LINE__, cmd->tag); @@ -3297,25 +3298,6 @@ void transport_send_task_abort(struct se_cmd *cmd) } spin_unlock_irqrestore(&cmd->t_state_lock, flags); - /* - * If there are still expected incoming fabric WRITEs, we wait - * until until they have completed before sending a TASK_ABORTED - * response. This response with TASK_ABORTED status will be - * queued back to fabric module by transport_check_aborted_status(). - */ - if (cmd->data_direction == DMA_TO_DEVICE) { - if (cmd->se_tfo->write_pending_status(cmd) != 0) { - spin_lock_irqsave(&cmd->t_state_lock, flags); - if (cmd->se_cmd_flags & SCF_SEND_DELAYED_TAS) { - spin_unlock_irqrestore(&cmd->t_state_lock, flags); - goto send_abort; - } - cmd->se_cmd_flags |= SCF_SEND_DELAYED_TAS; - spin_unlock_irqrestore(&cmd->t_state_lock, flags); - return; - } - } -send_abort: cmd->scsi_status = SAM_STAT_TASK_ABORTED; transport_lun_remove_cmd(cmd); diff --git a/include/target/target_core_fabric.h b/include/target/target_core_fabric.h index eb9d0923c55c..6859277fc409 100644 --- a/include/target/target_core_fabric.h +++ b/include/target/target_core_fabric.h @@ -101,6 +101,13 @@ struct target_core_fabric_ops { struct configfs_attribute **tfc_tpg_nacl_attrib_attrs; struct configfs_attribute **tfc_tpg_nacl_auth_attrs; struct configfs_attribute **tfc_tpg_nacl_param_attrs; + + /* + * Set this member variable to true if the SCSI transport protocol + * (e.g. iSCSI) requires that the Data-Out buffer is transferred in + * its entirety before a command is aborted. + */ + bool write_pending_must_be_called; }; int target_register_template(const struct target_core_fabric_ops *fo); From patchwork Tue Nov 27 23:52:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10701641 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2708913BB for ; Tue, 27 Nov 2018 23:52:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 173132C967 for ; Tue, 27 Nov 2018 23:52:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0B4DB2C9F8; Tue, 27 Nov 2018 23:52:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A8192C967 for ; Tue, 27 Nov 2018 23:52:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726780AbeK1KwT (ORCPT ); Wed, 28 Nov 2018 05:52:19 -0500 Received: from out002.mailprotect.be ([83.217.72.86]:38121 "EHLO out002.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726570AbeK1KwS (ORCPT ); Wed, 28 Nov 2018 05:52:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=Tmm1JHiZf1syubuAdIrrd+H2aNZzpAqTyw8kD6M61Oo=; b=JnRxT3Kln3FD qYIZMbLQcc8jPNPMkW1OorV25bYa4VB2pVGOlxDw38CjPf4Md2p0HSPfGuK87rNJkQgaN3/dyG2ca c+LG+k/p561Y3RqM1Sj6YvZTgWfx7bjubG1AtO/OyIsY1rMS+MEbiUGTTvZIs/OkQ0lwBnz5hLzf0 X4QdhDPHYwZMYQZHjwazWrXbUVWOKgPoFu/RbZe9VUdNJvh+DoVtYBXAXO4bs0wZzF4cqbgbh2JRV P/NefadoNYzYFSp4Sqt6EsUot+xGG8cEZpWHsqnL7UM5fQP9NvDhJnOFfJxgDqsAkXcgdf1aGhp54 GDLLlAq0qC3h563aO90ztw==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out002.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gRn9h-000H1E-Cd; Wed, 28 Nov 2018 00:52:37 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id B7AF2C060F; Wed, 28 Nov 2018 00:52:34 +0100 (CET) From: Bart Van Assche To: "Martin K . Petersen" Cc: Christoph Hellwig , target-devel@vger.kernel.org, Bart Van Assche , Nicholas Bellinger , Mike Christie , David Disseldorp , Hannes Reinecke Subject: [PATCH v2 08/10] target/core: Fix TAS handling for aborted commands Date: Tue, 27 Nov 2018 15:52:02 -0800 Message-Id: <20181127235204.186731-9-bvanassche@acm.org> X-Mailer: git-send-email 2.20.0.rc0.387.gc7a69e6b6c-goog In-Reply-To: <20181127235204.186731-1-bvanassche@acm.org> References: <20181127235204.186731-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: SB/global_tokens (0.0047360859013) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5lla81YpijpOMnr6Yq2Cnld602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTagCTS5H5Pie2sCQ3gGSzr06cM7U7xDGmYwNG93LVnxwxjk yGQYCd08t3lHobjxX/OigDGQOIiVUN5rGO3B5zfVpnsdsF0/474T9aStD4uEKVG9P9yTThxC66Ku Xb0HO3W8nbMwgkUuW83PKbk25YSnvgtxKKcMIJ7ptgUxRg53TuCt4QJNIvyoxb4710Nl6KAZZ+9r UkyLOOkgJ9eTXvOC4trOptRiSOXsXUvIrRE5GnBkyt07+qNKezAr8zvSTyVI2C8QBYsWIMCVBHpa 7Qj+JYN6Crh9DXUDEtWWsjsNUfobM/P6vznYRdd5hfgiYzLMODodi5MLJiAvrVIiQFNhc8S+HKYI 1vbaqYoREZsvVKq8YZ9/SG1CqFB/T9oOuGkszjGcI+mbLJLuOAP016dVWgH88tf6uZ3Odz3W94Ik DCkIj7lUenMOpFxPb4a0gTxJECCYsMoByn2L5D4ESJJSPTtI2NWSXQ8+P45Rhlff/dnzpf4jUQPU su/un+Dgc451thv0hd9gZGlVL/SEDgzCn2QHoll2X5InL6dYibIoTL/MkTXVmMpAWIpXwTCeSh0y Myb8PasQ+c0C4IKe30H3UDH+6KBhyClAYMoUKs513yCv9TR+UxzLZWL8hwGBjhpUEpQA9BsGTyd9 ZPwtyPLKf1lID1iBLBCYtInCwWc7eVTGkXx1W/AJdj/iYTWr9z8Tnd2CLe8uZyN+uszKlEef/T4L oeGoG7IekiK9ZTbkfdJyTL1wxWsKT+29tv8uLgFfUqsUgOciGGUcMuG9HCBimKSOuMSxAdirM+Sx h6lCNBJ4/+uf5QH8Sat24Y/EeP90qxD5ZyDMvulM5hETbIS+UGszJ+li7JqcBmkxeyx+tXAusPyu ouDRKpAIOvjL/ZoQHSQ8RtblgvstmR/m8uJ8vjc650DsegsBPu9u8X15wtiEEpCtcWh35a9RQ/VT KzVIK7zBCZaWqBSFkpsp3Br8647lNwN4qOsSZg+fYhVZG191EemzZutM6S62m/Kt2a29tg70BJb3 HR3NbZv4gReBJXkVVPSc006zUgMG2KMDF/xcb3XRuJkRyiZZ6HPi7yzMODodi5MLJiAvrVIiQFNh KIIGqsHi8yYemObHrBMMHOTYQ/Lj3ueyyCegyQhvesx2PyW5cLuSbbpC1c/2zTYs X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The TASK ABORTED STATUS (TAS) bit is defined as follows in SAM: "TASK_ABORTED: this status shall be returned if a command is aborted by a command or task management function on another I_T nexus and the control mode page TAS bit is set to one". TAS handling is spread over the target core and the iSCSI target driver. If a LUN RESET is received, the target core will send the TASK_ABORTED response for all commands for which such a response has to be sent. If an ABORT TASK is received, only the iSCSI target driver will send the TASK_ABORTED response for the commands for which that response has to be sent. That is a bug since all target drivers have to honor the TAS bit. Fix this by moving the code that handles TAS from the iSCSI target driver into the target core. Additionally, if a command has been aborted, instead of sending the TASK_ABORTED status from the context that processes the SCSI command send it from the context of the ABORT TMF. The core_tmr_abort_task() change in this patch causes the CMD_T_TAS flag to be set if a TASK_ABORTED status has to be sent back to the initiator that submitted the command. If that flag has been set transport_cmd_finish_abort() will send the TASK_ABORTED response. Cc: Nicholas Bellinger Cc: Mike Christie Cc: Christoph Hellwig Cc: David Disseldorp Cc: Hannes Reinecke Signed-off-by: Bart Van Assche --- drivers/target/iscsi/iscsi_target.c | 11 ++--- drivers/target/iscsi/iscsi_target_erl1.c | 28 ++---------- drivers/target/target_core_tmr.c | 3 +- drivers/target/target_core_transport.c | 55 +----------------------- include/target/target_core_base.h | 1 - include/target/target_core_fabric.h | 1 - 6 files changed, 10 insertions(+), 89 deletions(-) diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c index c1d5a173553d..984941e036c8 100644 --- a/drivers/target/iscsi/iscsi_target.c +++ b/drivers/target/iscsi/iscsi_target.c @@ -1493,8 +1493,6 @@ __iscsit_check_dataout_hdr(struct iscsi_conn *conn, void *buf, if (hdr->flags & ISCSI_FLAG_CMD_FINAL) iscsit_stop_dataout_timer(cmd); - transport_check_aborted_status(se_cmd, - (hdr->flags & ISCSI_FLAG_CMD_FINAL)); return iscsit_dump_data_payload(conn, payload_length, 1); } } else { @@ -1509,12 +1507,9 @@ __iscsit_check_dataout_hdr(struct iscsi_conn *conn, void *buf, * TASK_ABORTED status. */ if (se_cmd->transport_state & CMD_T_ABORTED) { - if (hdr->flags & ISCSI_FLAG_CMD_FINAL) - if (--cmd->outstanding_r2ts < 1) { - iscsit_stop_dataout_timer(cmd); - transport_check_aborted_status( - se_cmd, 1); - } + if (hdr->flags & ISCSI_FLAG_CMD_FINAL && + --cmd->outstanding_r2ts < 1) + iscsit_stop_dataout_timer(cmd); return iscsit_dump_data_payload(conn, payload_length, 1); } diff --git a/drivers/target/iscsi/iscsi_target_erl1.c b/drivers/target/iscsi/iscsi_target_erl1.c index a211e8154f4c..1b54a9c70851 100644 --- a/drivers/target/iscsi/iscsi_target_erl1.c +++ b/drivers/target/iscsi/iscsi_target_erl1.c @@ -943,20 +943,8 @@ int iscsit_execute_cmd(struct iscsi_cmd *cmd, int ooo) return 0; } spin_unlock_bh(&cmd->istate_lock); - /* - * Determine if delayed TASK_ABORTED status for WRITEs - * should be sent now if no unsolicited data out - * payloads are expected, or if the delayed status - * should be sent after unsolicited data out with - * ISCSI_FLAG_CMD_FINAL set in iscsi_handle_data_out() - */ - if (transport_check_aborted_status(se_cmd, - (cmd->unsolicited_data == 0)) != 0) + if (cmd->se_cmd.transport_state & CMD_T_ABORTED) return 0; - /* - * Otherwise send CHECK_CONDITION and sense for - * exception - */ return transport_send_check_condition_and_sense(se_cmd, cmd->sense_reason, 0); } @@ -974,13 +962,7 @@ int iscsit_execute_cmd(struct iscsi_cmd *cmd, int ooo) if (!(cmd->cmd_flags & ICF_NON_IMMEDIATE_UNSOLICITED_DATA)) { - /* - * Send the delayed TASK_ABORTED status for - * WRITEs if no more unsolicitied data is - * expected. - */ - if (transport_check_aborted_status(se_cmd, 1) - != 0) + if (cmd->se_cmd.transport_state & CMD_T_ABORTED) return 0; iscsit_set_dataout_sequence_values(cmd); @@ -995,11 +977,7 @@ int iscsit_execute_cmd(struct iscsi_cmd *cmd, int ooo) if ((cmd->data_direction == DMA_TO_DEVICE) && !(cmd->cmd_flags & ICF_NON_IMMEDIATE_UNSOLICITED_DATA)) { - /* - * Send the delayed TASK_ABORTED status for WRITEs if - * no more nsolicitied data is expected. - */ - if (transport_check_aborted_status(se_cmd, 1) != 0) + if (cmd->se_cmd.transport_state & CMD_T_ABORTED) return 0; iscsit_set_unsoliticed_dataout(cmd); diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c index 6d1179a7f043..bca0f8a25f92 100644 --- a/drivers/target/target_core_tmr.c +++ b/drivers/target/target_core_tmr.c @@ -165,7 +165,8 @@ void core_tmr_abort_task( printk("ABORT_TASK: Found referenced %s task_tag: %llu\n", se_cmd->se_tfo->get_fabric_name(), ref_tag); - if (!__target_check_io_state(se_cmd, se_sess, 0)) + if (!__target_check_io_state(se_cmd, se_sess, + dev->dev_attrib.emulate_tas)) continue; spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 05c3bef2b394..24eafaceffba 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -1805,7 +1805,7 @@ void transport_generic_request_failure(struct se_cmd *cmd, if (cmd->transport_complete_callback) cmd->transport_complete_callback(cmd, false, &post_ret); - if (transport_check_aborted_status(cmd, 1)) + if (cmd->transport_state & CMD_T_ABORTED) return; switch (sense_reason) { @@ -2012,8 +2012,6 @@ static bool target_handle_task_attr(struct se_cmd *cmd) return true; } -static int __transport_check_aborted_status(struct se_cmd *, int); - void target_execute_cmd(struct se_cmd *cmd) { /* @@ -2023,7 +2021,7 @@ void target_execute_cmd(struct se_cmd *cmd) * If the received CDB has already been aborted stop processing it here. */ spin_lock_irq(&cmd->t_state_lock); - if (__transport_check_aborted_status(cmd, 1)) { + if (cmd->transport_state & CMD_T_ABORTED) { spin_unlock_irq(&cmd->t_state_lock); return; } @@ -3237,55 +3235,6 @@ transport_send_check_condition_and_sense(struct se_cmd *cmd, } EXPORT_SYMBOL(transport_send_check_condition_and_sense); -static int __transport_check_aborted_status(struct se_cmd *cmd, int send_status) - __releases(&cmd->t_state_lock) - __acquires(&cmd->t_state_lock) -{ - int ret; - - assert_spin_locked(&cmd->t_state_lock); - WARN_ON_ONCE(!irqs_disabled()); - - if (!(cmd->transport_state & CMD_T_ABORTED)) - return 0; - /* - * If cmd has been aborted but either no status is to be sent or it has - * already been sent, just return - */ - if (!send_status || !(cmd->se_cmd_flags & SCF_SEND_DELAYED_TAS)) { - if (send_status) - cmd->se_cmd_flags |= SCF_SEND_DELAYED_TAS; - return 1; - } - - pr_debug("Sending delayed SAM_STAT_TASK_ABORTED status for CDB:" - " 0x%02x ITT: 0x%08llx\n", cmd->t_task_cdb[0], cmd->tag); - - cmd->se_cmd_flags &= ~SCF_SEND_DELAYED_TAS; - cmd->scsi_status = SAM_STAT_TASK_ABORTED; - trace_target_cmd_complete(cmd); - - spin_unlock_irq(&cmd->t_state_lock); - ret = cmd->se_tfo->queue_status(cmd); - if (ret) - transport_handle_queue_full(cmd, cmd->se_dev, ret, false); - spin_lock_irq(&cmd->t_state_lock); - - return 1; -} - -int transport_check_aborted_status(struct se_cmd *cmd, int send_status) -{ - int ret; - - spin_lock_irq(&cmd->t_state_lock); - ret = __transport_check_aborted_status(cmd, send_status); - spin_unlock_irq(&cmd->t_state_lock); - - return ret; -} -EXPORT_SYMBOL(transport_check_aborted_status); - void transport_send_task_abort(struct se_cmd *cmd) { unsigned long flags; diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h index bff51baee7e0..31358b0403c8 100644 --- a/include/target/target_core_base.h +++ b/include/target/target_core_base.h @@ -134,7 +134,6 @@ enum se_cmd_flags_table { SCF_SENT_CHECK_CONDITION = 0x00000800, SCF_OVERFLOW_BIT = 0x00001000, SCF_UNDERFLOW_BIT = 0x00002000, - SCF_SEND_DELAYED_TAS = 0x00004000, SCF_ALUA_NON_OPTIMIZED = 0x00008000, SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC = 0x00020000, SCF_COMPARE_AND_WRITE = 0x00080000, diff --git a/include/target/target_core_fabric.h b/include/target/target_core_fabric.h index 6859277fc409..3c100c1f3173 100644 --- a/include/target/target_core_fabric.h +++ b/include/target/target_core_fabric.h @@ -161,7 +161,6 @@ void target_execute_cmd(struct se_cmd *cmd); int transport_generic_free_cmd(struct se_cmd *, int); bool transport_wait_for_tasks(struct se_cmd *); -int transport_check_aborted_status(struct se_cmd *, int); int transport_send_check_condition_and_sense(struct se_cmd *, sense_reason_t, int); int target_get_sess_cmd(struct se_cmd *, bool); From patchwork Tue Nov 27 23:52:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10701647 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3BE4E13BB for ; Tue, 27 Nov 2018 23:52:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A6A12C967 for ; Tue, 27 Nov 2018 23:52:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1F0EE2C9D5; Tue, 27 Nov 2018 23:52:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E18C82C967 for ; Tue, 27 Nov 2018 23:52:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726370AbeK1KwZ (ORCPT ); Wed, 28 Nov 2018 05:52:25 -0500 Received: from com-out001.mailprotect.be ([83.217.72.83]:53581 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726783AbeK1KwZ (ORCPT ); Wed, 28 Nov 2018 05:52:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=TyEa7VtwFLFp0Wa3ha8mR4J+fZp3Bb9+nfTaqDAfD9c=; b=pDKxJPogFGGG b73blmdKCeqxkbwOgAlD8H10Joxi/5R/rANDc0FcqQPHiPRQkUoJ3z0AJNGeXuRMSm64V8eTihVCU 8wL14RcpndTUqJTjXyzBevmaQk75pbItsPdyNIUHeOjItGef9ExuPZJ9ba1Z3liEKWLXghET+F3mn rAMn1DIqwqs2pHEqp/QyU5zE5x+5fLhiJTUUVawh1/RJoatu1B6uWLgBngYHGgBPXenof47yrLswC tKTxHO9PJMD7C8NuaNA7njkTE9YYkdTNmXNPV2ZNO441/EW8USprUqy5Oj14PXOu5CIP0DuGTXkXO VFLXMhGB4vT4IjL6ZKW2DA==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gRn9j-000A2s-Hg; Wed, 28 Nov 2018 00:52:40 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id B6D09C0504; Wed, 28 Nov 2018 00:52:36 +0100 (CET) From: Bart Van Assche To: "Martin K . Petersen" Cc: Christoph Hellwig , target-devel@vger.kernel.org, Bart Van Assche , Nicholas Bellinger , Mike Christie , David Disseldorp , Hannes Reinecke Subject: [PATCH v2 09/10] target/core: Make ABORT and LUN RESET handling synchronous Date: Tue, 27 Nov 2018 15:52:03 -0800 Message-Id: <20181127235204.186731-10-bvanassche@acm.org> X-Mailer: git-send-email 2.20.0.rc0.387.gc7a69e6b6c-goog In-Reply-To: <20181127235204.186731-1-bvanassche@acm.org> References: <20181127235204.186731-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: SB/global_tokens (0.000815775000679) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5mM0LGRa04hyz3ZJRJ/6j7R602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTagCTS5H5Pie2sCQ3gGSzr06cM7U7xDGmYwNG93LVnxwxjk yGQYCd08t3lHobjxX/OigDGQOIiVUN5rGO3B5zfVpnsdsF0/474T9aStD4uEKVG9P9yTThxC66Ku Xb0HO3W8nbMwgkUuW83PKbk25YSnvgtxKKcMIJ7ptgUxRg53TuCt4QJNIvyoxb4710Nl6KAZZ+9r UkyLOOkgJ9eTXvOC4trOptRiSOXsXUvIrRE5GnkoXxJOKz/Jrv2PbgpDrpdI2C8QBYsWIMCVBHpa 7Qj+JYN6Crh9DXUDEtWWsjsNUWDlGPaDR+Aes7asAZpVFyfMODodi5MLJiAvrVIiQFNhc8S+HKYI 1vbaqYoREZsvVKq8YZ9/SG1CqFB/T9oOuGkszjGcI+mbLJLuOAP016dVWgH88tf6uZ3Odz3W94Ik DCkIj7lUenMOpFxPb4a0gTxJECCYsMoByn2L5D4ESJJSPTtI2NWSXQ8+P45Rhlff/dnzpf4jUQPU su/un+Dgc451thv0hd9gZGlVL/SEDgzCn2QHoll2X5InL6dYibIoTL/MkTXVmMpAWIpXwTCeSh0y Myb8PasQ+c0C4IKe30H3UDH+6KBhyClAYMoUKs513yCv9TR+UxzLZWL8hwGBjhpUEpQA9BsGTyd9 ZPwtyPLKf1lID1iBLBCYtInCwWc7eVTGkXx1W/AJdj/iYTWr9z+VwEkOajFjFmqvkRWBM5Ak/pd8 QZXKDa1xjH2LFMQjAAMqtgmYbB0fa5wbFbqEEhJfUqsUgOciGGUcMuG9HCBimKSOuMSxAdirM+Sx h6lCNBJ4/+uf5QH8Sat24Y/EeP90qxD5ZyDMvulM5hETbIS+UGszJ+li7JqcBmkxeyx+tXAusPyu ouDRKpAIOvjL/ZpmfQMWhiXUQqjxETTBa9V9Rm5grddBAAoI+2W9zqQ78tiEEpCtcWh35a9RQ/VT KzVIK7zBCZaWqBSFkpsp3Br8647lNwN4qOsSZg+fYhVZG191EemzZutM6S62m/Kt2a29tg70BJb3 HR3NbZv4gReBJXkVVPSc006zUgMG2KMDF/xcb3XRuJkRyiZZ6HPi7yzMODodi5MLJiAvrVIiQFNh KIIGqsHi8yYemObHrBMMHOTYQ/Lj3ueyyCegyQhvesx2PyW5cLuSbbpC1c/2zTYs X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Instead of invoking target driver callback functions from the context that handles an abort or LUN RESET task management function, only set the abort flag from that context and perform the actual abort handling from the context of the regular command processing flow. This approach has the advantage that the task management code becomes much easier to read and to verify since the number of potential race conditions against the command processing flow is strongly reduced. This patch has been tested by running the following two shell commands concurrently for about ten minutes for both the iSCSI and the SRP target drivers ($dev is an initiator device node connected with storage provided by the target driver under test): * fio with data verification enabled on a filesystem mounted on top of $dev. * while true; do sg_reset -d $dev; echo -n .; sleep .1; done Cc: Nicholas Bellinger Cc: Mike Christie Cc: Christoph Hellwig Cc: David Disseldorp Cc: Hannes Reinecke Signed-off-by: Bart Van Assche --- drivers/target/target_core_internal.h | 2 - drivers/target/target_core_tmr.c | 49 +++--- drivers/target/target_core_transport.c | 230 +++++++++++++------------ include/target/target_core_fabric.h | 1 + 4 files changed, 148 insertions(+), 134 deletions(-) diff --git a/drivers/target/target_core_internal.h b/drivers/target/target_core_internal.h index 0c6635587930..853344415963 100644 --- a/drivers/target/target_core_internal.h +++ b/drivers/target/target_core_internal.h @@ -138,7 +138,6 @@ int init_se_kmem_caches(void); void release_se_kmem_caches(void); u32 scsi_get_new_index(scsi_index_t); void transport_subsystem_check_init(void); -int transport_cmd_finish_abort(struct se_cmd *); unsigned char *transport_dump_cmd_direction(struct se_cmd *); void transport_dump_dev_state(struct se_device *, char *, int *); void transport_dump_dev_info(struct se_device *, struct se_lun *, @@ -148,7 +147,6 @@ int transport_dump_vpd_assoc(struct t10_vpd *, unsigned char *, int); int transport_dump_vpd_ident_type(struct t10_vpd *, unsigned char *, int); int transport_dump_vpd_ident(struct t10_vpd *, unsigned char *, int); void transport_clear_lun_ref(struct se_lun *); -void transport_send_task_abort(struct se_cmd *); sense_reason_t target_cmd_size_check(struct se_cmd *cmd, unsigned int size); void target_qf_do_work(struct work_struct *work); bool target_check_wce(struct se_device *dev); diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c index bca0f8a25f92..a89b34587005 100644 --- a/drivers/target/target_core_tmr.c +++ b/drivers/target/target_core_tmr.c @@ -171,11 +171,15 @@ void core_tmr_abort_task( spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); - cancel_work_sync(&se_cmd->work); - transport_wait_for_tasks(se_cmd); + /* + * Ensure that this ABORT request is visible to the LU RESET + * code. + */ + if (!tmr->tmr_dev) + WARN_ON_ONCE(transport_lookup_tmr_lun(tmr->task_cmd, + se_cmd->orig_fe_lun) < 0); - if (!transport_cmd_finish_abort(se_cmd)) - target_put_sess_cmd(se_cmd); + target_put_cmd_and_wait(se_cmd); printk("ABORT_TASK: Sending TMR_FUNCTION_COMPLETE for" " ref_tag: %llu\n", ref_tag); @@ -269,14 +273,28 @@ static void core_tmr_drain_tmr_list( (preempt_and_abort_list) ? "Preempt" : "", tmr_p, tmr_p->function, tmr_p->response, cmd->t_state); - cancel_work_sync(&cmd->work); - transport_wait_for_tasks(cmd); - - if (!transport_cmd_finish_abort(cmd)) - target_put_sess_cmd(cmd); + target_put_cmd_and_wait(cmd); } } +/** + * core_tmr_drain_state_list() - abort SCSI commands associated with a device + * + * @dev: Device for which to abort outstanding SCSI commands. + * @prout_cmd: Pointer to the SCSI PREEMPT AND ABORT if this function is called + * to realize the PREEMPT AND ABORT functionality. + * @tmr_sess: Session through which the LUN RESET has been received. + * @tas: Task Aborted Status (TAS) bit from the SCSI control mode page. + * A quote from SPC-4, paragraph "7.5.10 Control mode page": + * "A task aborted status (TAS) bit set to zero specifies that + * aborted commands shall be terminated by the device server + * without any response to the application client. A TAS bit set + * to one specifies that commands aborted by the actions of an I_T + * nexus other than the I_T nexus on which the command was + * received shall be completed with TASK ABORTED status." + * @preempt_and_abort_list: For the PREEMPT AND ABORT functionality, a list + * with registrations that will be preempted. + */ static void core_tmr_drain_state_list( struct se_device *dev, struct se_cmd *prout_cmd, @@ -351,18 +369,7 @@ static void core_tmr_drain_state_list( cmd->tag, (preempt_and_abort_list) ? "preempt" : "", cmd->pr_res_key); - /* - * If the command may be queued onto a workqueue cancel it now. - * - * This is equivalent to removal from the execute queue in the - * loop above, but we do it down here given that - * cancel_work_sync may block. - */ - cancel_work_sync(&cmd->work); - transport_wait_for_tasks(cmd); - - if (!transport_cmd_finish_abort(cmd)) - target_put_sess_cmd(cmd); + target_put_cmd_and_wait(cmd); } } diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 24eafaceffba..8ae787044eef 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -707,32 +707,6 @@ static void transport_lun_remove_cmd(struct se_cmd *cmd) percpu_ref_put(&lun->lun_ref); } -int transport_cmd_finish_abort(struct se_cmd *cmd) -{ - bool send_tas = cmd->transport_state & CMD_T_TAS; - bool ack_kref = (cmd->se_cmd_flags & SCF_ACK_KREF); - int ret = 0; - - if (send_tas) - transport_send_task_abort(cmd); - - if (cmd->se_cmd_flags & SCF_SE_LUN_CMD) - transport_lun_remove_cmd(cmd); - /* - * Allow the fabric driver to unmap any resources before - * releasing the descriptor via TFO->release_cmd() - */ - if (!send_tas) - cmd->se_tfo->aborted_task(cmd); - - if (transport_cmd_check_stop_to_fabric(cmd)) - return 1; - if (!send_tas && ack_kref) - ret = target_put_sess_cmd(cmd); - - return ret; -} - static void target_complete_failure_work(struct work_struct *work) { struct se_cmd *cmd = container_of(work, struct se_cmd, work); @@ -782,12 +756,88 @@ void transport_copy_sense_to_cmd(struct se_cmd *cmd, unsigned char *sense) } EXPORT_SYMBOL(transport_copy_sense_to_cmd); +static void target_handle_abort(struct se_cmd *cmd) +{ + bool tas = cmd->transport_state & CMD_T_TAS; + bool ack_kref = cmd->se_cmd_flags & SCF_ACK_KREF; + int ret; + + pr_debug("tag %#llx: send_abort_response = %d\n", cmd->tag, tas); + + if (tas) { + if (!(cmd->se_cmd_flags & SCF_SCSI_TMR_CDB)) { + cmd->scsi_status = SAM_STAT_TASK_ABORTED; + pr_debug("Setting SAM_STAT_TASK_ABORTED status for CDB: 0x%02x, ITT: 0x%08llx\n", + cmd->t_task_cdb[0], cmd->tag); + trace_target_cmd_complete(cmd); + ret = cmd->se_tfo->queue_status(cmd); + if (ret) { + transport_handle_queue_full(cmd, cmd->se_dev, + ret, false); + return; + } + } else { + cmd->se_tmr_req->response = TMR_FUNCTION_REJECTED; + cmd->se_tfo->queue_tm_rsp(cmd); + } + } else { + /* + * Allow the fabric driver to unmap any resources before + * releasing the descriptor via TFO->release_cmd(). + */ + cmd->se_tfo->aborted_task(cmd); + if (ack_kref) + WARN_ON_ONCE(target_put_sess_cmd(cmd) != 0); + /* + * To do: establish a unit attention condition on the I_T + * nexus associated with cmd. See also the paragraph "Aborting + * commands" in SAM. + */ + } + + WARN_ON_ONCE(kref_read(&cmd->cmd_kref) == 0); + + transport_lun_remove_cmd(cmd); + + transport_cmd_check_stop_to_fabric(cmd); +} + +static void target_abort_work(struct work_struct *work) +{ + struct se_cmd *cmd = container_of(work, struct se_cmd, work); + + target_handle_abort(cmd); +} + +static bool target_cmd_interrupted(struct se_cmd *cmd) +{ + int post_ret; + + if (cmd->transport_state & CMD_T_ABORTED) { + if (cmd->transport_complete_callback) + cmd->transport_complete_callback(cmd, false, &post_ret); + INIT_WORK(&cmd->work, target_abort_work); + queue_work(target_completion_wq, &cmd->work); + return true; + } else if (cmd->transport_state & CMD_T_STOP) { + if (cmd->transport_complete_callback) + cmd->transport_complete_callback(cmd, false, &post_ret); + complete_all(&cmd->t_transport_stop_comp); + return true; + } + + return false; +} + +/* May be called from interrupt context so must not sleep. */ void target_complete_cmd(struct se_cmd *cmd, u8 scsi_status) { - struct se_device *dev = cmd->se_dev; int success; unsigned long flags; + if (target_cmd_interrupted(cmd)) + return; + cmd->scsi_status = scsi_status; spin_lock_irqsave(&cmd->t_state_lock, flags); @@ -803,25 +853,7 @@ void target_complete_cmd(struct se_cmd *cmd, u8 scsi_status) break; } - /* - * Check for case where an explicit ABORT_TASK has been received - * and transport_wait_for_tasks() will be waiting for completion.. - */ - if (cmd->transport_state & CMD_T_ABORTED || - cmd->transport_state & CMD_T_STOP) { - spin_unlock_irqrestore(&cmd->t_state_lock, flags); - /* - * If COMPARE_AND_WRITE was stopped by __transport_wait_for_tasks(), - * release se_device->caw_sem obtained by sbc_compare_and_write() - * since target_complete_ok_work() or target_complete_failure_work() - * won't be called to invoke the normal CAW completion callbacks. - */ - if (cmd->se_cmd_flags & SCF_COMPARE_AND_WRITE) { - up(&dev->caw_sem); - } - complete_all(&cmd->t_transport_stop_comp); - return; - } else if (!success) { + if (!success) { INIT_WORK(&cmd->work, target_complete_failure_work); } else { INIT_WORK(&cmd->work, target_complete_ok_work); @@ -1805,8 +1837,11 @@ void transport_generic_request_failure(struct se_cmd *cmd, if (cmd->transport_complete_callback) cmd->transport_complete_callback(cmd, false, &post_ret); - if (cmd->transport_state & CMD_T_ABORTED) + if (cmd->transport_state & CMD_T_ABORTED) { + INIT_WORK(&cmd->work, target_abort_work); + queue_work(target_completion_wq, &cmd->work); return; + } switch (sense_reason) { case TCM_NON_EXISTENT_LUN: @@ -2020,20 +2055,10 @@ void target_execute_cmd(struct se_cmd *cmd) * * If the received CDB has already been aborted stop processing it here. */ - spin_lock_irq(&cmd->t_state_lock); - if (cmd->transport_state & CMD_T_ABORTED) { - spin_unlock_irq(&cmd->t_state_lock); - return; - } - if (cmd->transport_state & CMD_T_STOP) { - pr_debug("%s:%d CMD_T_STOP for ITT: 0x%08llx\n", - __func__, __LINE__, cmd->tag); - - spin_unlock_irq(&cmd->t_state_lock); - complete_all(&cmd->t_transport_stop_comp); + if (target_cmd_interrupted(cmd)) return; - } + spin_lock_irq(&cmd->t_state_lock); cmd->t_state = TRANSPORT_PROCESSING; cmd->transport_state &= ~CMD_T_PRE_EXECUTE; cmd->transport_state |= CMD_T_ACTIVE | CMD_T_SENT; @@ -2646,14 +2671,30 @@ static void target_wait_free_cmd(struct se_cmd *cmd, bool *aborted, bool *tas) spin_unlock_irqrestore(&cmd->t_state_lock, flags); } +/* + * Call target_put_sess_cmd() and wait until target_release_cmd_kref(@cmd) has + * finished. + */ +void target_put_cmd_and_wait(struct se_cmd *cmd) +{ + DECLARE_COMPLETION_ONSTACK(compl); + + WARN_ON_ONCE(cmd->abrt_compl); + cmd->abrt_compl = &compl; + target_put_sess_cmd(cmd); + wait_for_completion(&compl); +} + /* * This function is called by frontend drivers after processing of a command * has finished. * - * The protocol for ensuring that either the regular flow or the TMF - * code drops one reference is as follows: + * The protocol for ensuring that either the regular frontend command + * processing flow or target_handle_abort() code drops one reference is as + * follows: * - Calling .queue_data_in(), .queue_status() or queue_tm_rsp() will cause - * the frontend driver to drop one reference, synchronously or asynchronously. + * the frontend driver to call this function synchronously or asynchronously. + * That will cause one reference to be dropped. * - During regular command processing the target core sets CMD_T_COMPLETE * before invoking one of the .queue_*() functions. * - The code that aborts commands skips commands and TMFs for which @@ -2665,7 +2706,7 @@ static void target_wait_free_cmd(struct se_cmd *cmd, bool *aborted, bool *tas) * - For aborted commands for which CMD_T_TAS has been set .queue_status() will * be called and will drop a reference. * - For aborted commands for which CMD_T_TAS has not been set .aborted_task() - * will be called. transport_cmd_finish_abort() will drop the final reference. + * will be called. target_handle_abort() will drop the final reference. */ int transport_generic_free_cmd(struct se_cmd *cmd, int wait_for_tasks) { @@ -2690,8 +2731,7 @@ int transport_generic_free_cmd(struct se_cmd *cmd, int wait_for_tasks) } if (aborted) cmd->free_compl = &compl; - if (!aborted || tas) - ret = target_put_sess_cmd(cmd); + ret = target_put_sess_cmd(cmd); if (aborted) { pr_debug("Detected CMD_T_ABORTED for ITT: %llu\n", cmd->tag); wait_for_completion(&compl); @@ -3219,6 +3259,8 @@ transport_send_check_condition_and_sense(struct se_cmd *cmd, { unsigned long flags; + WARN_ON_ONCE(cmd->se_cmd_flags & SCF_SCSI_TMR_CDB); + spin_lock_irqsave(&cmd->t_state_lock, flags); if (cmd->se_cmd_flags & SCF_SENT_CHECK_CONDITION) { spin_unlock_irqrestore(&cmd->t_state_lock, flags); @@ -3235,46 +3277,15 @@ transport_send_check_condition_and_sense(struct se_cmd *cmd, } EXPORT_SYMBOL(transport_send_check_condition_and_sense); -void transport_send_task_abort(struct se_cmd *cmd) -{ - unsigned long flags; - int ret; - - spin_lock_irqsave(&cmd->t_state_lock, flags); - if (cmd->se_cmd_flags & (SCF_SENT_CHECK_CONDITION)) { - spin_unlock_irqrestore(&cmd->t_state_lock, flags); - return; - } - spin_unlock_irqrestore(&cmd->t_state_lock, flags); - - cmd->scsi_status = SAM_STAT_TASK_ABORTED; - - transport_lun_remove_cmd(cmd); - - pr_debug("Setting SAM_STAT_TASK_ABORTED status for CDB: 0x%02x, ITT: 0x%08llx\n", - cmd->t_task_cdb[0], cmd->tag); - - trace_target_cmd_complete(cmd); - ret = cmd->se_tfo->queue_status(cmd); - if (ret) - transport_handle_queue_full(cmd, cmd->se_dev, ret, false); -} - static void target_tmr_work(struct work_struct *work) { struct se_cmd *cmd = container_of(work, struct se_cmd, work); struct se_device *dev = cmd->se_dev; struct se_tmr_req *tmr = cmd->se_tmr_req; - unsigned long flags; int ret; - spin_lock_irqsave(&cmd->t_state_lock, flags); - if (cmd->transport_state & CMD_T_ABORTED) { - tmr->response = TMR_FUNCTION_REJECTED; - spin_unlock_irqrestore(&cmd->t_state_lock, flags); - goto check_stop; - } - spin_unlock_irqrestore(&cmd->t_state_lock, flags); + if (cmd->transport_state & CMD_T_ABORTED) + goto aborted; switch (tmr->function) { case TMR_ABORT_TASK: @@ -3308,18 +3319,16 @@ static void target_tmr_work(struct work_struct *work) break; } - spin_lock_irqsave(&cmd->t_state_lock, flags); - if (cmd->transport_state & CMD_T_ABORTED) { - spin_unlock_irqrestore(&cmd->t_state_lock, flags); - goto check_stop; - } - spin_unlock_irqrestore(&cmd->t_state_lock, flags); + if (cmd->transport_state & CMD_T_ABORTED) + goto aborted; cmd->se_tfo->queue_tm_rsp(cmd); -check_stop: - transport_lun_remove_cmd(cmd); transport_cmd_check_stop_to_fabric(cmd); + return; + +aborted: + target_handle_abort(cmd); } int transport_generic_handle_tmr( @@ -3338,11 +3347,10 @@ int transport_generic_handle_tmr( spin_unlock_irqrestore(&cmd->t_state_lock, flags); if (aborted) { - pr_warn_ratelimited("handle_tmr caught CMD_T_ABORTED TMR %d" - "ref_tag: %llu tag: %llu\n", cmd->se_tmr_req->function, - cmd->se_tmr_req->ref_task_tag, cmd->tag); - transport_lun_remove_cmd(cmd); - transport_cmd_check_stop_to_fabric(cmd); + pr_warn_ratelimited("handle_tmr caught CMD_T_ABORTED TMR %d ref_tag: %llu tag: %llu\n", + cmd->se_tmr_req->function, + cmd->se_tmr_req->ref_task_tag, cmd->tag); + target_handle_abort(cmd); return 0; } diff --git a/include/target/target_core_fabric.h b/include/target/target_core_fabric.h index 3c100c1f3173..c6d6bfdcd41a 100644 --- a/include/target/target_core_fabric.h +++ b/include/target/target_core_fabric.h @@ -156,6 +156,7 @@ int target_submit_tmr(struct se_cmd *se_cmd, struct se_session *se_sess, int transport_handle_cdb_direct(struct se_cmd *); sense_reason_t transport_generic_new_cmd(struct se_cmd *); +void target_put_cmd_and_wait(struct se_cmd *cmd); void target_execute_cmd(struct se_cmd *cmd); int transport_generic_free_cmd(struct se_cmd *, int); From patchwork Tue Nov 27 23:52:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10701645 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 551E213BB for ; Tue, 27 Nov 2018 23:52:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 45C382C967 for ; Tue, 27 Nov 2018 23:52:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 39EF32C9D5; Tue, 27 Nov 2018 23:52:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CDD1F2C967 for ; Tue, 27 Nov 2018 23:52:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726820AbeK1KwY (ORCPT ); Wed, 28 Nov 2018 05:52:24 -0500 Received: from com-out001.mailprotect.be ([83.217.72.83]:43037 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726370AbeK1KwY (ORCPT ); Wed, 28 Nov 2018 05:52:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=IPEoorPCD0OTCy2v9nVG1hm7y73T04MOsIKzW+vLGhk=; b=J7/NpmwZf8HF iUxvO7iXrvo8T3g+BjncU6kiVTRYN32lgUICDb/DVT/v8Nd4m3Q62OGzbItyf7KUkFuZd27Xb/Gjc aS516mLjdQHJhP392SfTEciP54EwAE2WWRLZkGwkVvJtJumPmja1eazCHmP5NLLc2HsmjVWhOoNJo 6sBagBiYgCMcp6dr7ngpvUN1M/L7aszQvTPihkoK6vZq/cfq05YPMx0yhE1c4A2g1LZOXXy7qCHK8 d6FurT+HclgD5Edjc/TS8/WApTHSG9Ag7YbIapgItFYJiG4IYsBdYQt6+Pnunsb5YvayEMbyMz5XK U9UX0LcYT1mT6cUiVM+EMg==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gRn9l-000A2s-9v; Wed, 28 Nov 2018 00:52:41 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id CC50DC0511; Wed, 28 Nov 2018 00:52:38 +0100 (CET) From: Bart Van Assche To: "Martin K . Petersen" Cc: Christoph Hellwig , target-devel@vger.kernel.org, Bart Van Assche , Nicholas Bellinger , Mike Christie , David Disseldorp , Hannes Reinecke Subject: [PATCH v2 10/10] target/core: Reduce the amount of code executed with a spinlock held Date: Tue, 27 Nov 2018 15:52:04 -0800 Message-Id: <20181127235204.186731-11-bvanassche@acm.org> X-Mailer: git-send-email 2.20.0.rc0.387.gc7a69e6b6c-goog In-Reply-To: <20181127235204.186731-1-bvanassche@acm.org> References: <20181127235204.186731-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: Combined (0.02) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5lUhrdv9t27uyqf8Y0L5yAt602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTagCTS5H5Pie2sCQ3gGSzr06cM7U7xDGmYwNG93LVnxwxjk yGQYCd08t3lHobjxX/OigDGQOIiVUN5rGO3B5zfVpnsdsF0/474T9aStD4uEKVG9P9yTThxC66Ku Xb0HO3W8nbMwgkUuW83PKbk25YSnvgtxKKcMIJ7ptgUxRg53TuCt4QJNIvyoxb4710Nl6KAZZ+9r UkyLOOkgJ9eTXvOC4trOptRiSOXsXUvIrRE5Gv2ZitGQ4mLSIBXGbHhMZvdI2C8QBYsWIMCVBHpa 7Qj+JYN6Crh9DXUDEtWWsjsNUWDlGPaDR+Aes7asAZpVFyfMODodi5MLJiAvrVIiQFNhc8S+HKYI 1vbaqYoREZsvVKq8YZ9/SG1CqFB/T9oOuGkszjGcI+mbLJLuOAP016dVWgH88tf6uZ3Odz3W94Ik DCkIj7lUenMOpFxPb4a0gTxJECCYsMoByn2L5D4ESJJSPTtI2NWSXQ8+P45Rhlff/V8o9A8S4+tr vYumJM3atRPpj3GbeSYQbpjOFT4aGmRsFCWUldd4Zfx8AzM82qsIbx1/rxbQicf/5tMwo2bfwweZ +eEX1T91V5n3FsMEfdSIIO3fJ9DGWEJopzxygkVT7yk4xAm9D8KTeKJT7gNACPfxVynFIF3Xrs2K JHQMxL9Pga9lSGLsEntA55GTrob+bwU0pkWukw/5GtMnr6abkRloTB1ySA0lU3tuTBwvekVdLOCQ TrSFM7snLE/cSYe0laqW2xg/HY4alqklDBtTqXGJI9CnVA3fjMGyg48sBVMwSw4LvlF4kd5XJtyi c4/Tu+J4YfXDApCFS5UnqSvzTBMZqJNdbvPaUyoCdu6Y7CHSkG34KkwBCHXe+q6DmHcPHFUsWGxX 7laPjOe49+dpVQ6ftGfnbLVxY5L6rakrXfsAkgCIMo7V3eOzJJ/4nSzNzW4P2kDC4uGq3HDl7GPw DDt+pvlHhV6a5QjptwQBGybQnI83ChkUX8F6u4X0g9iAwvJfZx3lGs1VZ0iZG6egppXkjOrhVptJ 8gZRjxEnfx1IYQ/4lg9Ffvqg9IG0EE8tjDWZlB+G9Jc9fWekhCkYETsycmIe9DyBCzx4I5obgO+2 ucHiHFYFX/uMKqFwmrSG6vY4ocfmWv3Fe9Iziczdq+A= X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Due to the "make ABORT and LUN RESET handling synchronous" patch, cmd->work is only modified from the regular command execution path and no longer asynchronously by the code that executes task management functions. Since the regular command execution code is sequential per command, no locking is required to manipulate cmd->work. Hence stop protecting cmd->work manipulations with locking. Cc: Nicholas Bellinger Cc: Mike Christie Cc: Christoph Hellwig Cc: David Disseldorp Cc: Hannes Reinecke Signed-off-by: Bart Van Assche --- drivers/target/target_core_transport.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 8ae787044eef..9e0bbb135e7b 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -853,16 +853,12 @@ void target_complete_cmd(struct se_cmd *cmd, u8 scsi_status) break; } - if (!success) { - INIT_WORK(&cmd->work, target_complete_failure_work); - } else { - INIT_WORK(&cmd->work, target_complete_ok_work); - } - cmd->t_state = TRANSPORT_COMPLETE; cmd->transport_state |= (CMD_T_COMPLETE | CMD_T_ACTIVE); spin_unlock_irqrestore(&cmd->t_state_lock, flags); + INIT_WORK(&cmd->work, success ? target_complete_ok_work : + target_complete_failure_work); if (cmd->se_cmd_flags & SCF_USE_CPUID) queue_work_on(cmd->cpuid, target_completion_wq, &cmd->work); else