Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3473968ybl; Mon, 3 Feb 2020 00:42:50 -0800 (PST) X-Google-Smtp-Source: APXvYqyAPsqdVm1OUYNs8TLnW4gKY8rCQ+bHEVgIi80ekuwtigITOtG5fIaKOx2++XvskxbKPnxY X-Received: by 2002:a05:6830:13d9:: with SMTP id e25mr16508781otq.134.1580719370236; 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=X7s1k6IdhNNDj6Xr1GsUzLR6lMaa/OnjZequW/wZgJui5go4Fj+TZy+vtZ3an8puzV 0+Vd+28FYXTuhSStS7FpG0BP91zKHNcxLg9yaOXX6RHuiyXL5GvsRtGIN7+2bR1tgnwa NYndVwLXzUoT/dofitL9Vm4A4/+JKmyNqYBvucpzx/rrMpOvb9cIFR0jbl9E5Kpr7E5Y V3TdSH8NfGZGQEVE6osavhGG61btlFzgVyZ1KKlS4k4wLnIZy9/d3eahT8JtFTE72mWE YASzdzrlB151pWtHZgchGurzY17KWPbRzkfzLgAedfE65iGF3L2dJrzKTHu0eb3Tjk+I AvXw== 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=DtC3RdmXsxo4ZHGbWfOkGtSF1VeGnSXJE1zivz0gRcg=; b=MYQoaOz0Y8/mXa4kjGu854xpRbl+UU/1TBtO4XEoEMs3bd5HwgB+mLvENyh6FJWtGX tQnkG2VLG8z2kwU31e2EDG6fkYNOfagepwr2LO9DAvznAcPk9Y40qy0lOIJJk1XniMEM nEHZ9rXPJx6dfp8XCls1l0IsG4Uv8NU2XxHGtAHhLqnaAMQ5Q7NM9mTGCZb7G0iG3OyK QpvUj4KEYHERNNwjfKdZOTHnR+2pUttTg5UnHSJIOodY3ZW33yRnblOjJNaIRHXLIEwP qm5njrgc1KQ8b6gW03Erz1kUbqGNX+4oYbTfNil2FzXF9pT77lsMDIp0Ps1bK3rYx2iL rQNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=TFRPAwHi; 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 u12si7899589oiv.13.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=TFRPAwHi; 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 S1727684AbgBCHMF (ORCPT + 99 others); Mon, 3 Feb 2020 02:12:05 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:5246 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727652AbgBCHME (ORCPT ); Mon, 3 Feb 2020 02:12:04 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 489zXY5myfz9tyK0; Mon, 3 Feb 2020 08:11:57 +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=TFRPAwHi; 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 qxF730EMfxaN; Mon, 3 Feb 2020 08:11:57 +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 489zXY4mFnz9tyJn; Mon, 3 Feb 2020 08:11:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1580713917; bh=DtC3RdmXsxo4ZHGbWfOkGtSF1VeGnSXJE1zivz0gRcg=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=TFRPAwHiAJ2CRpID91pNonmwJgwc9hX+u7Le3Hr9WzqfkMK6lG1hCqTBvA6sIxsWQ 9jzPHkEZ6oIr55ls//Fehjv9FpwQWiPPDj/qETxpeowFNOghWItIfylDUeBkrQu7PP Ef6xDPVjON5Pvy04cHis7cAA2SlEAC6M37EIWeWs= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 3920A8B791; Mon, 3 Feb 2020 08:12:02 +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 bOU-TGH54_M2; Mon, 3 Feb 2020 08:12:02 +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 158AF8B752; Mon, 3 Feb 2020 08:12:02 +0100 (CET) Received: by po14934vm.idsi0.si.c-s.fr (Postfix, from userid 0) id CCBB0652AD; Mon, 3 Feb 2020 07:12:01 +0000 (UTC) Message-Id: <4a78ee8a7b954de0cfd44bd72b1b39c6fe34dc45.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 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: Mon, 3 Feb 2020 07:12:01 +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 --- v3: no change 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 64011ea444b4..b040094f7920 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 2b573768a7f7..b78a2a656dea 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, long 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