From 61311e5672a0105db0df0c9801c14e2fb832ea6c Mon Sep 17 00:00:00 2001 From: Shiraz Hashim Date: Fri, 11 Aug 2017 17:49:28 +0530 Subject: [PATCH] arm: provision page alloc debug support Equip arm to support ARCH_SUPPORTS_DEBUG_PAGEALLOC and enable it by default. Having this support means all pages freed at buddy level would be marked as read-only and would help catch any scribbling over free page area. Allocated pages mapping attributes is restored to read/write. ARCH_SUPPORTS_DEBUG_PAGEALLOC needs FORCE_PAGES which ensures all kernel mapping are populated with page granularity and it would ensure page level accesses can be rightly configured. Change-Id: I9b23d1fb0b9594cc148b082c104da9a773c26057 Signed-off-by: Shiraz Hashim Signed-off-by: Charan Teja Reddy Signed-off-by: Vijayanand Jitta Signed-off-by: Qingqing Zhou --- arch/arm/Kconfig.debug | 4 ++++ arch/arm/mm/pageattr.c | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/arch/arm/Kconfig.debug b/arch/arm/Kconfig.debug index 88bc14fde8c4..f7a66fd143fd 100644 --- a/arch/arm/Kconfig.debug +++ b/arch/arm/Kconfig.debug @@ -99,6 +99,10 @@ config DEBUG_USER 8 - SIGSEGV faults 16 - SIGBUS faults +config ARCH_SUPPORTS_DEBUG_PAGEALLOC + def_bool y + depends on FORCE_PAGES + config FORCE_PAGES bool "Force lowmem to be mapped with 4K pages" help diff --git a/arch/arm/mm/pageattr.c b/arch/arm/mm/pageattr.c index ee3d2cc59106..e3056af25546 100644 --- a/arch/arm/mm/pageattr.c +++ b/arch/arm/mm/pageattr.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2014, The Linux Foundation. All rights reserved. + * Copyright (c) 2014,2017-2018 The Linux Foundation. All rights reserved. */ #include #include @@ -89,3 +89,19 @@ int set_memory_x(unsigned long addr, int numpages) __pgprot(0), __pgprot(L_PTE_XN)); } + +#ifdef CONFIG_ARCH_SUPPORTS_DEBUG_PAGEALLOC +void __kernel_map_pages(struct page *page, int numpages, int enable) +{ + unsigned long addr; + + if (PageHighMem(page)) + return; + + addr = (unsigned long) page_address(page); + if (enable) + set_memory_rw(addr, numpages); + else + set_memory_ro(addr, numpages); +} +#endif