Date: Mon, 30 Dec 2019 14:23:59 -0500 From: "Farhan Khan" <farhan@farhan.codes> To: "Hans Petter Selasky" <hps@selasky.org>, freebsd-usb@freebsd.org Subject: Re: Page fault at USB attachment code Message-ID: <8490a117-3e38-4ff1-af77-5c963a654168@www.fastmail.com> In-Reply-To: <5e3315f6-33e0-e494-4515-9f6023e1f54c@selasky.org> References: <7b2a53c8-8640-4b0c-8d6e-22a1988a3ebd@www.fastmail.com> <5e3315f6-33e0-e494-4515-9f6023e1f54c@selasky.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Dec 26, 2019, at 3:33 AM, Hans Petter Selasky wrote: > On 2019-12-26 01:46, Farhan Khan wrote: > > Hi all, > > > > I am writing a simple USB network device driver skeleton, just to learn the framework. What I think is fairly simple code is having a kernel panic when it hits the attachment code. > > > > The code and kgdb output are below. I apologize, its been some time since I used kgdb, so I am not sure what the next step I should do to debug this. > > > > --------------------- > > static int > > skel_usb_attach(device_t self) > > { > > struct usb_attach_arg *uaa = device_get_ivars(self); > > struct skel_usb_softc *uc = device_get_softc(self); > > struct skel_softc *sc = uc->sc_sc; > > struct ieee80211com *ic = &sc->sc_ic; > > > > device_set_usb_desc(self); > > uc->uc_udev = uaa->device; > > sc->sc_dev = self; > > ic->ic_name = device_get_nameunit(self); > > > > return 0; > > } > > --------------------- > > > > When I run kgdb, I get the following output. > > > > --------------------- > > sudo kgdb -n last > > GNU gdb (GDB) 8.3.1 [GDB v8.3.1 for FreeBSD] > > Copyright (C) 2019 Free Software Foundation, Inc. > > License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> > > This is free software: you are free to change and redistribute it. > > There is NO WARRANTY, to the extent permitted by law. > > Type "show copying" and "show warranty" for details. > > This GDB was configured as "x86_64-portbld-freebsd13.0". > > Type "show configuration" for configuration details. > > For bug reporting instructions, please see: > > <http://www.gnu.org/software/gdb/bugs/>. > > Find the GDB manual and other documentation resources online at: > > <http://www.gnu.org/software/gdb/documentation/>. > > > > For help, type "help". > > Type "apropos word" to search for commands related to "word"... > > Reading symbols from /usr/obj/usr/src/amd64.amd64/sys/GENERIC/kernel.full... > > > > Unread portion of the kernel message buffer: > > Matched! > > skel0 on uhub0 > > skel0: <ATHEROS USB2.0 WLAN, rev 1.10/ff.ff, addr 2> on usbus0 > > > > Fatal trap 12: page fault while in kernel mode > > cpuid = 0; apic id = 00 > > fault virtual address = 0x7170 > > fault code = supervisor write data, page not present > > instruction pointer = 0x20:0xffffffff8271f094 > > stack pointer = 0x28:0xfffffe00036f5930 > > frame pointer = 0x28:0xfffffe00036f5950 > > code segment = base 0x0, limit 0xfffff, type 0x1b > > = DPL 0, pres 1, long 1, def32 0, gran 1 > > processor eflags = interrupt enabled, resume, IOPL = 0 > > current process = 15 (usbus0) > > trap number = 12 > > panic: page fault > > cpuid = 0 > > time = 1577299341 > > KDB: stack backtrace: > > db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame 0xfffffe00036f5590 > > vpanic() at vpanic+0x17e/frame 0xfffffe00036f55f0 > > panic() at panic+0x43/frame 0xfffffe00036f5650 > > trap_fatal() at trap_fatal+0x386/frame 0xfffffe00036f56b0 > > trap_pfault() at trap_pfault+0x99/frame 0xfffffe00036f5730 > > trap() at trap+0x2a3/frame 0xfffffe00036f5860 > > calltrap() at calltrap+0x8/frame 0xfffffe00036f5860 > > --- trap 0xc, rip = 0xffffffff8271f094, rsp = 0xfffffe00036f5930, rbp = 0xfffffe00036f5950 --- > > skel_usb_attach() at skel_usb_attach+0x34/frame 0xfffffe00036f5950 > > device_attach() at device_attach+0x3ca/frame 0xfffffe00036f5990 > > device_probe_and_attach() at device_probe_and_attach+0x70/frame 0xfffffe00036f59c0 > > usb_probe_and_attach_sub() at usb_probe_and_attach_sub+0x150/frame 0xfffffe00036f5a10 > > usb_probe_and_attach() at usb_probe_and_attach+0x463/frame 0xfffffe00036f5ae0 > > uhub_explore() at uhub_explore+0x753/frame 0xfffffe00036f5b50 > > usb_bus_explore() at usb_bus_explore+0x11a/frame 0xfffffe00036f5b70 > > usb_process() at usb_process+0x103/frame 0xfffffe00036f5bb0 > > fork_exit() at fork_exit+0x80/frame 0xfffffe00036f5bf0 > > fork_trampoline() at fork_trampoline+0xe/frame 0xfffffe00036f5bf0 > > --- trap 0, rip = 0, rsp = 0, rbp = 0 --- > > KDB: enter: panic > > > > warning: Could not load shared library symbols for if_skel_usb.ko. > > Do you need "set solib-search-path" or "set sysroot"? > > --------------------- > > > > Note: I am testing this with an Atheros USB device. > > > > Thanks! > > > > Are you sure you specified sizeof the correct softc, in the driver > declaration? > > --HPS > > Hi HPS, It was a very silly mistake on my end. The HAL layer was not allocating memory for the skel_softc variable. This was causing "sc->sc_dev = self;" to panic. Thank you! -- Farhan Khan PGP Fingerprint: 1312 89CE 663E 1EB2 179C 1C83 C41D 2281 F8DA C0DE
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?8490a117-3e38-4ff1-af77-5c963a654168>