android_kernel_samsung_sm8650/fs/erofs
Gao Xiang 8481b97df5 BACKPORT: erofs: fix infinite loop due to a race of filling compressed_bvecs
I encountered a race issue after lengthy (~594647 sec) stress tests on
a 64k-page arm64 VM with several 4k-block EROFS images.  The timing
is like below:

z_erofs_try_inplace_io                  z_erofs_fill_bio_vec
  cmpxchg(&compressed_bvecs[].page,
          NULL, ..)
                                        [access bufvec]
  compressed_bvecs[] = *bvec;

Previously, z_erofs_submit_queue() just accessed bufvec->page only, so
other fields in bufvec didn't matter.  After the subpage block support
is landed, .offset and .end can be used too, but filling bufvec isn't
an atomic operation which can cause inconsistency.

Let's use a spinlock to keep the atomicity of each bufvec.

Fixes: 192351616a9d ("erofs: support I/O submission for sub-page compressed blocks")
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Reviewed-by: Sandeep Dhavale <dhavale@google.com>
Reviewed-by: Yue Hu <huyue2@coolpad.com>
Link: https://lore.kernel.org/r/20240125120039.3228103-1-hsiangkao@linux.alibaba.com

Bug: 324640522
(cherry picked from commit cc4b2dd95f0d1eba8c691b36e8f4d1795582f1ff
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/ master)

[dhavale: introduced spinlock in struct erofs_workgroup, upstream has a
change where atomic is replaced by lockref but pulling that and related
changes will cause unnecessary churn. Adding spinlock keeps the spirit
of the change in-tact by fixing the race. Also updated commit message
as we are not using lockref.]

Change-Id: Id20a0a433277ab71d46bce48c81824564d1b391d
Signed-off-by: Sandeep Dhavale <dhavale@google.com>
2024-02-12 20:56:13 +00:00
..
compress.h UPSTREAM: erofs: fold in z_erofs_decompress() 2024-01-03 18:37:43 +00:00
data.c UPSTREAM: erofs: enable large folios for iomap mode 2024-01-03 18:37:43 +00:00
decompressor_lzma.c This is the 6.1.57 stable release 2023-11-02 07:05:54 +00:00
decompressor.c FROMGIT: erofs: refine z_erofs_transform_plain() for sub-page block support 2024-01-03 18:37:43 +00:00
dir.c BACKPORT: erofs: avoid hardcoded blocksize for subpage block support 2023-10-06 21:48:22 +00:00
erofs_fs.h BACKPORT: erofs: set block size to the on-disk block size 2023-10-06 21:48:22 +00:00
fscache.c BACKPORT: erofs: avoid hardcoded blocksize for subpage block support 2023-10-06 21:48:22 +00:00
inode.c BACKPORT: FROMGIT: erofs: enable sub-page compressed block support 2024-01-03 18:37:43 +00:00
internal.h BACKPORT: erofs: fix infinite loop due to a race of filling compressed_bvecs 2024-02-12 20:56:13 +00:00
Kconfig BACKPORT: erofs: add per-cpu threads for decompression as an option 2023-03-02 01:13:35 +00:00
Makefile erofs: register fscache volume 2022-05-18 00:11:19 +08:00
namei.c BACKPORT: erofs: avoid hardcoded blocksize for subpage block support 2023-10-06 21:48:22 +00:00
pcpubuf.c erofs: get rid of ->lru usage 2021-10-25 08:22:59 +08:00
super.c BACKPORT: erofs: adapt managed inode operations into folios 2024-01-03 18:37:43 +00:00
sysfs.c erofs: fix use-after-free of fsid and domain_id string 2022-11-10 09:53:20 +08:00
utils.c mm: shrinkers: provide shrinkers with names 2022-07-03 18:08:40 -07:00
xattr.c BACKPORT: erofs: avoid hardcoded blocksize for subpage block support 2023-10-06 21:48:22 +00:00
xattr.h BACKPORT: erofs: avoid hardcoded blocksize for subpage block support 2023-10-06 21:48:22 +00:00
zdata.c BACKPORT: erofs: fix infinite loop due to a race of filling compressed_bvecs 2024-02-12 20:56:13 +00:00
zmap.c BACKPORT: FROMGIT: erofs: fix up compacted indexes for block size < 4096 2024-01-03 18:37:43 +00:00