Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp1525733lqp; Fri, 22 Mar 2024 19:57:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVUQBonVS7RtbWKYFtHHX5rHXqC2x1DM2EftnA/x2A2eXaAuCl9fT3g5LPyFS4D8H3mJy0bcHI1quRxOdIO1mxb8BzvYVetQW+6d1C4Fw== X-Google-Smtp-Source: AGHT+IHKd9Ofa4Y982PCd8l0n7O7EzTQFeh1pD+x5BTFyCQuy/JqoBaRqEWh8pUleBOnGyu/K3l8 X-Received: by 2002:a05:622a:12:b0:431:3f65:a55b with SMTP id x18-20020a05622a001200b004313f65a55bmr708121qtw.0.1711162661412; Fri, 22 Mar 2024 19:57:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711162661; cv=pass; d=google.com; s=arc-20160816; b=P2OF6gNz5QLlb6fen7f7FqLIWfW/EyDxvApcfK2bVjp7LnYZIuns9JDel8y5Fl+pHL +rGOk9KTsIgj21wCja/ef+m2vH3nzpJ8lKy33ygjGAMk1af77EAs9/qH+Fxbya1tMwHR uYRc85jDS5cTsjwmziZHZL+LJBgkl3aqgCqCoe4W0dK8CeFQnbMITKw2crW1bGnk2n2A Y6hY2I2IZw26nLJou6UEoCAWaH8vAjdMafN1L3aPbJ5LA0G61pBJX/KGmY721qVrV7/t fidntZj3NTDxE21fYQRVwoexu1C2IHQXFIQjx8FqsQW9NcO1gXvWon7zVfOEqLSQPsD+ pdCg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:feedback-id:dkim-signature; bh=kpSl8o7jNHU35uGRWAm6lGoxX/v+3hFWNREiHEQrRxE=; fh=yxJPGlXST/ALXNtBxh0W1V9L3vt/F7i4t1muGM8Bu4Y=; b=oHqJe/3JT1D46JNA3wI6FyPwM7EQR8/94sdBI4GUCZjQJVH+nPyLwgnvr62yicdB/K baKyM1SAciug1URa4EQlIPd/2n4bM56QyJiJ9aWuSM8mhdDG8iaaJPslwvNHj3m+vRPj vhZf6ERFT9t4DIdRlNxIMdlsOeIgdHokEDEJPbMQFVP0+2aJYfuN6ZP//y9DoJe5iDiE 4bqQjnCgxBsHQpjZAtY1/3JWkjswPsHnxAXSdEM/FNq6GkmEPo8+5jStM871859BKOG+ nBG1voi2cvgyr5621zIQh/Ahu2LaaUAe852eNdq59ha4r7UtjdYoJVluMNeTMS1/90fQ g/Gw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Nw5ZN0aK; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-112193-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112193-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id bv25-20020a05622a0a1900b00430dccf24f2si986123qtb.751.2024.03.22.19.57.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 19:57:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112193-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Nw5ZN0aK; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-112193-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112193-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id D5AED1C21BDD for ; Sat, 23 Mar 2024 02:57:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3B1014C6B; Sat, 23 Mar 2024 02:57:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Nw5ZN0aK" Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) (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 8DADB10E5; Sat, 23 Mar 2024 02:57:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711162647; cv=none; b=LHhU1kue9ytgkBVODLQbbCSimMRKKxFKrCAm9sfTljXrNkHzclCv75vNbay1QhyD+SbY6Q3ayTxIUMqV9vURWeck57+6XQZaqiJtrfGGCwz+zS5DuadmKSGhU1nofYc6RkisaeZn6HwbAaNnJStLbNSedJfEV25W9np2rvxc2Mk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711162647; c=relaxed/simple; bh=vpZhcowLAm3Dy6FfbLwUZs3OgFJBOZ6DIZw//2d1m3k=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JMv3+EKX5051XwkonLraYiWXWhYIr2k2jgYR3sGI0OUQ1ximGqK4EMiTMdMyPBamYK8bREWT1xnADU5uR+jTv3rVsxCM+ufxYHSdaL3cQeUIMLCVTl6q2kZeeze7XIIof9oSWUDAvVRRTqKZ3fMDRJGnT0n58b5uWSMOkNYhkuY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Nw5ZN0aK; arc=none smtp.client-ip=209.85.222.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-789f1b59a28so183654185a.3; Fri, 22 Mar 2024 19:57:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711162644; x=1711767444; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:from:to:cc:subject:date :message-id:reply-to; bh=kpSl8o7jNHU35uGRWAm6lGoxX/v+3hFWNREiHEQrRxE=; b=Nw5ZN0aK7HCFRA9u+ddgaPbKBn6Zxe85nbnyfMVkITRLhThSIOf55ElxEo/1TogED5 DxwYPCwm5VRsjMLOj9YCBzRP8ytiYcOXromCTG83wifXeZTEc5eKTWbH4+LsNgQMQxzz 1bh5Ik0LDc/xKiI7srcAdO/AAfPcR5MKBk8WAy1Sbaw/BQUY8F9kbCssFf8oP1HbmvmG ZtringrOGtdLXs/LPpMVFWh83cgrDsmEZ8zmZfZkYVJAK45OdfuUB6i3pOfnByfUHslK KTFxq1zNuvogiZMD8O7j0xc79gerPZDDYLtaNrPIrASUOEVea2oIbitkX+MLw0ltjfyE Dnhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711162644; x=1711767444; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kpSl8o7jNHU35uGRWAm6lGoxX/v+3hFWNREiHEQrRxE=; b=ksHl7UwUB6wTWPRISSt78Meq5ZP9ZX/0nNikWhpkm+57EVZN8JXO6lgCo2MTg1bcdu e3oT83bRSfZGWe3hMUuIEkc+YMrCFw2zqMnaw+EYSHveollMIwbZ+WOdv6zmshdGNdtJ 5YNYBGezAC9EkjN51dJFrZAdytGjYIBAk5bFOmf9q2UPq+T+fe+Jjvhi6Prdmz4K5PC4 vWGYbLSsxzUtJtczQjqz+zT+gDaNUqimeAZF/Ud8EF8waJaW2sQHKB10k3qTKBKWrfn2 1uHbO6JZWMShqiOpX7q/+xDS7HPIqeatcwIs2UxeWwFvDQuv+ArG7rXFXPcD0UZ3vkW6 Y9FA== X-Forwarded-Encrypted: i=1; AJvYcCUskpDvADa27vKrXrSgdTcpskUCbwumtSC4cmkCrk6290lc3BFbtlsb9M9faj5tMvp10K9YEBXuHgSSmQhj2ptsNEC/6Jsfsdi7JfylzGtON6opHrfyu5X4Ix8AtZHVTx/JGYsk7hfYEkL6UbVd6cww4YvKtjLWjv3ZM5bdqwsUpJ5V6FaKNlnHDR2GJsTlRDvYR6K+PKbggQkIORTZwIrpi8TmoMF4wQ== X-Gm-Message-State: AOJu0Yz67gi3NAixf04AaP+paf3MrhUqbpN5XZOQAvD3OORjReT13Gds 9rK49MIdAX7ILLZJ3w6VGETaLBiyDAto+8qu1d2UXaqtM0EHJQaM X-Received: by 2002:a05:620a:a93:b0:788:12af:3f0e with SMTP id v19-20020a05620a0a9300b0078812af3f0emr1255744qkg.56.1711162644512; Fri, 22 Mar 2024 19:57:24 -0700 (PDT) Received: from fauth2-smtp.messagingengine.com (fauth2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id h26-20020ae9ec1a000000b007886b695939sm363844qkg.118.2024.03.22.19.57.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 19:57:24 -0700 (PDT) Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfauth.nyi.internal (Postfix) with ESMTP id 1006A1200066; Fri, 22 Mar 2024 22:57:23 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Fri, 22 Mar 2024 22:57:23 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledruddtfedgheefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepuehoqhhu nhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrg htthgvrhhnpeevvdejffefgeffhfelffeikeeigeehjeekgfefudeugfejfefhteekvedu teelhfenucffohhmrghinheprhhushhtqdhlrghnghdrohhrghdpiihulhhiphgthhgrth drtghomhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhm pegsohhquhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdeiledvgeehtd eigedqudejjeekheehhedvqdgsohhquhhnrdhfvghngheppehgmhgrihhlrdgtohhmsehf ihigmhgvrdhnrghmvg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 22 Mar 2024 22:57:21 -0400 (EDT) Date: Fri, 22 Mar 2024 19:57:20 -0700 From: Boqun Feng To: Kent Overstreet Cc: Linus Torvalds , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, llvm@lists.linux.dev, Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , Andreas Hindborg , Alice Ryhl , Alan Stern , Andrea Parri , Will Deacon , Peter Zijlstra , Nicholas Piggin , David Howells , Jade Alglave , Luc Maranget , "Paul E. McKenney" , Akira Yokosawa , Daniel Lustig , Joel Fernandes , Nathan Chancellor , Nick Desaulniers , kent.overstreet@gmail.com, Greg Kroah-Hartman , elver@google.com, Mark Rutland , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Catalin Marinas , linux-arm-kernel@lists.infradead.org, linux-fsdevel@vger.kernel.org Subject: Re: [WIP 0/3] Memory model and atomic API in Rust Message-ID: References: <20240322233838.868874-1-boqun.feng@gmail.com> <3modld2dafaqjxa2b7jln47ws4ylzhbsvhvnphoklwvzange5p@wlir7276aitp> <34r4signulvsclmsiqgghskmj5xce3zs5hwgfulzaez2wdyklr@ck6zrj732c4m> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <34r4signulvsclmsiqgghskmj5xce3zs5hwgfulzaez2wdyklr@ck6zrj732c4m> On Fri, Mar 22, 2024 at 10:33:13PM -0400, Kent Overstreet wrote: > On Fri, Mar 22, 2024 at 07:26:28PM -0700, Boqun Feng wrote: > > On Fri, Mar 22, 2024 at 10:07:31PM -0400, Kent Overstreet wrote: > > [...] > > > > Boqun already mentioned the "mixing access sizes", which is actually > > > > quite fundamental in the kernel, where we play lots of games with that > > > > (typically around locking, where you find patterns line unlock writing > > > > a zero to a single byte, even though the whole lock data structure is > > > > a word). And sometimes the access size games are very explicit (eg > > > > lib/lockref.c). > > > > > > I don't think mixing access sizes should be a real barrier. On the read > > > > Well, it actually is, since mixing access sizes is, guess what, > > an undefined behavior: > > > > (example in https://doc.rust-lang.org/std/sync/atomic/#memory-model-for-atomic-accesses) > > > > thread::scope(|s| { > > // This is UB: using different-sized atomic accesses to the same data > > s.spawn(|| atomic.store(1, Ordering::Relaxed)); > > s.spawn(|| unsafe { > > let differently_sized = transmute::<&AtomicU16, &AtomicU8>(&atomic); > > differently_sized.store(2, Ordering::Relaxed); > > }); > > }); > > > > Of course, you can say "I will just ignore the UB", but if you have to > > ignore "compiler rules" to make your code work, why bother use compiler > > builtin in the first place? Being UB means they are NOT guaranteed to > > work. > > That's not what I'm proposing - you'd need additional compiler support. Ah, OK. > but the new intrinsic would be no different, semantics wise for the > compiler to model, than a "lock orb". Be ready to be disappointed: https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/is.20atomic.20aliasing.20allowed.3F/near/402078545 https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/is.20atomic.20aliasing.20allowed.3F/near/402082631 ;-) In fact, if you get a chance to read the previous discussion links I shared, you will find I was just like you in the beginning: hope we could extend the model to support more kernel code properly. But my overall feeling is that it's either very challenging or lack of motivation to do. Regards, Boqun