From patchwork Wed Mar 29 18:40:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13193133 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 7A08BC6FD18 for ; Wed, 29 Mar 2023 18:41:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229569AbjC2SlD (ORCPT ); Wed, 29 Mar 2023 14:41:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229505AbjC2SlC (ORCPT ); Wed, 29 Mar 2023 14:41:02 -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 9843218F for ; Wed, 29 Mar 2023 11:41:01 -0700 (PDT) Received: by mail-io1-xd30.google.com with SMTP id ca18e2360f4ac-7585535bd79so9937739f.0 for ; Wed, 29 Mar 2023 11:41:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1680115260; 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=gJ++MD0LIGmWuvVGWTBiMDXuzauI3zu3ho73y0eaU1Lwl/VosI+DByixd0MFXQXppE 3Y716lGGVqsCGm4S411NJINv0WUfG4lVR24FoauRIYqB8BKKsOn/+a7v+oDhSBGIReht 7GYf+tVnPgcyu4/MCldiaI16dF+ikimFppByMhkEw9xLVrt9nTXc8+Bz2V+C7e/i9ux4 ubhfWDBlgBivLdZNb5Y4U8/R7zA+rOFmGtQOX96cp3c2Y5aYQyR6MXeSA0L5uXtXAPXC KJ18CJHJOFmqwA9ooKSjguchcYlzlfKx5HoJ22DlwopioC/ONvnW6npUGUe/MyCe2akA xd0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680115260; 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=pzeXWnVDphQNM24mgc/N+fg1HjbCGsNJ69qYGgQlS/YZnNPvpzWXUhdh/BvYame61z 3gxGzdndwu/txOPcB1JhF07OpBQHuhYYP7+JKSKV1WzbUIOLpTxJnHffMfFNzD76P5Wi w61QJ/lWGy7K0HBsuC6l6B8f+1n8xxt5bnN0LqNG1A3NO8UFlT9zcQRxdigc0Q+R5/K6 eoCZ8MF8KOhkNs5NGRl6X4X3xn5tAoWix16w86YdxWpbbQ94lm0YtRyRr4FZk/0cbeEM GviH2yvrwIioMsfDLXA3lio3DQUVU/irMyddG4AuFay4ZVZJqYOa/Ig2FopEzIs7ZKEm nJzw== X-Gm-Message-State: AO0yUKURWrzSPOvxJsLWAVdL29DziA2D5Vpcd8wLycXZVaCmE275dgnS mj4hkQB1dnOduZmQ9+wyOQ89qqYFVxqsw/yB3Cfmcg== X-Google-Smtp-Source: AK7set8s3jHXmhvcwCwnvJTb85l/IjY9FweqqTiA9yZraU6kJKHhLZxV2UD3PoiX+dgJiCAZvpjMpg== X-Received: by 2002:a05:6602:2d87:b0:759:485:41d with SMTP id k7-20020a0566022d8700b007590485041dmr11983777iow.0.1680115260466; Wed, 29 Mar 2023 11:41:00 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id m36-20020a056638272400b004063e6fb351sm10468087jav.89.2023.03.29.11.40.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 11:40:59 -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: Wed, 29 Mar 2023 12:40:45 -0600 Message-Id: <20230329184055.1307648-2-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230329184055.1307648-1-axboe@kernel.dk> References: <20230329184055.1307648-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 Wed Mar 29 18:40:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13193134 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 6970AC6FD18 for ; Wed, 29 Mar 2023 18:41:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229620AbjC2SlG (ORCPT ); Wed, 29 Mar 2023 14:41:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229505AbjC2SlF (ORCPT ); Wed, 29 Mar 2023 14:41:05 -0400 Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7368186 for ; Wed, 29 Mar 2023 11:41:02 -0700 (PDT) Received: by mail-io1-xd31.google.com with SMTP id o12so7243321iow.6 for ; Wed, 29 Mar 2023 11:41:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1680115262; x=1682707262; 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=nWdycVsGGnTkb0KL3x/WbQKyUgfgtr0eaATuLfjWJRZBN6rb/fEU61r20Ka1NNihh7 GwA7MrkMgY77qdf/YWd2EOMksSeeug+7OIlgbZ5Ai4qMwAxtDqldO3UBMAZj+yYQ8YH9 h0ZFF/xGA05+i5sv3R6HvuJDl3bkr6p0GMtCy6UNfz7LEYBCDxxvhiw2XlpXlNhD+FKy 74AIfEaB1e38gPpCptVTkRbDMTXTgf+9UT2xxO1RFbnxIVAP6gefP0Ze8aYYR9cWMBx0 9hJetdSCseZRTs+Zv9eL2IOfZyPpQHvCJsAxR+Fs2Mc3Qh7BanvR24okoZTHH+uavlp7 zhzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680115262; x=1682707262; 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=AHIZZXyeAtBsZJatxpq69bOrKQANw/OYnXjwh3cCoRQrlPHJsTMrXuTsHifBcM0VfZ zmhCiuXZwpTl55KzxbBefhtdBpOIJBu3lHG2TBqQrLgpgQf70rLBdcaiPayOU/T41fU0 fQEiSlM3ewL83lCV6QxE5rLmYLb6tPQL3vMpMlSikqBqB3lBG44GoH/zhfSgz3BbQ0tT KtTGeaX0cwN+Yy/tUavaPewdFgtzSmg/Y0B46UkEeixtU3O2KnRsdkqNUz3aIsLSsU5V qWLrkYFaZWryZ9OXUrFEA4406AI76p9WBDu5is753ToGBtmFrU5vszNLUMmVVhNqfjbq 4aOQ== X-Gm-Message-State: AO0yUKUQKJsdvMmbc7Hh72mNg8Pw8j6gNnGYq2LkInwWLX1F96cBAH1U Oi9qUba+iE30Nd2ug1f+A+VwlyZZ9dFicQltsaQSzQ== X-Google-Smtp-Source: AK7set/rKxF0aenbWIHl6xpcUHtWHJcHn+ym4kcfPVjbUYynt4zu2nzTms5QRLGUoXOqQdCYKfPEnQ== X-Received: by 2002:a6b:b257:0:b0:758:8b42:ce5a with SMTP id b84-20020a6bb257000000b007588b42ce5amr11978855iof.1.1680115261721; Wed, 29 Mar 2023 11:41:01 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id m36-20020a056638272400b004063e6fb351sm10468087jav.89.2023.03.29.11.41.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 11:41:01 -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: Wed, 29 Mar 2023 12:40:46 -0600 Message-Id: <20230329184055.1307648-3-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230329184055.1307648-1-axboe@kernel.dk> References: <20230329184055.1307648-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 Wed Mar 29 18:40:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13193135 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 59101C74A5B for ; Wed, 29 Mar 2023 18:41:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229723AbjC2SlN (ORCPT ); Wed, 29 Mar 2023 14:41:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229571AbjC2SlF (ORCPT ); Wed, 29 Mar 2023 14:41:05 -0400 Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD54E1FDA for ; Wed, 29 Mar 2023 11:41:03 -0700 (PDT) Received: by mail-io1-xd35.google.com with SMTP id bl9so7234784iob.8 for ; Wed, 29 Mar 2023 11:41:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1680115263; x=1682707263; 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=XMkysAG5kgc7/AQwMJFGJ3Cx++C0nMIt19OeWo+dMA5bB+K70IHOX8vJm0FrOySfhi fLFxfN6H54P2yip53Hwtx1zlgsX3CIn+gW6Jm64qYvuFd96VyLZYIPGvNMyQCYou4+cK CokCVreTCQhWO18DaVkafXVOokAJ7AByD/xVmhxWPodoZU+KbggQI4zLvuInnL2Mrawx qt5I94PPDvP0klXxyQnz+RkINfXZrkNhmFyw5oHJ1/kjTh5Sp+ebMtG3Oha9cPDimwng 8lrNxW60rNrP1NREdcvwFBrLztB9GICjxPYMTxB+HnKJsjOhDu5hf6eXB/si0xcYKJaJ 28vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680115263; x=1682707263; 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=2b6zwbv1gmjwKfRtiAPbiOuBawi4eCOfzaECbjqN8lXBB6c5q30LW6hJHKyUQ7n5bm Kfto/VgSUMBhc6UV76Ez/FrmurcELBOucsKzb1dmjcRg08Q/wDabO3eGiQf+GVQVvZKh Pb8iFAE+1oSVOUO/KOuh9j3VFl/eIeWxmYtbjb534pm0w5qseXME1JU/nL9ieOEC+cuL t+ucBYDMMtmKp+2GfgaRkMMq3eQ3mqb+ixWmcaCappofmrLVk9IYx09Uyy9DEAJeqC5G XTYFS8K+Q1BJ/sis8u1+4lfsNx6cpxSLljmMpba3ahcSyw9bfHDcDTTSKw05p8pWYfdF /sJA== X-Gm-Message-State: AO0yUKV7NDCBQH2FNbiD/81yKvyZklqEGMWOq91KqKB3cVERHHhIJHW2 fK3LOn00yOyhdgfc8YePo7zWCUcIo+qlICDy7WywoA== X-Google-Smtp-Source: AK7set9SGE/l+jD1Q12SLn6zOemkfTfgQlkhrS2CqmKaDVbimHfLRdVLDiSvIX/6Vjpwa4B9GU6LGQ== X-Received: by 2002:a05:6602:1246:b0:758:5525:860a with SMTP id o6-20020a056602124600b007585525860amr11266384iou.0.1680115262710; Wed, 29 Mar 2023 11:41:02 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id m36-20020a056638272400b004063e6fb351sm10468087jav.89.2023.03.29.11.41.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 11:41:02 -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] iov_iter: add iter_iov_addr() and iter_iov_len() helpers Date: Wed, 29 Mar 2023 12:40:47 -0600 Message-Id: <20230329184055.1307648-4-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230329184055.1307648-1-axboe@kernel.dk> References: <20230329184055.1307648-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 Wed Mar 29 18:40:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13193136 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 18591C6FD18 for ; Wed, 29 Mar 2023 18:41:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229703AbjC2SlO (ORCPT ); Wed, 29 Mar 2023 14:41:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229605AbjC2SlG (ORCPT ); Wed, 29 Mar 2023 14:41:06 -0400 Received: from mail-il1-x129.google.com (mail-il1-x129.google.com [IPv6:2607:f8b0:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C17304C2C for ; Wed, 29 Mar 2023 11:41:04 -0700 (PDT) Received: by mail-il1-x129.google.com with SMTP id x6so8583837ile.3 for ; Wed, 29 Mar 2023 11:41:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1680115264; 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=qdi43+mLD0a4vUBOb613AgoA7UaRrr2PLFq8vlQHDsbqpvZzh7a3Tgz7O4g2DyihAo GFQIKSg9EQ5ZKL16bA8AgX0oA5+oOf+NtGLiKJN085iduJOpO150CkxUhdUXkSldMse5 uqZfSrbU7TbtUFJ+1x7gXbrURttTEPskYQQg92QPax8uPNbdOShEgMhzUTB5pJCz0CX5 slcyweq3LMpo9mv9VjVbKVRcbHB6IbCm7jP3Rfim4a+JdgWiBY+8VSIlnQsGierDctkm oI1F4RoYl2u4CaGoyZTwuyfgCG9CH1em7OEQlN+/PvhCTikZHq5vknfyUiTCcLY1SJX1 zVXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680115264; 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=HSPtBQ5PaKSziskWlXzMsR/LzmHFxrunXNuZr1nfcPo7hMURw4iy2ZWJ2bBW/+2dSj 0MY8M+qAxPuEvLOIR7U/vn79TkxxMHb+Zgoq+sbV4FhC5aDmzfbY56IRGsZuAYk6BPNS k+imJSmLGbJ552TC7zkb7sy951gepMPxnxCVhFU3+ql4rRPOD8DQvGN9g3myhXYp01Kr +YS5zmKWRsJaxiEmTp11HtebA4nJaPqmrbCwSFflO9LEDhVnA4nSuRBgMK0o1/LiX6yD EStT0N6HyC6H8We3Kgzqn/Y+Kg9Tnw/chA7jR362lbQnJt4RIKVWA055Mp5p6gtlDDa3 hoEg== X-Gm-Message-State: AAQBX9eyediL2iU4MY8pV0iq1fKMAxSCgqMMWAcucDdjvRqfCnz/XUQ3 0eV+yGcw1hNNoq7KZaZZ92sPVAbSh/u3yfWGAB2M1w== X-Google-Smtp-Source: AKy350aSEj5hRiKjuwniCuaVLNY/j5/Zxm+O3ifltJIIAcBB0G3x7Q+R8kmMoWblHZBgmhSQ4TDO/Q== X-Received: by 2002:a92:cda6:0:b0:31f:9b6e:2f52 with SMTP id g6-20020a92cda6000000b0031f9b6e2f52mr12817007ild.0.1680115263827; Wed, 29 Mar 2023 11:41:03 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id m36-20020a056638272400b004063e6fb351sm10468087jav.89.2023.03.29.11.41.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 11:41:03 -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] iov_iter: remove iov_iter_iovec() Date: Wed, 29 Mar 2023 12:40:48 -0600 Message-Id: <20230329184055.1307648-5-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230329184055.1307648-1-axboe@kernel.dk> References: <20230329184055.1307648-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 Wed Mar 29 18:40:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13193138 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 3C83CC77B62 for ; Wed, 29 Mar 2023 18:41:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229730AbjC2SlQ (ORCPT ); Wed, 29 Mar 2023 14:41:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229691AbjC2SlL (ORCPT ); Wed, 29 Mar 2023 14:41:11 -0400 Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5728186 for ; Wed, 29 Mar 2023 11:41:05 -0700 (PDT) Received: by mail-io1-xd29.google.com with SMTP id i3so669820iow.5 for ; Wed, 29 Mar 2023 11:41:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1680115265; x=1682707265; 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=2yUWt0xYDEJ7bCONaqqAHkStl/lIzPiBlubuf1kcx1og/Y4amwtqr1sJmWQKaaFUEn BQY/smQbMfRLRZzTGx4kMhDxHkEB4f2CyB3LsiWE3+8dzRIk4PTCRLrZ7y5uuPxyGmPX CJ0KWXRn/egJxsft6CtHrSk5CfD45h0d21AeeUbQbgk9xMZ+Zbn+MB0o0cufBXpxexdy KLcBj1lVtIaxEvLv/UTizgX8cTK2LdsSBlPZdG16HKRYr4xv6LD3m9dUdoBRagIBZN1R FYsdGx93qLuVCsub1DD+WYRZO0nWpFaBg3ninY0eMg+kGQ7Zn/7FczI5ZFhwXgpi0mEy Jq3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680115265; x=1682707265; 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=0J+EOiODDAnOIwx3PS2eW3cByrIeaeLercHaBIUA80Pr9kc9hz7xrsPVb1T7udj8zS m2c2K2l82j8yN9kfteHubAfATGHY2GLPFvdcBTqLjgij16StGQxy4SNcPXYHI3isTceA kMk3gs2aglr3b2KJ7nyCPJFG76JyN8P6kuyN/aeCJA3YWEwka/3Jj8NgjsHMKcVzICYu ZAwuWoZ+4dEPhB17Z0KmPp8QL+ig4ln9HEWjypIdq+kQKwDZ5ZGVpmjgsWoDW7HaPpCn L2UNOBhmDjwO++l7S9FDUuFV1BMQt/WgdIgL/cyER3I06FwId0YmDB573oVkHS9MrE3R 1hnw== X-Gm-Message-State: AO0yUKWLT/d+vvbbSTTAvR1gI3jR/t2czyHm2uqIjQ7q2zATR2lZYueP jb7wImG0tmQKMFQa8Tjxu2Dyg7QUqQMDxTw1xC42XQ== X-Google-Smtp-Source: AK7set8rR8FhOKC4cfAvmlPuF7FBzR1R2F60+jLZB+bEhhbuoG8heTMsfm6uuCjKjjOSduHb5R+C7g== X-Received: by 2002:a05:6602:2dcf:b0:758:6517:c621 with SMTP id l15-20020a0566022dcf00b007586517c621mr15108082iow.2.1680115264768; Wed, 29 Mar 2023 11:41:04 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id m36-20020a056638272400b004063e6fb351sm10468087jav.89.2023.03.29.11.41.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 11:41:04 -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] iov_iter: set nr_segs = 1 for ITER_UBUF Date: Wed, 29 Mar 2023 12:40:49 -0600 Message-Id: <20230329184055.1307648-6-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230329184055.1307648-1-axboe@kernel.dk> References: <20230329184055.1307648-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 Wed Mar 29 18:40:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13193137 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 12F75C77B61 for ; Wed, 29 Mar 2023 18:41:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229605AbjC2SlP (ORCPT ); Wed, 29 Mar 2023 14:41:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229660AbjC2SlH (ORCPT ); Wed, 29 Mar 2023 14:41:07 -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 AB5DE10DB for ; Wed, 29 Mar 2023 11:41:06 -0700 (PDT) Received: by mail-il1-x130.google.com with SMTP id o12so3563316ilh.13 for ; Wed, 29 Mar 2023 11:41:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1680115266; 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=U0VcraBYDXC4QOd32aPXOd6FdUFJG3e+L8qS4/nO0PQ=; b=GN+TKYHX/Fk+/Qti8rTPVEFBex+/1+wEWvE9Jzxwk/K2eeFunZMbT4WXIm4GVZTGji E5RRzkrmdR6s//ZFA9rsI5hQSUIlUJrkC+xHQrkYdYOLYJcYxMCJR9r7w6tr6WGqI7hw Zz04B959Dew8wUE+JyQBmVDUOMXt/K35xxRsZ9XOuk44H4S88MolZwz3O9vJkfI9TgrN zJrWWvFXn0mRrChzxRSTkgggNzUcibrFumpIbQBrpJRKW5pEyLJspPAIniwGRiCg2zd4 td0qlk654bXVlRhRhiQxNwThWkn0rsyJCWLgvz3xwDFUNaklcRw/mYOvWP+yeoWFHDGc 0eMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680115266; 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=U0VcraBYDXC4QOd32aPXOd6FdUFJG3e+L8qS4/nO0PQ=; b=hYIsooCZDoanhGh+94yVKp3YyWYuRXrpzQWccuMU/nRrbiiSityASfZDtHKA6RSx0K /oOwVW3u3J6i37L4Dz/iCI718yRjU/cKp8Im2iqk0YFTAbC0GwSOyGWwW4nPoK1fH7QM zBy+VUT7XxC2hitAD3wVgosQ/r5gDviJHzrCs8hZqTE8dCH6qqGFjKfkA/0qk3NxCPDb BoHh9pRlrxMsC25sGbD8giTbWQzIbGO1CH7oMa6xKtKfDLo9/sjKCyYjTPXISHWggZtB XePnPSmFvbYnqCy6Vk5/QbJID0k4uBRyiuq1Lw+40Zv7D2PukdJnuEKnxNOcXDinEnrk puPw== X-Gm-Message-State: AAQBX9eNik0sV8+6D9Gry2mbNvbGeqdq0xT5kXIMgA7nSNc3uvGDpQAk eBC/lVc1w62HV5sUW2PW/OaAyomnEnocMFcFDUr8VA== X-Google-Smtp-Source: AKy350aY7ZrWWrk34HMjbkMzQNGa6Bu1NC/lty11c8FWPIpBH4kzB40UoUzvVOF6cUPvcEjsMXCbpA== X-Received: by 2002:a92:cda6:0:b0:31f:9b6e:2f52 with SMTP id g6-20020a92cda6000000b0031f9b6e2f52mr12817037ild.0.1680115265705; Wed, 29 Mar 2023 11:41:05 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id m36-20020a056638272400b004063e6fb351sm10468087jav.89.2023.03.29.11.41.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 11:41:05 -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: overlay struct iovec and ubuf/len Date: Wed, 29 Mar 2023 12:40:50 -0600 Message-Id: <20230329184055.1307648-7-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230329184055.1307648-1-axboe@kernel.dk> References: <20230329184055.1307648-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 | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/include/linux/uio.h b/include/linux/uio.h index 5dbd2dcab35c..361688b86291 100644 --- a/include/linux/uio.h +++ b/include/linux/uio.h @@ -49,15 +49,30 @@ 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 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; + 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 +84,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 Wed Mar 29 18:40:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13193141 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 51403C77B61 for ; Wed, 29 Mar 2023 18:41:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229739AbjC2SlT (ORCPT ); Wed, 29 Mar 2023 14:41:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229718AbjC2SlN (ORCPT ); Wed, 29 Mar 2023 14:41:13 -0400 Received: from mail-il1-x135.google.com (mail-il1-x135.google.com [IPv6:2607:f8b0:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98F3F1BE4 for ; Wed, 29 Mar 2023 11:41:07 -0700 (PDT) Received: by mail-il1-x135.google.com with SMTP id j2so1553989ila.8 for ; Wed, 29 Mar 2023 11:41:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1680115266; 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=303Nu16BnhfbRchxfy7E3Vfr0miRZ+SmSqAxmWAMiymaxT+QfalejvwDZfQrcSyqh1 okTRPheqzv5yXo0fo/RzFIyfjYB2gDFESv+6uic0jhxF+1mCDrJbpUktf3t62XvOeSVo hICcnzhGo32yPz/5V0RzJFRHCpuFUx8ESdbvzEMr6AvGt65u4ECFiQtOSDLH+3SaCPOZ j7HI8HSTmV/DYnvTGlHqxivvLSinbHoGZ5Esyxn9N/43mJVKcMjMyoOvAsNxezbgCQIx HOYDylDW12Cc+6m/zMQhp2joofzq4rI/B2se/bkLS5hsdYJqyYOQDkV9W07py/6InHJK 9IxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680115266; 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=VKWA3aXc/5FnRU2wCgfy3fVLFpi3VbXSGB9NGngtGJWgEoAD2WE6TwPUeTb1cDxM/I PkhD9HZKZ8oTkhS0uyfPt3N9kKYeSmTi52Ww6K4bop9ahwYoTPnOobSZnsghK62BJGgZ 9CiiiAqKTHhC0IpCrNpXtjgjW1Jp3o4TEqmFsrPDgPu+66MgtKT6C4nMFQKb8V3kMVUl V6w1eKh4vMInJJHwhYGPBVuCiXwkk4f0kGa3Z3YiLZXN19CcnfpZa04sPDgl82wi559Y KGNRxSxuDmXYpL59bcpd2Jugg0RodA+P8UHhJtymm9l+NCeskGmmy1XlMYVPfGG4e0x6 APng== X-Gm-Message-State: AAQBX9c8COfLQE9fw6GgjoldCqNjLuKZVf240Hd1Yg+IX4JFPCyfEojP Vt0ZB1XT/HeOmrHYpi6PpAzMaEC0HBEorj8IicGg9g== X-Google-Smtp-Source: AKy350Zt2aEwvhvN4pVijKz7+mi+CqCUB3K6LeC1lzK2SHo4E9RIyNwxWhK8XfreI//ENbIrW2jm0g== X-Received: by 2002:a05:6e02:218f:b0:326:1778:fae3 with SMTP id j15-20020a056e02218f00b003261778fae3mr6057930ila.2.1680115266696; Wed, 29 Mar 2023 11:41:06 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id m36-20020a056638272400b004063e6fb351sm10468087jav.89.2023.03.29.11.41.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 11:41: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 07/11] IB/hfi1: check for user backed iterator, not specific iterator type Date: Wed, 29 Mar 2023 12:40:51 -0600 Message-Id: <20230329184055.1307648-8-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230329184055.1307648-1-axboe@kernel.dk> References: <20230329184055.1307648-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 Wed Mar 29 18:40: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: 13193139 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 8D9DFC74A5B for ; Wed, 29 Mar 2023 18:41:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229733AbjC2SlR (ORCPT ); Wed, 29 Mar 2023 14:41:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229700AbjC2SlM (ORCPT ); Wed, 29 Mar 2023 14:41:12 -0400 Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A552E5260 for ; Wed, 29 Mar 2023 11:41:08 -0700 (PDT) Received: by mail-io1-xd29.google.com with SMTP id h187so5518470iof.7 for ; Wed, 29 Mar 2023 11:41:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1680115268; x=1682707268; 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=i/aFHmZoCpMqZl6FXMw+T03+UL6N14GYACYsmk+zlqsT4FaGZzGcnP9ufw8drSAHT8 lAiE3qCo43QUWbt3yDc6d0zTxPfsIjAm4LesepDrecaLYcEtuaCY+tRqlgusRvtDe0Pl 1ltdzcCYf8xk419eBjo86/u/0gbnXw7Hp9FClCb6VJD7BV+DLc7GmXcrwtbW1YLUa0fN WoqY2IaesVMNje09QfjuAo3MiRMysvM9uOpjpPGB70NMYZpbi+XeWyi5Rtz4fvKNZCFH vJUQBZwKhsBAV/QeqGFq8kiTxP8cl1K91hrKz5z0p6bMmg++Y+RLi0akT7ly/DiIZTT9 Id2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680115268; x=1682707268; 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=H/z3AYdJS8H4UQxMUBhIxhfUYtfrXf+5txzaAuYL0jlsiqvWdRVzKZtWWMJVZzPgKL xZNwg3bc5n1tRXhE6yO5dhzITT9rp0enId61PHnxKYUPXZX1wu6VePwkhcEmBIncDIjB X4238+iVTxHDopWxqc/95XlgGx3+CRMXtz/2/ai4YQVY5PpMZzVd3yCYJYnSZucGtdqM KuVHDSQzMlqMZsNTAZoft/Pj1ckfcDRKab2W2SVHVsF4XRgwn7XifZniUQXdHD2D93GS Zl3X69Q6EFy6gzOH+XSw7iiu1u5qkwdAkTgXWj7CsQyssIqLS3SHPdx/oV6v/Li3x7cE BgWg== X-Gm-Message-State: AO0yUKVUvKEkREuOfzP+7b7XtzWTNHFCgmGBjaf5geoQPJBUtAJkX3Tc TLUVb3eowvbRoG5s05956CPINSIiXMF6j1RpdD4WPA== X-Google-Smtp-Source: AK7set9OqgsKxt44QIf3xpV4OzzDRCwCk1c/e+Uzt7UK1+mLA2Kn7SPEFjQRBg5pNbrmENqUcsDWxA== X-Received: by 2002:a05:6602:2dcf:b0:758:6517:c621 with SMTP id l15-20020a0566022dcf00b007586517c621mr15108166iow.2.1680115267652; Wed, 29 Mar 2023 11:41:07 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id m36-20020a056638272400b004063e6fb351sm10468087jav.89.2023.03.29.11.41.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 11:41: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 08/11] IB/qib: check for user backed iterator, not specific iterator type Date: Wed, 29 Mar 2023 12:40:52 -0600 Message-Id: <20230329184055.1307648-9-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230329184055.1307648-1-axboe@kernel.dk> References: <20230329184055.1307648-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 Wed Mar 29 18:40: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: 13193140 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 34918C6FD18 for ; Wed, 29 Mar 2023 18:41:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229700AbjC2SlS (ORCPT ); Wed, 29 Mar 2023 14:41:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229704AbjC2SlM (ORCPT ); Wed, 29 Mar 2023 14:41:12 -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 96B4F1BD8 for ; Wed, 29 Mar 2023 11:41:09 -0700 (PDT) Received: by mail-il1-x130.google.com with SMTP id s1so8568434ild.6 for ; Wed, 29 Mar 2023 11:41:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1680115268; x=1682707268; 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=BsTGsPp7rZFm1zzMckI8g51kniEGARAtpYfBMfRdNevOd53kbbZmqwRVUkgPSNVOPS XFywQcl1ix5+emGa1egmiRNDzKpXYBs5h5gzBeG+46Ubo5KG6PkugRLAfTx0PK0hcgfc 4Yho2kgcQBKhhhwt1R8UCnyv7DkQeRmQd9UVVunF26T+DDmdXHcExKmbZAY/muNTCx5D 87sJ0ex/enOfZuP8N/U0++82b3z8X77dCPjZsCJeXPQ4QHjw+NfxKKk9KsqApQAudBGF SnWHqRmuFTfj303c0KKc5AWZkoee4WTWxAIL/UJ4/baX9UQkLMrahe9PFTril+SPWnIo lZzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680115268; x=1682707268; 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=stcdere82nsVNt3MVqhFGK7RgQf1s733X5ks9dHBpuSztHwe+PHau83mbS7baGOA4y IvAfFlvb2kMyZ8GIDg3nxIC1xxz6YUyxQMwbtneRgc7S4J7WT1YqTgcjhaZ21ykRnQMS H9x4ZZ6RMLIVfJyeRTpeW00UYP1zw006vJznTelQ9dfeMu1CQ9RBzOAXITdq4PUAxEKh 1xdJc8aIDB+J0k8m80SI3JCY3yJ01teVjl0vMPteRS2rnL3cShUrdmsKAgYRj3vIXmsH FPh6dqAunyvonRF45DVbvMuPdGVZ4GfyvW+xu6RB35GPAdCBS61d5onovgzVuQ/Azgch drMw== X-Gm-Message-State: AAQBX9eSyXsthFakz5HZM2vPn64hT9ciGUiSGiFtdtWlfv4SOm/sAUWC Zs+bYWZpG1PkfR6Jss+T36DcbtbclXUZyCMqbS7ocg== X-Google-Smtp-Source: AKy350YHOzdvk8olRol4+RINlgxmHYIUvNUbcIpK0FIGtOz3Buj1+cT9Z4GWtv3xu7FiDfseFCE2rQ== X-Received: by 2002:a92:3652:0:b0:319:5431:5d5b with SMTP id d18-20020a923652000000b0031954315d5bmr10986230ilf.1.1680115268681; Wed, 29 Mar 2023 11:41:08 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id m36-20020a056638272400b004063e6fb351sm10468087jav.89.2023.03.29.11.41.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 11:41: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 09/11] ALSA: pcm: check for user backed iterator, not specific iterator type Date: Wed, 29 Mar 2023 12:40:53 -0600 Message-Id: <20230329184055.1307648-10-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230329184055.1307648-1-axboe@kernel.dk> References: <20230329184055.1307648-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 Wed Mar 29 18:40: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: 13193143 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 73A17C761AF for ; Wed, 29 Mar 2023 18:41:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229768AbjC2SlV (ORCPT ); Wed, 29 Mar 2023 14:41:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229671AbjC2SlN (ORCPT ); Wed, 29 Mar 2023 14:41:13 -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 920142108 for ; Wed, 29 Mar 2023 11:41:10 -0700 (PDT) Received: by mail-il1-x132.google.com with SMTP id s1so8568460ild.6 for ; Wed, 29 Mar 2023 11:41:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1680115269; 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=NJ+KQ3zxi/4UvbaJfWzuW7IIyB+5/n9vCN9CUy+htDOSpqTXm0RkWUHMFw10ybvQn9 4B/Y+R+a0XonvaQZ0GRTNLVk6z+Eh5WbGUcnsRs1zF94rbmEBBYdWC1U8fvbbuUqLrFT RqRbkx+nzDfIVz6icy9YfPXJS4FQatMf+opioHRy8dk5KybXzJzUGFJq/vh47/vMX3I6 Rnt5+TPE+hAP9GgNfe2plLM+6erd9jd4zpwpe1sVZh58/X6zefD7zjVgYOOdmABCADTW +4QBwZGhH7NzaAzijkTkzKpnUg8NNkaLNTnWEILqdKJO4Y7eIhJacoErcUj/DGIsugYn HemQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680115269; 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=qNHPs7ndKYAxAsI8Xf2ofD9Dc8epIkBtCNN6AF8HHmQDoy6+Osv9WLYyY+RIq0R7TQ FidZtSKqSeez1xGaCBa5fbzP7pAuKfEWr1BxJ47UfE6HQvN6iaYrJhH9bP3vPllBP7Z8 zOL+JvekYqHlovtdGbW8x5i++8ghCx13+b2kV69psDXV5U6gMmCw7mkTf/w2qG+EOAxO 1MnIOPgCK5QQdSbQVORSGk9H1RH2GE9Jc87PaLCVIw9UMhvv7iJ5pWQtzVYFCgaGPHGM m+mksf6ud5UjsJzQtk5Cb/iRz4pDpvVoMVs78X1+clMQdp3zLhQ5ccGS3U18/FIHw2r9 rvQg== X-Gm-Message-State: AAQBX9cgi47s4YNifmEwztL7TyZKYQXaVMWNHdmg1s3W8Ejqjifz3pgh hGc0caWkWPfy4XWWN5eTTZRIialo7rmyHgwlmcPTuQ== X-Google-Smtp-Source: AKy350bfpY8D4e+hOHv12oZYQKJ3c0vfhoQzGx5uO/+qtezIMlnc6aWhm5cZh7kMQXO8X+x8SCdwhA== X-Received: by 2002:a05:6e02:ec1:b0:326:218d:6c14 with SMTP id i1-20020a056e020ec100b00326218d6c14mr2788509ilk.1.1680115269633; Wed, 29 Mar 2023 11:41:09 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id m36-20020a056638272400b004063e6fb351sm10468087jav.89.2023.03.29.11.41.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 11:41: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 10/11] iov_iter: convert import_single_range() to ITER_UBUF Date: Wed, 29 Mar 2023 12:40:54 -0600 Message-Id: <20230329184055.1307648-11-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230329184055.1307648-1-axboe@kernel.dk> References: <20230329184055.1307648-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 Wed Mar 29 18:40: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: 13193142 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 432C6C74A5B for ; Wed, 29 Mar 2023 18:41:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229747AbjC2SlU (ORCPT ); Wed, 29 Mar 2023 14:41:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229740AbjC2SlN (ORCPT ); Wed, 29 Mar 2023 14:41:13 -0400 Received: from mail-io1-xd2e.google.com (mail-io1-xd2e.google.com [IPv6:2607:f8b0:4864:20::d2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 360C330D2 for ; Wed, 29 Mar 2023 11:41:11 -0700 (PDT) Received: by mail-io1-xd2e.google.com with SMTP id k17so7251870iob.1 for ; Wed, 29 Mar 2023 11:41:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1680115270; x=1682707270; 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=D/5ASckaf9bmeXQFyqcdTogslw5IeiU+xWykjuvsXK0mkhQvzu9TjlOnSrqsslmXiV YEYCJa3SS+i6eFCs5Tzs/Z3gciOEiFbUZ9OLlyijYb1jYMmwRWC092RVGt7YBwUHfdQ7 AQv2ndCagPn82WTvL6unRZmwFnHMuxAMNYxeTpARBHmI/yzTO9NgSIMKSDSCO/UW6vew TJbpVAf3i7CPneRozC0Rsir1My+hu7IfxreiYeQlk19Xq6dc7MqbWo1RlSiRF4t/LLxF U9EsyHsrVFhXIXaCykWeljjoIEisZ/hVrvAhS74g00y1FLwaOJEn5L0WKCQf+a46G/Bx 235A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680115270; x=1682707270; 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=umDP8c1PRBbF9iiRcfdNVtJQ6OMgWMw50bVrpAefz3nXDBD3LJtMGQMVtbY31AjIm3 4YlfzwoI7Wc+/CYZdap/1vc3G11SVVnybd6aYsOwURtLXa1U91jf2L33Ji260jHJiCUU j/EF9BUif/vnU7NSewiChnpI0k1/zMEYKcs+MTr6fcmjAzHiVFA/qGmyFAS85dvumDO+ dFwuCobJH1vDoIHqyqDqnGNdYFCGqmcbiaj0/vFDu2lw77IoUOQElSnFeJAaxvW8OZ9X b6FH80//ErHmpoOB2/w9Xw516CHGTUY6vTjauQI5joTiDU0ZTligbXAVIbTWmSBwxd21 DyKw== X-Gm-Message-State: AO0yUKUHXErGkHZAkVbmlB2IKj0TjkuQ5OXEkB7Qsh+xDdJcbOJri4Hb QTQJhfWJR4jfkgGBPRDpaCgFOmaG0e9/fVdTShrHug== X-Google-Smtp-Source: AK7set8s6XH1rW3hkG7I+hLmnxVFSRTZwvgT9dcWQn8IU4XmhJybOycFMg7y2SAPkX/0pIZJEbZnag== X-Received: by 2002:a05:6602:72c:b0:719:6a2:99d8 with SMTP id g12-20020a056602072c00b0071906a299d8mr9141433iox.0.1680115270601; Wed, 29 Mar 2023 11:41:10 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id m36-20020a056638272400b004063e6fb351sm10468087jav.89.2023.03.29.11.41.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 11:41: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 11/11] iov_iter: import single vector iovecs as ITER_UBUF Date: Wed, 29 Mar 2023 12:40:55 -0600 Message-Id: <20230329184055.1307648-12-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230329184055.1307648-1-axboe@kernel.dk> References: <20230329184055.1307648-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;