From patchwork Mon Nov 30 02:46:07 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: 11939547 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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 25EAFC71156 for ; Mon, 30 Nov 2020 02:47:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E6A1C20857 for ; Mon, 30 Nov 2020 02:47:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726603AbgK3CrF (ORCPT ); Sun, 29 Nov 2020 21:47:05 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:43647 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726000AbgK3CrF (ORCPT ); Sun, 29 Nov 2020 21:47:05 -0500 Received: by mail-pf1-f195.google.com with SMTP id w202so9466589pff.10; Sun, 29 Nov 2020 18:46:50 -0800 (PST) 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=uo+5W/VFPGcdmJas5S5VfCp+uberliRJhse/5+5MoEs=; b=qC61DSU/aPZp9pg6ENHHnPGjj6lw3YpEG30S34AQpfSjFzWTMX5vyvFbPQtShjD5VH d3EqRuYApoI5LmuvsOt4lNd/Sx5vb21lpTMfC3g4qyRxVj1jYoHXxlGn7hy6MgwxcqeE zbzYd2RYc9liI2/AzkjdgE5jCoLRvl38W7anitPhsaUD6khgjOfrDOaO5nb7higStKS6 Wty77cnbi9Qo/GQ+L8hjBC2RTD762fYIynY0vr3FLWuTfc6kq88KkPHEGqd9gTArY03s XzyAY8+DHXFxHFHrDakC5EiQc6FfSrvFYQNcNmrcwNh1S37DHrSCVwvEc60RFRKbgmlJ s/4w== X-Gm-Message-State: AOAM5335BwA45V38LNS2GJcvJqzlLelDe3iGlhroUmYSy4nbLFE4dKTV jqZF0cdtP/PWdi1cxybQ18M+5g5DX5Q= X-Google-Smtp-Source: ABdhPJxUa/UG3UwhIngJplELaSW0y1y3pJsgxmzZ8dl+JDG+y+xzN7Oy+mlGhCRyxdCtwHLs6dP98A== X-Received: by 2002:aa7:82c5:0:b029:19a:aaac:9b4c with SMTP id f5-20020aa782c50000b029019aaaac9b4cmr14034095pfn.75.1606704384660; Sun, 29 Nov 2020 18:46:24 -0800 (PST) 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 n127sm14734659pfd.143.2020.11.29.18.46.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2020 18:46:23 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: "James E . J . Bottomley" , Jens Axboe , Christoph Hellwig , Ming Lei , linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, Bart Van Assche , Alan Stern , Stanley Chu , Hannes Reinecke , "Rafael J . Wysocki" , stable , Can Guo Subject: [PATCH v4 1/9] block: Fix a race in the runtime power management code Date: Sun, 29 Nov 2020 18:46:07 -0800 Message-Id: <20201130024615.29171-2-bvanassche@acm.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201130024615.29171-1-bvanassche@acm.org> References: <20201130024615.29171-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org With the current implementation the following race can happen: * blk_pre_runtime_suspend() calls blk_freeze_queue_start() and blk_mq_unfreeze_queue(). * blk_queue_enter() calls blk_queue_pm_only() and that function returns true. * blk_queue_enter() calls blk_pm_request_resume() and that function does not call pm_request_resume() because the queue runtime status is RPM_ACTIVE. * blk_pre_runtime_suspend() changes the queue status into RPM_SUSPENDING. Fix this race by changing the queue runtime status into RPM_SUSPENDING before switching q_usage_counter to atomic mode. Acked-by: Alan Stern Acked-by: Stanley Chu Reviewed-by: Christoph Hellwig Reviewed-by: Hannes Reinecke Cc: Ming Lei Cc: Rafael J. Wysocki Cc: stable Fixes: 986d413b7c15 ("blk-mq: Enable support for runtime power management") Signed-off-by: Can Guo Signed-off-by: Bart Van Assche --- block/blk-pm.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/block/blk-pm.c b/block/blk-pm.c index b85234d758f7..17bd020268d4 100644 --- a/block/blk-pm.c +++ b/block/blk-pm.c @@ -67,6 +67,10 @@ int blk_pre_runtime_suspend(struct request_queue *q) WARN_ON_ONCE(q->rpm_status != RPM_ACTIVE); + spin_lock_irq(&q->queue_lock); + q->rpm_status = RPM_SUSPENDING; + spin_unlock_irq(&q->queue_lock); + /* * Increase the pm_only counter before checking whether any * non-PM blk_queue_enter() calls are in progress to avoid that any @@ -89,15 +93,14 @@ int blk_pre_runtime_suspend(struct request_queue *q) /* Switch q_usage_counter back to per-cpu mode. */ blk_mq_unfreeze_queue(q); - spin_lock_irq(&q->queue_lock); - if (ret < 0) + if (ret < 0) { + spin_lock_irq(&q->queue_lock); + q->rpm_status = RPM_ACTIVE; pm_runtime_mark_last_busy(q->dev); - else - q->rpm_status = RPM_SUSPENDING; - spin_unlock_irq(&q->queue_lock); + spin_unlock_irq(&q->queue_lock); - if (ret) blk_clear_pm_only(q); + } return ret; } From patchwork Mon Nov 30 02:46:08 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: 11939551 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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 779EBC83014 for ; Mon, 30 Nov 2020 02:47:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3D99D20857 for ; Mon, 30 Nov 2020 02:47:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726725AbgK3CrN (ORCPT ); Sun, 29 Nov 2020 21:47:13 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:39705 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726000AbgK3CrN (ORCPT ); Sun, 29 Nov 2020 21:47:13 -0500 Received: by mail-pg1-f195.google.com with SMTP id f17so9195671pge.6; Sun, 29 Nov 2020 18:46:52 -0800 (PST) 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=ek/NBMowVicklCRXVtMA4IKHziAJguvbGxIIObE1pyI=; b=aPhmzYjEV0HFm0FYhdENZ9Br/A/liFzsWaWNas7S8dZKmqWsOvzhTV73XsCJ9pu+zn 2IbMJpUmTo3+qv5Ffs21ybHh9TizAJOk/IA4PiiiPRfD+R4SaVIJ7XFTRhDl/0dGQuHU VNEEN/nPCOZRPkAVvI5hE1JK7X8hzcAAiEZcFEbQ7IT8mRQWQ5vfIr37TtGgiulQKCI7 wskxd5194PbVk5Auz9bpulVvKJePPAPlDaSvgI73b2Xpap0UMaKy8JDveea+EsYnTIqp m43hgrbxprspigqXA3xSliOMEEzCTLFThkkosyOB/TvLL2XBGFQ89ydwI+2II1qI5Pv+ aEOg== X-Gm-Message-State: AOAM533NZ0M4lPUF9tscug4SHjazxq+KdftdXQinKpVix3zzQF5eGdES TN9bHtXGwNaPQQ9ERPaWbD5uVJ004DE= X-Google-Smtp-Source: ABdhPJzS03gqauwE4QVphlrDXH3dcEVGnM0Bu+xstROCnJYuLDZAlvhftznD8uhaOcIYkIJ0lmps1g== X-Received: by 2002:aa7:8c12:0:b029:18b:9939:9798 with SMTP id c18-20020aa78c120000b029018b99399798mr16668116pfd.44.1606704386704; Sun, 29 Nov 2020 18:46:26 -0800 (PST) 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 n127sm14734659pfd.143.2020.11.29.18.46.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2020 18:46:25 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: "James E . J . Bottomley" , Jens Axboe , Christoph Hellwig , Ming Lei , linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, Bart Van Assche , Alan Stern , Stanley Chu , Hannes Reinecke , "Rafael J . Wysocki" , Can Guo Subject: [PATCH v4 2/9] block: Introduce BLK_MQ_REQ_PM Date: Sun, 29 Nov 2020 18:46:08 -0800 Message-Id: <20201130024615.29171-3-bvanassche@acm.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201130024615.29171-1-bvanassche@acm.org> References: <20201130024615.29171-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Introduce the BLK_MQ_REQ_PM flag. This flag makes the request allocation functions set RQF_PM. This is the first step towards removing BLK_MQ_REQ_PREEMPT. Cc: Alan Stern Cc: Stanley Chu Cc: Christoph Hellwig Cc: Hannes Reinecke Cc: Ming Lei Cc: Rafael J. Wysocki Cc: Can Guo Signed-off-by: Bart Van Assche Reviewed-by: Christoph Hellwig Reviewed-by: Hannes Reinecke --- block/blk-core.c | 7 ++++--- block/blk-mq.c | 2 ++ include/linux/blk-mq.h | 2 ++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 2db8bda43b6e..10696f9fb6ac 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -424,11 +424,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, BLK_MQ_REQ_PM and/or BLK_MQ_REQ_PREEMPT */ 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 | BLK_MQ_REQ_PREEMPT); while (true) { bool success = false; @@ -630,7 +630,8 @@ 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 | + BLK_MQ_REQ_PREEMPT)); req = blk_mq_alloc_request(q, op, flags); if (!IS_ERR(req) && q->mq_ops->initialize_rq_fn) diff --git a/block/blk-mq.c b/block/blk-mq.c index 1b25ec2fe9be..b5880a1fb38d 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -292,6 +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_PM) + rq->rq_flags |= RQF_PM; if (data->flags & BLK_MQ_REQ_PREEMPT) rq->rq_flags |= RQF_PREEMPT; if (blk_queue_io_stat(data->q)) diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h index b23eeca4d677..c00e856c6fb1 100644 --- a/include/linux/blk-mq.h +++ b/include/linux/blk-mq.h @@ -444,6 +444,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_PM */ + BLK_MQ_REQ_PM = (__force blk_mq_req_flags_t)(1 << 2), /* set RQF_PREEMPT */ BLK_MQ_REQ_PREEMPT = (__force blk_mq_req_flags_t)(1 << 3), }; From patchwork Mon Nov 30 02:46:09 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: 11939549 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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 359A3C83012 for ; Mon, 30 Nov 2020 02:47:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0AB8021527 for ; Mon, 30 Nov 2020 02:47:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726637AbgK3CrK (ORCPT ); Sun, 29 Nov 2020 21:47:10 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:35850 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726000AbgK3CrK (ORCPT ); Sun, 29 Nov 2020 21:47:10 -0500 Received: by mail-pl1-f195.google.com with SMTP id r2so5672368pls.3; Sun, 29 Nov 2020 18:46:54 -0800 (PST) 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=L9bMMO9PLHWj2MaCkKXM22x7qw+mqsaR/qfG6E0Sag8=; b=Jcdsbpw0pmxN5VUAFk7Lu+nQJlat4dE4HSdCoNq2gJ2AVtZloomv4OcyhR5xZKbyIB dd5H7Aic8NFAZzXBWwzYeL7FFksGSBVtXcQep5EVcjd1e45q/9SGt+W2/fGrT+qMxypV M0zNpXE/eqNIOYQEDuBr4PFtg9K0rsxMyU19hR9glJxZ/ay0T/yBgiF5J1fXwTzxGFAq 3bxUMS3UdgUXxyN5t6Kq8oOf3mOdWisQPPdXMfLVdJC6o2+ZQymVJZRtH2JXyWaXZCQ/ IrN1LVUnXXF+MgTk9qm6aLN8MrMteHvNZvmo51E9CVKsBfUirECBxwxJXFCl8SJCmqXc hI+Q== X-Gm-Message-State: AOAM5317Q+kapGvmO10BN8X7Su3kUnRzwSmOd1S/xdtCRI1o4CZHsaYj /tYXWimV7bnhpjOS76lYmbk= X-Google-Smtp-Source: ABdhPJypsp/jGB9VdBi6zZ4uaJD0Ls1LCxAHHQ0IB9jT11HRJOa/TZ1ASPMTtcFmQASWDKjuv8FOsg== X-Received: by 2002:a17:902:d716:b029:da:10c1:51b5 with SMTP id w22-20020a170902d716b02900da10c151b5mr16783188ply.50.1606704388827; Sun, 29 Nov 2020 18:46:28 -0800 (PST) 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 n127sm14734659pfd.143.2020.11.29.18.46.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2020 18:46:27 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: "James E . J . Bottomley" , Jens Axboe , Christoph Hellwig , Ming Lei , linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, Bart Van Assche , Hannes Reinecke , "David S . Miller" , Alan Stern , Can Guo , Stanley Chu , "Rafael J . Wysocki" Subject: [PATCH v4 3/9] ide: Do not set the RQF_PREEMPT flag for sense requests Date: Sun, 29 Nov 2020 18:46:09 -0800 Message-Id: <20201130024615.29171-4-bvanassche@acm.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201130024615.29171-1-bvanassche@acm.org> References: <20201130024615.29171-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@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. Cc: Christoph Hellwig Cc: Hannes Reinecke Cc: David S. Miller Cc: Alan Stern Cc: Can Guo Cc: Stanley Chu Cc: Ming Lei Cc: Rafael J. Wysocki Signed-off-by: Bart Van Assche Reviewed-by: Christoph Hellwig Reviewed-by: Hannes Reinecke --- drivers/ide/ide-atapi.c | 1 - drivers/ide/ide-io.c | 5 ----- 2 files changed, 6 deletions(-) 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; diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c index 1a53c7a75224..c210ea3bd02f 100644 --- a/drivers/ide/ide-io.c +++ b/drivers/ide/ide-io.c @@ -515,11 +515,6 @@ blk_status_t ide_issue_rq(ide_drive_t *drive, struct request *rq, * above to return us whatever is in the queue. Since we call * ide_do_request() ourselves, we end up taking requests while * the queue is blocked... - * - * We let requests forced at head of queue with ide-preempt - * though. I hope that doesn't happen too much, hopefully not - * unless the subdriver triggers such a thing in its own PM - * state machine. */ if ((drive->dev_flags & IDE_DFLAG_BLOCKED) && ata_pm_request(rq) == 0 && From patchwork Mon Nov 30 02:46:10 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: 11939563 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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 14D6FC8301B for ; Mon, 30 Nov 2020 02:47:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DF0462076C for ; Mon, 30 Nov 2020 02:47:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726861AbgK3CrS (ORCPT ); Sun, 29 Nov 2020 21:47:18 -0500 Received: from mail-pj1-f65.google.com ([209.85.216.65]:40954 "EHLO mail-pj1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726811AbgK3CrR (ORCPT ); Sun, 29 Nov 2020 21:47:17 -0500 Received: by mail-pj1-f65.google.com with SMTP id t12so432897pjq.5; Sun, 29 Nov 2020 18:46:56 -0800 (PST) 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=VEU+xCwmLM+BtzvRP5JXTk9ZPc+wm9/yMiB5hxhuJk0=; b=MvIh6KFIeZw/NvNX/DS8J+hQMnNvMWfyFbPyTXUHu/FJ5kX8IW/uw8l6Fa43H3V6YJ CFaEY5w8MPuifN7HScmVM/vXnQ4ljcp3U1XqN+6mKvwEeY4lVleaQYkkOr8WkyahsY7W Dvdbl77RW7yBhNWpgmjMEWZUKyzL+lBr5YREPYAOd6dwFZQw4GRxF3+vIhSu2xnkRp/u Q26C2FHsxYa+9O9fGA49c/yYpqy8gaUtMDk5Ft4cxrxQKLZ/pbhmMj+L5aY52KIUJMqp lB3WOfbJ+7KkdTukGSErBmx69/f/bhoAQBaYzvS+ES0Cwf/NxZSlcyW8xHXABo7oDffM RLYg== X-Gm-Message-State: AOAM532hnWTMmBaF3NKbv2n4pC6y0Hk5k2f3Fz4eSRW8hPztmEd9eMxp DMtXgLH5sPFVdo/A9YGlu34= X-Google-Smtp-Source: ABdhPJxeHWlCShqBgl1RlcInuRhMcfTWzGXDC79erLCIRyaWbXT/fj9BT/a9YIp70TQ/nQHay7KcwA== X-Received: by 2002:a17:90a:d086:: with SMTP id k6mr23638224pju.141.1606704390962; Sun, 29 Nov 2020 18:46:30 -0800 (PST) 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 n127sm14734659pfd.143.2020.11.29.18.46.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2020 18:46:30 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: "James E . J . Bottomley" , Jens Axboe , Christoph Hellwig , Ming Lei , linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, Bart Van Assche , Hannes Reinecke , "David S . Miller" , Alan Stern , Can Guo , Stanley Chu , "Rafael J . Wysocki" Subject: [PATCH v4 4/9] ide: Mark power management requests with RQF_PM instead of RQF_PREEMPT Date: Sun, 29 Nov 2020 18:46:10 -0800 Message-Id: <20201130024615.29171-5-bvanassche@acm.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201130024615.29171-1-bvanassche@acm.org> References: <20201130024615.29171-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org This is another step that prepares for the removal of RQF_PREEMPT. Cc: Christoph Hellwig Cc: Hannes Reinecke Cc: David S. Miller Cc: Alan Stern Cc: Can Guo Cc: Stanley Chu Cc: Ming Lei Cc: Rafael J. Wysocki Signed-off-by: Bart Van Assche Reviewed-by: Christoph Hellwig Reviewed-by: Hannes Reinecke --- drivers/ide/ide-io.c | 2 +- drivers/ide/ide-pm.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c index c210ea3bd02f..4867b67b60d6 100644 --- a/drivers/ide/ide-io.c +++ b/drivers/ide/ide-io.c @@ -518,7 +518,7 @@ blk_status_t ide_issue_rq(ide_drive_t *drive, struct request *rq, */ if ((drive->dev_flags & IDE_DFLAG_BLOCKED) && ata_pm_request(rq) == 0 && - (rq->rq_flags & RQF_PREEMPT) == 0) { + (rq->rq_flags & RQF_PM) == 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; From patchwork Mon Nov 30 02:46:11 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: 11939553 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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 9C4E1C83016 for ; Mon, 30 Nov 2020 02:47:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8025E2076C for ; Mon, 30 Nov 2020 02:47:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726751AbgK3CrO (ORCPT ); Sun, 29 Nov 2020 21:47:14 -0500 Received: from mail-pj1-f68.google.com ([209.85.216.68]:52015 "EHLO mail-pj1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726691AbgK3CrO (ORCPT ); Sun, 29 Nov 2020 21:47:14 -0500 Received: by mail-pj1-f68.google.com with SMTP id r20so397247pjp.1; Sun, 29 Nov 2020 18:46:58 -0800 (PST) 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=7/BAMz2CYvfGS5mHYfgF/debVAmENTs8RcHIS0BLCRE=; b=blp3ClspGjPIfRVPjBnp9YY6/JWfUknFjMh+oroRtF/P796EEyx1aP8OrYITmn/SrS DZinbLSSxDdGvAzUXJz869ZYUOD6NDckb9P8psbKmSCX0zPu/vY78bgwL+faKt8OB2cF jmpakyw1emaP6EfjKtGWilgomBzPSO3wtxI9rwzueXBi6jJjN/XywZw7UnUweTl4O3de wXZaYTc0TkfMTLyqukuoMYl93YsE4pPX5odfplYUgBVe4Q9cRwzpIQns6N+VC9/AP/md OwbvEhL7YuAjnk8KptPwTC8ah86DeiLb50TWEA5hZj8JClZWCgBkzNv7tysnqGQnmx3A zI1A== X-Gm-Message-State: AOAM532rbW4L/sNFlNq+oB9JWcLoBASFr/M8VSM1myXi+FHeXfSOaiwq 6xqBRIQOLxdW3SvkpHDRzlU= X-Google-Smtp-Source: ABdhPJwVIZrAn+WXwvUCw81oOt5ne9jRKZ0UkaewnWLMgQ2sH96yj9G+yLkkHzT9dCsAajJgkkrUSg== X-Received: by 2002:a17:902:7607:b029:da:62c8:e206 with SMTP id k7-20020a1709027607b02900da62c8e206mr7086658pll.1.1606704393072; Sun, 29 Nov 2020 18:46:33 -0800 (PST) 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 n127sm14734659pfd.143.2020.11.29.18.46.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2020 18:46:32 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: "James E . J . Bottomley" , Jens Axboe , Christoph Hellwig , Ming Lei , linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, Bart Van Assche , Alan Stern , Can Guo , Stanley Chu , "Rafael J . Wysocki" Subject: [PATCH v4 5/9] scsi: Do not wait for a request in scsi_eh_lock_door() Date: Sun, 29 Nov 2020 18:46:11 -0800 Message-Id: <20201130024615.29171-6-bvanassche@acm.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201130024615.29171-1-bvanassche@acm.org> References: <20201130024615.29171-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org scsi_eh_lock_door() is the only function in the SCSI error handler that calls blk_get_request(). It is not guaranteed that a request is available when scsi_eh_lock_door() is called. Hence pass the BLK_MQ_REQ_NOWAIT flag to blk_get_request(). Reviewed-by: Alan Stern Reviewed-by: Christoph Hellwig Cc: Can Guo Cc: Stanley Chu Cc: Ming Lei Cc: Rafael J. Wysocki Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_error.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index d94449188270..6de6e1bf3dcb 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -1993,7 +1993,12 @@ static void scsi_eh_lock_door(struct scsi_device *sdev) struct request *req; struct scsi_request *rq; - req = blk_get_request(sdev->request_queue, REQ_OP_SCSI_IN, 0); + /* + * It is not guaranteed that a request is available nor that + * sdev->request_queue is unfrozen. Hence the BLK_MQ_REQ_NOWAIT below. + */ + req = blk_get_request(sdev->request_queue, REQ_OP_SCSI_IN, + BLK_MQ_REQ_NOWAIT); if (IS_ERR(req)) return; rq = scsi_req(req); From patchwork Mon Nov 30 02:46:12 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: 11939555 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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 E3073C83018 for ; Mon, 30 Nov 2020 02:47:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C6E112086A for ; Mon, 30 Nov 2020 02:47:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726809AbgK3CrR (ORCPT ); Sun, 29 Nov 2020 21:47:17 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:39710 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726691AbgK3CrQ (ORCPT ); Sun, 29 Nov 2020 21:47:16 -0500 Received: by mail-pg1-f195.google.com with SMTP id f17so9195871pge.6; Sun, 29 Nov 2020 18:47:00 -0800 (PST) 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=lkvYW585n0gw4FHLOeoVk4lRx4G25yxo/9FkfuXk+tM=; b=P/CS1B6mknzTb7+Kqz245lrJsHJ/xjOdwhuc/4O2lW9NPvIOrf7L/sOPRx4WN3pv9e l1ykkmU5WqTNkDf3dBDK6i175wHX11njGl4THeTS7KgsYLkecY227oUbcS1b/o6ZH9iG tTIxovTmUDTcP/Rc+qiU8Avtv9xN48sAUINncYjxZOhuSXlbmJlS/0z/GE/74hGK+YTn Jv2g4TMpCQXJA5Wgga+DsptUjTbDfAYUt/G3ZQPfyUsCVNxTbgQmeBrGZ1ZIj8/8v57Z Rnk4UwYgjTZXk07F5wo+EFsOssX05sNpcVEEAgxVGGkaPTpc7RHw8istfhdpiAnSdbAP nmJw== X-Gm-Message-State: AOAM531ZqTvsNZcQUGrEr93jRBMgC/bAYZP1020JydvuHHTtR0VGfxw9 dFTvSDeHwcPIMehHa+w450k= X-Google-Smtp-Source: ABdhPJx0ilH2wM+f45myJ+MHvaNdFfxB7PAffN43zNaSwNk4K/5XpxS0CtlYRArG8QR67DlzuZ2lXg== X-Received: by 2002:a63:4b1f:: with SMTP id y31mr9577098pga.29.1606704395241; Sun, 29 Nov 2020 18:46:35 -0800 (PST) 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 n127sm14734659pfd.143.2020.11.29.18.46.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2020 18:46:34 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: "James E . J . Bottomley" , Jens Axboe , Christoph Hellwig , Ming Lei , linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, Bart Van Assche , Alan Stern , James Bottomley , Woody Suwalski , Can Guo , Stanley Chu , "Rafael J . Wysocki" , Stan Johnson Subject: [PATCH v4 6/9] scsi_transport_spi: Set RQF_PM for domain validation commands Date: Sun, 29 Nov 2020 18:46:12 -0800 Message-Id: <20201130024615.29171-7-bvanassche@acm.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201130024615.29171-1-bvanassche@acm.org> References: <20201130024615.29171-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Disable runtime power management during domain validation. Since a later patch removes RQF_PREEMPT, set RQF_PM for domain validation commands such that these are executed in the quiesced SCSI device state. Cc: Alan Stern Cc: Christoph Hellwig Cc: James Bottomley Cc: Woody Suwalski Cc: Can Guo Cc: Stanley Chu Cc: Ming Lei Cc: Rafael J. Wysocki Cc: Stan Johnson Signed-off-by: Bart Van Assche Reviewed-by: Christoph Hellwig --- drivers/scsi/scsi_transport_spi.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/drivers/scsi/scsi_transport_spi.c b/drivers/scsi/scsi_transport_spi.c index f3d5b1bbd5aa..c37dd15d16d2 100644 --- a/drivers/scsi/scsi_transport_spi.c +++ b/drivers/scsi/scsi_transport_spi.c @@ -117,12 +117,16 @@ static int spi_execute(struct scsi_device *sdev, const void *cmd, sshdr = &sshdr_tmp; for(i = 0; i < DV_RETRIES; i++) { + /* + * The purpose of the RQF_PM flag below is to bypass the + * SDEV_QUIESCE state. + */ result = scsi_execute(sdev, cmd, dir, buffer, bufflen, sense, sshdr, DV_TIMEOUT, /* retries */ 1, REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT | REQ_FAILFAST_DRIVER, - 0, NULL); + RQF_PM, NULL); if (driver_byte(result) != DRIVER_SENSE || sshdr->sense_key != UNIT_ATTENTION) break; @@ -1005,23 +1009,26 @@ spi_dv_device(struct scsi_device *sdev) */ 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; + goto put_sdev; /* 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; + goto free_buffer; scsi_target_quiesce(starget); @@ -1041,12 +1048,16 @@ spi_dv_device(struct scsi_device *sdev) spi_initial_dv(starget) = 1; - out_free: +free_buffer: 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); From patchwork Mon Nov 30 02:46:13 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: 11939557 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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 38E30C8301A for ; Mon, 30 Nov 2020 02:47:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1FA2E20757 for ; Mon, 30 Nov 2020 02:47:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726867AbgK3CrS (ORCPT ); Sun, 29 Nov 2020 21:47:18 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:38887 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726691AbgK3CrS (ORCPT ); Sun, 29 Nov 2020 21:47:18 -0500 Received: by mail-pf1-f196.google.com with SMTP id w187so9485632pfd.5; Sun, 29 Nov 2020 18:47:02 -0800 (PST) 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=Jq2pbaYrRdnUtUgGV5B/zAxCvRijH9Fr7LSJktZsZ7A=; b=OSEUmCznSViTGGyZDbH8N7z+W5nOZwfUfPutt4vdyDosILRvQ4OCnbbaT8V+f9ir4e zYd/vVwM6uCwjqhR5xAbjwkFSPcfJc3GYyRLncoUpcWhNhsmiMoP48mLzR43/A7wh3Ts xAwmDuBFWUN0HB3cZ/wwdFZYif5z+l++eaQEwCix4kL2oFXf1vIMjl8mEFp6h5pk+JSy v9pBW3AiXLuJNrVBC1sRe/IThNpb75Yrdkdo5lze8xnXs1tsnrA+MIjK5HK7QvlD1mia A8TngEM+bmniEgIWiv8KPZlR22KvQxIqYPml1IAT6aWlug00G/yjU0bF/alR9o6sJ2FE gS/w== X-Gm-Message-State: AOAM533zZ77mTFEyeRb2vaXQ3hMTIAl1TCMi6Ml2/uJqLMJXmB1oGTrP RA3Y6gyDNTXkp6FLcOLx8qs= X-Google-Smtp-Source: ABdhPJzpSRp/Mil3I70o9W9CkQpnc8PrR/U5w3gWzTBQ6HkOpMcEsCirS9zUshTdRh9J/5PsNyHnOA== X-Received: by 2002:a63:7f03:: with SMTP id a3mr14168878pgd.313.1606704397262; Sun, 29 Nov 2020 18:46:37 -0800 (PST) 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 n127sm14734659pfd.143.2020.11.29.18.46.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2020 18:46:36 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: "James E . J . Bottomley" , Jens Axboe , Christoph Hellwig , Ming Lei , linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, Bart Van Assche , Can Guo , Stanley Chu , Alan Stern , "Rafael J . Wysocki" , Martin Kepplinger Subject: [PATCH v4 7/9] scsi: Only process PM requests if rpm_status != RPM_ACTIVE Date: Sun, 29 Nov 2020 18:46:13 -0800 Message-Id: <20201130024615.29171-8-bvanassche@acm.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201130024615.29171-1-bvanassche@acm.org> References: <20201130024615.29171-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Instead of submitting all SCSI commands submitted with scsi_execute() to a SCSI device if rpm_status != RPM_ACTIVE, only submit RQF_PM (power management requests) if rpm_status != RPM_ACTIVE. This patch makes the SCSI core handle the runtime power management status (rpm_status) as it should be handled. Cc: Christoph Hellwig Cc: Can Guo Cc: Stanley Chu Cc: Alan Stern Cc: Ming Lei Cc: Rafael J. Wysocki Cc: Martin Kepplinger Signed-off-by: Bart Van Assche Reviewed-by: Christoph Hellwig --- drivers/scsi/scsi_lib.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index b7ac14571415..91bc39a4c3c3 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -249,7 +249,8 @@ int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd, req = blk_get_request(sdev->request_queue, 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); @@ -1206,6 +1207,8 @@ static blk_status_t scsi_device_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: /* @@ -1232,18 +1235,18 @@ scsi_device_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; } @@ -2517,15 +2520,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. * @@ -2587,12 +2588,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); From patchwork Mon Nov 30 02:46:14 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: 11939559 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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 7B5CCC8301E for ; Mon, 30 Nov 2020 02:47:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 51FF420771 for ; Mon, 30 Nov 2020 02:47:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726897AbgK3CrU (ORCPT ); Sun, 29 Nov 2020 21:47:20 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:38837 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726691AbgK3CrU (ORCPT ); Sun, 29 Nov 2020 21:47:20 -0500 Received: by mail-pl1-f195.google.com with SMTP id l1so5668763pld.5; Sun, 29 Nov 2020 18:47:04 -0800 (PST) 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=dc3KA4G0u9z3zbg3gtVIeoxia8Wwz3LorG0wWR1Dri4=; b=jgr95PedbI2gFRo4QAW8UCXcr7kFN0Ewkx2hqKndgmlVGX6oSOJSFAdr01NnA5NfTk TobEPNtQhV5M+05KiDA7esHC2jhLamen4ORUOxrPkpoALGun8hTgTJX14GXHr67I+/AI v68SwykJqKraCSF5e3fiMqLE305zR3cYO6Yj5JHrUFO9bRDDbVEcU9gJV7PuxX8RcRWv yFIWnhJg4byPzEF89F4ZHUmRzpsD9UWwJqoKHW6QiMnE4Qz8MZaUc297fD5A8rtZzxHd fSXAGDUURXzu+rWNaitRSHC1dflNhXT1N5ezs506IzMDQA63O3JDcrUjx0q16AbrqCO0 pjPw== X-Gm-Message-State: AOAM531D5inuhqVEGCTYGW9+wS4Z8Os7SolZtIKr0yv8x1+mBaEOBZBT JsrwtvKU67v0qzwF7AQk7Ik= X-Google-Smtp-Source: ABdhPJyJ7ksWFc6OJ0sUpV/NchfbjUxUD3qfDaehhekN/A2eMRNW6jZTOTIoDFVSQzC1EYI1CJdLDw== X-Received: by 2002:a17:90a:f0ce:: with SMTP id fa14mr5735301pjb.156.1606704399300; Sun, 29 Nov 2020 18:46:39 -0800 (PST) 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 n127sm14734659pfd.143.2020.11.29.18.46.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2020 18:46:38 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: "James E . J . Bottomley" , Jens Axboe , Christoph Hellwig , Ming Lei , linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, Bart Van Assche , Can Guo , Stanley Chu , Alan Stern , "Rafael J . Wysocki" , Martin Kepplinger Subject: [PATCH v4 8/9] block: Remove RQF_PREEMPT and BLK_MQ_REQ_PREEMPT Date: Sun, 29 Nov 2020 18:46:14 -0800 Message-Id: <20201130024615.29171-9-bvanassche@acm.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201130024615.29171-1-bvanassche@acm.org> References: <20201130024615.29171-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Remove flag RQF_PREEMPT and BLK_MQ_REQ_PREEMPT since these are no longer used by any kernel code. Cc: Christoph Hellwig Cc: Can Guo Cc: Stanley Chu Cc: Alan Stern Cc: Ming Lei Cc: Rafael J. Wysocki Cc: Martin Kepplinger Signed-off-by: Bart Van Assche Reviewed-by: Christoph Hellwig Reviewed-by: Hannes Reinecke --- block/blk-core.c | 7 +++---- block/blk-mq-debugfs.c | 1 - block/blk-mq.c | 2 -- include/linux/blk-mq.h | 2 -- include/linux/blkdev.h | 6 +----- 5 files changed, 4 insertions(+), 14 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 10696f9fb6ac..a00bce9f46d8 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -424,11 +424,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, BLK_MQ_REQ_PM 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_PM | BLK_MQ_REQ_PREEMPT); + const bool pm = flags & BLK_MQ_REQ_PM; while (true) { bool success = false; @@ -630,8 +630,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_PM | - 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 3094542e12ae..9336a6f8d6ef 100644 --- a/block/blk-mq-debugfs.c +++ b/block/blk-mq-debugfs.c @@ -297,7 +297,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 b5880a1fb38d..d50504888b68 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -294,8 +294,6 @@ static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data, rq->cmd_flags = data->cmd_flags; if (data->flags & BLK_MQ_REQ_PM) rq->rq_flags |= RQF_PM; - if (data->flags & BLK_MQ_REQ_PREEMPT) - rq->rq_flags |= RQF_PREEMPT; if (blk_queue_io_stat(data->q)) rq->rq_flags |= RQF_IO_STAT; INIT_LIST_HEAD(&rq->queuelist); diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h index c00e856c6fb1..88af1df94308 100644 --- a/include/linux/blk-mq.h +++ b/include/linux/blk-mq.h @@ -446,8 +446,6 @@ enum { BLK_MQ_REQ_RESERVED = (__force blk_mq_req_flags_t)(1 << 1), /* set RQF_PM */ BLK_MQ_REQ_PM = (__force blk_mq_req_flags_t)(1 << 2), - /* set RQF_PREEMPT */ - BLK_MQ_REQ_PREEMPT = (__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 639cae2c158b..7d4b746f7e6a 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -79,9 +79,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 */ @@ -430,8 +427,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; From patchwork Mon Nov 30 02:46:15 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: 11939561 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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 D974CC64E7B for ; Mon, 30 Nov 2020 02:47:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A71872076C for ; Mon, 30 Nov 2020 02:47:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726988AbgK3CrX (ORCPT ); Sun, 29 Nov 2020 21:47:23 -0500 Received: from mail-pj1-f68.google.com ([209.85.216.68]:38656 "EHLO mail-pj1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726691AbgK3CrW (ORCPT ); Sun, 29 Nov 2020 21:47:22 -0500 Received: by mail-pj1-f68.google.com with SMTP id j13so433189pjz.3; Sun, 29 Nov 2020 18:47:07 -0800 (PST) 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=4JgpHAM7ijqDR/daqOEIIKcPlm8O8muBHkiT8mO3EUY=; b=OU5hFKJ7Pj125/WpCiIgABuKzjbZT7By+/pnOy8fcyfCBDBJGfr+UmppqJhn8oslp1 rvlZjQFJ7DyLz1pKjysRBA/eASVE0CYuIQr/G0Ku+1xMQx07w27IBtgmtp65nL6ng+Fy jO/oo7dUBZ9wL5rVspSncizF8FKd/tpoSknAFDyEKsKiOughgYolzSBZVQmLQd7gJPtd 8B+ANvFToIhYVY0tVrOY8LwPorig/bUu77eD8iG7VBf99taGU3Ns3IIYJlJ6K9ABfnqG /rHCAMVRgRgUE4srDWJtdpeX4XgY/nI9Gih+wyvUW/PMHUyJkAnwLD6zr8zd3t9j612+ c4Wg== X-Gm-Message-State: AOAM533fmR1+szOtJG4es6TCVM8DjY+e/CANNB7UeHEpU8jOhsQCN7Er gu2Tarp4ZFU7DS4V73Ygg48= X-Google-Smtp-Source: ABdhPJySzFwaS9kN5Nehx4yAWHDsKt0CycJXycGTqD+OB5huQZiDmvnMpZPa38YaDmL3k1FJ6d0fow== X-Received: by 2002:a17:90a:aa14:: with SMTP id k20mr23553945pjq.131.1606704401812; Sun, 29 Nov 2020 18:46:41 -0800 (PST) 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 n127sm14734659pfd.143.2020.11.29.18.46.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2020 18:46:40 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: "James E . J . Bottomley" , Jens Axboe , Christoph Hellwig , Ming Lei , linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, Bart Van Assche , Alan Stern , Can Guo , Stanley Chu , "Rafael J . Wysocki" , Martin Kepplinger Subject: [PATCH v4 9/9] block: Do not accept any requests while suspended Date: Sun, 29 Nov 2020 18:46:15 -0800 Message-Id: <20201130024615.29171-10-bvanassche@acm.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201130024615.29171-1-bvanassche@acm.org> References: <20201130024615.29171-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Alan Stern blk_queue_enter() accepts BLK_MQ_REQ_PM requests independent of the runtime power management state. Now that SCSI domain validation no longer depends on this behavior, modify the behavior of blk_queue_enter() as follows: - Do not accept any requests while suspended. - Only process power management requests while suspending or resuming. Submitting BLK_MQ_REQ_PM requests to a device that is runtime suspended causes runtime-suspended devices not to resume as they should. The request which should cause a runtime resume instead gets issued directly, without resuming the device first. Of course the device can't handle it properly, the I/O fails, and the device remains suspended. The problem is fixed by checking that the queue's runtime-PM status isn't RPM_SUSPENDED before allowing a request to be issued, and queuing a runtime-resume request if it is. In particular, the inline blk_pm_request_resume() routine is renamed blk_pm_resume_queue() and the code is unified by merging the surrounding checks into the routine. If the queue isn't set up for runtime PM, or there currently is no restriction on allowed requests, the request is allowed. Likewise if the BLK_MQ_REQ_PM flag is set and the status isn't RPM_SUSPENDED. Otherwise a runtime resume is queued and the request is blocked until conditions are more suitable. Reviewed-by: Christoph Hellwig Reviewed-by: Can Guo Reviewed-by: Stanley Chu Cc: Ming Lei Cc: Rafael J. Wysocki Reported-and-tested-by: Martin Kepplinger Signed-off-by: Alan Stern Signed-off-by: Bart Van Assche [ bvanassche: modified commit message and removed Cc: stable because without the previous patches from this series this patch would break parallel SCSI domain validation ] Reviewed-by: Hannes Reinecke --- block/blk-core.c | 6 +++--- block/blk-pm.h | 14 +++++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index a00bce9f46d8..230880cbf8c8 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -440,7 +440,8 @@ int blk_queue_enter(struct request_queue *q, blk_mq_req_flags_t flags) * responsible for ensuring that that counter is * globally visible before the queue is unfrozen. */ - if (pm || !blk_queue_pm_only(q)) { + if ((pm && q->rpm_status != RPM_SUSPENDED) || + !blk_queue_pm_only(q)) { success = true; } else { percpu_ref_put(&q->q_usage_counter); @@ -465,8 +466,7 @@ int blk_queue_enter(struct request_queue *q, blk_mq_req_flags_t flags) wait_event(q->mq_freeze_wq, (!q->mq_freeze_depth && - (pm || (blk_pm_request_resume(q), - !blk_queue_pm_only(q)))) || + blk_pm_resume_queue(pm, q)) || blk_queue_dying(q)); if (blk_queue_dying(q)) return -ENODEV; diff --git a/block/blk-pm.h b/block/blk-pm.h index ea5507d23e75..a2283cc9f716 100644 --- a/block/blk-pm.h +++ b/block/blk-pm.h @@ -6,11 +6,14 @@ #include #ifdef CONFIG_PM -static inline void blk_pm_request_resume(struct request_queue *q) +static inline int blk_pm_resume_queue(const bool pm, struct request_queue *q) { - if (q->dev && (q->rpm_status == RPM_SUSPENDED || - q->rpm_status == RPM_SUSPENDING)) - pm_request_resume(q->dev); + if (!q->dev || !blk_queue_pm_only(q)) + return 1; /* Nothing to do */ + if (pm && q->rpm_status != RPM_SUSPENDED) + return 1; /* Request allowed */ + pm_request_resume(q->dev); + return 0; } static inline void blk_pm_mark_last_busy(struct request *rq) @@ -44,8 +47,9 @@ static inline void blk_pm_put_request(struct request *rq) --rq->q->nr_pending; } #else -static inline void blk_pm_request_resume(struct request_queue *q) +static inline int blk_pm_resume_queue(const bool pm, struct request_queue *q) { + return 1; } static inline void blk_pm_mark_last_busy(struct request *rq)