Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756874AbZF3UMp (ORCPT ); Tue, 30 Jun 2009 16:12:45 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754663AbZF3UMh (ORCPT ); Tue, 30 Jun 2009 16:12:37 -0400 Received: from smtp1.linux-foundation.org ([140.211.169.13]:58388 "EHLO smtp1.linux-foundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754531AbZF3UMg (ORCPT ); Tue, 30 Jun 2009 16:12:36 -0400 Date: Tue, 30 Jun 2009 13:10:54 -0700 (PDT) From: Linus Torvalds X-X-Sender: torvalds@localhost.localdomain To: "H. Peter Anvin" cc: Mikael Pettersson , Yinghai Lu , Ingo Molnar , Matthew Wilcox , Grant Grundler , Linux Kernel Mailing List , linux-pci@vger.kernel.org Subject: Re: [BUG 2.6.31-rc1] HIGHMEM64G causes hang in PCI init on 32-bit x86 In-Reply-To: <4A4A25B1.5010102@zytor.com> Message-ID: References: <200906261559.n5QFxJH8027336@pilspetsen.it.uu.se> <19013.29264.623540.275538@pilspetsen.it.uu.se> <4A45A5C1.5080701@zytor.com> <19013.59956.144640.331854@pilspetsen.it.uu.se> <20090629022911.GC20297@lackof.org> <4A484A8A.9020704@zytor.com> <19016.41349.636663.515540@pilspetsen.it.uu.se> <20090629112155.GJ5480@parisc-linux.org> <19016.44061.600652.676183@pilspetsen.it.uu.se> <4A490804.3040609@zytor.com> <4A494478.7020304@kernel.org> <4A494E3C.70304@kernel.org> <4A495C0D.2020807@zytor.com> <4A4966EF.6010809@kernel.org> <4A496D4B.3040608@kernel.org> <19017.53428.834539.389495@pilspetsen.it.uu.se> <4A4A25B1.5010102@zytor.com> User-Agent: Alpine 2.01 (LFD 1184 2008-12-16) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1442 Lines: 40 On Tue, 30 Jun 2009, H. Peter Anvin wrote: > > By process of elimination, the culprit must be round_up(), which reveals > that the macro definition of round_up() has a *very* sublte behavior > with mixed types: > > #define round_up(x, y) (((x) + (y) - 1) & ~((y) - 1)) > > ram_alignment() returns unsigned long, which becomes (y). This means > that the mask word on the right hand of the & gets truncated to 32 bits > *before* the masking happens -- since ((y) - 1) is still unsigned long, > inverting it will not set bits [63..32] to on. Good catch. Also, this shows another bug in the #define: it evaluates 'y' twice, which is a no-no for something that _looks_ like a function. > I think this macro is actively dangerous. Better would be: > > ({ __typeof__(x) __mask = (y)-1; ((x)+__mask) & ~__mask; }) Yes. Please make it so. > The deep irony in this is that in our particular case is perhaps that > align_up(x,y)-1 is the same thing as x | (y-1) which would have avoided > the problem... I don't know how deep that irony is, but I do agree that maybe we should do that simplification too. In addition to fixing round_up() to not bite future generations in the ass. Linus -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/