From patchwork Fri Jun 5 09:11:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: bibo mao X-Patchwork-Id: 11589223 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 C43FC92A for ; Fri, 5 Jun 2020 09:11:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8DEC82075B for ; Fri, 5 Jun 2020 09:11:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8DEC82075B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8480E80008; Fri, 5 Jun 2020 05:11:20 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7F8CB8E0006; Fri, 5 Jun 2020 05:11:20 -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 70E8380008; Fri, 5 Jun 2020 05:11:20 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0189.hostedemail.com [216.40.44.189]) by kanga.kvack.org (Postfix) with ESMTP id 5AF028E0006 for ; Fri, 5 Jun 2020 05:11:20 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 13A82180AD801 for ; Fri, 5 Jun 2020 09:11:20 +0000 (UTC) X-FDA: 76894589520.11.ink83_5f0b92926d9e Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin11.hostedemail.com (Postfix) with ESMTP id DF5EB180F8B82 for ; Fri, 5 Jun 2020 09:11:19 +0000 (UTC) X-Spam-Summary: 2,0,0,02c695ed2ed60899,d41d8cd98f00b204,maobibo@loongson.cn,,RULES_HIT:2:41:69:355:379:541:800:960:968:988:989:1042:1260:1261:1345:1437:1535:1605:1730:1747:1777:1792:1801:1981:2194:2198:2199:2200:2393:2559:2562:2693:2731:2901:2916:2918:3138:3139:3140:3141:3142:3865:3866:3867:3868:3870:3871:3872:4049:4119:4250:4321:4605:5007:6261:8957:9592:10004:11026:11473:11657:11658:11914:12043:12048:12160:12296:12297:12438:12555:12683:12895:13161:13229:14096:14394:21080:21451:21627:21772:21990:30002:30003:30054:30070,0,RBL:114.242.206.163:@loongson.cn:.lbl8.mailshell.net-62.14.2.100 64.201.201.201,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:25,LUA_SUMMARY:none X-HE-Tag: ink83_5f0b92926d9e X-Filterd-Recvd-Size: 8849 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by imf40.hostedemail.com (Postfix) with ESMTP for ; Fri, 5 Jun 2020 09:11:17 +0000 (UTC) Received: from kvm-dev1.localdomain (unknown [10.2.5.134]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9DxXesqDNpeHOw9AA--.611S2; Fri, 05 Jun 2020 17:11:06 +0800 (CST) From: Bibo Mao To: Thomas Bogendoerfer , Andrew Morton , Paul Burton , Jiaxun Yang Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 1/2] MIPS: set page access bit with pgprot on some MIPS platform Date: Fri, 5 Jun 2020 17:11:05 +0800 Message-Id: <1591348266-28392-1-git-send-email-maobibo@loongson.cn> X-Mailer: git-send-email 1.8.3.1 X-CM-TRANSID: AQAAf9DxXesqD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amd-Queue-Id: DF5EB180F8B82 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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: On MIPS system which has rixi hardware bit, page access bit is not set in pgrot. For memory reading, there will be one page fault to allocate physical page; however valid bit is not set, there will be the second fast tlb-miss fault handling to set valid/access bit. This patch set page access/valid bit with pgrot if there is reading access privilege. It will reduce one tlb-miss handling for memory reading access. The valid/access bit will be cleared in order to track memory accessing activity. If the page is accessed, tlb-miss fast handling will set valid/access bit, pte_sw_mkyoung is not necessary in slow page fault path. This patch removes pte_sw_mkyoung function which is defined as empty function except MIPS system. Signed-off-by: Bibo Mao Acked-by: Andrew Morton --- arch/mips/include/asm/pgtable.h | 11 +++++++++-- arch/mips/mm/cache.c | 34 +++++++++++++++++----------------- include/asm-generic/pgtable.h | 16 ---------------- mm/memory.c | 3 --- 4 files changed, 26 insertions(+), 38 deletions(-) diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h index 85b39c9..e2452ab 100644 --- a/arch/mips/include/asm/pgtable.h +++ b/arch/mips/include/asm/pgtable.h @@ -25,6 +25,15 @@ struct mm_struct; struct vm_area_struct; +#define __PP _PAGE_PRESENT +#define __NX _PAGE_NO_EXEC +#define __NR _PAGE_NO_READ +#define ___W _PAGE_WRITE +#define ___A _PAGE_ACCESSED +#define ___R (_PAGE_SILENT_READ | _PAGE_ACCESSED) +#define __PC _page_cachable_default + + #define PAGE_NONE __pgprot(_PAGE_PRESENT | _PAGE_NO_READ | \ _page_cachable_default) #define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_WRITE | \ @@ -414,8 +423,6 @@ static inline pte_t pte_mkyoung(pte_t pte) return pte; } -#define pte_sw_mkyoung pte_mkyoung - #ifdef CONFIG_MIPS_HUGE_TLB_SUPPORT static inline int pte_huge(pte_t pte) { return pte_val(pte) & _PAGE_HUGE; } diff --git a/arch/mips/mm/cache.c b/arch/mips/mm/cache.c index ad6df1c..f814e43 100644 --- a/arch/mips/mm/cache.c +++ b/arch/mips/mm/cache.c @@ -158,23 +158,23 @@ void __update_cache(unsigned long address, pte_t pte) static inline void setup_protection_map(void) { if (cpu_has_rixi) { - protection_map[0] = __pgprot(_page_cachable_default | _PAGE_PRESENT | _PAGE_NO_EXEC | _PAGE_NO_READ); - protection_map[1] = __pgprot(_page_cachable_default | _PAGE_PRESENT | _PAGE_NO_EXEC); - protection_map[2] = __pgprot(_page_cachable_default | _PAGE_PRESENT | _PAGE_NO_EXEC | _PAGE_NO_READ); - protection_map[3] = __pgprot(_page_cachable_default | _PAGE_PRESENT | _PAGE_NO_EXEC); - protection_map[4] = __pgprot(_page_cachable_default | _PAGE_PRESENT); - protection_map[5] = __pgprot(_page_cachable_default | _PAGE_PRESENT); - protection_map[6] = __pgprot(_page_cachable_default | _PAGE_PRESENT); - protection_map[7] = __pgprot(_page_cachable_default | _PAGE_PRESENT); - - protection_map[8] = __pgprot(_page_cachable_default | _PAGE_PRESENT | _PAGE_NO_EXEC | _PAGE_NO_READ); - protection_map[9] = __pgprot(_page_cachable_default | _PAGE_PRESENT | _PAGE_NO_EXEC); - protection_map[10] = __pgprot(_page_cachable_default | _PAGE_PRESENT | _PAGE_NO_EXEC | _PAGE_WRITE | _PAGE_NO_READ); - protection_map[11] = __pgprot(_page_cachable_default | _PAGE_PRESENT | _PAGE_NO_EXEC | _PAGE_WRITE); - protection_map[12] = __pgprot(_page_cachable_default | _PAGE_PRESENT); - protection_map[13] = __pgprot(_page_cachable_default | _PAGE_PRESENT); - protection_map[14] = __pgprot(_page_cachable_default | _PAGE_PRESENT | _PAGE_WRITE); - protection_map[15] = __pgprot(_page_cachable_default | _PAGE_PRESENT | _PAGE_WRITE); + protection_map[0] = __pgprot(__PC | __PP | __NX | __NR); + protection_map[1] = __pgprot(__PC | __PP | __NX | ___R); + protection_map[2] = __pgprot(__PC | __PP | __NX | __NR); + protection_map[3] = __pgprot(__PC | __PP | __NX | ___R); + protection_map[4] = __pgprot(__PC | __PP | ___R); + protection_map[5] = __pgprot(__PC | __PP | ___R); + protection_map[6] = __pgprot(__PC | __PP | ___R); + protection_map[7] = __pgprot(__PC | __PP | ___R); + + protection_map[8] = __pgprot(__PC | __PP | __NX | __NR); + protection_map[9] = __pgprot(__PC | __PP | __NX | ___R); + protection_map[10] = __pgprot(__PC | __PP | __NX | ___W | __NR); + protection_map[11] = __pgprot(__PC | __PP | __NX | ___W | ___R); + protection_map[12] = __pgprot(__PC | __PP | ___R); + protection_map[13] = __pgprot(__PC | __PP | ___R); + protection_map[14] = __pgprot(__PC | __PP | ___W | ___R); + protection_map[15] = __pgprot(__PC | __PP | ___W | ___R); } else { protection_map[0] = PAGE_NONE; diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h index b5278ec..fa5c73f 100644 --- a/include/asm-generic/pgtable.h +++ b/include/asm-generic/pgtable.h @@ -244,22 +244,6 @@ static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addres } #endif -/* - * On some architectures hardware does not set page access bit when accessing - * memory page, it is responsibilty of software setting this bit. It brings - * out extra page fault penalty to track page access bit. For optimization page - * access bit can be set during all page fault flow on these arches. - * To be differentiate with macro pte_mkyoung, this macro is used on platforms - * where software maintains page access bit. - */ -#ifndef pte_sw_mkyoung -static inline pte_t pte_sw_mkyoung(pte_t pte) -{ - return pte; -} -#define pte_sw_mkyoung pte_sw_mkyoung -#endif - #ifndef pte_savedwrite #define pte_savedwrite pte_write #endif diff --git a/mm/memory.c b/mm/memory.c index c7c8960..8bb31c4 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -2704,7 +2704,6 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) } flush_cache_page(vma, vmf->address, pte_pfn(vmf->orig_pte)); entry = mk_pte(new_page, vma->vm_page_prot); - entry = pte_sw_mkyoung(entry); entry = maybe_mkwrite(pte_mkdirty(entry), vma); /* * Clear the pte entry and flush it first, before updating the @@ -3379,7 +3378,6 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) __SetPageUptodate(page); entry = mk_pte(page, vma->vm_page_prot); - entry = pte_sw_mkyoung(entry); if (vma->vm_flags & VM_WRITE) entry = pte_mkwrite(pte_mkdirty(entry)); @@ -3662,7 +3660,6 @@ vm_fault_t alloc_set_pte(struct vm_fault *vmf, struct mem_cgroup *memcg, flush_icache_page(vma, page); entry = mk_pte(page, vma->vm_page_prot); - entry = pte_sw_mkyoung(entry); if (write) entry = maybe_mkwrite(pte_mkdirty(entry), vma); /* copy-on-write page */