Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp1020380iol; Sun, 12 Jun 2022 04:07:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGMKVLNjWYXm5bv0g6sCfNiesbQuUcfNkCW7tzlBKKo9DCrLV4UNRqQAuUclZoAhdrqogw X-Received: by 2002:a17:90b:4d8a:b0:1e6:87ad:bfd3 with SMTP id oj10-20020a17090b4d8a00b001e687adbfd3mr9801870pjb.138.1655032035677; Sun, 12 Jun 2022 04:07:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655032035; cv=none; d=google.com; s=arc-20160816; b=J4r/N1iLkj86C2dOWzdj3onb9neWKl8NF3eTpl2jc9X0+rOa9xC9A6VO37mYsBaD7u 6ZogLP86ddeanV3nJ13hSnjnzlqqoMPYtYN1pQKW2JsXWK+r++q11q3u4rLOEDeftn3d rn0F+nBiwad1jGZ8/x4+l4/9fJl+UxpUhfNIkBDNYn6NOvPR0ti3NFJu13icwBF/g2s5 w7x+oA5AuMkILtVqmMYRONLgn8sGPO7UOd4jZ/vjep6GthzwmXrVDbxg9t+kYMiyI+Iv BuVThEcciU3ajZBiv8d99iv9cK8rzu7NkGDMdz9Q2IyuosvslVhbZcoJa3gay3Nxz+jd WKpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=BSwA4NeVgnxLtuLfBKKExOEIpE9041JXV4ItPWNPtss=; b=qM9/y5qeCC8ts6KOOTm6CzRdQtSty8N5mgKGxj0WPqrgsAWQ4pum/Eo1iLqFkaBt5S 4GyU4TCE3/TTiZw6WRhtT+MnXVCTqgpZKR9+xbud+Iq11CpHk3BVJTajVQ6rDqCK1o0T Ys3eGEiFsdXTFCnXW/7qUzqoImmTM+u+56Bc+Zr3/2BN1ZEYLKiUxp1+LbjDCOCPHVtP cLkOB8Guj2MqgIAWI6rOavOHxhh8zOfgxsW7Hqet4/Xat/bZL6u6ahKjhUHsHYi0qSnu z4W+idg1StwuRHpwbbO9dNzqAA69LtF3MIvp+572b1qaIDHcff/KZBLNFaXxYd3lBSzM JZ4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fastly.com header.s=google header.b="Phou/fv0"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fastly.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f5-20020a170902ce8500b00163e1c910dbsi7511751plg.13.2022.06.12.04.07.01; Sun, 12 Jun 2022 04:07:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@fastly.com header.s=google header.b="Phou/fv0"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fastly.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235326AbiFLJAx (ORCPT + 99 others); Sun, 12 Jun 2022 05:00:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235156AbiFLJAp (ORCPT ); Sun, 12 Jun 2022 05:00:45 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BC1751E50 for ; Sun, 12 Jun 2022 02:00:41 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id n185so1469706wmn.4 for ; Sun, 12 Jun 2022 02:00:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=BSwA4NeVgnxLtuLfBKKExOEIpE9041JXV4ItPWNPtss=; b=Phou/fv0D1wJ4Nk2pfva5TbGOkuRvzB5hCvplrKRFOl/E/aof+dvqIV0hEg7B8yWA2 boGSuUryK0hJY/CJr9pfeCKgO8aBpITFUNTkAfI2yfs4h8oPM5j7bbtdchgPKTxhphMi REgT3rfdCzXU5GZMDjqVC2Rut3LVv5IF5cjDs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=BSwA4NeVgnxLtuLfBKKExOEIpE9041JXV4ItPWNPtss=; b=yD0iMgxSRV8WQxFWVUwUe+yWZ1I/Glxn+vAtXBEXtGQWaGurb4Vh0GrYlbkBvlcdnY gOLRcSig7BtlBJzFtUhPVCOU9DFSbnJkRqmrDJzw8WpV3FOd7dqjNXEOLgSNTOEO/CRs EYvqx62nlBNQtnoo8syj7QCeqOva8BcExrtkQJ+MC7c3LX+LmL86vgFPYdJbHOOB9R39 jxJAX73FBoRSVnyTelUWMhufFuM7qs/wOWwlGz/xXcJUjvOdF4PPfznqTHKS6g0+b0Jl 6yuAnswHCgsMk5xfXNbWM/li6wDuheJGhNOuH8EONWog0/qxV0BV5X8FgChvuQw7MB08 lQ9g== X-Gm-Message-State: AOAM530b1FxWU6DzhukJwZTFfjfaQC8VSG9Rtdd0qW5FNW2ZRijrSUz7 S76JaAL+3XjXzS7iw4Yqp5xAOw== X-Received: by 2002:a05:600c:358f:b0:39c:7fe7:cbe2 with SMTP id p15-20020a05600c358f00b0039c7fe7cbe2mr8463834wmq.46.1655024439801; Sun, 12 Jun 2022 02:00:39 -0700 (PDT) Received: from localhost.localdomain ([178.130.153.185]) by smtp.gmail.com with ESMTPSA id d34-20020a05600c4c2200b0039c5b4ab1b0sm4798603wmp.48.2022.06.12.02.00.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Jun 2022 02:00:38 -0700 (PDT) From: Joe Damato To: Alexander Viro , linux-kernel@vger.kernel.org Cc: Joe Damato Subject: [RFC,iov_iter v2 3/8] iov_iter: add copyin_iovec helper Date: Sun, 12 Jun 2022 01:57:52 -0700 Message-Id: <1655024280-23827-4-git-send-email-jdamato@fastly.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1655024280-23827-1-git-send-email-jdamato@fastly.com> References: <1655024280-23827-1-git-send-email-jdamato@fastly.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org copyin_iovec is a helper which wraps copyin and selects the right copy method based on the iter_copy_type. Signed-off-by: Joe Damato --- lib/iov_iter.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/iov_iter.c b/lib/iov_iter.c index d32d7e5..6720cb2 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -168,6 +168,15 @@ static int copyin(void *to, const void __user *from, size_t n) return n; } +static int copyin_iovec(void *to, const void __user *from, size_t n, + struct iov_iter *i) +{ + if (unlikely(iov_iter_copy_is_nt(i))) + return __copy_from_user_nocache(to, from, n); + else + return copyin(to, from, n); +} + static size_t copy_page_to_iter_iovec(struct page *page, size_t offset, size_t bytes, struct iov_iter *i) { @@ -278,7 +287,7 @@ static size_t copy_page_from_iter_iovec(struct page *page, size_t offset, size_t to = kaddr + offset; /* first chunk, usually the only one */ - left = copyin(to, buf, copy); + left = copyin_iovec(to, buf, copy, i); copy -= left; skip += copy; to += copy; @@ -288,7 +297,7 @@ static size_t copy_page_from_iter_iovec(struct page *page, size_t offset, size_t iov++; buf = iov->iov_base; copy = min(bytes, iov->iov_len); - left = copyin(to, buf, copy); + left = copyin_iovec(to, buf, copy, i); copy -= left; skip = copy; to += copy; @@ -307,7 +316,7 @@ static size_t copy_page_from_iter_iovec(struct page *page, size_t offset, size_t kaddr = kmap(page); to = kaddr + offset; - left = copyin(to, buf, copy); + left = copyin_iovec(to, buf, copy, i); copy -= left; skip += copy; to += copy; @@ -316,7 +325,7 @@ static size_t copy_page_from_iter_iovec(struct page *page, size_t offset, size_t iov++; buf = iov->iov_base; copy = min(bytes, iov->iov_len); - left = copyin(to, buf, copy); + left = copyin_iovec(to, buf, copy, i); copy -= left; skip = copy; to += copy; @@ -766,7 +775,7 @@ size_t _copy_from_iter(void *addr, size_t bytes, struct iov_iter *i) if (iter_is_iovec(i)) might_fault(); iterate_and_advance(i, bytes, base, len, off, - copyin(addr + off, base, len), + copyin_iovec(addr + off, base, len, i), memcpy(addr + off, base, len) ) -- 2.7.4