Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1573850rdb; Mon, 19 Feb 2024 23:33:56 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU0Pmjux+vqZqTXfnpAH5hQWonEQ6kb4Q4w6QrVP4lZ5vynLC0Xq0rPamslxXUM5hJqRqCdrIcX3EnihsjkeNon28gm2okw07fTuoCzyg== X-Google-Smtp-Source: AGHT+IFwfnjN/GNvFMMJ52r0Qe7vuvUbckdka5aUXBSW1dnw0AroIAOF1FcGTtvok4IC1hF61peh X-Received: by 2002:aa7:de04:0:b0:564:d28e:c4b with SMTP id h4-20020aa7de04000000b00564d28e0c4bmr262382edv.30.1708414436156; Mon, 19 Feb 2024 23:33:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708414436; cv=pass; d=google.com; s=arc-20160816; b=nLtF/wMLaYVHBXF6uYYdE5QkelJUry4m8O3C1N9C59TnntWdYH4npeyIy/521GVHoY MU1OTLmZEyJ1YlK83mlsge8uD/nYE97OSHBIQRGMJbf6Req2znOyM8EvSUnzTQprJWsI +yib65sMCOApqbpdRifjCHdIOFnr34/7NnaZkGnq7JjVzMq+9XJ2xt62scg3GxDuyIxc WyTnDNiY2+4VYhSRVLFhilxaRcfji8uSavvkfq6f7edO1QMtw3Z4w5aPhbVNv5EZgMYt 5jLBVwAor/2BevxrHqW/uTq80tMpVsWlFz/YOfNxeQty7ryROpiQw7hbnNUc2YWAvejj 09Tg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=zsenoJ7EMCFSDYF3hHTZ5Kjc4dQDNAVYOwwzOKqMxdA=; fh=Gx1cQvlT36kqoxdkWmLQa0OXBEB5GNObMJvKLS/B+zc=; b=rUJjya0zLe77qAriD7KT8va38YOPzYsC3er99xNY+Q9xu4pv5Doons+sozp6K98L7E OHHNMzj4P6Izn+x1CeuvgSO6OAHuRgHltf+YKXDQMLVwsqFHdA4m2ZEUCh10n8RiC/ji cl+7F57WYJO7qdrbZxYCVj5OMy+c/F+BfIcbdJGyQaFwNQhKLF6qjHbEFWGv+0QTQjok 3mBfSmROwYPiqQwmgF5i9ez3ycUxI2YlwqGnC+qPvikrW5XzbZ7Wbjhq/j8DfA/viOgV IkbOjdmwMnxCFtxlzQRVmgIJTj9AYTSkvmE7h7x0w+xQoUvrXsANKPDhSqGbVhcyyicJ bJJQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=kSe83qHl; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-72482-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72482-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id y3-20020a056402134300b00563948c8f8esi3154777edw.262.2024.02.19.23.33.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 23:33:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-72482-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=kSe83qHl; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-72482-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72482-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id ADCC81F2285E for ; Tue, 20 Feb 2024 07:33:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CB1755A788; Tue, 20 Feb 2024 07:33:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kSe83qHl" Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (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 955052D79D for ; Tue, 20 Feb 2024 07:33:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708414428; cv=none; b=VkBF0homiKkwQ5Kw+s+NN/OwNyhr/38IaIj/bBhk0tDnA3CLnOxQd4UwYcO6HThRlkbrqeQo7SpS7DUqwRefmiYZYoXLmwQcb3p0mkYJ0rlG86Emo8mOpFrlW2pKbHmxR04qWZKtt/9l5Rgfjsq3JhU6NyIWTmAS/+5nYNmVg90= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708414428; c=relaxed/simple; bh=gXDvV6ZXXMBqmPgURlBl8TrIV2CHccnufrRAQwQy6GE=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=XWK3hRmfmVVlnv6+ANjr88r4pYnEKln5fzoUo/TaLJAGyoWbVK2IUtrhr7qLuhf/VRjzeXE8Sen5GJaRoBq/akY2GVQvHTjYqW3PNkoO2RJlnDUrI1g/lVUAB/RWLkKG7+jcGAxKutj1TG7/bV+rMBEQGBrO+iEQROc7SOP9rtI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kSe83qHl; arc=none smtp.client-ip=209.85.216.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-2999329dfe7so1657306a91.0 for ; Mon, 19 Feb 2024 23:33:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708414426; x=1709019226; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=zsenoJ7EMCFSDYF3hHTZ5Kjc4dQDNAVYOwwzOKqMxdA=; b=kSe83qHlChxhxvOM8k1RmbibxbDZXqcORdNablyxGLPjMihyKNZeeTRNZQu0s65HB6 LXnulA5xbbAx/vnz+OgbkRIenRCp03JiRuI9J4E0WzQBhCAse/bh/IXy2xilvIiQrCa1 DoVXhFV9Mqrohrw+kl98IahUyqE+3iRI/J+F0WEoVNuepGsV8PVxDd4bgxfwm4jiWopk iB0h2Ab3Eg9WagnVvReO3kF1wEMgswGIgiT4oGi38kqCNZamsujq5pDxOzZP2rkfg3Or 3etXxDRBuiS6d1PUmq0SADAetZajM0QOCvZoSohPIgv6mc4uxU2X+DOamO9/ptSEqa1y +Kiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708414426; x=1709019226; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zsenoJ7EMCFSDYF3hHTZ5Kjc4dQDNAVYOwwzOKqMxdA=; b=P5+TYrVPH6tuJHmTcSouePa47vVusj87+3x/jEKQ83zkXFhWuo3QHGBV8+uS2sVmu1 tubZ9MaNrt57QzxtLsQMg2Bnu3x90K/Kdgv7+6c90Gqi6tHWMor86n17t3dar+rdgRqp JDL2xjYrqmbROde8DG2kU0akBVTzQaYiMaig10fJo4pfoYXZU3ZW2RoSgpzAKmDh4c1M M8cY7ttHt6im/jaAKkRtqfoJ8FHHb4b3aodLC2se05+SsBOR0LCrLg63Y2K2aBt5MP/c 5shl4qyY+BAAJC/ALiEvgNOOHvytQc0D4M8/LM7Zv5hrQwzkVtMxJAmqQe8PFQ10Ph9/ 0t1A== X-Forwarded-Encrypted: i=1; AJvYcCU4mf4oO4t5lU5MgqaBpk4md7tqlEe4zYFJ1l7lGvsb/LhuNp24/Y6oouEu48h8GzMgES7Xq23wDh4Oo9yew2xyJm/Vw3Ln8+oW+VAq X-Gm-Message-State: AOJu0YxQDctDCcgEi6qBOjJNGrFFuUDcmyTlCZP2qLiOy6i6UxoluynB oDLt9n23el6snOkTkAyVfNZkza8Tf02o9O7heTS2f6915MX1fY+2FrLLY4GFWhTlu4RPIt7QHsa /7jt9wu9SPT2JmaiwYkdF1/UQt3Q= X-Received: by 2002:a17:90a:b014:b0:299:6e88:7b6a with SMTP id x20-20020a17090ab01400b002996e887b6amr6036719pjq.36.1708414425900; Mon, 19 Feb 2024 23:33:45 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240216180559.208276-1-tj@kernel.org> <20240216180559.208276-17-tj@kernel.org> In-Reply-To: <20240216180559.208276-17-tj@kernel.org> From: Lai Jiangshan Date: Tue, 20 Feb 2024 15:33:34 +0800 Message-ID: Subject: Re: [PATCH 16/17] workqueue: Allow cancel_work_sync() and disable_work() from atomic contexts on BH work items To: Tejun Heo Cc: torvalds@linux-foundation.org, linux-kernel@vger.kernel.org, allen.lkml@gmail.com, kernel-team@meta.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello, Tejun On Sat, Feb 17, 2024 at 2:06=E2=80=AFAM Tejun Heo wrote: > @@ -4072,7 +4070,32 @@ static bool __flush_work(struct work_struct *work,= bool from_cancel) > if (!pool) > return false; > > - wait_for_completion(&barr.done); > + if ((pool->flags & POOL_BH) && from_cancel) { pool pointer might be invalid here, please check POOL_BH before rcu_read_unlock() or move rcu_read_unlock() here, or use "*work_data_bits(work) & WORK_OFFQ_B= H". > + /* > + * We're flushing a BH work item which is being canceled.= It > + * must have been executing during start_flush_work() and= can't > + * currently be queued. If @work is still executing, we k= now it > + * is running in the BH context and thus can be busy-wait= ed. > + * > + * On RT, prevent a live lock when current preempted soft > + * interrupt processing or prevents ksoftirqd from runnin= g by > + * keeping flipping BH. If the tasklet runs on a differen= t CPU > + * then this has no effect other than doing the BH > + * disable/enable dance for nothing. This is copied from > + * kernel/softirq.c::tasklet_unlock_spin_wait(). > + */ s/tasklet/BH work/g Although the comment is copied from kernel/softirq.c, but I can't envision what the scenario is when the current task "prevents ksoftirqd from running by keeping flipping BH" since the @work is still executing or the tasklet is running. > + while (!try_wait_for_completion(&barr.done)) { > + if (IS_ENABLED(CONFIG_PREEMPT_RT)) { > + local_bh_disable(); > + local_bh_enable(); > + } else { > + cpu_relax(); > + } > + } > + } else { > + wait_for_completion(&barr.done); > + } > + > destroy_work_on_stack(&barr.work); > return true; > } > @@ -4090,6 +4113,7 @@ static bool __flush_work(struct work_struct *work, = bool from_cancel) > */ > bool flush_work(struct work_struct *work) > { > + might_sleep(); > return __flush_work(work, false); > } > EXPORT_SYMBOL_GPL(flush_work); > @@ -4179,6 +4203,11 @@ static bool __cancel_work_sync(struct work_struct = *work, u32 cflags) > > ret =3D __cancel_work(work, cflags | WORK_CANCEL_DISABLE); > > + if (*work_data_bits(work) & WORK_OFFQ_BH) > + WARN_ON_ONCE(in_hardirq()); When !PREEMPT_RT, this check is sufficient. But when PREEMP_RT, it should be only in the contexts that allow local_bh_disable() for synching a BH work, although I'm not sure what check code is proper. In PREEMPT_RT, local_bh_disable() is disallowed in not only hardirq context but also !preemptible() context (I'm not sure about it). __local_bh_disable_ip() (PREEMP_RT version) doesn't contain full check except for "WARN_ON_ONCE(in_hardirq())" either. Since the check is just for debugging, I'm OK with the current check. Thanks Lai