From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EAEE527A911; Mon, 28 Apr 2025 17:39:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745861963; cv=none; b=XJjkqA7mDsleLo8pGNXAoQRhagmvxywO6TUN7AW83ozC7ARTjby/5biF+JqJY4PpUYlMbBaxyfOvYLK2O+EMET3hjQfUkuOtezdoegWT0wAeg5khcJw9wI0AW2EPgOi0zOJWRNW2ldHZmx/ZFjSuvrQKBQzGhpFEpf1vbIDqo1U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745861963; c=relaxed/simple; bh=fQMNSjnB4gVshimuVVYOR1fmCiWCDutclLSx2h4MeLc=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=smszF5hnSWEYuP7DzwUxLb+jvHVdwvoAPxKrXLjq3y4uIxz1jpmzesCMjfI6nZ9ng6xRENdnoHcuCi6kv7ta/dPnEQusE5/J58M3ZzQNbmVgh+FsfzUhiGNOL54ocvpsrJm9jty5w3D9f91y5ksBmQGcqC3o9YKWq7N0qEpbw+U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=IkH1lf/X; arc=none smtp.client-ip=209.85.222.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IkH1lf/X" Received: by mail-qk1-f169.google.com with SMTP id af79cd13be357-7c08fc20194so1174305185a.2; Mon, 28 Apr 2025 10:39:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745861961; x=1746466761; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:subject:cc :to:from:date:feedback-id:message-id:from:to:cc:subject:date :message-id:reply-to; bh=IDDLCOEVMpC0X/vw5gShRSSSgzF0jyB8R6+odx3QnJs=; b=IkH1lf/XzAp+1laraHickaotwFBDJJU1TZaDN2urkIE7gL+Cz9DNKGPtQAONqj+3eD 2RiuVZyJix86JZRxq/kf5zipV9L6EwAARR27ewdjFiJ7/5wasjYLyk9RmgpRwXxurL7Z 3xOcX3puXhcMfB5qJZP35ihCTKkTdkE3/YdTRMdvrJ+7wT58xuHYvI2yBT6hJ2RiarX0 AbZu77HpZQOFJREJvwpfDQFv+5CzhWWi6cYdAqaiWDjXMhdD7pYnUR6kj1p7LjRimhVA uHhKA6fO8+mbl1W+jtVQ+rsiU8LIA/ruF6C01p2B08zW6gwBh86It6W8HcrYR5Mo4XXa hyMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745861961; x=1746466761; h=in-reply-to:content-disposition:mime-version:references:subject:cc :to:from:date:feedback-id:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IDDLCOEVMpC0X/vw5gShRSSSgzF0jyB8R6+odx3QnJs=; b=sYDM2BMzBu0Cp6LIcbOUgVxfKWBTUxnY7dBOI3enbs5nIOb4i7y1ofFzTzlZQKLK7p MB+PfXOXqztyJ8UHoiZkepMykPyLPEwS1esjlkaBM9vD5UJg3eftklE7DIossgC826iM UZFXMcHVG5WYMsQWlNFdo4recn82RusSjp2QpBdBSPtRv/QxyOk4CA/adfZApViQMMAj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Gd26yVfmA== X-Received: by 2002:a05:620a:1a22:b0:7c5:4f6f:3d13 with SMTP id af79cd13be357-7c9668bfd98mr1472535385a.42.1745861960497; Mon, 28 Apr 2025 10:39:20 -0700 (PDT) Received: from fauth-a1-smtp.messagingengine.com (fauth-a1-smtp.messagingengine.com. [103.168.172.200]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c958ce3cf6sm647137585a.64.2025.04.28.10.39.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Apr 2025 10:39:20 -0700 (PDT) Message-ID: <680fbd48.050a0220.398eb0.7d07@mx.google.com> X-Google-Original-Message-ID: Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfauth.phl.internal (Postfix) with ESMTP id 1B2541200079; Mon, 28 Apr 2025 13:39:19 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-03.internal (MEProxy); Mon, 28 Apr 2025 13:39:19 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvieduheejucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddt vdenucfhrhhomhepuehoqhhunhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrih hlrdgtohhmqeenucggtffrrghtthgvrhhnpefhtedvgfdtueekvdekieetieetjeeihedv teehuddujedvkedtkeefgedvvdehtdenucffohhmrghinhepkhgvrhhnvghlrdhorhhgne cuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepsghoqhhu nhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedtieegqdduje ejkeehheehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfhhigihmvgdr nhgrmhgvpdhnsggprhgtphhtthhopedvhedpmhhouggvpehsmhhtphhouhhtpdhrtghpth htohepuggrkhhrsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehgrhgvghhkhheslhhi nhhugihfohhunhgurghtihhonhdrohhrghdprhgtphhtthhopehrrghfrggvlheskhgvrh hnvghlrdhorhhgpdhrtghpthhtohepsghhvghlghgrrghssehgohhoghhlvgdrtghomhdp rhgtphhtthhopehkfihilhgtiiihnhhskhhisehkvghrnhgvlhdrohhrghdprhgtphhtth hopeiihhhifiesnhhvihguihgrrdgtohhmpdhrtghpthhtoheptghjihgrsehnvhhiughi rgdrtghomhdprhgtphhtthhopehjhhhusggsrghrugesnhhvihguihgrrdgtohhmpdhrtg hpthhtohepsghskhgvghhgshesnhhvihguihgrrdgtohhm X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 28 Apr 2025 13:39:18 -0400 (EDT) Date: Mon, 28 Apr 2025 10:39:17 -0700 From: Boqun Feng To: Danilo Krummrich Cc: gregkh@linuxfoundation.org, rafael@kernel.org, bhelgaas@google.com, kwilczynski@kernel.org, zhiw@nvidia.com, cjia@nvidia.com, jhubbard@nvidia.com, bskeggs@nvidia.com, acurrid@nvidia.com, joelagnelf@nvidia.com, ttabi@nvidia.com, acourbot@nvidia.com, ojeda@kernel.org, alex.gaynor@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, benno.lossin@proton.me, a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu, linux-pci@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 0/3] Devres optimization with bound devices References: <20250428140137.468709-1-dakr@kernel.org> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250428140137.468709-1-dakr@kernel.org> On Mon, Apr 28, 2025 at 04:00:26PM +0200, Danilo Krummrich wrote: > This patch series implements a direct accessor for the data stored within > a Devres container for cases where we can prove that we own a reference > to a Device (i.e. a bound device) of the same device that was used > to create the corresponding Devres container. > > Usually, when accessing the data stored within a Devres container, it is > not clear whether the data has been revoked already due to the device > being unbound and, hence, we have to try whether the access is possible > and subsequently keep holding the RCU read lock for the duration of the > access. > > However, when we can prove that we hold a reference to Device > matching the device the Devres container has been created with, we can > guarantee that the device is not unbound for the duration of the > lifetime of the Device reference and, hence, it is not possible > for the data within the Devres container to be revoked. > > Therefore, in this case, we can bypass the atomic check and the RCU read > lock, which is a great optimization and simplification for drivers. > Acked-by: Boqun Feng You would need to, however, change the titles for patch #2 and #3 because there is no `Devres::access_with()` any more. Regards, Boqun > The patches of this series are also available in [1]. > > [1] https://web.git.kernel.org/pub/scm/linux/kernel/git/dakr/linux.git/log/?h=rust/devres > > Changes in v2: > - Revocable::access(): remvoe explicit lifetimes; don't refer to 'a in > the safety requirement > - Devres::access() > - rename Devres::access_with() to Devres::access() > - add missing '```' at the end of the example > - remove 's lifetime > - add # Errors section > > Danilo Krummrich (3): > rust: revocable: implement Revocable::access() > rust: devres: implement Devres::access_with() > samples: rust: pci: take advantage of Devres::access_with() > > rust/kernel/devres.rs | 38 +++++++++++++++++++++++++++++++++ > rust/kernel/revocable.rs | 12 +++++++++++ > samples/rust/rust_driver_pci.rs | 12 +++++------ > 3 files changed, 56 insertions(+), 6 deletions(-) > > > base-commit: 3be746ebc1e6e32f499a65afe405df9030153a63 > -- > 2.49.0 >