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 62458C25B0E for ; Tue, 16 Aug 2022 16:23:51 +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=fZ89QudW+BvyYpqbAwJIgaXhErjtY/spHACbSa4jgXo=; b=Pwp6zqtqxxy8E4 DVX9AHA2SRZ0/Z2E6JdH75rXKKYqcDkw6pxASELnDW8cAbOUUlPldXk+llezjySfp2n3ScaUCnvPI WImQPlbe0NIXJbLoHWfQ7i3L9mdk/VGplDyjBQU7/Xz1Bf5/EdmPd4HSX6wzYOX13mciPEnb1bBo9 LOE9IRF9mDc3cBT5K/iZmoLuBFT46FAmbFEzqIri8zRnmyg/WakJudK844BcQx0uAE5aS5TLnkdH5 dWDH1LCQNKzrDxI+b//m3WdJRCEDApO5GCceP5jlyyL9pvMQq2ir4hsVAZORILzHFhTsDoxERggif 4f5UizSzto0D3DA2WcYg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oNzKm-004W2b-Ee; Tue, 16 Aug 2022 16:22:28 +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 1oNzKi-004VuE-8O for linux-arm-kernel@lists.infradead.org; Tue, 16 Aug 2022 16:22:26 +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 3924C41A42; Tue, 16 Aug 2022 16:22:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=marcan.st; s=default; t=1660666936; bh=v9Eb3B2oIUOczoWOpMilc4gFuASbH6f5NiE3832J0GI=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=xk494yGeO5UkuZpnlGKL4Nq9gERUn/CyV0L3S9M62tv6t3TPQQaFKl7aW+F+VPjQs J6QUP88yR2MiznuQLMSvrWKeTx2/ReGUdOwZK8D7jsqdKzeljMCpL6wv2TeuXRyxr0 4V1bqb3dG0XT9RpNkB9F+csP/ao0gEVjf0a9g+USUXdkbFgoGpHh6CworlZMGnD/cv WA4Bai1qkDK1vJ8mIcjdGqq6mJm6Y/IhUZHvrvUMYg7CMI2ekXAhbeVdHH6ZjEgpth 1Hyl9rNt++q4bx6l9Z07aUaPmsT2MKK5xLaZJqCsnPkKeKqCbvzxicZEYbOmbQWan0 r8CB7Gu3o92Yw== Message-ID: <74559da4-5cd4-7cc4-0303-ab5f6a8b92ae@marcan.st> Date: Wed, 17 Aug 2022 01:22:09 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [PATCH] workqueue: Fix memory ordering race in queue_work*() Content-Language: es-ES To: Boqun Feng , Will Deacon Cc: Linus Torvalds , Herbert Xu , Tejun Heo , peterz@infradead.org, jirislaby@kernel.org, maz@kernel.org, mark.rutland@arm.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: <20220816134156.GB11202@willie-the-truck> From: Hector Martin In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220816_092224_721359_9CAD5F22 X-CRM114-Status: GOOD ( 16.48 ) 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 16/08/2022 23.55, Boqun Feng wrote: > On Tue, Aug 16, 2022 at 02:41:57PM +0100, Will Deacon wrote: >> It's worth noting that with the spinlock-based implementation (i.e. >> prior to e986a0d6cb36) then we would have the same problem on >> architectures that implement spinlocks with acquire/release semantics; >> accesses from outside of the critical section can drift in and reorder >> with each other there, so the conversion looked legitimate to me in >> isolation and I vaguely remember going through callers looking for >> potential issues. Alas, I obviously missed this case. >> > > I just to want to mention that although spinlock-based atomic bitops > don't provide the full barrier in test_and_set_bit(), but they don't > have the problem spotted by Hector, because test_and_set_bit() and > clear_bit() sync with each other via locks: > > test_and_set_bit(): > lock(..); > old = *p; // mask is already set by other test_and_set_bit() > *p = old | mask; > unlock(...); > clear_bit(): > lock(..); > *p ~= mask; > unlock(..); > > so "having a full barrier before test_and_set_bit()" may not be the > exact thing we need here, as long as a test_and_set_bit() can sync with > a clear_bit() uncondiontally, then the world is safe. For example, we > can make test_and_set_bit() RELEASE, and clear_bit() ACQUIRE on ARM64: > > test_and_set_bit(): > atomic_long_fetch_or_release(..); // pair with clear_bit() > // guarantee everything is > // observed. > clear_bit(): > atomic_long_fetch_andnot_acquire(..); > > , maybe that's somewhat cheaper than a full barrier implementation. > > Thoughts? Just to find the exact ordering requirement for bitops. It's worth pointing out that the workqueue code does *not* pair test_and_set_bit() with clear_bit(). It does an atomic_long_set() instead (and then there are explicit barriers around it, which are expected to pair with the implicit barrier in test_and_set_bit()). If we define test_and_set_bit() to only sync with clear_bit() and not necessarily be a true barrier, that breaks the usage of the workqueue code. - Hector _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel