Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp6106861rwr; Tue, 9 May 2023 10:15:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6inF/eGojKjpc3seU7JhwuOt9VtU64LEKJUBwAlCrOI++tmX+qA7lzsDiY5yPVZ6dc57Gf X-Received: by 2002:a05:6a20:244a:b0:100:5222:7c0d with SMTP id t10-20020a056a20244a00b0010052227c0dmr10816107pzc.52.1683652554406; Tue, 09 May 2023 10:15:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683652554; cv=none; d=google.com; s=arc-20160816; b=ZN+Z/s2cvTGoeLnnFuYszZ3PtuSnylbpG+PQrqs3iQyCaPxOBvUobqNy5xtKK/YIDs 37vRequFGdSzxlBs//wVgQWwQXwSE71O1/PoM+ug9LTY78b3b8AdgkoAPJ/veMPZ2lOu 5CxW/Qw8a656/9M57SKzsdJSuWiq/NlTrejJIgSmcweRQe7pWcVO1gonyT6pvRBaKBQO vCE1usosv3d1sKcmf2TOYHP9sTwc2ooSWDeMOYhMeKbGrivuis3tBZyiM2IPub43VHtE QGQeHpZMpPlMyZsUgKCy5DxWf6L0ctZY/qnYJ+0t2xqKk8EbzM0GLlDmnxzEYHATrZnB MAww== 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=oQzCDYvJ0lsDeSo/s7SzXt92I5sJ/6Jd0MY/kK+yD7U=; b=i1uTibG/wyc7gRJZDRizDYWT/IS1grecKd64FKskaxgNkmyTc0GBQ2CQZABfICsb3X UDnoFEUcECPpIX2gXcyk2/zYHY1ti0F1B1P/ctjaY8wXnuzP2/qkLfjPM6eLP0pX8+bo lVtwWtqWUNpeB0zPuDeEcYpFWleZI0cIePDeCdt6PBgUKEsBPnUjk8tkBq3nHgKrjxX+ uvTHicbN9epbpvcz4mbYeWczmzJeBZ4eeS2LZ6htWnfa7BEZPAx2pfh6sySs1Os7DnG+ PiUwerNcy2axtTZXYZyj8DC1P/DgKZy0Gbat0MuKvYcamglkXvRKbTesUvZx9JQbE1sV HA/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=PHvXBmFr; 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=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m15-20020a638c0f000000b005212e660b50si1958514pgd.865.2023.05.09.10.15.39; Tue, 09 May 2023 10:15:54 -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=@linux.dev header.s=key1 header.b=PHvXBmFr; 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=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229498AbjEIRAL (ORCPT + 99 others); Tue, 9 May 2023 13:00:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234932AbjEIQ6j (ORCPT ); Tue, 9 May 2023 12:58:39 -0400 Received: from out-51.mta1.migadu.com (out-51.mta1.migadu.com [IPv6:2001:41d0:203:375::33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54F5F55BB for ; Tue, 9 May 2023 09:57:36 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1683651452; 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=oQzCDYvJ0lsDeSo/s7SzXt92I5sJ/6Jd0MY/kK+yD7U=; b=PHvXBmFrG1haHZH++ByGkbPhrVLFCqbuynFUtixhqKw8mL0m5MIf5c7OUEjz7eapdhaScW hCJHsByetQerY+RW9TsdnWKMQdY24yvdwZbxmirMlKSiBi5Di6g55JhMWL5pXOi8+suAQa Dg3gJDde1WSrFwgXqlCxQnFt2d4bGZY= From: Kent Overstreet To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-bcachefs@vger.kernel.org Cc: Kent Overstreet , Alexander Viro , Matthew Wilcox Subject: [PATCH 23/32] iov_iter: copy_folio_from_iter_atomic() Date: Tue, 9 May 2023 12:56:48 -0400 Message-Id: <20230509165657.1735798-24-kent.overstreet@linux.dev> In-Reply-To: <20230509165657.1735798-1-kent.overstreet@linux.dev> References: <20230509165657.1735798-1-kent.overstreet@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 Add a foliated version of copy_page_from_iter_atomic() Signed-off-by: Kent Overstreet Cc: Alexander Viro Cc: Matthew Wilcox --- include/linux/uio.h | 2 ++ lib/iov_iter.c | 53 ++++++++++++++++++++++++++++++++++++--------- 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/include/linux/uio.h b/include/linux/uio.h index 27e3fd9429..b2c281cb10 100644 --- a/include/linux/uio.h +++ b/include/linux/uio.h @@ -154,6 +154,8 @@ static inline struct iovec iov_iter_iovec(const struct iov_iter *iter) size_t copy_page_from_iter_atomic(struct page *page, unsigned offset, size_t bytes, struct iov_iter *i); +size_t copy_folio_from_iter_atomic(struct folio *folio, size_t offset, + size_t bytes, struct iov_iter *i); void iov_iter_advance(struct iov_iter *i, size_t bytes); void iov_iter_revert(struct iov_iter *i, size_t bytes); size_t fault_in_iov_iter_readable(const struct iov_iter *i, size_t bytes); diff --git a/lib/iov_iter.c b/lib/iov_iter.c index 274014e4ea..27ba7e9f9e 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -800,18 +800,10 @@ size_t iov_iter_zero(size_t bytes, struct iov_iter *i) } EXPORT_SYMBOL(iov_iter_zero); -size_t copy_page_from_iter_atomic(struct page *page, unsigned offset, size_t bytes, - struct iov_iter *i) +static inline size_t __copy_page_from_iter_atomic(struct page *page, unsigned offset, + size_t bytes, struct iov_iter *i) { char *kaddr = kmap_atomic(page), *p = kaddr + offset; - if (!page_copy_sane(page, offset, bytes)) { - kunmap_atomic(kaddr); - return 0; - } - if (WARN_ON_ONCE(!i->data_source)) { - kunmap_atomic(kaddr); - return 0; - } iterate_and_advance(i, bytes, base, len, off, copyin(p + off, base, len), memcpy(p + off, base, len) @@ -819,8 +811,49 @@ size_t copy_page_from_iter_atomic(struct page *page, unsigned offset, size_t byt kunmap_atomic(kaddr); return bytes; } + +size_t copy_page_from_iter_atomic(struct page *page, unsigned offset, size_t bytes, + struct iov_iter *i) +{ + if (!page_copy_sane(page, offset, bytes)) + return 0; + if (WARN_ON_ONCE(!i->data_source)) + return 0; + return __copy_page_from_iter_atomic(page, offset, bytes, i); +} EXPORT_SYMBOL(copy_page_from_iter_atomic); +size_t copy_folio_from_iter_atomic(struct folio *folio, size_t offset, + size_t bytes, struct iov_iter *i) +{ + size_t ret = 0; + + if (WARN_ON(offset + bytes > folio_size(folio))) + return 0; + if (WARN_ON_ONCE(!i->data_source)) + return 0; + +#ifdef CONFIG_HIGHMEM + while (bytes) { + struct page *page = folio_page(folio, offset >> PAGE_SHIFT); + unsigned b = min(bytes, PAGE_SIZE - (offset & PAGE_MASK)); + unsigned r = __copy_page_from_iter_atomic(page, offset, b, i); + + offset += r; + bytes -= r; + ret += r; + + if (r != b) + break; + } +#else + ret = __copy_page_from_iter_atomic(&folio->page, offset, bytes, i); +#endif + + return ret; +} +EXPORT_SYMBOL(copy_folio_from_iter_atomic); + static void pipe_advance(struct iov_iter *i, size_t size) { struct pipe_inode_info *pipe = i->pipe; -- 2.40.1