Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp368888rdb; Thu, 30 Nov 2023 07:02:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IGagQ8y9aYsepo87ma5RpBtV0mKcNBS/ExlxOplsd6zln5fpKGwxgj4cD5yUKgMoegTTNwq X-Received: by 2002:a05:6808:150c:b0:3b8:3fd7:a194 with SMTP id u12-20020a056808150c00b003b83fd7a194mr27796474oiw.33.1701356578346; Thu, 30 Nov 2023 07:02:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701356578; cv=none; d=google.com; s=arc-20160816; b=HuHKkUVkpPDMaDyYDLWrX3f1os+lpKO4ykkbTFw1dpzRKs4vGvTsSZqBEkYdW4/G8A zWRnflLUmcoOdlenyHFSII1j5TEXdAON9UpKlVIZHt5N3ulfAmF4EHes+6W2dlNInHuK q63xtG5f6kG5BDsRqm6xZyR21U5/vhOg9vEBLTHnV7zTO3++6tTno+BOgZKY8/hqUxlv 3RWB6/uWlNv0KWpxrsDqw5CxU3vTCOTBxHdlWFMUqg1WuFaA8gpIgL2SxtvSzdLAeXA+ 5huDa5VvOcnPJgguqIHHXBif61DLyQnuUd51L3g4EJxSWzPEeHcgIS7dEnHRoz1DbiTg 18DQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :feedback-id:references:in-reply-to:message-id:subject:cc:from:to :date:dkim-signature; bh=uo2vqq/xcRDYM6o4gUKdCIhET5kcnBqayNRuV/1IFZY=; fh=DK619n1YiaBOjRj6Xgu1Blu8XKz5LoQ2UiTa0ORO+0M=; b=0tA/lI0aSnWktJ4AxHcFMmP9cgDH6uMBNhfsgIvLVW8D8jMRErYJ4N7XEyQDKOJ8M2 jH/3PpZcaxijXiD/DUzL6IH0nUwCaqPnCfj7WjjIOI8bud/d1BgpoGeh89nJnc2+9iWt v2E1xHzdEM8U0ASTtVX70RBzkEyDRRHQ/6ZMi5oj2wtf2wzjmmFkmMDmOkRh5TM6uI0S 8d+cfCAXqgA5BPCK+JdwNMdhS83UaEUYjt7jwP6cuP57CxGoo80XvevdUT0Om1JhxHkZ TLnYSAsNiYjTmJZaa5Bjo8DYjyqbfZIAycP8UCMQ8lVHJf5JvsMe13FoPuqUJORfAPQ6 AFRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=bqW4S8AB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id s21-20020a056808209500b003b84432a285si558080oiw.1.2023.11.30.07.02.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 07:02:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=bqW4S8AB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id E68D18031D4D; Thu, 30 Nov 2023 07:02:54 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346084AbjK3PCW (ORCPT + 99 others); Thu, 30 Nov 2023 10:02:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235195AbjK3PCV (ORCPT ); Thu, 30 Nov 2023 10:02:21 -0500 Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D39F61A4 for ; Thu, 30 Nov 2023 07:02:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1701356545; x=1701615745; bh=uo2vqq/xcRDYM6o4gUKdCIhET5kcnBqayNRuV/1IFZY=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=bqW4S8ABCR3oUPVl1gnYRytnSkn8znO+ZjOvjkZXuN3fewQK/9el9fndFgKOY0Igh soPaRM72dS+exH3qAMUp+teBMOiNFRjfzKtEBHMtD8f5BLG/FteB8PhalP+zdGE+Xz cZkPHR5xpZeIUitKd3zrO9biSOIfu5xp8cdyLuqGKn4WpXH9zhOi/7HocLwu7wCItW pbvA+B7SwXq57f0QQnePsuJKy3CVaxM391XEEtzi1kEpxmwZrGwiESzZMeI4CgtMn5 AoYsbTT2ZY/DbpwIdDEgGmpixtghJGotnDrmsukaH9atODdyP5gMsclqLBHVr8QMmg K0fyn3KHoVRjQ== Date: Thu, 30 Nov 2023 15:02:06 +0000 To: Matthew Wilcox From: Benno Lossin Cc: Alice Ryhl , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Peter Zijlstra , Alexander Viro , Christian Brauner , Greg Kroah-Hartman , =?utf-8?Q?Arve_Hj=C3=B8nnev=C3=A5g?= , 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: In-Reply-To: References: <20231129-alice-file-v1-0-f81afe8c7261@google.com> <20231129-alice-file-v1-1-f81afe8c7261@google.com> Feedback-ID: 71780778:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,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 fry.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 (fry.vger.email [0.0.0.0]); Thu, 30 Nov 2023 07:02:55 -0800 (PST) On 11/29/23 16:13, Matthew Wilcox wrote: > On Wed, Nov 29, 2023 at 12:51:07PM +0000, Alice Ryhl wrote: >> This introduces a struct for the EBADF error type, rather than just >> using the Error type directly. This has two advantages: >> * `File::from_fd` returns a `Result, BadFdError>`, which the >> compiler will represent as a single pointer, with null being an error. >> This is possible because the compiler understands that `BadFdError` >> has only one possible value, and it also understands that the >> `ARef` smart pointer is guaranteed non-null. >> * Additionally, we promise to users of the method that the method can >> only fail with EBADF, which means that they can rely on this promise >> without having to inspect its implementation. >> That said, there are also two disadvantages: >> * Defining additional error types involves boilerplate. >> * The question mark operator will only utilize the `From` trait once, >> which prevents you from using the question mark operator on >> `BadFdError` in methods that return some third error type that the >> kernel `Error` is convertible into. (However, it works fine in methods >> that return `Error`.) >=20 > 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. In this case we are actually doing that: `ARef` is a non-null pointer to a `T` and since `BadFdError` is a unit struct (i.e. there exists only a single value it can take) `Result, BadFdError>` has the same size as a pointer. This is because the Rust compiler represents the `Err` variant as null. We also do have support for `ERR_PTR`, but that requires `unsafe`, since we do not know which kind of pointer the C side returned (was it an `ARef`, `&mut T`, `&T` etc.?) and can therefore only support `*mut T`. --=20 Cheers, Benno