From nobody Thu Apr 2 15:41:24 2026 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.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 1813D34D4CC for ; Sat, 28 Mar 2026 15:32:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774711935; cv=none; b=nJXVmbk48e8LiCGZftr8Sis6GPH+mCk7m/2r/ZB2bdTpcdq0/nW3cnqDE8+c2WeNBFP62VsadQ28zTaqUrsodbnrD5rhChFYnJVipThhC2KaAywnAlVUAbKeSWsMhuzZ/2XgF9/Hzxc/SWavxUKqsunNA0I7p7BpcOITq6JuxQM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774711935; c=relaxed/simple; bh=gmOLacFBLCNj5VvdypSCbBb3+/owFsIUDBdTNEiM7QU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YD14hI88hHJa3VZSiO+k9Dq1dnE6Rq2HxnS4wqFXBJ+4LG5APuX1oFfWxr1GDHTYOFtPjsaJ0KPKwYWj0cQEahwylGF4LzZIw8xNn03FR6Kqhg2NcaGm1Kzl8nRJ37Yf5ks1u59qL5RdhEimdh5lIK4t1u6SnuqFW8uMIoLl7zk= 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=JKtJNYy0; arc=none smtp.client-ip=209.85.221.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="JKtJNYy0" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-43cf5d14d6eso312020f8f.0 for ; Sat, 28 Mar 2026 08:32:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774711930; x=1775316730; 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=JKtJNYy091Ew3hS08qXDYPtAFUqHbPfMtU2JUA+4i+29AAk76nsZeVURnHc7cX2D+D Sfq5aDmo0AH9Wp4cs25DZo+rrFrq6OJhTajCg7NCwoXELxpU9sBermHLGpbXQ971NSKA pzZZfgQPv293FV9sVnZKmXarftUQ7NcwKk89eeNtJHy85eGTBWnqLBx3rhb2nJ8nPBqZ 6nnGDaWxugl+qgxRPyfRGl+Fc2U16PDGGBsAj3NA7DFHKVeZdp3wWDWuZ8mhVMXaX5/m dcF8q3njesLARMymAK6E9VE2GdUTUD96x6lK11FhqpUnZYakexirlJKOV98kIwlojUIn FlLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774711930; x=1775316730; 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=RAWhWcWB6atBV/vmcfDpZS3I1sSqD9wglbTLrS0n0oXh//oABbqkm8WhfcPULuB5CX /3sGsEpx/U88cUN4XNhxoCEmxnBoGViA9pR5v0V0J5kb+Kz2DYJMNjszBiWCOp0L3yG+ pUKIR8d0RQwAxbyDLfW2eom2gOIwsC6PLTP1zE8MHsKNTya2OZmu1gjmzERYGOUvDtvH o/d0h9+yiKd+vxqY1c5WwpWmOt2yD6BuY8uo9UU3QANocpI3DxoacknnzDqnu4lSxPd2 EnD6gUbex8Mq1rE3A60T3kaoJQXvJjN3Mv1MG1I7OlaKen35Cbc/4A0yqho9iA93FRoF nPYA== X-Forwarded-Encrypted: i=1; AJvYcCXiR/3O3ivcf/94owNocEkHOTtrMQF7uKPS8S8TkI6lhjTYy75R/P1yCJTIFWfl2V8rXB3jd8z2UADyUbQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzhEzXBMdDWOWGlhYeoeNYx9w9t4azvIWo+0uEhgLhsJwQ/zFZP mJRKaxzdsRazGqBEBwfUxKU0iTalhVWVOkbQKIgbMdb+il5b8z9lk/U7sxX3FQ== X-Gm-Gg: ATEYQzyV2WJGhfJsgoS2DfORYmvWTKVp+aWXMSornlYvfLv8axYyQAFyTlZjYjcHRc7 0yh/QVt+PckhFHc90g3tLl/AyO8nsVWvlSbfPHRdh/qEbkoB9b6r7SpvvgLEk8O/D4Urx1sV+FT mbpTMYzDQdlvdeCk3BOElx9wRH+J3IFmtMH4lD58zpyXbTpqm6jLytA/NsmIO1g2UBGltBMemxi ecAQLH17OxWZRHqPHNsJiz5EjawujLeSf1/shBPFOClplNjxSS6lNqYYyqAmIRGqE3wtlvFSdDi vTbZW4DnIfsoRqU91kK/hZG5jBAFn/nLL8KjBEJF/GdmLrGpMXWpoHlhfj5VCwjbOOh85/QulOG 1N277Ci7Qv7Gkro2jaThObi05krzLoAqCuyUrUMdKeZ++mUh8kQsA7cPAucFISvx707GIhHikgJ lWGr98dNDst65BDT5mQ3ec7AKdwIAs7nTD2XH0gs8XWGTgejcjUP8qGRaohkzxLnuNskjmMCPfr g== X-Received: by 2002:a5d:5402:0:b0:43c:ef4f:79cd with SMTP id ffacd0b85a97d-43cef4f7b47mr3752356f8f.48.1774711930452; Sat, 28 Mar 2026 08:32:10 -0700 (PDT) Received: from f.. (cst-prg-89-171.cust.vodafone.cz. [46.135.89.171]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43cf245f8a3sm6725310f8f.24.2026.03.28.08.32.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Mar 2026 08:32:09 -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 5/5] fs: locklessly bump refs in igrab as long as it does not transition 0->1 Date: Sat, 28 Mar 2026 16:31:46 +0100 Message-ID: <20260328153146.3368470-7-mjguzik@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260328153146.3368470-1-mjguzik@gmail.com> References: <20260328153146.3368470-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