From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1CC08C04FF8 for ; Tue, 16 Apr 2024 18:12:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=g03aJo6Z/WBJeQ81D/uMAvB4Wg2wXUCMskJVFy0IdnU=; b=RbqdvjJSvu6Y5W kRdHtOWtORXqs0OtmI9RBfbYgzis4QDF1hxi8jrFuJUmAfbiWrDJys8fo89jYozSSf/I29rExHxRk nT6p9IOKgBbugBfdZTSTGJjtdHQDqNaDLLIPVmLMcxfw9U7qMwC39kWiMBguoflov+QelHUSxZBsX caeR6DeJpMZ9EmTVHTgDknQ08vCT85tj5b0r72usoCxJLpqKKRymmDPB6aFCi1FV3y0HZSuNe8+Pd atr20fJh2xvwpIFxg5idj3jqGQYmMJjfPb3qby2O9ok8fMAZdIJJLfcfOdL9lWN8+m3r7VR3BVFyA BEiRiQEkz9tkargD4g2w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwnII-0000000DHHr-0nms; Tue, 16 Apr 2024 18:12:34 +0000 Received: from mail-ot1-x334.google.com ([2607:f8b0:4864:20::334]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwnIE-0000000DHG6-0p8A for linux-arm-kernel@lists.infradead.org; Tue, 16 Apr 2024 18:12:31 +0000 Received: by mail-ot1-x334.google.com with SMTP id 46e09a7af769-6eb7d1a5d39so1779620a34.2 for ; 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=lists.infradead.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=XY+64AXsSPTN+8NazDd7Hg32bljibL/yw7Zp/RIr0DmMhKmnLEZmdWp6VAAkJrUL3G 09zedPRIkmEbYwi0EfFL3TNWzH9/JB/ZrJ+pj5AffqRePr97fwA+pIF60WRxbaRaTcKJ f5i/MUTi+iyMo+dATcbaZTmML4rIxZpf8SO4zgedoY/zYQ7q2xMSNFWX7LKWMsL/AGjt eEC4vlKKSVKRHLRKUy0xH7VdGDSg1a0geQ6pMyQVuT7frmhaFJaoTKuuegBma5AEYaaI qqouyWBteOA3o77utveqod4bRJkAhdSL3WcC+S1JviYWNhJ9/q3Hb/M2XUYZF6BJlkPT huvA== 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=W4f1zVL6OXs3nosK0twSwmMEFunqjM+C9sgDlLHYgqtwVvpT4dpXFrdpJarpV4rsFC bsB+awd1dwMIC5iD2+JP4HDd42Mg/A5BmBBpFlStSlNg3XKJPjPSU98YY3xgg1twHdcE ycKrl6ozpQjWaALL7u6VVRQgpiFsVk+JC7MjaYXIS2vIFZvwQoScrDB+Mhb+Fx1KX2y7 Vm4/USJqp2ccAy4FSjfM5sW5s6/iS4wc3K1nvAts0C4/pJBvi0eRqgmqn+tpMRcuoaZB nmQ1Hb0uZ1zR4HIwAz0BAAVt316hePddWiVuwlAh9EMKe8K71+t8fhFJX4VqkBm24tF5 T0dQ== X-Forwarded-Encrypted: i=1; AJvYcCXNtSL3dClRquosNYoAAqMVTUXA4KAlRvzzVdOW2JxdydL5OYH4bGJ92EX7S0eTPbhC6ibTI7tEWTzHdrrCi+pLzzZvrAQ5ej5ln8tRxOFJuNFGXgI= X-Gm-Message-State: AOJu0YxymW6dwbzN9XdRPXpAkx88z6xV8v2pT01iuYB0kmtBw32fpWRN mDSc4YCqQ0SsebuuDrvCAPf1YS+ZScJug3aEDjHUsVDBkZk8AUS1 X-Google-Smtp-Source: AGHT+IEsvpJ9PHMdwG/Acyze2YUbjWscWF8ldU9oec4TpSg6OiR2NDXpJYNLstl4DLb3bNX7ulcKpA== 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> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240409105015.GC21779@noisy.programming.kicks-ass.net> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240416_111230_259991_132B5BA7 X-CRM114-Status: GOOD ( 27.75 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel