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: 9570755 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 9267960578 for ; Mon, 13 Feb 2017 21:01:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 847F822BF1 for ; Mon, 13 Feb 2017 21:01:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 796FC28356; Mon, 13 Feb 2017 21:01:26 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI 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 2064B28355 for ; Mon, 13 Feb 2017 21:01:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753394AbdBMVBZ (ORCPT ); Mon, 13 Feb 2017 16:01:25 -0500 Received: from mail-wr0-f180.google.com ([209.85.128.180]:34972 "EHLO mail-wr0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753382AbdBMVBX (ORCPT ); Mon, 13 Feb 2017 16:01:23 -0500 Received: by mail-wr0-f180.google.com with SMTP id c4so1050310wrd.2 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=iXuGc8DoxIt11gtsn53zEiXVcZi9O+CMkuJvcjgKVfp4yY6uXCuB+yhZhDq/WHpZJf SM4JropH8pnJyodjz/8R9r7fN3hvMknG/MhNN3xO89bLodjYO4JahzGg1j97K4mcbNk8 hAD8vUMb2f0Y/8hNbx4autMeDQzXEuuA/ptg5Tt1AIpzx2SQcONZVa8lfWsrFZKuaMve dFCr0NLX1sLyA8SBUK8hYO8ooFHM1CxwUrLvL+sA46n825swsCo/0a+GQZ5grC6TezQm UHM9bO6p/WfMis83vr0wCM3WW+yIWRZBNsFknEWjnOZXtMucNM62Y/v6IQJQpB1Suy6g BTcA== X-Gm-Message-State: AMke39k4tXRTbtfKB/P15aLvRbFDfCCNN+jEjapCNfvBHYR/NvsefcNj3n1RcQiJj7bzIBum 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-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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;