From nobody Tue Dec 2 01:50:46 2025 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (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 2C87B279DAD for ; Sun, 23 Nov 2025 22:51:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763938305; cv=none; b=OjV6ri4ntnr6oTDxtry6WO8a/2RYZsCMH9J72NRU2cnZI6cD4lA4O/IIP7pOzBb1nTAvJfpUwr/hjN5n+IJMnXQohDWRp9JxvP9oIWqaJSalAysuc4vi9Z1iCLnmISx6Qx1eqhkXT/rMtFUCKZI7R+sYKO7rjpELxKr/tjxc4Rg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763938305; c=relaxed/simple; bh=TaA27OxA1hBFyRB5sQEZB6XkCgdFpDueoKtHtp+vFGM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GjBZDDw24ZL5cXvQlrGzEdZfA+bVSFZkJstQyg/lPX2fQkBZlEdI752gwa6KqEBwBVeGcZwGGJmeiDUHQmwufYHqT44QB8+y9DyNn+5oE7VOyxQ3VoBzdN+rTh6kbqPKae51aw8UaC6QAKewUya2KmeU5pki/E8n9Z2FZickLQY= 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=ftiNcTx1; arc=none smtp.client-ip=209.85.128.51 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="ftiNcTx1" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4779d47be12so29010575e9.2 for ; Sun, 23 Nov 2025 14:51:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763938301; x=1764543101; 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=PR8DhyhbmfM3XR45v/DX3VtwAUQ7pza2V3aAfSC4t8o=; b=ftiNcTx13YdP4WuIFjBYEQY9qh3Zw5EizPLOwUI0Oo29LmHJH65J9m5pF9tilsgK4R Rahz3xxfxLMMQwK14JXW532fLPTYPEwkK3ER1iCLC6qfx/26ECwO0Rv2iU494tZ7Nj+n kNNDxSdI9r705Qgcb7Msyeau1ATIy0ChwWxeIzgVQRW8cVAikB/9IKpzTRZmBmDB6vW6 fkxIN2vlVHGp7KWT88WoGGAU7COpoAKtaSOaDVh5PRcaok/AAmVbDQqger9TwVxKz6/X Xn6IB6EtTFeqJLZ6w5szBwq5njjyzULzOsqBp2lw4WThiqTSW1xjDSUFxEnTbVJOKv58 oC2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763938301; x=1764543101; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=PR8DhyhbmfM3XR45v/DX3VtwAUQ7pza2V3aAfSC4t8o=; b=r7ELr6LOkkYlL86e9S8hD8ZHA3/tGLsMTyvIMVavJQPOD2Rq6NEsKVKUxlboFkWocP 2IzPgUoDzWwJuIn0fCnpq3c3ECug9YPB3uF6+hdINQ3GO6aPMpOd/yP2Hrx9DepbKaN3 J8avsFrOF2OjYa4erTkR7iJpMTsNkjEOY2DP7rElM8FCrJE/89qqE2nyXTE8MsPReM1s +984zdDOIB99GWtPCzlG/m2w4j3aXUq8lrXWq7csZ9GspLY6EXhRz0/N8TekSvma6l1j NUzfGgxIZI3R14clLeMSF7IJXdKymi4utzqIRp+GF/nXDvR4lIpglmwjTwsGS+x+IhSc h47A== X-Forwarded-Encrypted: i=1; AJvYcCV0nH2CPbYQBeqVe2EWKqv3t/FuLIYXKhp1hO0JJFZJ3+o93o1gnsdeQSTggnGHuMHyU7p+9lQuA2S83Uk=@vger.kernel.org X-Gm-Message-State: AOJu0YzoY6yD+0eAL7pnamWyfy6j7p0+IAVMm8Wf1U2Sajhq9yVfBQVL y9lTdyk6y4vsBusVUGF6mhC9wEL0xERHjwD9/rn5sQ+LntCljTc41mD4 X-Gm-Gg: ASbGncvczJnTP4FDW6QD9tkq8OrTnZ1s2uIAIjaJ+XzezmTqfJkcB1idWrIhzfVufsB qA7c/L/kxebXT5W3SfvgqcPwFInYAM+TnpXxbS1KcWN4RuD2kzATOtEP9Kz2/Gya3ZTwuj3ULtV FR49AIpVnnUW3G4NvH6iw34ktQPdtIDduskvgnYya/A4y11+39MgbX6VyZA9w3nLRPIiExnWw9L plJiMPqYuFqbymWeGacMXu2eDGk7M1IqB6tCn3/5p5cg8daPO3qaGeSYN9HkMx7+aSPuwNy7w/8 bK3quub2DapgAilCLHq6rYus0shAa0+6rnT8/YmKNt0hSN//QTmJ9AfPlge5KOa/Q9BauNRKvZ7 aMOI1eVGvFiDPFJAE8ptLKnrQaW73GAWdhg7e1wGad+DCa9MGLwq4SHZ/MwF9kWBX8/L5IzMuiA xkvZGZAaHH+G4sUQ== X-Google-Smtp-Source: AGHT+IF2fkOx1psmIiI8t6n1UVP6WxxL86e2rgF4bc5zvWBkXEsJkKhYvtgfzcrreOJ89mrZR3pH7Q== X-Received: by 2002:a05:6000:40da:b0:42b:47da:c316 with SMTP id ffacd0b85a97d-42cc1cc30c2mr10114899f8f.26.1763938301503; Sun, 23 Nov 2025 14:51:41 -0800 (PST) Received: from 127.mynet ([2a01:4b00:bd21:4f00:7cc6:d3ca:494:116c]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42cb7fb9190sm24849064f8f.33.2025.11.23.14.51.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Nov 2025 14:51:40 -0800 (PST) From: Pavel Begunkov To: linux-block@vger.kernel.org, io-uring@vger.kernel.org Cc: Vishal Verma , tushar.gohad@intel.com, Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Alexander Viro , Christian Brauner , Andrew Morton , Sumit Semwal , =?UTF-8?q?Christian=20K=C3=B6nig?= , Pavel Begunkov , linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org Subject: [RFC v2 01/11] file: add callback for pre-mapping dmabuf Date: Sun, 23 Nov 2025 22:51:21 +0000 Message-ID: <74d689540fa200fe37f1a930165357a92fe9e68c.1763725387.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: References: 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" Add a file callback that maps a dmabuf for the given file and returns an opaque token of type struct dma_token representing the mapping. The implementation details are hidden from the caller, and the implementors are normally expected to extend the structure. The callback callers will be able to pass the token with an IO request, which implemented in following patches as a new iterator type. The user should release the token once it's not needed by calling the provided release callback via appropriate helpers. Signed-off-by: Pavel Begunkov --- include/linux/dma_token.h | 35 +++++++++++++++++++++++++++++++++++ include/linux/fs.h | 4 ++++ 2 files changed, 39 insertions(+) create mode 100644 include/linux/dma_token.h diff --git a/include/linux/dma_token.h b/include/linux/dma_token.h new file mode 100644 index 000000000000..9194b34282c2 --- /dev/null +++ b/include/linux/dma_token.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_DMA_TOKEN_H +#define _LINUX_DMA_TOKEN_H + +#include + +struct dma_token_params { + struct dma_buf *dmabuf; + enum dma_data_direction dir; +}; + +struct dma_token { + void (*release)(struct dma_token *); +}; + +static inline void dma_token_release(struct dma_token *token) +{ + token->release(token); +} + +static inline struct dma_token * +dma_token_create(struct file *file, struct dma_token_params *params) +{ + struct dma_token *res; + + if (!file->f_op->dma_map) + return ERR_PTR(-EOPNOTSUPP); + res =3D file->f_op->dma_map(file, params); + + WARN_ON_ONCE(!IS_ERR(res) && !res->release); + + return res; +} + +#endif diff --git a/include/linux/fs.h b/include/linux/fs.h index c895146c1444..0ce9a53fabec 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2262,6 +2262,8 @@ struct dir_context { struct iov_iter; struct io_uring_cmd; struct offset_ctx; +struct dma_token; +struct dma_token_params; =20 typedef unsigned int __bitwise fop_flags_t; =20 @@ -2309,6 +2311,8 @@ struct file_operations { int (*uring_cmd_iopoll)(struct io_uring_cmd *, struct io_comp_batch *, unsigned int poll_flags); int (*mmap_prepare)(struct vm_area_desc *); + struct dma_token *(*dma_map)(struct file *, + struct dma_token_params *); } __randomize_layout; =20 /* Supports async buffered reads */ --=20 2.52.0