Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp629966ybi; Fri, 26 Jul 2019 16:21:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqzk4zHRtwtxcYe8bVAnXzcAVxwGPWdDD3wbYH6AG4JIa04nn95zieH6oNVhCMPtrL9JgluN X-Received: by 2002:a63:3203:: with SMTP id y3mr94765479pgy.191.1564183294296; Fri, 26 Jul 2019 16:21:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564183294; cv=none; d=google.com; s=arc-20160816; b=L1Zj14yibnCoHY/RYZuAzw+eTHmHT4GAOSegZk/CnYH3dGSjgkIoND8ekm08fRpCoM sF4zFN7+Mf6oOKTVUEczbKtsZDYk7VOuyGQFLkz/kFjP/vA0dn4xG9c2OcAKcRXIfrh3 7sBv/c08d+sJs8VB5f4hUZ4dGk9gw41YNh7oYq4lDRZSCvmvVCmNx4Av2aGAne83Wq31 HbWB6XYCSv8q6Ojdh8Nj4MCyfR1t63loGj3YEHwmYGARNUOT/xx8YhK/ohZTJQO3rXNg Vgan6xsyseFHfvCd6Svtn/At8pPYu1Vigu5cy7YvJ7xqBh2hdkoGjTNcHInmX6GfS97L g30Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature; bh=ugYwzqnv6FobgASB/IV2QGrorIeaEWGKXnYtHi2Zf0I=; b=NCSsPuC/Tqn5aIoPztVU9ZP1KxDq5c7psDTxs5YG+y6Amh90lUbSE/tQdcMyC8wALD yhZ5EFsg60+EPvMRaWIhzp/5oya4GteA8U47zX98EocrvEFP9pws/kGgyhFb9JQZ8awI jBw2nNBXKuk2AtQqwiBGgZZSU0MMQjE+dt+vd1WJ3MSGnFm71YBaQKmn+sFE+ynax5sI YcC4maAvzei+BqUW2RCwOVtiU9GnCDVuG03H999IRy8Ce5nW9Vg68w6CmglDqmsn3x9P y4yjpLxqwYYokRTdBObnlFlkIzjQhTAHHy1kAoYXpq5RmHUSn0TnIZGjYso9FSlX55jX FY8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=t93ANIwe; 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 f17si24908714pgh.552.2019.07.26.16.21.19; Fri, 26 Jul 2019 16:21:34 -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=t93ANIwe; 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 S1727607AbfGZWsR (ORCPT + 99 others); Fri, 26 Jul 2019 18:48:17 -0400 Received: from mail-vs1-f73.google.com ([209.85.217.73]:51151 "EHLO mail-vs1-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726339AbfGZWsQ (ORCPT ); Fri, 26 Jul 2019 18:48:16 -0400 Received: by mail-vs1-f73.google.com with SMTP id u17so14551907vsq.17 for ; Fri, 26 Jul 2019 15:48:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=ugYwzqnv6FobgASB/IV2QGrorIeaEWGKXnYtHi2Zf0I=; b=t93ANIwehynL05QpzsPZQsNzsYxLbN+DEc+mU/gC8S3QoOdwTg6FWn2YHKT6g/JEBV +plV+4WjbYjE9Iw7uZ1VG0BDJ+16Y9xWYd9v1LIt6vDngPyZg0/hmMjTS2I9YEl9jicA 31jSLX5XQ9oBkwYmBtzOxenRKIsCwx4PNL90gPuNXhPk5XJ3rUEY55ZCDSl1dislK+H0 g6Wfn1ehtdFKdIlTR020Dp7vd8oiLIwlhadCFIXKZS3z+9hQC3ZJf+K+w2i2gEvpCJ31 DBHOPYqz9sCbWxdhFNbi+HS5+FiuDxaZBwOgrnmhPGa7Xuj/2HX8s72wsXj3lo0fpkwD hnag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=ugYwzqnv6FobgASB/IV2QGrorIeaEWGKXnYtHi2Zf0I=; b=iDVWuiNuHyVZ2eR8pj5MCv1rrFOXroRswe3HFXMi3GKb1lEYP/ACAXaTw5Q3JeVfQg L3q9mjdLDAqNt6Sqxyb09B1kVAGklpYTDpYstupWb0Vm7LBAgYiv7rOowXXgcinloEY6 wmv4ddNoOj3PNTrcAjp/vuMEH8gxXBmnhh/lLeeUqHOaywYMdLVQGjoQ4pPQefWR4gdH +FG8L/FXkLbvSmPRTT+FGYfPGkTOxCIyfVRQDB5h6wRApvO0fBSkFlkqy+5wGDTHeik1 w7Q7VZuDUm7EwVvfMj7XgVDtLQGpeHBq0uPcFirvU9+tOuIMecsHmT8XQQCyYrsN6HL0 dGYw== X-Gm-Message-State: APjAAAXWoPBRrvJf7jv/nn+vVPdpYo496gsXmyCCGw49pMVTlpiY4Kq4 Kck3PVBp1J3wnnWLZXOipUD59bhnVQStpkMs X-Received: by 2002:a1f:6e8e:: with SMTP id j136mr2583640vkc.80.1564181295126; Fri, 26 Jul 2019 15:48:15 -0700 (PDT) Date: Fri, 26 Jul 2019 15:48:09 -0700 Message-Id: <20190726224810.79660-1-henryburns@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.22.0.709.g102302147b-goog Subject: [PATCH] mm/z3fold.c: Fix z3fold_destroy_pool() ordering From: Henry Burns To: Vitaly Vul Cc: Andrew Morton , Shakeel Butt , Jonathan Adams , David Howells , Thomas Gleixner , Al Viro , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Henry Burns , 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 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 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