Message ID | 20240220191114.3272126-1-dhavale@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-73574-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp611682dyc; Tue, 20 Feb 2024 11:12:25 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWHN00oRdz7KWC34Ebpx59/sNPEV3KfJ+gO8hyigAAPQj4Otcxkd6Y7AVEgqpvDg/tug1jvEThUGKhNIN5XCb2NStNeXw== X-Google-Smtp-Source: AGHT+IF9S96A87Ge70N3XqmP48tHb7Yw6ryxkb9q4o49M7YswdF8A/KtrSJl7bTWRsCKeP6I0DM1 X-Received: by 2002:aa7:cd10:0:b0:564:ed81:7b1b with SMTP id b16-20020aa7cd10000000b00564ed817b1bmr237543edw.8.1708456345234; Tue, 20 Feb 2024 11:12:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708456345; cv=pass; d=google.com; s=arc-20160816; b=VQC/M1cAT+Xth8hbdq7L3TdD7YoTRa/xBDIKYlaC7e1Ky0DGlp8UHHZ805BB7iKVkF hT5T//5dq9KCMHRzo3utyaw9NsrOysTUASieN8doSLeA5ouH0OJpALPDmNze61Tm1kht MfshiHG315/bYf0ZewqJINQ3hvaQRYOQEWWLK5G+T1oDuk7NQ8DQnroij41Yk8q16a+x XvNER8aCC/X2qk8cpBZe4ytPH/AgxhhMx1lksX4exJB7VfZHV1LnVpnFrmlHxVlMUKOE sZG2vryR6Lu6RcKqgT7laEvzHXyn5gAtB1bDXH1IGnkNj91PSgYNW8L1B17sxt1+S2Hf A0ig== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature; bh=bU90kCEdhdXywfoVlc2lzAzGm8wFNOTBAuo+9ULMyJM=; fh=2RupxOt2KrJzl8z2UscQA56OyDMlCQIYV9JfXZK8jq0=; b=bFJH8jj4Tx34RrKfuptru21OUsNR4TuiaX7EADHhW3pxSlKROwthT/mDcojfP6qFB8 iApt4dP64ap7yUTc54bMBaswvRp3Scm1WGvK9A2l6Wmu5X6gvp+nPaBrjZM2bLBC+3+h DFhhWQSqKNTIKNsHWhofJUGWjiT1NKqSFad8MN372BZuIRoC426zWJC+aoGdQ7x5K3Bn S3fOdjxQVJFjprmO92n+Wu43QdEcqKPH8/iHYi+wvWqRxE4+ul57sY4rrHBCLXptwJOz nVYjAersSAvNT47vuVSfYer1YDGq4kVW/RsJmShEtYGosVZVPP2fHFAolaCOYhPMXbxz XpiA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=lR3tcSEM; arc=pass (i=1 spf=pass spfdomain=flex--dhavale.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-73574-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73574-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id j23-20020a508a97000000b0056445f54eafsi2822715edj.685.2024.02.20.11.12.25 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 11:12:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-73574-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=lR3tcSEM; arc=pass (i=1 spf=pass spfdomain=flex--dhavale.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-73574-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73574-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D61511F218F0 for <ouuuleilei@gmail.com>; Tue, 20 Feb 2024 19:12:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D62E7137C2B; Tue, 20 Feb 2024 19:12:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="lR3tcSEM" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 DB0D37602B for <linux-kernel@vger.kernel.org>; Tue, 20 Feb 2024 19:12:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708456329; cv=none; b=gGLwBwZKwtVSzFN7PLDwpCuk10BM48aV+TMMrfJ9pcm/a1e/f/OzPkcLLNtPjjT+DBDV2tUuUiXexaujiOahrLHk4bSRMYHZgbmWNcxU52s+yaxJHOWo7vA4WT7zxTBDF9N5RbVM8VC9EozkcyZR7JeuwKUs7W7YnWTUseKBQW0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708456329; c=relaxed/simple; bh=UV5OpmpTeat3ITv1BlNGoqwicB3qNORaSpRz3WR/B0Y=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=Qhh7FYEEzJ18mHK0ihxXhvYopjULDN1hgFszFECzoukIIBRa1KrEqDJIo5zw56Kl6DGF1W7liidD+cBysfqWRCxvaD8lM7vcWRu8uLXjSYAzGtvQ3j9DBDpvDJ91JfihAbEeqBVDzyru87tDoMxAndJ5cJHWOot6g0OJu3fjA1k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--dhavale.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=lR3tcSEM; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--dhavale.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60770007e52so62620597b3.1 for <linux-kernel@vger.kernel.org>; Tue, 20 Feb 2024 11:12:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708456327; x=1709061127; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=bU90kCEdhdXywfoVlc2lzAzGm8wFNOTBAuo+9ULMyJM=; b=lR3tcSEM91+atxZwb2pJMWNRJ1q2Lh3XLxNPB+gEXJNZ8Uf9QgW52wmFiQCpYmGRRM ZdOkNcgMxNbn3Z5e9qpuQF4p1oR4Y8crpqBzf+pV5oZFbk3fSefICN+R2YdB0fuYbWOK ZiTNhXP5pNJFfrBMMD6uvPdK/TIEqhplETjk42fF5u4INIE/UPfpf2nBXXUAi23v1as0 +zoPJNTnGxojplmoH29ULDdT/MlmVuUs0BEVbt++owflZzkuxV8bVbyb8cGYRW7fqZrG dLpATMY30Xqr7RTl9sLaobjeDdyVSr839KKCl+HVE+ETZA/SuiePB+h9pOrXEyesMDed y0hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708456327; x=1709061127; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=bU90kCEdhdXywfoVlc2lzAzGm8wFNOTBAuo+9ULMyJM=; b=MBnhfQiAx4n41BmhKafavwhoW3OgGTFUhQL0VGj2KDctIBKYroyqJN9zyrUEWsmauM hSCrKe9VZ/2F0LUuq4P1sjAROqx+0PrLpUsoTbhhxxgo7nsEXMMmMTilLDwm7cL5PvtU JkfbIAS6sIgRSzhriGS6Vbw2mYFIrnsLrXU7pu229nGilK7uh6fadxWk9U6D6AVKqT5M atDWbhjir7LK+T6lRkkPypkka/BKrBEWj1B1m6FhQwXY6M/HmoNFliMXTZ87Lwe5pwOZ Xx09dWvOBXZWjXK0qp/pYT7aSoVBHUFMcgh7vm2eq2EnOwjrHs4EgcWtb8gilot6TEmW C94A== X-Forwarded-Encrypted: i=1; AJvYcCU0UCOh69Ho52VpQ6UcUUSzJ0z/nsYnW3e6FXsoMO2yag2IVaHcAOgW9ph0t2PhwEO5I7b/O1BDRhVrY5AxlQ6pdBEc7vTsnJRMUz9a X-Gm-Message-State: AOJu0YyoJS32/btWWs4/KIGvqN964AqTBSg3pa46crrdtU0tmgttaws4 n4CI3WJ/dQIsOPqGmEFqwZtWfbgwx01yWahhLsHfxVUIayUCfkxfMPavmgByfLhSQvuh7qKfs5G KhLoauw== X-Received: from dhavale-desktop.mtv.corp.google.com ([2620:15c:211:201:e64d:5a86:7ce2:3f59]) (user=dhavale job=sendgmr) by 2002:a81:fe07:0:b0:608:22c7:1269 with SMTP id j7-20020a81fe07000000b0060822c71269mr1506123ywn.0.1708456326859; Tue, 20 Feb 2024 11:12:06 -0800 (PST) Date: Tue, 20 Feb 2024 11:11:13 -0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> Mime-Version: 1.0 X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Message-ID: <20240220191114.3272126-1-dhavale@google.com> Subject: [PATCH v1] erofs: fix refcount on the metabuf used for inode lookup From: Sandeep Dhavale <dhavale@google.com> To: Gao Xiang <xiang@kernel.org>, Chao Yu <chao@kernel.org>, Yue Hu <huyue2@coolpad.com>, Jeffle Xu <jefflexu@linux.alibaba.com> Cc: quic_wenjieli@quicinc.com, Sandeep Dhavale <dhavale@google.com>, stable@vger.kernel.org, kernel-team@android.com, linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791446320702673294 X-GMAIL-MSGID: 1791446320702673294 |
Series |
[v1] erofs: fix refcount on the metabuf used for inode lookup
|
|
Commit Message
Sandeep Dhavale
Feb. 20, 2024, 7:11 p.m. UTC
In erofs_find_target_block() when erofs_dirnamecmp() returns 0,
we do not assign the target metabuf. This causes the caller
erofs_namei()'s erofs_put_metabuf() at the end to be not effective
leaving the refcount on the page.
As the page from metabuf (buf->page) is never put, such page cannot be
migrated or reclaimed. Fix it now by putting the metabuf from
previous loop and assigning the current metabuf to target before
returning so caller erofs_namei() can do the final put as it was
intended.
Fixes: 500edd095648 ("erofs: use meta buffers for inode lookup")
Cc: stable@vger.kernel.org
Signed-off-by: Sandeep Dhavale <dhavale@google.com>
---
fs/erofs/namei.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
Comments
Hi Sandeep, On 2024/2/21 03:11, Sandeep Dhavale wrote: > In erofs_find_target_block() when erofs_dirnamecmp() returns 0, > we do not assign the target metabuf. This causes the caller > erofs_namei()'s erofs_put_metabuf() at the end to be not effective > leaving the refcount on the page. > As the page from metabuf (buf->page) is never put, such page cannot be > migrated or reclaimed. Fix it now by putting the metabuf from > previous loop and assigning the current metabuf to target before > returning so caller erofs_namei() can do the final put as it was > intended. > > Fixes: 500edd095648 ("erofs: use meta buffers for inode lookup") > Cc: stable@vger.kernel.org > Signed-off-by: Sandeep Dhavale <dhavale@google.com> Many thanks for the catch! > --- > fs/erofs/namei.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/fs/erofs/namei.c b/fs/erofs/namei.c > index d4f631d39f0f..bfe1c926436b 100644 > --- a/fs/erofs/namei.c > +++ b/fs/erofs/namei.c > @@ -132,7 +132,10 @@ static void *erofs_find_target_block(struct erofs_buf *target, > > if (!diff) { > *_ndirents = 0; > - goto out; > + if (!IS_ERR(candidate)) > + erofs_put_metabuf(target); > + *target = buf; > + return de; > } else if (diff > 0) { > head = mid + 1; > startprfx = matched; The fix is correct, yet I tend to try to reorganize this snippet for simplicity, how about the following diff (untested)? If it looks good to you, could you resend a formal patch? Thanks! Thanks, Gao Xiang fs/erofs/namei.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/fs/erofs/namei.c b/fs/erofs/namei.c index d4f631d39f0f..9fb2d627578e 100644 --- a/fs/erofs/namei.c +++ b/fs/erofs/namei.c @@ -129,25 +129,24 @@ static void *erofs_find_target_block(struct erofs_buf *target, /* string comparison without already matched prefix */ diff = erofs_dirnamecmp(name, &dname, &matched); - - if (!diff) { - *_ndirents = 0; - goto out; - } else if (diff > 0) { - head = mid + 1; - startprfx = matched; - - if (!IS_ERR(candidate)) - erofs_put_metabuf(target); - *target = buf; - candidate = de; - *_ndirents = ndirents; - } else { + if (diff < 0) { erofs_put_metabuf(&buf); - back = mid - 1; endprfx = matched; + continue; } + + if (!IS_ERR(candidate)) + erofs_put_metabuf(target); + *target = buf; + if (!diff) { + *_ndirents = 0; + return de; + } + head = mid + 1; + startprfx = matched; + candidate = de; + *_ndirents = ndirents; continue; } out: /* free if the candidate is valid */ -- 2.39.3
> > If it looks good to you, could you resend a formal patch? Thanks! > Hi Gao, This looks better and more readable. I will send a v2. Thanks, Sandeep. > Thanks, > Gao Xiang
diff --git a/fs/erofs/namei.c b/fs/erofs/namei.c index d4f631d39f0f..bfe1c926436b 100644 --- a/fs/erofs/namei.c +++ b/fs/erofs/namei.c @@ -132,7 +132,10 @@ static void *erofs_find_target_block(struct erofs_buf *target, if (!diff) { *_ndirents = 0; - goto out; + if (!IS_ERR(candidate)) + erofs_put_metabuf(target); + *target = buf; + return de; } else if (diff > 0) { head = mid + 1; startprfx = matched;