From patchwork Mon Aug 31 02:53:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 257819 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80E8DC433E2 for ; Mon, 31 Aug 2020 02:54:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 65BDA2076D for ; Mon, 31 Aug 2020 02:54:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726775AbgHaCyK (ORCPT ); Sun, 30 Aug 2020 22:54:10 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:33545 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726573AbgHaCyJ (ORCPT ); Sun, 30 Aug 2020 22:54:09 -0400 Received: by mail-pl1-f194.google.com with SMTP id h2so2361511plr.0 for ; Sun, 30 Aug 2020 19:54:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=S8GnYufv9MZP7N22DryU0jHU7x5XYfvZ5ydievKhN2I=; b=nj7YUQBlTcKnv8ItHN6MJwKS9XUgAAJy/VEsfl0kXy2tc6RsZptIkThHpu/pnrYKx3 zygP5sCFgmtwlD5PsKOTDKvgHw40/8lAfFhCcuhFqmQ5OyuvXzhE1VGLQLe8apavqmTM ezJksUbGty3GVa8v+KKOKee8XvOowqOEvpshMHneS+Mu9gu4ctuI5jeWOltBpfxK0332 SUynII4OK+qQfKOnW2xjMxP5n8zl3hMquQ5xg4W2uvzvIh1MG9I+EyAww9tv3A9vFDEO UEIwzdkbTf5G9dWjFP2lQ91UBk1uLDLPdM5CsFe8AqgjVyly8L2hX0im4G9TDf6cncmc C3sQ== X-Gm-Message-State: AOAM531utQesqxYQdgRmxVE8kmwbPtRfqcQnOcghP/evKhj5IIr2pPT2 omEELCZX1aQGf/H7Vnq1QN8= X-Google-Smtp-Source: ABdhPJxiV2BNFdqYaNOGPLBxH1mY8UlWyz3nQaUUXvxkxoPgH80f0ydipEcvLbdRkQVqvfEQwQCOdg== X-Received: by 2002:a17:90a:af84:: with SMTP id w4mr8678964pjq.94.1598842448395; Sun, 30 Aug 2020 19:54:08 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net (c-73-241-217-19.hsd1.ca.comcast.net. [73.241.217.19]) by smtp.gmail.com with ESMTPSA id l123sm583569pgl.24.2020.08.30.19.54.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Aug 2020 19:54:07 -0700 (PDT) From: Bart Van Assche To: Alan Stern Cc: linux-scsi@vger.kernel.org, Martin Kepplinger , Can Guo , Bart Van Assche , "David S . Miller" Subject: [PATCH RFC 1/6] ide: Do not set the RQF_PREEMPT flag for sense requests Date: Sun, 30 Aug 2020 19:53:52 -0700 Message-Id: <20200831025357.32700-2-bvanassche@acm.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200831025357.32700-1-bvanassche@acm.org> References: <20200831025357.32700-1-bvanassche@acm.org> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org RQF_PREEMPT is used for two different purposes in the legacy IDE code: 1. To mark power management requests. 2. To mark requests that should preempt another request. An (old) explanation of that feature is as follows: "The IDE driver in the Linux kernel normally uses a series of busywait delays during its initialization. When the driver executes these busywaits, the kernel does nothing for the duration of the wait. The time spent in these waits could be used for other initialization activities, if they could be run concurrently with these waits. More specifically, busywait-style delays such as udelay() in module init functions inhibit kernel preemption because the Big Kernel Lock is held, while yielding APIs such as schedule_timeout() allow preemption. This is true because the kernel handles the BKL specially and releases and reacquires it across reschedules allowed by the current thread. This IDE-preempt specification requires that the driver eliminate these busywaits and replace them with a mechanism that allows other work to proceed while the IDE driver is initializing." Since I haven't found an implementation of (2), do not set the PREEMPT flag for sense requests. This patch causes sense requests to be postponed while a drive is suspended instead of being submitted to ide_queue_rq(). If it would ever be necessary to restore the IDE PREEMPT functionality, that can be done by introducing a new flag in struct ide_request. This patch is a first step towards removing the PREEMPT flag from the block layer. Cc: David S. Miller Signed-off-by: Bart Van Assche --- drivers/ide/ide-atapi.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/ide/ide-atapi.c b/drivers/ide/ide-atapi.c index 2162bc80f09e..013ad33fbbc8 100644 --- a/drivers/ide/ide-atapi.c +++ b/drivers/ide/ide-atapi.c @@ -223,7 +223,6 @@ void ide_prep_sense(ide_drive_t *drive, struct request *rq) sense_rq->rq_disk = rq->rq_disk; sense_rq->cmd_flags = REQ_OP_DRV_IN; ide_req(sense_rq)->type = ATA_PRIV_SENSE; - sense_rq->rq_flags |= RQF_PREEMPT; req->cmd[0] = GPCMD_REQUEST_SENSE; req->cmd[4] = cmd_len; From patchwork Mon Aug 31 02:53:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 296943 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E7B3C433E2 for ; Mon, 31 Aug 2020 02:54:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 685592076D for ; Mon, 31 Aug 2020 02:54:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727042AbgHaCyP (ORCPT ); Sun, 30 Aug 2020 22:54:15 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:46400 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726573AbgHaCyK (ORCPT ); Sun, 30 Aug 2020 22:54:10 -0400 Received: by mail-pl1-f195.google.com with SMTP id k13so2328333plk.13 for ; Sun, 30 Aug 2020 19:54:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HUKSBOdCli73E40HgK4a0srrRRXVezp10WSLTZYZcj0=; b=ow49/JPbc9h/EQAsXW3Y8G5vqMaGQNUrKX+kSDZbsTNtDkK54x6CSsz/xNMOJp+gJw 3+TnXtkMkoLVpj78a5xho+Uc8ihJrjx75tE3UuZQrz/07dDmK3yvsqBd3NNg0WDNAz0/ EIuuS0HHtSrxtV2+3u9kqtt2tePBXqhEfQTZxncrn7nvG0nbtXkpeYmZeIymTTxO2hTm asG1IyIKLItIyyFj9/Y0DjHtyfv3xNkYSyg5c7Le+yZPe1AxyQ6tqo45anoiDkMdrVZL 6C7j0YIJho98vkUZaHWEld7PIPVwDYsKBzScrU6ogyypnodXm09PEa08Bp7TzASjGyNF ms+A== X-Gm-Message-State: AOAM530MomXEGDwnc34mae8B9kQhFXEUjAK4jLl6jFKM6dpbEtEAxUxt +EY8cUJ9eEoZyC4lHjoEqKg= X-Google-Smtp-Source: ABdhPJxbgFMdKy7l6KubWC5cOqNgU7NaoEKJweDwUt/29dlHM0F6o8aIkrEpxd/F1rldC5XiM7Dc2A== X-Received: by 2002:a17:90b:289:: with SMTP id az9mr7116465pjb.31.1598842449797; Sun, 30 Aug 2020 19:54:09 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net (c-73-241-217-19.hsd1.ca.comcast.net. [73.241.217.19]) by smtp.gmail.com with ESMTPSA id l123sm583569pgl.24.2020.08.30.19.54.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Aug 2020 19:54:08 -0700 (PDT) From: Bart Van Assche To: Alan Stern Cc: linux-scsi@vger.kernel.org, Martin Kepplinger , Can Guo , Bart Van Assche Subject: [PATCH RFC 2/6] scsi: Remove an incorrect comment Date: Sun, 30 Aug 2020 19:53:53 -0700 Message-Id: <20200831025357.32700-3-bvanassche@acm.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200831025357.32700-1-bvanassche@acm.org> References: <20200831025357.32700-1-bvanassche@acm.org> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org scsi_device.sdev_target is used in more code than the single_lun code, hence remove the comment next to the definition of the sdev_target member. Signed-off-by: Bart Van Assche --- include/scsi/scsi_device.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h index bc5909033d13..264501d23aea 100644 --- a/include/scsi/scsi_device.h +++ b/include/scsi/scsi_device.h @@ -144,7 +144,7 @@ struct scsi_device { struct scsi_vpd __rcu *vpd_pg80; struct scsi_vpd __rcu *vpd_pg89; unsigned char current_tag; /* current tag */ - struct scsi_target *sdev_target; /* used only for single_lun */ + struct scsi_target *sdev_target; blist_flags_t sdev_bflags; /* black/white flags as also found in * scsi_devinfo.[hc]. For now used only to From patchwork Mon Aug 31 02:53:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 296941 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4253C43461 for ; Mon, 31 Aug 2020 02:54:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8DDD52076D for ; Mon, 31 Aug 2020 02:54:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727065AbgHaCyW (ORCPT ); Sun, 30 Aug 2020 22:54:22 -0400 Received: from mail-pj1-f68.google.com ([209.85.216.68]:51817 "EHLO mail-pj1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726960AbgHaCyS (ORCPT ); Sun, 30 Aug 2020 22:54:18 -0400 Received: by mail-pj1-f68.google.com with SMTP id ds1so2374411pjb.1 for ; Sun, 30 Aug 2020 19:54:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4YX0sEfiQTofSJ4KcUjPBVPtbkSMO7Wts0x5QKbGp/I=; b=cpjHoVd4+zHKv/xkc6sCsZm0nl8hZLtX9oUniTeIr3gZrV9fdqrhoewJFEa6/qHVH0 FFhGFjKcIarXcO3WVpjazDPO2CSCxGaiFCEWEGnc+hQ8VeMgr9HGROh4jhBPAM+oRK7P 4Zlp71bm7VfTw5eut21RmWjRJxVe2BdpIwAbwGZIfos8dRoipCeM+1o8WeHDC+65ua+2 5d/1GE6l82oKNqcamT88EpUYi049+JIXSyPNQFM/cvM5+5pUVQelIyExj1+tstbKiGC3 s4fB/hTttaDH6djv7zpYpU9Pp+ldkOMqz4imRIqXC0gJSAJ/Xy+4RB+xjyMT/Cj/uzSn e8iQ== X-Gm-Message-State: AOAM531qXusWWgMZtC4ic1NlTfZ1+9ijA1e1TlNibWbH+3SiV43GxO6u 7TuqPO3PCjk4lI54Rz8Bgg8= X-Google-Smtp-Source: ABdhPJx6AAo+CN+uErgb7TIHvIomOTrqIJw9ZcQnYZyJgkamjZSemBKAXADal4kDcT08qXwKOo40kg== X-Received: by 2002:a17:90a:4401:: with SMTP id s1mr8431645pjg.79.1598842451502; Sun, 30 Aug 2020 19:54:11 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net (c-73-241-217-19.hsd1.ca.comcast.net. [73.241.217.19]) by smtp.gmail.com with ESMTPSA id l123sm583569pgl.24.2020.08.30.19.54.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Aug 2020 19:54:10 -0700 (PDT) From: Bart Van Assche To: Alan Stern Cc: linux-scsi@vger.kernel.org, Martin Kepplinger , Can Guo , Bart Van Assche Subject: [PATCH RFC 3/6] scsi: Pass a request queue pointer to __scsi_execute() Date: Sun, 30 Aug 2020 19:53:54 -0700 Message-Id: <20200831025357.32700-4-bvanassche@acm.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200831025357.32700-1-bvanassche@acm.org> References: <20200831025357.32700-1-bvanassche@acm.org> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org This patch does not change any functionality but makes a later patch easier to read. Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_lib.c | 12 +++++------- include/scsi/scsi_device.h | 8 ++++---- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 1bc7f2ffe627..1d7135f61962 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -221,7 +221,7 @@ void scsi_queue_insert(struct scsi_cmnd *cmd, int reason) /** * __scsi_execute - insert request and wait for the result - * @sdev: scsi device + * @q: queue to insert the request into * @cmd: scsi command * @data_direction: data direction * @buffer: data buffer @@ -237,7 +237,7 @@ void scsi_queue_insert(struct scsi_cmnd *cmd, int reason) * Returns the scsi_cmnd result field if a command was executed, or a negative * Linux error code if we didn't get that far. */ -int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd, +int __scsi_execute(struct request_queue *q, const unsigned char *cmd, int data_direction, void *buffer, unsigned bufflen, unsigned char *sense, struct scsi_sense_hdr *sshdr, int timeout, int retries, u64 flags, req_flags_t rq_flags, @@ -247,15 +247,13 @@ int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd, struct scsi_request *rq; int ret = DRIVER_ERROR << 24; - req = blk_get_request(sdev->request_queue, - data_direction == DMA_TO_DEVICE ? + req = blk_get_request(q, data_direction == DMA_TO_DEVICE ? REQ_OP_SCSI_OUT : REQ_OP_SCSI_IN, BLK_MQ_REQ_PREEMPT); if (IS_ERR(req)) return ret; rq = scsi_req(req); - if (bufflen && blk_rq_map_kern(sdev->request_queue, req, - buffer, bufflen, GFP_NOIO)) + if (bufflen && blk_rq_map_kern(q, req, buffer, bufflen, GFP_NOIO)) goto out; rq->cmd_len = COMMAND_SIZE(cmd[0]); @@ -268,7 +266,7 @@ int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd, /* * head injection *required* here otherwise quiesce won't work */ - blk_execute_rq(req->q, NULL, req, 1); + blk_execute_rq(q, NULL, req, 1); /* * Some devices (USB mass-storage in particular) may transfer diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h index 264501d23aea..ef6e96e12c7c 100644 --- a/include/scsi/scsi_device.h +++ b/include/scsi/scsi_device.h @@ -437,7 +437,7 @@ extern const char *scsi_device_state_name(enum scsi_device_state); extern int scsi_is_sdev_device(const struct device *); extern int scsi_is_target_device(const struct device *); extern void scsi_sanitize_inquiry_string(unsigned char *s, int len); -extern int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd, +extern int __scsi_execute(struct request_queue *q, const unsigned char *cmd, int data_direction, void *buffer, unsigned bufflen, unsigned char *sense, struct scsi_sense_hdr *sshdr, int timeout, int retries, u64 flags, @@ -448,9 +448,9 @@ extern int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd, ({ \ BUILD_BUG_ON((sense) != NULL && \ sizeof(sense) != SCSI_SENSE_BUFFERSIZE); \ - __scsi_execute(sdev, cmd, data_direction, buffer, bufflen, \ - sense, sshdr, timeout, retries, flags, rq_flags, \ - resid); \ + __scsi_execute(sdev->request_queue, cmd, data_direction, \ + buffer, bufflen, sense, sshdr, timeout, retries, \ + flags, rq_flags, resid); \ }) static inline int scsi_execute_req(struct scsi_device *sdev, const unsigned char *cmd, int data_direction, void *buffer, From patchwork Mon Aug 31 02:53:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 296942 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2D53C433E7 for ; Mon, 31 Aug 2020 02:54:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A83992076D for ; Mon, 31 Aug 2020 02:54:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726775AbgHaCyU (ORCPT ); Sun, 30 Aug 2020 22:54:20 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:37641 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726946AbgHaCyO (ORCPT ); Sun, 30 Aug 2020 22:54:14 -0400 Received: by mail-pl1-f194.google.com with SMTP id c15so2351494plq.4 for ; Sun, 30 Aug 2020 19:54:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=q0GipgpvZhLUV8bGMCiFNZOWoygkRH0DKlv2BF+3dm4=; b=BNpGJTns0PE3KupFGXJ7QHYKd879Y3PltiAD1nZwD9PzWLcZwj+k95ifzkNNS5dHdL YkDKFTzQpf1jyLGCJ36xL1xxncY9YxLuOalY9LZmDS9OjfrHwjfJbjJn38UNSmGBjQec nFsglm4tflk6OterjQhsod2xtmnPyATYdY2aJWQkK/HrMpAagbtho7eVEysLWCSCRXDo +Ll/5HN16ig7YRHvqrkSs//F+AhdpWs5x3aGRXDFTO7dzWX/EzdggQ8TMIEZfUCNAtez YDH5vdY0+ZVb70iL85aBfItMQX/pRluLmoGox16qOAIs2/d1w23q7pSq3M3CDxvrHsBt nmlA== X-Gm-Message-State: AOAM5331MoYZzK2+OZBg1gERpr1nnIabx/yY8+dXjddkFgUy5MkjlW7M XTQHDJATbgr1AsrZBOMkshVMosE5aAaUNA== X-Google-Smtp-Source: ABdhPJz/WEaB5LifcjLr1y2zeJc2DNqRnRuhTmx9KljYIwcvmksTYTrvwHZMNh4ajv6WGd3SjzhMyA== X-Received: by 2002:a17:902:5991:: with SMTP id p17mr7106151pli.154.1598842452965; Sun, 30 Aug 2020 19:54:12 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net (c-73-241-217-19.hsd1.ca.comcast.net. [73.241.217.19]) by smtp.gmail.com with ESMTPSA id l123sm583569pgl.24.2020.08.30.19.54.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Aug 2020 19:54:12 -0700 (PDT) From: Bart Van Assche To: Alan Stern Cc: linux-scsi@vger.kernel.org, Martin Kepplinger , Can Guo , Bart Van Assche Subject: [PATCH RFC 4/6] scsi_transport_spi: Make spi_execute() accept a request queue pointer Date: Sun, 30 Aug 2020 19:53:55 -0700 Message-Id: <20200831025357.32700-5-bvanassche@acm.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200831025357.32700-1-bvanassche@acm.org> References: <20200831025357.32700-1-bvanassche@acm.org> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Passing a request queue pointer to spi_execute() instead of a SCSI device pointer will allow a later patch to associate two request queues with a SCSI device. Additionally, instead of assuming that the device state is SDEV_QUIESCE before domain validation starts, read the device state. This patch does not change any functionality but makes a later patch easier to read. Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_transport_spi.c | 69 ++++++++++++++++--------------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/drivers/scsi/scsi_transport_spi.c b/drivers/scsi/scsi_transport_spi.c index f3d5b1bbd5aa..959990f66865 100644 --- a/drivers/scsi/scsi_transport_spi.c +++ b/drivers/scsi/scsi_transport_spi.c @@ -104,7 +104,7 @@ static int sprint_frac(char *dest, int value, int denom) return result; } -static int spi_execute(struct scsi_device *sdev, const void *cmd, +static int spi_execute(struct request_queue *q, const void *cmd, enum dma_data_direction dir, void *buffer, unsigned bufflen, struct scsi_sense_hdr *sshdr) @@ -117,7 +117,7 @@ static int spi_execute(struct scsi_device *sdev, const void *cmd, sshdr = &sshdr_tmp; for(i = 0; i < DV_RETRIES; i++) { - result = scsi_execute(sdev, cmd, dir, buffer, bufflen, sense, + result = __scsi_execute(q, cmd, dir, buffer, bufflen, sense, sshdr, DV_TIMEOUT, /* retries */ 1, REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT | @@ -620,13 +620,14 @@ enum spi_compare_returns { /* This is for read/write Domain Validation: If the device supports * an echo buffer, we do read/write tests to it */ static enum spi_compare_returns -spi_dv_device_echo_buffer(struct scsi_device *sdev, u8 *buffer, - u8 *ptr, const int retries) +spi_dv_device_echo_buffer(struct scsi_device *sdev, struct request_queue *q, + u8 *buffer, u8 *ptr, const int retries) { int len = ptr - buffer; int j, k, r, result; unsigned int pattern = 0x0000ffff; struct scsi_sense_hdr sshdr; + enum scsi_device_state sdev_state = sdev->sdev_state; const char spi_write_buffer[] = { WRITE_BUFFER, 0x0a, 0, 0, 0, 0, 0, len >> 8, len & 0xff, 0 @@ -671,11 +672,10 @@ spi_dv_device_echo_buffer(struct scsi_device *sdev, u8 *buffer, } for (r = 0; r < retries; r++) { - result = spi_execute(sdev, spi_write_buffer, DMA_TO_DEVICE, + result = spi_execute(q, spi_write_buffer, DMA_TO_DEVICE, buffer, len, &sshdr); if(result || !scsi_device_online(sdev)) { - - scsi_device_set_state(sdev, SDEV_QUIESCE); + scsi_device_set_state(sdev, sdev_state); if (scsi_sense_valid(&sshdr) && sshdr.sense_key == ILLEGAL_REQUEST /* INVALID FIELD IN CDB */ @@ -693,9 +693,9 @@ spi_dv_device_echo_buffer(struct scsi_device *sdev, u8 *buffer, } memset(ptr, 0, len); - spi_execute(sdev, spi_read_buffer, DMA_FROM_DEVICE, - ptr, len, NULL); - scsi_device_set_state(sdev, SDEV_QUIESCE); + spi_execute(q, spi_read_buffer, DMA_FROM_DEVICE, ptr, len, + NULL); + scsi_device_set_state(sdev, sdev_state); if (memcmp(buffer, ptr, len) != 0) return SPI_COMPARE_FAILURE; @@ -706,11 +706,12 @@ spi_dv_device_echo_buffer(struct scsi_device *sdev, u8 *buffer, /* This is for the simplest form of Domain Validation: a read test * on the inquiry data from the device */ static enum spi_compare_returns -spi_dv_device_compare_inquiry(struct scsi_device *sdev, u8 *buffer, - u8 *ptr, const int retries) +spi_dv_device_compare_inquiry(struct scsi_device *sdev, struct request_queue *q, + u8 *buffer, u8 *ptr, const int retries) { int r, result; const int len = sdev->inquiry_len; + enum scsi_device_state sdev_state = sdev->sdev_state; const char spi_inquiry[] = { INQUIRY, 0, 0, 0, len, 0 }; @@ -718,11 +719,11 @@ spi_dv_device_compare_inquiry(struct scsi_device *sdev, u8 *buffer, for (r = 0; r < retries; r++) { memset(ptr, 0, len); - result = spi_execute(sdev, spi_inquiry, DMA_FROM_DEVICE, - ptr, len, NULL); + result = spi_execute(q, spi_inquiry, DMA_FROM_DEVICE, ptr, len, + NULL); if(result || !scsi_device_online(sdev)) { - scsi_device_set_state(sdev, SDEV_QUIESCE); + scsi_device_set_state(sdev, sdev_state); return SPI_COMPARE_FAILURE; } @@ -742,9 +743,10 @@ spi_dv_device_compare_inquiry(struct scsi_device *sdev, u8 *buffer, } static enum spi_compare_returns -spi_dv_retrain(struct scsi_device *sdev, u8 *buffer, u8 *ptr, - enum spi_compare_returns - (*compare_fn)(struct scsi_device *, u8 *, u8 *, int)) +spi_dv_retrain(struct scsi_device *sdev, struct request_queue *q, u8 *buffer, + u8 *ptr, enum spi_compare_returns + (*compare_fn)(struct scsi_device *, struct request_queue *, + u8 *, u8 *, int)) { struct spi_internal *i = to_spi_internal(sdev->host->transportt); struct scsi_target *starget = sdev->sdev_target; @@ -754,7 +756,7 @@ spi_dv_retrain(struct scsi_device *sdev, u8 *buffer, u8 *ptr, for (;;) { int newperiod; - retval = compare_fn(sdev, buffer, ptr, DV_LOOPS); + retval = compare_fn(sdev, q, buffer, ptr, DV_LOOPS); if (retval == SPI_COMPARE_SUCCESS || retval == SPI_COMPARE_SKIP_TEST) @@ -800,7 +802,8 @@ spi_dv_retrain(struct scsi_device *sdev, u8 *buffer, u8 *ptr, } static int -spi_dv_device_get_echo_buffer(struct scsi_device *sdev, u8 *buffer) +spi_dv_device_get_echo_buffer(struct scsi_device *sdev, + struct request_queue *q, u8 *buffer) { int l, result; @@ -824,8 +827,8 @@ spi_dv_device_get_echo_buffer(struct scsi_device *sdev, u8 *buffer) * (reservation conflict, device not ready, etc) just * skip the write tests */ for (l = 0; ; l++) { - result = spi_execute(sdev, spi_test_unit_ready, DMA_NONE, - NULL, 0, NULL); + result = spi_execute(q, spi_test_unit_ready, DMA_NONE, NULL, 0, + NULL); if(result) { if(l >= 3) @@ -836,8 +839,8 @@ spi_dv_device_get_echo_buffer(struct scsi_device *sdev, u8 *buffer) } } - result = spi_execute(sdev, spi_read_buffer_descriptor, - DMA_FROM_DEVICE, buffer, 4, NULL); + result = spi_execute(q, spi_read_buffer_descriptor, DMA_FROM_DEVICE, + buffer, 4, NULL); if (result) /* Device has no echo buffer */ @@ -847,7 +850,8 @@ spi_dv_device_get_echo_buffer(struct scsi_device *sdev, u8 *buffer) } static void -spi_dv_device_internal(struct scsi_device *sdev, u8 *buffer) +spi_dv_device_internal(struct scsi_device *sdev, struct request_queue *q, + u8 *buffer) { struct spi_internal *i = to_spi_internal(sdev->host->transportt); struct scsi_target *starget = sdev->sdev_target; @@ -859,7 +863,7 @@ spi_dv_device_internal(struct scsi_device *sdev, u8 *buffer) DV_SET(offset, 0); DV_SET(width, 0); - if (spi_dv_device_compare_inquiry(sdev, buffer, buffer, DV_LOOPS) + if (spi_dv_device_compare_inquiry(sdev, q, buffer, buffer, DV_LOOPS) != SPI_COMPARE_SUCCESS) { starget_printk(KERN_ERR, starget, "Domain Validation Initial Inquiry Failed\n"); /* FIXME: should probably offline the device here? */ @@ -875,9 +879,8 @@ spi_dv_device_internal(struct scsi_device *sdev, u8 *buffer) if (i->f->set_width && max_width) { i->f->set_width(starget, 1); - if (spi_dv_device_compare_inquiry(sdev, buffer, - buffer + len, - DV_LOOPS) + if (spi_dv_device_compare_inquiry(sdev, q, buffer, buffer + len, + DV_LOOPS) != SPI_COMPARE_SUCCESS) { starget_printk(KERN_ERR, starget, "Wide Transfers Fail\n"); i->f->set_width(starget, 0); @@ -946,7 +949,7 @@ spi_dv_device_internal(struct scsi_device *sdev, u8 *buffer) DV_SET(width, max_width); /* Do the read only INQUIRY tests */ - spi_dv_retrain(sdev, buffer, buffer + sdev->inquiry_len, + spi_dv_retrain(sdev, q, buffer, buffer + sdev->inquiry_len, spi_dv_device_compare_inquiry); /* See if we actually managed to negotiate and sustain DT */ if (i->f->get_dt) @@ -958,7 +961,7 @@ spi_dv_device_internal(struct scsi_device *sdev, u8 *buffer) * negotiated DT */ if (len == -1 && spi_dt(starget)) - len = spi_dv_device_get_echo_buffer(sdev, buffer); + len = spi_dv_device_get_echo_buffer(sdev, q, buffer); if (len <= 0) { starget_printk(KERN_INFO, starget, "Domain Validation skipping write tests\n"); @@ -970,7 +973,7 @@ spi_dv_device_internal(struct scsi_device *sdev, u8 *buffer) len = SPI_MAX_ECHO_BUFFER_SIZE; } - if (spi_dv_retrain(sdev, buffer, buffer + len, + if (spi_dv_retrain(sdev, q, buffer, buffer + len, spi_dv_device_echo_buffer) == SPI_COMPARE_SKIP_TEST) { /* OK, the stupid drive can't do a write echo buffer @@ -1030,7 +1033,7 @@ spi_dv_device(struct scsi_device *sdev) starget_printk(KERN_INFO, starget, "Beginning Domain Validation\n"); - spi_dv_device_internal(sdev, buffer); + spi_dv_device_internal(sdev, sdev->request_queue, buffer); starget_printk(KERN_INFO, starget, "Ending Domain Validation\n"); From patchwork Mon Aug 31 02:53:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 257817 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24BAEC433E2 for ; Mon, 31 Aug 2020 02:54:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 08BD12076D for ; Mon, 31 Aug 2020 02:54:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727056AbgHaCyV (ORCPT ); Sun, 30 Aug 2020 22:54:21 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:43387 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726984AbgHaCyP (ORCPT ); Sun, 30 Aug 2020 22:54:15 -0400 Received: by mail-pf1-f194.google.com with SMTP id f18so527939pfa.10 for ; Sun, 30 Aug 2020 19:54:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fQ3YgPbT5W7c+FaOm1s6QGKjCVUM85RXDDNSW5xzmMo=; b=mA2fGBvUXZElpXuzfBrl6dCGh1Aj5/25DJ1pzCp/7usPH4fZarl0d8kLFKFr4vhP4U 0BHbMXYrBYG+k9ez2t4dyLACTZO2JWG13EFN93F/Es8v4QXn1dZptcvoERBCCn2NIpdp GsMtYfX92U0ix5EqP9jagrD2uhZyTr+mHWBI8fTTEqvICzgeQY1Vgr7pIG0foxOBI/aN P4806pSsC0MznkJzPQGOhFZCL8CP87OAcCHDpT+S8TxmWQOCKGKa/N+ZAgULJmEJokgL jW0wB3+Hi2OLnmlOmMfQ504iEaYv1N36OGpjlyd0wkew7f5f1Lq3cilpLRavvrY10SWH oNwQ== X-Gm-Message-State: AOAM530JYAPPiZT2dJl5mzV3zvSq4J/DFD/hPJEBbXFHsT+KfT9iAyex g9D4pOmn/gfvxnF3WpzTI3c= X-Google-Smtp-Source: ABdhPJxBhpK7PfHr0BWIGF006Arnv+HGYVIFQZKwCM9m3PPEvay1vrtk75SnNXf3sb7lyszJSEVifQ== X-Received: by 2002:aa7:947b:: with SMTP id t27mr1676523pfq.240.1598842454489; Sun, 30 Aug 2020 19:54:14 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net (c-73-241-217-19.hsd1.ca.comcast.net. [73.241.217.19]) by smtp.gmail.com with ESMTPSA id l123sm583569pgl.24.2020.08.30.19.54.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Aug 2020 19:54:13 -0700 (PDT) From: Bart Van Assche To: Alan Stern Cc: linux-scsi@vger.kernel.org, Martin Kepplinger , Can Guo , Bart Van Assche Subject: [PATCH RFC 5/6] scsi_transport_spi: Freeze request queues instead of quiescing Date: Sun, 30 Aug 2020 19:53:56 -0700 Message-Id: <20200831025357.32700-6-bvanassche@acm.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200831025357.32700-1-bvanassche@acm.org> References: <20200831025357.32700-1-bvanassche@acm.org> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Instead of quiescing the request queues involved in domain validation, freeze these. As a result, the struct request_queue pm_only member is no longer set during domain validation. That will allow to modify scsi_execute() such that it stops setting the BLK_MQ_REQ_PREEMPT flag. Three additional changes in this patch are that scsi_mq_alloc_queue() is exported, that scsi_device_quiesce() is no longer exported and that scsi_target_{quiesce,resume}() have been changed into scsi_target_{freeze,unfreeze}(). Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_lib.c | 22 ++++++------ drivers/scsi/scsi_priv.h | 2 ++ drivers/scsi/scsi_transport_spi.c | 56 ++++++++++++++++++++----------- include/scsi/scsi_device.h | 6 ++-- 4 files changed, 51 insertions(+), 35 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 1d7135f61962..49eb8f2dffd8 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1866,6 +1866,7 @@ struct request_queue *scsi_mq_alloc_queue(struct scsi_device *sdev) blk_queue_flag_set(QUEUE_FLAG_SCSI_PASSTHROUGH, sdev->request_queue); return sdev->request_queue; } +EXPORT_SYMBOL_GPL(scsi_mq_alloc_queue); int scsi_mq_setup_tags(struct Scsi_Host *shost) { @@ -2540,7 +2541,6 @@ scsi_device_quiesce(struct scsi_device *sdev) return err; } -EXPORT_SYMBOL(scsi_device_quiesce); /** * scsi_device_resume - Restart user issued commands to a quiesced device. @@ -2569,30 +2569,30 @@ void scsi_device_resume(struct scsi_device *sdev) EXPORT_SYMBOL(scsi_device_resume); static void -device_quiesce_fn(struct scsi_device *sdev, void *data) +device_freeze_fn(struct scsi_device *sdev, void *data) { - scsi_device_quiesce(sdev); + blk_mq_freeze_queue(sdev->request_queue); } void -scsi_target_quiesce(struct scsi_target *starget) +scsi_target_freeze(struct scsi_target *starget) { - starget_for_each_device(starget, NULL, device_quiesce_fn); + starget_for_each_device(starget, NULL, device_freeze_fn); } -EXPORT_SYMBOL(scsi_target_quiesce); +EXPORT_SYMBOL(scsi_target_freeze); static void -device_resume_fn(struct scsi_device *sdev, void *data) +device_unfreeze_fn(struct scsi_device *sdev, void *data) { - scsi_device_resume(sdev); + blk_mq_unfreeze_queue(sdev->request_queue); } void -scsi_target_resume(struct scsi_target *starget) +scsi_target_unfreeze(struct scsi_target *starget) { - starget_for_each_device(starget, NULL, device_resume_fn); + starget_for_each_device(starget, NULL, device_unfreeze_fn); } -EXPORT_SYMBOL(scsi_target_resume); +EXPORT_SYMBOL(scsi_target_unfreeze); /** * scsi_internal_device_block_nowait - try to transition to the SDEV_BLOCK state diff --git a/drivers/scsi/scsi_priv.h b/drivers/scsi/scsi_priv.h index d12ada035961..6b9203df84c8 100644 --- a/drivers/scsi/scsi_priv.h +++ b/drivers/scsi/scsi_priv.h @@ -95,6 +95,8 @@ extern int scsi_mq_setup_tags(struct Scsi_Host *shost); extern void scsi_mq_destroy_tags(struct Scsi_Host *shost); extern void scsi_exit_queue(void); extern void scsi_evt_thread(struct work_struct *work); +extern int scsi_device_quiesce(struct scsi_device *sdev); +extern void scsi_device_resume(struct scsi_device *sdev); struct request_queue; struct request; diff --git a/drivers/scsi/scsi_transport_spi.c b/drivers/scsi/scsi_transport_spi.c index 959990f66865..63bec8980b27 100644 --- a/drivers/scsi/scsi_transport_spi.c +++ b/drivers/scsi/scsi_transport_spi.c @@ -997,59 +997,75 @@ void spi_dv_device(struct scsi_device *sdev) { struct scsi_target *starget = sdev->sdev_target; + struct request_queue *q1, *q2; u8 *buffer; const int len = SPI_MAX_ECHO_BUFFER_SIZE*2; /* - * Because this function and the power management code both call - * scsi_device_quiesce(), it is not safe to perform domain validation - * while suspend or resume is in progress. Hence the - * lock/unlock_system_sleep() calls. + * Because creates a new request queue that is not visible to the rest + * of the system, domain validation must be serialized against suspend, + * resume and runtime power management. Hence the + * lock/unlock_system_sleep() and scsi_autopm_{get,put}_device() calls. */ lock_system_sleep(); + if (scsi_autopm_get_device(sdev)) + goto unlock_system_sleep; + if (unlikely(spi_dv_in_progress(starget))) - goto unlock; + goto put_autopm; if (unlikely(scsi_device_get(sdev))) - goto unlock; + goto put_autopm; spi_dv_in_progress(starget) = 1; buffer = kzalloc(len, GFP_KERNEL); if (unlikely(!buffer)) - goto out_put; - - /* We need to verify that the actual device will quiesce; the - * later target quiesce is just a nice to have */ - if (unlikely(scsi_device_quiesce(sdev))) - goto out_free; - - scsi_target_quiesce(starget); + goto put_sdev; spi_dv_pending(starget) = 1; mutex_lock(&spi_dv_mutex(starget)); starget_printk(KERN_INFO, starget, "Beginning Domain Validation\n"); - spi_dv_device_internal(sdev, sdev->request_queue, buffer); + /* + * Save the request queue pointer before it is overwritten by + * scsi_mq_alloc_queue(). + */ + q1 = sdev->request_queue; + q2 = scsi_mq_alloc_queue(sdev); + + if (q2) { + /* + * Restore the request queue pointer such that no other + * subsystem can submit SCSI commands to 'sdev'. + */ + sdev->request_queue = q1; + scsi_target_freeze(starget); + spi_dv_device_internal(sdev, q2, buffer); + blk_cleanup_queue(q2); + scsi_target_unfreeze(starget); + } starget_printk(KERN_INFO, starget, "Ending Domain Validation\n"); mutex_unlock(&spi_dv_mutex(starget)); spi_dv_pending(starget) = 0; - scsi_target_resume(starget); - spi_initial_dv(starget) = 1; - out_free: kfree(buffer); - out_put: + +put_sdev: spi_dv_in_progress(starget) = 0; scsi_device_put(sdev); -unlock: + +put_autopm: + scsi_autopm_put_device(sdev); + +unlock_system_sleep: unlock_system_sleep(); } EXPORT_SYMBOL(spi_dv_device); diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h index ef6e96e12c7c..08f88ef04bc9 100644 --- a/include/scsi/scsi_device.h +++ b/include/scsi/scsi_device.h @@ -422,10 +422,8 @@ extern struct scsi_event *sdev_evt_alloc(enum scsi_device_event evt_type, extern void sdev_evt_send(struct scsi_device *sdev, struct scsi_event *evt); extern void sdev_evt_send_simple(struct scsi_device *sdev, enum scsi_device_event evt_type, gfp_t gfpflags); -extern int scsi_device_quiesce(struct scsi_device *sdev); -extern void scsi_device_resume(struct scsi_device *sdev); -extern void scsi_target_quiesce(struct scsi_target *); -extern void scsi_target_resume(struct scsi_target *); +extern void scsi_target_freeze(struct scsi_target *); +extern void scsi_target_unfreeze(struct scsi_target *); extern void scsi_scan_target(struct device *parent, unsigned int channel, unsigned int id, u64 lun, enum scsi_scan_mode rescan); From patchwork Mon Aug 31 02:53:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 257816 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79A7FC433E6 for ; Mon, 31 Aug 2020 02:54:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5C8EC207EA for ; Mon, 31 Aug 2020 02:54:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727084AbgHaCyY (ORCPT ); Sun, 30 Aug 2020 22:54:24 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:40479 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727054AbgHaCyW (ORCPT ); Sun, 30 Aug 2020 22:54:22 -0400 Received: by mail-pg1-f194.google.com with SMTP id h12so3515992pgm.7 for ; Sun, 30 Aug 2020 19:54:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SeFFyUKS6uGufgLGDwNhxeXppNyw1pKVFHPf/YB+iH0=; b=K/5G7q833zDF9PwQMMf0gNSjfHxfcGMdfgYolfjUXaJnnUq76wCcPmP7jmo1YxgPm9 f1gSVv+WfLfgS4JdnbzlwVS6bNsBxuDjSICrgRJ0gpb0Jq+j31nIopuN5Wo4dD5gY2uX dntIv6tO0MpnNSad2BwFym2pKEECu4eDxz0C4F2CJWTL+fLbAJe3jjS+fBjDEBuAwPG9 374hGVuZ6WV1wWlChBC9k5J8W+Ow09VBGbY6EUY1S7Ewfo3SAKoj6/OCTMnl+nTOIY6/ iaKWOKxsdSNGuEvJKFr2+kO2M1HSoatuWSwDgKUIFIeO4PG/z3v6XQa1f2R553xtdQHw L3Jw== X-Gm-Message-State: AOAM531c7dnv8IcNluuJhnp8ibUzClSn+KvAGaH6sBGcvz4Sx5MnSM9o PsH3OkYnxnz6fwiRZmjstAk= X-Google-Smtp-Source: ABdhPJwzbTRu1Sz3qJz8PMl/txNcg3nyQydghqpojfl8Vnp3W+zcffbdnK90FG8i6A7WkDxL6/9cPA== X-Received: by 2002:a63:e051:: with SMTP id n17mr6903455pgj.219.1598842456031; Sun, 30 Aug 2020 19:54:16 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net (c-73-241-217-19.hsd1.ca.comcast.net. [73.241.217.19]) by smtp.gmail.com with ESMTPSA id l123sm583569pgl.24.2020.08.30.19.54.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Aug 2020 19:54:15 -0700 (PDT) From: Bart Van Assche To: Alan Stern Cc: linux-scsi@vger.kernel.org, Martin Kepplinger , Can Guo , Bart Van Assche Subject: [PATCH RFC 6/6] block, scsi, ide: Only submit power management requests in state RPM_SUSPENDED Date: Sun, 30 Aug 2020 19:53:57 -0700 Message-Id: <20200831025357.32700-7-bvanassche@acm.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200831025357.32700-1-bvanassche@acm.org> References: <20200831025357.32700-1-bvanassche@acm.org> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Recently Martin Kepplinger reported a problem with the SCSI runtime PM code. Alan Stern root-caused that deadlock as follows: Thread 0 Thread 1 -------- -------- Start runtime suspend blk_pre_runtime_suspend calls blk_set_pm_only and sets q->rpm_status to RPM_SUSPENDING Call sd_open -> ... -> scsi_test_unit_ready -> __scsi_execute -> ... -> blk_queue_enter Sees BLK_MQ_REQ_PREEMPT set and RPM_SUSPENDING queue status, so does not postpone the request blk_post_runtime_suspend sets q->rpm_status to RPM_SUSPENDED The drive goes into runtime suspend Issues the TEST UNIT READY request Request fails because the drive is suspended Fix that deadlock by only accepting power management requests while suspended. Remove flag RQF_PREEMPT. Cc: Alan Stern Cc: Martin Kepplinger Cc: Can Guo Signed-off-by: Bart Van Assche --- block/blk-core.c | 6 +++--- block/blk-mq-debugfs.c | 1 - block/blk-mq.c | 4 ++-- drivers/ide/ide-io.c | 3 +-- drivers/ide/ide-pm.c | 2 +- drivers/scsi/scsi_lib.c | 27 ++++++++++++++------------- include/linux/blk-mq.h | 4 ++-- include/linux/blkdev.h | 6 +----- 8 files changed, 24 insertions(+), 29 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index d9d632639bd1..78a002ff9473 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -420,11 +420,11 @@ EXPORT_SYMBOL(blk_cleanup_queue); /** * blk_queue_enter() - try to increase q->q_usage_counter * @q: request queue pointer - * @flags: BLK_MQ_REQ_NOWAIT and/or BLK_MQ_REQ_PREEMPT + * @flags: BLK_MQ_REQ_NOWAIT and/or BLK_MQ_REQ_PM */ int blk_queue_enter(struct request_queue *q, blk_mq_req_flags_t flags) { - const bool pm = flags & BLK_MQ_REQ_PREEMPT; + const bool pm = flags & BLK_MQ_REQ_PM; while (true) { bool success = false; @@ -626,7 +626,7 @@ struct request *blk_get_request(struct request_queue *q, unsigned int op, struct request *req; WARN_ON_ONCE(op & REQ_NOWAIT); - WARN_ON_ONCE(flags & ~(BLK_MQ_REQ_NOWAIT | BLK_MQ_REQ_PREEMPT)); + WARN_ON_ONCE(flags & ~(BLK_MQ_REQ_NOWAIT | BLK_MQ_REQ_PM)); req = blk_mq_alloc_request(q, op, flags); if (!IS_ERR(req) && q->mq_ops->initialize_rq_fn) diff --git a/block/blk-mq-debugfs.c b/block/blk-mq-debugfs.c index 3f09bcb8a6fd..9273978f06e7 100644 --- a/block/blk-mq-debugfs.c +++ b/block/blk-mq-debugfs.c @@ -296,7 +296,6 @@ static const char *const rqf_name[] = { RQF_NAME(MIXED_MERGE), RQF_NAME(MQ_INFLIGHT), RQF_NAME(DONTPREP), - RQF_NAME(PREEMPT), RQF_NAME(FAILED), RQF_NAME(QUIET), RQF_NAME(ELVPRIV), diff --git a/block/blk-mq.c b/block/blk-mq.c index 0015a1892153..4e7589e55bf5 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -292,8 +292,8 @@ static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data, rq->mq_hctx = data->hctx; rq->rq_flags = 0; rq->cmd_flags = data->cmd_flags; - if (data->flags & BLK_MQ_REQ_PREEMPT) - rq->rq_flags |= RQF_PREEMPT; + if (data->flags & BLK_MQ_REQ_PM) + rq->rq_flags |= RQF_PM; if (blk_queue_io_stat(data->q)) rq->rq_flags |= RQF_IO_STAT; INIT_LIST_HEAD(&rq->queuelist); diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c index 1a53c7a75224..beb850679fa9 100644 --- a/drivers/ide/ide-io.c +++ b/drivers/ide/ide-io.c @@ -522,8 +522,7 @@ blk_status_t ide_issue_rq(ide_drive_t *drive, struct request *rq, * state machine. */ if ((drive->dev_flags & IDE_DFLAG_BLOCKED) && - ata_pm_request(rq) == 0 && - (rq->rq_flags & RQF_PREEMPT) == 0) { + ata_pm_request(rq) == 0) { /* there should be no pending command at this point */ ide_unlock_port(hwif); goto plug_device; diff --git a/drivers/ide/ide-pm.c b/drivers/ide/ide-pm.c index 192e6c65d34e..82ab308f1aaf 100644 --- a/drivers/ide/ide-pm.c +++ b/drivers/ide/ide-pm.c @@ -77,7 +77,7 @@ int generic_ide_resume(struct device *dev) } memset(&rqpm, 0, sizeof(rqpm)); - rq = blk_get_request(drive->queue, REQ_OP_DRV_IN, BLK_MQ_REQ_PREEMPT); + rq = blk_get_request(drive->queue, REQ_OP_DRV_IN, BLK_MQ_REQ_PM); ide_req(rq)->type = ATA_PRIV_PM_RESUME; ide_req(rq)->special = &rqpm; rqpm.pm_step = IDE_PM_START_RESUME; diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 49eb8f2dffd8..bd9930964697 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -248,7 +248,8 @@ int __scsi_execute(struct request_queue *q, const unsigned char *cmd, int ret = DRIVER_ERROR << 24; req = blk_get_request(q, data_direction == DMA_TO_DEVICE ? - REQ_OP_SCSI_OUT : REQ_OP_SCSI_IN, BLK_MQ_REQ_PREEMPT); + REQ_OP_SCSI_OUT : REQ_OP_SCSI_IN, + rq_flags & RQF_PM ? BLK_MQ_REQ_PM : 0); if (IS_ERR(req)) return ret; rq = scsi_req(req); @@ -1219,6 +1220,8 @@ static blk_status_t scsi_prep_state_check(struct scsi_device *sdev, struct request *req) { switch (sdev->sdev_state) { + case SDEV_CREATED: + return BLK_STS_OK; case SDEV_OFFLINE: case SDEV_TRANSPORT_OFFLINE: /* @@ -1245,18 +1248,18 @@ scsi_prep_state_check(struct scsi_device *sdev, struct request *req) return BLK_STS_RESOURCE; case SDEV_QUIESCE: /* - * If the devices is blocked we defer normal commands. + * If the device is blocked we only accept power management + * commands. */ - if (req && !(req->rq_flags & RQF_PREEMPT)) + if (req && WARN_ON_ONCE(!(req->rq_flags & RQF_PM))) return BLK_STS_RESOURCE; return BLK_STS_OK; default: /* * For any other not fully online state we only allow - * special commands. In particular any user initiated - * command is not allowed. + * power management commands. */ - if (req && !(req->rq_flags & RQF_PREEMPT)) + if (req && !(req->rq_flags & RQF_PM)) return BLK_STS_IOERR; return BLK_STS_OK; } @@ -2489,15 +2492,13 @@ void sdev_evt_send_simple(struct scsi_device *sdev, EXPORT_SYMBOL_GPL(sdev_evt_send_simple); /** - * scsi_device_quiesce - Block user issued commands. + * scsi_device_quiesce - Block all commands except power management. * @sdev: scsi device to quiesce. * * This works by trying to transition to the SDEV_QUIESCE state * (which must be a legal transition). When the device is in this - * state, only special requests will be accepted, all others will - * be deferred. Since special requests may also be requeued requests, - * a successful return doesn't guarantee the device will be - * totally quiescent. + * state, only power management requests will be accepted, all others will + * be deferred. * * Must be called with user context, may sleep. * @@ -2558,12 +2559,12 @@ void scsi_device_resume(struct scsi_device *sdev) * device deleted during suspend) */ mutex_lock(&sdev->state_mutex); + if (sdev->sdev_state == SDEV_QUIESCE) + scsi_device_set_state(sdev, SDEV_RUNNING); if (sdev->quiesced_by) { sdev->quiesced_by = NULL; blk_clear_pm_only(sdev->request_queue); } - if (sdev->sdev_state == SDEV_QUIESCE) - scsi_device_set_state(sdev, SDEV_RUNNING); mutex_unlock(&sdev->state_mutex); } EXPORT_SYMBOL(scsi_device_resume); diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h index 9d2d5ad367a4..864f3b512d83 100644 --- a/include/linux/blk-mq.h +++ b/include/linux/blk-mq.h @@ -433,8 +433,8 @@ enum { BLK_MQ_REQ_NOWAIT = (__force blk_mq_req_flags_t)(1 << 0), /* allocate from reserved pool */ BLK_MQ_REQ_RESERVED = (__force blk_mq_req_flags_t)(1 << 1), - /* set RQF_PREEMPT */ - BLK_MQ_REQ_PREEMPT = (__force blk_mq_req_flags_t)(1 << 3), + /* set RQF_PM */ + BLK_MQ_REQ_PM = (__force blk_mq_req_flags_t)(1 << 3), }; struct request *blk_mq_alloc_request(struct request_queue *q, unsigned int op, diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index bb5636cc17b9..909cb8b1d4ee 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -77,9 +77,6 @@ typedef __u32 __bitwise req_flags_t; #define RQF_MQ_INFLIGHT ((__force req_flags_t)(1 << 6)) /* don't call prep for this one */ #define RQF_DONTPREP ((__force req_flags_t)(1 << 7)) -/* set for "ide_preempt" requests and also for requests for which the SCSI - "quiesce" state must be ignored. */ -#define RQF_PREEMPT ((__force req_flags_t)(1 << 8)) /* vaguely specified driver internal error. Ignored by the block layer */ #define RQF_FAILED ((__force req_flags_t)(1 << 10)) /* don't warn about errors */ @@ -424,8 +421,7 @@ struct request_queue { unsigned long queue_flags; /* * Number of contexts that have called blk_set_pm_only(). If this - * counter is above zero then only RQF_PM and RQF_PREEMPT requests are - * processed. + * counter is above zero then only RQF_PM requests are processed. */ atomic_t pm_only;