Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp569824rwo; Fri, 21 Jul 2023 17:24:45 -0700 (PDT) X-Google-Smtp-Source: APBJJlGiFc/PK3DkJNDpJzSrp3q/up4OtSDvTtaiUzm8jLj7RuOkbnyC4WdGLK32H0hq5JkHPA4a X-Received: by 2002:a17:903:41c7:b0:1b8:6dea:e270 with SMTP id u7-20020a17090341c700b001b86deae270mr3275167ple.16.1689985484902; Fri, 21 Jul 2023 17:24:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689985484; cv=none; d=google.com; s=arc-20160816; b=HvO1o0nKOOim0+ye0Eli3sawWR0o3Grx6S3ITY6iwNJwgOasGUB/tlMFYUSelbZBFU sejGs73OBM6G6XHh5AEc/lD7PPkAtdZUY+A9BIjs7/Hbu7wMzwFwXJwRmAd2gvG6XhBp T9nRb6YNAhcBc5t/xzFGUqcJkIcqb6c4nGOJHG3QI1+t1Kt2EMeoKFYmO9XP3bKM2Mio PJG3C84GoZAtqq9SlWiUi4kizTklZ5NrMhg9DpdZS9fOEaVADwWQWLf9B59k9qbafoFp bXP8HpdnXuLUsdm5L/tW5+lUKbSsmPiVTXOdqG9vtoxsDvqhmjV0hJySDk2GjOtpc4Tb N/1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=YuIgZ0kCdlWgwOipolMH4qwbkf4qo8GzSPfjGjifT9M=; fh=qxEx1IY95hyw97KQGgg8Dobjzr8elYGfmQzV5rhi/RY=; b=eMVJ3u3bVNKQA3iGR3jXvk3XQiejcsOKdw3UQTUo0Mbr8Gtp5kTOWrhmVojB8JdqCY HveMHKuI74MZGvjG0dkn5aDMEUBmUCNVne373Q9fZ59zRHkxpMjYbKiFxPRJTOE8ndKZ NkEJoS66yDR5NSUmoLDE4ZzVE9iPzCYmBIoTblBycrVRnfAcDN0jqLdnNZ3LHHhSwcpz klzhWie/krxom+G6aPrztFk0hqYtqBhp8DtTB0f5iLInzTlhc/Zg0bRllwZc5cgmkBi4 Ou9STfJzDssl+BbJ4xsc5Xi1whB3Jf+y6i/ZzYqxMs1cEDKNVE3jcJi9tzhfI7fLuKsK a3wQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=B3Hme8dq; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f2-20020a170902ce8200b001bb02e4b739si4420075plg.475.2023.07.21.17.24.25; Fri, 21 Jul 2023 17:24:44 -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=@gmail.com header.s=20221208 header.b=B3Hme8dq; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230228AbjGVAHH (ORCPT + 99 others); Fri, 21 Jul 2023 20:07:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229533AbjGVAHG (ORCPT ); Fri, 21 Jul 2023 20:07:06 -0400 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37857E44; Fri, 21 Jul 2023 17:07:03 -0700 (PDT) Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-4faaaa476a9so4038296e87.2; Fri, 21 Jul 2023 17:07:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689984421; x=1690589221; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=YuIgZ0kCdlWgwOipolMH4qwbkf4qo8GzSPfjGjifT9M=; b=B3Hme8dqaOXMsrPG2++TgbuKnjnbxyHIC+ORugqmopZwL1w8TJEChZufUpZKZR1PQq tOIy46NPX7iBctrWcZ1cseEMzbjLLKRJD3MY6izVCeb7CUBHq1JFi8n8XXsXOzHMMCXH sx8gn6dzNjDKuNgfW5k8AGYZX6oKrCw1CkMimOwfAoj412POis87U/94PR+7owwkLeOg k2z88VJTw5RViiSFqp+7NcIass1DiRMrYcSyqFU3tm8WBa7FbhJmZeTOr1v9kRzFhloX XXbnQ4Bs79CaLpJjTTc8drlWVkncvsKx3tk6AqeExXG1KFqazjwMLuz+PnhJtnhSUTe3 nYrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689984421; x=1690589221; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=YuIgZ0kCdlWgwOipolMH4qwbkf4qo8GzSPfjGjifT9M=; b=RZw/q8/b8HLM7DwJK/I0gPQ/dPGXRz+uXv3ROOMwvX6e1EhjNCryv5u92nu6GyHld4 Lk+RqmpIqZHzUeH/DXLGACTpvx37Ft0/3oaAUE2c5ltpp7W8mV01NXzOOJNmCsf/T2vQ h5T/ehqjMz/qfsAkZI5ym5PlbZEewTFqva/W4bZGrgC01VgJUmtYobgX6U3sFzmSGc1k +Sf+C5Er5kE8cC24BY5b3zfCko6oTkXf6jcxScNETfiBgAe1nVdWsavEQyPId4WWDd0e B7HBcZp6waUczOsBNJL58DafXUl+bNtv1YhcLxBGXbC7ezjkEpf/9YhuyH4a86Mb99Sx Ibnw== X-Gm-Message-State: ABy/qLZy45R+IjW1wehjv6p6AU56ld9fW+Z70GWCDILUracSflqaq6tQ eSd92GNltG/6z3dW7lIEYKiS48HlDaQKs/4RgX8= X-Received: by 2002:a05:6512:3da7:b0:4fb:52a3:e809 with SMTP id k39-20020a0565123da700b004fb52a3e809mr3283162lfv.28.1689984421181; Fri, 21 Jul 2023 17:07:01 -0700 (PDT) MIME-Version: 1.0 References: <20230713035512.4139457-1-willy@infradead.org> <20230713035512.4139457-2-willy@infradead.org> In-Reply-To: <20230713035512.4139457-2-willy@infradead.org> From: =?UTF-8?Q?Andreas_Gr=C3=BCnbacher?= Date: Sat, 22 Jul 2023 02:06:50 +0200 Message-ID: Subject: Re: [PATCH 1/7] highmem: Add memcpy_to_folio() and memcpy_from_folio() To: "Matthew Wilcox (Oracle)" Cc: Andrew Morton , David Sterba , linux-fsdevel@vger.kernel.org, Pankaj Raghav , Konstantin Komarov , ntfs3@lists.linux.dev, Theodore Tso , Jan Kara , linux-ext4@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,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 Am Do., 13. Juli 2023 um 06:04 Uhr schrieb Matthew Wilcox (Oracle) : > 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); We want memcpy(to, from, chunk) here. > + 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); And also here. > + 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 > Thanks, Andreas