From patchwork Tue Mar 28 17:36:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13191411 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 E5EA5C761AF for ; Tue, 28 Mar 2023 17:36:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229635AbjC1RgU (ORCPT ); Tue, 28 Mar 2023 13:36:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229549AbjC1RgT (ORCPT ); Tue, 28 Mar 2023 13:36:19 -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 8570DD50D for ; Tue, 28 Mar 2023 10:36:18 -0700 (PDT) Received: by mail-il1-x134.google.com with SMTP id e9e14a558f8ab-3230125dde5so421495ab.1 for ; Tue, 28 Mar 2023 10:36:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1680024977; 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=kguXiZPFcvLxJWrtyUvMfJvLBJN9Ay1HNtZpd3doRKU=; b=BACQfHc0JtTyq2co22zooUZF48RVAPlk3hsZjdF4A0OR/lkF9alXKO1+mg/EU1OhTx 07UrP7UgB8PjCvbEza0HSXeOnsCGUJ/gJL5ujbAK22J91Sm9ugavKYun2yvHA5MGXBp6 +iSKblglwV67SpIHT3vPopDlhl3A3BUfETdP6rLQjn+2FC1iR28NB3nNrTXsklsQrxrU AjimNh0P3Yr0AY4mYco0VYrLXE6wXtaZr9NJzEVD0lwVSvLnV1vEO89X5AAZahHIlQGe 21ob+7EdOV8xwvdeh3WfZUNgRONaczQN+dT9NmFScVHs3vU9qm7Z2TL2tioJlz3bD1Fj fM9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680024977; 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=kguXiZPFcvLxJWrtyUvMfJvLBJN9Ay1HNtZpd3doRKU=; b=zENVZI3IYNTsSWlYOCuDQSb8ssxTIBduiBfn3wr2zBjTve9uy0ejd8l2Rs7fSOgAhY y94KpkdOKwsi/0jGyergKbRxsEuOWNXiHNa6RDDvyYDtSgL3OLIjp3nEbyQJyMS2OGtw aiUhSC3ajYZrEdZ34l+ydIG0xGcLknu6muAL5Hf4UxbnN4sl2VMJk/nJ1f32NjCrJuAp /xmkmg7MRTnlFIDn86fha4omrgfoEIpJdUrzYEvQVZ8uKckHwhInMQeh8TpNewo6aUpz 5vnMuSAzxVpmupqYfUlCA5Oy5dZCV5okrs7x3gw8VS70MFC52hcR1xXtrl63JaIrBMiu bWCw== X-Gm-Message-State: AO0yUKW9a9tfCS4HHMYv+GtC4QL+1Fbxk4s9DUqQNmpwWbvC/pYN8WLL phF5jAW7PofEMQ92XX1BztEaxlRTl/GZU0XZurBzSQ== X-Google-Smtp-Source: AK7set+kCEA/6Ti+bw0J0xQjLs3BVCf1MVRayD7+oTv2fvKwFhJEgLA5htndtW4MmCO39qkJx9DFrg== X-Received: by 2002:a05:6602:2c82:b0:740:7d21:d96f with SMTP id i2-20020a0566022c8200b007407d21d96fmr10321949iow.1.1680024977535; Tue, 28 Mar 2023 10:36:17 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id p15-20020a056638216f00b00403089c2a1dsm9994115jak.108.2023.03.28.10.36.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 10:36:17 -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 1/8] iov_iter: teach iov_iter_iovec() to deal with ITER_UBUF Date: Tue, 28 Mar 2023 11:36:06 -0600 Message-Id: <20230328173613.555192-2-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230328173613.555192-1-axboe@kernel.dk> References: <20230328173613.555192-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Even if we're returning an iovec, we can trivially fill it in with the details from an ITER_UBUF as well. This enables loops that assume ITER_IOVEC to deal with ITER_UBUF transparently. This is done in preparation for automatically importing single segment iovecs as ITER_UBUF. Suggested-by: Al Viro Signed-off-by: Jens Axboe --- include/linux/uio.h | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/include/linux/uio.h b/include/linux/uio.h index 27e3fd942960..3b4403efcce1 100644 --- a/include/linux/uio.h +++ b/include/linux/uio.h @@ -143,13 +143,29 @@ static inline size_t iov_length(const struct iovec *iov, unsigned long nr_segs) return ret; } +/* + * Don't assume we're called with ITER_IOVEC, enable usage of ITER_UBUF + * as well by simply filling in the iovec. + */ 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_len = min(iter->count, - iter->iov->iov_len - iter->iov_offset), - }; + if (WARN_ON_ONCE(!iter->user_backed)) { + return (struct iovec) { + .iov_base = NULL, + .iov_len = 0 + }; + } else if (iter_is_ubuf(iter)) { + return (struct iovec) { + .iov_base = iter->ubuf + iter->iov_offset, + .iov_len = iter->count + }; + } else { + return (struct iovec) { + .iov_base = iter->iov->iov_base + iter->iov_offset, + .iov_len = min(iter->count, + iter->iov->iov_len - iter->iov_offset), + }; + } } size_t copy_page_from_iter_atomic(struct page *page, unsigned offset, From patchwork Tue Mar 28 17:36:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13191412 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 152E4C6FD18 for ; Tue, 28 Mar 2023 17:36:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229822AbjC1Rg0 (ORCPT ); Tue, 28 Mar 2023 13:36:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229637AbjC1RgU (ORCPT ); Tue, 28 Mar 2023 13:36:20 -0400 Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85D40BDD5 for ; Tue, 28 Mar 2023 10:36:19 -0700 (PDT) Received: by mail-il1-x12e.google.com with SMTP id v5so4149647ilj.4 for ; Tue, 28 Mar 2023 10:36:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1680024978; x=1682616978; 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=kUQpl1oWFdL7IxlxYgl03xOfPQkkFY7MMHFgeypc77w=; b=ER3LpRgsniOjcjFAHTBdUrXrZvGP68K999Rxb4KF5++9cPbmpkf6E9nBIuhG9Jpu55 YSHxAQ47Sio50ltVAtcaatFGiR48+k3NwaeyIHxf7EhDLVpkqmBILE7WYoKu6iCvo2Sx GOs9uVn0avXHjttE15SAY6/pp5YAf+mg2LKSSBpK/ULFlYu7+TgmPtLC8q1Tjd9QtFSa KJVoKSi7arQWFU7t6TjKeikbw5/N+1N3/P2HbpZSX047tiSZY+tX9lOa/6yT2Yw6uLYL v0jF/NV4/ZV0KCFubVhUUGs6+gYCCtJNfGZPsVpG6ce6rp3LWT8B+HAiILBoK0629kHq 9aZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680024978; x=1682616978; 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=kUQpl1oWFdL7IxlxYgl03xOfPQkkFY7MMHFgeypc77w=; b=drJ+V39Lnwik2eLK1n61CV/cRp9ULf+7BqzEMD3k4YQ/JMcx8yIzrQgpuUKpg8BZhv S45PiUBeiUmb2MQx/4oOfVEGclzGp6QBE/Vj7u4udioAbuJC+ne6WX/7/6vw1qHfQnyo gXDN3SPc0qfndFCRiESXy90528SSXx2RTt5RdXH1ohqgESNOh3CM9Fu+j+tPnnUy+pFg hmXEPFCD68MhBdssZE8ZaC97kLBYiUUwWg/AK3z7DlVJ0L8YrZ95rYJlAY4NBfOcwXA4 nxt60o6wrvvy6Na1FMKFRgijiNOwtlxuDX/sqNF0NOXyh9dUaOC/cDsTIUH1dElCewCe hMNw== X-Gm-Message-State: AAQBX9eXdadmEzwAR+3wZd9TGJ/pSs1nobeGScaMTcHX9uPc4ouuL9XN yFqitAVcQu0y9EwiDFQshlg+yfgf3Oz5t+fbVi8dIA== X-Google-Smtp-Source: AKy350YH6eGwPDcLUmZXAMY8+Kyn5iddxlOgqYqWZx/kjzb3lZTDTKW/p6e9TMiftyWXUYV1lxi8pA== X-Received: by 2002:a05:6e02:1bc1:b0:326:1d0a:cce6 with SMTP id x1-20020a056e021bc100b003261d0acce6mr1905213ilv.0.1680024978551; Tue, 28 Mar 2023 10:36:18 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id p15-20020a056638216f00b00403089c2a1dsm9994115jak.108.2023.03.28.10.36.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 10:36:18 -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 2/8] iov_iter: add iovec_nr_user_vecs() helper Date: Tue, 28 Mar 2023 11:36:07 -0600 Message-Id: <20230328173613.555192-3-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230328173613.555192-1-axboe@kernel.dk> References: <20230328173613.555192-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This returns the number of user segments in an iov_iter. The input can either be an ITER_IOVEC, where it'll return the number of iovecs. Or it can be an ITER_UBUF, in which case the number of segments is always 1. Outside of those two, no user backed iterators exist. Just return 0 for those. Signed-off-by: Jens Axboe --- include/linux/uio.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/linux/uio.h b/include/linux/uio.h index 3b4403efcce1..8ba4d61e9e9b 100644 --- a/include/linux/uio.h +++ b/include/linux/uio.h @@ -168,6 +168,15 @@ static inline struct iovec iov_iter_iovec(const struct iov_iter *iter) } } +static inline int iovec_nr_user_vecs(const struct iov_iter *iter) +{ + if (iter_is_ubuf(iter)) + return 1; + else if (iter->iter_type == ITER_IOVEC) + return iter->nr_segs; + return 0; +} + 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 Tue Mar 28 17:36:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13191413 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 A7969C77B61 for ; Tue, 28 Mar 2023 17:36:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229825AbjC1Rg1 (ORCPT ); Tue, 28 Mar 2023 13:36:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229703AbjC1RgV (ORCPT ); Tue, 28 Mar 2023 13:36:21 -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 86989D53A for ; Tue, 28 Mar 2023 10:36:20 -0700 (PDT) Received: by mail-io1-xd30.google.com with SMTP id y85so5665677iof.13 for ; Tue, 28 Mar 2023 10:36:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1680024979; 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=/CyL6+qOmsnDhD9RFiMpSlzgf9oOvRe6j0pJ/jAF//Y=; b=gL4HHW8gGgyPquwp3cG2V70dREieqNxl+qvxP7oaOtLm123KpDpqgWnHeV5YBezQwe m/MuU3ZEHpLXCjcYHhYoVkQ8w9vEKw0rfto6GkSxWFiYNJL/z99uTNXH64/wEIkzqVbM zl2/sGquRRY2xGov0cjbl+dlPjy/JrbTdIfoeRn5dJS6qKeprNguHpQeu5ICIpqGRGaZ PSWanoa0UZgTKlSQKrCHjYRe0/ArTt0WqaHd1OrBvGn5bNDp4fuqfKyYycMx7Mn44HIC UiaU3GyW2u/u1hEuq2vDa+xJRPU8eHp5bukyZ6FfFrBguuozA0b/Rc35OgYddT4mo+yc S5Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680024979; 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=/CyL6+qOmsnDhD9RFiMpSlzgf9oOvRe6j0pJ/jAF//Y=; b=w7CA2+obNF4j1zm93QOoN0fq6GAgnilbzCSDsDDl6G9TRnuUf5RaeuEgKHbyNomUVy 2YnBUxrHBQtc+lhEhTE1OXB6XwxoHf2XbDzGUB1tUhYflXO/+Ik5BZuY4MLIHaoqSmCP vHSuuMm59A75acV3yvRLlsMAKYU3gm+NJol4M9pn6rn7d5WHRr3a5NpgiQ8BviZHJf3R DJ9yimGo5gAxd0hWznHytFA2BUlaIBM1nElfC/wLunmXEI9QxQWDsW6U4IW8Vk758/sF fGzPzMprmDBmKkKlX2RW4n9sh/XHqeID+6+rLxqI1z84+v4OGgS7fE0wNBWso1C0XJxa t1pg== X-Gm-Message-State: AO0yUKWSWMuahSNMoGNxSQIFunBhulz6Us4CXElg2qxr+6bMj7xtv3Qz r7STHAN6t8mhIZzVFGpUgMGHI0BioWbzyjAtioG/Xw== X-Google-Smtp-Source: AK7set8n1r+fBTFphU6wg4/DSjgq/aWJ7eqxR4OQ+pYFKzWiQlRrN1NXmiDXVxMy5VVnug3jwRCnKw== X-Received: by 2002:a05:6602:1301:b0:758:6ae8:8e92 with SMTP id h1-20020a056602130100b007586ae88e92mr9360665iov.1.1680024979542; Tue, 28 Mar 2023 10:36:19 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id p15-20020a056638216f00b00403089c2a1dsm9994115jak.108.2023.03.28.10.36.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 10:36:19 -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 3/8] snd: move mapping an iov_iter to user bufs into a helper Date: Tue, 28 Mar 2023 11:36:08 -0600 Message-Id: <20230328173613.555192-4-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230328173613.555192-1-axboe@kernel.dk> References: <20230328173613.555192-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org snd_pcm_{readv,writev} both do the same mapping of a struct iov_iter into an array of buffers. Move this into a helper. No functional changes intended in this patch. Signed-off-by: Jens Axboe --- sound/core/pcm_native.c | 55 ++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index 331380c2438b..925d96343148 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -3512,13 +3512,36 @@ static ssize_t snd_pcm_write(struct file *file, const char __user *buf, return result; } +static void __user **snd_map_bufs(struct snd_pcm_runtime *runtime, + struct iov_iter *iter, + snd_pcm_uframes_t *frames, int max_segs) +{ + void __user **bufs; + unsigned long i; + + if (!iter->user_backed) + return ERR_PTR(-EFAULT); + if (!iter->nr_segs) + return ERR_PTR(-EINVAL); + if (iter->nr_segs > max_segs || iter->nr_segs != runtime->channels) + return ERR_PTR(-EINVAL); + if (!frame_aligned(runtime, iter->iov->iov_len)) + return ERR_PTR(-EINVAL); + bufs = kmalloc_array(iter->nr_segs, sizeof(void *), GFP_KERNEL); + if (bufs == NULL) + return ERR_PTR(-ENOMEM); + for (i = 0; i < iter->nr_segs; ++i) + bufs[i] = iter->iov[i].iov_base; + *frames = bytes_to_samples(runtime, iter->iov->iov_len); + return bufs; +} + static ssize_t snd_pcm_readv(struct kiocb *iocb, struct iov_iter *to) { struct snd_pcm_file *pcm_file; struct snd_pcm_substream *substream; struct snd_pcm_runtime *runtime; snd_pcm_sframes_t result; - unsigned long i; void __user **bufs; snd_pcm_uframes_t frames; @@ -3530,18 +3553,9 @@ 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)) - return -EINVAL; - if (to->nr_segs > 1024 || to->nr_segs != runtime->channels) - return -EINVAL; - if (!frame_aligned(runtime, to->iov->iov_len)) - return -EINVAL; - frames = bytes_to_samples(runtime, to->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; + bufs = snd_map_bufs(runtime, to, &frames, 1024); + if (IS_ERR(bufs)) + return PTR_ERR(bufs); result = snd_pcm_lib_readv(substream, bufs, frames); if (result > 0) result = frames_to_bytes(runtime, result); @@ -3555,7 +3569,6 @@ static ssize_t snd_pcm_writev(struct kiocb *iocb, struct iov_iter *from) struct snd_pcm_substream *substream; struct snd_pcm_runtime *runtime; snd_pcm_sframes_t result; - unsigned long i; void __user **bufs; snd_pcm_uframes_t frames; @@ -3567,17 +3580,9 @@ 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)) - return -EINVAL; - if (from->nr_segs > 128 || from->nr_segs != runtime->channels || - !frame_aligned(runtime, from->iov->iov_len)) - return -EINVAL; - frames = bytes_to_samples(runtime, from->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; + bufs = snd_map_bufs(runtime, from, &frames, 128); + if (IS_ERR(bufs)) + return PTR_ERR(bufs); result = snd_pcm_lib_writev(substream, bufs, frames); if (result > 0) result = frames_to_bytes(runtime, result); From patchwork Tue Mar 28 17:36:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13191414 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 3A5C3C6FD18 for ; Tue, 28 Mar 2023 17:36:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229892AbjC1Rg2 (ORCPT ); Tue, 28 Mar 2023 13:36:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229716AbjC1RgW (ORCPT ); Tue, 28 Mar 2023 13:36:22 -0400 Received: from mail-io1-xd2c.google.com (mail-io1-xd2c.google.com [IPv6:2607:f8b0:4864:20::d2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DF46DBD6 for ; Tue, 28 Mar 2023 10:36:21 -0700 (PDT) Received: by mail-io1-xd2c.google.com with SMTP id d14so5680324ion.9 for ; Tue, 28 Mar 2023 10:36:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1680024980; x=1682616980; 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=ITran+xi/3uKyeWNClmpzkXO9DoPYyKa0CIb3OZWNrM=; b=vsw4esRMjg+z7gi9PKRbC4LXLWIgHZMp2lgvrsAnQoJPHVZwAs4NbKKBPPDxfQyXjX 8JhP90Dtpxb3jpFob/3AM3QlVclwYf9Ef8b9yqV5klxoIcrWCLPm8oj5NmoIrgtiPGAe 3t1lAWLJ++7TpCNXI3lD6qWwLrv5WzyLytNGT0SJ6gBRECqLuwtJk05aiV5PRhw134O+ IXOF7W6IJ0Rlz2V9FRkPaP7Jkd8Kb+b6/pL9A5SPqP0pfYXPvGD4FuAmABiI413usGp0 1naoUsUxpk2Ke0JXIU17KBFX74GVHir2cLklcQ2YPITf9kTsHSvCh5rV6Wtl+uSaOGmy AvgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680024980; x=1682616980; 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=ITran+xi/3uKyeWNClmpzkXO9DoPYyKa0CIb3OZWNrM=; b=oIBFWhZ2PVIwPaoloc9yPow2bM5kF6xbjS1t3sK2IovT5xbqxzni2zZMjyxhxRYzp7 mwMzo4XzwzE3om5wl4YDFCBBvfETy5HMw1X6cX198DBsMY7+j2JbX07y6RohjkiZGPow mWjtSr4Si/wYFvS8Bx8s/7llIraGYwZLaYj3V2tLbIy/1KU1v3bWPon+GT+T90RiBV95 wfVRdRopIa3G3X9PRW1qgek47X+Yf0POk/BloYAd6tOayd9hVHWpI6qPxwQvKpVsqoGB DrySPHw/9zM3phZHCaLaZs+nbABI1rRg93jME9w9JVG5d+eCQm/kOZsC/gGXhXIw4U28 A2Bg== X-Gm-Message-State: AO0yUKWks52us/dPqs0TFf4Bh0tvAOe37gVTR5zZ8E+l95LtJdaMe384 1U6IAsFtUrN6Moln+pUQ5AFP6hD7nK+LI1N8UgddAQ== X-Google-Smtp-Source: AK7set+91vfEdHeIwMKTyqR/zJ8vM/oNyI5UXLMrDxpABWWmb8kC2UAmV/sad0GxlhA7XLBhkgGgTA== X-Received: by 2002:a05:6602:2dcf:b0:758:6517:c621 with SMTP id l15-20020a0566022dcf00b007586517c621mr12819350iow.2.1680024980416; Tue, 28 Mar 2023 10:36:20 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id p15-20020a056638216f00b00403089c2a1dsm9994115jak.108.2023.03.28.10.36.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 10:36:19 -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 4/8] snd: make snd_map_bufs() deal with ITER_UBUF Date: Tue, 28 Mar 2023 11:36:09 -0600 Message-Id: <20230328173613.555192-5-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230328173613.555192-1-axboe@kernel.dk> References: <20230328173613.555192-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This probably doesn't make any sense, as it's reliant on passing in different things in multiple segments. Most likely we can just make this go away as it's already checking for ITER_IOVEC upon entry, and it looks like nr_segments == 2 is the smallest legal value. IOW, any attempt to readv/writev with 1 segment would fail with -EINVAL already. Signed-off-by: Jens Axboe --- sound/core/pcm_native.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index 925d96343148..05913d68923a 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -3516,23 +3516,28 @@ static void __user **snd_map_bufs(struct snd_pcm_runtime *runtime, struct iov_iter *iter, snd_pcm_uframes_t *frames, int max_segs) { + int nr_segs = iovec_nr_user_vecs(iter); void __user **bufs; + struct iovec iov; unsigned long i; if (!iter->user_backed) return ERR_PTR(-EFAULT); - if (!iter->nr_segs) + if (!nr_segs) return ERR_PTR(-EINVAL); - if (iter->nr_segs > max_segs || iter->nr_segs != runtime->channels) + if (nr_segs > max_segs || nr_segs != runtime->channels) return ERR_PTR(-EINVAL); - if (!frame_aligned(runtime, iter->iov->iov_len)) + iov = iov_iter_iovec(iter); + if (!frame_aligned(runtime, iov.iov_len)) return ERR_PTR(-EINVAL); - bufs = kmalloc_array(iter->nr_segs, sizeof(void *), GFP_KERNEL); + bufs = kmalloc_array(nr_segs, sizeof(void *), GFP_KERNEL); if (bufs == NULL) return ERR_PTR(-ENOMEM); - for (i = 0; i < iter->nr_segs; ++i) + bufs[0] = iov.iov_base; + /* we know it's an ITER_IOVEC is nr_segs > 1 */ + for (i = 1; i < nr_segs; ++i) bufs[i] = iter->iov[i].iov_base; - *frames = bytes_to_samples(runtime, iter->iov->iov_len); + *frames = bytes_to_samples(runtime, iov.iov_len); return bufs; } From patchwork Tue Mar 28 17:36:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13191415 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 6AE80C77B6C for ; Tue, 28 Mar 2023 17:36:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229940AbjC1Rga (ORCPT ); Tue, 28 Mar 2023 13:36:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229721AbjC1RgX (ORCPT ); Tue, 28 Mar 2023 13:36:23 -0400 Received: from mail-il1-x131.google.com (mail-il1-x131.google.com [IPv6:2607:f8b0:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55C40D525 for ; Tue, 28 Mar 2023 10:36:22 -0700 (PDT) Received: by mail-il1-x131.google.com with SMTP id e6so6705016ilu.9 for ; Tue, 28 Mar 2023 10:36:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1680024981; x=1682616981; 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=DPgTwTI5W0XG5CA6xrGMyHEB/r6kqIaXzt06jC3ZMH8=; b=oeXvDUR0AZKAhQ0k5Iy9bee7rVqzn/+yJiqzvDVjOs/gNRBTeTqIcH9PSMUu2JBwYG 5Efqizb3FNsWIORmmQU5Help56rkF50zYVbbcMba+XBnPenQlfaGI+shqmA3/QMu4n6z 0YN8ZrTStVyyo7Sd3niWg35UK6uN/wtJ3soSzfXATvGDsee62QhpWlFK7SsJpBHEdqqg DVQdUORC92wCgKld8k2MRjDS03ldTuPIVIpBbD0DqE9Z5icg1MvKEPIA6xRPwtUPU93x qKjV7npgsdo8iOTsK629wA+3xf9q3GZFifj7j5tcd/wtC8X/c2HLhNdjz0nrLmOi9rNf tlUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680024981; x=1682616981; 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=DPgTwTI5W0XG5CA6xrGMyHEB/r6kqIaXzt06jC3ZMH8=; b=Gamfl0xfDGBKAxxq96FF8L4wDwkg0vKxuGmRadPh+sRlCXEahzPJeJSnqLBUAO3VGl TrA/tvLiZeM0/Ek3P75AJgZyF2jttqRscS6PfquRag25SRVXCFbHLuVZ4/URP8TlUMk1 NMxraY4LvB5SeZnfynZoVIWr+FUco8Jgjh489Xg63miI6Fu9hHNq1UXUP8n0Zyhhu4lN ongsC2AJwuEh39xinbBuvNL8XLJLCmDbEUzRgjXJt9lOyf3MQXfXcMgS5vLpPi6lh6hB 5eG/oYk+NGEPoifc8Dmy2QOh5vLw6VUItKyRa0xN3G32NzzcTOGjJ3R5XS2+60/gUsDj FQNw== X-Gm-Message-State: AAQBX9ctU9hj547E/mPtZLW8v29vbcAs5XGsqiKj5bonPI0udau3JBKm bEv4FilgAcXao+hoM6q7oA/MRn7uOCnAAq4mWsW5JQ== X-Google-Smtp-Source: AKy350ay90y+Kneb0/E4isuJGqd8++H7ZLqHYkpd7CGo2euqKdd9KOQY8UO6SdcsPgr5lu0TJrGXEA== X-Received: by 2002:a05:6e02:1bcf:b0:326:1e9e:d204 with SMTP id x15-20020a056e021bcf00b003261e9ed204mr2180551ilv.3.1680024981371; Tue, 28 Mar 2023 10:36:21 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id p15-20020a056638216f00b00403089c2a1dsm9994115jak.108.2023.03.28.10.36.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 10:36:21 -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 5/8] IB/hfi1: make hfi1_write_iter() deal with ITER_UBUF iov_iter Date: Tue, 28 Mar 2023 11:36:10 -0600 Message-Id: <20230328173613.555192-6-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230328173613.555192-1-axboe@kernel.dk> References: <20230328173613.555192-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Don't assume that a user backed iterator is always of the type ITER_IOVEC. Handle the single segment case separately, then we can use the same logic for ITER_UBUF and ITER_IOVEC. Signed-off-by: Jens Axboe --- drivers/infiniband/hw/hfi1/file_ops.c | 42 ++++++++++++++++----------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/drivers/infiniband/hw/hfi1/file_ops.c b/drivers/infiniband/hw/hfi1/file_ops.c index b1d6ca7e9708..f52f57c30429 100644 --- a/drivers/infiniband/hw/hfi1/file_ops.c +++ b/drivers/infiniband/hw/hfi1/file_ops.c @@ -262,11 +262,17 @@ static ssize_t hfi1_write_iter(struct kiocb *kiocb, struct iov_iter *from) struct hfi1_user_sdma_pkt_q *pq; struct hfi1_user_sdma_comp_q *cq = fd->cq; int done = 0, reqs = 0; - unsigned long dim = from->nr_segs; + unsigned long dim; int idx; if (!HFI1_CAP_IS_KSET(SDMA)) return -EINVAL; + if (!from->user_backed) + return -EFAULT; + dim = iovec_nr_user_vecs(from); + if (!dim) + return -EINVAL; + idx = srcu_read_lock(&fd->pq_srcu); pq = srcu_dereference(fd->pq, &fd->pq_srcu); if (!cq || !pq) { @@ -274,11 +280,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) { @@ -286,20 +287,27 @@ static ssize_t hfi1_write_iter(struct kiocb *kiocb, struct iov_iter *from) return -ENOSPC; } - while (dim) { - int ret; + if (dim == 1) { + struct iovec iov = iov_iter_iovec(from); unsigned long count = 0; - ret = hfi1_user_sdma_process_request( - fd, (struct iovec *)(from->iov + done), - dim, &count); - if (ret) { - reqs = ret; - break; + reqs = hfi1_user_sdma_process_request(fd, &iov, 1, &count); + } else { + while (dim) { + int ret; + unsigned long count = 0; + + ret = hfi1_user_sdma_process_request(fd, + (struct iovec *)(from->iov + done), + dim, &count); + if (ret) { + reqs = ret; + break; + } + dim -= count; + done += count; + reqs++; } - dim -= count; - done += count; - reqs++; } srcu_read_unlock(&fd->pq_srcu, idx); From patchwork Tue Mar 28 17:36:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13191416 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 03259C76196 for ; Tue, 28 Mar 2023 17:36:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229956AbjC1Rgb (ORCPT ); Tue, 28 Mar 2023 13:36:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229725AbjC1RgZ (ORCPT ); Tue, 28 Mar 2023 13:36:25 -0400 Received: from mail-io1-xd2c.google.com (mail-io1-xd2c.google.com [IPv6:2607:f8b0:4864:20::d2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42517D50D for ; Tue, 28 Mar 2023 10:36:23 -0700 (PDT) Received: by mail-io1-xd2c.google.com with SMTP id h187so3961067iof.7 for ; Tue, 28 Mar 2023 10:36:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1680024982; x=1682616982; 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=xwwpNkl97QizhYZnvuFRLqCzVAAtNtlsaziCI/Oydsc=; b=uzI0rbxg++PYHO5BNhGjMza/dk1NgVjdshDWsWlmzRr7H9YLnZ2uzOMJIPUL6MrY5U +J72JK4IxZjkavNlbXYHgIcFNKFoIwbDgCQUldQc9GMb/CEAv7RlnA7OdotBxGEeRwL3 VpY90c8tpQ86DzcEprOw1DJohaOMUAS4gVnGEiUdhDTsnS5Lf+JeaWB7N3XXNyAxrMFW fWk2o8BZYS2O8+i6XDPRKkwLzRLDTQXaLd2PnPkM/XiDge2ERGWB/g8bWCQze+ubcAda PiJDkoDEvdfkB5gwktticUujhs2vLt3u3aOfb21ct9UF2FxfmSSwlhEz/vHywcsE+IZj sHdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680024982; x=1682616982; 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=xwwpNkl97QizhYZnvuFRLqCzVAAtNtlsaziCI/Oydsc=; b=4DowxogwG2soX/zurOGtMQvNHHViNHHjuYUlbpI6QOr8NuUFkH2dcIHWhqLXkbq9td MLfblVTvuvrMjirQkzhz6/5Y+0xtxn7NEqOed+Nu6a9FkuAjuWwUzrrbvCJkEZzG8HUe kUOt1jlFd6Df+tcafpvj4ss20Vn+KX4sQYdKZMYzMIP3nNCHMcokhgk+hVo2GNZuaJW0 EXYP65Pr1mfDWWQP6boM/QS6fy8ygcIeu/r/gCcmiMbziiNaCMuUO9Gb3sSCVxEqO5eK T0JwNIeHnXt0VJw1mB2ELtYoeWwXOegaVYJBFcYsOevcV0chvev4fPvpLlU7VVNXUqoC yMMg== X-Gm-Message-State: AO0yUKX3p37agAzOW0JfsbJG5FKbZvRWhXm7XwKjcma06eRDeHbdDygB 2MRCw+XqPJOTRSn5jQCLUwhS3VCFJO7nrJ9ebKHUtw== X-Google-Smtp-Source: AK7set/Un9qW8bmzOkq5SY8B6Vw038uDJX44LA+Y2DrfyekNDESqBLes3NC6vzqrx9n6Qq0/fZB2Vg== X-Received: by 2002:a05:6602:2f04:b0:758:9dcb:5d1a with SMTP id q4-20020a0566022f0400b007589dcb5d1amr11766576iow.2.1680024982329; Tue, 28 Mar 2023 10:36:22 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id p15-20020a056638216f00b00403089c2a1dsm9994115jak.108.2023.03.28.10.36.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 10:36:22 -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 6/8] IB/qib: make qib_write_iter() deal with ITER_UBUF iov_iter Date: Tue, 28 Mar 2023 11:36:11 -0600 Message-Id: <20230328173613.555192-7-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230328173613.555192-1-axboe@kernel.dk> References: <20230328173613.555192-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Don't assume that a user backed iterator is always of the type ITER_IOVEC. Handle the single segment case separately, then we can use the same logic for ITER_UBUF and ITER_IOVEC. Signed-off-by: Jens Axboe --- drivers/infiniband/hw/qib/qib_file_ops.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/infiniband/hw/qib/qib_file_ops.c b/drivers/infiniband/hw/qib/qib_file_ops.c index 80fe92a21f96..577d972ba048 100644 --- a/drivers/infiniband/hw/qib/qib_file_ops.c +++ b/drivers/infiniband/hw/qib/qib_file_ops.c @@ -2244,10 +2244,18 @@ static ssize_t qib_write_iter(struct kiocb *iocb, struct iov_iter *from) struct qib_filedata *fp = iocb->ki_filp->private_data; struct qib_ctxtdata *rcd = ctxt_fp(iocb->ki_filp); struct qib_user_sdma_queue *pq = fp->pq; + int nr_segs = iovec_nr_user_vecs(from); - if (!iter_is_iovec(from) || !from->nr_segs || !pq) + if (!from->user_backed) + return -EFAULT; + if (!nr_segs || !pq) return -EINVAL; + if (nr_segs == 1) { + struct iovec iov = iov_iter_iovec(from); + return qib_user_sdma_writev(rcd, pq, &iov, 1); + } + return qib_user_sdma_writev(rcd, pq, from->iov, from->nr_segs); } From patchwork Tue Mar 28 17:36:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13191417 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 61D2FC6FD18 for ; Tue, 28 Mar 2023 17:36:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230041AbjC1Rgc (ORCPT ); Tue, 28 Mar 2023 13:36:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229802AbjC1RgZ (ORCPT ); Tue, 28 Mar 2023 13:36:25 -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 2F400D52E for ; Tue, 28 Mar 2023 10:36:24 -0700 (PDT) Received: by mail-io1-xd29.google.com with SMTP id d22so4657140iow.12 for ; Tue, 28 Mar 2023 10:36:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1680024983; x=1682616983; 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=oNiZElylqd4oRsTQgc5WV3Ag1/Bvc2tTEOYDdozkUio=; b=pT8ktMSFhDLu8ROs3hlcIIFLQA9c7pJphrhLxeCiX6sTdP+QmoRgQZrW43liuOFHCY iypi62DSY9NM6ZC/v6PjBJVXjpy2QEEE+1/uHxUwKUrH3yKKrviC8jKhsMtRUgExYr33 pcF8Kp4utptLUEabfZm4EqCS/5aWWK2Z0FoySU+Xwui6kPF3z0OVIX+O4H2TawaF/AEY 1FPLkDMH7gfDmE0XOp6pUjiKrrT2lWN0+KuFVr8WvEX3KRGDri2jBL42g4GAtVVfrbu6 xrdcHTDGAjUNxuwUwIXJIyKtaRlaIWv67E1a7T8+gbFZb6MxY7/oRZmpt1vB1HDlDxqx hDIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680024983; x=1682616983; 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=oNiZElylqd4oRsTQgc5WV3Ag1/Bvc2tTEOYDdozkUio=; b=qNXHH/V4G6j0hyqfCLN1zfFzheoINPfis+KN8qMeOxP1EQ4bjelsmd6aCgUS/TV1y0 MA6z8ieuu+ABdvE4m6Ms4nSL101vRt+NCN8b8rHLYz3kYGxQW9iI5GAuX7EDNve/YIKJ bcwAT5/W7fAWEhxmfc0TYufLxrah4OpZ8X6qa1PTmGtO84Pmq6kkIL9uCpzFkKauk+rm CGRAS0rsYtDa7m5yStoVDf49yN1jw3XyNpC0RwihGZYzkwU6cXMjWKG1CiVB2h4KdYcF pvEYmXhUqbiTzj39nDeAyly1IGrftJA73OpUTGFaSVKs0mIRaZLN7m8E3PH8QrKPFYg5 wjNw== X-Gm-Message-State: AO0yUKUgVBY4fENCQNITWfBrql7DFlu++E0dWa2x4iZLce0Z/+vWoTsK x8cbokriT1ygJh5+KjYoLQMomple1ctplUv4mW9TUA== X-Google-Smtp-Source: AK7set8b/NbFUGqeeN1a6ECQP6ujpIqXhcqKrzQyLA5JTrtvfc0SRc7JTHVcWrPu4CdwjU0GIwODEA== X-Received: by 2002:a05:6602:2f04:b0:758:9dcb:5d1a with SMTP id q4-20020a0566022f0400b007589dcb5d1amr11766606iow.2.1680024983235; Tue, 28 Mar 2023 10:36:23 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id p15-20020a056638216f00b00403089c2a1dsm9994115jak.108.2023.03.28.10.36.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 10:36:22 -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 7/8] iov_iter: convert import_single_range() to ITER_UBUF Date: Tue, 28 Mar 2023 11:36:12 -0600 Message-Id: <20230328173613.555192-8-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230328173613.555192-1-axboe@kernel.dk> References: <20230328173613.555192-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 274014e4eafe..fc82cc42ffe6 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -1866,9 +1866,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 Tue Mar 28 17:36:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13191418 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 69D13C761AF for ; Tue, 28 Mar 2023 17:36:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229946AbjC1Rge (ORCPT ); Tue, 28 Mar 2023 13:36:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229812AbjC1RgZ (ORCPT ); Tue, 28 Mar 2023 13:36:25 -0400 Received: from mail-il1-x131.google.com (mail-il1-x131.google.com [IPv6:2607:f8b0:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05348DBC9 for ; Tue, 28 Mar 2023 10:36:25 -0700 (PDT) Received: by mail-il1-x131.google.com with SMTP id r4so6715946ilt.8 for ; Tue, 28 Mar 2023 10:36:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1680024984; x=1682616984; 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=VRuLnY8LfItYmha1a1+5ihq4yOs2ex342r7sq+hJ1lo=; b=BI8hfl+CiitYpdnkPcVnUgegUqZlouG3QSCBfG9DFA0nNSGrunJY088Y1iE3b25nT8 vrYps9cKkGZc9dVYN+GTCs/40hnrVgSCtptGg+4QVef5zzI4re8ZU5KQQgbACpcaPXXE FZNppFiMKiOG3UBXL9e8OW9Qa1f1UP/9x0U84oI4S70SHdsyPqVZOKZvso3UCoGdDlJo YdnwoiHRVluIo97ZviBmPvWTTK32JnY5m5MY3sXdD5TgT8wAoIK6fHKqIjSGUZM3wcoT GNaCVkfUCNF+lpIYCax8MyxIixmMqnKOvzdmWcALQPYROM6Kr86/hCIfSNxOmnugWslc /w1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680024984; x=1682616984; 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=VRuLnY8LfItYmha1a1+5ihq4yOs2ex342r7sq+hJ1lo=; b=ZFxJqI7G//YWt1EZFckQyu6wScEe7bv+PDsv2tY5VeVpwiVNJajiG4tTcq3Vt7Eqbx frcUkL41uICue4VH1qON16rmy7qnUh+/bsHCYcH6qfN1GdCm+g4YJy7hT4XRykuPYBOH 8fEYXHiUH5yBcAp/94fDTsdCTJ+aCpIBlWG8U0gFHqgihdderMB+KhiuYNMoJZExoDRP hw3FmA65kCHblez17WmkSjP7JpQ3VOn6kp5S0tEZPB4dbfHdnVtgH7NgLtjg8wwnQ4jz H2fdKpgNOPrtwykVdTBRx8q26V+mqZHkzIhiMPRdfIhtHzIFys55qCbbHS5LC/8Tlbw8 BztA== X-Gm-Message-State: AAQBX9fkqPFAi7clVQIWV21njAdRalf09FTzxfR/tKQIgJbb5hWQVHbS kz4+5QNte45KR+tdjLmMbjWyRrD6QnOnMWMk4TkNSQ== X-Google-Smtp-Source: AKy350bivxXUnmoww1f+N8VP5Fwqw/aCwTds3RdSAT1ZEz5A5O7TFf5C8IQq36lwlB5lZn3UrOV5rg== X-Received: by 2002:a05:6e02:88c:b0:325:c88b:79b6 with SMTP id z12-20020a056e02088c00b00325c88b79b6mr8857121ils.2.1680024984093; Tue, 28 Mar 2023 10:36:24 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id p15-20020a056638216f00b00403089c2a1dsm9994115jak.108.2023.03.28.10.36.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 10:36:23 -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 8/8] iov_iter: import single vector iovecs as ITER_UBUF Date: Tue, 28 Mar 2023 11:36:13 -0600 Message-Id: <20230328173613.555192-9-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230328173613.555192-1-axboe@kernel.dk> References: <20230328173613.555192-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 fc82cc42ffe6..63cf9997bd50 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -1780,6 +1780,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) @@ -1788,6 +1812,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;