<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/fs/erofs/zdata.c, branch linux-6.5.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-6.5.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-6.5.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2023-11-20T10:57:11Z</updated>
<entry>
<title>erofs: fix erofs_insert_workgroup() lockref usage</title>
<updated>2023-11-20T10:57:11Z</updated>
<author>
<name>Gao Xiang</name>
</author>
<published>2023-10-31T06:05:24Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=531a6b22b5afd4af0244a5cc735998e73135fc46'/>
<id>urn:sha1:531a6b22b5afd4af0244a5cc735998e73135fc46</id>
<content type='text'>
[ Upstream commit 1a0ac8bd7a4fa5b2f4ef14c3b1e9d6e5a5faae06 ]

As Linus pointed out [1], lockref_put_return() is fundamentally
designed to be something that can fail.  It behaves as a fastpath-only
thing, and the failure case needs to be handled anyway.

Actually, since the new pcluster was just allocated without being
populated, it won't be accessed by others until it is inserted into
XArray, so lockref helpers are actually unneeded here.

Let's just set the proper reference count on initializing.

[1] https://lore.kernel.org/r/CAHk-=whCga8BeQnJ3ZBh_Hfm9ctba_wpF444LpwRybVNMzO6Dw@mail.gmail.com

Fixes: 7674a42f35ea ("erofs: use struct lockref to replace handcrafted approach")
Reviewed-by: Chao Yu &lt;chao@kernel.org&gt;
Link: https://lore.kernel.org/r/20231031060524.1103921-1-hsiangkao@linux.alibaba.com
Signed-off-by: Gao Xiang &lt;hsiangkao@linux.alibaba.com&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>erofs: release ztailpacking pclusters properly</title>
<updated>2023-09-13T07:52:58Z</updated>
<author>
<name>Jingbo Xu</name>
</author>
<published>2023-08-22T11:05:30Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=9f9e7fea0ff2ad237ceda88597d2a5936d67c4f0'/>
<id>urn:sha1:9f9e7fea0ff2ad237ceda88597d2a5936d67c4f0</id>
<content type='text'>
[ Upstream commit 91b1ad0815fbb1095c8b9e8a2bf4201186afe304 ]

Currently ztailpacking pclusters are chained with FOLLOWED_NOINPLACE and
not recorded into the managed_pslots XArray.

After commit 7674a42f35ea ("erofs: use struct lockref to replace
handcrafted approach"), ztailpacking pclusters won't be freed with
erofs_workgroup_put() anymore, which will cause the following issue:

BUG erofs_pcluster-1 (Tainted: G           OE     ): Objects remaining in erofs_pcluster-1 on __kmem_cache_shutdown()

Use z_erofs_free_pcluster() directly to free ztailpacking pclusters.

Fixes: 7674a42f35ea ("erofs: use struct lockref to replace handcrafted approach")
Signed-off-by: Jingbo Xu &lt;jefflexu@linux.alibaba.com&gt;
Reviewed-by: Gao Xiang &lt;hsiangkao@linux.alibaba.com&gt;
Reviewed-by: Chao Yu &lt;chao@kernel.org&gt;
Link: https://lore.kernel.org/r/20230822110530.96831-1-jefflexu@linux.alibaba.com
Signed-off-by: Gao Xiang &lt;hsiangkao@linux.alibaba.com&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>erofs: ensure that the post-EOF tails are all zeroed</title>
<updated>2023-09-06T20:22:21Z</updated>
<author>
<name>Gao Xiang</name>
</author>
<published>2023-08-31T11:29:58Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=85dd7f7e68c427129ab1e6eb7a5dfc633f7663ad'/>
<id>urn:sha1:85dd7f7e68c427129ab1e6eb7a5dfc633f7663ad</id>
<content type='text'>
commit e4c1cf523d820730a86cae2c6d55924833b6f7ac upstream.

This was accidentally fixed up in commit e4c1cf523d82 but we can't
take the full change due to other dependancy issues, so here is just
the actual bugfix that is needed.

[Background]

keltargw reported an issue [1] that with mmaped I/Os, sometimes the
tail of the last page (after file ends) is not filled with zeroes.

The root cause is that such tail page could be wrongly selected for
inplace I/Os so the zeroed part will then be filled with compressed
data instead of zeroes.

A simple fix is to avoid doing inplace I/Os for such tail parts,
actually that was already fixed upstream in commit e4c1cf523d82
("erofs: tidy up z_erofs_do_read_page()") by accident.

[1] https://lore.kernel.org/r/3ad8b469-25db-a297-21f9-75db2d6ad224@linux.alibaba.com

Reported-by: keltargw &lt;keltar.gw@gmail.com&gt;
Fixes: 3883a79abd02 ("staging: erofs: introduce VLE decompression support")
Signed-off-by: Gao Xiang &lt;hsiangkao@linux.alibaba.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>erofs: fix wrong primary bvec selection on deduplicated extents</title>
<updated>2023-08-01T08:12:17Z</updated>
<author>
<name>Gao Xiang</name>
</author>
<published>2023-07-19T06:54:59Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=94c43de73521d8ed7ebcfc6191d9dace1cbf7caa'/>
<id>urn:sha1:94c43de73521d8ed7ebcfc6191d9dace1cbf7caa</id>
<content type='text'>
When handling deduplicated compressed data, there can be multiple
decompressed extents pointing to the same compressed data in one shot.

In such cases, the bvecs which belong to the longest extent will be
selected as the primary bvecs for real decompressors to decode and the
other duplicated bvecs will be directly copied from the primary bvecs.

Previously, only relative offsets of the longest extent were checked to
decompress the primary bvecs.  On rare occasions, it can be incorrect
if there are several extents with the same start relative offset.
As a result, some short bvecs could be selected for decompression and
then cause data corruption.

For example, as Shijie Sun reported off-list, considering the following
extents of a file:
 117:   903345..  915250 |   11905 :     385024..    389120 |    4096
...
 119:   919729..  930323 |   10594 :     385024..    389120 |    4096
...
 124:   968881..  980786 |   11905 :     385024..    389120 |    4096

The start relative offset is the same: 2225, but extent 119 (919729..
930323) is shorter than the others.

Let's restrict the bvec length in addition to the start offset if bvecs
are not full.

Reported-by: Shijie Sun &lt;sunshijie@xiaomi.com&gt;
Fixes: 5c2a64252c5d ("erofs: introduce partial-referenced pclusters")
Tested-by Shijie Sun &lt;sunshijie@xiaomi.com&gt;
Reviewed-by: Yue Hu &lt;huyue2@coolpad.com&gt;
Reviewed-by: Chao Yu &lt;chao@kernel.org&gt;
Signed-off-by: Gao Xiang &lt;hsiangkao@linux.alibaba.com&gt;
Link: https://lore.kernel.org/r/20230719065459.60083-1-hsiangkao@linux.alibaba.com
</content>
</entry>
<entry>
<title>erofs: avoid infinite loop in z_erofs_do_read_page() when reading beyond EOF</title>
<updated>2023-07-11T16:50:43Z</updated>
<author>
<name>Chunhai Guo</name>
</author>
<published>2023-07-10T09:34:10Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=8191213a5835b0317c5e4d0d337ae1ae00c75253'/>
<id>urn:sha1:8191213a5835b0317c5e4d0d337ae1ae00c75253</id>
<content type='text'>
z_erofs_do_read_page() may loop infinitely due to the inappropriate
truncation in the below statement. Since the offset is 64 bits and min_t()
truncates the result to 32 bits. The solution is to replace unsigned int
with a 64-bit type, such as erofs_off_t.
    cur = end - min_t(unsigned int, offset + end - map-&gt;m_la, end);

    - For example:
        - offset = 0x400160000
        - end = 0x370
        - map-&gt;m_la = 0x160370
        - offset + end - map-&gt;m_la = 0x400000000
        - offset + end - map-&gt;m_la = 0x00000000 (truncated as unsigned int)
    - Expected result:
        - cur = 0
    - Actual result:
        - cur = 0x370

Signed-off-by: Chunhai Guo &lt;guochunhai@vivo.com&gt;
Fixes: 3883a79abd02 ("staging: erofs: introduce VLE decompression support")
Reviewed-by: Gao Xiang &lt;hsiangkao@linux.alibaba.com&gt;
Reviewed-by: Chao Yu &lt;chao@kernel.org&gt;
Link: https://lore.kernel.org/r/20230710093410.44071-1-guochunhai@vivo.com
Signed-off-by: Gao Xiang &lt;hsiangkao@linux.alibaba.com&gt;
</content>
</entry>
<entry>
<title>erofs: avoid useless loops in z_erofs_pcluster_readmore() when reading beyond EOF</title>
<updated>2023-07-11T16:50:33Z</updated>
<author>
<name>Chunhai Guo</name>
</author>
<published>2023-07-10T04:25:31Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=936aa701d82d397c2d1afcd18ce2c739471d978d'/>
<id>urn:sha1:936aa701d82d397c2d1afcd18ce2c739471d978d</id>
<content type='text'>
z_erofs_pcluster_readmore() may take a long time to loop when the page
offset is large enough, which is unnecessary should be prevented.

For example, when the following case is encountered, it will loop 4691368
times, taking about 27 seconds:
    - offset = 19217289215
    - inode_size = 1442672

Signed-off-by: Chunhai Guo &lt;guochunhai@vivo.com&gt;
Fixes: 386292919c25 ("erofs: introduce readmore decompression strategy")
Reviewed-by: Gao Xiang &lt;hsiangkao@linux.alibaba.com&gt;
Reviewed-by: Yue Hu &lt;huyue2@coolpad.com&gt;
Reviewed-by: Chao Yu &lt;chao@kernel.org&gt;
Link: https://lore.kernel.org/r/20230710042531.28761-1-guochunhai@vivo.com
Signed-off-by: Gao Xiang &lt;hsiangkao@linux.alibaba.com&gt;
</content>
</entry>
<entry>
<title>erofs: Fix detection of atomic context</title>
<updated>2023-06-22T13:16:02Z</updated>
<author>
<name>Sandeep Dhavale</name>
</author>
<published>2023-06-21T22:08:47Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=12d0a24afd9ea58e581ea64d64e066f2027b28d9'/>
<id>urn:sha1:12d0a24afd9ea58e581ea64d64e066f2027b28d9</id>
<content type='text'>
Current check for atomic context is not sufficient as
z_erofs_decompressqueue_endio can be called under rcu lock
from blk_mq_flush_plug_list(). See the stacktrace [1]

In such case we should hand off the decompression work for async
processing rather than trying to do sync decompression in current
context. Patch fixes the detection by checking for
rcu_read_lock_any_held() and while at it use more appropriate
!in_task() check than in_atomic().

Background: Historically erofs would always schedule a kworker for
decompression which would incur the scheduling cost regardless of
the context. But z_erofs_decompressqueue_endio() may not always
be in atomic context and we could actually benefit from doing the
decompression in z_erofs_decompressqueue_endio() if we are in
thread context, for example when running with dm-verity.
This optimization was later added in patch [2] which has shown
improvement in performance benchmarks.

==============================================
[1] Problem stacktrace
[name:core&amp;]BUG: sleeping function called from invalid context at kernel/locking/mutex.c:291
[name:core&amp;]in_atomic(): 0, irqs_disabled(): 0, non_block: 0, pid: 1615, name: CpuMonitorServi
[name:core&amp;]preempt_count: 0, expected: 0
[name:core&amp;]RCU nest depth: 1, expected: 0
CPU: 7 PID: 1615 Comm: CpuMonitorServi Tainted: G S      W  OE      6.1.25-android14-5-maybe-dirty-mainline #1
Hardware name: MT6897 (DT)
Call trace:
 dump_backtrace+0x108/0x15c
 show_stack+0x20/0x30
 dump_stack_lvl+0x6c/0x8c
 dump_stack+0x20/0x48
 __might_resched+0x1fc/0x308
 __might_sleep+0x50/0x88
 mutex_lock+0x2c/0x110
 z_erofs_decompress_queue+0x11c/0xc10
 z_erofs_decompress_kickoff+0x110/0x1a4
 z_erofs_decompressqueue_endio+0x154/0x180
 bio_endio+0x1b0/0x1d8
 __dm_io_complete+0x22c/0x280
 clone_endio+0xe4/0x280
 bio_endio+0x1b0/0x1d8
 blk_update_request+0x138/0x3a4
 blk_mq_plug_issue_direct+0xd4/0x19c
 blk_mq_flush_plug_list+0x2b0/0x354
 __blk_flush_plug+0x110/0x160
 blk_finish_plug+0x30/0x4c
 read_pages+0x2fc/0x370
 page_cache_ra_unbounded+0xa4/0x23c
 page_cache_ra_order+0x290/0x320
 do_sync_mmap_readahead+0x108/0x2c0
 filemap_fault+0x19c/0x52c
 __do_fault+0xc4/0x114
 handle_mm_fault+0x5b4/0x1168
 do_page_fault+0x338/0x4b4
 do_translation_fault+0x40/0x60
 do_mem_abort+0x60/0xc8
 el0_da+0x4c/0xe0
 el0t_64_sync_handler+0xd4/0xfc
 el0t_64_sync+0x1a0/0x1a4

[2] Link: https://lore.kernel.org/all/20210317035448.13921-1-huangjianan@oppo.com/

Reported-by: Will Shiu &lt;Will.Shiu@mediatek.com&gt;
Suggested-by: Gao Xiang &lt;xiang@kernel.org&gt;
Signed-off-by: Sandeep Dhavale &lt;dhavale@google.com&gt;
Reviewed-by: Gao Xiang &lt;hsiangkao@linux.alibaba.com&gt;
Reviewed-by: Alexandre Mergnat &lt;amergnat@baylibre.com&gt;
Link: https://lore.kernel.org/r/20230621220848.3379029-1-dhavale@google.com
Signed-off-by: Gao Xiang &lt;hsiangkao@linux.alibaba.com&gt;
</content>
</entry>
<entry>
<title>erofs: use poison pointer to replace the hard-coded address</title>
<updated>2023-06-18T04:10:53Z</updated>
<author>
<name>Gao Xiang</name>
</author>
<published>2023-05-26T20:14:59Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=43d86ec93630396b622acf3f9cb88f734d4098e8'/>
<id>urn:sha1:43d86ec93630396b622acf3f9cb88f734d4098e8</id>
<content type='text'>
It's safer and cleaner to replace such hard-coded illegal pointer
with poison pointers.

Signed-off-by: Gao Xiang &lt;hsiangkao@linux.alibaba.com&gt;
Reviewed-by: Yue Hu &lt;huyue2@coolpad.com&gt;
Link: https://lore.kernel.org/r/20230526201459.128169-7-hsiangkao@linux.alibaba.com
</content>
</entry>
<entry>
<title>erofs: use struct lockref to replace handcrafted approach</title>
<updated>2023-06-18T04:10:47Z</updated>
<author>
<name>Gao Xiang</name>
</author>
<published>2023-05-29T12:37:27Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=7674a42f35ea302b97ff3659f2e6f28be23ac9b9'/>
<id>urn:sha1:7674a42f35ea302b97ff3659f2e6f28be23ac9b9</id>
<content type='text'>
Let's avoid the current handcrafted lockref although `struct lockref`
inclusion usually increases extra 4 bytes with an explicit spinlock if
CONFIG_DEBUG_SPINLOCK is off.

Apart from the size difference, note that the meaning of refcount is
also changed to active users. IOWs, it doesn't take an extra refcount
for XArray tree insertion.

I don't observe any significant performance difference at least on
our cloud compute server but the new one indeed simplifies the
overall codebase a bit.

Signed-off-by: Gao Xiang &lt;hsiangkao@linux.alibaba.com&gt;
Reviewed-by: Yue Hu &lt;huyue2@coolpad.com&gt;
Link: https://lore.kernel.org/r/20230529123727.79943-1-hsiangkao@linux.alibaba.com
</content>
</entry>
<entry>
<title>erofs: adapt managed inode operations into folios</title>
<updated>2023-05-29T15:06:03Z</updated>
<author>
<name>Gao Xiang</name>
</author>
<published>2023-05-26T20:14:57Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=7b4e372c36fcd33c74ba3cbd65fa534b9c558184'/>
<id>urn:sha1:7b4e372c36fcd33c74ba3cbd65fa534b9c558184</id>
<content type='text'>
This patch gets rid of erofs_try_to_free_cached_page() and fold it
into .release_folio().

It also moves managed inode operations into zdata.c, which simplifies
the code a bit.  No logic changes.

Signed-off-by: Gao Xiang &lt;hsiangkao@linux.alibaba.com&gt;
Reviewed-by: Yue Hu &lt;huyue2@coolpad.com&gt;
Link: https://lore.kernel.org/r/20230526201459.128169-5-hsiangkao@linux.alibaba.com
</content>
</entry>
</feed>
