From owner-svn-src-all@FreeBSD.ORG Fri Oct 29 17:06:01 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C89EF1065675; Fri, 29 Oct 2010 17:06:01 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 852BE8FC19; Fri, 29 Oct 2010 17:06:01 +0000 (UTC) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id 0879D46B37; Fri, 29 Oct 2010 13:06:01 -0400 (EDT) Received: from jhbbsd.localnet (smtp.hudson-trading.com [209.249.190.9]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id BD5EB8A009; Fri, 29 Oct 2010 13:05:59 -0400 (EDT) From: John Baldwin To: Attilio Rao Date: Fri, 29 Oct 2010 13:02:08 -0400 User-Agent: KMail/1.13.5 (FreeBSD/7.3-CBSD-20100819; KDE/4.4.5; amd64; ; ) References: <201010281631.o9SGVdtZ014923@svn.freebsd.org> <201010291026.20252.jhb@freebsd.org> In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <201010291302.08687.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.6 (bigwig.baldwin.cx); Fri, 29 Oct 2010 13:05:59 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.96.3 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-1.9 required=4.2 tests=BAYES_00 autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on bigwig.baldwin.cx Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r214457 - in head/sys: amd64/amd64 conf i386/i386 x86/x86 X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Oct 2010 17:06:01 -0000 On Friday, October 29, 2010 10:33:05 am Attilio Rao wrote: > 2010/10/29 John Baldwin : > > On Friday, October 29, 2010 10:17:23 am Attilio Rao wrote: > >> 2010/10/29 John Baldwin : > >> > On Thursday, October 28, 2010 8:25:38 pm Attilio Rao wrote: > >> >> 2010/10/28 John Baldwin : > >> >> > On Thursday, October 28, 2010 4:28:12 pm Attilio Rao wrote: > >> >> >> 2010/10/28 John Baldwin : > >> >> >> > On Thursday, October 28, 2010 1:21:34 pm Attilio Rao wrote: > >> >> >> >> 2010/10/28 John Baldwin : > >> >> >> >> > On Thursday, October 28, 2010 12:31:39 pm Attilio Rao wrote: > >> >> >> >> >> Author: attilio > >> >> >> >> >> Date: Thu Oct 28 16:31:39 2010 > >> >> >> >> >> New Revision: 214457 > >> >> >> >> >> URL: http://svn.freebsd.org/changeset/base/214457 > >> >> >> >> >> > >> >> >> >> >> Log: > >> >> >> >> >> Merge nexus.c from amd64 and i386 to x86 subtree. > >> >> >> >> >> > >> >> >> >> >> Sponsored by: Sandvine Incorporated > >> >> >> >> >> Tested by: gianni > >> >> >> >> >> > >> >> >> >> > > >> >> >> >> > It would be better to merge these two routines. The loader now passes > >> >> > the > >> >> >> >> > smap to i386 kernels as well, so ram_attach() should probably be > >> >> > changed to > >> >> >> >> > try the amd64 approach first and if that fails fall back to using the > >> >> >> >> > phys_avail[] array instead. > >> >> >> >> > >> >> >> >> What do you think about this patch?: > >> >> >> >> Index: nexus.c > >> >> >> >> =================================================================== > >> >> >> >> --- nexus.c (revision 214457) > >> >> >> >> +++ nexus.c (working copy) > >> >> >> >> @@ -52,9 +52,7 @@ > >> >> >> >> #include > >> >> >> >> #include > >> >> >> >> #include > >> >> >> >> -#ifdef __amd64__ > >> >> >> >> #include > >> >> >> >> -#endif > >> >> >> >> #include > >> >> >> >> #include > >> >> >> >> #include > >> >> >> >> @@ -67,12 +65,10 @@ > >> >> >> >> #include > >> >> >> >> #include > >> >> >> >> > >> >> >> >> -#ifdef __amd64__ > >> >> >> >> #include > >> >> >> >> -#include > >> >> >> >> -#endif > >> >> >> >> #include > >> >> >> >> #include > >> >> >> >> +#include > >> >> >> >> > >> >> >> >> #ifdef DEV_APIC > >> >> >> >> #include "pcib_if.h" > >> >> >> >> @@ -89,11 +85,13 @@ > >> >> >> >> #include > >> >> >> >> > >> >> >> >> #ifdef __amd64__ > >> >> >> >> -#define RMAN_BUS_SPACE_IO AMD64_BUS_SPACE_IO > >> >> >> >> -#define RMAN_BUS_SPACE_MEM AMD64_BUS_SPACE_MEM > >> >> >> >> +#define X86_BUS_SPACE_IO AMD64_BUS_SPACE_IO > >> >> >> >> +#define X86_BUS_SPACE_MEM AMD64_BUS_SPACE_MEM > >> >> >> >> +#define ELF_KERN_STR "elf64 kernel" > >> >> >> >> #else > >> >> >> >> -#define RMAN_BUS_SPACE_IO I386_BUS_SPACE_IO > >> >> >> >> -#define RMAN_BUS_SPACE_MEM I386_BUS_SPACE_MEM > >> >> >> >> +#define X86_BUS_SPACE_IO I386_BUS_SPACE_IO > >> >> >> >> +#define X86_BUS_SPACE_MEM I386_BUS_SPACE_MEM > >> >> >> >> +#define ELF_KERN_STR "elf32 kernel" > >> >> >> >> #endif > >> >> >> >> @@ -701,16 +699,11 @@ > >> >> >> >> panic("ram_attach: resource %d failed to attach", > >> >> > rid); > >> >> >> >> rid++; > >> >> >> >> } > >> >> >> >> - return (0); > >> >> >> >> -} > >> >> >> >> -#else > >> >> >> >> -static int > >> >> >> >> -ram_attach(device_t dev) > >> >> >> >> -{ > >> >> >> >> - struct resource *res; > >> >> >> >> - vm_paddr_t *p; > >> >> >> >> - int error, i, rid; > >> >> >> >> > >> >> >> >> + /* If at least one smap attached, return. */ > >> >> >> >> + if (rid != 0) > >> >> >> >> + return (0); > >> >> >> >> + > >> >> >> > > >> >> >> > Perhaps this instead: > >> >> >> > > >> >> >> > /* If we found an SMAP, return. */ > >> >> >> > if (smapbase != NULL) > >> >> >> > return (0); > >> >> >> > >> >> >> No, I don't think this check is right, smapbase will always be != NULL > >> >> >> (otherwise the code panics). > >> >> > > >> >> > Oh, that needs to be fixed then. It can be NULL on i386 with an old loader > >> >> > (or on a really old machine without an SMAP). The amd64 nexus code could > >> >> > assume it would never be NULL, but i386 cannot. > >> >> > > >> >> > It should probably more closely match what i386 does during the memory probe > >> >> > which is: > >> >> > > >> >> > kmdp = search("elf kernel"); > >> >> > if (kmdp == NULL) > >> >> > kmdp = search("elfXX kernel"); > >> >> > if (kmdp != NULL) > >> >> > smapbase = preload_search(...); > >> >> > else > >> >> > smapbase = NULL; > >> >> > if (smapbase != NULL) { > >> >> > for (smap = ...) { > >> >> > } > >> >> > > >> >> > return (0); > >> >> > } > >> >> > > >> >> > /* fall through to old i386 code using phys_avail[] */ > >> >> > >> >> This further patch should address your concerns about nexus.c: > >> >> Index: nexus.c > >> >> =================================================================== > >> >> --- nexus.c (revision 214457) > >> >> +++ nexus.c (working copy) > >> >> @@ -52,9 +52,7 @@ > >> >> #include > >> >> #include > >> >> #include > >> >> -#ifdef __amd64__ > >> >> #include > >> >> -#endif > >> >> #include > >> >> #include > >> >> #include > >> >> @@ -67,12 +65,10 @@ > >> >> #include > >> >> #include > >> >> > >> >> -#ifdef __amd64__ > >> >> #include > >> >> -#include > >> >> -#endif > >> >> #include > >> >> #include > >> >> +#include > >> >> > >> >> #ifdef DEV_APIC > >> >> #include "pcib_if.h" > >> >> @@ -89,13 +85,15 @@ > >> >> #include > >> >> > >> >> #ifdef __amd64__ > >> >> -#define RMAN_BUS_SPACE_IO AMD64_BUS_SPACE_IO > >> >> -#define RMAN_BUS_SPACE_MEM AMD64_BUS_SPACE_MEM > >> >> +#define BUS_SPACE_IO AMD64_BUS_SPACE_IO > >> >> +#define BUS_SPACE_MEM AMD64_BUS_SPACE_MEM > >> >> #else > >> >> -#define RMAN_BUS_SPACE_IO I386_BUS_SPACE_IO > >> >> -#define RMAN_BUS_SPACE_MEM I386_BUS_SPACE_MEM > >> >> +#define BUS_SPACE_IO I386_BUS_SPACE_IO > >> >> +#define BUS_SPACE_MEM I386_BUS_SPACE_MEM > >> >> #endif > >> >> > >> >> +#define ELF_KERN_STR ("elf"__XSTRING(__ELF_WORD_SIZE)" kernel") > >> >> + > >> >> static MALLOC_DEFINE(M_NEXUSDEV, "nexusdev", "Nexus device"); > >> >> > >> >> #define DEVTONX(dev) ((struct nexus_device *)device_get_ivars(dev)) > >> >> @@ -435,7 +433,7 @@ > >> >> #else > >> >> rman_set_bushandle(r, rman_get_start(r)); > >> >> #endif > >> >> - rman_set_bustag(r, RMAN_BUS_SPACE_IO); > >> >> + rman_set_bustag(r, BUS_SPACE_IO); > >> >> break; > >> >> case SYS_RES_MEMORY: > >> >> #ifdef PC98 > >> >> @@ -446,7 +444,7 @@ > >> >> #endif > >> >> vaddr = pmap_mapdev(rman_get_start(r), rman_get_size(r)); > >> >> rman_set_virtual(r, vaddr); > >> >> - rman_set_bustag(r, RMAN_BUS_SPACE_MEM); > >> >> + rman_set_bustag(r, BUS_SPACE_MEM); > >> >> #ifdef PC98 > >> >> /* PC-98: the type of bus_space_handle_t is the structure. */ > >> >> bh->bsh_base = (bus_addr_t) vaddr; > >> >> @@ -668,48 +666,45 @@ > >> >> return (0); > >> >> } > >> >> > >> >> -#ifdef __amd64__ > >> >> static int > >> >> ram_attach(device_t dev) > >> >> { > >> >> struct bios_smap *smapbase, *smap, *smapend; > >> >> struct resource *res; > >> >> + vm_paddr_t *p; > >> >> caddr_t kmdp; > >> >> uint32_t smapsize; > >> >> - int error, rid; > >> >> + int error, i, rid; > >> >> > >> >> /* Retrieve the system memory map from the loader. */ > >> >> kmdp = preload_search_by_type("elf kernel"); > >> >> if (kmdp == NULL) > >> >> - kmdp = preload_search_by_type("elf64 kernel"); > >> >> - smapbase = (struct bios_smap *)preload_search_info(kmdp, > >> >> - MODINFO_METADATA | MODINFOMD_SMAP); > >> >> - smapsize = *((u_int32_t *)smapbase - 1); > >> >> - smapend = (struct bios_smap *)((uintptr_t)smapbase + smapsize); > >> >> + kmdp = preload_search_by_type(ELF_KERN_STR); > >> >> + if (kmdp != NULL) { > >> >> + smapbase = (struct bios_smap *)preload_search_info(kmdp, > >> >> + MODINFO_METADATA | MODINFOMD_SMAP); > >> >> + smapsize = *((u_int32_t *)smapbase - 1); > >> >> + smapend = (struct bios_smap *)((uintptr_t)smapbase + smapsize); > >> > > >> > I think this doesn't check for the case that smapbase is NULL. I would > >> > expect kmdp to always be non-NULL in practice (it just means we have a > >> > kernel). However, the preload_search_info() can fail when booting on an old > >> > machine without an SMAP or an old loader that doesn't pass the SMAP to i386. > >> > >> I don't understand where is the problem. > >> smap is only used when it is consistent in that patch, otherwise it is > >> not used and fallsthrough the physavail[] approach. > >> It doesn't need to be set to NULL or checked. > >> > >> I guess that you want to patch the file and see how it looks like, > >> will be easier to review than inline .diff, in this case. > > > > The preload_search_info() can fail and return NULL (old machine with no SMAP > > or an older /boot/loader on i386). Then when you do this: > > > > smapsize = *((u_int32_t *)smapbase - 1); > > > > the kernel will panic. > > Ah, I thought that it could be failing only with a NULL kmdp. > That patch should fix it then: I think this looks fine, but I haven't tested it. :) -- John Baldwin