From patchwork Tue Jun 30 03:18:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 11633035 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 34B65618 for ; Tue, 30 Jun 2020 03:19:12 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EE1A220760 for ; Tue, 30 Jun 2020 03:19:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EE1A220760 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D70208D001D; Mon, 29 Jun 2020 23:19:10 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D20818D000F; Mon, 29 Jun 2020 23:19:10 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C35CB8D001D; Mon, 29 Jun 2020 23:19:10 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0200.hostedemail.com [216.40.44.200]) by kanga.kvack.org (Postfix) with ESMTP id B1E608D000F for ; Mon, 29 Jun 2020 23:19:10 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 394F48248068 for ; Tue, 30 Jun 2020 03:19:10 +0000 (UTC) X-FDA: 76984422060.12.tail61_04147f026e74 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id 111291800E52C for ; Tue, 30 Jun 2020 03:19:10 +0000 (UTC) X-Spam-Summary: 1,0,0,17d97947d41e5122,d41d8cd98f00b204,richard.weiyang@linux.alibaba.com,,RULES_HIT:41:355:379:541:960:968:973:988:989:1260:1261:1311:1314:1345:1437:1515:1534:1542:1711:1730:1747:1777:1792:2393:2559:2562:2898:3138:3139:3140:3141:3142:3352:3865:3866:3867:3868:3870:3872:4321:4605:5007:6119:6261:7807:7875:10004:11026:11473:11658:11914:12043:12048:12297:12438:12555:12895:13161:13229:13894:13972:14181:14394:14721:21080:21451:21627:30012:30054:30065:30070,0,RBL:115.124.30.54:@linux.alibaba.com:.lbl8.mailshell.net-62.20.2.100 64.201.201.201;04yfo3t33nb5t6mb1zoett3eia4kxyph85a94gjmm6gyfsbjc9945eebexwmu7m.cgpmoiyuphs6bmffm7j9iy853t6trt9xjizhkpsugcsidy681r1gria4g3norhs.h-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: tail61_04147f026e74 X-Filterd-Recvd-Size: 3667 Received: from out30-54.freemail.mail.aliyun.com (out30-54.freemail.mail.aliyun.com [115.124.30.54]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Tue, 30 Jun 2020 03:19:08 +0000 (UTC) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01f04397;MF=richard.weiyang@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0U175Gc6_1593487136; Received: from localhost(mailfrom:richard.weiyang@linux.alibaba.com fp:SMTPD_---0U175Gc6_1593487136) by smtp.aliyun-inc.com(127.0.0.1); Tue, 30 Jun 2020 11:18:56 +0800 From: Wei Yang To: dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, akpm@linux-foundation.org Cc: x86@kernel.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, Wei Yang Subject: [PATCH] mm: define pte_add_end for consistency Date: Tue, 30 Jun 2020 11:18:52 +0800 Message-Id: <20200630031852.45383-1-richard.weiyang@linux.alibaba.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) MIME-Version: 1.0 X-Rspamd-Queue-Id: 111291800E52C X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 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: When walking page tables, we define several helpers to get the address of the next boundary. But we don't have one for pte level. Let's define it and consolidate the code in several places. Signed-off-by: Wei Yang --- arch/x86/mm/init_64.c | 6 ++---- include/linux/pgtable.h | 7 +++++++ mm/kasan/init.c | 4 +--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index dbae185511cd..f902fbd17f27 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c @@ -973,9 +973,7 @@ remove_pte_table(pte_t *pte_start, unsigned long addr, unsigned long end, pte = pte_start + pte_index(addr); for (; addr < end; addr = next, pte++) { - next = (addr + PAGE_SIZE) & PAGE_MASK; - if (next > end) - next = end; + next = pte_addr_end(addr, end); if (!pte_present(*pte)) continue; @@ -1558,7 +1556,7 @@ void register_page_bootmem_memmap(unsigned long section_nr, get_page_bootmem(section_nr, pud_page(*pud), MIX_SECTION_INFO); if (!boot_cpu_has(X86_FEATURE_PSE)) { - next = (addr + PAGE_SIZE) & PAGE_MASK; + next = pte_addr_end(addr, end); pmd = pmd_offset(pud, addr); if (pmd_none(*pmd)) continue; diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index 32b6c52d41b9..0de09c6c89d2 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -706,6 +706,13 @@ static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot) }) #endif +#ifndef pte_addr_end +#define pte_addr_end(addr, end) \ +({ unsigned long __boundary = ((addr) + PAGE_SIZE) & PAGE_MASK; \ + (__boundary - 1 < (end) - 1) ? __boundary : (end); \ +}) +#endif + /* * When walking page tables, we usually want to skip any p?d_none entries; * and any p?d_bad entries - reporting the error before resetting to none. diff --git a/mm/kasan/init.c b/mm/kasan/init.c index fe6be0be1f76..89f748601f74 100644 --- a/mm/kasan/init.c +++ b/mm/kasan/init.c @@ -349,9 +349,7 @@ static void kasan_remove_pte_table(pte_t *pte, unsigned long addr, unsigned long next; for (; addr < end; addr = next, pte++) { - next = (addr + PAGE_SIZE) & PAGE_MASK; - if (next > end) - next = end; + next = pte_addr_end(addr, end); if (!pte_present(*pte)) continue;