From patchwork Tue Nov 6 17:17:09 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: 10670869 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 A7FA917D4 for ; Tue, 6 Nov 2018 17:18:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A8772AA15 for ; Tue, 6 Nov 2018 17:18:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 799252AA1D; Tue, 6 Nov 2018 17:18: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 D4A6F2AA15 for ; Tue, 6 Nov 2018 17:18:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388987AbeKGCo5 (ORCPT ); Tue, 6 Nov 2018 21:44:57 -0500 Received: from com-out001.mailprotect.be ([83.217.72.83]:52189 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389281AbeKGCo4 (ORCPT ); Tue, 6 Nov 2018 21:44:56 -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=T2DPGxgmo7jlsonG2Y91U577hGzHr6Rdcs2PIcX70OU=; b=KUdQ+JA3nj3h G9JewNrOrjcTIjvSBj5DdNU8d1r1lG9vLmpAbPWYBAGntpKvGqs5NpPYprrnJwWWoi/FXm3Wyo+5l MOAikl8fdfSOHB3G0MOMdFgjzilyVB/H2wXTMX7I+zBL6puNmMz7yNELMpCWnkGhOsfYNMCkvoK0p v8rlMBy9RkreczwrFlmtdYxYl4mByuxu+gkhx6VhBn3zHecqQUeGTuv1OTkPc6xNxqCXendbiKn1P +LEPbtwNI3U7Zfv8QwNgZ9A3xerbFBU/+eCaqKrznP0JPmyO3GxtmhFai10eQbt/dYHDheXeYIZVx sPbIrEtnX8hF+CV8/Q6how==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gK4zn-000CJL-5G; Tue, 06 Nov 2018 18:18: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 E8606C0BA4; Tue, 6 Nov 2018 18:18: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 01/10] target/tcmu: Fix queue_cmd_ring() declaration Date: Tue, 6 Nov 2018 09:17:09 -0800 Message-Id: <20181106171718.89594-2-bvanassche@acm.org> X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-goog In-Reply-To: <20181106171718.89594-1-bvanassche@acm.org> References: <20181106171718.89594-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: Combined (0.01) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5rrwZdWsJx3Z3dPjdEB1FMR602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTagCTS5H5Pie2sCQ3gGSzr06cM7U7xDGmYwNG93LVnxwxjk yGQYCd08t3lHobjxX/OigDGQOIiVUN5rGO3B5zfVpnsdsF0/474T9aStD4uEKVG9P9yTThxC66Ku Xb0HO3W8nbMwgkUuW83PKbk25YSnvgtxKKcMIJ7ptgUxRg53TuCt4QJNIvyoxb4710Nl6KAZZ+9r UkyLOOkgJ9eTXvOC4trOptRiSOXsXUvIrRE5GkM9Ydp+RcHvAMT9Z/3ZSXFI2C8QBYsWIMCVBHpa 7Qj+JYN6Crh9DXUDEtWWsjsNUWDlGPaDR+Aes7asAZpVFyfMODodi5MLJiAvrVIiQFNhc8S+HKYI 1vbaqYoREZsvVKq8YZ9/SG1CqFB/T9oOuGliwtRkR+GX5UQPXdpKZF7ITlSXoP8r3OOc9CaULF46 7VT2rSAdw3oKkBNp3q2CTUjaBEkZvVwfNyBf8N9Cj3+++mTSKn34bbFRlO1kXUycpLT8XjuR2au2 vXjeilQq2Qb31qklcVekvgO5ge3Iu/DWvQSnovmZV/iKI4Qq8lKVZU757KiUYziXyuXG4Z+FT7fy UhTxDKdOQwQquEi4jLe86t14bfTnkAn7W6VlJXtsnkdl1her2dsH1gtu4R2VkYfnELRpqCZGYewS zF6qDSUBpQp9p69drFuEpAhhs7hKCCLwHYF1mz4X0cGLGMLXeUeTV5gTmW8ZFxfceWltbaMy2bRk WbJQMsEazexAznFikUFGnvKVJnFQQaAnDicXOB0lxU/TKjOssk5IMwdmSU/MN6mG9OgEfwYjdW8p pBMOL6KehsbCb0/0wF8xekzsVEvRMrw5DdwH1AXXXLvYNFIciWrFfcvTzpdI3AEG059XQb6SP9NR QUvJbfVcsG6K+zp3OnKG9eRDP2/Ogb+c8D2oYTsY8dUpTw48b2MGkvEkgszLgRqa1sRnErSRPh8z fPP2CFl7xGIrJ5fPg33HFhWuygEwwwWe3xXNBQ8NJdm4Pscvb9y1CBweR1aEOEmF+7+XwJhp74Ne BZS/7a9ATcUMpAEntM8yKElR+Y84QVlpY/2Olap60rnP5huMjJeWSwzfzlDTegaelgiu9QvTToG3 X/ekOoQKVaL7/+VCcmuF/Q== 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") Cc: Nicholas Bellinger Cc: Mike Christie Cc: Christoph Hellwig Cc: David Disseldorp Cc: Hannes Reinecke Signed-off-by: Bart Van Assche Reviewed-by: David Disseldorp --- 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 6 17:17:10 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: 10670877 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 BAC2215E9 for ; Tue, 6 Nov 2018 17:18:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A15412AA73 for ; Tue, 6 Nov 2018 17:18:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9426A2AA7C; Tue, 6 Nov 2018 17:18:56 +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 2DE8A2AA73 for ; Tue, 6 Nov 2018 17:18:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389372AbeKGCpH (ORCPT ); Tue, 6 Nov 2018 21:45:07 -0500 Received: from out002.mailprotect.be ([83.217.72.86]:59903 "EHLO out002.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389286AbeKGCpH (ORCPT ); Tue, 6 Nov 2018 21:45: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=OTtQQ3PHT+PLCgbxeZS5RkpyiaDVFFRjmyhDekuELnY=; b=vgfdeYjGtZ8/ kz9TUJewR4EPC5DtkVYR31neasgwpD2UjoU+wV9JwEMnM4rAQ2E6bVBSKyQZr8I0UwQma2/IM8v5g +DpaIkaT7ZSeiTYyTWeh7ndnHEdzUBeJxf70WcZm6xdvQHhGj9EHdsI9N68+v+tOade5hVhVjslHB Pth49UqtsY8JIdEy5cnYqmpdQiT0/f6C3HK5cdzZZmXBM0wGSPDPdS6/h8vRx6s+JDAFsV/7bQQcC XU49doLOinWhyzFHLCW+hh569JhTxWBvVUN+rLXgQcWnjh+ZM5HLP8VMawdJ1a13NCzA0F2T+Daa7 TMszJborDcENPDgxpOobkQ==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out002.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gK502-0002kB-8U; Tue, 06 Nov 2018 18:18:47 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id 087C8C0C72; Tue, 6 Nov 2018 18:18:27 +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 , Hannes Reinecke , David Disseldorp Subject: [PATCH 02/10] target/core: Use kvcalloc() instead of open-coding it Date: Tue, 6 Nov 2018 09:17:10 -0800 Message-Id: <20181106171718.89594-3-bvanassche@acm.org> X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-goog In-Reply-To: <20181106171718.89594-1-bvanassche@acm.org> References: <20181106171718.89594-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: Combined (0.04) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5s0S1U1x75jAaBp0saxZSJV602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTagCTS5H5Pie2sCQ3gGSzr06cM7U7xDGmYwNG93LVnxwxjk yGQYCd08t3lHobjxX/OigDGQOIiVUN5rGO3B5zfVpnsdsF0/474T9aStD4uEKVG9P9yTThxC66Ku Xb0HO3W8nbMwgkUuW83PKbk25YSnvgtxKKcMIJ7ptgUxRg53TuCt4QJNIvyoxb4710Nl6KAZZ+9r UkyLOOkgJ9eTXvOC4trOptRiSOXsXUvIrRE5GgrmkZF+3A4KzBPo/tRUQixI2C8QBYsWIMCVBHpa 7Qj+JYN6Crh9DXUDEtWWsjsNUfobM/P6vznYRdd5hfgiYzLMODodi5MLJiAvrVIiQFNhc8S+HKYI 1vbaqYoREZsvVKq8YZ9/SG1CqFB/T9oOuGliwtRkR+GX5UQPXdpKZF7ITlSXoP8r3OOc9CaULF46 7VT2rSAdw3oKkBNp3q2CTUjaBEkZvVwfNyBf8N9Cj3+++mTSKn34bbFRlO1kXUycpLT8XjuR2au2 vXjeilQq2Qb31qklcVekvgO5ge3Iu/DWvQSnovmZV/iKI4Qq8lKVZU757KiUYziXyuXG4Z+FT7fy UhTxDKdOQwQquEi4jLe86t14bfTnkAn7W6VlJXtsnkdl1her2dsH1gtu4R2VkYfnELRpqCZGYewS zF6qDSUBpQp9p69drFuEpAhhs7hKCC1kk1HkTaAEFG/D78FaYe+8a0U8sLEZlrdsBxrZ62yd2bRk WbJQMsEazexAznFikUFGnvKVJnFQQaAnDicXOB0lxU/TKjOssk5IMwdmSU/MN6mG9OgEfwYjdW8p pBMOL6KehsbCb0/0wF8xekzsVEvRMrw5DdwH1AXXXLvYNFIciWrFfcvTzpdI3AEG059XQWfyYuGB nPzxG2w3izoUwRN3OnKG9eRDP2/Ogb+c8D2oYTsY8dUpTw48b2MGkvEkgszLgRqa1sRnErSRPh8z fPP2CFl7xGIrJ5fPg33HFhWuygEwwwWe3xXNBQ8NJdm4Pscvb9y1CBweR1aEOEmF+7+XwJhp74Ne BZS/7a9ATcUMpAEntM8yKElR+Y84QVlpY/2Olap60rnP5huMjJeWSwzfzlDTegaelgiu9QvTToG3 X/ekOoQKVaL7/+VCcmuF/Q== 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. Cc: Nicholas Bellinger Cc: Mike Christie Cc: Christoph Hellwig Cc: Hannes Reinecke Cc: David Disseldorp Signed-off-by: Bart Van Assche Reviewed-by: David Disseldorp --- drivers/target/target_core_transport.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 2cfd61d62e97..086cac18ebca 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -273,14 +273,10 @@ 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); 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 6 17:17:11 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: 10670871 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 B3C8A15E9 for ; Tue, 6 Nov 2018 17:18:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 99F0B2AA0C for ; Tue, 6 Nov 2018 17:18:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8DDCC2AA17; Tue, 6 Nov 2018 17:18:48 +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 6DD622AA0C for ; Tue, 6 Nov 2018 17:18:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389260AbeKGCo4 (ORCPT ); Tue, 6 Nov 2018 21:44:56 -0500 Received: from com-out001.mailprotect.be ([83.217.72.83]:48459 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388987AbeKGCo4 (ORCPT ); Tue, 6 Nov 2018 21:44:56 -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=HpbkcOpN51ZZXKHLzL/PNvVHyMorw1pxmM3aKPXiKDA=; b=l/XQsMPVSW2U cxkj7o5dp/C5ZErYlY4j5IeJh88rSfFKQQETw5iWxo0wolYe4XwCOUUz2/tqV+S7yn4+pvpn+EgeQ +iaIEL/ka4hYVTKotKOrCGQFSln/S7+sbqWMQU2RkNHfXwr5uxnAIa49oRJauteXhxJr7/cHViTCM eam2C0JDBvCcGks48izsuIHHvYOnlC47GlUrT81qkpP5y/K+Ov3r8/AiYHXoy/1WUnA4WCply0u5D hU5Iy8lP7FE2vEBEOqoFvZPoO9VoGcQ4DBZqEWb1VR1EbEGhRiHA3bA5TzQyJZq9yNUCLzZb3mvzx iabZmSGB4ZPZreTVoyf8qw==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gK4zp-000CL1-SL; Tue, 06 Nov 2018 18:18:34 +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 1EF87C09E2; Tue, 6 Nov 2018 18:18:29 +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 03/10] target/core: Simplify transport_clear_lun_ref() Date: Tue, 6 Nov 2018 09:17:11 -0800 Message-Id: <20181106171718.89594-4-bvanassche@acm.org> X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-goog In-Reply-To: <20181106171718.89594-1-bvanassche@acm.org> References: <20181106171718.89594-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: Combined (0.04) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5p/5vsOrgxcXRhQfDN4KPx5602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTagCTS5H5Pie2sCQ3gGSzr06cM7U7xDGmYwNG93LVnxwxjk yGQYCd08t3lHobjxX/OigDGQOIiVUN5rGO3B5zfVpnsdsF0/474T9aStD4uEKVG9P9yTThxC66Ku Xb0HO3W8nbMwgkUuW83PKbk25YSnvgtxKKcMIJ7ptgUxRg53TuCt4QJNIvyoxb4710Nl6KAZZ+9r UkyLOOkgJ9eTXvOC4trOptRiSOXsXUvIrRE5GjPyemA1C42LxG/ptR7/wXtI2C8QBYsWIMCVBHpa 7Qj+JYN6Crh9DXUDEtWWsjsNUWDlGPaDR+Aes7asAZpVFyfMODodi5MLJiAvrVIiQFNhc8S+HKYI 1vbaqYoREZsvVKq8YZ9/SG1CqFB/T9oOuGliwtRkR+GX5UQPXdpKZF7ITlSXoP8r3OOc9CaULF46 7VT2rSAdw3oKkBNp3q2CTUjaBEkZvVwfNyBf8N9Cj3+++mTSKn34bbFRlO1kXUycpLT8XjuR2au2 vXjeilQq2Qb31qklcVekvgO5ge3Iu/DWvQSnovmZV/iKI4Qq8lKVZU757KiUYziXyuXG4Z+FT7fy UhTxDKdOQwQquEi4jLe86t14bfTnkAn7W6VlJXtsnkdl1her2dsH1gtu4R2VkYfnELRpqCZGYewS zF6qDSUBpQp9p69drFuEpAhhs7hKCCLwHYF1mz4X0cGLGMLXeUePcCTb5ERze+93N2yPxSNA2bRk WbJQMsEazexAznFikUFGnvKVJnFQQaAnDicXOB0lxU/TKjOssk5IMwdmSU/MN6mG9OgEfwYjdW8p pBMOL6KehsbCb0/0wF8xekzsVEvRMrw5DdwH1AXXXLvYNFIciWrFfcvTzpdI3AEG059XQScJKPzR NNUExGTx4glCpE93OnKG9eRDP2/Ogb+c8D2oYTsY8dUpTw48b2MGkvEkgszLgRqa1sRnErSRPh8z fPP2CFl7xGIrJ5fPg33HFhWuygEwwwWe3xXNBQ8NJdm4Pscvb9y1CBweR1aEOEmF+7+XwJhp74Ne BZS/7a9ATcUMpAEntM8yKElR+Y84QVlpY/2Olap60rnP5huMjJeWSwzfzlDTegaelgiu9QvTToG3 X/ekOoQKVaL7/+VCcmuF/Q== 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 086cac18ebca..a2cecbec9b8e 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -2910,38 +2910,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 6 17:17:12 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: 10670875 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 6C5B71803 for ; Tue, 6 Nov 2018 17:18:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 525722AA27 for ; Tue, 6 Nov 2018 17:18:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 46E862AA2E; Tue, 6 Nov 2018 17:18: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 41BE82AA27 for ; Tue, 6 Nov 2018 17:18:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389281AbeKGCpE (ORCPT ); Tue, 6 Nov 2018 21:45:04 -0500 Received: from com-out001.mailprotect.be ([83.217.72.83]:57659 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389286AbeKGCpE (ORCPT ); Tue, 6 Nov 2018 21:45:04 -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=y1zijoD7V1EOZ6JexeXVLLM32qYX1FHnjcFM9Rj7q7U=; b=EIfnSQuhJGJr xuaZbfCzT8zOjpJMd2IhHUc39O1bNmipKCD2tOjKExtkXn+2/TjgL42YLCboJXmwist+Yc8DNXmED d+PmtE0BBo7nhdAHU8UYYeQ3aWfHJ428mLo3en6BfF3r5R+6rNJeONvNOT8nHRynpUQgYBdvFWDEa ITBdd19T02B9ZJGaF0IFqb2wkZJZVAeCATtvSCs2b9kXy82f5+vA5yrQ9NgpYyEsypQ/XCxBCwwen L4ye9LM50D/q/B3b4HVzmPDCErjQ0hrCcako5qGnVHV3TpGZR2fknhuHnMsHDoocAA8RchK1Dx5zv jEj4JEU3KesN40tAw1rUfQ==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gK4zr-000CLa-Vz; Tue, 06 Nov 2018 18:18: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 13846C0C8A; Tue, 6 Nov 2018 18:18:31 +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 04/10] target/core: Make sure that target_wait_for_sess_cmds() waits long enough Date: Tue, 6 Nov 2018 09:17:12 -0800 Message-Id: <20181106171718.89594-5-bvanassche@acm.org> X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-goog In-Reply-To: <20181106171718.89594-1-bvanassche@acm.org> References: <20181106171718.89594-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: SB/global_tokens (0.00184631991759) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5oTkgpwpCqOOjiMhDH1K5vp602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTagCTS5H5Pie2sCQ3gGSzr06cM7U7xDGmYwNG93LVnxwxjk yGQYCd08t3lHobjxX/OigDGQOIiVUN5rGO3B5zfVpnsdsF0/474T9aStD4uEKVG9P9yTThxC66Ku Xb0HO3W8nbMwgkUuW83PKbk25YSnvgtxKKcMIJ7ptgUxRg53TuCt4QJNIvyoxb4710Nl6KAZZ+9r UkyLOOkgJ9eTXvOC4trOptRiSOXsXUvIrRE5Gn9IoDI3FwcKOGmPp98nE8JI2C8QBYsWIMCVBHpa 7Qj+JYN6Crh9DXUDEtWWsjsNUWDlGPaDR+Aes7asAZpVFyfMODodi5MLJiAvrVIiQFNhc8S+HKYI 1vbaqYoREZsvVKq8YZ9/SG1CqFB/T9oOuGliwtRkR+GX5UQPXdpKZF7ITlSXoP8r3OOc9CaULF46 7VT2rSAdw3oKkBNp3q2CTUjaBEkZvVwfNyBf8N9Cj3+++mTSKn34bbFRlO1kXUycpH0i0CUyLQvl 9O+c0636VhIifL76GD10kuo3nOZaoX+g3LKzgLvGn75f1GdWNx/7rKBnyF5Al8KyqkBC47VmroNn IKDFkcg0DoDn7tP2jpvLswQ+LrsRjP8UUIXm0+DPmv7PKPGj8NXeGCulL/QJEqN6EipRzMVZ5Lqw Tx7Vvn9S5OBZ87WmFyXBm/oIAtLmOrCBf5k3qwLPOJPnfDsxRzB+BCXXJcb4hoyR6yACXgxi1tj3 tnRFP71SNe8OabONmAeYUOp7A73HI6oJg7w/Vocy7+Ttx50kPf/opRnU1TyFH6IJwoZKvMkvY/jz 9IkVzN59uTrDo5OUYDGpGZVhMc74agj+RX0dbSrc5Jkf/lehMDRcCgYQIezXimM8MMGBqePpnOc1 Yjsvm51FfilkyeTjx6VdUzwc6VGfl9kqYqrqKK10ONaLwqjc31fO80X8Z+zAFWmAK6L8pLjYAyx9 cPRwc/tu2n0gQeKRgdo8fP/wbsmG5LlZyL0etItIQ47Q9ScHL8+lTGBIVE9xbEkX79tiWrQqR9OH b3+AhBHyQJhMoK6//HisH+Inv79AsPwENh1/rxbQicf/5tMwo2bfwwdcWaJjyTNTJd/rBV6qRhfQ Ewne7W7yM4pg5t5Ye8wOsvdQwaaQ0m5yz9ncfoPJBe4xL7hrJSk60SF3F6RYOYr2 X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 a2cecbec9b8e..3c4335e56f08 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; @@ -577,6 +591,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); @@ -2715,6 +2730,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); @@ -2745,8 +2761,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); } @@ -2754,6 +2768,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); } /** @@ -2882,6 +2898,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); @@ -2896,17 +2914,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 6 17:17:13 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: 10670881 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 682FC1803 for ; Tue, 6 Nov 2018 17:18:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 50AB52AA83 for ; Tue, 6 Nov 2018 17:18:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4553A2AA7C; Tue, 6 Nov 2018 17:18:58 +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 C0C2B2AA82 for ; Tue, 6 Nov 2018 17:18:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389353AbeKGCpJ (ORCPT ); Tue, 6 Nov 2018 21:45:09 -0500 Received: from com-out001.mailprotect.be ([83.217.72.83]:33251 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389286AbeKGCpI (ORCPT ); Tue, 6 Nov 2018 21:45:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=mS9CaVCmSVQVErO2OBdyeZpkd1dUuad5HSd2p+wPTj8=; b=j/FHd1CyYbhM fwBLKj+CrpoBoNY8fdupcqyBd+nXy+0LAHWNU6A1ABGIhbLN2POs0L9AasC1bDfwaUTpbOKrURK+/ ZUy/dQC6mX7ilb7NYaCWbV43Xu+9RHhiqCEDAe8p9iHSFBsUZmxYBSJ7uidYuamwdohZzi+HvX02p wK47r/4J/XQlGNoU6z4ig9KlS1qz2N7fXPHvMt0G0YzynMpAytZRysSDVfl8bjVGFjUgB5hdCrb6Y AWwF2I9TO1teXz7vJLdsD8oAG2Fu7GYo6FG52Qs0KvjEjIizQGvIxcXcUYGvxCQeuSvJWzQMV99Yf HYlOkvMVDSYHWXG4/xwghw==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gK4zu-000CIm-1I; Tue, 06 Nov 2018 18:18:38 +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 2E264C030B; Tue, 6 Nov 2018 18:18: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 05/10] target/core: Use system workqueues for TMF Date: Tue, 6 Nov 2018 09:17:13 -0800 Message-Id: <20181106171718.89594-6-bvanassche@acm.org> X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-goog In-Reply-To: <20181106171718.89594-1-bvanassche@acm.org> References: <20181106171718.89594-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: Combined (0.01) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5o1PGANeTM2nkqmURV8Ej/N602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTagCTS5H5Pie2sCQ3gGSzr06cM7U7xDGmYwNG93LVnxwxjk yGQYCd08t3lHobjxX/OigDGQOIiVUN5rGO3B5zfVpnsdsF0/474T9aStD4uEKVG9P9yTThxC66Ku Xb0HO3W8nbMwgkUuW83PKbk25YSnvgtxKKcMIJ7ptgUxRg53TuCt4QJNIvyoxb4710Nl6KAZZ+9r UkyLOOkgJ9eTXvOC4trOptRiSOXsXUvIrRE5GsPaOUOqBESO6HCHyr/OInVI2C8QBYsWIMCVBHpa 7Qj+JYN6Crh9DXUDEtWWsjsNUWDlGPaDR+Aes7asAZpVFyfMODodi5MLJiAvrVIiQFNhc8S+HKYI 1vbaqYoREZsvVKq8YZ9/SG1CqFB/T9oOuGliwtRkR+GX5UQPXdpKZF7ITlSXoP8r3OOc9CaULF46 7VT2rSAdw3oKkBNp3q2CTUjaBEkZvVwfNyBf8N9Cj3+++mTSKn34bbFRlO1kXUycpLT8XjuR2au2 vXjeilQq2Qb31qklcVekvgO5ge3Iu/DWvQSnovmZV/iKI4Qq8lKVZU757KiUYziXyuXG4Z+FT7fy UhTxDKdOQwQquEi4jLe86t14bfTnkAn7W6VlJXtsnkdl1her2dsH1gtu4R2VkYfnELRpqCZGYewS zF6qDSUBpQp9p69drFuEpAhhs7hKCCLwHYF1mz4X0cGLGMLXeUcb2iuu8cPRTO726D+h/H2J2bRk WbJQMsEazexAznFikUFGnvKVJnFQQaAnDicXOB0lxU/TKjOssk5IMwdmSU/MN6mG9OgEfwYjdW8p pBMOL6KehsbCb0/0wF8xekzsVEvRMrw5DdwH1AXXXLvYNFIciWrFfcvTzpdI3AEG059XQcqecphG M7rTkZocCVec5dx3OnKG9eRDP2/Ogb+c8D2oYTsY8dUpTw48b2MGkvEkgszLgRqa1sRnErSRPh8z fPP2CFl7xGIrJ5fPg33HFhWuygEwwwWe3xXNBQ8NJdm4Pscvb9y1CBweR1aEOEmF+7+XwJhp74Ne BZS/7a9ATcUMpAEntM8yKElR+Y84QVlpY/2Olap60rnP5huMjJeWSwzfzlDTegaelgiu9QvTToG3 X/ekOoQKVaL7/+VCcmuF/Q== 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 3c4335e56f08..cf76d3709683 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -3411,7 +3411,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 6 17:17:14 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: 10670887 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 344E415E9 for ; Tue, 6 Nov 2018 17:19:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1AA6C2AA47 for ; Tue, 6 Nov 2018 17:19:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F24D2AA75; Tue, 6 Nov 2018 17:19:00 +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 9A2C42AA47 for ; Tue, 6 Nov 2018 17:18:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389519AbeKGCpL (ORCPT ); Tue, 6 Nov 2018 21:45:11 -0500 Received: from com-out001.mailprotect.be ([83.217.72.83]:52995 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389427AbeKGCpK (ORCPT ); Tue, 6 Nov 2018 21:45:10 -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=8FcVWB3KfbF1yKBYxU9smvFVwHsJDykRDK19y0SGaiw=; b=rUuHkIKWPdkp oNgiarc4nqG7p2DIjQQSAvsVKRSvKTs0sJqtK58o0GDxiYddNPTotCkLRhf9W2i3Qq7IF1kC8maD0 KxhG/V+UC0bGi9qULc7+PsSY/inK0TfSFg633qbfbv1DxcTrW8dqfKePqpnlf5vWQuJD8RnagUaoO /cXCupZlkrEpSe/l3Z2CePvqfxAD5faylGneXbm8A93I/eSOzDNLyOYdC9Lfl+x9EZ4xisbu9CoPg X0RB61Kf1KjuA2o9E9ukK4VAbRjS9n3O1ZRMEjjsT020ObukReb9aVDVKemB1ptoYFd1hZCrmA13y Rd5OlnLYu+1LUPjInAGqJw==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gK4zv-000CIm-VX; Tue, 06 Nov 2018 18:18: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 3F939C030B; Tue, 6 Nov 2018 18:18: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 06/10] target/core: Make it possible to wait from more than one context for command completion Date: Tue, 6 Nov 2018 09:17:14 -0800 Message-Id: <20181106171718.89594-7-bvanassche@acm.org> X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-goog In-Reply-To: <20181106171718.89594-1-bvanassche@acm.org> References: <20181106171718.89594-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: Combined (0.02) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5h4yBsmlnnBJoMXqhaOfSvp602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTagCTS5H5Pie2sCQ3gGSzr06cM7U7xDGmYwNG93LVnxwxjk yGQYCd08t3lHobjxX/OigDGQOIiVUN5rGO3B5zfVpnsdsF0/474T9aStD4uEKVG9P9yTThxC66Ku Xb0HO3W8nbMwgkUuW83PKbk25YSnvgtxKKcMIJ7ptgUxRg53TuCt4QJNIvyoxb4710Nl6KAZZ+9r UkyLOOkgJ9eTXvOC4trOptRiSOXsXUvIrRE5Ggoe/DV2oPXhZ7pdjjqefgNI2C8QBYsWIMCVBHpa 7Qj+JYN6Crh9DXUDEtWWsjsNUWDlGPaDR+Aes7asAZpVFyfMODodi5MLJiAvrVIiQFNhc8S+HKYI 1vbaqYoREZsvVKq8YZ9/SG1CqFB/T9oOuGliwtRkR+GX5UQPXdpKZF7ITlSXoP8r3OOc9CaULF46 7VT2rSAdw3oKkBNp3q2CTUjaBEkZvVwfNyBf8N9Cj3+++mTSKn34bbFRlO1kXUycpLT8XjuR2au2 vXjeilQq2Qb31qklcVekvgO5ge3Iu/DWvQSnovmZV/iKI4Qq8lKVZU757KiUYziXyuXG4Z+FT7fy UhTxDKdOQwQquEi4jLe86t14bfTnkAn7W6VlJXtsnkdl1her2dsH1gtu4R2VkYfnELRpqCZGYewS zF6qDSUBpQp9p69drFuEpAhhs7hKCCLwHYF1mz4X0cGLGMLXeUdcgrWhoUCxFIlUEwmScwps2bRk WbJQMsEazexAznFikUFGnvKVJnFQQaAnDicXOB0lxU/TKjOssk5IMwdmSU/MN6mG9OgEfwYjdW8p pBMOL6KehsbCb0/0wF8xekzsVEvRMrw5DdwH1AXXXLvYNFIciWrFfcvTzpdI3AEG059XQWKWM7hT 1imMJXURUzLK6N93OnKG9eRDP2/Ogb+c8D2oYTsY8dUpTw48b2MGkvEkgszLgRqa1sRnErSRPh8z fPP2CFl7xGIrJ5fPg33HFhWuygEwwwWe3xXNBQ8NJdm4Pscvb9y1CBweR1aEOEmF+7+XwJhp74Ne BZS/7a9ATcUMpAEntM8yKElR+Y84QVlpY/2Olap60rnP5huMjJeWSwzfzlDTegaelgiu9QvTToG3 X/ekOoQKVaL7/+VCcmuF/Q== 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 cf76d3709683..7b77520a2b35 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -1327,7 +1327,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); @@ -2688,7 +2689,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) { @@ -2755,7 +2756,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) { @@ -2766,8 +2768,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 6 17:17:15 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: 10670873 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 B8D1915E9 for ; Tue, 6 Nov 2018 17:18:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F2092AA2B for ; Tue, 6 Nov 2018 17:18:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9316A2AA2E; Tue, 6 Nov 2018 17:18:53 +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 1BF942AA20 for ; Tue, 6 Nov 2018 17:18:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389303AbeKGCpE (ORCPT ); Tue, 6 Nov 2018 21:45:04 -0500 Received: from com-out001.mailprotect.be ([83.217.72.83]:42819 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389281AbeKGCpE (ORCPT ); Tue, 6 Nov 2018 21:45:04 -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=D/hbiJfMzigm+V9lBjIbqr0uRPeE5Z64IWYkVFE2OtI=; b=Dr/R0w1EejOG v+15h9E1KBRlduAp6Gt+myeiIQVgrfO4WURXth2bmng2djmPav/yBAZPxwjNnZXfBA444om9mwsnG 8F9VSegDGsXJALEscGMGAyJm9/KvxjBm4Ggfonu6C+0PVEORI3KgEmrNOP5y2lGtDltFtMEexsqfr mYRILVG70gmYOD4U/61p6GlXrvqM83nK3qZyJzaMHUV/tQoYcLOWLTMUV4AC4IPKP3vbxSuSpTp8g wqK28kkstItYTqSiOzqnMmhTyIhodH39rwHIcihQxHSjy1K3SGtiw4q5u42jhplJi2WEQJC5kZt4s 2ojjy8GisUhsPhT7ffxLpA==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gK4zx-000CLa-TW; Tue, 06 Nov 2018 18:18:42 +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 2F3D7C030B; Tue, 6 Nov 2018 18:18: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 07/10] target/core: Simplify the code for aborting SCSI commands Date: Tue, 6 Nov 2018 09:17:15 -0800 Message-Id: <20181106171718.89594-8-bvanassche@acm.org> X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-goog In-Reply-To: <20181106171718.89594-1-bvanassche@acm.org> References: <20181106171718.89594-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: Combined (0.04) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5oVSXQ0s+/7WZoUPSz3EBHl602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTagCTS5H5Pie2sCQ3gGSzr06cM7U7xDGmYwNG93LVnxwxjk yGQYCd08t3lHobjxX/OigDGQOIiVUN5rGO3B5zfVpnsdsF0/474T9aStD4uEKVG9P9yTThxC66Ku Xb0HO3W8nbMwgkUuW83PKbk25YSnvgtxKKcMIJ7ptgUxRg53TuCt4QJNIvyoxb4710Nl6KAZZ+9r UkyLOOkgJ9eTXvOC4trOptRiSOXsXUvIrRE5Gi64E/luATX2C15uIo03jxlI2C8QBYsWIMCVBHpa 7Qj+JYN6Crh9DXUDEtWWsjsNUWDlGPaDR+Aes7asAZpVFyfMODodi5MLJiAvrVIiQFNhc8S+HKYI 1vbaqYoREZsvVKq8YZ9/SG1CqFB/T9oOuGliwtRkR+GX5UQPXdpKZF7ITlSXoP8r3OOc9CaULF46 7VT2rSAdw3oKkBNp3q2CTUjaBEkZvVwfNyBf8N9Cj3+++mTSKn34bbFRlO1kXUycpLT8XjuR2au2 vXjeilQq2Qb31qklcVekvgO5ge3Iu/DWvQSnovmZV/iKI4Qq8lKVZU757KiUYziXyuXG4Z+FT7fy UhTxDKdOQwQquEi4jLe86t14bfTnkAn7W6VlJXtsnkdl1her2dsH1gtu4R2VkYfnELRpqCZGYewS zF6qDSUBpQp9p69drFuEpAhhs7hKCCLwHYF1mz4X0cGLGMLXeUelyYvxOs9QGp7DuNSpjNB+2bRk WbJQMsEazexAznFikUFGnvKVJnFQQaAnDicXOB0lxU/TKjOssk5IMwdmSU/MN6mG9OgEfwYjdW8p pBMOL6KehsbCb0/0wF8xekzsVEvRMrw5DdwH1AXXXLvYNFIciWrFfcvTzpdI3AEG059XQUt63dWQ TTh3AT6Ut54lNDJ3OnKG9eRDP2/Ogb+c8D2oYTsY8dUpTw48b2MGkvEkgszLgRqa1sRnErSRPh8z fPP2CFl7xGIrJ5fPg33HFhWuygEwwwWe3xXNBQ8NJdm4Pscvb9y1CBweR1aEOEmF+7+XwJhp74Ne BZS/7a9ATcUMpAEntM8yKElR+Y84QVlpY/2Olap60rnP5huMjJeWSwzfzlDTegaelgiu9QvTToG3 X/ekOoQKVaL7/+VCcmuF/Q== 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 7b77520a2b35..34cfd6a83505 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -2583,7 +2583,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); @@ -3296,25 +3297,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 6 17:17:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10670879 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0E96D17D4 for ; Tue, 6 Nov 2018 17:18:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E7A1C2AA73 for ; Tue, 6 Nov 2018 17:18:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DC55C2AA83; Tue, 6 Nov 2018 17:18:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 19A312AA73 for ; Tue, 6 Nov 2018 17:18:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389483AbeKGCpI (ORCPT ); Tue, 6 Nov 2018 21:45:08 -0500 Received: from out002.mailprotect.be ([83.217.72.86]:48983 "EHLO out002.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389309AbeKGCpI (ORCPT ); Tue, 6 Nov 2018 21:45:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=yWF5+NzcYaLyiKWg98mSp9F/1FQM6edO1yzazlO6fkw=; b=fGrPcRBxDA5i TC5vy7U3VZ7ViGavuTj5udvzwEYr2Gx2vynEU7UTOVT9KTBOvzfN3PvMD4BfUKUbpm4PZ/He38Djs LLQZdYTHe6ywCwvAYqxdSjN+vkTqiM5U/kEUcFZMsFNnxI5Qc2tQu6Fkmv4se7a7cShzVhvzQyhJr NLVutTsnCq/pviDcoWieVKyC6myIXqu1OuSj8tI//Mw9zcN5XqghEG81V4SZ73+kRm3EtgwmBl4iz jNhOb2O3mqRZUNx86tQXyq20LFVyQiHUNDxjhEb9JVIiPMyNwa39UoaYW9fQsuz/X+HesxRMKhbnO zbOGPEOFO3j7G8skBXSFEg==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out002.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gK502-0003KB-8U; Tue, 06 Nov 2018 18:18:47 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id 20858C030B; Tue, 6 Nov 2018 18:18:39 +0100 (CET) From: Bart Van Assche To: "Martin K . Petersen" Cc: Christoph Hellwig , target-devel@vger.kernel.org, Bart Van Assche , Nicholas Bellinger , Mike Christie , David Disseldorp , Hannes Reinecke Subject: [PATCH 08/10] target/core: Fix TAS handling for aborted commands Date: Tue, 6 Nov 2018 09:17:16 -0800 Message-Id: <20181106171718.89594-9-bvanassche@acm.org> X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-goog In-Reply-To: <20181106171718.89594-1-bvanassche@acm.org> References: <20181106171718.89594-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: SB/global_tokens (0.00634592035284) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5n8r70X09Xaud/87FEzDXLJ602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTagCTS5H5Pie2sCQ3gGSzr06cM7U7xDGmYwNG93LVnxwxjk yGQYCd08t3lHobjxX/OigDGQOIiVUN5rGO3B5zfVpnsdsF0/474T9aStD4uEKVG9P9yTThxC66Ku Xb0HO3W8nbMwgkUuW83PKbk25YSnvgtxKKcMIJ7ptgUxRg53TuCt4QJNIvyoxb4710Nl6KAZZ+9r UkyLOOkgJ9eTXvOC4trOptRiSOXsXUvIrRE5GvzrnIZnvex9ONaKBybTnm9I2C8QBYsWIMCVBHpa 7Qj+JYN6Crh9DXUDEtWWsjsNUfobM/P6vznYRdd5hfgiYzLMODodi5MLJiAvrVIiQFNhc8S+HKYI 1vbaqYoREZsvVKq8YZ9/SG1CqFB/T9oOuGliwtRkR+GX5UQPXdpKZF7ITlSXoP8r3OOc9CaULF46 7VT2rSAdw3oKkBNp3q2CTUjaBEkZvVwfNyBf8N9Cj3+++mTSKn34bbFRlO1kXUycpH0i0CUyLQvl 9O+c0636VhIifL76GD10kuo3nOZaoX+g3LKzgLvGn75f1GdWNx/7rKBnyF5Al8KyqkBC47VmroNn IKDFkcg0DoDn7tP2jpvLswQ+LrsRjP8UUIXm0+DPmv7PKPGj8NXeGCulL/QJEqN6EipRzMVZ5Lqw Tx7Vvn9S5OBZ87WmFyXBm/oIAtLmOrCBf5k3qwLPOJPnfDsxRzDQNyioppyJmMAgZEU7lOctlNXB CyoXqWZ9fgj+yLApDgeYUOp7A73HI6oJg7w/Vocy7+Ttx50kPf/opRnU1TyFH6IJwoZKvMkvY/jz 9IkVzN59uTrDo5OUYDGpGZVhMc74agj+RX0dbSrc5Jkf/lehMDRcCgYQIezXimM8MMGBqePpnOc1 Yjsvm51FfilkyeQh1W1MhmkBfqnHNZtJFrg2D22m1Led9vQBeL77Ic6CMOzAFWmAK6L8pLjYAyx9 cPRwc/tu2n0gQeKRgdo8fP/wbsmG5LlZyL0etItIQ47Q9ScHL8+lTGBIVE9xbEkX79tiWrQqR9OH b3+AhBHyQJhMoK6//HisH+Inv79AsPwENh1/rxbQicf/5tMwo2bfwwdcWaJjyTNTJd/rBV6qRhfQ Ewne7W7yM4pg5t5Ye8wOsvdQwaaQ0m5yz9ncfoPJBe4xL7hrJSk60SF3F6RYOYr2 X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The TASK ABORTED STATUS (TAS) bit is defined as follows in SAM: "TASK_ABORTED: this status shall be returned if a command is aborted by a command or task management function on another I_T nexus and the control mode page TAS bit is set to one". TAS handling is spread over the target core and the iSCSI target driver. If a LUN RESET is received, the target core will send the TASK_ABORTED response for all commands for which such a response has to be sent. If an ABORT TASK is received, only the iSCSI target driver will send the TASK_ABORTED response for the commands for which that response has to be sent. That is a bug since all target drivers have to honor the TAS bit. Fix this by moving the code that handles TAS from the iSCSI target driver into the target core. Additionally, if a command has been aborted, instead of sending the TASK_ABORTED status from the context that processes the SCSI command send it from the context of the ABORT TMF. The core_tmr_abort_task() change in this patch causes the CMD_T_TAS flag to be set if a TASK_ABORTED status has to be sent back to the initiator that submitted the command. If that flag has been set transport_cmd_finish_abort() will send the TASK_ABORTED response. Cc: Nicholas Bellinger Cc: Mike Christie Cc: Christoph Hellwig Cc: David Disseldorp Cc: Hannes Reinecke Signed-off-by: Bart Van Assche --- drivers/target/iscsi/iscsi_target.c | 11 ++--- drivers/target/iscsi/iscsi_target_erl1.c | 28 ++---------- drivers/target/target_core_tmr.c | 3 +- drivers/target/target_core_transport.c | 55 +----------------------- include/target/target_core_base.h | 1 - include/target/target_core_fabric.h | 1 - 6 files changed, 10 insertions(+), 89 deletions(-) diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c index c1d5a173553d..984941e036c8 100644 --- a/drivers/target/iscsi/iscsi_target.c +++ b/drivers/target/iscsi/iscsi_target.c @@ -1493,8 +1493,6 @@ __iscsit_check_dataout_hdr(struct iscsi_conn *conn, void *buf, if (hdr->flags & ISCSI_FLAG_CMD_FINAL) iscsit_stop_dataout_timer(cmd); - transport_check_aborted_status(se_cmd, - (hdr->flags & ISCSI_FLAG_CMD_FINAL)); return iscsit_dump_data_payload(conn, payload_length, 1); } } else { @@ -1509,12 +1507,9 @@ __iscsit_check_dataout_hdr(struct iscsi_conn *conn, void *buf, * TASK_ABORTED status. */ if (se_cmd->transport_state & CMD_T_ABORTED) { - if (hdr->flags & ISCSI_FLAG_CMD_FINAL) - if (--cmd->outstanding_r2ts < 1) { - iscsit_stop_dataout_timer(cmd); - transport_check_aborted_status( - se_cmd, 1); - } + if (hdr->flags & ISCSI_FLAG_CMD_FINAL && + --cmd->outstanding_r2ts < 1) + iscsit_stop_dataout_timer(cmd); return iscsit_dump_data_payload(conn, payload_length, 1); } diff --git a/drivers/target/iscsi/iscsi_target_erl1.c b/drivers/target/iscsi/iscsi_target_erl1.c index a211e8154f4c..1b54a9c70851 100644 --- a/drivers/target/iscsi/iscsi_target_erl1.c +++ b/drivers/target/iscsi/iscsi_target_erl1.c @@ -943,20 +943,8 @@ int iscsit_execute_cmd(struct iscsi_cmd *cmd, int ooo) return 0; } spin_unlock_bh(&cmd->istate_lock); - /* - * Determine if delayed TASK_ABORTED status for WRITEs - * should be sent now if no unsolicited data out - * payloads are expected, or if the delayed status - * should be sent after unsolicited data out with - * ISCSI_FLAG_CMD_FINAL set in iscsi_handle_data_out() - */ - if (transport_check_aborted_status(se_cmd, - (cmd->unsolicited_data == 0)) != 0) + if (cmd->se_cmd.transport_state & CMD_T_ABORTED) return 0; - /* - * Otherwise send CHECK_CONDITION and sense for - * exception - */ return transport_send_check_condition_and_sense(se_cmd, cmd->sense_reason, 0); } @@ -974,13 +962,7 @@ int iscsit_execute_cmd(struct iscsi_cmd *cmd, int ooo) if (!(cmd->cmd_flags & ICF_NON_IMMEDIATE_UNSOLICITED_DATA)) { - /* - * Send the delayed TASK_ABORTED status for - * WRITEs if no more unsolicitied data is - * expected. - */ - if (transport_check_aborted_status(se_cmd, 1) - != 0) + if (cmd->se_cmd.transport_state & CMD_T_ABORTED) return 0; iscsit_set_dataout_sequence_values(cmd); @@ -995,11 +977,7 @@ int iscsit_execute_cmd(struct iscsi_cmd *cmd, int ooo) if ((cmd->data_direction == DMA_TO_DEVICE) && !(cmd->cmd_flags & ICF_NON_IMMEDIATE_UNSOLICITED_DATA)) { - /* - * Send the delayed TASK_ABORTED status for WRITEs if - * no more nsolicitied data is expected. - */ - if (transport_check_aborted_status(se_cmd, 1) != 0) + if (cmd->se_cmd.transport_state & CMD_T_ABORTED) return 0; iscsit_set_unsoliticed_dataout(cmd); diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c index 6d1179a7f043..bca0f8a25f92 100644 --- a/drivers/target/target_core_tmr.c +++ b/drivers/target/target_core_tmr.c @@ -165,7 +165,8 @@ void core_tmr_abort_task( printk("ABORT_TASK: Found referenced %s task_tag: %llu\n", se_cmd->se_tfo->get_fabric_name(), ref_tag); - if (!__target_check_io_state(se_cmd, se_sess, 0)) + if (!__target_check_io_state(se_cmd, se_sess, + dev->dev_attrib.emulate_tas)) continue; spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 34cfd6a83505..b42187f69eea 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -1804,7 +1804,7 @@ void transport_generic_request_failure(struct se_cmd *cmd, if (cmd->transport_complete_callback) cmd->transport_complete_callback(cmd, false, &post_ret); - if (transport_check_aborted_status(cmd, 1)) + if (cmd->transport_state & CMD_T_ABORTED) return; switch (sense_reason) { @@ -2011,8 +2011,6 @@ static bool target_handle_task_attr(struct se_cmd *cmd) return true; } -static int __transport_check_aborted_status(struct se_cmd *, int); - void target_execute_cmd(struct se_cmd *cmd) { /* @@ -2022,7 +2020,7 @@ void target_execute_cmd(struct se_cmd *cmd) * If the received CDB has already been aborted stop processing it here. */ spin_lock_irq(&cmd->t_state_lock); - if (__transport_check_aborted_status(cmd, 1)) { + if (cmd->transport_state & CMD_T_ABORTED) { spin_unlock_irq(&cmd->t_state_lock); return; } @@ -3236,55 +3234,6 @@ transport_send_check_condition_and_sense(struct se_cmd *cmd, } EXPORT_SYMBOL(transport_send_check_condition_and_sense); -static int __transport_check_aborted_status(struct se_cmd *cmd, int send_status) - __releases(&cmd->t_state_lock) - __acquires(&cmd->t_state_lock) -{ - int ret; - - assert_spin_locked(&cmd->t_state_lock); - WARN_ON_ONCE(!irqs_disabled()); - - if (!(cmd->transport_state & CMD_T_ABORTED)) - return 0; - /* - * If cmd has been aborted but either no status is to be sent or it has - * already been sent, just return - */ - if (!send_status || !(cmd->se_cmd_flags & SCF_SEND_DELAYED_TAS)) { - if (send_status) - cmd->se_cmd_flags |= SCF_SEND_DELAYED_TAS; - return 1; - } - - pr_debug("Sending delayed SAM_STAT_TASK_ABORTED status for CDB:" - " 0x%02x ITT: 0x%08llx\n", cmd->t_task_cdb[0], cmd->tag); - - cmd->se_cmd_flags &= ~SCF_SEND_DELAYED_TAS; - cmd->scsi_status = SAM_STAT_TASK_ABORTED; - trace_target_cmd_complete(cmd); - - spin_unlock_irq(&cmd->t_state_lock); - ret = cmd->se_tfo->queue_status(cmd); - if (ret) - transport_handle_queue_full(cmd, cmd->se_dev, ret, false); - spin_lock_irq(&cmd->t_state_lock); - - return 1; -} - -int transport_check_aborted_status(struct se_cmd *cmd, int send_status) -{ - int ret; - - spin_lock_irq(&cmd->t_state_lock); - ret = __transport_check_aborted_status(cmd, send_status); - spin_unlock_irq(&cmd->t_state_lock); - - return ret; -} -EXPORT_SYMBOL(transport_check_aborted_status); - void transport_send_task_abort(struct se_cmd *cmd) { unsigned long flags; diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h index bff51baee7e0..31358b0403c8 100644 --- a/include/target/target_core_base.h +++ b/include/target/target_core_base.h @@ -134,7 +134,6 @@ enum se_cmd_flags_table { SCF_SENT_CHECK_CONDITION = 0x00000800, SCF_OVERFLOW_BIT = 0x00001000, SCF_UNDERFLOW_BIT = 0x00002000, - SCF_SEND_DELAYED_TAS = 0x00004000, SCF_ALUA_NON_OPTIMIZED = 0x00008000, SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC = 0x00020000, SCF_COMPARE_AND_WRITE = 0x00080000, diff --git a/include/target/target_core_fabric.h b/include/target/target_core_fabric.h index 6859277fc409..3c100c1f3173 100644 --- a/include/target/target_core_fabric.h +++ b/include/target/target_core_fabric.h @@ -161,7 +161,6 @@ void target_execute_cmd(struct se_cmd *cmd); int transport_generic_free_cmd(struct se_cmd *, int); bool transport_wait_for_tasks(struct se_cmd *); -int transport_check_aborted_status(struct se_cmd *, int); int transport_send_check_condition_and_sense(struct se_cmd *, sense_reason_t, int); int target_get_sess_cmd(struct se_cmd *, bool); From patchwork Tue Nov 6 17:17:17 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: 10670883 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 9B6ED15E9 for ; Tue, 6 Nov 2018 17:18:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 80FF82AA75 for ; Tue, 6 Nov 2018 17:18:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 758082AA82; Tue, 6 Nov 2018 17:18:58 +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 51D102AA75 for ; Tue, 6 Nov 2018 17:18:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389309AbeKGCpI (ORCPT ); Tue, 6 Nov 2018 21:45:08 -0500 Received: from out002.mailprotect.be ([83.217.72.86]:57461 "EHLO out002.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389353AbeKGCpI (ORCPT ); Tue, 6 Nov 2018 21:45:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=/L4tQ7m0chuqH0Nx23gUN++QThb0aP1vtoPrm12Z9aU=; b=nN5MWN0PIYD9 s6/Z/YOsOSEu5usix06y5vg7jS8/h0bO4B1+N1GNbQnHiC30BdLjBmSnK4745nc9Q682zVCUXL0G3 U5nr+Lkvt9gGFTpoiniDVQLolPU4aCC7KDypVEIfsTy1lHGAJ5DpUNZAl+l5bZJxvnsUCOD6U842K x6c7J5CnO8bUICtGCH6Eu5BsXg5EeJa6O0ARrWSpno4lcvamRLSCfzUy0j+vCru/uMG9XSLA5V+lp /IeRR2pIQw+Fsyb1A6UXFpT3DDm0tzt0H1q2eB/TrdX4xSdS0BtMo07QwDNqxlr2xN6tIXouYQ3ES xUNwk07BEvEfdNzYvLdZ1Q==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out002.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gK502-0003Km-8U; Tue, 06 Nov 2018 18:18:47 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id 11025C0C8A; Tue, 6 Nov 2018 18:18:41 +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 09/10] target/core: Make ABORT and LUN RESET handling synchronous Date: Tue, 6 Nov 2018 09:17:17 -0800 Message-Id: <20181106171718.89594-10-bvanassche@acm.org> X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-goog In-Reply-To: <20181106171718.89594-1-bvanassche@acm.org> References: <20181106171718.89594-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: SB/global_tokens (0.000893333323619) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5thFfTLeYqfNR3AHLoagjXB602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTagCTS5H5Pie2sCQ3gGSzr06cM7U7xDGmYwNG93LVnxwxjk yGQYCd08t3lHobjxX/OigDGQOIiVUN5rGO3B5zfVpnsdsF0/474T9aStD4uEKVG9P9yTThxC66Ku Xb0HO3W8nbMwgkUuW83PKbk25YSnvgtxKKcMIJ7ptgUxRg53TuCt4QJNIvyoxb4710Nl6KAZZ+9r UkyLOOkgJ9eTXvOC4trOptRiSOXsXUvIrRE5GtR1g+NKOhr6g6SlsP8QcSRI2C8QBYsWIMCVBHpa 7Qj+JYN6Crh9DXUDEtWWsjsNUfobM/P6vznYRdd5hfgiYzLMODodi5MLJiAvrVIiQFNhc8S+HKYI 1vbaqYoREZsvVKq8YZ9/SG1CqFB/T9oOuGliwtRkR+GX5UQPXdpKZF7ITlSXoP8r3OOc9CaULF46 7VT2rSAdw3oKkBNp3q2CTUjaBEkZvVwfNyBf8N9Cj3+++mTSKn34bbFRlO1kXUycpH0i0CUyLQvl 9O+c0636VhIifL76GD10kuo3nOZaoX+g3LKzgLvGn75f1GdWNx/7rKBnyF5Al8KyqkBC47VmroNn IKDFkcg0DoDn7tP2jpvLswQ+LrsRjP8UUIXm0+DPmv7PKPGj8NXeGCulL/QJEqN6EipRzMVZ5Lqw Tx7Vvn9S5OBZ87WmFyXBm/oIAtLmOrCBf5k3qwLPOJPnfDsxRzDQNyioppyJmMAgZEU7lOctnhbF /nIX1ETvnsmWAxfSaweYUOp7A73HI6oJg7w/Vocy7+Ttx50kPf/opRnU1TyFH6IJwoZKvMkvY/jz 9IkVzN59uTrDo5OUYDGpGZVhMc74agj+RX0dbSrc5Jkf/lehMDRcCgYQIezXimM8MMGBqePpnOc1 Yjsvm51FfilkyeQU7370Z7k+bXna9cSTkOqSD22m1Led9vQBeL77Ic6CMOzAFWmAK6L8pLjYAyx9 cPRwc/tu2n0gQeKRgdo8fP/wbsmG5LlZyL0etItIQ47Q9ScHL8+lTGBIVE9xbEkX79tiWrQqR9OH b3+AhBHyQJhMoK6//HisH+Inv79AsPwENh1/rxbQicf/5tMwo2bfwwdcWaJjyTNTJd/rBV6qRhfQ Ewne7W7yM4pg5t5Ye8wOsvdQwaaQ0m5yz9ncfoPJBe4xL7hrJSk60SF3F6RYOYr2 X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 b42187f69eea..b2d8d158e273 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -706,32 +706,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); @@ -781,12 +755,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); @@ -802,25 +852,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); @@ -1804,8 +1836,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: @@ -2019,20 +2054,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; @@ -2645,14 +2670,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 @@ -2664,7 +2705,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) { @@ -2689,8 +2730,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); @@ -3218,6 +3258,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); @@ -3234,46 +3276,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: @@ -3307,18 +3318,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( @@ -3337,11 +3346,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 6 17:17:18 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: 10670885 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 D2AB617D4 for ; Tue, 6 Nov 2018 17:18:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B960B2AA73 for ; Tue, 6 Nov 2018 17:18:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ADAA12AA7C; Tue, 6 Nov 2018 17:18:58 +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 4F4762AA73 for ; Tue, 6 Nov 2018 17:18:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389286AbeKGCpJ (ORCPT ); Tue, 6 Nov 2018 21:45:09 -0500 Received: from com-out001.mailprotect.be ([83.217.72.83]:47729 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389427AbeKGCpJ (ORCPT ); Tue, 6 Nov 2018 21:45:09 -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=nh80oYfGiuFc9PivKX9tLekztzl+GZUd9QlIBsFFBUs=; b=M39ydqSrYDxp uAsRnHIikT79ckiiGjOzVrLoX2k0n05UvjUqW0/tYqsHYsM1V33eYCwLPvg48kK8zV0X7yvEjCqyb 1eC6l1MP3tAoM7pgvp1d7GHuFlK2qPU0lOOawowRu/FAT6vHbed7saILNgQKoY+qJRVwtxinBaz/X rb1TvRDx9TGPOZiYxkRGdHAsE+MdbHmRKN0tjnEOEbn8+o1nlK1RhaS78wwSh1Y6f5QjYDSLGcXLF FFVKsRha2XNeCaAQJaMVPeCSB08CFGYJ6FN0eFOouNjxeUuOxbMz/VfVYKPJQRB52CK+EXpYFdxvF h0aGMAJQk/vmT9uu5qMAAw==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gK503-000CLa-SB; Tue, 06 Nov 2018 18:18:48 +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 241FCC0BA4; Tue, 6 Nov 2018 18:18:43 +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 10/10] target/core: Reduce the amount of code executed with a spinlock held Date: Tue, 6 Nov 2018 09:17:18 -0800 Message-Id: <20181106171718.89594-11-bvanassche@acm.org> X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-goog In-Reply-To: <20181106171718.89594-1-bvanassche@acm.org> References: <20181106171718.89594-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: Combined (0.02) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5go+Lo/gkMXCIHbkNTSQROl602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTagCTS5H5Pie2sCQ3gGSzr06cM7U7xDGmYwNG93LVnxwxjk yGQYCd08t3lHobjxX/OigDGQOIiVUN5rGO3B5zfVpnsdsF0/474T9aStD4uEKVG9P9yTThxC66Ku Xb0HO3W8nbMwgkUuW83PKbk25YSnvgtxKKcMIJ7ptgUxRg53TuCt4QJNIvyoxb4710Nl6KAZZ+9r UkyLOOkgJ9eTXvOC4trOptRiSOXsXUvIrRE5GgGxg6GggjB1MxLEp3ZzomxI2C8QBYsWIMCVBHpa 7Qj+JYN6Crh9DXUDEtWWsjsNUWDlGPaDR+Aes7asAZpVFyfMODodi5MLJiAvrVIiQFNhc8S+HKYI 1vbaqYoREZsvVKq8YZ9/SG1CqFB/T9oOuGliwtRkR+GX5UQPXdpKZF7ITlSXoP8r3OOc9CaULF46 7VT2rSAdw3oKkBNp3q2CTUjaBEkZvVwfNyBf8N9Cj3+++mTSKn34bbFRlO1kXUycpLT8XjuR2au2 vXjeilQq2Qb31qklcVekvgO5ge3Iu/DWvQSnovmZV/iKI4Qq8lKVZU757KiUYziXyuXG4Z+FT7fy UhTxDKdOQwQquEi4jLe86t14bfTnkAn7W6VlJXtsnkdl1her2dsH1gtu4R2VkYfnELRpqCZGYewS zF6qDSUBpQp9p69drFuEpAhhs7hKCCLwHYF1mz4X0cGLGMLXeUfk4pNo86TrudwFGUCzM0p22bRk WbJQMsEazexAznFikUFGnvKVJnFQQaAnDicXOB0lxU/TKjOssk5IMwdmSU/MN6mG9OgEfwYjdW8p pBMOL6KehsbCb0/0wF8xekzsVEvRMrw5DdwH1AXXXLvYNFIciWrFfcvTzpdI3AEG059XQbG5VOTu CAJlYGERapFTpQx3OnKG9eRDP2/Ogb+c8D2oYTsY8dUpTw48b2MGkvEkgszLgRqa1sRnErSRPh8z fPP2CFl7xGIrJ5fPg33HFhWuygEwwwWe3xXNBQ8NJdm4Pscvb9y1CBweR1aEOEmF+7+XwJhp74Ne BZS/7a9ATcUMpAEntM8yKElR+Y84QVlpY/2Olap60rnP5huMjJeWSwzfzlDTegaelgiu9QvTToG3 X/ekOoQKVaL7/+VCcmuF/Q== 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 b2d8d158e273..445d21e69e0c 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -852,16 +852,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