Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4733360rdh; Wed, 29 Nov 2023 09:08:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IFzMlm25oW41lqrTzLHd4epjl0q/xHVsvC69H7rIuQYyNhu1kiSX2415n56T9ZTbjzoWaLR X-Received: by 2002:a17:90b:3a8b:b0:285:c054:668b with SMTP id om11-20020a17090b3a8b00b00285c054668bmr10882500pjb.37.1701277715534; Wed, 29 Nov 2023 09:08:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701277715; cv=none; d=google.com; s=arc-20160816; b=0IbJSac+TQJ5Kz2JvotgXgJSpB74J8/1Zz1DmXdb+sfKIZmb6I5PrV75Cjq9oc2guL oI5PQHUqPMnv22DyyoLxhAQCRC+38qjxxrIy/zg7JdCxhJJJ9SarFRBzp62GlXd5aq0x n38jqwtk6AsIuqasnpx3aQfkiAtjbdVKGOPUb0q9/n6mg1fRPFPsduh6FYQs+YIJFeYg qcAQJ8Jq/tOFk0OmzzXu88/KZljIPATmoO04uk5fD80oKxqClZq7/lLuFcbDcrgh2QeZ nZ9hFzek2XaTqLW4tKmg6VjJmDrb/u69Rbrb2ZE55JpXzw/LVGPDV6XGLntU+U9ju6dC daqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:feedback-id :dkim-signature; bh=TqpbWl3d4t7hd7UzjUjrZAkkyJ8NQqp/9vDtc/IE+6s=; fh=XaA1EXxq+lj9AgZ0RFbM0r66eFND52/7y47kAc1RLds=; b=Cvg1x9527pr8DxOpXpm39c3gbEx9dO2RE8nWbaiRGiqMMpHnj7Hox/AwaHLVIN4zZY LFD+g6C7t2gpmcNP6ZJ7x+Hx33/x8IIdnYCZtdxMbiUmo0EXDljj3ay1Vjjcdhqez+8e 1+za3gXOvr8SRNI9eAksS/A+HmwXkDHO6e11p6EvJtql3Ejj9xaud9ODjQN8Ey7fRKYi CVYOses8+LxVdJRLFbClY7s8LPRxZQu3SbanMFfWz2nF0OndImF4Zmh8d6YCUXSM7r+l kolasVvXds3W/X7MAacyntn6X6rbV80to8y7ayghtpJS5Mt43haBMRoxZa95UYw+OpJU Kahg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="VM/zah9o"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id a12-20020a17090a854c00b0028549378e55si1595793pjw.153.2023.11.29.09.08.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 09:08:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="VM/zah9o"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 15CC98061151; Wed, 29 Nov 2023 09:08:30 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229799AbjK2RIP (ORCPT + 99 others); Wed, 29 Nov 2023 12:08:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229501AbjK2RIO (ORCPT ); Wed, 29 Nov 2023 12:08:14 -0500 Received: from mail-qk1-x736.google.com (mail-qk1-x736.google.com [IPv6:2607:f8b0:4864:20::736]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 810D2BC; Wed, 29 Nov 2023 09:08:20 -0800 (PST) Received: by mail-qk1-x736.google.com with SMTP id af79cd13be357-77dd54d9da2so5486585a.0; Wed, 29 Nov 2023 09:08:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701277699; x=1701882499; 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=TqpbWl3d4t7hd7UzjUjrZAkkyJ8NQqp/9vDtc/IE+6s=; b=VM/zah9oJ9oDtJWw6px6aOW3yezQrVHgTRYZN/aVPug2KQv1+xf22M2plfz4x+fonZ Z0WgT9vCfgLSvt90ZTplR2FsnRuU/Dq0um4pDTX0fHSj5i26wrqodSlN9ntGSHkd8o8X KlO6ubHvErZAyeWi49v3fOEzpztvPZGIQmjUcz6fRMDhS2gar9S1DXothH/AORQJMcMg 1j7BWg+xvacUP6GnnlMZ0LbG37+31adPtadmKn7xSIPJhjbe2XuAWvdVyTzQyTaHcxFT i8DV9XcVXfzVSMQyUlvNp80EAxLv+nE5MrjmTQUjRVNt2L4+cu9u/tMHH6FNXSIL8jpi XcMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701277699; x=1701882499; 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=TqpbWl3d4t7hd7UzjUjrZAkkyJ8NQqp/9vDtc/IE+6s=; b=r8Ki6WLwh2XIYY0ZEqRSWjDk8owabFi/1tOt7uG+IG9l8D2RYfV4ys156T5KQARp3E q4oHkPlLRyQSKJehVCLyCuVIAoLDyQTYFGjxo+NA8FpxCvgYdj5mENCOKY1e75zZXXza ep0KNjdKlDg7OTIIPGzX0KKictdDAHFKRhWoPTHtw+mBX/bRnWL3us4ljT1A3VCRgMs9 AJugg18K+shAYbH0gWDldYzPOtKG26YZ/0BZ2YxE/naZMgOALwGX50ivYh6AsoDSF4e8 yP8fukwLqebHjVerM8fRan8sRDURgRhprdFuzGjq3dUDhP8A/tWXxK08Va1CjloXdDN/ rl4A== X-Gm-Message-State: AOJu0YyJQ9ByJoO6kfdhB3CdhpwGMUbhK58IeSQrYqLIen9UOVX54v6n A+iENY6nfHhSqWxI8O0QPbo= X-Received: by 2002:a05:620a:1266:b0:77d:5f72:3c82 with SMTP id b6-20020a05620a126600b0077d5f723c82mr18621228qkl.32.1701277699615; Wed, 29 Nov 2023 09:08:19 -0800 (PST) Received: from auth1-smtp.messagingengine.com (auth1-smtp.messagingengine.com. [66.111.4.227]) by smtp.gmail.com with ESMTPSA id rk9-20020a05620a900900b0077dd0ec0320sm413785qkn.130.2023.11.29.09.08.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 09:08:19 -0800 (PST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailauth.nyi.internal (Postfix) with ESMTP id 9D98F27C0054; Wed, 29 Nov 2023 12:08:18 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 29 Nov 2023 12:08:18 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudeihedgleegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepuehoqhhu nhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrg htthgvrhhnpeehudfgudffffetuedtvdehueevledvhfelleeivedtgeeuhfegueeviedu ffeivdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe gsohhquhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdeiledvgeehtdei gedqudejjeekheehhedvqdgsohhquhhnrdhfvghngheppehgmhgrihhlrdgtohhmsehfih igmhgvrdhnrghmvg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 29 Nov 2023 12:08:15 -0500 (EST) Date: Wed, 29 Nov 2023 09:08:14 -0800 From: Boqun Feng To: Peter Zijlstra Cc: Matthew Wilcox , Alice Ryhl , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , Andreas Hindborg , Alexander Viro , Christian Brauner , Greg Kroah-Hartman , Arve =?iso-8859-1?B?SGr4bm5lduVn?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Carlos Llamas , Suren Baghdasaryan , Dan Williams , Kees Cook , Thomas Gleixner , Daniel Xu , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH 1/7] rust: file: add Rust abstraction for `struct file` Message-ID: References: <20231129-alice-file-v1-0-f81afe8c7261@google.com> <20231129-alice-file-v1-1-f81afe8c7261@google.com> <20231129152305.GB23596@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231129152305.GB23596@noisy.programming.kicks-ass.net> X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 29 Nov 2023 09:08:30 -0800 (PST) On Wed, Nov 29, 2023 at 04:23:05PM +0100, Peter Zijlstra wrote: > On Wed, Nov 29, 2023 at 03:13:22PM +0000, Matthew Wilcox wrote: > > > > @@ -157,6 +158,12 @@ void rust_helper_init_work_with_key(struct work_struct *work, work_func_t func, > > > } > > > EXPORT_SYMBOL_GPL(rust_helper_init_work_with_key); > > > > > > +struct file *rust_helper_get_file(struct file *f) > > > +{ > > > + return get_file(f); > > > +} > > > +EXPORT_SYMBOL_GPL(rust_helper_get_file); > > > > This is ridiculous. A function call instead of doing the > > atomic_long_inc() in Rust? > > Yeah, I complained about something similar a while ago. And recently > talked to Boqun about this as well, > > Bindgen *could* in theory 'compile' the inline C headers into (unsafe) > Rust, the immediate problem is that Rust has a wildly different inline > asm syntax (because Rust needs terrible syntax or whatever). > > Boqun said it should all be fixable, but is a non-trivial amount of > work. > Right, but TBH, I was only thinking about "inlining" our atomic primitives back then. The idea is since atomic primitives only have small body (most of which is asm code), it's relatively easy to translate that from a C function into a Rust one. And what's left is translating asm blocks. Things get interesting here: Originally I think the translation, despite the different syntax, might be relatively easy, for example, considering smp_store_release() on ARM64, we are going to translate from asm volatile ("stlr %w1, %0" \ : "=Q" (*__p) \ : "rZ" (*(__u32 *)__u.__c) \ : "memory"); to something like: asm!("stlr {val}, [{ptr}]", val = in(reg) __u.__c, ptr = in(reg) __p); , the translation is non-trivial, but it's not that hard, since it's basically find-and-replace. But but but, I then realized we have asm goto in C but Rust doesn't support them, and I haven't thought through how hard tht would be.. Regards, Boqun