Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp148551lqb; Tue, 16 Apr 2024 11:13:12 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXVZZ5VKFjd9Wp4BlKbXJzNWWYDwb8+DVUDVRYTcf/wXT36sekSDjhpOtTzbPLamIrc51FnUxZd9/X2svH+NfpXQONZoVSCKh09p3vWTg== X-Google-Smtp-Source: AGHT+IG7RVqp21UAo2iBVMymEX6um39F7dYD1xA3ADdQfKb8cVxb8VIQ+WEO627VrvdqPlQ+SlrJ X-Received: by 2002:a05:6a00:1798:b0:6ea:8793:6d64 with SMTP id s24-20020a056a00179800b006ea87936d64mr17740453pfg.23.1713291192251; Tue, 16 Apr 2024 11:13:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713291190; cv=pass; d=google.com; s=arc-20160816; b=sRhCis6DyKaNWfGp+T69rUY4ZcoC1Bjuur19aJi2USlcoi4pmso2I1GlXwe3iXqrIt TUn2lz5YaB4kzwRmcO0arEAARHpCici2xR/0wgGceRNgTwaFB5SHxbZ24VxLjIdgNziV EVV9qlGis3HuSjqqRwFtGhllgU5x5mw2gLqe9QHqm4jBrq5OjwkHXHjFjuDQlYVnhkjK bKhLhT2cxWUAhLBBaAM07nhGdUEmLjGw+xbRQElKmBSci4TlnzElnCRacAfHm/x7C6Uv 96MaD3XBzKGIxtX+G2IY/AqKmQpVwMhy3GKh8iqcFYwDToPqF7cPiVcr/wq62xL8C6mp 0TwQ== 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=iKA01nHZWWeCUMwezGVKQPv6dB8WRSswCOMzscXKYBI=; fh=I1GnAteARwIOgfvpPcOGkAkApgDxRl/wQBC0aqmzE/I=; b=Mof/vFUi92M1OBuLEtQGMc+2huSoAoi2btOaCKqamYmjEu8lVDnn4Pui9gJZ0y+eja HGYqvxnvbQqM7H8lVYwrFWmp2E/Qhxjd5PQHX49RsTwhTSiNKWZt5ItW3yXXLk8v2Lar ZCyBWbh4b48gxLfQuy8fh/UObR4FqfGy8gxBNcJfZxGBn7pOr1CX+rFQWEkcZW8IFH9o VQQCCMiKrl7aMJVO0sFdzeUsR729pl5JNhn1jDGh/j1hiVdLKHWA3rbaX0VffQRmF7sg 88RfJFOUzot3F0Qk8VbAPlegNnNScGndzs+N5ZGh4n7E1mzmIbyovaxOKVeXSnTrZpXG UjjQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=heJ3p54w; 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-147357-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147357-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id i186-20020a62c1c3000000b006e6b30a7ec6si10062499pfg.231.2024.04.16.11.13.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 11:13:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-147357-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=@gmail.com header.s=20230601 header.b=heJ3p54w; 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-147357-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147357-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 7D5F4283DD6 for ; Tue, 16 Apr 2024 18:13:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 64A87134CE8; Tue, 16 Apr 2024 18:12:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="heJ3p54w" Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com [209.85.210.45]) (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 DD378134CD4; Tue, 16 Apr 2024 18:12:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713291151; cv=none; b=gwAsldPZOciEMa6ihtz7MGCR6DN9bnk1RvqkFN6VPbBwSctV9N/Uk9wBXBrxzruM9cC7yKLjZoi+W3XTDOaSgedwGx+63ymyGF0TTNV1eWJmEBokK3FBI3AP/lg+T9Dv+q07lO4ltlRQXHNl4EdA3poeUcoMS2NnPrnxVOilr68= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713291151; c=relaxed/simple; bh=o/Pz18+RKaep+hg8mtEP9kW2B/vTbdfUmQG+bVJKW20=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nfmRvLYL57p3HBjgfcfW7THHcpfvYtPFlAPtqx0u6W2CN2XnogLXMuZAqwB71HCRElvOetnMW8YUd1y1+nKeLIz0iQMGHgdOLDWEE63t1YbV9mLBmkRFEDP/Y5NE3X76SAJJrFq+Sh4v1krrgXUdTjsLDahZKOej658jPBi3Ckc= 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=heJ3p54w; arc=none smtp.client-ip=209.85.210.45 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-ot1-f45.google.com with SMTP id 46e09a7af769-6eb8ae9b14eso1044890a34.0; Tue, 16 Apr 2024 11:12:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713291149; x=1713895949; 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=iKA01nHZWWeCUMwezGVKQPv6dB8WRSswCOMzscXKYBI=; b=heJ3p54wCh+Vu5wIz2uayiU9dyUbZxLrWAv1WTjzFOCjbiE79JFK3LDV8PipJALN/6 e568ozu5vwDOZPG4C3m7OgW1Hxs85oxEUaU8/GoZlfd629aqLNDnu79R2StPeI98ZpLF DhHCjTdPVYLS5a1uc1//P8SGODC5AJ56KOCaFMinIR3aw+iYlxW0TUldIGQqXExDUkin 8A9BmDCxHvAWq8JekbzDW50Ddh/0AAVL5E/ExYURIdOebDKiSUHdPyJypbw0WBYplt7c 2MZPG0VE/xFTPAYoE+Pf88YB77TJp/Sr73rDYymTsIBkCvDEHbOrnZ04+slgMzJFpX5v W59g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713291149; x=1713895949; 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=iKA01nHZWWeCUMwezGVKQPv6dB8WRSswCOMzscXKYBI=; b=r7qq5R0bPw8EB3XuKBw13g6HPMmG0ZulezUlfQfTZD0bIHwfvq1DWd2PmRfzc+YXG7 edtDnSxUILsMVTe3RTQ7Szt5Ahy4UKl97Kkislmv9I2MNLZxfaBstsV+Q7y9YruISvPf P4aquINR3hOWoy4raPX5kMFh5DS3q4nBXW1R9fFeXQqCVVPWaxfyJb6iZM4nYSWqWnjB G8DfRS6cVdYSZV0orDyW7h5iXi227WyDRo6VEpJn95PZg4XL5rlZWfgwCGFxV8CEVQjs KaG+LN0m7WWzyEfdUHhetlyiSsnx5nftduGNXLY+9roI6EJTdOlX4tkkIAqvaZ36KzFI 14oQ== X-Forwarded-Encrypted: i=1; AJvYcCVbffWMoZDWX+piLgzm4VLzZNITVKNVIa2wvj4l1Yv7VVva6KiuYT241OeQrPmDrpM9kLFKy7nt4urxGTfNLO9gEah04Bzj/KDzTd30CBa08kNTF5Id1+GvsSVLSb3+a9P2R30iNzDB8uLL7RBmdq1hAwzT1yW7CbRTQLOxKt03sHG8fTF+d/Z+x4IiLuCQ1ObCmdK9loDgtJ9pv+JaUUlS9tbUPZunCA== X-Gm-Message-State: AOJu0YxSApu6IvetWOUq4FjnBRZL2004FGG8CoHEPXpCiIoJtVAYaYUf QUYogQew185tUZr4TzYpxUNaus2WLH3Cz1o0jbszacnHV2bQ0wrS X-Received: by 2002:a9d:4d95:0:b0:6eb:7bc3:12a5 with SMTP id u21-20020a9d4d95000000b006eb7bc312a5mr7305200otk.32.1713291148792; Tue, 16 Apr 2024 11:12:28 -0700 (PDT) Received: from fauth2-smtp.messagingengine.com (fauth2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id c25-20020a05620a135900b0078edf6393edsm3676965qkl.73.2024.04.16.11.12.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 11:12:28 -0700 (PDT) Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfauth.nyi.internal (Postfix) with ESMTP id 028C71200077; Tue, 16 Apr 2024 14:12:27 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Tue, 16 Apr 2024 14:12:27 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudejiedgiedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepuehoqhhu nhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrg htthgvrhhnpeethfejhfekjeffueegieejudegjeetveeuhfelhfevvdfgfeekkeevkeel veekgfenucffohhmrghinhepghhithhhuhgsrdgtohhmpdhgnhhurdhorhhgnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepsghoqhhunhdomhgv shhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedtieegqddujeejkeehhe ehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfhhigihmvgdrnhgrmhgv X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 16 Apr 2024 14:12:26 -0400 (EDT) Date: Tue, 16 Apr 2024 11:12:07 -0700 From: Boqun Feng To: Peter Zijlstra Cc: Mark Rutland , 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 , "Bj\"orn Roy Baron" , Benno Lossin , Andreas Hindborg , Alice Ryhl , Alan Stern , Andrea Parri , Will Deacon , 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, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Catalin Marinas , torvalds@linux-foundation.org, 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> <20240409105015.GC21779@noisy.programming.kicks-ass.net> 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: <20240409105015.GC21779@noisy.programming.kicks-ass.net> On Tue, Apr 09, 2024 at 12:50:15PM +0200, Peter Zijlstra wrote: > On Mon, Mar 25, 2024 at 01:59:55PM -0700, Boqun Feng wrote: > > On Mon, Mar 25, 2024 at 10:44:45AM +0000, Mark Rutland wrote: > > [...] > > > > > > > > * I choose to re-implement atomics in Rust `asm` because we are still > > > > figuring out how we can make it easy and maintainable for Rust to call > > > > a C function _inlinely_ (Gary makes some progress [2]). Otherwise, > > > > atomic primitives would be function calls, and that can be performance > > > > bottleneck in a few cases. > > > > > > I don't think we want to maintain two copies of each architecture's atomics. > > > This gets painful very quickly (e.g. as arm64's atomics get patched between > > > LL/SC and LSE forms). > > > > > > > No argument here ;-) > > Didn't we talk about bindgen being able to convert inline C functions > into equivalent inline Rust functions? ISTR that getting stuck on Rust Yes, we did. > not having a useful inline asm. > Mostly two features were missing: 1) asm goto and 2) memory operands, #1 gets implemented[1] by Gary, and should be available in Rust 1.78 (plan to release at May 2, 2024); For #2, my understanding is that arch-specific effort is needed (since different architectures may have different contraints on memory operands), I haven't yet found anyone is working on this. (background explanation for broader audience: in GCC's inline asm, you can specify an memory location, other than a register location, as an input or output of an asm block's operand[2], but current Rust inline asm doesn't provide this functionality, by default, without option "pure", "nomem", etc, every asm block in Rust can be thought as a C asm block with "memory" clobber) That being said, if you look at the link I shared or this gist from Gary: https://gist.github.com/nbdd0121/d4bf7dd7f9b6d6b50fa18b1092f45a3c there is another way (yeah, we probably also have discussed this previously), basically what it does is compiling the functions in a C file as LLVM IR, so that Rust can call these functions at LLVM IR level. This in theory is doing some local LTO, and I've tested that it works for asm blocks. We still need to tweak our build system to make this work, but should it work, it would mean that Rust can call a C function in a pretty efficient way. > But fixing all that in a hurry seems like the much saner path forward. So a sane plan to me is wiring our atomics into Rust functions via what Mark has (i.e. starting off as FFI calls), then we can switch to the "local LTO" approach when it's ready. In case that "local LTO" needs more work and we do have performance need, we can always either 1) manually implement some primitives in Rust asm, or 2) look into how bindgen or other tools can translate simple C functions (asm blocks) into Rust. Regards, Boqun [1]: https://github.com/rust-lang/rust/pull/119365 [2]: https://gcc.gnu.org/onlinedocs/gcc/Simple-Constraints.html#index-m-in-constraint