)]}'
{
  "commit": "e1ce9b7a1656a1bf62807f0e1de039dc07116dc5",
  "tree": "2a406bbc5a01981e6f0cdefae1c71422b5729f01",
  "parents": [
    "46027ba6734bb5b38a240f7da22fcaaf965f81b2"
  ],
  "author": {
    "name": "Long Li",
    "email": "leo.lilong@huawei.com",
    "time": "Fri Nov 18 12:23:57 2022 +0100"
  },
  "committer": {
    "name": "Carlos Maiolino",
    "email": "cem@kernel.org",
    "time": "Fri Nov 18 12:23:57 2022 +0100"
  },
  "message": "xfs: fix sb write verify for lazysbcount\n\nSource kernel commit: 7cecd500d90164419add650e26cc1de03a7a66cb\n\nWhen lazysbcount is enabled, fsstress and loop mount/unmount test report\nthe following problems:\n\nXFS (loop0): SB summary counter sanity check failed\nXFS (loop0): Metadata corruption detected at xfs_sb_write_verify+0x13b/0x460,\nxfs_sb block 0x0\nXFS (loop0): Unmount and run xfs_repair\nXFS (loop0): First 128 bytes of corrupted metadata buffer:\n00000000: 58 46 53 42 00 00 10 00 00 00 00 00 00 28 00 00  XFSB.........(..\n00000010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................\n00000020: 69 fb 7c cd 5f dc 44 af 85 74 e0 cc d4 e3 34 5a  i.|._.D..t....4Z\n00000030: 00 00 00 00 00 20 00 06 00 00 00 00 00 00 00 80  ..... ..........\n00000040: 00 00 00 00 00 00 00 81 00 00 00 00 00 00 00 82  ................\n00000050: 00 00 00 01 00 0a 00 00 00 00 00 04 00 00 00 00  ................\n00000060: 00 00 0a 00 b4 b5 02 00 02 00 00 08 00 00 00 00  ................\n00000070: 00 00 00 00 00 00 00 00 0c 09 09 03 14 00 00 19  ................\nXFS (loop0): Corruption of in-memory data (0x8) detected at _xfs_buf_ioapply\n+0xe1e/0x10e0 (fs/xfs/xfs_buf.c:1580).  Shutting down filesystem.\nXFS (loop0): Please unmount the filesystem and rectify the problem(s)\nXFS (loop0): log mount/recovery failed: error -117\nXFS (loop0): log mount failed\n\nThis corruption will shutdown the file system and the file system will\nno longer be mountable. The following script can reproduce the problem,\nbut it may take a long time.\n\n#!/bin/bash\n\ndevice\u003d/dev/sda\ntestdir\u003d/mnt/test\nround\u003d0\n\nfunction fail()\n{\necho \"$*\"\nexit 1\n}\n\nmkdir -p $testdir\nwhile [ $round -lt 10000 ]\ndo\necho \"******* round $round ********\"\nmkfs.xfs -f $device\nmount $device $testdir || fail \"mount failed!\"\nfsstress -d $testdir -l 0 -n 10000 -p 4 \u003e/dev/null \u0026\nsleep 4\nkillall -w fsstress\numount $testdir\nxfs_repair -e $device \u003e /dev/null\nif [ $? -eq 2 ];then\necho \"ERR CODE 2: Dirty log exception during repair.\"\nexit 1\nfi\nround\u003d$(($round+1))\ndone\n\nWith lazysbcount is enabled, There is no additional lock protection for\nreading m_ifree and m_icount in xfs_log_sb(), if other cpu modifies the\nm_ifree, this will make the m_ifree greater than m_icount. For example,\nconsider the following sequence and ifreedelta is postive:\n\nCPU0                            CPU1\nxfs_log_sb                      xfs_trans_unreserve_and_mod_sb\n----------                      ------------------------------\npercpu_counter_sum(\u0026mp-\u003em_icount)\npercpu_counter_add_batch(\u0026mp-\u003em_icount,\nidelta, XFS_ICOUNT_BATCH)\npercpu_counter_add(\u0026mp-\u003em_ifree, ifreedelta);\npercpu_counter_sum(\u0026mp-\u003em_ifree)\n\nAfter this, incorrect inode count (sb_ifree \u003e sb_icount) will be writen to\nthe log. In the subsequent writing of sb, incorrect inode count (sb_ifree \u003e\nsb_icount) will fail to pass the boundary check in xfs_validate_sb_write()\nthat cause the file system shutdown.\n\nWhen lazysbcount is enabled, we don\u0027t need to guarantee that Lazy sb\ncounters are completely correct, but we do need to guarantee that sb_ifree\n\u003c\u003d sb_icount. On the other hand, the constraint that m_ifree \u003c\u003d m_icount\nmust be satisfied any time that there /cannot/ be other threads allocating\nor freeing inode chunks. If the constraint is violated under these\ncircumstances, sb_i{count,free} (the ondisk superblock inode counters)\nmaybe incorrect and need to be marked sick at unmount, the count will\nbe rebuilt on the next mount.\n\nFixes: 8756a5af1819 (\"libxfs: add more bounds checking to sb sanity checks\")\nSigned-off-by: Long Li \u003cleo.lilong@huawei.com\u003e\nReviewed-by: Darrick J. Wong \u003cdjwong@kernel.org\u003e\nSigned-off-by: Darrick J. Wong \u003cdjwong@kernel.org\u003e\n\n\n\n\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "fc33dc4a2a68fe9240946a8ef06cd09c17320183",
      "old_mode": 33188,
      "old_path": "libxfs/xfs_sb.c",
      "new_id": "d05f0e6e4b7bf94abcbd8b994cf871dbc6a13df2",
      "new_mode": 33188,
      "new_path": "libxfs/xfs_sb.c"
    }
  ]
}
