Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp648180ybl; Fri, 31 Jan 2020 05:36:08 -0800 (PST) X-Google-Smtp-Source: APXvYqzo3vGQaLTe0y99vOqDMXqJhPRmSvYxtxDCmifDp3MZ2xbwVknbi3jnnARoyUjtyJuMNlhN X-Received: by 2002:a9d:268:: with SMTP id 95mr7718029otb.183.1580477768535; Fri, 31 Jan 2020 05:36:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580477768; cv=none; d=google.com; s=arc-20160816; b=IV4L0LO2GpTmcns5b+YjeIngkylXP01yZxnlS++bgcGrqr/ZOf/VSGV1lfKGWnhfh8 JAXlSLPGVqULxq8AHtMmvE/Q0e+TU1R1IbdPayWBFl4tsPJ3LDZPBjurVw3Ork+2IuuH rRBGtk9YetWJqEXdrlysAMoyjaxgILYJSe8QhtR49xwxdhvy+p4ojfqxYDFR6ETJ9Ivv Q+DeCCpfTimxV5KtB9EYqFC/5wguzYvPOQduFnB7AuFo5WfB1WLPYLa70H20Av853aBU 1NzIPWrzkU3u6myffj5R4yj6gTYOAR0xbo0T/6JiJbg56piVky+ue6SKcUoSWZW5LErc 9RiA== 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=+Y0PaYkFrqDzJi1Ln3AX9oehwDcMeZVtP5iNC1ylbdQ=; b=wN3PqYXLJ1BjykSSp8C+LDXYxF2Mf3Y9akD92iLLXXEArbgi7S9Keyrh8Fj6Q6JDH0 HZAr2nwGfHy/nxo2y/WpW1VPEiL2NTEfMpKHsbvPEOrCSvByLVUjuWGBZq/bfaR8Emg0 htYL0kOxQ4So9VvyGknNvLtggFLzy9y8RWWqvRSyFY9mPOwvBXdmC13XpZCVyYih8D2W irVwPbUDJtB9JuyHzZJggt+i5nMgeY4G5+si3HQTV2P6CTdmtP5eRjzc2J6qEo30qSvi OF9c61XdO5TfIhGyCDCFKP3VnOAUluYec0ToV2bvYrujlApySeV65krUfkXRO4Gs/Rzi ATMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b="D16EjVD/"; 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 q202si4354278oic.160.2020.01.31.05.35.56; Fri, 31 Jan 2020 05:36:08 -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="D16EjVD/"; 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 S1728822AbgAaNe6 (ORCPT + 99 others); Fri, 31 Jan 2020 08:34:58 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:34808 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728788AbgAaNe4 (ORCPT ); Fri, 31 Jan 2020 08:34:56 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 488J9n3llLzB09ZH; Fri, 31 Jan 2020 14:34:53 +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=D16EjVD/; 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 Oim7FYvWxMRI; Fri, 31 Jan 2020 14:34:53 +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 488J9n2hB5zB09ZG; Fri, 31 Jan 2020 14:34:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1580477693; bh=+Y0PaYkFrqDzJi1Ln3AX9oehwDcMeZVtP5iNC1ylbdQ=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=D16EjVD/UOY6pt3bc3ip97cp5iPn/mhD+7hxinHXQrnRcP6MrSCuwsHC2D6wxa7y9 dTp8vL/OoP/VgemS0TtUX/zg7gzmCnN3gjV21zWuBP20lu2YHWtJSUQWO0+bqfWJwr vyECgDzpRUah6Xt/NMOirTRCAJHfXmHIzm/5Coa0= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id AEE908B8AC; Fri, 31 Jan 2020 14:34:54 +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 Ko0s9s0Lw_7w; Fri, 31 Jan 2020 14:34:54 +0100 (CET) Received: from po14934vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.230.105]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 792E48B8A2; Fri, 31 Jan 2020 14:34:54 +0100 (CET) Received: by po14934vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 71AF165288; Fri, 31 Jan 2020 13:34:54 +0000 (UTC) Message-Id: In-Reply-To: <84be5ad6a996adf5693260749dcb4d8c69182073.1580477672.git.christophe.leroy@c-s.fr> References: <84be5ad6a996adf5693260749dcb4d8c69182073.1580477672.git.christophe.leroy@c-s.fr> From: Christophe Leroy Subject: [PATCH v2 6/7] powerpc/mm: implement 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: Fri, 31 Jan 2020 13:34:54 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In addition to the set_memory_xx() functions which allows to change the memory attributes of not (yet) used memory regions, implement a set_memory_attr() function to: - set the final memory protection after init on currently used kernel regions. - enable/disable kernel memory regions in the scope of DEBUG_PAGEALLOC. Unlike the set_memory_xx() which can act in three step as the regions are unused, this function must modify 'on the fly' as the kernel is executing from them. At the moment only PPC32 will use it and changing page attributes on the fly is not an issue. Signed-off-by: Christophe Leroy --- v2: new --- arch/powerpc/include/asm/set_memory.h | 2 ++ arch/powerpc/mm/pageattr.c | 33 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/arch/powerpc/include/asm/set_memory.h b/arch/powerpc/include/asm/set_memory.h index c3621030a3fb..4dadff67e265 100644 --- a/arch/powerpc/include/asm/set_memory.h +++ b/arch/powerpc/include/asm/set_memory.h @@ -29,4 +29,6 @@ static inline int set_memory_x(unsigned long addr, int numpages) return change_memory_attr(addr, numpages, SET_MEMORY_X); } +int set_memory_attr(unsigned long addr, int numpages, pgprot_t prot); + #endif diff --git a/arch/powerpc/mm/pageattr.c b/arch/powerpc/mm/pageattr.c index 0cb5294732b7..dff6c92cd09b 100644 --- a/arch/powerpc/mm/pageattr.c +++ b/arch/powerpc/mm/pageattr.c @@ -72,3 +72,36 @@ int change_memory_attr(unsigned long addr, int numpages, int action) return apply_to_page_range(&init_mm, start, sz, change_page_attr, (void *)action); } + +/* + * Set the attributes of a page: + * + * This function is used by PPC32 at the end of init to set final kernel memory + * protection. It includes changing the maping of the page it is executing from + * and data pages it is using. + */ +static int set_page_attr(pte_t *ptep, unsigned long addr, void *data) +{ + pgprot_t prot = __pgprot((int)data); + + spin_lock(&init_mm.page_table_lock); + + set_pte_at(&init_mm, addr, ptep, pte_modify(*ptep, prot)); + flush_tlb_kernel_range(addr, addr + PAGE_SIZE); + + spin_unlock(&init_mm.page_table_lock); + + return 0; +} + +int set_memory_attr(unsigned long addr, int numpages, pgprot_t prot) +{ + unsigned long start = ALIGN_DOWN(addr, PAGE_SIZE); + unsigned long sz = numpages * PAGE_SIZE; + + if (!numpages) + return 0; + + return apply_to_page_range(&init_mm, start, sz, set_page_attr, + (void *)pgprot_val(prot)); +} -- 2.25.0