Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2062612rdb; Sun, 4 Feb 2024 13:15:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IHIBpZ19DE64wUcd260oQl0JLTKoTlp0wz7tG6C2aGKJNT79EGfYwQNqGTXAhkLz9n5uAZf X-Received: by 2002:a17:903:2307:b0:1d9:3966:b2a1 with SMTP id d7-20020a170903230700b001d93966b2a1mr14604951plh.1.1707081338839; Sun, 04 Feb 2024 13:15:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707081338; cv=pass; d=google.com; s=arc-20160816; b=pI1Za8Zja/Fb3HICvbDHzr6K4Zbqyct24EovpGODEiwiN1pffbQP8do/GJGgfKv4Xm 3AcMCiq4vYIhtjda+6XJFvFtHauoS6xHcZ4R15UoSDAShGlABN5yfX7SV/26rF/hfcYH nITK9J2ydk6rpAlC5fFhc6o3DhhQtB021K64eLZ3CCMx/QAKGhXqwne68GSlOGfeiNLN y95vKs8FG4AdSaCMHSfqFFoLgS5MqkX0hrGtNynELegQzUx5K16pI+JGsIwMAXQggOA3 C4d5qEqYYxhNbEFsGAmas1S3lV9sVzqRJsf8GKv4qMSUt3fYvVGMv9/CXhNnX2Z2fGoW 4Rhw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:sender:dkim-signature; bh=DlMROPYiqbdd9NKGh0wea7FTnlpIWxLsmTfTz5ljzLU=; fh=HUL/ttoHh8DFNYpVnE4W5nrz0DrOAbvae/YmpvcGZgY=; b=nTz2eiTE5XTg3eW2PErQlVuCPLftmmIuqBst0Z0bYLhSV7FK+Gu1Ytf0o/5RA+5186 vrTispXqOPVLK+PNJD63H3x9iLnI5N8QuU13OxFRckJQR9cuqV63VWg4TqDz6CKtdYCm 0MCp9cx9MfQAyc1XDPQtKIb7vVesk1cLjCzfTx7AOb9CW9ildDrag7guZZMjFxwWqo3N dENt46DepAbK/jyPcGdXcxI9r+dmQ50OWZvo1mGJ8e6Is6g7+jsTsZbru9ebcw654RHI bSxUK/yTHPxX3xCTcLZ5srD6+KqEkH+ZXirO0EksaQ+9EAc109gRMYQRdNwzhJ5W9tfo qByA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=f7XWj9Sn; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-51906-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51906-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCU/ScJvnG4CvOfttav8EzvkRO3XKH5GYCDu3mgSXhFII2iQUZN7xn+hex4dlerVGnTUA+49NZq9ves2NvT941Lkbiwv0vDDGmrdQjHUQg== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id q4-20020a170902dac400b001d75eef04e1si5315203plx.73.2024.02.04.13.15.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Feb 2024 13:15:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51906-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=f7XWj9Sn; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-51906-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51906-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 685EFB2170D for ; Sun, 4 Feb 2024 21:14:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CB5822868D; Sun, 4 Feb 2024 21:14:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="f7XWj9Sn" Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 776B62556E; Sun, 4 Feb 2024 21:14:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707081265; cv=none; b=lIHGUn8UGzQrjY8BYEJteHh6jN73w5dJVq+Z3HmCXQfUfOdCtt/47UjcjXrcqgMJEShUxyi/AOQ6LPWdZnf6iGkBsxjNVZj8p4NsW9SUWZX93lheCB5VY8t68TgTQ0BCdKCskH55LAMU4o8eYk/69gx4aTfR2Chfqa384+WT78A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707081265; c=relaxed/simple; bh=nDRSwWjiurLq688508mdp6fBlHDdaVsyZGnjnjY3Hxo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WVe5tbFcmarXGOxspCmJW9sFXdxhdaPlXx6zNqg72ipJseXpIPYdchY9kkdI1VpTB2eFpnDAPMZ+QoDKB0SaaZTdTkhJG9JqEh3Vt7Zm27bKHEWjMF6z1G26bZPVHDRK8U3yJI/jL8Mf1P08HTYLBZbUOAtDIAMLhPHejMVjCT0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=f7XWj9Sn; arc=none smtp.client-ip=209.85.215.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-5d3912c9a83so2929810a12.3; Sun, 04 Feb 2024 13:14:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707081263; x=1707686063; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:from:to:cc:subject:date:message-id :reply-to; bh=DlMROPYiqbdd9NKGh0wea7FTnlpIWxLsmTfTz5ljzLU=; b=f7XWj9Snk+ebfcKGLOa8zpLP5YhHbxvtzhzdfmdg6R24fZRY7Z5UV0Nl1cnNMOLXMJ zBIfQ8goyWeuNP6iG5k9lDG8hzsL/79cflSL/XYDcpCj85V9MrI7/nxokT4BmSMLf1QZ NnWO6Bvha8l50yHS8uTmI6MrRRNOZzkWkmw+HSKdwFp8zpLNHVmSzsYXrYnQCKcxC5eE h/viwqozX3gR2iePKedYg5+cyGJpBY93lqtW5V5t6ciSCE4VhViTMwIqpO6OllCqACyw cTT2CXdaZAJl/XqhX26u68hYlM+vCsOvNapqkZAiHqMe5cQpc6CbpzjMetE3XXnIsCeX Qesg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707081263; x=1707686063; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DlMROPYiqbdd9NKGh0wea7FTnlpIWxLsmTfTz5ljzLU=; b=i8+V+DOqYs7pGAmci128pcbIwsbnu/bDprxAonH9qEGtEC0BBmojJ+8qCnYLlWHH0L jr6nfeSC3vKKVO6LEI4a4/R4iWW1yA1EiW8YWnagxdTArNki/4cJdklMcXxypXdJ1Tq/ w9gRB9Yl4wjXSHiRlmKDVxn8GsXKt1zccsWaYYfr1KCP8Ss2vP5ksM6ZtmJo5qj3kwFt kyVabJ3WjIVgXzP9Bd38vs81v8gs+TWymxyUqlfPAKf9hqaYa6Evm/KYNO9CncfADolO AYjv5uO/Ri07xRwEYLunDrdtxcV0fMEMrxr/O6f85Qh/n32W7deUyHJ6ZmZ9G32nBe+w I4vA== X-Gm-Message-State: AOJu0YxrKGgk7nXxUNeLUawhIgaO5Tg1du+3Yy7q+3LrZmrk57vVtWxS hq6M4bycqPIWz0SOQFIvmBIH8lahAtv42qkbA1YExCId1ukJnrG3 X-Received: by 2002:a17:902:654b:b0:1d9:40f3:ada8 with SMTP id d11-20020a170902654b00b001d940f3ada8mr9317476pln.3.1707081262605; Sun, 04 Feb 2024 13:14:22 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXok8bKHNe5PByrhpn7cw7isMSves1hUfeCvwMRKswiYRlOL/8s1SNdKhPZGPbnjEm37nBLrUOixbDnrAA7wD73NyW769TDo2XN8eFWPG6/SEBHR/J62ugjht2s5HYLOi17f0VTnZBWzgdYOXR2E5YwQvLBKLcVGspv Received: from localhost (dhcp-141-239-144-21.hawaiiantel.net. [141.239.144.21]) by smtp.gmail.com with ESMTPSA id l4-20020a170903244400b001d9620dd3fdsm4867600pls.206.2024.02.04.13.14.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Feb 2024 13:14:22 -0800 (PST) Sender: Tejun Heo Date: Sun, 4 Feb 2024 11:14:21 -1000 From: Tejun Heo To: Chandan Babu R Cc: jiangshanlai@gmail.com, linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org Subject: [PATCH wq/for-6.9] workqueue: Fix pwq->nr_in_flight corruption in try_to_grab_pending() Message-ID: References: <87o7cxeehy.fsf@debian-BULLSEYE-live-builder-AMD64> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87o7cxeehy.fsf@debian-BULLSEYE-live-builder-AMD64> dd6c3c544126 ("workqueue: Move pwq_dec_nr_in_flight() to the end of work item handling") relocated pwq_dec_nr_in_flight() after set_work_pool_and_keep_pending(). However, the latter destroys information contained in work->data that's needed by pwq_dec_nr_in_flight() including the flush color. With flush color destroyed, flush_workqueue() can stall easily when mixed with cancel_work*() usages. This is easily triggered by running xfstests generic/001 test on xfs: INFO: task umount:6305 blocked for more than 122 seconds. ... task:umount state:D stack:13008 pid:6305 tgid:6305 ppid:6301 flags:0x00004000 Call Trace: __schedule+0x2f6/0xa20 schedule+0x36/0xb0 schedule_timeout+0x20b/0x280 wait_for_completion+0x8a/0x140 __flush_workqueue+0x11a/0x3b0 xfs_inodegc_flush+0x24/0xf0 xfs_unmountfs+0x14/0x180 xfs_fs_put_super+0x3d/0x90 generic_shutdown_super+0x7c/0x160 kill_block_super+0x1b/0x40 xfs_kill_sb+0x12/0x30 deactivate_locked_super+0x35/0x90 deactivate_super+0x42/0x50 cleanup_mnt+0x109/0x170 __cleanup_mnt+0x12/0x20 task_work_run+0x60/0x90 syscall_exit_to_user_mode+0x146/0x150 do_syscall_64+0x5d/0x110 entry_SYSCALL_64_after_hwframe+0x6c/0x74 Fix it by stashing work_data before calling set_work_pool_and_keep_pending() and using the stashed value for pwq_dec_nr_in_flight(). Signed-off-by: Tejun Heo Reported-by: Chandan Babu R Link: http://lkml.kernel.org/r/87o7cxeehy.fsf@debian-BULLSEYE-live-builder-AMD64 Fixes: dd6c3c544126 ("workqueue: Move pwq_dec_nr_in_flight() to the end of work item handling") --- Hello, Chandan. Thanks a lot for the report. I could reproduce the problem and verified that this patch fixes the issue. I'm applying this to wq/for-6.9 but would really appreciate if you could confirm the fix. Thanks. kernel/workqueue.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index ffb625db9771..55c9816506b0 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -1999,6 +1999,8 @@ static int try_to_grab_pending(struct work_struct *work, bool is_dwork, */ pwq = get_work_pwq(work); if (pwq && pwq->pool == pool) { + unsigned long work_data; + debug_work_deactivate(work); /* @@ -2016,11 +2018,15 @@ static int try_to_grab_pending(struct work_struct *work, bool is_dwork, list_del_init(&work->entry); - /* work->data points to pwq iff queued, point to pool */ + /* + * work->data points to pwq iff queued. Let's point to pool. As + * this destroys work->data needed by the next step, stash it. + */ + work_data = *work_data_bits(work); set_work_pool_and_keep_pending(work, pool->id); /* must be the last step, see the function comment */ - pwq_dec_nr_in_flight(pwq, *work_data_bits(work)); + pwq_dec_nr_in_flight(pwq, work_data); raw_spin_unlock(&pool->lock); rcu_read_unlock();