Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp111446rdb; Wed, 21 Feb 2024 19:51:20 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUvunaJwNBAGoe8PUPoLLtVjJn0liXM3WeqRFiESwhfZjdDL3wx5+GJzc8orEbW4O3EVrsMFxMHTFEaY4DOuMqVcj2jRslEoXH5nFWtBg== X-Google-Smtp-Source: AGHT+IGUW4pIUono8MnsZJkGwBvcd4N/UdJ+vKIyUxXHLNOtDwl1k23TdeSNdRpX4B6I2xt5Lurw X-Received: by 2002:a2e:a545:0:b0:2d2:3dd7:813d with SMTP id e5-20020a2ea545000000b002d23dd7813dmr7695581ljn.17.1708573880431; Wed, 21 Feb 2024 19:51:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708573880; cv=pass; d=google.com; s=arc-20160816; b=WEdQwE+KlM4sZRW2/wFfnIwcU5Ji3Dw/aHLZvAELeYA9HzYkdchsqgHE3m9b+X4fs4 dz+qTlzjXO0UC8EEqn7Hg119/KnzKth6vsmKWEU2iNuyz3aCDS8/qx69W1ykbikO9UEv p2zvjaiBEOzXbKUzb9bq8wTFrl2GCT+RxIA6hCF3TUGOm3kfhr/CD1KJl2HcoGITxdOe KIVdPExY2yTvkxtAD0NYzusdaby+6KBNytPZIEV062C7ud5zHKgn272pLmSirW0WWM87 yxM4ymwTUkrxAm88YdlNmMo9AMLArHamJ1wuh+uA8AzA8PGnhDNAFS9LQ9fXK6Tj4V4U N9GQ== 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 :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=CJY79D8M1SCoCxDQDU82IOlMUxEszgYij44uwT/4mVw=; fh=bmJMP5ZABTubPEgidfBiEdusydDuNG0BjCBCe+D3FK0=; b=gEM92Wvdgs65XDSQ9oOtjOIKyo8FwX4qRuGauAWMDEBhJZuGkEfXknhL2Hf1QBlmum HP26ZaqhLQiHYMGMpEdLLIZ6UtKOMcuLqH7aGaSpoUSZbYC3avvDkeaJxr/4jD/aiVQS 544WzQiXAB3hKhCozV+cGAFyRFQh35v4R/rM4YnfPSARZioviWhArP/nWNA9brcQC1Zf CaCsRiIY4YCi2xEdbSobmFbR7Zz/sVM1TdpMDh/d1vufGjLaFQUfWVd6+SC4Wp81OK95 6v+rPmVptKiib9vdx14cL6hGiZ00TklhZsMPvavlLszaSxVnZ4JxLYgDvg9s+o/eMtqo XIjg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hgxftMf3; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-75876-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75876-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id s26-20020a508d1a000000b005650584776bsi872080eds.15.2024.02.21.19.51.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 19:51:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75876-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hgxftMf3; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-75876-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75876-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 0062F1F21B89 for ; Thu, 22 Feb 2024 03:51:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5B3D417C71; Thu, 22 Feb 2024 03:51:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hgxftMf3" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 68CE5179A1 for ; Thu, 22 Feb 2024 03:51:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708573862; cv=none; b=EmB6JWJBmameiSl95TTx2DHqyZCtYF9X5GRbjquWwro96zhIGXGfy4OUXf7tE5p6uqvhhqi5h6hHLuk+x2PyOb9FEBkHPvPglUfsEl5hOLaGac++aLJhkivhn57KQYUsQUWyPuLF1zjFgPv6udoc411ncmGmTuk6VhTa+7J081I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708573862; c=relaxed/simple; bh=AmuEmjS5wBqNkgpz1y48vQc7UX9xpoy7av58HWxwi4g=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=GUzsRUl9TStCHArszXO8C1VY+wDjMUN652tHbh8SPaFSzths2u43YkLLMNGuG8dHyMuQvcoSDHv+u/54hEkjKm2004a5McGW0lLEIW+BA3/UGWz9r1VhcDWg4PLNOlA63tc/XyjKFwWQzNugV+Yb6eLudKXb8ova7OgdN9rR6KQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hgxftMf3; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12172C433C7; Thu, 22 Feb 2024 03:50:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708573862; bh=AmuEmjS5wBqNkgpz1y48vQc7UX9xpoy7av58HWxwi4g=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=hgxftMf3qeKrempOip8cL2/wXV7Qe0jKIMhcyAMmARCfJBqkTlYH7pfkD6F/QEDTZ 2P0ENRO11mjnDNpCv7hBGSawqvMBUrKwIvKAyo8lWWM1ybhvBEaAxO17MqZhTpa5s8 p4M1UQxwr01Lyoo4Uq20z67ck3iuY3rBdOeZyv+q33OuN679bVcPNzASn9v8iNGGta uZq3IHdkZiDV/rOlrAxoIpn+TDNnHXI7kWqvZLTjHfXKS5A0y2ZupIrqsVtIe3TzlI 02OEpLQLbaRfGSfvs/CNkUNZ5ABrzh6snjKoCgdgR9X5wQp4Gt7agAOY/qc7C/+elu HdnajIsAvdc4w== Message-ID: Date: Thu, 22 Feb 2024 11:50:57 +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 v4 4/4] f2fs: stop checkpoint when get a out-of-bounds segment Content-Language: en-US To: Zhiguo Niu Cc: Zhiguo Niu , jaegeuk@kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, ke.wang@unisoc.com, hongyu.jin@unisoc.com References: <1708409484-27326-1-git-send-email-zhiguo.niu@unisoc.com> From: Chao Yu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2024/2/22 10:15, Zhiguo Niu wrote: > > > On Thu, Feb 22, 2024 at 9:37 AM Chao Yu > wrote: > > On 2024/2/20 14:11, Zhiguo Niu wrote: > > There is low probability that an out-of-bounds segment will be got > > on a small-capacity device. In order to prevent subsequent write requests > > allocating block address from this invalid segment, which may cause > > unexpected issue, stop checkpoint should be performed. > > > > Also introduce a new stop cp reason: STOP_CP_REASON_NO_SEGMENT. > > > > Signed-off-by: Zhiguo Niu > > > --- > > changes of v4: use more suitable MACRO name according to Chao's suggestions > > changes of v3: correct MACRO spelling and update based on the lastes code > > --- > > --- > >   fs/f2fs/segment.c       | 7 ++++++- > >   include/linux/f2fs_fs.h | 1 + > >   2 files changed, 7 insertions(+), 1 deletion(-) > > > > diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c > > index c25aaec..e42e34c 100644 > > --- a/fs/f2fs/segment.c > > +++ b/fs/f2fs/segment.c > > @@ -2665,7 +2665,12 @@ static void get_new_segment(struct f2fs_sb_info *sbi, > >       if (secno >= MAIN_SECS(sbi)) { > >               secno = find_first_zero_bit(free_i->free_secmap, > >                                                       MAIN_SECS(sbi)); > > -             f2fs_bug_on(sbi, secno >= MAIN_SECS(sbi)); > > +             if (secno >= MAIN_SECS(sbi)) { > > +                     f2fs_stop_checkpoint(sbi, false, > > +                             STOP_CP_REASON_NO_SEGMENT); > > We should relocate stop_checkpoint(sbi, false, STOP_CP_REASON_NO_SEGMENT) outside > segmap_lock spinlock, due to it may sleep in f2fs_flush_merged_writes(). > > Indeed it is. How about the following fix? > @@ -2665,11 +2665,7 @@ static void get_new_segment(struct f2fs_sb_info *sbi, >         if (secno >= MAIN_SECS(sbi)) { >                 secno = find_first_zero_bit(free_i->free_secmap, >                                                         MAIN_SECS(sbi)); > -               if (secno >= MAIN_SECS(sbi)) { > -                       f2fs_stop_checkpoint(sbi, false, > -                               STOP_CP_REASON_NO_SEGMENT); > -                       f2fs_bug_on(sbi, 1); > -               } > +               f2fs_bug_on(sbi, secno >= MAIN_SECS(sbi)); >         } >         segno = GET_SEG_FROM_SEC(sbi, secno); >         zoneno = GET_ZONE_FROM_SEC(sbi, secno); > @@ -2700,6 +2696,8 @@ static void get_new_segment(struct f2fs_sb_info *sbi, >         __set_inuse(sbi, segno); >         *newseg = segno; >         spin_unlock(&free_i->segmap_lock); > +       if (secno >= MAIN_SECS(sbi)) > +               f2fs_stop_checkpoint(sbi, false, STOP_CP_REASON_NO_SEGMENT); How about this? --- fs/f2fs/segment.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index d0209ea77dd2..8edc42071e6f 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -2646,6 +2646,7 @@ static void get_new_segment(struct f2fs_sb_info *sbi, unsigned int old_zoneno = GET_ZONE_FROM_SEG(sbi, *newseg); bool init = true; int i; + int ret = 0; spin_lock(&free_i->segmap_lock); @@ -2671,9 +2672,8 @@ static void get_new_segment(struct f2fs_sb_info *sbi, secno = find_first_zero_bit(free_i->free_secmap, MAIN_SECS(sbi)); if (secno >= MAIN_SECS(sbi)) { - f2fs_stop_checkpoint(sbi, false, - STOP_CP_REASON_NO_SEGMENT); - f2fs_bug_on(sbi, 1); + ret = -ENOSPC; + goto out_unlock; } } segno = GET_SEG_FROM_SEC(sbi, secno); @@ -2704,7 +2704,13 @@ static void get_new_segment(struct f2fs_sb_info *sbi, f2fs_bug_on(sbi, test_bit(segno, free_i->free_segmap)); __set_inuse(sbi, segno); *newseg = segno; +out_unlock: spin_unlock(&free_i->segmap_lock); + + if (ret) { + f2fs_stop_checkpoint(sbi, false, STOP_CP_REASON_NO_SEGMENT); + f2fs_bug_on(sbi, 1); + } } static void reset_curseg(struct f2fs_sb_info *sbi, int type, int modified) -- 2.40.1 > > Thanks, > > > +                     f2fs_bug_on(sbi, 1); > > +             } > > + > >       } > >       segno = GET_SEG_FROM_SEC(sbi, secno); > >       zoneno = GET_ZONE_FROM_SEC(sbi, secno); > > diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h > > index 9b69c50..755e9a4 100644 > > --- a/include/linux/f2fs_fs.h > > +++ b/include/linux/f2fs_fs.h > > @@ -75,6 +75,7 @@ enum stop_cp_reason { > >       STOP_CP_REASON_CORRUPTED_SUMMARY, > >       STOP_CP_REASON_UPDATE_INODE, > >       STOP_CP_REASON_FLUSH_FAIL, > > +     STOP_CP_REASON_NO_SEGMENT, > >       STOP_CP_REASON_MAX, > >   }; > > >