From owner-freebsd-current@FreeBSD.ORG Wed May 16 00:01:58 2007 Return-Path: X-Original-To: freebsd-current@freebsd.org Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 439AD16A416 for ; Wed, 16 May 2007 00:01:58 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from server.baldwin.cx (66-23-211-162.clients.speedfactory.net [66.23.211.162]) by mx1.freebsd.org (Postfix) with ESMTP id E2A9813C45A for ; Wed, 16 May 2007 00:01:06 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from localhost.corp.yahoo.com (john@localhost [127.0.0.1]) (authenticated bits=0) by server.baldwin.cx (8.13.8/8.13.8) with ESMTP id l4G00oVx046154; Tue, 15 May 2007 20:00:54 -0400 (EDT) (envelope-from jhb@freebsd.org) From: John Baldwin To: freebsd-current@freebsd.org Date: Tue, 15 May 2007 19:14:56 -0400 User-Agent: KMail/1.9.6 References: <09BFF2FA5EAB4A45B6655E151BBDD90303DE3A51@NT-IRVA-0750.brcm.ad.broadcom.com> In-Reply-To: <09BFF2FA5EAB4A45B6655E151BBDD90303DE3A51@NT-IRVA-0750.brcm.ad.broadcom.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200705151914.56433.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH authentication, not delayed by milter-greylist-2.0.2 (server.baldwin.cx [127.0.0.1]); Tue, 15 May 2007 20:00:54 -0400 (EDT) X-Virus-Scanned: ClamAV 0.88.3/3249/Tue May 15 17:16:41 2007 on server.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-4.4 required=4.2 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.1.3 X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on server.baldwin.cx Cc: David Christensen Subject: Re: Releasing MSI Resources in a Module Causes Kernel Panic on -CURRENT X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 May 2007 00:01:58 -0000 On Monday 14 May 2007 10:27:02 pm David Christensen wrote: > I'm working on the bce driver and loading/unloading it as a kernel > module. > On an MSI capable 5708 controller I can load the module and pass traffic > without a problem, but when I unload the driver I get the following > panic: > ------------------------------------------------------------------------ > --- > bce0: mem > 0xfc000000-0xfdffffff irq 57 at device 0.0 on pci74 > bce0: ASIC ID 0x57081020; Revision (B2); PCI-X 64-bit 133MHz > bce0: Ethernet address: 00:10:18:15:f6:c2 > bce0: [ITHREAD] > miibus0: on bce0 > brgphy0: PHY 1 on miibus0 > brgphy0: 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, 1000baseT, > 1000baseT-FDX, auto > brgphy0: detached > miibus0: detached > bce0: Removing interrupt handler. > bce0: Releasing IRQ. > panic: resource_list_release: resource entry is not busy > cpuid = 7 > KDB: enter: panic > [thread pid 806 tid 100182 ] > Stopped at kdb_enter+0x31: leave > db> bt > Tracing pid 806 tid 100182 td 0xffffff0208a1bd20 > kdb_enter() at kdb_enter+0x31 > panic() at panic+0x1e3 > resource_list_release() at resource_list_release+0xd8 > bus_generic_rl_release_resource() at > bus_generic_rl_release_resource+0x86 > bus_release_resource() at bus_release_resource+0x75 > bce_release_resources() at bce_release_resources+0xe3 > bce_detach() at bce_detach+0xce > device_detach() at device_detach+0x68 > devclass_delete_driver() at devclass_delete_driver+0xb7 > driver_module_handler() at driver_module_handler+0xec > module_unload() at module_unload+0xa0 > linker_file_unload() at linker_file_unload+0xdb > kern_kldunload() at kern_kldunload+0xce > kldunloadf() at kldunloadf+0x19 > syscall() at syscall+0x38c > Xfast_syscall() at Xfast_syscall+0xab > --- syscall (444, FreeBSD ELF64, kldunloadf), rip = 0x80068d4cc, rsp = > 0x7fffffffe738, rbp = 0x2 --- > db> > ------------------------------------------------------------------------ > --- > Looking at other MSI capable drivers I see they are releasing the > interrupt > in the same way that I am so why am I getting the panic? I see where > the > panic comes from > (http://fxr.watson.org/fxr/source/kern/subr_bus.c#L2751) > but I don't quite understand what didn't get set. > > Here's the allocation: > > /* Allocate PCI IRQ resources. */ > count = pci_msi_count(dev); > if (count == 1 && pci_alloc_msi(dev, &count) == 0) { > rid = 1; > sc->bce_flags |= BCE_USING_MSI_FLAG; > DBPRINT(sc, BCE_INFO_RESET, "Allocating MSI > interrupt.\n"); > } else > rid = 0; > > sc->bce_res_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, > RF_SHAREABLE | RF_ACTIVE); > > And here the de-allocation: > > if (sc->bce_res_irq != NULL) { > DBPRINT(sc, BCE_WARN_RESET, "Releasing IRQ.\n"); > bus_release_resource(dev, SYS_RES_IRQ, sc->bce_flags & > BCE_USING_MSI_FLAG ? 1 : 0, > sc->bce_res_irq); > } > > if (sc->bce_flags & BCE_USING_MSI_FLAG) { > DBPRINT(sc, BCE_WARN_RESET, "Releasing MSI vector.\n"); > pci_release_msi(dev); > } > > What is going wrong? Can you print out the rid being passed to bus_release_resource()? Also, having 'debug.bootverbose' on (sysctl) during the kldload/kldunload would be helpful. -- John Baldwin