From nobody Thu Apr 2 14:10:31 2026 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6982A349AFC for ; Sat, 28 Mar 2026 15:38:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774712304; cv=none; b=OYjn8QU4vUtRwQZd4qt8zZFV9vShIENWmWMyjwQMcW4Q1hlc1kySDlsnmqe+HuOCCDo4xzfaOBHPgDwUAP1c+PfBiemycXc+XlBqfjsL/hj69gBRR9Wa0UT+5SpY8FUiP9L9LPse277JvG1gX0ZaC4i0F52MXsrgYda8bn6QES0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774712304; c=relaxed/simple; bh=q6/M4OdZtc+alS1DwnvRyoUObRGRNii9NRUn255hTcA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Tm5YF5tmNbSWG0n0ctm9WCHMRo9ebKWCO/o47ur9tI7pTAB/5QpBhgjWo1RNN/+yXmFvSQkQ1HU5xFRgAvbXhquHzpWrSQrqnujszsh+YgATNxoKuPA6HmRTARRul5iOfMyJ/cfis/OQYU8fPpjnlAeQ2A22BLhG+mt5jZrzrGc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QF/Gbi2q; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QF/Gbi2q" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-4852b81c73aso26902105e9.3 for ; Sat, 28 Mar 2026 08:38:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774712302; x=1775317102; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ALuBtMTHfXISMz1y0xRBvnd5xru82Lmp3xXwNF/dfxA=; b=QF/Gbi2q0o/KWwkSr9Ez1TYLC41KIYVclsMtVZO3yyDh273mN2KuPYtb7gnSGRqqSn kHX7ddaOSWY7h0R/QFgEL4T75DNvEAdrnYhqh+fknG+4OD74L1f/3UpfNaMResFcaQqh 1WB6mViLC5T/+as/7PbJ55IZeUjUv0QLBvwOyuJiUmgJHh2Sexf1yV5bEPXt480eramS MZiHswyD7+Z7wOY7tp6Ix3CxugswoNWFaTgvdFiYiQ6cM7AvAe4LJQJ0EykWxnJfZ6kK HuZz8b8fQln5YHGg9jo/pvi/48D9Dc/bUdtLgphQ/66mbq6TWgPkJW9lQdrwb6Axk6fg x5oQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774712302; x=1775317102; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=ALuBtMTHfXISMz1y0xRBvnd5xru82Lmp3xXwNF/dfxA=; b=FVCLNwGFhb5t/cGtHhMDLv+acYiL+8jdR0DL6Wl0TqA3FbGGscPGFoySqEw5p4WFaG 0PdbVwASXpQcnX+0qlOGtvT1CXP7zRI4ZFEqjA83+PkMYGHfNNcNrNTmxAqM25gIY2X5 cpYRVvzTVPubfbzYwSZ19H/t3eoXhe3R+aRA/L4mcvAG4a4Sr+2AcLS/7TJ59Nwld8Av 6j3xVMszDcDUBAD6vdcd9QkFo0187+KUZ4hVigoN+4pbwFXZ9cJCBjUgiVdgWNByypO/ UPuogOMG5koar7QwagYlorX2WGJDEg1qfkB1joStIC3KvCjdg2SK19bTeRgXGyRDy9iR txIA== X-Forwarded-Encrypted: i=1; AJvYcCWdk9dmqXLd6Hg48ZP9FU23c+SFcY+uJII2b2FKX3hDY42VsRxsC/wMZBN2JIrJIAQnsYkCAopzEASZlNE=@vger.kernel.org X-Gm-Message-State: AOJu0YzctD78YVJfYIGOeUEog2JBmf72qPgcbPgXIh3WRR4d4014xvMM VTiPyaUupXlKIPuKZcoidp1g7KduVl3Mg4ZGqzfrDbFjY7qeYDCVqe0LHcnr8Q== X-Gm-Gg: ATEYQzyRd17SR0ADdoxXxz5AkziOF7yUubCF2c5qyb2VMKU2ioyiw7tnQUQGkl/orYY ezzwy4HVh6b2UkXQqS0yFaECbOo9InQ/T6W6nQvOF93dOd279vFNjrtwiuFo/HCMn4rq/YAnAUF +CX0zuVWobxRoUkHOMP1gywiaj6ab0fSONshSuQ2oRQ07WF0c4LMYYTCzFkbodRLWYwxhl3OBh0 gdcgymKDNlF7RVsxD0I85yyeFl/+Gl8ED37fq1vjK5WKd8UUgzYIIIEjZe1mhajm9wkYcAfsmis T1GJlyBCVCMb73FK8/rX4OWzy8rwT5mKeLa5biV71kv0zNjcnDmntL7GERoaNirNh27EqNqK7ae QsMSIzy8+te0IdTFSO2dOYMeJk6hmfxy5gQBHYZgG/WojsF1rzDD4yWuPMj8XTU4rglS32BRp+e f7OKE75+bH78vwKphJJa7+bCT3gUgyYwGZadSnIEOW9CLV8vr+y9k+6HyoTSR+RaJFZhIYbe3eN 5Z8n6IaSgOs X-Received: by 2002:a05:600c:8215:b0:485:3dfc:569 with SMTP id 5b1f17b1804b1-48727f5fe53mr101847915e9.16.1774712301825; Sat, 28 Mar 2026 08:38:21 -0700 (PDT) Received: from f.. (cst-prg-89-171.cust.vodafone.cz. [46.135.89.171]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43cf247102dsm7196887f8f.27.2026.03.28.08.38.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Mar 2026 08:38:21 -0700 (PDT) From: Mateusz Guzik To: brauner@kernel.org Cc: viro@zeniv.linux.org.uk, jack@suse.cz, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Mateusz Guzik Subject: [PATCH v2 1/5] fs: add icount_read_once() Date: Sat, 28 Mar 2026 16:38:03 +0100 Message-ID: <20260328153807.3368975-2-mjguzik@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260328153807.3368975-1-mjguzik@gmail.com> References: <20260328153807.3368975-1-mjguzik@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It will be used to denote the caller acknowledges how the count can change from under them. Signed-off-by: Mateusz Guzik --- include/linux/fs.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/linux/fs.h b/include/linux/fs.h index 8afbe2ef2686..0cf27085a579 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2225,6 +2225,11 @@ static inline void mark_inode_dirty_sync(struct inod= e *inode) __mark_inode_dirty(inode, I_DIRTY_SYNC); } =20 +static inline int icount_read_once(const struct inode *inode) +{ + return atomic_read(&inode->i_count); +} + static inline int icount_read(const struct inode *inode) { return atomic_read(&inode->i_count); --=20 2.48.1 From nobody Thu Apr 2 14:10:31 2026 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0D07354AC7 for ; Sat, 28 Mar 2026 15:38:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774712306; cv=none; b=toN6Jj6mpHHjprUlN4zZMtyHUqgPEvxdaZAVfVgoZu6OvF9pmfILTzBPo7ZFjSmgExYhFxN1jkuswc2FJKkgIpLANepVOTcj9HOSU6kbSoBg2HcUPEFT2qCzgrJkJX/gn/5IXXdICBiR7y001Fe860X3e328DFzIcSwbeoqmteg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774712306; c=relaxed/simple; bh=8xxPYCYi3jBF56gf5sck7mIQAohhuUh0PXeHCMgHG/g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=affLTxNpUN2wPB4oRpEcfLmOx3RwPX3xQTGiTZB6vUCuy96vBOS7c6jBBCPGSUtk3RzXkbFXS6IwH10N6FBoEyR5/AJsAgzrZdmXk7KNHVufPBUDJ3OPr3Zt2CbiDNyNodpiKUPNWrFU6eRxvLZtISxqwshDu0GCsiUSHYneObc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mXtQBN3p; arc=none smtp.client-ip=209.85.221.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mXtQBN3p" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-43b527ac5d0so1617350f8f.2 for ; Sat, 28 Mar 2026 08:38:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774712303; x=1775317103; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=a1fu/byEUJ6qDFBkZYB9aFVVTkqU/ACSQVsqGJXvhx0=; b=mXtQBN3pFb8hvpxyVJyW8Mu0rBgXPr48bh14n4Y9a8gzYxHeBhOY7rItkKyJAhAl6X kgK5jH+CSGtKKK0Pg150AR4b91NaAzVjZTezIsABc1kX/6+8+7XZNsEn/uHq6GKxIYxL EJetWjaxPeHa0jxPjkprpNIFhs8vCfAyd5MpoUUDL3LJ5kgk1lEPVJtci5jGmDTeWdy9 RoHnGvWW1woA0Z5x1BbLsJ8sJcHhxdXQRE1zWRX6y1+9JzfBIF9qlVAGtDHW7Z05pSlV 0OpBpYDG6KntTvYsTXQo2uhpOHIIrrwh4r8qvwaMMYr0Ap4NYGBMEZiFXVCdblOO7bd0 zYdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774712303; x=1775317103; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=a1fu/byEUJ6qDFBkZYB9aFVVTkqU/ACSQVsqGJXvhx0=; b=o7aB53AIdbQKSZhYbg+DDQV8/wtVarmWxheZQxQVOMHKpJyQar51PvyJYGsKuk7ury ZM6zc9qF6rEZTY6dDe+00bSN5Egn7GUzougk0zaiTIGGnEp85ETwU0TyvJpCd/hU98lj +kE8V2G1ZWsnG3CsfNAdrFYdX2nJ+hrsKNXpAcVo0eGHzs+9WL4/4Ngh/aPTC+o/OP2z 3SwdZVZT5cQZGhjCKu/cNd/6y8MWcR78MGXW7/YyNf8mnFk2lWMnKVWdCGwB3FT2D8Ml fW3l+DUQc05B931idzAH5gqfs011mdPx18mA+naCYfq0hjo9AqKzW+AxhwyUHB6E4AfC xgqg== X-Forwarded-Encrypted: i=1; AJvYcCVRyZRP6GzG0LG7le7P8JoOcCpSfb05RnCsvVIZEXPDeUJrErK9YJ79x+MmUDmPJT94BZMx7WOvjWkiBCE=@vger.kernel.org X-Gm-Message-State: AOJu0Yzju0+oLY0WVIM0+5zepa5p8+QJ7nPhhoeEr6VC4IY/vKMzangT X3qKHeJRAEVrqtVzx6loSFja8jU79eTvFpdQhZaVGYgEp9Yo36HqEqUR X-Gm-Gg: ATEYQzyOI33ClC4qYLVeej+KrZfUjBu4HDmL24ffrkp4IojKU5FEtj9Yd8jyQ3VT1/l 7pFhO816YfdtFyvo9nSuxGLiqhBo4Kpyc4ody4maKsiYk5LN90ksI/bvhWRYKtxXwXgnFKsTUaj zm1182q6eyjZmVcbDN+BE56Aeqs+BVys4RaQLSdFKB6EQFzc6mHsucj61ZeeHGfE4T21lfpTI1o sqAYfPux+LBqyZtxJ/jqnUcReZ7QoaXwG6K9u2h4kgXX734cBQWeT4GXdPaLuA6+pvtY1VWy/Bd enYgzzYzu1Cfwk6ZdtOCvidCxgrqlEdii815b4WUBr9lHhDCgEmfd6MHFVXhEJS+UZtnIy7wJR3 4FEtRqg8nqnlz4nnW76i9svihifMQXQu1HSF1ddMF03LU1S8Q72SAxEoGxmZxI0mL00l1PEAvfL bnBulUNUrmui/TaKrGFQymO7t5Z/Vta6Tpt75q+BIFQl36JLNbyNSGwuIJXnDaq7x11o3O4p6zE 8gzt2SpER5s X-Received: by 2002:a05:6000:2902:b0:43b:45f5:eec with SMTP id ffacd0b85a97d-43b9e9d8c84mr11010354f8f.4.1774712303145; Sat, 28 Mar 2026 08:38:23 -0700 (PDT) Received: from f.. (cst-prg-89-171.cust.vodafone.cz. [46.135.89.171]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43cf247102dsm7196887f8f.27.2026.03.28.08.38.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Mar 2026 08:38:22 -0700 (PDT) From: Mateusz Guzik To: brauner@kernel.org Cc: viro@zeniv.linux.org.uk, jack@suse.cz, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Mateusz Guzik Subject: [PATCH v2 2/5] Use icount_read() and icount_read_once() as appropriate. Date: Sat, 28 Mar 2026 16:38:04 +0100 Message-ID: <20260328153807.3368975-3-mjguzik@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260328153807.3368975-1-mjguzik@gmail.com> References: <20260328153807.3368975-1-mjguzik@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Don't open-code ->i_count access. This is expected to be a nop. Signed-off-by: Mateusz Guzik --- arch/powerpc/platforms/cell/spufs/file.c | 2 +- fs/btrfs/inode.c | 2 +- fs/ceph/mds_client.c | 2 +- fs/ext4/ialloc.c | 4 ++-- fs/hpfs/inode.c | 2 +- fs/inode.c | 12 ++++++------ fs/nfs/inode.c | 4 ++-- fs/smb/client/inode.c | 2 +- fs/ubifs/super.c | 2 +- fs/xfs/xfs_inode.c | 2 +- fs/xfs/xfs_trace.h | 2 +- include/trace/events/filelock.h | 2 +- security/landlock/fs.c | 2 +- 13 files changed, 20 insertions(+), 20 deletions(-) diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platfo= rms/cell/spufs/file.c index 10fa9b844fcc..f6de8c1169d5 100644 --- a/arch/powerpc/platforms/cell/spufs/file.c +++ b/arch/powerpc/platforms/cell/spufs/file.c @@ -1430,7 +1430,7 @@ static int spufs_mfc_open(struct inode *inode, struct= file *file) if (ctx->owner !=3D current->mm) return -EINVAL; =20 - if (icount_read(inode) !=3D 1) + if (icount_read_once(inode) !=3D 1) return -EBUSY; =20 mutex_lock(&ctx->mapping_lock); diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 8d97a8ad3858..f36c49e83c04 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -4741,7 +4741,7 @@ static void btrfs_prune_dentries(struct btrfs_root *r= oot) =20 inode =3D btrfs_find_first_inode(root, min_ino); while (inode) { - if (icount_read(&inode->vfs_inode) > 1) + if (icount_read_once(&inode->vfs_inode) > 1) d_prune_aliases(&inode->vfs_inode); =20 min_ino =3D btrfs_ino(inode) + 1; diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c index b1746273f186..2cb3c919d40d 100644 --- a/fs/ceph/mds_client.c +++ b/fs/ceph/mds_client.c @@ -2223,7 +2223,7 @@ static int trim_caps_cb(struct inode *inode, int mds,= void *arg) int count; dput(dentry); d_prune_aliases(inode); - count =3D icount_read(inode); + count =3D icount_read_once(inode); if (count =3D=3D 1) (*remaining)--; doutc(cl, "%p %llx.%llx cap %p pruned, count now %d\n", diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c index 3fd8f0099852..8c80d5087516 100644 --- a/fs/ext4/ialloc.c +++ b/fs/ext4/ialloc.c @@ -252,10 +252,10 @@ void ext4_free_inode(handle_t *handle, struct inode *= inode) "nonexistent device\n", __func__, __LINE__); return; } - if (icount_read(inode) > 1) { + if (icount_read_once(inode) > 1) { ext4_msg(sb, KERN_ERR, "%s:%d: inode #%llu: count=3D%d", __func__, __LINE__, inode->i_ino, - icount_read(inode)); + icount_read_once(inode)); return; } if (inode->i_nlink) { diff --git a/fs/hpfs/inode.c b/fs/hpfs/inode.c index 0e932cc8be1b..1b4fcf760aad 100644 --- a/fs/hpfs/inode.c +++ b/fs/hpfs/inode.c @@ -184,7 +184,7 @@ void hpfs_write_inode(struct inode *i) struct hpfs_inode_info *hpfs_inode =3D hpfs_i(i); struct inode *parent; if (i->i_ino =3D=3D hpfs_sb(i->i_sb)->sb_root) return; - if (hpfs_inode->i_rddir_off && !icount_read(i)) { + if (hpfs_inode->i_rddir_off && !icount_read_once(i)) { if (*hpfs_inode->i_rddir_off) pr_err("write_inode: some position still there\n"); kfree(hpfs_inode->i_rddir_off); diff --git a/fs/inode.c b/fs/inode.c index 5ad169d51728..1f5a383ccf27 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -907,7 +907,7 @@ void evict_inodes(struct super_block *sb) again: spin_lock(&sb->s_inode_list_lock); list_for_each_entry(inode, &sb->s_inodes, i_sb_list) { - if (icount_read(inode)) + if (icount_read_once(inode)) continue; =20 spin_lock(&inode->i_lock); @@ -1926,7 +1926,7 @@ static void iput_final(struct inode *inode) int drop; =20 WARN_ON(inode_state_read(inode) & I_NEW); - VFS_BUG_ON_INODE(atomic_read(&inode->i_count) !=3D 0, inode); + VFS_BUG_ON_INODE(icount_read(inode) !=3D 0, inode); =20 if (op->drop_inode) drop =3D op->drop_inode(inode); @@ -1945,7 +1945,7 @@ static void iput_final(struct inode *inode) * Re-check ->i_count in case the ->drop_inode() hooks played games. * Note we only execute this if the verdict was to drop the inode. */ - VFS_BUG_ON_INODE(atomic_read(&inode->i_count) !=3D 0, inode); + VFS_BUG_ON_INODE(icount_read(inode) !=3D 0, inode); =20 if (drop) { inode_state_set(inode, I_FREEING); @@ -1989,7 +1989,7 @@ void iput(struct inode *inode) * equal to one, then two CPUs racing to further drop it can both * conclude it's fine. */ - VFS_BUG_ON_INODE(atomic_read(&inode->i_count) < 1, inode); + VFS_BUG_ON_INODE(icount_read_once(inode) < 1, inode); =20 if (atomic_add_unless(&inode->i_count, -1, 1)) return; @@ -2023,7 +2023,7 @@ EXPORT_SYMBOL(iput); void iput_not_last(struct inode *inode) { VFS_BUG_ON_INODE(inode_state_read_once(inode) & (I_FREEING | I_CLEAR), in= ode); - VFS_BUG_ON_INODE(atomic_read(&inode->i_count) < 2, inode); + VFS_BUG_ON_INODE(icount_read_once(inode) < 2, inode); =20 WARN_ON(atomic_sub_return(1, &inode->i_count) =3D=3D 0); } @@ -3046,7 +3046,7 @@ void dump_inode(struct inode *inode, const char *reas= on) } =20 state =3D inode_state_read_once(inode); - count =3D atomic_read(&inode->i_count); + count =3D icount_read_once(inode); =20 if (!sb || get_kernel_nofault(s_type, &sb->s_type) || !s_type || diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c index 98a8f0de1199..22834eddd5b1 100644 --- a/fs/nfs/inode.c +++ b/fs/nfs/inode.c @@ -608,7 +608,7 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, st= ruct nfs_fattr *fattr) inode->i_sb->s_id, (unsigned long long)NFS_FILEID(inode), nfs_display_fhandle_hash(fh), - icount_read(inode)); + icount_read_once(inode)); =20 out: return inode; @@ -2261,7 +2261,7 @@ static int nfs_update_inode(struct inode *inode, stru= ct nfs_fattr *fattr) dfprintk(VFS, "NFS: %s(%s/%llu fh_crc=3D0x%08x ct=3D%d info=3D0x%llx)\n", __func__, inode->i_sb->s_id, inode->i_ino, nfs_display_fhandle_hash(NFS_FH(inode)), - icount_read(inode), fattr->valid); + icount_read_once(inode), fattr->valid); =20 if (!(fattr->valid & NFS_ATTR_FATTR_FILEID)) { /* Only a mounted-on-fileid? Just exit */ diff --git a/fs/smb/client/inode.c b/fs/smb/client/inode.c index 888f9e35f14b..ab35e35b16d7 100644 --- a/fs/smb/client/inode.c +++ b/fs/smb/client/inode.c @@ -2842,7 +2842,7 @@ int cifs_revalidate_dentry_attr(struct dentry *dentry) } =20 cifs_dbg(FYI, "Update attributes: %s inode 0x%p count %d dentry: 0x%p d_t= ime %ld jiffies %ld\n", - full_path, inode, icount_read(inode), + full_path, inode, icount_read_once(inode), dentry, cifs_get_time(dentry), jiffies); =20 again: diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c index 9a77d8b64ffa..38972786817e 100644 --- a/fs/ubifs/super.c +++ b/fs/ubifs/super.c @@ -358,7 +358,7 @@ static void ubifs_evict_inode(struct inode *inode) goto out; =20 dbg_gen("inode %llu, mode %#x", inode->i_ino, (int)inode->i_mode); - ubifs_assert(c, !icount_read(inode)); + ubifs_assert(c, !icount_read_once(inode)); =20 truncate_inode_pages_final(&inode->i_data); =20 diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index beaa26ec62da..4f659eba6ae5 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -1046,7 +1046,7 @@ xfs_itruncate_extents_flags( int error =3D 0; =20 xfs_assert_ilocked(ip, XFS_ILOCK_EXCL); - if (icount_read(VFS_I(ip))) + if (icount_read_once(VFS_I(ip))) xfs_assert_ilocked(ip, XFS_IOLOCK_EXCL); if (whichfork =3D=3D XFS_DATA_FORK) ASSERT(new_size <=3D XFS_ISIZE(ip)); diff --git a/fs/xfs/xfs_trace.h b/fs/xfs/xfs_trace.h index 5e8190fe2be9..cbdec40826b3 100644 --- a/fs/xfs/xfs_trace.h +++ b/fs/xfs/xfs_trace.h @@ -1156,7 +1156,7 @@ DECLARE_EVENT_CLASS(xfs_iref_class, TP_fast_assign( __entry->dev =3D VFS_I(ip)->i_sb->s_dev; __entry->ino =3D ip->i_ino; - __entry->count =3D icount_read(VFS_I(ip)); + __entry->count =3D icount_read_once(VFS_I(ip)); __entry->pincount =3D atomic_read(&ip->i_pincount); __entry->iflags =3D ip->i_flags; __entry->caller_ip =3D caller_ip; diff --git a/include/trace/events/filelock.h b/include/trace/events/fileloc= k.h index 116774886244..c8c8847bb6f6 100644 --- a/include/trace/events/filelock.h +++ b/include/trace/events/filelock.h @@ -190,7 +190,7 @@ TRACE_EVENT(generic_add_lease, __entry->i_ino =3D inode->i_ino; __entry->wcount =3D atomic_read(&inode->i_writecount); __entry->rcount =3D atomic_read(&inode->i_readcount); - __entry->icount =3D icount_read(inode); + __entry->icount =3D icount_read_once(inode); __entry->owner =3D fl->c.flc_owner; __entry->flags =3D fl->c.flc_flags; __entry->type =3D fl->c.flc_type; diff --git a/security/landlock/fs.c b/security/landlock/fs.c index c1ecfe239032..32d560f12dbd 100644 --- a/security/landlock/fs.c +++ b/security/landlock/fs.c @@ -1278,7 +1278,7 @@ static void hook_sb_delete(struct super_block *const = sb) struct landlock_object *object; =20 /* Only handles referenced inodes. */ - if (!icount_read(inode)) + if (!icount_read_once(inode)) continue; =20 /* --=20 2.48.1 From nobody Thu Apr 2 14:10:31 2026 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4494C70830 for ; Sat, 28 Mar 2026 15:44:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774712689; cv=none; b=eYF35j0wmtoiyjKIfMye4yvHf+cHJC8FIwKufrAUIwEyA2qE6LJHXtVT0eu2vG5n95jIIGfK48XmgBCriZF2+I7TCI1IUon9z5aiHas/XrLJzBV2vvzvbaTeLrqpdA21ItyEaFGRKJh2lcbQb4kRyIcoqWIcdcgCank93bDYK1s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774712689; c=relaxed/simple; bh=HZYHztId16pgGQ1AA2UfRM6DJRt8s7EcWewCjcgDwxM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DdNae2D3oTjipKi/o2FVHduco3V7NLHWKPJgmriGJioXGGSTkgF9QnYerKgRjfQxPew1CyoA8s04fdvfLFNkN9OaRMDWfJMD9//T8Kbp3t8jeEnc125aYhB6LLCfk8nlUdOrpoNjAUbWrnE4bajbcC7VqFqtgHFuotV3Vra0/kA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TYGLyi2U; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TYGLyi2U" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-48704db565eso42098015e9.1 for ; Sat, 28 Mar 2026 08:44:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774712685; x=1775317485; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Wqq43BIgVMA1uE3zJr5f2QtdxqeDEFGIZU0biEFlpEg=; b=TYGLyi2Uw4w66rcR/hhwRr4Z3OSlv0kHiLWNUwIYp3UszCKUeZFzqJbiyq44lQxtyA 2GUtruKK83mv/oxwUrIFqPkk6H1pizXEjdR9qzLIUJ+K5LWCmXONTxnhZv9AuTKdTUXJ 5Te+n58zWy8hgunWBjAXNxYmG3wld1pCxUUAlHGajLPgf3ryhpiagHMrj7iODtvtzHA8 vNl37qIoJVTkib1LYinJN1MjEusvt9WacMlz7pc3a4n5eHINsqNLCq5TZUm2NwN9nH5y pWqadh9KhODRC7WrhUDSK1mlfPGvCNjqz6WwuudWWMAFLQa0A2WM0dOI+M4XIu8j9FaY jpfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774712685; x=1775317485; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Wqq43BIgVMA1uE3zJr5f2QtdxqeDEFGIZU0biEFlpEg=; b=L3C+HFJr4m7IfMhXoQfQ5dC6hrV61igbNaqeM5DU9CB44GvECuHE0H1QJDKa2U0Bfy 3qJ0KHtxwKJPB7cY0borg4g3LdkuAaQS/n/WtJk2VTu0s9yStS6Ba6xyK0uGgs75cy1X r6FTIB44xZz7dwzPGD4G86OZ3m29XprZVwqZryIo1YSRVUWi0er2JOxxKNOWqe55bMQd I8MPsMWshj+69Ogogv+MHpTCsxWq38FeUuYMJfBajq0OzeboyHEghYxjYd/90Rrqm4Rc fUbgmapZ0OaYtKvgdWj7bAj3fRJhLspj6UFEnUVN08pElyt49EOD7w4TisrJ5HUgAAMq QqpQ== X-Forwarded-Encrypted: i=1; AJvYcCUeIhpe1XTp8Id1TjFYyrSoJ85JSuGZ47/O6HI8iVGx33cLl5oh6H9qU0vrKSjQa3iOabu/GpAufVud11o=@vger.kernel.org X-Gm-Message-State: AOJu0Yy+L9GIcKdFTuia3QOAdxE+eiUxTKeO63+UOU9NTxg7ziAC5JtW odsKjCKjg3XeuTsH9GKDfCvhA8RceKnMGekefpyvk5M1KTRbvNByrRwL6lcnkQ== X-Gm-Gg: ATEYQzyc0pVghqZ0NaC6tgi7XEdXi8FTN8aLyAARwB0dMZbC0fIjyGF3PIxqMw6DGUe Thr/B4KHxTDdbArFaV4Dcj0XTDkol29z1AnnYrVZibBKC0NSPCkmko5whDX8KB1dYW4tQ96JMO9 +7u46mL6KQvQ/Pyxsl/IDOvTPuwRZH9Krke6X8tgxkVuJK3YDjeKwsr5N7ToSi9UnSstIGEmByn JFtEOQe+Nn5R5X+dvU26IAEozkN1Q224CU8y55dwm719GSM2ud4ilTmQw3kvahP+1Zby2m7cOJm Ljvx2FEU/cGBoszPM0FZswCeV3VNCsDbTMXGd+0p4Uke3MWEqkawoUBPDW2Wn/N2taXbP+r5VzD RR6iIlxN0RVQ7UWAkIHUcSgW6qxXtuS+ECUWnyYxsaC9PncgJ54NA7Pg3Yz0/Wi7FnbHi8cGq4v 8WWfYsWUXDDpviupob6EP8cVngDj8fFl3Gt61ZRonO6x2M65/BjL582ncumdX9My6QH5Kg+F//E w== X-Received: by 2002:a05:600c:c8f:b0:487:21c7:2885 with SMTP id 5b1f17b1804b1-48727d45a8emr109339485e9.5.1774712304275; Sat, 28 Mar 2026 08:38:24 -0700 (PDT) Received: from f.. (cst-prg-89-171.cust.vodafone.cz. [46.135.89.171]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43cf247102dsm7196887f8f.27.2026.03.28.08.38.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Mar 2026 08:38:23 -0700 (PDT) From: Mateusz Guzik To: brauner@kernel.org Cc: viro@zeniv.linux.org.uk, jack@suse.cz, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Mateusz Guzik Subject: [PATCH v2 3/5] fs: enforce locking in icount_read(), add some commentary Date: Sat, 28 Mar 2026 16:38:05 +0100 Message-ID: <20260328153807.3368975-4-mjguzik@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260328153807.3368975-1-mjguzik@gmail.com> References: <20260328153807.3368975-1-mjguzik@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Signed-off-by: Mateusz Guzik --- include/linux/fs.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/linux/fs.h b/include/linux/fs.h index 0cf27085a579..07363fce4406 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2225,13 +2225,21 @@ static inline void mark_inode_dirty_sync(struct ino= de *inode) __mark_inode_dirty(inode, I_DIRTY_SYNC); } =20 +/* + * returns the refcount on the inode. it can change arbitrarily. + */ static inline int icount_read_once(const struct inode *inode) { return atomic_read(&inode->i_count); } =20 +/* + * returns the refcount on the inode. The lock guarantees no new references + * are added, but references can be dropped as long as the result is > 0. + */ static inline int icount_read(const struct inode *inode) { + lockdep_assert_held(&inode->i_lock); return atomic_read(&inode->i_count); } =20 --=20 2.48.1 From nobody Thu Apr 2 14:10:31 2026 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8A6C34DCF9 for ; Sat, 28 Mar 2026 15:38:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774712312; cv=none; b=S9HNCasQvyRsCSw13+ZzQwhICT3alsSQjycnImn3oSSOiwedfdrzBLOgNYY5wDmkKR3cUO+pcdZjLXNew9mgJrOD5+PU7D1TqYn+I+96dwearLOEDmVQoLUWI6VR9xXc3Usg+xwoodWD1PfDnUtm+dPNj29FzjlwYWupL7aeZVU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774712312; c=relaxed/simple; bh=jKFU9ClukmgrQPWCuZbiDz6loGcaVsfq+0devSW3yqM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H6qvWnXTeaUUHnTbEOb3px59G7dchUIldJ03OBZq3JjDmmUJhSCTZPLNs/VQdCfuL+RMt8R2c0no8laWCYtKUQV+o0Uq8iy5lr13xEExFQeZ5X5VKo7fMlIcKtSQQfA8xfMOcyweguIZqkOOgR5X/lq0zDyY9rtWA3+UEOshh7I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=d54tlCLI; arc=none smtp.client-ip=209.85.221.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="d54tlCLI" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-43b9f43a1feso1209616f8f.1 for ; Sat, 28 Mar 2026 08:38:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774712306; x=1775317106; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VSDysc2SqFR5k0dxgouFFuDk3xltDf+gaI9kO7u+6DU=; b=d54tlCLIAxO4E5L9qkqidJsAsPupSKML+yLUH4Ea0tmotgjQ+5fJlWPR1aZvREBZNv Xbabun8tWx151fbaD37uc1qzDF+enXOUyLoTmRt0DOj6KSM6I/a+LjvjuAfDh+rxC/Lr tvYWv6HfoWj6ej9HRIiK7xMnzppcDa2YjyACH4GNyIhpynr/PxPL3lCt5qfMeCAOGXxD R5y2QWt8y7WBxptjVRTbNY1DpSetuDMC4N3MW7m/1tsivKWIZglMKxQZvH4s/s0IZXkw H963SUlvTQx5akZVrRwiqPoNXSBNCiXRGogH9myxYJm/ipsNTmq/2g0saDGK0Iim4B0V GoGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774712306; x=1775317106; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=VSDysc2SqFR5k0dxgouFFuDk3xltDf+gaI9kO7u+6DU=; b=M7nvExMvcLA8w1+EmGkoiaf5HgJ9AIuj+1+z5+ByMZEl+kM4ToAeKlIZwSneH8CGJ0 QroIQCEYkZ2Hjv12hLBgnrYKewfrdtuFQSOm3GN9k3dQMxx68ToLBtu+ZEyIW8/dLRC3 mTQS1/lczcIpzkIx+Rr65/D19zxdmC6jFoS+YuLZ3ho+EZkB+35I/GHhOOIJdA18R9Sz HHp9DoUtGWBQWLnmSsIckApQZeXTp8hY1glNFXYBGn5Y+LusJEERFNuMAn2tULAHqJVL yqM3wJS4vJ7CV24byiw/3TeHbAd1yEQhGfU2RBnOztpGjMzUmRo6bXezQmxbXeZtniFo J64A== X-Forwarded-Encrypted: i=1; AJvYcCU8Ztt5WoZlDJykYj/ukxXNzapAkUSpxZmUbEQytADKCnBWZ+mgl6JyEOM6oK+2ByEFc6KKTZp6bomLi/k=@vger.kernel.org X-Gm-Message-State: AOJu0YzKBrRM0siK/XhT0wgfRbTUGa2UCOIu9//zqmDvrP5WIfb0mk3i TezyoQuE5xoKJ9za53PRQyDOItXNV6dn4JWX1MzrkdqOfJ/w+kHCrRDd X-Gm-Gg: ATEYQzyTOiujkLg3UXOp+O8hU55MXSZkr/DzCW5uZmBha4AW1wzHpra06E1e+JN16AM HQlWmlKiM/mzdLk+D+arQxR5pl+5vyCoJQC0zVu7WmDH7NfGHq0u82Gv7oFbmBioX+hUkc51l6s U59wd9iHV7IHOMPoC9F4MZtKHOkLOyFCYPLmUc1BeLkwNr/zqj5cYUO2WURlPQwx1Ng9q0uORFb fEEuLqpZO4+PjbUbAv2f+eM/q9Tl1KukKmLH2uFrUTq7Wj6UDNLWrWkXWbv+eth7LH9ICYaX6kj 3wBytxEw/Di21hyLM0ycn0CqD0sfYDrCpkbkmUwaJYVFIiuZZRqaw4VgGDmU4JakCOz57G4N68Z 0YVGwvL7++ZVt4x/9eTGvt0it1aaTZ840H4iq0wMGEJT/K4Vtd8llhJokU96xIgB4EjTdSCPqbA EtWZAar7JHNexYSBKRWVtM+fkPmne/PWJ8Biy8ZSR/2q9ifOo1azbTpiDAQ/ZPXGrW6lYf0K5yW A== X-Received: by 2002:a05:6000:26d3:b0:439:ba4d:bf40 with SMTP id ffacd0b85a97d-43b9ea62f50mr10725997f8f.43.1774712306142; Sat, 28 Mar 2026 08:38:26 -0700 (PDT) Received: from f.. (cst-prg-89-171.cust.vodafone.cz. [46.135.89.171]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43cf247102dsm7196887f8f.27.2026.03.28.08.38.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Mar 2026 08:38:25 -0700 (PDT) From: Mateusz Guzik To: brauner@kernel.org Cc: viro@zeniv.linux.org.uk, jack@suse.cz, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Mateusz Guzik Subject: [PATCH v2 4/5] fs: handle hypothetical filesystems hich use I_DONTCACHE and drop the lock in ->drop_inode Date: Sat, 28 Mar 2026 16:38:06 +0100 Message-ID: <20260328153807.3368975-5-mjguzik@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260328153807.3368975-1-mjguzik@gmail.com> References: <20260328153807.3368975-1-mjguzik@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" f2fs and ntfs play games where they transitiong the refcount 0->1 and relea= se the inode spinlock, allowing other threads to grab a ref of their own. They also return 0 in that case, making this problem harmless. Should they start using the I_DONTCACHE machinery down the road while retaining the above, iput_final() will get a race where it can proceed to teardown an inode with references. Future-proof it. Developing better ->drop_inode and sanitizing all users is left as en exercise for the reader. Signed-off-by: Mateusz Guzik --- fs/inode.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index 1f5a383ccf27..fc6045e6d43f 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -1933,20 +1933,29 @@ static void iput_final(struct inode *inode) else drop =3D inode_generic_drop(inode); =20 - if (!drop && - !(inode_state_read(inode) & I_DONTCACHE) && - (sb->s_flags & SB_ACTIVE)) { + /* + * XXXCRAP: there are ->drop_inode hooks playing nasty games releasing the + * spinlock and temporarily grabbing refs. This opens a possibility someo= ne + * else will sneak in and grab a ref while it happens. + * + * If such a hook returns 0 (=3D=3D don't drop) this happens to be harmle= ss as long + * as the inode is not marked with I_DONTCACHE. Otherwise we are proceedi= ng with + * teardown despite references being present. + * + * Damage-control the problem by including the count in the decision. How= ever, + * assert no refs showed up if the hook decided to drop the inode. + */ + if (drop) + VFS_BUG_ON_INODE(icount_read(inode) !=3D 0, inode); + + if (icount_read(inode) > 0 || + (!drop && !(inode_state_read(inode) & I_DONTCACHE) && + (sb->s_flags & SB_ACTIVE))) { __inode_lru_list_add(inode, true); spin_unlock(&inode->i_lock); return; } =20 - /* - * Re-check ->i_count in case the ->drop_inode() hooks played games. - * Note we only execute this if the verdict was to drop the inode. - */ - VFS_BUG_ON_INODE(icount_read(inode) !=3D 0, inode); - if (drop) { inode_state_set(inode, I_FREEING); } else { --=20 2.48.1 From nobody Thu Apr 2 14:10:31 2026 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD179349AFC for ; Sat, 28 Mar 2026 15:38:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774712311; cv=none; b=NwtS1zlH1V2zsvMnvJSpe/0yJW277dZ+zdQwPkfSLMGHGxtr61DtVR/MMxGgZPK2mTrPWG+JF2B6yReb/NJQqMesgAh3lu2P7yFwGk0s3fJ1NQN9xz4EEvh82rggN9lC/hhM+atkgzwWXu+rQpA4lprdg2nnDzqer8gJhFo2QIw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774712311; c=relaxed/simple; bh=gmOLacFBLCNj5VvdypSCbBb3+/owFsIUDBdTNEiM7QU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Kdy9vBR26OvoA2Oabn1Mtx7TKYYuwFvUDRN5y5QUr2ADFGY/Yq8GGv5WxniPeHaxsZcKM6T35OR9rSFnNRpP4uxkHAqpYb/cTPkAYs1coPmN4h4My10B2YmoqGgkzSm+evz7uAyLIYJ2fQUES6aJx3aryaehjvbQv92l6F+XmmA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=OsKO5nu2; arc=none smtp.client-ip=209.85.221.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OsKO5nu2" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-43b9f43a1feso1209630f8f.1 for ; Sat, 28 Mar 2026 08:38:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774712308; x=1775317108; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KQLr+3qAuCwpPc4ueOptHqyuEcLu/FKN06xV1u7l/MM=; b=OsKO5nu2vgjueinaqtcweQ0o9XDaX3yPAAJCZxzoRl1HnxU6+2csLTkKu1ZHYV8LQr jKXycxLj0P6YWGBwmlQjdQUBPiEjG+EhC5F98xi4R/rzbVqJjSGYLSt8NmJKQxDpKjZQ NvVRCb/o7qSfPiEro6CyEZV7xhi4oT7oYAtxr+jPIKH6P1nYK00Lq1DF5PLrtRE/7y+E PIsjSrZv5ZDQT5uRXFOFvx+BLXbB2mDhIL6U0hmr2tbtmyxO2Vreadyo/nmHhXFfjq7x p1QL45mMEQgKLUdMCOWI3YCOIVo9oe1qAkGsBMvy5yvtFzOXYfiDGEDBv9UuuOuaHIHu cSRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774712308; x=1775317108; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=KQLr+3qAuCwpPc4ueOptHqyuEcLu/FKN06xV1u7l/MM=; b=MGgZ/M5poErqdXWCzMG79iCeJz+LTfRx+g3zn91DH2fq7FQcpaLzg6LrzBmyan7Mpk pcKEKpwog93J4RLe7HtE9Pv1TyGOLl+NMbZserwCbfmUOUPsSzYWYNf0+nvYen9PWtIC NC+IAEoRsd7DF7f+e5a4S0K9LIGCUQ58nYMK51P4nAFoUNimyksUb/3dg7I7nrfgrEl+ vrIPqmwRfIx2goJq3XrBEJZLtwC6imbfOAjjmcyMOMgeiQY2mm7zxsYGUBchNTOD4Cou IAmhYxgB4rRmCwoPK0rHDmli8ZJzsJKpwK3PRGjwKsqOjGK4yO07HY6lVOpQ75p2qXVN nBCw== X-Forwarded-Encrypted: i=1; AJvYcCWGlwrc+BjZxGkuEnFKHAVLWuG+RC5rReMyQCL4j/hBgvFMCXZ1a+jPNVLDG0YsVxQ9R6cIHzkAMDACGN8=@vger.kernel.org X-Gm-Message-State: AOJu0Yzmk0qNEg7Qn+hzG127A4zJBvqZJQO1Z0mAEUhDylGRXMw08l9A c2BhMtZrkSXB9CHeZWyVJgbcLsFym5GPyXu9YX0dqS3EVtlThMI6JzpR X-Gm-Gg: ATEYQzw2oy51UrwyrDnlU/gF8GV7OuJ3IVc+QusXTEma0QuTdftNDfu3R8vvwznKKNU Qu+9NhTjy7foCvMH2u0emlX/nVyRnSRqZzVS8zkkPFve1Rer6yX/ePL40ds8eYYhyjXrLHL5SJo 2xMrJ4ZTedw1w2rHisZpwjZ/uqkSLZf1aJnzdYFRyg/ChjGLXn6GpiMBQCTVMEaRMAHhuAa0UEY 4Ic0Q5luYg42/uO/asONrf6HoeeHxAH2QGv/Vmsfx6ssuTg/c+i8lx+S3bEdGKJYuoCj7MgVtLp Gq+SVME8qkJ47RN/gjmevoccWePD/ONFr4TDpNDeuEKAFnWfmMy4QR8EphMCXTPKsgXbQsdITBA dRgLrV6T1hO8fdNyop9yIKupLEzwhmqPR5xVstG00tj8YBNEM4cfRV+nb+j+ihn86MO1mJ/cZ/r fzDM1LM//b0ITh/bc7aWW3zIKeVnWmf3nnD01dIhrBO4UG0lu0B7H5FQ84s1o5LJxQYUqAoIZ5m hA9sUpJnv9o X-Received: by 2002:a05:6000:2311:b0:43b:6a16:17e with SMTP id ffacd0b85a97d-43b9e9da63dmr10805829f8f.11.1774712307989; Sat, 28 Mar 2026 08:38:27 -0700 (PDT) Received: from f.. (cst-prg-89-171.cust.vodafone.cz. [46.135.89.171]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43cf247102dsm7196887f8f.27.2026.03.28.08.38.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Mar 2026 08:38:27 -0700 (PDT) From: Mateusz Guzik To: brauner@kernel.org Cc: viro@zeniv.linux.org.uk, jack@suse.cz, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Mateusz Guzik Subject: [PATCH v2 5/5] fs: locklessly bump refs in igrab as long as it does not transition 0->1 Date: Sat, 28 Mar 2026 16:38:07 +0100 Message-ID: <20260328153807.3368975-6-mjguzik@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260328153807.3368975-1-mjguzik@gmail.com> References: <20260328153807.3368975-1-mjguzik@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The bump is gated by I_FREEING | I_WILL_FREE, but these flags can only legally show up if the count is 0. Consequently if the value is at least 1 and it succesfully CAS'ed to something higher, the flags must not be there. I verified all places which look at the refcount either only care about it staying 0 (and have the lock enforce it) or don't hold the inode lock to begin with. Thus the patch retains the invariant for correct consumers and does not make things worse for the rest. Signed-off-by: Mateusz Guzik --- fs/inode.c | 5 +++++ include/linux/fs.h | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index fc6045e6d43f..17b925887382 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -1580,6 +1580,11 @@ EXPORT_SYMBOL(iunique); =20 struct inode *igrab(struct inode *inode) { + if (atomic_add_unless(&inode->i_count, 1, 0)) { + VFS_BUG_ON_INODE(inode_state_read_once(inode) & (I_FREEING | I_WILL_FREE= ), inode); + return inode; + } + spin_lock(&inode->i_lock); if (!(inode_state_read(inode) & (I_FREEING | I_WILL_FREE))) { __iget(inode); diff --git a/include/linux/fs.h b/include/linux/fs.h index 07363fce4406..119e0a3d2f42 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2234,8 +2234,8 @@ static inline int icount_read_once(const struct inode= *inode) } =20 /* - * returns the refcount on the inode. The lock guarantees no new references - * are added, but references can be dropped as long as the result is > 0. + * returns the refcount on the inode. The lock guarantees no 0->1 or 1->0 = transitions + * of the count are going to take place, otherwise it changes arbitrarily. */ static inline int icount_read(const struct inode *inode) { --=20 2.48.1