From nobody Sun Oct 5 19:46:04 2025 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E5A382D0275 for ; Thu, 31 Jul 2025 11:52:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753962727; cv=none; b=im1Y3WDCjUfd5UmLDJaGlgsfBlPMf6IB75cbD9nSx659VgmpOOguserT1g2rgoMLXYarj2fmgtMIsqkkwc/us7/suY0YxnCqtnnx5tvcuxPxMnDQIq22ImeEhokMF+kTIe4nUq4QBRbBVPH1uJEc0Bl7ybYRePMy/QgKDsVXmcE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753962727; c=relaxed/simple; bh=QFA8j7SQOVxFc/i0AuPkiRtB7FNb/J7gKEV/pzhSERM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=DsEFaZYynpVBgbqcjPTm+P01JIhMD7O1qlRa72Y0TQF4DXtSFqdiMD9hAfXwvC6UB/f9hNjD+nr+J0JaS9UlNvfn/hPRIS9ba99vxXrd8TaVm82nvib1oE+9djlNRked2q32Db4ZlaUXtmwjHQn05Ee5to6QgvRlgfkzSzfJtTU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--glider.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=YpP3S1rS; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--glider.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="YpP3S1rS" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-451d30992bcso5545505e9.2 for ; Thu, 31 Jul 2025 04:52:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753962723; x=1754567523; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Wxltob97dGGsyXvDSMkg1S6ftRZJNYows0FnYbt40l0=; b=YpP3S1rSzHDGLXxBaP2LBJCsgwmoWZQcXGZ91KK9oAlt6Dp0iCWiKXKnhkFDQsolyQ /ZWHdcMOVQf5risY7NV6VqQI+4gqoB1DQgE0xhzx4zoiXzJ6JfXTncrTjdxe5Ms+Idly 1Jg3MZl5tSK9gpe2h492TZRahwyeHUtcgau9MwCWlIdtJF1hcCuBm5NrV83mNVjK9kFR zzOuisPJG4vnvnMQFXbQ3LDG4+Yk8F7hln/1gzglcQUckzweBHHLkQOEZBjhdYGDjTqi jcOjfh1WflHwVrD3H3OzldOPZnAURFTp2LJ6QqCy4rXh+nfbLSnh1xTJWif46+CqV98f OTwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753962723; x=1754567523; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Wxltob97dGGsyXvDSMkg1S6ftRZJNYows0FnYbt40l0=; b=a47bdY7B0uN9Yy9PkoMhhgBEmoOrtA/zyilOH/M6EMbjp4xhPhKXeRb5Bk/6OJgHLs r9fXgSJVFXHZ7TDXNnVv3oAYOynsT7E3ZhBuzubz8JAeGmJEA+3mJnL7KI1KeZMyRSLp kGwO7ynFMaqpHxhrWVAM3vxlbfZzotdryzKIAM5D7tqlps3VLSiJdR0eYqSoD/EgBg1d vL0yuQi5Ya9MND0wL1s1HQQCt60Ztd3cWeMUbarzxdZoZzJspJ5S/G3ORjNWsmby+Koc WqviFONVBq3uTIABjTUwnAwP/Os3DUDBQovO0A0GWqvnNb2wxl8dFBufdN40bJndtPL7 q6lg== X-Forwarded-Encrypted: i=1; AJvYcCWaKczTCX/RxEf3JWxKaqoIj/TVTlg8/0Y1Rq145E9aPtPoYL03WmPdXrLXZMwbh0S0bioIpE6zhGn/Av4=@vger.kernel.org X-Gm-Message-State: AOJu0Yz8Uc/bPjrGrMk2qM5GlGSCAGCnN/knsaNK5eqa8I7I3jt0HJx1 cXjtlF3UL/VVaLvP6e8cXS7K/E8JHEAspzzpU6qMYZft8EwUP8yO83Iv1W0KlDizLJqTNTIhNjE +ERk5nQ== X-Google-Smtp-Source: AGHT+IFczRzgbAWMCrFR+KuaSw8jlM2FhbJ4UCMBla1L68NW1HL1ZxJDw+kXgA8OIQOhdu+rFoC0wF435Fo= X-Received: from wmbet6.prod.google.com ([2002:a05:600c:8186:b0:454:d702:f3c2]) (user=glider job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1f92:b0:43c:f44c:72a6 with SMTP id 5b1f17b1804b1-45892b9341emr73441445e9.2.1753962723337; Thu, 31 Jul 2025 04:52:03 -0700 (PDT) Date: Thu, 31 Jul 2025 13:51:36 +0200 In-Reply-To: <20250731115139.3035888-1-glider@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250731115139.3035888-1-glider@google.com> X-Mailer: git-send-email 2.50.1.552.g942d659e1b-goog Message-ID: <20250731115139.3035888-8-glider@google.com> Subject: [PATCH v4 07/10] kcov: add ioctl(KCOV_UNIQUE_ENABLE) From: Alexander Potapenko To: glider@google.com Cc: quic_jiangenj@quicinc.com, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, Dmitry Vyukov , Aleksandr Nogikh , Andrey Konovalov , Borislav Petkov , Dave Hansen , Ingo Molnar , Josh Poimboeuf , Marco Elver , Peter Zijlstra , Thomas Gleixner Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" ioctl(KCOV_UNIQUE_ENABLE) enables collection of deduplicated coverage in the presence of CONFIG_KCOV_ENABLE_GUARDS. The buffer shared with the userspace is divided in two parts, one holding a bitmap, and the other one being the trace. The single parameter of ioctl(KCOV_UNIQUE_ENABLE) determines the number of words used for the bitmap. Each __sanitizer_cov_trace_pc_guard() instrumentation hook receives a pointer to a unique guard variable. Upon the first call of each hook, the guard variable is initialized with a unique integer, which is used to map those hooks to bits in the bitmap. In the new coverage collection mode, the kernel first checks whether the bit corresponding to a particular hook is set, and then, if it is not, the PC is written into the trace buffer, and the bit is set. Note: when CONFIG_KCOV_ENABLE_GUARDS is disabled, ioctl(KCOV_UNIQUE_ENABLE) returns -ENOTSUPP, which is consistent with the existing kcov code. Measuring the exact performance impact of this mode directly can be challenging. However, based on fuzzing experiments (50 instances x 24h with and without deduplication), we observe the following: - When normalized by pure fuzzing time, total executions decreased by 2.1% (p=3D0.01). - When normalized by fuzzer uptime, the reduction in total executions was statistically insignificant (-1.0% with p=3D0.20). Despite a potential slight slowdown in execution count, the new mode positively impacts fuzzing effectiveness: - Statistically significant increase in corpus size (+0.6%, p<0.01). - Statistically significant increase in coverage (+0.6%, p<0.01). - A 99.8% reduction in coverage overflows. Also update the documentation. Signed-off-by: Alexander Potapenko Reviewed-by: Dmitry Vyukov --- v4: Add Reviewed-by: Dmitry Vyukov v3: - s/check_kcov_mode/get_kcov_mode in objtool v2: - Address comments by Dmitry Vyukov: - rename CONFIG_KCOV_ENABLE_GUARDS to CONFIG_KCOV_UNIQUE - rename KCOV_MODE_TRACE_UNIQUE_PC to KCOV_MODE_UNIQUE_PC - simplify index allocation - update documentation and comments - Address comments by Marco Elver: - change _IOR to _IOW in KCOV_UNIQUE_ENABLE definition - rename sanitizer_cov_write_subsequent() to kcov_append_to_buffer() - Use __test_and_set_bit() to avoid the lock prefix on the bit operation - Update code to match the new description of struct kcov_state - Rename kcov_get_mode() to kcov_arg_to_mode() to avoid confusion with get_kcov_mode(). Also make it use `enum kcov_mode`. Change-Id: I9805e7b22619a50e05cc7c7d794dacf6f7de2f03 --- Documentation/dev-tools/kcov.rst | 43 ++++++++ include/linux/kcov.h | 2 + include/linux/kcov_types.h | 8 ++ include/uapi/linux/kcov.h | 1 + kernel/kcov.c | 164 ++++++++++++++++++++++++++----- tools/objtool/check.c | 2 +- 6 files changed, 193 insertions(+), 27 deletions(-) diff --git a/Documentation/dev-tools/kcov.rst b/Documentation/dev-tools/kco= v.rst index abf3ad2e784e8..6446887cd1c92 100644 --- a/Documentation/dev-tools/kcov.rst +++ b/Documentation/dev-tools/kcov.rst @@ -192,6 +192,49 @@ Normally the shared buffer is used as follows:: up to the buffer[0] value saved above | =20 =20 +Unique coverage collection +--------------------------- + +Instead of collecting a trace of PCs, KCOV can deduplicate them on the fly. +This mode is enabled by the ``KCOV_UNIQUE_ENABLE`` ioctl (only available if +``CONFIG_KCOV_UNIQUE`` is on). + +.. code-block:: c + + /* Same includes and defines as above. */ + #define KCOV_UNIQUE_ENABLE _IOW('c', 103, unsigned long) + #define BITMAP_SIZE (4<<10) + + /* Instead of KCOV_ENABLE, enable unique coverage collection. */ + if (ioctl(fd, KCOV_UNIQUE_ENABLE, BITMAP_SIZE)) + perror("ioctl"), exit(1); + /* Reset the coverage from the tail of the ioctl() call. */ + __atomic_store_n(&cover[BITMAP_SIZE], 0, __ATOMIC_RELAXED); + memset(cover, 0, BITMAP_SIZE * sizeof(unsigned long)); + + /* Call the target syscall call. */ + /* ... */ + + /* Read the number of collected PCs. */ + n =3D __atomic_load_n(&cover[BITMAP_SIZE], __ATOMIC_RELAXED); + /* Disable the coverage collection. */ + if (ioctl(fd, KCOV_DISABLE, 0)) + perror("ioctl"), exit(1); + +Calling ``ioctl(fd, KCOV_UNIQUE_ENABLE, bitmap_size)`` carves out ``bitmap= _size`` +unsigned long's from those allocated by ``KCOV_INIT_TRACE`` to keep an opa= que +bitmap that prevents the kernel from storing the same PC twice. The remain= ing +part of the buffer is used to collect PCs, like in other modes (this part = must +contain at least two unsigned long's, like when collecting non-unique PCs). + +The mapping between a PC and its position in the bitmap is persistent duri= ng the +kernel lifetime, so it is possible for the callers to directly use the bit= map +contents as a coverage signal (like when fuzzing userspace with AFL). + +In order to reset the coverage between the runs, the user needs to rewind = the +trace (by writing 0 into the first buffer element past ``bitmap_size``) an= d zero +the whole bitmap. + Comparison operands collection ------------------------------ =20 diff --git a/include/linux/kcov.h b/include/linux/kcov.h index 2acccfa5ae9af..cea2e62723ef9 100644 --- a/include/linux/kcov.h +++ b/include/linux/kcov.h @@ -10,6 +10,7 @@ struct task_struct; #ifdef CONFIG_KCOV =20 enum kcov_mode { + KCOV_MODE_INVALID =3D -1, /* Coverage collection is not enabled yet. */ KCOV_MODE_DISABLED =3D 0, /* KCOV was initialized, but tracing mode hasn't been chosen yet. */ @@ -23,6 +24,7 @@ enum kcov_mode { KCOV_MODE_TRACE_CMP =3D 3, /* The process owns a KCOV remote reference. */ KCOV_MODE_REMOTE =3D 4, + KCOV_MODE_UNIQUE_PC =3D 5, }; =20 #define KCOV_IN_CTXSW (1 << 30) diff --git a/include/linux/kcov_types.h b/include/linux/kcov_types.h index 9d38a2020b099..8be930f47cd78 100644 --- a/include/linux/kcov_types.h +++ b/include/linux/kcov_types.h @@ -18,6 +18,14 @@ struct kcov_state { /* Buffer for coverage collection, shared with the userspace. */ unsigned long *trace; =20 + /* Size of the bitmap (in bits). */ + unsigned int bitmap_size; + /* + * Bitmap for coverage deduplication, shared with the + * userspace. + */ + unsigned long *bitmap; + /* * KCOV sequence number: incremented each time kcov is reenabled, used * by kcov_remote_stop(), see the comment there. diff --git a/include/uapi/linux/kcov.h b/include/uapi/linux/kcov.h index ed95dba9fa37e..e743ee011eeca 100644 --- a/include/uapi/linux/kcov.h +++ b/include/uapi/linux/kcov.h @@ -22,6 +22,7 @@ struct kcov_remote_arg { #define KCOV_ENABLE _IO('c', 100) #define KCOV_DISABLE _IO('c', 101) #define KCOV_REMOTE_ENABLE _IOW('c', 102, struct kcov_remote_arg) +#define KCOV_UNIQUE_ENABLE _IOW('c', 103, unsigned long) =20 enum { /* diff --git a/kernel/kcov.c b/kernel/kcov.c index 2005fc7f578ee..a92c848d17bce 100644 --- a/kernel/kcov.c +++ b/kernel/kcov.c @@ -28,6 +28,10 @@ #include #include =20 +#ifdef CONFIG_KCOV_UNIQUE +atomic_t kcov_guard_max_index =3D ATOMIC_INIT(0); +#endif + #define kcov_debug(fmt, ...) pr_debug("%s: " fmt, __func__, ##__VA_ARGS__) =20 /* Number of 64-bit words written per one comparison: */ @@ -163,9 +167,9 @@ static __always_inline bool in_softirq_really(void) return in_serving_softirq() && !in_hardirq() && !in_nmi(); } =20 -static notrace bool check_kcov_mode(enum kcov_mode needed_mode, struct tas= k_struct *t) +static notrace enum kcov_mode get_kcov_mode(struct task_struct *t) { - unsigned int mode; + enum kcov_mode mode; =20 /* * We are interested in code coverage as a function of a syscall inputs, @@ -173,7 +177,7 @@ static notrace bool check_kcov_mode(enum kcov_mode need= ed_mode, struct task_stru * coverage collection section in a softirq. */ if (!in_task() && !(in_softirq_really() && t->kcov_softirq)) - return false; + return KCOV_MODE_INVALID; mode =3D READ_ONCE(t->kcov_mode); /* * There is some code that runs in interrupts but for which @@ -183,7 +187,7 @@ static notrace bool check_kcov_mode(enum kcov_mode need= ed_mode, struct task_stru * kcov_start(). */ barrier(); - return mode =3D=3D needed_mode; + return mode; } =20 static notrace unsigned long canonicalize_ip(unsigned long ip) @@ -202,7 +206,7 @@ static notrace void kcov_append_to_buffer(unsigned long= *trace, int size, =20 if (likely(pos < size)) { /* - * Some early interrupt code could bypass check_kcov_mode() check + * Some early interrupt code could bypass get_kcov_mode() check * and invoke __sanitizer_cov_trace_pc(). If such interrupt is * raised between writing pc and updating pos, the pc could be * overitten by the recursive __sanitizer_cov_trace_pc(). @@ -219,14 +223,76 @@ static notrace void kcov_append_to_buffer(unsigned lo= ng *trace, int size, * This is called once per basic-block/edge. */ #ifdef CONFIG_KCOV_UNIQUE +DEFINE_PER_CPU(u32, saved_index); +/* + * Assign an index to a guard variable that does not have one yet. + * For an unlikely case of a race with another task executing the same bas= ic + * block for the first time with kcov enabled, we store the unused index i= n a + * per-cpu variable. + * In an even less likely case of the current task losing the race and get= ting + * rescheduled onto a CPU that already has a saved index, the index is + * discarded. This will result in an unused hole in the bitmap, but such e= vents + * should have minor impact on the overall memory consumption. + */ +static __always_inline u32 init_pc_guard(u32 *guard) +{ + /* If the current CPU has a saved free index, use it. */ + u32 index =3D this_cpu_xchg(saved_index, 0); + u32 old_guard; + + if (likely(!index)) + /* + * Allocate a new index. No overflow is possible, because 2**32 + * unique basic blocks will take more space than the max size + * of the kernel text segment. + */ + index =3D atomic_inc_return(&kcov_guard_max_index); + + /* + * Make sure another task is not initializing the same guard + * concurrently. + */ + old_guard =3D cmpxchg(guard, 0, index); + if (unlikely(old_guard)) { + /* We lost the race, save the index for future use. */ + this_cpu_write(saved_index, index); + return old_guard; + } + return index; +} + void notrace __sanitizer_cov_trace_pc_guard(u32 *guard) { - if (!check_kcov_mode(KCOV_MODE_TRACE_PC, current)) - return; + enum kcov_mode mode =3D get_kcov_mode(current); + u32 pc_index; =20 - kcov_append_to_buffer(current->kcov_state.trace, - current->kcov_state.trace_size, - canonicalize_ip(_RET_IP_)); + switch (mode) { + case KCOV_MODE_UNIQUE_PC: + pc_index =3D READ_ONCE(*guard); + if (unlikely(!pc_index)) + pc_index =3D init_pc_guard(guard); + + /* + * Use the bitmap for coverage deduplication. We assume both + * s.bitmap and s.trace are non-NULL. + */ + if (likely(pc_index < current->kcov_state.bitmap_size)) + if (__test_and_set_bit(pc_index, + current->kcov_state.bitmap)) + return; + /* + * If the PC is new, or the bitmap is too small, write PC to the + * trace. + */ + fallthrough; + case KCOV_MODE_TRACE_PC: + kcov_append_to_buffer(current->kcov_state.trace, + current->kcov_state.trace_size, + canonicalize_ip(_RET_IP_)); + break; + default: + return; + } } EXPORT_SYMBOL(__sanitizer_cov_trace_pc_guard); =20 @@ -238,7 +304,7 @@ EXPORT_SYMBOL(__sanitizer_cov_trace_pc_guard_init); #else /* !CONFIG_KCOV_UNIQUE */ void notrace __sanitizer_cov_trace_pc(void) { - if (!check_kcov_mode(KCOV_MODE_TRACE_PC, current)) + if (get_kcov_mode(current) !=3D KCOV_MODE_TRACE_PC) return; =20 kcov_append_to_buffer(current->kcov_state.trace, @@ -256,7 +322,7 @@ static void notrace write_comp_data(u64 type, u64 arg1,= u64 arg2, u64 ip) u64 *trace; =20 t =3D current; - if (!check_kcov_mode(KCOV_MODE_TRACE_CMP, t)) + if (get_kcov_mode(t) !=3D KCOV_MODE_TRACE_CMP) return; =20 ip =3D canonicalize_ip(ip); @@ -374,7 +440,7 @@ static void kcov_start(struct task_struct *t, struct kc= ov *kcov, t->kcov =3D kcov; /* Cache in task struct for performance. */ t->kcov_state =3D *state; - /* See comment in check_kcov_mode(). */ + /* See comment in get_kcov_mode(). */ barrier(); WRITE_ONCE(t->kcov_mode, mode); } @@ -409,6 +475,10 @@ static void kcov_reset(struct kcov *kcov) kcov->mode =3D KCOV_MODE_INIT; kcov->remote =3D false; kcov->remote_size =3D 0; + kcov->state.trace =3D kcov->state.area; + kcov->state.trace_size =3D kcov->state.size; + kcov->state.bitmap =3D NULL; + kcov->state.bitmap_size =3D 0; kcov->state.sequence++; } =20 @@ -549,18 +619,23 @@ static int kcov_close(struct inode *inode, struct fil= e *filep) return 0; } =20 -static int kcov_get_mode(unsigned long arg) +static enum kcov_mode kcov_arg_to_mode(unsigned long arg, int *error) { - if (arg =3D=3D KCOV_TRACE_PC) + if (arg =3D=3D KCOV_TRACE_PC) { return KCOV_MODE_TRACE_PC; - else if (arg =3D=3D KCOV_TRACE_CMP) + } else if (arg =3D=3D KCOV_TRACE_CMP) { #ifdef CONFIG_KCOV_ENABLE_COMPARISONS return KCOV_MODE_TRACE_CMP; #else - return -ENOTSUPP; + if (error) + *error =3D -ENOTSUPP; + return KCOV_MODE_INVALID; #endif - else - return -EINVAL; + } else { + if (error) + *error =3D -EINVAL; + return KCOV_MODE_INVALID; + } } =20 /* @@ -595,12 +670,47 @@ static inline bool kcov_check_handle(u64 handle, bool= common_valid, return false; } =20 +static long kcov_handle_unique_enable(struct kcov *kcov, + unsigned long bitmap_words) +{ + struct task_struct *t =3D current; + + if (!IS_ENABLED(CONFIG_KCOV_UNIQUE)) + return -ENOTSUPP; + if (kcov->mode !=3D KCOV_MODE_INIT || !kcov->state.area) + return -EINVAL; + if (kcov->t !=3D NULL || t->kcov !=3D NULL) + return -EBUSY; + + /* + * Cannot use zero-sized bitmap, also the bitmap must leave at least two + * words for the trace. + */ + if ((!bitmap_words) || (bitmap_words >=3D (kcov->state.size - 1))) + return -EINVAL; + + kcov->state.bitmap_size =3D bitmap_words * sizeof(unsigned long) * 8; + kcov->state.bitmap =3D kcov->state.area; + kcov->state.trace_size =3D kcov->state.size - bitmap_words; + kcov->state.trace =3D ((unsigned long *)kcov->state.area + bitmap_words); + + kcov_fault_in_area(kcov); + kcov->mode =3D KCOV_MODE_UNIQUE_PC; + kcov_start(t, kcov, kcov->mode, &kcov->state); + kcov->t =3D t; + /* Put either in kcov_task_exit() or in KCOV_DISABLE. */ + kcov_get(kcov); + + return 0; +} + static int kcov_ioctl_locked(struct kcov *kcov, unsigned int cmd, unsigned long arg) { struct task_struct *t; unsigned long flags, unused; - int mode, i; + enum kcov_mode mode; + int error =3D 0, i; struct kcov_remote_arg *remote_arg; struct kcov_remote *remote; =20 @@ -618,9 +728,9 @@ static int kcov_ioctl_locked(struct kcov *kcov, unsigne= d int cmd, t =3D current; if (kcov->t !=3D NULL || t->kcov !=3D NULL) return -EBUSY; - mode =3D kcov_get_mode(arg); - if (mode < 0) - return mode; + mode =3D kcov_arg_to_mode(arg, &error); + if (mode =3D=3D KCOV_MODE_INVALID) + return error; kcov_fault_in_area(kcov); kcov->mode =3D mode; kcov_start(t, kcov, mode, &kcov->state); @@ -628,6 +738,8 @@ static int kcov_ioctl_locked(struct kcov *kcov, unsigne= d int cmd, /* Put either in kcov_task_exit() or in KCOV_DISABLE. */ kcov_get(kcov); return 0; + case KCOV_UNIQUE_ENABLE: + return kcov_handle_unique_enable(kcov, arg); case KCOV_DISABLE: /* Disable coverage for the current task. */ unused =3D arg; @@ -646,9 +758,9 @@ static int kcov_ioctl_locked(struct kcov *kcov, unsigne= d int cmd, if (kcov->t !=3D NULL || t->kcov !=3D NULL) return -EBUSY; remote_arg =3D (struct kcov_remote_arg *)arg; - mode =3D kcov_get_mode(remote_arg->trace_mode); - if (mode < 0) - return mode; + mode =3D kcov_arg_to_mode(remote_arg->trace_mode, &error); + if (mode =3D=3D KCOV_MODE_INVALID) + return error; if ((unsigned long)remote_arg->area_size > LONG_MAX / sizeof(unsigned long)) return -EINVAL; diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 60eb5faa27d28..f4ec041de0224 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1154,7 +1154,7 @@ static const char *uaccess_safe_builtin[] =3D { "__tsan_unaligned_write16", /* KCOV */ "write_comp_data", - "check_kcov_mode", + "get_kcov_mode", "__sanitizer_cov_trace_pc", "__sanitizer_cov_trace_pc_guard", "__sanitizer_cov_trace_const_cmp1", --=20 2.50.1.552.g942d659e1b-goog