Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3368574rwb; Tue, 16 Aug 2022 01:25:25 -0700 (PDT) X-Google-Smtp-Source: AA6agR7/QCubMNFEa1+nB513qA1ZbEXPy3Ts6MM0gBWy8ozjKCvrJCXb9UmcvwEq5/REteHoz0Ru X-Received: by 2002:a17:907:7388:b0:731:e57:dea3 with SMTP id er8-20020a170907738800b007310e57dea3mr13002336ejc.640.1660638324873; Tue, 16 Aug 2022 01:25:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660638324; cv=none; d=google.com; s=arc-20160816; b=SxcsXrP+q4y4VZPUkuP3PZZnNYVu3o9O9ZYAZwzKO69/UKxx9JUmFhPLUFraatjYF7 XveGwsNWgT1jAyN9ogP0ioCD/4mDzqiRhJwRaNp+HCOwqP4tGWUzyEWMeKK2K/nkAZp/ IPsDQWYg8cxT1sSCrH+fXfuJn2W8WTPxnobK6IUoelEFV9eQlmiXN4QhzFuDKJqY5PDV Kd215JDphExtZ1++W5t+MLmyN13HK1to20yAkXCbWjHZfceqe1YjC5Zr25a3xNNj5rxC sqXpPrtl7tAI8dj5UbBMIxVEJCksZ11hYSh2wih4+j1hkpVTweHVzQNHbh5CCEqxtrjK B/3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:subject :from:references:cc:to:content-language:user-agent:mime-version:date :message-id:dkim-signature; bh=7RrcDW9emVCkxGeTCo/7LN4YLBNaNL+3MhdyJfwF1fk=; b=P8PiWDXoLEMobmFCgKVX6+R20g/KDM0Ov1TSsHVg10OcYVy4vzWYgh8Jh5qt4W00cH xmXb6fG9ZBDFm3n7WREO6I4xKncAsOr99lKhhyThYzjIlzxu22fZIiljSIL/5cvKfs73 3zscjIpwNTY7N1wUPBlpAeXMWPxGTVoO52BuUKwakAyGWQpjSucgzS6GvgLn7GWVFU9W p5LSu91VsTxkz1NW0Tp99vAaZzEyFTDxAlRXo6h7+0qisFsEpgThKg1drpngNysITM7e KY4VsEE1ZiW/KYbsAZnSOTGxUGPekI8w1V1uDn7uj2aDFzZ7Og/pQSQtw/ZVmf9nJSia TLkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@marcan.st header.s=default header.b=EcSu5BD6; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=marcan.st Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b6-20020a056402278600b0043e898f7840si11580861ede.449.2022.08.16.01.24.58; Tue, 16 Aug 2022 01:25: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=@marcan.st header.s=default header.b=EcSu5BD6; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=marcan.st Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231807AbiHPILM (ORCPT + 99 others); Tue, 16 Aug 2022 04:11:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232512AbiHPIKg (ORCPT ); Tue, 16 Aug 2022 04:10:36 -0400 X-Greylist: delayed 41899 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 15 Aug 2022 22:36:40 PDT Received: from mail.marcansoft.com (marcansoft.com [212.63.210.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AE1C67C84; Mon, 15 Aug 2022 22:36:40 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: marcan@marcan.st) by mail.marcansoft.com (Postfix) with ESMTPSA id 9D5EB447D6; Tue, 16 Aug 2022 05:36:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=marcan.st; s=default; t=1660628198; bh=LDV8KEPCOtRgxMbfux9/6KsJjkeggvwXB+aHn8IlWLI=; h=Date:To:Cc:References:From:Subject:In-Reply-To; b=EcSu5BD6o5VrpBFcpBXJIz6I/+WaBA0jWNVC8P/rW4gyyZncMVpPk1bJgjIK5ksTW fHqtXhFxFgAWCzs7stoll3p0mS2G/dTkmwoCCbvyqO+CLva3jPNvavrtR5GWCKtDli 2k45NWTqBLW3zOpP83gvbLc9/hQ2RrjzZv/xWgOqK670RCY5oY2mihSGfXOoFOM3Pd L1Wj81O5ZhAmR99xY6Jvce2M6GvxekL6bBHrcL2OfG1ByMfu2plrwW032Fj67Egexc mfSW4St7Shka/buVYsWjsTV1EW/c0OevIMBwJszNcv7hVP4nQrWtm7gfo+wKuHymKc WhbfgvKJgpG0Q== Message-ID: Date: Tue, 16 Aug 2022 14:36:31 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Content-Language: es-ES To: Linus Torvalds , Herbert Xu , Will Deacon Cc: 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 References: From: Hector Martin Subject: Re: [PATCH] workqueue: Fix memory ordering race in queue_work*() In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 16/08/2022 14.27, Linus Torvalds wrote: > On Mon, Aug 15, 2022 at 9:15 PM Herbert Xu wrote: >> >> Please revert this as test_and_set_bit was always supposed to be >> a full memory barrier. This is an arch bug. > > From looking at it, the asm-generic implementation is a bit > questionable, though. In particular, it does > > if (READ_ONCE(*p) & mask) > return 1; > > so it's *entirely* unordered for the "bit was already set" case. 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). 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): include/asm-generic/bitops/instrumented-atomic.h So either one doc and the implementation are wrong, or the other doc is wrong. > --- a/include/asm-generic/bitops/atomic.h > +++ b/include/asm-generic/bitops/atomic.h > @@ -39,9 +39,6 @@ arch_test_and_set_bit( > unsigned long mask = BIT_MASK(nr); > > p += BIT_WORD(nr); > - if (READ_ONCE(*p) & mask) > - return 1; > - > old = arch_atomic_long_fetch_or(mask, (atomic_long_t *)p); > return !!(old & mask); > } > @@ -53,9 +50,6 @@ arch_test_and_clear_bit > unsigned long mask = BIT_MASK(nr); > > p += BIT_WORD(nr); > - if (!(READ_ONCE(*p) & mask)) > - return 0; > - > old = arch_atomic_long_fetch_andnot(mask, (atomic_long_t *)p); > return !!(old & mask); > } > > but the above is not just whitespace-damaged, it's entirely untested > and based purely on me looking at that code. That does work, I in fact tried that fix first to prove that the early-exit was the problem. I don't have a particularly strong opinion on which way is right here, I just saw the implementation matched the docs (that I found) and Will commented on the other thread implying this was all deliberate. - Hector