Drop specificdata from KCOV, kMSan doesn't interact well with it. Also

reduces the overhead.
This commit is contained in:
maxv 2020-04-04 06:51:46 +00:00
parent a4770732da
commit b3036422e2
4 changed files with 42 additions and 26 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_lwp.c,v 1.231 2020/03/26 21:31:55 ad Exp $ */
/* $NetBSD: kern_lwp.c,v 1.232 2020/04/04 06:51:46 maxv Exp $ */
/*-
* Copyright (c) 2001, 2006, 2007, 2008, 2009, 2019, 2020
@ -211,7 +211,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.231 2020/03/26 21:31:55 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.232 2020/04/04 06:51:46 maxv Exp $");
#include "opt_ddb.h"
#include "opt_lockdebug.h"
@ -244,6 +244,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.231 2020/03/26 21:31:55 ad Exp $");
#include <sys/sysctl.h>
#include <sys/psref.h>
#include <sys/msan.h>
#include <sys/kcov.h>
#include <uvm/uvm_extern.h>
#include <uvm/uvm_object.h>
@ -1360,6 +1361,7 @@ lwp_free(struct lwp *l, bool recycle, bool last)
kmem_free(l->l_name, MAXCOMLEN);
kmsan_lwp_free(l);
kcov_lwp_free(l);
cpu_lwp_free2(l);
uvm_lwp_exit(l);

View File

@ -1,7 +1,7 @@
/* $NetBSD: subr_kcov.c,v 1.11 2019/12/07 19:50:33 kamil Exp $ */
/* $NetBSD: subr_kcov.c,v 1.12 2020/04/04 06:51:46 maxv Exp $ */
/*
* Copyright (c) 2019 The NetBSD Foundation, Inc.
* Copyright (c) 2019-2020 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@ -115,8 +115,6 @@ typedef struct kcov_desc {
bool lwpfree;
} kcov_t;
static specificdata_key_t kcov_lwp_key;
static void
kcov_lock(kcov_t *kd)
{
@ -143,10 +141,10 @@ kcov_free(kcov_t *kd)
kmem_free(kd, sizeof(*kd));
}
static void
kcov_lwp_free(void *arg)
void
kcov_lwp_free(struct lwp *l)
{
kcov_t *kd = (kcov_t *)arg;
kcov_t *kd = (kcov_t *)l->l_kcov;
if (kd == NULL) {
return;
@ -234,6 +232,7 @@ kcov_fops_close(file_t *fp)
static int
kcov_fops_ioctl(file_t *fp, u_long cmd, void *addr)
{
struct lwp *l = curlwp;
int error = 0;
int mode;
kcov_t *kd;
@ -256,7 +255,7 @@ kcov_fops_ioctl(file_t *fp, u_long cmd, void *addr)
error = EBUSY;
break;
}
if (lwp_getspecific(kcov_lwp_key) != NULL) {
if (l->l_kcov != NULL) {
error = EBUSY;
break;
}
@ -278,7 +277,7 @@ kcov_fops_ioctl(file_t *fp, u_long cmd, void *addr)
if (error)
break;
lwp_setspecific(kcov_lwp_key, kd);
l->l_kcov = kd;
kd->enabled = true;
break;
case KCOV_IOC_DISABLE:
@ -286,11 +285,11 @@ kcov_fops_ioctl(file_t *fp, u_long cmd, void *addr)
error = ENOENT;
break;
}
if (lwp_getspecific(kcov_lwp_key) != kd) {
if (l->l_kcov != kd) {
error = ENOENT;
break;
}
lwp_setspecific(kcov_lwp_key, NULL);
l->l_kcov = NULL;
kd->enabled = false;
break;
default:
@ -339,6 +338,13 @@ out:
return error;
}
/* -------------------------------------------------------------------------- */
/*
* Constraints on the functions here: they must be marked with __nomsan, and
* must not make any external call.
*/
static inline bool __nomsan
in_interrupt(void)
{
@ -364,7 +370,7 @@ __sanitizer_cov_trace_pc(void)
return;
}
kd = lwp_getspecific(kcov_lwp_key);
kd = curlwp->l_kcov;
if (__predict_true(kd == NULL)) {
/* Not traced. */
return;
@ -405,7 +411,7 @@ trace_cmp(uint64_t type, uint64_t arg1, uint64_t arg2, intptr_t pc)
return;
}
kd = lwp_getspecific(kcov_lwp_key);
kd = curlwp->l_kcov;
if (__predict_true(kd == NULL)) {
/* Not traced. */
return;
@ -549,20 +555,12 @@ __sanitizer_cov_trace_switch(uint64_t val, uint64_t *cases)
MODULE(MODULE_CLASS_MISC, kcov, NULL);
static void
kcov_init(void)
{
lwp_specific_key_create(&kcov_lwp_key, kcov_lwp_free);
}
static int
kcov_modcmd(modcmd_t cmd, void *arg)
{
switch (cmd) {
case MODULE_CMD_INIT:
kcov_init();
return 0;
case MODULE_CMD_FINI:
return EINVAL;

View File

@ -1,7 +1,7 @@
/* $NetBSD: kcov.h,v 1.6 2019/05/26 01:44:34 kamil Exp $ */
/* $NetBSD: kcov.h,v 1.7 2020/04/04 06:51:46 maxv Exp $ */
/*
* Copyright (c) 2019 The NetBSD Foundation, Inc.
* Copyright (c) 2019-2020 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@ -32,6 +32,10 @@
#ifndef _SYS_KCOV_H_
#define _SYS_KCOV_H_
#ifdef _KERNEL_OPT
#include "opt_kcov.h"
#endif
#include <sys/param.h>
#include <sys/types.h>
#include <sys/atomic.h>
@ -47,4 +51,12 @@
typedef volatile uint64_t kcov_int_t;
#define KCOV_ENTRY_SIZE sizeof(kcov_int_t)
#ifdef _KERNEL
#ifdef KCOV
void kcov_lwp_free(struct lwp *);
#else
#define kcov_lwp_free(a) __nothing
#endif
#endif
#endif /* !_SYS_KCOV_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: lwp.h,v 1.203 2020/03/26 19:46:42 ad Exp $ */
/* $NetBSD: lwp.h,v 1.204 2020/04/04 06:51:46 maxv Exp $ */
/*
* Copyright (c) 2001, 2006, 2007, 2008, 2009, 2010, 2019, 2020
@ -54,6 +54,7 @@ struct lwp;
static __inline struct cpu_info *lwp_getcpu(struct lwp *);
#include <machine/cpu.h> /* curcpu() and cpu_info */
#ifdef _KERNEL_OPT
#include "opt_kcov.h"
#include "opt_kmsan.h"
#endif
#endif
@ -209,6 +210,9 @@ struct lwp {
#ifdef KMSAN
void *l_kmsan; /* !: KMSAN private data. */
#endif
#ifdef KCOV
void *l_kcov; /* !: KCOV private data. */
#endif
};
/*