Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp667713ybc; Tue, 19 Nov 2019 07:23:12 -0800 (PST) X-Google-Smtp-Source: APXvYqyR/j+1DOtdNFLXzGr0aEpEk/yTx+4eEvfA8VnmXKs2c84jec9CbGzzZx1KOjWzBMzsiQ+N X-Received: by 2002:a1c:4c15:: with SMTP id z21mr6008506wmf.132.1574176992792; Tue, 19 Nov 2019 07:23:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574176992; cv=none; d=google.com; s=arc-20160816; b=IvgAEbWaVe7U6onKOp03P81g8UUdNpuRVU+OHBXvf/r3zAYl2srXrk/GuwN9475REw PKVOWTyi8RVAAx3kJI3eLeDsFQkEWKgW1PtGyK7qTzjhp2QuYKrAkGi545qu+WF7Jt5I 4rMtAgL261/G5vFMBIVca0BAJ0UEucV9NeJ5nToqFCvz1vH+WOCG8tYSaovpKCykkxhf VUsZtOW73gm1CThbvpytOysZI/EJtxJtVUu6W4915x6j8L2/+yVYERQwJgDTal2JMnix t7LQBmuNs/2u9PKkexZYl8Ms0EIMPoVwlKxOzbHgP7dgfXXljwo5T7MCIbHQFCeuOW9E u+tA== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:from:subject:dkim-signature; bh=wLB89YSfgFbBGVbXR/ZLzoyZwIzs8AJRlNKdafMUlZc=; b=W1L2KpSnMaIeD/Y7d/lU3iJiCS8HSc5hb2MeakN/rkygJ/SDnqG3Pm/LqaAXzg7fe0 uZXfGAY+yBSAfug0B5mWtynJGvAWXu+5zoKI2o/iNzTaFfN8vw9oqhZA1wyHpgEEpBRZ oFtz9MjxjQn9VpzX/ie8qmrZkt9OMWQtOltkhOM4I4RGRjYgoB4TSs6b7BaK/Cbg35Gs 2vwhh8nW0ZO0DyfpKzT5r0hbd1+s01zGuPrZiRYRT2Z6lpU3/lLOhjazlRrKZMJMpqmc ChNt4vTQZyvqIyj07O0FmV6fYuTu5fN5oPjwuoxpYH6ZodBx05fOMLDIxfZ2CCe+iK3h DATg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=JZU5Egl9; 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 v9si17146372edf.36.2019.11.19.07.22.48; Tue, 19 Nov 2019 07:23:12 -0800 (PST) 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-dk.20150623.gappssmtp.com header.s=20150623 header.b=JZU5Egl9; 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 S1727509AbfKSPVE (ORCPT + 99 others); Tue, 19 Nov 2019 10:21:04 -0500 Received: from mail-io1-f65.google.com ([209.85.166.65]:33693 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727790AbfKSPVE (ORCPT ); Tue, 19 Nov 2019 10:21:04 -0500 Received: by mail-io1-f65.google.com with SMTP id j13so404829ioe.0 for ; Tue, 19 Nov 2019 07:21:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=wLB89YSfgFbBGVbXR/ZLzoyZwIzs8AJRlNKdafMUlZc=; b=JZU5Egl9ZoaDwz0bdBgxNinwLYcLz3n+Hn0aSbO/AVFn/aCE1lLwcN1r/3QDejrEwj 6kglXsZ4RySU2HEjz8jO/+dMfP0KzreCJJzgp6h7hlw6u+wxrZj6UwrfdYtdIGDWXGiR OYES5PwFK/+xSi0YVlN3UdH6klun9G6QoHg4Tc+ZnUsv6IMI/4muOABPexjk1oA0ADE5 b3zj+/FHbBkydFhTf4a73F5C1bOOVr937pWuybe9hb0lgDZmy5CuNokkTpHWHs08/nD+ f69g2JR9eA014LrlsmPjz5j30rtzeVJA7qw7ztGe066Nw7m/BfFu8Iv6+9T9ezL/N4tx eaVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=wLB89YSfgFbBGVbXR/ZLzoyZwIzs8AJRlNKdafMUlZc=; b=Dsn9tWXxJtz9pKR/QTvbJEW8P6GethL0wxk/BktROezEExSTVRVGdEgUIriRQHnUw8 9amqwdcG0GVVAuKmMTQc4TOd+Ufzyy+zRcDz/AR0zlq7haaJOkHWl+5uURfVpZXJ8oi4 bh3vQs2fSx3wWC2TB8Y2NNSiNErQTdmc2L6EBpJpINRBs+aoLC6cnNzVHTDduymxPO8w Bo9fuHu/NFNychntxlA+QzmzpQBW8VbD2ZLb8K4XvDb7pncqcDltDlIbA0mXPubUeSMi RPAADfPvw0H0E9HRJ9b/GY4XLWwIOBGMq/dQLvuR/To7BeoOY18aU3+Tj0ZmvANg4PIS ytNg== X-Gm-Message-State: APjAAAX4Rv2NmBDQYCPctKEBenBf3QqWon44ursI1UXndfbshXYMOioM ADRwbY37uiTSyyydhUwZPtFxBw== X-Received: by 2002:a02:70cb:: with SMTP id f194mr19334335jac.126.1574176861577; Tue, 19 Nov 2019 07:21:01 -0800 (PST) Received: from [192.168.1.159] ([65.144.74.34]) by smtp.gmail.com with ESMTPSA id t7sm4262873iog.85.2019.11.19.07.20.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Nov 2019 07:21:00 -0800 (PST) Subject: Re: INFO: task hung in io_wq_destroy From: Jens Axboe To: Eric Biggers Cc: syzbot , andriy.shevchenko@linux.intel.com, davem@davemloft.net, f.fainelli@gmail.com, gregkh@linuxfoundation.org, idosch@mellanox.com, kimbrownkd@gmail.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, petrm@mellanox.com, syzkaller-bugs@googlegroups.com, tglx@linutronix.de, viro@zeniv.linux.org.uk, wanghai26@huawei.com, yuehaibing@huawei.com References: <000000000000f86a4f0595fdb152@google.com> <20191119022330.GC3147@sol.localdomain> Message-ID: <09cdf1d6-4660-9712-e374-4bbb120d6858@kernel.dk> Date: Tue, 19 Nov 2019 08:20:58 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/18/19 9:34 PM, Jens Axboe wrote: > On 11/18/19 8:15 PM, Jens Axboe wrote: >> On 11/18/19 7:23 PM, Eric Biggers wrote: >>> Hi Jens, >>> >>> On Mon, Oct 28, 2019 at 03:00:08PM -0600, Jens Axboe wrote: >>>> This is fixed in my for-next branch for a few days at least, unfortunately >>>> linux-next is still on the old one. Next version should be better. >>> >>> This is still occurring on linux-next. Here's a report on next-20191115 from >>> https://syzkaller.appspot.com/text?tag=CrashReport&x=16fa3d1ce00000 >> >> Hmm, I'll take a look. Looking at the reproducer, it's got a massive >> sleep at the end. I take it this triggers before that time actually >> passes? Because that's around 11.5 days of sleep. >> >> No luck reproducing this so far, I'll try on linux-next. > > I see what it is - if the io-wq is setup and torn down before the > manager thread is started, then we won't create the workers we already > expected. The manager thread will exit without doing anything, but > teardown will wait for the expected workers to exit before being > allowed to proceed. That never happens. > > I've got a patch for this, but I'll test it a bit and send it out > tomorrow. This should fix it - wait until the manager is started and has created the required fixed workers, then check if it failed or not. That closes the gap between startup and teardown, as we have settled things before anyone is allowed to call io_wq_destroy(). diff --git a/fs/io-wq.c b/fs/io-wq.c index 9174007ce107..1f640c489f7c 100644 --- a/fs/io-wq.c +++ b/fs/io-wq.c @@ -33,6 +33,7 @@ enum { enum { IO_WQ_BIT_EXIT = 0, /* wq exiting */ IO_WQ_BIT_CANCEL = 1, /* cancel work on list */ + IO_WQ_BIT_ERROR = 2, /* error on setup */ }; enum { @@ -562,14 +563,14 @@ void io_wq_worker_sleeping(struct task_struct *tsk) spin_unlock_irq(&wqe->lock); } -static void create_io_worker(struct io_wq *wq, struct io_wqe *wqe, int index) +static bool create_io_worker(struct io_wq *wq, struct io_wqe *wqe, int index) { struct io_wqe_acct *acct =&wqe->acct[index]; struct io_worker *worker; worker = kcalloc_node(1, sizeof(*worker), GFP_KERNEL, wqe->node); if (!worker) - return; + return false; refcount_set(&worker->ref, 1); worker->nulls_node.pprev = NULL; @@ -581,7 +582,7 @@ static void create_io_worker(struct io_wq *wq, struct io_wqe *wqe, int index) "io_wqe_worker-%d/%d", index, wqe->node); if (IS_ERR(worker->task)) { kfree(worker); - return; + return false; } spin_lock_irq(&wqe->lock); @@ -599,6 +600,7 @@ static void create_io_worker(struct io_wq *wq, struct io_wqe *wqe, int index) atomic_inc(&wq->user->processes); wake_up_process(worker->task); + return true; } static inline bool io_wqe_need_worker(struct io_wqe *wqe, int index) @@ -606,9 +608,6 @@ static inline bool io_wqe_need_worker(struct io_wqe *wqe, int index) { struct io_wqe_acct *acct = &wqe->acct[index]; - /* always ensure we have one bounded worker */ - if (index == IO_WQ_ACCT_BOUND && !acct->nr_workers) - return true; /* if we have available workers or no work, no need */ if (!hlist_nulls_empty(&wqe->free_list) || !io_wqe_run_queue(wqe)) return false; @@ -621,10 +620,19 @@ static inline bool io_wqe_need_worker(struct io_wqe *wqe, int index) static int io_wq_manager(void *data) { struct io_wq *wq = data; + int i; - while (!kthread_should_stop()) { - int i; + /* create fixed workers */ + for (i = 0; i < wq->nr_wqes; i++) { + if (create_io_worker(wq, wq->wqes[i], IO_WQ_ACCT_BOUND)) + continue; + goto err; + } + refcount_set(&wq->refs, wq->nr_wqes); + complete(&wq->done); + + while (!kthread_should_stop()) { for (i = 0; i < wq->nr_wqes; i++) { struct io_wqe *wqe = wq->wqes[i]; bool fork_worker[2] = { false, false }; @@ -644,6 +652,10 @@ static int io_wq_manager(void *data) schedule_timeout(HZ); } + return 0; +err: + set_bit(IO_WQ_BIT_ERROR, &wq->state); + complete(&wq->done); return 0; } @@ -982,7 +994,6 @@ struct io_wq *io_wq_create(unsigned bounded, struct mm_struct *mm, wq->user = user; i = 0; - refcount_set(&wq->refs, wq->nr_wqes); for_each_online_node(node) { struct io_wqe *wqe; @@ -1020,6 +1031,10 @@ struct io_wq *io_wq_create(unsigned bounded, struct mm_struct *mm, wq->manager = kthread_create(io_wq_manager, wq, "io_wq_manager"); if (!IS_ERR(wq->manager)) { wake_up_process(wq->manager); + wait_for_completion(&wq->done); + if (test_bit(IO_WQ_BIT_ERROR, &wq->state)) + goto err; + reinit_completion(&wq->done); return wq; } @@ -1041,10 +1056,9 @@ void io_wq_destroy(struct io_wq *wq) { int i; - if (wq->manager) { - set_bit(IO_WQ_BIT_EXIT, &wq->state); + set_bit(IO_WQ_BIT_EXIT, &wq->state); + if (wq->manager) kthread_stop(wq->manager); - } rcu_read_lock(); for (i = 0; i < wq->nr_wqes; i++) { -- Jens Axboe