From patchwork Tue Feb 1 21:09:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 539562 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8282C433FE for ; Tue, 1 Feb 2022 21:10:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241145AbiBAVKN (ORCPT ); Tue, 1 Feb 2022 16:10:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229923AbiBAVKM (ORCPT ); Tue, 1 Feb 2022 16:10:12 -0500 Received: from Chamillionaire.breakpoint.cc (Chamillionaire.breakpoint.cc [IPv6:2a0a:51c0:0:12e:520::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A8F5C061714; Tue, 1 Feb 2022 13:10:12 -0800 (PST) Received: from localhost ([127.0.0.1] helo=flow.W.breakpoint.cc) by Chamillionaire.breakpoint.cc with esmtp (Exim 4.92) (envelope-from ) id 1nF0Pg-0006wn-Uh; Tue, 01 Feb 2022 22:10:09 +0100 From: Sebastian Andrzej Siewior To: linux-scsi@vger.kernel.org, linux-usb@vger.kernel.org, usb-storage@lists.one-eyed-alien.net Cc: "James E.J. Bottomley" , "Martin K. Petersen" , Alan Stern , Greg Kroah-Hartman , Sebastian Andrzej Siewior Subject: [PATCH 1/2] scsi: Add scsi_done_direct() for immediate completion. Date: Tue, 1 Feb 2022 22:09:53 +0100 Message-Id: <20220201210954.570896-2-sebastian@breakpoint.cc> In-Reply-To: <20220201210954.570896-1-sebastian@breakpoint.cc> References: <20220201210954.570896-1-sebastian@breakpoint.cc> MIME-Version: 1.0 X-Breakpoint-Spam-Score: -1.0 X-Breakpoint-Spam-Level: - X-Breakpoint-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Add scsi_done_direct() which behaves like scsi_done() except that it invokes blk_mq_complete_request_direct() in order to complete the request. Callers from process context can complete the request directly instead waking ksoftirqd. Signed-off-by: Sebastian Andrzej Siewior --- drivers/scsi/scsi_lib.c | 27 +++++++++++++++++++++++---- include/scsi/scsi_cmnd.h | 1 + 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 0a70aa763a961..778ef6d09616f 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1625,26 +1625,45 @@ static blk_status_t scsi_prepare_cmd(struct request *req) return scsi_cmd_to_driver(cmd)->init_command(cmd); } -void scsi_done(struct scsi_cmnd *cmd) +static bool scsi_done_need_blk_compl(struct scsi_cmnd *cmd) { switch (cmd->submitter) { case SUBMITTED_BY_BLOCK_LAYER: break; case SUBMITTED_BY_SCSI_ERROR_HANDLER: - return scsi_eh_done(cmd); + scsi_eh_done(cmd); + return false; case SUBMITTED_BY_SCSI_RESET_IOCTL: - return; + return false; } if (unlikely(blk_should_fake_timeout(scsi_cmd_to_rq(cmd)->q))) - return; + return false; if (unlikely(test_and_set_bit(SCMD_STATE_COMPLETE, &cmd->state))) + return false; + return true; +} + +void scsi_done(struct scsi_cmnd *cmd) +{ + if (!scsi_done_need_blk_compl(cmd)) return; + trace_scsi_dispatch_cmd_done(cmd); blk_mq_complete_request(scsi_cmd_to_rq(cmd)); } EXPORT_SYMBOL(scsi_done); +void scsi_done_direct(struct scsi_cmnd *cmd) +{ + if (!scsi_done_need_blk_compl(cmd)) + return; + + trace_scsi_dispatch_cmd_done(cmd); + blk_mq_complete_request_direct(scsi_cmd_to_rq(cmd), scsi_complete); +} +EXPORT_SYMBOL(scsi_done_direct); + static void scsi_mq_put_budget(struct request_queue *q, int budget_token) { struct scsi_device *sdev = q->queuedata; diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h index 6794d7322cbde..ff1c4b51f7aef 100644 --- a/include/scsi/scsi_cmnd.h +++ b/include/scsi/scsi_cmnd.h @@ -168,6 +168,7 @@ static inline struct scsi_driver *scsi_cmd_to_driver(struct scsi_cmnd *cmd) } void scsi_done(struct scsi_cmnd *cmd); +void scsi_done_direct(struct scsi_cmnd *cmd); extern void scsi_finish_command(struct scsi_cmnd *cmd); From patchwork Tue Feb 1 21:09:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 539259 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C838CC4332F for ; Tue, 1 Feb 2022 21:10:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233213AbiBAVKO (ORCPT ); Tue, 1 Feb 2022 16:10:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232017AbiBAVKN (ORCPT ); Tue, 1 Feb 2022 16:10:13 -0500 Received: from Chamillionaire.breakpoint.cc (Chamillionaire.breakpoint.cc [IPv6:2a0a:51c0:0:12e:520::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0A70C06173B; Tue, 1 Feb 2022 13:10:12 -0800 (PST) Received: from localhost ([127.0.0.1] helo=flow.W.breakpoint.cc) by Chamillionaire.breakpoint.cc with esmtp (Exim 4.92) (envelope-from ) id 1nF0Pj-0006wn-9E; Tue, 01 Feb 2022 22:10:11 +0100 From: Sebastian Andrzej Siewior To: linux-scsi@vger.kernel.org, linux-usb@vger.kernel.org, usb-storage@lists.one-eyed-alien.net Cc: "James E.J. Bottomley" , "Martin K. Petersen" , Alan Stern , Greg Kroah-Hartman , Sebastian Andrzej Siewior Subject: [PATCH 2/2] usb: storage: Complete the scsi request directly. Date: Tue, 1 Feb 2022 22:09:54 +0100 Message-Id: <20220201210954.570896-3-sebastian@breakpoint.cc> In-Reply-To: <20220201210954.570896-1-sebastian@breakpoint.cc> References: <20220201210954.570896-1-sebastian@breakpoint.cc> MIME-Version: 1.0 X-Breakpoint-Spam-Score: -1.0 X-Breakpoint-Spam-Level: - X-Breakpoint-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The storage driver completes its requests directly from a kernel thread. Use scsi_done_direct() to avoid waking ksoftirqd. Signed-off-by: Sebastian Andrzej Siewior --- drivers/usb/storage/usb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c index 8b543f2c98575..ed7c6ad96a743 100644 --- a/drivers/usb/storage/usb.c +++ b/drivers/usb/storage/usb.c @@ -417,7 +417,7 @@ static int usb_stor_control_thread(void * __us) if (srb) { usb_stor_dbg(us, "scsi cmd done, result=0x%x\n", srb->result); - scsi_done(srb); + scsi_done_direct(srb); } } /* for (;;) */