Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp693724ybi; Fri, 26 Jul 2019 17:51:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqyUB+cSS6AYASBXf1jGeCHak+OzLu5ssNhlcsT8x4zc0yWfkNOD7+2a3CJXN/doBK6sofMf X-Received: by 2002:a17:90a:cf0d:: with SMTP id h13mr48866389pju.63.1564188683194; Fri, 26 Jul 2019 17:51:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564188683; cv=none; d=google.com; s=arc-20160816; b=qENXaQbSTFleWYvMhDO7uUmT9MS7CdF7iQcj7Zio4VnpvBJmBpKbSGfrliTt5jsDfA BSsPPGgm7IIORPUsCmA+gdO3xWolMxq71o/FXkV2VHnwUZEPpFenK2/FI0qkGtez7rS+ 29Y4sZ/5n4Dcktiw4jZLvXcyYzQJ71WtFimiQFjv0/F0bi0jQJttukpHI81ASkvdneQC InVQ9lPRyYR+hei1EKBOFiR/k2xZY0QqEPn9McG7N1NCoIG0p/0iShBCk7bXmK/4MI7m H/s1Wg9EYoBQ9MSfWnlNPC9fRODhpx2tXB+8DvMghQq9GCUCxQuUqBeqzKrVxw4bp9v+ 4hhg== 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=m8/4TDGoTP0YJOmmNh1QY5sjP7utSN3T4GKeg0uRKkI=; b=d2v9YdHpb3URmhy7cmztZOgb3iqBZ4XkpSJYGxv7X+OVoBNijy7hnkjirPSBMTWkdZ dfxgvbEcBxecm/W/o4x+n76WEd3EL8qgT9fCqlqHMw+l2WnAEGcIxYp1c288ihFGZhxb zQYGX2ARi8Ya7RMcJPYtltVL2/e5eSg9RCXaf8wRXIfZortlD5pRb/X7fnl0hbdcK1QI Xg6QduT4PUZ/sxliJhrUASlOEXiCt++SOV1Rj7/0DprxqD++qCepncp68PZRDhWxWHlm G1y4dY1SKQgFVZRctEB/ZVl0L16JHp9fXP+wITtFuwU3PSVJjxcuoeBClgYNlwpSrgBr +Lhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=S58mOK6k; 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 30si9487337pgm.346.2019.07.26.17.50.53; Fri, 26 Jul 2019 17:51:23 -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=S58mOK6k; 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 S1727309AbfGZWxa (ORCPT + 99 others); Fri, 26 Jul 2019 18:53:30 -0400 Received: from mail-yw1-f67.google.com ([209.85.161.67]:32784 "EHLO mail-yw1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726086AbfGZWxa (ORCPT ); Fri, 26 Jul 2019 18:53:30 -0400 Received: by mail-yw1-f67.google.com with SMTP id l124so20868318ywd.0 for ; Fri, 26 Jul 2019 15:53:29 -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=m8/4TDGoTP0YJOmmNh1QY5sjP7utSN3T4GKeg0uRKkI=; b=S58mOK6kmyfjaqk1fnTJ++/++kcxrVvJPN9KcacKz65Ijo+9nbPY62HM1CffSp86Gu /dPN5MfoF9x3qzmvRf4i/6AryZbuh86DENdsSJKo1zLveUuyHt3BmI5KngT42emGLpRg LfE5/fDELYjpJFgZ6/3aEWoIOYp7eIVl/VMYJO3P6dhqng+w41uZfFsmu2hMSxMur74E cjujptrMLPPTtmOt4Ya3Uv+rKDOFMywYfHOEFwqVFz7D2oHaFLDQNzYLJ324mImcBbId h3rDRv/vOKwwLN7nnncz9jasy9fPT3hIXPkkvg9QeXHJnJnt2ZVEQ6gEW6zaDfc0rSja EY0Q== 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=m8/4TDGoTP0YJOmmNh1QY5sjP7utSN3T4GKeg0uRKkI=; b=mu/Dr/xDseszRRSSvzuOV4bWp/p1QyGargMAjGaDQsQEhMtSUza/6VkE7y5y2wOnc+ pqnvVf9UTCPcYhJasy6H0TUMqBfKnMPVVf94lQ5RcaLrHypj9EOTaOoba4nHj8MzBhh4 yD0v8p4AzOIBTDpW3jlvdfWQ8GtSjujRu51UN7NA/SqtZa7DlzIRnVg6vYbe83F+FniF 36+QvgwBpqgM5RbgOstIiRKKupd4SmGQOZkaa/k3Hx313NtNHm867SrvyKbijJwTylyl 1WbdctPTQ1X2IIBd8+Kv0HIcOo1QrLqRv8WQI1S2U4TAGAz3qDmkosTphQxOQhGZie0S DfCg== X-Gm-Message-State: APjAAAVIhtfWwIZmWBQ74Vl0S9tMZ4Dh4BsHlGEf+CrPk7iWJ1uLTnUf pfr0fG6lq/MTptmwyapPNtDhTvJU1X3BbeArbHdwDQ== X-Received: by 2002:a81:19c6:: with SMTP id 189mr57026739ywz.296.1564181608700; Fri, 26 Jul 2019 15:53:28 -0700 (PDT) MIME-Version: 1.0 References: <20190726224810.79660-1-henryburns@google.com> In-Reply-To: <20190726224810.79660-1-henryburns@google.com> From: Shakeel Butt Date: Fri, 26 Jul 2019 15:53:17 -0700 Message-ID: Subject: Re: [PATCH] mm/z3fold.c: Fix z3fold_destroy_pool() ordering To: Henry Burns Cc: Vitaly Vul , Andrew Morton , Jonathan Adams , 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: Shakeel Butt > 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 >