Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3383990rwb; Tue, 16 Aug 2022 01:50:05 -0700 (PDT) X-Google-Smtp-Source: AA6agR4KDe5EmhdWG/3khbGV1ae4ZV76wSBO8YP4JSePhRIfxZ4jnC6+r5ECU6E2M6TxhSTKm0Xt X-Received: by 2002:a17:902:8486:b0:171:48cd:1356 with SMTP id c6-20020a170902848600b0017148cd1356mr20197633plo.153.1660639805173; Tue, 16 Aug 2022 01:50:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660639805; cv=none; d=google.com; s=arc-20160816; b=fr3t3JaBWHP9HxlGJtlrVdSa93H814JJAb65n4aOlwnEhyU9c6bhbJUQ8KaYp0L2NI oVWCEoLZfKwQMxPlXCJCz9xOoDBrhEVqnmenxjeVwzdhgj8Smt/l13c8sXQXxrc9hG33 KIgWAASHUGump9NnPD7hdG+9MXnsA7/Ovgrq+BgW8LRhpBEAFI8SvHHIr9QsS3CCPwSO tb/TaMbdXxNAW8fQR+atOGjh2J30zcTVzqv6j7XG4Qwe5KnlJrP91S5DpfTJomwyUaCk Cb7mY8Ej/RX5ciRW1TZssLwANU5G7+e9ulbKssE8N2gHnTU3iHOR6j7u2C5EjdWhdFKS LMYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=WBv3h3wgQyY1EiVeiutsnqi3DPEWUTFH2e+SxIIu+SI=; b=q/d5AxQtFWLrs98kDbAt8TMR1BzuOQifht2m2Esix2oVepOjni2KKSc56Rg0IUEJIP j2NyV5rTZxDAmZ7wk7m1qURh+BUiH+k+m4eais5yzwcvxFnsJ+XPpZTrtT4QaLMOXIpl cjGxMd0u4SQxDU/7twAOAD+aNGOVBa5eR/+OLzOwsw8P4FZ1pLjeYgl2utPw11S7foTo aUR9JmDy+xYCGuI9HUFxfXgAxAI0N1/eIIcVa25PL8qP9MS3Y9D+8bqqn/kRcI/VZfjK mO3JFrZD6IrwPaqUNxRDVKF6isQKyTGHTPNA6qsqKjweaZikQ9KWqbrBm+ocmLGaMmS6 P/zQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=HMgDCIXl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mw6-20020a17090b4d0600b001fa581da1fcsi12697104pjb.24.2022.08.16.01.49.44; Tue, 16 Aug 2022 01:50:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=HMgDCIXl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233024AbiHPIbn (ORCPT + 99 others); Tue, 16 Aug 2022 04:31:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232934AbiHPIaD (ORCPT ); Tue, 16 Aug 2022 04:30:03 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B4A3135AFE for ; Mon, 15 Aug 2022 22:53:08 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id tl27so17036307ejc.1 for ; Mon, 15 Aug 2022 22:53:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=WBv3h3wgQyY1EiVeiutsnqi3DPEWUTFH2e+SxIIu+SI=; b=HMgDCIXlUYJ6kJuRhk+eXtuR9vuZC+EQUek1ea7s4szj5UjzZ0duIpqooXHBusQSn3 2C1m8fobBSmp7OoimIVuJSe5viRJfsH3IXM7JVm4shRAKMJvp9GtGyRvl5HJ4S4/A7CS 8yKVcomowZtnMK4E6sYXaCaspJq0LI7wL44x0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=WBv3h3wgQyY1EiVeiutsnqi3DPEWUTFH2e+SxIIu+SI=; b=JvOLX0Yp6I/UmD6wNB1JDH34JjP3cToY7dGJscb7jgNjMsnKu1xCMyp+E54d/jPIDr TkL5mF8x2WZjMPysymlWNXN6s3tyP/IM8ac6YDCvhv0oXIClIssVZ2bTAjAgdexU/jnp C5/FbmQYpYeKCIu12PZkOLYf2nHNdQMLVA48Me9qwkCVTvbsD5rW7t5h2epnKSjkM+qS NPaXqoSQ7DHCpU0xscwgohLNBMqZEBRhLXTY43N5CsdseAvmcErXRk2cKlFWeWOdNNeY AgfdM89B1Luyh8CEv+jJgkpeXn3A5o1WlSci2R922eaMfciezYHUw0M+Kg2oXTPDlrJy hcKQ== X-Gm-Message-State: ACgBeo2ViWhaw80xC0m2jstJCqbJMPpdVF3cq8Ez7loC9FHdn4ZPUcOY /fUTJ/6GFv/J/GL3Ym2cDUO27w4vDZqG3Y9v/FI= X-Received: by 2002:a17:907:2722:b0:731:23a3:be78 with SMTP id d2-20020a170907272200b0073123a3be78mr12607950ejl.330.1660629186550; Mon, 15 Aug 2022 22:53:06 -0700 (PDT) Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com. [209.85.221.52]) by smtp.gmail.com with ESMTPSA id e8-20020a170906844800b0072af102e65csm4893180ejy.152.2022.08.15.22.53.05 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 15 Aug 2022 22:53:05 -0700 (PDT) Received: by mail-wr1-f52.google.com with SMTP id j1so11345407wrw.1 for ; Mon, 15 Aug 2022 22:53:05 -0700 (PDT) X-Received: by 2002:adf:b343:0:b0:225:1a75:2a9a with SMTP id k3-20020adfb343000000b002251a752a9amr270998wrd.281.1660629185303; Mon, 15 Aug 2022 22:53:05 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Linus Torvalds Date: Mon, 15 Aug 2022 22:52:49 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] workqueue: Fix memory ordering race in queue_work*() To: Hector Martin Cc: Herbert Xu , Will Deacon , Tejun Heo , peterz@infradead.org, jirislaby@kernel.org, maz@kernel.org, mark.rutland@arm.com, boqun.feng@gmail.com, catalin.marinas@arm.com, oneukum@suse.com, roman.penyaev@profitbricks.com, asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 15, 2022 at 10:36 PM Hector Martin wrote: > > These ops are documented in Documentation/atomic_bitops.txt as being > unordered in the failure ("bit was already set" case), and that matches > the generic implementation (which arm64 uses). Yeah, that documentation is pure garbage. We need to fix it. I think that "unordered on failure" was added at the same time that the generic implementation was rewritten. IOW, the documentation was changed to match that broken implementation, but it's clearly completely broken. I think I understand *why* it's broken - it looks like a "harmless" optimization. After all, if the bitop doesn't do anything, there's nothing to order it with. It makes a certain amount of sense - as long as you don't think about it too hard. The reason it is completely and utterly broken is that it's not actually just "the bitop doesn't do anything". Even when it doesn't change the bit value, just the ordering of the read of the old bit value can be meaningful, exactly for that case of "I added more work to the queue, I need to set the bit to tell the consumers, and if I'm the first person to set the bit I may need to wake the consumer up". > On the other hand, Twitter just pointed out that contradicting > documentation exists (I believe this was the source of the third party > doc I found that claimed it's always a barrier): It's not just that other documentation exists - it's literally that the unordered semantics don't even make sense, and don't match reality and history. And nobody thought about it or caught it at the time. The Xen people seem to have noticed at some point, and tried to introduce a "sync_set_set()" > So either one doc and the implementation are wrong, or the other doc is > wrong. That doc and the generic implementation is clearly wrong. Linus