2018-06-06 10:42:14 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2005-11-02 11:58:39 +08:00
|
|
|
* Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
|
|
|
|
* All Rights Reserved.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
#ifndef __XFS_INODE_H__
|
|
|
|
#define __XFS_INODE_H__
|
|
|
|
|
2013-08-12 18:49:35 +08:00
|
|
|
#include "xfs_inode_buf.h"
|
2013-08-12 18:49:33 +08:00
|
|
|
#include "xfs_inode_fork.h"
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-11-28 11:23:41 +08:00
|
|
|
/*
|
2013-08-12 18:49:35 +08:00
|
|
|
* Kernel only inode definitions
|
2008-11-28 11:23:41 +08:00
|
|
|
*/
|
2013-08-12 18:49:35 +08:00
|
|
|
struct xfs_dinode;
|
|
|
|
struct xfs_inode;
|
2008-10-30 14:05:38 +08:00
|
|
|
struct xfs_buf;
|
|
|
|
struct xfs_bmbt_irec;
|
|
|
|
struct xfs_inode_log_item;
|
|
|
|
struct xfs_mount;
|
|
|
|
struct xfs_trans;
|
|
|
|
struct xfs_dquot;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
typedef struct xfs_inode {
|
|
|
|
/* Inode linking and identification information. */
|
|
|
|
struct xfs_mount *i_mount; /* fs mount struct ptr */
|
|
|
|
struct xfs_dquot *i_udquot; /* user dquot */
|
|
|
|
struct xfs_dquot *i_gdquot; /* group dquot */
|
2013-07-11 13:00:40 +08:00
|
|
|
struct xfs_dquot *i_pdquot; /* project dquot */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Inode location stuff */
|
|
|
|
xfs_ino_t i_ino; /* inode number (agno/agino)*/
|
2008-11-28 11:23:41 +08:00
|
|
|
struct xfs_imap i_imap; /* location for xfs_imap() */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Extent information. */
|
2018-07-18 07:51:50 +08:00
|
|
|
struct xfs_ifork *i_cowfp; /* copy on write extents */
|
|
|
|
struct xfs_ifork i_df; /* data fork */
|
xfs: make inode attribute forks a permanent part of struct xfs_inode
Syzkaller reported a UAF bug a while back:
==================================================================
BUG: KASAN: use-after-free in xfs_ilock_attr_map_shared+0xe3/0xf6 fs/xfs/xfs_inode.c:127
Read of size 4 at addr ffff88802cec919c by task syz-executor262/2958
CPU: 2 PID: 2958 Comm: syz-executor262 Not tainted
5.15.0-0.30.3-20220406_1406 #3
Hardware name: Red Hat KVM, BIOS 1.13.0-2.module+el8.3.0+7860+a7792d29
04/01/2014
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0x82/0xa9 lib/dump_stack.c:106
print_address_description.constprop.9+0x21/0x2d5 mm/kasan/report.c:256
__kasan_report mm/kasan/report.c:442 [inline]
kasan_report.cold.14+0x7f/0x11b mm/kasan/report.c:459
xfs_ilock_attr_map_shared+0xe3/0xf6 fs/xfs/xfs_inode.c:127
xfs_attr_get+0x378/0x4c2 fs/xfs/libxfs/xfs_attr.c:159
xfs_xattr_get+0xe3/0x150 fs/xfs/xfs_xattr.c:36
__vfs_getxattr+0xdf/0x13d fs/xattr.c:399
cap_inode_need_killpriv+0x41/0x5d security/commoncap.c:300
security_inode_need_killpriv+0x4c/0x97 security/security.c:1408
dentry_needs_remove_privs.part.28+0x21/0x63 fs/inode.c:1912
dentry_needs_remove_privs+0x80/0x9e fs/inode.c:1908
do_truncate+0xc3/0x1e0 fs/open.c:56
handle_truncate fs/namei.c:3084 [inline]
do_open fs/namei.c:3432 [inline]
path_openat+0x30ab/0x396d fs/namei.c:3561
do_filp_open+0x1c4/0x290 fs/namei.c:3588
do_sys_openat2+0x60d/0x98c fs/open.c:1212
do_sys_open+0xcf/0x13c fs/open.c:1228
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x3a/0x7e arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x44/0x0
RIP: 0033:0x7f7ef4bb753d
Code: 00 c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 48
89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73
01 c3 48 8b 0d 1b 79 2c 00 f7 d8 64 89 01 48
RSP: 002b:00007f7ef52c2ed8 EFLAGS: 00000246 ORIG_RAX: 0000000000000055
RAX: ffffffffffffffda RBX: 0000000000404148 RCX: 00007f7ef4bb753d
RDX: 00007f7ef4bb753d RSI: 0000000000000000 RDI: 0000000020004fc0
RBP: 0000000000404140 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0030656c69662f2e
R13: 00007ffd794db37f R14: 00007ffd794db470 R15: 00007f7ef52c2fc0
</TASK>
Allocated by task 2953:
kasan_save_stack+0x19/0x38 mm/kasan/common.c:38
kasan_set_track mm/kasan/common.c:46 [inline]
set_alloc_info mm/kasan/common.c:434 [inline]
__kasan_slab_alloc+0x68/0x7c mm/kasan/common.c:467
kasan_slab_alloc include/linux/kasan.h:254 [inline]
slab_post_alloc_hook mm/slab.h:519 [inline]
slab_alloc_node mm/slub.c:3213 [inline]
slab_alloc mm/slub.c:3221 [inline]
kmem_cache_alloc+0x11b/0x3eb mm/slub.c:3226
kmem_cache_zalloc include/linux/slab.h:711 [inline]
xfs_ifork_alloc+0x25/0xa2 fs/xfs/libxfs/xfs_inode_fork.c:287
xfs_bmap_add_attrfork+0x3f2/0x9b1 fs/xfs/libxfs/xfs_bmap.c:1098
xfs_attr_set+0xe38/0x12a7 fs/xfs/libxfs/xfs_attr.c:746
xfs_xattr_set+0xeb/0x1a9 fs/xfs/xfs_xattr.c:59
__vfs_setxattr+0x11b/0x177 fs/xattr.c:180
__vfs_setxattr_noperm+0x128/0x5e0 fs/xattr.c:214
__vfs_setxattr_locked+0x1d4/0x258 fs/xattr.c:275
vfs_setxattr+0x154/0x33d fs/xattr.c:301
setxattr+0x216/0x29f fs/xattr.c:575
__do_sys_fsetxattr fs/xattr.c:632 [inline]
__se_sys_fsetxattr fs/xattr.c:621 [inline]
__x64_sys_fsetxattr+0x243/0x2fe fs/xattr.c:621
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x3a/0x7e arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x44/0x0
Freed by task 2949:
kasan_save_stack+0x19/0x38 mm/kasan/common.c:38
kasan_set_track+0x1c/0x21 mm/kasan/common.c:46
kasan_set_free_info+0x20/0x30 mm/kasan/generic.c:360
____kasan_slab_free mm/kasan/common.c:366 [inline]
____kasan_slab_free mm/kasan/common.c:328 [inline]
__kasan_slab_free+0xe2/0x10e mm/kasan/common.c:374
kasan_slab_free include/linux/kasan.h:230 [inline]
slab_free_hook mm/slub.c:1700 [inline]
slab_free_freelist_hook mm/slub.c:1726 [inline]
slab_free mm/slub.c:3492 [inline]
kmem_cache_free+0xdc/0x3ce mm/slub.c:3508
xfs_attr_fork_remove+0x8d/0x132 fs/xfs/libxfs/xfs_attr_leaf.c:773
xfs_attr_sf_removename+0x5dd/0x6cb fs/xfs/libxfs/xfs_attr_leaf.c:822
xfs_attr_remove_iter+0x68c/0x805 fs/xfs/libxfs/xfs_attr.c:1413
xfs_attr_remove_args+0xb1/0x10d fs/xfs/libxfs/xfs_attr.c:684
xfs_attr_set+0xf1e/0x12a7 fs/xfs/libxfs/xfs_attr.c:802
xfs_xattr_set+0xeb/0x1a9 fs/xfs/xfs_xattr.c:59
__vfs_removexattr+0x106/0x16a fs/xattr.c:468
cap_inode_killpriv+0x24/0x47 security/commoncap.c:324
security_inode_killpriv+0x54/0xa1 security/security.c:1414
setattr_prepare+0x1a6/0x897 fs/attr.c:146
xfs_vn_change_ok+0x111/0x15e fs/xfs/xfs_iops.c:682
xfs_vn_setattr_size+0x5f/0x15a fs/xfs/xfs_iops.c:1065
xfs_vn_setattr+0x125/0x2ad fs/xfs/xfs_iops.c:1093
notify_change+0xae5/0x10a1 fs/attr.c:410
do_truncate+0x134/0x1e0 fs/open.c:64
handle_truncate fs/namei.c:3084 [inline]
do_open fs/namei.c:3432 [inline]
path_openat+0x30ab/0x396d fs/namei.c:3561
do_filp_open+0x1c4/0x290 fs/namei.c:3588
do_sys_openat2+0x60d/0x98c fs/open.c:1212
do_sys_open+0xcf/0x13c fs/open.c:1228
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x3a/0x7e arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x44/0x0
The buggy address belongs to the object at ffff88802cec9188
which belongs to the cache xfs_ifork of size 40
The buggy address is located 20 bytes inside of
40-byte region [ffff88802cec9188, ffff88802cec91b0)
The buggy address belongs to the page:
page:00000000c3af36a1 refcount:1 mapcount:0 mapping:0000000000000000
index:0x0 pfn:0x2cec9
flags: 0xfffffc0000200(slab|node=0|zone=1|lastcpupid=0x1fffff)
raw: 000fffffc0000200 ffffea00009d2580 0000000600000006 ffff88801a9ffc80
raw: 0000000000000000 0000000080490049 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
Memory state around the buggy address:
ffff88802cec9080: fb fb fb fc fc fa fb fb fb fb fc fc fb fb fb fb
ffff88802cec9100: fb fc fc fb fb fb fb fb fc fc fb fb fb fb fb fc
>ffff88802cec9180: fc fa fb fb fb fb fc fc fa fb fb fb fb fc fc fb
^
ffff88802cec9200: fb fb fb fb fc fc fb fb fb fb fb fc fc fb fb fb
ffff88802cec9280: fb fb fc fc fa fb fb fb fb fc fc fa fb fb fb fb
==================================================================
The root cause of this bug is the unlocked access to xfs_inode.i_afp
from the getxattr code paths while trying to determine which ILOCK mode
to use to stabilize the xattr data. Unfortunately, the VFS does not
acquire i_rwsem when vfs_getxattr (or listxattr) call into the
filesystem, which means that getxattr can race with a removexattr that's
tearing down the attr fork and crash:
xfs_attr_set: xfs_attr_get:
xfs_attr_fork_remove: xfs_ilock_attr_map_shared:
xfs_idestroy_fork(ip->i_afp);
kmem_cache_free(xfs_ifork_cache, ip->i_afp);
if (ip->i_afp &&
ip->i_afp = NULL;
xfs_need_iread_extents(ip->i_afp))
<KABOOM>
ip->i_forkoff = 0;
Regrettably, the VFS is much more lax about i_rwsem and getxattr than
is immediately obvious -- not only does it not guarantee that we hold
i_rwsem, it actually doesn't guarantee that we *don't* hold it either.
The getxattr system call won't acquire the lock before calling XFS, but
the file capabilities code calls getxattr with and without i_rwsem held
to determine if the "security.capabilities" xattr is set on the file.
Fixing the VFS locking requires a treewide investigation into every code
path that could touch an xattr and what i_rwsem state it expects or sets
up. That could take years or even prove impossible; fortunately, we
can fix this UAF problem inside XFS.
An earlier version of this patch used smp_wmb in xfs_attr_fork_remove to
ensure that i_forkoff is always zeroed before i_afp is set to null and
changed the read paths to use smp_rmb before accessing i_forkoff and
i_afp, which avoided these UAF problems. However, the patch author was
too busy dealing with other problems in the meantime, and by the time he
came back to this issue, the situation had changed a bit.
On a modern system with selinux, each inode will always have at least
one xattr for the selinux label, so it doesn't make much sense to keep
incurring the extra pointer dereference. Furthermore, Allison's
upcoming parent pointer patchset will also cause nearly every inode in
the filesystem to have extended attributes. Therefore, make the inode
attribute fork structure part of struct xfs_inode, at a cost of 40 more
bytes.
This patch adds a clunky if_present field where necessary to maintain
the existing logic of xattr fork null pointer testing in the existing
codebase. The next patch switches the logic over to XFS_IFORK_Q and it
all goes away.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
2022-07-10 01:56:06 +08:00
|
|
|
struct xfs_ifork i_af; /* attribute fork */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Transaction and locking information. */
|
|
|
|
struct xfs_inode_log_item *i_itemp; /* logging information */
|
2024-02-19 23:41:13 +08:00
|
|
|
struct rw_semaphore i_lock; /* inode lock */
|
2005-04-17 06:20:36 +08:00
|
|
|
atomic_t i_pincount; /* inode pin count */
|
2021-08-07 02:05:39 +08:00
|
|
|
struct llist_node i_gclist; /* deferred inactivation list */
|
2019-04-12 22:40:25 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Bitsets of inode metadata that have been checked and/or are sick.
|
|
|
|
* Callers must hold i_flags_lock before accessing this field.
|
|
|
|
*/
|
|
|
|
uint16_t i_checked;
|
|
|
|
uint16_t i_sick;
|
|
|
|
|
2006-09-28 09:06:03 +08:00
|
|
|
spinlock_t i_flags_lock; /* inode i_flags lock */
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Miscellaneous state. */
|
2011-12-19 04:00:08 +08:00
|
|
|
unsigned long i_flags; /* see defined flags below */
|
2019-04-18 07:30:24 +08:00
|
|
|
uint64_t i_delayed_blks; /* count of delay alloc blks */
|
2021-03-30 02:11:40 +08:00
|
|
|
xfs_fsize_t i_disk_size; /* number of bytes in file */
|
2021-03-30 02:11:40 +08:00
|
|
|
xfs_rfsblock_t i_nblocks; /* # of direct & btree blocks */
|
2021-03-30 02:11:39 +08:00
|
|
|
prid_t i_projid; /* owner's project id */
|
2021-03-30 02:11:41 +08:00
|
|
|
xfs_extlen_t i_extsize; /* basic/minimum extent size */
|
2021-03-30 02:11:43 +08:00
|
|
|
/* cowextsize is only used for v3 inodes, flushiter for v1/2 */
|
|
|
|
union {
|
|
|
|
xfs_extlen_t i_cowextsize; /* basic cow extent size */
|
|
|
|
uint16_t i_flushiter; /* incremented on flush */
|
|
|
|
};
|
2021-03-30 02:11:44 +08:00
|
|
|
uint8_t i_forkoff; /* attr fork offset >> 3 */
|
2021-03-30 02:11:44 +08:00
|
|
|
uint16_t i_diflags; /* XFS_DIFLAG_... */
|
2021-03-30 02:11:45 +08:00
|
|
|
uint64_t i_diflags2; /* XFS_DIFLAG2_... */
|
2021-03-30 02:11:45 +08:00
|
|
|
struct timespec64 i_crtime; /* time created */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2023-09-11 23:39:07 +08:00
|
|
|
/*
|
|
|
|
* Unlinked list pointers. These point to the next and previous inodes
|
|
|
|
* in the AGI unlinked bucket list, respectively. These fields can
|
|
|
|
* only be updated with the AGI locked.
|
|
|
|
*
|
|
|
|
* i_next_unlinked caches di_next_unlinked.
|
|
|
|
*/
|
2022-07-14 09:38:54 +08:00
|
|
|
xfs_agino_t i_next_unlinked;
|
2023-09-11 23:39:07 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the inode is not on an unlinked list, this field is zero. If the
|
|
|
|
* inode is the first element in an unlinked list, this field is
|
|
|
|
* NULLAGINO. Otherwise, i_prev_unlinked points to the previous inode
|
|
|
|
* in the unlinked list.
|
|
|
|
*/
|
2022-07-14 09:46:43 +08:00
|
|
|
xfs_agino_t i_prev_unlinked;
|
2022-07-14 09:38:54 +08:00
|
|
|
|
2008-10-30 14:36:14 +08:00
|
|
|
/* VFS inode */
|
|
|
|
struct inode i_vnode; /* embedded VFS inode */
|
xfs: implement per-inode writeback completion queues
When scheduling writeback of dirty file data in the page cache, XFS uses
IO completion workqueue items to ensure that filesystem metadata only
updates after the write completes successfully. This is essential for
converting unwritten extents to real extents at the right time and
performing COW remappings.
Unfortunately, XFS queues each IO completion work item to an unbounded
workqueue, which means that the kernel can spawn dozens of threads to
try to handle the items quickly. These threads need to take the ILOCK
to update file metadata, which results in heavy ILOCK contention if a
large number of the work items target a single file, which is
inefficient.
Worse yet, the writeback completion threads get stuck waiting for the
ILOCK while holding transaction reservations, which can use up all
available log reservation space. When that happens, metadata updates to
other parts of the filesystem grind to a halt, even if the filesystem
could otherwise have handled it.
Even worse, if one of the things grinding to a halt happens to be a
thread in the middle of a defer-ops finish holding the same ILOCK and
trying to obtain more log reservation having exhausted the permanent
reservation, we now have an ABBA deadlock - writeback completion has a
transaction reserved and wants the ILOCK, and someone else has the ILOCK
and wants a transaction reservation.
Therefore, we create a per-inode writeback io completion queue + work
item. When writeback finishes, it can add the ioend to the per-inode
queue and let the single worker item process that queue. This
dramatically cuts down on the number of kworkers and ILOCK contention in
the system, and seems to have eliminated an occasional deadlock I was
seeing while running generic/476.
Testing with a program that simulates a heavy random-write workload to a
single file demonstrates that the number of kworkers drops from
approximately 120 threads per file to 1, without dramatically changing
write bandwidth or pagecache access latency.
Note that we leave the xfs-conv workqueue's max_active alone because we
still want to be able to run ioend processing for as many inodes as the
system can handle.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
2019-04-16 04:13:20 +08:00
|
|
|
|
|
|
|
/* pending io completions */
|
|
|
|
spinlock_t i_ioend_lock;
|
|
|
|
struct work_struct i_ioend_work;
|
|
|
|
struct list_head i_ioend_list;
|
2005-04-17 06:20:36 +08:00
|
|
|
} xfs_inode_t;
|
|
|
|
|
2023-09-11 23:39:07 +08:00
|
|
|
static inline bool xfs_inode_on_unlinked_list(const struct xfs_inode *ip)
|
|
|
|
{
|
|
|
|
return ip->i_prev_unlinked != 0;
|
|
|
|
}
|
|
|
|
|
2022-07-10 01:56:06 +08:00
|
|
|
static inline bool xfs_inode_has_attr_fork(struct xfs_inode *ip)
|
|
|
|
{
|
|
|
|
return ip->i_forkoff > 0;
|
|
|
|
}
|
|
|
|
|
2022-07-10 01:56:05 +08:00
|
|
|
static inline struct xfs_ifork *
|
|
|
|
xfs_ifork_ptr(
|
|
|
|
struct xfs_inode *ip,
|
|
|
|
int whichfork)
|
|
|
|
{
|
|
|
|
switch (whichfork) {
|
|
|
|
case XFS_DATA_FORK:
|
|
|
|
return &ip->i_df;
|
|
|
|
case XFS_ATTR_FORK:
|
2022-07-10 01:56:06 +08:00
|
|
|
if (!xfs_inode_has_attr_fork(ip))
|
xfs: make inode attribute forks a permanent part of struct xfs_inode
Syzkaller reported a UAF bug a while back:
==================================================================
BUG: KASAN: use-after-free in xfs_ilock_attr_map_shared+0xe3/0xf6 fs/xfs/xfs_inode.c:127
Read of size 4 at addr ffff88802cec919c by task syz-executor262/2958
CPU: 2 PID: 2958 Comm: syz-executor262 Not tainted
5.15.0-0.30.3-20220406_1406 #3
Hardware name: Red Hat KVM, BIOS 1.13.0-2.module+el8.3.0+7860+a7792d29
04/01/2014
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0x82/0xa9 lib/dump_stack.c:106
print_address_description.constprop.9+0x21/0x2d5 mm/kasan/report.c:256
__kasan_report mm/kasan/report.c:442 [inline]
kasan_report.cold.14+0x7f/0x11b mm/kasan/report.c:459
xfs_ilock_attr_map_shared+0xe3/0xf6 fs/xfs/xfs_inode.c:127
xfs_attr_get+0x378/0x4c2 fs/xfs/libxfs/xfs_attr.c:159
xfs_xattr_get+0xe3/0x150 fs/xfs/xfs_xattr.c:36
__vfs_getxattr+0xdf/0x13d fs/xattr.c:399
cap_inode_need_killpriv+0x41/0x5d security/commoncap.c:300
security_inode_need_killpriv+0x4c/0x97 security/security.c:1408
dentry_needs_remove_privs.part.28+0x21/0x63 fs/inode.c:1912
dentry_needs_remove_privs+0x80/0x9e fs/inode.c:1908
do_truncate+0xc3/0x1e0 fs/open.c:56
handle_truncate fs/namei.c:3084 [inline]
do_open fs/namei.c:3432 [inline]
path_openat+0x30ab/0x396d fs/namei.c:3561
do_filp_open+0x1c4/0x290 fs/namei.c:3588
do_sys_openat2+0x60d/0x98c fs/open.c:1212
do_sys_open+0xcf/0x13c fs/open.c:1228
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x3a/0x7e arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x44/0x0
RIP: 0033:0x7f7ef4bb753d
Code: 00 c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 48
89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73
01 c3 48 8b 0d 1b 79 2c 00 f7 d8 64 89 01 48
RSP: 002b:00007f7ef52c2ed8 EFLAGS: 00000246 ORIG_RAX: 0000000000000055
RAX: ffffffffffffffda RBX: 0000000000404148 RCX: 00007f7ef4bb753d
RDX: 00007f7ef4bb753d RSI: 0000000000000000 RDI: 0000000020004fc0
RBP: 0000000000404140 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0030656c69662f2e
R13: 00007ffd794db37f R14: 00007ffd794db470 R15: 00007f7ef52c2fc0
</TASK>
Allocated by task 2953:
kasan_save_stack+0x19/0x38 mm/kasan/common.c:38
kasan_set_track mm/kasan/common.c:46 [inline]
set_alloc_info mm/kasan/common.c:434 [inline]
__kasan_slab_alloc+0x68/0x7c mm/kasan/common.c:467
kasan_slab_alloc include/linux/kasan.h:254 [inline]
slab_post_alloc_hook mm/slab.h:519 [inline]
slab_alloc_node mm/slub.c:3213 [inline]
slab_alloc mm/slub.c:3221 [inline]
kmem_cache_alloc+0x11b/0x3eb mm/slub.c:3226
kmem_cache_zalloc include/linux/slab.h:711 [inline]
xfs_ifork_alloc+0x25/0xa2 fs/xfs/libxfs/xfs_inode_fork.c:287
xfs_bmap_add_attrfork+0x3f2/0x9b1 fs/xfs/libxfs/xfs_bmap.c:1098
xfs_attr_set+0xe38/0x12a7 fs/xfs/libxfs/xfs_attr.c:746
xfs_xattr_set+0xeb/0x1a9 fs/xfs/xfs_xattr.c:59
__vfs_setxattr+0x11b/0x177 fs/xattr.c:180
__vfs_setxattr_noperm+0x128/0x5e0 fs/xattr.c:214
__vfs_setxattr_locked+0x1d4/0x258 fs/xattr.c:275
vfs_setxattr+0x154/0x33d fs/xattr.c:301
setxattr+0x216/0x29f fs/xattr.c:575
__do_sys_fsetxattr fs/xattr.c:632 [inline]
__se_sys_fsetxattr fs/xattr.c:621 [inline]
__x64_sys_fsetxattr+0x243/0x2fe fs/xattr.c:621
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x3a/0x7e arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x44/0x0
Freed by task 2949:
kasan_save_stack+0x19/0x38 mm/kasan/common.c:38
kasan_set_track+0x1c/0x21 mm/kasan/common.c:46
kasan_set_free_info+0x20/0x30 mm/kasan/generic.c:360
____kasan_slab_free mm/kasan/common.c:366 [inline]
____kasan_slab_free mm/kasan/common.c:328 [inline]
__kasan_slab_free+0xe2/0x10e mm/kasan/common.c:374
kasan_slab_free include/linux/kasan.h:230 [inline]
slab_free_hook mm/slub.c:1700 [inline]
slab_free_freelist_hook mm/slub.c:1726 [inline]
slab_free mm/slub.c:3492 [inline]
kmem_cache_free+0xdc/0x3ce mm/slub.c:3508
xfs_attr_fork_remove+0x8d/0x132 fs/xfs/libxfs/xfs_attr_leaf.c:773
xfs_attr_sf_removename+0x5dd/0x6cb fs/xfs/libxfs/xfs_attr_leaf.c:822
xfs_attr_remove_iter+0x68c/0x805 fs/xfs/libxfs/xfs_attr.c:1413
xfs_attr_remove_args+0xb1/0x10d fs/xfs/libxfs/xfs_attr.c:684
xfs_attr_set+0xf1e/0x12a7 fs/xfs/libxfs/xfs_attr.c:802
xfs_xattr_set+0xeb/0x1a9 fs/xfs/xfs_xattr.c:59
__vfs_removexattr+0x106/0x16a fs/xattr.c:468
cap_inode_killpriv+0x24/0x47 security/commoncap.c:324
security_inode_killpriv+0x54/0xa1 security/security.c:1414
setattr_prepare+0x1a6/0x897 fs/attr.c:146
xfs_vn_change_ok+0x111/0x15e fs/xfs/xfs_iops.c:682
xfs_vn_setattr_size+0x5f/0x15a fs/xfs/xfs_iops.c:1065
xfs_vn_setattr+0x125/0x2ad fs/xfs/xfs_iops.c:1093
notify_change+0xae5/0x10a1 fs/attr.c:410
do_truncate+0x134/0x1e0 fs/open.c:64
handle_truncate fs/namei.c:3084 [inline]
do_open fs/namei.c:3432 [inline]
path_openat+0x30ab/0x396d fs/namei.c:3561
do_filp_open+0x1c4/0x290 fs/namei.c:3588
do_sys_openat2+0x60d/0x98c fs/open.c:1212
do_sys_open+0xcf/0x13c fs/open.c:1228
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x3a/0x7e arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x44/0x0
The buggy address belongs to the object at ffff88802cec9188
which belongs to the cache xfs_ifork of size 40
The buggy address is located 20 bytes inside of
40-byte region [ffff88802cec9188, ffff88802cec91b0)
The buggy address belongs to the page:
page:00000000c3af36a1 refcount:1 mapcount:0 mapping:0000000000000000
index:0x0 pfn:0x2cec9
flags: 0xfffffc0000200(slab|node=0|zone=1|lastcpupid=0x1fffff)
raw: 000fffffc0000200 ffffea00009d2580 0000000600000006 ffff88801a9ffc80
raw: 0000000000000000 0000000080490049 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
Memory state around the buggy address:
ffff88802cec9080: fb fb fb fc fc fa fb fb fb fb fc fc fb fb fb fb
ffff88802cec9100: fb fc fc fb fb fb fb fb fc fc fb fb fb fb fb fc
>ffff88802cec9180: fc fa fb fb fb fb fc fc fa fb fb fb fb fc fc fb
^
ffff88802cec9200: fb fb fb fb fc fc fb fb fb fb fb fc fc fb fb fb
ffff88802cec9280: fb fb fc fc fa fb fb fb fb fc fc fa fb fb fb fb
==================================================================
The root cause of this bug is the unlocked access to xfs_inode.i_afp
from the getxattr code paths while trying to determine which ILOCK mode
to use to stabilize the xattr data. Unfortunately, the VFS does not
acquire i_rwsem when vfs_getxattr (or listxattr) call into the
filesystem, which means that getxattr can race with a removexattr that's
tearing down the attr fork and crash:
xfs_attr_set: xfs_attr_get:
xfs_attr_fork_remove: xfs_ilock_attr_map_shared:
xfs_idestroy_fork(ip->i_afp);
kmem_cache_free(xfs_ifork_cache, ip->i_afp);
if (ip->i_afp &&
ip->i_afp = NULL;
xfs_need_iread_extents(ip->i_afp))
<KABOOM>
ip->i_forkoff = 0;
Regrettably, the VFS is much more lax about i_rwsem and getxattr than
is immediately obvious -- not only does it not guarantee that we hold
i_rwsem, it actually doesn't guarantee that we *don't* hold it either.
The getxattr system call won't acquire the lock before calling XFS, but
the file capabilities code calls getxattr with and without i_rwsem held
to determine if the "security.capabilities" xattr is set on the file.
Fixing the VFS locking requires a treewide investigation into every code
path that could touch an xattr and what i_rwsem state it expects or sets
up. That could take years or even prove impossible; fortunately, we
can fix this UAF problem inside XFS.
An earlier version of this patch used smp_wmb in xfs_attr_fork_remove to
ensure that i_forkoff is always zeroed before i_afp is set to null and
changed the read paths to use smp_rmb before accessing i_forkoff and
i_afp, which avoided these UAF problems. However, the patch author was
too busy dealing with other problems in the meantime, and by the time he
came back to this issue, the situation had changed a bit.
On a modern system with selinux, each inode will always have at least
one xattr for the selinux label, so it doesn't make much sense to keep
incurring the extra pointer dereference. Furthermore, Allison's
upcoming parent pointer patchset will also cause nearly every inode in
the filesystem to have extended attributes. Therefore, make the inode
attribute fork structure part of struct xfs_inode, at a cost of 40 more
bytes.
This patch adds a clunky if_present field where necessary to maintain
the existing logic of xattr fork null pointer testing in the existing
codebase. The next patch switches the logic over to XFS_IFORK_Q and it
all goes away.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
2022-07-10 01:56:06 +08:00
|
|
|
return NULL;
|
|
|
|
return &ip->i_af;
|
2022-07-10 01:56:05 +08:00
|
|
|
case XFS_COW_FORK:
|
|
|
|
return ip->i_cowfp;
|
|
|
|
default:
|
|
|
|
ASSERT(0);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-10 01:56:07 +08:00
|
|
|
static inline unsigned int xfs_inode_fork_boff(struct xfs_inode *ip)
|
|
|
|
{
|
|
|
|
return ip->i_forkoff << 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int xfs_inode_data_fork_size(struct xfs_inode *ip)
|
|
|
|
{
|
|
|
|
if (xfs_inode_has_attr_fork(ip))
|
|
|
|
return xfs_inode_fork_boff(ip);
|
|
|
|
|
|
|
|
return XFS_LITINO(ip->i_mount);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int xfs_inode_attr_fork_size(struct xfs_inode *ip)
|
|
|
|
{
|
|
|
|
if (xfs_inode_has_attr_fork(ip))
|
|
|
|
return XFS_LITINO(ip->i_mount) - xfs_inode_fork_boff(ip);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int
|
|
|
|
xfs_inode_fork_size(
|
|
|
|
struct xfs_inode *ip,
|
|
|
|
int whichfork)
|
|
|
|
{
|
|
|
|
switch (whichfork) {
|
|
|
|
case XFS_DATA_FORK:
|
|
|
|
return xfs_inode_data_fork_size(ip);
|
|
|
|
case XFS_ATTR_FORK:
|
|
|
|
return xfs_inode_attr_fork_size(ip);
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-13 13:45:15 +08:00
|
|
|
/* Convert from vfs inode to xfs inode */
|
|
|
|
static inline struct xfs_inode *XFS_I(struct inode *inode)
|
|
|
|
{
|
2008-10-30 14:36:14 +08:00
|
|
|
return container_of(inode, struct xfs_inode, i_vnode);
|
2008-08-13 13:45:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* convert from xfs inode to vfs inode */
|
|
|
|
static inline struct inode *VFS_I(struct xfs_inode *ip)
|
|
|
|
{
|
2008-10-30 14:36:14 +08:00
|
|
|
return &ip->i_vnode;
|
2008-08-13 13:45:15 +08:00
|
|
|
}
|
|
|
|
|
2024-02-23 04:30:59 +08:00
|
|
|
/* convert from const xfs inode to const vfs inode */
|
|
|
|
static inline const struct inode *VFS_IC(const struct xfs_inode *ip)
|
|
|
|
{
|
|
|
|
return &ip->i_vnode;
|
|
|
|
}
|
|
|
|
|
2011-12-19 04:00:11 +08:00
|
|
|
/*
|
|
|
|
* For regular files we only update the on-disk filesize when actually
|
|
|
|
* writing data back to disk. Until then only the copy in the VFS inode
|
|
|
|
* is uptodate.
|
|
|
|
*/
|
|
|
|
static inline xfs_fsize_t XFS_ISIZE(struct xfs_inode *ip)
|
|
|
|
{
|
2016-02-09 13:54:58 +08:00
|
|
|
if (S_ISREG(VFS_I(ip)->i_mode))
|
2011-12-19 04:00:11 +08:00
|
|
|
return i_size_read(VFS_I(ip));
|
2021-03-30 02:11:40 +08:00
|
|
|
return ip->i_disk_size;
|
2011-12-19 04:00:11 +08:00
|
|
|
}
|
|
|
|
|
2012-02-29 17:53:49 +08:00
|
|
|
/*
|
|
|
|
* If this I/O goes past the on-disk inode size update it unless it would
|
|
|
|
* be past the current in-core inode size.
|
|
|
|
*/
|
|
|
|
static inline xfs_fsize_t
|
|
|
|
xfs_new_eof(struct xfs_inode *ip, xfs_fsize_t new_size)
|
|
|
|
{
|
|
|
|
xfs_fsize_t i_size = i_size_read(VFS_I(ip));
|
|
|
|
|
2014-10-02 07:21:53 +08:00
|
|
|
if (new_size > i_size || new_size < 0)
|
2012-02-29 17:53:49 +08:00
|
|
|
new_size = i_size;
|
2021-03-30 02:11:40 +08:00
|
|
|
return new_size > ip->i_disk_size ? new_size : 0;
|
2012-02-29 17:53:49 +08:00
|
|
|
}
|
|
|
|
|
2006-11-11 15:04:54 +08:00
|
|
|
/*
|
|
|
|
* i_flags helper functions
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
__xfs_iflags_set(xfs_inode_t *ip, unsigned short flags)
|
|
|
|
{
|
|
|
|
ip->i_flags |= flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
xfs_iflags_set(xfs_inode_t *ip, unsigned short flags)
|
|
|
|
{
|
|
|
|
spin_lock(&ip->i_flags_lock);
|
|
|
|
__xfs_iflags_set(ip, flags);
|
|
|
|
spin_unlock(&ip->i_flags_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
xfs_iflags_clear(xfs_inode_t *ip, unsigned short flags)
|
|
|
|
{
|
|
|
|
spin_lock(&ip->i_flags_lock);
|
|
|
|
ip->i_flags &= ~flags;
|
|
|
|
spin_unlock(&ip->i_flags_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
__xfs_iflags_test(xfs_inode_t *ip, unsigned short flags)
|
|
|
|
{
|
|
|
|
return (ip->i_flags & flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
xfs_iflags_test(xfs_inode_t *ip, unsigned short flags)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
spin_lock(&ip->i_flags_lock);
|
|
|
|
ret = __xfs_iflags_test(ip, flags);
|
|
|
|
spin_unlock(&ip->i_flags_lock);
|
|
|
|
return ret;
|
|
|
|
}
|
2007-08-29 09:44:50 +08:00
|
|
|
|
|
|
|
static inline int
|
|
|
|
xfs_iflags_test_and_clear(xfs_inode_t *ip, unsigned short flags)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
spin_lock(&ip->i_flags_lock);
|
|
|
|
ret = ip->i_flags & flags;
|
|
|
|
if (ret)
|
|
|
|
ip->i_flags &= ~flags;
|
|
|
|
spin_unlock(&ip->i_flags_lock);
|
|
|
|
return ret;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-12-19 04:00:09 +08:00
|
|
|
static inline int
|
|
|
|
xfs_iflags_test_and_set(xfs_inode_t *ip, unsigned short flags)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
spin_lock(&ip->i_flags_lock);
|
|
|
|
ret = ip->i_flags & flags;
|
|
|
|
if (!ret)
|
|
|
|
ip->i_flags |= flags;
|
|
|
|
spin_unlock(&ip->i_flags_lock);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-12-18 08:22:39 +08:00
|
|
|
static inline prid_t
|
|
|
|
xfs_get_initial_prid(struct xfs_inode *dp)
|
|
|
|
{
|
2021-03-30 02:11:44 +08:00
|
|
|
if (dp->i_diflags & XFS_DIFLAG_PROJINHERIT)
|
2021-03-30 02:11:39 +08:00
|
|
|
return dp->i_projid;
|
2013-12-18 08:22:39 +08:00
|
|
|
|
|
|
|
return XFS_PROJID_DEFAULT;
|
|
|
|
}
|
|
|
|
|
2016-10-04 00:11:16 +08:00
|
|
|
static inline bool xfs_is_reflink_inode(struct xfs_inode *ip)
|
|
|
|
{
|
2021-03-30 02:11:45 +08:00
|
|
|
return ip->i_diflags2 & XFS_DIFLAG2_REFLINK;
|
2016-10-04 00:11:16 +08:00
|
|
|
}
|
|
|
|
|
2021-03-23 00:51:54 +08:00
|
|
|
static inline bool xfs_is_metadata_inode(struct xfs_inode *ip)
|
|
|
|
{
|
|
|
|
struct xfs_mount *mp = ip->i_mount;
|
|
|
|
|
|
|
|
return ip == mp->m_rbmip || ip == mp->m_rsumip ||
|
|
|
|
xfs_is_quota_inode(&mp->m_sb, ip->i_ino);
|
|
|
|
}
|
|
|
|
|
2018-07-18 07:51:51 +08:00
|
|
|
/*
|
|
|
|
* Check if an inode has any data in the COW fork. This might be often false
|
|
|
|
* even for inodes with the reflink flag when there is no pending COW operation.
|
|
|
|
*/
|
|
|
|
static inline bool xfs_inode_has_cow_data(struct xfs_inode *ip)
|
|
|
|
{
|
|
|
|
return ip->i_cowfp && ip->i_cowfp->if_bytes;
|
|
|
|
}
|
|
|
|
|
2020-08-18 00:59:07 +08:00
|
|
|
static inline bool xfs_inode_has_bigtime(struct xfs_inode *ip)
|
|
|
|
{
|
2021-03-30 02:11:45 +08:00
|
|
|
return ip->i_diflags2 & XFS_DIFLAG2_BIGTIME;
|
2020-08-18 00:59:07 +08:00
|
|
|
}
|
|
|
|
|
2021-11-16 17:04:43 +08:00
|
|
|
static inline bool xfs_inode_has_large_extent_counts(struct xfs_inode *ip)
|
|
|
|
{
|
|
|
|
return ip->i_diflags2 & XFS_DIFLAG2_NREXT64;
|
|
|
|
}
|
|
|
|
|
2024-04-16 05:54:11 +08:00
|
|
|
/*
|
|
|
|
* Decide if this file is a realtime file whose data allocation unit is larger
|
|
|
|
* than a single filesystem block.
|
|
|
|
*/
|
|
|
|
static inline bool xfs_inode_has_bigrtalloc(struct xfs_inode *ip)
|
|
|
|
{
|
|
|
|
return XFS_IS_REALTIME_INODE(ip) && ip->i_mount->m_sb.sb_rextsize > 1;
|
|
|
|
}
|
|
|
|
|
2019-10-25 13:25:38 +08:00
|
|
|
/*
|
|
|
|
* Return the buftarg used for data allocations on a given inode.
|
|
|
|
*/
|
|
|
|
#define xfs_inode_buftarg(ip) \
|
|
|
|
(XFS_IS_REALTIME_INODE(ip) ? \
|
|
|
|
(ip)->i_mount->m_rtdev_targp : (ip)->i_mount->m_ddev_targp)
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* In-core inode flags.
|
|
|
|
*/
|
2011-12-19 04:00:09 +08:00
|
|
|
#define XFS_IRECLAIM (1 << 0) /* started reclaiming this inode */
|
|
|
|
#define XFS_ISTALE (1 << 1) /* inode has been staled */
|
|
|
|
#define XFS_IRECLAIMABLE (1 << 2) /* inode can be reclaimed */
|
2021-11-25 02:06:02 +08:00
|
|
|
#define XFS_INEW (1 << 3) /* inode has just been allocated */
|
2021-03-30 02:11:38 +08:00
|
|
|
#define XFS_IPRESERVE_DM_FIELDS (1 << 4) /* has legacy DMAPI fields set */
|
2011-12-19 04:00:09 +08:00
|
|
|
#define XFS_ITRUNCATED (1 << 5) /* truncated down so flush-on-close */
|
|
|
|
#define XFS_IDIRTY_RELEASE (1 << 6) /* dirty release already seen */
|
2020-08-18 07:41:01 +08:00
|
|
|
#define XFS_IFLUSHING (1 << 7) /* inode is being flushed */
|
2011-12-19 04:00:10 +08:00
|
|
|
#define __XFS_IPINNED_BIT 8 /* wakeup key for zero pin count */
|
|
|
|
#define XFS_IPINNED (1 << __XFS_IPINNED_BIT)
|
2020-04-30 22:41:37 +08:00
|
|
|
#define XFS_IEOFBLOCKS (1 << 9) /* has the preallocblocks tag set */
|
2021-08-07 02:05:39 +08:00
|
|
|
#define XFS_NEED_INACTIVE (1 << 10) /* see XFS_INACTIVATING below */
|
2016-10-04 00:11:29 +08:00
|
|
|
/*
|
|
|
|
* If this unlinked inode is in the middle of recovery, don't let drop_inode
|
|
|
|
* truncate and free the inode. This can happen if we iget the inode during
|
|
|
|
* log recovery to replay a bmap operation on the inode.
|
|
|
|
*/
|
|
|
|
#define XFS_IRECOVERY (1 << 11)
|
2017-12-15 07:42:22 +08:00
|
|
|
#define XFS_ICOWBLOCKS (1 << 12)/* has the cowblocks tag set */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2021-08-07 02:05:39 +08:00
|
|
|
/*
|
|
|
|
* If we need to update on-disk metadata before this IRECLAIMABLE inode can be
|
|
|
|
* freed, then NEED_INACTIVE will be set. Once we start the updates, the
|
|
|
|
* INACTIVATING bit will be set to keep iget away from this inode. After the
|
|
|
|
* inactivation completes, both flags will be cleared and the inode is a
|
|
|
|
* plain old IRECLAIMABLE inode.
|
|
|
|
*/
|
|
|
|
#define XFS_INACTIVATING (1 << 13)
|
|
|
|
|
2023-09-11 23:39:08 +08:00
|
|
|
/* Quotacheck is running but inode has not been added to quota counts. */
|
|
|
|
#define XFS_IQUOTAUNCHECKED (1 << 14)
|
|
|
|
|
2023-10-18 04:12:08 +08:00
|
|
|
/*
|
|
|
|
* Remap in progress. Callers that wish to update file data while
|
|
|
|
* holding a shared IOLOCK or MMAPLOCK must drop the lock and retake
|
|
|
|
* the lock in exclusive mode. Relocking the file will block until
|
|
|
|
* IREMAPPING is cleared.
|
|
|
|
*/
|
|
|
|
#define XFS_IREMAPPING (1U << 15)
|
|
|
|
|
2021-08-07 02:05:39 +08:00
|
|
|
/* All inode state flags related to inode reclaim. */
|
|
|
|
#define XFS_ALL_IRECLAIM_FLAGS (XFS_IRECLAIMABLE | \
|
|
|
|
XFS_IRECLAIM | \
|
|
|
|
XFS_NEED_INACTIVE | \
|
|
|
|
XFS_INACTIVATING)
|
|
|
|
|
2011-06-23 09:34:59 +08:00
|
|
|
/*
|
|
|
|
* Per-lifetime flags need to be reset when re-using a reclaimable inode during
|
2012-03-22 13:15:10 +08:00
|
|
|
* inode lookup. This prevents unintended behaviour on the new inode from
|
2011-06-23 09:34:59 +08:00
|
|
|
* ocurring.
|
|
|
|
*/
|
|
|
|
#define XFS_IRECLAIM_RESET_FLAGS \
|
|
|
|
(XFS_IRECLAIMABLE | XFS_IRECLAIM | \
|
2021-08-07 02:05:39 +08:00
|
|
|
XFS_IDIRTY_RELEASE | XFS_ITRUNCATED | XFS_NEED_INACTIVE | \
|
2023-09-11 23:39:08 +08:00
|
|
|
XFS_INACTIVATING | XFS_IQUOTAUNCHECKED)
|
2011-06-23 09:34:59 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Flags for inode locking.
|
2007-05-08 11:50:19 +08:00
|
|
|
* Bit ranges: 1<<1 - 1<<16-1 -- iolock/ilock modes (bitfield)
|
|
|
|
* 1<<16 - 1<<32-1 -- lockdep annotation (integers)
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2022-04-21 08:47:16 +08:00
|
|
|
#define XFS_IOLOCK_EXCL (1u << 0)
|
|
|
|
#define XFS_IOLOCK_SHARED (1u << 1)
|
|
|
|
#define XFS_ILOCK_EXCL (1u << 2)
|
|
|
|
#define XFS_ILOCK_SHARED (1u << 3)
|
|
|
|
#define XFS_MMAPLOCK_EXCL (1u << 4)
|
|
|
|
#define XFS_MMAPLOCK_SHARED (1u << 5)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-05-08 11:50:19 +08:00
|
|
|
#define XFS_LOCK_MASK (XFS_IOLOCK_EXCL | XFS_IOLOCK_SHARED \
|
2015-02-23 18:43:37 +08:00
|
|
|
| XFS_ILOCK_EXCL | XFS_ILOCK_SHARED \
|
|
|
|
| XFS_MMAPLOCK_EXCL | XFS_MMAPLOCK_SHARED)
|
2007-05-08 11:50:19 +08:00
|
|
|
|
2009-12-15 07:14:59 +08:00
|
|
|
#define XFS_LOCK_FLAGS \
|
|
|
|
{ XFS_IOLOCK_EXCL, "IOLOCK_EXCL" }, \
|
|
|
|
{ XFS_IOLOCK_SHARED, "IOLOCK_SHARED" }, \
|
|
|
|
{ XFS_ILOCK_EXCL, "ILOCK_EXCL" }, \
|
2015-02-23 18:43:37 +08:00
|
|
|
{ XFS_ILOCK_SHARED, "ILOCK_SHARED" }, \
|
|
|
|
{ XFS_MMAPLOCK_EXCL, "MMAPLOCK_EXCL" }, \
|
|
|
|
{ XFS_MMAPLOCK_SHARED, "MMAPLOCK_SHARED" }
|
2009-12-15 07:14:59 +08:00
|
|
|
|
|
|
|
|
2007-05-08 11:50:19 +08:00
|
|
|
/*
|
|
|
|
* Flags for lockdep annotations.
|
|
|
|
*
|
2011-01-25 17:06:21 +08:00
|
|
|
* XFS_LOCK_PARENT - for directory operations that require locking a
|
xfs: clean up inode lockdep annotations
Lockdep annotations are a maintenance nightmare. Locking has to be
modified to suit the limitations of the annotations, and we're
always having to fix the annotations because they are unable to
express the complexity of locking heirarchies correctly.
So, next up, we've got more issues with lockdep annotations for
inode locking w.r.t. XFS_LOCK_PARENT:
- lockdep classes are exclusive and can't be ORed together
to form new classes.
- IOLOCK needs multiple PARENT subclasses to express the
changes needed for the readdir locking rework needed to
stop the endless flow of lockdep false positives involving
readdir calling filldir under the ILOCK.
- there are only 8 unique lockdep subclasses available,
so we can't create a generic solution.
IOWs we need to treat the 3-bit space available to each lock type
differently:
- IOLOCK uses xfs_lock_two_inodes(), so needs:
- at least 2 IOLOCK subclasses
- at least 2 IOLOCK_PARENT subclasses
- MMAPLOCK uses xfs_lock_two_inodes(), so needs:
- at least 2 MMAPLOCK subclasses
- ILOCK uses xfs_lock_inodes with up to 5 inodes, so needs:
- at least 5 ILOCK subclasses
- one ILOCK_PARENT subclass
- one RTBITMAP subclass
- one RTSUM subclass
For the IOLOCK, split the space into two sets of subclasses.
For the MMAPLOCK, just use half the space for the one subclass to
match the non-parent lock classes of the IOLOCK.
For the ILOCK, use 0-4 as the ILOCK subclasses, 5-7 for the
remaining individual subclasses.
Because they are now all different, modify xfs_lock_inumorder() to
handle the nested subclasses, and to assert fail if passed an
invalid subclass. Further, annotate xfs_lock_inodes() to assert fail
if an invalid combination of lock primitives and inode counts are
passed that would result in a lockdep subclass annotation overflow.
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2015-08-19 08:32:49 +08:00
|
|
|
* parent directory inode and a child entry inode. IOLOCK requires nesting,
|
|
|
|
* MMAPLOCK does not support this class, ILOCK requires a single subclass
|
|
|
|
* to differentiate parent from child.
|
2011-01-25 17:06:21 +08:00
|
|
|
*
|
|
|
|
* XFS_LOCK_RTBITMAP/XFS_LOCK_RTSUM - the realtime device bitmap and summary
|
|
|
|
* inodes do not participate in the normal lock order, and thus have their
|
|
|
|
* own subclasses.
|
2007-05-08 11:50:19 +08:00
|
|
|
*
|
2007-06-29 15:26:09 +08:00
|
|
|
* XFS_LOCK_INUMORDER - for locking several inodes at the some time
|
2007-05-08 11:50:19 +08:00
|
|
|
* with xfs_lock_inodes(). This flag is used as the starting subclass
|
|
|
|
* and each subsequent lock acquired will increment the subclass by one.
|
xfs: clean up inode lockdep annotations
Lockdep annotations are a maintenance nightmare. Locking has to be
modified to suit the limitations of the annotations, and we're
always having to fix the annotations because they are unable to
express the complexity of locking heirarchies correctly.
So, next up, we've got more issues with lockdep annotations for
inode locking w.r.t. XFS_LOCK_PARENT:
- lockdep classes are exclusive and can't be ORed together
to form new classes.
- IOLOCK needs multiple PARENT subclasses to express the
changes needed for the readdir locking rework needed to
stop the endless flow of lockdep false positives involving
readdir calling filldir under the ILOCK.
- there are only 8 unique lockdep subclasses available,
so we can't create a generic solution.
IOWs we need to treat the 3-bit space available to each lock type
differently:
- IOLOCK uses xfs_lock_two_inodes(), so needs:
- at least 2 IOLOCK subclasses
- at least 2 IOLOCK_PARENT subclasses
- MMAPLOCK uses xfs_lock_two_inodes(), so needs:
- at least 2 MMAPLOCK subclasses
- ILOCK uses xfs_lock_inodes with up to 5 inodes, so needs:
- at least 5 ILOCK subclasses
- one ILOCK_PARENT subclass
- one RTBITMAP subclass
- one RTSUM subclass
For the IOLOCK, split the space into two sets of subclasses.
For the MMAPLOCK, just use half the space for the one subclass to
match the non-parent lock classes of the IOLOCK.
For the ILOCK, use 0-4 as the ILOCK subclasses, 5-7 for the
remaining individual subclasses.
Because they are now all different, modify xfs_lock_inumorder() to
handle the nested subclasses, and to assert fail if passed an
invalid subclass. Further, annotate xfs_lock_inodes() to assert fail
if an invalid combination of lock primitives and inode counts are
passed that would result in a lockdep subclass annotation overflow.
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2015-08-19 08:32:49 +08:00
|
|
|
* However, MAX_LOCKDEP_SUBCLASSES == 8, which means we are greatly
|
|
|
|
* limited to the subclasses we can represent via nesting. We need at least
|
|
|
|
* 5 inodes nest depth for the ILOCK through rename, and we also have to support
|
|
|
|
* XFS_ILOCK_PARENT, which gives 6 subclasses. Then we have XFS_ILOCK_RTBITMAP
|
|
|
|
* and XFS_ILOCK_RTSUM, which are another 2 unique subclasses, so that's all
|
|
|
|
* 8 subclasses supported by lockdep.
|
|
|
|
*
|
|
|
|
* This also means we have to number the sub-classes in the lowest bits of
|
|
|
|
* the mask we keep, and we have to ensure we never exceed 3 bits of lockdep
|
|
|
|
* mask and we can't use bit-masking to build the subclasses. What a mess.
|
|
|
|
*
|
|
|
|
* Bit layout:
|
|
|
|
*
|
|
|
|
* Bit Lock Region
|
|
|
|
* 16-19 XFS_IOLOCK_SHIFT dependencies
|
|
|
|
* 20-23 XFS_MMAPLOCK_SHIFT dependencies
|
|
|
|
* 24-31 XFS_ILOCK_SHIFT dependencies
|
|
|
|
*
|
|
|
|
* IOLOCK values
|
|
|
|
*
|
|
|
|
* 0-3 subclass value
|
2016-11-30 11:33:25 +08:00
|
|
|
* 4-7 unused
|
xfs: clean up inode lockdep annotations
Lockdep annotations are a maintenance nightmare. Locking has to be
modified to suit the limitations of the annotations, and we're
always having to fix the annotations because they are unable to
express the complexity of locking heirarchies correctly.
So, next up, we've got more issues with lockdep annotations for
inode locking w.r.t. XFS_LOCK_PARENT:
- lockdep classes are exclusive and can't be ORed together
to form new classes.
- IOLOCK needs multiple PARENT subclasses to express the
changes needed for the readdir locking rework needed to
stop the endless flow of lockdep false positives involving
readdir calling filldir under the ILOCK.
- there are only 8 unique lockdep subclasses available,
so we can't create a generic solution.
IOWs we need to treat the 3-bit space available to each lock type
differently:
- IOLOCK uses xfs_lock_two_inodes(), so needs:
- at least 2 IOLOCK subclasses
- at least 2 IOLOCK_PARENT subclasses
- MMAPLOCK uses xfs_lock_two_inodes(), so needs:
- at least 2 MMAPLOCK subclasses
- ILOCK uses xfs_lock_inodes with up to 5 inodes, so needs:
- at least 5 ILOCK subclasses
- one ILOCK_PARENT subclass
- one RTBITMAP subclass
- one RTSUM subclass
For the IOLOCK, split the space into two sets of subclasses.
For the MMAPLOCK, just use half the space for the one subclass to
match the non-parent lock classes of the IOLOCK.
For the ILOCK, use 0-4 as the ILOCK subclasses, 5-7 for the
remaining individual subclasses.
Because they are now all different, modify xfs_lock_inumorder() to
handle the nested subclasses, and to assert fail if passed an
invalid subclass. Further, annotate xfs_lock_inodes() to assert fail
if an invalid combination of lock primitives and inode counts are
passed that would result in a lockdep subclass annotation overflow.
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2015-08-19 08:32:49 +08:00
|
|
|
*
|
|
|
|
* MMAPLOCK values
|
|
|
|
*
|
|
|
|
* 0-3 subclass value
|
|
|
|
* 4-7 unused
|
|
|
|
*
|
|
|
|
* ILOCK values
|
|
|
|
* 0-4 subclass values
|
|
|
|
* 5 PARENT subclass (not nestable)
|
|
|
|
* 6 RTBITMAP subclass (not nestable)
|
|
|
|
* 7 RTSUM subclass (not nestable)
|
|
|
|
*
|
2007-05-08 11:50:19 +08:00
|
|
|
*/
|
xfs: clean up inode lockdep annotations
Lockdep annotations are a maintenance nightmare. Locking has to be
modified to suit the limitations of the annotations, and we're
always having to fix the annotations because they are unable to
express the complexity of locking heirarchies correctly.
So, next up, we've got more issues with lockdep annotations for
inode locking w.r.t. XFS_LOCK_PARENT:
- lockdep classes are exclusive and can't be ORed together
to form new classes.
- IOLOCK needs multiple PARENT subclasses to express the
changes needed for the readdir locking rework needed to
stop the endless flow of lockdep false positives involving
readdir calling filldir under the ILOCK.
- there are only 8 unique lockdep subclasses available,
so we can't create a generic solution.
IOWs we need to treat the 3-bit space available to each lock type
differently:
- IOLOCK uses xfs_lock_two_inodes(), so needs:
- at least 2 IOLOCK subclasses
- at least 2 IOLOCK_PARENT subclasses
- MMAPLOCK uses xfs_lock_two_inodes(), so needs:
- at least 2 MMAPLOCK subclasses
- ILOCK uses xfs_lock_inodes with up to 5 inodes, so needs:
- at least 5 ILOCK subclasses
- one ILOCK_PARENT subclass
- one RTBITMAP subclass
- one RTSUM subclass
For the IOLOCK, split the space into two sets of subclasses.
For the MMAPLOCK, just use half the space for the one subclass to
match the non-parent lock classes of the IOLOCK.
For the ILOCK, use 0-4 as the ILOCK subclasses, 5-7 for the
remaining individual subclasses.
Because they are now all different, modify xfs_lock_inumorder() to
handle the nested subclasses, and to assert fail if passed an
invalid subclass. Further, annotate xfs_lock_inodes() to assert fail
if an invalid combination of lock primitives and inode counts are
passed that would result in a lockdep subclass annotation overflow.
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2015-08-19 08:32:49 +08:00
|
|
|
#define XFS_IOLOCK_SHIFT 16
|
2016-11-30 11:33:25 +08:00
|
|
|
#define XFS_IOLOCK_MAX_SUBCLASS 3
|
2022-04-21 08:47:16 +08:00
|
|
|
#define XFS_IOLOCK_DEP_MASK 0x000f0000u
|
xfs: clean up inode lockdep annotations
Lockdep annotations are a maintenance nightmare. Locking has to be
modified to suit the limitations of the annotations, and we're
always having to fix the annotations because they are unable to
express the complexity of locking heirarchies correctly.
So, next up, we've got more issues with lockdep annotations for
inode locking w.r.t. XFS_LOCK_PARENT:
- lockdep classes are exclusive and can't be ORed together
to form new classes.
- IOLOCK needs multiple PARENT subclasses to express the
changes needed for the readdir locking rework needed to
stop the endless flow of lockdep false positives involving
readdir calling filldir under the ILOCK.
- there are only 8 unique lockdep subclasses available,
so we can't create a generic solution.
IOWs we need to treat the 3-bit space available to each lock type
differently:
- IOLOCK uses xfs_lock_two_inodes(), so needs:
- at least 2 IOLOCK subclasses
- at least 2 IOLOCK_PARENT subclasses
- MMAPLOCK uses xfs_lock_two_inodes(), so needs:
- at least 2 MMAPLOCK subclasses
- ILOCK uses xfs_lock_inodes with up to 5 inodes, so needs:
- at least 5 ILOCK subclasses
- one ILOCK_PARENT subclass
- one RTBITMAP subclass
- one RTSUM subclass
For the IOLOCK, split the space into two sets of subclasses.
For the MMAPLOCK, just use half the space for the one subclass to
match the non-parent lock classes of the IOLOCK.
For the ILOCK, use 0-4 as the ILOCK subclasses, 5-7 for the
remaining individual subclasses.
Because they are now all different, modify xfs_lock_inumorder() to
handle the nested subclasses, and to assert fail if passed an
invalid subclass. Further, annotate xfs_lock_inodes() to assert fail
if an invalid combination of lock primitives and inode counts are
passed that would result in a lockdep subclass annotation overflow.
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2015-08-19 08:32:49 +08:00
|
|
|
|
|
|
|
#define XFS_MMAPLOCK_SHIFT 20
|
|
|
|
#define XFS_MMAPLOCK_NUMORDER 0
|
|
|
|
#define XFS_MMAPLOCK_MAX_SUBCLASS 3
|
2022-04-21 08:47:16 +08:00
|
|
|
#define XFS_MMAPLOCK_DEP_MASK 0x00f00000u
|
xfs: clean up inode lockdep annotations
Lockdep annotations are a maintenance nightmare. Locking has to be
modified to suit the limitations of the annotations, and we're
always having to fix the annotations because they are unable to
express the complexity of locking heirarchies correctly.
So, next up, we've got more issues with lockdep annotations for
inode locking w.r.t. XFS_LOCK_PARENT:
- lockdep classes are exclusive and can't be ORed together
to form new classes.
- IOLOCK needs multiple PARENT subclasses to express the
changes needed for the readdir locking rework needed to
stop the endless flow of lockdep false positives involving
readdir calling filldir under the ILOCK.
- there are only 8 unique lockdep subclasses available,
so we can't create a generic solution.
IOWs we need to treat the 3-bit space available to each lock type
differently:
- IOLOCK uses xfs_lock_two_inodes(), so needs:
- at least 2 IOLOCK subclasses
- at least 2 IOLOCK_PARENT subclasses
- MMAPLOCK uses xfs_lock_two_inodes(), so needs:
- at least 2 MMAPLOCK subclasses
- ILOCK uses xfs_lock_inodes with up to 5 inodes, so needs:
- at least 5 ILOCK subclasses
- one ILOCK_PARENT subclass
- one RTBITMAP subclass
- one RTSUM subclass
For the IOLOCK, split the space into two sets of subclasses.
For the MMAPLOCK, just use half the space for the one subclass to
match the non-parent lock classes of the IOLOCK.
For the ILOCK, use 0-4 as the ILOCK subclasses, 5-7 for the
remaining individual subclasses.
Because they are now all different, modify xfs_lock_inumorder() to
handle the nested subclasses, and to assert fail if passed an
invalid subclass. Further, annotate xfs_lock_inodes() to assert fail
if an invalid combination of lock primitives and inode counts are
passed that would result in a lockdep subclass annotation overflow.
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2015-08-19 08:32:49 +08:00
|
|
|
|
|
|
|
#define XFS_ILOCK_SHIFT 24
|
2022-04-21 08:47:16 +08:00
|
|
|
#define XFS_ILOCK_PARENT_VAL 5u
|
xfs: clean up inode lockdep annotations
Lockdep annotations are a maintenance nightmare. Locking has to be
modified to suit the limitations of the annotations, and we're
always having to fix the annotations because they are unable to
express the complexity of locking heirarchies correctly.
So, next up, we've got more issues with lockdep annotations for
inode locking w.r.t. XFS_LOCK_PARENT:
- lockdep classes are exclusive and can't be ORed together
to form new classes.
- IOLOCK needs multiple PARENT subclasses to express the
changes needed for the readdir locking rework needed to
stop the endless flow of lockdep false positives involving
readdir calling filldir under the ILOCK.
- there are only 8 unique lockdep subclasses available,
so we can't create a generic solution.
IOWs we need to treat the 3-bit space available to each lock type
differently:
- IOLOCK uses xfs_lock_two_inodes(), so needs:
- at least 2 IOLOCK subclasses
- at least 2 IOLOCK_PARENT subclasses
- MMAPLOCK uses xfs_lock_two_inodes(), so needs:
- at least 2 MMAPLOCK subclasses
- ILOCK uses xfs_lock_inodes with up to 5 inodes, so needs:
- at least 5 ILOCK subclasses
- one ILOCK_PARENT subclass
- one RTBITMAP subclass
- one RTSUM subclass
For the IOLOCK, split the space into two sets of subclasses.
For the MMAPLOCK, just use half the space for the one subclass to
match the non-parent lock classes of the IOLOCK.
For the ILOCK, use 0-4 as the ILOCK subclasses, 5-7 for the
remaining individual subclasses.
Because they are now all different, modify xfs_lock_inumorder() to
handle the nested subclasses, and to assert fail if passed an
invalid subclass. Further, annotate xfs_lock_inodes() to assert fail
if an invalid combination of lock primitives and inode counts are
passed that would result in a lockdep subclass annotation overflow.
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2015-08-19 08:32:49 +08:00
|
|
|
#define XFS_ILOCK_MAX_SUBCLASS (XFS_ILOCK_PARENT_VAL - 1)
|
2022-04-21 08:47:16 +08:00
|
|
|
#define XFS_ILOCK_RTBITMAP_VAL 6u
|
|
|
|
#define XFS_ILOCK_RTSUM_VAL 7u
|
|
|
|
#define XFS_ILOCK_DEP_MASK 0xff000000u
|
xfs: clean up inode lockdep annotations
Lockdep annotations are a maintenance nightmare. Locking has to be
modified to suit the limitations of the annotations, and we're
always having to fix the annotations because they are unable to
express the complexity of locking heirarchies correctly.
So, next up, we've got more issues with lockdep annotations for
inode locking w.r.t. XFS_LOCK_PARENT:
- lockdep classes are exclusive and can't be ORed together
to form new classes.
- IOLOCK needs multiple PARENT subclasses to express the
changes needed for the readdir locking rework needed to
stop the endless flow of lockdep false positives involving
readdir calling filldir under the ILOCK.
- there are only 8 unique lockdep subclasses available,
so we can't create a generic solution.
IOWs we need to treat the 3-bit space available to each lock type
differently:
- IOLOCK uses xfs_lock_two_inodes(), so needs:
- at least 2 IOLOCK subclasses
- at least 2 IOLOCK_PARENT subclasses
- MMAPLOCK uses xfs_lock_two_inodes(), so needs:
- at least 2 MMAPLOCK subclasses
- ILOCK uses xfs_lock_inodes with up to 5 inodes, so needs:
- at least 5 ILOCK subclasses
- one ILOCK_PARENT subclass
- one RTBITMAP subclass
- one RTSUM subclass
For the IOLOCK, split the space into two sets of subclasses.
For the MMAPLOCK, just use half the space for the one subclass to
match the non-parent lock classes of the IOLOCK.
For the ILOCK, use 0-4 as the ILOCK subclasses, 5-7 for the
remaining individual subclasses.
Because they are now all different, modify xfs_lock_inumorder() to
handle the nested subclasses, and to assert fail if passed an
invalid subclass. Further, annotate xfs_lock_inodes() to assert fail
if an invalid combination of lock primitives and inode counts are
passed that would result in a lockdep subclass annotation overflow.
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2015-08-19 08:32:49 +08:00
|
|
|
#define XFS_ILOCK_PARENT (XFS_ILOCK_PARENT_VAL << XFS_ILOCK_SHIFT)
|
|
|
|
#define XFS_ILOCK_RTBITMAP (XFS_ILOCK_RTBITMAP_VAL << XFS_ILOCK_SHIFT)
|
|
|
|
#define XFS_ILOCK_RTSUM (XFS_ILOCK_RTSUM_VAL << XFS_ILOCK_SHIFT)
|
|
|
|
|
|
|
|
#define XFS_LOCK_SUBCLASS_MASK (XFS_IOLOCK_DEP_MASK | \
|
2015-02-23 18:43:37 +08:00
|
|
|
XFS_MMAPLOCK_DEP_MASK | \
|
|
|
|
XFS_ILOCK_DEP_MASK)
|
|
|
|
|
|
|
|
#define XFS_IOLOCK_DEP(flags) (((flags) & XFS_IOLOCK_DEP_MASK) \
|
|
|
|
>> XFS_IOLOCK_SHIFT)
|
|
|
|
#define XFS_MMAPLOCK_DEP(flags) (((flags) & XFS_MMAPLOCK_DEP_MASK) \
|
|
|
|
>> XFS_MMAPLOCK_SHIFT)
|
|
|
|
#define XFS_ILOCK_DEP(flags) (((flags) & XFS_ILOCK_DEP_MASK) \
|
|
|
|
>> XFS_ILOCK_SHIFT)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-03-21 05:42:38 +08:00
|
|
|
/*
|
|
|
|
* Layouts are broken in the BREAK_WRITE case to ensure that
|
|
|
|
* layout-holders do not collide with local writes. Additionally,
|
|
|
|
* layouts are broken in the BREAK_UNMAP case to make sure the
|
|
|
|
* layout-holder has a consistent view of the file's extent map. While
|
|
|
|
* BREAK_WRITE breaks can be satisfied by recalling FL_LAYOUT leases,
|
|
|
|
* BREAK_UNMAP breaks additionally require waiting for busy dax-pages to
|
|
|
|
* go idle.
|
|
|
|
*/
|
|
|
|
enum layout_break_reason {
|
|
|
|
BREAK_WRITE,
|
|
|
|
BREAK_UNMAP,
|
|
|
|
};
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* For multiple groups support: if S_ISGID bit is set in the parent
|
|
|
|
* directory, group of new file is set to that of the parent, and
|
|
|
|
* new subdirectory gets S_ISGID bit from parent.
|
|
|
|
*/
|
2007-08-30 15:21:12 +08:00
|
|
|
#define XFS_INHERIT_GID(pip) \
|
2021-08-19 09:46:52 +08:00
|
|
|
(xfs_has_grpid((pip)->i_mount) || (VFS_I(pip)->i_mode & S_ISGID))
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-08-12 18:49:45 +08:00
|
|
|
int xfs_release(struct xfs_inode *ip);
|
2023-06-05 12:48:15 +08:00
|
|
|
int xfs_inactive(struct xfs_inode *ip);
|
2022-03-10 02:16:09 +08:00
|
|
|
int xfs_lookup(struct xfs_inode *dp, const struct xfs_name *name,
|
2013-08-12 18:49:45 +08:00
|
|
|
struct xfs_inode **ipp, struct xfs_name *ci_name);
|
2023-01-13 19:49:25 +08:00
|
|
|
int xfs_create(struct mnt_idmap *idmap,
|
2021-01-21 21:19:58 +08:00
|
|
|
struct xfs_inode *dp, struct xfs_name *name,
|
xfs: initialise attr fork on inode create
When we allocate a new inode, we often need to add an attribute to
the inode as part of the create. This can happen as a result of
needing to add default ACLs or security labels before the inode is
made visible to userspace.
This is highly inefficient right now. We do the create transaction
to allocate the inode, then we do an "add attr fork" transaction to
modify the just created empty inode to set the inode fork offset to
allow attributes to be stored, then we go and do the attribute
creation.
This means 3 transactions instead of 1 to allocate an inode, and
this greatly increases the load on the CIL commit code, resulting in
excessive contention on the CIL spin locks and performance
degradation:
18.99% [kernel] [k] __pv_queued_spin_lock_slowpath
3.57% [kernel] [k] do_raw_spin_lock
2.51% [kernel] [k] __raw_callee_save___pv_queued_spin_unlock
2.48% [kernel] [k] memcpy
2.34% [kernel] [k] xfs_log_commit_cil
The typical profile resulting from running fsmark on a selinux enabled
filesytem is adds this overhead to the create path:
- 15.30% xfs_init_security
- 15.23% security_inode_init_security
- 13.05% xfs_initxattrs
- 12.94% xfs_attr_set
- 6.75% xfs_bmap_add_attrfork
- 5.51% xfs_trans_commit
- 5.48% __xfs_trans_commit
- 5.35% xfs_log_commit_cil
- 3.86% _raw_spin_lock
- do_raw_spin_lock
__pv_queued_spin_lock_slowpath
- 0.70% xfs_trans_alloc
0.52% xfs_trans_reserve
- 5.41% xfs_attr_set_args
- 5.39% xfs_attr_set_shortform.constprop.0
- 4.46% xfs_trans_commit
- 4.46% __xfs_trans_commit
- 4.33% xfs_log_commit_cil
- 2.74% _raw_spin_lock
- do_raw_spin_lock
__pv_queued_spin_lock_slowpath
0.60% xfs_inode_item_format
0.90% xfs_attr_try_sf_addname
- 1.99% selinux_inode_init_security
- 1.02% security_sid_to_context_force
- 1.00% security_sid_to_context_core
- 0.92% sidtab_entry_to_string
- 0.90% sidtab_sid2str_get
0.59% sidtab_sid2str_put.part.0
- 0.82% selinux_determine_inode_label
- 0.77% security_transition_sid
0.70% security_compute_sid.part.0
And fsmark creation rate performance drops by ~25%. The key point to
note here is that half the additional overhead comes from adding the
attribute fork to the newly created inode. That's crazy, considering
we can do this same thing at inode create time with a couple of
lines of code and no extra overhead.
So, if we know we are going to add an attribute immediately after
creating the inode, let's just initialise the attribute fork inside
the create transaction and chop that whole chunk of code out of
the create fast path. This completely removes the performance
drop caused by enabling SELinux, and the profile looks like:
- 8.99% xfs_init_security
- 9.00% security_inode_init_security
- 6.43% xfs_initxattrs
- 6.37% xfs_attr_set
- 5.45% xfs_attr_set_args
- 5.42% xfs_attr_set_shortform.constprop.0
- 4.51% xfs_trans_commit
- 4.54% __xfs_trans_commit
- 4.59% xfs_log_commit_cil
- 2.67% _raw_spin_lock
- 3.28% do_raw_spin_lock
3.08% __pv_queued_spin_lock_slowpath
0.66% xfs_inode_item_format
- 0.90% xfs_attr_try_sf_addname
- 0.60% xfs_trans_alloc
- 2.35% selinux_inode_init_security
- 1.25% security_sid_to_context_force
- 1.21% security_sid_to_context_core
- 1.19% sidtab_entry_to_string
- 1.20% sidtab_sid2str_get
- 0.86% sidtab_sid2str_put.part.0
- 0.62% _raw_spin_lock_irqsave
- 0.77% do_raw_spin_lock
__pv_queued_spin_lock_slowpath
- 0.84% selinux_determine_inode_label
- 0.83% security_transition_sid
0.86% security_compute_sid.part.0
Which indicates the XFS overhead of creating the selinux xattr has
been halved. This doesn't fix the CIL lock contention problem, just
means it's not a limiting factor for this workload. Lock contention
in the security subsystems is going to be an issue soon, though...
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
[djwong: fix compilation error when CONFIG_SECURITY=n]
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Gao Xiang <hsiangkao@redhat.com>
2021-03-23 00:52:03 +08:00
|
|
|
umode_t mode, dev_t rdev, bool need_xattr,
|
|
|
|
struct xfs_inode **ipp);
|
2023-01-13 19:49:25 +08:00
|
|
|
int xfs_create_tmpfile(struct mnt_idmap *idmap,
|
2021-01-21 21:19:58 +08:00
|
|
|
struct xfs_inode *dp, umode_t mode,
|
2018-04-07 01:09:42 +08:00
|
|
|
struct xfs_inode **ipp);
|
2013-08-12 18:49:45 +08:00
|
|
|
int xfs_remove(struct xfs_inode *dp, struct xfs_name *name,
|
|
|
|
struct xfs_inode *ip);
|
|
|
|
int xfs_link(struct xfs_inode *tdp, struct xfs_inode *sip,
|
|
|
|
struct xfs_name *target_name);
|
2023-01-13 19:49:25 +08:00
|
|
|
int xfs_rename(struct mnt_idmap *idmap,
|
2021-01-21 21:19:58 +08:00
|
|
|
struct xfs_inode *src_dp, struct xfs_name *src_name,
|
2013-08-12 18:49:45 +08:00
|
|
|
struct xfs_inode *src_ip, struct xfs_inode *target_dp,
|
|
|
|
struct xfs_name *target_name,
|
2014-12-24 05:51:42 +08:00
|
|
|
struct xfs_inode *target_ip, unsigned int flags);
|
2013-08-12 18:49:45 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
void xfs_ilock(xfs_inode_t *, uint);
|
|
|
|
int xfs_ilock_nowait(xfs_inode_t *, uint);
|
|
|
|
void xfs_iunlock(xfs_inode_t *, uint);
|
|
|
|
void xfs_ilock_demote(xfs_inode_t *, uint);
|
2024-02-19 23:41:12 +08:00
|
|
|
void xfs_assert_ilocked(struct xfs_inode *, uint);
|
2013-12-07 04:30:09 +08:00
|
|
|
uint xfs_ilock_data_map_shared(struct xfs_inode *);
|
2013-12-18 18:14:39 +08:00
|
|
|
uint xfs_ilock_attr_map_shared(struct xfs_inode *);
|
2007-08-28 11:57:51 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
uint xfs_ip2xflags(struct xfs_inode *);
|
2018-07-12 13:26:07 +08:00
|
|
|
int xfs_ifree(struct xfs_trans *, struct xfs_inode *);
|
2018-05-11 00:35:42 +08:00
|
|
|
int xfs_itruncate_extents_flags(struct xfs_trans **,
|
|
|
|
struct xfs_inode *, int, xfs_fsize_t, int);
|
2005-04-17 06:20:36 +08:00
|
|
|
void xfs_iext_realloc(xfs_inode_t *, int, int);
|
2013-08-12 18:49:35 +08:00
|
|
|
|
2020-04-04 02:45:37 +08:00
|
|
|
int xfs_log_force_inode(struct xfs_inode *ip);
|
2010-02-06 09:37:26 +08:00
|
|
|
void xfs_iunpin_wait(xfs_inode_t *);
|
2013-08-12 18:49:35 +08:00
|
|
|
#define xfs_ipincount(ip) ((unsigned int) atomic_read(&ip->i_pincount))
|
|
|
|
|
2020-06-30 05:49:20 +08:00
|
|
|
int xfs_iflush_cluster(struct xfs_buf *);
|
2018-01-27 07:27:33 +08:00
|
|
|
void xfs_lock_two_inodes(struct xfs_inode *ip0, uint ip0_mode,
|
|
|
|
struct xfs_inode *ip1, uint ip1_mode);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-04-23 13:59:02 +08:00
|
|
|
xfs_extlen_t xfs_get_extsz_hint(struct xfs_inode *ip);
|
2016-10-04 00:11:43 +08:00
|
|
|
xfs_extlen_t xfs_get_cowextsz_hint(struct xfs_inode *ip);
|
2012-04-23 13:59:02 +08:00
|
|
|
|
2023-01-13 19:49:25 +08:00
|
|
|
int xfs_init_new_inode(struct mnt_idmap *idmap, struct xfs_trans *tp,
|
2021-06-02 08:48:24 +08:00
|
|
|
struct xfs_inode *pip, xfs_ino_t ino, umode_t mode,
|
|
|
|
xfs_nlink_t nlink, dev_t rdev, prid_t prid, bool init_xattrs,
|
|
|
|
struct xfs_inode **ipp);
|
2013-08-12 18:49:47 +08:00
|
|
|
|
2018-05-09 23:45:04 +08:00
|
|
|
static inline int
|
|
|
|
xfs_itruncate_extents(
|
|
|
|
struct xfs_trans **tpp,
|
|
|
|
struct xfs_inode *ip,
|
|
|
|
int whichfork,
|
|
|
|
xfs_fsize_t new_size)
|
|
|
|
{
|
2018-05-11 00:35:42 +08:00
|
|
|
return xfs_itruncate_extents_flags(tpp, ip, whichfork, new_size, 0);
|
2018-05-09 23:45:04 +08:00
|
|
|
}
|
|
|
|
|
2022-06-03 13:37:38 +08:00
|
|
|
int xfs_break_dax_layouts(struct inode *inode, bool *retry);
|
2018-03-21 05:42:38 +08:00
|
|
|
int xfs_break_layouts(struct inode *inode, uint *iolock,
|
|
|
|
enum layout_break_reason reason);
|
2013-08-12 18:49:45 +08:00
|
|
|
|
2023-10-25 22:10:20 +08:00
|
|
|
static inline void xfs_update_stable_writes(struct xfs_inode *ip)
|
|
|
|
{
|
|
|
|
if (bdev_stable_writes(xfs_inode_buftarg(ip)->bt_bdev))
|
|
|
|
mapping_set_stable_writes(VFS_I(ip)->i_mapping);
|
|
|
|
else
|
|
|
|
mapping_clear_stable_writes(VFS_I(ip)->i_mapping);
|
|
|
|
}
|
|
|
|
|
2015-02-23 19:38:08 +08:00
|
|
|
/*
|
|
|
|
* When setting up a newly allocated inode, we need to call
|
|
|
|
* xfs_finish_inode_setup() once the inode is fully instantiated at
|
|
|
|
* the VFS level to prevent the rest of the world seeing the inode
|
|
|
|
* before we've completed instantiation. Otherwise we can do it
|
|
|
|
* the moment the inode lookup is complete.
|
|
|
|
*/
|
|
|
|
static inline void xfs_finish_inode_setup(struct xfs_inode *ip)
|
|
|
|
{
|
|
|
|
xfs_iflags_clear(ip, XFS_INEW);
|
|
|
|
barrier();
|
|
|
|
unlock_new_inode(VFS_I(ip));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void xfs_setup_existing_inode(struct xfs_inode *ip)
|
|
|
|
{
|
|
|
|
xfs_setup_inode(ip);
|
2016-04-06 05:48:27 +08:00
|
|
|
xfs_setup_iops(ip);
|
2015-02-23 19:38:08 +08:00
|
|
|
xfs_finish_inode_setup(ip);
|
|
|
|
}
|
|
|
|
|
2018-07-26 03:52:32 +08:00
|
|
|
void xfs_irele(struct xfs_inode *ip);
|
2008-12-03 19:20:40 +08:00
|
|
|
|
2021-10-13 02:09:23 +08:00
|
|
|
extern struct kmem_cache *xfs_inode_cache;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-10-04 00:11:49 +08:00
|
|
|
/* The default CoW extent size hint. */
|
|
|
|
#define XFS_DEFAULT_COWEXTSZ_HINT 32
|
|
|
|
|
2021-08-07 02:05:39 +08:00
|
|
|
bool xfs_inode_needs_inactive(struct xfs_inode *ip);
|
|
|
|
|
2024-04-16 05:54:28 +08:00
|
|
|
int xfs_iunlink(struct xfs_trans *tp, struct xfs_inode *ip);
|
2024-04-16 05:54:49 +08:00
|
|
|
int xfs_iunlink_remove(struct xfs_trans *tp, struct xfs_perag *pag,
|
|
|
|
struct xfs_inode *ip);
|
2024-04-16 05:55:00 +08:00
|
|
|
struct xfs_inode *xfs_iunlink_lookup(struct xfs_perag *pag, xfs_agino_t agino);
|
2024-04-16 05:54:28 +08:00
|
|
|
|
xfs: implement per-inode writeback completion queues
When scheduling writeback of dirty file data in the page cache, XFS uses
IO completion workqueue items to ensure that filesystem metadata only
updates after the write completes successfully. This is essential for
converting unwritten extents to real extents at the right time and
performing COW remappings.
Unfortunately, XFS queues each IO completion work item to an unbounded
workqueue, which means that the kernel can spawn dozens of threads to
try to handle the items quickly. These threads need to take the ILOCK
to update file metadata, which results in heavy ILOCK contention if a
large number of the work items target a single file, which is
inefficient.
Worse yet, the writeback completion threads get stuck waiting for the
ILOCK while holding transaction reservations, which can use up all
available log reservation space. When that happens, metadata updates to
other parts of the filesystem grind to a halt, even if the filesystem
could otherwise have handled it.
Even worse, if one of the things grinding to a halt happens to be a
thread in the middle of a defer-ops finish holding the same ILOCK and
trying to obtain more log reservation having exhausted the permanent
reservation, we now have an ABBA deadlock - writeback completion has a
transaction reserved and wants the ILOCK, and someone else has the ILOCK
and wants a transaction reservation.
Therefore, we create a per-inode writeback io completion queue + work
item. When writeback finishes, it can add the ioend to the per-inode
queue and let the single worker item process that queue. This
dramatically cuts down on the number of kworkers and ILOCK contention in
the system, and seems to have eliminated an occasional deadlock I was
seeing while running generic/476.
Testing with a program that simulates a heavy random-write workload to a
single file demonstrates that the number of kworkers drops from
approximately 120 threads per file to 1, without dramatically changing
write bandwidth or pagecache access latency.
Note that we leave the xfs-conv workqueue's max_active alone because we
still want to be able to run ioend processing for as many inodes as the
system can handle.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
2019-04-16 04:13:20 +08:00
|
|
|
void xfs_end_io(struct work_struct *work);
|
|
|
|
|
2020-06-30 05:47:20 +08:00
|
|
|
int xfs_ilock2_io_mmap(struct xfs_inode *ip1, struct xfs_inode *ip2);
|
|
|
|
void xfs_iunlock2_io_mmap(struct xfs_inode *ip1, struct xfs_inode *ip2);
|
2023-10-18 04:12:08 +08:00
|
|
|
void xfs_iunlock2_remapping(struct xfs_inode *ip1, struct xfs_inode *ip2);
|
2024-04-16 05:54:55 +08:00
|
|
|
void xfs_bumplink(struct xfs_trans *tp, struct xfs_inode *ip);
|
2024-04-16 05:55:11 +08:00
|
|
|
void xfs_lock_inodes(struct xfs_inode **ips, int inodes, uint lock_mode);
|
|
|
|
void xfs_sort_inodes(struct xfs_inode **i_tab, unsigned int num_inodes);
|
2020-06-30 05:47:20 +08:00
|
|
|
|
2023-09-11 23:39:07 +08:00
|
|
|
static inline bool
|
|
|
|
xfs_inode_unlinked_incomplete(
|
|
|
|
struct xfs_inode *ip)
|
|
|
|
{
|
|
|
|
return VFS_I(ip)->i_nlink == 0 && !xfs_inode_on_unlinked_list(ip);
|
|
|
|
}
|
|
|
|
int xfs_inode_reload_unlinked_bucket(struct xfs_trans *tp, struct xfs_inode *ip);
|
|
|
|
int xfs_inode_reload_unlinked(struct xfs_inode *ip);
|
|
|
|
|
2023-12-16 02:03:35 +08:00
|
|
|
bool xfs_ifork_zapped(const struct xfs_inode *ip, int whichfork);
|
2024-02-23 04:30:53 +08:00
|
|
|
void xfs_inode_count_blocks(struct xfs_trans *tp, struct xfs_inode *ip,
|
|
|
|
xfs_filblks_t *dblocks, xfs_filblks_t *rblocks);
|
2024-04-16 05:54:10 +08:00
|
|
|
unsigned int xfs_inode_alloc_unitsize(struct xfs_inode *ip);
|
2023-12-16 02:03:35 +08:00
|
|
|
|
2024-02-23 04:30:59 +08:00
|
|
|
struct xfs_dir_update_params {
|
|
|
|
const struct xfs_inode *dp;
|
|
|
|
const struct xfs_inode *ip;
|
|
|
|
const struct xfs_name *name;
|
|
|
|
int delta;
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef CONFIG_XFS_LIVE_HOOKS
|
|
|
|
void xfs_dir_update_hook(struct xfs_inode *dp, struct xfs_inode *ip,
|
|
|
|
int delta, const struct xfs_name *name);
|
|
|
|
|
|
|
|
struct xfs_dir_hook {
|
|
|
|
struct xfs_hook dirent_hook;
|
|
|
|
};
|
|
|
|
|
|
|
|
void xfs_dir_hook_disable(void);
|
|
|
|
void xfs_dir_hook_enable(void);
|
|
|
|
|
|
|
|
int xfs_dir_hook_add(struct xfs_mount *mp, struct xfs_dir_hook *hook);
|
|
|
|
void xfs_dir_hook_del(struct xfs_mount *mp, struct xfs_dir_hook *hook);
|
|
|
|
void xfs_dir_hook_setup(struct xfs_dir_hook *hook, notifier_fn_t mod_fn);
|
|
|
|
#else
|
|
|
|
# define xfs_dir_update_hook(dp, ip, delta, name) ((void)0)
|
|
|
|
#endif /* CONFIG_XFS_LIVE_HOOKS */
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif /* __XFS_INODE_H__ */
|