From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 147FD72617 for ; Sun, 23 Nov 2025 22:51:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763938301; cv=none; b=QHtznDuhfvEVqxNRedVseKkBtBeBRQI/qL0FYYGyaJL2ux8wHnuft8Eyhvns4D7LuvSfYITa1cNaY6NREHjacZwsOSK3bVVUXHTp/D3mGc9719mYBDyJS2zeRmVrdni3DhbKN5KZSe+NxfQmts/WOQkqZO9cGH6wwwhDuDZ2TIg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763938301; c=relaxed/simple; bh=8PyEGRkcRN3H3Qg+AG9OmNSVW+xgeo66cxYJL94BR4E=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=fxLUD2Id9WTRaFHFWGB4UgYkZY4cQOKQg+XOcvynwHFF0utoDPz6aDduASneEvnq4xzNsXL6vGUeQuE0YuFtF3mM2HNeEHaKjALsgpDxnDnXhg00NwhnMEzb7zYiFgnypgZOkMZL+z6Ifbxstha0zYbJ/3GTUFKWrPgIPFozlJQ= 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=l6BKAYFq; arc=none smtp.client-ip=209.85.128.53 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="l6BKAYFq" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-47118259fd8so31532045e9.3 for ; Sun, 23 Nov 2025 14:51:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763938298; x=1764543098; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=QZk9sSNTwOxRpwZ/DRrF1dwGfvdtNtexBNm/jAu7ryY=; b=l6BKAYFqN+Det8YbgstB6eqhQCK+zE1qvXHle/mj0weBCTEnef8YgpixLJdZkJ65iP 9p/BSabegsCDKPdS36tISi4H26MiJgGXG9BxBkcTAJVBkrQAUmRtN69eUYZuhsv/D+2k lpaPaDH+pTtEkI22e9fcCXPanrMsNzqr5114pkBfSmljaf/xtvFsVwz7m8CiqnhQ8dTm WNZX4acCn3nIqfBdbSN+gqRUilyE8ob+Fqf9zjTs9MIHLJlbzND6tThoX9/vlgLLyo0Z GiGxpfryUVqJ/5b7Z5UI1Fe9cjAzcSNdiSFnufibnxHCVr32cQ2wTVpJKz7SPSYhxFGK 7TNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763938298; x=1764543098; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=QZk9sSNTwOxRpwZ/DRrF1dwGfvdtNtexBNm/jAu7ryY=; b=HhFb3o8uEAODLqSos1qPYfpVDEAQXcnhz/9I8iKuRF1Ekuy8jaId5Vvk2Ct5iGiSTC LePGmtY2Ks9minkn3q4NQmvdggkq5iw9QUBQpwJw0DGdVWhRABhwo7Pe4zrB5Jbci7oE JtWqG9Otlb9L7If1OiD1iEFqnD98U23MSzo2ZJD7Bb9QDJwkQInr7xMH/71FSrzh5HYw 0gaNroSuQxnioH3DJoEHuxI+LZabBV8qVF/1wo0Jc4mlUVhP48wJKPcNs4H7gHTKUHm1 43j4wdNUX8i1MK/iQoHU+74fcyzQb6dJUBfqlLfjqrQY+BVWVAcgD7Tii9fGNSFvKHEl Ob0g== X-Forwarded-Encrypted: i=1; AJvYcCXnfQFEroh2KbmpUxqoX/td1v0RdIfIZ+HMJJXoNqgHugl3HFhwxc0SfYYEpfHfibkyh48+pTGaGUJ4XQTE@vger.kernel.org X-Gm-Message-State: AOJu0YzXegowqPWL3hzqmhBZorK5yjD/sEBAEqmqsqO8Im2q+ESxAPqL VJSC2YZEH82jVsBG63TVgHoz/FfId7kXYEecZ73fVglhlTAzkNS0Wt4A X-Gm-Gg: ASbGncuomJ79b38De6vGIN0cAr0DAqjTt5E0SvhOMfmUqhZjfe+Iah79SyI17QMF+HO RZIDp3kePB8Bs5j4yarYgNJvMF4v+qvcka+5xZnGbF9Q/WHojXnS1rwgMG20slA+bnOq6A8K/VY hUfGn6FDngQQzQQeDzaMSFwbK3g9AtDzAkQ3cSCPEUgGRjsA1VdC5E6y4OTuBhib9qXtYkjbgap 3mRgsN6zIp+knpTSQZ9vu51S1LtfVvimc031Erk8npT1R1ePbp0Vfzs2mY/Ky9qX+jUePvPgNiO tyC+4t7NA6PiiB53Tw8SVAEGF2/nK/HN6w07eDMxQ9Z02XtcbphWc+fRvr2Dmtcqj15cO1fd8Ot T9UOQC9RPTGeJQVy2gXr/RBbSxvtXP+QTxyddUcNH7a1+iYQRwMZiMKbGr8g6pVVq6Qlnloqh+b 5P5DgLEI+qnkEFGw== X-Google-Smtp-Source: AGHT+IEIzt6XAqBENWHKeltpmV3b1E5pfBhghZPeIUxjN0aB1YgGqF8Sp/+lNyxIs5uZ/0aP6PM4yA== X-Received: by 2002:a05:600c:5491:b0:477:fcb:226b with SMTP id 5b1f17b1804b1-477c016e60cmr94038575e9.2.1763938298240; Sun, 23 Nov 2025 14:51:38 -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.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Nov 2025 14:51:36 -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 00/11] Add dmabuf read/write via io_uring Date: Sun, 23 Nov 2025 22:51:20 +0000 Message-ID: X-Mailer: git-send-email 2.52.0 Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Picking up the work on supporting dmabuf in the read/write path. There are two main changes. First, it doesn't pass a dma addresss directly by rather wraps it into an opaque structure, which is extended and understood by the target driver. The second big change is support for dynamic attachments, which added a good part of complexity (see Patch 5). I kept the main machinery in nvme at first, but move_notify can ask to kill the dma mapping asynchronously, and any new IO would need to wait during submission, thus it was moved to blk-mq. That also introduced an extra callback layer b/w driver and blk-mq. There are some rough corners, and I'm not perfectly happy about the complexity and layering. For v3 I'll try to move the waiting up in the stack to io_uring wrapped into library helpers. For now, I'm interested what is the best way to test move_notify? And how dma_resv_reserve_fences() errors should be handled in move_notify? The uapi didn't change, after registration it looks like a normal io_uring registered buffer and can be used as such. Only non-vectored fixed reads/writes are allowed. Pseudo code: // registration reg_buf_idx = 0; io_uring_update_buffer(ring, reg_buf_idx, { dma_buf_fd, file_fd }); // request creation io_uring_prep_read_fixed(sqe, file_fd, buffer_offset, buffer_size, file_offset, reg_buf_idx); And as previously, a good bunch of code was taken from Keith's series [1]. liburing based example: git: https://github.com/isilence/liburing.git dmabuf-rw link: https://github.com/isilence/liburing/tree/dmabuf-rw [1] https://lore.kernel.org/io-uring/20220805162444.3985535-1-kbusch@fb.com/ Pavel Begunkov (11): file: add callback for pre-mapping dmabuf iov_iter: introduce iter type for pre-registered dma block: move around bio flagging helpers block: introduce dma token backed bio type block: add infra to handle dmabuf tokens nvme-pci: add support for dmabuf reggistration nvme-pci: implement dma_token backed requests io_uring/rsrc: add imu flags io_uring/rsrc: extended reg buffer registration io_uring/rsrc: add dmabuf-backed buffer registeration io_uring/rsrc: implement dmabuf regbuf import block/Makefile | 1 + block/bdev.c | 14 ++ block/bio.c | 21 +++ block/blk-merge.c | 23 +++ block/blk-mq-dma-token.c | 236 +++++++++++++++++++++++++++++++ block/blk-mq.c | 20 +++ block/blk.h | 3 +- block/fops.c | 3 + drivers/nvme/host/pci.c | 217 ++++++++++++++++++++++++++++ include/linux/bio.h | 49 ++++--- include/linux/blk-mq-dma-token.h | 60 ++++++++ include/linux/blk-mq.h | 21 +++ include/linux/blk_types.h | 8 +- include/linux/blkdev.h | 3 + include/linux/dma_token.h | 35 +++++ include/linux/fs.h | 4 + include/linux/uio.h | 10 ++ include/uapi/linux/io_uring.h | 13 +- io_uring/rsrc.c | 201 +++++++++++++++++++++++--- io_uring/rsrc.h | 23 ++- io_uring/rw.c | 7 +- lib/iov_iter.c | 30 +++- 22 files changed, 948 insertions(+), 54 deletions(-) create mode 100644 block/blk-mq-dma-token.c create mode 100644 include/linux/blk-mq-dma-token.h create mode 100644 include/linux/dma_token.h -- 2.52.0