Commit 42062343 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'erofs-for-5.12-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs

Pull erofs fix from Gao Xiang:
 "Fix an urgent regression introduced by commit baa2c7c9 ("block:
  set .bi_max_vecs as actual allocated vector number"), which could
  cause unexpected hung since linux 5.12-rc1.

  Resolve it by avoiding using bio->bi_max_vecs completely"

* tag 'erofs-for-5.12-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs:
  erofs: fix bio->bi_max_vecs behavior change
parents e83bad7f 9f377622
...@@ -129,6 +129,7 @@ static inline struct bio *erofs_read_raw_page(struct bio *bio, ...@@ -129,6 +129,7 @@ static inline struct bio *erofs_read_raw_page(struct bio *bio,
struct page *page, struct page *page,
erofs_off_t *last_block, erofs_off_t *last_block,
unsigned int nblocks, unsigned int nblocks,
unsigned int *eblks,
bool ra) bool ra)
{ {
struct inode *const inode = mapping->host; struct inode *const inode = mapping->host;
...@@ -145,8 +146,7 @@ static inline struct bio *erofs_read_raw_page(struct bio *bio, ...@@ -145,8 +146,7 @@ static inline struct bio *erofs_read_raw_page(struct bio *bio,
/* note that for readpage case, bio also equals to NULL */ /* note that for readpage case, bio also equals to NULL */
if (bio && if (bio &&
/* not continuous */ (*last_block + 1 != current_block || !*eblks)) {
*last_block + 1 != current_block) {
submit_bio_retry: submit_bio_retry:
submit_bio(bio); submit_bio(bio);
bio = NULL; bio = NULL;
...@@ -216,7 +216,8 @@ static inline struct bio *erofs_read_raw_page(struct bio *bio, ...@@ -216,7 +216,8 @@ static inline struct bio *erofs_read_raw_page(struct bio *bio,
if (nblocks > DIV_ROUND_UP(map.m_plen, PAGE_SIZE)) if (nblocks > DIV_ROUND_UP(map.m_plen, PAGE_SIZE))
nblocks = DIV_ROUND_UP(map.m_plen, PAGE_SIZE); nblocks = DIV_ROUND_UP(map.m_plen, PAGE_SIZE);
bio = bio_alloc(GFP_NOIO, bio_max_segs(nblocks)); *eblks = bio_max_segs(nblocks);
bio = bio_alloc(GFP_NOIO, *eblks);
bio->bi_end_io = erofs_readendio; bio->bi_end_io = erofs_readendio;
bio_set_dev(bio, sb->s_bdev); bio_set_dev(bio, sb->s_bdev);
...@@ -229,16 +230,8 @@ static inline struct bio *erofs_read_raw_page(struct bio *bio, ...@@ -229,16 +230,8 @@ static inline struct bio *erofs_read_raw_page(struct bio *bio,
/* out of the extent or bio is full */ /* out of the extent or bio is full */
if (err < PAGE_SIZE) if (err < PAGE_SIZE)
goto submit_bio_retry; goto submit_bio_retry;
--*eblks;
*last_block = current_block; *last_block = current_block;
/* shift in advance in case of it followed by too many gaps */
if (bio->bi_iter.bi_size >= bio->bi_max_vecs * PAGE_SIZE) {
/* err should reassign to 0 after submitting */
err = 0;
goto submit_bio_out;
}
return bio; return bio;
err_out: err_out:
...@@ -252,7 +245,6 @@ static inline struct bio *erofs_read_raw_page(struct bio *bio, ...@@ -252,7 +245,6 @@ static inline struct bio *erofs_read_raw_page(struct bio *bio,
/* if updated manually, continuous pages has a gap */ /* if updated manually, continuous pages has a gap */
if (bio) if (bio)
submit_bio_out:
submit_bio(bio); submit_bio(bio);
return err ? ERR_PTR(err) : NULL; return err ? ERR_PTR(err) : NULL;
} }
...@@ -264,23 +256,26 @@ static inline struct bio *erofs_read_raw_page(struct bio *bio, ...@@ -264,23 +256,26 @@ static inline struct bio *erofs_read_raw_page(struct bio *bio,
static int erofs_raw_access_readpage(struct file *file, struct page *page) static int erofs_raw_access_readpage(struct file *file, struct page *page)
{ {
erofs_off_t last_block; erofs_off_t last_block;
unsigned int eblks;
struct bio *bio; struct bio *bio;
trace_erofs_readpage(page, true); trace_erofs_readpage(page, true);
bio = erofs_read_raw_page(NULL, page->mapping, bio = erofs_read_raw_page(NULL, page->mapping,
page, &last_block, 1, false); page, &last_block, 1, &eblks, false);
if (IS_ERR(bio)) if (IS_ERR(bio))
return PTR_ERR(bio); return PTR_ERR(bio);
DBG_BUGON(bio); /* since we have only one bio -- must be NULL */ if (bio)
submit_bio(bio);
return 0; return 0;
} }
static void erofs_raw_access_readahead(struct readahead_control *rac) static void erofs_raw_access_readahead(struct readahead_control *rac)
{ {
erofs_off_t last_block; erofs_off_t last_block;
unsigned int eblks;
struct bio *bio = NULL; struct bio *bio = NULL;
struct page *page; struct page *page;
...@@ -291,7 +286,7 @@ static void erofs_raw_access_readahead(struct readahead_control *rac) ...@@ -291,7 +286,7 @@ static void erofs_raw_access_readahead(struct readahead_control *rac)
prefetchw(&page->flags); prefetchw(&page->flags);
bio = erofs_read_raw_page(bio, rac->mapping, page, &last_block, bio = erofs_read_raw_page(bio, rac->mapping, page, &last_block,
readahead_count(rac), true); readahead_count(rac), &eblks, true);
/* all the page errors are ignored when readahead */ /* all the page errors are ignored when readahead */
if (IS_ERR(bio)) { if (IS_ERR(bio)) {
...@@ -305,7 +300,6 @@ static void erofs_raw_access_readahead(struct readahead_control *rac) ...@@ -305,7 +300,6 @@ static void erofs_raw_access_readahead(struct readahead_control *rac)
put_page(page); put_page(page);
} }
/* the rare case (end in gaps) */
if (bio) if (bio)
submit_bio(bio); submit_bio(bio);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment