Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp3695507rdb; Sun, 10 Dec 2023 17:21:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IF1zdj2EM5ChRo0u9nkCYeIfz5bPWj1wkwld50cSdmaPW7hzteUgaqBFJ/a5YxH6lwEKPG5 X-Received: by 2002:a05:6830:1304:b0:6d9:d48f:9cc7 with SMTP id p4-20020a056830130400b006d9d48f9cc7mr3641275otq.26.1702257662509; Sun, 10 Dec 2023 17:21:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702257662; cv=none; d=google.com; s=arc-20160816; b=WHeM1mK4Q+jAsllNhQX26bRk9Upthgt+6ADvorqR/O2sYTByNT2lC2zEM372KaqsaT 1HgtxmVwAhywwY87yU8nakn7s/PXr/7nyyPhRAMDtrKxnx//+uIlRlDmQpTcAtW8wtLa RmLZRW12Sr7KmWV/Fe5Uovk/l9sE/JlcSOTxcspz/LMfXPd9v5/Y9qFaS504jvFYSQxA vmB1NC9jnRtm2BGH2IFYDMAOmwqhPdaGCM3RnhGEsBWdZNx68XEns/STxxdXZtqpYSBt gQxt7V8RR5C768TEJV1QQSDWxDlcTyl2ebqSqsyXawnTFT9h6P90Z48IEpuxeHGZoRbn 7PxQ== 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=Uuz0jwb3PNQkrLULfff6ouksNMtSPtItSVdeK1cdQGc=; fh=e2QygIhcr0lSTmAb4JoIYI1zNXz6sYVFWYZGjkaNTJw=; b=da2cIeBFmIxvL/6hg0GmLORO/gXHGJD0NPwLbatVd9rN6D3x5jkG2zCv3dbH+2CoMn aCiRRsncwgVRrbJPSJWXnM3HEAl3+6bVJAU58hCQl0qbdBflm4dt52Yd+6WRs4/Lv/Jr w+22E4ejutROnN72PrAOc3ZK+kEKBsRw2770WZS/2kv1K+Mil2lNRzsQNwYZEng6+q1H AUcZP4eu7kvDaPXaJXQ1WmmDJokAB03z4OC/kg7nRurOkY7WrH6seYx7tANmzI7/vRrw XxO4ArbZO8GOL46AkJ2SizOD7uLkm9TkPwdKVdcFnKPjlXS8PcwhtbyWP0KJyPpE/tA9 5D4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=TdBqw7yy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id s63-20020a632c42000000b005c6eb3502bcsi5028474pgs.408.2023.12.10.17.21.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Dec 2023 17:21:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=TdBqw7yy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 1835880758C9; Sun, 10 Dec 2023 17:21:00 -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 S229655AbjLKBUr (ORCPT + 99 others); Sun, 10 Dec 2023 20:20:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229483AbjLKBUp (ORCPT ); Sun, 10 Dec 2023 20:20:45 -0500 Received: from mail-qk1-x732.google.com (mail-qk1-x732.google.com [IPv6:2607:f8b0:4864:20::732]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B15AFED; Sun, 10 Dec 2023 17:20:50 -0800 (PST) Received: by mail-qk1-x732.google.com with SMTP id af79cd13be357-77f552d4179so146145585a.1; Sun, 10 Dec 2023 17:20:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702257650; x=1702862450; 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=Uuz0jwb3PNQkrLULfff6ouksNMtSPtItSVdeK1cdQGc=; b=TdBqw7yyWm8e4PSZC8RkkJuQKv+WvgbrlMhMIGBhK2c5d/zji503YA6MMETsSmFQ18 KpzUu5SanjjU/Bpg20H9f+F/ghJjJPbLmrvyyVlPU40fFh3GYeXz0W5xVWiD485Sxgef gaM4vqyNNJ0qqHM1RaKvGeyZQcQkk7F9SPpl1xsS04p2xW9AFabRwXcUO4W4GiibBVpq 3j4OwYqClQZKljckgRczi6aTCk31WQi7txKcUuwlf1UJZscDcEPZ14QGqz3YzHGRdyLo MNQcIC+fiVRuWiQ4rAqNqDEljCkXinq9/Q0FzxgYeef44ObQPIVsRpOOZHe9iNbUDVr/ Y2CA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702257650; x=1702862450; 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=Uuz0jwb3PNQkrLULfff6ouksNMtSPtItSVdeK1cdQGc=; b=oX2XwKUar9zrVKlWm9UAEfRbdaY5SW89TZedSZKBUEwgBmhdsGhGkwMq/KbaMfukI2 szdodmxCj9qFwg9AtxuL2aBHKb2DKUaAhEVfeg4ONtI3TzikWDXLOBrYNRIIPzfpDvlR p3TdACaexNQvNLBR10IUza/uF2n10f7/jeyE/854hWEItoo/zn2jq8jfoQZMeyqLvmqa jAK5tOH6SAVi2mI+nk6DgB3dxs2pBH2OenOn83dRiGC5/UFIibOJRjpnaSJSPeKqHo3K as6UsNsvdTydr3CFJbXLKiYtpOaqF2ric9RRa0Ab7c2r+S+9nHXoRS5rcUXsd07dAazX vWAg== X-Gm-Message-State: AOJu0YyW2Go8HM6XYYb/yf3UdrdoWLy88PA0i3sjVv3rlCUQ1ZGWuVVy zhCDyr/gaKcQCqIyuIVrrxc= X-Received: by 2002:a05:620a:a58:b0:77f:69ed:7f40 with SMTP id j24-20020a05620a0a5800b0077f69ed7f40mr2501765qka.7.1702257649715; Sun, 10 Dec 2023 17:20:49 -0800 (PST) Received: from auth2-smtp.messagingengine.com (auth2-smtp.messagingengine.com. [66.111.4.228]) by smtp.gmail.com with ESMTPSA id ov11-20020a05620a628b00b0077d7e9a134bsm2505634qkn.129.2023.12.10.17.20.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Dec 2023 17:20:49 -0800 (PST) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailauth.nyi.internal (Postfix) with ESMTP id BDCE127C0054; Sun, 10 Dec 2023 20:20:48 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Sun, 10 Dec 2023 20:20:48 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudeluddgfeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepuehoqhhu nhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrg htthgvrhhnpeehudfgudffffetuedtvdehueevledvhfelleeivedtgeeuhfegueeviedu ffeivdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe gsohhquhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdeiledvgeehtdei gedqudejjeekheehhedvqdgsohhquhhnrdhfvghngheppehgmhgrihhlrdgtohhmsehfih igmhgvrdhnrghmvg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 10 Dec 2023 20:20:46 -0500 (EST) Date: Sun, 10 Dec 2023 17:19:28 -0800 From: Boqun Feng To: Alice Ryhl Cc: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , Andreas Hindborg , Peter Zijlstra , 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 , 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: References: <20231206-alice-file-v2-0-af617c0d9d94@google.com> <20231206-alice-file-v2-2-af617c0d9d94@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231206-alice-file-v2-2-af617c0d9d94@google.com> 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]); Sun, 10 Dec 2023 17:21:00 -0800 (PST) On Wed, Dec 06, 2023 at 11:59:47AM +0000, Alice Ryhl wrote: [...] > @@ -151,6 +152,21 @@ pub fn as_ptr(&self) -> *mut bindings::file { > self.0.get() > } > > + /// Returns the credentials of the task that originally opened the file. > + pub fn cred(&self) -> &Credential { I wonder whether it would be helpful if we use explicit lifetime here: pub fn cred<'file>(&'file self) -> &'file Credential It might be easier for people to get. For example, the lifetime of the returned Credential reference is constrainted by 'file, the lifetime of the file reference. But yes, maybe need to hear others' feedback first. Regards, Boqun > + // SAFETY: Since the caller holds a reference to the file, it is guaranteed that its > + // refcount does not hit zero during this function call. > + // > + // It's okay to read the `f_cred` field without synchronization as `f_cred` is never > + // changed after initialization of the file. > + let ptr = unsafe { (*self.as_ptr()).f_cred }; > + > + // SAFETY: The signature of this function ensures that the caller will only access the > + // returned credential while the file is still valid, and the C side ensures that the > + // credential stays valid at least as long as the file. > + unsafe { Credential::from_ptr(ptr) } > + } > + > /// Returns the flags associated with the file. > /// > /// The flags are a combination of the constants in [`flags`]. > diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs > index ce9abceab784..097fe9bb93ed 100644 > --- a/rust/kernel/lib.rs > +++ b/rust/kernel/lib.rs > @@ -33,6 +33,7 @@ > #[cfg(not(testlib))] > mod allocator; > mod build_assert; > +pub mod cred; > pub mod error; > pub mod file; > pub mod init; > > -- > 2.43.0.rc2.451.g8631bc7472-goog > >