Bug 165984 - [libpmc] pmc(3) causes kernel panic when sampling current process
Summary: [libpmc] pmc(3) causes kernel panic when sampling current process
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 8.2-RELEASE
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-12 19:30 UTC by Vitaly Magerya
Modified: 2017-12-31 22:32 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vitaly Magerya 2012-03-12 19:30:13 UTC
While trying to use pmc(3) framework to sample current process, I'm
reliably getting a panic. The message on the screen says:

    kernel trap 9 with interrupt disabled

    Fatal trap 9: general protection fault while in kernel mode
    cpuid = 0; apic id = 00
    instruction pointer     = 0x20:0xffffffff80e81707
    stack pointer           = 0x28:0xffffffff80bd68d0
    frame pointer           = 0x28:0xffffffff80bd6920
    code segment            = base rx0, limit 0xfffff, type 0x1b
                            = DPL 0, pres 1, long 1, def32 0, gran 1
    processor eflags        = resume, IOPL = 0
    current process         = 10201 (a.out)
    trap number             = 9
    panic: general protection fault
    pcuid = 0
    KDB: stack backtrace:
    #0 0xffffffff805f4e0e at kdb_backtrace+0x5e
    #1 0xffffffff805c2d07 at panic+0x187
    #2 0xffffffff808ac600 at trap_fatal+0x290
    #3 0xffffffff808acbe9 at trap+0x109
    #4 0xffffffff80894fb4 at calltrap+0x8
    #5 0xffffffff808acc30 at trap+0x150
    #6 0xffffffff80895384 at nmi_calltrap+0x8
    Uptime: 16h57m31s
    Cannot dump. Device not defined or unavailable.
    Automatic reboot in 15 seconds - press a key on the console to abort

The system is an Intel Atom 330 box running FreeBSD 8.2 amd64.

If it makes any difference, here's what I have in /boot/loader.conf:

    kern.hwpmc.nsamples="64"
    kern.hwpmc.nbuffers="64"

I can provide more details about my box on request, but the problem
may be generic.

How-To-Repeat: Take the program below, compile it, load hwpmc(4) kernel module and 
execute the program, like this:

    # kldload hwpmc
    $ cc -lpmc crash.c
    $ ./a.out

---- crash.c ----

#include <sys/types.h>
#include <pmc.h>
#include <fcntl.h>

int main() {
    pmc_id_t pmcid;
    pmc_value_t value;
    int fd, i;

    pmc_init();
    pmc_allocate("instructions", PMC_MODE_TS, 0, PMC_CPU_ANY, &pmcid);
    fd = open("pmc.log", O_WRONLY|O_CREAT|O_TRUNC, 0666);
    pmc_configure_logfile(fd);
    pmc_start(pmcid);
    for (i = 0; i < 10*1000000; i++);
    pmc_stop(pmcid);
    pmc_flush_logfile();
    pmc_release(pmcid);
    return 0;
}
Comment 1 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 07:59:58 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped