summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVitaly Wool <vitalywool@gmail.com>2019-09-23 18:32:56 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2019-09-24 18:54:06 -0400
commit6e73fd25e2c7510b7dfadbaf701f31d4bff9c75b (patch)
treec30f895dd10313f6deea311db822d18a3d4bb015
parent07bfa4415ab607e459b69bd86aa7e7602ce10b4f (diff)
Revert "mm/z3fold.c: fix race between migration and destruction"
With the original commit applied, z3fold_zpool_destroy() may get blocked on wait_event() for indefinite time. Revert this commit for the time being to get rid of this problem since the issue the original commit addresses is less severe. Link: http://lkml.kernel.org/r/20190910123142.7a9c8d2de4d0acbc0977c602@gmail.com Fixes: d776aaa9895eb6eb77 ("mm/z3fold.c: fix race between migration and destruction") Reported-by: Agustín Dall'Alba <agustin@dallalba.com.ar> Signed-off-by: Vitaly Wool <vitalywool@gmail.com> Cc: Vlastimil Babka <vbabka@suse.cz> Cc: Vitaly Wool <vitalywool@gmail.com> Cc: Shakeel Butt <shakeelb@google.com> Cc: Jonathan Adams <jwadams@google.com> Cc: Henry Burns <henrywolfeburns@gmail.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--mm/z3fold.c90
1 files changed, 0 insertions, 90 deletions
diff --git a/mm/z3fold.c b/mm/z3fold.c
index 75b7962439ff..ed19d98c9dcd 100644
--- a/mm/z3fold.c
+++ b/mm/z3fold.c
@@ -41,7 +41,6 @@
41#include <linux/workqueue.h> 41#include <linux/workqueue.h>
42#include <linux/slab.h> 42#include <linux/slab.h>
43#include <linux/spinlock.h> 43#include <linux/spinlock.h>
44#include <linux/wait.h>
45#include <linux/zpool.h> 44#include <linux/zpool.h>
46#include <linux/magic.h> 45#include <linux/magic.h>
47 46
@@ -146,8 +145,6 @@ struct z3fold_header {
146 * @release_wq: workqueue for safe page release 145 * @release_wq: workqueue for safe page release
147 * @work: work_struct for safe page release 146 * @work: work_struct for safe page release
148 * @inode: inode for z3fold pseudo filesystem 147 * @inode: inode for z3fold pseudo filesystem
149 * @destroying: bool to stop migration once we start destruction
150 * @isolated: int to count the number of pages currently in isolation
151 * 148 *
152 * This structure is allocated at pool creation time and maintains metadata 149 * This structure is allocated at pool creation time and maintains metadata
153 * pertaining to a particular z3fold pool. 150 * pertaining to a particular z3fold pool.
@@ -166,11 +163,8 @@ struct z3fold_pool {
166 const struct zpool_ops *zpool_ops; 163 const struct zpool_ops *zpool_ops;
167 struct workqueue_struct *compact_wq; 164 struct workqueue_struct *compact_wq;
168 struct workqueue_struct *release_wq; 165 struct workqueue_struct *release_wq;
169 struct wait_queue_head isolate_wait;
170 struct work_struct work; 166 struct work_struct work;
171 struct inode *inode; 167 struct inode *inode;
172 bool destroying;
173 int isolated;
174}; 168};
175 169
176/* 170/*
@@ -775,7 +769,6 @@ static struct z3fold_pool *z3fold_create_pool(const char *name, gfp_t gfp,
775 goto out_c; 769 goto out_c;
776 spin_lock_init(&pool->lock); 770 spin_lock_init(&pool->lock);
777 spin_lock_init(&pool->stale_lock); 771 spin_lock_init(&pool->stale_lock);
778 init_waitqueue_head(&pool->isolate_wait);
779 pool->unbuddied = __alloc_percpu(sizeof(struct list_head)*NCHUNKS, 2); 772 pool->unbuddied = __alloc_percpu(sizeof(struct list_head)*NCHUNKS, 2);
780 if (!pool->unbuddied) 773 if (!pool->unbuddied)
781 goto out_pool; 774 goto out_pool;
@@ -815,15 +808,6 @@ out:
815 return NULL; 808 return NULL;
816} 809}
817 810
818static bool pool_isolated_are_drained(struct z3fold_pool *pool)
819{
820 bool ret;
821
822 spin_lock(&pool->lock);
823 ret = pool->isolated == 0;
824 spin_unlock(&pool->lock);
825 return ret;
826}
827/** 811/**
828 * z3fold_destroy_pool() - destroys an existing z3fold pool 812 * z3fold_destroy_pool() - destroys an existing z3fold pool
829 * @pool: the z3fold pool to be destroyed 813 * @pool: the z3fold pool to be destroyed
@@ -833,22 +817,6 @@ static bool pool_isolated_are_drained(struct z3fold_pool *pool)
833static void z3fold_destroy_pool(struct z3fold_pool *pool) 817static void z3fold_destroy_pool(struct z3fold_pool *pool)
834{ 818{
835 kmem_cache_destroy(pool->c_handle); 819 kmem_cache_destroy(pool->c_handle);
836 /*
837 * We set pool-> destroying under lock to ensure that
838 * z3fold_page_isolate() sees any changes to destroying. This way we
839 * avoid the need for any memory barriers.
840 */
841
842 spin_lock(&pool->lock);
843 pool->destroying = true;
844 spin_unlock(&pool->lock);
845
846 /*
847 * We need to ensure that no pages are being migrated while we destroy
848 * these workqueues, as migration can queue work on either of the
849 * workqueues.
850 */
851 wait_event(pool->isolate_wait, !pool_isolated_are_drained(pool));
852 820
853 /* 821 /*
854 * We need to destroy pool->compact_wq before pool->release_wq, 822 * We need to destroy pool->compact_wq before pool->release_wq,
@@ -1339,28 +1307,6 @@ static u64 z3fold_get_pool_size(struct z3fold_pool *pool)
1339 return atomic64_read(&pool->pages_nr); 1307 return atomic64_read(&pool->pages_nr);
1340} 1308}
1341 1309
1342/*
1343 * z3fold_dec_isolated() expects to be called while pool->lock is held.
1344 */
1345static void z3fold_dec_isolated(struct z3fold_pool *pool)
1346{
1347 assert_spin_locked(&pool->lock);
1348 VM_BUG_ON(pool->isolated <= 0);
1349 pool->isolated--;
1350
1351 /*
1352 * If we have no more isolated pages, we have to see if
1353 * z3fold_destroy_pool() is waiting for a signal.
1354 */
1355 if (pool->isolated == 0 && waitqueue_active(&pool->isolate_wait))
1356 wake_up_all(&pool->isolate_wait);
1357}
1358
1359static void z3fold_inc_isolated(struct z3fold_pool *pool)
1360{
1361 pool->isolated++;
1362}
1363
1364static bool z3fold_page_isolate(struct page *page, isolate_mode_t mode) 1310static bool z3fold_page_isolate(struct page *page, isolate_mode_t mode)
1365{ 1311{
1366 struct z3fold_header *zhdr; 1312 struct z3fold_header *zhdr;
@@ -1387,34 +1333,6 @@ static bool z3fold_page_isolate(struct page *page, isolate_mode_t mode)
1387 spin_lock(&pool->lock); 1333 spin_lock(&pool->lock);
1388 if (!list_empty(&page->lru)) 1334 if (!list_empty(&page->lru))
1389 list_del(&page->lru); 1335 list_del(&page->lru);
1390 /*
1391 * We need to check for destruction while holding pool->lock, as
1392 * otherwise destruction could see 0 isolated pages, and
1393 * proceed.
1394 */
1395 if (unlikely(pool->destroying)) {
1396 spin_unlock(&pool->lock);
1397 /*
1398 * If this page isn't stale, somebody else holds a
1399 * reference to it. Let't drop our refcount so that they
1400 * can call the release logic.
1401 */
1402 if (unlikely(kref_put(&zhdr->refcount,
1403 release_z3fold_page_locked))) {
1404 /*
1405 * If we get here we have kref problems, so we
1406 * should freak out.
1407 */
1408 WARN(1, "Z3fold is experiencing kref problems\n");
1409 z3fold_page_unlock(zhdr);
1410 return false;
1411 }
1412 z3fold_page_unlock(zhdr);
1413 return false;
1414 }
1415
1416
1417 z3fold_inc_isolated(pool);
1418 spin_unlock(&pool->lock); 1336 spin_unlock(&pool->lock);
1419 z3fold_page_unlock(zhdr); 1337 z3fold_page_unlock(zhdr);
1420 return true; 1338 return true;
@@ -1483,10 +1401,6 @@ static int z3fold_page_migrate(struct address_space *mapping, struct page *newpa
1483 1401
1484 queue_work_on(new_zhdr->cpu, pool->compact_wq, &new_zhdr->work); 1402 queue_work_on(new_zhdr->cpu, pool->compact_wq, &new_zhdr->work);
1485 1403
1486 spin_lock(&pool->lock);
1487 z3fold_dec_isolated(pool);
1488 spin_unlock(&pool->lock);
1489
1490 page_mapcount_reset(page); 1404 page_mapcount_reset(page);
1491 put_page(page); 1405 put_page(page);
1492 return 0; 1406 return 0;
@@ -1506,14 +1420,10 @@ static void z3fold_page_putback(struct page *page)
1506 INIT_LIST_HEAD(&page->lru); 1420 INIT_LIST_HEAD(&page->lru);
1507 if (kref_put(&zhdr->refcount, release_z3fold_page_locked)) { 1421 if (kref_put(&zhdr->refcount, release_z3fold_page_locked)) {
1508 atomic64_dec(&pool->pages_nr); 1422 atomic64_dec(&pool->pages_nr);
1509 spin_lock(&pool->lock);
1510 z3fold_dec_isolated(pool);
1511 spin_unlock(&pool->lock);
1512 return; 1423 return;
1513 } 1424 }
1514 spin_lock(&pool->lock); 1425 spin_lock(&pool->lock);
1515 list_add(&page->lru, &pool->lru); 1426 list_add(&page->lru, &pool->lru);
1516 z3fold_dec_isolated(pool);
1517 spin_unlock(&pool->lock); 1427 spin_unlock(&pool->lock);
1518 z3fold_page_unlock(zhdr); 1428 z3fold_page_unlock(zhdr);
1519} 1429}