From patchwork Mon Mar 27 12:06:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 9646469 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 46EE060328 for ; Mon, 27 Mar 2017 12:07:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E80227F07 for ; Mon, 27 Mar 2017 12:07:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 335DB28364; Mon, 27 Mar 2017 12:07:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F18B42835B for ; Mon, 27 Mar 2017 12:07:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752375AbdC0MHr (ORCPT ); Mon, 27 Mar 2017 08:07:47 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:35771 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752607AbdC0MHg (ORCPT ); Mon, 27 Mar 2017 08:07:36 -0400 Received: by mail-pg0-f67.google.com with SMTP id g2so12358541pge.2 for ; Mon, 27 Mar 2017 05:07:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WJx1fDSA5tdu073+n23diFYmIrbupoVSclkyVrBavaU=; b=qCp7AhndzoUJ02v69y/ErkSdWj0gEnUTQiTLZ2EjIIPNyfDYBC4TUUX/JdsHUFXJIT ZXCp4gqWbKqEzX0cA6z4KYmhpjqH9riTWINPIkZxxfJJXy5fXH4hfXvo8WyZJmLi3g05 dvA/TSqQ68o4Hnb3oAjB1T3f9R0CpHTjgcO5+rhF/rwRQS4jvWe0HREZWFNKrqvypu83 sV28r215q9dogRpp3+Rd19rO/EcNlWivKZvLWcAnIiINkUwHb9u5F5SqaCQt9hRBe8Z3 S+8D4u7GbRiJsFHbZ3cMYuc1FooQ9lpgkZM4msgPA+7QgxsUxoyBzTzzCHJ9S/2fRI1f eMrA== 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; bh=WJx1fDSA5tdu073+n23diFYmIrbupoVSclkyVrBavaU=; b=FDRAY9U2ZirZ4PTwuXhdIXD7+8GuIbj68X6+FyQETwTkb7+ImApwsiRALHtYFrTHwn MDHoTmuH3X9hkb35WLqHlzgZkcvRwM7EEC3NZm5qFb3LZCbyKAOlHGrOmndreDmjBZve NOQgS4nJVIEPXXhnymozUm8wdYApSBveXQbD/gRWBc0GDa/nnPoiPFELdZKcRJy8ZGLn Yl8Bgr93+V/P4wMAEs2Xc0YFNOsokmqSpl96yoMrJ6P65/R3+yciPTZtgzcjAEzg+5sh eeAK2JLNKtB1/tCDg2FWQUzxNWWsFYdwRAK87Ht4H+fIjIsUI/SdFs0+FpXXnY+Bhvub xc+Q== X-Gm-Message-State: AFeK/H0gE4luC5SyDaZ9PwVAOpkV6iNSoVqtfMaS2aBMo2d3UC1ICnzzivvukoxd3vcIfw== X-Received: by 10.98.80.208 with SMTP id g77mr25320963pfj.249.1490616434795; Mon, 27 Mar 2017 05:07:14 -0700 (PDT) Received: from localhost (li405-222.members.linode.com. [106.187.53.222]) by smtp.gmail.com with ESMTPSA id g29sm952101pfg.37.2017.03.27.05.07.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Mar 2017 05:07:14 -0700 (PDT) From: Ming Lei To: Jens Axboe , linux-block@vger.kernel.org, Christoph Hellwig Cc: Bart Van Assche , Hannes Reinecke , Ming Lei Subject: [PATCH v3 2/4] block: add a read barrier in blk_queue_enter() Date: Mon, 27 Mar 2017 20:06:56 +0800 Message-Id: <20170327120658.29864-3-tom.leiming@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170327120658.29864-1-tom.leiming@gmail.com> References: <20170327120658.29864-1-tom.leiming@gmail.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Without the barrier, reading DEAD flag of .q_usage_counter and reading .mq_freeze_depth may be reordered, then the following wait_event_interruptible() may never return. Reviewed-by: Hannes Reinecke Signed-off-by: Ming Lei Reviewed-by: Johannes Thumshirn Reviewed-by: Bart Van Assche --- block/blk-core.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/block/blk-core.c b/block/blk-core.c index ad388d5e309a..5e8963bc98d9 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -669,6 +669,15 @@ int blk_queue_enter(struct request_queue *q, bool nowait) if (nowait) return -EBUSY; + /* + * read pair of barrier in blk_mq_freeze_queue_start(), + * we need to order reading __PERCPU_REF_DEAD flag of + * .q_usage_counter and reading .mq_freeze_depth, + * otherwise the following wait may never return if the + * two reads are reordered. + */ + smp_rmb(); + ret = wait_event_interruptible(q->mq_freeze_wq, !atomic_read(&q->mq_freeze_depth) || blk_queue_dying(q));