From patchwork Tue Jan 23 16:10:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Obst X-Patchwork-Id: 191048 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp440577dyi; Tue, 23 Jan 2024 08:12:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IGthWODBb09gR4NezQs316FMImhat0x6sJQzCF3Uw/L5RPIU5fBkhtU3mjH05sFgmkc5QLc X-Received: by 2002:a17:907:c709:b0:a30:6107:cdea with SMTP id ty9-20020a170907c70900b00a306107cdeamr58882ejc.2.1706026324638; Tue, 23 Jan 2024 08:12:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706026324; cv=pass; d=google.com; s=arc-20160816; b=aDD9kqDzQZin/WIQTgFMVwvKOoApMlZdIdTDksOkOWOssROKXICDDzkl/0XmB9bPXA TLWlJJQnPCbFmB2Trc26PWNwGs597rB6RIl+upVX86RFnOBS7NgRAQXCYB4I/V/4Q1/m 4a92Y4KX39CgZzO1UhBJ7I2zaGzzGfgAGBp47eloQHxOLyHS/xq5ysuwxm5VDUYwpKSG NG/FkV9doFqXgu/FKrAxiVcvbP0JZQdhS/koKxTLWHAow+q2UNzdRo92A+BRx6AiB4CX vnCtUPMKxkn0BYaOo7AtvQwLwAaWhbdSGPP1k0D90e/TFwtlt1ZxzN2n3rhHIOr2zEW3 t/vA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=ui-outboundreport:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from; bh=ANc39AHGrGGYgwE5S+bUaCgQbwCwNpjMDAKoK49/6Yg=; fh=BZI9iWTaEf0O3fXVlcMygnOLgsZaFpsfuA9TcLqdYG4=; b=Sy9HsFJH+AWCq6N9rKKVi0r50a3Wl6gmq5988YLPhBT/zjt3+umAuhm79mHTj0AXoM XDKXC64nrGlca8DlL2UUTJCRoorgUnAxj3brdehzmdDFyklrExM36sXB7+4/be6FbpXJ BWpmRNwKuto7pU/JAJ+NBE3GDpkDQBS/iFkz3vDm7qHNX7Wb8uEMckALItLzTyZYNzsW 25TRjoUtz7yhWLiml7jimWzDHUVAhEsX9pqovJP6O8Rz+hQnjcKbuTcGMl8Nau5d0wer mrp/rUB8x9eSCfbFrnpCrhmYB9l3kUSKOh+Ct3LAWALb6rsuDvOa1UpDhkHxEpNm6ssi bLJg== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=valentinobst.de); spf=pass (google.com: domain of linux-kernel+bounces-35631-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35631-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id i3-20020a170906250300b00a2ca9f3ce99si10922325ejb.661.2024.01.23.08.12.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 08:12:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-35631-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=valentinobst.de); spf=pass (google.com: domain of linux-kernel+bounces-35631-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35631-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 1E3DA1F21272 for ; Tue, 23 Jan 2024 16:12:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4E1446BB55; Tue, 23 Jan 2024 16:10:31 +0000 (UTC) Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.126.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A64C3612ED; Tue, 23 Jan 2024 16:10:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.126.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706026228; cv=none; b=Naq+pPnLwStlMo4G5MqgTVA/Unp+D+euvKkJamtGzcIlWv2/XLGZJpMP6slWUrR16mULo+YCl9NZAtoRoVikZ+Vj25sz1hrGR6fCeaF97CHZcnl4SBIf4vC9ysn1CkcJHGsZtTrxD/Qf5CBrLhbYhGnH860BahaXip6uUErohPM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706026228; c=relaxed/simple; bh=yNxLPKFKZ3J06UdonBVMW5YOPuqcKhVVrMz3VR5s+xM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hvC80aNq5FrKRMiGJAuki0X+BiD0Ck68pRqK3JC6BcjbeB3Zg8ytIrW0urOKLGVeVTmayyTPmKVJbSSh6DJi7zmk9laNSE7CDdwymgtUkfQijh5uwwatLrP4qM3fF0yc4wafLkT+r5t9VojihyQ3lzrMpYkUjB3Kb0RHSIekC2Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=valentinobst.de; spf=pass smtp.mailfrom=valentinobst.de; arc=none smtp.client-ip=212.227.126.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=valentinobst.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=valentinobst.de Received: from localhost.localdomain ([95.223.130.98]) by mrelayeu.kundenserver.de (mreue009 [213.165.67.97]) with ESMTPSA (Nemesis) id 1MRmsE-1rYGfy13MI-00TFbA; Tue, 23 Jan 2024 17:10:08 +0100 From: Valentin Obst To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 10/12] rust: kernel: add doclinks Date: Tue, 23 Jan 2024 17:10:07 +0100 Message-ID: <20240123161007.125380-1-kernel@valentinobst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240123150112.124084-1-kernel@valentinobst.de> References: <20240123150112.124084-1-kernel@valentinobst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Provags-ID: V03:K1:AYk5K0DI/SeWiuqD1FwjDB4RASXP+DR8GlmX0yrZEINI+MyAPQ1 flxlJl42P3tRBLLjJo001pw3HRffuZ5eqK/SCAxR4K7mzt1Dzya9bY2CTWrEkS2jQwSjZok 5NTNrhjKg3ZuSt4mdT6hD4pGULN6HuhWmTW9L/bSV5yEDwHbjRjg8nKIwT2c1hAD6NrUuXC 0LKknSklVTmUdDBi+faLw== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:JcwRn86CuEo=;E4gMNnRFw+wRTIjyK2DmlkoHTYq MNhN/4+rRSGmzclDMty8eLoFMSIOd20kALaVhdLkvqTkE1SFw5Bn1iiYuPpwjIY06aEe2S421 e8iK1p5Ei1RyV1zTl/GaKlASHO6TwRqpTtbbiziwx4oBh4+ewATqfK7O5t54GONq6a5JOSFPR 55Peov9PXa8tpQq0lcbTPQ1glNVC0I97DKJarOz9S6SsYQweyE+O4y8GupvYs/YL9UaJ5wgY1 wYhBSURtFDHHV5jlrqet9QU10eWFra0qKc+oMr60IgnpLPPlgbEv4zE6Pnuh3RhUTKxdhiNNN jP76k3v4tJ7vp/caBEB+aMN1ZDVzv1Kb2hukC1l6qJbqHvQ0hfSeyzunOySpIyjdj3UNblE9p pQ2U2c+1rvBg7Rf1fYs5kLL8q3KWKt1WP5EBeJy8XNR88KN8z0R99E7xTwZR8dXgVMxMeJgtz 2jSZup6mvXfXMOLhQxLrO9DRyLjvO//Z6G/AxFhkESbPe+UkLtO1kfKCYz1po8qMGF0JWYSOy OoULW7SrvdPnIEvs0CetPmHv+KgP6YMUgnqZQBwA671BQNIqQaNC0lSbMPuol35O/ImZ8NYWb 07v4RHZ6NPX6y/C2qEKEuFoFuIqGwDbfAHBC9vgpzLbqLbbhAgioQM5HM4rIrRL0O93UAi4qc otQ++JnattkOpmaRYrfHDnJpTUhg/hoMJcqq3YSj5jc2sRpfUXjWITsmi5EOaArLySsDzUfLp EYkxSyX4nMWCjdTeEvnh9FcjkraVGO3lDoKe3cLy0jETW7deXRnctR+TPZIeBi95MzZ7J0Lru rSPTt5C1saWDjtfl5dxHiw1UENwgdJoCv7JBOS3pCYDcH5VT5Mq99SzjT69EcF7tFTbkDD289 bnoKARD1gGHdcqQ== X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788898259422861004 X-GMAIL-MSGID: 1788898259422861004 Add doclinks to existing documentation. Signed-off-by: Valentin Obst Reviewed-by: Trevor Gross Reviewed-by: Martin Rodriguez Reboredo --- rust/kernel/sync/arc.rs | 6 +++--- rust/kernel/sync/lock.rs | 13 +++++++++--- rust/kernel/workqueue.rs | 45 ++++++++++++++++++++++++---------------- 3 files changed, 40 insertions(+), 24 deletions(-) diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs index 6c46b1affca5..936bc549a082 100644 --- a/rust/kernel/sync/arc.rs +++ b/rust/kernel/sync/arc.rs @@ -365,12 +365,12 @@ fn from(item: Pin>) -> Self { /// A borrowed reference to an [`Arc`] instance. /// /// For cases when one doesn't ever need to increment the refcount on the allocation, it is simpler -/// to use just `&T`, which we can trivially get from an `Arc` instance. +/// to use just `&T`, which we can trivially get from an [`Arc`] instance. /// /// However, when one may need to increment the refcount, it is preferable to use an `ArcBorrow` /// over `&Arc` because the latter results in a double-indirection: a pointer (shared reference) -/// to a pointer (`Arc`) to the object (`T`). An [`ArcBorrow`] eliminates this double -/// indirection while still allowing one to increment the refcount and getting an `Arc` when/if +/// to a pointer ([`Arc`]) to the object (`T`). An [`ArcBorrow`] eliminates this double +/// indirection while still allowing one to increment the refcount and getting an [`Arc`] when/if /// needed. /// /// # Invariants diff --git a/rust/kernel/sync/lock.rs b/rust/kernel/sync/lock.rs index 67588654c22f..956a0618ecc6 100644 --- a/rust/kernel/sync/lock.rs +++ b/rust/kernel/sync/lock.rs @@ -21,14 +21,21 @@ /// # Safety /// /// - Implementers must ensure that only one thread/CPU may access the protected data once the lock -/// is owned, that is, between calls to `lock` and `unlock`. -/// - Implementers must also ensure that `relock` uses the same locking method as the original +/// is owned, that is, between calls to [`lock`] and [`unlock`]. +/// - Implementers must also ensure that [`relock`] uses the same locking method as the original /// lock operation. +/// +/// [`lock`]: Backend::lock +/// [`unlock`]: Backend::unlock +/// [`relock`]: Backend::relock pub unsafe trait Backend { /// The state required by the lock. type State; - /// The state required to be kept between `lock` and `unlock`. + /// The state required to be kept between [`lock`] and [`unlock`]. + /// + /// [`lock`]: Backend::lock + /// [`unlock`]: Backend::unlock type GuardState; /// Initialises the lock. diff --git a/rust/kernel/workqueue.rs b/rust/kernel/workqueue.rs index d900dc911149..ed3af3491b47 100644 --- a/rust/kernel/workqueue.rs +++ b/rust/kernel/workqueue.rs @@ -12,19 +12,19 @@ //! //! # The raw API //! -//! The raw API consists of the `RawWorkItem` trait, where the work item needs to provide an +//! The raw API consists of the [`RawWorkItem`] trait, where the work item needs to provide an //! arbitrary function that knows how to enqueue the work item. It should usually not be used //! directly, but if you want to, you can use it without using the pieces from the safe API. //! //! # The safe API //! -//! The safe API is used via the `Work` struct and `WorkItem` traits. Furthermore, it also includes -//! a trait called `WorkItemPointer`, which is usually not used directly by the user. +//! The safe API is used via the [`Work`] struct and [`WorkItem`] traits. Furthermore, it also +//! includes a trait called [`WorkItemPointer`], which is usually not used directly by the user. //! -//! * The `Work` struct is the Rust wrapper for the C `work_struct` type. -//! * The `WorkItem` trait is implemented for structs that can be enqueued to a workqueue. -//! * The `WorkItemPointer` trait is implemented for the pointer type that points at a something -//! that implements `WorkItem`. +//! * The [`Work`] struct is the Rust wrapper for the C `work_struct` type. +//! * The [`WorkItem`] trait is implemented for structs that can be enqueued to a workqueue. +//! * The [`WorkItemPointer`] trait is implemented for the pointer type that points at a something +//! that implements [`WorkItem`]. //! //! ## Example //! @@ -218,7 +218,9 @@ pub fn try_spawn(&self, func: T) -> Result<(), All } } -/// A helper type used in `try_spawn`. +/// A helper type used in [`try_spawn`]. +/// +/// [`try_spawn`]: Queue::try_spawn #[pin_data] struct ClosureWork { #[pin] @@ -258,9 +260,11 @@ fn run(mut this: Pin>) { /// /// # Safety /// -/// Implementers must ensure that any pointers passed to a `queue_work_on` closure by `__enqueue` +/// Implementers must ensure that any pointers passed to a `queue_work_on` closure by [`__enqueue`] /// remain valid for the duration specified in the guarantees section of the documentation for -/// `__enqueue`. +/// [`__enqueue`]. +/// +/// [`__enqueue`]: RawWorkItem::__enqueue pub unsafe trait RawWorkItem { /// The return type of [`Queue::enqueue`]. type EnqueueOutput; @@ -290,10 +294,11 @@ unsafe fn __enqueue(self, queue_work_on: F) -> Self::EnqueueOutput /// Defines the method that should be called directly when a work item is executed. /// -/// This trait is implemented by `Pin>` and `Arc`, and is mainly intended to be +/// This trait is implemented by `Pin>` and [`Arc`], and is mainly intended to be /// implemented for smart pointer types. For your own structs, you would implement [`WorkItem`] -/// instead. The `run` method on this trait will usually just perform the appropriate -/// `container_of` translation and then call into the `run` method from the [`WorkItem`] trait. +/// instead. The [`run`] method on this trait will usually just perform the appropriate +/// `container_of` translation and then call into the [`run`][WorkItem::run] method from the +/// [`WorkItem`] trait. /// /// This trait is used when the `work_struct` field is defined using the [`Work`] helper. /// @@ -309,8 +314,10 @@ pub unsafe trait WorkItemPointer: RawWorkItem { /// /// # Safety /// - /// The provided `work_struct` pointer must originate from a previous call to `__enqueue` where - /// the `queue_work_on` closure returned true, and the pointer must still be valid. + /// The provided `work_struct` pointer must originate from a previous call to [`__enqueue`] + /// where the `queue_work_on` closure returned true, and the pointer must still be valid. + /// + /// [`__enqueue`]: RawWorkItem::__enqueue unsafe extern "C" fn run(ptr: *mut bindings::work_struct); } @@ -328,12 +335,14 @@ pub trait WorkItem { /// Links for a work item. /// -/// This struct contains a function pointer to the `run` function from the [`WorkItemPointer`] +/// This struct contains a function pointer to the [`run`] function from the [`WorkItemPointer`] /// trait, and defines the linked list pointers necessary to enqueue a work item in a workqueue. /// /// Wraps the kernel's C `struct work_struct`. /// /// This is a helper type used to associate a `work_struct` with the [`WorkItem`] that uses it. +/// +/// [`run`]: WorkItemPointer::run #[repr(transparent)] pub struct Work { work: Opaque, @@ -409,7 +418,7 @@ pub unsafe fn raw_get(ptr: *const Self) -> *mut bindings::work_struct { /// } /// ``` /// -/// Note that since the `Work` type is annotated with an id, you can have several `work_struct` +/// Note that since the [`Work`] type is annotated with an id, you can have several `work_struct` /// fields by using a different id for each one. /// /// # Safety @@ -429,7 +438,7 @@ pub unsafe trait HasWork { /// Returns the offset of the [`Work`] field. /// /// This method exists because the [`OFFSET`] constant cannot be accessed if the type is not - /// `Sized`. + /// [`Sized`]. /// /// [`Work`]: Work /// [`OFFSET`]: HasWork::OFFSET