From patchwork Thu May 4 10:56:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 13231035 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC79CC7EE21 for ; Thu, 4 May 2023 10:56:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3F5BD6B007B; Thu, 4 May 2023 06:56:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3A5F26B007D; Thu, 4 May 2023 06:56:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 294DE6B007E; Thu, 4 May 2023 06:56:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) by kanga.kvack.org (Postfix) with ESMTP id E3C496B007B for ; Thu, 4 May 2023 06:56:35 -0400 (EDT) Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-9659c5b14d8so49649266b.3 for ; Thu, 04 May 2023 03:56:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683197795; x=1685789795; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=ifOfkEUyxxO0eazLLKLawS21srpdOWmLX2BHDyl3i/E=; b=r6/ULPkETTOQMH/robFPgDlQCst1bREYJAsFn1dwhp1MLmY5wcl5twzUKHdKZPf3Ze EsTq0uWPk86oeTO9wQ/eYqzHXRD+koT4Uf2UClwaMh7lkTA6VTMO7nuZOKmTLTdr+Pd5 yU00n4P009PDG13BAWmuQXGz5t705gggUNyiK7Ro7snRgKBmcWGitgDPMmbxSu2IaNzq WL4esf1Oek2AYFza9Y74mHcHzccfEuf/XoB/JYsVoGbaR2dKVKe3/4W1YFh4r2/T710o 86pPPfnJrjmyuIOHyluem8JkDDqd2gxZku1IPJ3+pMbf9eYlLiQWGdZRhbCJhiDMMQU/ /bvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683197795; x=1685789795; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ifOfkEUyxxO0eazLLKLawS21srpdOWmLX2BHDyl3i/E=; b=CWh4wztvN/YcxX2oQj342578Ee0jSCo8lngBAGs0NswYtb40FR2Lw6lyray3RrpE0s TviMbNBQo6HwEA3hrs/OZ49aZ+Y/3M7s7Ump/fU+Y16izhapj95P4w3xkhgrGFx5U9OT ncDQ7GEHtGiF8burCix5byUybpi4UYwuVdFrzof+uROxyqlQnNyjyrITiuqZ/2CMPpco GN2vf5NqyLGwKDAKKc9IHVPnjSN7HxcN4kmZcC449gmRa2SnrQTset9dtTGjhgN93OID oQVKMy6bc45B3+ikNew6UL3i7rf9qu6zFMStKEw/WD3YrcK4SiYXBbHAY9uLBMGZlkS8 dfxQ== X-Gm-Message-State: AC+VfDwsPCtgPsATRBp3iv6UVzFT4wk/x1HjtpqkU+d8hrDq4xeR8CPu +zMoVX1/CwqMAFMquy8SBwU= X-Google-Smtp-Source: ACHHUZ6TwBZnyii5xpKaYAkZBKaa26bobPL9RsirRFkmhWeDc3ct+W+i8UFXXhJGPnxNy6ZUymQpZQ== X-Received: by 2002:a17:907:8a02:b0:93e:908d:cfe2 with SMTP id sc2-20020a1709078a0200b0093e908dcfe2mr6022858ejc.0.1683197794976; Thu, 04 May 2023 03:56:34 -0700 (PDT) Received: from zambezi.local (ip-94-112-104-28.bb.vodafone.cz. [94.112.104.28]) by smtp.gmail.com with ESMTPSA id hf15-20020a1709072c4f00b009659fa6eeddsm988030ejc.196.2023.05.04.03.56.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 May 2023 03:56:34 -0700 (PDT) From: Ilya Dryomov To: Christoph Hellwig Cc: Jan Kara , Johannes Thumshirn , Jens Axboe , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm: always respect QUEUE_FLAG_STABLE_WRITES on the block device Date: Thu, 4 May 2023 12:56:24 +0200 Message-Id: <20230504105624.9789-1-idryomov@gmail.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Commit 1cb039f3dc16 ("bdi: replace BDI_CAP_STABLE_WRITES with a queue and a sb flag") introduced a regression for the raw block device use case. Capturing QUEUE_FLAG_STABLE_WRITES flag in set_bdev_super() has the effect of respecting it only when there is a filesystem mounted on top of the block device. If a filesystem is not mounted, block devices that do integrity checking return sporadic checksum errors. Additionally, this commit made the corresponding sysfs knob writeable for debugging purposes. However, because QUEUE_FLAG_STABLE_WRITES flag is captured when the filesystem is mounted and isn't consulted after that anywhere outside of swap code, changing it doesn't take immediate effect even though dumping the knob shows the new value. With no way to dump SB_I_STABLE_WRITES flag, this is needlessly confusing. Resurrect the original stable writes behavior by changing folio_wait_stable() to account for the case of a raw block device and also: - for the case of a filesystem, test QUEUE_FLAG_STABLE_WRITES flag each time instead of capturing it in the superblock so that changes are reflected immediately (thus aligning with the case of a raw block device) - retain SB_I_STABLE_WRITES flag for filesystems that need stable writes independent of the underlying block device (currently just NFS) Cc: stable@vger.kernel.org Fixes: 1cb039f3dc16 ("bdi: replace BDI_CAP_STABLE_WRITES with a queue and a sb flag") Signed-off-by: Ilya Dryomov --- fs/super.c | 2 -- mm/page-writeback.c | 12 +++++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/fs/super.c b/fs/super.c index 04bc62ab7dfe..6705b3506ae8 100644 --- a/fs/super.c +++ b/fs/super.c @@ -1213,8 +1213,6 @@ static int set_bdev_super(struct super_block *s, void *data) s->s_dev = s->s_bdev->bd_dev; s->s_bdi = bdi_get(s->s_bdev->bd_disk->bdi); - if (bdev_stable_writes(s->s_bdev)) - s->s_iflags |= SB_I_STABLE_WRITES; return 0; } diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 516b1aa247e8..469bc57add8c 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -3169,7 +3169,17 @@ EXPORT_SYMBOL_GPL(folio_wait_writeback_killable); */ void folio_wait_stable(struct folio *folio) { - if (folio_inode(folio)->i_sb->s_iflags & SB_I_STABLE_WRITES) + struct inode *inode = folio_inode(folio); + struct super_block *sb = inode->i_sb; + bool stable_writes; + + if (sb_is_blkdev_sb(sb)) + stable_writes = bdev_stable_writes(I_BDEV(inode)); + else + stable_writes = bdev_stable_writes(sb->s_bdev) || + (sb->s_iflags & SB_I_STABLE_WRITES); + + if (stable_writes) folio_wait_writeback(folio); } EXPORT_SYMBOL_GPL(folio_wait_stable);