From nobody Mon Oct 6 15:16:36 2025 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (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 E1C2F2877F2 for ; Sat, 19 Jul 2025 14:34:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752935653; cv=none; b=SqV2zqbFbABUVz9vCl45erD4oe+w4Tk6AkNX7zp1BgEZuw54h/giU4FEUdKPcOu6+AcZUyk/3Xbl93iyoElM0WIqdRYiUHRtqak2euN4+OQLCZSNQkV4UFSW54uhcsxZxbahn0O0uRTPmwVOyIqWlJMqUxVQ6OPXVi9QxKAVvMo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752935653; c=relaxed/simple; bh=H4aHIJOV1TJAq6ZuusFg9Zqr2Br14ng8uZtfr3ysksQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cbHKxEO6F8AarwiWzB1FivbcCqqP3aiHqXXDm2iBoZiJ1b8sfthxiaqfHwvBFLtqCJxOBZHsJPd/c/Vp9HrG28pmRrJKdZsnHGR9+h9HyXJnw+p/kPAi7AXR2Hi6RFjCqqSo0GNUcPfyDsERxyMyY1mqX9mgJWiOvZxOYRGjxfg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=furiosa.ai; spf=none smtp.mailfrom=furiosa.ai; dkim=pass (1024-bit key) header.d=furiosa.ai header.i=@furiosa.ai header.b=LVAHdl1W; arc=none smtp.client-ip=209.85.214.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=furiosa.ai Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=furiosa.ai Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=furiosa.ai header.i=@furiosa.ai header.b="LVAHdl1W" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-23649faf69fso25507605ad.0 for ; Sat, 19 Jul 2025 07:34:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=furiosa.ai; s=google; t=1752935651; x=1753540451; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TkIl0Ng87tj2Fj8IQfRrJkmK5nZP9FIei480gavcNNA=; b=LVAHdl1Wrq0uawe3y/ixfQc3yT6BbiwWtht0+RGCFhvZFl04LGSg35NAT9ETQYSSIc eRM78ss+P/L8QQxPEu199EbTHs/EQ9g3YV4dr3LiQM0BxAbwQ1RHRazR6lk4ixQh2zw9 6o3GqZIh3A/YNGjwytyV0iLgE2VyEjzUW+KbA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752935651; x=1753540451; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TkIl0Ng87tj2Fj8IQfRrJkmK5nZP9FIei480gavcNNA=; b=LRVIIiQKPnlONl+bWRUzU5PgAnhDMSa38J6ahBup/ZcZHA17L7ltD0PVte3YB4U7/A CqvUJYixCs3CNKB+CWEAkpz/09mh3iNO2pVf+NllJYiSnQt0lxsGT/17ateivMkfdEiv F46tBMCHRDva2pH7mhZb8bM0KFt9/wjHgm43Z8RLVyu0YOsRy0LJhVzJiExo4+SZ/gvx 6eB6wrNR8wKV8NB9TOKpsX+hx3cucCV443NOcj7qGYuohr7ZX9Vj/odqOyCKqrB+0QYX GvJjXAZGpTcEzef1TJZTM+OJz058ZlaITVtJoFKyxUD1S568HUjI1APN7m/PQ0frpiLh htig== X-Forwarded-Encrypted: i=1; AJvYcCVcRvePH8WkhUNy9H9s1Y+vFNxWx5/871oQxI+XhurvJT/ZGzs632nU5DuzWWq71rE4GSIrCZIDI3G+QJI=@vger.kernel.org X-Gm-Message-State: AOJu0YyfipQFm5SgHnOlnPv8eA8mGTV9Qf2SmN3P8wYdvj1oMvhoPb06 jWCkP6Ed4xqwmmENTPfUQoYQxvXcvVcE0P/prWRGbQjm5ZPYBWwHqwF5DhDS1+8z2gQ= X-Gm-Gg: ASbGncv75Xx+XGo3+jDenl0L62NXuHawQRc1/CWZTUBEjVL5kKJKvtB52R1gkYKo1TM 3BLH48XcQIbPSLNAK3qKGqtOGnmRdInlsqIwsbgptUGR4PpQFKmFWh3nLUFbqnW6sViVeJL5s8O oZRyKRSIRlv9z9fCBHB8e9Y2L/HKtu8Yy+voKQ63zvBzOlQerxdH5KYwtqbuhhQzh12jO5zr34y k9JWNXKek0OgxG2raC3g30n7rkXQQprX7HcFJCGpgAAHrF7hUzf7Tb4zZhJgEurBcDhS2zmCC2l 7YgunJsJ8dy12afjjJHQq30zUIPuOQGCCyWxxkbW6hZsM3YLtQCrqL1izNxAoO4y2fcKQf1UTEL aVNk0rQj+PjJPRRsnC/0qzEnkKflr+FsTW8a81FSdiiHKAKr5wbQa29n8W/U= X-Google-Smtp-Source: AGHT+IGpEs8uiBA7/aVMtHrt52Qtzk5GqQnPoy335qfDXK4TTerS+kRTHT4TOUh64k+czliVVMOb7A== X-Received: by 2002:a17:902:e88d:b0:234:ed31:fc96 with SMTP id d9443c01a7336-23e2572fbc3mr200769665ad.26.1752935651099; Sat, 19 Jul 2025 07:34:11 -0700 (PDT) Received: from sidong.sidong.yang.office.furiosa.vpn ([61.83.209.48]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-23e3b5e3d4esm30017525ad.23.2025.07.19.07.34.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Jul 2025 07:34:10 -0700 (PDT) From: Sidong Yang To: Miguel Ojeda , Arnd Bergmann , Jens Axboe Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, io-uring@vger.kernel.org, Sidong Yang Subject: [PATCH 1/4] rust: bindings: add io_uring headers in bindings_helper.h Date: Sat, 19 Jul 2025 14:33:55 +0000 Message-ID: <20250719143358.22363-2-sidong.yang@furiosa.ai> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250719143358.22363-1-sidong.yang@furiosa.ai> References: <20250719143358.22363-1-sidong.yang@furiosa.ai> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch adds two headers io_uring.h io_uring/cmd.h in bindings_helper for implementing rust io_uring abstraction. Signed-off-by: Sidong Yang --- rust/bindings/bindings_helper.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helpe= r.h index 8cbb660e2ec2..a41205e2b8b8 100644 --- a/rust/bindings/bindings_helper.h +++ b/rust/bindings/bindings_helper.h @@ -72,6 +72,8 @@ #include #include #include +#include +#include #include =20 #if defined(CONFIG_DRM_PANIC_SCREEN_QR_CODE) --=20 2.43.0 From nobody Mon Oct 6 15:16:36 2025 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 C386428850C for ; Sat, 19 Jul 2025 14:34:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752935656; cv=none; b=hY4Ts0nGRC1n1vD+FWECaN5dJkVtyBrck4imU04yI9GxLsmdRUu1yYU3IXH5aLalnE4qyO/wuGPX8WtkRAjSDtAPTc+Gm8XBH6bRKQywqtvAMF1n2n6EaqUH5/8Js1Yc/y8WH5hUIP84aMXUSNUs/WAbGaWcTPTyVlBXqArkakM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752935656; c=relaxed/simple; bh=hiYfT7g7dEoDoCFfoRNmanSXnUrnNYBQJyWlQ2T6V+I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=a6FFr/a3+2DsCQUNoOczq307UT/ZjzN+qyN6RWk0ZAjgzF5Ju9B0N/ROB733WC9CLBhizaIAZZ9BgORrDokETciUq1O6UX4czI+bP9dG4o/hVeqTy1g8NJUzLzXmyLr3SAl6Vez0dtYSalOJ/dFBpoRoHeetZJKd7uFgRKWLO8w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=furiosa.ai; spf=none smtp.mailfrom=furiosa.ai; dkim=pass (1024-bit key) header.d=furiosa.ai header.i=@furiosa.ai header.b=UHA2Vjl0; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=furiosa.ai Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=furiosa.ai Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=furiosa.ai header.i=@furiosa.ai header.b="UHA2Vjl0" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-235d6de331fso34309855ad.3 for ; Sat, 19 Jul 2025 07:34:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=furiosa.ai; s=google; t=1752935654; x=1753540454; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QoZ5l7uX723ZF26lE5z2JZL2KcJPe7FMlPZI7PwJSRw=; b=UHA2Vjl0HVSaJ5MUNvqQs9kjuKTho+MVWNouiA0AgG98jP63Fet7xfUtuOeSSO5JXx xq5i4nfJxk542Y+Gzm7Q+ny5knN4q4MLnSQwB4aIEne3FPgnREnnZvul597C0q1bAFNt 4pkkCBjs19vvD8HJEq1fUSTYuDxuD1anp5x7E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752935654; x=1753540454; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QoZ5l7uX723ZF26lE5z2JZL2KcJPe7FMlPZI7PwJSRw=; b=XRclkY2zyRhy5arI0OpbiygCMU3OhRtqjwm1PizsW6BQdLfVWvC8W/pnJwUuJVeyTP uuruog6yZI9xwCSFsm37X35psGiqVawTRNHrrPtkE1ISLpm5CWK0www2P+OuWKW83TeG cVaguuNN7+QeFDRPAiO5hnxoMwZ2AexyMq82ZG8nsUFqdbJE+hlEP/qfZ5bV3npSV6/Z 0xak7MEUc9qqJqcYxxUGuaPt5b0fkYnoZJvj1J/OrPOPXAarJjMIt8+A34POhLquWXdt PuzEFqGyWVIu8jmgfHRpX0c5fK8So6J3SViRLa5+FBcdGTO40aSkW6PUbktlPQCyAI5o m85A== X-Forwarded-Encrypted: i=1; AJvYcCWoDsSjZ1JHPfHfu6H351KG6Zb5/ZbeGjrFVohDJElL3Sqg5vGrhQALMcYMCklcJfKqOYXB6YNsxGmLabg=@vger.kernel.org X-Gm-Message-State: AOJu0YxQNfCDBOLEQjnXx30QajSbqNkO+lex87HojgLRvsPZr1IOUVa/ ujjkOsDkxCfPVXWCXWSpMdTW3NwctZsCWpG8WoNl7DBxDiZPsHmG+s5+eT9ABWYhtuMZxooOx2H 8u5Qj X-Gm-Gg: ASbGncs/eY8Z4EtrVoDF90iiyji6jyNPgmWMCLLpp+MoisHqMO6DbiyvmFHQ6zGvncV Bppe6xQYSIhZtZHHsNi9NaJ4B+5g7+MHbT86nBP9Imcwi6q8TRNvR/o1zr7JD2a5oCvsRdBSn0k LdB2qXB1Hj5VY5LUBXzKAC9dbE7QvREhHtuLPxEYFeEe1QVNGb1/QOWDcYTUjhpSAJoQeE8+kg5 BeQ0y3T9FkiO+OveqYp3r0sAufkwsDNazuGHDA7I2ubIGoQb02RtDOWzMb4zQl1NUt5WIVomX4D GaK9mIwyqPxSNnhd7kwmQwHEdCJrmJF+1Mm140fs6CYlDoKiRSMO2TWjCCRJxnl71Xd/ecGKNj5 RBpLNkwryIW1uoTOnB/k1GE/7j129z6Hk5IMXoYI5VH0tBrxXmJHCAf7OGZ7oLwO2aXT3MQ== X-Google-Smtp-Source: AGHT+IFnM/CiV+7xt++m6hPsUY32KdWuau4dLfx8UwlhOPQ9sEoM5NIlxtAMRGhEYpHMy1yGgtgf5g== X-Received: by 2002:a17:902:ef08:b0:23d:d9ae:3b56 with SMTP id d9443c01a7336-23e256b7467mr228306365ad.22.1752935654049; Sat, 19 Jul 2025 07:34:14 -0700 (PDT) Received: from sidong.sidong.yang.office.furiosa.vpn ([61.83.209.48]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-23e3b5e3d4esm30017525ad.23.2025.07.19.07.34.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Jul 2025 07:34:13 -0700 (PDT) From: Sidong Yang To: Miguel Ojeda , Arnd Bergmann , Jens Axboe Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, io-uring@vger.kernel.org, Sidong Yang Subject: [PATCH 2/4] rust: io_uring: introduce rust abstraction for io-uring cmd Date: Sat, 19 Jul 2025 14:33:56 +0000 Message-ID: <20250719143358.22363-3-sidong.yang@furiosa.ai> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250719143358.22363-1-sidong.yang@furiosa.ai> References: <20250719143358.22363-1-sidong.yang@furiosa.ai> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch introduces rust abstraction for io-uring sqe, cmd. IoUringSqe abstracts io_uring_sqe and it has cmd_data(). and IoUringCmd is abstraction for io_uring_cmd. From this, user can get cmd_op, flags, pdu and also sqe. Signed-off-by: Sidong Yang --- rust/kernel/io_uring.rs | 114 ++++++++++++++++++++++++++++++++++++++++ rust/kernel/lib.rs | 1 + 2 files changed, 115 insertions(+) create mode 100644 rust/kernel/io_uring.rs diff --git a/rust/kernel/io_uring.rs b/rust/kernel/io_uring.rs new file mode 100644 index 000000000000..7843effbedb4 --- /dev/null +++ b/rust/kernel/io_uring.rs @@ -0,0 +1,114 @@ +// SPDX-License-Identifier: GPL-2.0 + +// Copyright (C) 2025 Furiosa AI. + +//! Files and file descriptors. +//! +//! C headers: [`include/linux/io_uring/cmd.h`](srctree/include/linux/io_u= ring/cmd.h) and +//! [`include/linux/file.h`](srctree/include/linux/file.h) + +use core::mem::MaybeUninit; + +use crate::{fs::File, types::Opaque}; + +pub mod flags { + pub const COMPLETE_DEFER: i32 =3D bindings::io_uring_cmd_flags_IO_URIN= G_F_COMPLETE_DEFER; + pub const UNLOCKED: i32 =3D bindings::io_uring_cmd_flags_IO_URING_F_UN= LOCKED; + + pub const MULTISHOT: i32 =3D bindings::io_uring_cmd_flags_IO_URING_F_M= ULTISHOT; + pub const IOWQ: i32 =3D bindings::io_uring_cmd_flags_IO_URING_F_IOWQ; + pub const NONBLOCK: i32 =3D bindings::io_uring_cmd_flags_IO_URING_F_NO= NBLOCK; + + pub const SQE128: i32 =3D bindings::io_uring_cmd_flags_IO_URING_F_SQE1= 28; + pub const CQE32: i32 =3D bindings::io_uring_cmd_flags_IO_URING_F_CQE32; + pub const IOPOLL: i32 =3D bindings::io_uring_cmd_flags_IO_URING_F_IOPO= LL; + + pub const CANCEL: i32 =3D bindings::io_uring_cmd_flags_IO_URING_F_CANC= EL; + pub const COMPAT: i32 =3D bindings::io_uring_cmd_flags_IO_URING_F_COMP= AT; + pub const TASK_DEAD: i32 =3D bindings::io_uring_cmd_flags_IO_URING_F_T= ASK_DEAD; +} + +#[repr(transparent)] +pub struct IoUringCmd { + inner: Opaque, +} + +impl IoUringCmd { + /// Returns the cmd_op with associated with the io_uring_cmd. + #[inline] + pub fn cmd_op(&self) -> u32 { + // SAFETY: The call guarantees that the pointer is not dangling an= d stays valid + unsafe { (*self.inner.get()).cmd_op } + } + + /// Returns the flags with associated with the io_uring_cmd. + #[inline] + pub fn flags(&self) -> u32 { + // SAFETY: The call guarantees that the pointer is not dangling an= d stays valid + unsafe { (*self.inner.get()).flags } + } + + /// Returns the ref pdu for free use. + #[inline] + pub fn pdu(&mut self) -> MaybeUninit<&mut [u8; 32]> { + // SAFETY: The call guarantees that the pointer is not dangling an= d stays valid + unsafe { MaybeUninit::new(&mut (*self.inner.get()).pdu) } + } + + /// Constructs a new `struct io_uring_cmd` wrapper from a file descrip= tor. + #[inline] + pub unsafe fn from_raw<'a>(ptr: *const bindings::io_uring_cmd) -> &'a = IoUringCmd { + // SAFETY: The caller guarantees that the pointer is not dangling = and stays valid for the + // duration of 'a. The cast is okay because `File` is `repr(transp= arent)`. + unsafe { &*ptr.cast() } + } + + // Returns the file that referenced by uring cmd self. + #[inline] + pub fn file<'a>(&'a self) -> &'a File { + // SAFETY: The call guarantees that the pointer is not dangling an= d stays valid + let file =3D unsafe { (*self.inner.get()).file }; + unsafe { File::from_raw_file(file) } + } + + // Returns the sqe that referenced by uring cmd self. + #[inline] + pub fn sqe(&self) -> &IoUringSqe { + // SAFETY: The call guarantees that the pointer is not dangling an= d stays valid + let ptr =3D unsafe { (*self.inner.get()).sqe }; + unsafe { IoUringSqe::from_raw(ptr) } + } + + // Called by consumers of io_uring_cmd, if they originally returned -E= IOCBQUEUED upon receiving the command + #[inline] + pub fn done(self, ret: isize, res2: u64, issue_flags: u32) { + // SAFETY: The call guarantees that the pointer is not dangling an= d stays valid + unsafe { + bindings::io_uring_cmd_done(self.inner.get(), ret, res2, issue= _flags); + } + } +} + +#[repr(transparent)] +pub struct IoUringSqe { + inner: Opaque, +} + +impl<'a> IoUringSqe { + pub fn cmd_data(&'a self) -> &'a [Opaque] { + // SAFETY: The call guarantees that the pointer is not dangling an= d stays valid + unsafe { + let cmd =3D (*self.inner.get()).__bindgen_anon_6.cmd.as_ref(); + core::slice::from_raw_parts(cmd.as_ptr() as *const Opaque,= 8) + } + } + + #[inline] + pub unsafe fn from_raw(ptr: *const bindings::io_uring_sqe) -> &'a IoUr= ingSqe { + // SAFETY: The caller guarantees that the pointer is not dangling = and stays valid for the + // duration of 'a. The cast is okay because `File` is `repr(transp= arent)`. + // + // INVARIANT: The caller guarantees that there are no problematic = `fdget_pos` calls. + unsafe { &*ptr.cast() } + } +} diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index 6b4774b2b1c3..fb310e78d51d 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -80,6 +80,7 @@ pub mod fs; pub mod init; pub mod io; +pub mod io_uring; pub mod ioctl; pub mod jump_label; #[cfg(CONFIG_KUNIT)] --=20 2.43.0 From nobody Mon Oct 6 15:16:36 2025 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 BEA70288538 for ; Sat, 19 Jul 2025 14:34:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752935659; cv=none; b=XXnCXSh2QBTedWLuz/8Pd2SJirt1YQQmRYeCsXFewfmvqm6wMVkUX7dsUdD/iLXxh16ySB4F0ySWrGJDJy2YeTcrYwnIk8gSjbtpnW/mYOj2K6Rt4Ot+QB1887KH0AdR1YYfpR3sAO7apYMBNQL5evOoqLHEi33bpYHEAcpjKTQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752935659; c=relaxed/simple; bh=sLwtCfowiTS4RrXXFn1Q5b/rrzQ0SHWiAbzOJPGBWkA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WO1lbwDvWWBWofmFbC3eBUC3RTDP6WpkvEriPRZalkNOw76WSAs0bsQp22mosvvHx8KPQTSWdMCcwYyCkYVszlYY3D6o3g9UtGc1vv/rMuBaP8A7QJ9FBfWqoJmvrw7kRhaTFcJMpW8IziJ81EH5O3WEyMes8dtIOyZo14vAv64= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=furiosa.ai; spf=none smtp.mailfrom=furiosa.ai; dkim=pass (1024-bit key) header.d=furiosa.ai header.i=@furiosa.ai header.b=kFegiSQF; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=furiosa.ai Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=furiosa.ai Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=furiosa.ai header.i=@furiosa.ai header.b="kFegiSQF" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-23c703c471dso43329405ad.0 for ; Sat, 19 Jul 2025 07:34:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=furiosa.ai; s=google; t=1752935657; x=1753540457; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GJB64qIr1jI1unz5Cd2pxQc3wV9oq6+knIF/UbqEYPk=; b=kFegiSQF1cM/J6yqx8kDEapU2dFaoYgFZCRO5bDFccXG/JHj15c9/T1SUpDB7nPnX8 gTEViRWVHOTt0X91zdQu1cbjyphTiSbzpjQh94MjjEop8nSxGgSZIS67LE4yonXMK8xd MDQdTkZUJJTQfZrCq1wLZuGSZ1LHN/KaataNM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752935657; x=1753540457; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GJB64qIr1jI1unz5Cd2pxQc3wV9oq6+knIF/UbqEYPk=; b=Y0kay+AWLdRu3wW3549CQvdIYJILd9CqBMEYjtvW25uL9y75X/aeCsGKGa2yBFZg2+ +6KByZ7hrPcv4dTI7iGgBih16MDa579iUsEwGuM7HTQ5HDKdxbPUg5dugZkJWoEqMHG7 9DLIK+thgiUXEnolk3ttXkrHHWsz9c7Fgn4ABsrhFyN1dujUXnUBt+Y8fF5CNZgd3Eda 0lwPRBmRUojpnmMb9JlV4/KgJwABcExGNEvpG/yIwtDQ4/fFx1UjRPWv99RKIUqrU1RH qmjvkaqZZvJjqpwJqBCGINvsD/3hzialU17hiliMt3vsisH7fK32aOZWmTrJkjevPNQB X9zA== X-Forwarded-Encrypted: i=1; AJvYcCWLp7vB8cqQk/jOdXMM/Z7WQ/dZdyrUgrD+sTib5VvWAgIdHAMK7zZqocIFEQHwpqY/M+lFyvDaCJuzEY4=@vger.kernel.org X-Gm-Message-State: AOJu0YwwkE3H31VPCr761SPrmi3Q9a8Zk6IPkslu62/sIp98ztUjH6Mf O55WtuFzPPYugNEDGA1/G5MYpexJ72xC2xfkOJk8WfZ2lcKz7VITydsvmzNeuwVtwUk= X-Gm-Gg: ASbGncscBKFfERkD8eepa/mRLDEnXg5UXt+8+taqZScfRerpGSG73g5nUtL3Rmumsso hpfLPMsh38vCCGs5Z7trbgCi3rp9g6xkp8GxA29WMI7rBGpdnsWSUAHx7IZLZmyfYapupHAHeM4 UcpqFJzfIYKZebOzcS/vJymII1Q7U4SlNHuOVwmV3fMV1DbugSNOaBsAC3bmxAN1nnRmDtY2Hm0 VwXAfc1PZFQVekHc2DzORksspd6QdnyCWZMFMBHKNeZa+PqwVXIW3+VmQH5rC9tA8F6nh3djEEh ZcpRF0kMdAB3EZ1XOwjqJB8likPlMRgkwKBVLrl9mrGbXtny02aT7Em+t/ZnBta4/ARhqS79zwO m9gqpdwFZns4vlSBve6PkEHpXUAqv4//IVUj3XPkeROB6P/6zVXcfPz6yPx8= X-Google-Smtp-Source: AGHT+IEHwNE8IADSH4GO3pbWUP0SVea1fLKYm82T+O7m/zHFp+l1HBmhBGrJcNYJqAEcFH8nEvTaHw== X-Received: by 2002:a17:903:19eb:b0:221:751f:cfbe with SMTP id d9443c01a7336-23e2f73fea7mr182817445ad.19.1752935657000; Sat, 19 Jul 2025 07:34:17 -0700 (PDT) Received: from sidong.sidong.yang.office.furiosa.vpn ([61.83.209.48]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-23e3b5e3d4esm30017525ad.23.2025.07.19.07.34.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Jul 2025 07:34:16 -0700 (PDT) From: Sidong Yang To: Miguel Ojeda , Arnd Bergmann , Jens Axboe Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, io-uring@vger.kernel.org, Sidong Yang Subject: [PATCH 3/4] rust: miscdevice: add uring_cmd() for MiscDevice trait Date: Sat, 19 Jul 2025 14:33:57 +0000 Message-ID: <20250719143358.22363-4-sidong.yang@furiosa.ai> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250719143358.22363-1-sidong.yang@furiosa.ai> References: <20250719143358.22363-1-sidong.yang@furiosa.ai> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch adds uring_cmd() function for MiscDevice trait and its callback implementation. It uses IoUringCmd that io_uring_cmd rust abstraction. Signed-off-by: Sidong Yang --- rust/kernel/miscdevice.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/rust/kernel/miscdevice.rs b/rust/kernel/miscdevice.rs index 288f40e79906..5255faf27934 100644 --- a/rust/kernel/miscdevice.rs +++ b/rust/kernel/miscdevice.rs @@ -14,6 +14,7 @@ error::{to_result, Error, Result, VTABLE_DEFAULT_ERROR}, ffi::{c_int, c_long, c_uint, c_ulong}, fs::File, + io_uring::IoUringCmd, mm::virt::VmaNew, prelude::*, seq_file::SeqFile, @@ -175,6 +176,15 @@ fn show_fdinfo( ) { build_error!(VTABLE_DEFAULT_ERROR) } + + fn uring_cmd( + _device: ::Borrowed<'_>, + _file: &File, + _io_uring_cmd: &IoUringCmd, + issue_flags: u32, + ) -> Result { + build_error!(VTABLE_DEFAULT_ERROR) + } } =20 /// A vtable for the file operations of a Rust miscdevice. @@ -332,6 +342,25 @@ impl MiscdeviceVTable { T::show_fdinfo(device, m, file); } =20 + unsafe extern "C" fn uring_cmd( + ioucmd: *mut bindings::io_uring_cmd, + issue_flags: ffi::c_uint, + ) -> ffi::c_int { + // SAFETY: The file is valid for the duration of this call. + let ioucmd =3D unsafe { IoUringCmd::from_raw(ioucmd) }; + let file =3D ioucmd.file(); + + // SAFETY: The file is valid for the duration of this call. + let private =3D unsafe { (*file.as_ptr()).private_data }.cast(); + // SAFETY: Ioctl calls can borrow the private data of the file. + let device =3D unsafe { ::borrow(private= ) }; + + match T::uring_cmd(device, file, ioucmd, issue_flags) { + Ok(ret) =3D> ret as ffi::c_int, + Err(err) =3D> err.to_errno() as ffi::c_int, + } + } + const VTABLE: bindings::file_operations =3D bindings::file_operations { open: Some(Self::open), release: Some(Self::release), @@ -354,6 +383,11 @@ impl MiscdeviceVTable { } else { None }, + uring_cmd: if T::HAS_URING_CMD { + Some(Self::uring_cmd) + } else { + None + }, // SAFETY: All zeros is a valid value for `bindings::file_operatio= ns`. ..unsafe { MaybeUninit::zeroed().assume_init() } }; --=20 2.43.0 From nobody Mon Oct 6 15:16:36 2025 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 9B050288CBA for ; Sat, 19 Jul 2025 14:34:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752935662; cv=none; b=jJPzfnoLH268FA6rM2Ez9AEyxdNBVCQVBjCzdCHqQO/HpLa/C2QHS/6kdle3k2pnfYqqQSSE1pL6yM6kiMwRwlMn52c9tqtfgVJrSHYh0eYCKRHQ7MBK4qkyWt3OHTICOTgsTIISDs1ZbXKbfCvkaFuxaN5ri5/jpVlnNxU9sGw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752935662; c=relaxed/simple; bh=R8jGhX8GJtxbiAjtt52NeFBV/TnGPSvZljPJO54V9Lc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Pg9bKlbxEn9Ax8BWlW+qEe7TvDTDRfO0/qTyYLtUDNofbSHc8kUWGJDnB6tPToveXmrcoJ3pQNQTfcXMS/4GffuCl+42R6rv6uFyXltUmMjooaoXx4tLwKEylJcLx+LSxoSyRaVhn/2scLXDeppGwIeEog21cUpljkqoVze8q/g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=furiosa.ai; spf=none smtp.mailfrom=furiosa.ai; dkim=pass (1024-bit key) header.d=furiosa.ai header.i=@furiosa.ai header.b=aJfYuXOx; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=furiosa.ai Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=furiosa.ai Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=furiosa.ai header.i=@furiosa.ai header.b="aJfYuXOx" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-234fcadde3eso34956825ad.0 for ; Sat, 19 Jul 2025 07:34:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=furiosa.ai; s=google; t=1752935660; x=1753540460; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JXkaSAeBjzAQ8y2xwh0Xd1YosILeCAcR4SjyO3knpT8=; b=aJfYuXOxg5aGSwJytWRSxA2iVptDm6BSlt+stdfturMsUIiU+oTsmKsEAMyLSlaXqO G5TkolIGNV00tg7nANLFhpxuXloH+FwRnvq47kzMKJDEsSy22Q18K+MBRk7NVP3mYCLE nbmrHP2KLJhOGX47b3qAg/oVkz0Bny0npGBTg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752935660; x=1753540460; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JXkaSAeBjzAQ8y2xwh0Xd1YosILeCAcR4SjyO3knpT8=; b=pcWe+xgWtadBFd7tHdnfAObdmvKOTUaN+uouYUy2yF+/2EppuS686H+Qm0hIiRiM2J UQKerIV2G34z54FD4QT4wg5B9ZIIBjRB15VBhBo/wUvpaMHoo82l15lWafHF5KsdklRa g254Xn+udtApMub8TRIJikyBG5dfYhaKCVO2D7zCWkt3+gNmfsBq5m0ut4q0aeoheyEg kv2zkbx6aaRpH+mzDbZA5KqYllmanY36x9y2hHIZp1lvFJgTBJo09txGxuifO6wQZCyP A2ERFAxfxaQgzej6V2dICi99x7ml8VktKV+0nVwpUcBYKrGeEAkkATxiG0utcbMzxEtC NlZA== X-Forwarded-Encrypted: i=1; AJvYcCXP2mhcTLtXU4jBGIutQ5GhVdHoiCjIUuFYYFWPmgKiDJd0pflhFDRMe1VoZEJrGx0aVdTNzDQ4o9H0O9M=@vger.kernel.org X-Gm-Message-State: AOJu0YzAY8YH6yxnlL9plhMPDgUZolXpqfDlbgn82UpNLkjXYZ2bUKhc wZgeyaBgNWVGasyyKe9nRPzvJvx0Xd7noWuIxitRXB9pp486s9wQxOm2WTF4sn7rr8Y= X-Gm-Gg: ASbGncu/9F2tpYUR25m01OxHAeCRyFAyUQCQM4Hzx1l/hXkpc8C52iIj1x4+p3D3TlI /nItDdVgSf87o2hUmSmAsuKjby8L+uvnTwPHREyOkuJk3Kmv8KLWgL+hkWdLI/w/+JG4NsPd3v+ 2eoc9s2f9iB0+1zoO7u2T4L0CFVNMBDudGPwxTSWRB1iKizCxq5LBHMZyabL1m7A4adCQLoTQb5 G+SXJpg4GSWHoomMTQAhVdFAe03VqY1lhSk7irmLgVmWqyYFS/dOc/S49NNkinvizl+ol824Kr2 5JXtZ/w5iKqGGuPfnckNHxnF614xnpPAGj3upu952YVb5Kyhn+gDv3Y5Kw07pcT4BMPVfwHoNZK 5+s6NSZE/2G3WWRy1drtd7qi84GibPN362KwtNp4uUwkZC2CW0KYc5kV8tCc= X-Google-Smtp-Source: AGHT+IH1voNmCvwGJvMrZvclPm+sCwPYvCoAW1RlSoHG0ImiAoioy10GrH2F7hsoOibb8Z+aHB5r3g== X-Received: by 2002:a17:903:1b6c:b0:234:8ec1:4aea with SMTP id d9443c01a7336-23e2579eed1mr218928065ad.52.1752935659962; Sat, 19 Jul 2025 07:34:19 -0700 (PDT) Received: from sidong.sidong.yang.office.furiosa.vpn ([61.83.209.48]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-23e3b5e3d4esm30017525ad.23.2025.07.19.07.34.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Jul 2025 07:34:19 -0700 (PDT) From: Sidong Yang To: Miguel Ojeda , Arnd Bergmann , Jens Axboe Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, io-uring@vger.kernel.org, Sidong Yang Subject: [PATCH 4/4] samples: rust: rust_misc_device: add uring_cmd example Date: Sat, 19 Jul 2025 14:33:58 +0000 Message-ID: <20250719143358.22363-5-sidong.yang@furiosa.ai> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250719143358.22363-1-sidong.yang@furiosa.ai> References: <20250719143358.22363-1-sidong.yang@furiosa.ai> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch makes rust_misc_device handle uring_cmd. Command ops are like ioctl that set or get values in simple way. Signed-off-by: Sidong Yang --- samples/rust/rust_misc_device.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/samples/rust/rust_misc_device.rs b/samples/rust/rust_misc_devi= ce.rs index c881fd6dbd08..cd0e578231d2 100644 --- a/samples/rust/rust_misc_device.rs +++ b/samples/rust/rust_misc_device.rs @@ -101,6 +101,7 @@ c_str, device::Device, fs::File, + io_uring::IoUringCmd, ioctl::{_IO, _IOC_SIZE, _IOR, _IOW}, miscdevice::{MiscDevice, MiscDeviceOptions, MiscDeviceRegistration}, new_mutex, @@ -114,6 +115,9 @@ const RUST_MISC_DEV_GET_VALUE: u32 =3D _IOR::('|' as u32, 0x81); const RUST_MISC_DEV_SET_VALUE: u32 =3D _IOW::('|' as u32, 0x82); =20 +const RUST_MISC_DEV_URING_CMD_SET_VALUE: u32 =3D 0x83; +const RUST_MISC_DEV_URING_CMD_GET_VALUE: u32 =3D 0x84; + module! { type: RustMiscDeviceModule, name: "rust_misc_device", @@ -190,6 +194,32 @@ fn ioctl(me: Pin<&RustMiscDevice>, _file: &File, cmd: = u32, arg: usize) -> Result =20 Ok(0) } + + fn uring_cmd( + me: Pin<&RustMiscDevice>, + _file: &File, + io_uring_cmd: &IoUringCmd, + _issue_flags: u32, + ) -> Result { + dev_info!(me.dev, "UringCmd Rust Misc Device Sample\n"); + let cmd =3D io_uring_cmd.cmd_op(); + let cmd_data =3D io_uring_cmd.sqe().cmd_data().as_ptr() as *const = usize; + let addr =3D unsafe { *cmd_data }; + + match cmd { + RUST_MISC_DEV_URING_CMD_SET_VALUE =3D> { + me.set_value(UserSlice::new(addr, 8).reader())?; + } + RUST_MISC_DEV_URING_CMD_GET_VALUE =3D> { + me.get_value(UserSlice::new(addr, 8).writer())?; + } + _ =3D> { + dev_err!(me.dev, "-> uring_cmd not recognised: {}\n", cmd); + return Err(ENOTTY); + } + } + Ok(0) + } } =20 #[pinned_drop] --=20 2.43.0