From mboxrd@z Thu Jan 1 00:00:00 1970 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 369472F7F15 for ; Mon, 18 May 2026 04:56:27 +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=1779080190; cv=none; b=gyJgYwDTLoSa8NAPpnNgjK6Kd7OUbbY9VmJcKP1iZ6Qx3n/TFYKfGA0m3LBL3IunIhFPhZuLUetG5cw9OLIOGB3WKtgUXEI9o2B5x10vgbLFNc3Ff2N+XTSXN99woGliraZB8Qig3ZaLP7QeJy8CFMZ+xSDsJIEirymLuP5S+nA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779080190; c=relaxed/simple; bh=jK17ra+U3QeRaBG3iM0+CtThYytvEeuX9BGPWLAfSjQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PN+mg1ly6OrEjLgfx6hBRcFOm39Zgau92UueREsEezk2z823yPJv3vBfMaM5q2GjFQWASIsjaYaGTFTxLx8jv4zt+IJIMGtcUABmmHYeqYfhhd09cRGQ8sR4Zf/i4clnJi7lPMK9OEmGm30Rhf+7xwEYelSHJmY9kKTKNnydEvs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=HKNCDNnm; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="HKNCDNnm" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-48fde2f2d61so3540015e9.3 for ; Sun, 17 May 2026 21:56:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1779080186; x=1779684986; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=k0OZZFbtpd0P0l844Mf3BjaBFBMK33D0MsUv0CPwPZc=; b=HKNCDNnmBqBMbtR7WYw4L+mwpO1GaFHXth9d9WvFPWPFXXUdIok+Zbps+PMpub2wRO CDMZB/UWrLfcsnTjrQmrQbMaC3T7qUqGb+122e+zufcZY4xv5Rz/Jjju5QZhI32Ci7vr 3nhyLiQEYaOic7nKNRQk/POigzkQtfoWuMdaIvDugAUH7oG/nsIDGxy9OhFuc/BIBr9S 2t82pPzNf2M948ca0ruUH1WjlFgC3AluupfHiQDZiEexu0smmQ7dCn/EGLJs392YxCKA KT6hSPv2a0/agcbC2Hp+mijfIkSs7ImkE4SXJd5tf6rnNPNXDd/k4QIqBz9Qof9V/gMX 3A/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779080186; x=1779684986; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=k0OZZFbtpd0P0l844Mf3BjaBFBMK33D0MsUv0CPwPZc=; b=JyZjxM9m5PtBddeY6sIhW3/SHOF6K7UlBAmqN32b8bB+2TgzXOyAc8BOaUn1BxFDsW a29AHa8zHrifdsVyRI0w3PIhL1fEiIvlQ7m5f6Rxn01v7px9x9e2obOGrkDCMOkqoiKX px+UW5CQF+adMaU//wVvEFU1voHu6ZHVX6lTamrRcmVYLE6RffZAbPmnZ15J8QGdkW5e E30q94rPhIqo285BYsArjja0yZt184xot/sHgHO8GR+B4JX14J/xQUDqyfdCLbkJFrDZ IlKwHZl/8wWO+czv3ZXouc8tcPTVUtuUg2ZwLgR3IqJT0zb6WRCahvq7pI/LYuLSwKKV BBJA== X-Forwarded-Encrypted: i=1; AFNElJ8BtpthNLU9KwH0U1AuW2Om83VMWoo11XsM5xvKIh/pIssR7HHVDrVtHQY2iSoiMlWNOT2lcoI5M/pArBA=@vger.kernel.org X-Gm-Message-State: AOJu0YyLQjBbFdxA0d/ZsGj9Oflj/auuCJ5kEleScoNsvGiGGWdX5lfk AZFQntW0do35au6rlsx30BZdGvLK8ay/aS27Ks5E1PdDxxhpuwl+/g2J4yGMNiY5+DKoQwhiohN HcNmwXrM= X-Gm-Gg: Acq92OHLPGA6m0KhozSNkP7pPPvGyLBaVIrK77K0ziZOT/9mWXn2Qo6LB6Hl4v8Rgac 6QTTdc2xSYbQX24Qgv8/yVpIUQNjHE7JWr9+0y34VJoMDIFiRD74gFtfFGH3GzMG/vPXRgH9XGC T1lziMu4MNT5HA26B1c71yYRgFZ2DZ4m3flA84kGBmKPs61j9fd1fo+6TGOQSA7k7Ibhhg56ZbO GqQb99UtoynKsObTJtmZO7AJmq4RmFqHgIDnil1YcT9XIHpSsQzg3R5N5AthjFZQs1rMDQH5jKD Jiq2iXfJzKnCrRtXYCPx4+Z70xL2zxCD/+qijdjUveBbokblq6odh7B4QITvN0CC1JGKAlfnxIm tDhSHq+ZBOMQ9oBpZ48n72tw3+7zV+ZSuyGklXABCPSsaBRZSHIngVdkN5fbq2fyFvpDB7eJSKX /WwvgCl6G4+qHasoD0gvLv9Q== X-Received: by 2002:a05:600c:4fc5:b0:48e:65f3:a950 with SMTP id 5b1f17b1804b1-48fe5fd55cfmr95968225e9.1.1779080186449; Sun, 17 May 2026 21:56:26 -0700 (PDT) Received: from localhost ([202.127.77.110]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2bd5c2631basm129395475ad.34.2026.05.17.21.56.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 May 2026 21:56:25 -0700 (PDT) Date: Mon, 18 May 2026 12:56:22 +0800 From: Heming Zhao To: Tetsuo Handa Cc: Mark Fasheh , Joel Becker , Joseph Qi , jiangyiwen , Andrew Morton , ocfs2-devel@lists.linux.dev, LKML Subject: Re: [PATCH v2] ocfs2: kill osb->system_file_mutex lock Message-ID: References: <934355dd-a0b1-4e53-93ac-0a7ae7458051@I-love.SAKURA.ne.jp> <831c4fc1-c89f-48bc-84c6-25b2cefc2b20@I-love.SAKURA.ne.jp> <670882aa-b637-4565-adf0-ddcd9d7a588b@I-love.SAKURA.ne.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Mon, May 18, 2026 at 01:23:40PM +0900, Tetsuo Handa wrote: > Commit 43b10a20372d ("ocfs2: avoid system inode ref confusion by adding > mutex lock") tried to avoid a refcount leak caused by allowing multiple > threads to call igrab(inode). But addition of osb->system_file_mutex made > locking dependency complicated and is causing lockdep to warn about > possibility of AB-BA deadlock. > > Since _ocfs2_get_system_file_inode() returns the same inode for the same > input arguments, we don't need to serialize _ocfs2_get_system_file_inode(). > What we need to make sure is that igrab(inode) is called for only once(). > Therefore, replace osb->system_file_mutex with cmpxchg()-based locking. > > Fixes: 43b10a20372d ("ocfs2: avoid system inode ref confusion by adding mutex lock") > Signed-off-by: Tetsuo Handa LGTM. Thanks for the patch. Reviewed-by: Heming Zhao > --- > Changes in v2: > Updated patch description. > > fs/ocfs2/ocfs2.h | 2 -- > fs/ocfs2/super.c | 2 -- > fs/ocfs2/sysfile.c | 9 +++------ > 3 files changed, 3 insertions(+), 10 deletions(-) > > diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h > index 7b50e03dfa66..62cad6522c7a 100644 > --- a/fs/ocfs2/ocfs2.h > +++ b/fs/ocfs2/ocfs2.h > @@ -494,8 +494,6 @@ struct ocfs2_super > struct rb_root osb_rf_lock_tree; > struct ocfs2_refcount_tree *osb_ref_tree_lru; > > - struct mutex system_file_mutex; > - > /* > * OCFS2 needs to schedule several different types of work which > * require cluster locking, disk I/O, recovery waits, etc. Since these > diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c > index b875f01c9756..6dd45c2153f8 100644 > --- a/fs/ocfs2/super.c > +++ b/fs/ocfs2/super.c > @@ -1997,8 +1997,6 @@ static int ocfs2_initialize_super(struct super_block *sb, > spin_lock_init(&osb->osb_xattr_lock); > ocfs2_init_steal_slots(osb); > > - mutex_init(&osb->system_file_mutex); > - > atomic_set(&osb->alloc_stats.moves, 0); > atomic_set(&osb->alloc_stats.local_data, 0); > atomic_set(&osb->alloc_stats.bitmap_data, 0); > diff --git a/fs/ocfs2/sysfile.c b/fs/ocfs2/sysfile.c > index d53a6cc866be..67e492f4b828 100644 > --- a/fs/ocfs2/sysfile.c > +++ b/fs/ocfs2/sysfile.c > @@ -98,11 +98,9 @@ struct inode *ocfs2_get_system_file_inode(struct ocfs2_super *osb, > } else > arr = get_local_system_inode(osb, type, slot); > > - mutex_lock(&osb->system_file_mutex); > if (arr && ((inode = *arr) != NULL)) { > /* get a ref in addition to the array ref */ > inode = igrab(inode); > - mutex_unlock(&osb->system_file_mutex); > BUG_ON(!inode); > > return inode; > @@ -112,11 +110,10 @@ struct inode *ocfs2_get_system_file_inode(struct ocfs2_super *osb, > inode = _ocfs2_get_system_file_inode(osb, type, slot); > > /* add one more if putting into array for first time */ > - if (arr && inode) { > - *arr = igrab(inode); > - BUG_ON(!*arr); > + if (inode && arr && !*arr && !cmpxchg(&(*arr), NULL, inode)) { > + inode = igrab(inode); > + BUG_ON(!inode); > } > - mutex_unlock(&osb->system_file_mutex); > return inode; > } > > -- > 2.54.0 > >