From: Alexander Shishkin <alexander.shishkin@linux.intel.com>
To: Dmitry Vyukov <dvyukov@google.com>,
syzkaller@googlegroups.com, vegard.nossum@oracle.com,
catalin.marinas@arm.com, taviso@google.com, will.deacon@arm.com,
linux-kernel@vger.kernel.org, quentin.casasnovas@oracle.com,
kcc@google.com, edumazet@google.com, glider@google.com,
keescook@google.com, bhelgaas@google.com, sasha.levin@oracle.com,
akpm@linux-foundation.org, drysdale@google.com,
linux-arm-kernel@lists.infradead.org, ard.biesheuvel@linaro.org,
ryabinin.a.a@gmail.com, kirill@shutemov.name,
Peter Zijlstra <peterz@infradead.org>
Cc: Dmitry Vyukov <dvyukov@google.com>
Subject: Re: [PATCH v6] kernel: add kcov code coverage
Date: Thu, 28 Jan 2016 14:30:51 +0200 [thread overview]
Message-ID: <87si1h6g3o.fsf@ashishki-desk.ger.corp.intel.com> (raw)
In-Reply-To: <1453726850-49137-1-git-send-email-dvyukov@google.com>
Dmitry Vyukov <dvyukov@google.com> writes:
> + fd = open("/sys/kernel/debug/kcov", O_RDWR);
> + if (fd == -1)
> + perror("open"), exit(1);
> + /* Setup trace mode and trace size. */
> + if (ioctl(fd, KCOV_INIT_TRACE, COVER_SIZE))
> + perror("ioctl"), exit(1);
> + /* Mmap buffer shared between kernel- and user-space. */
> + cover = (unsigned long*)mmap(NULL, COVER_SIZE * sizeof(unsigned long),
> + PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
> + if ((void*)cover == MAP_FAILED)
> + perror("mmap"), exit(1);
> + /* Enable coverage collection on the current thread. */
> + if (ioctl(fd, KCOV_ENABLE, 0))
> + perror("ioctl"), exit(1);
> + /* Reset coverage from the tail of the ioctl() call. */
> + __atomic_store_n(&cover[0], 0, __ATOMIC_RELAXED);
> + /* That's the target syscal call. */
> + read(-1, NULL, 0);
> + /* Read number of PCs collected. */
> + n = __atomic_load_n(&cover[0], __ATOMIC_RELAXED);
> + for (i = 0; i < n; i++)
> + printf("0x%lx\n", cover[i + 1]);
Kirill is right, this does look a lot like a candidate for a perf
pmu. Most of the legwork that you do in this patch is already taken care
of by perf afaict: enabling/disabling, context tracking, ring buffer for
exporting data to userspace. You'll also get other things like privilege
separation for free.
Moreover, this can already be achieved by means of hardware assisted
instruction tracing such as BTS or PT on Intel cpus (BTS will literally
output instruction pointer addresses into a ring buffer). ARM Coresight
ETM/PTM support is also on its way. That's not to say that this work is
not useful (and it's gotta be, or who will be the one to debug the
debugger), but more to make a case for a perf-based implementation.
Regards,
--
Alex
next prev parent reply other threads:[~2016-01-28 12:31 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-25 13:00 Dmitry Vyukov
2016-01-25 13:03 ` Dmitry Vyukov
2016-01-25 15:38 ` Kirill A. Shutemov
2016-01-25 13:53 ` kbuild test robot
2016-01-28 12:30 ` Alexander Shishkin [this message]
2016-02-02 16:02 ` Andrey Ryabinin
2016-02-04 15:07 ` Dmitry Vyukov
2016-02-04 15:19 ` Andrey Ryabinin
2016-02-02 17:19 ` Jiri Slaby
2016-02-04 15:07 ` Dmitry Vyukov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87si1h6g3o.fsf@ashishki-desk.ger.corp.intel.com \
--to=alexander.shishkin@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=ard.biesheuvel@linaro.org \
--cc=bhelgaas@google.com \
--cc=catalin.marinas@arm.com \
--cc=drysdale@google.com \
--cc=dvyukov@google.com \
--cc=edumazet@google.com \
--cc=glider@google.com \
--cc=kcc@google.com \
--cc=keescook@google.com \
--cc=kirill@shutemov.name \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=quentin.casasnovas@oracle.com \
--cc=ryabinin.a.a@gmail.com \
--cc=sasha.levin@oracle.com \
--cc=syzkaller@googlegroups.com \
--cc=taviso@google.com \
--cc=vegard.nossum@oracle.com \
--cc=will.deacon@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®