OpenCloudOS-Kernel/fs
Dave Chinner 158a682abb xfs: fix low space alloc deadlock
commit 1dd0510f6d upstream.

I've recently encountered an ABBA deadlock with g/476. The upcoming
changes seem to make this much easier to hit, but the underlying
problem is a pre-existing one.

Essentially, if we select an AG for allocation, then lock the AGF
and then fail to allocate for some reason (e.g. minimum length
requirements cannot be satisfied), then we drop out of the
allocation with the AGF still locked.

The caller then modifies the allocation constraints - usually
loosening them up - and tries again. This can result in trying to
access AGFs that are lower than the AGF we already have locked from
the failed attempt. e.g. the failed attempt skipped several AGs
before failing, so we have locks an AG higher than the start AG.
Retrying the allocation from the start AG then causes us to violate
AGF lock ordering and this can lead to deadlocks.

The deadlock exists even if allocation succeeds - we can do a
followup allocations in the same transaction for BMBT blocks that
aren't guaranteed to be in the same AG as the original, and can move
into higher AGs. Hence we really need to move the tp->t_firstblock
tracking down into xfs_alloc_vextent() where it can be set when we
exit with a locked AG.

xfs_alloc_vextent() can also check there if the requested
allocation falls within the allow range of AGs set by
tp->t_firstblock. If we can't allocate within the range set, we have
to fail the allocation. If we are allowed to to non-blocking AGF
locking, we can ignore the AG locking order limitations as we can
use try-locks for the first iteration over requested AG range.

This invalidates a set of post allocation asserts that check that
the allocation is always above tp->t_firstblock if it is set.
Because we can use try-locks to avoid the deadlock in some
circumstances, having a pre-existing locked AGF doesn't always
prevent allocation from lower order AGFs. Hence those ASSERTs need
to be removed.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Jinliang Zheng <alexjlzheng@tencent.com>
Reviewed-by: Tianxiang Peng <txpeng@tencent.com>
Reviewed-by: Hao Peng <flyingpeng@tencent.com>
Signed-off-by: Jianping Liu <frankjpliu@tencent.com>
2024-12-31 17:48:18 +08:00
..
9p fs/9p: only translate RWX permissions for plain 9P2000 2024-11-28 21:43:45 +08:00
adfs Merge branch 'work.adfs' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2019-07-19 11:33:22 -07:00
affs tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
afs tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
autofs autofs: fix a leak in autofs_expire_indirect() 2019-10-25 00:03:11 -04:00
befs fs: Fill in max and min timestamps in superblock 2019-08-30 07:27:17 -07:00
bfs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
btrfs btrfs: reinitialize delayed ref list after deleting it from the list 2024-12-31 16:32:32 +08:00
cachefiles ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
ceph ceph: remove the incorrect Fw reference check when dirtying pages 2024-12-31 16:32:32 +08:00
cgroupfs tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
cifs smb: client: fix OOBs when building SMB2_IOCTL request 2024-12-31 16:32:32 +08:00
coda tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
configfs tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
cramfs cramfs: fix usage on non-MTD device 2019-11-23 21:44:49 -05:00
crypto tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
debugfs tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
devpts tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
dlm tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
ecryptfs ecryptfs: Fix buffer size for tag 66 packet 2024-11-28 21:43:46 +08:00
efivarfs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
efs fs: Fill in max and min timestamps in superblock 2019-08-30 07:27:17 -07:00
erofs erofs: fix pcluster use-after-free on UP platforms 2024-11-28 21:43:44 +08:00
exportfs exportfs_decode_fh(): negative pinned may become positive without the parent locked 2019-11-10 11:56:05 -05:00
ext2 tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
ext4 ext4: fix double brelse() the buffer of the extents path 2024-12-31 17:48:02 +08:00
f2fs f2fs: fix to do sanity check on i_xattr_nid in sanity_check_inode() 2024-11-28 21:43:46 +08:00
fat fat: fix uninitialized field in nostale filehandles 2024-11-28 15:08:37 +08:00
freevxfs fs: Fill in max and min timestamps in superblock 2019-08-30 07:27:17 -07:00
fscache tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
fuse fuse: Initialize beyond-EOF page contents before setting uptodate 2024-11-28 14:52:34 +08:00
gfs2 gfs2: ignore negated quota changes 2024-11-28 21:43:47 +08:00
hfs hfs: fix to initialize fields of hfs_inode_info after hfs_alloc_inode() 2024-11-28 14:52:33 +08:00
hfsplus hfsplus: fix uninit-value in copy_name 2024-11-28 21:43:47 +08:00
hostfs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
hpfs fs: hpfs: Initialize filesystem timestamp ranges 2019-08-30 08:11:25 -07:00
hugetlbfs tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
iomap tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
isofs tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
jbd2 jbd2: speed up jbd2_transaction_committed() 2024-11-05 15:37:21 +08:00
jffs2 jffs2: Fix potential illegal address access in jffs2_free_inode 2024-11-28 21:43:46 +08:00
jfs jfs: Fix uninit-value access of new_ea in ea_buffer 2024-12-31 17:48:02 +08:00
kernfs tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
lockd tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
minix tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
nfs tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
nfs_common ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
nfsd tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
nilfs2 nilfs2: fix kernel bug due to missing clearing of checked flag 2024-12-31 17:48:03 +08:00
nls
notify tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
ntfs tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
ocfs2 ocfs2: add bounds checking to ocfs2_xattr_find_entry() 2024-12-31 17:48:02 +08:00
omfs fs: omfs: Initialize filesystem timestamp ranges 2019-08-30 08:11:25 -07:00
openpromfs Merge branch 'work.mount0' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2019-07-19 10:42:02 -07:00
orangefs tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
overlayfs tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
proc fs/proc: Fix memory leak in sysctl-restrict 2024-11-28 14:45:32 +08:00
pstore pstore: ram_core: fix possible overflow in persistent_ram_init_ecc() 2024-11-28 21:43:45 +08:00
qnx4 tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
qnx6 fs: Fill in max and min timestamps in superblock 2019-08-30 07:27:17 -07:00
quota tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
ramfs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
reiserfs tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
romfs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
squashfs Squashfs: sanity check symbolic link size 2024-11-28 21:43:47 +08:00
sysfs fs: sysfs: Fix reference leak in sysfs_break_active_protection() 2024-11-28 21:43:45 +08:00
sysv sysv: don't call sb_bread() with pointers_lock held 2024-11-28 21:43:45 +08:00
tracefs tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
ubifs ubifs: Set page uptodate in the correct place 2024-11-28 21:43:44 +08:00
udf udf: Avoid using corrupted block bitmap buffer 2024-11-28 14:52:33 +08:00
ufs ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
unicode unicode: make array 'token' static const, makes object smaller 2019-09-17 11:48:24 -04:00
verity tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
xfs xfs: fix low space alloc deadlock 2024-12-31 17:48:18 +08:00
Kconfig ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
Kconfig.binfmt
Makefile tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
aio.c tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
anon_inodes.c Merge branch 'work.mount0' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2019-07-19 10:42:02 -07:00
attr.c tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
bad_inode.c
binfmt_aout.c tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
binfmt_elf.c duptext: export fault data structure, add mmu notifier when memory unmap and add an offset to heap segment 2024-10-08 10:20:31 +08:00
binfmt_elf_fdpic.c tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
binfmt_em86.c
binfmt_flat.c tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
binfmt_misc.c tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
binfmt_script.c
block_dev.c tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
buffer.c tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
char_dev.c tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
compat.c
compat_binfmt_elf.c duptext: export fault data structure, add mmu notifier when memory unmap and add an offset to heap segment 2024-10-08 10:20:31 +08:00
compat_ioctl.c tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
coredump.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
d_path.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
dax.c tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
dcache.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
dcookies.c
direct-io.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
drop_caches.c tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
eventfd.c tkernel: add base tlinux kernel interfaces 2024-06-11 20:09:33 +08:00
eventpoll.c tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
exec.c exec: Fix ToCToU between perm check and set-uid/gid usage 2024-11-28 14:52:33 +08:00
fcntl.c tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
fhandle.c fs/handle.c - fix up kerneldoc 2019-08-07 21:51:47 -04:00
file.c fix bitmap corruption on close_range() with CLOSE_RANGE_UNSHARE 2024-12-31 16:30:52 +08:00
file_table.c tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
filesystems.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
fs-writeback.c writeback: Fix inode->i_io_list not be protected by inode->i_lock error 2024-11-28 21:43:53 +08:00
fs_context.c tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
fs_parser.c vfs: Make fs_parse() handle fs_param_is_fd-type params better 2019-09-12 21:06:14 -04:00
fs_pin.c switch the remnants of releasing the mountpoint away from fs_pin 2019-07-16 22:52:37 -04:00
fs_struct.c
fs_types.c
fsopen.c Merge branch 'work.mount0' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2019-07-19 10:42:02 -07:00
inode.c vfs: fix race between evice_inodes() and find_inode()&iput() 2024-12-31 16:31:22 +08:00
internal.h tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
io_uring.c tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
ioctl.c fs/ioctl: nvidia-smi process and memory display in docker 2024-11-28 21:43:52 +08:00
libfs.c tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
locks.c filelock: fix potential use-after-free in posix_lock_inode 2024-12-31 17:48:02 +08:00
mbcache.c tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
mount.h switch the remnants of releasing the mountpoint away from fs_pin 2019-07-16 22:52:37 -04:00
mpage.c tkernel: add base tlinux kernel interfaces 2024-06-11 20:09:33 +08:00
namei.c tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
namespace.c tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
no-block.c
nsfs.c
open.c ftruncate: pass a signed offset 2024-11-28 21:43:47 +08:00
pipe.c tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
pnode.c tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
pnode.h ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
posix_acl.c
proc_namespace.c tkernel: add base tlinux kernel interfaces 2024-06-11 20:09:33 +08:00
read_write.c tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
readdir.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
remap_range.c tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
select.c tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
seq_file.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
signalfd.c tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
splice.c tkernel: add base tlinux kernel interfaces 2024-06-11 20:09:33 +08:00
stack.c
stat.c tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
statfs.c vfs: Fix EOVERFLOW testing in put_compat_statfs64 2019-10-03 14:21:35 -07:00
super.c tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
sync.c
timerfd.c tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
userfaultfd.c tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00
utimes.c tkernel: add base tlinux kernel interfaces 2024-06-11 20:09:33 +08:00
xattr.c tkernel: sync code to the same with tk4 pub/lts/0017-kabi 2024-06-12 13:13:20 +08:00