Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp1519801lqp; Fri, 22 Mar 2024 19:33:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVqhOE+bN/8rrCiBcMsRIXhnPpJ2tSD8mXWTakgvOQuqNmYuhDyK8w/QuvLYat0yVbEM7edW2aQmVZiUZ0oj4NICTonuBXmo8AxCBrguw== X-Google-Smtp-Source: AGHT+IGSxDJzQYL8rsYTmDvMam/1WanaVookU/8oWYsku9Sm47a08aUnxyFN1QWlPIBiT1KmNWTV X-Received: by 2002:ac8:57cf:0:b0:431:442b:df0 with SMTP id w15-20020ac857cf000000b00431442b0df0mr18556qta.6.1711161220885; Fri, 22 Mar 2024 19:33:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711161220; cv=pass; d=google.com; s=arc-20160816; b=L+MLjRXLESa6b7qNYP2xcs2YWAZKHwVsIFnQdn3opNuFa4hSHsl6EtB7646K1PI/xE KXQ/61yqE/g2YwJkPTJm8HMK7YJ89BM+gI3f5vBKyC7xamC5hksiDGkQ25FtuJ96ckUv qdEtgP8UMDJmdPzbXwvm7p1ttS6NLywurmHNJFjkhXEXZlM0ZnjN/3/PUV4xo8MwrPOA Xr0WJd4iepG+vbBOOpQ4/QyDEBYTzxE8C3siZxeyg3Nh6b6zBiTp+SJ6VdWjXxmjBs8v ZTdLAofFpSX4JUdpoRw6p+hMF9rZM9hK+GsV6GeV43Yd+SHZi7ozeHcxtblISwipskKI qx7A== 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:dkim-signature:date; bh=dGiRxMGRKYQMRfH49RA51pj9cBv1uQC8JISxFiAALsM=; fh=7GtkrGMbvqMq516zkYdg0b+b6arxeTWND55dXWnl/z8=; b=Z9zk40Hb1OWB4O6Vo1f/bENbqpwbHQS4J1l96muvYTKQbj7AIizbRmZyAEEqtBCSgn lBJ1MwObyA/7lx1Z89sCBuj4XMMCask8UMzdQ3tvrwUVyTLV3Fo+HeNZrxQETs4VxBfo 4QYbY3yLhhrD6+vfCG1VDJHaVEFIPfDo5DLeXF/h9xAZiUZGN6CffMTkWHX40tId/s9I aDzWIK0cTeFe8CZwdzDj3URdrbKzXqjJIzWDgd57Rvqh7Rm5n3BebSAA9YfYg/fCW2qj pvNgib212Txz874s9Vr9gUmbwqUDJaGUoc9285siiA5T/9IVv3y7krS+3E6YqW2pNV2e XK4g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=xmoGr6Zy; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-112184-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112184-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id t12-20020ac8588c000000b0043128709117si928038qta.0.2024.03.22.19.33.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 19:33:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112184-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=xmoGr6Zy; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-112184-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112184-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev 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 937171C21B31 for ; Sat, 23 Mar 2024 02:33:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 815444A12; Sat, 23 Mar 2024 02:33:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="xmoGr6Zy" Received: from out-174.mta0.migadu.com (out-174.mta0.migadu.com [91.218.175.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0580E7E6 for ; Sat, 23 Mar 2024 02:33:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711161206; cv=none; b=VRM0JIGDG0Ys2g4fblqe4PHM/5ufHOok2VdWfG+A9jRjIZ2tlrqSbIceDO2FXLdgxL6Cq3TSex7meIozzu5nYi9K12kRCrAL0ooj4PSbxiSQPx2gLEVuvA/Pf9yzsmC53tvDvL3FyitXv/xgA6XKbH+aw7y0FDS3NwSbAwkoqBk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711161206; c=relaxed/simple; bh=34TWMNT6M0hd6HGrpS/KoKUmis1d5YNlXoP1KScGnUQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=H1vO5+7Xb6f5pvabhx6jorOkJHuomKDTTIjJXjW+Ht12/mP1yLuKs1NGgaXvF86/LJiK7hNLDzgiION1eWPlSt4tg8SwRxgQ4SdSIZReolsXP8RYPTf5TxgtUQy3JPNebXdLH0sRgc9ZsQ10TI+K1nrbuFAQa8LxZvuRR8xRIwo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=xmoGr6Zy; arc=none smtp.client-ip=91.218.175.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Date: Fri, 22 Mar 2024 22:33:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1711161201; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=dGiRxMGRKYQMRfH49RA51pj9cBv1uQC8JISxFiAALsM=; b=xmoGr6ZyTaRZLl83NHpBYA88BVWCxbSMGBYrs8r5D714hM3UEvZXAUpBN3vIJm8tmz2GLr T3y58i66roDsXvtXdR2y13/D9BngQutwTbLlD6Y7Fb0fVnuUokJb9XyJX0jEMID9lYp3ph 8gUcfF+qotI0cy/V3ReJqUXnsbltt9U= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Kent Overstreet To: Boqun Feng 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 , =?utf-8?B?QmrDtnJu?= 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: <34r4signulvsclmsiqgghskmj5xce3zs5hwgfulzaez2wdyklr@ck6zrj732c4m> References: <20240322233838.868874-1-boqun.feng@gmail.com> <3modld2dafaqjxa2b7jln47ws4ylzhbsvhvnphoklwvzange5p@wlir7276aitp> 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: X-Migadu-Flow: FLOW_OUT 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. but the new intrinsic would be no different, semantics wise for the compiler to model, than a "lock orb".