linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Meng Xu <mengxu.gatech@gmail.com>
To: linux-btrfs@vger.kernel.org
Subject: Possible data race on btrfs_set_block_group_used(&cache->item, ...) when two syncfs runs in parallel
Date: Wed, 27 Nov 2019 21:15:15 -0500	[thread overview]
Message-ID: <CAAwBoOKOAUf4KqmpTE+FFU4wz7nL9wO2HyjsiH5=1CL0HRkuSQ@mail.gmail.com> (raw)

Hi Btrfs Developer,

I am writing to report a data race between
btrfs_set_block_group_used(&cache->item, ...) and memcpy() while both
threads are running syncfs. Following is the call stack observed at
run time. I can confirm that the order of the [READ] and [WRITE]
statements are not deterministic.

[Setup]
create("bar", 511) = 3;
dup2(3, 198) = 198;
open("baz", 2097152, 511) = 4;


[Thread 1]
syncfs(4);

__do_sys_syncfs
  sync_filesystem
    __sync_filesystem
      btrfs_sync_fs
        btrfs_commit_transaction
          btrfs_start_dirty_block_groups
            write_one_cache_group
              write_extent_buffer
                [READ] memcpy(kaddr + offset, src, cur)  (src is the
pointer read)


[Thread 2]
syncfs(198);

__do_sys_syncfs
  sync_filesystem
    __sync_filesystem
      btrfs_sync_fs
        btrfs_commit_transaction
          btrfs_run_delayed_refs
            __btrfs_run_delayed_refs
               btrfs_run_delayed_refs_for_head
                 run_one_delayed_ref
                   run_delayed_tree_ref
                     alloc_reserved_tree_block
                       btrfs_update_block_group
                         btrfs_set_block_group_used
                           [WRITE]
btrfs_set_block_group_used(&cache->item, old_val);

Would you mind confirming whether this is a valid data race and
whether this might lead to inconsistent states on disk?

Best Regards,
Meng

                 reply	other threads:[~2019-11-28  2:15 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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='CAAwBoOKOAUf4KqmpTE+FFU4wz7nL9wO2HyjsiH5=1CL0HRkuSQ@mail.gmail.com' \
    --to=mengxu.gatech@gmail.com \
    --cc=linux-btrfs@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).