From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 DD2A213C81E for ; Mon, 25 Mar 2024 13:57:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711375028; cv=none; b=IHYCOIq6ia1dRLGFQmOOwOM4lPXeK4VH5pwjNpF/REbqsTurouGeTy74VabI84FUaUMs9I4iUeAUndIO0Lhyxduru8KicJiZAQQd28R3weZ1LQjP8469wam4MBPmj2bCtF2l6Sc6mrsmmX6R7tXm7fTPHL/+IjnEH0rnbNzwpQc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711375028; c=relaxed/simple; bh=Su0oRSDMDN6WKCvVoRZlpj1EX7RmBmcvnQ0SRJYHWr0=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: MIME-Version:Content-Type; b=UyaXzmOcDLv9ZR9FrDgEufb31s6kbeSTBWDAyp0quheg6UtKPwZJoERmomIVtRpQ9NkS34QYICQ5iVI31cSKaRBQWa5yBNu1Lst8bt728bkly7CkjY1qiRkk85aMcXjQFiqw7hCCPPPXT3W3AXC2y2IQW0oV+OVa4c3wQnN6dQM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=aEMugEbk; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="aEMugEbk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711375025; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Su0oRSDMDN6WKCvVoRZlpj1EX7RmBmcvnQ0SRJYHWr0=; b=aEMugEbkulQEEQjmk1XhINUNj04ER4yYwKBpTJ4PkPSfJ/qe3yiAwW7KlDWlITElNrdQkL Hqvt5+6Qnroinma8jGFgu4o9l6No0hV6CUTBUJilOZJjkHEkCXdjy/iaD/qHPDx+BKzehS 4Nh4i6eVRslN/GOYcf6jsMhre0yxdfg= Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-614-NPbNGDGJOQ2jtbu-UDEutg-1; Mon, 25 Mar 2024 09:57:04 -0400 X-MC-Unique: NPbNGDGJOQ2jtbu-UDEutg-1 Received: by mail-lj1-f197.google.com with SMTP id 38308e7fff4ca-2d6c5548f93so5085861fa.0 for ; Mon, 25 Mar 2024 06:57:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711375021; x=1711979821; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Su0oRSDMDN6WKCvVoRZlpj1EX7RmBmcvnQ0SRJYHWr0=; b=Glic0OQ97MbxTg0nTjbSe0heKBab7C2Wg/wKDaKREYmiEuX1mYHDe/01zo0PV2MeWM nILDd8LkkJyVFBq6Wt7zv2jtcd970MtjnQE5f8DxqGEZ8qEyRyjWB/ZVngynSNKwFP6J MMLFC8JUkF+yUQ95Xq5T9c3pwGUMGTxJzwgV0RXT8/5rF3pe9bHbA3F4NqlLcL8b8e4G H5M6wxB51D5f+I6BOjQ9+96eaIYlLNU47ZMqyjnUvReOGj1NJljcvsdbiK3PrvQ9koPd Hc+/cVf/rKCtvyUQD1cYANr/o6SGXkyg2i2fEA8zaktMPiomlHUIDd/ZtTw/tLw31Bha Wtww== X-Forwarded-Encrypted: i=1; AJvYcCV2s7OLvvP9cpu8FYbxeGy/4ANfEbgwaN+rkVzajj0aYTrrQnFquZv8ywW5hjH2/fuffGvmHuB1c2XOco5mewDyR4dFvJ0R4rnakVLN3/8= X-Gm-Message-State: AOJu0YyMQM44///jpgwboH25nTiTq+asoynid2q5PIh7QCaCR5MMxmCn hj4dSR0ssnrw7Cod9AcEfg8D6/IiMsIIoaALL2ujt36dShRpa+IZpV0UX5poVxd4TQbhLyw6Qh3 uzaHXW8qQXX+bi2U+WY6KXSgPOzSVyjN1BuvolOBMeD+qQ5TuvYB/1+XPQI8M3FC0 X-Received: by 2002:a2e:88d0:0:b0:2d4:78b4:e568 with SMTP id a16-20020a2e88d0000000b002d478b4e568mr4342014ljk.1.1711375021350; Mon, 25 Mar 2024 06:57:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEsEsxChr4oIHfPIiuFPvTM+72aemZNo0G3gI+fLGhTYtrb+QS9VpjMdi/YbUXjC7EP1XZSIg== X-Received: by 2002:a2e:88d0:0:b0:2d4:78b4:e568 with SMTP id a16-20020a2e88d0000000b002d478b4e568mr4341961ljk.1.1711375020848; Mon, 25 Mar 2024 06:57:00 -0700 (PDT) Received: from pstanner-thinkpadt14sgen1.remote.csb (nat-pool-muc-t.redhat.com. [149.14.88.26]) by smtp.gmail.com with ESMTPSA id n3-20020a05600c4f8300b00414887d9329sm4600055wmq.46.2024.03.25.06.56.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 06:57:00 -0700 (PDT) Message-ID: Subject: Re: [WIP 0/3] Memory model and atomic API in Rust From: Philipp Stanner To: Linus Torvalds , Kent Overstreet Cc: Boqun Feng , 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 Date: Mon, 25 Mar 2024 14:56:58 +0100 In-Reply-To: References: <20240322233838.868874-1-boqun.feng@gmail.com> User-Agent: Evolution 3.48.4 (3.48.4-1.fc38) Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, 2024-03-22 at 17:36 -0700, Linus Torvalds wrote: > On Fri, 22 Mar 2024 at 17:21, Kent Overstreet > wrote: > >=20 > > Besides that there's cross arch support to think about - it's hard > > to > > imagine us ever ditching our own atomics. >=20 > > [... SNIP ...] > >=20 > > I was thinking about something more incremental - just an optional > > mode > > where our atomics were C atomics underneath. It'd probably give the > > compiler people a much more effective way to test their stuff than > > anything they have now. >=20 > I suspect it might be painful, and some compiler people would throw > their hands up in horror, because the C++ atomics model is based > fairly solidly on atomic types, and the kernel memory model is much > more fluid. >=20 > 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). >=20 > But it actually goes deeper than that. While we do have "atomic_t" > etc > for arithmetic atomics, and that probably would map fairly well to > C++ > atomics, in other cases we simply base our atomics not on _types_, > but > on code. >=20 > IOW, we do things like "cmpxchg()", and the target of that atomic > access is just a regular data structure field. >=20 > It's kind of like our "volatile" usage. If you read the C (and C++) > standards, you'll find that you should use "volatile" on data types. > That's almost *never* what the kernel does. The kernel uses > "volatile" > in _code_ (ie READ_ONCE() etc), and uses it by casting etc. >=20 > Compiler people don't tend to really like those kinds of things. Just for my understanding: Why don't they like it? I guess since compiler people have to support volatile pointers anyways, temporarily casting something to such a volatile pointer shouldn't be a problem either =E2=80=93 so they don't dislike it because it= 's more difficult to implement, but because it's more difficult to verify for correctness? P. >=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Linus >=20