From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64F24C25B10 for ; Fri, 10 May 2024 11:41:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CB80D6B00BA; Fri, 10 May 2024 07:41:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C680E6B00BB; Fri, 10 May 2024 07:41:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B308E6B00BC; Fri, 10 May 2024 07:41:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 90B456B00BA for ; Fri, 10 May 2024 07:41:04 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 41728A17A6 for ; Fri, 10 May 2024 11:41:04 +0000 (UTC) X-FDA: 82102294848.21.CAEFFA0 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf19.hostedemail.com (Postfix) with ESMTP id C0C5B1A000F for ; Fri, 10 May 2024 11:40:59 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; spf=none (imf19.hostedemail.com: domain of yi.zhang@huaweicloud.com has no SPF policy when checking 45.249.212.51) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715341260; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T8V+CO6Ls6gFy7RPARzed/4DMgvnC2o+IpFPFBnoWbo=; b=Tj6VaLWJI1AzwvBJoxCSg7xYtkkIJBkrFBz8PY8YrDAPKMP+rtFeTmqB0jh3vAX6N60e1t 3F8Ggok0tUIOGOUYPJNc1+aCER9GTuEosBbrQ+G1UArN3dFj3Q7qIRIRfHPXrYIFUU/J6T rzedAh7SwgNVCqtK9MQt1R3xBr2AesU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715341260; a=rsa-sha256; cv=none; b=BAbBAn/LniocqGGXtE4j9rlEsCpYpoXPu0nwxRS8L3jle4NPua9W89CEg6sN4UAVYaB1cw EyoW3DorGhHlDOK/2AJyrZT+pEs3hYDHRr5BUJUxwc3Zih+lixmYdsHc5iZPk4zEQHTvdX vV4ryOq6Q8/857spYrSfyrtKbsICZWc= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; spf=none (imf19.hostedemail.com: domain of yi.zhang@huaweicloud.com has no SPF policy when checking 45.249.212.51) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VbRlc51G7z4f3m7L for ; Fri, 10 May 2024 19:40:44 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 9FF941A016E for ; Fri, 10 May 2024 19:40:54 +0800 (CST) Received: from [10.174.179.80] (unknown [10.174.179.80]) by APP2 (Coremail) with SMTP id Syh0CgAXOQzEBz5mwBtJMg--.30386S3; Fri, 10 May 2024 19:40:54 +0800 (CST) Subject: Re: [PATCH v3 03/26] ext4: correct the hole length returned by ext4_map_blocks() To: Luis Henriques Cc: Theodore Ts'o , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> <20240127015825.1608160-4-yi.zhang@huaweicloud.com> <87zfszuib1.fsf@brahms.olymp> <20240509163953.GI3620298@mit.edu> <87h6f6vqzj.fsf@brahms.olymp> <87seyquhpi.fsf@brahms.olymp> From: Zhang Yi Message-ID: Date: Fri, 10 May 2024 19:40:52 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <87seyquhpi.fsf@brahms.olymp> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CM-TRANSID:Syh0CgAXOQzEBz5mwBtJMg--.30386S3 X-Coremail-Antispam: 1UD129KBjvJXoWxWFyUZry8uF13Cw4fZF4xJFb_yoW5tFW8pF WfZFnrtr4kJ348CrZ2yw1rXF10vr45Gr15Xr4rJryfAas09rykWF42kFWY9F97Wr40gw1U tF4jva9rWFyjvFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUv2b4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Cr0_Gr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I 0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40E x7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x 0Yz7v_Jr0_Gr1lF7xvr2IY64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1lc7I2V7IY0VAS 07AlzVAYIcxG8wCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c 02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_ WrylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7 CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6rW3Jr0E3s1lIxAIcVC2z280aVAF wI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa 7IU13rcDUUUUU== X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspam-User: X-Stat-Signature: qteebg7c9yrmmcue3nf5dsr4c81etumf X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: C0C5B1A000F X-HE-Tag: 1715341259-87377 X-HE-Meta: U2FsdGVkX18gUNnkvJF50CIUfIhk+b3UCERiuWIwHm3tzWL1G5Dkae98ZNNYD4lfobek/2yTw6+Q81fdlyYLfYk78F/Ebh95h9W4E5kqQjolygl/niG4dlZuNfBDa0yPkUD4sDfta0h9UeUW78pp+raN2RbRVwsBaK5ER6H7XRy9GZddrlirTn2RPQk/U2yHTcuxAHjt7zw+w2OtrM9SS9iWN9OhT3W1w0fxdxlTw9nalhC/4JFX9WVB7uFmN9IYwK0yTSChYNEr4qRL7E31HGfnQ18KAkYDFw3detATj4ESGrL75BKUmwFoxHu48pLtPUA3rnuZYoj9pTRUD/hsvr4h1qrDbf08AlnIJqh4FsCg2d9Ef8jfyvBJSyFMYehJvl8ZCY4d1knSvh+Qvc9UrBJjrCHn6VFZ5tD8G9/7SetXI54j+zKjC5K7AwZTAmiZ1KFLDuQ3lGQ3+upD1fYvgBS68+SWhOkZFAChrxFOEBsE75vY+r+5qBIf99wrPI3B2tIE7ybYsDUq8GXUXMNq+Tl6YUKNqF/03OxHO7GHvKC70YU7idX9vl5KbZqZyVSaYtsrVSWFS6jQh7+PIV9cptP3QVaXOYU0Wa3bfimUdpGdjbA12RCD8vtDk8Arzx5nL6JnFEWACP7oX1uH+As8XGsbjiDvPOeKWfUQUFXovPIDqiz1GWP3pV9KvZQc2KKNDMLAp8BZ8q88Sns18Mv9vF3cTQAmOqRvGTpZrFqBbukUPHVy7d1o1TG75A7ZOknSFmM/nkvd1k2XSJj5gLJvJ5kV8U+LF6RVu0Kn6s6aIp1SQgJCxYak4RoIN0eN2fUHvzfLsCkDom9mgBKhcVE+dxdk0Hf39KbnnQtvC13WRlTKaTL/JrTNS3lXzHxjQLINzD9UDcoetkFFE0L+ViL68Gq3Q7y9bGRmry+2kIJe3ITR8CpKG17ugyD+igclLYU2GItNRYE/6eNQS4KqMHN RhBLTzIX 2lInQk2+ecxql1V3EaJxrTI1sHXb9ghknGOOZ3KhzQT27h1khVeYh11bOOtoW1HV1P+TmdF8mcT270lg3X0lDU0+5F07xY59sAWeaoZoCgT9Z7/5sRxfxvK12p9HeEHM5w/A7XBOYTcp/8vxB1ii3lqlMf89rXUbAuUQ5dUVL7JCXo/+CnDCGmHtMx03hY5nd/jURLu7Fa+PNAO4VNU1HKeUMLOOxhz6BWRbnIrLyPX+k1Ftw1/8Z1x7bJhNAvqWL8Bd2d2Co5L+OetaE69DRiNlhwp+6DxkhlW5p9PVB0Z8bQ4rjUifxPgICAA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 2024/5/10 17:41, Luis Henriques wrote: > On Fri 10 May 2024 11:39:48 AM +08, Zhang Yi wrote; > >> On 2024/5/10 1:23, Luis Henriques wrote: >>> On Thu 09 May 2024 12:39:53 PM -04, Theodore Ts'o wrote; >>> >>>> On Thu, May 09, 2024 at 04:16:34PM +0100, Luis Henriques wrote: >>>>> >>>>> It's looks like it's easy to trigger an infinite loop here using fstest >>>>> generic/039. If I understand it correctly (which doesn't happen as often >>>>> as I'd like), this is due to an integer overflow in the 'if' condition, >>>>> and should be fixed with the patch below. >>>> >>>> Thanks for the report. However, I can't reproduce the failure, and >>>> looking at generic/039, I don't see how it could be relevant to the >>>> code path in question. Generic/039 creates a test symlink with two >>>> hard links in the same directory, syncs the file system, and then >>>> removes one of the hard links, and then drops access to the block >>>> device using dmflakey. So I don't see how the extent code would be >>>> involved at all. Are you sure that you have the correct test listed? >>> >>> Yep, I just retested and it's definitely generic/039. I'm using a simple >>> test environment, with virtme-ng. >>> >>>> Looking at the code in question in fs/ext4/extents.c: >>>> >>>> again: >>>> ext4_es_find_extent_range(inode, &ext4_es_is_delayed, hole_start, >>>> hole_start + len - 1, &es); >>>> if (!es.es_len) >>>> goto insert_hole; >>>> >>>> * There's a delalloc extent in the hole, handle it if the delalloc >>>> * extent is in front of, behind and straddle the queried range. >>>> */ >>>> - if (lblk >= es.es_lblk + es.es_len) { >>>> + if (lblk >= ((__u64) es.es_lblk) + es.es_len) { >>>> /* >>>> * The delalloc extent is in front of the queried range, >>>> * find again from the queried start block. >>>> len -= lblk - hole_start; >>>> hole_start = lblk; >>>> goto again; >>>> >>>> lblk and es.es_lblk are both __u32. So the infinite loop is >>>> presumably because es.es_lblk + es.es_len has overflowed. This should >>>> never happen(tm), and in fact we have a test for this case which >>> >>> If I instrument the code, I can see that es.es_len is definitely set to >>> EXT_MAX_BLOCKS, which will overflow. >>> >> >> Thanks for the report. After looking at the code, I think the root >> cause of this issue is the variable es was not initialized on replaying >> fast commit. ext4_es_find_extent_range() will return directly when >> EXT4_FC_REPLAY flag is set, and then the es.len becomes stall. >> >> I can always reproduce this issue on generic/039 with >> MKFS_OPTIONS="-O fast_commit". >> >> This uninitialization problem originally existed in the old >> ext4_ext_put_gap_in_cache(), but it didn't trigger any real problem >> since we never check and use extent cache when replaying fast commit. >> So I suppose the correct fix would be to unconditionally initialize >> the es variable. > > Oh, you're absolutely right -- the extent_status 'es' struct isn't being > initialized in that case. I totally failed to see that. And yes, I also > failed to mention I had 'fast_commit' feature enabled, sorry! > > Thanks a lot for figuring this out, Yi. I'm looking at this code and > trying to understand if it would be safe to call __es_find_extent_range() > when EXT4_FC_REPLAY is in progress. Probably not, and probably better to > simply do: > > es->es_lblk = es->es_len = es->es_pblk = 0; > > in that case. I'll send out a patch later today. > Yeah, I'm glad it could help. Thanks, Yi.