From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.72 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796033881; b=ZNcg1KinhmEV67f9fma1yIHvxQgSjGtuVRShui+w4LvfHJCprh6Jjypvc5hU7SUpZfvH Ky2DC3Hl6LMKaWy9148erXKjh65euCir9bPznvGXnkCzM2WVuOwwoqunnbkrwLu/hX9p+ 7HBzKo3+JEedsZBlN7Etb+Ixj8/t7hlXp0oHBJe8y0YXmNeiF1LoXhoBid4LPONcagwca hM1ZWu7ygImaA9f0z0ws5DMSUmXNRl1tZ8K130t5dRavWh0bfxpsGTfHTDkyoowNX0Ub1 C5WxK6kBv3B1PjjhWOTeMpCK1Kyy4vIUhyRVDRWzvRoh5qFJyH9UxzwnT4hk3g9Twpw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796033881; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Developer-Key:X-Developer-Signature: X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=krUXzY4APFeIV7lt6MdrSTpuLFm4dQN6E4IIILYBSnY=; b=hxrDVeBOMpP98Mwjdc59SgQlgOWkWT8F+j821m0o4PaO9MtYiA/wYc2+Z3YtS+SzbSpU p1S3kxDxVYRHSrfAwNLGQWIL2IWqDXCuHnBqNCQzvteyduzDlT7YXbjWKUEUHECCMKqsP EREmO+5vjxE7rAOhWkPNlgYLyso3XisWuIxaqSfuBg8yVkb7xzkZ90fPcwuMtp9yFPuWI 4H47T/Uuwh+FMTsWewk0TkHeikV252IEMpUXfW7Z7jVBtXRjnkJPOOQfQXnI8tzUaMpdz Ofkopa/cuVjYmiO4iYxsQtHBByIsnD7rYFh9D1W9QNVwMObUdJ7I7WXYbh+5/XsiTdg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=WmcHNXfo; arc=none smtp.remote-ip=209.85.128.72 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA870606A32F for ; Mon, 30 Nov 2026 10:18:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CA870606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=WmcHNXfo Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4a16dc2323cso63436955e9.3 for ; Mon, 30 Nov 2026 02:18:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796033879; x=1796638679; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=krUXzY4APFeIV7lt6MdrSTpuLFm4dQN6E4IIILYBSnY=; b=WmcHNXfoBQvZ+4RY0w4ovFNObICDG7l+uWlEuS+2fMjQpZDrS7tmdIl5V/Z1CvdGyZ p8FF2tQuhuchMFUf6gJ//yJQXxvN+INyeeNgmoJgRrANkt3eeU0C6UsAVSZlp7j0CPSP 5ngV07h3t1irR5clOLNUeea2rYa80VSlDNM7CBqAsJB5TboP4vQiLCqtZOdb0oYyf7tf NRWhz3rQTJ66piz+R0k43W2uDF6FoACfVCXmx48Oi3Xv/BzRB2SE154TnZDxTO3eRdbC Qr6R+ODfSwUrltcmE3hBmDaR0lpXSmFe99Za9zeV+vaGcr8V2FPxdHzQ/qog2aL2J96p Tk5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796033879; x=1796638679; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=krUXzY4APFeIV7lt6MdrSTpuLFm4dQN6E4IIILYBSnY=; b=qDJIPPlt4DF/PKMu9PPvkNj6l3AUQe5XYYJFrfwaPj2asL69OZb53S8MrX6z2UEi4z tns6m1IsWzycbpqtdJ5UCSMa8N6v8+fDhIpVo06z/W4haqeWm6WJZAAmS/o9qxmwVagU 2kOId9eH9tihZGZhJnJN/RDt5lCXPv0hTW8YeCajcoJNNeZzLE2xcLlF0UsNWNVRiRXe tFMhg3LF9fcYB7eaCWhJ1oxJeJuxJIVEmfHhGy97Ne60ExlLB5fa1yh8D3ajxZqreKaO maFZ8DLQSJpHy5fl+NSMdvtW6pASDHdW93OxxDj1v2sCMAMWAvz93CyLW3KYF+aR1mWU em+Q== X-Forwarded-Encrypted: i=1; AL+hErFgKkIiD3ARgQB+sAoqbqXrFGRvD2gwFOXRoeyBUXKjqsGuYO/aLKAidzqf72fZ4vLcQgwkvBAGR3mOzhY=@vger.kernel.org X-Gm-Message-State: APuU4Z9bJM2SvAQJC7t38P4f02ZxrqCL+mdo/OeTppPkxAJmVfJww0zT bwUT01Y3F/BjbYwddWK54uwv/nJZBLN2Ov7Ee+pEJhLEhhdl8UrcqA0Om5HaUlnA+t7NIWlvnmx kl10khthE1eBH0Sv1NQ== X-Received: from wmbgx14.prod.google.com ([2002:a05:600c:858e:b0:4bb:52ec:7054]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:3113:b0:4bb:5f45:c97f with SMTP id 5b1f17b1804b1-4bb88816b2bmr706820665e9.27.1796033878966; Mon, 30 Nov 2026 02:17:58 -0800 (PST) Date: Mon, 30 Nov 2026 10:17:45 +0000 In-Reply-To: <20261130-drm-ioctl-return-i32-v1-0-2134e8274300@google.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261130-drm-ioctl-return-i32-v1-0-2134e8274300@google.com> X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=4536; i=aliceryhl@google.com; h=from:subject:message-id; bh=TVVMsq8QT8wh+kwTM2OE5GBCixlrZJgijuZUjiakCyE=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBrDU1Sr7s9m926fgf2lZIs4wlHLcRJ0nHNvFBT5 8wAZKxOz/mJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCaw1NUgAKCRAEWL7uWMY5 RgH+EACtvtxn1B4MaqyNojk4Y9SDKwo5kNmeM3xRwxBM9vn8cC4ry75ltOQvWgvyui7B5QiaGX+ GUwTTN74l1H07ndzQKcKnQiw/u+U7yOPLDzoMLhACjp+8NGD4ECHeQi7qbUd20ifNe4Z0bWZxok OKy4lGHgtLA+1rjwyg5n15HBCOjlc/iTIPYiJ3tW53Tej1XlvQ6zJvBcb9Fqzc1kz6fS9wM2vr0 5OaGGH+1qDaZW3L6L7SG5Z/5M+K5sG53jAD+S85cKi8SX/yc5wwVGC8eFwr0J0BziUhgteZ4Sfe 8lVYRhPUOYu/WoiaBUDyYwsKZ5jctTxrB4fVkzaaWF7y0e8LqdoMjfx4b8Aw6SJmNpk4xJ3a1Vk EfIzqs6ccJd2gfywsgymf+aRxMpS2vRf2TJVZ4KSisjXaJ5t014e8OYg0rPImv1Kc96xOuNCoPC IPNnuhzxo/WvrRacKvuIGeX6e1oy9bsifVbNB4hk4dxjPX/XohheU1IzqzIfuDdg7LPT2jdvAfw Qi1ig4nXsm/D5opwMHSUe74pOgZtSD/ohpncUyz7TCeFZwyovjYyTna8UWp+hlgaeh/8hKjJayw qZMx4NtKRUo2ii2Hmk6qL6a3NBoOA2A6kSEwKbPnbbl9NEVW8dkzT9VfXkNEF11g08KP+DjFYTC O2cJm20KB3+WS1Q== X-Mailer: b4 0.14.3 Message-ID: <20261130-drm-ioctl-return-i32-v1-2-2134e8274300@google.com> Subject: [PATCH 2/2] rust: drm: ioctl: document declare_drm_ioctls! arguments and assertions From: Alice Ryhl To: Danilo Krummrich Cc: Daniel Almeida , Miguel Ojeda , Boqun Feng , Gary Guo , "=?utf-8?q?Bj=C3=B6rn_Roy_Baron?=" , Benno Lossin , Andreas Hindborg , Trevor Gross , Tamir Duberstein , Alexandre Courbot , "=?utf-8?q?Onur_=C3=96zkan?=" , nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, Alice Ryhl Content-Type: text/plain; charset="utf-8" The documentation for `declare_drm_ioctls!` is currently quite incomplete, and the assertions do not provide a easily readable error message. Thus update the docs and assertions to better document how to create drm ioctls. This came up while I was teaching my Rust for Linux course. Signed-off-by: Alice Ryhl --- rust/kernel/drm/ioctl.rs | 52 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 10 deletions(-) diff --git a/rust/kernel/drm/ioctl.rs b/rust/kernel/drm/ioctl.rs index b2e7244bd5c0..d6a5a560824a 100644 --- a/rust/kernel/drm/ioctl.rs +++ b/rust/kernel/drm/ioctl.rs @@ -90,17 +90,43 @@ pub const fn __dev_ctx_cast( /// /// `(ioctl_number, argument_type, flags, user_callback),` /// -/// `argument_type` is the type name within the `bindings` crate. -/// `user_callback` should have the following prototype: +/// where: +/// +/// - `ioctl_number` is the ioctl name without the `DRM_IOCTL_` prefix; the macro prepends +/// `DRM_IOCTL_` and looks up the resulting constant in the uapi header (the header must be +/// included in `rust/uapi/uapi_helper.h`). Entries must be listed in ascending order with no +/// gaps. +/// - `argument_type` is the type name of the ioctl argument struct within `uapi`. Its size must +/// match the size encoded in the ioctl number. +/// - `flags` is a bitmask of DRM ioctl flags such as [`AUTH`](crate::drm::ioctl::AUTH), +/// [`MASTER`](crate::drm::ioctl::MASTER), [`ROOT_ONLY`](crate::drm::ioctl::ROOT_ONLY), or +/// [`RENDER_ALLOW`](crate::drm::ioctl::RENDER_ALLOW). +/// - `user_callback` is the handler function, which should have the following prototype: /// /// ```ignore -/// fn foo(device: &kernel::drm::Device, -/// reg_data: &Self::RegistrationData<'_>, -/// data: &mut uapi::argument_type, -/// file: &kernel::drm::File, +/// fn foo( +/// device: &kernel::drm::Device, +/// reg_data: &Self::RegistrationData<'_>, +/// data: &mut uapi::argument_type, +/// file: &kernel::drm::File, /// ) -> Result /// ``` -/// where `Self` is the drm::drv::Driver implementation these ioctls are being declared within. +/// +/// where `Self` is the [`drm::Driver`](crate::drm::Driver) implementation these ioctls are being +/// declared within. The callback receives four arguments: +/// +/// - `device`: the registered [`drm::Device`](crate::drm::Device) on which the ioctl was invoked. +/// - `reg_data`: the driver's [`RegistrationData`](crate::drm::Driver::RegistrationData) provided +/// when the device was registered. +/// - `data`: a mutable reference to the ioctl argument struct copied from userspace (or +/// zero-initialized when the ioctl has no input). This parameter is always `&mut` regardless of +/// the ioctl direction, even for write-only (`DRM_IOW`) ioctls; modifications are only copied +/// back to userspace when the ioctl command includes `DRM_IOR` or `DRM_IOWR`. +/// - `file`: the [`drm::File`](crate::drm::File) representing the open file descriptor on which +/// the ioctl was called. +/// +/// Returning `Ok(val)` returns `val` as the `ioctl(2)` return value (typically `0`), whereas +/// `Err(err)` returns the corresponding negative errno. /// /// # Examples /// @@ -121,9 +147,15 @@ macro_rules! declare_drm_ioctls { // and that the size of the specified type is correct. $( let cmd: u32 = $crate::macros::concat_idents!(DRM_IOCTL_, $cmd); - ::core::assert!(i == $crate::ioctl::_IOC_NR(cmd)); - ::core::assert!(core::mem::size_of::<$crate::uapi::$struct>() == - $crate::ioctl::_IOC_SIZE(cmd)); + ::core::assert!( + i == $crate::ioctl::_IOC_NR(cmd), + "DRM ioctls must be listed in order starting from DRM_COMMAND_BASE with no gaps" + ); + ::core::assert!( + ::core::mem::size_of::<$crate::uapi::$struct>() == + $crate::ioctl::_IOC_SIZE(cmd), + "DRM ioctl argument type size does not match ioctl command size" + ); let i: u32 = i + 1; )* }; -- 2.56.1.839.g22a8290db9-goog