Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3473969ybl; Mon, 3 Feb 2020 00:42:50 -0800 (PST) X-Google-Smtp-Source: APXvYqyBPxtfAHDxpUd6oHy+Wz+a/X+1FT06nDZjME3R2WT7fAUZ+AnATw+rdxSvcQ0UQeSWllxA X-Received: by 2002:a9d:68c8:: with SMTP id i8mr17764321oto.34.1580719370270; Mon, 03 Feb 2020 00:42:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580719370; cv=none; d=google.com; s=arc-20160816; b=Kec8Lv41qXz9NoK0KMY5V7I2O3KeRbWZGeuKa7RIz6eVB6LD7NbYNOkVgDgxAo6vl3 NASGZL84/znqz1v0AvhTkjZ+AfdsMkrwhypGZJ/rcNMoGb0oigfzQissFc316lBIOGzM kKujPDLSKumMnNYXeUICc6qa0MivX7000kYo4baWbRfGKzPfcMBESUz2WmJzxJrywpLD L/PK68t9BnIbADWiuZUzkqodch5iRaEJt+f0IFUwoOTPAFGICjtVoITMMlaDC8OIaQ0g MVJT6ybQkjlNUeXwONboLvZsSMO4nns+9px++TTNwsCPnNNOjILPQZbI5iG+GDOaYPvV My0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:cc:to:subject:from:references :in-reply-to:message-id:dkim-signature; bh=vbwUE7eW4n0CeytBw4h62e+GSLr21YOno7Doo4/25XY=; b=VK+KdK3ZMvJv+3g2C8Hghm2XFiGeknrxXUaujynCuedh3TKo7R3JyTgETFgZ/wNSq7 2AO2fMEgEb2bQaWCjvIkR/EOJyxN1RahFYB05MuxN9HXGMr9yOeGWp4CbpFGgw4GOHEY 29B1I9Wy0vjJ6pQOCWrqsbJZWaX9uNw6obHLPESp4FZeKFe6FobVDt7hZaHWfmLgQJU9 HHUHuY1gHdtr39tw+zepyBIcZZiEoBzD+fwcATMH/xGUS3i6Cz7fEjBTlBTCoEv5mkmw 5CgkHN9b7TuvfBBFvP5j8RfIgRGIXnFkkGHFeCqetIaUNC3G0gYIUTLxhYsvzZAc7px0 HwFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=I74dLGoO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p71si8185724oic.138.2020.02.03.00.42.37; Mon, 03 Feb 2020 00:42:50 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=I74dLGoO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727697AbgBCHMH (ORCPT + 99 others); Mon, 3 Feb 2020 02:12:07 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:41044 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727672AbgBCHMF (ORCPT ); Mon, 3 Feb 2020 02:12:05 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 489zXb1x5qz9tyK1; Mon, 3 Feb 2020 08:11:59 +0100 (CET) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=I74dLGoO; dkim-adsp=pass; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id sUBt5xgKkoR0; Mon, 3 Feb 2020 08:11:59 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 489zXb0v4Mz9tyJn; Mon, 3 Feb 2020 08:11:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1580713919; bh=vbwUE7eW4n0CeytBw4h62e+GSLr21YOno7Doo4/25XY=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=I74dLGoOef61oxp4O27Zd0yae/yQgmSs+jvGSaEg4axpBDSipFybOk1OeV0EL0oyd hLiM4+YyiRPDpQ2DhV/C2CEZpwReIUHFXG8fjMi/5iyGnlS1uyJ10p4TM97ccRHNs8 xgYqOJ6/T6vbhTsI/QoOpjFYW+1fZ/oR9LL0dc9M= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id AE1018B791; Mon, 3 Feb 2020 08:12:03 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id yr0slnhUa4ez; Mon, 3 Feb 2020 08:12:03 +0100 (CET) Received: from po14934vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.230.102]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 874018B752; Mon, 3 Feb 2020 08:12:03 +0100 (CET) Received: by po14934vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 2E04B652AD; Mon, 3 Feb 2020 07:12:02 +0000 (UTC) Message-Id: <6076aaa16f3119a766dc64afa2a039786830d7d0.1580713729.git.christophe.leroy@c-s.fr> In-Reply-To: <80ebd9075cd7c8b412c6d5d05f7542f9026642ef.1580713729.git.christophe.leroy@c-s.fr> References: <80ebd9075cd7c8b412c6d5d05f7542f9026642ef.1580713729.git.christophe.leroy@c-s.fr> From: Christophe Leroy Subject: [PATCH v3 7/7] powerpc/32: use set_memory_attr() To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , ruscur@russell.cc Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Date: Mon, 3 Feb 2020 07:12:02 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use set_memory_attr() instead of the PPC32 specific change_page_attr() change_page_attr() was checking that the address was not mapped by blocks and was handling highmem, but that's unneeded because the affected pages can't be in highmem and block mapping verification is already done by the callers. Signed-off-by: Christophe Leroy --- v3: no change v2: new --- arch/powerpc/mm/pgtable_32.c | 95 ++++-------------------------------- 1 file changed, 10 insertions(+), 85 deletions(-) diff --git a/arch/powerpc/mm/pgtable_32.c b/arch/powerpc/mm/pgtable_32.c index 5fb90edd865e..3d92eaf3ee2f 100644 --- a/arch/powerpc/mm/pgtable_32.c +++ b/arch/powerpc/mm/pgtable_32.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -121,99 +122,20 @@ void __init mapin_ram(void) } } -/* Scan the real Linux page tables and return a PTE pointer for - * a virtual address in a context. - * Returns true (1) if PTE was found, zero otherwise. The pointer to - * the PTE pointer is unmodified if PTE is not found. - */ -static int -get_pteptr(struct mm_struct *mm, unsigned long addr, pte_t **ptep, pmd_t **pmdp) -{ - pgd_t *pgd; - pud_t *pud; - pmd_t *pmd; - pte_t *pte; - int retval = 0; - - pgd = pgd_offset(mm, addr & PAGE_MASK); - if (pgd) { - pud = pud_offset(pgd, addr & PAGE_MASK); - if (pud && pud_present(*pud)) { - pmd = pmd_offset(pud, addr & PAGE_MASK); - if (pmd_present(*pmd)) { - pte = pte_offset_map(pmd, addr & PAGE_MASK); - if (pte) { - retval = 1; - *ptep = pte; - if (pmdp) - *pmdp = pmd; - /* XXX caller needs to do pte_unmap, yuck */ - } - } - } - } - return(retval); -} - -static int __change_page_attr_noflush(struct page *page, pgprot_t prot) -{ - pte_t *kpte; - pmd_t *kpmd; - unsigned long address; - - BUG_ON(PageHighMem(page)); - address = (unsigned long)page_address(page); - - if (v_block_mapped(address)) - return 0; - if (!get_pteptr(&init_mm, address, &kpte, &kpmd)) - return -EINVAL; - __set_pte_at(&init_mm, address, kpte, mk_pte(page, prot), 0); - pte_unmap(kpte); - - return 0; -} - -/* - * Change the page attributes of an page in the linear mapping. - * - * THIS DOES NOTHING WITH BAT MAPPINGS, DEBUG USE ONLY - */ -static int change_page_attr(struct page *page, int numpages, pgprot_t prot) -{ - int i, err = 0; - unsigned long flags; - struct page *start = page; - - local_irq_save(flags); - for (i = 0; i < numpages; i++, page++) { - err = __change_page_attr_noflush(page, prot); - if (err) - break; - } - wmb(); - local_irq_restore(flags); - flush_tlb_kernel_range((unsigned long)page_address(start), - (unsigned long)page_address(page)); - return err; -} - void mark_initmem_nx(void) { - struct page *page = virt_to_page(_sinittext); unsigned long numpages = PFN_UP((unsigned long)_einittext) - PFN_DOWN((unsigned long)_sinittext); if (v_block_mapped((unsigned long)_stext + 1)) mmu_mark_initmem_nx(); else - change_page_attr(page, numpages, PAGE_KERNEL); + set_memory_attr((unsigned long)_sinittext, numpages, PAGE_KERNEL); } #ifdef CONFIG_STRICT_KERNEL_RWX void mark_rodata_ro(void) { - struct page *page; unsigned long numpages; if (v_block_mapped((unsigned long)_sinittext)) { @@ -222,20 +144,18 @@ void mark_rodata_ro(void) return; } - page = virt_to_page(_stext); numpages = PFN_UP((unsigned long)_etext) - PFN_DOWN((unsigned long)_stext); - change_page_attr(page, numpages, PAGE_KERNEL_ROX); + set_memory_attr((unsigned long)_stext, numpages, PAGE_KERNEL_ROX); /* * mark .rodata as read only. Use __init_begin rather than __end_rodata * to cover NOTES and EXCEPTION_TABLE. */ - page = virt_to_page(__start_rodata); numpages = PFN_UP((unsigned long)__init_begin) - PFN_DOWN((unsigned long)__start_rodata); - change_page_attr(page, numpages, PAGE_KERNEL_RO); + set_memory_attr((unsigned long)__start_rodata, numpages, PAGE_KERNEL_RO); // mark_initmem_nx() should have already run by now ptdump_check_wx(); @@ -245,9 +165,14 @@ void mark_rodata_ro(void) #ifdef CONFIG_DEBUG_PAGEALLOC void __kernel_map_pages(struct page *page, int numpages, int enable) { + unsigned long addr = (unsigned long)page_address(page); + if (PageHighMem(page)) return; - change_page_attr(page, numpages, enable ? PAGE_KERNEL : __pgprot(0)); + if (enable) + set_memory_attr(addr, numpages, PAGE_KERNEL); + else + set_memory_attr(addr, numpages, __pgprot(0)); } #endif /* CONFIG_DEBUG_PAGEALLOC */ -- 2.25.0