From patchwork Thu May 20 12:25:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Gruenbacher X-Patchwork-Id: 12270097 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A912C433ED for ; Thu, 20 May 2021 12:25:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2920461279 for ; Thu, 20 May 2021 12:25:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2920461279 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id DADB46B00CA; Thu, 20 May 2021 08:25:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D608E6B00CB; Thu, 20 May 2021 08:25:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C4BB56B00CD; Thu, 20 May 2021 08:25:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0171.hostedemail.com [216.40.44.171]) by kanga.kvack.org (Postfix) with ESMTP id 87E556B00CA for ; Thu, 20 May 2021 08:25:51 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 2508818018765 for ; Thu, 20 May 2021 12:25:51 +0000 (UTC) X-FDA: 78161530902.23.802B442 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf11.hostedemail.com (Postfix) with ESMTP id E073520007F0 for ; Thu, 20 May 2021 12:25:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621513550; 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=jVHI9tAO4j1d0e06AWNsK9Ts1IDxwkkuCGwpEsW+/6g=; b=GzkPW/hyurEEZ6U6SE7Y5RRExZ0lXwk75E9gmWOmc5ROMn1pr7jvBf3Z/tMoO/tqKCRCU7 qV5PGJOrLTEUCVU7Mktqp5+tV2a868DEobZ+th83D1TA3RpX3alI2HqH0n+GntcwPCDE69 LlcmkjZ0pwcEXOLYW9V2n/hYGxoFbF8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-444-cfoyeOgQNduXqNWdhpx9LA-1; Thu, 20 May 2021 08:25:48 -0400 X-MC-Unique: cfoyeOgQNduXqNWdhpx9LA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 79F75802B4F; Thu, 20 May 2021 12:25:47 +0000 (UTC) Received: from max.com (unknown [10.40.195.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id DF11760C04; Thu, 20 May 2021 12:25:45 +0000 (UTC) From: Andreas Gruenbacher To: Alexander Viro , cluster-devel@redhat.com Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Jan Kara , Andreas Gruenbacher Subject: [PATCH 2/6] iov_iter: Add iov_iter_fault_in_writeable() Date: Thu, 20 May 2021 14:25:32 +0200 Message-Id: <20210520122536.1596602-3-agruenba@redhat.com> In-Reply-To: <20210520122536.1596602-1-agruenba@redhat.com> References: <20210520122536.1596602-1-agruenba@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Rspamd-Queue-Id: E073520007F0 Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="GzkPW/hy"; spf=none (imf11.hostedemail.com: domain of agruenba@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=agruenba@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam04 X-Stat-Signature: hdez5fbpy463p919955cyhpfuk4q9qbb X-HE-Tag: 1621513548-842898 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: Add the equivalent of iov_iter_fault_in_readable(), but for pages that will be written to. While at it, fix an indentation error in iov_iter_fault_in_readable(). Signed-off-by: Andreas Gruenbacher --- include/linux/uio.h | 1 + lib/iov_iter.c | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/include/linux/uio.h b/include/linux/uio.h index d3ec87706d75..6811eb6ac6e3 100644 --- a/include/linux/uio.h +++ b/include/linux/uio.h @@ -124,6 +124,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page, void iov_iter_advance(struct iov_iter *i, size_t bytes); void iov_iter_revert(struct iov_iter *i, size_t bytes); int iov_iter_fault_in_readable(struct iov_iter *i, size_t bytes); +int iov_iter_fault_in_writeable(struct iov_iter *i, size_t bytes); size_t iov_iter_single_seg_count(const struct iov_iter *i); size_t copy_page_to_iter(struct page *page, size_t offset, size_t bytes, struct iov_iter *i); diff --git a/lib/iov_iter.c b/lib/iov_iter.c index c701b7a187f2..317c94eac907 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -480,13 +480,31 @@ int iov_iter_fault_in_readable(struct iov_iter *i, size_t bytes) iterate_iovec(i, bytes, v, iov, skip, ({ err = fault_in_pages_readable(v.iov_base, v.iov_len); if (unlikely(err)) - return err; + return err; 0;})) } return 0; } EXPORT_SYMBOL(iov_iter_fault_in_readable); +int iov_iter_fault_in_writeable(struct iov_iter *i, size_t bytes) +{ + size_t skip = i->iov_offset; + const struct iovec *iov; + int err; + struct iovec v; + + if (!(i->type & (ITER_BVEC|ITER_KVEC))) { + iterate_iovec(i, bytes, v, iov, skip, ({ + err = fault_in_pages_writeable(v.iov_base, v.iov_len); + if (unlikely(err)) + return err; + 0;})) + } + return 0; +} +EXPORT_SYMBOL(iov_iter_fault_in_writeable); + void iov_iter_init(struct iov_iter *i, unsigned int direction, const struct iovec *iov, unsigned long nr_segs, size_t count)