From patchwork Mon Jul 29 19:17:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mauricio Faria de Oliveira X-Patchwork-Id: 1138623 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 45y8by2sGPz9sBt; Tue, 30 Jul 2019 05:18:21 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1hsB9x-0004yD-5H; Mon, 29 Jul 2019 19:18: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 1hsB9u-0004xg-SG for kernel-team@lists.ubuntu.com; Mon, 29 Jul 2019 19:18:10 +0000 Received: from mail-qk1-f198.google.com ([209.85.222.198]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1hsB9u-0006Cd-DF for kernel-team@lists.ubuntu.com; Mon, 29 Jul 2019 19:18:10 +0000 Received: by mail-qk1-f198.google.com with SMTP id z13so52814702qka.15 for ; Mon, 29 Jul 2019 12:18:10 -0700 (PDT) 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:mime-version :content-transfer-encoding; bh=YdIX1MiQs2vCLO127SliVBLyHJAOpLZxmZdDKwU0bJY=; b=iKWx0+f/I5PLK8T1n0i3Qoq4NQ8ri2EuEkSQxS3illNupr4oHugCuEA9++w7s2muGc QtIh5HMU+YldYy2D8SgBpt2nTUMf2gZLk4dPIwgeRRk97Bu98Tz8cxpZLcfr8w1AmLvM pagW+ynIm+c1R2oulbsKkDbmPwvsnJJZ6fyXPKzu+Cm2OiYIRCSer2JD33fnYCUjnja7 qBfmYebNadlqkjChrDpFS/urMCn3ZquuMGtCe4cAhV4DjkCbEZYUR6ravVhot5NRuo8k rhQpsjX0dVG8tBH/cIxj0TGTQqcGSlCuxe2BEgMeg6fAEinwsm0Z8mhDmwLeIglqbqCV /acw== X-Gm-Message-State: APjAAAV6UDcMiopoyRy5aN5RiZqMrnCz1qkSxMGoZzNcC/zODU4qfs2L XG5dSRn8KpiRpdwrjFSYvQ6jXl8wnsUXNVxq+QPc97xPJzGX7QD6U0nKy17CCaYWh0FUGpeXwWQ vEXGbU9cRsDuYD98mKaA/tm7GfuC3+uVC5AHxaE2UFA== X-Received: by 2002:a37:9d1:: with SMTP id 200mr72005170qkj.306.1564427889425; Mon, 29 Jul 2019 12:18:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqxpZsIpfkv+Bil6bM2CC0ohrn7Qbg3So/bZ/r8yymAf0hZgpzf9a4kt8JsyqnunN6I0yN7d1A== X-Received: by 2002:a37:9d1:: with SMTP id 200mr72005166qkj.306.1564427889228; Mon, 29 Jul 2019 12:18:09 -0700 (PDT) Received: from localhost.localdomain ([2804:14c:4e7:1017:8190:a107:cfe1:e44e]) by smtp.gmail.com with ESMTPSA id u1sm34355242qth.21.2019.07.29.12.18.07 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 29 Jul 2019 12:18:08 -0700 (PDT) From: Mauricio Faria de Oliveira To: kernel-team@lists.ubuntu.com Subject: [B][PATCH] bcache: only set BCACHE_DEV_WB_RUNNING when cached device attached Date: Mon, 29 Jul 2019 16:17:24 -0300 Message-Id: <20190729191724.16235-1-mfo@canonical.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 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: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Coly Li BugLink: https://bugs.launchpad.net/bugs/1837788 When people set a writeback percent via sysfs file, /sys/block/bcache/bcache/writeback_percent current code directly sets BCACHE_DEV_WB_RUNNING to dc->disk.flags and schedules kworker dc->writeback_rate_update. If there is no cache set attached to, the writeback kernel thread is not running indeed, running dc->writeback_rate_update does not make sense and may cause NULL pointer deference when reference cache set pointer inside update_writeback_rate(). This patch checks whether the cache set point (dc->disk.c) is NULL in sysfs interface handler, and only set BCACHE_DEV_WB_RUNNING and schedule dc->writeback_rate_update when dc->disk.c is not NULL (it means the cache device is attached to a cache set). This problem might be introduced from initial bcache commit, but commit 3fd47bfe55b0 ("bcache: stop dc->writeback_rate_update properly") changes part of the original code piece, so I add 'Fixes: 3fd47bfe55b0' to indicate from which commit this patch can be applied. Fixes: 3fd47bfe55b0 ("bcache: stop dc->writeback_rate_update properly") Reported-by: Bjørn Forsman Signed-off-by: Coly Li Reviewed-by: Bjørn Forsman Cc: stable@vger.kernel.org Signed-off-by: Jens Axboe (backported from commit 1f0ffa67349c56ea54c03ccfd1e073c990e7411e) [mfo: backport: fix fuzz; applies with git cherry-pick, not git am] Signed-off-by: Mauricio Faria de Oliveira Acked-by: Connor Kuehl Acked-by: Andrea Righi --- drivers/md/bcache/sysfs.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c index 17df47d085f1..6acbd38fa946 100644 --- a/drivers/md/bcache/sysfs.c +++ b/drivers/md/bcache/sysfs.c @@ -333,8 +333,13 @@ STORE(bch_cached_dev) if (attr == &sysfs_writeback_running) bch_writeback_queue(dc); + /* + * Only set BCACHE_DEV_WB_RUNNING when cached device attached to + * a cache set, otherwise it doesn't make sense. + */ if (attr == &sysfs_writeback_percent) - if (!test_and_set_bit(BCACHE_DEV_WB_RUNNING, &dc->disk.flags)) + if ((dc->disk.c != NULL) && + (!test_and_set_bit(BCACHE_DEV_WB_RUNNING, &dc->disk.flags))) schedule_delayed_work(&dc->writeback_rate_update, dc->writeback_rate_update_seconds * HZ);