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+OpuDtMmDeRLdc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, 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