Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2443938rdb; Fri, 8 Dec 2023 08:16:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IGzgbksIB5pVSSuXwSP8dh6CQ3Exyr6Kcy+Ap6/lHp5VuQP8WuSDYvgadMBztCVizjKshf6 X-Received: by 2002:a17:902:ee86:b0:1d0:8c04:85fe with SMTP id a6-20020a170902ee8600b001d08c0485femr285590pld.12.1702052162122; Fri, 08 Dec 2023 08:16:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702052162; cv=none; d=google.com; s=arc-20160816; b=Yxm7HGHn7mhDwpPxTlAJMD7VfIIFoWQiwcbmfmc5U5MxR3T98uW7JMqU/gGpI9HxQH jMJuJ4FVzup1z073W8Mh9Pa7gL24eCdVW5PrvNNxzf5jNb6MoEfO4n3NT7vCEK6qHhNw 84N66p6byXChVvORwwZeOycb3fqKxLud8zzF6gduVIsYF3a7GQRPsTCplUfJyccPgdjz mpetPc7+7MVpfyFW6ot8XEexJ3+85hG+r2n9Giq+5b2bwxRXBaVCr+SM4pPIMV3o9lhf z5pUKs1or8qEofAsDLW8dnEF/ehTZFCqdlaeeKERCmvFqTi8emhABZ4HxdjsbB+5KTpj pTFw== 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=ek4co/YpsGRGW/CGOUlf0EOIjWRaI4i0rP+RwDefBy4=; fh=yGC6hLtEKxG/qAMK6tCmLY72Pr3WjPw6U6qgCoktHOQ=; b=rDPhk3IgSI5w7kHKrvzU/1kZW62MCbB1Bi0jF7jKdkH+lfYc5AJkKAB+NOlAwbxogz wMCTEdpd3VSS2wgtJsk4JFbyeNNljbb6zaM52WaB9VhCwP7ALaUW0cEcw8f6ATWB2DBZ YiTvReBhT2eV7Ge8N56SOwNqz3rYSbLG/OZ5f/A6GhiCrost+4W1U114eARPL7vxShwQ 7fDyWpk0DO+XqUPgqr/SJ2KxEKkpDZTYfMctQJGwQKLwpeng+K9JEnOaH+T0J8bl5rP5 LmU+CY9WAwqYiDxXtjwr1y0rjDqCDyNm/AG/Wx4IfsePvD0IEeqf2yEVMhtaEzmDjuUj L2+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=YXm7Jqtm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id p8-20020a170902e74800b001c613b5e778si1821392plf.557.2023.12.08.08.15.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 08:16:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=YXm7Jqtm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id E798480822C4; Fri, 8 Dec 2023 08:15:09 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1574462AbjLHQOr (ORCPT + 99 others); Fri, 8 Dec 2023 11:14:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235994AbjLHQO1 (ORCPT ); Fri, 8 Dec 2023 11:14:27 -0500 Received: from mail-40133.protonmail.ch (mail-40133.protonmail.ch [185.70.40.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82D1D212A; Fri, 8 Dec 2023 08:13:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1702052023; x=1702311223; bh=ek4co/YpsGRGW/CGOUlf0EOIjWRaI4i0rP+RwDefBy4=; 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=YXm7Jqtm2MRsihn4lo0W4ggKNDyx9zcUfb6gxx6B0Wt0+w5Tdh1sbAkvAOypJ9lnH 1ILv9/Ns9LQCE+unShsUMCttnsFElCpxKdA/WnL6mJ4T7HkD155i+KrKfLdzuZW4NO 9ezlowMCpgkhJb0YmHGMrw4645Ds6PyPNTAWcrFU22eAd13IwrzWOakiRs5cglpcEQ D9PjW7u7fbSCihRCYbl86+j2m1F0xivRLHi6MArRCvSM0YtwvzMs9xg/0oq14sJEob l/XqpZ2H0THWfSk0qUts3LgyPeVFJYwzfGFHe7p/j/qoyAJWOGxNvJ0BEzqT+EVNXh pHRipQHGInDKg== Date: Fri, 08 Dec 2023 16:13:26 +0000 To: Alice Ryhl From: Benno Lossin Cc: 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 , Matthew Wilcox , Thomas Gleixner , Daniel Xu , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH v2 2/7] rust: cred: add Rust abstraction for `struct cred` Message-ID: <8VBM8spxE8lhkvhYGfxxUFwslCWxi-ZL6rGHHDYD6Gn5dZqsdUQfZYDqtykJzQNFJVsQje_B4hGVDRqy3zY3TZGLSL7_YXbhKcIYfvBS02I=@proton.me> In-Reply-To: <20231206-alice-file-v2-2-af617c0d9d94@google.com> References: <20231206-alice-file-v2-0-af617c0d9d94@google.com> <20231206-alice-file-v2-2-af617c0d9d94@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 howler.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 (howler.vger.email [0.0.0.0]); Fri, 08 Dec 2023 08:15:10 -0800 (PST) On 12/6/23 12:59, Alice Ryhl wrote: > +/// Wraps the kernel's `struct cred`. > +/// > +/// # Invariants > +/// > +/// Instances of this type are always ref-counted, that is, a call to `g= et_cred` ensures that the > +/// allocation remains valid at least until the matching call to `put_cr= ed`. > +#[repr(transparent)] > +pub struct Credential(pub(crate) Opaque); Why is the field `pub(crate)`? [...] > +// SAFETY: The type invariants guarantee that `Credential` is always ref= -counted. > +unsafe impl AlwaysRefCounted for Credential { > + fn inc_ref(&self) { > + // SAFETY: The existence of a shared reference means that the re= fcount is nonzero. > + unsafe { bindings::get_cred(self.0.get()) }; > + } > + > + unsafe fn dec_ref(obj: core::ptr::NonNull) { > + // SAFETY: The safety requirements guarantee that the refcount i= s nonzero. Can you also justify the `cast()`? --=20 Cheers, Benno > + unsafe { bindings::put_cred(obj.cast().as_ptr()) }; > + } > +}