From patchwork Thu Feb 16 16:05:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yin Fengwei X-Patchwork-Id: 13143462 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 D8967C61DA4 for ; Thu, 16 Feb 2023 16:24:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1C20C6B0074; Thu, 16 Feb 2023 11:24:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1717C6B0075; Thu, 16 Feb 2023 11:24:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F2C3B6B0078; Thu, 16 Feb 2023 11:24:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id E15166B0074 for ; Thu, 16 Feb 2023 11:24:02 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 8FF83120682 for ; Thu, 16 Feb 2023 16:24:02 +0000 (UTC) X-FDA: 80473676724.08.1F89787 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by imf07.hostedemail.com (Postfix) with ESMTP id 09C2E40003 for ; Thu, 16 Feb 2023 16:23:58 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=Vk7ehqvm; spf=pass (imf07.hostedemail.com: domain of fengwei.yin@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=fengwei.yin@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676564639; 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=UCVGVzbGOj6nSY0Xre4Jiqva3fI981tXrWQgsEKi3TU=; b=aCveFDlsrZ5uowPoIruCeRFTX1MebnF8DhkRnAlrSxdm9nxgjo3eky/SsDTHbGrtXrqdkG iBubHl8mn7/yM95hE3XL/QOCux0fReem+UeDiVGbJfl2kPXtpl43eT2EmZ5GWotonc1Ud4 4aDjA4qEbzXACcP5uxvZQzJGSAJYGzU= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=Vk7ehqvm; spf=pass (imf07.hostedemail.com: domain of fengwei.yin@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=fengwei.yin@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676564639; a=rsa-sha256; cv=none; b=C5TbrmwmlQaIdkQKWgW44VnY7dniWO7JFIVC/91OO8dUpU+Uj9abLbCLtjqwYGGwS4K0ag FDOINgSSmxMAafcZvod69zEBi1ajBCBL3w2Gh6UxMrHF4CU9qtM552GZ7Zy8BJRPOl6NrW uTMsGKtHDoUhD0F2gvygQwklpts6a4k= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1676564639; x=1708100639; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DHRxEroRnQsnwmr8DiY+XEo82K4MP2f42ZhEh8hKQH4=; b=Vk7ehqvmDPG52E+Ezm/IaD7skRDISIMXevL+m4Yc2qFSKa9AGRCQnw3v tNGhFkwjzxzzN2ugZdcWkG5BaRJbHCV53XRSMEyNU4X+R3cQ9P5QPk6jm kj10gpHp4KacjO/mN6DpD6rDsDm4kYlNupcXl3qwqEukezDbKHuGtBCQI QEtDP+p/R8VX0CG4GFbgCAM/I0aSNtb9pMlTdlPgLlokEqsqRKQCzZuO/ 19k4vjpDPzh75xruxqh/Lk1Gpoo3Kj8MjTibgkHjOa1AMAB6xnDykOo5R IgMxn4xKSG4Gp3zFRu7/qCXRkF5gvVkmnnf3aQGyHbLhi5vtx6GrlqGm4 A==; X-IronPort-AV: E=McAfee;i="6500,9779,10623"; a="319841101" X-IronPort-AV: E=Sophos;i="5.97,302,1669104000"; d="scan'208";a="319841101" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Feb 2023 08:04:02 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10623"; a="794069862" X-IronPort-AV: E=Sophos;i="5.97,302,1669104000"; d="scan'208";a="794069862" Received: from fyin-dev.sh.intel.com ([10.239.159.32]) by orsmga004.jf.intel.com with ESMTP; 16 Feb 2023 08:04:00 -0800 From: Yin Fengwei To: willy@infradead.org, linux-mm@kvack.org Cc: fengwei.yin@intel.com Subject: [RFC PATCH 1/2] mm: remove duplicated flush_dcache_folio() Date: Fri, 17 Feb 2023 00:05:27 +0800 Message-Id: <20230216160528.2146188-2-fengwei.yin@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230216160528.2146188-1-fengwei.yin@intel.com> References: <20230216160528.2146188-1-fengwei.yin@intel.com> MIME-Version: 1.0 X-Stat-Signature: gaoasm3fysguuqxftz5fczze48p4iyh5 X-Rspam-User: X-Rspamd-Queue-Id: 09C2E40003 X-Rspamd-Server: rspam06 X-HE-Tag: 1676564638-618926 X-HE-Meta: U2FsdGVkX196TJm9Qy/J3V5V1PKXW/BOzHTuS98Q//roqM7/t21NbL3UU6HGSVX1hG3Vc+JJEj6dHarZSln9aluyqRG7PTQP6t2t50fbr8oS3lk11a4i5lc2nYYqVi+uRg2+bmhiXMbftklTTV1rxtEVjOpE6PAsc6+zHMN9P6N2hfhajdc+HY3S8c1o5zIyCQMf4GEPVyiPUpPalz6eZZwrbuMag8W/JCEOV7gTlksIZgDIlD/sfb97MKUyJfVoqOGTHFwz7Cqc/UnksywtKeVXY5t8pMeksId+t6+4Wqs8fSs/kRpv0N2qKzw5ocqVf3FOwQmFToUqZcxDjq9RZ1yb7OIGHk0a1DS7Vhrp3Q8aAX21zMBFCPglVIVF0hoB54fBXdAxCTHgE5ozmUzn9HI1q/Kte5wApe0SjkMDxCkM5B6Vn3wcP0CZ+ztMo9wQ84xqywcSZTD4GI1Asw0JoXCnbBhjCJe5sdvHfcm78PgRxuJj7PbiEjNTy/OnP+HOiqsOuo7Ulq8wnOnbKOIHAwkJ1xK+Q/JjLqgJnd0mcuWo8DFbvf5nEiJjuj/xRNyW4CUnwfqF1aSJMI8zk5U6kFO+/PJXuuZTS6H0urREiPBotG/qCESRGFxMmQ+aAeE5Fv5hccNfMyiNEdx+wQMoyfRbVRfBGtoT10b0z96exmqo3mCaUV3HrQkABR8OicLQMG12NztTKBBVBTcl+V8Di+YvqLM1qB9CeklASGxy+ZqO8GxyjZwM6luY+5inCSKO5cdqXrwXg2e/GY+eZfRb44z3nRBVcpqDZCaLBCJuATV1K+3eaidP2Ov5FmqwV4Acliaoj4Ya51nKRX72s7Ykxmmw2z1wk+zovQnyF5AocITn43l2HEX8s4BncIqYcmvVDv4XbSaOarJdMTACRhSQdcN3R/G62mSmM/2oxc8JIEu24onWVab4PruT397IUo8+FHOdH3Cl5Lu/IF3Z0yH hZ34GmuN 2ab9lhihH3yp/Ibs40+9H8VcyoWnlrY7G0cVhcK4U2YQQQnKK2RtVsx0HwopJYixXTTP5ehixXCSMjKpAZbKGvBqS1tjvu5fzSHDYTHTXHHmSO1cQ8NfLSek3V/uR/rOZbsFhoHvZwsnCFzO3fx6X1LEzL86piPqOrC/9/Tv8vWknu0KA+kQ5H+4MQqqvFfUaCygkMi6SWkaRLDUxw5/jmykgeg== 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: folio_zero_range() calls the flush_dcache_folio() already. Remove unnecessary flush_dcache_folio() call. Signed-off-by: Yin Fengwei --- fs/libfs.c | 1 - mm/shmem.c | 7 +------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index 4eda519c3002..d57370c8e382 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -543,7 +543,6 @@ EXPORT_SYMBOL(simple_setattr); static int simple_read_folio(struct file *file, struct folio *folio) { folio_zero_range(folio, 0, folio_size(folio)); - flush_dcache_folio(folio); folio_mark_uptodate(folio); folio_unlock(folio); return 0; diff --git a/mm/shmem.c b/mm/shmem.c index 448f393d8ab2..66e50f0a15ab 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1401,7 +1401,6 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) goto redirty; } folio_zero_range(folio, 0, folio_size(folio)); - flush_dcache_folio(folio); folio_mark_uptodate(folio); } @@ -2010,11 +2009,7 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, * it now, lest undo on failure cancel our earlier guarantee. */ if (sgp != SGP_WRITE && !folio_test_uptodate(folio)) { - long i, n = folio_nr_pages(folio); - - for (i = 0; i < n; i++) - clear_highpage(folio_page(folio, i)); - flush_dcache_folio(folio); + folio_zero_range(folio, 0, folio_size(folio)); folio_mark_uptodate(folio); } From patchwork Thu Feb 16 16:05:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yin Fengwei X-Patchwork-Id: 13143463 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 49FA8C636CC for ; Thu, 16 Feb 2023 16:24:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B5E606B0075; Thu, 16 Feb 2023 11:24:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B0E6F6B0078; Thu, 16 Feb 2023 11:24:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C4F76B007D; Thu, 16 Feb 2023 11:24:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 7250B6B0075 for ; Thu, 16 Feb 2023 11:24:05 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 49D608117B for ; Thu, 16 Feb 2023 16:24:05 +0000 (UTC) X-FDA: 80473676850.06.9756A21 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by imf23.hostedemail.com (Postfix) with ESMTP id 2ED1B140003 for ; Thu, 16 Feb 2023 16:24:02 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="LY+/HbXB"; spf=pass (imf23.hostedemail.com: domain of fengwei.yin@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=fengwei.yin@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676564643; a=rsa-sha256; cv=none; b=ampHwpgX0FCmb4zf1juppvDWC5aPWBnywzFfQQRyTj8gfhYIa30W0Pk0HG9e5coWTzxfvK D7JUzQ0xdYtZ9aDYyavrhMZLjmST9ugN4v42Taph+B3OZKuNKMOBHUO9GLv+Vh6p1jbgDu Pkl0CjBVWgjvYApGISdMmudREkwsBFQ= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="LY+/HbXB"; spf=pass (imf23.hostedemail.com: domain of fengwei.yin@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=fengwei.yin@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676564643; 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=BG6QNHgnlGIDcrPt2OX+YmItKmiSKykGwZwUVNrng7c=; b=YqRqqZ2PXBJ9avKS2VKTx0PwVPB3z5lzoolcYHlAKZs3wemr+C0rxC3j5Z73ZBNpBXGnH6 rKgy0JVTWiraeFAZg+IC30Spx64LPpJ0O6FsJS9PDW5GTMtNiJKsP5JPSZ7cmTPdren8X4 F9iMFZYyRPqCzAI+FF8jwTdbfv0/A70= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1676564643; x=1708100643; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4rYxOFLaTSsgISDQ5sSUZXknU8rVMgwYyhkVtFgn0Fs=; b=LY+/HbXBPTUs68grhAjZGnd1qDTwrvSKRkJ98vvXv81RKAWiissWsD9w GHrBmzVBeughZ9MsziRPLcIwH6hAZiOzRPxqolbCLlAdKrI4eLVvjBu8a V+2Uy4AsUn8FnbEl9moPPIBn7f8amSurvxWy1N/K0auld17Ux0XkUqhzu Q7CbI4qkjmPzYEXF8/eMTyg4RG4+SCSI0pZHsAlyb7O5UuNUE8HhmNOFh uax58r0nzvb8FT55z+hVRuXEAJSJJt9yogT9jykAjVSuw5/+HOe1lBWBt hIJTnAl3aPZ3M567BmamwTBwZ8rQiMsjASYGdJS10wLEqpl07frGeFmrG A==; X-IronPort-AV: E=McAfee;i="6500,9779,10623"; a="319841112" X-IronPort-AV: E=Sophos;i="5.97,302,1669104000"; d="scan'208";a="319841112" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Feb 2023 08:04:03 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10623"; a="794069879" X-IronPort-AV: E=Sophos;i="5.97,302,1669104000"; d="scan'208";a="794069879" Received: from fyin-dev.sh.intel.com ([10.239.159.32]) by orsmga004.jf.intel.com with ESMTP; 16 Feb 2023 08:04:02 -0800 From: Yin Fengwei To: willy@infradead.org, linux-mm@kvack.org Cc: fengwei.yin@intel.com Subject: [RFC PATCH 2/2] mm: add zero_user_folio_segments() Date: Fri, 17 Feb 2023 00:05:28 +0800 Message-Id: <20230216160528.2146188-3-fengwei.yin@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230216160528.2146188-1-fengwei.yin@intel.com> References: <20230216160528.2146188-1-fengwei.yin@intel.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 2ED1B140003 X-Rspamd-Server: rspam01 X-Stat-Signature: kiqoqfarf6hzwcrqt7mk6ziu6m9omfna X-HE-Tag: 1676564642-891227 X-HE-Meta: U2FsdGVkX1/k4glKcasRok7OIv9K99fYpEjWdMvlqQz0yMZw2zS8uviuvDSP1pSUtgThiynVMPJcOAoOZdnZf7eCtt0JYQsDeBLkOF64p8THsRd3LmwnU/Yu6jaNxPXU/TalYUxT39c4Sl0PswamiZM8Vp4E+d+OpuDtMmDeRLdcJgYSHDY5W9Jps5rA3jLwFjcmSytrVq8YbxLFsSZoNb20zLP6hS8RHhFop5XKfn6+VKFcQ4eh/E+2cjHfjBqbHDQSZWePCECN+jHgyDWczR4Dt15nVInm6eBc+RT8hPkw/b0XKPsQ7P36hB3/lhufW2idOiyMCl+R0JY30lcSoWPOA5Z58+zG/8xTAMaA+WwNghy28p/ENokg3jYFmwwVzjARUlcpW7pB6BjjsvzQCFLA9wjV6IFb2oRkRc8/xSg4dyftSmGkXjUmvoAwtwnIoO3ve9r+uTm85iD7QJ0T8vjJ3M+rg1h+bEI1yudrzcQP+Luit580V3tLLk3ZO6diKTz5kkQDrNSaLobO1XXqGGNDtT0KLpsaOYMlwrv9aFV6hO00C8F2C3oSUPSD32/X/kRmKMUH3uIvVD3vSYZQA/lPx5t6LD1nPYJsoGWc/Siz6fyY/E6XFwR/STYt0CVEJQEXxdZGpk5Gb2EqJpVo7ECPWUJ14IB92GP4QcPUUJysJOsG3FlhQGM0pAHWrN9b/3h8Z8C/P4HXZEIuBua1pkfyN9bF9AEb56Lp7n8IR082OSbG/OkZ1Csq/xErjkQo5oz4/nuUZajdBvUZYsDGM1oHk5mNFEcaX2a/ssfpg1ZheZk/gsuiGPQPTyQ3sZU+guBI7E6cV8HkUSPrM6PJZySbE42RNQcBSEUC54XhegbAjYW7JGtgyHC/YQQSMsxVfL1wLwHJKIgdri4ZvgPSevXpw3BQvWbydSkQBTeG1OhN6WsXRrsDS/lpwthO5upk/QI/4jBQmFexs+H7heM 8vqRL3IT MfVAyGitn9PSaATSBB951i/YHGEMNGHab89fEDomLP8hssfTUwujBFyW1yB8xtcQSLIH9lxeUVuU15QSB+pmwLyeGmEcZKWR9/dREIP+uC/JEDBHcjsNxmpe7m8X9Zs+N8uAGGmk3ucSuFQj1w4nDiDCK4DKlIMXJOEGsYDDJwKDlnrDjOFj85c9pty8cf29O7vziI3x6j2jKebj28lnMsrGiAc6JWUCY1tRY 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: zero_user_folio_segments() has same function as zero_user_segments(). but take folio as parameter. Update folio_zero_segments(), folio_zero_segment() and folio_zero_range() to use it. Signed-off-by: Yin Fengwei --- include/linux/highmem.h | 26 +++++++++++++++++--- mm/highmem.c | 53 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 3 deletions(-) diff --git a/include/linux/highmem.h b/include/linux/highmem.h index b06254e76d99..0039116e416a 100644 --- a/include/linux/highmem.h +++ b/include/linux/highmem.h @@ -266,6 +266,8 @@ static inline void tag_clear_highpage(struct page *page) #ifdef CONFIG_HIGHMEM void zero_user_segments(struct page *page, unsigned start1, unsigned end1, unsigned start2, unsigned end2); +void zero_user_folio_segments(struct folio *folio, unsigned start1, + unsigned end1, unsigned start2, unsigned end2); #else static inline void zero_user_segments(struct page *page, unsigned start1, unsigned end1, @@ -286,6 +288,24 @@ static inline void zero_user_segments(struct page *page, for (i = 0; i < compound_nr(page); i++) flush_dcache_page(page + i); } + +static inline void zero_user_folio_segments(struct folio *folio, + unsigned start1, unsigned end1, + unsigned start2, unsigned end2) +{ + void *kaddr = kmap_local_page(&folio->page); + + BUG_ON(end1 > folio_size(folio) || end2 > folio_size(folio)); + + if (end1 > start1) + memset(kaddr + start1, 0, end1 - start1); + + if (end2 > start2) + memset(kaddr + start2, 0, end2 - start2); + + kunmap_local(kaddr); + flush_dcache_folio(folio); +} #endif static inline void zero_user_segment(struct page *page, @@ -454,7 +474,7 @@ static inline size_t memcpy_from_file_folio(char *to, struct folio *folio, static inline void folio_zero_segments(struct folio *folio, size_t start1, size_t xend1, size_t start2, size_t xend2) { - zero_user_segments(&folio->page, start1, xend1, start2, xend2); + zero_user_folio_segments(folio, start1, xend1, start2, xend2); } /** @@ -466,7 +486,7 @@ static inline void folio_zero_segments(struct folio *folio, static inline void folio_zero_segment(struct folio *folio, size_t start, size_t xend) { - zero_user_segments(&folio->page, start, xend, 0, 0); + zero_user_folio_segments(folio, start, xend, 0, 0); } /** @@ -478,7 +498,7 @@ static inline void folio_zero_segment(struct folio *folio, static inline void folio_zero_range(struct folio *folio, size_t start, size_t length) { - zero_user_segments(&folio->page, start, start + length, 0, 0); + zero_user_folio_segments(folio, start, start + length, 0, 0); } #endif /* _LINUX_HIGHMEM_H */ diff --git a/mm/highmem.c b/mm/highmem.c index db251e77f98f..e234b249208f 100644 --- a/mm/highmem.c +++ b/mm/highmem.c @@ -443,6 +443,59 @@ void zero_user_segments(struct page *page, unsigned start1, unsigned end1, BUG_ON((start1 | start2 | end1 | end2) != 0); } EXPORT_SYMBOL(zero_user_segments); + +static inline void zero_user_folio_segment(struct folio *folio, + unsigned start1, unsigned end1, + unsigned start2, unsigned end2) +{ + void *kaddr; + unsigned s; + + BUG_ON(end1 > folio_size(folio) || end2 > folio_size(folio)); + + if (start1 > start2) { + swap(start1, start2); + swap(end1, end2); + } + + if (start1 >= end1) + start1 = end1 = 0; + + if (start2 >= end2) + start2 = end2 = 0; + + start2 = max_t(unsigned, end1, start2); + s = start1; + while((start1 < end1) || (start2 < end2)) { + kaddr = kmap_local_folio(folio, + offset_in_folio(folio, PAGE_ALIGN_DOWN(s))); + + if ((end2 > start2) && (end1 >= start1)) { + unsigned this_end = min_t(unsigned, end2, + PAGE_ALIGN_DOWN(start2) + PAGE_SIZE); + + memset(kaddr + offset_in_page(start2), 0, + this_end - start2); + + start2 = this_end; + } + + if (end1 > start1) { + unsigned this_end = min_t(unsigned, end1, + PAGE_ALIGN_DOWN(start1) + PAGE_SIZE); + + memset(kaddr + offset_in_page(start1), 0, + this_end - start1); + s = start1 = this_end; + } else { + s = start2; + } + kunmap_local(kaddr); + } + + flush_dcache_folio(folio); +} +EXPORT_SYMBOL(zero_user_folio_segments); #endif /* CONFIG_HIGHMEM */ #ifdef CONFIG_KMAP_LOCAL