From patchwork Wed Aug 16 12:07:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13355117 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A980C04E69 for ; Wed, 16 Aug 2023 12:08:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ED3AA8D0036; Wed, 16 Aug 2023 08:08:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E826D8D0001; Wed, 16 Aug 2023 08:08:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D720C8D0036; Wed, 16 Aug 2023 08:08:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id C8C4E8D0001 for ; Wed, 16 Aug 2023 08:08:03 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9E7AB40EFC for ; Wed, 16 Aug 2023 12:08:03 +0000 (UTC) X-FDA: 81129844446.02.6E45E0A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf01.hostedemail.com (Postfix) with ESMTP id A563140026 for ; Wed, 16 Aug 2023 12:08:01 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Mu9OXORA; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692187681; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=wO3T+Kgn8IqvgBuNhCcF+dgBv+VoPvzdg3BdkPf9/3I=; b=OQzTDxOqCvLk9OfKdai9iJ1TfoGPLrzpESJ+atEjZIkkhdnTnVp90RHoI+kIZUK4tZn7AI 5wThNhJDZEeQRmIxJA0gdtHSg0gRJOpI8HaFLZYNMw2NXgJRwmKmMudjQxlkaK54ZOTUu6 sbN/6/WiToZ8rWQpYwwx95I+UUWj/ac= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Mu9OXORA; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692187681; a=rsa-sha256; cv=none; b=3yCNEg8Gk0Ad1FkAd8htIgehKnI6NauV5SP649hM4EtRgm1YErjzpMQFX+pjKNHwPbcu30 rBfho4YsleahIHeXuakx3Fr2mkRNQc3D/FVL1XrSDswhvS1n8h0uhbVeHYVaYAiT0h5C4Q sqPCpKF6K5fhysKDhP4LAkm3K+LZMYk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692187681; 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=wO3T+Kgn8IqvgBuNhCcF+dgBv+VoPvzdg3BdkPf9/3I=; b=Mu9OXORAb+9qivMNfozE9Usxf+c7R3j2Eh4Lv9sTXxQzyPeq52wUe6efkR9fK3Zb1EOyQV TBoMppPd67l+MpkIMDDoAQBONY8ECNDYbK0dlFkXmy7ukwJOPXeBNLbowi2yaXbyQyCZsV mcmh20Kyvwp26wxSqzhVO9ixQukLnDA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-517-ow2g6_iFP9a7UhFz3Anncw-1; Wed, 16 Aug 2023 08:07:59 -0400 X-MC-Unique: ow2g6_iFP9a7UhFz3Anncw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AF1CC101A53C; Wed, 16 Aug 2023 12:07:58 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id D03D91121314; Wed, 16 Aug 2023 12:07:56 +0000 (UTC) From: David Howells To: Al Viro , Linus Torvalds Cc: David Howells , Jens Axboe , Christoph Hellwig , Christian Brauner , David Laight , Matthew Wilcox , Jeff Layton , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/2] iov_iter: Don't deal with iter->copy_mc in memcpy_from_iter_mc() Date: Wed, 16 Aug 2023 13:07:41 +0100 Message-ID: <20230816120741.534415-3-dhowells@redhat.com> In-Reply-To: <20230816120741.534415-1-dhowells@redhat.com> References: <20230816120741.534415-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Rspam-User: X-Stat-Signature: edakxzi3zyh4wg4gfknw9wkizp1wbbq5 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: A563140026 X-HE-Tag: 1692187681-687962 X-HE-Meta: U2FsdGVkX1/6O9MKU52x1yBr9HfAORNP2MJcT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S3p0KLTQDyhYLWJeSm4rmmDAZ5fy+6Zt8B1qHrmc/jVhiYwyOV9DRPQs80uelfl2AYYw X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 378da0cb3069..33febccadd9d 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -450,14 +450,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) { - struct iov_iter *iter = priv2; + return copy_mc_to_kernel(to + progress, iter_from, len); +} - 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); +static size_t __copy_from_iter_mc(void *addr, size_t bytes, struct iov_iter *i) +{ + size_t progress; + + 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) @@ -467,9 +486,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); @@ -690,9 +707,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;