From patchwork Mon Feb 13 21:01:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Valente X-Patchwork-Id: 93913 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp1270853qgi; Mon, 13 Feb 2017 13:01:27 -0800 (PST) X-Received: by 10.84.218.68 with SMTP id f4mr8539238plm.136.1487019687652; Mon, 13 Feb 2017 13:01:27 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 79si11058032pfs.104.2017.02.13.13.01.27; Mon, 13 Feb 2017 13:01:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753419AbdBMVB0 (ORCPT + 25 others); Mon, 13 Feb 2017 16:01:26 -0500 Received: from mail-wr0-f182.google.com ([209.85.128.182]:34760 "EHLO mail-wr0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753385AbdBMVBX (ORCPT ); Mon, 13 Feb 2017 16:01:23 -0500 Received: by mail-wr0-f182.google.com with SMTP id o16so159167781wra.1 for ; Mon, 13 Feb 2017 13:01:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=vq6a+XIyM3H1ozOodhh7jkqfDf0tPazZ70MUINp2W5E=; b=jNQj7emBgQ7d1jR/4E+X9kZ8/WGzqLbN699proUNmvTXoifG8sNC5AYNINZk/oe+N1 24IWHkiIUF2J+KAz+xNiGxRiWXH6z+E+ayz6HBFEZS62IUzsPhF4SsOrTnqK6Z3LkUuR mEndrEA1l0DrAMwY9zg9SVfjsw6Z2cjKFJmhk= 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=vq6a+XIyM3H1ozOodhh7jkqfDf0tPazZ70MUINp2W5E=; b=ljULOHzwfwF68Cl5TYiyZrMm0tc/UorAxhy3W9XKfjhyarD0w04c9CGNZZnWVJokcW ekWo/XQvBJyolxvn2iywQHpB1ad42nGLRlUpCGV3X2uyNENdKcx7tc1eSUwc+v/8TFc5 JPV9xDVXNJ6dogoR0kqk7HoAd2WGd7n3pmIVKkF7pHG++VWlT9X5wI7pLLa2vsNKlG0T +LxVHTRkZKP36sohXWLCXVELv2YtIPGRt7gU948KVGQfmeJVF2ZRjifAy5fBuxUi3ppd svcO+bEtGfhZzUynpRGsgc9rCreoWUfO5nDYswfzGxxb81tXXmQWZ5NWbBDkFhYl10Mn N/Hw== X-Gm-Message-State: AMke39muHL4mKAiTSTwMclUVN/4tvAFbPoYGzMnAGfhGCbXGdkRfDxrfjATNhVxwKWKqOXjd X-Received: by 10.223.141.229 with SMTP id o92mr23398942wrb.22.1487019682250; Mon, 13 Feb 2017 13:01:22 -0800 (PST) Received: from localhost.localdomain ([185.14.10.163]) by smtp.gmail.com with ESMTPSA id m26sm12114781wrb.68.2017.02.13.13.01.20 (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 13 Feb 2017 13:01:21 -0800 (PST) From: Paolo Valente To: Jens Axboe , Tejun Heo Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, ulf.hansson@linaro.org, linus.walleij@linaro.org, broonie@kernel.org, Paolo Valente Subject: [PATCH BUGFIX] block: make elevator_get robust against cross blk/blk-mq choice Date: Mon, 13 Feb 2017 22:01:07 +0100 Message-Id: <20170213210107.4848-2-paolo.valente@linaro.org> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20170213210107.4848-1-paolo.valente@linaro.org> References: <20170213210107.4848-1-paolo.valente@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If, at boot, a legacy I/O scheduler is chosen for a device using blk-mq, or, viceversa, a blk-mq scheduler is chosen for a device using blk, then that scheduler is set and initialized without any check, driving the system into an inconsistent state. This commit addresses this issue by letting elevator_get fail for these wrong cross choices. Signed-off-by: Paolo Valente --- block/elevator.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) -- 2.10.0 diff --git a/block/elevator.c b/block/elevator.c index 27ff1ed..a25bdd9 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -99,7 +99,8 @@ static void elevator_put(struct elevator_type *e) module_put(e->elevator_owner); } -static struct elevator_type *elevator_get(const char *name, bool try_loading) +static struct elevator_type *elevator_get(const char *name, bool try_loading, + bool mq_ops) { struct elevator_type *e; @@ -113,6 +114,12 @@ static struct elevator_type *elevator_get(const char *name, bool try_loading) e = elevator_find(name); } + if (e && (e->uses_mq != mq_ops)) { + pr_err("ERROR: attempted to choose %s %s I/O scheduler in blk%s", + name, e->uses_mq ? "blk-mq" : "legacy", mq_ops ? "-mq" : ""); + e = NULL; + } + if (e && !try_module_get(e->elevator_owner)) e = NULL; @@ -201,7 +208,7 @@ int elevator_init(struct request_queue *q, char *name) q->boundary_rq = NULL; if (name) { - e = elevator_get(name, true); + e = elevator_get(name, true, q->mq_ops); if (!e) return -EINVAL; } @@ -212,7 +219,7 @@ int elevator_init(struct request_queue *q, char *name) * off async and request_module() isn't allowed from async. */ if (!e && *chosen_elevator) { - e = elevator_get(chosen_elevator, false); + e = elevator_get(chosen_elevator, false, q->mq_ops); if (!e) printk(KERN_ERR "I/O scheduler %s not found\n", chosen_elevator); @@ -220,17 +227,20 @@ int elevator_init(struct request_queue *q, char *name) if (!e) { if (q->mq_ops && q->nr_hw_queues == 1) - e = elevator_get(CONFIG_DEFAULT_SQ_IOSCHED, false); + e = elevator_get(CONFIG_DEFAULT_SQ_IOSCHED, false, + q->mq_ops); else if (q->mq_ops) - e = elevator_get(CONFIG_DEFAULT_MQ_IOSCHED, false); + e = elevator_get(CONFIG_DEFAULT_MQ_IOSCHED, false, + q->mq_ops); else - e = elevator_get(CONFIG_DEFAULT_IOSCHED, false); + e = elevator_get(CONFIG_DEFAULT_IOSCHED, false, + q->mq_ops); if (!e) { printk(KERN_ERR "Default I/O scheduler not found. " \ "Using noop/none.\n"); - e = elevator_get("noop", false); + e = elevator_get("noop", false, q->mq_ops); } } @@ -1051,7 +1061,7 @@ static int __elevator_change(struct request_queue *q, const char *name) return elevator_switch(q, NULL); strlcpy(elevator_name, name, sizeof(elevator_name)); - e = elevator_get(strstrip(elevator_name), true); + e = elevator_get(strstrip(elevator_name), true, q->mq_ops); if (!e) { printk(KERN_ERR "elevator: type %s not found\n", elevator_name); return -EINVAL;