From patchwork Thu Jan 10 03:12:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauricio Faria de Oliveira X-Patchwork-Id: 1022673 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43Zrfm0wGbz9sNJ; Thu, 10 Jan 2019 14:13:20 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1ghQmP-0006l5-W4; Thu, 10 Jan 2019 03:13:13 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.86_2) (envelope-from ) id 1ghQmN-0006ir-69 for kernel-team@lists.ubuntu.com; Thu, 10 Jan 2019 03:13:11 +0000 Received: from mail-qt1-f199.google.com ([209.85.160.199]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1ghQmM-0000X1-RH for kernel-team@lists.ubuntu.com; Thu, 10 Jan 2019 03:13:10 +0000 Received: by mail-qt1-f199.google.com with SMTP id 41so8696194qto.17 for ; Wed, 09 Jan 2019 19:13:10 -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:subject:date:message-id:in-reply-to :references; bh=IytyOWm2V4QMNzFhyZjMo/nbKVUXUMs7i24Qp9XxZlI=; b=bxnNdN+A5lIP/BjuXhaFPynde24D4wB1b63ETwcXXapjmksMIxfjNcpeBaxsDx5UXR YV2NNoO48QaFbMgF7ra+Fo1qkj1zwIzs71mZYkrWiJvYpd2ltpta3RxY2Ta/qjtXStZW mfT3Z/u7Dvc7yrhsDw3LKE4g8BZ758fEqL/BXry7Pezwl7IhODt5V9bXssq1q1fjCQ+6 oRc0i3BuxTy9AVbj0adRVhnzM+HUzx+aoVaciv3Kgu/q5lrdI7dbioLfXcOuvfORhnBJ Y29JXoA5us5W/3ji6CgNSVg2sHqEPLdKkVbgjcK0johjOiShd/DPLw80/bZwdxWi/C7d rAgw== X-Gm-Message-State: AJcUukcOJ+8VmOn7NOgGriPHeEtYu+nS5iiyZtc/lNGUaKtIyXEuGqnf bN7qZR2HUlXNkmYBwB1YXVPr9+vSDTcaTQDq8mtM4JNW/mRI2JLG7BBboliwERYSVSS0iSxl3j2 0OJKuMXci+6aROdAm/4rkdeQGpt5c7vBMGpWLKDN88Q== X-Received: by 2002:aed:2471:: with SMTP id s46mr7984487qtc.160.1547089989931; Wed, 09 Jan 2019 19:13:09 -0800 (PST) X-Google-Smtp-Source: ALg8bN65IkvHh3Oy1RsJl3Y6VDb/izhdG2enZjftniMHpEHOKIld0uif+aZ/ql+1BrKN76TYYqR6tQ== X-Received: by 2002:aed:2471:: with SMTP id s46mr7984479qtc.160.1547089989764; Wed, 09 Jan 2019 19:13:09 -0800 (PST) Received: from localhost.localdomain ([177.181.227.0]) by smtp.gmail.com with ESMTPSA id s9sm43971956qta.35.2019.01.09.19.13.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Jan 2019 19:13:09 -0800 (PST) From: Mauricio Faria de Oliveira To: kernel-team@lists.ubuntu.com Subject: [SRU B][PATCH 04/13] block: properly protect the 'queue' kobj in blk_unregister_queue Date: Thu, 10 Jan 2019 01:12:10 -0200 Message-Id: <20190110031219.30676-5-mfo@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190110031219.30676-1-mfo@canonical.com> References: <20190110031219.30676-1-mfo@canonical.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Mike Snitzer BugLink: https://bugs.launchpad.net/bugs/1810998 The original commit e9a823fb34a8b (block: fix warning when I/O elevator is changed as request_queue is being removed) is pretty conflated. "conflated" because the resource being protected by q->sysfs_lock isn't the queue_flags (it is the 'queue' kobj). q->sysfs_lock serializes __elevator_change() (via elv_iosched_store) from racing with blk_unregister_queue(): 1) By holding q->sysfs_lock first, __elevator_change() can complete before a racing blk_unregister_queue(). 2) Conversely, __elevator_change() is testing for QUEUE_FLAG_REGISTERED in case elv_iosched_store() loses the race with blk_unregister_queue(), it needs a way to know the 'queue' kobj isn't there. Expand the scope of blk_unregister_queue()'s q->sysfs_lock use so it is held until after the 'queue' kobj is removed. To do so blk_mq_unregister_dev() must not also take q->sysfs_lock. So rename __blk_mq_unregister_dev() to blk_mq_unregister_dev(). Also, blk_unregister_queue() should use q->queue_lock to protect against any concurrent writes to q->queue_flags -- even though chances are the queue is being cleaned up so no concurrent writes are likely. Fixes: e9a823fb34a8b ("block: fix warning when I/O elevator is changed as request_queue is being removed") Signed-off-by: Mike Snitzer Reviewed-by: Ming Lei Signed-off-by: Jens Axboe (cherry picked from commit 667257e8b2988c0183ba23e2bcd6900e87961606) Signed-off-by: Mauricio Faria de Oliveira --- block/blk-mq-sysfs.c | 9 +-------- block/blk-sysfs.c | 13 ++++++++++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/block/blk-mq-sysfs.c b/block/blk-mq-sysfs.c index 79969c3c234f..a54b4b070f1c 100644 --- a/block/blk-mq-sysfs.c +++ b/block/blk-mq-sysfs.c @@ -248,7 +248,7 @@ static int blk_mq_register_hctx(struct blk_mq_hw_ctx *hctx) return ret; } -static void __blk_mq_unregister_dev(struct device *dev, struct request_queue *q) +void blk_mq_unregister_dev(struct device *dev, struct request_queue *q) { struct blk_mq_hw_ctx *hctx; int i; @@ -265,13 +265,6 @@ static void __blk_mq_unregister_dev(struct device *dev, struct request_queue *q) q->mq_sysfs_init_done = false; } -void blk_mq_unregister_dev(struct device *dev, struct request_queue *q) -{ - mutex_lock(&q->sysfs_lock); - __blk_mq_unregister_dev(dev, q); - mutex_unlock(&q->sysfs_lock); -} - void blk_mq_hctx_kobj_init(struct blk_mq_hw_ctx *hctx) { kobject_init(&hctx->kobj, &blk_mq_hw_ktype); diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index 870484eaed1f..9272452ff456 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -929,12 +929,17 @@ void blk_unregister_queue(struct gendisk *disk) if (WARN_ON(!q)) return; + /* + * Protect against the 'queue' kobj being accessed + * while/after it is removed. + */ mutex_lock(&q->sysfs_lock); - queue_flag_clear_unlocked(QUEUE_FLAG_REGISTERED, q); - mutex_unlock(&q->sysfs_lock); - wbt_exit(q); + spin_lock_irq(q->queue_lock); + queue_flag_clear(QUEUE_FLAG_REGISTERED, q); + spin_unlock_irq(q->queue_lock); + wbt_exit(q); if (q->mq_ops) blk_mq_unregister_dev(disk_to_dev(disk), q); @@ -946,4 +951,6 @@ void blk_unregister_queue(struct gendisk *disk) kobject_del(&q->kobj); blk_trace_remove_sysfs(disk_to_dev(disk)); kobject_put(&disk_to_dev(disk)->kobj); + + mutex_unlock(&q->sysfs_lock); }