From patchwork Tue Apr 18 01:17:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dominique Martinet X-Patchwork-Id: 13214923 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CFFA9C77B75 for ; Tue, 18 Apr 2023 01:18:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229963AbjDRBSR (ORCPT ); Mon, 17 Apr 2023 21:18:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229510AbjDRBSQ (ORCPT ); Mon, 17 Apr 2023 21:18:16 -0400 Received: from nautica.notk.org (ipv6.notk.org [IPv6:2001:41d0:1:7a93::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E70B75275 for ; Mon, 17 Apr 2023 18:17:57 -0700 (PDT) Received: by nautica.notk.org (Postfix, from userid 108) id E88BCC01E; Tue, 18 Apr 2023 03:17:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1681780675; bh=PkmCiQrLL96YjUanWM39Rl4r3Fvd3m+dxKjvFbXSGJY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=x0wQjItY1a08pEs/jBZdRfoK+1LmesvgY+fHTuktkpy2HL5g7J30l5U/aqnL4pt3U 9DtY7Vln7MSBkGMAJmgKxd4gBD/GlTYpLSQKO/GlLiozEXEzQtY1PviakRK/KUgBop fQZVJC+36bEucdUjClJaw6BwyqQEjUD9pCsJ6jGs3ZFbWxcNJUuJVqHg20lWXEH100 y8cXEwsW7WVbO0z5TQQ/4i9SNX87NnghlEy74SnXIPIi9mN2efyFkUbqcvcEwL6C/h H8LmkRnng5wSTTUh4h2eGaaLJ1sjLpPW/8kS81W4+LSdw15TYsfUSszq70OB9UYU9w I3pu2oQR+gerg== Received: from odin.codewreck.org (localhost [127.0.0.1]) by nautica.notk.org (Postfix) with ESMTPS id E621FC01A; Tue, 18 Apr 2023 03:17:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1681780675; bh=PkmCiQrLL96YjUanWM39Rl4r3Fvd3m+dxKjvFbXSGJY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=x0wQjItY1a08pEs/jBZdRfoK+1LmesvgY+fHTuktkpy2HL5g7J30l5U/aqnL4pt3U 9DtY7Vln7MSBkGMAJmgKxd4gBD/GlTYpLSQKO/GlLiozEXEzQtY1PviakRK/KUgBop fQZVJC+36bEucdUjClJaw6BwyqQEjUD9pCsJ6jGs3ZFbWxcNJUuJVqHg20lWXEH100 y8cXEwsW7WVbO0z5TQQ/4i9SNX87NnghlEy74SnXIPIi9mN2efyFkUbqcvcEwL6C/h H8LmkRnng5wSTTUh4h2eGaaLJ1sjLpPW/8kS81W4+LSdw15TYsfUSszq70OB9UYU9w I3pu2oQR+gerg== Received: from [127.0.0.2] (localhost [::1]) by odin.codewreck.org (OpenSMTPD) with ESMTP id f0ea5edb; Tue, 18 Apr 2023 01:17:47 +0000 (UTC) From: Dominique Martinet Date: Tue, 18 Apr 2023 10:17:33 +0900 Subject: [PATCH U-BOOT 1/3] btrfs: fix offset within btrfs_read_extent_reg() MIME-Version: 1.0 Message-Id: <20230418-btrfs-extent-reads-v1-1-47ba9839f0cc@codewreck.org> References: <20230418-btrfs-extent-reads-v1-0-47ba9839f0cc@codewreck.org> In-Reply-To: <20230418-btrfs-extent-reads-v1-0-47ba9839f0cc@codewreck.org> To: =?utf-8?q?Marek_Beh=C3=BAn?= , Qu Wenruo Cc: linux-btrfs@vger.kernel.org, u-boot@lists.denx.de, Dominique Martinet X-Mailer: b4 0.13-dev-f371f X-Developer-Signature: v=1; a=openpgp-sha256; l=3027; i=asmadeus@codewreck.org; h=from:subject:message-id; bh=zXCI+2WXL0xQZjXCJ7JbhDsxIxPG1DYINwdsoueMUxk=; b=owEBbQKS/ZANAwAIAatOm+xqmOZwAcsmYgBkPe+7UM3z+mAW/rG27aWAaxpGjZGEF3hH4Zfxl g71s9rxEL+JAjMEAAEIAB0WIQT8g9txgG5a3TOhiE6rTpvsapjmcAUCZD3vuwAKCRCrTpvsapjm cMf0D/991mQmrNQKw1rM7MT3B/m23XBniBrnN6ftSdX1iUTha/gF501CPsboTCiGLwmOBmAGkAn ysmugWIKNY0QWKtDqRILlxu9AeZVs8CDCteu80QcFa/XA8rQV0lpo6lCSgvWw9TmizdW8/kYMAG wzYCGYGvdKX3keBvrT0tlVchsmyh2ep94/jzo3asTdXckSl68O9BMDSnRtu+AtVxuoBG5NsTgfK eUZv9VIvfJljw3yfXYU7Q0yFRgHYmJffnxJXFUW8cKDXHBv/FXlQYx4mni8vEVS06yuxVK3SszL HmThvO/JRVWeuHDlzHKIl3jg1vt4rIk0pwj4p4DINyV+ZTXlnUYHrb3ZWl2GpOU8sryAJo5NlYF 1UKUFAN/fTKYM8e/52qBfswZTq2P+hN+ynuzZq0AHwuuokCX1v83E5yxHGUZDosslhyvxWrfNUV ZOl5NOfSUJzLoorCOxi5YEOGHhnKO+cGoag9NDSihTslAypoSoMhKxjWS2iv1YkjqyVAf9MUu+L C5bPlYQSNcjLCv0KBKg9oXctbUZwGjpXs1tTPcCA9RddR6NfRB7CKlNt5klSPzkDSzvtpSKUrnc PTVAFwfxiMfYJl++5kqzhBQbnLDZuxh22tmCSepShGrBMf8YFjI1l9IdArD3eLjFgzQWa6LOo6/ x/TMpGnD2Fw5B4g== X-Developer-Key: i=asmadeus@codewreck.org; a=openpgp; fpr=B894379F662089525B3FB1B9333F1F391BBBB00A Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Dominique Martinet btrfs_read_extent_reg correctly computed the extent offset in the BTRFS_COMPRESS_NONE case, but did not account for the 'offset - key.offset' part correctly in the compressed case, making the function read incorrect data. In the case I examined, the last 4k of a file was corrupted and contained data from a few blocks prior: btrfs_file_read() -> btrfs_read_extent_reg (aligned part loop from 0x40480000 to 0x40ba0000, 128KB at a time) last read had 0x4000 bytes in extent, but aligned_end - cur limited the read to 0x3000 (offset 0x720000) -> read_and_truncate_page -> btrfs_read_extent_reg reading the last 0x1000 bytes from offset 0x73000 (end of the previous 0x4000) into 0x40ba3000 here key.offset = 0x70000 so we need to use it to recover the 0x3000 offset. Confirmed by checking data, before patch: u-boot=> mmc load 1:1 $loadaddr boot/uImage u-boot=> md 0x40ba0000 40ba0000: c0232ff8 c0c722cb 030e94be bf10000c ./#..".......... u-boot=> md 0x40ba3000 40ba3000: c0232ff8 c0c722cb 030e94be bf10000c ./#..".......... After patch (also confirmed with data read from linux): u-boot=> md 0x40ba3000 40ba3000: 64cc9f03 81142256 6910000c 0c03483c ...dV".....i --- fs/btrfs/inode.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 40025662f250..3d6e39e6544d 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -443,6 +443,8 @@ int btrfs_read_extent_reg(struct btrfs_path *path, IS_ALIGNED(len, fs_info->sectorsize)); ASSERT(offset >= key.offset && offset + len <= key.offset + extent_num_bytes); + /* offset is now offset within extent */ + offset = btrfs_file_extent_offset(leaf, fi) + offset - key.offset; /* Preallocated or hole , fill @dest with zero */ if (btrfs_file_extent_type(leaf, fi) == BTRFS_FILE_EXTENT_PREALLOC || @@ -454,9 +456,7 @@ int btrfs_read_extent_reg(struct btrfs_path *path, if (btrfs_file_extent_compression(leaf, fi) == BTRFS_COMPRESS_NONE) { u64 logical; - logical = btrfs_file_extent_disk_bytenr(leaf, fi) + - btrfs_file_extent_offset(leaf, fi) + - offset - key.offset; + logical = btrfs_file_extent_disk_bytenr(leaf, fi) + offset; read = len; num_copies = btrfs_num_copies(fs_info, logical, len); @@ -511,7 +511,7 @@ int btrfs_read_extent_reg(struct btrfs_path *path, if (ret < dsize) memset(dbuf + ret, 0, dsize - ret); /* Then copy the needed part */ - memcpy(dest, dbuf + btrfs_file_extent_offset(leaf, fi), len); + memcpy(dest, dbuf + offset, len); ret = len; out: free(cbuf); From patchwork Tue Apr 18 01:17:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dominique Martinet X-Patchwork-Id: 13214925 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55F1BC77B76 for ; Tue, 18 Apr 2023 01:18:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230168AbjDRBSU (ORCPT ); Mon, 17 Apr 2023 21:18:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230000AbjDRBSR (ORCPT ); Mon, 17 Apr 2023 21:18:17 -0400 Received: from nautica.notk.org (ipv6.notk.org [IPv6:2001:41d0:1:7a93::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6153349F2 for ; Mon, 17 Apr 2023 18:18:01 -0700 (PDT) Received: by nautica.notk.org (Postfix, from userid 108) id 3816DC022; Tue, 18 Apr 2023 03:18:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1681780680; bh=o8ahh+GkkNunS6bzuWieQkRWIvaKeN5a/F4HG1+hJKE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=XLkKVDRX5TSIgD6ksDWir4ZPfMis07n5tkrKulRTW8wvCKLNSCtJ7WIdY/02oFvc0 HsRYhtumQvcZniK1LXl5vjv5y2JpKEgCiXqt+Yd6ehggt//jSTEICoCCFjwxvkrpHA J6hp7w3bn8IRidRQ8c73axKm5RgC45e5oMLrHmKbTbLEgG0JE6x/4i3zDIb/5Nlsq6 KD1I5NF1zPkELf/Glz9TlgjNrbkvUfjLjZqy/nJYh5n2uGpeFT4ALooIfXEWoSQ1Dr 4rTTCMpSlRMNus4O9mohJ8ZXaqeRsNLvb+k9StDjgIgNGU2OnD7Abua19DUAkR3ZAw gbqmXKix7eXiQ== Received: from odin.codewreck.org (localhost [127.0.0.1]) by nautica.notk.org (Postfix) with ESMTPS id 77D68C020; Tue, 18 Apr 2023 03:17:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1681780679; bh=o8ahh+GkkNunS6bzuWieQkRWIvaKeN5a/F4HG1+hJKE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=xToj4DEmsFmSsy186tuKzL3ZV9lBDAadwRg1hazrpGNm00kJ14VzUCoBvBOtK658s lhdAC9oNNX7o01oHPuV7bb/7KSrROfKWpv8lJqKlX4JcXgzmmuesA78YxiVW2qXhkH vXcVyxUFl9WQH6Ci/G7TVnSfG/uiY9hL+CuYl5bv39BbvFgdF8snPQwdVbzDpmENac HK9g80IS4rUuDiveTdczJjmmc5n5I0dJUHT7NKlldwq7dMeq8we3WNOXNorFSTL8R0 mtXgXYZnSnV9f1ncTADJuKoC+am2Dc1g1IHBYj6Tr/n4g7TX+FVWuOeDe1UDdj9Iz9 a/b3vpdXeL80Q== Received: from [127.0.0.2] (localhost [::1]) by odin.codewreck.org (OpenSMTPD) with ESMTP id ed1adae2; Tue, 18 Apr 2023 01:17:47 +0000 (UTC) From: Dominique Martinet Date: Tue, 18 Apr 2023 10:17:34 +0900 Subject: [PATCH U-BOOT 2/3] btrfs: btrfs_file_read: allow opportunistic read until the end MIME-Version: 1.0 Message-Id: <20230418-btrfs-extent-reads-v1-2-47ba9839f0cc@codewreck.org> References: <20230418-btrfs-extent-reads-v1-0-47ba9839f0cc@codewreck.org> In-Reply-To: <20230418-btrfs-extent-reads-v1-0-47ba9839f0cc@codewreck.org> To: =?utf-8?q?Marek_Beh=C3=BAn?= , Qu Wenruo Cc: linux-btrfs@vger.kernel.org, u-boot@lists.denx.de, Dominique Martinet X-Mailer: b4 0.13-dev-f371f X-Developer-Signature: v=1; a=openpgp-sha256; l=2420; i=asmadeus@codewreck.org; h=from:subject:message-id; bh=BghhxjYbg3uvl/WVD9A/qmvqlstJ4ddaxDDM+2P4agE=; b=owEBbAKT/ZANAwAIAatOm+xqmOZwAcsmYgBkPe+7GNMSAPRdHeAhmheOKpt8wygY3fgQYinEl K1dI5bt+r2JAjIEAAEIAB0WIQT8g9txgG5a3TOhiE6rTpvsapjmcAUCZD3vuwAKCRCrTpvsapjm cEZbD/jvhcW1iJVfJlFTg4wvPzxXpqTKJ51dOC7i0NAl1cGb9fJvL84RGYcL8KU8Tu7YW5Y5Jxx LYTvfty7XZYNVCoabpHhPnLP+XWF+QaUOkdMnphHvjLEauWCGbPBqplr1Zei0eHuCdDEztIS5Wp h7Ie09OD+CVAANvziJCrQMe+Y3fi/eB9VOFs0r7LZPtFo7esdauIbObPD5pKaZnjD+15MpOZ+2/ 1+DgirE90VlhdSHjmMmhyj0/O3GA0apfSPSha/QVfBZ8JvLUhcRn3JWzZ+Q842dKTbYm59yD0DD M11wl2SYP6psUXVHmJH5lfTzepW3Ns9b+s/cQY5LZLNRDXCQVvSU9j3Kev5t8JofjTj5EAxyfQK YL0R3Wumcot/17Pgk0+GqdEm0eFpoCYcTp/gC/9SsRoOGzckkK973Pi3PYrTbcp74c48E66Y0IG zuWcGIMfl+kxccMxI+EPS794Kf0MQxOjfU85rlxdLFAx3DgGusViHz2gYFtvLJ5B3bqxs8qViKB FKGSyCDlZV2+d/8ZWI/9FMj+xxY51XnpU/La1Xn2ExAd12fE6L+4m/P62FjDeNEE959nw+bKMB/ jXtl2hH6Ywojj4WATRVkbLo4x5JArpvu7yT1/+Y5HnOgFKBgKkf6lQK8j7Uznym3ZSrITNIltD3 F7neRhv6H4bXj X-Developer-Key: i=asmadeus@codewreck.org; a=openpgp; fpr=B894379F662089525B3FB1B9333F1F391BBBB00A Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Dominique Martinet btrfs_file_read main 'aligned read' loop would limit the last read to the aligned end even if the data is present in the extent: there is no reason not to read the data that we know will be presented correctly. If that somehow fails cur only advances up to the aligned_end anyway and the file tail is read through the old code unchanged; this could be required if e.g. the end data is inlined. Signed-off-by: Dominique Martinet --- fs/btrfs/inode.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 3d6e39e6544d..efffec0f2e68 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -663,7 +663,8 @@ int btrfs_file_read(struct btrfs_root *root, u64 ino, u64 file_offset, u64 len, struct btrfs_path path; struct btrfs_key key; u64 aligned_start = round_down(file_offset, fs_info->sectorsize); - u64 aligned_end = round_down(file_offset + len, fs_info->sectorsize); + u64 end = file_offset + len; + u64 aligned_end = round_down(end, fs_info->sectorsize); u64 next_offset; u64 cur = aligned_start; int ret = 0; @@ -743,26 +744,26 @@ int btrfs_file_read(struct btrfs_root *root, u64 ino, u64 file_offset, u64 len, extent_num_bytes = btrfs_file_extent_num_bytes(path.nodes[0], fi); ret = btrfs_read_extent_reg(&path, fi, cur, - min(extent_num_bytes, aligned_end - cur), + min(extent_num_bytes, end - cur), dest + cur - file_offset); if (ret < 0) goto out; - cur += min(extent_num_bytes, aligned_end - cur); + cur += min(extent_num_bytes, end - cur); } /* Read the tailing unaligned part*/ - if (file_offset + len != aligned_end) { + if (file_offset + len != cur) { btrfs_release_path(&path); - ret = lookup_data_extent(root, &path, ino, aligned_end, + ret = lookup_data_extent(root, &path, ino, cur, &next_offset); /* <0 is error, >0 means no extent */ if (ret) goto out; fi = btrfs_item_ptr(path.nodes[0], path.slots[0], struct btrfs_file_extent_item); - ret = read_and_truncate_page(&path, fi, aligned_end, - file_offset + len - aligned_end, - dest + aligned_end - file_offset); + ret = read_and_truncate_page(&path, fi, cur, + file_offset + len - cur, + dest + cur - file_offset); } out: btrfs_release_path(&path); From patchwork Tue Apr 18 01:17:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dominique Martinet X-Patchwork-Id: 13214926 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F770C77B75 for ; Tue, 18 Apr 2023 01:18:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229946AbjDRBSV (ORCPT ); Mon, 17 Apr 2023 21:18:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230026AbjDRBSR (ORCPT ); Mon, 17 Apr 2023 21:18:17 -0400 Received: from nautica.notk.org (ipv6.notk.org [IPv6:2001:41d0:1:7a93::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4452B5240 for ; Mon, 17 Apr 2023 18:18:02 -0700 (PDT) Received: by nautica.notk.org (Postfix, from userid 108) id DE159C024; Tue, 18 Apr 2023 03:18:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1681780680; bh=JEEceTcAlFlQ8AvAYBKKcvBhFH03YxmDwBi7XxmCZgY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=m0on4y97W5N18Z228u+zl0XTVg5qgcNUNwCSybQEWcZJ+gNJdmad68LJ2EviVbZ5K geOXLXzmc8f/6p1xTzWJfbMbP+H8OS0i8e3eaQBrOVrwxXNsS2prBgO1FMwG3ZVFnc 0DijuXoHZUaVoIF6PnpKvoSlLlI9M9Nd7o5EQe9UpsZoLnH9Xitflwcyjo13M6gBfr Fz99iddS3U0MWOz0aoSt1N67/XjQ/i5DKIgoPLTJQgU0Un33QOmnuuupCNI+V/faXA 2h2cl5TGT4f3rpWO/DQzTnvSHpKUj8cyUeaBPhRcFuIdri/ogWzClLv/gkCV67aZdz pelrCT8S2pI+Q== Received: from odin.codewreck.org (localhost [127.0.0.1]) by nautica.notk.org (Postfix) with ESMTPS id 466F4C01B; Tue, 18 Apr 2023 03:17:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1681780680; bh=JEEceTcAlFlQ8AvAYBKKcvBhFH03YxmDwBi7XxmCZgY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=m0on4y97W5N18Z228u+zl0XTVg5qgcNUNwCSybQEWcZJ+gNJdmad68LJ2EviVbZ5K geOXLXzmc8f/6p1xTzWJfbMbP+H8OS0i8e3eaQBrOVrwxXNsS2prBgO1FMwG3ZVFnc 0DijuXoHZUaVoIF6PnpKvoSlLlI9M9Nd7o5EQe9UpsZoLnH9Xitflwcyjo13M6gBfr Fz99iddS3U0MWOz0aoSt1N67/XjQ/i5DKIgoPLTJQgU0Un33QOmnuuupCNI+V/faXA 2h2cl5TGT4f3rpWO/DQzTnvSHpKUj8cyUeaBPhRcFuIdri/ogWzClLv/gkCV67aZdz pelrCT8S2pI+Q== Received: from [127.0.0.2] (localhost [::1]) by odin.codewreck.org (OpenSMTPD) with ESMTP id 366bc826; Tue, 18 Apr 2023 01:17:47 +0000 (UTC) From: Dominique Martinet Date: Tue, 18 Apr 2023 10:17:35 +0900 Subject: [PATCH U-BOOT 3/3] btrfs: btfs_file_read: zero trailing data if no extent was found MIME-Version: 1.0 Message-Id: <20230418-btrfs-extent-reads-v1-3-47ba9839f0cc@codewreck.org> References: <20230418-btrfs-extent-reads-v1-0-47ba9839f0cc@codewreck.org> In-Reply-To: <20230418-btrfs-extent-reads-v1-0-47ba9839f0cc@codewreck.org> To: =?utf-8?q?Marek_Beh=C3=BAn?= , Qu Wenruo Cc: linux-btrfs@vger.kernel.org, u-boot@lists.denx.de, Dominique Martinet X-Mailer: b4 0.13-dev-f371f X-Developer-Signature: v=1; a=openpgp-sha256; l=1155; i=asmadeus@codewreck.org; h=from:subject:message-id; bh=KV8LCug/kjzNfyVJRp0HJmoGD0NM/QstSUaV4D5ngSk=; b=owEBbQKS/ZANAwAIAatOm+xqmOZwAcsmYgBkPe+79zAzeLVKK7dPvDg4oaxruBfFEbgyy71Xy tVSgYtheiSJAjMEAAEIAB0WIQT8g9txgG5a3TOhiE6rTpvsapjmcAUCZD3vuwAKCRCrTpvsapjm cBsoD/0abWSShUl0/rNCs6Uj1q0XzFJY3bUFX5mkK7Drwt/hAJlQ3SqxFaecUKlfz/82IH06/6x pw7/dL0pAFXHb0VTWt/HLpJs04RdnekeLEiRY1UWPniiPvPQMmZpHDLV5XBfm6JJl8/bgrEdbov XTdGcZN1MsZae4ij4ElipBdGR8fWqhd5VRMrpsxEs958pVm4xhVhR7CuebWi2FocoK4y7T0QYQb L/7M9DDpVS7XmWLTl736k/VnovE3gMzL5xfVyZerLa0L21SC1JhRL7tjB2LRCS1l55ts/FHghWV iWd1BwxrGf4VcIxYyOumWQ1rt5d0brivlnnrJx5F/bxMOR9QtFK0Bk2ERWHJybAM3oNgu3y7XaD axBEF3z9A/8x5v2rp9OpS6kCD2vCQMeUgq8k+Yp1Gs+UJBT7fMZgN7KgDW172Pi4ngJApkjMLr7 nCJ7WIm0cpU85CNSmdjZFSKbBWeyzsKTE6kLCctIdfqFkF0LYmBMh/S57dK+mCoTK43JjuhrP2r wH3ijW49zgaxqiEmEwqkGRrFtOrriNYlbreGpO50JwXa/2mBjdh10GTXsL8sn/3brZ0RkjAGbaO 8bAlXaBBkmOd/vr7A5NrR2Kkejycg9JomWF0tVqk6xAIIVmoGmInP52jPOnRtfs2G0r/rQ0bT+D L4EIXaKh2J1Y5cg== X-Developer-Key: i=asmadeus@codewreck.org; a=openpgp; fpr=B894379F662089525B3FB1B9333F1F391BBBB00A Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Dominique Martinet btfs_file_read's truncate path has a comment noting '>0 means no extent' and bailing out immediately, but the buffer has not been written so probably needs zeroing out. This is a theorical fix only and hasn't been tested on a file that actually runs this code path. Signed-off-by: Dominique Martinet --- fs/btrfs/inode.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index efffec0f2e68..23c006c98c3b 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -756,9 +756,12 @@ int btrfs_file_read(struct btrfs_root *root, u64 ino, u64 file_offset, u64 len, btrfs_release_path(&path); ret = lookup_data_extent(root, &path, ino, cur, &next_offset); - /* <0 is error, >0 means no extent */ - if (ret) + /* <0 is error, >0 means no extent: zero end of buffer */ + if (ret) { + if (ret > 0) + memset(dest + cur, 0, end - cur); goto out; + } fi = btrfs_item_ptr(path.nodes[0], path.slots[0], struct btrfs_file_extent_item); ret = read_and_truncate_page(&path, fi, cur,