Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3386980rwb; Tue, 16 Aug 2022 01:55:25 -0700 (PDT) X-Google-Smtp-Source: AA6agR4vNG6RotomdsS4VYBwZ5vzj04xoWU6uZlImyqNJRxndtrIlVdgllTJE5xgfF70bJ0hQPn3 X-Received: by 2002:a17:903:493:b0:170:d825:f8d3 with SMTP id jj19-20020a170903049300b00170d825f8d3mr21009172plb.34.1660640124849; Tue, 16 Aug 2022 01:55:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660640124; cv=none; d=google.com; s=arc-20160816; b=1LJhcoa5wzvLC/kzSmRmw/ymJOvyxeRIcERaaOnSpp9E+kdexYOIfjRMEA2ykADsDy 64/LpHrGxE2NAPtt2e6M3nbbY5QIUP8Dlcce/0cJKuVyP5SmqVvOt4GyIjxFaj0ZaO49 G5gR9ys00eFEUGcvVT2gz40u4o0oqPlXKf5YiaTmG3JA0gOncFVl1004hNXbvsApLHgo aCJFzOGUqa1oV6DYiEiQpDnnA6/wyno7G0rz/Sd5l/IOdQ0yE1gyN4/BhOkcdoQVEM6f BSttmQ+DtB814Pt0d12ttL9/TKhO+vWWAqu2ZoGspS9zVpkeOgojKn0C07MFMnXL4B3O IYNA== 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=jdACKcZQnW2rz+ym/pyFpE18JDDBRDsTGyRhdRj6JS8=; b=nCfTG0rFtv4mwqnLq/lsgm13GKm6RU2oXJBNxdZRZGgJguqrbhxU/wBwb1cwI3JpSJ UcTaBow3yGneMtk2Ws9Y0Ut+2wa77wfG6OY8BEWMWc7Wa38yVr/4k5WPSZzsLnKxh4yB tYhMW0WJI0wn6OTeD6VuF0iVdkng82bzr7dRyoWbsWUASWjLHZGiMFiI5dWrPZh/iy1V i7ecA8vjrB4EZoDRN7B8VJ02tkH4aPbqMv0WWVACQepYA80W824GMQFX171pLqJyyDLy OZSHJCoOILR77xgJ0MC4B7yHy/4+k7sdNh3DFC0815cRDOSlXph/Msw80NhN7qdCgLR5 hCpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=gqP6eFnk; 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 y13-20020aa78f2d000000b0052c0f9617fbsi12033533pfr.278.2022.08.16.01.55.13; Tue, 16 Aug 2022 01:55:24 -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=gqP6eFnk; 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 S232683AbiHPIWN (ORCPT + 99 others); Tue, 16 Aug 2022 04:22:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232117AbiHPIVN (ORCPT ); Tue, 16 Aug 2022 04:21:13 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD9F265828 for ; Mon, 15 Aug 2022 23:04:03 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id w3so12175606edc.2 for ; Mon, 15 Aug 2022 23:04:03 -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=jdACKcZQnW2rz+ym/pyFpE18JDDBRDsTGyRhdRj6JS8=; b=gqP6eFnkxg6m9YfSUzZ+10ZckWcrXTsAkZH0q+/zWP6PQQ1qM9nrnOZTfPWOPIIAHt Ni0Y6J1PD0BbYmGLR37J/IVpCDgWZB9D4z9b5oRZmqVQjPUK+0A1N0rS84547ExO55I/ wnXf8etONDtUtGvrJys1HFW6iEOEr9i6fsIEM= 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=jdACKcZQnW2rz+ym/pyFpE18JDDBRDsTGyRhdRj6JS8=; b=gSanKhLIcgG5H/JTHZDg+mjaq5w9AiE04U0BjvgkMD3i7AFBgmZlYj66BdGse5sRWW 7xh/nOKCrTOcKWIDWSl6/DPu6Ix2+8kSFKh8LWOs/qfFJLjA5If1agk73GfG1aGuU1bM QBuLQ7PTYOUaYCmCS4CuSUGgu5gi6voDnmyx5NVKG9S8Afzv3+W463wsovDnsOVlKkZ4 lD1DBTOct4i9Guy1nlPGuoWFBTOaQGP0i7Vni2JXHnJMjrdCnUu0cKmu98dFcSYok/ou jVLHPvZ72qI1EDz4dxfYB1GeRqiQl6uA43ZyAeZHgFkYslpfghxET4xKEKtXCZ02xoNC lG1w== X-Gm-Message-State: ACgBeo1z/viWLEjieH6D/pwl29BRPHqbTOSDoveuyO0/D1/yVNp0JOcG TI16xlsQpB4O89VXB/w0Nkj+r7gFxB6wpjNhWH8= X-Received: by 2002:a05:6402:11c8:b0:440:6513:be2c with SMTP id j8-20020a05640211c800b004406513be2cmr16980831edw.45.1660629842541; Mon, 15 Aug 2022 23:04:02 -0700 (PDT) Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com. [209.85.221.42]) by smtp.gmail.com with ESMTPSA id r2-20020a17090609c200b0073156e6cd59sm4899837eje.4.2022.08.15.23.04.02 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 15 Aug 2022 23:04:02 -0700 (PDT) Received: by mail-wr1-f42.google.com with SMTP id e27so6635296wra.11 for ; Mon, 15 Aug 2022 23:04:02 -0700 (PDT) X-Received: by 2002:a05:6000:2a4:b0:225:162f:4cc7 with SMTP id l4-20020a05600002a400b00225162f4cc7mr1024841wry.274.1660629841690; Mon, 15 Aug 2022 23:04:01 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Linus Torvalds Date: Mon, 15 Aug 2022 23:03:45 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] workqueue: Fix memory ordering race in queue_work*() To: Herbert Xu Cc: Will Deacon , Tejun Heo , marcan@marcan.st, 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:49 PM Herbert Xu wrote: > > I think this is the source of all this: [ commit 61e02392d3c7 ] Yes, that doc update seems to actually predate the broken code. But you can actually see how that commit clearly was only meant to change the "test_and_set_bit_lock()" case. IOW, in that commit, the test_and_set_bit() comments clearly say * test_and_set_bit - Set a bit and return its old value * This operation is atomic and cannot be reordered. * It may be reordered on other architectures than x86. * It also implies a memory barrier. (that "It may be reordered on other architectures than x86" does show clear confusion, since it also says "It also implies a memory barrier") And the very commit that adds that - RMW operations that are conditional are unordered on FAILURE, language then updates the comment only above test_and_set_bit_lock(). And yes, on failure to lock, ordering doesn't matter. You didn't get the bit lock, there is no ordering for you. But then I think that mistake in the documentation (the relaxed semantics was only for the "lock" version of the bitops, not for the rest ot it) then later led to the mistake in the code. End result: test_and_set_bit_lock() does indeed only imply an ordering if it got the lock (ie it was successful). But test_and_set_bit() itself is always "succesful". If the bit was already set, that's not any indication of any "failure". It's just an indication that it was set. Nothing more, nothing less, and the memory barrier is still required regardless. Linus