Skip to content
Commit 8481b97d authored by Gao Xiang's avatar Gao Xiang Committed by Treehugger Robot
Browse files

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: 19235161 ("erofs: support I/O submission for sub-page compressed blocks")
Signed-off-by: default avatarGao Xiang <hsiangkao@linux.alibaba.com>
Reviewed-by: default avatarSandeep Dhavale <dhavale@google.com>
Reviewed-by: default avatarYue Hu <huyue2@coolpad.com>
Link: https://lore.kernel.org/r/20240125120039.3228103-1-hsiangkao@linux.alibaba.com

Bug: 324640522
(cherry picked from commit cc4b2dd9
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: default avatarSandeep Dhavale <dhavale@google.com>
parent 886c9d1f
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment