From patchwork Mon Mar 27 23:27: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: 13190234 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 7D7B0C761A6 for ; Mon, 27 Mar 2023 23:27:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230514AbjC0X1j (ORCPT ); Mon, 27 Mar 2023 19:27:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230220AbjC0X1c (ORCPT ); Mon, 27 Mar 2023 19:27:32 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16E3B2723 for ; Mon, 27 Mar 2023 16:27:26 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id lr16-20020a17090b4b9000b0023f187954acso10695850pjb.2 for ; Mon, 27 Mar 2023 16:27:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1679959645; x=1682551645; 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=oudBH5W1YN7luLtpSU6havksFDdCltkYkitZ66kKZEwqtJauy6VPvCVeuVpvEurLEv s29FljZyUQJ7lWExCkoDNsRFq3+yBwse8uHXRlxNGbk2IuKmtAiItlA5FFTkBvBYrXCY CtGv1lNIrGpgZ91fxxvFQ+Vbzd2cSjqiqmAOTdPWZVbPBV4lVNUVsC1DHGf7puqRUFoO BJFeChHwj1Bzgrbg4wXhMngsCRL7beXhjWd0utPtemMXTQGGYIVaPtGBsf9p7JVIve6q xLTOKEeZZISK7n21wTpVI4vM5BJYPJGTM09Pw5Uf2OH/NgxISY8uNwxmeFd8ixpzNH4i M8tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679959645; x=1682551645; 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=k4GMfVdY2rmFKtxwFnEiONRgreLeOFGOrBIfi+r5vsDOQu5CA46WGBNjmR8f/gkGzR OugwmNGYEv1oGL2jmJ99cJz6s/fiIVO/Qa75nrNRwU4evtCQfWdietkl49GhQIX9+1gv R5dcqlWtMCfLOww107VtMVDr+Qz8IBJdMps/VDvD0LZEUGdEbBZhta6uy5cSjue9McO/ Jzoyv/pW8mpo11cxZmEWw0oFpMihYqlo1l11LYg9K+gCxg4Bd6DoeRcEbRsgyVTvB7dQ mgTojbGnySvfaPKhBRRDKB6NCvQwqPgYRu5ZX8RBnybR4/kkS8uYQ4yqLZT1K7qiyeZu AO2A== X-Gm-Message-State: AAQBX9fpLdBX8Ov3w7eYr9rovmnBHEPJSDNgbJmM1Y2+2icC0eDRF3LS g0E52gV8bfejmHAjQd7j/6qnWYMEXlu6PwmGjoFXCA== X-Google-Smtp-Source: AKy350ZZlUS/vQzXVfCu/6DG10e1c/E30kpBAbfbpaB5nPmBlRHTZQK7hLQUYFl+pUCRhkTaGyTc4g== X-Received: by 2002:a17:902:b607:b0:1a2:6092:2193 with SMTP id b7-20020a170902b60700b001a260922193mr562802pls.4.1679959645229; Mon, 27 Mar 2023 16:27:25 -0700 (PDT) Received: from localhost.localdomain ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id s14-20020a170902b18e00b001a1ccb37847sm15534222plr.146.2023.03.27.16.27.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 16:27:24 -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/3] iov_iter: teach iov_iter_iovec() to deal with ITER_UBUF Date: Mon, 27 Mar 2023 17:27:11 -0600 Message-Id: <20230327232713.313974-2-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230327232713.313974-1-axboe@kernel.dk> References: <20230327232713.313974-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 Mon Mar 27 23:27: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: 13190235 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 4A70CC6FD1D for ; Mon, 27 Mar 2023 23:27:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230288AbjC0X1p (ORCPT ); Mon, 27 Mar 2023 19:27:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230273AbjC0X1h (ORCPT ); Mon, 27 Mar 2023 19:27:37 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BB7E2D4E for ; Mon, 27 Mar 2023 16:27:27 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id p3-20020a17090a74c300b0023f69bc7a68so10678087pjl.4 for ; Mon, 27 Mar 2023 16:27:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1679959646; x=1682551646; 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=IajKLrMCXCjOZDwYufESbCKzfN53bE1qXlW3mAtwzWljdMtwRNMjPIkIMXMXItNH6r akEIBdQUNDvnIeQxVtxGvrZNVzEHKjSZLObDzxwGFILMaROEPn1w9bxYevtNn4CeAM7h Cte8OXuRU/hf7cmQxs1mLz+Y4MpoZLerSoLKlTtXPQOAbCwpD7KFFOpJamb9e6VWVYou wUYrdwpW1l4AP+jksxsnlnJBiCQY8CqaJd11f6UrXteXEDzg0c9glWP3o/j4afRx8Ncd xLlYU7XYIJ/fgW+LwTcKdA3IWPU86kZjegW043uFr+kbNo2LD1RZSveOf9gSPVTy6KFM arEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679959646; x=1682551646; 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=NDC5Ui+QiKfvWhbQh52bimXTuXHfAp+TMXDCxQzMBsd1c5LI+aPM9AVQ/mHjeoxMJx 4xK09aXQejUx0TzL+mPsu6ltzgs5oOoLwA8MfkJSMAbz69Vnu2Yd9gvmKnpb20SQaK3b UQx6XWpUGIoa5XgR6LczzgF4XCKCD5pGoJtamzJOmF/dwWuXBetf3cARI2ce90ithPYx 7qlSDV02mVYPTUlqddNDmuYVHihjUnD7X88V0noB+wixpJyr+t31ATv665cUOn9IVOFJ wmeLiDfX7sLcssdBbQaM+M2OFcTcRj1TyybtQhyCIGBdV6mabmbKu7BsqFokBhPDo0vb P9LQ== X-Gm-Message-State: AAQBX9cW7wF/jLHndVmxtdWpWyELSJuNuzndKMlDuayRUa+pCScmp900 zM1+LZJG36r6fFM092WyA4HY7xi9qy5N3NHBb1ZX5w== X-Google-Smtp-Source: AKy350bIVuvrrc+yJODeBmexe/uN1gyoPZzM/3KsQCh0w6lJ4Jh1Jl0uRDUKlk2TcjOyEQcZaSWkgA== X-Received: by 2002:a17:90a:644b:b0:233:b57f:23c5 with SMTP id y11-20020a17090a644b00b00233b57f23c5mr11511967pjm.2.1679959646443; Mon, 27 Mar 2023 16:27:26 -0700 (PDT) Received: from localhost.localdomain ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id s14-20020a170902b18e00b001a1ccb37847sm15534222plr.146.2023.03.27.16.27.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 16:27:25 -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/3] iov_iter: convert import_single_range() to ITER_UBUF Date: Mon, 27 Mar 2023 17:27:12 -0600 Message-Id: <20230327232713.313974-3-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230327232713.313974-1-axboe@kernel.dk> References: <20230327232713.313974-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 23:27: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: 13190236 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 B17B6C76195 for ; Mon, 27 Mar 2023 23:27:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229985AbjC0X1q (ORCPT ); Mon, 27 Mar 2023 19:27:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230201AbjC0X1h (ORCPT ); Mon, 27 Mar 2023 19:27:37 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45B2B2D65 for ; Mon, 27 Mar 2023 16:27:28 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id le6so9966385plb.12 for ; Mon, 27 Mar 2023 16:27:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1679959647; 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=5YvhmYqFwE45/+fdIM6T0939zWYyiLrCUChhI1VxTnIXZgu/pY/DphMdHT8GDb2P/m Ifn/+I5Mvx9by3buCvH50D6DMfhJ6hCU7vnakXKXXs80hLsOnmapofA6KriW4MHi2Jsg C0UL+NH6GXdfOHP4CmusKWtZh1jKZrokS+qohYivmdUuDeIWv1uVCiJ179Gk4QcRdJeo HsCeq9ZMgk57P6/yTpOku9ptCjmHygwTZPbUBONzxGPGx27FSUqrltXqU7A3eguYqtVM 67Scguz7uobyMNlDbyV+1u9QI6LrNCACs4lCS5Flhz9NIBPm2jTMaaHPeg87HLhJKNSJ vWlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679959647; 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=IwJtiDOkWCm4f/AoqY4hQWpadQ69b0tqWhQngf7FvekFCq76wtokEXZbPQMrJ6CAGk jo+hT4RUD374H63rmNvFAMeqvLDW3ilvx5O96fJbaCroTFvSnrRh2NSofNytobE0ytCC TaR392OejvGI0OLtcbm0zw0meth4ycJvnqFxQCiVB76Y1U+fhs9zsjVEvs9ixuKyV6VD hnW76j3od3y6Vl1z4uaBliFW0bGKNn5ycgPamqOfNut5dgYt14TH6Iigdw1T6FVvhyit fgXW0J5Iu/DeApnsJa6jxDLSbyK4ettpUvEBIgUSmYpAx2BfEhxLbewI+wvfGEECWqnn nOTA== X-Gm-Message-State: AAQBX9cLw2QyPmgTE3WGrNLA0X6Qh0ER0+yKAoM5Hh5F5ej6O4ivGph8 u3ZnBpZy+hfFZ/geA/BCR1T7fRhUtVcglgmuCwUxGg== X-Google-Smtp-Source: AKy350ZFClyDoyTKZ5x8f1bNy3rhtURN/DSsvCZ5i5mqgZ7TwDVVYbVTW+kFYyZTnw8vXcNu10UTOg== X-Received: by 2002:a17:903:2844:b0:19a:7060:948 with SMTP id kq4-20020a170903284400b0019a70600948mr12044587plb.1.1679959647431; Mon, 27 Mar 2023 16:27:27 -0700 (PDT) Received: from localhost.localdomain ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id s14-20020a170902b18e00b001a1ccb37847sm15534222plr.146.2023.03.27.16.27.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 16:27:27 -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/3] iov_iter: import single vector iovecs as ITER_UBUF Date: Mon, 27 Mar 2023 17:27:13 -0600 Message-Id: <20230327232713.313974-4-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230327232713.313974-1-axboe@kernel.dk> References: <20230327232713.313974-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;