Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Drop specificdata from KCOV, kMSan doesn't interact well...



details:   https://anonhg.NetBSD.org/src/rev/649ad39c08f6
branches:  trunk
changeset: 970783:649ad39c08f6
user:      maxv <maxv%NetBSD.org@localhost>
date:      Sat Apr 04 06:51:46 2020 +0000

description:
Drop specificdata from KCOV, kMSan doesn't interact well with it. Also
reduces the overhead.

diffstat:

 sys/kern/kern_lwp.c  |   6 ++++--
 sys/kern/subr_kcov.c |  40 +++++++++++++++++++---------------------
 sys/sys/kcov.h       |  16 ++++++++++++++--
 sys/sys/lwp.h        |   6 +++++-
 4 files changed, 42 insertions(+), 26 deletions(-)

diffs (227 lines):

diff -r 0eb48b2cfb6d -r 649ad39c08f6 sys/kern/kern_lwp.c
--- a/sys/kern/kern_lwp.c       Sat Apr 04 03:35:01 2020 +0000
+++ b/sys/kern/kern_lwp.c       Sat Apr 04 06:51:46 2020 +0000
@@ -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 @@
 #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 @@
                kmem_free(l->l_name, MAXCOMLEN);
 
        kmsan_lwp_free(l);
+       kcov_lwp_free(l);
        cpu_lwp_free2(l);
        uvm_lwp_exit(l);
 
diff -r 0eb48b2cfb6d -r 649ad39c08f6 sys/kern/subr_kcov.c
--- a/sys/kern/subr_kcov.c      Sat Apr 04 03:35:01 2020 +0000
+++ b/sys/kern/subr_kcov.c      Sat Apr 04 06:51:46 2020 +0000
@@ -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 @@
        bool lwpfree;
 } kcov_t;
 
-static specificdata_key_t kcov_lwp_key;
-
 static void
 kcov_lock(kcov_t *kd)
 {
@@ -143,10 +141,10 @@
        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 @@
 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 @@
                        error = EBUSY;
                        break;
                }
-               if (lwp_getspecific(kcov_lwp_key) != NULL) {
+               if (l->l_kcov != NULL) {
                        error = EBUSY;
                        break;
                }
@@ -278,7 +277,7 @@
                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 @@
                        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 @@
        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 @@
                return;
        }
 
-       kd = lwp_getspecific(kcov_lwp_key);
+       kd = curlwp->l_kcov;
        if (__predict_true(kd == NULL)) {
                /* Not traced. */
                return;
@@ -405,7 +411,7 @@
                return;
        }
 
-       kd = lwp_getspecific(kcov_lwp_key);
+       kd = curlwp->l_kcov;
        if (__predict_true(kd == NULL)) {
                /* Not traced. */
                return;
@@ -549,20 +555,12 @@
 
 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;
diff -r 0eb48b2cfb6d -r 649ad39c08f6 sys/sys/kcov.h
--- a/sys/sys/kcov.h    Sat Apr 04 03:35:01 2020 +0000
+++ b/sys/sys/kcov.h    Sat Apr 04 06:51:46 2020 +0000
@@ -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_ */
diff -r 0eb48b2cfb6d -r 649ad39c08f6 sys/sys/lwp.h
--- a/sys/sys/lwp.h     Sat Apr 04 03:35:01 2020 +0000
+++ b/sys/sys/lwp.h     Sat Apr 04 06:51:46 2020 +0000
@@ -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 @@
 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 @@
 #ifdef KMSAN
        void            *l_kmsan; /* !: KMSAN private data. */
 #endif
+#ifdef KCOV
+       void            *l_kcov; /* !: KCOV private data. */
+#endif
 };
 
 /*



Home | Main Index | Thread Index | Old Index