Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp1328710lqb; Thu, 30 May 2024 07:16:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXhKzC/qaqbYQn2C3+psnqbe7jEe9ls8GOLGum03VPTdrXL4T5mF6drIkHeVgtHIg8lDr1zc+hqBPp99uG0/pC1NKu62AklEGljb1eWQg== X-Google-Smtp-Source: AGHT+IH73AQQZWm1fpQuJY1w/H/Lh4hzdQEt/lAljhybWfrmin3kAKM1hFWNiSHND7kO32CPa1nB X-Received: by 2002:a05:6e02:1849:b0:374:5d1b:837 with SMTP id e9e14a558f8ab-3747df6eb48mr26142145ab.17.1717078570449; Thu, 30 May 2024 07:16:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717078570; cv=pass; d=google.com; s=arc-20160816; b=SNm64FkpV6IhX7vwjQ7LXTq3/fNvN5X2BwZC7TM1baMLfWjWEhAj1Y46M1jpgYoSBo VxQ+hMK49frOESs7eEK8zYBTzGWb3E9ncd4LAEHFUetPGHieEZBPhk7NWVkq+HByRI7N mRsjHEglFQn3ztmVnGE4dTAf+D2Gaol+ROlQRx3vYQmC9eoUA3/XTRFWmmKVsnF9/L1R /1SFkfgOeAbU0jOCBtbghashaYtJF71Lv/jaJ1vPG+Mq2nHZoJ3xYRvcRbYVQL7mvzCv yUimgVvs+wlm+1k/TByLVMJinQFQWBbTZymY1nltyzTKez1f3KJSdHHwXuwuUeAXLbcL 0SIw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=VMkhjE61Vc1NS7D/6XyyeGHdm9O21TTgPnUhmBGVGKE=; fh=f4rhZkORDPXI0NmXyLyiZHrUs6Ohlaxo5tFEnC7SIxI=; b=JZXkPbaIFaZqJMNCeg9ynUDLoSBaw2NcLmNBRqFSwzxzKIr3AdHLpl8NEY+GO3TnvE VCcTapk/P/8l5zCXBreALExixridwIZuQpWO1yqiA0lxTkdP7a8sRh9Go3oPPRNqcBgG tnKBAwm4Hc6fnlCoktcmw7yx8wi3bR6StOgszbpxx3cnR4VYFOKC5hCkEojxl1Mn/kdN SK7hS0Xb+IFjBnSbe3jtyHvVCaqRuiWDMz4lKkffvhz+E/WuzYZpXWWOqhXqTAs9WJCA DWiNv2Z375bEXcSvpLOKEV2D8LoM8s6bbOJk3pgb8vg1vtGfurPhKFpfoQWHQh8fMhVb qo5Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=UcUICF0W; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-195500-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195500-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id af79cd13be357-794abd3e7a4si239923285a.517.2024.05.30.07.16.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 07:16:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-195500-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=UcUICF0W; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-195500-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195500-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 2C1A51C235D1 for ; Thu, 30 May 2024 14:16:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AE70717623D; Thu, 30 May 2024 14:16:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UcUICF0W" Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9075C186E57; Thu, 30 May 2024 14:16:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717078563; cv=none; b=LWq9d97fDDcP0O2whDJsmct8mCKMl8HFXgEzzWvC9AEJq3GLUZBYm5z4loeJsGip7fGQhsXXYDl6bODndUg1axBLHVy1FQSYd0Mx00U/O1paBIuZxCLdMADTTP1XKVRhP+7M9yJjetysxyz5D0OmO1wdssLhyngjkxNnHaLF37s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717078563; c=relaxed/simple; bh=eYDjkHMzZN4bT1iF4ma6alWdkJjbsBK42F15E8PeHMQ=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=DQ42Hw46OOM5DjcSkBV8RBzBKaveKyF0+mSKHoKsCaZhv8AQHNyfkEAQlqxN0QVOj9dLw761f8EhkOkIF3mHZPVHbZv12azwaojcVxNZOf5S5vbwUCPx0BdA7R0bNn6zCPOrH65+hnTh0+22GbvsBhAHmFU+ejLhqdQqpaf2aZM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UcUICF0W; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1f47f07acd3so8377725ad.0; Thu, 30 May 2024 07:16:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717078562; x=1717683362; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=VMkhjE61Vc1NS7D/6XyyeGHdm9O21TTgPnUhmBGVGKE=; b=UcUICF0W+KUqWOod8EtQBCj1Cv6WzHVFqO1wZV5SgehyqUKAd+3neVLwUZeOuqUEKj jjex51rEPEYUe+7y/nsC9ZHntXR/7pbO+OiEkq4N58AQ3zT0/sZt9RWubRYHZq42Z6fQ daj6yRlGKqeMhOrDESl21If/0yXk+QusT3Cc3A6+u+23FiVIdVJ8As7NmxygEnFU+VVn mbB+Gd+Kd2p/wZj+tzv9Ep6564q9ATgpLBlAQR3bHkFDzNqLsduv1vIvKwanIsnPS/My T/hQuVUS5LPwQV9Db6gHC1xFPZmadE0G31yh0XuZzz4ZBBXMtqUCkyB6F6BMv/kjqKm5 9sVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717078562; x=1717683362; 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=VMkhjE61Vc1NS7D/6XyyeGHdm9O21TTgPnUhmBGVGKE=; b=AqRKvlLpho29df/hM8dqXIE4laAhlhLWtu3qA/3wfVCbhFDD+K15ZP5wDWr3xbUNO/ LAyY8pbFkMx9ixEkZXVFOVwI4IwK0kgX65gctVJD2JzDAf5nfIxn6/UQoTN/oCLU7+9P VCrtNjT/iAN+rV5fzZWV89pSQ285exkvcgWfHqh5XW5vy7YadPIsTeK1ZGED5UI6FDPY 55l4Wwm6SQ4oFDpQ+JNy7LUHRZHnDIoG4DyTco3F27JZzQ4UV2OyI+/sXZWA1cCJG5wO xIR7S/rcTArfq021VZppZdB7S0qMrGCvsXLzlM+liNtF35CJMrTdbcL3TiSGhKdCmhgQ MGwQ== X-Forwarded-Encrypted: i=1; AJvYcCXyPmo8I3iO6h1Aot9ArW5OZfFcVEIhmi6BjlflMTG1SvKQZhNFT/EyVgYFiB/A1AFRCOYuZNlzRbaeVgn6sOnrHSApopOB2NhWcCoe X-Gm-Message-State: AOJu0YxTiVBHCNVte1yvbPwurWqmKwTVVA9zdLi7y/+BnEAxiBpg5FO6 zfcr+umAocmKrC7BmZHyzyWBlR+F449ocNb2TUuB2eezVo9AHQvpTDsehw== X-Received: by 2002:a17:902:ea07:b0:1f4:a6cb:db3d with SMTP id d9443c01a7336-1f61973ac5emr23204175ad.44.1717078561680; Thu, 30 May 2024 07:16:01 -0700 (PDT) Received: from carrot.. (i223-217-95-32.s42.a014.ap.plala.or.jp. [223.217.95.32]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f44c9d89b3sm118848285ad.292.2024.05.30.07.15.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 07:16:00 -0700 (PDT) From: Ryusuke Konishi To: Andrew Morton Cc: linux-nilfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] nilfs2: fix potential kernel bug due to lack of writeback flag waiting Date: Thu, 30 May 2024 23:15:56 +0900 Message-Id: <20240530141556.4411-1-konishi.ryusuke@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Destructive writes to a block device on which nilfs2 is mounted can cause a kernel bug in the folio/page writeback start routine or writeback end routine (__folio_start_writeback in the log below): kernel BUG at mm/page-writeback.c:3070! Oops: invalid opcode: 0000 [#1] PREEMPT SMP KASAN PTI ... RIP: 0010:__folio_start_writeback+0xbaa/0x10e0 Code: 25 ff 0f 00 00 0f 84 18 01 00 00 e8 40 ca c6 ff e9 17 f6 ff ff e8 36 ca c6 ff 4c 89 f7 48 c7 c6 80 c0 12 84 e8 e7 b3 0f 00 90 <0f> 0b e8 1f ca c6 ff 4c 89 f7 48 c7 c6 a0 c6 12 84 e8 d0 b3 0f 00 ... Call Trace: nilfs_segctor_do_construct+0x4654/0x69d0 [nilfs2] nilfs_segctor_construct+0x181/0x6b0 [nilfs2] nilfs_segctor_thread+0x548/0x11c0 [nilfs2] kthread+0x2f0/0x390 ret_from_fork+0x4b/0x80 ret_from_fork_asm+0x1a/0x30 This is because when the log writer starts a writeback for segment summary blocks or a super root block that use the backing device's page cache, it does not wait for the ongoing folio/page writeback, resulting in an inconsistent writeback state. Fix this issue by waiting for ongoing writebacks when putting folios/pages on the backing device into writeback state. Signed-off-by: Ryusuke Konishi Fixes: 9ff05123e3bf ("nilfs2: segment constructor") Tested-by: Ryusuke Konishi Cc: stable@vger.kernel.org --- Andrew, please apply this as a bug fix. This fixes a kernel bug that is reproducible in some destructive testing. Thanks, Ryusuke Konishi fs/nilfs2/segment.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/nilfs2/segment.c b/fs/nilfs2/segment.c index 60d4f59f7665..6ea81f1d5094 100644 --- a/fs/nilfs2/segment.c +++ b/fs/nilfs2/segment.c @@ -1652,6 +1652,7 @@ static void nilfs_segctor_prepare_write(struct nilfs_sc_info *sci) if (bh->b_folio != bd_folio) { if (bd_folio) { folio_lock(bd_folio); + folio_wait_writeback(bd_folio); folio_clear_dirty_for_io(bd_folio); folio_start_writeback(bd_folio); folio_unlock(bd_folio); @@ -1665,6 +1666,7 @@ static void nilfs_segctor_prepare_write(struct nilfs_sc_info *sci) if (bh == segbuf->sb_super_root) { if (bh->b_folio != bd_folio) { folio_lock(bd_folio); + folio_wait_writeback(bd_folio); folio_clear_dirty_for_io(bd_folio); folio_start_writeback(bd_folio); folio_unlock(bd_folio); @@ -1681,6 +1683,7 @@ static void nilfs_segctor_prepare_write(struct nilfs_sc_info *sci) } if (bd_folio) { folio_lock(bd_folio); + folio_wait_writeback(bd_folio); folio_clear_dirty_for_io(bd_folio); folio_start_writeback(bd_folio); folio_unlock(bd_folio); -- 2.34.1