Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2012508rdb; Thu, 21 Sep 2023 06:22:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHl7WsMltr+T/br+qr6rodkscGo0YxzkjZgV5Z6jJtcUcAtkTdDuGiixi7EkLkXcztZKgsz X-Received: by 2002:a05:6e02:4c9:b0:350:f0bb:6a39 with SMTP id f9-20020a056e0204c900b00350f0bb6a39mr5221740ils.10.1695302567907; Thu, 21 Sep 2023 06:22:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695302567; cv=none; d=google.com; s=arc-20160816; b=lMaK7ta/XxnDFynO0npbazOIGxHtSXqwM//Je9rFRe5NpGEIPvux8B+RS8Iav7HTPi Hi7paMy1gXtotXIQym/cqqVSw7K8V9FWBfydtViQ3fbe7OUCzvK5Aq9r8VsE0LjOz60b QGjegziOahvA6fBODqvaeBFXEU3oDqJbCH2C1QMfq05f8aPQ000zZd7+SjQhyugmAmAt QPVQqZUi0g/lKK9r7xqfmVBtXQXko1mhPh7gGX0efAw3yqtF/Y88iUv5GWgww5D/b0FJ V20tFCUtNN+IHMjd9MVWt5PjYD8irAj4qDW2A55C0NEvlHcagm375v1oQullFl0f0XZT +Tkw== 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=gfSLwCbdFMwywMZPFTO5hx480mND9O9O9B3C6PwfVhs=; fh=dzqEI/am1IoNVOMZmTOChre3TckBGjOgtLT35fkBuy0=; b=VFYc+iz+KHmYxfavcA44zrAKx8iVXhjCnocKm6LeUXfQyZ+6fy9LGYSlDcUyCnajfN oZc+x5fh+NOxrSNpVnvlRXQRtsWUJRGpBJ8ZKCz+Wo1sbsjz2c1Dr9bqKvfPLJSbe3HR l58vRUoVsMZX0uNubxsk2PiWc5vt+LOoMSMEWKZ77LrvTEk/smipEweIQItsPLOlyrEe e64yhf4HvClTLLDqpaFYHaA9038F/cYNIq6GGCnxp+g6oIWWg19M95ZafduZuswX3PHt Zb3BD5STLzh5JsFcBtw1UOVv+2kY53Jy/R/kT8wQINILszfagCKji+JXC8WgUQsH8uk8 lXMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=izbvrqtS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id l9-20020a655609000000b00578faac74a4si1424821pgs.577.2023.09.21.06.22.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 06:22:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=izbvrqtS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id E4A8A81DE23D; Wed, 20 Sep 2023 15:24:39 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229789AbjITWYi (ORCPT + 99 others); Wed, 20 Sep 2023 18:24:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229634AbjITWYY (ORCPT ); Wed, 20 Sep 2023 18:24:24 -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 A6EF2110 for ; Wed, 20 Sep 2023 15:23:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695248580; 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=gfSLwCbdFMwywMZPFTO5hx480mND9O9O9B3C6PwfVhs=; b=izbvrqtS3EVFPDLbNIa9AARTxfF5UmyHpipM2nkx39DAIi8S3IS2IJiKjJe/5RkyQ+7JFX TLnnV2R8NRTQSkgrfm0yPhdDQpDDTi0M+fk2joBOwQkMm6PT5y0tDREPHsqn9O7eYgH7b1 7qdiHaeBkOnKoHc3/ZYhqaCo70NYL2A= 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-74-jGqCcrvuM6694XgMINqOzQ-1; Wed, 20 Sep 2023 18:22:54 -0400 X-MC-Unique: jGqCcrvuM6694XgMINqOzQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (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 A146428EC111; Wed, 20 Sep 2023 22:22:53 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 07578492C37; Wed, 20 Sep 2023 22:22:51 +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 v5 06/11] iov_iter: Don't deal with iter->copy_mc in memcpy_from_iter_mc() Date: Wed, 20 Sep 2023 23:22:26 +0100 Message-ID: <20230920222231.686275-7-dhowells@redhat.com> In-Reply-To: <20230920222231.686275-1-dhowells@redhat.com> References: <20230920222231.686275-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 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 (snail.vger.email [0.0.0.0]); Wed, 20 Sep 2023 15:24:40 -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(), --- 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;