From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=103.168.172.155 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796039120; b=UeATIT1C5Foxz620cZo34bH3ndWOUyLBTokBd/eYp1XF5Mi7I6S287qMVtn2UDpr4ANy 6nsZFGEUZR3OTkDGTJKCuY6uHvQdO3ox6iKpCFi6KOw9PoKLlNgglv8ztIzPceaRt1SrB t/Z31H7fXj0OgO9db9TzdgDr+Y6XUKf8+3cRL7uM3cUdP7zSZrnAsrpWD7JMppmWQZ2Zu KcssGDyyMdt3Fclj0lGOOhalORc9oww32YzqplF4ybnRNWyk8BgpMv0NtVXanRIoQRaqQ jMbTcWa3pLCqKeXU1qOq6k2IjT33x2bPTkEY4o6psjz7P4ShlkMRIHid0BY+SDWmBPw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796039120; h=DMARC-Filter:Received:Received:DKIM-Signature:DKIM-Signature: X-DKIM2-Info:DKIM2-Signature:X-DKIM2-Info:Message-Instance: X-ME-Sender:X-ME-Received:X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID: Received:Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; bh=jUh3Ghw1xLiLPRXfenby6X7RZpj5t2+oao6WW59TF5E=; b=oQz3uaB12gLgxie0OGJ9Y5SfxJWkPeZ3MI4Tjfza02gMGUyi5HCLTIPe2xKDPXLiW1YD qvYKH1Z9WQ4x94vm/8y64YD4voHF8ftXVHfaxDMrh/v/dvEIKjbsrr6F+MoeLLHzi6Xih J8h6R7OoZHS5B2PcIdSFBkC2ifABFfDPYHRElKeUVPHHG9PYFe694GVDmr3qT1h1r/Boq WkjoVeJTdwJgtWQX2p7WYnKOfC/UjbZdwm+yOLPmnZ6vOVDQn6X/MNNiLUWiOLw4sYLcZ ZrXm6xkJHVLSLxBJXagEcd2tnE7k3BibkKWSJp7bdR0cRY/o/AsdUxK3SqNj44aWxUw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=jannau.net; spf=pass smtp.mailfrom=jannau.net; dkim=pass header.d=jannau.net header.i=@jannau.net header.a=rsa-sha256 header.s=fm2 header.b=rtahXmQv; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b="CyaM1V/9"; arc=none smtp.remote-ip=103.168.172.155 Received: from fhigh-a4-smtp.messagingengine.com (fhigh-a4-smtp.messagingengine.com [103.168.172.155]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5E32606A331 for ; Mon, 30 Nov 2026 11:45:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B5E32606A331 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jannau.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=jannau.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=jannau.net header.i=@jannau.net header.a=rsa-sha256 header.s=fm2 header.b=rtahXmQv; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=CyaM1V/9 Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfhigh.phl.internal (Postfix) with ESMTP id F04B71402DB8 for ; Mon, 30 Nov 2026 06:45:18 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Mon, 30 Nov 2026 06:45:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jannau.net; h=cc :cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1796039118; x=1796125518; bh=jUh3Ghw1xL iLPRXfenby6X7RZpj5t2+oao6WW59TF5E=; b=rtahXmQvyqD3I/ZtETnDMUj6dK 8j4Q1/Tacljm7MO1bt7pp+0nSZevvNIJgv6m0BGjFwARAgGr4oIInijzmuQ2Ubf4 JaNKKTReSDb0Ruf+C6pL46BzxeucuzwqaxZgP1YSpQB9a/YAlJOhkgQyaQfHHQdU bWyx+bsGhkmxzV15k8w0mUSquhjL6MrLawAb578h2mmqlgypz0J1Fa2vSAUeSQO0 6uZuCU/ly4ubegRwkgMyY0/gbs8fibYnlUa/HwujVPTFsIDAjqIUVu9PqjYasoJP Dz339/y7Zw/iUF7ggj0ESyyMlaoiI8HCUtRIn/A1Bo/w2kip0gm5ljRk693A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1796039118; x=1796125518; bh=jUh3Ghw1xLiLPRXfenby6X7RZpj5t2+oao6 WW59TF5E=; b=CyaM1V/9h+A9cEVIiyCycg4vRj9b4APjDjbOOk7s0NsQyNNrFBO 1orJFlzoNxbNVLozk1bbsDknhDhn9ZD688OHnYGWWhhSYTXQmo7D/ss/ANNKmapN lS5GSpZdeNjKovXxAdN2lBKaZ0trlIqS1otHNaTRaeeOUNPpVjbWrP1Uff4AT7GK +KgVFll8Cc/vQ88higUcsrmx7qmVbjWhvKjRh+r+RUychBgdG5sNpeC8PEOppvSy 3w71N76MkO2/AuC0nzN4OdxstOOmu1jW+yuRDPFOMZ0VlggusxnOoegSF4nb2p8O 9xWl2B4a+DBw2J8j5LXjJ0uqBXdO0+3CKzw== X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=sign d=jannau.net a=rsa-sha256; DKIM2-Signature: i=1; m=1; t=1796039118; d=jannau.net; mf=PGpAamFubmF1Lm5ldD4=; rt=PGxpbnV4LWtlcm5lbEB2Z2VyLmtlcm5lbC5vcmc+; s=fm2:rsa-sha256:L1f9XDXGY/XtyGLMadBFVPAncTwTcmK1BqL1ejY5xHWgLaM r8q6aU4clWQ8eJsjMP1I2Sy1vV/ldMMPD9cqsAm6WGjWmDJfqBUPFhjQcW0pzwcc /eLei7qaaNTxbqk2aJcCY5s6x/UkhMZ56gymHrRimdTmZ8CVmWA2o3IsYFgcCJuI ca8LgqmtMG9fxHMHPfJTRud1FovE2r8lKcyf0TwZ2o3oS+hzjSkrJvKhOFu97gCS tdeS1jePceDyv78ZcVQZrMEw3bmTCox//2ZdnMLrVuE8bUSaICg2wsG0w8tAnoaY 7/AlcK1JAAyEVT9g0MU0WK67eT0mT5RBpxuClrg==; X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=mi-m=1; hc=12; hn=cc,content-disposition,content-type,date,feedback-id,from, in-reply-to,message-id,mime-version,references,subject,to; Message-Instance: m=1; h=sha256:Q7mGzJjnODqyjYfke6/0Hmk8hWoZUYg4rvhnEN1tfJU=:S9MX6ZmeGpG1mBpAmFJqW//4JfCur4fAseEiYlUySWg=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTFxajegWK9dUQuNZXU1B3yw4cyelv94ORGvpAo0vdXj6FWPemmjf/MJogr1ff4N3p FRkwwQHdeBIpKRq+KHj4spD+tWR5avBDUgU7L79X0H0UL8yulgN18NRRZG8ZszXWyerJzK QlLxBuQt0WmxB6kVF/SHy9XJhLU2QVptXfXExMcBp4osv7/CJllpUWIGMJQzxjr09GCubK h7KtCPI8u5wLRLL0aZ/NsWNSMptKkoD3oNaWlJ4efm7Hk6M9SCaz2J23uaC7yk80NcHWVx +E+utuCUAm0Isn7mISs8RVHrUxec8UJvmmot/Q+OreTo05rkKm6y2266twBVV9OuwB7GpF tqchCecBd1Zv30zOQY87e9v3CRGHcdeX/bK5ZaqGcKoYU5UdAKk3q7NrmOthWLCBvkxhx2 v8BQfLaVXVZ3+7NhCWzsbzGNXw0ben8B9ubOmi5jXKlhYDKRDfRN7r/wKuFiqyur5RPXSp TxJsq8DD5WVi6O7sltckw7TGYq2WfhHhqefqK3Dpmzd5cG0BloWRAsy1yX9LzfhZoSYcAW e16LdbP0SN6Polk30NI/eOyO9I7BPx67zVwvyTkVc5UJeVDH2bpf58E9K6eiE5WauPKExb W1oUWrgv8MOilF3n3jIdhUUDKhpMOpS8oZYJU/+NLummq6nXzoRbufXpCxAA X-ME-Proxy: Feedback-ID: i47b949f6:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 30 Nov 2026 06:45:17 -0500 (EST) Date: Mon, 30 Nov 2026 12:45:16 +0100 From: Janne Grunau To: Alice Ryhl Cc: Danilo Krummrich , Daniel Almeida , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?B?QmrDtnJu?= Roy Baron , Benno Lossin , Andreas Hindborg , Trevor Gross , Tamir Duberstein , Alexandre Courbot , Onur =?utf-8?B?w5Z6a2Fu?= , nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Subject: Re: [PATCH 2/2] rust: drm: ioctl: document declare_drm_ioctls! arguments and assertions Message-ID: <20261130114516.GB41778@robin.jannau.net> References: <20261130-drm-ioctl-return-i32-v1-0-2134e8274300@google.com> <20261130-drm-ioctl-return-i32-v1-2-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 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20261130-drm-ioctl-return-i32-v1-2-2134e8274300@google.com> On Mon, Nov 30, 2026 at 10:17:45AM +0000, Alice Ryhl wrote: > 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; > )* > }; Reviewed-by: Janne Grunau Janne