QEMU调试内核2.6.19 init [1]:segfault ffffffffffffffd8错误6

时间:2017-02-13 15:03:59

标签: linux segmentation-fault kernel qemu

环境:

➜  ~ uname -a
Linux ho 4.4.0-62-generic #83~14.04.1-Ubuntu SMP Wed Jan 18 18:10:30 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

➜  ~ gcc --version
gcc (Ubuntu 4.9.4-2ubuntu1~14.04.1) 4.9.4

➜  ~ gdb --version
GNU gdb (GDB) 7.12.1.20170213-git

➜  ~ qemu-system-x86_64 --version
QEMU emulator version 2.0.0 (Debian 2.0.0+dfsg-2ubuntu1.31),

错误信息(最后):

QEMU 2.0.0 monitor - type 'help' for more information
(qemu) [    0.000000] Linux version 2.6.19 (honhe@honhe-android) (gcc version 4.9.4 (Ubuntu 4.9.4-2ubuntu1~14.04.1) ) #20 SMP Mon Feb 13 16:03:25 CST 2017
[    0.000000] Command line: root=/dev/ram  console=ttyS0 rdinit=/test
[    0.000000] BIOS-provided physical RAM map:
[    0.000000]  BIOS-e820: 0000000000000000 - 000000000009fc00 (usable)
[    0.000000]  BIOS-e820: 000000000009fc00 - 00000000000a0000 (reserved)
[    0.000000]  BIOS-e820: 00000000000f0000 - 0000000000100000 (reserved)
[    0.000000]  BIOS-e820: 0000000000100000 - 0000000007ffe000 (usable)
[    0.000000]  BIOS-e820: 0000000007ffe000 - 0000000008000000 (reserved)
[    0.000000]  BIOS-e820: 00000000fffc0000 - 0000000100000000 (reserved)
[    0.000000] end_pfn_map = 1048576
[    0.000000] DMI 2.4 present.
[    0.000000] Zone PFN ranges:
[    0.000000]   DMA             0 ->     4096
[    0.000000]   DMA32        4096 ->  1048576
[    0.000000]   Normal    1048576 ->  1048576
[    0.000000] early_node_map[2] active PFN ranges
[    0.000000]     0:        0 ->      159
[    0.000000]     0:      256 ->    32766
[    0.000000] ACPI: PM-Timer IO Port: 0xb008
[    0.000000] ACPI: LAPIC (acpi_id[0x00] lapic_id[0x00] enabled)
[    0.000000] Processor #0 (Bootup-CPU)
[    0.000000] ACPI: LAPIC_NMI (acpi_id[0xff] dfl dfl lint[0x1])
[    0.000000] ACPI: IOAPIC (id[0x00] address[0xfec00000] gsi_base[0])
[    0.000000] IOAPIC[0]: apic_id 0, address 0xfec00000, GSI 0-23
[    0.000000] ACPI: INT_SRC_OVR (bus 0 bus_irq 0 global_irq 2 dfl dfl)
[    0.000000] ACPI: INT_SRC_OVR (bus 0 bus_irq 5 global_irq 5 high level)
[    0.000000] ACPI: INT_SRC_OVR (bus 0 bus_irq 9 global_irq 9 high level)
[    0.000000] ACPI: INT_SRC_OVR (bus 0 bus_irq 10 global_irq 10 high level)
[    0.000000] ACPI: INT_SRC_OVR (bus 0 bus_irq 11 global_irq 11 high level)
[    0.000000] Setting APIC routing to flat
[    0.000000] ACPI: HPET id: 0x8086a201 base: 0xfed00000
[    0.000000] Using ACPI (MADT) for SMP configuration information
[    0.000000] Nosave address range: 000000000009f000 - 00000000000a0000
[    0.000000] Nosave address range: 00000000000a0000 - 00000000000f0000
[    0.000000] Nosave address range: 00000000000f0000 - 0000000000100000
[    0.000000] Allocating PCI resources starting at 10000000 (gap: 8000000:f7fc0000)
[    0.000000] PERCPU: Allocating 35200 bytes of per cpu data
[    0.000000] Built 1 zonelists.  Total pages: 30910
[    0.000000] Kernel command line: root=/dev/ram  console=ttyS0 rdinit=/test
[    0.000000] Initializing CPU#0
[    0.000000] PID hash table entries: 512 (order: 9, 4096 bytes)
[    1.015485] Console: colour VGA+ 80x25
[    1.019629] Dentry cache hash table entries: 16384 (order: 5, 131072 bytes)
[    1.020071] Inode-cache hash table entries: 8192 (order: 4, 65536 bytes)
[    1.020322] Checking aperture...
[    1.022154] Memory: 121856k/131064k available (2750k kernel code, 8700k reserved, 1515k data, 240k init)
[    1.100831] Calibrating delay using timer specific routine.. 6443.59 BogoMIPS (lpj=12887196)
[    1.101919] Security Framework v1.0.0 initialized
[    1.102612] SELinux:  Disabled at boot.
[    1.103076] Mount-cache hash table entries: 256
[    1.107454] CPU: L1 I Cache: 64K (64 bytes/line), D cache 64K (64 bytes/line)
[    1.107639] CPU: L2 Cache: 512K (64 bytes/line)
[    1.107893] MCE: warning: using only 10 banks
[    1.108419] SMP alternatives: switching to UP code
[    1.109054] Freeing SMP alternatives: 36k freed
[    1.109430] ACPI: Core revision 20060707
[    1.168831] activating NMI Watchdog ... done.
[    1.169332] Using local APIC timer interrupts.
[    1.200898] result 62514742
[    1.201078] Detected 62.514 MHz APIC timer.
[    1.206413] Brought up 1 CPUs
[    1.206850] testing NMI watchdog ... OK.
[    1.247637] time.c: Using 100.000000 MHz WALL HPET GTOD HPET/TSC timer.
[    1.247980] time.c: Detected 3191.982 MHz processor.
[    1.252278] checking if image is initramfs...it isn't (no cpio magic); looks like an initrd
[    1.367810] Freeing initrd memory: 1408k freed
[    1.374534] NET: Registered protocol family 16
[    1.378959] ACPI: bus type pci registered
[    1.379505] PCI: Using configuration type 1
[    1.405164] ACPI: Interpreter enabled
[    1.405453] ACPI: Using IOAPIC for interrupt routing
[    1.409244] ACPI: PCI Root Bridge [PCI0] (0000:00)
[    1.410167] ACPI: Assume root bridge [\_SB_.PCI0] bus is 0
[    1.419448] PCI quirk: region b000-b03f claimed by PIIX4 ACPI
[    1.419752] PCI quirk: region b100-b10f claimed by PIIX4 SMB
[    1.448305] ACPI: PCI Interrupt Link [LNKA] (IRQs 5 *10 11)
[    1.449900] ACPI: PCI Interrupt Link [LNKB] (IRQs 5 *10 11)
[    1.451229] ACPI: PCI Interrupt Link [LNKC] (IRQs 5 10 *11)
[    1.452585] ACPI: PCI Interrupt Link [LNKD] (IRQs 5 10 *11)
[    1.453409] ACPI: PCI Interrupt Link [LNKS] (IRQs *9)
[    1.454786] Linux Plug and Play Support v0.97 (c) Adam Belay
[    1.455057] pnp: PnP ACPI init
[    1.463177] pnp: PnP ACPI: found 9 devices
[    1.465873] SCSI subsystem initialized
[    1.466823] usbcore: registered new interface driver usbfs
[    1.467389] usbcore: registered new interface driver hub
[    1.468117] usbcore: registered new device driver usb
[    1.468791] PCI: Using ACPI for IRQ routing
[    1.469032] PCI: If a device doesn't work, try "pci=routeirq".  If it helps, post a report
[    1.470230] NetLabel: Initializing
[    1.470368] NetLabel:  domain hash size = 128
[    1.470539] NetLabel:  protocols = UNLABELED CIPSOv4
[    1.471317] NetLabel:  unlabeled traffic allowed by default
[    1.471634] hpet0: at MMIO 0xfed00000, IRQs 2, 8, 0
[    1.471890] hpet0: 3 64-bit timers, 100000000 Hz
[    1.473300] PCI-GART: No AMD northbridge found.
[    1.475991] NET: Registered protocol family 2
[    1.520927] IP route cache hash table entries: 1024 (order: 1, 8192 bytes)
[    1.526128] TCP established hash table entries: 4096 (order: 4, 65536 bytes)
[    1.527044] TCP bind hash table entries: 2048 (order: 3, 32768 bytes)
[    1.528173] TCP: Hash tables configured (established 4096 bind 2048)
[    1.528866] TCP reno registered
[    1.549665] microcode: CPU0 not a capable Intel processor
[    1.550345] IA-32 Microcode Update Driver: v1.14a <tigran@veritas.com>
[    1.558342] audit: initializing netlink socket (disabled)
[    1.560656] audit(1486995856.524:1): initialized
[    1.563012] Total HugeTLB memory allocated, 0
[    1.565128] VFS: Disk quotas dquot_6.5.1
[    1.565506] Dquot-cache hash table entries: 512 (order 0, 4096 bytes)
[    1.568190] fuse init (API version 7.8)
[    1.570439] io scheduler noop registered
[    1.570700] io scheduler anticipatory registered
[    1.570913] io scheduler deadline registered (default)
[    1.571242] io scheduler cfq registered
[    1.571703] Limiting direct PCI/PCI transfers.
[    1.571995] PCI: PIIX3: Enabling Passive Release on 0000:00:01.0
[    1.572386] Activating ISA DMA hang workarounds.
[    1.575864] ACPI: Power Button (FF) [PWRF]
[    1.708342] Linux agpgart interface v0.101 (c) Dave Jones
[    1.709041] Serial: 8250/16550 driver $Revision: 1.90 $ 32 ports, IRQ sharing enabled
[    1.710195] serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
[    1.718519] 00:06: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
[    1.722506] RAMDISK driver initialized: 16 RAM disks of 65536K size 1024 blocksize
[    1.724297] loop: loaded (max 8 devices)
[    1.725975] PPP generic driver version 2.4.2
[    1.726381] tun: Universal TUN/TAP device driver, 1.6
[    1.726575] tun: (C) 1999-2004 Max Krasnyansky <maxk@qualcomm.com>
[    1.728690] USB Universal Host Controller Interface driver v3.0
[    1.729632] PNP: PS/2 Controller [PNP0303:KBD,PNP0f13:MOU] at 0x60,0x64 irq 1,12
[    1.731235] serio: i8042 KBD port at 0x60,0x64 irq 1
[    1.731612] serio: i8042 AUX port at 0x60,0x64 irq 12
[    1.732744] mice: PS/2 mouse device common for all mice
[    1.735106] input: AT Translated Set 2 keyboard as /class/input/input0
[    1.736761] i2c /dev entries driver
[    1.737761] device-mapper: ioctl: 4.11.0-ioctl (2006-10-12) initialised: dm-devel@redhat.com
[    1.738663] TCP cubic registered
[    1.738844] NET: Registered protocol family 1
[    1.739287] NET: Registered protocol family 10
[    1.742869] NET: Registered protocol family 17
[    1.744421] powernow-k8: Processor cpuid 663 not supported
[    1.745944] BIOS EDD facility v0.16 2004-Jun-25, 0 devices found
[    1.746164] EDD information not available.
[    1.747925] md: Autodetecting RAID arrays.
[    1.748077] md: autorun ...
[    1.748180] md: ... autorun DONE.
[    1.750934] RAMDISK: Compressed image found at block 0
[    1.879840] kjournald starting.  Commit interval 5 seconds
[    1.880638] EXT3-fs: mounted filesystem with ordered data mode.
[    1.881174] VFS: Mounted root (ext3 filesystem) readonly.
[    1.882070] Freeing unused kernel memory: 240k freed
[    1.905310] Write protecting the kernel read-only data: 1174k
[    1.933120] init[1]: segfault at ffffffffffffffd8 rip 00000000004c91d3 rsp 00007fff975c1538 error 6
[    1.935330] init[1]: segfault at ffffffffffffffd8 rip 00000000004c91d3 rsp 00007fff975c1538 error 6
[    1.935636] init[1]: segfault at ffffffffffffffd8 rip 00000000004c91d3 rsp 00007fff975c1538 error 6

构建内核版本2.6.19和2.6.20

内核.config如下:(文本有限,所以过去在pastbin中)

&#13;
&#13;
<script src="//pastebin.com/embed_js/aR7gLhf9"></script>
&#13;
&#13;
&#13;

initrd image make script:

➜  cat makerootfs.sh 
#!/bin/bash

# Housekeeping...
rm -f /tmp/ramdisk.img
rm -f /tmp/ramdisk.img.gz

# Ramdisk Constants
RDSIZE=4000
BLKSIZE=1024

# Create an empty ramdisk image
dd if=/dev/zero of=/tmp/ramdisk.img bs=$BLKSIZE count=$RDSIZE

# Make it an ext3 mountable file system
/sbin/mke2fs -t ext3 -F -m 0 -b $BLKSIZE /tmp/ramdisk.img $RDSIZE

# Mount it so that we can populate
mount /tmp/ramdisk.img /mnt/initrd -t ext3 -o loop=/dev/loop0

#
cp -a /home/honhe/busybox-1.21.1/_install/* /mnt/initrd
chown root:root -R /mnt/initrd/
chmod +s /mnt/initrd/bin/busybox

# Grab the necessary dev files
mkdir -p /mnt/initrd/dev
mknod -m 622 /mnt/initrd/dev/console c 5 1
mknod -m 622 /mnt/initrd/dev/tty0 c 4 0
cp -a /dev/ram0 /mnt/initrd/dev
cp -a /dev/null /mnt/initrd/dev
cp -a /dev/tty0 /mnt/initrd/dev
cp -a /dev/tty1 /mnt/initrd/dev

# Create the init file
#cat >> /mnt/initrd/init << EOF
##!/bin/ash
#echo
#echo "Simple initrd is active"
#echo
#mount -t proc /proc /proc
#mount -t sysfs none /sys
#/bin/ash --login
#EOF
#chmod +x /mnt/initrd/init

# Finish up...
umount /mnt/initrd
gzip -9 /tmp/ramdisk.img

qemu start命令行:

 sudo qemu-system-x86_64 -nographic -kernel /home/honhe/kernel/linux1/arch/x86_64/boot/bzImage -initrd /tmp/ramdisk.img.gz -serial stdio -append "root=/dev/ram  console=ttyS0 rdinit=/bin/sh"

我使用gdb调试内核,找到导致段错误的函数kernel_execveinit/main.c调用。这是我能跟踪的唯一信息。

708 static void run_init_process(char *init_filename)
709 {
710         argv_init[0] = init_filename;   
711 >>      kernel_execve(init_filename, argv_init, envp_init);
712 }

那是什么导致了这个错误,我该怎么办?

任何帮助都将不胜感激。

编辑2017.02.14
使用相同的环境,构建内核4.9.0并使用QEMU来运行它,如下所示:

[    1.038728] sr 1:0:0:0: Attached scsi generic sg0 type 5
[    1.039799] md: Waiting for all devices to be available before autodetect
[    1.039951] md: If you don't use raid, use raid=noautodetect
[    1.042624] md: Autodetecting RAID arrays.
[    1.042735] md: Scanned 0 and added 0 devices.
[    1.042833] md: autorun ...
[    1.042899] md: ... autorun DONE.
[    1.043978] RAMDISK: gzip image found at block 0
[    1.211667] EXT4-fs (ram0): mounting ext3 file system using the ext4 subsystem
[    1.218562] EXT4-fs (ram0): mounted filesystem with ordered data mode. Opts: (null)
[    1.218996] VFS: Mounted root (ext3 filesystem) readonly on device 1:0.
[    1.221268] devtmpfs: mounted
[    1.251314] Freeing unused kernel memory: 1568K (ffffffff84f80000 - ffffffff85108000)
[    1.251854] Write protecting the kernel read-only data: 14336k
[    1.260913] Freeing unused kernel memory: 1760K (ffff8c9704848000 - ffff8c9704a00000)
[    1.288179] Freeing unused kernel memory: 240K (ffff8c9704dc4000 - ffff8c9704e00000)
can't run '/etc/init.d/rcS': No such file or directory

Please press Enter to activate this console. [    1.697918] tsc: Refined TSC clocksource calibration: 3191.988 MHz
[    1.698559] clocksource: tsc: mask: 0xffffffffffffffff max_cycles: 0x2e02b942467, max_idle_ns: 440795270039 ns
[    2.722816] clocksource: Switched to clocksource tsc

/ # ls
bin         dev         linuxrc     lost+found  sbin        usr
/ # uname -a
Linux (none) 4.9.0+ #7 SMP Tue Feb 14 13:57:18 CST 2017 x86_64 GNU/Linux
/ # 

0 个答案:

没有答案