Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp640868rwp; Wed, 12 Jul 2023 21:04:48 -0700 (PDT) X-Google-Smtp-Source: APBJJlGbSV8f8IOP9MuPtmuABwmhs+C81WhbUfYHgOsMvjJnj+3UYXx9+GP+mcJeA9EdzJxefJtb X-Received: by 2002:a17:906:2da:b0:994:30bf:5d4f with SMTP id 26-20020a17090602da00b0099430bf5d4fmr342174ejk.43.1689221088686; Wed, 12 Jul 2023 21:04:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689221088; cv=none; d=google.com; s=arc-20160816; b=iIWmkXB5YjeVgl1I6n0Mmy9i8OPPLEOYQu8E3luZpvOzrPJkrfBMGShtR1jE4mvi6u gU5g8BjzxswaA5Wl41XEdaGk48XqKSjWcZPnMs19dYm+SJORen55ZwJqszZ+z4m7flR7 jNrtrCeOPI3e65jxY4OSi71ZWsd19zUwCEeVqlyb92gZcCTX/C0j8LC7dO9rYjMHC8nx 8FZhrnr+A8sjWUBZ6IMlLfRT/opw996Jlb79hfjXzSkeNDUh8v2sDTpGfVY9YVCx1plk h3a3cC9mX6RdCMoJ9PuyUdu6AgbQZbEFz5m+ZJi9JUbcZzptxvqsNujC5CxRICPEPyX9 MqYg== 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=KarKDnAdc5ICiKgriHUs+5HIqBDCfuIyL8uoPMfdtgg=; fh=nmZyTsmztyk380IvEwoWJ6pEKhJ6Nps7FRu2tNkUHY4=; b=gCfDl6KkHpzX2iak/Um0a8rsnYgZrExU97MgkaOrkVkNnSO67HkGg7f6OVy3JfFoC9 gF299HlUacwTNrV6LVCIB+nKQ+au91mrki3ZRM1R2iTHgPDEJpcImpPs+6+wowKox0Ik zFpLxucALRgzZAz14ZTNnA1h8XKQJKGLKT26AdMX0EEuiGDeMdS2MpoOlER+d1m/9vdz S98uNv1AlIVtGtgZnoM1VDnxLjZMJViyuuy0P/5EvkgFu4rX3ubQQPaxWv+NBhSz2fgf MT1seMC4Tg1lKk/e1kIvRkIjwQrJy+u47lelxLZ351yLkfGpi+KwXB26bMmUO/ZUEFbY MsWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=ur4gJ0F4; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y12-20020a17090629cc00b0098d9dfee9c7si5731679eje.493.2023.07.12.21.04.25; Wed, 12 Jul 2023 21:04:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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=@infradead.org header.s=casper.20170209 header.b=ur4gJ0F4; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231404AbjGMDz1 (ORCPT + 99 others); Wed, 12 Jul 2023 23:55:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232167AbjGMDzZ (ORCPT ); Wed, 12 Jul 2023 23:55:25 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FF941BF2; Wed, 12 Jul 2023 20:55:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=KarKDnAdc5ICiKgriHUs+5HIqBDCfuIyL8uoPMfdtgg=; b=ur4gJ0F4o1/TWO3SHQnYnth3Yi zibcyPEy9vabUq9Bi7uSwmrb5LEhyXMLqQBHOPcEhnMdb1df+8ue1EV1/S0LivBGHEzvrjh1bmQfO WY7Hx6D0GILcyJWTHNMC6Bwp1i2zJUCwtEGYIVbbA777fGlsZyuRqFw96x9koSqlMmPXtL/zUzXUE OSJITXRpnTgZv19m7/9aigyvZamxYnHeKARFvjV+mQsBai0Gr2YtlZok1NtsZO95bx/GjzYD5k1KK mN1DID+3DD8SxcRU2pyiiFnLN7PoZfz0wY5Y4u8aaw4GxdHc7Mk5dqsQwUCi2Th4SnqlPYHkReDIZ 2SlqcDLw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qJnQA-00HMre-81; Thu, 13 Jul 2023 03:55:14 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , David Sterba , linux-fsdevel@vger.kernel.org, Pankaj Raghav , Konstantin Komarov , ntfs3@lists.linux.dev, "Theodore Tso" , Jan Kara , linux-ext4@vger.kernel.org Subject: [PATCH 1/7] highmem: Add memcpy_to_folio() and memcpy_from_folio() Date: Thu, 13 Jul 2023 04:55:06 +0100 Message-Id: <20230713035512.4139457-2-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230713035512.4139457-1-willy@infradead.org> References: <20230713035512.4139457-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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-ext4@vger.kernel.org These are the folio equivalent of memcpy_to_page() and memcpy_from_page(). Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/highmem.h | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/include/linux/highmem.h b/include/linux/highmem.h index 68da30625a6c..0280f57d4744 100644 --- a/include/linux/highmem.h +++ b/include/linux/highmem.h @@ -439,6 +439,50 @@ static inline void memzero_page(struct page *page, size_t offset, size_t len) kunmap_local(addr); } +static inline void memcpy_from_folio(char *to, struct folio *folio, + size_t offset, size_t len) +{ + VM_BUG_ON(offset + len > folio_size(folio)); + + do { + char *from = kmap_local_folio(folio, offset); + size_t chunk = len; + + if (folio_test_highmem(folio) && + (chunk > (PAGE_SIZE - offset_in_page(offset)))) + chunk = PAGE_SIZE - offset_in_page(offset); + memcpy(to, from, len); + kunmap_local(from); + + from += chunk; + offset += chunk; + len -= chunk; + } while (len > 0); +} + +static inline void memcpy_to_folio(struct folio *folio, size_t offset, + const char *from, size_t len) +{ + VM_BUG_ON(offset + len > folio_size(folio)); + + do { + char *to = kmap_local_folio(folio, offset); + size_t chunk = len; + + if (folio_test_highmem(folio) && + (chunk > (PAGE_SIZE - offset_in_page(offset)))) + chunk = PAGE_SIZE - offset_in_page(offset); + memcpy(to, from, len); + kunmap_local(to); + + from += chunk; + offset += chunk; + len -= chunk; + } while (len > 0); + + flush_dcache_folio(folio); +} + /** * memcpy_from_file_folio - Copy some bytes from a file folio. * @to: The destination buffer. -- 2.39.2