From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (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 C049934CFCF for ; Tue, 4 Aug 2026 23:01:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=209.85.208.50 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785884486; cv=pass; b=mvmP7xHzVVJkI84QYlyI1hc4qofWChb9hKqHY6R7gyuV/zsrlMB2ZZ/XQC6B9o5WSg1kIlyOP4K1k6SL+ok5CUcqeJ8Vg+B0rsfVrtWPhHUOxPLrUdpVKve965t/Lf9ngqPJSYotKLX4VC3j9cUJHy8lFDOPfdTudcQVGqOXm04= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785884486; c=relaxed/simple; bh=IopsMBq3Iqrmhpt1GvIJX0f0inBUyip79dSnD2RW0vI=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=kIxHSXMuVglkg7mHRFcnLbasCx6uCQ2Yj+xx6f3tnRnVy4Gn1sj/IBY2ieMtywoaorP0E4atX0bOdWQAPHPo9zTCX2W1sFKoh3fXASFNxWVFL7sFCk1dowCM2kU5MJ/xR6txln6WRXxjqwCErVVXFDooIwUvcFwi3gaqJvjn05k= ARC-Authentication-Results:i=2; 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=d684zmVV; arc=pass smtp.client-ip=209.85.208.50 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="d684zmVV" Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-6a0a4a18180so493984a12.0 for ; Tue, 04 Aug 2026 16:01:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1785884483; cv=none; d=google.com; s=arc-20260327; b=oAhTvx6+JcSsHqHCGOyOhqwQvQ1gAAgi+M2n542rK34dF7U/I9ack115WV7T5zgS0z 9tnt6DjTRV9vvL+PAAZfkXVOnRIrcUw0LEAbIU6egQ4M5jIYzs92kdrTYSL72QNp02pU rek6HjAApafS5Iy1QfNTn1ktVOW9KRGk/YzqSw6E8GiF8dz4hL5N3WnXoR1nXLv/rvvN 7tzAc2HpP+OIXGA1BRcsTybUOiDCT1+Grjt4nGzfLKxE2D5K1obuOhi2S16Ng//mJTiw QeMQRvbbQXgylPQ8ToYr0TB40Cyi9PfpXQzQfX/fVsIS3haOCd9L0a5hEtVSTM/qwH5O 6g9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=1yp2h2soLRnEcYsxIwWN6JD3tw9DOEM8R0hdKPhFP8g=; fh=CVv5bDfrG3wCfijl3yGpspcZ5fNstR+LmZuT8V4J590=; b=lfpuY5q2xSnw1mhVw3ceBNWglEtzQpG1QqX8nZryZDm35bSPlR7ZkJ3WwAQro9rGRc up9H5yCq0GpjHIenK6Kux1ozjFKrrMuGjUOePvhi42mzcYJZSeqvNtGOEGUSQgtmjdT0 KcwWtpKBQvSEvY9FjmrJyyQhcQX4+5pN+E5fIE+eTa23AmcqogsnCb63mJLN87PECpZG yEvPU8t4bKpovol2jzDGeAVTppYDvz+qzrnGkUYE5oTJml+7eRdsPh0j2hqWNE7nI/sZ EiNNhM8+X+EyIgdbfip1OOnXxocNsCuURLlGR37RtEsSWOsCdPX729n6wkOASIu/Tshy WSwg==; darn=vger.kernel.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785884483; x=1786489283; darn=vger.kernel.org; h=content-transfer-encoding:content-type:cc:to:subject:message-id :date:from:in-reply-to:references:mime-version:from:to:cc:subject :date:message-id:reply-to:content-type; bh=1yp2h2soLRnEcYsxIwWN6JD3tw9DOEM8R0hdKPhFP8g=; b=d684zmVVUDvH76KTkE/JHRALhH1p6ct83GO0P/OUAvjVKRKjUYr60lu7WumTn26RkW DUA2h0zETTlE1ynnXhM2kewN946wyPLdsAEyeq4j+gJBLUgKKPdIFJdYau2eVSm3SReH YwwcSQnDz4eqfoeATePu3q9LqreStNKh874fklLTf3k3o85UX0Bl9Hmbi+YO+RgTd1wP jsYwQtb90SuyRp695eKHRAIsCl4WxAGoVHC+RWn0DZzomRdZVGKScqPsWgCdnjF3bWOB u7MNXXNVxDDglPBSP9Oh5jUZ4gYCHq0k9c31m8QgpSjaDGb3+DPMQZxkxppHOauTDReY XEiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785884483; x=1786489283; h=content-transfer-encoding:content-type:cc:to:subject:message-id :date:from:in-reply-to:references:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=1yp2h2soLRnEcYsxIwWN6JD3tw9DOEM8R0hdKPhFP8g=; b=ptevJjiuVetyPYqR5ND7duB514bYDjQyK/XvqJwpJB/dHysgjZSnbVSYCnurg3b38S CulwoS2lbXD/tAmA7MAmvfHg/AK+MCCvbFcjZVNaEu74E6LFMbrP+f+svCeUCWv8v/CI IJD2W4qgpKnyIRaGZVZXwJWGOg/zP7pcIcYTPlRKU4+Ewwp6gMTudVIEXmYTzcpRCjKE AD+F6Hidh4gSm3JjwPKrZHydmlSTab7gfjX4yDBpNc8j6qoGAezwvz/e+gg+MagQVevx OzCkBsVestnpBU3AityXPGaLxm69BsOAczi2cmUEY9S4aA4WrkmVWzoiJXhcRYCiysOs 9jVA== X-Forwarded-Encrypted: i=1; AHgh+RozVRLcR9xcd9JsGyRJwFdCFGKOPUHNP9Uubc9fG4QTOkQ9hHLqqHUV9J8TElKcoNtidhBIRlKaHWNXUic=@vger.kernel.org X-Gm-Message-State: AOJu0YwPwz/RAZxgewMAWyoGix2QRQhXS4V7boCWhkpK/P0wQ5hW7nQo gK4I6s3BNiQlJAnvs7N3DSYztIMnqWu8rNFH4pWhYeYiO5KHPNoSxvwU4WW6srbXF3RTy/icWK6 2bXJO65xFfpjQ/e7qiTbObzypByXRf2Q= X-Gm-Gg: AR+sD12fI0xJiNKmPAQypBaxKNcOIHVfCk7bqdS+VMkL6CRAD3100HI09Lqb1g1EU7T zqpnQ0IcTSHZIYZGFFRgq1VX2AePFZX4g+HyTSndPgL4OtxKjTwAT5o3wiqx9yr3OlITsmRqHKW 5pOM2qN/D0jJ2SSj0O9v0Y/8lIZtAVfWdIYqMKmZRIfnSl9Sg049wVZu49ksPfqfJOKrXtCw+TJ z20d3blUmn8jmQlg7YQR/Kq2cSZh2zhudfHwG0o5xIVaMFs4XZJLRz8q4pYizvFdSHTngVSV/lX 7fmXEb6sWhrlNk9yoOkzMw5cdp+YI4qgHxnc0nXA/DtdafKX/5o8cNP5 X-Received: by 2002:a05:6402:1f4b:b0:69f:d4b7:9476 with SMTP id 4fb4d7f45d1cf-6a14f0e51c5mr1269188a12.4.1785884482828; Tue, 04 Aug 2026 16:01:22 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <3aa278c3b75de2bca8a94ec0c0e40922b1170881.1785621505.git.coshi036@gmail.com> In-Reply-To: From: Chris S Date: Tue, 4 Aug 2026 19:01:10 -0400 X-Gm-Features: AUfX_mxYao6cSkbq9heyNF_IuXvbT2WPjBf_yLUjm-kTEtW0_MWXVTs6WeiPsWA Message-ID: Subject: Re: [PATCH 19/19] buffer: stop clearing BH_Uptodate when a write fails To: Jan Kara Cc: Christian Brauner , Alexander Viro , Matthew Wilcox , linux-fsdevel@vger.kernel.org, "Theodore Ts'o" , Andreas Dilger , Baokun Li , Ojaswin Mujoo , Ritesh Harjani , Zhang Yi , Bob Copeland , Namjae Jeon , Sungjong Seo , Yuezhang Mo , OGAWA Hirofumi , Mark Fasheh , Joel Becker , Joseph Qi , Andreas Gruenbacher , linux-ext4@vger.kernel.org, ocfs2-devel@lists.linux.dev, gfs2@lists.linux.dev, linux-karma-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Jan, Thanks for your suggestion, changes on v2. Write completion no longer touches BH_Uptodate in either direction, here and in the jbd2 and ext4 fast commit handlers. I instrumented all four with WARN_ONCE(success && !buffer_uptodate(bh)) and exercised ext4 (data=3Djournal, fast_commit, -o sync), vfat and exfat - creates, rewrites, hardlinks, renames, deletes. It never fired. The BH_Write_EIO change is a separate patch at the end, since it has to move all five handlers and __bh_submit() together to stay bisectable. gfs2's handler is in it too; it already marked errors this way and needed the matching clear. __bh_submit() keeps set_buffer_req(), and the local 'op' goes with the clear - it had no other user. Chao On Tue, Aug 4, 2026 at 5:19=E2=80=AFAM Jan Kara wrote: > > On Sat 01-08-26 18:01:03, Chao Shi wrote: > > A buffer whose write failed still holds exactly the data the filesystem > > asked to be written. It is the disk that is out of date, not the buffe= r. > > Clearing BH_Uptodate says the opposite, and callers act on it: > > > > - mark_buffer_dirty() has a WARN_ON_ONCE(!buffer_uptodate(bh)). A > > filesystem that dirties the buffer again after a failed write - whic= h is > > the normal way to retry - trips it. That is the warning this series > > started from. > > > > - a buffer that is not up to date gets re-read from disk, which replac= es > > the data the filesystem was trying to write with the stale on-disk c= opy, > > silently. > > > > - the window between the write completing and the buffer being marked = not > > up to date is visible to anyone holding the folio lock, so the state= is > > not even self consistent while it lasts. > > > > BH_Write_EIO already records the failure, and by now every place in the > > tree that needs to know about it tests that flag instead: the two core > > helpers in this file, adfs, exfat, ext2, ext4, fat, gfs2, jbd2, ocfs2 a= nd > > omfs, converted one filesystem at a time in the preceding patches. The > > private completion handlers in jbd2 and ext4 fast commit were converted > > along with their waiters. Nothing is left that reads BH_Uptodate to fi= nd > > out whether a write failed, so the clears can go. > > > > Found by FuzzNvme. > > > > Signed-off-by: Chao Shi > > --- > > fs/buffer.c | 2 -- > > 1 file changed, 2 deletions(-) > > > > diff --git a/fs/buffer.c b/fs/buffer.c > > index ac978d9090c2..0002f0736398 100644 > > --- a/fs/buffer.c > > +++ b/fs/buffer.c > > @@ -207,7 +207,6 @@ void bh_end_write(struct bio *bio) > > } else { > > buffer_io_error(bh, ", lost sync page write"); > > mark_buffer_write_io_error(bh); > > - clear_buffer_uptodate(bh); > > } > > unlock_buffer(bh); > > } > > @@ -441,7 +440,6 @@ void bh_end_async_write(struct bio *bio) > > } else { > > buffer_io_error(bh, ", lost async page write"); > > mark_buffer_write_io_error(bh); > > - clear_buffer_uptodate(bh); > > } > > > > first =3D folio_buffers(folio); > > Please remove setting of the uptodate flag from these functions as well. > Write IO completion shouldn't really touch the uptodate flag at all... > > Hum, maybe we should actually clear the BH_Write_EIO flag on successful > write completion in all the end io handlers. And then we can drop the > clearing from __bh_submit(). And this will actually also address the > concern Sahiko raised (mostly harmless but still) that if the user gets t= o > check BH_Write_EIO after another process managed to redirty the buffer an= d > resubmit it for IO, it can miss detecting IO error that happened. > > Honza > -- > Jan Kara > SUSE Labs, CR