Merge tag 'erofs-for-5.16-rc1-fixes' of git://git.kernel.org/pub/scm/linux/kernel...
authorLinus Torvalds <torvalds@linux-foundation.org>
Sat, 13 Nov 2021 19:27:02 +0000 (11:27 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 13 Nov 2021 19:27:02 +0000 (11:27 -0800)
Pull erofs fixes from Gao Xiang:

 - fix unsafe pagevec reuse which could cause unexpected behaviors

 - get rid of the unused DELAYEDALLOC strategy that has been replaced by
   TRYALLOC

* tag 'erofs-for-5.16-rc1-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs:
  erofs: remove useless cache strategy of DELAYEDALLOC
  erofs: fix unsafe pagevec reuse of hooked pclusters

fs/erofs/zdata.c
fs/erofs/zdata.h
fs/erofs/zpvec.h

index bcb1b91..9a249bf 100644 (file)
@@ -96,16 +96,9 @@ static void z_erofs_free_pcluster(struct z_erofs_pcluster *pcl)
        DBG_BUGON(1);
 }
 
-/*
- * a compressed_pages[] placeholder in order to avoid
- * being filled with file pages for in-place decompression.
- */
-#define PAGE_UNALLOCATED     ((void *)0x5F0E4B1D)
-
 /* how to allocate cached pages for a pcluster */
 enum z_erofs_cache_alloctype {
        DONTALLOC,      /* don't allocate any cached pages */
-       DELAYEDALLOC,   /* delayed allocation (at the time of submitting io) */
        /*
         * try to use cached I/O if page allocation succeeds or fallback
         * to in-place I/O instead to avoid any direct reclaim.
@@ -267,10 +260,6 @@ static void preload_compressed_pages(struct z_erofs_collector *clt,
                        /* I/O is needed, no possible to decompress directly */
                        standalone = false;
                        switch (type) {
-                       case DELAYEDALLOC:
-                               t = tagptr_init(compressed_page_t,
-                                               PAGE_UNALLOCATED);
-                               break;
                        case TRYALLOC:
                                newpage = erofs_allocpage(pagepool, gfp);
                                if (!newpage)
@@ -371,8 +360,8 @@ static bool z_erofs_try_inplace_io(struct z_erofs_collector *clt,
 
 /* callers must be with collection lock held */
 static int z_erofs_attach_page(struct z_erofs_collector *clt,
-                              struct page *page,
-                              enum z_erofs_page_type type)
+                              struct page *page, enum z_erofs_page_type type,
+                              bool pvec_safereuse)
 {
        int ret;
 
@@ -382,9 +371,9 @@ static int z_erofs_attach_page(struct z_erofs_collector *clt,
            z_erofs_try_inplace_io(clt, page))
                return 0;
 
-       ret = z_erofs_pagevec_enqueue(&clt->vector, page, type);
+       ret = z_erofs_pagevec_enqueue(&clt->vector, page, type,
+                                     pvec_safereuse);
        clt->cl->vcnt += (unsigned int)ret;
-
        return ret ? 0 : -EAGAIN;
 }
 
@@ -727,7 +716,8 @@ hitted:
                tight &= (clt->mode >= COLLECT_PRIMARY_FOLLOWED);
 
 retry:
-       err = z_erofs_attach_page(clt, page, page_type);
+       err = z_erofs_attach_page(clt, page, page_type,
+                                 clt->mode >= COLLECT_PRIMARY_FOLLOWED);
        /* should allocate an additional short-lived page for pagevec */
        if (err == -EAGAIN) {
                struct page *const newpage =
@@ -735,7 +725,7 @@ retry:
 
                set_page_private(newpage, Z_EROFS_SHORTLIVED_PAGE);
                err = z_erofs_attach_page(clt, newpage,
-                                         Z_EROFS_PAGE_TYPE_EXCLUSIVE);
+                                         Z_EROFS_PAGE_TYPE_EXCLUSIVE, true);
                if (!err)
                        goto retry;
        }
@@ -1089,15 +1079,6 @@ repeat:
        if (!page)
                goto out_allocpage;
 
-       /*
-        * the cached page has not been allocated and
-        * an placeholder is out there, prepare it now.
-        */
-       if (page == PAGE_UNALLOCATED) {
-               tocache = true;
-               goto out_allocpage;
-       }
-
        /* process the target tagged pointer */
        t = tagptr_init(compressed_page_t, page);
        justfound = tagptr_unfold_tags(t);
index 879df53..4a69515 100644 (file)
@@ -179,4 +179,3 @@ static inline void z_erofs_onlinepage_endio(struct page *page)
 #define Z_EROFS_VMAP_GLOBAL_PAGES      2048
 
 #endif
-
index dfd7fe0..b05464f 100644 (file)
@@ -106,11 +106,18 @@ static inline void z_erofs_pagevec_ctor_init(struct z_erofs_pagevec_ctor *ctor,
 
 static inline bool z_erofs_pagevec_enqueue(struct z_erofs_pagevec_ctor *ctor,
                                           struct page *page,
-                                          enum z_erofs_page_type type)
+                                          enum z_erofs_page_type type,
+                                          bool pvec_safereuse)
 {
-       if (!ctor->next && type)
-               if (ctor->index + 1 == ctor->nr)
+       if (!ctor->next) {
+               /* some pages cannot be reused as pvec safely without I/O */
+               if (type == Z_EROFS_PAGE_TYPE_EXCLUSIVE && !pvec_safereuse)
+                       type = Z_EROFS_VLE_PAGE_TYPE_TAIL_SHARED;
+
+               if (type != Z_EROFS_PAGE_TYPE_EXCLUSIVE &&
+                   ctor->index + 1 == ctor->nr)
                        return false;
+       }
 
        if (ctor->index >= ctor->nr)
                z_erofs_pagevec_ctor_pagedown(ctor, false);