1. 15 10月, 2021 2 次提交
  2. 12 10月, 2021 2 次提交
  3. 27 8月, 2021 2 次提交
  4. 25 8月, 2021 1 次提交
  5. 24 8月, 2021 1 次提交
    • D
      xfs: only set IOMAP_F_SHARED when providing a srcmap to a write · 72a048c1
      Darrick J. Wong 提交于
      While prototyping a free space defragmentation tool, I observed an
      unexpected IO error while running a sequence of commands that can be
      recreated by the following sequence of commands:
      
      # xfs_io -f -c "pwrite -S 0x58 -b 10m 0 10m" file1
      # cp --reflink=always file1 file2
      # punch-alternating -o 1 file2
      # xfs_io -c "funshare 0 10m" file2
      fallocate: Input/output error
      
      I then scraped this (abbreviated) stack trace from dmesg:
      
      WARNING: CPU: 0 PID: 30788 at fs/iomap/buffered-io.c:577 iomap_write_begin+0x376/0x450
      CPU: 0 PID: 30788 Comm: xfs_io Not tainted 5.14.0-rc6-xfsx #rc6 5ef57b62a900814b3e4d885c755e9014541c8732
      Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.13.0-1ubuntu1.1 04/01/2014
      RIP: 0010:iomap_write_begin+0x376/0x450
      RSP: 0018:ffffc90000c0fc20 EFLAGS: 00010297
      RAX: 0000000000000001 RBX: ffffc90000c0fd10 RCX: 0000000000001000
      RDX: ffffc90000c0fc54 RSI: 000000000000000c RDI: 000000000000000c
      RBP: ffff888005d5dbd8 R08: 0000000000102000 R09: ffffc90000c0fc50
      R10: 0000000000b00000 R11: 0000000000101000 R12: ffffea0000336c40
      R13: 0000000000001000 R14: ffffc90000c0fd10 R15: 0000000000101000
      FS:  00007f4b8f62fe40(0000) GS:ffff88803ec00000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      CR2: 000056361c554108 CR3: 000000000524e004 CR4: 00000000001706f0
      Call Trace:
       iomap_unshare_actor+0x95/0x140
       iomap_apply+0xfa/0x300
       iomap_file_unshare+0x44/0x60
       xfs_reflink_unshare+0x50/0x140 [xfs 61947ea9b3a73e79d747dbc1b90205e7987e4195]
       xfs_file_fallocate+0x27c/0x610 [xfs 61947ea9b3a73e79d747dbc1b90205e7987e4195]
       vfs_fallocate+0x133/0x330
       __x64_sys_fallocate+0x3e/0x70
       do_syscall_64+0x35/0x80
       entry_SYSCALL_64_after_hwframe+0x44/0xae
      RIP: 0033:0x7f4b8f79140a
      
      Looking at the iomap tracepoints, I saw this:
      
      iomap_iter:           dev 8:64 ino 0x100 pos 0 length 0 flags WRITE|0x80 (0x81) ops xfs_buffered_write_iomap_ops caller iomap_file_unshare
      iomap_iter_dstmap:    dev 8:64 ino 0x100 bdev 8:64 addr -1 offset 0 length 131072 type DELALLOC flags SHARED
      iomap_iter_srcmap:    dev 8:64 ino 0x100 bdev 8:64 addr 147456 offset 0 length 4096 type MAPPED flags
      iomap_iter:           dev 8:64 ino 0x100 pos 0 length 4096 flags WRITE|0x80 (0x81) ops xfs_buffered_write_iomap_ops caller iomap_file_unshare
      iomap_iter_dstmap:    dev 8:64 ino 0x100 bdev 8:64 addr -1 offset 4096 length 4096 type DELALLOC flags SHARED
      console:              WARNING: CPU: 0 PID: 30788 at fs/iomap/buffered-io.c:577 iomap_write_begin+0x376/0x450
      
      The first time funshare calls ->iomap_begin, xfs sees that the first
      block is shared and creates a 128k delalloc reservation in the COW fork.
      The delalloc reservation is returned as dstmap, and the shared block is
      returned as srcmap.  So far so good.
      
      funshare calls ->iomap_begin to try the second block.  This time there's
      no srcmap (punch-alternating punched it out!) but we still have the
      delalloc reservation in the COW fork.  Therefore, we again return the
      reservation as dstmap and the hole as srcmap.  iomap_unshare_iter
      incorrectly tries to unshare the hole, which __iomap_write_begin rejects
      because shared regions must be fully written and therefore cannot
      require zeroing.
      
      Therefore, change the buffered write iomap_begin function not to set
      IOMAP_F_SHARED when there isn't a source mapping to read from for the
      unsharing.
      Signed-off-by: NDarrick J. Wong <djwong@kernel.org>
      Reviewed-by: NChristoph Hellwig <hch@lst.de>
      Reviewed-by: NChandan Babu R <chandanrlinux@gmail.com>
      72a048c1
  6. 21 8月, 2021 1 次提交
    • D
      xfs: fix perag structure refcounting error when scrub fails · 61e0d0cc
      Darrick J. Wong 提交于
      The kernel test robot found the following bug when running xfs/355 to
      scrub a bmap btree:
      
      XFS: Assertion failed: !sa->pag, file: fs/xfs/scrub/common.c, line: 412
      ------------[ cut here ]------------
      kernel BUG at fs/xfs/xfs_message.c:110!
      invalid opcode: 0000 [#1] SMP PTI
      CPU: 2 PID: 1415 Comm: xfs_scrub Not tainted 5.14.0-rc4-00021-g48c6615c #1
      Hardware name: Hewlett-Packard p6-1451cx/2ADA, BIOS 8.15 02/05/2013
      RIP: 0010:assfail+0x23/0x28 [xfs]
      RSP: 0018:ffffc9000aacb890 EFLAGS: 00010202
      RAX: 0000000000000000 RBX: ffffc9000aacbcc8 RCX: 0000000000000000
      RDX: 00000000ffffffc0 RSI: 000000000000000a RDI: ffffffffc09e7dcd
      RBP: ffffc9000aacbc80 R08: ffff8881fdf17d50 R09: 0000000000000000
      R10: 000000000000000a R11: f000000000000000 R12: 0000000000000000
      R13: ffff88820c7ed000 R14: 0000000000000001 R15: ffffc9000aacb980
      FS:  00007f185b955700(0000) GS:ffff8881fdf00000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      CR2: 00007f7f6ef43000 CR3: 000000020de38002 CR4: 00000000001706e0
      Call Trace:
       xchk_ag_read_headers+0xda/0x100 [xfs]
       xchk_ag_init+0x15/0x40 [xfs]
       xchk_btree_check_block_owner+0x76/0x180 [xfs]
       xchk_btree_get_block+0xd0/0x140 [xfs]
       xchk_btree+0x32e/0x440 [xfs]
       xchk_bmap_btree+0xd4/0x140 [xfs]
       xchk_bmap+0x1eb/0x3c0 [xfs]
       xfs_scrub_metadata+0x227/0x4c0 [xfs]
       xfs_ioc_scrub_metadata+0x50/0xc0 [xfs]
       xfs_file_ioctl+0x90c/0xc40 [xfs]
       __x64_sys_ioctl+0x83/0xc0
       do_syscall_64+0x3b/0xc0
      
      The unusual handling of errors while initializing struct xchk_ag is the
      root cause here.  Since the beginning of xfs_scrub, the goal of
      xchk_ag_read_headers has been to read all three AG header buffers and
      attach them both to the xchk_ag structure and the scrub transaction.
      Corruption errors on any of the three headers doesn't necessarily
      trigger an immediate return to userspace, because xfs_scrub can also
      tell us to /fix/ the problem.
      
      In other words, it's possible for the xchk_ag init functions to return
      an error code and a partially filled out structure so that scrub can use
      however much information it managed to pull.  Before 5.15, it was
      sufficient to cancel (or commit) the scrub transaction on the way out of
      the scrub code to release the buffers.
      
      Ccommit 48c6615c added a reference to the perag structure to struct
      xchk_ag.  Since perag structures are not attached to transactions like
      buffers are, this adds the requirement that the perag ref be released
      explicitly.  The scrub teardown function xchk_teardown was amended to do
      this for the xchk_ag embedded in struct xfs_scrub.
      
      Unfortunately, I forgot that certain parts of the scrub code probe
      multiple AGs and therefore handle the initialization and cleanup on
      their own.  Specifically, the bmbt scrubber will initialize it long
      enough to cross-reference AG metadata for btree blocks and for the
      extent mappings in the bmbt.
      
      If one of the AG headers is corrupt, the init function returns with a
      live perag structure reference and some of the AG header buffers.  If an
      error occurs, the cross referencing will be noted as XCORRUPTion and
      skipped, but the main scrub process will move on to the next record.
      It is now necessary to release the perag reference before we try to
      analyze something from a different AG, or else we'll trip over the
      assertion noted above.
      
      Fixes: 48c6615c ("xfs: grab active perag ref when reading AG headers")
      Reported-by: Nkernel test robot <oliver.sang@intel.com>
      Signed-off-by: NDarrick J. Wong <djwong@kernel.org>
      Reviewed-by: NChandan Babu R <chandanrlinux@gmail.com>
      61e0d0cc
  7. 20 8月, 2021 31 次提交