Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4715833rdh; Wed, 29 Nov 2023 08:43:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IExllBKsGLYmYz7oPL4zwZcKj4kmfD7NI0DEp5YyFZL8BpL3Z6RfDoTpQAlaIph+spevVBN X-Received: by 2002:a05:6a00:3991:b0:6cb:6407:defb with SMTP id fi17-20020a056a00399100b006cb6407defbmr20344098pfb.26.1701276186954; Wed, 29 Nov 2023 08:43:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701276186; cv=none; d=google.com; s=arc-20160816; b=SiM1kWISqZBEUbtSUVe3LFM7lX/8FvIY4vEDBOVpGRWOyH+7UAnAbJgzb1rjnpEghH y7voBzWvt0y/Jr87jzFXFBsiYhcwTLgKuhWW/x371FUzV44YdZy8lN9mQtyNSeiE+ocR jvQ9agUF/PB0zouMBb1BtHREgeQDDbT1gHAz+HlkTR1sY0SGi+roxJXwuoQKsBz1fH31 PniUPv43dHkIJqEeMFOE2Q7QHaLJxbdFV1PTEygjHG8VhgzO6Maq9e0cLqHtnvkJ4KGc 4j5kKaf0Jtv99HRVtDVmMb1LRCENp/XysIIrnZqE54MclUIcK/eMNVsmWKYfugAlJBUU dWYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=w6FX0CURCIc5lUI0TKDm4VLrqOeB/l4oPqjqbRob5JI=; fh=AfMCmeGFXywN7lTgavIvgSjyBOCdny2q+kSSkK6MD24=; b=UiXHcMLmXPpc/QQGIqJsk2m0xvcvHNfAnaR8ddcBQTzJXHAUcBYk5mxfMGObihecxE Sh1hJthWdXkqvLwzJh+M6LGaTUW22xrf6k70cHR71MUoJ3PAIMuMZWbcwGYuF6dPEiSv U45eoaNO+VjRhTJjw4zX5NmZ3VEO8A0s7LAtXmFvGjhebvMWR7IvuUq0DmxM3jRiJet5 9Gtgs9zm+6p4ORPYdHgb7OYAhjwqVeKYjS/wImDY/1QkEeqwBD/GEqpbx8HPa36Cn6Sr ski8vU9T1voCqoWxDiKhi+9GC+eSIyrc+B2fhrbFmjqA5zGnEPt52DoURu2aXc5UobMS dPyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="0qtm/rwq"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id a38-20020a056a001d2600b006cbf2bc1af9si13024641pfx.0.2023.11.29.08.43.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 08:43:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="0qtm/rwq"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id A06A78033193; Wed, 29 Nov 2023 08:43:04 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230381AbjK2Qmt (ORCPT + 99 others); Wed, 29 Nov 2023 11:42:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229535AbjK2Qms (ORCPT ); Wed, 29 Nov 2023 11:42:48 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12ED3A8 for ; Wed, 29 Nov 2023 08:42:55 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5cd573c2cccso8903377b3.1 for ; Wed, 29 Nov 2023 08:42:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701276174; x=1701880974; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=w6FX0CURCIc5lUI0TKDm4VLrqOeB/l4oPqjqbRob5JI=; b=0qtm/rwqKLTmg0uBNQ9djLMO6ApmdUrjMGiRlrpLewmfrf3TZZUqhWrJ63TpMrYpLv 8jk82dh0sU0R+h2DBJMDlKkm/SM+DpZh89w37LUl5HhqyE3BvBG/ycaq+yrRgpTqL6P9 bdHrJd6+VWH5ykdRlJLW97xm5zDsRLPzhC5rC5Asz+KL8Yk79mVTC/cQ9wbw0tcBvUxP vqoINIY2SxecDWX5l2I/aV/TSmRcQidN2Ytvi9gWIKZntlFUvsKTP54kZXUjzNgZK8DB gXhKlJj0cSD7y3Z43c9DAesajp2xZkc9lX1I2qoqy42jOSE0Wg2JjKgiOyaw4hQLZdzx a8gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701276174; x=1701880974; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=w6FX0CURCIc5lUI0TKDm4VLrqOeB/l4oPqjqbRob5JI=; b=TebVWONFPQqmZVuoFJPqzkcr0q3MviBS4Cw4lid0XCOcNponyhY5G0MW2TFgLS6nz2 1JyX7GYVCk8kUUfAIfoBEb8EIroPSs8N4GiXfzoY354F+0QdY3YdP8oAlzM4rY5pv+Je lkgeY3LrGFTT7MjhAUaRrt+PT2BgtkhAyvRCUywz+M8GNww4eqj7vhzyWk1BKJc+KHwh cETD/x4wLVdq/5xK+BfulzuVEBrEP1h61P/BhXh8UN9LLUpvETULm3TPzrd0KWWDG1mr 31AY3FZ7E1Q3UP+K+0nBErBADO3bwleCHy47kPRVgIXDf2s/SdJI7FWRhKJGb0cjuxUg VWYg== X-Gm-Message-State: AOJu0YzeUSIsAWq8cy7+BISKtU1sEq4iF51yE9v0IEekgXpJjYeqjibl gk4TGeo8hWvVd0nGPzWcGBmiIzWJJsSxCmA= X-Received: from aliceryhl2.c.googlers.com ([fda3:e722:ac3:cc00:68:949d:c0a8:572]) (user=aliceryhl job=sendgmr) by 2002:a05:690c:2b82:b0:5cb:ed68:a256 with SMTP id en2-20020a05690c2b8200b005cbed68a256mr609870ywb.4.1701276174047; Wed, 29 Nov 2023 08:42:54 -0800 (PST) Date: Wed, 29 Nov 2023 16:42:51 +0000 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog Message-ID: <20231129164251.3475162-1-aliceryhl@google.com> Subject: Re: [PATCH 1/7] rust: file: add Rust abstraction for `struct file` From: Alice Ryhl To: willy@infradead.org Cc: a.hindborg@samsung.com, alex.gaynor@gmail.com, aliceryhl@google.com, arve@android.com, benno.lossin@proton.me, bjorn3_gh@protonmail.com, boqun.feng@gmail.com, brauner@kernel.org, cmllamas@google.com, dan.j.williams@intel.com, dxu@dxuuu.xyz, gary@garyguo.net, gregkh@linuxfoundation.org, joel@joelfernandes.org, keescook@chromium.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, maco@android.com, ojeda@kernel.org, peterz@infradead.org, rust-for-linux@vger.kernel.org, surenb@google.com, tglx@linutronix.de, tkjos@android.com, viro@zeniv.linux.org.uk, wedsonaf@gmail.com Content-Type: text/plain; charset="utf-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Wed, 29 Nov 2023 08:43:04 -0800 (PST) Matthew Wilcox > I haven't looked at how Rust-for-Linux handles errors yet, but it's > disappointing to see that it doesn't do something like the PTR_ERR / > ERR_PTR / IS_ERR C thing under the hood. It would be cool to do that, but we haven't written the infrastructure to do that yet. (Note that in this particular case, the C function also returns the error as a null pointer.) >> @@ -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? I think there are two factors to consider here: First, doing the atomic increment from Rust currently runs into the memory model split between the C++ and LKMM memory models. It would be like using the C11 atomic_fetch_add instead of the one that the Kernel defines for LKMM using inline assembly. When I discussed this with Paul McKenney, we were advised that its best to avoid mixing the memory models. Avoiding this would require that we replicate the inline assembly that C uses to define its atomic operations on the Rust side. This is something that I think should be done, but it hasn't been done yet. Second, there's potentially an increased maintenance burden when C methods are reimplemented in Rust. Any change to the implementation on the C side would have to be reflected on the Rust side. Alice