NetBSD Problem Report #40311

From www@NetBSD.org  Thu Jan  1 03:51:29 2009
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by narn.NetBSD.org (Postfix) with ESMTP id BDD1D63B8C6
	for <gnats-bugs@gnats.netbsd.org>; Thu,  1 Jan 2009 03:51:29 +0000 (UTC)
Message-Id: <20090101035129.8FA7663B884@narn.NetBSD.org>
Date: Thu,  1 Jan 2009 03:51:29 +0000 (UTC)
From: lloyd@must-have-coffee.gen.nz
Reply-To: lloyd@must-have-coffee.gen.nz
To: gnats-bugs@NetBSD.org
Subject: No kernel symbols on tsarm 
X-Send-Pr-Version: www-1.0

>Number:         40311
>Category:       port-evbarm
>Synopsis:       No kernel symbols on tsarm
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    port-evbarm-maintainer
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jan 01 03:55:00 +0000 2009
>Closed-Date:    Sun May 20 14:10:45 +0000 2012
>Last-Modified:  Sun May 20 14:10:45 +0000 2012
>Originator:     Lloyd Parkes
>Release:        5.99.5
>Organization:
Must Have Coffee
>Environment:
NetBSD evbarm 5.99.5 NetBSD 5.99.5 (TS7200_SMALL) #3: Thu Jan  1 16:33:26 NZDT 2009  lloyd@maro.must-have-coffee.gen.nz:/vol/scratch/obj/evbarm/sys/arch/evbarm/compile/TS7200_SMALL evbarm
>Description:
In rev 1.10 of sys/arch/evbarm/tsarm/tsarm_machdep.c the call to ksyms_init was removed. It should have been replaced with a call to ksyms_addsyms_elf(0, NULL, NULL).



>How-To-Repeat:
Try and load a module or drop to DDB and notice the lack of symbols.



>Fix:
Add the following lines three lines above the call to db_machine_init. No diff because my source isn't very close to 1.10 anymore.

#if NKSYMS || defined(DDB) || defined(MODULAR)
        /* Firmware doesn't load symbols. */
        ksyms_addsyms_elf(0, NULL, NULL);
#endif


>Release-Note:

>Audit-Trail:
From: Martin Husemann <martin@duskware.de>
To: lloyd@must-have-coffee.gen.nz
Cc: gnats-bugs@NetBSD.org
Subject: Re: port-evbarm/40311: No kernel symbols on tsarm
Date: Fri, 2 Jan 2009 02:15:57 +0100

 On Thu, Jan 01, 2009 at 03:55:00AM +0000, lloyd@must-have-coffee.gen.nz wrote:
 > #if NKSYMS || defined(DDB) || defined(MODULAR)
 >         /* Firmware doesn't load symbols. */
 >         ksyms_addsyms_elf(0, NULL, NULL);
 > #endif

 I think it would be better to move the #ifdef SYMTAB_SPACE handling
 from ksyms_addsyms_elf() to ksyms_init(). Besides I do not understand how
 it even works with start == NULL.

 Calls that look like they add zero symbols from nowhere but instead perform
 deep magic are kinda evil.

 Martin

From: Lloyd Parkes <lloyd@must-have-coffee.gen.nz>
To: Martin Husemann <martin@duskware.de>
Cc: gnats-bugs@NetBSD.org
Subject: Re: port-evbarm/40311: No kernel symbols on tsarm
Date: Fri, 2 Jan 2009 17:06:11 +1300

 On 2/01/2009, at 2:15 PM, Martin Husemann wrote:

 > I think it would be better to move the #ifdef SYMTAB_SPACE handling
 > from ksyms_addsyms_elf() to ksyms_init().

 I'm not so sure. ksyms_init() is called very late these days and  
 getting the symbols in place early is good. It would be kind of nice  
 if dbsym actually did this for us when the kernel is built. With an  
 unoptimised kernel, ksyms_addsyms_elf() takes quite some time to  
 complete and it is still noticeable with an optmised kernel. With the  
 new MODULAR structure, it is no longer viable to run without a symbol  
 table.

 > Calls that look like they add zero symbols from nowhere but instead  
 > perform
 > deep magic are kinda evil.

 It took me at least half a day to find this.

 It might be made better with a little bit of sugar. Maybe something like

 #define ELF_SYMTAB_SYMBOLS NULL

 and rename ksyms_init to something that doesn't make it look like it  
 should be called before everything else.

 Anyway, this PR is about making tsarm work with ksyms, and not about  
 removing the warts from ksyms.

 Cheers,
 Lloyd



From: Martin Husemann <martin@duskware.de>
To: Lloyd Parkes <lloyd@must-have-coffee.gen.nz>
Cc: gnats-bugs@NetBSD.org
Subject: Re: port-evbarm/40311: No kernel symbols on tsarm
Date: Fri, 2 Jan 2009 10:13:46 +0100

 On Fri, Jan 02, 2009 at 05:06:11PM +1300, Lloyd Parkes wrote:
 > Anyway, this PR is about making tsarm work with ksyms, and not about  
 > removing the warts from ksyms.

 Yeah, and I'm fine with doing your change as an intermediate stopgap
 fix if we can't agree on the way to go quickly. However, I'm pretty sure
 this wasn't the only "NULL" call to ksyms_addsyms_elf() that I removed :-(
 [and still I don't see why it works at all - doesn't it deref the NULL start
 pointer?]

 Martin

From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@netbsd.org, lloyd@must-have-coffee.gen.nz, jmmv@NetBSD.org
Cc: 
Subject: Re: port-evbarm/40311: No kernel symbols on tsarm
Date: Sun, 4 Jan 2009 13:27:23 +0100

 --J/dobhs11T7y2rNN
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline

 Here is a patch (untested) that moves the SYMTAB_SPACE handling (once) into
 ksyms_init() and does not need to ressurrect all the 
 ksyms_addsyms_elf(0, NULL, NULL) calls all over the tree.

 Can someone please test if this works?

 Martin

 --J/dobhs11T7y2rNN
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename=patch

 Index: kern_ksyms.c
 ===================================================================
 RCS file: /cvsroot/src/sys/kern/kern_ksyms.c,v
 retrieving revision 1.49
 diff -u -p -r1.49 kern_ksyms.c
 --- kern_ksyms.c	1 Jan 2009 19:10:17 -0000	1.49
 +++ kern_ksyms.c	4 Jan 2009 12:23:56 -0000
 @@ -210,6 +210,14 @@ void
  ksyms_init()
  {

 +#ifdef SYMTAB_SPACE
 +	if (!ksyms_initted &&
 +	    strncmp(db_symtab, SYMTAB_FILLER, sizeof(SYMTAB_FILLER))) {
 +	    	ksyms_addsyms_elf(db_symtabsize, db_symtab,
 +		    db_symtab + db_symtabsize)
 +	}
 +#endif
 +
  	mutex_init(&ksyms_lock, MUTEX_DEFAULT, IPL_NONE);
  }

 @@ -347,14 +355,6 @@ ksyms_addsyms_elf(int symsize, void *sta
  	size_t strsize = 0;
  	Elf_Ehdr *ehdr;

 -#ifdef SYMTAB_SPACE
 -	if (symsize <= 0 &&
 -	    strncmp(db_symtab, SYMTAB_FILLER, sizeof(SYMTAB_FILLER))) {
 -		symsize = db_symtabsize;
 -		start = db_symtab;
 -		end = db_symtab + db_symtabsize;
 -	}
 -#endif
  	if (symsize <= 0) {
  		printf("[ Kernel symbol table missing! ]\n");
  		return;

 --J/dobhs11T7y2rNN--

From: "Julio M. Merino Vidal" <jmmv84@gmail.com>
To: gnats-bugs@gnats.netbsd.org
Cc: 
Subject: Re: port-evbarm/40311
Date: Tue, 20 Jan 2009 17:44:50 +0100

 The fix seems to work for me.  But there is a build problem in it:
 missing semicolon after the call to ksyms_addsyms_elf!

 -- 
 Julio M. Merino Vidal <jmmv84@gmail.com>

From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: port-evbarm/40311
Date: Tue, 20 Jan 2009 22:34:43 +0100

 On Tue, Jan 20, 2009 at 06:50:04PM +0000, Julio M. Merino Vidal wrote:
 >  The fix seems to work for me.  But there is a build problem in it:
 >  missing semicolon after the call to ksyms_addsyms_elf!

 Great, could you please commit your fixed version, undo your workaround
 and close this PR?

 Thanks,

 Martin

From: Lloyd Parkes <lloyd@must-have-coffee.gen.nz>
To: Martin Husemann <martin@duskware.de>
Cc: jmmv@NetBSD.org,
 gnats-bugs@netbsd.org
Subject: Re: port-evbarm/40311: No kernel symbols on tsarm
Date: Wed, 21 Jan 2009 19:31:13 +1300

 While it works (modulo the semi-colon), I realised that it doesn't  
 address the original issue that got me started on all this. The  
 symbols need to be loaded before DDB is initialised so that whenever  
 you might drop to DDB, you have them available.

 The requirements we have seem to be:

 	1) Symbols are necessary for module loading.
 	2) Symbols make DDB usable.
 	3) There is a mutex that should be initialised well after the  
 symbols are loaded.

 This raises the questions of what uses the mutex, and when is it  
 used? If the symbols are loaded nice and early, just before DDB is  
 initialised like they used to be, and then the kernel drops to DDB  
 before the mutex is initialised, what happens? Do the symbol lookups  
 trip over the uninitialised mutex?

 I simply don't have the time now that I'm back at work to look at this.

 If DDB works with the symbols being loaded after it is initialised  
 (and it probably will), then I think we can cope with a small window  
 where DDB doesn't have any symbols available to it until someone gets  
 some some time to look at it (and we run out of more important things  
 to worry about).

 Cheers,
 Lloyd

From: Martin Husemann <martin@duskware.de>
To: Lloyd Parkes <lloyd@must-have-coffee.gen.nz>
Cc: jmmv@NetBSD.org, gnats-bugs@netbsd.org
Subject: Re: port-evbarm/40311: No kernel symbols on tsarm
Date: Wed, 21 Jan 2009 09:14:25 +0100

 On Wed, Jan 21, 2009 at 07:31:13PM +1300, Lloyd Parkes wrote:
 > This raises the questions of what uses the mutex, and when is it  
 > used? If the symbols are loaded nice and early, just before DDB is  
 > initialised like they used to be, and then the kernel drops to DDB  
 > before the mutex is initialised, what happens? Do the symbol lookups  
 > trip over the uninitialised mutex?

 Ddb works w/o the mutex. I'm not sure that the tiny increase of the window
 where ddb could work but does not yet have symbols is a real problem - we
 should discuss this on tech-kern, probably. If it's decided to explicitly
 init the SYMTAB_SPACE symbols early, we need to systematically restore all
 the calls, and proabably should make a new special function (with no args)
 for this.

 Martin

From: "Julio M. Merino Vidal" <jmmv@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/40311 CVS commit: src/sys/kern
Date: Fri, 23 Jan 2009 09:22:25 +0000 (UTC)

 Module Name:	src
 Committed By:	jmmv
 Date:		Fri Jan 23 09:22:25 UTC 2009

 Modified Files:
 	src/sys/kern: kern_ksyms.c

 Log Message:
 Initialize SYMTAB_SPACE ksyms during ksyms_init.  Per PR port-evbarm/40311.


 To generate a diff of this commit:
 cvs rdiff -r1.49 -r1.50 src/sys/kern/kern_ksyms.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Julio M. Merino Vidal" <jmmv@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/40311 CVS commit: src/sys/arch/shark/shark
Date: Fri, 23 Jan 2009 09:23:02 +0000 (UTC)

 Module Name:	src
 Committed By:	jmmv
 Date:		Fri Jan 23 09:23:02 UTC 2009

 Modified Files:
 	src/sys/arch/shark/shark: shark_machdep.c

 Log Message:
 Remove hack to initialize SYMTAB_SPACE ksyms now that ksyms_init does it
 for us.  Per PR port-evbarm/40311.


 To generate a diff of this commit:
 cvs rdiff -r1.33 -r1.34 src/sys/arch/shark/shark/shark_machdep.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: matt@NetBSD.org
State-Changed-When: Sun, 20 May 2012 14:10:45 +0000
State-Changed-Why:
This was fixed in 2009.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.