Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp633548ybi; Fri, 26 Jul 2019 16:26:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqwL+RXIMRP9bzqOxjNHr7yadCV3hBCgHI6aiWV0ds9gN1mv3DYiG5OTatDDNV6mtkNtDAee X-Received: by 2002:a17:90a:b903:: with SMTP id p3mr98893380pjr.79.1564183601427; Fri, 26 Jul 2019 16:26:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564183601; cv=none; d=google.com; s=arc-20160816; b=FU0rRMKZApwpM7pHOUyp2FaIJRdQhx9DWMslQ3ox8BCcGcLh5kslKBSxm+GWygIj3T qW59iWfmWbE4a+JUdnX9+DBgoxxcj6JzI+VSQOc2LGsV/8l1pZy+qZCGJpAkBYKZhLRB nhK9XhO+CJLuZsdXx7oPcp6cBBhqESnWnNrnFFFZoTSuYgXNPqIurAcQe2o4t5rFB29D j5GmZQUjfzYO/BPI/hRYJaH+Sj/U9MV5ap8pXKK3EuxRj3Hy7Dg++lx9wQdkBIqEJyx/ FiyX0oETroiwwrD7Hu6Oj4eenGL0UGZyjtkH++5jzvN2BO1e5rJNPqTv4oSLpCfr9mcS wMaA== 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=ds6Pn84xnJTs59aQRjsfc8MfNMObGqVIqTNdYf6jDF8=; b=vhsYioWf0hOiJI3WBLxJY6hz5LURzNrza45afHb8EpzCI/AAaTBMxZYHVelf5tsJBX DqeKZm6YBRg7keKaCpEkk6D2nslxciTmwP+WE5ts8/JE9TFSPiEwUgrmcAFR6eLAAo9a Bv3hFckxXBuAVnLUaUX4yh5sTMoCspdIIN3glPstltwozzu0vdWNr+ysOQv/PjQtH0z7 GCiXtmhjnYMtSQDFpRqKJbUadKEm+90gXUWCMEjqtujJ7Rur9CpUuv0TQMQnRehFboO2 evR4AQfrjEFT7X9e5aNOyL4Dg98MtJs6np2ibQ+3IOyi48Le5S+F9q/PEalBHq+ZcGYV 8zdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=pmprGLF2; 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 s17si19994261pfc.237.2019.07.26.16.26.26; Fri, 26 Jul 2019 16:26:41 -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=pmprGLF2; 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 S1728154AbfGZXVK (ORCPT + 99 others); Fri, 26 Jul 2019 19:21:10 -0400 Received: from mail-qk1-f196.google.com ([209.85.222.196]:43600 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727278AbfGZXVK (ORCPT ); Fri, 26 Jul 2019 19:21:10 -0400 Received: by mail-qk1-f196.google.com with SMTP id m14so14616657qka.10 for ; Fri, 26 Jul 2019 16:21:09 -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=ds6Pn84xnJTs59aQRjsfc8MfNMObGqVIqTNdYf6jDF8=; b=pmprGLF2LW0+Sp8wpilnKxyQ9fpy3RtVaI/uwKChRR6jU8kYntVB/SBwjs2iJ/Ef8t AgoaxKSIaFJe7S7BnUBMzaU5bXb26v3v8TOCHBgGl7orVWxAEikEx7zs9FYVRZ2Kuhq4 LSTUWhQCKjMaQS5eEZ+BcJitwk4cPKvlrXSZDX1iHbS8B0nL0AA6pOZy4QXcTcQMysE5 AythhYvQwGo01Exhcg+nMLtnS5XdBJBKrjciS0HpJOZvZWTfMOeSAbBRtlq3DFoVJ+4G xBuI0RwArlsSejlPmK0YyqwlQDzixITgfEA6xxl4awy3u7kqIvjgYTSSMEYLmZZ99w5Y y/EA== 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=ds6Pn84xnJTs59aQRjsfc8MfNMObGqVIqTNdYf6jDF8=; b=GJLtpmIqKPKqXf8yiU6g5bEzUfUZ4q7HA1AB7P9RdOzbg7ZlMNe+a4DncyvVfO4cSo FEeE7Glxkdj7IKavPaQQuRpRewDMPG3+pexVR6rTJUTq6xDZz1U5sxGLdoghUjv71X8V p8vomGDOyXZjsl3wCNJT0g9o9lt0biz1oG8jBrlYvppWJiQspSO60LvJkDcNUblfeqkz osGhDQHYDKTL9ShW7vBJOrnimBsr1g4D25F+Hvpp7LNrDh2a2fXf/5dbcgPoJMLb/+lA ff64sPu2+v7SZcx5c2SQ1GzRzsRp2/diu1tAB3MkpEqUXxv5TqOI9N7dhCS+YeuWlhHs OQQg== X-Gm-Message-State: APjAAAWrAmXyiQsUKtC1oc/RK3acLF+ih2d7RRaSLGqFLdjfxuhelMio xKsBx26rQv2N8JsirkxGWityxdlBwz4l4GRAG/Io X-Received: by 2002:a37:9ac9:: with SMTP id c192mr65323076qke.30.1564183268223; Fri, 26 Jul 2019 16:21:08 -0700 (PDT) MIME-Version: 1.0 References: <20190726224810.79660-1-henryburns@google.com> <20190726224810.79660-2-henryburns@google.com> In-Reply-To: <20190726224810.79660-2-henryburns@google.com> From: Jonathan Adams Date: Fri, 26 Jul 2019 16:20:32 -0700 Message-ID: Subject: Re: [PATCH] mm/z3fold.c: Fix z3fold_destroy_pool() race condition 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. > > Calling z3fold_deregister_migration() before the workqueues are drained > means that there can be allocated pages referencing a freed inode, > causing any thread in compaction to be able to trip over the bad > pointer in PageMovable(). > > Fixes: 1f862989b04a ("mm/z3fold.c: support page migration") > > Signed-off-by: Henry Burns Reviewed-by: Jonathan Adams > Cc: > --- > mm/z3fold.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/mm/z3fold.c b/mm/z3fold.c > index 43de92f52961..ed19d98c9dcd 100644 > --- a/mm/z3fold.c > +++ b/mm/z3fold.c > @@ -817,16 +817,19 @@ static struct z3fold_pool *z3fold_create_pool(const char *name, gfp_t gfp, > static void z3fold_destroy_pool(struct z3fold_pool *pool) > { > kmem_cache_destroy(pool->c_handle); > - z3fold_unregister_migration(pool); > > /* > * 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). > + * > + * There are still outstanding pages until both workqueues are drained, > + * so we cannot unregister migration until then. > */ > > destroy_workqueue(pool->compact_wq); > destroy_workqueue(pool->release_wq); > + z3fold_unregister_migration(pool); > kfree(pool); > } > > -- > 2.22.0.709.g102302147b-goog >