Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp633117ybi; Fri, 26 Jul 2019 16:26:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqyaAV0Pi7lyACc3wK3SfPSzy6SaHBiFhK7d17wQQpIOZYlryKwTJ5iOQmdYbz4c5iHn6Vl2 X-Received: by 2002:a17:90b:95:: with SMTP id bb21mr101615771pjb.8.1564183560690; Fri, 26 Jul 2019 16:26:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564183560; cv=none; d=google.com; s=arc-20160816; b=UqmqHAK897qgnJmXAlOd/c02lJmYBbUNc2Dri3LKIrp6WmK4ZDBEvI/5fSJVU9MGvS 7vd5zsm0xzGxP+DoW3f+wu8YBgsklT/dz0wraiv6WC/Pe/aLNMp2tycSsH0E/tW6k3PW O06u+HIvaBxjcntyyP6ENYPbsb0CHKBOQWkDNqJjW/Z7k/hoLskYBpG5wc5SJUTwqB+a +ax+baik6PYBATUzYEmpGg5OAQdhpc7HbaRlxT5UZhygNjJdAfSpV5b36uSoHpiH3gqH pOn97p2D8RAy+/f6fr5tx3n0obrnMONRFjufz6LY24vtFJpcc4caN6Qf5RWp0UTJRQkp 4+tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=WuNOArHZs/CiCRyKyjlclGYC7Ncl5iJJmT+ESUl6jAA=; b=YN3CCDLD3V+62D7a9L5kmQgB7k4XXihHuI7ma0OvYHufwrX5TYwNHbhZkEsKknIWbX XoC2fb1b4XsSunTsiZdX2CTJzcCQszTSEC5pDkzTeJ7dwSQLkyCSfJGilZwNeAJUrzKU jTeCXJ3TWwVsUL7jopcN77sOs4yJb9PhptzyL1LifWK63Rwemw+FuXAXxyi01A872K5Y tcn4iaM0RLpZcBx9grP5wVsyaM3CkWYnkGQw63XmVNmDEPjrqSOoiV47jzZsjeXpINxv 32+PC3XHvdV/FD9P1nF43BQYeg4UY/pX2ai071+X47nW+6kBil42f9Xssf5PhRGWkF6h dJcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=kEGHfnb+; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 68si21886737pgb.104.2019.07.26.16.25.45; Fri, 26 Jul 2019 16:26:00 -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=@google.com header.s=20161025 header.b=kEGHfnb+; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727572AbfGZXUX (ORCPT + 99 others); Fri, 26 Jul 2019 19:20:23 -0400 Received: from mail-qt1-f194.google.com ([209.85.160.194]:36146 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726216AbfGZXUX (ORCPT ); Fri, 26 Jul 2019 19:20:23 -0400 Received: by mail-qt1-f194.google.com with SMTP id z4so54308197qtc.3 for ; Fri, 26 Jul 2019 16:20:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=WuNOArHZs/CiCRyKyjlclGYC7Ncl5iJJmT+ESUl6jAA=; b=kEGHfnb+ky7mAtpgS94T1BlDhXrjAF9XMpWdm7fL5wWt0lI7aJD3/bimEU3aictx5/ /FVoxvjWSJOsaau/ArFWCvjl3UvCYt0UKuqbV3FAYijG3r3NaxbYAKdIv1U91mIBuOWl kovT+dhR3I24/oGuwK8rnhXVMwHQc2af+OjHNTY8E16Znr5UlJcLtWNs1/2WObenCUL6 0XF23LaWT12L30puEcM9OgpjsfeZcqTR9sQGgi8O0ELN4Rr38CxkxB+JwiB78TG4CrBN 8pld23xKRXm20Xxzwcz/LE4LBTuO3cSd5KZ05jAqnl4jlavcMrtBsfAUmwQu1m8TlvJn qLYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=WuNOArHZs/CiCRyKyjlclGYC7Ncl5iJJmT+ESUl6jAA=; b=JJ9hM3pTKsnc8fu5sAhGALSg1NB+mY+gglgiWIu1JeAUtl8DUjZVFMN5iXmKLmtVyI FtyzI+JIzVYcBz/HdxKCeKd7UQieIeBlYLRaC3uwePtpYKDxM2VxQL4Go1/oMDCj/nZV Q94pQNc4Wbe8ZCdou3tWReT/OPosieuRMbd+GJ1iza1Cq0fpTxQYAwOAu3RnVnJTAKTG kvJp+Fzb1HYFncfNmpCB9PV/FkOQPooBZy9vl6EqFsB4FayOgY00ubpHh/cXsBfzLQCN 2z4MGI/mgcFBE8MCQLNruSWqbJJtfEWHJ8dAzNsUZS7r0lcveFyXl4HbbTgi4EYa9Tgm aayA== X-Gm-Message-State: APjAAAXJDRpHGdtl3Tdn8d9yVx6WSvXRnOK/pU/onCiI3MzJoNFyAoto sTqCIkDe6R91U3AuBKIrSv29NcSeru/VKVpRmmO1 X-Received: by 2002:a0c:b12b:: with SMTP id q40mr71961348qvc.0.1564183221451; Fri, 26 Jul 2019 16:20:21 -0700 (PDT) MIME-Version: 1.0 References: <20190726224810.79660-1-henryburns@google.com> In-Reply-To: <20190726224810.79660-1-henryburns@google.com> From: Jonathan Adams Date: Fri, 26 Jul 2019 16:19:45 -0700 Message-ID: Subject: Re: [PATCH] mm/z3fold.c: Fix z3fold_destroy_pool() ordering To: Henry Burns Cc: Vitaly Vul , Andrew Morton , Shakeel Butt , David Howells , Thomas Gleixner , Al Viro , Linux-MM , LKML , stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 26, 2019 at 3:48 PM Henry Burns wrote: > > The constraint from the zpool use of z3fold_destroy_pool() is there are no > outstanding handles to memory (so no active allocations), but it is possible > for there to be outstanding work on either of the two wqs in the pool. > > If there is work queued on pool->compact_workqueue when it is called, > z3fold_destroy_pool() will do: > > z3fold_destroy_pool() > destroy_workqueue(pool->release_wq) > destroy_workqueue(pool->compact_wq) > drain_workqueue(pool->compact_wq) > do_compact_page(zhdr) > kref_put(&zhdr->refcount) > __release_z3fold_page(zhdr, ...) > queue_work_on(pool->release_wq, &pool->work) *BOOM* > > So compact_wq needs to be destroyed before release_wq. > > Fixes: 5d03a6613957 ("mm/z3fold.c: use kref to prevent page free/compact race") > > Signed-off-by: Henry Burns Reviewed-by: Jonathan Adams > Cc: > --- > mm/z3fold.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/mm/z3fold.c b/mm/z3fold.c > index 1a029a7432ee..43de92f52961 100644 > --- a/mm/z3fold.c > +++ b/mm/z3fold.c > @@ -818,8 +818,15 @@ static void z3fold_destroy_pool(struct z3fold_pool *pool) > { > kmem_cache_destroy(pool->c_handle); > z3fold_unregister_migration(pool); > - destroy_workqueue(pool->release_wq); > + > + /* > + * We need to destroy pool->compact_wq before pool->release_wq, > + * as any pending work on pool->compact_wq will call > + * queue_work(pool->release_wq, &pool->work). > + */ > + > destroy_workqueue(pool->compact_wq); > + destroy_workqueue(pool->release_wq); > kfree(pool); > } > > -- > 2.22.0.709.g102302147b-goog >