Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3367787rwb; Tue, 16 Aug 2022 01:24:08 -0700 (PDT) X-Google-Smtp-Source: AA6agR50cf0VsBao+aHvH5mSxOoDqjzunCcz9Zlon5512/2W2ycGLGSThxiBTKRXd5UywgFVHZ6z X-Received: by 2002:a17:906:cc5e:b0:730:cf6d:5451 with SMTP id mm30-20020a170906cc5e00b00730cf6d5451mr12746289ejb.725.1660638247829; Tue, 16 Aug 2022 01:24:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660638247; cv=none; d=google.com; s=arc-20160816; b=azFUfvMtZNcj2lN2aMl/smI0LP+vABkmidtRp72T8Q9HpA85NMdv6lifEZlnlfCV3E DHrXmsnymrZa1eDq1NHnmvkKYV+u8o3tYuC1He+QpZ/696tsncmGX5n3M1V0bw2FY+p/ CX9KXHX02FRLQAyvNkVxTWKiGUk1Hv5SVjmMo/Gdj9L6oqMzrDF4Sg9gwWy3i4fGobg4 jjf2XIwV90uuTkQDuGfKJU5OaXvZbAPdzJtaShkt9r40eSUcfDs3xYFH9UiDlimlDuRo OyPn24P0r0VqjBEdw3BNJfD03Ewt97BgI8nhJ+iVp5zmzMwjoFSg0u4YUEFp5lU2f6gg W5nQ== 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:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=/jD2yIB7j8WXIMGxH1XLGnpE0gFoTFJIrooWD/YI6YA=; b=amEIFj7VTXUabtEpG6WDVNHH5yEREFoMAiYrcxZ3PFlild02a0GQzJM1roJPo1kvOl +JtO4JSmxDj7Yv5mD8hn5x4vR1AuRCtSeQrXq+YfQwztlnuSlz6JASfKRDBzU41+Xs8O Pwc3+tIMDSBnNmsFrsydWHONFNSZbsRNRZAtZCGFPPGN3mDY9rEFPMDJIg6pH4buX7Vk Cqy0PMAOAHrF/kXeY6niEMV7dg68S4V/uU47N+Yylb8ufZ+AsiboELSMjCLL8KWzw/Fa nFoylshxxxkHmZYe6XQyoyO7XiGvDaatq1md19xy8CfAQx/7HBK8PqTi5DHxiThPpIDv lSDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@marcan.st header.s=default header.b=Ar5abDx7; 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 qf27-20020a1709077f1b00b007306ac0faa0si10858739ejc.615.2022.08.16.01.23.41; Tue, 16 Aug 2022 01:24:07 -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=Ar5abDx7; 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 S232502AbiHPIMz (ORCPT + 99 others); Tue, 16 Aug 2022 04:12:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232025AbiHPILL (ORCPT ); Tue, 16 Aug 2022 04:11:11 -0400 Received: from mail.marcansoft.com (marcansoft.com [212.63.210.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12654DEA64; Mon, 15 Aug 2022 23:29:00 -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 AAA75447D4; Tue, 16 Aug 2022 06:28:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=marcan.st; s=default; t=1660631338; bh=ckiDupmPBCFt5SMzFxURk+watAFEoPDuoc/9452gvXQ=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=Ar5abDx7A0c+SPmkDgRjZvHgyC3acBWOhO1cnDNxSe1PiunFA2WMG2wwfUHYow0pb /kok3Crx9W64fVR5DXxsBmJKq7RoPPI1d6gDVGnARbs1M0QAFeXWKbMtyIB4uJNEib ZHnKnuuED1+ByvC3nmXwOvwI74o92uHcrhz7WfQg0XBz35JLo5xLvmAOFVjP765eqA NCVgsON2k+Q5nky+RyZU96b9dqN4aXKKxWgSagg8/u2nM5MBmI7Ao9q4/Sf0aOT4r2 YYPsxNKXe0/qeD16deX+5sDbKSdaeRmE+Bh1Vj2lN6rtgJbpqEA/kCPJW66t1EprpL Y/kHN5S5EUsfA== Message-ID: <24c88c4f-aea5-1fb7-0ead-95c88629d72b@marcan.st> Date: Tue, 16 Aug 2022 15:28:50 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Subject: Re: [PATCH] workqueue: Fix memory ordering race in queue_work*() Content-Language: en-US To: Linus Torvalds 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 References: From: Hector Martin 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 2022/08/16 14:52, Linus Torvalds wrote: > 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". This is the same reason I argued queue_work() itself needs to have a similar guarantee, even when it doesn't queue work (and I updated the doc to match). If test_and_set_bit() is used in this kind of context often in the kernel, clearly the current implementation/doc clashes with that. As I said, I don't have any particular beef in this fight, but this is horribly broken on M1/2 right now, so I'll send a patch to change the bitops instead and you all can fight it out over which way is correct :) -- Hector Martin (marcan@marcan.st) Public Key: https://mrcn.st/pub