From patchwork Mon Nov 21 12:14:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Bin X-Patchwork-Id: 23695 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1539734wrr; Mon, 21 Nov 2022 04:01:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf7WXzRUeTysOl49G0+/yowrcNwRrWpwo23+zsCrydbsDp4TbTEzVbxxj9++d/kmEzkYyspw X-Received: by 2002:a17:906:6d7:b0:781:951:2fb with SMTP id v23-20020a17090606d700b00781095102fbmr15052754ejb.64.1669032096939; Mon, 21 Nov 2022 04:01:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669032096; cv=none; d=google.com; s=arc-20160816; b=RCb1eZybFnYqF5EqynnbaTV67uIQXQUJ4FAv+cBOii3N/i5sNqH6uU9wHeO+IjEMrW CXYek8nMUnZD+nv9GGsZws+a790zowhrndj7N3MNanpdbb9b8m9KA9N7e64b+Xv3en8B QECtZ0M1k3G+eRmCMxwAu6q6e70nOJHjVFS35ofcVLx6HuGndeS4NnMAmtz/awBx9jEz csr6u6UlOHns7nfEnK0nKQrBw7HXNjzFbJlYfY6k2sEBT9m5r+3feEXi7SrrBAV2FtM2 EPGTM62Bbnjd4tDUdvwBJbZJOtflCuWgAyxsQRVU1d4IIuD9qFaqemGjRVpnL4qfAnNi y/8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=z91nk14mIObIqOVp8zgISmF4ZiBR3Rao3nom0meyhAE=; b=kjwWXuyJC3vaGN5sSqdKB8GDh7eR3u9Hzq4RYbsZ/jJhxsClfh4ZUUVTpUTFEpcxDn 73qiZBEB/ek6euEEug1tG/kuCIxG3eod9v8VfD4pE9VCZKGhMYQ693J9b/vYeTcEJdco 1Xqjnym68iMhTWCHOpbykTO8ovOYkNLzrn9JJCrRBIsWniHdx5anKL0RnsujqIgzQrvP 6fTxPVDYuPtGqIeWpJtwsKcvlrdOJBA/FtfTWfdc3zyPBHzmHSnT18+nx5w564LBvwVE 4riNcmZjXOV/zZy10EwYBTkmnpZhDZxGe2Ym35upLkv9FPIaJBjcvqeDOdNIUEz4Bc85 BgDg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x12-20020a170906148c00b00791a3dd01b6si8125123ejc.864.2022.11.21.04.00.58; Mon, 21 Nov 2022 04:01:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231232AbiKULxi (ORCPT + 99 others); Mon, 21 Nov 2022 06:53:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230124AbiKULxY (ORCPT ); Mon, 21 Nov 2022 06:53:24 -0500 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 905B9F39; Mon, 21 Nov 2022 03:53:22 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4NG5PS2tllz4f3jHx; Mon, 21 Nov 2022 19:53:16 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgDHONatZntj0uehAw--.51112S5; Mon, 21 Nov 2022 19:53:19 +0800 (CST) From: Ye Bin To: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org Cc: linux-kernel@vger.kernel.org, jack@suse.cz, Ye Bin , syzbot+05a0f0ccab4a25626e38@syzkaller.appspotmail.com Subject: [PATCH v2 1/3] ext4: fix incorrect calculate 'reserved' in '__es_remove_extent' when enable bigalloc feature Date: Mon, 21 Nov 2022 20:14:32 +0800 Message-Id: <20221121121434.1061725-2-yebin@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221121121434.1061725-1-yebin@huaweicloud.com> References: <20221121121434.1061725-1-yebin@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgDHONatZntj0uehAw--.51112S5 X-Coremail-Antispam: 1UD129KBjvJXoWxJF1UXr1rXF4UJF45CryrCrg_yoW8Kr48p3 y8Ar4UWryfuw1UW3yftw1j9Fn29a4UCrW7WFs3t343uFy5A34Sgr10yFs0vFWYqrWIqw4U XF4rKw1jq3WUXaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvCb4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUGw A2048vs2IY020Ec7CjxVAFwI0_JFI_Gr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr 0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY 17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcV C0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY 6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJrUvcSsGvfC2Kf nxnUUI43ZEXa7IU1M7K7UUUUU== X-CM-SenderInfo: p1hex046kxt4xhlfz01xgou0bp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750107000165838117?= X-GMAIL-MSGID: =?utf-8?q?1750107000165838117?= From: Ye Bin Syzbot report issue as follows: EXT4-fs error (device loop0): ext4_validate_block_bitmap:398: comm rep: bg 0: block 5: invalid block bitmap EXT4-fs (loop0): Delayed block allocation failed for inode 18 at logical offset 0 with max blocks 32 with error 28 EXT4-fs (loop0): This should not happen!! Data will be lost EXT4-fs (loop0): Total free blocks count 0 EXT4-fs (loop0): Free/Dirty block details EXT4-fs (loop0): free_blocks=0 EXT4-fs (loop0): dirty_blocks=32 EXT4-fs (loop0): Block reservation details EXT4-fs (loop0): i_reserved_data_blocks=2 EXT4-fs (loop0): Inode 18 (00000000845cd634): i_reserved_data_blocks (1) not cleared! Above issue happens as follows: Assume: sbi->s_cluster_ratio = 16 Step1: Insert delay block [0, 31] -> ei->i_reserved_data_blocks=2 Step2: ext4_writepages mpage_map_and_submit_extent -> return failed mpage_release_unused_pages -> to release [0, 30] ext4_es_remove_extent -> remove lblk=0 end=30 __es_remove_extent -> len1=0 len2=31-30=1 __es_remove_extent: ... if (len2 > 0) { ... if (len1 > 0) { ... } else { es->es_lblk = end + 1; es->es_len = len2; ... } if (count_reserved) count_rsvd(inode, lblk, orig_es.es_len - len1 - len2, &orig_es, &rc); goto out; -> will return but didn't calculate 'reserved' ... Step3: ext4_destroy_inode -> trigger "i_reserved_data_blocks (1) not cleared!" To solve above issue if 'len2>0' call 'get_rsvd()' before goto out. Reported-by: syzbot+05a0f0ccab4a25626e38@syzkaller.appspotmail.com Signed-off-by: Ye Bin Reviewed-by: Eric Whitney --- fs/ext4/extents_status.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c index cd0a861853e3..4684eaea9471 100644 --- a/fs/ext4/extents_status.c +++ b/fs/ext4/extents_status.c @@ -1371,7 +1371,7 @@ static int __es_remove_extent(struct inode *inode, ext4_lblk_t lblk, if (count_reserved) count_rsvd(inode, lblk, orig_es.es_len - len1 - len2, &orig_es, &rc); - goto out; + goto count; } if (len1 > 0) { @@ -1413,6 +1413,7 @@ static int __es_remove_extent(struct inode *inode, ext4_lblk_t lblk, } } +count: if (count_reserved) *reserved = get_rsvd(inode, end, es, &rc); out: From patchwork Mon Nov 21 12:14:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Bin X-Patchwork-Id: 23694 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1539073wrr; Mon, 21 Nov 2022 04:00:44 -0800 (PST) X-Google-Smtp-Source: AA0mqf7nfce4AGvpeGn+mbwV4Wn2WyPefMkcFuzD8b6M47iQ77jIhxhmvGw3tfoO+03Km+sL0J6Q X-Received: by 2002:a17:902:ba87:b0:189:1890:77c3 with SMTP id k7-20020a170902ba8700b00189189077c3mr7272898pls.138.1669032044615; Mon, 21 Nov 2022 04:00:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669032044; cv=none; d=google.com; s=arc-20160816; b=HAI3ZcsPesDUXCIMLsK89Yx9wir7MUORyLLlxfREEkV/gZVs4D7x4GaJqec93LDmIu UcqjZ4Z/BGuOB6237pbNCtpu2N9hGasIlbBtZRUKlbklEHUV9vUDBb0uCJw6jJeZy5qM hYcQewXzcGT3rCoglzt5ZdXCUGNRzfxyRZ+3RmJZFsQE5FPTTDwS7mZcAWUiVPFFufy+ VZyG+AXiiF+qv72Zpf4t81khXVRQCdn+9oe/ChsJQ2tSmhVea9dM9jl1gwMVpsBx8roC q9du58rzkFlW9BtOkn6oBVNmxCv64ncwaCfx/8P7f7fKGXKilG/u1UPeOanxc2VREe8D M8tQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=wiAY+1K8Z9ylpqt90PubTo1c3ZvsMx2qqme5hyeoqOc=; b=KAbn1W7hrC+bA6mAdtICslHjxMCuI4fdjeD8GGVnIbKvfJU3ASw4yMx6bxwF2QXgFx 9jdeGImhZiXJ5GKoXYwRxktJ/wOD1dVbEUeg6tRqAHl2inX3OF/pLzHUOb2Nv7KuwynQ 9kUvLaLM63hfMz/VwX1ZjN6hLDzp1wDndFaT0X+FfMeweeDggpdv6FiUgbcsgkrVxH70 /oCPlVtg03d9YuahLHCE5BDfvHIJkgTjTqgdgHGZsIoWpIMAjJHowUJeKDkNNC67gWdI y3kWn37f23L2faG+XDEzhfQ9bbwJxOYPBdUn50IQO1ddICKrI03XXqyMAMG45iE60GXU mCmw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d4-20020a170902cec400b00188f0ce7d94si11980410plg.608.2022.11.21.04.00.22; Mon, 21 Nov 2022 04:00:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231187AbiKULxf (ORCPT + 99 others); Mon, 21 Nov 2022 06:53:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229903AbiKULxX (ORCPT ); Mon, 21 Nov 2022 06:53:23 -0500 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFDAF165B2; Mon, 21 Nov 2022 03:53:22 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4NG5PS4wjJz4f3jYt; Mon, 21 Nov 2022 19:53:16 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgDHONatZntj0uehAw--.51112S6; Mon, 21 Nov 2022 19:53:19 +0800 (CST) From: Ye Bin To: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org Cc: linux-kernel@vger.kernel.org, jack@suse.cz, Ye Bin Subject: [PATCH v2 2/3] ext4: record error when detect abnormal 'i_reserved_data_blocks' Date: Mon, 21 Nov 2022 20:14:33 +0800 Message-Id: <20221121121434.1061725-3-yebin@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221121121434.1061725-1-yebin@huaweicloud.com> References: <20221121121434.1061725-1-yebin@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgDHONatZntj0uehAw--.51112S6 X-Coremail-Antispam: 1UD129KBjvdXoW7GF1DXr1UJFW8Zr17uF13XFb_yoWkGrbEqw 40yF10v393Xw4xWFs5GrnxJFsYkF4kCr18Ww4rKF15Zr1jvF4DAw4kAry7Zrn5Way8Grn0 9rWfJry3GrWrWjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbVxYFVCjjxCrM7AC8VAFwI0_Xr0_Wr1l1xkIjI8I6I8E6xAIw20E Y4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l82xGYIkIc2x26280x7IE14v26r15M2 8IrcIa0xkI8VCY1x0267AKxVW8JVW5JwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK 021l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r 4UJVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx 0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWU JVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJV W8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF 1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6x IIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvE x4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa 73UjIFyTuYvjxU2_MaUUUUU X-CM-SenderInfo: p1hex046kxt4xhlfz01xgou0bp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750106945160720924?= X-GMAIL-MSGID: =?utf-8?q?1750106945160720924?= From: Ye Bin If 'i_reserved_data_blocks' is not cleared which mean something wrong with code, free space accounting is likely wrong, according to Jan Kara's advice use ext4_error() to record this abnormal let fsck to repair and also we can capture this issue. Signed-off-by: Ye Bin --- fs/ext4/super.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 0690e2e0b74d..3d30007502a4 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -1387,10 +1387,9 @@ static void ext4_destroy_inode(struct inode *inode) } if (EXT4_I(inode)->i_reserved_data_blocks) - ext4_msg(inode->i_sb, KERN_ERR, - "Inode %lu (%p): i_reserved_data_blocks (%u) not cleared!", - inode->i_ino, EXT4_I(inode), - EXT4_I(inode)->i_reserved_data_blocks); + ext4_error(inode->i_sb, "Inode %lu (%p) i_reserved_data_blocks" + " (%u) not cleared!", inode->i_ino, EXT4_I(inode), + EXT4_I(inode)->i_reserved_data_blocks); } static void init_once(void *foo) From patchwork Mon Nov 21 12:14:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Bin X-Patchwork-Id: 23696 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1539730wrr; Mon, 21 Nov 2022 04:01:36 -0800 (PST) X-Google-Smtp-Source: AA0mqf584ReghPYigbChiEhjCpczapOJuAsDT0kGbzdBAg0FAfi8EapnptDB7zygLyME7YkTIRfD X-Received: by 2002:aa7:d943:0:b0:469:cdb7:7fe4 with SMTP id l3-20020aa7d943000000b00469cdb77fe4mr401317eds.261.1669032096830; Mon, 21 Nov 2022 04:01:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669032096; cv=none; d=google.com; s=arc-20160816; b=W+Dcks4NB3rP+plFosPjW5QHfRQboWhE2HWXVqDH9iYoQA6toh+pvYPQxgYpac4GDT hwpTCJFAGQ7tbbqrcf83cEGqE1beOHWn5/Zvv7Ni/Z/UlPCcTXvVOtAMXWsKv8qD1lhL 3oFTv4StzqJmxdxKSkKSYMX6Gi++WujrIIjs9+ViV7I0AgL30vwrfKY4ZwCMRKxL6nia 5CT6ukb676SfumXoKUP1kN28WHf4LA+qLksbv8QTVzaHPekgCRgdRzMuJho6GQ5VP6EP P1vmNnMq2aKurbvgJd3kBky+D/N1piAKvTa4hS3WEP9/rM8ZszbVaOUB0lcMz/9OWULZ 2LdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=rF5Lvy+GBvTgMPTvYUX1GdfrM3aRiPx5u6wmebZ2N2Q=; b=lzYrbDwF/iGPH8PanQXdWz/iSNcaoXAnMpQsyMKUbGKovllko2mnHjOIumvfs8t01I yfE3APeLviwRj08CyrcryqGslfAUM0WvULa09bSr44D7op+hPlTscISfxrpogkkqU0zl eYxuzUz+kX/RoDlee0rpsErHg3NN09bvpRGealRfFulQE0WSPXoFxI/Epe1mfNSqGQH7 O84eeEZ6MBcF6TC61ypVdYLaGgyYUHB+ztkFvWfOfK5IoVnfH4szmP9bfFgGvbYWDMZV trkz0/sPXNrRbs8+Huy/GhpZgcWocS5PsomEWvmDW91tCVsCkV/NPhXWPKaxF0Dp+BWK 2sGQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id di13-20020a170906730d00b007af039d0bd0si3153942ejc.404.2022.11.21.04.00.59; Mon, 21 Nov 2022 04:01:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230441AbiKULxm (ORCPT + 99 others); Mon, 21 Nov 2022 06:53:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230438AbiKULxY (ORCPT ); Mon, 21 Nov 2022 06:53:24 -0500 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9956016589; Mon, 21 Nov 2022 03:53:22 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4NG5PT0BnLz4f3m6Z; Mon, 21 Nov 2022 19:53:17 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgDHONatZntj0uehAw--.51112S7; Mon, 21 Nov 2022 19:53:20 +0800 (CST) From: Ye Bin To: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org Cc: linux-kernel@vger.kernel.org, jack@suse.cz, Ye Bin , syzbot+05a0f0ccab4a25626e38@syzkaller.appspotmail.com Subject: [PATCH v2 3/3] ext4: add check pending tree when evict inode Date: Mon, 21 Nov 2022 20:14:34 +0800 Message-Id: <20221121121434.1061725-4-yebin@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221121121434.1061725-1-yebin@huaweicloud.com> References: <20221121121434.1061725-1-yebin@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgDHONatZntj0uehAw--.51112S7 X-Coremail-Antispam: 1UD129KBjvJXoWxGrWxAF1kKw4DJr1UAF4rGrg_yoWrCryUp3 y5Cw15Cr48Xw1kuFWfKF4UXr1Yga48CFWUArZakr1aqFy8Xa4ftF18tr1YvF15JrZ8Gr1Y qF40k34j9w4UG3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvCb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUWw A2048vs2IY020Ec7CjxVAFwI0_Gr0_Xr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr 0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY 17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcV C0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY 6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJrUvcSsGvfC2Kf nxnUUI43ZEXa7IU8-zVUUUUUU== X-CM-SenderInfo: p1hex046kxt4xhlfz01xgou0bp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750107000067881958?= X-GMAIL-MSGID: =?utf-8?q?1750107000067881958?= From: Ye Bin Syzbot found the following issue: BUG: memory leak unreferenced object 0xffff8881bde17420 (size 32): comm "rep", pid 2327, jiffies 4295381963 (age 32.265s) hex dump (first 32 bytes): 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ backtrace: [<00000000ac6d38f8>] __insert_pending+0x13c/0x2d0 [<00000000d717de3b>] ext4_es_insert_delayed_block+0x399/0x4e0 [<000000004be03913>] ext4_da_map_blocks.constprop.0+0x739/0xfa0 [<00000000885a832a>] ext4_da_get_block_prep+0x10c/0x440 [<0000000029b7f8ef>] __block_write_begin_int+0x28d/0x860 [<00000000e182ebc3>] ext4_da_write_inline_data_begin+0x2d1/0xf30 [<00000000ced0c8a2>] ext4_da_write_begin+0x612/0x860 [<000000008d5f27fa>] generic_perform_write+0x215/0x4d0 [<00000000552c1cde>] ext4_buffered_write_iter+0x101/0x3b0 [<0000000052177ae8>] do_iter_readv_writev+0x19f/0x340 [<000000004b9de834>] do_iter_write+0x13b/0x650 [<00000000e2401b9b>] iter_file_splice_write+0x5a5/0xab0 [<0000000023aa5d90>] direct_splice_actor+0x103/0x1e0 [<0000000089e00fc1>] splice_direct_to_actor+0x2c9/0x7b0 [<000000004386851e>] do_splice_direct+0x159/0x280 [<00000000b567e609>] do_sendfile+0x932/0x1200 Above issue fixed by 1b8f787ef547 "ext4: fix warning in 'ext4_da_release_space'" in this scene. To make things better add check pending tree when evit inode. To avoid possible memleak free pending tree when check tree isn't cleared. Reported-by: syzbot+05a0f0ccab4a25626e38@syzkaller.appspotmail.com Signed-off-by: Ye Bin --- fs/ext4/extents_status.c | 28 ++++++++++++++++++++++++++++ fs/ext4/extents_status.h | 1 + fs/ext4/super.c | 3 +++ 3 files changed, 32 insertions(+) diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c index 4684eaea9471..a7a612eb70fe 100644 --- a/fs/ext4/extents_status.c +++ b/fs/ext4/extents_status.c @@ -1948,6 +1948,34 @@ void ext4_remove_pending(struct inode *inode, ext4_lblk_t lblk) write_unlock(&ei->i_es_lock); } +void ext4_check_inode_pending(struct inode *inode) +{ + struct ext4_inode_info *ei = EXT4_I(inode); + struct pending_reservation *pr; + struct ext4_pending_tree *tree; + struct rb_node *node; + int count = 0; + + write_lock(&ei->i_es_lock); + tree = &EXT4_I(inode)->i_pending_tree; + node = rb_first(&tree->root); + while (node) { + pr = rb_entry(node, struct pending_reservation, rb_node); + node = rb_next(node); + rb_erase(&pr->rb_node, &tree->root); + kmem_cache_free(ext4_pending_cachep, pr); + count++; + } + write_unlock(&ei->i_es_lock); + + if (count) + ext4_error(inode->i_sb, + "Inode %lu: pending tree has %d not cleared!", + inode->i_ino, count); + + return; +} + /* * ext4_is_pending - determine whether a cluster has a pending reservation * on it diff --git a/fs/ext4/extents_status.h b/fs/ext4/extents_status.h index 4ec30a798260..631267d45ab2 100644 --- a/fs/ext4/extents_status.h +++ b/fs/ext4/extents_status.h @@ -248,6 +248,7 @@ extern int __init ext4_init_pending(void); extern void ext4_exit_pending(void); extern void ext4_init_pending_tree(struct ext4_pending_tree *tree); extern void ext4_remove_pending(struct inode *inode, ext4_lblk_t lblk); +extern void ext4_check_inode_pending(struct inode *inode); extern bool ext4_is_pending(struct inode *inode, ext4_lblk_t lblk); extern int ext4_es_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk, bool allocated); diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 3d30007502a4..0498feecf10d 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -1390,6 +1390,9 @@ static void ext4_destroy_inode(struct inode *inode) ext4_error(inode->i_sb, "Inode %lu (%p) i_reserved_data_blocks" " (%u) not cleared!", inode->i_ino, EXT4_I(inode), EXT4_I(inode)->i_reserved_data_blocks); + + if (EXT4_SB(inode->i_sb)->s_cluster_ratio != 1) + ext4_check_inode_pending(inode); } static void init_once(void *foo)