From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A137AC28B2C for ; Tue, 16 Aug 2022 06:30:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To: Subject:MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FdC01qqC/B2ZeIapHK7QNH396t8lbZ2rV+a7Nes8ors=; b=vvjRVTVfXUc+SQ hGx0FB5IJepcyB46vkLlbxOHED8ol2bk2c4cyJHbmJ9+QN/gBlRjxnaBPxzxFfvt0jprmzuYkCvlH 4VKSjyRVcKpl25e1zYuqKNvx+5KXycTv+vIqhmdJg+EcdKRgRHVTkr3peAiECojUdr3AJtm9NxcQs l+T5dCsifVNwzX7CEDEh58+k+tqzIbmeOirdRnoq38zf/tcHBxW29yixYZZj2hpqE4y+hHqWcjFTy Nxbhxf+pC7Az59/4OWyT6vhzzLQti+xU11lHl54vx+x0jrPOBaaV2Gj3SICyxXXfjMyrHI+CGCVNE ATvNLpYaXN8B3ZHFWdhg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oNq4m-00DgLG-Ms; Tue, 16 Aug 2022 06:29:21 +0000 Received: from marcansoft.com ([212.63.210.85] helo=mail.marcansoft.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oNq4T-00Dg3X-Hc for linux-arm-kernel@lists.infradead.org; Tue, 16 Aug 2022 06:29:04 +0000 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: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220815_232902_471176_FBE9B5D3 X-CRM114-Status: GOOD ( 18.62 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel