The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Brian Gerst <bgerst@didntduck.org>
To: Linus Torvalds <torvalds@transmeta.com>
Cc: Linux kernel mailing list <linux-kernel@vger.kernel.org>
Subject: [PATCH] Clean up x86 write protect test
Date: Wed, 26 Sep 2001 21:42:11 -0400	[thread overview]
Message-ID: <3BB283F3.9E9105AC@didntduck.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 262 bytes --]

This patch changes the write protect test to use vmalloc instead of
touching the page tables directly.  As a side effect, this allows the
test to be run on processors supporting page size extensions, exercising
the exception handler code.

-- 

						Brian Gerst

[-- Attachment #2: diff-wp --]
[-- Type: text/plain, Size: 3764 bytes --]

diff -urN linux-2.4.10/arch/i386/kernel/setup.c linux/arch/i386/kernel/setup.c
--- linux-2.4.10/arch/i386/kernel/setup.c	Mon Sep 24 09:24:08 2001
+++ linux/arch/i386/kernel/setup.c	Wed Sep 26 20:58:23 2001
@@ -113,7 +113,7 @@
  */
 
 char ignore_irq13;		/* set if exception 16 works */
-struct cpuinfo_x86 boot_cpu_data = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };
+struct cpuinfo_x86 boot_cpu_data = { 0, 0, 0, 0, 0, 1, 0, 0, -1 };
 
 unsigned long mmu_cr4_features;
 
diff -urN linux-2.4.10/arch/i386/mm/init.c linux/arch/i386/mm/init.c
--- linux-2.4.10/arch/i386/mm/init.c	Mon Sep 24 09:24:08 2001
+++ linux/arch/i386/mm/init.c	Wed Sep 26 20:57:59 2001
@@ -246,7 +246,6 @@
 				unsigned long __pe;
 
 				set_in_cr4(X86_CR4_PSE);
-				boot_cpu_data.wp_works_ok = 1;
 				__pe = _KERNPG_TABLE + _PAGE_PSE + __pa(vaddr);
 				/* Make it "global" too if supported */
 				if (cpu_has_pge) {
@@ -373,39 +372,25 @@
 
 /*
  * Test if the WP bit works in supervisor mode. It isn't supported on 386's
- * and also on some strange 486's (NexGen etc.). All 586+'s are OK. The jumps
- * before and after the test are here to work-around some nasty CPU bugs.
+ * and also on some strange 486's (NexGen etc.). All 586+'s are OK.
  */
 
 /*
  * This function cannot be __init, since exceptions don't work in that
  * section.
  */
-static int do_test_wp_bit(unsigned long vaddr);
+static int do_test_wp_bit(int *vaddr);
 
 void __init test_wp_bit(void)
 {
-/*
- * Ok, all PSE-capable CPUs are definitely handling the WP bit right.
- */
-	const unsigned long vaddr = PAGE_OFFSET;
-	pgd_t *pgd;
-	pmd_t *pmd;
-	pte_t *pte, old_pte;
+	int *vaddr;
 
 	printk("Checking if this processor honours the WP bit even in supervisor mode... ");
-
-	pgd = swapper_pg_dir + __pgd_offset(vaddr);
-	pmd = pmd_offset(pgd, vaddr);
-	pte = pte_offset(pmd, vaddr);
-	old_pte = *pte;
-	*pte = mk_pte_phys(0, PAGE_READONLY);
-	local_flush_tlb();
-
+	vaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_READONLY);
+	if (!vaddr)
+		panic("Cannot allocate a read only page.\n");
 	boot_cpu_data.wp_works_ok = do_test_wp_bit(vaddr);
-
-	*pte = old_pte;
-	local_flush_tlb();
+	vfree(vaddr);
 
 	if (!boot_cpu_data.wp_works_ok) {
 		printk("No.\n");
@@ -502,14 +487,11 @@
 	if (!cpu_has_pae)
 		panic("cannot execute a PAE-enabled kernel on a PAE-less CPU!");
 #endif
-	if (boot_cpu_data.wp_works_ok < 0)
-		test_wp_bit();
 
 	/*
 	 * Subtle. SMP is doing it's boot stuff late (because it has to
 	 * fork idle threads) - but it also needs low mappings for the
-	 * protected-mode entry to work. We zap these entries only after
-	 * the WP-bit has been tested.
+	 * protected-mode entry to work.
 	 */
 #ifndef CONFIG_SMP
 	zap_low_mappings();
@@ -518,24 +500,22 @@
 }
 
 /* Put this after the callers, so that it cannot be inlined */
-static int do_test_wp_bit(unsigned long vaddr)
+static int do_test_wp_bit(int *vaddr)
 {
 	char tmp_reg;
 	int flag;
 
 	__asm__ __volatile__(
-		"	movb %0,%1	\n"
-		"1:	movb %1,%0	\n"
-		"	xorl %2,%2	\n"
+		"1:	movl %1,%0	\n"
+		"	xorl %1,%1	\n"
 		"2:			\n"
 		".section __ex_table,\"a\"\n"
 		"	.align 4	\n"
 		"	.long 1b,2b	\n"
 		".previous		\n"
-		:"=m" (*(char *) vaddr),
-		 "=q" (tmp_reg),
+		:"=m" (*vaddr),
 		 "=r" (flag)
-		:"2" (1)
+		:"1" (1)
 		:"memory");
 	
 	return flag;
diff -urN linux-2.4.10/include/asm-i386/bugs.h linux/include/asm-i386/bugs.h
--- linux-2.4.10/include/asm-i386/bugs.h	Wed Sep 26 19:25:21 2001
+++ linux/include/asm-i386/bugs.h	Wed Sep 26 20:57:59 2001
@@ -202,6 +202,8 @@
 #endif
 }
 
+extern void __init test_wp_bit(void);
+
 static void __init check_bugs(void)
 {
 	identify_cpu(&boot_cpu_data);
@@ -210,6 +212,7 @@
 	print_cpu_info(&boot_cpu_data);
 #endif
 	check_config();
+	test_wp_bit();
 	check_fpu();
 	check_hlt();
 	check_popad();

                 reply	other threads:[~2001-09-27  1:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3BB283F3.9E9105AC@didntduck.org \
    --to=bgerst@didntduck.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox