Skip to contentSkip to conversation

x86: Add testcases for RODATA and NX protections/attributes

PATCH New Arjan van de Ven 1 participant 1 message Jan 23, 2008

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 x86: Add testcases for RODATA and NX protections/attributes

Subject: x86: Add testcases for RODATA and NX protections/attributes
From: Arjan van de Ven <[email protected]>

This patch adds testcases for the CONFIG_DEBUG_RODATA configuration option as well as the NX CPU feature/mappings. Both testcases can move to tests/ once that patch gets merged into mainline.
(I'm half considering moving the rodata test into mm/init.c but I'll wait with that until init.c is unified)

As part of this I had to fix a not-quite-right alignment in the vmlinux.lds.h for the RODATA sections, which lead to 1 page less being marked read only.

---
 arch/x86/Kconfig.debug            |   16 +++
 arch/x86/kernel/Makefile_32       |    2 
 arch/x86/kernel/Makefile_64       |    3 
 arch/x86/kernel/test_nx.c         |  179 ++++++++++++++++++++++++++++++++++++++
 arch/x86/kernel/test_rodata.c     |   81 +++++++++++++++++
 arch/x86/mm/init_32.c             |    2 
 arch/x86/mm/init_64.c             |    2 
 include/asm-generic/vmlinux.lds.h |    1 
 include/asm-x86/cacheflush.h      |    7 +
 9 files changed, 292 insertions(+), 1 deletion(-)
arch/x86/Kconfig.debug +16 -0
Index: linux-2.6.24-rc8/arch/x86/Kconfig.debug
===================================================================
@@ -57,6 +57,22 @@ config DEBUG_RODATA
 	  portion of the kernel code won't be covered by a 2MB TLB anymore.
 	  If in doubt, say "N".
 
+config DEBUG_RODATA_TEST
+	bool "Testcase for the DEBUG_RODATA feature"
+	depends on DEBUG_RODATA
+	help
+	  This option enables a testcase for the DEBUG_RODATA
+	  feature as well as for the change_page_attr() infrastructure.
+	  If in doubt, say "N"
+
+config DEBUG_NX_TEST
+	tristate "Testcase for the NX non-executable stack feature"
+	depends on DEBUG_KERNEL && m
+	help
+	  This option enables a testcase for the CPU NX capability
+	  and the software setup of this feature.
+	  If in doubt, say "N"
+
 config 4KSTACKS
 	bool "Use 4Kb for kernel stacks instead of 8Kb"
 	depends on DEBUG_KERNEL
arch/x86/kernel/Makefile_32 +2 -0
Index: linux-2.6.24-rc8/arch/x86/kernel/Makefile_32
===================================================================
@@ -42,6 +42,8 @@ obj-$(CONFIG_EARLY_PRINTK)	+= early_prin
 obj-$(CONFIG_HPET_TIMER) 	+= hpet.o
 obj-$(CONFIG_K8_NB)		+= k8.o
 obj-$(CONFIG_MGEODE_LX)		+= geode_32.o mfgpt_32.o
+obj-$(CONFIG_DEBUG_RODATA_TEST)	+= test_rodata.o
+obj-$(CONFIG_DEBUG_NX_TEST)	+= test_nx.o
 
 obj-$(CONFIG_VMI)		+= vmi_32.o vmiclock_32.o
 obj-$(CONFIG_PARAVIRT)		+= paravirt_32.o
arch/x86/kernel/Makefile_64 +3 -0
Index: linux-2.6.24-rc8/arch/x86/kernel/Makefile_64
===================================================================
@@ -39,6 +39,9 @@ obj-$(CONFIG_AUDIT)		+= audit_64.o
 obj-$(CONFIG_MODULES)		+= module_64.o
 obj-$(CONFIG_PCI)		+= early-quirks.o
 
+obj-$(CONFIG_DEBUG_RODATA_TEST)	+= test_rodata.o
+obj-$(CONFIG_DEBUG_NX_TEST)	+= test_nx.o
+
 obj-y				+= topology.o
 obj-y				+= pcspeaker.o
 
arch/x86/kernel/test_nx.c new file +179 -0

179 lines not on this page · raw message

arch/x86/kernel/test_rodata.c new file +81 -0

81 lines not on this page · raw message

arch/x86/mm/init_32.c +2 -0
Index: linux-2.6.24-rc8/arch/x86/mm/init_32.c
===================================================================
@@ -789,6 +789,7 @@ static int noinline do_test_wp_bit(void)
 }
 
 #ifdef CONFIG_DEBUG_RODATA
+const int rodata_test_data = 5;
 
 void mark_rodata_ro(void)
 {
@@ -820,6 +821,7 @@ void mark_rodata_ro(void)
 	 * of who is the culprit.
 	 */
 	global_flush_tlb();
+	rodata_test();
 }
 #endif
 
arch/x86/mm/init_64.c +2 -0
Index: linux-2.6.24-rc8/arch/x86/mm/init_64.c
===================================================================
@@ -589,6 +589,7 @@ void free_initmem(void)
 }
 
 #ifdef CONFIG_DEBUG_RODATA
+const int rodata_test_data = 5;
 
 void mark_rodata_ro(void)
 {
@@ -622,6 +623,7 @@ void mark_rodata_ro(void)
 	 * of who is the culprit.
 	 */
 	global_flush_tlb();
+	rodata_test();
 }
 #endif
 
include/asm-x86/cacheflush.h +6 -1
Index: linux-2.6.24-rc8/include/asm-x86/cacheflush.h
===================================================================
@@ -34,8 +34,13 @@ void clflush_cache_range(void *addr, int
 void kernel_map_pages(struct page *page, int numpages, int enable);
 #endif
 
-#ifdef CONFIG_DEBUG_RODATA
 void mark_rodata_ro(void);
+#ifdef CONFIG_DEBUG_RODATA_TEST
+void rodata_test(void);
+#else
+static inline void rodata_test(void)
+{
+}
 #endif
 
 #endif
include/asm-generic/vmlinux.lds.h +1 -0
Index: linux-2.6.24-rc8/include/asm-generic/vmlinux.lds.h
===================================================================
@@ -137,6 +137,7 @@
 		VMLINUX_SYMBOL(__start___param) = .;			\
 		*(__param)						\
 		VMLINUX_SYMBOL(__stop___param) = .;			\
+		. = ALIGN((align));					\
 		VMLINUX_SYMBOL(__end_rodata) = .;			\
 	}								\
 									\
Signature · 3 lines
If you want to reach me at my work email, use [email protected]
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org