Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1572981rdh; Mon, 25 Sep 2023 18:02:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGacd2CdrWuUA4wBcY2zPph33WJoDxDku97psXWZJeoCRCWVRpUDTNNyxakeinC2hUQLy5x X-Received: by 2002:a05:6358:3388:b0:12b:da97:aba6 with SMTP id i8-20020a056358338800b0012bda97aba6mr10665098rwd.24.1695690165763; Mon, 25 Sep 2023 18:02:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695690165; cv=none; d=google.com; s=arc-20160816; b=uNBE0E4HnoQt2laE99ZhWw7QgrDNa6Ufdv0MKNO5gHhJe2HS/DxBb3bbD+hvnHtNSK P4TVvENlWA+7yc6wq8NhX0mSWN10ZuPuipuc6NHy0AxmPMqhXOxN316/0p5ETro9SZ07 p6p24DoGwUC41EaD4AbqJDfiFLOD4h3vJMcRYvEPfZUm5cfUIPf+2r43Cp4F14flL9TE mL+YEqrTEjLL53X6CjWISUvuG3UgtX1ZVISMOqhmlrUTcg0tGn1NLX99/1xpIYQLfSXX GalrED8GHrnhp7NROLr8mLqQGMyNeztez62J9/VlfwbWGIn3Ym2j2A1pFn8zFZ9i6I6o 9QTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ENB7CtH73xnlPC5Szfr84FelPyw0n3TXhDinmckBTOE=; fh=dzqEI/am1IoNVOMZmTOChre3TckBGjOgtLT35fkBuy0=; b=RjlueKbC059UVJLeSahY7cpdkUEx7t47GXZWtu8LbBZvTLt1tl7+STPHnvDTjL1fxX FY1kn+cB82puKcIMWYAqpRe7QloNjsFqtWXzZYcyU+RgrsysjPWZh2hgaoXT5m2gwLfs vC//6R6GC8xa4LRtaPpneUok0Cg3Z68SOOTeoSctRUeX4HJ/YdHDYQVh9k5Wtc1jwPHU JnZWm7/VmpjFDN9O4QbiZFXPs9oV7nXrya/Y6sM+HcK9FOrJWzw+6sMtBnlbN+azHMoj X4dPdqsMKNmVIQnjhL2Kl3VJAWnyieliYi1QU9FISrjvLO52dL5weERLYsRrH9Xgoe/b Igvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MQDZRni0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id r15-20020a632b0f000000b00578ea9a0b97si10873553pgr.539.2023.09.25.18.02.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 18:02:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MQDZRni0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id C70F7829F66D; Mon, 25 Sep 2023 05:06:37 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231596AbjIYMGR (ORCPT + 99 others); Mon, 25 Sep 2023 08:06:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231695AbjIYMFl (ORCPT ); Mon, 25 Sep 2023 08:05:41 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB57D193 for ; Mon, 25 Sep 2023 05:03:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695643423; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ENB7CtH73xnlPC5Szfr84FelPyw0n3TXhDinmckBTOE=; b=MQDZRni0zVeAJJvJg8/g2xMtvD/+lErL5uUErWa6h6RYqbI2OnsG435lCHUFVE7wAyP87O 3S97JPIwq47KobeSOmHsk5d2dcXIlXK5X8DexWLPYnhTbhW6uL0nIum0RTT0gt3W4cAbwX bIwKOWwoab6/ACPWdNErLF+1KO5xMjo= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-638-Tspro7EYNxWz9xyR8d5l5A-1; Mon, 25 Sep 2023 08:03:38 -0400 X-MC-Unique: Tspro7EYNxWz9xyR8d5l5A-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 07FBD3C1E9D8; Mon, 25 Sep 2023 12:03:38 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 609BB14171B6; Mon, 25 Sep 2023 12:03:36 +0000 (UTC) From: David Howells To: Jens Axboe Cc: David Howells , Al Viro , Linus Torvalds , Christoph Hellwig , Christian Brauner , David Laight , Matthew Wilcox , Jeff Layton , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 08/12] iov_iter: Don't deal with iter->copy_mc in memcpy_from_iter_mc() Date: Mon, 25 Sep 2023 13:03:05 +0100 Message-ID: <20230925120309.1731676-9-dhowells@redhat.com> In-Reply-To: <20230925120309.1731676-1-dhowells@redhat.com> References: <20230925120309.1731676-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Spam-Status: No, score=1.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,RCVD_IN_SBL_CSS,SPF_HELO_NONE, SPF_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 25 Sep 2023 05:06:38 -0700 (PDT) iter->copy_mc is only used with a bvec iterator and only by dump_emit_page() in fs/coredump.c so rather than handle this in memcpy_from_iter_mc() where it is checked repeatedly by _copy_from_iter() and copy_page_from_iter_atomic(), Signed-off-by: David Howells cc: Alexander Viro cc: Jens Axboe cc: Christoph Hellwig cc: Christian Brauner cc: Matthew Wilcox cc: Linus Torvalds cc: David Laight cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org --- lib/iov_iter.c | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/lib/iov_iter.c b/lib/iov_iter.c index 65374ee91ecd..943aa3cfd7b3 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -253,14 +253,33 @@ size_t _copy_mc_to_iter(const void *addr, size_t bytes, struct iov_iter *i) EXPORT_SYMBOL_GPL(_copy_mc_to_iter); #endif /* CONFIG_ARCH_HAS_COPY_MC */ -static size_t memcpy_from_iter_mc(void *iter_from, size_t progress, - size_t len, void *to, void *priv2) +static __always_inline +size_t memcpy_from_iter_mc(void *iter_from, size_t progress, + size_t len, void *to, void *priv2) +{ + return copy_mc_to_kernel(to + progress, iter_from, len); +} + +static size_t __copy_from_iter_mc(void *addr, size_t bytes, struct iov_iter *i) { - struct iov_iter *iter = priv2; + size_t progress; - if (iov_iter_is_copy_mc(iter)) - return copy_mc_to_kernel(to + progress, iter_from, len); - return memcpy_from_iter(iter_from, progress, len, to, priv2); + if (unlikely(i->count < bytes)) + bytes = i->count; + if (unlikely(!bytes)) + return 0; + progress = iterate_bvec(i, bytes, addr, NULL, memcpy_from_iter_mc); + i->count -= progress; + return progress; +} + +static __always_inline +size_t __copy_from_iter(void *addr, size_t bytes, struct iov_iter *i) +{ + if (unlikely(iov_iter_is_copy_mc(i))) + return __copy_from_iter_mc(addr, bytes, i); + return iterate_and_advance(i, bytes, addr, + copy_from_user_iter, memcpy_from_iter); } size_t _copy_from_iter(void *addr, size_t bytes, struct iov_iter *i) @@ -270,9 +289,7 @@ size_t _copy_from_iter(void *addr, size_t bytes, struct iov_iter *i) if (user_backed_iter(i)) might_fault(); - return iterate_and_advance2(i, bytes, addr, i, - copy_from_user_iter, - memcpy_from_iter_mc); + return __copy_from_iter(addr, bytes, i); } EXPORT_SYMBOL(_copy_from_iter); @@ -493,9 +510,7 @@ size_t copy_page_from_iter_atomic(struct page *page, size_t offset, } p = kmap_atomic(page) + offset; - n = iterate_and_advance2(i, n, p, i, - copy_from_user_iter, - memcpy_from_iter_mc); + __copy_from_iter(p, n, i); kunmap_atomic(p); copied += n; offset += n;