From patchwork Mon Mar 27 18:04: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: 13189802 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 F02B8C76195 for ; Mon, 27 Mar 2023 18:04:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230361AbjC0SE5 (ORCPT ); Mon, 27 Mar 2023 14:04:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229829AbjC0SE4 (ORCPT ); Mon, 27 Mar 2023 14:04:56 -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 440DC268A for ; Mon, 27 Mar 2023 11:04:56 -0700 (PDT) Received: by mail-io1-xd29.google.com with SMTP id ca18e2360f4ac-7585535bd79so5157639f.0 for ; Mon, 27 Mar 2023 11:04:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1679940295; 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=rPiNKiOlYrgP6omvQGmrOl81AEJmBJkx0lTBPz4b7B0=; b=2FAs0UHa5PbdBxQkOdD37QEeRqtQyUfu3yBnEySkLNPSeSmPke7p6FDAf/AMWMI3Vo WnChdq0LErNLgIqJAsuJN/2KLOKHJyhK/mJCrgkHHYKjALXDsRKmELMmYD0nITJ6l2Sz eN8IbSYeg67fLZunqCf+etMec2ts0RLI4dEt2wzYHm4I4i8J09ELNSGX/CPS337i4ept 4GwBCguGd9kEXuobIcyGNk5RTd82nwIznFkOG8ZBNq0J5aLkuu3f7/hSrfQ6y9r9z4mD 84TSy0VI0UwoAgU/3vE22BELQ6iFnczUG0mvRS5F5bbdFEh7pzfhuw6nLiq0BeS6Iaca DtpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679940295; 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=rPiNKiOlYrgP6omvQGmrOl81AEJmBJkx0lTBPz4b7B0=; b=TWwfYH0Tc5XEsDgQcOUaQlylDrPycjcVkaegKimBd7O6GJrE54gOZ9nNfvWp9Yt1q7 OLtryAqZyEFCDnsHSQTvC/YDfJmEDU8nJjsVl7/c26AkelNMZAxYm+tgQXD+wE9Xo7bR o6GcwTSBX/o828jPafxxEqINgFfz/+wlgnOuPFLVG8XGelyDwyL9CUVtpMJ1d3OmyqQy HqOxFqMm2HNbxIuXtivUMaNbeIhPwxnnw13Fov8AI61tQnmIVVk7SUIaaMd9MlIVC12T Zm0hHP01zgn9xZNLgPj3tk6MCczFZPYzP4Zwnfxq9g4zbtnIfF1ywX1h2VNvyBTkG0S+ Mf0Q== X-Gm-Message-State: AO0yUKW/GaEd5iw3ht8kiXzNMbpOQdKqpMkOa4EnKQ9PzqOuOCRPzyVG ZIq0OJwtNCJ/AXOD8QO/kHwHDRzCxnPvislJVTxKZw== X-Google-Smtp-Source: AK7set9NlcEs/CUNvUhV04SXXajqAMjZurHOQLts04ilQGgM3ySXuM0RG7vcUd+qqQu8kLDOd5iy/g== X-Received: by 2002:a05:6602:2d87:b0:759:485:41d with SMTP id k7-20020a0566022d8700b007590485041dmr7342874iow.0.1679940295300; Mon, 27 Mar 2023 11:04:55 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id e28-20020a0566380cdc00b0040634c51861sm8853235jak.132.2023.03.27.11.04.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 11:04:54 -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/4] fs: make do_loop_readv_writev() deal with ITER_UBUF Date: Mon, 27 Mar 2023 12:04:46 -0600 Message-Id: <20230327180449.87382-2-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230327180449.87382-1-axboe@kernel.dk> References: <20230327180449.87382-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org We caller this helper if we don't have a read_iter/write_iter available, and it will go over the iov_iter manually copying data in/out as needed. But it's currently assuming it's being passed an ITER_IOVEC. Enable use of ITER_UBUF with this helper as well, in preparation for importing single segment iovecs as ITER_UBUF. Signed-off-by: Jens Axboe --- fs/read_write.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/fs/read_write.c b/fs/read_write.c index 7a2ff6157eda..de9ce948d11a 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -748,10 +748,21 @@ static ssize_t do_loop_readv_writev(struct file *filp, struct iov_iter *iter, if (flags & ~RWF_HIPRI) return -EOPNOTSUPP; + if (WARN_ON_ONCE(iter->iter_type != ITER_IOVEC && + iter->iter_type != ITER_UBUF)) + return -EINVAL; + while (iov_iter_count(iter)) { - struct iovec iovec = iov_iter_iovec(iter); + struct iovec iovec; ssize_t nr; + if (iter_is_ubuf(iter)) { + iovec.iov_base = iter->ubuf + iter->iov_offset; + iovec.iov_len = iov_iter_count(iter); + } else { + iovec = iov_iter_iovec(iter); + } + if (type == READ) { nr = filp->f_op->read(filp, iovec.iov_base, iovec.iov_len, ppos); From patchwork Mon Mar 27 18:04: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: 13189803 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 7F682C76195 for ; Mon, 27 Mar 2023 18:05:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232439AbjC0SFD (ORCPT ); Mon, 27 Mar 2023 14:05:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230309AbjC0SE5 (ORCPT ); Mon, 27 Mar 2023 14:04:57 -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 19A9F2D60 for ; Mon, 27 Mar 2023 11:04:57 -0700 (PDT) Received: by mail-io1-xd29.google.com with SMTP id p17so4239968ioj.10 for ; Mon, 27 Mar 2023 11:04:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1679940296; x=1682532296; 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=zFM2a+ZzYXSxFvSgVUFtAECG7wgpfdxpPdXdbVNH0aY=; b=Op5McrhWUmqPfmlzUd/fkuZH2T8PHSJMThHTbKtxyoS1VPgAR537V3XFCiA+rYU/Ko tb4vxMidldiPki+Ziovlm4DEfjPofT5uaGt6ETAx3aHiNPJRc+KjtfKW25Nd6RURtdWd EIyeCyQbCKiQq2clKCfQDuIa+xd0CrPNXjulx3cHuuk/WySKjv+Hh4oTuBiJ9dm8C7B4 CitREeBdHLwvwjV/e/Z6WePhKObzs2UHxJjlbwqSGI8orQjQ7ca2Q4dpLs5msJMqo1OA shg4XnqIEGFTDfaooYShsJQmalrlUUp2UMGzrz0bAv3E6JClcHT3VAR35RQ3bjxib2Hy VRSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679940296; x=1682532296; 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=zFM2a+ZzYXSxFvSgVUFtAECG7wgpfdxpPdXdbVNH0aY=; b=ImoILDQyaiKGAIe2SZnMW559kIJSe+w/edwoLQ2EGEHRxSCYP8vQyp0r8pa4lUwj9I ohJ50sxyUeOpLrMceH8cFU0smjiSUdraizEEUVWh7Nrw2Q314HHZV8chs0qVA901L3o9 MzD+ETquPFQrGVx15MwvaLr8pV6dRi8vXF1QKEH0Vrggj5gR4BKeivi7pc0Oufb+Zw0j VikIEI2yqbZNMUGnYb07ujO+AN6C3vu06jl+cVCnLSZgd4WBo+3d3rmiFZMOascy8w5u h+YP0FoR/M8LL8QhBi86NDPun6gv2PuVvu9JpCYFCsbcBQ4WaAfwZGJ6kHjcGdx9sPdr jU9g== X-Gm-Message-State: AO0yUKW/03atpsSrnQ7fCwaSRG2DikAqjlT6pHFMFHNU8sV4Sdogk5ID JFX19yGbJMzsBEkDwwnjiwjcSdW/fTQXp3RAYmUTvA== X-Google-Smtp-Source: AK7set8T4r9lWuPxghF9ysmw/Rbpm2zoIC1qC9C86F1Of9w7080HBGaWgpck6FlWDd3/5EThK1t89w== X-Received: by 2002:a05:6602:2dcf:b0:758:6517:c621 with SMTP id l15-20020a0566022dcf00b007586517c621mr10171718iow.2.1679940296137; Mon, 27 Mar 2023 11:04:56 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id e28-20020a0566380cdc00b0040634c51861sm8853235jak.132.2023.03.27.11.04.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 11:04:55 -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/4] mm: make process_madvise() deal with ITER_UBUF Date: Mon, 27 Mar 2023 12:04:47 -0600 Message-Id: <20230327180449.87382-3-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230327180449.87382-1-axboe@kernel.dk> References: <20230327180449.87382-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org In preparation for having single segment iovec imports be transformed into ITER_UBUF, ensure that process_madvise() deals with those correctly when iterating the iov_iter. Signed-off-by: Jens Axboe --- mm/madvise.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mm/madvise.c b/mm/madvise.c index 340125d08c03..2bd0f6c067bb 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -1503,7 +1503,12 @@ 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); + if (iter_is_ubuf(&iter)) { + iovec.iov_base = iter.ubuf + iter.iov_offset; + iovec.iov_len = iov_iter_count(&iter); + } else { + iovec = iov_iter_iovec(&iter); + } ret = do_madvise(mm, (unsigned long)iovec.iov_base, iovec.iov_len, behavior); if (ret < 0) From patchwork Mon Mar 27 18:04: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: 13189804 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 94CF8C6FD1D for ; Mon, 27 Mar 2023 18:05:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232429AbjC0SFE (ORCPT ); Mon, 27 Mar 2023 14:05:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229829AbjC0SE6 (ORCPT ); Mon, 27 Mar 2023 14:04:58 -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 271EB3A81 for ; Mon, 27 Mar 2023 11:04:58 -0700 (PDT) Received: by mail-io1-xd31.google.com with SMTP id ca18e2360f4ac-752fe6c6d5fso5196939f.1 for ; Mon, 27 Mar 2023 11:04:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1679940297; 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=3EjGDt5/YbxFXYxnvhi7Sb3qTRKFQWxan3eGqdFzFwvjVRhSQCUim7vOVia6mKtAjd bB2vAUiuTmDg88jukpFFKOhOf381yB+jdqEIaEAjCOa9BIhuSI6tfu6XMXOgDIFFW+lo BhLxM4R0T4JwxYl3eSI+Nt0AT+feun3lGJlcuBrAV3m9Ic3HLE2VBO75LlUi5LIx4uau 5Q/dRKx2EHICHPwjSmaJjV7QLkk7isw9pSsr9vzWgoJRZ3QThXMK/Fz0338HcWGCK0jW OWVChrzYa2qhneTK2LBxyQlUu4Tn7u1W1INcdaG/iMHUPQrbwnoXP76JSszA1SoPrPFD MyJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679940297; 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=dpDYHh1bMNaPzhBGzM1KDHivSwCmtUhqqo1c1juSJeuWwbFhHMP5tRCIsMc4YGyaT1 z0rWEw1ktrkgI8Qam89F1aA2gx0j0RBaOlA089Mg8o5X0NEa0gcAHfWTv+m3oo4GZX6W sVD0sWADzkpyd3hyPzc/sB+kG7A27cpuU2Y9xUxBLPUlgh4nG23dagPyiGyOC6kVwaiD 3JNmBdZIp+HmU0bZAhq+7JP/bK3AG1x3qeXC7pY7ngnE1SRZV4AW5exMo+qN002ta7Sc bzfghgLXZxz3P+tPnwqbuBRe6vEl83myoONoTBSct1qwBEsn7ZYw04UHpSVnHDx6cwEV 2NZg== X-Gm-Message-State: AAQBX9e+DZy4OOohJ5XV2YhKGHSwUF4U/qWC7cO01duNN/v4WLeIKRCe koR4C6UJJLZ6GhFQhwS6Vy7YwhbRrOXfQbw/tjbTtA== X-Google-Smtp-Source: AKy350aQJmrR+de0MRoP9/0Z2RHP0l/2slVlUluaT0k+KFu9KsOl1biHEGzFLNH9eilmnJ70zDXboQ== X-Received: by 2002:a92:6701:0:b0:318:8674:be8 with SMTP id b1-20020a926701000000b0031886740be8mr5240414ilc.2.1679940297156; Mon, 27 Mar 2023 11:04:57 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id e28-20020a0566380cdc00b0040634c51861sm8853235jak.132.2023.03.27.11.04.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 11:04:56 -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/4] iov_iter: convert import_single_range() to ITER_UBUF Date: Mon, 27 Mar 2023 12:04:48 -0600 Message-Id: <20230327180449.87382-4-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230327180449.87382-1-axboe@kernel.dk> References: <20230327180449.87382-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 Mon Mar 27 18:04: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: 13189805 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 E022AC761A6 for ; Mon, 27 Mar 2023 18:05:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232446AbjC0SFF (ORCPT ); Mon, 27 Mar 2023 14:05:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231990AbjC0SE7 (ORCPT ); Mon, 27 Mar 2023 14:04:59 -0400 Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 050103AAC for ; Mon, 27 Mar 2023 11:04:59 -0700 (PDT) Received: by mail-io1-xd32.google.com with SMTP id ca18e2360f4ac-752fe6c6d5fso5197139f.1 for ; Mon, 27 Mar 2023 11:04:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1679940298; 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=c53GxGsaME1PuxlxsP1Vkgso5etFHpCP8C3QispDf2mjuqP0jv2NRJvHlsmpgTT8yr qMd8w8M2rdWb4vo//MSvfGx2Q3qfXywpzUj7PdSHJF2rNW1oN0jgIZ80s29Jby2IZtwK itw+wc/ET9ZgwOG8FTSLS3J7WFZqW9T9AVPvajCFVqN8lltH9N1u/2GPGsYo0uiJR9FF Tk1w9TZHP3sqORGFlmdLiVb5wb2Zh0fvsloFEhETrN/iOXJJDGCFtmBioAQh1Yde+tu1 QtFI8waLbjQlcFVemgtprDChu4E9Uh6Sxd/9c2EPYcUmhFNp3dGKgiN54CdOKy9oe7e6 XN8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679940298; 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=drLGTtI2TCR2RrjLvL7q0HzQEKa/G/ROgixYVxJPmU/xFROt7rdOzS/ZUevSwRmCHv 5ecTFxJbpxhqjIyUhjYZERaJXkUd7MtZXir/JP0SediYYTtCS2ak2aus/YO3fU4+oF68 HWnsAIfoqezqZN5oW1N6jDcOcPdmBJS6qZbDIQKpSaKF7nmOOGpTrTYbFt2A81XgbACm /9hPe8W1pwQbbvPze/Typ1vdo0LRT6mB2XD0pAxlKpY3Z4Zuzh6lmHan+nVtIGhFZqZc ioLjR+sY6enfqs6ZxszB//L4ASsVKHOrK9ZHsD44iuspSSdZ27Ko7uUKpJceKZkvG1CC UfUg== X-Gm-Message-State: AO0yUKUtvGNvDh09zNfs/jN3gdb3Iyj8pcza5j2RIuptIhw/YdgQ6jO0 1CK4QrcRN3MGCX2IL8O5vrWDgDrx3mUhB2FCO5dk5g== X-Google-Smtp-Source: AK7set/RwkNZtja9qv8eRxy3SfWj5mxh8eSuD7R/eplf4EodBLpNHsTFWpSUcfl3XbHWQpv0mHIS3g== X-Received: by 2002:a05:6602:2d87:b0:759:485:41d with SMTP id k7-20020a0566022d8700b007590485041dmr7343013iow.0.1679940298064; Mon, 27 Mar 2023 11:04:58 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id e28-20020a0566380cdc00b0040634c51861sm8853235jak.132.2023.03.27.11.04.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 11:04:57 -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/4] iov_iter: import single vector iovecs as ITER_UBUF Date: Mon, 27 Mar 2023 12:04:49 -0600 Message-Id: <20230327180449.87382-5-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230327180449.87382-1-axboe@kernel.dk> References: <20230327180449.87382-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;