From patchwork Fri Jan 19 12:43:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guilherme G. Piccoli" X-Patchwork-Id: 864213 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=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id 3zQ7vj4T5qz9s0g; Mon, 22 Jan 2018 22:08:17 +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 1edZxT-0005wa-FA; Mon, 22 Jan 2018 11:08:11 +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 1ecW0r-00022Z-R5 for kernel-team@lists.ubuntu.com; Fri, 19 Jan 2018 12:43:17 +0000 Received: from mail-qt0-f200.google.com ([209.85.216.200]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1ecW0r-0007A0-HZ for kernel-team@lists.ubuntu.com; Fri, 19 Jan 2018 12:43:17 +0000 Received: by mail-qt0-f200.google.com with SMTP id d15so2386136qtg.2 for ; Fri, 19 Jan 2018 04:43:17 -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; bh=xvAIl9OnOJOdmBlpxyyHV49SAuKKCdKk0zHiTB0+Nkk=; b=ITJ+ZgU3YHtpl1RsVhKyh1haUf9IhHEYeRnUXitWL19JqUDZxoGNr+8waMbVi6xn1z A+mBWGK1Quh6fDaF3EP9x7OYPIdqRaaO+MqbCvAe0daqTGbZE55xBbmVbfdcKRe1zpoQ F+JvbPbxR8mcfJQT5AdGMyxyiNnYan/Eld+koO7lc/rfkVt/svm+ulUYkIWU1VTVypZb 6fAcTgqEf7WywtEOV8qgwgJSz8kkPBp/w5I3jNivAxSZb3nS1o229JGxu4QOUlakYJo5 4EwC7Z7F6M5pS1f/ffCRFE1N8Pc8ZVYiOsAN2mFlep9n2INaq5EVQ1Cz0KkY/e0AGYxt ufDw== X-Gm-Message-State: AKwxytdjpaCLGVlUr5zxO6jykQpI0T9610uIf2xMJ3Nm6Xajn2BWSrrV ZJG/lpXTW80MNw9Qfd91ig3jG7diN9PvsTrg+PMkq9wtFuwXUyZ3Bc+0iV6Nyo+NmritpcJlmy3 UHpe2mZzWIoGyCmBn1ZPpm+q+qcbO/HJbXrxlSjGAeA== X-Received: by 10.200.54.208 with SMTP id b16mr36263060qtc.187.1516365796483; Fri, 19 Jan 2018 04:43:16 -0800 (PST) X-Google-Smtp-Source: ACJfBouNaI0WDi5aqBd7N0kGngCMLMO4MAG/MiwnFE1rVh05+Lau4Um9828Y/cNc7NwMY7qH4mSq7w== X-Received: by 10.200.54.208 with SMTP id b16mr36263049qtc.187.1516365796327; Fri, 19 Jan 2018 04:43:16 -0800 (PST) Received: from localhost ([179.110.113.168]) by smtp.gmail.com with ESMTPSA id i39sm5399992qte.19.2018.01.19.04.43.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Jan 2018 04:43:15 -0800 (PST) From: "Guilherme G. Piccoli" To: kernel-team@lists.ubuntu.com Subject: [PATCH][SRU][Artful] blk-mq-tag: check for NULL rq when iterating tags Date: Fri, 19 Jan 2018 10:43:12 -0200 Message-Id: <20180119124312.16507-1-gpiccoli@canonical.com> X-Mailer: git-send-email 2.15.1 X-Mailman-Approved-At: Mon, 22 Jan 2018 11:08:04 +0000 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: , Cc: gpiccoli@canonical.com MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Jens Axboe BugLink: https://bugs.launchpad.net/bugs/1744300 Since we introduced blk-mq-sched, the tags->rqs[] array has been dynamically assigned. So we need to check for NULL when iterating, since there's a window of time where the bit is set, but we haven't dynamically assigned the tags->rqs[] array position yet. This is perfectly safe, since the memory backing of the request is never going away while the device is alive. Reviewed-by: Bart Van Assche Reviewed-by: Omar Sandoval Signed-off-by: Jens Axboe (cherry-pick from commit 7f5562d5ecc44c757599b201df928ba52fa05047) Signed-off-by: Guilherme G. Piccoli Acked-by: Khalid Elmously Acked-by: Kamal Mostafa --- block/blk-mq-tag.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/block/blk-mq-tag.c b/block/blk-mq-tag.c index d0be72ccb091..dc9e6dac5a2a 100644 --- a/block/blk-mq-tag.c +++ b/block/blk-mq-tag.c @@ -214,7 +214,11 @@ static bool bt_iter(struct sbitmap *bitmap, unsigned int bitnr, void *data) bitnr += tags->nr_reserved_tags; rq = tags->rqs[bitnr]; - if (rq->q == hctx->queue) + /* + * We can hit rq == NULL here, because the tagging functions + * test and set the bit before assining ->rqs[]. + */ + if (rq && rq->q == hctx->queue) iter_data->fn(hctx, rq, iter_data->data, reserved); return true; } @@ -248,9 +252,15 @@ static bool bt_tags_iter(struct sbitmap *bitmap, unsigned int bitnr, void *data) if (!reserved) bitnr += tags->nr_reserved_tags; + + /* + * We can hit rq == NULL here, because the tagging functions + * test and set the bit before assining ->rqs[]. + */ rq = tags->rqs[bitnr]; + if (rq) + iter_data->fn(rq, iter_data->data, reserved); - iter_data->fn(rq, iter_data->data, reserved); return true; }