Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp1548177lqp; Fri, 22 Mar 2024 21:22:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXkA+FtMf9HB9hjwDQOi2OwzNHzoZI/CKWO0R/Fserkg74iST+xecY/2QEKm7jhXCEGpSh1Bfa5gS7uTpA/tUmREN0+Rq3vRU5KTTcQ/g== X-Google-Smtp-Source: AGHT+IFPRXgTCcgQbrgBLXWCXtqbtORW6HFjTFHPEoIIo4EqpoibzOuvWcxy2p/t9xY4EtUBAqDQ X-Received: by 2002:a05:6830:148b:b0:6e6:8c5e:b258 with SMTP id s11-20020a056830148b00b006e68c5eb258mr1751016otq.38.1711167779141; Fri, 22 Mar 2024 21:22:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711167779; cv=pass; d=google.com; s=arc-20160816; b=SsnIKErpeBGuLEYo/hv+3/MrCeDTPhMhPj3DtwQkx+ut4nZtHqbggm3WankIFnP+Yt h6Lt4ubz4Xc69roE5sqmtjeW6KdJaPKYAaaoD3259QleaKsnJOVWtliRRsrjHbnKQ0kt Ai3vT7CDwGQ5xBrEgjZpHI1lWFNp94lTuQFYqsUpeOSqVO8I++U3rjjdzrwkVT8KWSIR bkwTeI4qQdwKj1sFHMEew26hmOaNhROn+L+/NZJwTqY7fIRKgDTvXlsk+gNJvHUA7fYg TPLD/CKCayZcsQTCYmP42sA9UdMFXpA6hgsW7MJy0uB6LT4+ziZt0HGXBOJNHIhqOvZi t4mQ== 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=y0TVAH0ZYdb3ue+80a0C1DdjCsmM6e0n7TfPjNRdLqQ=; fh=7GtkrGMbvqMq516zkYdg0b+b6arxeTWND55dXWnl/z8=; b=edvnFwJ8TewjFtNgOjTWCQ4KznSi2YME4G1H6l8UDd4IsMrYYgHOhA/cjuqMLx4Dsv wsvwVDjl0nRlMBPFhLOHQnR1Y7IEwK11iP62I6ZxgMhGzjYhZbda56B1fcNTR72SQHYz gwV8dzt4yBElJR5bbMQIdM3Sir2KbWCYDkRaaU/JZF5W6G5OF9niI7UiovsbmKm3i190 1afQmhLUjKVAKY63HB/mm6c2XqRQ/RAiVFnmOjBVU8GbF9e7/lLC1dmESQpeZtnfcnCq ld9dh9uKrCkdzPyI/VWRO5z5Guw/1kxL0okzEGBz9XTkFKVHjmebYRX1qwiDE6yw6X1+ aKTA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=IDRcUmdN; 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-112223-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112223-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id w26-20020a63935a000000b005dbf27229f6si3242369pgm.343.2024.03.22.21.22.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 21:22:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112223-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=IDRcUmdN; 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-112223-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112223-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id F05E1284D75 for ; Sat, 23 Mar 2024 04:16:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 95B8B1A38C9; Sat, 23 Mar 2024 04:16:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="IDRcUmdN" Received: from out-189.mta1.migadu.com (out-189.mta1.migadu.com [95.215.58.189]) (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 52D3F4683 for ; Sat, 23 Mar 2024 04:16:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.189 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711167380; cv=none; b=mPfYIVEIpYhE1n5OMqb2+JY7aM3N1RVe5GtVLdAj5MI9pS2L5fLDfL6KadQy4vMnISqhVO3bl1Sy5O9c+QYYZN70HQYbZGyBQaeTPzztecFbGeXDavI4Y34IEVH5dstx7V7SXCfqO4fe0Bk0yXLPkavxoneU1OGzvHkVQiN4nJs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711167380; c=relaxed/simple; bh=oQwQPzepAo9xty2ZLMz/v4lfOpbZlyrOY1++1B41TBk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TJ9BchIehzRCvY+/ilSPbQd38zvUJsUho+aPf25io5+3PSfA67PoRWCDsPquY+cmzcS0ch3NEChWR2vziiCeTUVSNUYxs5m3rgSwO2pMgRd9eup0bPTWterlah7/51mmz97EYkEO5lZvqgAl8rp+03Z8pKus7kn+S87XgQ0Ajqg= 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=IDRcUmdN; arc=none smtp.client-ip=95.215.58.189 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: Sat, 23 Mar 2024 00:16:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1711167376; 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=y0TVAH0ZYdb3ue+80a0C1DdjCsmM6e0n7TfPjNRdLqQ=; b=IDRcUmdN8orWoZ4O6XUTc0cdl71Ze4mloh1oBhIoF0zrSqXDQomr/bG5vKi/fR9JnYYoPv Rk4vAube+jtJ/qUZcGEgFwatJoO7CRYtry2xosgiRsPu5tsnK4eT43YGs2Jtd3JyJTAPfP E9PqylE35oFyzjlsZnYy+uumLQPen6A= 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: <4ciizx33vzooa33ikjn7env6kvkpcv44dsawm4i2avqou2kdk4@b4hj6252l22l> References: <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: X-Migadu-Flow: FLOW_OUT On Fri, Mar 22, 2024 at 08:51:03PM -0700, Boqun Feng wrote: > On Fri, Mar 22, 2024 at 11:10:36PM -0400, Kent Overstreet wrote: > > On Fri, Mar 22, 2024 at 07:57:20PM -0700, Boqun Feng wrote: > > > 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. > > > > That's casting - that doesn't work because compiler people hate > > aliasing. > > > > But intrinsics for e.g. > > __atomic32_read_u8(atomic_u32_t *a, unsigned byte) > > __atomic32_write_u8(atomic_u32_t a*, unsigned byte) > > > > so "byte" here is the byte indexing in the u32? Hmm... I guess that'll > work. But I really don't know whether LLVM/Rust will support such an > intrinsic... They're going to need this eventually - really, entire structs that can be marked as atomic. Types aren't limited to the integers.