From patchwork Thu Mar 30 16:46:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13194575 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE828C7EE25 for ; Thu, 30 Mar 2023 16:47:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232764AbjC3Qrf (ORCPT ); Thu, 30 Mar 2023 12:47:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232292AbjC3QrJ (ORCPT ); Thu, 30 Mar 2023 12:47:09 -0400 Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FFAED321 for ; Thu, 30 Mar 2023 09:47:07 -0700 (PDT) Received: by mail-io1-xd33.google.com with SMTP id h187so6817631iof.7 for ; Thu, 30 Mar 2023 09:47:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1680194826; x=1682786826; 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=K4NGaKNQumVHBmJnPUCoj4JSRLmXQM6FZ5Zam1tOsx4=; b=0xgl9qbcPpXnPpzfzYkEBiHHcf0HF+wpRWyMej2tyTZ6+kw2ZNP9WdEmpYzG0qmgRC fDpUC5FtMv/0Von3VUnXWMqa2mPBg98nvr/76zPrd5WIuaiPVPFy62KAT6EjwXyM86Dv gKUX6NhN9EygZOPB44bSArElyhE8AqDQAVZWUSdLjvgbbOMqGDxdoWY2vYi+KS8FT/2L 1srBFfrOnAcSQ3ZQe5O/9qGkUTkOXWCz17+/YNW/MWL22ZIBmvalsjOitucV7OoK9BVy KerhTkpnUlPB6oV7nTO9uWHgb1xfDU8xZYbufsHfQ73GXSF/5J2saGe8e6/GvSDsuK0g i7nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680194826; x=1682786826; 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=K4NGaKNQumVHBmJnPUCoj4JSRLmXQM6FZ5Zam1tOsx4=; b=vCN7nj9glNw7ollsAF/LJ9BHI5Y+n2OSl/MCZtKQME2C3owv5Tu5fNf6Ff5qaGDATo smsZ2W7xr4Y3mw5hwJYkEHBlvj7fscHLQ7GpshUOkuYBPyMvQ1r7mWJya0jrv+rA1bNo qavaioWzvlrGUQyIg2e4Qj3z6I181rRY9+UtiAtdp6PJOEuhPKC/UJM2g4J++C9dAJHm JaTAnbPnV6HQ8Qjy94IxUvwjoP5/bpCYVsmMIcokqwFhkKKbjL536BvSWrqoN9PrsyRO vCaYRiPUDYo2yaOQKel9/hBD4W3oEin7L4c/w2B5d8joUZ0l8Kju+Vo/RhJ8zMFoiLF6 VrCw== X-Gm-Message-State: AAQBX9eGkyimxsIIyZeaYuBjGfn2gy0TKDDnUqB3fLbkY3ga8t8QUqFg 0d9bVtQA6LPlHErodlKyTS79nKmISGf9SbgAQHouTQ== X-Google-Smtp-Source: AKy350a/kxsf+6rLW0ZQJSJhFTwyNqct4efmzN2Ai76qtn2qZWfTs72/JD3IlTSE/oF9Y2jvfq5aCg== X-Received: by 2002:a6b:ce05:0:b0:758:5525:860a with SMTP id p5-20020a6bce05000000b007585525860amr1316300iob.0.1680194826546; Thu, 30 Mar 2023 09:47:06 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id v21-20020a056638251500b003a53692d6dbsm20876jat.124.2023.03.30.09.47.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:47:06 -0700 (PDT) From: Jens Axboe To: linux-fsdevel@vger.kernel.org Cc: torvalds@linux-foundation.org, brauner@kernel.org, viro@zeniv.linux.org.uk, Jens Axboe Subject: [PATCH 01/11] block: ensure bio_alloc_map_data() deals with ITER_UBUF correctly Date: Thu, 30 Mar 2023 10:46:52 -0600 Message-Id: <20230330164702.1647898-2-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330164702.1647898-1-axboe@kernel.dk> References: <20230330164702.1647898-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This helper blindly copies the iovec, even if we don't have one. Make this case a bit smarter by only doing so if we have an iovec array to copy. Signed-off-by: Jens Axboe --- block/blk-map.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/block/blk-map.c b/block/blk-map.c index 9137d16cecdc..3bfcad64d67c 100644 --- a/block/blk-map.c +++ b/block/blk-map.c @@ -29,10 +29,11 @@ static struct bio_map_data *bio_alloc_map_data(struct iov_iter *data, bmd = kmalloc(struct_size(bmd, iov, data->nr_segs), gfp_mask); if (!bmd) return NULL; - memcpy(bmd->iov, data->iov, sizeof(struct iovec) * data->nr_segs); bmd->iter = *data; - if (iter_is_iovec(data)) + if (iter_is_iovec(data)) { + memcpy(bmd->iov, data->iov, sizeof(struct iovec) * data->nr_segs); bmd->iter.iov = bmd->iov; + } return bmd; } From patchwork Thu Mar 30 16:46:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13194579 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94E29C7EE23 for ; Thu, 30 Mar 2023 16:47:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232683AbjC3Qrc (ORCPT ); Thu, 30 Mar 2023 12:47:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232315AbjC3QrL (ORCPT ); Thu, 30 Mar 2023 12:47:11 -0400 Received: from mail-il1-x134.google.com (mail-il1-x134.google.com [IPv6:2607:f8b0:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1250D33C for ; Thu, 30 Mar 2023 09:47:08 -0700 (PDT) Received: by mail-il1-x134.google.com with SMTP id e9e14a558f8ab-3261b76b17aso440665ab.0 for ; Thu, 30 Mar 2023 09:47:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1680194828; 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=T5KADcBCQpRfoMxkvcFrp6CNMp4s704nt9GxbLk5mRk=; b=SjNqtqecxNZAysEIzZL1YD4xWKUptk1YcV00LGGAVvP4MLxcpN5yPCKd8p7cjcoljK isX4BVrp3RrjTe17pcxRBIUQQYAONJpW+9RffUH2WzHcJqDQNDNVYWAW72wmBCJe8RDf /C2hP6I5R2nMZGQ61oTQTLdL5qwm74qboKaj/Yscux0BVIrSJIMIZUbmvlXJloS77sNJ EE20uFQwD5hepLhblNzIGMx2Nu4UCgt4Uq6V5rcY0fFgXq+Fn1b7Q+ly5+UcyBaKyfbJ zr6sHRDSYdT/Hyujr/vKyjU/hKh9qSZ4o1WJX4sF1ppYfQocWwgCBm1VSbOjgalTFa4b DfCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680194828; 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=T5KADcBCQpRfoMxkvcFrp6CNMp4s704nt9GxbLk5mRk=; b=tOQ56+PGdELj7+/7aCX1TGJpwUVvvOL+o9d3HWiVgUkYQX5fqyejKKteHNtL1i4xI9 Bv2jjp+AwYccGdhbJyobrRgRyLaCMMTFvM3+SO1E9isAPHiKgZAdviLjoe9uGYanv81N x8TJS2bVMIAe06bxqC+ulD/u98jm3OWtDS7Ad9aIpW+dRhlh3RUjjBZ1IvjnYba4ZMKB 5Oj74jMFUIrE1QuAu8vfqVHTJtpWl8L+ydCOpovAP64AU5gQBD5WNG75LYUXgIwyNoVo PEPl3VJ7XA/S4LZJz9itNy8FW2yZbVi9doxaV2ZaxJRn1cc9k9ElvelwbnSuANDb5Hgy LZ6g== X-Gm-Message-State: AAQBX9dJCYCcwsCOKc8sbpiPht4ekqDPEW+G04PJ8Y8T7WOLNBEFk2GV AopVsnyCrtBNJf5ndQwNOwWk3/h9xdYwfGDJNV75mA== X-Google-Smtp-Source: AKy350YxjE4LksVHrroNuBde8T2n6n/8abeeWlFKV/NNX6Trk9zAVAUsbjPA+WWHLFfcDQM59M8tXw== X-Received: by 2002:a05:6e02:48a:b0:325:e065:8bf8 with SMTP id b10-20020a056e02048a00b00325e0658bf8mr1793926ils.0.1680194827568; Thu, 30 Mar 2023 09:47:07 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id v21-20020a056638251500b003a53692d6dbsm20876jat.124.2023.03.30.09.47.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:47:07 -0700 (PDT) From: Jens Axboe To: linux-fsdevel@vger.kernel.org Cc: torvalds@linux-foundation.org, brauner@kernel.org, viro@zeniv.linux.org.uk, Jens Axboe Subject: [PATCH 02/11] iov_iter: add iter_iovec() helper Date: Thu, 30 Mar 2023 10:46:53 -0600 Message-Id: <20230330164702.1647898-3-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330164702.1647898-1-axboe@kernel.dk> References: <20230330164702.1647898-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This returns a pointer to the current iovec entry in the iterator. Only useful with ITER_IOVEC right now, but it prepares us to treat ITER_UBUF and ITER_IOVEC identically for the first segment. Rename struct iov_iter->iov to iov_iter->__iov to find any potentially troublesome spots, and also to prevent anyone from adding new code that accesses iter->iov directly. Signed-off-by: Jens Axboe --- block/blk-map.c | 4 +- drivers/infiniband/hw/hfi1/file_ops.c | 3 +- drivers/infiniband/hw/qib/qib_file_ops.c | 2 +- drivers/net/tun.c | 3 +- drivers/vhost/scsi.c | 2 +- fs/btrfs/file.c | 11 +++-- fs/fuse/file.c | 2 +- include/linux/uio.h | 9 ++-- io_uring/net.c | 4 +- io_uring/rw.c | 8 ++-- lib/iov_iter.c | 56 +++++++++++++----------- sound/core/pcm_native.c | 22 ++++++---- 12 files changed, 73 insertions(+), 53 deletions(-) diff --git a/block/blk-map.c b/block/blk-map.c index 3bfcad64d67c..04c55f1c492e 100644 --- a/block/blk-map.c +++ b/block/blk-map.c @@ -31,8 +31,8 @@ static struct bio_map_data *bio_alloc_map_data(struct iov_iter *data, return NULL; bmd->iter = *data; if (iter_is_iovec(data)) { - memcpy(bmd->iov, data->iov, sizeof(struct iovec) * data->nr_segs); - bmd->iter.iov = bmd->iov; + memcpy(bmd->iov, iter_iov(data), sizeof(struct iovec) * data->nr_segs); + bmd->iter.__iov = bmd->iov; } return bmd; } diff --git a/drivers/infiniband/hw/hfi1/file_ops.c b/drivers/infiniband/hw/hfi1/file_ops.c index b1d6ca7e9708..3065db9d6bb9 100644 --- a/drivers/infiniband/hw/hfi1/file_ops.c +++ b/drivers/infiniband/hw/hfi1/file_ops.c @@ -287,11 +287,12 @@ static ssize_t hfi1_write_iter(struct kiocb *kiocb, struct iov_iter *from) } while (dim) { + const struct iovec *iov = iter_iov(from); int ret; unsigned long count = 0; ret = hfi1_user_sdma_process_request( - fd, (struct iovec *)(from->iov + done), + fd, (struct iovec *)(iov + done), dim, &count); if (ret) { reqs = ret; diff --git a/drivers/infiniband/hw/qib/qib_file_ops.c b/drivers/infiniband/hw/qib/qib_file_ops.c index 80fe92a21f96..4cee39337866 100644 --- a/drivers/infiniband/hw/qib/qib_file_ops.c +++ b/drivers/infiniband/hw/qib/qib_file_ops.c @@ -2248,7 +2248,7 @@ static ssize_t qib_write_iter(struct kiocb *iocb, struct iov_iter *from) if (!iter_is_iovec(from) || !from->nr_segs || !pq) return -EINVAL; - return qib_user_sdma_writev(rcd, pq, from->iov, from->nr_segs); + return qib_user_sdma_writev(rcd, pq, iter_iov(from), from->nr_segs); } static struct class *qib_class; diff --git a/drivers/net/tun.c b/drivers/net/tun.c index ad653b32b2f0..5df1eba7b30a 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -1486,7 +1486,8 @@ static struct sk_buff *tun_napi_alloc_frags(struct tun_file *tfile, skb->truesize += skb->data_len; for (i = 1; i < it->nr_segs; i++) { - size_t fragsz = it->iov[i].iov_len; + const struct iovec *iov = iter_iov(it); + size_t fragsz = iov->iov_len; struct page *page; void *frag; diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c index b244e7c0f514..042caea64007 100644 --- a/drivers/vhost/scsi.c +++ b/drivers/vhost/scsi.c @@ -671,7 +671,7 @@ vhost_scsi_calc_sgls(struct iov_iter *iter, size_t bytes, int max_sgls) { int sgl_count = 0; - if (!iter || !iter->iov) { + if (!iter || !iter_iov(iter)) { pr_err("%s: iter->iov is NULL, but expected bytes: %zu" " present\n", __func__, bytes); return -EINVAL; diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 5cc5a1faaef5..f649647392e0 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -3730,10 +3730,15 @@ static int check_direct_read(struct btrfs_fs_info *fs_info, if (!iter_is_iovec(iter)) return 0; - for (seg = 0; seg < iter->nr_segs; seg++) - for (i = seg + 1; i < iter->nr_segs; i++) - if (iter->iov[seg].iov_base == iter->iov[i].iov_base) + for (seg = 0; seg < iter->nr_segs; seg++) { + for (i = seg + 1; i < iter->nr_segs; i++) { + const struct iovec *iov1 = iter_iov(iter) + seg; + const struct iovec *iov2 = iter_iov(iter) + i; + + if (iov1->iov_base == iov2->iov_base) return -EINVAL; + } + } return 0; } diff --git a/fs/fuse/file.c b/fs/fuse/file.c index de37a3a06a71..89d97f6188e0 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -1419,7 +1419,7 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from) static inline unsigned long fuse_get_user_addr(const struct iov_iter *ii) { - return (unsigned long)ii->iov->iov_base + ii->iov_offset; + return (unsigned long)iter_iov(ii)->iov_base + ii->iov_offset; } static inline size_t fuse_get_frag_size(const struct iov_iter *ii, diff --git a/include/linux/uio.h b/include/linux/uio.h index 27e3fd942960..4218624b7f78 100644 --- a/include/linux/uio.h +++ b/include/linux/uio.h @@ -51,7 +51,8 @@ struct iov_iter { }; size_t count; union { - const struct iovec *iov; + /* use iter_iov() to get the current vec */ + const struct iovec *__iov; const struct kvec *kvec; const struct bio_vec *bvec; struct xarray *xarray; @@ -68,6 +69,8 @@ struct iov_iter { }; }; +#define iter_iov(iter) (iter)->__iov + static inline enum iter_type iov_iter_type(const struct iov_iter *i) { return i->iter_type; @@ -146,9 +149,9 @@ static inline size_t iov_length(const struct iovec *iov, unsigned long nr_segs) static inline struct iovec iov_iter_iovec(const struct iov_iter *iter) { return (struct iovec) { - .iov_base = iter->iov->iov_base + iter->iov_offset, + .iov_base = iter_iov(iter)->iov_base + iter->iov_offset, .iov_len = min(iter->count, - iter->iov->iov_len - iter->iov_offset), + iter_iov(iter)->iov_len - iter->iov_offset), }; } diff --git a/io_uring/net.c b/io_uring/net.c index 4040cf093318..89e839013837 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -184,8 +184,8 @@ static int io_setup_async_msg(struct io_kiocb *req, async_msg->msg.msg_name = &async_msg->addr; /* if were using fast_iov, set it to the new one */ if (iter_is_iovec(&kmsg->msg.msg_iter) && !kmsg->free_iov) { - size_t fast_idx = kmsg->msg.msg_iter.iov - kmsg->fast_iov; - async_msg->msg.msg_iter.iov = &async_msg->fast_iov[fast_idx]; + size_t fast_idx = iter_iov(&kmsg->msg.msg_iter) - kmsg->fast_iov; + async_msg->msg.msg_iter.__iov = &async_msg->fast_iov[fast_idx]; } return -EAGAIN; diff --git a/io_uring/rw.c b/io_uring/rw.c index 4c233910e200..7573a34ea42a 100644 --- a/io_uring/rw.c +++ b/io_uring/rw.c @@ -503,10 +503,10 @@ static void io_req_map_rw(struct io_kiocb *req, const struct iovec *iovec, if (!iovec) { unsigned iov_off = 0; - io->s.iter.iov = io->s.fast_iov; - if (iter->iov != fast_iov) { - iov_off = iter->iov - fast_iov; - io->s.iter.iov += iov_off; + io->s.iter.__iov = io->s.fast_iov; + if (iter->__iov != fast_iov) { + iov_off = iter_iov(iter) - fast_iov; + io->s.iter.__iov += iov_off; } if (io->s.fast_iov != fast_iov) memcpy(io->s.fast_iov + iov_off, fast_iov + iov_off, diff --git a/lib/iov_iter.c b/lib/iov_iter.c index 274014e4eafe..87488c4aad3f 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -126,13 +126,13 @@ __out: \ iterate_buf(i, n, base, len, off, \ i->ubuf, (I)) \ } else if (likely(iter_is_iovec(i))) { \ - const struct iovec *iov = i->iov; \ + const struct iovec *iov = iter_iov(i); \ void __user *base; \ size_t len; \ iterate_iovec(i, n, base, len, off, \ iov, (I)) \ - i->nr_segs -= iov - i->iov; \ - i->iov = iov; \ + i->nr_segs -= iov - iter_iov(i); \ + i->__iov = iov; \ } else if (iov_iter_is_bvec(i)) { \ const struct bio_vec *bvec = i->bvec; \ void *base; \ @@ -355,7 +355,7 @@ size_t fault_in_iov_iter_readable(const struct iov_iter *i, size_t size) size_t skip; size -= count; - for (p = i->iov, skip = i->iov_offset; count; p++, skip = 0) { + for (p = iter_iov(i), skip = i->iov_offset; count; p++, skip = 0) { size_t len = min(count, p->iov_len - skip); size_t ret; @@ -398,7 +398,7 @@ size_t fault_in_iov_iter_writeable(const struct iov_iter *i, size_t size) size_t skip; size -= count; - for (p = i->iov, skip = i->iov_offset; count; p++, skip = 0) { + for (p = iter_iov(i), skip = i->iov_offset; count; p++, skip = 0) { size_t len = min(count, p->iov_len - skip); size_t ret; @@ -425,7 +425,7 @@ void iov_iter_init(struct iov_iter *i, unsigned int direction, .nofault = false, .user_backed = true, .data_source = direction, - .iov = iov, + .__iov = iov, .nr_segs = nr_segs, .iov_offset = 0, .count = count @@ -876,14 +876,14 @@ static void iov_iter_iovec_advance(struct iov_iter *i, size_t size) i->count -= size; size += i->iov_offset; // from beginning of current segment - for (iov = i->iov, end = iov + i->nr_segs; iov < end; iov++) { + for (iov = iter_iov(i), end = iov + i->nr_segs; iov < end; iov++) { if (likely(size < iov->iov_len)) break; size -= iov->iov_len; } i->iov_offset = size; - i->nr_segs -= iov - i->iov; - i->iov = iov; + i->nr_segs -= iov - iter_iov(i); + i->__iov = iov; } void iov_iter_advance(struct iov_iter *i, size_t size) @@ -958,12 +958,12 @@ void iov_iter_revert(struct iov_iter *i, size_t unroll) unroll -= n; } } else { /* same logics for iovec and kvec */ - const struct iovec *iov = i->iov; + const struct iovec *iov = iter_iov(i); while (1) { size_t n = (--iov)->iov_len; i->nr_segs++; if (unroll <= n) { - i->iov = iov; + i->__iov = iov; i->iov_offset = n - unroll; return; } @@ -980,7 +980,7 @@ size_t iov_iter_single_seg_count(const struct iov_iter *i) { if (i->nr_segs > 1) { if (likely(iter_is_iovec(i) || iov_iter_is_kvec(i))) - return min(i->count, i->iov->iov_len - i->iov_offset); + return min(i->count, iter_iov(i)->iov_len - i->iov_offset); if (iov_iter_is_bvec(i)) return min(i->count, i->bvec->bv_len - i->iov_offset); } @@ -1095,13 +1095,14 @@ static bool iov_iter_aligned_iovec(const struct iov_iter *i, unsigned addr_mask, unsigned k; for (k = 0; k < i->nr_segs; k++, skip = 0) { - size_t len = i->iov[k].iov_len - skip; + const struct iovec *iov = iter_iov(i) + k; + size_t len = iov->iov_len - skip; if (len > size) len = size; if (len & len_mask) return false; - if ((unsigned long)(i->iov[k].iov_base + skip) & addr_mask) + if ((unsigned long)(iov->iov_base + skip) & addr_mask) return false; size -= len; @@ -1194,9 +1195,10 @@ static unsigned long iov_iter_alignment_iovec(const struct iov_iter *i) unsigned k; for (k = 0; k < i->nr_segs; k++, skip = 0) { - size_t len = i->iov[k].iov_len - skip; + const struct iovec *iov = iter_iov(i) + k; + size_t len = iov->iov_len - skip; if (len) { - res |= (unsigned long)i->iov[k].iov_base + skip; + res |= (unsigned long)iov->iov_base + skip; if (len > size) len = size; res |= len; @@ -1273,14 +1275,15 @@ unsigned long iov_iter_gap_alignment(const struct iov_iter *i) return ~0U; for (k = 0; k < i->nr_segs; k++) { - if (i->iov[k].iov_len) { - unsigned long base = (unsigned long)i->iov[k].iov_base; + const struct iovec *iov = iter_iov(i) + k; + if (iov->iov_len) { + unsigned long base = (unsigned long)iov->iov_base; if (v) // if not the first one res |= base | v; // this start | previous end - v = base + i->iov[k].iov_len; - if (size <= i->iov[k].iov_len) + v = base + iov->iov_len; + if (size <= iov->iov_len) break; - size -= i->iov[k].iov_len; + size -= iov->iov_len; } } return res; @@ -1396,13 +1399,14 @@ static unsigned long first_iovec_segment(const struct iov_iter *i, size_t *size) return (unsigned long)i->ubuf + i->iov_offset; for (k = 0, skip = i->iov_offset; k < i->nr_segs; k++, skip = 0) { - size_t len = i->iov[k].iov_len - skip; + const struct iovec *iov = iter_iov(i) + k; + size_t len = iov->iov_len - skip; if (unlikely(!len)) continue; if (*size > len) *size = len; - return (unsigned long)i->iov[k].iov_base + skip; + return (unsigned long)iov->iov_base + skip; } BUG(); // if it had been empty, we wouldn't get called } @@ -1614,7 +1618,7 @@ static int iov_npages(const struct iov_iter *i, int maxpages) const struct iovec *p; int npages = 0; - for (p = i->iov; size; skip = 0, p++) { + for (p = iter_iov(i); size; skip = 0, p++) { unsigned offs = offset_in_page(p->iov_base + skip); size_t len = min(p->iov_len - skip, size); @@ -1691,7 +1695,7 @@ const void *dup_iter(struct iov_iter *new, struct iov_iter *old, gfp_t flags) flags); else if (iov_iter_is_kvec(new) || iter_is_iovec(new)) /* iovec and kvec have identical layout */ - return new->iov = kmemdup(new->iov, + return new->__iov = kmemdup(new->__iov, new->nr_segs * sizeof(struct iovec), flags); return NULL; @@ -1918,7 +1922,7 @@ void iov_iter_restore(struct iov_iter *i, struct iov_iter_state *state) if (iov_iter_is_bvec(i)) i->bvec -= state->nr_segs - i->nr_segs; else - i->iov -= state->nr_segs - i->nr_segs; + i->__iov -= state->nr_segs - i->nr_segs; i->nr_segs = state->nr_segs; } diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index 331380c2438b..8bb97ee6720d 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -3521,6 +3521,7 @@ static ssize_t snd_pcm_readv(struct kiocb *iocb, struct iov_iter *to) unsigned long i; void __user **bufs; snd_pcm_uframes_t frames; + const struct iovec *iov = iter_iov(to); pcm_file = iocb->ki_filp->private_data; substream = pcm_file->substream; @@ -3534,14 +3535,16 @@ static ssize_t snd_pcm_readv(struct kiocb *iocb, struct iov_iter *to) return -EINVAL; if (to->nr_segs > 1024 || to->nr_segs != runtime->channels) return -EINVAL; - if (!frame_aligned(runtime, to->iov->iov_len)) + if (!frame_aligned(runtime, iov->iov_len)) return -EINVAL; - frames = bytes_to_samples(runtime, to->iov->iov_len); + frames = bytes_to_samples(runtime, iov->iov_len); bufs = kmalloc_array(to->nr_segs, sizeof(void *), GFP_KERNEL); if (bufs == NULL) return -ENOMEM; - for (i = 0; i < to->nr_segs; ++i) - bufs[i] = to->iov[i].iov_base; + for (i = 0; i < to->nr_segs; ++i) { + bufs[i] = iov->iov_base; + iov++; + } result = snd_pcm_lib_readv(substream, bufs, frames); if (result > 0) result = frames_to_bytes(runtime, result); @@ -3558,6 +3561,7 @@ static ssize_t snd_pcm_writev(struct kiocb *iocb, struct iov_iter *from) unsigned long i; void __user **bufs; snd_pcm_uframes_t frames; + const struct iovec *iov = iter_iov(from); pcm_file = iocb->ki_filp->private_data; substream = pcm_file->substream; @@ -3570,14 +3574,16 @@ static ssize_t snd_pcm_writev(struct kiocb *iocb, struct iov_iter *from) if (!iter_is_iovec(from)) return -EINVAL; if (from->nr_segs > 128 || from->nr_segs != runtime->channels || - !frame_aligned(runtime, from->iov->iov_len)) + !frame_aligned(runtime, iov->iov_len)) return -EINVAL; - frames = bytes_to_samples(runtime, from->iov->iov_len); + frames = bytes_to_samples(runtime, iov->iov_len); bufs = kmalloc_array(from->nr_segs, sizeof(void *), GFP_KERNEL); if (bufs == NULL) return -ENOMEM; - for (i = 0; i < from->nr_segs; ++i) - bufs[i] = from->iov[i].iov_base; + for (i = 0; i < from->nr_segs; ++i) { + bufs[i] = iov->iov_base; + iov++; + } result = snd_pcm_lib_writev(substream, bufs, frames); if (result > 0) result = frames_to_bytes(runtime, result); From patchwork Thu Mar 30 16:46:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13194571 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC182C77B7D for ; Thu, 30 Mar 2023 16:47:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232452AbjC3Qr0 (ORCPT ); Thu, 30 Mar 2023 12:47:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232317AbjC3QrL (ORCPT ); Thu, 30 Mar 2023 12:47:11 -0400 Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0A1ECDF7 for ; Thu, 30 Mar 2023 09:47:09 -0700 (PDT) Received: by mail-io1-xd2b.google.com with SMTP id e13so8562962ioc.0 for ; Thu, 30 Mar 2023 09:47:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1680194829; x=1682786829; 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=4xGS1WJPD4n46wbrdJA3HTeawxdexvwLRq+jxow2GHk=; b=Pm080zNxEKZihq5GCHr1WApWy6jkwiuEYJ71qEAmlp6adzXucMDNsMWMLV2yARIa20 ArosHCZXaw1A0j1C6MkBECtcfZYECQkUa+ydrZ63aJDp5XsltUDkKfPHstWqALvD5dr8 zn9YGjZtPZ3Tqy5cSNXl7WzYhxKfe9rE6nbV0LQFD8uM+9Fj456ELIR5V866prwPBq3L t4ujRGHi86iBwUbWGKTGgFcIPUvOiSfId+V8tYf6DX54m/GFpa5gcd6PArm/R+KCzjS4 hG4NCHxQkmQhfp94rd8QpX8fTZVR1EB/jxopy9+fuwTQtaMhFYYtDewwzSTUqGVsG6aU h38g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680194829; x=1682786829; 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=4xGS1WJPD4n46wbrdJA3HTeawxdexvwLRq+jxow2GHk=; b=vGnLnkmYpimk78DUq0+XAXuh0gIWBMQhXzM8V0Pm7RhlnPCJ4HvztODDMmbrJ2k9sq ppv9Di7rwiQHrW091IgtUf1TTq6eVJ7lSPSCgOHYTXai9IpUD+EpbZfLkx7TbOv1sfsG Gl0fKI4KBZdw59rWIl9F5+KorOreEdd0OU/MEK4J9RQY/swKgAHcVBqCxeB89TcABJi4 ZJpD1wt2oYW1Ltg/ZdzqdgNMYsFRpJhNlwiS7SniN4r4ViHPfv5N7kE+i/OY6kPTiqsm 2I/sEfS5p2rsfSoqBYwWcm+yHHJIMzG65q5erg0smGyq8QPAK8UWenH/mb+r+ofTHB7m SBRQ== X-Gm-Message-State: AO0yUKXZjoHbTSkwFYnENBb3L5+3Uh7o24EPDhkuhOgqtJkPk2lZWIup W7oow41iQSHS/80G0W5/4/sZBmKXXnXejZthONQP9A== X-Google-Smtp-Source: AK7set/t0aXp+50AvjikBji+4hFd3QZt8YBWpHXN4zlaXGaQ9GF8mFpKHnacNLf++FhLec5k+dDWAA== X-Received: by 2002:a5d:9d96:0:b0:757:f2a2:affa with SMTP id ay22-20020a5d9d96000000b00757f2a2affamr14783063iob.1.1680194828806; Thu, 30 Mar 2023 09:47:08 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id v21-20020a056638251500b003a53692d6dbsm20876jat.124.2023.03.30.09.47.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:47:08 -0700 (PDT) From: Jens Axboe To: linux-fsdevel@vger.kernel.org Cc: torvalds@linux-foundation.org, brauner@kernel.org, viro@zeniv.linux.org.uk, Jens Axboe Subject: [PATCH 03/11] IB/hfi1: check for user backed iterator, not specific iterator type Date: Thu, 30 Mar 2023 10:46:54 -0600 Message-Id: <20230330164702.1647898-4-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330164702.1647898-1-axboe@kernel.dk> References: <20230330164702.1647898-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org In preparation for switching single segment iterators to using ITER_UBUF, swap the check for whether we are user backed or not. While at it, move it outside the srcu locking area to clean up the code a bit. Signed-off-by: Jens Axboe --- drivers/infiniband/hw/hfi1/file_ops.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/infiniband/hw/hfi1/file_ops.c b/drivers/infiniband/hw/hfi1/file_ops.c index 3065db9d6bb9..f3d6ce45c397 100644 --- a/drivers/infiniband/hw/hfi1/file_ops.c +++ b/drivers/infiniband/hw/hfi1/file_ops.c @@ -267,6 +267,8 @@ static ssize_t hfi1_write_iter(struct kiocb *kiocb, struct iov_iter *from) if (!HFI1_CAP_IS_KSET(SDMA)) return -EINVAL; + if (!from->user_backed) + return -EINVAL; idx = srcu_read_lock(&fd->pq_srcu); pq = srcu_dereference(fd->pq, &fd->pq_srcu); if (!cq || !pq) { @@ -274,11 +276,6 @@ static ssize_t hfi1_write_iter(struct kiocb *kiocb, struct iov_iter *from) return -EIO; } - if (!iter_is_iovec(from) || !dim) { - srcu_read_unlock(&fd->pq_srcu, idx); - return -EINVAL; - } - trace_hfi1_sdma_request(fd->dd, fd->uctxt->ctxt, fd->subctxt, dim); if (atomic_read(&pq->n_reqs) == pq->n_max_reqs) { From patchwork Thu Mar 30 16:46:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13194572 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5701EC7EE20 for ; Thu, 30 Mar 2023 16:47:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231358AbjC3Qr3 (ORCPT ); Thu, 30 Mar 2023 12:47:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232324AbjC3QrL (ORCPT ); Thu, 30 Mar 2023 12:47:11 -0400 Received: from mail-io1-xd30.google.com (mail-io1-xd30.google.com [IPv6:2607:f8b0:4864:20::d30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7DCBD321 for ; Thu, 30 Mar 2023 09:47:10 -0700 (PDT) Received: by mail-io1-xd30.google.com with SMTP id bl9so8534180iob.8 for ; Thu, 30 Mar 2023 09:47:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1680194829; x=1682786829; 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=kbAbvx+wulf4ZJIYePr1YK4tcZKpHnBQRhSua/RrBns=; b=kL1/24VbKbclc2SL6+pLwEoAwOn+lLr8s8ZhOEEwS7zybypTEX+bmLnySP0qETe4L7 YR5nuACtL2KzdXUhdkdEeN4126lrd2ddDVv6zD1UeXe8nc+RcbkradeC4LdBH0eRpViy SqorCzyTPS19rTISlGmMoTzk/Fnb7S3n7gl4lrpfe6DjSHgu2hM9sv+WrhaIsMKgivvF 7Kp5ao7+f0p4DLSqFY5VaYyZ3vc8kkD9vUca3lSCnxHB4vXe82zQnx5L6MOXaoSlzaYZ jF4wOsEz+4wI6a6GzcKTApsvz7wm/MJNY0DNEfqVBoJbPjtr/1u1aIf5/kLMgoRluum/ HnAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680194829; x=1682786829; 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=kbAbvx+wulf4ZJIYePr1YK4tcZKpHnBQRhSua/RrBns=; b=M+8jpFuKKVkc9Y5noxFTtbosWSpLwYqMhEaiXkGNoeN1cv1yfPi0gAz0Tz4l6yO7WY Ict4wdEvBWwgKa41OyTNVcla9kY6owwpp5G8MVu//F5e92kNWc4HTyd1+IARlYTpMi90 uLuo5V6hbv6PQPq0SrNNYwYrfqouDEjJWFYyG1twfrYbTsEts2nzV7UWEzMI6tjXa7II J9EhWx9WKhC7/O/PUosWnBa7x8qq7la1FrNMLZnUuhrGM7sAK4eRIeX1WICwc7NxwR9r JlVYHexWxEfQEsd0KBy8yquv3LAtYkFVGIBwD+8Zhno3wmgRYqmUuoSMTtW4QWkCcOlt jIwQ== X-Gm-Message-State: AAQBX9c/5Da/fn0mHPFuW3Z2c0EOVnogLijuWII63EMtxL5/Bz4P8kgE /sIDq6puz/EdwS4Bqz8Hzbq/ws+wD/cLf+ArR2avQw== X-Google-Smtp-Source: AKy350bnN5FddadbaEMOudAStd3VJtKvQcQK/dO0ZTlvJH28BAglkAMw3/Nn8Akv4zU9xVyk1aq3mw== X-Received: by 2002:a6b:8d8c:0:b0:758:9dcb:5d1a with SMTP id p134-20020a6b8d8c000000b007589dcb5d1amr1413507iod.2.1680194829721; Thu, 30 Mar 2023 09:47:09 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id v21-20020a056638251500b003a53692d6dbsm20876jat.124.2023.03.30.09.47.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:47:09 -0700 (PDT) From: Jens Axboe To: linux-fsdevel@vger.kernel.org Cc: torvalds@linux-foundation.org, brauner@kernel.org, viro@zeniv.linux.org.uk, Jens Axboe Subject: [PATCH 04/11] IB/qib: check for user backed iterator, not specific iterator type Date: Thu, 30 Mar 2023 10:46:55 -0600 Message-Id: <20230330164702.1647898-5-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330164702.1647898-1-axboe@kernel.dk> References: <20230330164702.1647898-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org In preparation for switching single segment iterators to using ITER_UBUF, swap the check for whether we are user backed or not. Signed-off-by: Jens Axboe --- drivers/infiniband/hw/qib/qib_file_ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/infiniband/hw/qib/qib_file_ops.c b/drivers/infiniband/hw/qib/qib_file_ops.c index 4cee39337866..815ea72ad473 100644 --- a/drivers/infiniband/hw/qib/qib_file_ops.c +++ b/drivers/infiniband/hw/qib/qib_file_ops.c @@ -2245,7 +2245,7 @@ static ssize_t qib_write_iter(struct kiocb *iocb, struct iov_iter *from) struct qib_ctxtdata *rcd = ctxt_fp(iocb->ki_filp); struct qib_user_sdma_queue *pq = fp->pq; - if (!iter_is_iovec(from) || !from->nr_segs || !pq) + if (!from->user_backed || !from->nr_segs || !pq) return -EINVAL; return qib_user_sdma_writev(rcd, pq, iter_iov(from), from->nr_segs); From patchwork Thu Mar 30 16:46:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13194576 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6CB45C7EE22 for ; Thu, 30 Mar 2023 16:47:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232560AbjC3Qra (ORCPT ); Thu, 30 Mar 2023 12:47:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232330AbjC3QrM (ORCPT ); Thu, 30 Mar 2023 12:47:12 -0400 Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D0D7CDD4 for ; Thu, 30 Mar 2023 09:47:11 -0700 (PDT) Received: by mail-io1-xd2f.google.com with SMTP id q6so8551555iot.2 for ; Thu, 30 Mar 2023 09:47:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1680194830; x=1682786830; 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=iaNE2rJZu9RSwFt75gnITqun68WHqA1LfJU9gOnr41w=; b=srU9podCLoschbuo8Y8Us2uW+8MgvM/PAFkNpCR2ifflU2MWtZvJ+ntRcFOeu+Qxqn D+Jr0PdWjthLhOruH4VIA8s0L9/tq0naIceJrRkiJ0KuT5h6eXNZXRF5DDFhFnzv8QgW P9vtkmt7ZSLje0YZPVe2TgOI0nH9bHbUkBMkJJZM9sBD734dkg7fQqI2DMqUyqjZNF65 fEHRddXmbomcCs7oMOmrTxIQ7AyNl4xvJ/e4vxq2lrfKYRodQWwNHNY1uG2kDQ9oVvU4 /Ecf1ueQbL4ux/03yVp5cib8bIXSNHxRAtdDttYZJpUNeB9PwgPjzATLpWNymCakG4+r yjpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680194830; x=1682786830; 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=iaNE2rJZu9RSwFt75gnITqun68WHqA1LfJU9gOnr41w=; b=wGAHYNZfcYVnNjBbSSTojlcDKUDzUugvZxW0eKizu+PFDiXLIXGJwfza2YZlYTQ0Sq Z29icGM+6VgPAtvVDFixujGwFXPoGo1lDUoYfEE8bEDT4T0L1xN/elHt0r85SMXnskfd 1jqDLFr0MMCBm+F+2Fv7gsKM6Gj58rXZLqIXC9RM9q1GLNV/Amx8/jo6hQAMSmeRs0fD WIdR3nig2Ljw3Gw+38RCCm3yK3qkv5jII6j4Qt3Z3c+Y3H913/dtZAI6FX5LSL8O081e zHZI3b/24axVbTu2t0WkPzSNUf4W3pT2ZTv8YVC9iZ49jISHzVgjJBrlafNoTLj2HUm+ a3Jw== X-Gm-Message-State: AAQBX9c9v5nJBeBhZemuYlxayCQsqIbDbCpBP+kxg/95age8P5PzaXo0 nsBTOIDLrvWLi4B1s7VvIUMc1Pa6H9KydqDEFe1L3Q== X-Google-Smtp-Source: AKy350YcCFxpC10XeWynzxalLJStttMtbwyfhd/bSB864vkKsJwA9f156WNZEi6n8sIFFXbChM11Lg== X-Received: by 2002:a05:6602:14c6:b0:758:8b42:ce5a with SMTP id b6-20020a05660214c600b007588b42ce5amr1821499iow.1.1680194830694; Thu, 30 Mar 2023 09:47:10 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id v21-20020a056638251500b003a53692d6dbsm20876jat.124.2023.03.30.09.47.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:47:10 -0700 (PDT) From: Jens Axboe To: linux-fsdevel@vger.kernel.org Cc: torvalds@linux-foundation.org, brauner@kernel.org, viro@zeniv.linux.org.uk, Jens Axboe Subject: [PATCH 05/11] ALSA: pcm: check for user backed iterator, not specific iterator type Date: Thu, 30 Mar 2023 10:46:56 -0600 Message-Id: <20230330164702.1647898-6-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330164702.1647898-1-axboe@kernel.dk> References: <20230330164702.1647898-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org In preparation for switching single segment iterators to using ITER_UBUF, swap the check for whether we are user backed or not. Signed-off-by: Jens Axboe --- sound/core/pcm_native.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index 8bb97ee6720d..5868661d461b 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -3531,7 +3531,7 @@ static ssize_t snd_pcm_readv(struct kiocb *iocb, struct iov_iter *to) if (runtime->state == SNDRV_PCM_STATE_OPEN || runtime->state == SNDRV_PCM_STATE_DISCONNECTED) return -EBADFD; - if (!iter_is_iovec(to)) + if (!to->user_backed) return -EINVAL; if (to->nr_segs > 1024 || to->nr_segs != runtime->channels) return -EINVAL; @@ -3571,7 +3571,7 @@ static ssize_t snd_pcm_writev(struct kiocb *iocb, struct iov_iter *from) if (runtime->state == SNDRV_PCM_STATE_OPEN || runtime->state == SNDRV_PCM_STATE_DISCONNECTED) return -EBADFD; - if (!iter_is_iovec(from)) + if (!from->user_backed) return -EINVAL; if (from->nr_segs > 128 || from->nr_segs != runtime->channels || !frame_aligned(runtime, iov->iov_len)) From patchwork Thu Mar 30 16:46:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13194573 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC6A2C77B7F for ; Thu, 30 Mar 2023 16:47:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232480AbjC3Qr1 (ORCPT ); Thu, 30 Mar 2023 12:47:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232359AbjC3QrN (ORCPT ); Thu, 30 Mar 2023 12:47:13 -0400 Received: from mail-il1-x130.google.com (mail-il1-x130.google.com [IPv6:2607:f8b0:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A109CDF7 for ; Thu, 30 Mar 2023 09:47:12 -0700 (PDT) Received: by mail-il1-x130.google.com with SMTP id h11so10096539ild.11 for ; Thu, 30 Mar 2023 09:47:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1680194831; x=1682786831; 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=DC1PRKIPWeSwJmEnC4u8bQghfT4SJuLeGzSfXQEaX64=; b=vK0pwwvRHfp2UyZEksH4vvb6R5y05R0iGbZ47EXC1Kd1UcFymwZP1+Bo4PTi1MMl7Q eelKBq55vwV9icNVODWTZ8LpKki6ZaW/pq7hbt39chyboNCMEi6rYHP5o+XUCaac0MVD ipvFuV0GZiCRXkTArd8ab56JMt90PKAa8+Yk2xKqh7mCBpy7Yume+o5Mls5eN5bl8sUL PMAgg5ShN0xvjQbA3UxmY6ObnPbLMPfiSo8f8AG+lFaslshpclTB/LXl+iMqsT/MarQX 5rz3+QcFTem4oDghGuiNE8ipAORp4RaQegUCBM5pnnmkC/NZd0WzNDL4Q4U2O/Y98uQX eZjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680194831; x=1682786831; 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=DC1PRKIPWeSwJmEnC4u8bQghfT4SJuLeGzSfXQEaX64=; b=RYAwXYvR4lIjOmkhGNLhh1z16gakPCkCqymw6gFvs739S6nmrkTKZO5U6pN4QKGw0p YETf/klYSl89zLv2dXHHIYYNbhY47OubL1krhWROBPaXMsgyie6NTpgV4EQYo/VySAvo vajPV/MYsViwKO+CHAr0BMwbdTaS4vNmu0mxW4rlDyIHd/ivdHNf3Ji5QBanHuOquPh7 76iT6GqnQxgihst3N3TFjTVToKRy9hh0fmc+obpLV3aSehzMNdShLrpWPHQs3aI8Q0HF swJEknBcRUzJ8OKHXWdyHzItvyCIWLwd9queFfHneuEciZEfQpwKo0I87G14yOE7HeeF +wrA== X-Gm-Message-State: AAQBX9dy2jrzFau9/b8Rx2zycSw9KfntUx0blLp+NR1PAVL0mKzdoq1N zlPXV+aYhGKBpr2jCuo3PCyarfbpg3vWqJgM91fruQ== X-Google-Smtp-Source: AKy350Yr0i+KT7q0jbNq2PAtT5AmB6DDEFYrlOwnVhRJxG6+qq5F7JKQVCNqEfxEAxs6snJ/Hw7LUg== X-Received: by 2002:a05:6e02:13e2:b0:313:fb1b:2f86 with SMTP id w2-20020a056e0213e200b00313fb1b2f86mr1553389ilj.0.1680194831655; Thu, 30 Mar 2023 09:47:11 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id v21-20020a056638251500b003a53692d6dbsm20876jat.124.2023.03.30.09.47.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:47:11 -0700 (PDT) From: Jens Axboe To: linux-fsdevel@vger.kernel.org Cc: torvalds@linux-foundation.org, brauner@kernel.org, viro@zeniv.linux.org.uk, Jens Axboe Subject: [PATCH 06/11] iov_iter: add iter_iov_addr() and iter_iov_len() helpers Date: Thu, 30 Mar 2023 10:46:57 -0600 Message-Id: <20230330164702.1647898-7-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330164702.1647898-1-axboe@kernel.dk> References: <20230330164702.1647898-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org These just return the address and length of the current iovec segment in the iterator. Convert existing iov_iter_iovec() users to use them instead of getting a copy of the current vec. Signed-off-by: Jens Axboe --- fs/read_write.c | 11 +++++------ include/linux/uio.h | 2 ++ io_uring/rw.c | 27 +++++++++++++-------------- mm/madvise.c | 9 ++++----- 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index 7a2ff6157eda..a21ba3be7dbe 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -749,15 +749,14 @@ static ssize_t do_loop_readv_writev(struct file *filp, struct iov_iter *iter, return -EOPNOTSUPP; while (iov_iter_count(iter)) { - struct iovec iovec = iov_iter_iovec(iter); ssize_t nr; if (type == READ) { - nr = filp->f_op->read(filp, iovec.iov_base, - iovec.iov_len, ppos); + nr = filp->f_op->read(filp, iter_iov_addr(iter), + iter_iov_len(iter), ppos); } else { - nr = filp->f_op->write(filp, iovec.iov_base, - iovec.iov_len, ppos); + nr = filp->f_op->write(filp, iter_iov_addr(iter), + iter_iov_len(iter), ppos); } if (nr < 0) { @@ -766,7 +765,7 @@ static ssize_t do_loop_readv_writev(struct file *filp, struct iov_iter *iter, break; } ret += nr; - if (nr != iovec.iov_len) + if (nr != iter_iov_len(iter)) break; iov_iter_advance(iter, nr); } diff --git a/include/linux/uio.h b/include/linux/uio.h index 4218624b7f78..b7fce87b720e 100644 --- a/include/linux/uio.h +++ b/include/linux/uio.h @@ -70,6 +70,8 @@ struct iov_iter { }; #define iter_iov(iter) (iter)->__iov +#define iter_iov_addr(iter) (iter_iov(iter)->iov_base + (iter)->iov_offset) +#define iter_iov_len(iter) (iter_iov(iter)->iov_len - (iter)->iov_offset) static inline enum iter_type iov_iter_type(const struct iov_iter *i) { diff --git a/io_uring/rw.c b/io_uring/rw.c index 7573a34ea42a..f33ba6f28247 100644 --- a/io_uring/rw.c +++ b/io_uring/rw.c @@ -447,26 +447,25 @@ static ssize_t loop_rw_iter(int ddir, struct io_rw *rw, struct iov_iter *iter) ppos = io_kiocb_ppos(kiocb); while (iov_iter_count(iter)) { - struct iovec iovec; + void __user *addr; + size_t len; ssize_t nr; if (iter_is_ubuf(iter)) { - iovec.iov_base = iter->ubuf + iter->iov_offset; - iovec.iov_len = iov_iter_count(iter); + addr = iter->ubuf + iter->iov_offset; + len = iov_iter_count(iter); } else if (!iov_iter_is_bvec(iter)) { - iovec = iov_iter_iovec(iter); + addr = iter_iov_addr(iter); + len = iter_iov_len(iter); } else { - iovec.iov_base = u64_to_user_ptr(rw->addr); - iovec.iov_len = rw->len; + addr = u64_to_user_ptr(rw->addr); + len = rw->len; } - if (ddir == READ) { - nr = file->f_op->read(file, iovec.iov_base, - iovec.iov_len, ppos); - } else { - nr = file->f_op->write(file, iovec.iov_base, - iovec.iov_len, ppos); - } + if (ddir == READ) + nr = file->f_op->read(file, addr, len, ppos); + else + nr = file->f_op->write(file, addr, len, ppos); if (nr < 0) { if (!ret) @@ -482,7 +481,7 @@ static ssize_t loop_rw_iter(int ddir, struct io_rw *rw, struct iov_iter *iter) if (!rw->len) break; } - if (nr != iovec.iov_len) + if (nr != len) break; } diff --git a/mm/madvise.c b/mm/madvise.c index 340125d08c03..9f389c5304d2 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -1456,7 +1456,7 @@ SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec, size_t, vlen, int, behavior, unsigned int, flags) { ssize_t ret; - struct iovec iovstack[UIO_FASTIOV], iovec; + struct iovec iovstack[UIO_FASTIOV]; struct iovec *iov = iovstack; struct iov_iter iter; struct task_struct *task; @@ -1503,12 +1503,11 @@ SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec, total_len = iov_iter_count(&iter); while (iov_iter_count(&iter)) { - iovec = iov_iter_iovec(&iter); - ret = do_madvise(mm, (unsigned long)iovec.iov_base, - iovec.iov_len, behavior); + ret = do_madvise(mm, (unsigned long)iter_iov_addr(&iter), + iter_iov_len(&iter), behavior); if (ret < 0) break; - iov_iter_advance(&iter, iovec.iov_len); + iov_iter_advance(&iter, iter_iov_len(&iter)); } ret = (total_len - iov_iter_count(&iter)) ? : ret; From patchwork Thu Mar 30 16:46:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13194574 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19BC4C7EE2A for ; Thu, 30 Mar 2023 16:47:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232798AbjC3Qrg (ORCPT ); Thu, 30 Mar 2023 12:47:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232364AbjC3QrO (ORCPT ); Thu, 30 Mar 2023 12:47:14 -0400 Received: from mail-il1-x132.google.com (mail-il1-x132.google.com [IPv6:2607:f8b0:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71E03CDD4 for ; Thu, 30 Mar 2023 09:47:13 -0700 (PDT) Received: by mail-il1-x132.google.com with SMTP id q5so4721418ilg.12 for ; Thu, 30 Mar 2023 09:47:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1680194832; 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=jpwUjTOd1XNUvc/0wj6/ArC+MvM71+0/O8hmrQy2F/M=; b=jrlfYvCIHJ4LXZi2Xqy7ue+zXTv0IN9AMsja3fZUzMERaxBkkp1nEKFHp8vhZr8uZH NnjRT6Ak+PL3nldTQURPYWzekcUnIdyZcrT4adYkph2ECoiXibjdFaPVGY1AnK+NuFZw eCkTy2WA2vyCgTac9UbEe/JHr7cG+tt+QZ+4sreF4H82syh6YBbgzprsfa/zqheMje7A PE1HBtO5N0f6H5h+pa/tzD0DUYg93+5lelMZRIRAkNKxxuhLZb3aL0eM4SzCk+ltu2O/ qhIhLH86m+6MRg/NgWiYA72Q55nzVGcC122bynXzcNf9kLqppDne2+qJeDxCLsez1/Dl nYcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680194832; 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=jpwUjTOd1XNUvc/0wj6/ArC+MvM71+0/O8hmrQy2F/M=; b=BeWRLZAW3Euvd1mo3rO5sWOquJyV6MILU80IXZh8EkmRBe9Qdjnta7ZbmL2p1Robz7 w+xPcDsgWIS6yMwSn8M58yACj2K+P2tq5jJjtLA3XI+/4F7kTZAr9Nq+o4VK69ftgsJP aqPgGvcKs5/cb3bMEFRPAUzEjTArv0Q1S2JDaMfmsDSYQ7sNlearbnMMhB9WDp2vRSjL s/6mj+ZFEeTW+BzU4OVr+Ak2tIz7yDnWB+YwpKs4j32C4HXB7gHJPmWRP34Ph6yaW3Sz fGzyCDtA0M5gaxPAu9EfDbFPiwheAtYw38ERUO1NL+c8/ZJf4kwLMwdfFiyznkb8sg9D +cmw== X-Gm-Message-State: AAQBX9cUrvcEuGtjBIG/fhtQqOYgAtQ6hT97jPrIR76WmgILb1wwL/li G7cYHfjqFTzDYefOaAdcPgwOs7uSLJBZXyst+1cTDw== X-Google-Smtp-Source: AKy350YgaLyFdyIkSqO644lZmbDb4MesLLur6QZjVw34wucOOoDXj1ELcUDejMDQUUiRRzAf38OV1w== X-Received: by 2002:a05:6e02:b4e:b0:323:504:cff6 with SMTP id f14-20020a056e020b4e00b003230504cff6mr1735885ilu.3.1680194832515; Thu, 30 Mar 2023 09:47:12 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id v21-20020a056638251500b003a53692d6dbsm20876jat.124.2023.03.30.09.47.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:47:12 -0700 (PDT) From: Jens Axboe To: linux-fsdevel@vger.kernel.org Cc: torvalds@linux-foundation.org, brauner@kernel.org, viro@zeniv.linux.org.uk, Jens Axboe Subject: [PATCH 07/11] iov_iter: remove iov_iter_iovec() Date: Thu, 30 Mar 2023 10:46:58 -0600 Message-Id: <20230330164702.1647898-8-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330164702.1647898-1-axboe@kernel.dk> References: <20230330164702.1647898-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org No more users are left of this function. Signed-off-by: Jens Axboe --- include/linux/uio.h | 9 --------- 1 file changed, 9 deletions(-) diff --git a/include/linux/uio.h b/include/linux/uio.h index b7fce87b720e..7f585ceedcb2 100644 --- a/include/linux/uio.h +++ b/include/linux/uio.h @@ -148,15 +148,6 @@ static inline size_t iov_length(const struct iovec *iov, unsigned long nr_segs) return ret; } -static inline struct iovec iov_iter_iovec(const struct iov_iter *iter) -{ - return (struct iovec) { - .iov_base = iter_iov(iter)->iov_base + iter->iov_offset, - .iov_len = min(iter->count, - iter_iov(iter)->iov_len - iter->iov_offset), - }; -} - size_t copy_page_from_iter_atomic(struct page *page, unsigned offset, size_t bytes, struct iov_iter *i); void iov_iter_advance(struct iov_iter *i, size_t bytes); From patchwork Thu Mar 30 16:46:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13194570 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3C34C6FD1D for ; Thu, 30 Mar 2023 16:47:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232412AbjC3QrX (ORCPT ); Thu, 30 Mar 2023 12:47:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232378AbjC3QrP (ORCPT ); Thu, 30 Mar 2023 12:47:15 -0400 Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BFA0CDCB for ; Thu, 30 Mar 2023 09:47:14 -0700 (PDT) Received: by mail-io1-xd33.google.com with SMTP id p17so8527216ioj.10 for ; Thu, 30 Mar 2023 09:47:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1680194833; x=1682786833; 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=OqvAB6d8goa2TAcTv+sr3+77aiqYZ9Ym4nn/6JW4p+g=; b=dzte15Gqp4cjRsbJLzbWwn94XvOXX4Egre/oxtQ1GjfkxqT/X6qAkOGReDejGZKfp3 yqD5bCHvpi9IVDaUJcvjVnSmfTr78j5WSm/ZFyBARceGSJUlzjXx1XluHx5A6TOAYvob Vd63Ef9uF6Pj+ZTs6/cyvNIYkJ2O6d01GAlVOr7h48hngri7PAm81pcO4DjAtXvJ4Wpb Io+zaQOmwiQ/DayJUVyUFnH5f6m2IwwrvjDF01hcbxKHERIVADmLHVTX9yRlRiuE8fRl +16eXsxZmtaTcyzFxh8yNBqgMjeE9skO04Up4fY+1/qJ7Y3vC7cm3ejFhDya6JUYS9pH 7LCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680194833; x=1682786833; 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=OqvAB6d8goa2TAcTv+sr3+77aiqYZ9Ym4nn/6JW4p+g=; b=aLCFlgEpYn7UL0SSEvAP5ji6KbBRPhXNN8FtvmvnduJTgCACiuNrfsxu15MGNdrjYj d0mwZs4xmNzrCrQd5RdRfKlIYwthh8riYhsBQ9+ZMUuFdpybXj4D8gNwzk0DukjIjFJt GVbGqbimyfT5oTV0biH95vFhL5NTo4yocrbJxIxqJaGqyOOLawYKYWDS9By6L1uGlara 8yCbzcW3FNWERtw88SEna4ItUn5+X/XL+WqSq/l8Plic19gn/ea18bEAUNY+VuNViv90 A6SA4cWujCxUXcykOITmHh4INRvjvnp65Po9KJKml1+KIOeGEbuT3PPfWUWetEDFagKM xNYQ== X-Gm-Message-State: AO0yUKUX8kxxFmrgxAnuvZdjCPaVyAQMBjRpjBEM3MLKyh4nN6XLrKt1 MfAKZAqigTCjLRlLUCDr0kDKxbfpmSkMncuMmGYLDg== X-Google-Smtp-Source: AK7set8/RjCICeWEl0bCRLxbc4bISYPLNktpF2cGm2Fq+oz6xnVePguVmGCD8E4IPyj5Ak6rdEceaw== X-Received: by 2002:a05:6602:2dcf:b0:758:6517:c621 with SMTP id l15-20020a0566022dcf00b007586517c621mr17378759iow.2.1680194833513; Thu, 30 Mar 2023 09:47:13 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id v21-20020a056638251500b003a53692d6dbsm20876jat.124.2023.03.30.09.47.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:47:13 -0700 (PDT) From: Jens Axboe To: linux-fsdevel@vger.kernel.org Cc: torvalds@linux-foundation.org, brauner@kernel.org, viro@zeniv.linux.org.uk, Jens Axboe Subject: [PATCH 08/11] iov_iter: set nr_segs = 1 for ITER_UBUF Date: Thu, 30 Mar 2023 10:46:59 -0600 Message-Id: <20230330164702.1647898-9-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330164702.1647898-1-axboe@kernel.dk> References: <20230330164702.1647898-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org To avoid needing to check if a given user backed iov_iter is of type ITER_IOVEC or ITER_UBUF, set the number of segments for the ITER_UBUF case to 1 as we're carrying a single segment. Signed-off-by: Jens Axboe --- include/linux/uio.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/uio.h b/include/linux/uio.h index 7f585ceedcb2..5dbd2dcab35c 100644 --- a/include/linux/uio.h +++ b/include/linux/uio.h @@ -355,7 +355,8 @@ static inline void iov_iter_ubuf(struct iov_iter *i, unsigned int direction, .user_backed = true, .data_source = direction, .ubuf = buf, - .count = count + .count = count, + .nr_segs = 1 }; } /* Flags for iov_iter_get/extract_pages*() */ From patchwork Thu Mar 30 16:47:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13194577 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A466C7EE24 for ; Thu, 30 Mar 2023 16:47:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232715AbjC3Qrd (ORCPT ); Thu, 30 Mar 2023 12:47:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232216AbjC3QrQ (ORCPT ); Thu, 30 Mar 2023 12:47:16 -0400 Received: from mail-il1-x12a.google.com (mail-il1-x12a.google.com [IPv6:2607:f8b0:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49981CDF5 for ; Thu, 30 Mar 2023 09:47:15 -0700 (PDT) Received: by mail-il1-x12a.google.com with SMTP id e9e14a558f8ab-3230125dde5so718475ab.1 for ; Thu, 30 Mar 2023 09:47:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1680194834; 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=KesrPkm/FsQKVOBkTbitXewEYIv5YwFi8+M44L5LLdQ=; b=AGfMQZPkWVTEs3aOmgnBWo/PeGwtbErkgDdA6/YaAI+IZ6uDY2mW0Ec7Rraove81AB uS8Sw9Y0zuV0j/K+TAJ4H5RH+97WdruqR5hP0ZH25sgTUTPSWUQGvcp4pR4fqYLVy/PO dbfqrPQ7HNaZ2N8j2X1UZUcVGVY+sSSeRZdYs+quOy34Mv5AtRSa7osFNcaBHoafvAYz XRw2sK939o1XWoz+C5kdSghNBzFduRD2gUDOf0O79TN5vvndESZFFk16RajAtvd5mRHB icAWvL9eBQMWpuE4UkAN8csipnEP//RPGRx57edYpGBSr+uk0uKiUBTYKQ4MUu0284Fp aLIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680194834; 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=KesrPkm/FsQKVOBkTbitXewEYIv5YwFi8+M44L5LLdQ=; b=mQIyaiY/ApZgP8kLze/LBAV4xOLzD+P/X4AqBqqcTmtr9FtCLNmI6+CZBturF8C4B5 ZUdeYk/Wl9ScCDWE0fkrxvZKCAg2WnOqTwcF8DbpoDCwww6UmyJawQf392tRjr4g1Uir 3GVkQZK8MhOLKEXlZqgl/nz2aklmLLpmEjjVUv3s2krtSVpJy4xXAw7SI66I5R7zIe5E R67RidxuWa6jG08egwcEKkVpHX0UeIcbYa5RRxjBz7/Sn+VGZW3T/JKgFl4+MvLup8Ff RHcMkYuQ34liTo+nbxEGqZy1eT630yMfGdVcsN6HMxl2C0prD8BSp2X5LJqPQklvl/zi gKSw== X-Gm-Message-State: AAQBX9dqaiNMUSO09Erm5LZsHMv/mp2GHXshp8rYxrZKYHWEMPbCFP+U dC45lT0WjFjU/ivhyOWi/ERmbMXeukOvWCOO/nzHDg== X-Google-Smtp-Source: AKy350anKqmXtvPXiIO7zceHnf43PvO+c2gmUm2JOPZpvAMxxc1UUn2HLS86ghMDOPFuom05jt0nWQ== X-Received: by 2002:a05:6e02:48a:b0:325:e065:8bf8 with SMTP id b10-20020a056e02048a00b00325e0658bf8mr1794099ils.0.1680194834412; Thu, 30 Mar 2023 09:47:14 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id v21-20020a056638251500b003a53692d6dbsm20876jat.124.2023.03.30.09.47.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:47:14 -0700 (PDT) From: Jens Axboe To: linux-fsdevel@vger.kernel.org Cc: torvalds@linux-foundation.org, brauner@kernel.org, viro@zeniv.linux.org.uk, Jens Axboe Subject: [PATCH 09/11] iov_iter: overlay struct iovec and ubuf/len Date: Thu, 30 Mar 2023 10:47:00 -0600 Message-Id: <20230330164702.1647898-10-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330164702.1647898-1-axboe@kernel.dk> References: <20230330164702.1647898-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Add an internal struct iovec that we can return as a pointer, with the fields of the iovec overlapping with the ITER_UBUF ubuf and length fields. Then we can have iter_iov() check for the appropriate type, and return &iter->__ubuf_iovec for ITER_UBUF and iter->__iov for ITER_IOVEC and things will magically work out for a single segment request regardless of either type. Signed-off-by: Jens Axboe --- include/linux/uio.h | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/include/linux/uio.h b/include/linux/uio.h index 5dbd2dcab35c..ed35f4427a0a 100644 --- a/include/linux/uio.h +++ b/include/linux/uio.h @@ -49,15 +49,35 @@ struct iov_iter { size_t iov_offset; int last_offset; }; - size_t count; + /* + * Hack alert: overlay ubuf_iovec with iovec + count, so + * that the members resolve correctly regardless of the type + * of iterator used. This means that you can use: + * + * &iter->__ubuf_iovec or iter->__iov + * + * interchangably for the user_backed cases, hence simplifying + * some of the cases that need to deal with both. + */ union { - /* use iter_iov() to get the current vec */ - const struct iovec *__iov; - const struct kvec *kvec; - const struct bio_vec *bvec; - struct xarray *xarray; - struct pipe_inode_info *pipe; - void __user *ubuf; + /* + * This really should be a const, but we cannot do that without + * also modifying any of the zero-filling iter init functions. + * Leave it non-const for now, but it should be treated as such. + */ + struct iovec __ubuf_iovec; + struct { + union { + /* use iter_iov() to get the current vec */ + const struct iovec *__iov; + const struct kvec *kvec; + const struct bio_vec *bvec; + struct xarray *xarray; + struct pipe_inode_info *pipe; + void __user *ubuf; + }; + size_t count; + }; }; union { unsigned long nr_segs; @@ -69,7 +89,13 @@ struct iov_iter { }; }; -#define iter_iov(iter) (iter)->__iov +static inline const struct iovec *iter_iov(const struct iov_iter *iter) +{ + if (iter->iter_type == ITER_UBUF) + return (const struct iovec *) &iter->__ubuf_iovec; + return iter->__iov; +} + #define iter_iov_addr(iter) (iter_iov(iter)->iov_base + (iter)->iov_offset) #define iter_iov_len(iter) (iter_iov(iter)->iov_len - (iter)->iov_offset) From patchwork Thu Mar 30 16:47:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13194581 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0DCCC77B60 for ; Thu, 30 Mar 2023 16:48:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231856AbjC3Qrw (ORCPT ); Thu, 30 Mar 2023 12:47:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232381AbjC3QrR (ORCPT ); Thu, 30 Mar 2023 12:47:17 -0400 Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9A29CDCB for ; Thu, 30 Mar 2023 09:47:15 -0700 (PDT) Received: by mail-io1-xd33.google.com with SMTP id p17so8527247ioj.10 for ; Thu, 30 Mar 2023 09:47:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1680194835; x=1682786835; 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=Q/kB5PhUmthEnCoqu+yOus3Fb3oBVmbBoIv7KU060Co=; b=kEs/0kLoBKtJvulYvNCnelAcTdv0BAmYF16vuEIDQPNzoMSPcPyhttooHRd2dL6LoZ 4Goxcv7GykHvXStaVd+3RKyXvRwZS102Pw9OY9a8J2cd/Os14lEXRoPsStFkJ4FAUuAh GXKnb0YBD+xEOLBi+rDhO15I9uQlDbOengy0fN+nvN4uYgR1908gf9tsxYE3y5ZHMrUW fwFUDXrKQTp7w7zcloiWTbCtJWrNbflhg4QBOK72ObeGeMIhTQpv3Ky4bV1Lh5Em9IaX Cq5yb/Exw/c81nxXdUfaDNyl8w6MEdgYTjypunuNEsuZMY+gOwHIH1W0rc4inv1Zzm+w +Dvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680194835; x=1682786835; 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=Q/kB5PhUmthEnCoqu+yOus3Fb3oBVmbBoIv7KU060Co=; b=Dq2Rb+9fcFXp18fnhqNp33hHLtaBh/xKjgd9L3DaDLvWAd9YUPoBdI1WwOsolv7kVq n9s5yJdwA0GY8YdvAxOMSneNsQ8mCo+GJozDiXUXAE4a9nBmeIYbw0pjlK+Bs/6sch4d tXaSBOQ5e405pAeVrou2HgxfsrR6PmDpa6IGgRZTSW3ub1bEPUZl1/RztePEffGYlApu M2SeFoskpDy56+W2VCNdwgSMwkk6fz+7sh2GTt8A5+J/s7cSqnpeKiHtbyFrY+8oV/yb qLxXBkfTAE7ox1a2IeNIL/E7FctRhMevtPHK9omXZnX7uDsXVQ6hQtGGpwS3johoGnuM plIw== X-Gm-Message-State: AO0yUKXRjRx/dK+VYsAIQ5B/lJCTKVX6N+vze74Ab2sCecxIdjnTQQky +chK5LLWJybbtXPQhVXsqzZdiSu44PSsfnH2Vyeg+A== X-Google-Smtp-Source: AK7set947rl3w1tIIxmmE87kE5S90Ob7/qw9snKJll9DllXDRByo5t2BFzTAvIqLil1s2uW2wI83Mw== X-Received: by 2002:a5d:9d96:0:b0:757:f2a2:affa with SMTP id ay22-20020a5d9d96000000b00757f2a2affamr14783195iob.1.1680194835296; Thu, 30 Mar 2023 09:47:15 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id v21-20020a056638251500b003a53692d6dbsm20876jat.124.2023.03.30.09.47.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:47:14 -0700 (PDT) From: Jens Axboe To: linux-fsdevel@vger.kernel.org Cc: torvalds@linux-foundation.org, brauner@kernel.org, viro@zeniv.linux.org.uk, Jens Axboe Subject: [PATCH 10/11] iov_iter: convert import_single_range() to ITER_UBUF Date: Thu, 30 Mar 2023 10:47:01 -0600 Message-Id: <20230330164702.1647898-11-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330164702.1647898-1-axboe@kernel.dk> References: <20230330164702.1647898-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Since we're just importing a single vector, we don't have to turn it into an ITER_IOVEC. Instead turn it into an ITER_UBUF, which is cheaper to iterate. Signed-off-by: Jens Axboe --- lib/iov_iter.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/iov_iter.c b/lib/iov_iter.c index 87488c4aad3f..f411bda1171f 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -1870,9 +1870,7 @@ int import_single_range(int rw, void __user *buf, size_t len, if (unlikely(!access_ok(buf, len))) return -EFAULT; - iov->iov_base = buf; - iov->iov_len = len; - iov_iter_init(i, rw, iov, 1, len); + iov_iter_ubuf(i, rw, buf, len); return 0; } EXPORT_SYMBOL(import_single_range); From patchwork Thu Mar 30 16:47:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13194580 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44157C6FD1D for ; Thu, 30 Mar 2023 16:48:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232909AbjC3Qrt (ORCPT ); Thu, 30 Mar 2023 12:47:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231317AbjC3QrR (ORCPT ); Thu, 30 Mar 2023 12:47:17 -0400 Received: from mail-il1-x136.google.com (mail-il1-x136.google.com [IPv6:2607:f8b0:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FB1ACDD4 for ; Thu, 30 Mar 2023 09:47:17 -0700 (PDT) Received: by mail-il1-x136.google.com with SMTP id l9so10118739iln.1 for ; Thu, 30 Mar 2023 09:47:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1680194836; x=1682786836; 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=s4CO9nZAOAEco+zmBX+Z9tyoqzZd7VU/Gm6MZ2qt56o=; b=4w6ImjJd/ECXjseQEXiaqQzKSKrICMv95OG9ACGS6Mc/kXe9K39lVbNQmw8nvjr1rV Dk0x/o+4toszbkCZeOVHPbTZZvV6yWvn14g6ATPbItPD6/E7l6b0/YNV9ZgcjDEa1NjE uCFIT7XKcjpiwhyYiqE9JBw1KOF2bcj2xD+MjCER8zRVshMdM22L1kzvF8g08bpLu+TR 5O4vNhBdiZzJVde2GZRH/LzYr07Dca5GY/iQX7GfKRKwuMLRPyJu7PniU0oFq5pJt8Qy bMVWct0Ua3Z2XxmVvl5EhoImYIhtxlAdoAw1AnhpZ4s3vUwEsZiILmoT/B9Wm4/+RgsP C+NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680194836; x=1682786836; 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=s4CO9nZAOAEco+zmBX+Z9tyoqzZd7VU/Gm6MZ2qt56o=; b=38R3D12hpbsGSbfc7tqUHtFf1VHy9aNp410OA1EX2KUdGX4dXSk8SEg/2vmUNITGaj zCg7bPa15yhJvS0CFd3rUny3WxgsdE/BKOQDJ6EdsRLW8MeA5qFaF8GihgpFojKZvtSj IlfkU6AwX/A2C6Yfji5+r9wCicuZu8jk+vXp2xl95mRB9TrT9TEQIWwtHd7y/+68LsKt hIer8yAlB9IIbxjHQlzUNVFJjGPlpvYqWcm9WhNGwymZJ+A1KCXsoG2k/1hupxQzOze0 HjQ+Yd2E5CmVySOz2BlneBBEHgo8g9Lr2Pv2Zn+uTLqRELwTAjImzd5eA5EQoB3mQf3C Syfg== X-Gm-Message-State: AAQBX9fGOD2CTUzuXGXRpXOgo4DGM9adN+H4DI3pXPrdIO6gKjN7iFK2 T6KJ4Mjtc/wbGQFCYhiYNJFoGe63zVU+djtx9Tl+fg== X-Google-Smtp-Source: AKy350axa2/au8hKZ3lugR9MQwmlu+ZPl6YemGFkjrx6KNOrDeVa1N7BLtFF5pnaBphe80ufXS7JCg== X-Received: by 2002:a05:6e02:dc8:b0:319:5431:5d5b with SMTP id l8-20020a056e020dc800b0031954315d5bmr1564313ilj.1.1680194836154; Thu, 30 Mar 2023 09:47:16 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id v21-20020a056638251500b003a53692d6dbsm20876jat.124.2023.03.30.09.47.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:47:15 -0700 (PDT) From: Jens Axboe To: linux-fsdevel@vger.kernel.org Cc: torvalds@linux-foundation.org, brauner@kernel.org, viro@zeniv.linux.org.uk, Jens Axboe Subject: [PATCH 11/11] iov_iter: import single vector iovecs as ITER_UBUF Date: Thu, 30 Mar 2023 10:47:02 -0600 Message-Id: <20230330164702.1647898-12-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330164702.1647898-1-axboe@kernel.dk> References: <20230330164702.1647898-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Add a special case to __import_iovec(), which imports a single segment iovec as an ITER_UBUF rather than an ITER_IOVEC. ITER_UBUF is cheaper to iterate than ITER_IOVEC, and for a single segment iovec, there's no point in using a segmented iterator. Signed-off-by: Jens Axboe --- lib/iov_iter.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lib/iov_iter.c b/lib/iov_iter.c index f411bda1171f..3e6c9bcfa612 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -1784,6 +1784,30 @@ struct iovec *iovec_from_user(const struct iovec __user *uvec, return iov; } +/* + * Single segment iovec supplied by the user, import it as ITER_UBUF. + */ +static ssize_t __import_iovec_ubuf(int type, const struct iovec __user *uvec, + struct iovec **iovp, struct iov_iter *i, + bool compat) +{ + struct iovec *iov = *iovp; + ssize_t ret; + + if (compat) + ret = copy_compat_iovec_from_user(iov, uvec, 1); + else + ret = copy_iovec_from_user(iov, uvec, 1); + if (unlikely(ret)) + return ret; + + ret = import_ubuf(type, iov->iov_base, iov->iov_len, i); + if (unlikely(ret)) + return ret; + *iovp = NULL; + return i->count; +} + ssize_t __import_iovec(int type, const struct iovec __user *uvec, unsigned nr_segs, unsigned fast_segs, struct iovec **iovp, struct iov_iter *i, bool compat) @@ -1792,6 +1816,9 @@ ssize_t __import_iovec(int type, const struct iovec __user *uvec, unsigned long seg; struct iovec *iov; + if (nr_segs == 1) + return __import_iovec_ubuf(type, uvec, iovp, i, compat); + iov = iovec_from_user(uvec, nr_segs, fast_segs, *iovp, compat); if (IS_ERR(iov)) { *iovp = NULL;