public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
To: Pekka Enberg <penberg@cs.helsinki.fi>,
	Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>,
	"H. Peter Anvin" <hpa@zytor.com>
Cc: Andi Kleen <andi@firstfloor.org>,
	Vegard Nossum <vegard.nossum@gmail.com>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: MCE boot crash in qemu
Date: Wed, 17 Jun 2009 08:57:20 +0200	[thread overview]
Message-ID: <20090617065720.GA4852@elte.hu> (raw)
In-Reply-To: <1245217856.5604.16.camel@penberg-laptop>


* Pekka Enberg <penberg@cs.helsinki.fi> wrote:

> On Mon, 2009-06-15 at 16:22 +0300, Pekka Enberg wrote:
> > On Mon, 2009-06-15 at 14:52 +0200, Andi Kleen wrote:
> > > x86: mce: Handle banks == 0 case in K7 quirk
> > > 
> > > This happens on QEMU which reports MCA capability, but no banks.
> > > Without this patch there is a buffer overrun and boot ops because the code
> > > would try to initialize the 0 element of a zero length kmalloc()
> > > buffer.
> > > 
> > > Signed-off-by: Andi Kleen <ak@linux.intel.com>
> > 
> > This fixes the bug for me!
> > 
> > Tested-by: Pekka Enberg <penberg@cs.helsinki.fi>
> 
> Ingo, I hit this again in my testing after rebasing to 
> linus/master so I really would like this in mainline.

yep, i've tidied up the changelog and have committed it to 
x86/urgent.

But the bank[] code is quirky and butt-ugly and that needs to be 
cleaned up - it's no wonder that bugs like this slip in.

 - There's zero description about the hw model it represents 
   and how it relates to the bank[] array - what do the banks mean, 
   how are they organized.

 - It's full of magic constants and implicitly-assumed size
   calculations with little explanation and little extensibility:

       ...
                if (c->x86 == 15 && banks > 4) {
                        /*
                         * disable GART TBL walk error reporting, which
                         * trips off incorrectly with the IOMMU & 3ware
                         * & Cerberus:
                         */
                        clear_bit(10, (unsigned long *)&bank[4]);
                }
       ...
                bank = kmalloc(banks * sizeof(u64), GFP_KERNEL);
       ...
                memset(bank, 0xff, banks * sizeof(u64));
       ...

 - There's lots of bitmaps, arrays, flags interacting, creating a
   maze of logic.

Instead of this messy code, the proper approach is to introduce an 
abstract data structure representing the attributes of an MCE bank 
register:

  struct mce_bank_register {
	int enabled;
	int polled;
	int dont_init;
	int msr_idx;
  };

( There's lots of other structural problems with the MCE code too - 
  but now that it's unified lets first fix the most obvious ones... )

	Ingo

  reply	other threads:[~2009-06-17  6:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-15 11:59 MCE boot crash in qemu Vegard Nossum
2009-06-15 12:01 ` Pekka Enberg
2009-06-15 12:52 ` Andi Kleen
2009-06-15 13:22   ` Pekka Enberg
2009-06-17  5:50     ` Pekka Enberg
2009-06-17  6:57       ` Ingo Molnar [this message]
2009-06-17 10:32   ` [tip:x86/urgent] x86: mce: Handle banks == 0 case in K7 quirk tip-bot for Andi Kleen

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=20090617065720.GA4852@elte.hu \
    --to=mingo@elte.hu \
    --cc=andi@firstfloor.org \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=penberg@cs.helsinki.fi \
    --cc=seto.hidetoshi@jp.fujitsu.com \
    --cc=vegard.nossum@gmail.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