From nobody Tue Apr 7 21:31:24 2026 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 66D6F2FDC20 for ; Wed, 11 Mar 2026 21:06:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773263214; cv=none; b=C8JGY2evJ/0odgSnHAoDLVHtPR5qpp96xMPASAVDTHPjb3MMtGQ0dVgbfOvFazqRotPH9TFORFzi7FfNBFkFvRynxkbePszfGUjS2bjChPWB+gcY2HExW38TOQNddEeIaW2rlTDBaAtwTsQdOgLpiGej+yKQB8kanazPcPxzu3s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773263214; c=relaxed/simple; bh=5DsfSgu+FPcywkrKjdBKgz/A0iooKEhY4/hZbp/L+BY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kg6PgK0jRweBHfQkGCRyU5aVPcSzkCmv0ywhvYPw5RO98ANmZ+wfk9rmzd/G4+fpbVgpG8tLILEPx0uzxbpRGPz5l0W6vQgg484SCWVUdUCLYSkHrLqt8my/lQoFIomztG/dNRTeXKS/vBlElduwZDrct1o7I7PtCd8DQee1l7Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=k/+2H3pf; arc=none smtp.client-ip=209.85.128.47 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=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="k/+2H3pf" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4852ef20fe8so8155e9.1 for ; Wed, 11 Mar 2026 14:06:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1773263211; x=1773868011; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=NzKnYN2/boQ9iOCZJ64ZuiUoSY4TlQ9bsFVP29RzfIo=; b=k/+2H3pfVCT2bXEXNz1bHdFxBqki0CV8LDMcnDz7VGXy4FWOpFnYv9EZeXAJoNhNBK c98nZOmfx7c5Mkf9+beHS2XOCOo5tyXepvwcF0tLCHrL1YTDQ1dgImk/QE/9ZkYZCjtd Da/ihPFOQFmIJsseMpB9MjwhVbY/puyQwW12nEJj2ADn0IqPKNnhxs4gcO0M4ekofoNV v4vSHDqlSBx3AXVPSnYLXpMavm4d/dftN4SkZ7t/XXpMHZL/lKPY+Vy2G9PTQpheUNYv 3xpY/sg08f5ESb5fprWqqMvyY1VQ0fE6L0vjLgaG+zYq/YDMve99ks5f4xp+H5sKu/3i 96zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773263211; x=1773868011; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=NzKnYN2/boQ9iOCZJ64ZuiUoSY4TlQ9bsFVP29RzfIo=; b=lF3mwzBTzSWv/ND2LMSmXRGiDM2RykSetoG23THDJfKaZ6ls+bJjb84D2xXhFzVfN3 oaMoDooNM6jacLBsd2gXDllZrF7qeuP8LlKGRJ/iyhMtCcbrl5oVA7gHRfyVcDAF2fje cIA8Em07P+SXSYQhV5oyo5dv1tsDVzu+UkOTgK7VUO8yb5vDompndR0lD+PtKyrmoC1m ltI5AuEB0BrCibZOX5S3LzqjkcSOI5FbhpKjePLitR02WbROiPOUj1AIDmVFVyc7Ncng 7FXOWOD9ueb59LqjDkPbkv7VWNiDIst7trXqp6A/8tXvjCykx3RtGlRO87wXkvbxyfBN /Wbg== X-Forwarded-Encrypted: i=1; AJvYcCV0+MLzPwuQJ2RPJhLcuw+GoM4QwsiYYmQcpWxG9maHl6OyHNGSJnjMcsL1ViZTpHepXuxPRSVoGHplzbg=@vger.kernel.org X-Gm-Message-State: AOJu0Yx4ThkDN5EdxzCxIqwjYnVOg6nrBl2LyNz5YhMebOBLmc5vn7z4 QJYKeVcRTPLs0s7mXnUn2Mig7fSXmL4lps/F8hTv7dEynHrbr1gpnWoK/SQYx7oSAQ== X-Gm-Gg: ATEYQzxvjl2TYGcURo2hjBA1c/DOYtihRy7h/ar8+RJKIrfCwiYIBTnK37GGq3P0VTX iuv1Kn+xGBHHO7HVzEOfWdsm9pRpPWucqBDwpcjZtCOTBrsDjRTcQ3z9urDFQSjrSIYv93oUKh2 RGR2ECPdghCZ5i/zb1GxHjHDygbeFY2SRbMa7uhk35yKFQpgzg4/VAiHaqdHF8YPjd/kkW3pDa5 rgGuzidXUiAATIaA7xbwy8kTfDpV0GCris0Sbr3aM/g8x//JFPtk+yWYFC4BDDwdW9faA0bvKwz gKO+0ginZC/m6V1/0AC49LpOCSzGJwG6MzBk2P5wfryf0++ebyvxNkdhBsNA/7obpYKoZmJmOIi KJhtp3J+pe4Wq9Hp+324rRxx+Gyi35WJEY+WUKc0ROaK7Lr87KUEwXm+tL4a1ycW9LSZ6c/FmOb ewNQDLsZvW8YFG11Pmg5ySwhEjtEOcJStQFZOvU7sE83AKTcq6Kz0= X-Received: by 2002:a05:600c:1c09:b0:477:255c:bea8 with SMTP id 5b1f17b1804b1-48552297bdcmr92595e9.7.1773263210284; Wed, 11 Mar 2026 14:06:50 -0700 (PDT) Received: from localhost ([2a00:79e0:288a:8:c9d4:528c:7414:ba3a]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-4854b0fa98bsm30652335e9.30.2026.03.11.14.06.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Mar 2026 14:06:49 -0700 (PDT) From: Jann Horn Date: Wed, 11 Mar 2026 22:06:15 +0100 Subject: [PATCH 2/3] kcov: wire up compiler instrumentation for CONFIG_KCOV_EXT_RECORDS Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260311-kcov-extrecord-v1-2-68f03c4a05ad@google.com> References: <20260311-kcov-extrecord-v1-0-68f03c4a05ad@google.com> In-Reply-To: <20260311-kcov-extrecord-v1-0-68f03c4a05ad@google.com> To: Dmitry Vyukov , Andrey Konovalov Cc: Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, llvm@lists.linux.dev, Jann Horn , Josh Poimboeuf , Peter Zijlstra X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1773263202; l=5297; i=jannh@google.com; s=20240730; h=from:subject:message-id; bh=5DsfSgu+FPcywkrKjdBKgz/A0iooKEhY4/hZbp/L+BY=; b=K6AVC8ItMBgT1JQDBXviHQZ3H70ou6Q4xycc4VLgngTNhupShXHtef90BIuy7Ymek+6rnFAi2 Y8bz3jas2jaCNDe7ONh2j6QP+E+fmvnj8kVvHN07gOFdeKaDUCFWjcu X-Developer-Key: i=jannh@google.com; a=ed25519; pk=AljNtGOzXeF6khBXDJVVvwSEkVDGnnZZYqfWhP1V+C8= This is the first half of CONFIG_KCOV_EXT_RECORDS. Set the appropriate compiler flags to call separate hooks for function entry/exit, and provide these hooks, but don't make it visible in the KCOV UAPI yet. With -fsanitize-coverage=3Dtrace-pc-entry-exit, the compiler behavior chang= es as follows: - The __sanitizer_cov_trace_pc() call on function entry is replaced with a call to __sanitizer_cov_trace_pc_entry(); so for now, __sanitizer_cov_trace_pc_entry() must be treated the same way as __sanitizer_cov_trace_pc(). - On function exit, an extra call to __sanitizer_cov_trace_pc_exit() happens; since function exit produced no coverage in the old UAPI, __sanitizer_cov_trace_pc_exit() should do nothing for now. Cc: Josh Poimboeuf Cc: Peter Zijlstra Signed-off-by: Jann Horn Reviewed-by: Dmitry Vyukov --- include/linux/kcov.h | 2 ++ kernel/kcov.c | 30 +++++++++++++++++++++++------- lib/Kconfig.debug | 14 ++++++++++++++ scripts/Makefile.kcov | 2 ++ tools/objtool/check.c | 2 ++ 5 files changed, 43 insertions(+), 7 deletions(-) diff --git a/include/linux/kcov.h b/include/linux/kcov.h index 0143358874b0..e5502d674029 100644 --- a/include/linux/kcov.h +++ b/include/linux/kcov.h @@ -81,6 +81,8 @@ typedef unsigned long long kcov_u64; #endif =20 void __sanitizer_cov_trace_pc(void); +void __sanitizer_cov_trace_pc_entry(void); +void __sanitizer_cov_trace_pc_exit(void); void __sanitizer_cov_trace_cmp1(u8 arg1, u8 arg2); void __sanitizer_cov_trace_cmp2(u16 arg1, u16 arg2); void __sanitizer_cov_trace_cmp4(u32 arg1, u32 arg2); diff --git a/kernel/kcov.c b/kernel/kcov.c index 0b369e88c7c9..2cc48b65384b 100644 --- a/kernel/kcov.c +++ b/kernel/kcov.c @@ -202,15 +202,10 @@ static notrace unsigned long canonicalize_ip(unsigned= long ip) return ip; } =20 -/* - * Entry point from instrumented code. - * This is called once per basic-block/edge. - */ -void notrace __sanitizer_cov_trace_pc(void) +static void notrace kcov_add_pc_record(unsigned long record) { struct task_struct *t; unsigned long *area; - unsigned long ip =3D canonicalize_ip(_RET_IP_); unsigned long pos; =20 t =3D current; @@ -230,11 +225,32 @@ void notrace __sanitizer_cov_trace_pc(void) */ WRITE_ONCE(area[0], pos); barrier(); - area[pos] =3D ip; + area[pos] =3D record; } } + +/* + * Entry point from instrumented code. + * This is called once per basic-block/edge. + */ +void notrace __sanitizer_cov_trace_pc(void) +{ + kcov_add_pc_record(canonicalize_ip(_RET_IP_)); +} EXPORT_SYMBOL(__sanitizer_cov_trace_pc); =20 +#ifdef CONFIG_KCOV_EXT_RECORDS +void notrace __sanitizer_cov_trace_pc_entry(void) +{ + unsigned long record =3D canonicalize_ip(_RET_IP_); + + kcov_add_pc_record(record); +} +void notrace __sanitizer_cov_trace_pc_exit(void) +{ +} +#endif + #ifdef CONFIG_KCOV_ENABLE_COMPARISONS static void notrace write_comp_data(u64 type, u64 arg1, u64 arg2, u64 ip) { diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 93f356d2b3d9..dddc330ad3ca 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -2215,6 +2215,20 @@ config KCOV =20 For more details, see Documentation/dev-tools/kcov.rst. =20 +config KCOV_EXT_RECORDS + bool "Support extended KCOV records with function entry/exit records" + depends on KCOV + depends on 64BIT + # TODO: check CLANG_VERSION instead once this has landed in an LLVM + # release + depends on $(cc-option,-fsanitize-coverage=3Dtrace-pc-entry-exit) + help + Extended KCOV records allow distinguishing between multiple types of + records: Normal edge coverage, function entry, and function exit. + + This will likely cause a small additional slowdown compared to normal + KCOV. + config KCOV_ENABLE_COMPARISONS bool "Enable comparison operands collection by KCOV" depends on KCOV diff --git a/scripts/Makefile.kcov b/scripts/Makefile.kcov index 78305a84ba9d..aa0be904268f 100644 --- a/scripts/Makefile.kcov +++ b/scripts/Makefile.kcov @@ -1,10 +1,12 @@ # SPDX-License-Identifier: GPL-2.0-only kcov-flags-y +=3D -fsanitize-coverage=3Dtrace-pc +kcov-flags-$(CONFIG_KCOV_EXT_RECORDS) +=3D -fsanitize-coverage=3Dtrace-pc= -entry-exit kcov-flags-$(CONFIG_KCOV_ENABLE_COMPARISONS) +=3D -fsanitize-coverage=3Dtr= ace-cmp =20 kcov-rflags-y +=3D -Cpasses=3Dsancov-module kcov-rflags-y +=3D -Cllvm-args=3D-sanitizer-coverage-level=3D3 kcov-rflags-y +=3D -Cllvm-args=3D-sanitizer-coverage-trace-pc +kcov-rflags-$(CONFIG_KCOV_EXT_RECORDS) +=3D -Cllvm-args=3D-sanitizer-cove= rage-trace-pc-entry-exit kcov-rflags-$(CONFIG_KCOV_ENABLE_COMPARISONS) +=3D -Cllvm-args=3D-sanitize= r-coverage-trace-compares =20 export CFLAGS_KCOV :=3D $(kcov-flags-y) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index a30379e4ff97..ae3127227621 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1251,6 +1251,8 @@ static const char *uaccess_safe_builtin[] =3D { "write_comp_data", "check_kcov_mode", "__sanitizer_cov_trace_pc", + "__sanitizer_cov_trace_pc_entry", + "__sanitizer_cov_trace_pc_exit", "__sanitizer_cov_trace_const_cmp1", "__sanitizer_cov_trace_const_cmp2", "__sanitizer_cov_trace_const_cmp4", --=20 2.53.0.473.g4a7958ca14-goog