Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1LsudB-0002Qv-4w for mharc-grub-devel@gnu.org; Sun, 12 Apr 2009 04:01:33 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LsudA-0002Qn-3g for grub-devel@gnu.org; Sun, 12 Apr 2009 04:01:32 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Lsud9-0002Qb-N1 for grub-devel@gnu.org; Sun, 12 Apr 2009 04:01:31 -0400 Received: from [199.232.76.173] (port=59063 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Lsud9-0002QY-Jl for grub-devel@gnu.org; Sun, 12 Apr 2009 04:01:31 -0400 Received: from [74.93.104.97] (port=51233 helo=sunset.davemloft.net) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Lsud8-0004yQ-C5; Sun, 12 Apr 2009 04:01:30 -0400 Received: from localhost (localhost [127.0.0.1]) by sunset.davemloft.net (Postfix) with ESMTP id 3BC4BC8C0DD; Sun, 12 Apr 2009 01:01:21 -0700 (PDT) Date: Sun, 12 Apr 2009 01:01:21 -0700 (PDT) Message-Id: <20090412.010121.183222401.davem@davemloft.net> To: grub-devel@gnu.org, proski@gnu.org From: David Miller In-Reply-To: <1239517755.3887.24.camel@mj> References: <20090411.010833.154152360.davem@davemloft.net> <1239517755.3887.24.camel@mj> X-Mailer: Mew version 6.2.51 on Emacs 22.1 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Cc: Subject: Re: [PATCH]: grub: Fix ofdisk disk cache corruption. X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 12 Apr 2009 08:01:32 -0000 From: Pavel Roskin Date: Sun, 12 Apr 2009 02:29:15 -0400 > On Sat, 2009-04-11 at 01:08 -0700, David Miller wrote: >> The ieee1275 ofdisk driver doesn't use a unique value for >> disk->id so it's really easy to get disk corruption. I was >> able to see such corruption by simply booting grub from one >> disk and booting a Linux kernel from another, both of which >> were on the same disk controller. > > I hope you mean disk cache corruption, as in the subject, not disk > corruption. GRUB only writes to disks to save environment variables, > and it's done very carefully. > >> +#define OFDISK_HASH_SZ 8 >> +static struct ofdisk_hash_ent *ofdisk_hash[OFDISK_HASH_SZ]; >> + >> +static int >> +ofdisk_hash_fn (const char *devpath) >> +{ >> + int hash = 0; >> + while (*devpath) >> + hash ^= *devpath++; >> + return (hash & (OFDISK_HASH_SZ - 1)); >> +} > > That's a 3 bit hash. The risk of collisions is very high. I would > understand if you had 8 entries for the hash values, but the hash values > themselves should be reasonably unique. In my testing there weren't many collisions. I think fixing disk cache corruption is more important than arguing over the distribution properties of the hash function I have choosen. Right? > If you can save the device names, then there is no point in using > hashes. You can use (long)devpath. Sure we need the hash, to find path entries we've saved beforehand. > >> + if (!op) >> + op = ofdisk_hash_add (devpath); >> >> - grub_ieee1275_open (devpath, &dev_ihandle); >> + grub_free (devpath); > > But if you free the device names, then they are bad IDs. The > probability of the same memory being reused for another name is high. > > Perhaps I misunderstand something. The path we use is dup'd into the hash entries we create, and the hash entry path string is the one we use. Therefore "devpath" is only needed across the ofdisk_hash_add() call.