Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp3837213ybh; Tue, 6 Aug 2019 02:13:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqwwoIQzHYQAfusGm6/oXcHS4wnylsmXIGtzELWp7RYviU73JAg2YEzJ8RDaDkt6jg6duVTx X-Received: by 2002:aa7:86cc:: with SMTP id h12mr2712198pfo.2.1565082818734; Tue, 06 Aug 2019 02:13:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565082818; cv=none; d=google.com; s=arc-20160816; b=fk/cyup44YdNE4sISazAnXUzgWmApQ/vFFj8uxPfNn+hX2r50sDgjPCWaZwzPFLbzn zx12ekTrHzzD7Oaa+hx0NbovsvW4cY+5M0aK2TFygq05Wz09pmqp8BFAvQTEtzJCIl0T bOtGUZRrALyvR1wayQrDcrx6UdkzRUlEFZUN/acJdMwK29GtDn7KrlLoGNliw6mI3KDE L6Fhp/iTw2UFl5V4/MVeUsiLiq53adGhZyZ3ey14/rWHYqb2Y+dLpXLwwUumjOsfz5bN X4rP2GtbKgwvE1DQ8KN3EUFohnrhoQT6u8TSDUp9YSwajZ76h0uiUE5oG87vaSHBc3k6 Qx4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=DCLv3sMLBM925x8RSSNrHS4fEWxpwWMaXUx5IHkTnME=; b=Kpi5rXEFER+xFY4b5sKwOYlVzap+wI4sFzYu3IvKr9XrcoCF5ow2v0SBIGEs0em570 Gng5QYnBE6Gp1yLuZEiPufMLVoxoZwJ0XN2nxOGS0CxDNWnNdWDBdJ5VoG174iP1oqIa ElBeFFjcyuNT5lYHAamnNbCAdiube1pee1+ma6Hlm3Ubf3AOnTJkTFQNYna1f+V2rPDF LXkwzRu+ujo0LpYKgpVIttebxgka1fhIzr1TL2VvSjr8M1G2XQhW9TXDma67gl/QPKOy zvUbEgWAoQBaV9ynTOsW6v8aBMZ/HvgPbXXkUQjja3fBZc90/DQdi93COqfeWQRmAmX9 WusA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o75si14635326pje.87.2019.08.06.02.13.23; Tue, 06 Aug 2019 02:13:38 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732525AbfHFJMl (ORCPT + 99 others); Tue, 6 Aug 2019 05:12:41 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:36940 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732411AbfHFJMl (ORCPT ); Tue, 6 Aug 2019 05:12:41 -0400 Received: from mail-wr1-f72.google.com ([209.85.221.72]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1huvWJ-0000nN-AC for linux-kernel@vger.kernel.org; Tue, 06 Aug 2019 09:12:39 +0000 Received: by mail-wr1-f72.google.com with SMTP id b1so41934822wru.4 for ; Tue, 06 Aug 2019 02:12:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=DCLv3sMLBM925x8RSSNrHS4fEWxpwWMaXUx5IHkTnME=; b=MFwy2FTukpq4ORJIuAVbWvA89WVwRc67hxoOXuEFJ6xKOBDHAFE3/eBHYuhZognXA3 eIOQNiVpVjNjjNC0zf+2uo4BMGHnw7kRIyPrFi8/XUJTSeT58iilIWaBOHtCgR4HC4fg P/eEA9ij+OjqoTIX+i7XL4GjUexScJldpQSEsL8ow5boUsJ0uRJF1bppwCyyblaznF5b o4/ScDwzLNTCbgIvsaF/POfGbFAbSGZYq0OnJKjCxJsYYlh9yEbWiyULoUGDFG6OHMh4 45p3prXkC2H7tm5SiIn1zZMCFS5Hyqzx4QQmy5F5W8lj2/eA0M9yIyj4iRbMLNz7wAy4 fcNA== X-Gm-Message-State: APjAAAU0PwVqeQwWWNiqMI2R25bXfEhFW3IZO8o7/6AXr5vaESoHsx/v Bq3+BNNavY3sVHgAsDmhv6vx9OiEWboWrGxRC0MVlw6w5WsNH1tG9IuHQS8KCQnFiF/8HRLaCXX /+RfYWjPvOtiNGwpzWInLsguO4ChpF15GFIs3Y70VFw== X-Received: by 2002:a5d:67cd:: with SMTP id n13mr3497169wrw.138.1565082758892; Tue, 06 Aug 2019 02:12:38 -0700 (PDT) X-Received: by 2002:a5d:67cd:: with SMTP id n13mr3497143wrw.138.1565082758555; Tue, 06 Aug 2019 02:12:38 -0700 (PDT) Received: from localhost (host21-131-dynamic.46-79-r.retail.telecomitalia.it. [79.46.131.21]) by smtp.gmail.com with ESMTPSA id y7sm64261675wmm.19.2019.08.06.02.12.37 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 06 Aug 2019 02:12:38 -0700 (PDT) Date: Tue, 6 Aug 2019 11:12:37 +0200 From: Andrea Righi To: Coly Li Cc: Kent Overstreet , linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] bcache: fix deadlock in bcache_allocator() Message-ID: <20190806091237.GB11184@xps-13> References: <20190710093117.GA2792@xps-13> <82f1c5a9-9da4-3529-1ca5-af724d280580@suse.de> <20190710154656.GA7572@xps-13> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190710154656.GA7572@xps-13> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 10, 2019 at 05:46:56PM +0200, Andrea Righi wrote: > On Wed, Jul 10, 2019 at 11:11:37PM +0800, Coly Li wrote: > > On 2019/7/10 5:31 下午, Andrea Righi wrote: > > > bcache_allocator() can call the following: > > > > > > bch_allocator_thread() > > > -> bch_prio_write() > > > -> bch_bucket_alloc() > > > -> wait on &ca->set->bucket_wait > > > > > > But the wake up event on bucket_wait is supposed to come from > > > bch_allocator_thread() itself => deadlock: > > > > > > [ 242.888435] INFO: task bcache_allocato:9015 blocked for more than 120 seconds. > > > [ 242.893786] Not tainted 4.20.0-042000rc3-generic #201811182231 > > > [ 242.896669] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. > > > [ 242.900428] bcache_allocato D 0 9015 2 0x80000000 > > > [ 242.900434] Call Trace: > > > [ 242.900448] __schedule+0x2a2/0x880 > > > [ 242.900455] ? __schedule+0x2aa/0x880 > > > [ 242.900462] schedule+0x2c/0x80 > > > [ 242.900480] bch_bucket_alloc+0x19d/0x380 [bcache] > > > [ 242.900503] ? wait_woken+0x80/0x80 > > > [ 242.900519] bch_prio_write+0x190/0x340 [bcache] > > > [ 242.900530] bch_allocator_thread+0x482/0xd10 [bcache] > > > [ 242.900535] kthread+0x120/0x140 > > > [ 242.900546] ? bch_invalidate_one_bucket+0x80/0x80 [bcache] > > > [ 242.900549] ? kthread_park+0x90/0x90 > > > [ 242.900554] ret_from_fork+0x35/0x40 > > > > > > Fix by making the call to bch_prio_write() non-blocking, so that > > > bch_allocator_thread() never waits on itself. > > > > > > Moreover, make sure to wake up the garbage collector thread when > > > bch_prio_write() is failing to allocate buckets. > > > > > > BugLink: https://bugs.launchpad.net/bugs/1784665 > > > Signed-off-by: Andrea Righi > > > > Hi Andrea, > > > > Hi Coly, > > > >From the BugLink, it seems several critical bcache fixes are missing. > > Could you please to try current 5.3-rc kernel, and try whether such > > problem exists or not ? > > Sure, I'll do a test with the latest 5.3-rc kernel. I just wanna mention > that I've been able to reproduce this problem after backporting all the > fixes (even those from linux-next), but I agree that testing 5.3-rc is a > better idea (I may have introduced bugs while backporting stuff). Finally I've been able to do a test with the latest 5.3.0-rc3 vanilla kernel (from today's Linus git) and I confirm that I can reproduce the same deadlock issue: [ 1158.490744] INFO: task bcache_allocato:15861 blocked for more than 120 seconds. [ 1158.495929] Not tainted 5.3.0-050300rc3-generic #201908042232 [ 1158.500653] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [ 1158.504413] bcache_allocato D 0 15861 2 0x80004000 [ 1158.504419] Call Trace: [ 1158.504429] __schedule+0x2a8/0x670 [ 1158.504432] schedule+0x2d/0x90 [ 1158.504448] bch_bucket_alloc+0xe5/0x370 [bcache] [ 1158.504453] ? wait_woken+0x80/0x80 [ 1158.504466] bch_prio_write+0x1dc/0x390 [bcache] [ 1158.504476] bch_allocator_thread+0x233/0x490 [bcache] [ 1158.504491] kthread+0x121/0x140 [ 1158.504503] ? invalidate_buckets+0x890/0x890 [bcache] [ 1158.504506] ? kthread_park+0xb0/0xb0 [ 1158.504510] ret_from_fork+0x35/0x40 [ 1158.473567] INFO: task python3:13282 blocked for more than 120 seconds. [ 1158.479846] Not tainted 5.3.0-050300rc3-generic #201908042232 [ 1158.484503] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [ 1158.490237] python3 D 0 13282 13274 0x00004000 [ 1158.490246] Call Trace: [ 1158.490347] __schedule+0x2a8/0x670 [ 1158.490360] ? __switch_to_asm+0x40/0x70 [ 1158.490365] schedule+0x2d/0x90 [ 1158.490433] bch_bucket_alloc+0xe5/0x370 [bcache] [ 1158.490468] ? wait_woken+0x80/0x80 [ 1158.490484] __bch_bucket_alloc_set+0x10d/0x160 [bcache] [ 1158.490497] bch_bucket_alloc_set+0x4e/0x70 [bcache] [ 1158.490519] __uuid_write+0x61/0x180 [bcache] [ 1158.490538] ? __write_super+0x154/0x190 [bcache] [ 1158.490556] bch_uuid_write+0x16/0x40 [bcache] [ 1158.490573] __cached_dev_store+0x668/0x8c0 [bcache] [ 1158.490592] bch_cached_dev_store+0x46/0x110 [bcache] [ 1158.490623] sysfs_kf_write+0x3c/0x50 [ 1158.490631] kernfs_fop_write+0x125/0x1a0 [ 1158.490648] __vfs_write+0x1b/0x40 [ 1158.490654] vfs_write+0xb1/0x1a0 [ 1158.490658] ksys_write+0xa7/0xe0 [ 1158.490663] __x64_sys_write+0x1a/0x20 [ 1158.490675] do_syscall_64+0x5a/0x130 [ 1158.490685] entry_SYSCALL_64_after_hwframe+0x44/0xa9 A better reproducer have been posted here: https://launchpadlibrarian.net/435523192/curtin-nvme.sh (see https://bugs.launchpad.net/curtin/+bug/1796292 for more details) With this new reproducer script is very easy to hit the deadlock. I've slightly modified my original patch and with that applied it seems that I can't trigger any problem. I'm not sure if my patch is actually the right thing to do, but it seems to prevent the deadlock from happening. I'll send a v2 soon. -Andrea