kernel vm question

From: Jacques Fourie (jf_at_trispen.com)
Date: 01/27/05

  • Next message: Zera William Holladay: "Re: kernel vm question"
    Date: Thu, 27 Jan 2005 09:57:04 -0500
    To: freebsd-hackers@freebsd.org
    
    
    

    Hi,

    I have a kernel module with the following entry point :

    static int test_modevent(module_t mod, int type, void *unused)
    {
       int s;
       unsigned char *p = NULL;
       unsigned char v = 0x55;

       switch (type)
         {
         case MOD_LOAD:
           p = (unsigned char *)ip_output;

           s = splhigh();

           v = p[0]; /* Page fault without this line */
           p[0] = v;
           printf("val = %02X\n", v);

           splx(s);
           break;

         case MOD_UNLOAD:
           break;

         default:
           break;
         }

       return 0;
    }

    If I remove the line "Page fault without this line" line, I get a page
    fault when loading this module. This crash seems to be hardware as well
    as version specific - I can not reproduce the crash on 4.8 but on one
    particular piece of hardware it crashes consistently on 4.9 and 4.10.
    Could someone please help me in understanding this behaviour? Attached
    is the full kernel module source and a dmesg of the hardware in question.

    regards,
    jacques

    
    

    Copyright (c) 1992-2004 The FreeBSD Project.
    Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
            The Regents of the University of California. All rights reserved.
    FreeBSD 4.10-RELEASE #2: Thu Jan 27 14:36:20 SAST 2005
        jacques@fbsd410.trispen.com:/usr/src/sys/compile/MYKERN
    Timecounter "i8254" frequency 1193182 Hz
    Timecounter "TSC" frequency 2657822812 Hz
    CPU: Intel(R) Xeon(TM) CPU 2.66GHz (2657.82-MHz 686-class CPU)
      Origin = "GenuineIntel" Id = 0xf29 Stepping = 9
      Features=0xbfebfbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CLFLUSH,DTS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE>
      Hyperthreading: 2 logical CPUs
    real memory = 4160225280 (4062720K bytes)
    avail memory = 4054249472 (3959228K bytes)
    Preloaded elf kernel "kernel" at 0xc0353000.
    Warning: Pentium 4 CPU: PSE disabled
    Pentium Pro MTRR support enabled
    md0: Malloc disk
    Using $PIR table, 20 entries at 0xc00fde80
    npx0: <math processor> on motherboard
    npx0: INT 16 interface
    pcib0: <Host to PCI bridge> on motherboard
    pci0: <PCI bus> on pcib0
    pci0: <unknown card> (vendor=0x8086, dev=0x2541) at 0.1
    pcib1: <PCI to PCI bridge (vendor=8086 device=2543)> at device 2.0 on pci0
    pci1: <PCI bus> on pcib1
    pci1: <unknown card> (vendor=0x8086, dev=0x1461) at 28.0
    pcib2: <PCI to PCI bridge (vendor=8086 device=1460)> at device 29.0 on pci1
    pci2: <PCI bus> on pcib2
    pci1: <unknown card> (vendor=0x8086, dev=0x1461) at 30.0
    pcib3: <PCI to PCI bridge (vendor=8086 device=1460)> at device 31.0 on pci1
    pci3: <PCI bus> on pcib3
    em0: <Intel(R) PRO/1000 Network Connection, Version - 1.7.25> port 0x7000-0x703f mem 0xfc200000-0xfc23ffff,0xfc280000-0xfc29ffff irq 10 at device 1.0 on pci3
    em0: Speed:N/A Duplex:N/A
    em1: <Intel(R) PRO/1000 Network Connection, Version - 1.7.25> port 0x7040-0x707f mem 0xfc240000-0xfc27ffff,0xfc2a0000-0xfc2bffff irq 10 at device 1.1 on pci3
    em1: Speed:N/A Duplex:N/A
    pci0: <unknown card> (vendor=0x8086, dev=0x2544) at 2.1
    pci0: <UHCI USB controller> at 29.0 irq 10
    pci0: <UHCI USB controller> at 29.1 irq 5
    pci0: <UHCI USB controller> at 29.2 irq 10
    pcib4: <Intel 82801BA/BAM (ICH2) Hub to PCI bridge> at device 30.0 on pci0
    pci4: <PCI bus> on pcib4
    pci4: <ATI Mach64-GR graphics accelerator> at 3.0 irq 11
    fxp0: <Intel 82550 Pro/100 Ethernet> port 0x8400-0x843f mem 0xfc300000-0xfc31ffff,0xfc341000-0xfc341fff irq 10 at device 4.0 on pci4
    fxp0: Ethernet address 00:04:23:ae:8c:1d
    inphy0: <i82555 10/100 media interface> on miibus0
    inphy0: 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, auto
    em2: <Intel(R) PRO/1000 Network Connection, Version - 1.7.25> port 0x8440-0x847f mem 0xfc320000-0xfc33ffff irq 11 at device 5.0 on pci4
    em2: Speed:N/A Duplex:N/A
    isab0: <PCI to ISA bridge (vendor=8086 device=2480)> at device 31.0 on pci0
    isa0: <ISA bus> on isab0
    atapci0: <Intel ICH3 ATA100 controller> port 0x6c60-0x6c6f,0-0x3,0-0x7,0-0x3,0-0x7 irq 0 at device 31.1 on pci0
    ata0: at 0x1f0 irq 14 on atapci0
    ata1: at 0x170 irq 15 on atapci0
    pci0: <unknown card> (vendor=0x8086, dev=0x2483) at 31.3 irq 0
    orm0: <Option ROMs> at iomem 0xc0000-0xc7fff,0xe3000-0xe3fff on isa0
    pmtimer0 on isa0
    atkbdc0: <Keyboard controller (i8042)> at port 0x60,0x64 on isa0
    atkbd0: <AT Keyboard> irq 1 on atkbdc0
    vga0: <Generic ISA VGA> at port 0x3c0-0x3df iomem 0xa0000-0xbffff on isa0
    sc0: <System console> on isa0
    sc0: VGA <16 virtual consoles, flags=0x200>
    sio0 at port 0x3f8-0x3ff irq 4 flags 0x80 on isa0
    sio0: type 16550A
    ppc0: <Parallel port> at port 0x378-0x37f irq 7 on isa0
    ppc0: SMC-like chipset (ECP/EPP/PS2/NIBBLE) in COMPATIBLE mode
    ppc0: FIFO with 16/16/9 bytes threshold
    ipfw2 initialized, divert enabled, rule-based forwarding enabled, default to accept, logging limited to 100 packets/entry by default
    DUMMYNET initialized (011031)
    ad0: 76319MB <ST380011A> [155061/16/63] at ata0-master UDMA100
    acd0: DVD-R <Slimtype DVDRW SOSW-852S> at ata1-master PIO4
    Mounting root from ufs:/dev/ad0s1a
    WARNING: / was not properly dismounted
    uhci0: <Intel 82801CA/CAM (ICH3) USB controller USB-A> port 0x6c00-0x6c1f irq 10 at device 29.0 on pci0
    usb0: <Intel 82801CA/CAM (ICH3) USB controller USB-A> on uhci0
    usb0: USB revision 1.0
    uhub0: Intel UHCI root hub, class 9/0, rev 1.00/1.00, addr 1
    uhub0: 2 ports with 2 removable, self powered
    uhci1: <Intel 82801CA/CAM (ICH3) USB controller USB-B> port 0x6c20-0x6c3f irq 5 at device 29.1 on pci0
    usb1: <Intel 82801CA/CAM (ICH3) USB controller USB-B> on uhci1
    usb1: USB revision 1.0
    uhub1: Intel UHCI root hub, class 9/0, rev 1.00/1.00, addr 1
    uhub1: 2 ports with 2 removable, self powered
    uhci2: <Intel 82801CA/CAM (ICH3) USB controller USB-C> port 0x6c40-0x6c5f irq 10 at device 29.2 on pci0
    usb2: <Intel 82801CA/CAM (ICH3) USB controller USB-C> on uhci2
    usb2: USB revision 1.0
    uhub2: Intel UHCI root hub, class 9/0, rev 1.00/1.00, addr 1
    uhub2: 2 ports with 2 removable, self powered

    
    

    #include <sys/param.h>
    #include <sys/systm.h>
    #include <sys/kernel.h>
    #include <sys/malloc.h>
    #include <sys/mbuf.h>
    #include <sys/protosw.h>
    #include <sys/socket.h>
    #include <sys/socketvar.h>
    #include <sys/proc.h>
    #include <sys/sysctl.h>

    #include <net/if.h>
    #include <net/route.h>

    #include <netinet/in.h>
    #include <netinet/in_systm.h>
    #include <netinet/ip.h>
    #include <netinet/in_pcb.h>
    #include <netinet/in_var.h>
    #include <netinet/ip_var.h>

    static int test_modevent(module_t mod, int type, void *unused)
    {
      int s;
      unsigned char *p = NULL;
      unsigned char v = 0x55;

      switch (type)
        {
        case MOD_LOAD:
          p = (unsigned char *)ip_output;

          s = splhigh();
          
          v = p[0];
          p[0] = v;
          printf("val = %02X\n", v);

          splx(s);
          break;

        case MOD_UNLOAD:
          break;

        default:
          break;
        }
        
      return 0;
    }

    moduledata_t testmod = {
      "test",
      test_modevent,
      0
    };

    DECLARE_MODULE(test, testmod, SI_SUB_DRIVERS, SI_ORDER_ANY);

    
    

    _______________________________________________
    freebsd-hackers@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
    To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"


  • Next message: Zera William Holladay: "Re: kernel vm question"

    Relevant Pages

    • [PATCH] spelling fixes: arch/ia64/
      ... do this dynamically on cpu arrival/departure. ... static int lsapic_retrigger ... - * Indices in rm map range from 1..num_entries. ...
      (Linux-Kernel)
    • [PATCH][2.6.8.1-mm4] Clustered APIC support for x86-64
      ... -static inline void clustered_apic_check ... * Copyright 2004 James Cleverdon, ... +/* which logical CPU number maps to which CPU */ ... +static void cluster_send_IPI_mask(cpumask_t mask, int vector) ...
      (Linux-Kernel)
    • Re: [PATCH 1/2] kthread_create
      ... to be created when a CPU goes online. ... D: 2) Getting the task struct without races is a hard: see kernel/sched.c ... +void kthread_bind(struct task_struct *k, unsigned int cpu); ...
      (Linux-Kernel)
    • Re: [PATCH 3/6]init call cleanup
      ... In CPU identify part, only did cleaup ... +void __devinit setup_local_APIC ... -static void __init apic_pm_activate ... -static void __init setup_APIC_timer(unsigned int clocks) ...
      (Linux-Kernel)
    • [PATCH] ppc64: cleanup/split SMP code
      ... Fix pSeries secondary CPU setup ... +extern void pseries_secondary_smp_init; ... +static int query_cpu_stopped ...
      (Linux-Kernel)