From jin@eubie.lbl.gov  Tue Oct 20 10:15:32 1998
Received: from eubie.lbl.gov (eubie.lbl.gov [131.243.2.36])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id KAA09524
          for <FreeBSD-gnats-submit@freebsd.org>; Tue, 20 Oct 1998 10:15:32 -0700 (PDT)
          (envelope-from jin@eubie.lbl.gov)
Received: (from jin@localhost)
	by eubie.lbl.gov (8.9.1/8.9.1) id KAA00422;
	Tue, 20 Oct 1998 10:15:06 -0700 (PDT)
	(envelope-from jin)
Message-Id: <199810201715.KAA00422@eubie.lbl.gov>
Date: Tue, 20 Oct 1998 10:15:06 -0700 (PDT)
From: Jin Guojun (FTG staff) <jin@eubie.lbl.gov>
Reply-To: jin@eubie.lbl.gov
To: FreeBSD-gnats-submit@freebsd.org
Subject: modload failure
X-Send-Pr-Version: 3.2

>Number:         8386
>Category:       kern
>Synopsis:       modload failure
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Oct 20 10:20:00 PDT 1998
>Closed-Date:    Mon Mar 29 16:15:29 PST 1999
>Last-Modified:  Mon Mar 29 16:16:04 PST 1999
>Originator:     Jin Guojun (FTG staff)
>Release:        FreeBSD 3.0-19981015-BETA i386
>Organization:
>Environment:

	currently test under 3.0-19981015-BETA, last one prior to
	3.0-RELEASE

>Description:

	code segment in modload.c

        /*
         * Transfer the relinked module to kernel memory in chunks of
         * MODIOBUF size at a time.
         */
        for (bytesleft = info_buf.a_text + info_buf.a_data;
            bytesleft > 0;
            bytesleft -= sz) {
                sz = min(bytesleft, MODIOBUF);
                read(modfd, buf, sz);
                ldbuf.cnt = sz;
                ldbuf.data = buf;
                if (ioctl(devfd, LMLOADBUF, &ldbuf) == -1)
                        err(11, "error transferring buffer");
        }
 
        /*
         * Save ourselves before disaster (potentitally) strikes...
         */
        sync();
 
        /*
         * Trigger the module as loaded by calling the entry procedure;
         * this will do all necessary table fixup to ensure that state
         * is maintained on success, or blow everything back to ground
         * zero on failure.
         */
        if (ioctl(devfd, LMREADY, &modentry) == -1)	/* failed HERE	*/
                err(14, "error initializing module");	/* exited HERE	*/
 

DEBUG output from kern_lkm.c

... (repeating lines omitted)
LKM: LMLOADBUF (loading @ 285184 of 329868, i = 512) 2
LKM: LMLOADBUF (loading @ 285696 of 329868, i = 512) 2
LKM: LMLOADBUF (loading @ 286208 of 329868, i = 512) 2
lkm_state is 00
LKM: LMUNRESERV

------------

	As we see LMLOADBUF is lkm_state=2, and the "for loop " for the
	ioctl(devfd, LMLOADBUF, &ldbuf) was successfully finished.
	After sync(), somehow, lkm_state became 00 which causes kern_lkm
	return ENXIO (Device not configured) and let modload exit at
	the last two line printed above.
	There is no other code between these two segments except sync().
	Could sync() zeros out the local variable "lkm_state"?
	What could happen here?


>How-To-Repeat:

	compile kernel with "make DEBUG=-D_DEBUG" or modified Makefile
	to add DEBUG=-DDEBUG line, then install the kernel and reboot.
	Testing modload anything to see the output.

>Fix:
	
	

>Release-Note:
>Audit-Trail:

From: Jin Guojun (FTG staff) <jin@george.lbl.gov>
To: FreeBSD-gnats-submit@FreeBSD.ORG
Cc:  Subject: Re: kern/8386: modload failure
Date: Tue, 20 Oct 1998 12:26:52 -0700 (PDT)

 >       currently test under 3.0-19981015-BETA, last one prior to
 >       3.0-RELEASE
 
 The new 3.0-RELEASE does the samething.
 
 > DEBUG output from kern_lkm.c
 >  
 > ... (repeating lines omitted)
 > LKM: LMLOADBUF (loading @ 285184 of 329868, i = 512) 2
 > LKM: LMLOADBUF (loading @ 285696 of 329868, i = 512) 2
 > LKM: LMLOADBUF (loading @ 286208 of 329868, i = 512) 2
 > lkm_state is 00
 > LKM: LMUNRESERV
 
 In 2.2.7-RELEASE, the output looks like following:
 
 ... (repeating lines omitted)
 LKM: LMLOADBUF (loading @ 207360 of 251884, i = 512)
 LKM: LMLOADBUF (loading @ 207872 of 251884, i = 512)
 LKM: LMLOADBUF (loading @ 208384 of 251884, i = 512)
 znatm0 <Zeitnet PCI ATM 0001> rev 10 int a irq 9 on pci0:13:0
 ZAALGlobInit sb_modifhandler name ZNI,ZATMSB155
 ZS10MsgHandler: Entry efbffc6c 1
 ZAALGlobInit sb_modifhandler name ZNI,ZATMSB
 ZS10MsgHandler: Entry efbffc6c 1
 ZAALGlobInit sb_modifhandler name ZATMSBUS
 ZS10MsgHandler: Entry efbffc6c 1
 ZS10MsgHandler: Entry efbffc54 3
 ZeitNet : Version 3.0(1.22) 
 ATM: Loss of frame detected on Link 0
 ATM: Driver For OC3-MultiModeFiber Successfully Initialized
 ZS10MsgHandler: Entry efbffbd4 5
 ZS10MsgHandler: Entry efbffa58 5
 ZATM domain added
 LKM: LMREADY
 
 	-Jin

From: Jin Guojun (FTG staff) <jin@george.lbl.gov>
To: FreeBSD-gnats-submit@FreeBSD.ORG
Cc: se@mi.uni-koeln.de
Subject: Re: kern/8386: modload failure
Date: Tue, 20 Oct 1998 15:55:29 -0700 (PDT)

 Here is the problem in pci/pci_compat.c. Is it line ???? supposed to be
 
 	if (lkm == NULL)	{
 		return	-1;
 	}
 
 segment of pci/pci_compat.c
 
 static void
 pci_rescan(void)
 {
         /* XXX do nothing, currently, soon to come ... */
 }
  
 int pci_register_lkm (struct pci_device *dvp, int if_revision)
 { 
         struct pci_lkm *lkm;
   
         if (if_revision != 0) {
                 return (-1);
         }
         if (dvp == NULL || dvp->pd_probe == NULL || dvp->pd_attach == NULL) {
                 return (-1);
         }
         lkm = malloc (sizeof (*lkm), M_DEVBUF, M_WAITOK);
         if (lkm != NULL) {	/* ?????????????????????????	*/
                 return (-1);
         }
  
         lkm->dvp = dvp;
         lkm->next = pci_lkm_head;
         pci_lkm_head = lkm;
         pci_rescan();  
         return (0);
 }
 
State-Changed-From-To: open->closed 
State-Changed-By: sheldonh 
State-Changed-When: Mon Mar 29 16:15:29 PST 1999 
State-Changed-Why:  
modload superceded by kldload. 
>Unformatted:
