From patchwork Thu Nov 17 01:42:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Bin X-Patchwork-Id: 21366 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp156955wrr; Wed, 16 Nov 2022 17:27:18 -0800 (PST) X-Google-Smtp-Source: AA0mqf4y/c0VSiJXSE0UmNeAqJm/BHXkfWaxOUwOnSwxtaxqVtwwPTUghQU0WJM8m+Je29Z2SHzY X-Received: by 2002:a17:906:38c:b0:78d:4ebb:7ea1 with SMTP id b12-20020a170906038c00b0078d4ebb7ea1mr345963eja.357.1668648438809; Wed, 16 Nov 2022 17:27:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668648438; cv=none; d=google.com; s=arc-20160816; b=gW3N11hi5QAz0smMSqkcA0+9LeeVyqZzhmZf6/Ciro26654fCB+02ShquzzUVvSQ7j /tiAU/VQ4xC+FhM9iXISy3sby6/3qiGP7me8DzDjfbrz6M2cA9TGnufANS9yDRtxR4Pp jVNZjPsQZCIazXGN8EYgfZ/iT1xK+g7k3Su2WYfw11Ufi2n7e+ReZn2xjsjJfTrT0Gi3 19/f9vXxYW16TckzD0uZ6hxTN7H4Ars+IsmTLR2D7APBpd6Bv0V5cIhHu5FGdALt+Q+C mauoYStoJ75e4kQbOkXJeojTfJ/8QsT+sbVsKLQdRR27hLvaMezozLDUJcizZReQ/XEV x9Ng== 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=CutDlsFvzprEfFNiiOw1ACG6/H13ngVeVWulWY3p1b+96/4g1Q+Es/KzKnEAoevv7F Hf/EwPdjp7jXUMRvk2wK8FZ9ybAZPw2MAk2xz3oRU8obq18ZXhuUAQDJfXh96pfq0pwR itw9OjhBuIZOl4LsHYCo84sSFLVi9SBOpA/yLmZlUquG1ctaW5hFOg3/kSSU/fLPZItK YK2gY903elE8xOfizJxaukjswKRiBnaQDBoUQVcaD2OM2gH1mGjjAE8MVtlyHZy82/V+ l0Q6JaiTM//qmeHe3JTWvalSrZtV7LNOD2EGXa7w2UQaRK2wqeXBjb30XKG+SEyNXQtD h7PA== 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 ne27-20020a1709077b9b00b007adc4a0aeb5si17145150ejc.873.2022.11.16.17.26.55; Wed, 16 Nov 2022 17:27:18 -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 S239031AbiKQBVb (ORCPT + 99 others); Wed, 16 Nov 2022 20:21:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238678AbiKQBV3 (ORCPT ); Wed, 16 Nov 2022 20:21:29 -0500 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF9AD21BD; Wed, 16 Nov 2022 17:21:27 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4NCMZB0Jh5z4f3mSK; Thu, 17 Nov 2022 09:21:22 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgAnmdaSjHVj0gCfAg--.26536S5; Thu, 17 Nov 2022 09:21:25 +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 1/3] ext4: fix incorrect calculate 'reserved' in '__es_remove_extent' when enable bigalloc feature Date: Thu, 17 Nov 2022 09:42:44 +0800 Message-Id: <20221117014246.610202-2-yebin@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221117014246.610202-1-yebin@huaweicloud.com> References: <20221117014246.610202-1-yebin@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgAnmdaSjHVj0gCfAg--.26536S5 X-Coremail-Antispam: 1UD129KBjvJXoWxJF1UXr1rXF4UJF45CryrCrg_yoW8Kr48p3 y8Ar4UWryfuw1UW3yftw1j9Fn29a4UCrW7WFs3t343uFy5A34Sgr10yFs0vFWYqrWIqw4U XF4rKw1jq3WUXaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvmb4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6r1S6rWUM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUGw A2048vs2IY020Ec7CjxVAFwI0_JFI_Gr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W0oVCq3wA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0 oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7V C0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j 6r4UM4x0Y48IcxkI7VAKI48JMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r 4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF 67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2I x0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2 z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnU UI43ZEXa7IU1M7K7UUUUU== 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_NONE 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?1749704705424095694?= X-GMAIL-MSGID: =?utf-8?q?1749704705424095694?= 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 --- 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 Thu Nov 17 01:42:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Bin X-Patchwork-Id: 21368 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp157657wrr; Wed, 16 Nov 2022 17:29:55 -0800 (PST) X-Google-Smtp-Source: AA0mqf6gz1mo2wZYDi4Ed/z50yKSHe9IlQ+FEUkdc4cvqqrikRmugYSxzAfoBOWps4owvyQDWMlz X-Received: by 2002:a17:906:85cc:b0:781:ee12:814 with SMTP id i12-20020a17090685cc00b00781ee120814mr393376ejy.63.1668648595702; Wed, 16 Nov 2022 17:29:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668648595; cv=none; d=google.com; s=arc-20160816; b=PbFsIjmmNx8Sn7Xvphf5jl9zxceSJdz4p3Zj7e0IfunAc/dyK8HywJz+020XUhb+0z PnhRENCAFov+7o9OMY/nMXtKyzSIMZ4vsQYmF0y9UNW/X9UcuXgUniwDT8xix9cMol5p 9ij+c33UHlwcHS6d+yQbrgxURrPrlkFDdiX/QRiMuruAXHCHz5GZENXsjA/IjgAHZP22 CpULQxf286AMzxUlWipBbWW3yhwzIxs0Bfv/aR5Isx+Z/mTNv6T/Z9y7CSnNQwAp1rcX 5fPR41oxsbFrxqWFM4dgXFGb4XEmUVy6sFHJp8ML0fQUK2K8+9IKEoMHu4PowAtWIA7P jsNw== 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=R+m+Gs77hK0M1qngwu5LOSZlel1K1QF+DsVCFLssPo0=; b=FHhqLM9Ee14dQlB81EBJdMdUaHqlww7j2Nz+efbftAJ2beobtYH34nCx2Q5fx97HNn FY0YLF+kL5dUNKB6U/CrQgbR8LoxULBN9jSWdPVOxURMv0fekHWLTMEOFrWn/+fISiAC vp0YnVEoC0z0DloNf1kJQkkZp/PT6HuppRG/ciQY7GmJNJSkAWRGhSH3m44DIJrkuqif ywE9aWeWxEVfzz/4HEsRhTKQACQpGTNuvs0U7qUptYuoYSGQkZQOKwWKRykZu913FjA2 OeNEEbB/pd9UjxrL5zWvXUGzJPrTxeLJuBdhW6le6UAbFZUwsiw561pRQlDLFkdhcku+ PwFg== 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 jg30-20020a170907971e00b007881b45441asi15724967ejc.721.2022.11.16.17.29.32; Wed, 16 Nov 2022 17:29:55 -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 S239082AbiKQBVt (ORCPT + 99 others); Wed, 16 Nov 2022 20:21:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238990AbiKQBVa (ORCPT ); Wed, 16 Nov 2022 20:21:30 -0500 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2387A1FCE2; Wed, 16 Nov 2022 17:21:28 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4NCMZB1jtHz4f3jLS; Thu, 17 Nov 2022 09:21:22 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgAnmdaSjHVj0gCfAg--.26536S6; Thu, 17 Nov 2022 09:21:25 +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 2/3] ext4: WANR_ON when detect abnormal 'i_reserved_data_blocks' Date: Thu, 17 Nov 2022 09:42:45 +0800 Message-Id: <20221117014246.610202-3-yebin@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221117014246.610202-1-yebin@huaweicloud.com> References: <20221117014246.610202-1-yebin@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgAnmdaSjHVj0gCfAg--.26536S6 X-Coremail-Antispam: 1UD129KBjvdXoW7GF1fWw1fuF4kWw4UGFW7urg_yoWkGrgEq3 WUAF10vrWfXw4S9Fs5GrnxJrZYka1DCr18Ww4rKw15Zr10vF4DCw4qyry3Arn5Way8Gr90 9rW8Jry3GrWrWjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbskYFVCjjxCrM7AC8VAFwI0_Xr0_Wr1l1xkIjI8I6I8E6xAIw20E Y4v20xvaj40_JFC_Wr1l1IIY67AEw4v_Jr0_Jr4l82xGYIkIc2x26280x7IE14v26r15M2 8IrcIa0xkI8VCY1x0267AKxVW8JVW5JwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK 021l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r xl6s0DM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl 6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6x IIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_ Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr 1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE 14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7 IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E 87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73Uj IFyTuYvjxU2_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_NONE 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?1749704869667917408?= X-GMAIL-MSGID: =?utf-8?q?1749704869667917408?= From: Ye Bin If 'i_reserved_data_blocks' is not cleared which mean something wrong with code, so emit WARN_ON to capture this abnormal closer to the first scene. Signed-off-by: Ye Bin --- fs/ext4/super.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 63ef74eb8091..30885a6fe18b 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -1385,11 +1385,14 @@ static void ext4_destroy_inode(struct inode *inode) dump_stack(); } - 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); + if (EXT4_I(inode)->i_reserved_data_blocks) { + ext4_warning(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); + + WARN_ON(1); + } } static void init_once(void *foo) From patchwork Thu Nov 17 01:42:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Bin X-Patchwork-Id: 21367 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp157641wrr; Wed, 16 Nov 2022 17:29:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf7qweFMxNwLrywIyav/qzOt9/2AKJvp4YCNSMzqnJLnsdemfnzkQLOU9HpKOruAvi4WeNUq X-Received: by 2002:a17:907:b606:b0:7af:ecf4:61c0 with SMTP id vl6-20020a170907b60600b007afecf461c0mr385452ejc.178.1668648594406; Wed, 16 Nov 2022 17:29:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668648594; cv=none; d=google.com; s=arc-20160816; b=PMlCbKGccF4g2i2CMzPVh9+ymvmPvj1u3ZFzbv0WOT9oGKTfqopoqBrYfMmLoBWawy e7nJ9QYcLB0zH37YssZ38KFCqVPDeAkXcjUiIWW+ow5ACDUXz9nXcELEqyOr6OWOMjww szmvyw5hAbByBBBw/16DUyetIt+YdzmURnfqBvQ2bm+YCKsfhcq9cbHP53xQKOGd+x7c js8raN3mJ+RIlcXPZ2VHWPQqDUi5sqE/rn02xiKIRIMW4TeyqE6j7XS9osgnrMTnDlHV +oviYurM6z1q9sZpJxyzDArNZyYFMX1HhT5TuRRUbtZAMJS+IGa9ZYRrdS6EGPxdiRxR ezBw== 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=xXuok2QqXqGAL14NucPFXjArT3wuVrelJK8f3kZukr0=; b=KOtXb2Z8/VXvi4UMFKo8ynbZzDo+3G4DPXjXXhejMceVy92ubEdcgq+KfeNomjhdj8 a8QN8v1Q+0LhfeLdEf0R9jDj6FpIduFNyoLwV7zWkuAR2px+7poQFFYzKuIBk7J4AJlQ M2Ksbefd46JoenkPFYmHatSIA+JYHazwppEvQvSWTUP4owAgYjSV767XoU/yxU+WQPDG K/JUoPZ3Nvo/vT4WZtLfkKol5kC2z5PAmwPQpI2zIVuy9tGGLCswHQCUO0YzaWrXuZd5 cIwGp0YUeAd8mxQmMu/HOkuq2diglavNEKE10IaQDNxG+GzSSiDYhrj6R8jlbQQC5eI2 76Tg== 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 du19-20020a17090772d300b007aee7ca1184si12132549ejc.602.2022.11.16.17.29.31; Wed, 16 Nov 2022 17:29:54 -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 S239123AbiKQBVo (ORCPT + 99 others); Wed, 16 Nov 2022 20:21:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239006AbiKQBVa (ORCPT ); Wed, 16 Nov 2022 20:21:30 -0500 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4320B2EF08; Wed, 16 Nov 2022 17:21:28 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4NCMZB45wCz4f3jZX; Thu, 17 Nov 2022 09:21:22 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgAnmdaSjHVj0gCfAg--.26536S7; Thu, 17 Nov 2022 09:21:25 +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 3/3] ext4: add check pending tree when evict inode Date: Thu, 17 Nov 2022 09:42:46 +0800 Message-Id: <20221117014246.610202-4-yebin@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221117014246.610202-1-yebin@huaweicloud.com> References: <20221117014246.610202-1-yebin@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgAnmdaSjHVj0gCfAg--.26536S7 X-Coremail-Antispam: 1UD129KBjvJXoWxGrWxAF1kKw4DJr1UAF4rGrg_yoWrAr47p3 yYkw15Cr4rZw1DuFWftF4UXr1Yqay8CFW7ArZakr12qFy8Xa4rtF18tr1jvF15JrZ8Gr1Y qF4jk34j9w45G3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvmb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6r1S6rWUM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUWw A2048vs2IY020Ec7CjxVAFwI0_Gr0_Xr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W0oVCq3wA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0 oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7V C0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j 6r4UM4x0Y48IcxkI7VAKI48JMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r 4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF 67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2I x0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2 z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnU UI43ZEXa7IU8-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_NONE 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?1749704868478432796?= X-GMAIL-MSGID: =?utf-8?q?1749704868478432796?= 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 | 30 ++++++++++++++++++++++++++++++ fs/ext4/extents_status.h | 1 + fs/ext4/super.c | 3 +++ 3 files changed, 34 insertions(+) diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c index 4684eaea9471..786f7e39ee09 100644 --- a/fs/ext4/extents_status.c +++ b/fs/ext4/extents_status.c @@ -1948,6 +1948,36 @@ 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) + return; + + ext4_warning(inode->i_sb, "Inode %lu: pending tree has %d not cleared!", + inode->i_ino, count); + WARN_ON(1); + + 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 30885a6fe18b..ae433e1337ed 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -1393,6 +1393,9 @@ static void ext4_destroy_inode(struct inode *inode) WARN_ON(1); } + + if (EXT4_SB(inode->i_sb)->s_cluster_ratio != 1) + ext4_check_inode_pending(inode); } static void init_once(void *foo)