From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 49B9F1367 for ; Mon, 18 Mar 2024 16:33:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710779597; cv=none; b=YejobJFISnkGDJVyn6fE0qKBovuiihI42MCJgCijXIL/ngwzA5AS/t12X8jRu25HkQEChWdpjm2ax2ppU55XAEUeQpqn1pWBHE3BEl0pzZR8gu0WRG7YZ3cNCDloshe0U9892OidJnkxxLU8a47S/nogI97r1u6PIGF2H1tABts= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710779597; c=relaxed/simple; bh=ZqcrnYKejZwHfHmc4Of0ZS4uU03oOY4FKd3F4uKHMgI=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=XDOR/r2+DXorGtGr/2UgrRLrzgqureQX/eRU3iSpfjuLJM8Vb960ZFjcbLcymzKOtdkq8EwmBqzwtm/NlXjuhiX4fs0J/U0znEXRnh15N+seoebBF1ID2Uj5e3zBnya5Liq1oEIKy9Y3/+Gify3KRqF6Cj90JkQtSVBdi+9bv8s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org; spf=pass smtp.mailfrom=linuxfoundation.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=Miylbacr; arc=none smtp.client-ip=209.85.167.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linuxfoundation.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="Miylbacr" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-513ccc70a6dso7875722e87.1 for ; Mon, 18 Mar 2024 09:33:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1710779593; x=1711384393; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Csd1F43W5mUQQPhPfMy1JJBPV1LDTh07kLrNMjBi2N4=; b=MiylbacrT51EsgC0aPvWpCdsW2n3kaJA0x/e23jvo9A1M4z2bOnOM11+ueQTkGX51i rsrKLRxoLgtDoYpWXa/UhGpovuw+YqeoBtYYYdaHonal6EpyojSzbQXeUb1VLitsRFa0 Zosbp3tje4/auZa751Qx2dq1edqMr4slHcql8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710779593; x=1711384393; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Csd1F43W5mUQQPhPfMy1JJBPV1LDTh07kLrNMjBi2N4=; b=OavVgFTX5o/7JFGkD1z1dvYANiGdUdS8jtPM2OOz9n72GeMCq/NcPte9dDFHTyX/Dx TLtusK5gEQEoHJXO7Vl6Ly383+pfA9c3oIfkGhBulkjXhyt3Q04eaCRR0Il4clfZMV+O qsraVCRqq+h48RKV9x35Go+Z9hkBPtp9W39+1tkDRQMwJI21KmneakgDdMipHEADDoLh f4QFMHmkmGBBXnzzcfojbo6nQ3chzZhXSsa9wxXkXYGrjfegpMqsGYtcJZo0jl97PSJg 9VZWkCKV2gtA2VPyinRG7HEFVqMWzIbVdHWouFTxHMFiFsT/3+DxYCra7YuildaKyfWF 6Y7w== X-Gm-Message-State: AOJu0YyNHtAUm+lFMcYXAUHLBdIbKvTNtmPbWFuAD3VaU10HYC/YM07B b3LE/koyCN9X72DZ8S3EwWzLPhLbVolM7T+rZSaodyIND9UF33cROBPYrKdqriRwDfVKX6PupT7 Hcx6WVg== X-Google-Smtp-Source: AGHT+IGqlFrQvUTDBg9AHcZ3pQDmsBeK8cjlMXDVHzE2J3e6ur0KdT5xI1N5WMZWli3rCiVWkUyofg== X-Received: by 2002:ac2:4d9a:0:b0:513:d82a:8d3a with SMTP id g26-20020ac24d9a000000b00513d82a8d3amr5632081lfe.35.1710779593164; Mon, 18 Mar 2024 09:33:13 -0700 (PDT) Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com. [209.85.167.54]) by smtp.gmail.com with ESMTPSA id a10-20020a056512020a00b00513e5a52bc7sm617756lfo.35.2024.03.18.09.33.12 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 18 Mar 2024 09:33:12 -0700 (PDT) Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-51381021af1so6560189e87.0 for ; Mon, 18 Mar 2024 09:33:12 -0700 (PDT) X-Received: by 2002:ac2:499e:0:b0:513:e8a0:2d85 with SMTP id f30-20020ac2499e000000b00513e8a02d85mr3485157lfl.44.1710779592103; Mon, 18 Mar 2024 09:33:12 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-toolchains@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <83f5e119-6e32-415a-a1c8-8e6b0bd11a75@paulmck-laptop> In-Reply-To: From: Linus Torvalds Date: Mon, 18 Mar 2024 09:32:55 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: A few proposals, this time from the C++ standards committee To: paulmck@kernel.org Cc: linux-toolchains@vger.kernel.org, peterz@infradead.org, hpa@zytor.com, rostedt@goodmis.org, gregkh@linuxfoundation.org, keescook@chromium.org Content-Type: text/plain; charset="UTF-8" [ Final note on this, I hope ] On Sun, 17 Mar 2024 at 13:50, Linus Torvalds wrote: > > Now, on x86, this happens automatically, because even if you move the > "*p = N" down to after the function call, all stores are releases, so > by the time 'p' becomes visible to anybody else, you are guaranteed to > see the right ordering. Actually, I take that back. Even x86 (and s390) can see problems from the "move store past a function call" issue, although they require more effort by the compiler. Because while it is true that every store is a release on x86, and as such any store that exposes the address to another CPU will automatically have done the release that also guarantees that the value 'N' is visible to any other thread (and then the acquire will guarantee that the other end sees the right value), that doesn't necessarily fix the problem. Why? Once the compiler has missed the original memory barrier (that was in the function that it moved the store past), the compiler could end up doing further store movement, and simply generate the code to do the '*p = N' store after exposing the address. At that point, even a strong memory ordering won't help - although it would probably make the problem easier to spot as a human (and would probably make it easier to trigger too, since then things like interrupts, preemption or single-stepping would also make the window to see it much much bigger). So x86 wouldn't be immune to this, it would just require more reordering by the compiler (which might in turn require that the function was inlined in order to give that re-ordering possibility, of course). Linus