public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Zachary Amsden <zach@vmware.com>
To: Andi Kleen <ak@muc.de>
Cc: linux-kernel@vger.kernel.org, Riley@Williams.Name,
	davej@codemonkey.org.uk, hpa@zytor.com,
	Linus Torvalds <torvalds@osdl.org>
Subject: Re: [PATCH] i386/gcc bug with do_test_wp_bit
Date: Wed, 06 Oct 2004 12:34:00 -0700	[thread overview]
Message-ID: <416448A8.5040305@vmware.com> (raw)
In-Reply-To: <20041006115550.GA58628@muc.de>

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

Confirmed.  As Andi says, sorting the exception table does fix the problem.  Tested 2.6.9-rc3 with gcc 3.3.3 and there are no issues.  My major malfunction was working on an older 2.6 kernel and believing the patches were still relevant.  Linus, please revert the following commit, it is no longer needed and do_test_wp_bit is better inlined into __init and subsequently discarded now that exceptions in __init work.

I've added a nicer patch that inlines the do_test_wp_bit function and deprecates the outdated comment.

Zach


# This is a BitKeeper generated diff -Nru style patch.
#
# ChangeSet
#   2004/10/05 18:51:53-07:00 torvalds@evo.osdl.org 
#   i386: mark do_test_wp_bit() noinline
#   
#   As reported by Zachary Amsden <zach@vmware.com>,
#   some gcc versions will inline the function even when
#   it is declared after the call-site. This particular
#   function must not be inlined, since the exception
#   recovery doesn't like __init sections (which the caller
#   is in).
# 
# arch/i386/mm/init.c
#   2004/10/05 18:51:43-07:00 torvalds@evo.osdl.org +2 -2
#   i386: mark do_test_wp_bit() noinline
#   
#   As reported by Zachary Amsden <zach@vmware.com>,
#   some gcc versions will inline the function even when
#   it is declared after the call-site. This particular
#   function must not be inlined, since the exception
#   recovery doesn't like __init sections (which the caller
#   is in).
# 
diff -Nru a/arch/i386/mm/init.c b/arch/i386/mm/init.c
--- a/arch/i386/mm/init.c	2004-10-05 19:04:53 -07:00
+++ b/arch/i386/mm/init.c	2004-10-05 19:04:53 -07:00
@@ -45,7 +45,7 @@
 DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
 unsigned long highstart_pfn, highend_pfn;
 
-static int do_test_wp_bit(void);
+static int noinline do_test_wp_bit(void);
 
 /*
  * Creates a middle page table and puts a pointer to it in the
@@ -673,7 +673,7 @@
  * This function cannot be __init, since exceptions don't work in that
  * section.  Put this after the callers, so that it cannot be inlined.
  */
-static int do_test_wp_bit(void)
+static int noinline do_test_wp_bit(void)
 {
 	char tmp_reg;
 	int flag;


Andi Kleen wrote:

>On Tue, Oct 05, 2004 at 06:45:05PM -0700, Zachary Amsden wrote:
>  
>
>>Playing around with gcc 3.3.3, I compiled a 2.6 series kernel for i386 
>>and discovered it panics on boot.  The problem was gcc 3.3.3 can inline 
>>functions even if declared after their call sites.  This causes i386 to 
>>not boot, since do_test_wp_bit() must not exist in the __init section.  
>>Similar problems may exist in the boot code for other architectures, but 
>>I can't confirm that at this time.  x86_64 is not affected.
>>    
>>
>
>That should have been fixed long ago by sorting the exception
>table. I checked and the code is still there: 
>
>asmlinkage void __init start_kernel(void)
>{
>	...
>        sort_main_extable();
>
>
>Something must be rotten in your setup. I definitely don't see the
>same problems with a unit-at-a-time 3.3 gcc. 
>
>Can you double check that the sort is really done?
>
>The patch is imho not needed.
>
>-Andi
>  
>


[-- Attachment #2: i386-wp-bit.patch --]
[-- Type: text/plain, Size: 1841 bytes --]

diff -ru linux-2.6.9-rc3/arch/i386/mm/init.c linux-2.6.9-rc3-za1/arch/i386/mm/init.c
--- linux-2.6.9-rc3/arch/i386/mm/init.c	2004-10-05 18:21:03.000000000 -0700
+++ linux-2.6.9-rc3-za1/arch/i386/mm/init.c	2004-10-06 12:26:03.000000000 -0700
@@ -45,8 +45,6 @@
 DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
 unsigned long highstart_pfn, highend_pfn;
 
-static int do_test_wp_bit(void);
-
 /*
  * Creates a middle page table and puts a pointer to it in the
  * given global directory entry. This only returns the gd entry
@@ -525,6 +523,28 @@
  * used to involve black magic jumps to work around some nasty CPU bugs,
  * but fortunately the switch to using exceptions got rid of all that.
  */
+static inline int do_test_wp_bit(void)
+{
+	char tmp_reg;
+	int flag;
+
+	__asm__ __volatile__(
+		"	movb %0,%1	\n"
+		"1:	movb %1,%0	\n"
+		"	xorl %2,%2	\n"
+		"2:			\n"
+		".section __ex_table,\"a\"\n"
+		"	.align 4	\n"
+		"	.long 1b,2b	\n"
+		".previous		\n"
+		:"=m" (*(char *)fix_to_virt(FIX_WP_TEST)),
+		 "=q" (tmp_reg),
+		 "=r" (flag)
+		:"2" (1)
+		:"memory");
+	
+	return flag;
+}
 
 void __init test_wp_bit(void)
 {
@@ -669,33 +689,6 @@
 		panic("pgtable_cache_init(): Cannot create pgd cache");
 }
 
-/*
- * This function cannot be __init, since exceptions don't work in that
- * section.  Put this after the callers, so that it cannot be inlined.
- */
-static int do_test_wp_bit(void)
-{
-	char tmp_reg;
-	int flag;
-
-	__asm__ __volatile__(
-		"	movb %0,%1	\n"
-		"1:	movb %1,%0	\n"
-		"	xorl %2,%2	\n"
-		"2:			\n"
-		".section __ex_table,\"a\"\n"
-		"	.align 4	\n"
-		"	.long 1b,2b	\n"
-		".previous		\n"
-		:"=m" (*(char *)fix_to_virt(FIX_WP_TEST)),
-		 "=q" (tmp_reg),
-		 "=r" (flag)
-		:"2" (1)
-		:"memory");
-	
-	return flag;
-}
-
 void free_initmem(void)
 {
 	unsigned long addr;
Only in linux-2.6.9-rc3: .MAINTAINERS.swp

      reply	other threads:[~2004-10-06 19:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-06  1:45 [PATCH] i386/gcc bug with do_test_wp_bit Zachary Amsden
2004-10-06  2:05 ` Linus Torvalds
2004-10-06  3:19   ` Zachary Amsden
2004-10-06 11:55 ` Andi Kleen
2004-10-06 19:34   ` Zachary Amsden [this message]

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=416448A8.5040305@vmware.com \
    --to=zach@vmware.com \
    --cc=Riley@Williams.Name \
    --cc=ak@muc.de \
    --cc=davej@codemonkey.org.uk \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@osdl.org \
    /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