From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (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 9086338B12D for ; Wed, 13 May 2026 10:06:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778666764; cv=none; b=sQxS2FzMr+SMG+oesINHyaw8YuhoVsA9gqtdqy0zhh9d3Yna+Mh2UzZUNsRsLo7V01AORgfAh311yOP9E7hnET48g7gZrrYMzubOYIx6ImRlKyBvL4aBJoeDxQ6WJ1wK5Fnh7y7aIA+eYrGGDSCkacqDTS8VeQrlfRa6LIElSVM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778666764; c=relaxed/simple; bh=CfUsDrF5ylNvxQAC5m07A4hEbvmSGmwJUzmCib0VNCs=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ppBIOUavsNuIppXSHZ+Md0TK/ak1KUh2lB1m+yf/FWue90SXI3bybUyM7sYLOadrzIMF0pKWrFcLIcjNAxymX2JZtCfrOb4I+HsvEprwDtdCDbgTvsDvA8UtNnq9Cz3M2z/nbWH0hXt32O19rEWaA8TTSExyFMTz9rTNgsCsBEU= 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=nYiQ/0MW; arc=none smtp.client-ip=209.85.218.50 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="nYiQ/0MW" Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-bd2e8931915so283363566b.1 for ; Wed, 13 May 2026 03:06:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778666761; x=1779271561; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=Y8agHE2UtR+0v8hUNRpGN3/NHmgQczj9TZKmKbKc+JU=; b=nYiQ/0MWx9zqnzz8qzzGMzyLjhAbZWS6PTm/379VNMshJcLtpIu5kxF6cnraFj1DbO BlzU1fL4lAJVK+xJyT+t0C2pgU0zXoRNRBJDuoDV7aRAV8/BXPrXurjZhhbFPRP66G4B IJsfO+VD/5yKfUDzBtYj/qCOyb/VG1WmTK1QWVOgt5y86ToAS0jGu5rCD0iTU4ZwdKbt PGSxd6voPOYFRhsskQZ2JVQRddLAKGHuQPOZVZK0jJea0/IaUCVN2Tich+MDh3mSnq/3 vJA4Hf9G9AHe9O8fkuLzpoR2r1IZWqWqTZZsA1X2Vx2+bgVyylnlQ272ERqYKRVGESq0 DC0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778666761; x=1779271561; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Y8agHE2UtR+0v8hUNRpGN3/NHmgQczj9TZKmKbKc+JU=; b=hDo0n3CJandCkdROixCAAt1i6Qmvot7RgpsMhQdw7YJR4NrGLVYGBCkV85tyJNR2z6 52omIXSB52gUHSXC9BjZk/5KmEjUARNaWaayqePNMHqQlqr1Tk4rrAFMFoG3SFwhyKr7 nDXQVbX2byDLRwpOW7vyWJcR9VthvLOxT6/v+r2a2M52D+r4d5C4Ffvcrl+ZHl9QOAyr P0SVgZKmSYwJk4PIqvzMRo2FbhKyX7EcgHgBFAKyC0Of8hBNgAcxWwPn95mXEpURTuC3 Maq7D1T3dVEFzyUaP2e8/0cvzD5pwjwf1mG+GFoUR5fCw7FQJ6iKa+tXpoOq4ASLpjsy BN9g== X-Forwarded-Encrypted: i=1; AFNElJ8IIllKd/vZed0pSL+45HKKI8FG4pcZlmDF/fw3momdhoj4iJzxz2nGR6JxDwEnSsO8y+QL6TgQqqExAM8=@vger.kernel.org X-Gm-Message-State: AOJu0Yy8mUW8llGlXRzA0azCEc0CfLJLZQG8uIIEfwNA5d/szj3Yczyq FxLRtR0toxGvN4hsRWTs0wAEjVFO/mt85g7KKPxUmCl238KSGEo09xRi X-Gm-Gg: Acq92OES0PMnOtsvOw61H6zNXLeM139HFm3dNxEkNsUnOpsFyi+9CglMzCJFnZkQI5x SAC2alWpNbWXRDhGFIBa+tKXfZk1kTcC8BHcIyHiLfK0oCW3njIUW/Hj6+wPDCJAv1heUdnU7d8 5pnpn26FGSadZN4Z/ufhvaQGEaayVNaJXvdn31FQLeCcUsYaMP1tBLJ7fjv8+NESOIGYOPanMMu 2QYeoVlyWGhpdCrDLXHM5vmS6stGpoRS5caif3FQGNZdelyzMQ57pnR7mN6Oe/ys0g627Gtx+tq wgWgwQ5wUnhOqvS6E5ediKVrswMicvP9OOaR8i7TzomOCIebt/bj0BcbhUUKg7lwxe/3AYZttze HN1lfwZz+ncM6oOLMEJc5HZCB4zwx0W1qTyvdL4M4HHPzzCMHQLyZ6DpHbe/FX0eICKmNaePXSy cw+pRmOh5at7o5RDhRYjsslrAmSafpKeBTr6UYHlZi77l2VQ08EG7UwPPiWYl2 X-Received: by 2002:a17:907:9493:b0:bc5:2352:555c with SMTP id a640c23a62f3a-bd3add39c4bmr174356866b.14.1778666759127; Wed, 13 May 2026 03:05:59 -0700 (PDT) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-bd2dba8fd22sm216615666b.16.2026.05.13.03.05.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2026 03:05:58 -0700 (PDT) Date: Wed, 13 May 2026 11:05:57 +0100 From: David Laight To: Pavel Begunkov Cc: Jens Axboe , Keith Busch , Christoph Hellwig , Sagi Grimberg , Alexander Viro , Christian Brauner , Andrew Morton , Sumit Semwal , Christian =?UTF-8?B?S8O2bmln?= , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, Nitesh Shetty , Kanchan Joshi , Anuj Gupta , Tushar Gohad , William Power , Phil Cayton , Jason Gunthorpe Subject: Re: [PATCH v3 02/10] iov_iter: add iterator type for dmabuf maps Message-ID: <20260513110557.705bdeed@pumpkin> In-Reply-To: <20a233d2f35274817aa643cc0fe113707eb47e72.1777475843.git.asml.silence@gmail.com> References: <20a233d2f35274817aa643cc0fe113707eb47e72.1777475843.git.asml.silence@gmail.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Wed, 29 Apr 2026 16:25:48 +0100 Pavel Begunkov wrote: > Introduce a new iterator type for dmabuf maps. The map in an opaque > object with internals and format specific to the subsystem / driver, and > only it can use that subsystem / driver for issuing IO. The task of the > middle layers is to pass the map / iterator further down, maybe doing > basic splitting and length checking. The iterator can only be used by > operations of the file the associated map was created for. > > Suggested-by: Keith Busch > Signed-off-by: Pavel Begunkov > --- > include/linux/uio.h | 11 +++++++++++ > lib/iov_iter.c | 29 +++++++++++++++++++++++------ > 2 files changed, 34 insertions(+), 6 deletions(-) > > diff --git a/include/linux/uio.h b/include/linux/uio.h > index a9bc5b3067e3..75051aed70de 100644 > --- a/include/linux/uio.h > +++ b/include/linux/uio.h > @@ -12,6 +12,7 @@ > > struct page; > struct folio_queue; > +struct io_dmabuf_map; > > typedef unsigned int __bitwise iov_iter_extraction_t; > > @@ -29,6 +30,7 @@ enum iter_type { > ITER_FOLIOQ, > ITER_XARRAY, > ITER_DISCARD, > + ITER_DMABUF_MAP, > }; > > #define ITER_SOURCE 1 // == WRITE > @@ -71,6 +73,7 @@ struct iov_iter { > const struct folio_queue *folioq; > struct xarray *xarray; > void __user *ubuf; > + struct io_dmabuf_map *dmabuf_map; > }; > size_t count; > }; > @@ -155,6 +158,11 @@ static inline bool iov_iter_is_xarray(const struct iov_iter *i) > return iov_iter_type(i) == ITER_XARRAY; > } > > +static inline bool iov_iter_is_dmabuf_map(const struct iov_iter *i) > +{ > + return iov_iter_type(i) == ITER_DMABUF_MAP; > +} > + > static inline unsigned char iov_iter_rw(const struct iov_iter *i) > { > return i->data_source ? WRITE : READ; > @@ -300,6 +308,9 @@ void iov_iter_folio_queue(struct iov_iter *i, unsigned int direction, > unsigned int first_slot, unsigned int offset, size_t count); > void iov_iter_xarray(struct iov_iter *i, unsigned int direction, struct xarray *xarray, > loff_t start, size_t count); > +void iov_iter_dmabuf_map(struct iov_iter *i, unsigned int direction, > + struct io_dmabuf_map *map, > + loff_t off, size_t count); > ssize_t iov_iter_get_pages2(struct iov_iter *i, struct page **pages, > size_t maxsize, unsigned maxpages, size_t *start); > ssize_t iov_iter_get_pages_alloc2(struct iov_iter *i, struct page ***pages, > diff --git a/lib/iov_iter.c b/lib/iov_iter.c > index 243662af1af7..e2253684b991 100644 > --- a/lib/iov_iter.c > +++ b/lib/iov_iter.c > @@ -575,7 +575,8 @@ void iov_iter_advance(struct iov_iter *i, size_t size) > { > if (unlikely(i->count < size)) > size = i->count; > - if (likely(iter_is_ubuf(i)) || unlikely(iov_iter_is_xarray(i))) { > + if (likely(iter_is_ubuf(i)) || unlikely(iov_iter_is_xarray(i)) || > + unlikely(iov_iter_is_dmabuf_map(i))) { Doesn't the extra check add more code to all the non-ubuf cases? This could be fixed by either making iter_type a bitmask (with one bit set) or writing an iter_is_one_of(i, ITER_xxx, ITER_yyy) define that uses '(1 << i->iter_type) & ((1 << ITER_xxx) | ...)' (look at the the nolibc printf code for an example). > i->iov_offset += size; > i->count -= size; > } else if (likely(iter_is_iovec(i) || iov_iter_is_kvec(i))) { > @@ -631,7 +632,8 @@ void iov_iter_revert(struct iov_iter *i, size_t unroll) > return; > } > unroll -= i->iov_offset; > - if (iov_iter_is_xarray(i) || iter_is_ubuf(i)) { > + if (iov_iter_is_xarray(i) || iter_is_ubuf(i) || iter_is_ubuf() should have been first here. -- David > + iov_iter_is_dmabuf_map(i)) { > BUG(); /* We should never go beyond the start of the specified > * range since we might then be straying into pages that > * aren't pinned. > @@ -775,6 +777,20 @@ void iov_iter_xarray(struct iov_iter *i, unsigned int direction, > } > EXPORT_SYMBOL(iov_iter_xarray); > > +void iov_iter_dmabuf_map(struct iov_iter *i, unsigned int direction, > + struct io_dmabuf_map *map, > + loff_t off, size_t count) > +{ > + WARN_ON(direction & ~(READ | WRITE)); > + *i = (struct iov_iter){ > + .iter_type = ITER_DMABUF_MAP, > + .data_source = direction, > + .dmabuf_map = map, > + .count = count, > + .iov_offset = off, > + }; > +} > + > /** > * iov_iter_discard - Initialise an I/O iterator that discards data > * @i: The iterator to initialise. > @@ -841,7 +857,7 @@ static unsigned long iov_iter_alignment_bvec(const struct iov_iter *i) > > unsigned long iov_iter_alignment(const struct iov_iter *i) > { > - if (likely(iter_is_ubuf(i))) { > + if (likely(iter_is_ubuf(i)) || iov_iter_is_dmabuf_map(i)) { > size_t size = i->count; > if (size) > return ((unsigned long)i->ubuf + i->iov_offset) | size; > @@ -872,7 +888,7 @@ unsigned long iov_iter_gap_alignment(const struct iov_iter *i) > size_t size = i->count; > unsigned k; > > - if (iter_is_ubuf(i)) > + if (iter_is_ubuf(i) || iov_iter_is_dmabuf_map(i)) > return 0; > > if (WARN_ON(!iter_is_iovec(i))) > @@ -1469,11 +1485,12 @@ EXPORT_SYMBOL_GPL(import_ubuf); > void iov_iter_restore(struct iov_iter *i, struct iov_iter_state *state) > { > if (WARN_ON_ONCE(!iov_iter_is_bvec(i) && !iter_is_iovec(i) && > - !iter_is_ubuf(i)) && !iov_iter_is_kvec(i)) > + !iter_is_ubuf(i) && !iov_iter_is_kvec(i) && > + !iov_iter_is_dmabuf_map(i))) > return; > i->iov_offset = state->iov_offset; > i->count = state->count; > - if (iter_is_ubuf(i)) > + if (iter_is_ubuf(i) || iov_iter_is_dmabuf_map(i)) > return; > /* > * For the *vec iters, nr_segs + iov is constant - if we increment