linux-bcache.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Zhou Jifeng" <zhoujifeng@kylinos.com.cn>
To: "Coly Li" <colyli@kernel.org>
Cc: "kent.overstreet" <kent.overstreet@linux.dev>,
	linux-bcache <linux-bcache@vger.kernel.org>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] bcache: enhancing the security of dirty data writeback
Date: Wed, 6 Aug 2025 19:19:49 +0800	[thread overview]
Message-ID: <tencent_59A1DBB462115B77340A389D@qq.com> (raw)
In-Reply-To: <20250805162915.3kaqbxjbwfuj6u6w@P16.>

On Wed, 6 Aug 2025 at 00:29, Coly Li <colyli@kernel.org> wrote:
>
> On Tue, Aug 05, 2025 at 05:37:44PM +0800, Zhou Jifeng wrote:
> > On Tue, 5 Aug 2025 at 13:00, Coly Li <colyli@kernel.org> wrote:
> > >
> > > On Thu, Jul 31, 2025 at 02:21:40PM +0800, Zhou Jifeng wrote:
> > > > There is a potential data consistency risk in bcache's writeback mode:when
> > > > the application calls fsync, bcache returns success after completing the
> > > > log write, persisting the cache disk data, and persisting the HDD internal
> > > > cache. However, at this point, the actual application data may still be in
> > > > a dirty state and remain stuck in the cache disk. when these data are
> > > > subsequently written back to the HDD asynchronously through REQ_OP_WRITE,
> > > > there is no forced refresh mechanism to ensure physical placement on the
> > > > disk, and there may be no power-off protection measures, which poses a risk
> > > > of data loss. This mechanism may cause the application to misjudge that the
> > > > data has been persisted, which is different from the actual storage state,
> > > > and also violates the semantic agreement that fsync should ensure data
> > > > persistence.
> > > >
> > >
> > > [snipped]
> > >
> > >
> > >
> > > If before the cleared key inserted into the btree, there are new write
> > > into overlapped LBA range of the cleared key and a dirty key inserted.
> > > Then the cleared key is inserted and overwrites the dirty key, but the
> > > dirty data on cache is not written back to backing device yet. How to
> > > handle such situation?
> > >
> >
> > There are indeed some issues here. I have initially come up with a
> > solution: Utilize the existing dc->writeback_keys mechanism for
> > protection. The general processing flow is as follows:
> > 1. In the write_dirty_finish() function, remove the operation of
> > updating bkey insertion, and delete the code bch_keybuf_del(&dc
> > ->writeback_keys, w).
> > 2. After executing the read_dirty(dc) code, perform flush, then
> > insert the updated bkey, and finally remove the bkey from dc->
> > writeback_keys. This process is equivalent to sending a flush
> > every KEYBUF_NR bkeys are written back.
> > 3. Support configurable KEYBUF_NR to indirectly control the
> > frequency of flush.
> >
> > Is this plan appropriate? Or are there any better ways to handle it?
>
> No, I won't suggest this way. It sounds complicaed and changes the main
> code flow too much in an implicit way, this should be avoided.
>
> So it seems Kent's suggestion to flush backing device before committing
> jset is the proper method I can see now.
>
> Coly Li
>

Sorry, my previous response was not rigorous enough. I have carefully
considered your question about "the bkey being overwritten". In fact,
there is no issue of being overwritten. The bcache has ingeniously
designed a replace mechanism. In my code, the bkey with the dirty flag
cleared is inserted using the replace method. This method handles
address overlaps ingeniously during the insertion of the bkey and will
not overwrite the bkey generated by concurrent writes. The main code
for the replace mechanism is located in bch_btree_insert_key->bch_extent_insert_fixup
, which calls the bch_bkey_equal_header function, which is also a
crucial checkpoint.

  reply	other threads:[~2025-08-06 11:20 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-31  6:21 [PATCH] bcache: enhancing the security of dirty data writeback Zhou Jifeng
2025-07-31 15:49 ` Kent Overstreet
2025-08-01  2:27   ` Zhou Jifeng
2025-08-01  2:37     ` Kent Overstreet
2025-08-01  3:30       ` Zhou Jifeng
2025-08-01  3:41         ` Kent Overstreet
2025-08-01  6:10           ` Zhou Jifeng
2025-08-02 17:29             ` Coly Li
2025-08-02 18:49               ` Kent Overstreet
2025-08-04  3:47               ` Zhou Jifeng
2025-08-04  4:17                 ` Kent Overstreet
2025-08-04 15:31                   ` Coly Li
2025-08-04 16:07                     ` Kent Overstreet
2025-08-05  1:17                       ` Zhou Jifeng
2025-08-05  1:31                         ` Kent Overstreet
2025-08-05  3:31                           ` Coly Li
2025-08-05  3:34                             ` Kent Overstreet
2025-08-05  4:57 ` Coly Li
2025-08-05  9:37   ` Zhou Jifeng
2025-08-05 16:29     ` Coly Li
2025-08-06 11:19       ` Zhou Jifeng [this message]
2025-08-06 16:10         ` Coly Li
2025-08-07  2:01           ` Zhou Jifeng
2025-08-13  2:12             ` [PATCH v2] " Zhou Jifeng
2025-08-13  7:11               ` Zhou Jifeng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tencent_59A1DBB462115B77340A389D@qq.com \
    --to=zhoujifeng@kylinos.com.cn \
    --cc=colyli@kernel.org \
    --cc=kent.overstreet@linux.dev \
    --cc=linux-bcache@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).