Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp5855321ybn; Sun, 29 Sep 2019 07:08:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqyHa6c7jd6ACd+cK5l1Qcs8zjWYHwFpp+S/cswlFs37VBODLwPMFGMsF+cq6qjL1lmBzjve X-Received: by 2002:a50:cc43:: with SMTP id n3mr15045484edi.250.1569766122221; Sun, 29 Sep 2019 07:08:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569766122; cv=none; d=google.com; s=arc-20160816; b=v+i45Z/R0LL8D+aSN1k0bS4ja8xrheZndvSObPfSmkt92Q3fcXk0j2EasHs1CmKf9r x/rzHqbbaD72cifWleTcAvsxCopCxQ3akSjdQ+7KvUJ3kJSrgvtgw0SqLhi/rwA0js9h bA7R7R0NcwvYTknioAULCCYOD/yuGs6bWlLOos9ulS87tIIBhQmQP6lhaMpWFp7etKB+ Qa7PrqDny5ZJ8gErIQn7j0gHjD7ILTyYosuHUMbKzwZ2klwGnVHnHEw3z4eOUs2rEQZ5 tRtkZzbtG5cXUei/bxTNoq0UoNBe44J/Vos/LCxdWOYu4LGXwm8n5yaRxYrbOdVfUYbf SKlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LRSMMaB4DkTt+3bV5aaZUUDrK8YBssqbVE0alIDGonY=; b=aS0REbBwiGjwTNidDBBNyYCANiWAafT8I0jW/Tde6voG8MeG2B3fUWUP/av5z71WEM vLsj3kdbPOFpC7ufFRoKCej+iV8IOnSf4sUm8fE9ZA+w1Qsbg6y9AgV8B7TROO0VPWaC bB7o7wBPi5FWVEacCdyYKP/zNYzfVacSvHBVrKVNCk5C/L02nEUK4g4lOCZ4rNdxOlER rK5rKtmCqqAgHj5zamFcnHzo8KSZKPV1PSzb7yU9wuAQSa4RQzHuGNa8yRJyD+zylyvH JO4IhKCEnBsarUgV60yYSUjwlzHar1uFcccgNufAgdzydC3YyyTEbzT1hP0dtZbS1KiC Cxag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OyIUfPJb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e22si5543142ejx.107.2019.09.29.07.08.17; Sun, 29 Sep 2019 07:08:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OyIUfPJb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730096AbfI2OBw (ORCPT + 99 others); Sun, 29 Sep 2019 10:01:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:44194 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729496AbfI2OBv (ORCPT ); Sun, 29 Sep 2019 10:01:51 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0DC192082F; Sun, 29 Sep 2019 14:01:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569765708; bh=/IlfYszVZ1szqZovrcaBcxnJw84xiCvpKaU+6jouhKk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OyIUfPJb/CAgTpaMQRNOZG7T9snjsXfj1NHkO9KBmL6rmm/tDRqYEuoeOTCjZ5GRR JEPTjCazt+4ZRFKctskTJKkMYl29aqTAWg3rduWmxoyBjPAi8jYmTg8IMhBukbINWl vPtVlmpRk4Cy8WBDh2eHmU7mZ8xu6xRwitIVCQZk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Agust=C3=ADn=20DallAlba?= , Vitaly Wool , Vlastimil Babka , Shakeel Butt , Jonathan Adams , Henry Burns , Andrew Morton , Linus Torvalds Subject: [PATCH 5.2 22/45] Revert "mm/z3fold.c: fix race between migration and destruction" Date: Sun, 29 Sep 2019 15:55:50 +0200 Message-Id: <20190929135030.759427274@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190929135024.387033930@linuxfoundation.org> References: <20190929135024.387033930@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vitaly Wool commit 6e73fd25e2c7510b7dfadbaf701f31d4bff9c75b upstream. 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 Signed-off-by: Vitaly Wool Cc: Vlastimil Babka Cc: Vitaly Wool Cc: Shakeel Butt Cc: Jonathan Adams Cc: Henry Burns Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/z3fold.c | 90 ------------------------------------------------------------ 1 file changed, 90 deletions(-) --- a/mm/z3fold.c +++ b/mm/z3fold.c @@ -41,7 +41,6 @@ #include #include #include -#include #include /* @@ -145,8 +144,6 @@ struct z3fold_header { * @release_wq: workqueue for safe page release * @work: work_struct for safe page release * @inode: inode for z3fold pseudo filesystem - * @destroying: bool to stop migration once we start destruction - * @isolated: int to count the number of pages currently in isolation * * This structure is allocated at pool creation time and maintains metadata * pertaining to a particular z3fold pool. @@ -165,11 +162,8 @@ struct z3fold_pool { const struct zpool_ops *zpool_ops; struct workqueue_struct *compact_wq; struct workqueue_struct *release_wq; - struct wait_queue_head isolate_wait; struct work_struct work; struct inode *inode; - bool destroying; - int isolated; }; /* @@ -777,7 +771,6 @@ static struct z3fold_pool *z3fold_create goto out_c; spin_lock_init(&pool->lock); spin_lock_init(&pool->stale_lock); - init_waitqueue_head(&pool->isolate_wait); pool->unbuddied = __alloc_percpu(sizeof(struct list_head)*NCHUNKS, 2); if (!pool->unbuddied) goto out_pool; @@ -817,15 +810,6 @@ out: return NULL; } -static bool pool_isolated_are_drained(struct z3fold_pool *pool) -{ - bool ret; - - spin_lock(&pool->lock); - ret = pool->isolated == 0; - spin_unlock(&pool->lock); - return ret; -} /** * z3fold_destroy_pool() - destroys an existing z3fold pool * @pool: the z3fold pool to be destroyed @@ -835,22 +819,6 @@ static bool pool_isolated_are_drained(st static void z3fold_destroy_pool(struct z3fold_pool *pool) { kmem_cache_destroy(pool->c_handle); - /* - * We set pool-> destroying under lock to ensure that - * z3fold_page_isolate() sees any changes to destroying. This way we - * avoid the need for any memory barriers. - */ - - spin_lock(&pool->lock); - pool->destroying = true; - spin_unlock(&pool->lock); - - /* - * We need to ensure that no pages are being migrated while we destroy - * these workqueues, as migration can queue work on either of the - * workqueues. - */ - wait_event(pool->isolate_wait, !pool_isolated_are_drained(pool)); /* * We need to destroy pool->compact_wq before pool->release_wq, @@ -1341,28 +1309,6 @@ static u64 z3fold_get_pool_size(struct z return atomic64_read(&pool->pages_nr); } -/* - * z3fold_dec_isolated() expects to be called while pool->lock is held. - */ -static void z3fold_dec_isolated(struct z3fold_pool *pool) -{ - assert_spin_locked(&pool->lock); - VM_BUG_ON(pool->isolated <= 0); - pool->isolated--; - - /* - * If we have no more isolated pages, we have to see if - * z3fold_destroy_pool() is waiting for a signal. - */ - if (pool->isolated == 0 && waitqueue_active(&pool->isolate_wait)) - wake_up_all(&pool->isolate_wait); -} - -static void z3fold_inc_isolated(struct z3fold_pool *pool) -{ - pool->isolated++; -} - static bool z3fold_page_isolate(struct page *page, isolate_mode_t mode) { struct z3fold_header *zhdr; @@ -1389,34 +1335,6 @@ static bool z3fold_page_isolate(struct p spin_lock(&pool->lock); if (!list_empty(&page->lru)) list_del(&page->lru); - /* - * We need to check for destruction while holding pool->lock, as - * otherwise destruction could see 0 isolated pages, and - * proceed. - */ - if (unlikely(pool->destroying)) { - spin_unlock(&pool->lock); - /* - * If this page isn't stale, somebody else holds a - * reference to it. Let't drop our refcount so that they - * can call the release logic. - */ - if (unlikely(kref_put(&zhdr->refcount, - release_z3fold_page_locked))) { - /* - * If we get here we have kref problems, so we - * should freak out. - */ - WARN(1, "Z3fold is experiencing kref problems\n"); - z3fold_page_unlock(zhdr); - return false; - } - z3fold_page_unlock(zhdr); - return false; - } - - - z3fold_inc_isolated(pool); spin_unlock(&pool->lock); z3fold_page_unlock(zhdr); return true; @@ -1485,10 +1403,6 @@ static int z3fold_page_migrate(struct ad queue_work_on(new_zhdr->cpu, pool->compact_wq, &new_zhdr->work); - spin_lock(&pool->lock); - z3fold_dec_isolated(pool); - spin_unlock(&pool->lock); - page_mapcount_reset(page); put_page(page); return 0; @@ -1508,14 +1422,10 @@ static void z3fold_page_putback(struct p INIT_LIST_HEAD(&page->lru); if (kref_put(&zhdr->refcount, release_z3fold_page_locked)) { atomic64_dec(&pool->pages_nr); - spin_lock(&pool->lock); - z3fold_dec_isolated(pool); - spin_unlock(&pool->lock); return; } spin_lock(&pool->lock); list_add(&page->lru, &pool->lru); - z3fold_dec_isolated(pool); spin_unlock(&pool->lock); z3fold_page_unlock(zhdr); }