Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3021385rwb; Mon, 15 Aug 2022 16:18:40 -0700 (PDT) X-Google-Smtp-Source: AA6agR6edjC4y5QKxY+SLQ4FTlCiFfhEtZ2spFOfG0opq6eidZ+kb0lZaHEKNuvPiHjkzs8z4jxN X-Received: by 2002:a05:6402:1d55:b0:440:7104:240c with SMTP id dz21-20020a0564021d5500b004407104240cmr16615586edb.207.1660605520196; Mon, 15 Aug 2022 16:18:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660605520; cv=none; d=google.com; s=arc-20160816; b=a+skRoklYYBRzJadbs0T+pPu9AcE9vH7d2RmNa4gU0BdqMgkIBdU7Uv9ul3jP6JdmX pQAiiTHdWa5u0ZNHBGe8rW0Ha6or0DtRRcGWB78v1TMJYkXW04ScqKpTQKD/U3kgvXlo FhTt06Z9WCDXwhi1dW5v05/8DUW46jtUakzkpv4qPHi0fwy0CADI+RC0ktCHxmE8OTOY M5DtVARoqM+sn2OuW6WS9ZPeJqrGlnQ5c8yq7s32O7xJfhC9/eSWw2ioOT833IKhA9dM tIvBNi5jZjDSFHlrqjqimT24kQVWyj8StV7uRugvmjAx9BlVLC0K7z5cEBBigZkxJdO+ IoWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=9QzkD1r7Z2AxBwRWsq7AvaSoMqrd2iT90cH3Q6yYS18=; b=cA5HmkMTjnssTc9WCkridTEgsaklQ6gSGnuftIIguePJbaJS5EQNr4Ifg8na9zALpg I2EIhDmWz6Exn5+tlG8QI4jtiR0L+VMdRNOudla1ToaLPDT6yObwzpcK8VWJKk/o1Uah OtD5tQwo1hPTjCqlMFj3aIchWbq3sCQqCWEFJY6SRwH97rJl43HKgpvcljU/8RSAyH+W NvVALRweHBPOkqiH97wIJG8kLm754WAcBIYiiSizFXatD4pCOwGX4tU1nKZ2k+AVjl5j q2blAYVMwQ5dt3x2QrRSx3HgEgD/OS3mFt/g6hRdT1aiFFiDhNaTQPGs3APWECdDtxnS qAKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=kT3Ho+pN; 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 l10-20020a1709066b8a00b00726c7fc61dfsi7686119ejr.103.2022.08.15.16.18.14; Mon, 15 Aug 2022 16:18:40 -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=@infradead.org header.s=desiato.20200630 header.b=kT3Ho+pN; 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 S1344671AbiHOWOV (ORCPT + 99 others); Mon, 15 Aug 2022 18:14:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350296AbiHOWMD (ORCPT ); Mon, 15 Aug 2022 18:12:03 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B805711C945 for ; Mon, 15 Aug 2022 12:39:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=9QzkD1r7Z2AxBwRWsq7AvaSoMqrd2iT90cH3Q6yYS18=; b=kT3Ho+pNVZj3d2wQZJbx8/jmdR 3b1dVFURYZg8t52HmHPCOIrFOToVT0hN6FALvZ1UZzG243Gyfuw8iQM3L1kFsg755r/SElJNtIO69 3AO/JCDTno8+/IqhgKzIxIv3MYqy3y2oOH0PwDxfKbMcyBnrHuifJb3CTQp5s1iolByb7Gu3ssjZ/ VEnQcD8WRlp29mDH9NBw2oDjyn1Bn5lreTp2QmtceGIrJDIKDviS4wEd7r0E9KH7Ns20s3dcmQ+9a TQbCP4t6zh/Mq2o8EIt5QvFcj8QRJm4iBhsXP4vzYHUrlKDXwLOL4afWGNJQ9TDPJPs5ZEVBFdfgj daGwkqOA==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=worktop.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1oNfvB-002kMX-R2; Mon, 15 Aug 2022 19:38:46 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id 57D35980264; Mon, 15 Aug 2022 21:38:41 +0200 (CEST) Date: Mon, 15 Aug 2022 21:38:41 +0200 From: Peter Zijlstra To: Hector Martin Cc: Boqun Feng , Will Deacon , Linux ARM , Greg KH , jirislaby@kernel.org, Marc Zyngier , Mark Rutland , Catalin Marinas , Asahi Linux , Oliver Neukum , LKML Subject: Re: Debugging a TTY race condition on M1 (memory ordering dragons) Message-ID: References: <6c089268-4f2c-9fdf-7bcb-107b611fbc21@marcan.st> <20220815134711.GA10374@willie-the-truck> <63cd54a8-3c48-d1b9-406a-c521bd02ee4a@marcan.st> <8ccfdd2d-ef77-4586-e50c-985e1d13726a@marcan.st> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,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 Tue, Aug 16, 2022 at 04:15:00AM +0900, Hector Martin wrote: > FWIW, I didn't actually use a full barrier in my patch. I just replaced > the test_and_set_bit() with the underlying atomic op, sans early exit path. That isn't quite true; you used atomic_long_fetch_or() which is used in the generic implementation, but x86 would end up using "LOCK BTS" for arch_test_and_set_bit(), while atomic_*fetch_or() ends up being a "LOCK CMPXCHG" loop (which is significantly worse, performance wise). That said; I don't have a nice solution that works well across the various architectures. (in one previous instance of this problem we ended up using a cmpxchg_relaxed() coupled with an smp_mb__before_atomic(), but there is no relaxed version of test_and_set_bit())