Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2105775rdb; Tue, 20 Feb 2024 18:19:00 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWC03QxFZWWCrUATI5Uj/1SVJjp14klnmWI7lDnxiCWn+IzJEYz4KnB6AQoexOccazDzlYz08cTiwIDYBgzPouEiXh+wG9iZ4TfCuPtHQ== X-Google-Smtp-Source: AGHT+IGuLhb/qpwXlW8K8xIry8nnFU//3RpvFQ093hIEd4eMnz6mGMONu5I4+UAiJ0wqvK6NVJPI X-Received: by 2002:a67:fd0b:0:b0:470:4712:594 with SMTP id f11-20020a67fd0b000000b0047047120594mr7038050vsr.9.1708481940463; Tue, 20 Feb 2024 18:19:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708481940; cv=pass; d=google.com; s=arc-20160816; b=PTNkEke+WIFylkgTpVrjbU1O6OzypRNIfygfsB3egQXK1Sb7TjH8gYFJZv+YuUUZcw W3XaLcpjF0c2R7Ws3OIKrxyGML2zloW6gk+9H9LWmwYZVIlWrxpOBsqxywgSPqUxNOFF bNGhf0x3sGrueZ0k4quuTEQ3XTseRqCkm7aFgdRBBkKW2XpBxYLiyRpFSZl2le9IIVjJ iHnbqwvrfuCOdUu3u5bEMG0pw1tt0VPduJ233e6x5iiB+tBbkI+yQxsTPcaE8g6VdGBr bYwTmr2qZdSLYoGeFA99mDqxutEpm71g5EsbEjPseH/FNtaz+XwdVVjVBO1ulNHLfUyM 87Hg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id:dkim-signature; bh=u91vHPmTfNCmbDbQ1w3BDcSiany6MNqpaa6ax/w7hOY=; fh=FK8w6Cs1q5mhZ8PixpX6KCFqAEpJzWd9wMo9oTf7Fbk=; b=jeNBniJlszDzCiX1Up8a8ILqVdvX+kt25LShommGsG2Ak7O0Q/4apFO9Fst6Lq4Jcs qnMbzitCFGu1IqSEbal0irBf3h0IPy85+6+WghCKme5AWdrTnasjf3j16J9ssrmzldqQ hIOytLZBneSbfEV3J4KHPErXv7uriltYOlRS0SDOzoF9o2GSCk0svCpvDcK0IxKbmkSe prRuFsJl9X9mR8i9nZv6r9mNPULKxSiykIFLX0Ju9FW2vlNlSlsCRDDCGVwCd1CyRQ/l VgOYGm2jtyKrv/Dkb1oP6fGq/c0sPIVcCcIl7vT0Y/LL8CUhr1xo2j14MmpB+0ycJ8hp cpNg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=R9oBRzmt; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-73944-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73944-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id m11-20020ac8688b000000b0042dd9363a37si9551897qtq.426.2024.02.20.18.19.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 18:19:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-73944-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=R9oBRzmt; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-73944-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73944-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 3AA7C1C226C3 for ; Wed, 21 Feb 2024 02:19:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0521BF9D1; Wed, 21 Feb 2024 02:18:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="R9oBRzmt" Received: from out30-97.freemail.mail.aliyun.com (out30-97.freemail.mail.aliyun.com [115.124.30.97]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8174717BBA; Wed, 21 Feb 2024 02:18:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.97 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708481910; cv=none; b=TCbnBmcXzNzx68LmxP7Ea5pQVYHJZkGRze6kklY/dUSbZ9Z+nYEDd0y9MdRwFiFMb+YzeY0capeYhII2Q0/87g/zuB3cfDTlYa1V0w7O1fw2CCYXfEKaVLTjS5nGZVojGZMhFyvGPGbJtehrXVgwqSBwWYkaleJJe/oWhbrdqMU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708481910; c=relaxed/simple; bh=rRqpE8h/KNn+FQIAVNM5vudNpdCVfCEusK6cOl+XA6o=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=VjcCL2EaWGuw7EYblxyajZDDKQdPZgkej8N4v1B8Z6/IZh0ZkUNqUCGHIf7fF8oc9TVEkEqGusOjiVsteRXQ8SQM5OEhWxWu5ZELhP4EISyswiC3ogHi5/FFfb0CSqmGdDLKLR1dGcoGTrUff8aKGC4KDGe8Wpjic2w2li9dXwM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=R9oBRzmt; arc=none smtp.client-ip=115.124.30.97 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1708481905; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=u91vHPmTfNCmbDbQ1w3BDcSiany6MNqpaa6ax/w7hOY=; b=R9oBRzmtj6TSc3lSFdTXsxrkQe1zJcI4CJqRT6qXmxd0e2Uhdm/B3N7GKqlc6dWynV7RiXFE96e7cP2BQWgehxpa0mAlBy6A7X7hr5RKAWDUW2DNGguk5mD5O+hzqT+X9p8pQi6b9MvD5d1VxlbUNRVUVbnrezcHDbWOplpijP0= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R961e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046060;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=10;SR=0;TI=SMTPD_---0W0yLCp9_1708481903; Received: from 30.97.48.183(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0W0yLCp9_1708481903) by smtp.aliyun-inc.com; Wed, 21 Feb 2024 10:18:24 +0800 Message-ID: <6c2d5345-98bc-49b1-adc7-bcc349a0a6bb@linux.alibaba.com> Date: Wed, 21 Feb 2024 10:18:22 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1] erofs: fix refcount on the metabuf used for inode lookup To: Sandeep Dhavale , Gao Xiang , Chao Yu , Yue Hu , Jeffle Xu Cc: quic_wenjieli@quicinc.com, stable@vger.kernel.org, kernel-team@android.com, linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org References: <20240220191114.3272126-1-dhavale@google.com> From: Gao Xiang In-Reply-To: <20240220191114.3272126-1-dhavale@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 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