From nobody Thu Dec 18 01:54:45 2025 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A05620F075; Tue, 14 Jan 2025 05:36:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736832975; cv=none; b=JPWGGe8yS/jAFHxV9NUiPPL01P8hrRdkeGplSLM8P4e1c2MMutotiO+mF7dbo70/t/aBqnrlHkXSQjd0fI06l6BJT2MgjpKswwylJt+uNBXjKsOrXQ/qjX1/1EF5c91Q6PeQ1q0J6XUqobymawN49mrxJuUdyq+zImCl6Xq7bHw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736832975; c=relaxed/simple; bh=B7wHQFKQobnmg8wdM6NUVeUWs1lU5h8VAiYZXhUuszQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=RL1zzpbWXyaJFzbGFEevU3u4FKOszIbUPa//ZPH1ISu7E22af/Hs/5eKs7vhUY0QIGh1/jojsS8lFE/tSC/yP7GffNBKa1N35N6Cj/YsmbnvgfvwOaMHWfX1EC5qluJhyqxCDDnZsv4GSc9DyFEmK7NteOVV0uDJZlV6BQ5wbos= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=h4nA0eA4; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="h4nA0eA4" Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50E2faK3019063; Tue, 14 Jan 2025 05:35:53 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= qDL277UfuO/ZrvRomYA8juO/sG4dUYnxhYSbKtRIw2g=; b=h4nA0eA4UEs6Tu4k wBfX7hgWFXXrnM+JGs+WebRVn7gpdPNJKHjYRSmkvrgEFV6N8C1Wtoo5mNH54CmU b5vckJfXnF6+ezglMfy/TK+YUxne1465BNOuXwxR17lz8k10fKU8kMC0l7QO2x5d Ym/yBCF6U5EKWI1tJvKVzF95OMKkz4P+ZQVKy7/TmkVpw0KC+MRsfGsiV7A0ivHk r8+MMeA1vSZ/O1nSBZZCnBrVcSIrKEHLwl22a8MgDFQsmp41YFwKkQhxWa4u6WEW 1sKZxzqy1COV3V0YYAqGHp5YoUMrXvPGWR++NEv6X6u4P8BKFkdxcxnJXkPWuoh+ 6SF9aw== Received: from nasanppmta05.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 445fc68ap7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 14 Jan 2025 05:35:52 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA05.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 50E5ZpkU015485 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 14 Jan 2025 05:35:51 GMT Received: from la-sh002-lnx.ap.qualcomm.com (10.80.80.8) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Mon, 13 Jan 2025 21:35:46 -0800 From: "Jiao, Joey" Date: Tue, 14 Jan 2025 13:34:31 +0800 Subject: [PATCH 1/7] kcov: introduce new kcov KCOV_TRACE_UNIQ_PC mode 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: <20250114-kcov-v1-1-004294b931a2@quicinc.com> References: <20250114-kcov-v1-0-004294b931a2@quicinc.com> In-Reply-To: <20250114-kcov-v1-0-004294b931a2@quicinc.com> To: Dmitry Vyukov , Andrey Konovalov , Jonathan Corbet , Andrew Morton , Dennis Zhou , Tejun Heo , Christoph Lameter , Catalin Marinas , Will Deacon CC: , , , , , , X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1736832941; l=9637; i=quic_jiangenj@quicinc.com; s=20250114; h=from:subject:message-id; bh=B7wHQFKQobnmg8wdM6NUVeUWs1lU5h8VAiYZXhUuszQ=; b=3Fvg8y8dQ7utfwGWRCIqEI/3IwdHZiSSLCJAtwDZ3DSR+sj7AgVMY66KyCdxL52wgtcbIHf8o 9j75hRm567mDu2jxJ/jTIXR40Kjt9iqFT8hdyyzRUDAE3mZ2DSasfbM X-Developer-Key: i=quic_jiangenj@quicinc.com; a=ed25519; pk=JPzmfEvx11SW1Q1qtMhFcAx46KP1Ui36jcetDgbev28= X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: qeP3yiT5DpcBwuW5hL4M01mTLK8jZQWF X-Proofpoint-GUID: qeP3yiT5DpcBwuW5hL4M01mTLK8jZQWF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=777 adultscore=0 suspectscore=0 malwarescore=0 phishscore=0 clxscore=1015 impostorscore=0 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2501140043 The current kcov KCOV_TRACE_PC mode stores PC in sequence. Introduce KCOV_TRACE_UNIQ_PC mode to store unique PC info. In unique PC mode, - use hashmap to store unique PC in kcov_entry - use gen_pool_alloc in __sanitizer_cov_trace_pc to avoid sleeping function kmalloc Signed-off-by: Jiao, Joey --- include/linux/kcov.h | 6 +- include/uapi/linux/kcov.h | 2 + kernel/kcov.c | 190 ++++++++++++++++++++++++++++++++++++++++--= ---- 3 files changed, 173 insertions(+), 25 deletions(-) diff --git a/include/linux/kcov.h b/include/linux/kcov.h index 75a2fb8b16c32917817b8ec7f5e45421793431ae..aafd9f88450cb8672c701349300= b54662bc38079 100644 --- a/include/linux/kcov.h +++ b/include/linux/kcov.h @@ -20,9 +20,11 @@ enum kcov_mode { */ KCOV_MODE_TRACE_PC =3D 2, /* Collecting comparison operands mode. */ - KCOV_MODE_TRACE_CMP =3D 3, + KCOV_MODE_TRACE_CMP =3D 4, /* The process owns a KCOV remote reference. */ - KCOV_MODE_REMOTE =3D 4, + KCOV_MODE_REMOTE =3D 8, + /* COllecting uniq pc mode. */ + KCOV_MODE_TRACE_UNIQ_PC =3D 16, }; =20 #define KCOV_IN_CTXSW (1 << 30) diff --git a/include/uapi/linux/kcov.h b/include/uapi/linux/kcov.h index ed95dba9fa37e291e9e9e0109eb8481bb7a5e9da..d2a2bff36f285a5e3a03395f889= 0fcb716cf3f07 100644 --- a/include/uapi/linux/kcov.h +++ b/include/uapi/linux/kcov.h @@ -35,6 +35,8 @@ enum { KCOV_TRACE_PC =3D 0, /* Collecting comparison operands mode. */ KCOV_TRACE_CMP =3D 1, + /* Collecting uniq PC mode. */ + KCOV_TRACE_UNIQ_PC =3D 2, }; =20 /* diff --git a/kernel/kcov.c b/kernel/kcov.c index 28a6be6e64fdd721d49c4040ed10ce33f9d890a1..bbd7b7503206fe595976458ab68= 5b95f784607d7 100644 --- a/kernel/kcov.c +++ b/kernel/kcov.c @@ -9,9 +9,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -32,6 +34,29 @@ /* Number of 64-bit words written per one comparison: */ #define KCOV_WORDS_PER_CMP 4 =20 +struct kcov_entry { + unsigned long ent; + + struct hlist_node node; +}; + +/* Min gen pool alloc order. */ +#define MIN_POOL_ALLOC_ORDER ilog2(roundup_pow_of_two(sizeof(struct kcov_e= ntry))) + +/* + * kcov hashmap to store uniq pc, prealloced mem for kcov_entry + * and area shared between kernel and userspace. + */ +struct kcov_map { + /* 15 bits fit most cases for hash collision, memory and performance. */ + DECLARE_HASHTABLE(buckets, 15); + struct gen_pool *pool; + /* Prealloced memory added to pool to be used as kcov_entry. */ + void *mem; + /* Buffer shared with user space. */ + void *area; +}; + /* * kcov descriptor (one per opened debugfs file). * State transitions of the descriptor: @@ -60,6 +85,8 @@ struct kcov { unsigned int size; /* Coverage buffer shared with user space. */ void *area; + /* Coverage hashmap for unique pc. */ + struct kcov_map *map; /* Task for which we collect coverage, or NULL. */ struct task_struct *t; /* Collecting coverage from remote (background) threads. */ @@ -171,7 +198,7 @@ static 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 unsigned int check_kcov_mode(enum kcov_mode needed_mode, st= ruct task_struct *t) { unsigned int mode; =20 @@ -191,7 +218,94 @@ static notrace bool check_kcov_mode(enum kcov_mode nee= ded_mode, struct task_stru * kcov_start(). */ barrier(); - return mode =3D=3D needed_mode; + return mode & needed_mode; +} + +static int kcov_map_init(struct kcov *kcov, unsigned long size) +{ + struct kcov_map *map; + void *area; + unsigned long flags; + + map =3D kzalloc(sizeof(*map), GFP_KERNEL); + if (!map) + return -ENOMEM; + + area =3D vmalloc_user(size * sizeof(unsigned long)); + if (!area) { + kfree(map); + return -ENOMEM; + } + + spin_lock_irqsave(&kcov->lock, flags); + map->area =3D area; + + kcov->map =3D map; + kcov->area =3D area; + spin_unlock_irqrestore(&kcov->lock, flags); + + hash_init(map->buckets); + + map->pool =3D gen_pool_create(MIN_POOL_ALLOC_ORDER, -1); + if (!map->pool) + return -ENOMEM; + + map->mem =3D vmalloc(size * (1 << MIN_POOL_ALLOC_ORDER)); + if (!map->mem) { + vfree(area); + gen_pool_destroy(map->pool); + kfree(map); + return -ENOMEM; + } + + if (gen_pool_add(map->pool, (unsigned long)map->mem, size * + (1 << MIN_POOL_ALLOC_ORDER), -1)) { + vfree(area); + vfree(map->mem); + gen_pool_destroy(map->pool); + kfree(map); + return -ENOMEM; + } + + return 0; +} + +static inline u32 hash_key(const struct kcov_entry *k) +{ + return jhash((u32 *)k, offsetof(struct kcov_entry, node), 0); +} + +static notrace inline void kcov_map_add(struct kcov_map *map, struct kcov_= entry *ent, + struct task_struct *t) +{ + struct kcov *kcov; + struct kcov_entry *entry; + unsigned int key =3D hash_key(ent); + unsigned long pos, *area; + + kcov =3D t->kcov; + + hash_for_each_possible_rcu(map->buckets, entry, node, key) { + if (entry->ent =3D=3D ent->ent) + return; + } + + entry =3D (struct kcov_entry *)gen_pool_alloc(map->pool, 1 << MIN_POOL_AL= LOC_ORDER); + if (unlikely(!entry)) + return; + + barrier(); + memcpy(entry, ent, sizeof(*entry)); + hash_add_rcu(map->buckets, &entry->node, key); + + area =3D t->kcov_area; + + pos =3D READ_ONCE(area[0]) + 1; + if (likely(pos < t->kcov_size)) { + WRITE_ONCE(area[0], pos); + barrier(); + area[pos] =3D ent->ent; + } } =20 static notrace unsigned long canonicalize_ip(unsigned long ip) @@ -212,25 +326,34 @@ void notrace __sanitizer_cov_trace_pc(void) unsigned long *area; unsigned long ip =3D canonicalize_ip(_RET_IP_); unsigned long pos; + struct kcov_entry entry =3D {0}; + unsigned int mode; =20 t =3D current; - if (!check_kcov_mode(KCOV_MODE_TRACE_PC, t)) + if (!check_kcov_mode(KCOV_MODE_TRACE_PC | KCOV_MODE_TRACE_UNIQ_PC, t)) return; =20 area =3D t->kcov_area; - /* The first 64-bit word is the number of subsequent PCs. */ - pos =3D READ_ONCE(area[0]) + 1; - if (likely(pos < t->kcov_size)) { - /* Previously we write pc before updating pos. However, some - * early interrupt code could bypass check_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(). - * Update pos before writing pc to avoid such interleaving. - */ - WRITE_ONCE(area[0], pos); - barrier(); - area[pos] =3D ip; + mode =3D t->kcov_mode; + if (mode =3D=3D KCOV_MODE_TRACE_PC) { + area =3D t->kcov_area; + /* The first 64-bit word is the number of subsequent PCs. */ + pos =3D READ_ONCE(area[0]) + 1; + if (likely(pos < t->kcov_size)) { + /* Previously we write pc before updating pos. However, some + * early interrupt code could bypass check_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(). + * Update pos before writing pc to avoid such interleaving. + */ + WRITE_ONCE(area[0], pos); + barrier(); + area[pos] =3D ip; + } + } else { + entry.ent =3D ip; + kcov_map_add(t->kcov->map, &entry, t); } } EXPORT_SYMBOL(__sanitizer_cov_trace_pc); @@ -432,11 +555,33 @@ static void kcov_get(struct kcov *kcov) refcount_inc(&kcov->refcount); } =20 +static void kcov_map_free(struct kcov *kcov) +{ + int bkt; + struct hlist_node *tmp; + struct kcov_entry *entry; + struct kcov_map *map; + + map =3D kcov->map; + if (!map) + return; + rcu_read_lock(); + hash_for_each_safe(map->buckets, bkt, tmp, entry, node) { + hash_del_rcu(&entry->node); + gen_pool_free(map->pool, (unsigned long)entry, 1 << MIN_POOL_ALLOC_ORDER= ); + } + rcu_read_unlock(); + vfree(map->area); + vfree(map->mem); + gen_pool_destroy(map->pool); + kfree(map); +} + static void kcov_put(struct kcov *kcov) { if (refcount_dec_and_test(&kcov->refcount)) { kcov_remote_reset(kcov); - vfree(kcov->area); + kcov_map_free(kcov); kfree(kcov); } } @@ -546,6 +691,8 @@ static int kcov_get_mode(unsigned long arg) #else return -ENOTSUPP; #endif + else if (arg =3D=3D KCOV_TRACE_UNIQ_PC) + return KCOV_MODE_TRACE_UNIQ_PC; else return -EINVAL; } @@ -698,7 +845,6 @@ static long kcov_ioctl(struct file *filep, unsigned int= cmd, unsigned long arg) unsigned int remote_num_handles; unsigned long remote_arg_size; unsigned long size, flags; - void *area; =20 kcov =3D filep->private_data; switch (cmd) { @@ -713,16 +859,14 @@ static long kcov_ioctl(struct file *filep, unsigned i= nt cmd, unsigned long arg) size =3D arg; if (size < 2 || size > INT_MAX / sizeof(unsigned long)) return -EINVAL; - area =3D vmalloc_user(size * sizeof(unsigned long)); - if (area =3D=3D NULL) - return -ENOMEM; + res =3D kcov_map_init(kcov, size); + if (res) + return res; spin_lock_irqsave(&kcov->lock, flags); if (kcov->mode !=3D KCOV_MODE_DISABLED) { spin_unlock_irqrestore(&kcov->lock, flags); - vfree(area); return -EBUSY; } - kcov->area =3D area; kcov->size =3D size; kcov->mode =3D KCOV_MODE_INIT; spin_unlock_irqrestore(&kcov->lock, flags); --=20 2.47.1 From nobody Thu Dec 18 01:54:45 2025 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AAEC423355D; Tue, 14 Jan 2025 05:36:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736832977; cv=none; b=Bztx2tlrvZi05eISPhAefeijYdqXGlmSADJgXkmnI9xrGBlRKosJfLxsQvVGRXJ4UXJthnCh0+8nthfTFt3DroQGFNQ1NURMO3JhCaOAofEfP4k9UmRojBMczV+TelCJx1FH0nx+4dC5wRCOcP5iZdw8cQ7ngOSErdYjUvGt/NM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736832977; c=relaxed/simple; bh=fvIA7qPV+F40Lv2i0NOI93SQe1UCKicXtboCEOT2WIE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=gk/casC2uHItah8rwSuG7UtAkb+mudxRvcKB9PFZdTOSTvWtp8HXgzP7t62v8ec7bI/e3ysD11PJmRAsdsLdUKP1+qaAg1ZqMjkU9V1TSBfWnqLV7eJAMrunO8GPA8BcIGRwG6+uwed2M7UbLWPEJsupVdYraWOxsgl4vVSX8Hc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=jjgWv3xq; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="jjgWv3xq" Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50DKsOnq026165; Tue, 14 Jan 2025 05:35:56 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= ZBlk7f8TqoTzSTj9rN2g/BtOKJD+wVKUTcgd9+/bG5o=; b=jjgWv3xqg/L/e6Uo AC9koJ2vVx9qp+MOxby5ntqzJyl0t4sN+iJH7F+MitXJEnoPQTTTUF8FWPdgpyfG nmRmCe5zMMpuXNDjldrt9ZRfgbc4K+IXR4JV1Dju1Lbji7Va4g/aK5Ur21ZtFrTA y+VLaeSLn9s9YIWPiZEtwt1mhbGfJYMkKpYSwbhBIxmOfMNQGr7v8RPnMAUPQOAz GyvMwdFGp6bYQapq+o0ALxLzjE7JaGQovBEWY3eaz+izjXycBFCus5vKRXGkq+7n ShZx0lMOufzrKVPJC/P1Xh/GQ8vIyxWnQb5PTKDNcGPNUwNOCZ2SZdo4OLwn8NNW w4FtSw== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 445a928wyk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 14 Jan 2025 05:35:55 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA02.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 50E5ZtXN019909 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 14 Jan 2025 05:35:55 GMT Received: from la-sh002-lnx.ap.qualcomm.com (10.80.80.8) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Mon, 13 Jan 2025 21:35:49 -0800 From: "Jiao, Joey" Date: Tue, 14 Jan 2025 13:34:32 +0800 Subject: [PATCH 2/7] kcov: introduce new kcov KCOV_TRACE_UNIQ_EDGE mode 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: <20250114-kcov-v1-2-004294b931a2@quicinc.com> References: <20250114-kcov-v1-0-004294b931a2@quicinc.com> In-Reply-To: <20250114-kcov-v1-0-004294b931a2@quicinc.com> To: Dmitry Vyukov , Andrey Konovalov , Jonathan Corbet , Andrew Morton , Dennis Zhou , Tejun Heo , Christoph Lameter , Catalin Marinas , Will Deacon CC: , , , , , , X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1736832942; l=7640; i=quic_jiangenj@quicinc.com; s=20250114; h=from:subject:message-id; bh=fvIA7qPV+F40Lv2i0NOI93SQe1UCKicXtboCEOT2WIE=; b=kUJuqBf1WmXlkxHJKhCifPFT0HbTOCIQVzM7sdSklSI6WvFaFMlQeqx5N+zeSQr1xFpBOVsHQ FNLdRqhqeubCMcg5KCoYN8gH6gRE5trVbdd0mTyeNPGbGPsxiea0tMG X-Developer-Key: i=quic_jiangenj@quicinc.com; a=ed25519; pk=JPzmfEvx11SW1Q1qtMhFcAx46KP1Ui36jcetDgbev28= X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: YQARHycxSoqmMiVizCvzkbVFl1mo40vy X-Proofpoint-ORIG-GUID: YQARHycxSoqmMiVizCvzkbVFl1mo40vy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 malwarescore=0 suspectscore=0 impostorscore=0 adultscore=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 clxscore=1015 mlxlogscore=999 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2501140044 KCOV_TRACE_UNIQ_EDGE stores uniq edge info, which is bitwise xor operation of prev_pc and current pc. And only hash the lower 12 bits so the hash is independent of any module offsets. Signed-off-by: Jiao, Joey --- include/linux/kcov.h | 4 ++- include/uapi/linux/kcov.h | 2 ++ kernel/kcov.c | 73 ++++++++++++++++++++++++++++++++++++-------= ---- 3 files changed, 61 insertions(+), 18 deletions(-) diff --git a/include/linux/kcov.h b/include/linux/kcov.h index aafd9f88450cb8672c701349300b54662bc38079..56b858205ba16c47fc72bda9938= c98f034503c8c 100644 --- a/include/linux/kcov.h +++ b/include/linux/kcov.h @@ -23,8 +23,10 @@ enum kcov_mode { KCOV_MODE_TRACE_CMP =3D 4, /* The process owns a KCOV remote reference. */ KCOV_MODE_REMOTE =3D 8, - /* COllecting uniq pc mode. */ + /* Collecting uniq pc mode. */ KCOV_MODE_TRACE_UNIQ_PC =3D 16, + /* Collecting uniq edge mode. */ + KCOV_MODE_TRACE_UNIQ_EDGE =3D 32, }; =20 #define KCOV_IN_CTXSW (1 << 30) diff --git a/include/uapi/linux/kcov.h b/include/uapi/linux/kcov.h index d2a2bff36f285a5e3a03395f8890fcb716cf3f07..9b2019f0ab8b8cb5426d2d6b744= 72fa1a7293817 100644 --- a/include/uapi/linux/kcov.h +++ b/include/uapi/linux/kcov.h @@ -37,6 +37,8 @@ enum { KCOV_TRACE_CMP =3D 1, /* Collecting uniq PC mode. */ KCOV_TRACE_UNIQ_PC =3D 2, + /* Collecting uniq edge mode. */ + KCOV_TRACE_UNIQ_EDGE =3D 4, }; =20 /* diff --git a/kernel/kcov.c b/kernel/kcov.c index bbd7b7503206fe595976458ab685b95f784607d7..5a0ead92729294d99db80bb4e0f= 5b04c8b025dba 100644 --- a/kernel/kcov.c +++ b/kernel/kcov.c @@ -83,10 +83,14 @@ struct kcov { enum kcov_mode mode; /* Size of arena (in long's). */ unsigned int size; + /* Previous PC. */ + unsigned long prev_pc; /* Coverage buffer shared with user space. */ void *area; /* Coverage hashmap for unique pc. */ struct kcov_map *map; + /* Edge hashmap for unique edge. */ + struct kcov_map *map_edge; /* Task for which we collect coverage, or NULL. */ struct task_struct *t; /* Collecting coverage from remote (background) threads. */ @@ -221,7 +225,7 @@ static notrace unsigned int check_kcov_mode(enum kcov_m= ode needed_mode, struct t return mode & needed_mode; } =20 -static int kcov_map_init(struct kcov *kcov, unsigned long size) +static int kcov_map_init(struct kcov *kcov, unsigned long size, bool edge) { struct kcov_map *map; void *area; @@ -240,8 +244,12 @@ static int kcov_map_init(struct kcov *kcov, unsigned l= ong size) spin_lock_irqsave(&kcov->lock, flags); map->area =3D area; =20 - kcov->map =3D map; - kcov->area =3D area; + if (edge) { + kcov->map_edge =3D map; + } else { + kcov->map =3D map; + kcov->area =3D area; + } spin_unlock_irqrestore(&kcov->lock, flags); =20 hash_init(map->buckets); @@ -276,7 +284,7 @@ static inline u32 hash_key(const struct kcov_entry *k) } =20 static notrace inline void kcov_map_add(struct kcov_map *map, struct kcov_= entry *ent, - struct task_struct *t) + struct task_struct *t, unsigned int mode) { struct kcov *kcov; struct kcov_entry *entry; @@ -298,7 +306,10 @@ static notrace inline void kcov_map_add(struct kcov_ma= p *map, struct kcov_entry memcpy(entry, ent, sizeof(*entry)); hash_add_rcu(map->buckets, &entry->node, key); =20 - area =3D t->kcov_area; + if (mode =3D=3D KCOV_MODE_TRACE_UNIQ_PC) + area =3D t->kcov_area; + else + area =3D kcov->map_edge->area; =20 pos =3D READ_ONCE(area[0]) + 1; if (likely(pos < t->kcov_size)) { @@ -327,13 +338,15 @@ void notrace __sanitizer_cov_trace_pc(void) unsigned long ip =3D canonicalize_ip(_RET_IP_); unsigned long pos; struct kcov_entry entry =3D {0}; + /* Only hash the lower 12 bits so the hash is independent of any module o= ffsets. */ + unsigned long mask =3D (1 << 12) - 1; unsigned int mode; =20 t =3D current; - if (!check_kcov_mode(KCOV_MODE_TRACE_PC | KCOV_MODE_TRACE_UNIQ_PC, t)) + if (!check_kcov_mode(KCOV_MODE_TRACE_PC | KCOV_MODE_TRACE_UNIQ_PC | + KCOV_MODE_TRACE_UNIQ_EDGE, t)) return; =20 - area =3D t->kcov_area; mode =3D t->kcov_mode; if (mode =3D=3D KCOV_MODE_TRACE_PC) { area =3D t->kcov_area; @@ -352,8 +365,15 @@ void notrace __sanitizer_cov_trace_pc(void) area[pos] =3D ip; } } else { - entry.ent =3D ip; - kcov_map_add(t->kcov->map, &entry, t); + if (mode & KCOV_MODE_TRACE_UNIQ_PC) { + entry.ent =3D ip; + kcov_map_add(t->kcov->map, &entry, t, KCOV_MODE_TRACE_UNIQ_PC); + } + if (mode & KCOV_MODE_TRACE_UNIQ_EDGE) { + entry.ent =3D (hash_long(t->kcov->prev_pc & mask, BITS_PER_LONG) & mask= ) ^ ip; + t->kcov->prev_pc =3D ip; + kcov_map_add(t->kcov->map_edge, &entry, t, KCOV_MODE_TRACE_UNIQ_EDGE); + } } } EXPORT_SYMBOL(__sanitizer_cov_trace_pc); @@ -555,14 +575,17 @@ static void kcov_get(struct kcov *kcov) refcount_inc(&kcov->refcount); } =20 -static void kcov_map_free(struct kcov *kcov) +static void kcov_map_free(struct kcov *kcov, bool edge) { int bkt; struct hlist_node *tmp; struct kcov_entry *entry; struct kcov_map *map; =20 - map =3D kcov->map; + if (edge) + map =3D kcov->map_edge; + else + map =3D kcov->map; if (!map) return; rcu_read_lock(); @@ -581,7 +604,8 @@ static void kcov_put(struct kcov *kcov) { if (refcount_dec_and_test(&kcov->refcount)) { kcov_remote_reset(kcov); - kcov_map_free(kcov); + kcov_map_free(kcov, false); + kcov_map_free(kcov, true); kfree(kcov); } } @@ -636,18 +660,27 @@ static int kcov_mmap(struct file *filep, struct vm_ar= ea_struct *vma) unsigned long size, off; struct page *page; unsigned long flags; + void *area; =20 spin_lock_irqsave(&kcov->lock, flags); size =3D kcov->size * sizeof(unsigned long); - if (kcov->area =3D=3D NULL || vma->vm_pgoff !=3D 0 || - vma->vm_end - vma->vm_start !=3D size) { + if (!vma->vm_pgoff) { + area =3D kcov->area; + } else if (vma->vm_pgoff =3D=3D size >> PAGE_SHIFT) { + area =3D kcov->map_edge->area; + } else { + spin_unlock_irqrestore(&kcov->lock, flags); + return -EINVAL; + } + + if (!area || vma->vm_end - vma->vm_start !=3D size) { res =3D -EINVAL; goto exit; } spin_unlock_irqrestore(&kcov->lock, flags); vm_flags_set(vma, VM_DONTEXPAND); for (off =3D 0; off < size; off +=3D PAGE_SIZE) { - page =3D vmalloc_to_page(kcov->area + off); + page =3D vmalloc_to_page(area + off); res =3D vm_insert_page(vma, vma->vm_start + off, page); if (res) { pr_warn_once("kcov: vm_insert_page() failed\n"); @@ -693,6 +726,8 @@ static int kcov_get_mode(unsigned long arg) #endif else if (arg =3D=3D KCOV_TRACE_UNIQ_PC) return KCOV_MODE_TRACE_UNIQ_PC; + else if (arg =3D=3D KCOV_TRACE_UNIQ_EDGE) + return KCOV_MODE_TRACE_UNIQ_EDGE; else return -EINVAL; } @@ -747,7 +782,8 @@ static int kcov_ioctl_locked(struct kcov *kcov, unsigne= d int cmd, * at task exit or voluntary by KCOV_DISABLE. After that it can * be enabled for another task. */ - if (kcov->mode !=3D KCOV_MODE_INIT || !kcov->area) + if (kcov->mode !=3D KCOV_MODE_INIT || !kcov->area || + !kcov->map_edge->area) return -EINVAL; t =3D current; if (kcov->t !=3D NULL || t->kcov !=3D NULL) @@ -859,7 +895,10 @@ static long kcov_ioctl(struct file *filep, unsigned in= t cmd, unsigned long arg) size =3D arg; if (size < 2 || size > INT_MAX / sizeof(unsigned long)) return -EINVAL; - res =3D kcov_map_init(kcov, size); + res =3D kcov_map_init(kcov, size, false); + if (res) + return res; + res =3D kcov_map_init(kcov, size, true); if (res) return res; spin_lock_irqsave(&kcov->lock, flags); --=20 2.47.1 From nobody Thu Dec 18 01:54:45 2025 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B54E923355F; Tue, 14 Jan 2025 05:36:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736832977; cv=none; b=nMgW51WEN5musur4IF8MwIEaz6qKqVsAL90vT72YcmkK4wUhSTnO+b1gxE90rY1YIwuhAVv/bomIGqDrH6uxOwvykWYOT98V7RXRF8ahMe4lQVq6MCaJC52y9DGWsK8daCeYcfHzdLmlJ+X2jvVrpVbLe2wzU1GZTilrCf5Vd2A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736832977; c=relaxed/simple; bh=cUrFJ9xlku6iOVJmqRm3AKSPyxlxbIELfrHlRVSE678=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=DMyohpSn7BjoA5WoItLE6/hjVxwR5+ybKlM2Y0uzOHQH+rn7z67QEd/B5o2IhulQb0rS673gxMpNcIIOwWafIReXno+L+w0nR0QM3F2NmnA7T1TZj+PRxk1HPY2FzfkJ0lxECJ3i6C0/YPi5e1m1R8p1WR0Orfb3cit3vU6IOiQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=aXbBkGUg; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="aXbBkGUg" Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50E2fc3u019144; Tue, 14 Jan 2025 05:35:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= CFVY0tjOmtO4qAqPnzy1tUQpQ6ETWmPtYq/HPU3qSi0=; b=aXbBkGUgRenYY+kr GhmhQxZFugwhs7ZerU+nCDz07oNXy4dB4IsS2Dn6ffnsRAFAHFmCulqCfnvn0VZR bIytfkOm3h0P5hnNhe8KtDRHc8NH8eI9DlQNPjFbr8uU61jzSSWI8lo63KxdwObG g+W8U0oLtB92OF40g3tTxMK1mz7UYvFQ8oMYPZrIgS+gcyD4nqoVAm9Gz6kFruCF s4DxNhbl1OReEc6X2stwMw0UD7kOwcqAU55wLJ0gHbGVK0i5TF/P7V49jaVzrFOQ HtJqJkcvB2YAuVoH74/8hjKc+QzkWFrpur5WdJVKmG7EukAMBxVk0586B5vLzQkx lXQJPQ== Received: from nasanppmta01.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 445fc68apd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 14 Jan 2025 05:35:59 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA01.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 50E5Zwtu020376 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 14 Jan 2025 05:35:58 GMT Received: from la-sh002-lnx.ap.qualcomm.com (10.80.80.8) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Mon, 13 Jan 2025 21:35:52 -0800 From: "Jiao, Joey" Date: Tue, 14 Jan 2025 13:34:33 +0800 Subject: [PATCH 3/7] kcov: allow using KCOV_TRACE_UNIQ_[PC|EDGE] modes together 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: <20250114-kcov-v1-3-004294b931a2@quicinc.com> References: <20250114-kcov-v1-0-004294b931a2@quicinc.com> In-Reply-To: <20250114-kcov-v1-0-004294b931a2@quicinc.com> To: Dmitry Vyukov , Andrey Konovalov , Jonathan Corbet , Andrew Morton , Dennis Zhou , Tejun Heo , Christoph Lameter , Catalin Marinas , Will Deacon CC: , , , , , , X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1736832942; l=1250; i=quic_jiangenj@quicinc.com; s=20250114; h=from:subject:message-id; bh=cUrFJ9xlku6iOVJmqRm3AKSPyxlxbIELfrHlRVSE678=; b=PN4imkwKcD7/nAryYV3lJaq77IA4e+9rhwFDEIua2TPoylFR2tEVvYzX1A0kElet197HOJhRv KnL6OAxKhzVAAeMfHluhR5AD/KnczeQvktL1Pe8Wg8BhWFmOtiquMjy X-Developer-Key: i=quic_jiangenj@quicinc.com; a=ed25519; pk=JPzmfEvx11SW1Q1qtMhFcAx46KP1Ui36jcetDgbev28= X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: 2ybqo6M8sHxWZsrwE_g4pZ5-4RN20TNw X-Proofpoint-GUID: 2ybqo6M8sHxWZsrwE_g4pZ5-4RN20TNw X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=891 adultscore=0 suspectscore=0 malwarescore=0 phishscore=0 clxscore=1015 impostorscore=0 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2501140043 KCOV_TRACE_UNIQ_PC and KCOV_TRACE_UNIQ_EDGE modes can be used separately, and now they can be used together to simulate current KCOV_TRACE_PC mode without sequence info. Signed-off-by: Jiao, Joey --- kernel/kcov.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/kernel/kcov.c b/kernel/kcov.c index 5a0ead92729294d99db80bb4e0f5b04c8b025dba..c04bbec9ac3186a5145240de8ac= 609ad8a7ca733 100644 --- a/kernel/kcov.c +++ b/kernel/kcov.c @@ -716,6 +716,8 @@ static int kcov_close(struct inode *inode, struct file = *filep) =20 static int kcov_get_mode(unsigned long arg) { + int mode =3D 0; + if (arg =3D=3D KCOV_TRACE_PC) return KCOV_MODE_TRACE_PC; else if (arg =3D=3D KCOV_TRACE_CMP) @@ -724,12 +726,14 @@ static int kcov_get_mode(unsigned long arg) #else return -ENOTSUPP; #endif - else if (arg =3D=3D KCOV_TRACE_UNIQ_PC) - return KCOV_MODE_TRACE_UNIQ_PC; - else if (arg =3D=3D KCOV_TRACE_UNIQ_EDGE) - return KCOV_MODE_TRACE_UNIQ_EDGE; - else + if (arg & KCOV_TRACE_UNIQ_PC) + mode |=3D KCOV_MODE_TRACE_UNIQ_PC; + if (arg & KCOV_TRACE_UNIQ_EDGE) + mode |=3D KCOV_MODE_TRACE_UNIQ_EDGE; + if (!mode) return -EINVAL; + + return mode; } =20 /* --=20 2.47.1 From nobody Thu Dec 18 01:54:45 2025 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9455B23A574; Tue, 14 Jan 2025 05:36:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736832981; cv=none; b=KNY0WCbGnKHyChzNi+rz+yU8kMme5LzR+Un2ZOTKmXSh0W+yLpLdLMdxXEnKpmyxTWEj+kk+0s/WSzFUS2lvc0rOKWP79VXysrd0n9zeDhKbqBOsdFXwZpqyGsVRzIb4jRqR/k9rx/yCt42/udOynLaKQKNB1ARC0RwO4qw+yVk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736832981; c=relaxed/simple; bh=87rus4o59M/h6mbCeTYN+uwPYg3Cu8v5VQQt/ES6TT4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=LNbSexJEAS6+A79mtIw3EoQ0C0Vh9J41OCYO5bDnaiqjdBT73WjDKHUh8SoblnwHDW9U0zsP8DjUDl/3f9yinNDsyBkDMpMlijat1rlAbxTfGXbxuTqApVg6u9BGKrChylSnghawvVi/P+bGT1iGBaTpas/XflH9K75g1S9HNb8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=iXWopfu7; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="iXWopfu7" Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50DH3oqq020410; Tue, 14 Jan 2025 05:36:03 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= drhXWUnxNp13ZTiPp3leq5WA8tzUkJEr4CWQ0Yv1pZw=; b=iXWopfu7nQ9ngkx7 h9V/MplxVwH+7w8ND4lXLO9AoxrObwWm6Rv9F5E1sL5EmPsM5k+9BrZTA29a60rc 4No3GOYTHQc1X4zvMoRu75RlwOXDjgCwnxKCS2q/cMNwKsgdgMz384yv0sCYO/dR oGaop5K6sWKj8cnCleQybJtOqPRZxMpj/PPi1xZeAMP/QUZqfcIoapQ6GlXYNh8V m6cOTT02MFtvDQR1DqIEjklPJtQOC0gPnqbJcghap6FBH09vAJ3KExYiSQnIZsl9 3DHoKQ2l2vjts65JrffTIAFnhTPtgDX7P5T1qnliGRJ9hoCDYRzf830qHzYjaqCR Bl+x9A== Received: from nasanppmta01.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4456wa9fhh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 14 Jan 2025 05:36:03 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA01.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 50E5a28k020523 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 14 Jan 2025 05:36:02 GMT Received: from la-sh002-lnx.ap.qualcomm.com (10.80.80.8) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Mon, 13 Jan 2025 21:35:56 -0800 From: "Jiao, Joey" Date: Tue, 14 Jan 2025 13:34:34 +0800 Subject: [PATCH 4/7] kcov: introduce new kcov KCOV_TRACE_UNIQ_CMP mode 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: <20250114-kcov-v1-4-004294b931a2@quicinc.com> References: <20250114-kcov-v1-0-004294b931a2@quicinc.com> In-Reply-To: <20250114-kcov-v1-0-004294b931a2@quicinc.com> To: Dmitry Vyukov , Andrey Konovalov , Jonathan Corbet , Andrew Morton , Dennis Zhou , Tejun Heo , Christoph Lameter , Catalin Marinas , Will Deacon CC: , , , , , , X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1736832942; l=6956; i=quic_jiangenj@quicinc.com; s=20250114; h=from:subject:message-id; bh=87rus4o59M/h6mbCeTYN+uwPYg3Cu8v5VQQt/ES6TT4=; b=dLbyxsjISwicFnHI2UlW7HXO0FqBJGbKRAtWrXffXPrseH1onOKQ7Uil5a0dOqyIK0G9Sonh3 Af14LF0A5HiDGL5/ZS9Y7gv/n6tgLyBJ6vxQua47w0wN4Ujd1sTIXzx X-Developer-Key: i=quic_jiangenj@quicinc.com; a=ed25519; pk=JPzmfEvx11SW1Q1qtMhFcAx46KP1Ui36jcetDgbev28= X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: -qyd1GNp6Gcg_3HTW0CFg-UHDCJbFmyY X-Proofpoint-ORIG-GUID: -qyd1GNp6Gcg_3HTW0CFg-UHDCJbFmyY X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 clxscore=1015 suspectscore=0 adultscore=0 mlxlogscore=734 priorityscore=1501 phishscore=0 malwarescore=0 impostorscore=0 lowpriorityscore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2501140044 Similar to KCOV_TRACE_CMP mode, KCOV_TRACE_UNIQ_CMP stores unique CMP data into area. Signed-off-by: Jiao, Joey --- include/linux/kcov.h | 2 + include/uapi/linux/kcov.h | 2 + kernel/kcov.c | 112 ++++++++++++++++++++++++++++++++----------= ---- 3 files changed, 83 insertions(+), 33 deletions(-) diff --git a/include/linux/kcov.h b/include/linux/kcov.h index 56b858205ba16c47fc72bda9938c98f034503c8c..a78d78164bf75368c71a958a543= 8fc3ee68c95ca 100644 --- a/include/linux/kcov.h +++ b/include/linux/kcov.h @@ -27,6 +27,8 @@ enum kcov_mode { KCOV_MODE_TRACE_UNIQ_PC =3D 16, /* Collecting uniq edge mode. */ KCOV_MODE_TRACE_UNIQ_EDGE =3D 32, + /* Collecting uniq cmp mode. */ + KCOV_MODE_TRACE_UNIQ_CMP =3D 64, }; =20 #define KCOV_IN_CTXSW (1 << 30) diff --git a/include/uapi/linux/kcov.h b/include/uapi/linux/kcov.h index 9b2019f0ab8b8cb5426d2d6b74472fa1a7293817..08abfca273c9624dc54a2c70b12= a4a9302700f26 100644 --- a/include/uapi/linux/kcov.h +++ b/include/uapi/linux/kcov.h @@ -39,6 +39,8 @@ enum { KCOV_TRACE_UNIQ_PC =3D 2, /* Collecting uniq edge mode. */ KCOV_TRACE_UNIQ_EDGE =3D 4, + /* Collecting uniq CMP mode. */ + KCOV_TRACE_UNIQ_CMP =3D 8, }; =20 /* diff --git a/kernel/kcov.c b/kernel/kcov.c index c04bbec9ac3186a5145240de8ac609ad8a7ca733..af73c40114d23adedab8318e865= 7d24bf36ae865 100644 --- a/kernel/kcov.c +++ b/kernel/kcov.c @@ -36,6 +36,11 @@ =20 struct kcov_entry { unsigned long ent; +#ifdef CONFIG_KCOV_ENABLE_COMPARISONS + unsigned long type; + unsigned long arg1; + unsigned long arg2; +#endif =20 struct hlist_node node; }; @@ -44,7 +49,7 @@ struct kcov_entry { #define MIN_POOL_ALLOC_ORDER ilog2(roundup_pow_of_two(sizeof(struct kcov_e= ntry))) =20 /* - * kcov hashmap to store uniq pc, prealloced mem for kcov_entry + * kcov hashmap to store uniq pc|edge|cmp, prealloced mem for kcov_entry * and area shared between kernel and userspace. */ struct kcov_map { @@ -87,7 +92,7 @@ struct kcov { unsigned long prev_pc; /* Coverage buffer shared with user space. */ void *area; - /* Coverage hashmap for unique pc. */ + /* Coverage hashmap for unique pc|cmp. */ struct kcov_map *map; /* Edge hashmap for unique edge. */ struct kcov_map *map_edge; @@ -289,14 +294,23 @@ static notrace inline void kcov_map_add(struct kcov_m= ap *map, struct kcov_entry struct kcov *kcov; struct kcov_entry *entry; unsigned int key =3D hash_key(ent); - unsigned long pos, *area; + unsigned long pos, start_index, end_pos, max_pos, *area; =20 kcov =3D t->kcov; =20 - hash_for_each_possible_rcu(map->buckets, entry, node, key) { - if (entry->ent =3D=3D ent->ent) - return; - } + if ((mode =3D=3D KCOV_MODE_TRACE_UNIQ_PC || + mode =3D=3D KCOV_MODE_TRACE_UNIQ_EDGE)) + hash_for_each_possible_rcu(map->buckets, entry, node, key) { + if (entry->ent =3D=3D ent->ent) + return; + } + else + hash_for_each_possible_rcu(map->buckets, entry, node, key) { + if (entry->ent =3D=3D ent->ent && entry->type =3D=3D ent->type && + entry->arg1 =3D=3D ent->arg1 && entry->arg2 =3D=3D ent->arg2) { + return; + } + } =20 entry =3D (struct kcov_entry *)gen_pool_alloc(map->pool, 1 << MIN_POOL_AL= LOC_ORDER); if (unlikely(!entry)) @@ -306,16 +320,31 @@ static notrace inline void kcov_map_add(struct kcov_m= ap *map, struct kcov_entry memcpy(entry, ent, sizeof(*entry)); hash_add_rcu(map->buckets, &entry->node, key); =20 - if (mode =3D=3D KCOV_MODE_TRACE_UNIQ_PC) + if (mode =3D=3D KCOV_MODE_TRACE_UNIQ_PC || mode =3D=3D KCOV_MODE_TRACE_UN= IQ_CMP) area =3D t->kcov_area; else area =3D kcov->map_edge->area; =20 pos =3D READ_ONCE(area[0]) + 1; - if (likely(pos < t->kcov_size)) { - WRITE_ONCE(area[0], pos); - barrier(); - area[pos] =3D ent->ent; + if (mode =3D=3D KCOV_MODE_TRACE_UNIQ_PC || mode =3D=3D KCOV_MODE_TRACE_UN= IQ_EDGE) { + if (likely(pos < t->kcov_size)) { + WRITE_ONCE(area[0], pos); + barrier(); + area[pos] =3D ent->ent; + } + } else { + start_index =3D 1 + (pos - 1) * KCOV_WORDS_PER_CMP; + max_pos =3D t->kcov_size * sizeof(unsigned long); + end_pos =3D (start_index + KCOV_WORDS_PER_CMP) * sizeof(u64); + if (likely(end_pos <=3D max_pos)) { + /* See comment in __sanitizer_cov_trace_pc(). */ + WRITE_ONCE(area[0], pos); + barrier(); + area[start_index] =3D ent->type; + area[start_index + 1] =3D ent->arg1; + area[start_index + 2] =3D ent->arg2; + area[start_index + 3] =3D ent->ent; + } } } =20 @@ -384,33 +413,44 @@ static void notrace write_comp_data(u64 type, u64 arg= 1, u64 arg2, u64 ip) struct task_struct *t; u64 *area; u64 count, start_index, end_pos, max_pos; + struct kcov_entry entry =3D {0}; + unsigned int mode; =20 t =3D current; - if (!check_kcov_mode(KCOV_MODE_TRACE_CMP, t)) + if (!check_kcov_mode(KCOV_MODE_TRACE_CMP | KCOV_MODE_TRACE_UNIQ_CMP, t)) return; =20 + mode =3D t->kcov_mode; ip =3D canonicalize_ip(ip); =20 - /* - * We write all comparison arguments and types as u64. - * The buffer was allocated for t->kcov_size unsigned longs. - */ - area =3D (u64 *)t->kcov_area; - max_pos =3D t->kcov_size * sizeof(unsigned long); - - count =3D READ_ONCE(area[0]); - - /* Every record is KCOV_WORDS_PER_CMP 64-bit words. */ - start_index =3D 1 + count * KCOV_WORDS_PER_CMP; - end_pos =3D (start_index + KCOV_WORDS_PER_CMP) * sizeof(u64); - if (likely(end_pos <=3D max_pos)) { - /* See comment in __sanitizer_cov_trace_pc(). */ - WRITE_ONCE(area[0], count + 1); - barrier(); - area[start_index] =3D type; - area[start_index + 1] =3D arg1; - area[start_index + 2] =3D arg2; - area[start_index + 3] =3D ip; + if (mode =3D=3D KCOV_MODE_TRACE_CMP) { + /* + * We write all comparison arguments and types as u64. + * The buffer was allocated for t->kcov_size unsigned longs. + */ + area =3D (u64 *)t->kcov_area; + max_pos =3D t->kcov_size * sizeof(unsigned long); + + count =3D READ_ONCE(area[0]); + + /* Every record is KCOV_WORDS_PER_CMP 64-bit words. */ + start_index =3D 1 + count * KCOV_WORDS_PER_CMP; + end_pos =3D (start_index + KCOV_WORDS_PER_CMP) * sizeof(u64); + if (likely(end_pos <=3D max_pos)) { + /* See comment in __sanitizer_cov_trace_pc(). */ + WRITE_ONCE(area[0], count + 1); + barrier(); + area[start_index] =3D type; + area[start_index + 1] =3D arg1; + area[start_index + 2] =3D arg2; + area[start_index + 3] =3D ip; + } + } else { + entry.type =3D type; + entry.arg1 =3D arg1; + entry.arg2 =3D arg2; + entry.ent =3D ip; + kcov_map_add(t->kcov->map, &entry, t, KCOV_MODE_TRACE_UNIQ_CMP); } } =20 @@ -730,6 +770,12 @@ static int kcov_get_mode(unsigned long arg) mode |=3D KCOV_MODE_TRACE_UNIQ_PC; if (arg & KCOV_TRACE_UNIQ_EDGE) mode |=3D KCOV_MODE_TRACE_UNIQ_EDGE; + if (arg =3D=3D KCOV_TRACE_UNIQ_CMP) +#ifdef CONFIG_KCOV_ENABLE_COMPARISONS + mode =3D KCOV_MODE_TRACE_UNIQ_CMP; +#else + return -EOPNOTSUPP; +#endif if (!mode) return -EINVAL; =20 --=20 2.47.1 From nobody Thu Dec 18 01:54:45 2025 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2AEB8233555; Tue, 14 Jan 2025 05:36:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736832990; cv=none; b=oIncuGEm9R3KyCQcH/NewC2v0NfOCSMhTsFzbQM1nHfsJ8+ZTe2JhwqQryMTKiyV6jUm1xGdpIaY2iK0KEmhX3uMwPT7A0a74l1yz5AXgAxQIEMCUHhoGCfyV4NshGg/6V8hep1CQsDP8ix8mMFG+zwifBiNMR4bWEZQbH9XbUM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736832990; c=relaxed/simple; bh=Lulb9I7d15ITpgpA7vYK556BzHyWX5kLFMs7zHurtPk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=uunMn0ZDN12kK6h0AsWVDWsR1QFpJFU7UULkb4qI6stV3KprO6mtsOE+7+GiRfDSwWgxeTIbUuoIY/NLV/iszmMcdRptM0XYK1Nc8shdaFaPIjvebDMnJjBhhlXi3Fgc5aSfpv9W46ATc8Yjg6ytfIylVeYwHBdyOqFhP9o7m08= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=JCcY18Jy; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="JCcY18Jy" Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50E23rPd008664; Tue, 14 Jan 2025 05:36:06 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= SnTIiCvc99mwVePAnY7xDBhzjlSnYyKXixXlpKzOnM4=; b=JCcY18JyP35QhE2i nTjLZc54+6+TZtbHeqOYLvTzs51/WglbUjzKvSN3lsVfQz+xcPJwbZ99TgdvzWn7 LXMehmLWqLiUyLd4SPi0JjnNHo2mo15MwWRqxvyHDbA9BfK+Hr/9CV2YcB9CJ8oW D9iSo3GMZWa0RQfAoewUcgVxfAF0ofbldSUuN/t1rRoSVGgmjZO2MU5La2FXQemL fWgQqX6qZ79MfriW7E0xk2uwE2Gbku+0Sm4DgW20S7AdSBXti4neB5cW/rvT+y84 739faLja8SC7lzZzbseLpoMcCZmkxjWf0zEbIuuq1tvq8HD+iroq0bUWawsQ24pl HEv1UQ== Received: from nasanppmta04.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 445eterdbu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 14 Jan 2025 05:36:06 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA04.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 50E5a5VP031710 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 14 Jan 2025 05:36:05 GMT Received: from la-sh002-lnx.ap.qualcomm.com (10.80.80.8) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Mon, 13 Jan 2025 21:35:59 -0800 From: "Jiao, Joey" Date: Tue, 14 Jan 2025 13:34:35 +0800 Subject: [PATCH 5/7] kcov: add the new KCOV uniq modes example code 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: <20250114-kcov-v1-5-004294b931a2@quicinc.com> References: <20250114-kcov-v1-0-004294b931a2@quicinc.com> In-Reply-To: <20250114-kcov-v1-0-004294b931a2@quicinc.com> To: Dmitry Vyukov , Andrey Konovalov , Jonathan Corbet , Andrew Morton , Dennis Zhou , Tejun Heo , Christoph Lameter , Catalin Marinas , Will Deacon CC: , , , , , , X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1736832942; l=11230; i=quic_jiangenj@quicinc.com; s=20250114; h=from:subject:message-id; bh=Lulb9I7d15ITpgpA7vYK556BzHyWX5kLFMs7zHurtPk=; b=PsYnlyeqPpQvbH0Tjx/23z40jyNSYl78V1dqIGIKdCPIfjW6tQcTCFyzJ9UvXBOuXjtWtUwDB TAqwKIXfgCUBSNrKOSChk4WtD7SAjYOBbZ/LvHcIKI1yVt1GRWOuj8H X-Developer-Key: i=quic_jiangenj@quicinc.com; a=ed25519; pk=JPzmfEvx11SW1Q1qtMhFcAx46KP1Ui36jcetDgbev28= X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: wnv8w4hud187Ydr9CX1bF6ILuw6Aa77S X-Proofpoint-GUID: wnv8w4hud187Ydr9CX1bF6ILuw6Aa77S X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxlogscore=999 impostorscore=0 suspectscore=0 mlxscore=0 lowpriorityscore=0 priorityscore=1501 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2501140044 - Use single program to select different mode. - Mode [0|1|2|4|8] to KCOV_TRACE_[PC|CMP|UNIQ_PC|UNIQ_EDGE|UNIQ_CMP]. - Mode 6 to KCOV_TRACE_UNIQ_PC and KCOV_TRACE_UNIQ_EDGE. Signed-off-by: Jiao, Joey --- Documentation/dev-tools/kcov.rst | 243 ++++++++++++++++++++---------------= ---- 1 file changed, 122 insertions(+), 121 deletions(-) diff --git a/Documentation/dev-tools/kcov.rst b/Documentation/dev-tools/kco= v.rst index 6611434e2dd247c6c40afcbf1e6c4e22e0562176..061ae20b867fd9e68b447b86719= 733278ee6b86f 100644 --- a/Documentation/dev-tools/kcov.rst +++ b/Documentation/dev-tools/kcov.rst @@ -40,11 +40,12 @@ Coverage data only becomes accessible once debugfs has = been mounted:: =20 mount -t debugfs none /sys/kernel/debug =20 -Coverage collection +Coverage collection for different modes ------------------- =20 The following program demonstrates how to use KCOV to collect coverage for= a -single syscall from within a test program: +single syscall from within a test program, argv[1] can be provided to sele= ct +which mode to enable: =20 .. code-block:: c =20 @@ -60,55 +61,130 @@ single syscall from within a test program: #include #include =20 - #define KCOV_INIT_TRACE _IOR('c', 1, unsigned long) + #define KCOV_INIT_TRACE _IOR('c', 1, unsigned long) #define KCOV_ENABLE _IO('c', 100) - #define KCOV_DISABLE _IO('c', 101) + #define KCOV_DISABLE _IO('c', 101) #define COVER_SIZE (64<<10) =20 #define KCOV_TRACE_PC 0 #define KCOV_TRACE_CMP 1 + #define KCOV_TRACE_UNIQ_PC 2 + #define KCOV_TRACE_UNIQ_EDGE 4 + #define KCOV_TRACE_UNIQ_CMP 8 + + /* Number of 64-bit words per record. */ + #define KCOV_WORDS_PER_CMP 4 + + /* + * The format for the types of collected comparisons. + * + * Bit 0 shows whether one of the arguments is a compile-time constant. + * Bits 1 & 2 contain log2 of the argument size, up to 8 bytes. + */ + + #define KCOV_CMP_CONST (1 << 0) + #define KCOV_CMP_SIZE(n) ((n) << 1) + #define KCOV_CMP_MASK KCOV_CMP_SIZE(3) =20 int main(int argc, char **argv) { - int fd; - unsigned long *cover, n, i; - - /* A single fd descriptor allows coverage collection on a single - * thread. - */ - fd =3D open("/sys/kernel/debug/kcov", O_RDWR); - if (fd =3D=3D -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 =3D (unsigned long*)mmap(NULL, COVER_SIZE * sizeof(unsigned long), - PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if ((void*)cover =3D=3D MAP_FAILED) - perror("mmap"), exit(1); - /* Enable coverage collection on the current thread. */ - if (ioctl(fd, KCOV_ENABLE, KCOV_TRACE_PC)) - perror("ioctl"), exit(1); - /* Reset coverage from the tail of the ioctl() call. */ - __atomic_store_n(&cover[0], 0, __ATOMIC_RELAXED); - /* Call the target syscall call. */ - read(-1, NULL, 0); - /* Read number of PCs collected. */ - n =3D __atomic_load_n(&cover[0], __ATOMIC_RELAXED); - for (i =3D 0; i < n; i++) - printf("0x%lx\n", cover[i + 1]); - /* Disable coverage collection for the current thread. After this call - * coverage can be enabled for a different thread. - */ - if (ioctl(fd, KCOV_DISABLE, 0)) - perror("ioctl"), exit(1); - /* Free resources. */ - if (munmap(cover, COVER_SIZE * sizeof(unsigned long))) - perror("munmap"), exit(1); - if (close(fd)) - perror("close"), exit(1); - return 0; + int fd; + unsigned long *cover, *edge, n, n1, i, type, arg1, arg2, is_const,= size; + unsigned int mode =3D KCOV_TRACE_PC; + + /* argv[1] controls which mode to use, default to KCOV_TRACE_PC. + * supported modes include: + * KCOV_TRACE_PC + * KCOV_TRACE_CMP + * KCOV_TRACE_UNIQ_PC + * KCOV_TRACE_UNIQ_EDGE + * KCOV_TRACE_UNIQ_PC | KCOV_TRACE_UNIQ_EDGE + * KCOV_TRACE_UNIQ_CMP + */ + if (argc > 1) + mode =3D (unsigned int)strtoul(argv[1], NULL, 10); + printf("The mode is: %u\n", mode); + if (mode !=3D KCOV_TRACE_PC && mode !=3D KCOV_TRACE_CMP && + !(mode & (KCOV_TRACE_UNIQ_PC | KCOV_TRACE_UNIQ_EDGE | KCOV_TRA= CE_UNIQ_CMP))) { + printf("Unsupported mode!\n"); + exit(1); + } + /* A single fd descriptor allows coverage collection on a single + * thread. + */ + fd =3D open("/sys/kernel/debug/kcov", O_RDWR); + if (fd =3D=3D -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 =3D (unsigned long*)mmap(NULL, COVER_SIZE * sizeof(unsigned = long), + PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + if ((void*)cover =3D=3D MAP_FAILED) + perror("mmap"), exit(1); + if (mode & KCOV_TRACE_UNIQ_EDGE) { + edge =3D (unsigned long*)mmap(NULL, COVER_SIZE * sizeof(unsign= ed long), + PROT_READ | PROT_WRITE, MAP_SHARED, fd, COVER_SIZE= * sizeof(unsigned long)); + if ((void*)edge =3D=3D MAP_FAILED) + perror("mmap"), exit(1); + } + /* Enable coverage collection on the current thread. */ + if (ioctl(fd, KCOV_ENABLE, mode)) + perror("ioctl"), exit(1); + /* Reset coverage from the tail of the ioctl() call. */ + __atomic_store_n(&cover[0], 0, __ATOMIC_RELAXED); + if (mode & KCOV_TRACE_UNIQ_EDGE) + __atomic_store_n(&edge[0], 0, __ATOMIC_RELAXED); + /* Call the target syscall call. */ + read(-1, NULL, 0); + /* Read number of PCs collected. */ + n =3D __atomic_load_n(&cover[0], __ATOMIC_RELAXED); + if (mode & KCOV_TRACE_UNIQ_EDGE) + n1 =3D __atomic_load_n(&edge[0], __ATOMIC_RELAXED); + if (mode & (KCOV_TRACE_CMP | KCOV_TRACE_UNIQ_CMP)) { + for (i =3D 0; i < n; i++) { + uint64_t ip; + + type =3D cover[i * KCOV_WORDS_PER_CMP + 1]; + /* arg1 and arg2 - operands of the comparison. */ + arg1 =3D cover[i * KCOV_WORDS_PER_CMP + 2]; + arg2 =3D cover[i * KCOV_WORDS_PER_CMP + 3]; + /* ip - caller address. */ + ip =3D cover[i * KCOV_WORDS_PER_CMP + 4]; + /* size of the operands. */ + size =3D 1 << ((type & KCOV_CMP_MASK) >> 1); + /* is_const - true if either operand is a compile-time con= stant.*/ + is_const =3D type & KCOV_CMP_CONST; + printf("ip: 0x%lx type: 0x%lx, arg1: 0x%lx, arg2: 0x%lx, " + "size: %lu, %s\n", + ip, type, arg1, arg2, size, + is_const ? "const" : "non-const"); + } + } else { + for (i =3D 0; i < n; i++) + printf("0x%lx\n", cover[i + 1]); + if (mode & KCOV_TRACE_UNIQ_EDGE) { + printf("=3D=3D=3D=3D=3D=3Dedge=3D=3D=3D=3D=3D=3D\n"); + for (i =3D 0; i < n1; i++) + printf("0x%lx\n", edge[i + 1]); + } + } + /* Disable coverage collection for the current thread. After this = call + * coverage can be enabled for a different thread. + */ + if (ioctl(fd, KCOV_DISABLE, 0)) + perror("ioctl"), exit(1); + /* Free resources. */ + if (munmap(cover, COVER_SIZE * sizeof(unsigned long))) + perror("munmap"), exit(1); + if (mode & KCOV_TRACE_UNIQ_EDGE) { + if (munmap(edge, COVER_SIZE * sizeof(unsigned long))) + perror("munmap"), exit(1); + } + if (close(fd)) + perror("close"), exit(1); + return 0; } =20 After piping through ``addr2line`` the output of the program looks as foll= ows:: @@ -137,85 +213,10 @@ mmaps coverage buffer, and then forks child processes= in a loop. The child processes only need to enable coverage (it gets disabled automatically when a thread exits). =20 -Comparison operands collection ------------------------------- - -Comparison operands collection is similar to coverage collection: - -.. code-block:: c - - /* Same includes and defines as above. */ - - /* Number of 64-bit words per record. */ - #define KCOV_WORDS_PER_CMP 4 - - /* - * The format for the types of collected comparisons. - * - * Bit 0 shows whether one of the arguments is a compile-time constant. - * Bits 1 & 2 contain log2 of the argument size, up to 8 bytes. - */ - - #define KCOV_CMP_CONST (1 << 0) - #define KCOV_CMP_SIZE(n) ((n) << 1) - #define KCOV_CMP_MASK KCOV_CMP_SIZE(3) - - int main(int argc, char **argv) - { - int fd; - uint64_t *cover, type, arg1, arg2, is_const, size; - unsigned long n, i; - - fd =3D open("/sys/kernel/debug/kcov", O_RDWR); - if (fd =3D=3D -1) - perror("open"), exit(1); - if (ioctl(fd, KCOV_INIT_TRACE, COVER_SIZE)) - perror("ioctl"), exit(1); - /* - * Note that the buffer pointer is of type uint64_t*, because all - * the comparison operands are promoted to uint64_t. - */ - cover =3D (uint64_t *)mmap(NULL, COVER_SIZE * sizeof(unsigned long), - PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if ((void*)cover =3D=3D MAP_FAILED) - perror("mmap"), exit(1); - /* Note KCOV_TRACE_CMP instead of KCOV_TRACE_PC. */ - if (ioctl(fd, KCOV_ENABLE, KCOV_TRACE_CMP)) - perror("ioctl"), exit(1); - __atomic_store_n(&cover[0], 0, __ATOMIC_RELAXED); - read(-1, NULL, 0); - /* Read number of comparisons collected. */ - n =3D __atomic_load_n(&cover[0], __ATOMIC_RELAXED); - for (i =3D 0; i < n; i++) { - uint64_t ip; - - type =3D cover[i * KCOV_WORDS_PER_CMP + 1]; - /* arg1 and arg2 - operands of the comparison. */ - arg1 =3D cover[i * KCOV_WORDS_PER_CMP + 2]; - arg2 =3D cover[i * KCOV_WORDS_PER_CMP + 3]; - /* ip - caller address. */ - ip =3D cover[i * KCOV_WORDS_PER_CMP + 4]; - /* size of the operands. */ - size =3D 1 << ((type & KCOV_CMP_MASK) >> 1); - /* is_const - true if either operand is a compile-time constant.*/ - is_const =3D type & KCOV_CMP_CONST; - printf("ip: 0x%lx type: 0x%lx, arg1: 0x%lx, arg2: 0x%lx, " - "size: %lu, %s\n", - ip, type, arg1, arg2, size, - is_const ? "const" : "non-const"); - } - if (ioctl(fd, KCOV_DISABLE, 0)) - perror("ioctl"), exit(1); - /* Free resources. */ - if (munmap(cover, COVER_SIZE * sizeof(unsigned long))) - perror("munmap"), exit(1); - if (close(fd)) - perror("close"), exit(1); - return 0; - } - Note that the KCOV modes (collection of code coverage or comparison operan= ds) -are mutually exclusive. +are mutually exclusive, KCOV_TRACE_UNIQ_PC and KCOV_TRACE_UNIQ_EDGE can be +enabled together. + =20 Remote coverage collection -------------------------- --=20 2.47.1 From nobody Thu Dec 18 01:54:45 2025 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B8C20233558; Tue, 14 Jan 2025 05:36:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736832993; cv=none; b=eYXi/9mpL0+1C6AsBVft0c8TwXeepblnuYGwYgHjZP4cthAMunRLzM/KuVS1gfP/Xo5fi3BoknAAAQnGcJTmzWMjCFDnE6B/2TuPARNwJdqSrkPfWaY4zP5zFbX/wmvcSGDKIXAIYstjFyS/Q8KKE0KPWD4xMyL+014h3uQJCug= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736832993; c=relaxed/simple; bh=EXcTVhs0X6v2Sn7y/hEncpAKcEG0rAcAKxXrOMGyy08=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=OhU+hNCzmLBhTo9iGQkSXsy8L0ugUE0ZtOLYEe6SuDPCocAyS04QEvvtmwq5pNf7RwpBZgQjj4EoEmj+FdN1ll1fSb4jeT1KRjjJe0W0nwbUFV+FN+WvBnFFNY10RdvS347K/o0/eG26ZFlRHXDwuu2t5sIlVITl020hd1BSf6w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=pib3eWcG; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="pib3eWcG" Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50E40k6j020873; Tue, 14 Jan 2025 05:36:09 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= sbZl6GtDotLNfy1i0ybFvuNDyQMsou97Y3PruXQtvYc=; b=pib3eWcGHBy1q5JO eqjOf146/5gOab2zbejzkS2zfNrQW2mDtMyDQAhbTP8n6nM/nD+Fm8FIRFxSv/hw PLyXf92MGH3p2QrEOwHZ6bW4YJ5bXwPBnoJValvoWFGYWzgcj/X2gtl2h7iBE+Vd Ud3nCD2wZycQ/XRcxOh4udyfp965MOGdXQDIT855hgCMhLfW9+XnleDiTW2QSIB4 X87O1VDwqdCOSIV5lQRK7vXnwtIAGY6aUU8y2LGTB+70/wXMtS3h3aUhQ5LO7jvG 4syLPlEWs1ra4stuiLFpyJfP6FDVN09pNxgY7lcUnDKkKAZbJ2L8nYFv1UwTtxj+ NhOR9Q== Received: from nasanppmta04.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 445gh60522-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 14 Jan 2025 05:36:09 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA04.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 50E5a9Sk032192 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 14 Jan 2025 05:36:09 GMT Received: from la-sh002-lnx.ap.qualcomm.com (10.80.80.8) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Mon, 13 Jan 2025 21:36:03 -0800 From: "Jiao, Joey" Date: Tue, 14 Jan 2025 13:34:36 +0800 Subject: [PATCH 6/7] kcov: disable instrumentation for genalloc and bitmap 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: <20250114-kcov-v1-6-004294b931a2@quicinc.com> References: <20250114-kcov-v1-0-004294b931a2@quicinc.com> In-Reply-To: <20250114-kcov-v1-0-004294b931a2@quicinc.com> To: Dmitry Vyukov , Andrey Konovalov , Jonathan Corbet , Andrew Morton , Dennis Zhou , Tejun Heo , Christoph Lameter , Catalin Marinas , Will Deacon CC: , , , , , , X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1736832942; l=875; i=quic_jiangenj@quicinc.com; s=20250114; h=from:subject:message-id; bh=EXcTVhs0X6v2Sn7y/hEncpAKcEG0rAcAKxXrOMGyy08=; b=DPbLlmPLNl9LVZSN1bfAVqQsyLNyv2HqNKFt/s+LvYi8cIICAf3fRzFkJUf2iumIUN1xDcknK z8FbRLfWBReCSA8dPFnjOChSeV9/ToF4C7tcNQG1a9YzeqfEVSpKKbd X-Developer-Key: i=quic_jiangenj@quicinc.com; a=ed25519; pk=JPzmfEvx11SW1Q1qtMhFcAx46KP1Ui36jcetDgbev28= X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: CzmwwnNWwZyaCVN5LYXu9a4ccWBCgyOh X-Proofpoint-GUID: CzmwwnNWwZyaCVN5LYXu9a4ccWBCgyOh X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxscore=0 suspectscore=0 malwarescore=0 mlxlogscore=778 phishscore=0 clxscore=1015 spamscore=0 lowpriorityscore=0 priorityscore=1501 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2501140044 gen_pool_alloc in kcov_map_add triggers recursive call, which trigger BUG: TASK stack guard page was hit at ffffc9000451ff38. Disable KCOV to avoid the recursive call. Signed-off-by: Jiao, Joey --- lib/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Makefile b/lib/Makefile index a8155c972f02856fcc61ee949ddda436cfe211ff..7a110a9a4a527b881ca3a0239d0= b60511cb6e38b 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -15,6 +15,8 @@ KCOV_INSTRUMENT_debugobjects.o :=3D n KCOV_INSTRUMENT_dynamic_debug.o :=3D n KCOV_INSTRUMENT_fault-inject.o :=3D n KCOV_INSTRUMENT_find_bit.o :=3D n +KCOV_INSTRUMENT_genalloc.o :=3D n +KCOV_INSTRUMENT_bitmap.o :=3D n =20 # string.o implements standard library functions like memset/memcpy etc. # Use -ffreestanding to ensure that the compiler does not try to "optimize" --=20 2.47.1 From nobody Thu Dec 18 01:54:45 2025 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF41023499F; Tue, 14 Jan 2025 05:36:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736832993; cv=none; b=W28GOUMvb3Wp8vOsGUdZ4tIdwO/4TZjI62dQcPiTdlzkARnTiDAXMV/luZPXX/sFGI83RcwkHEsGfLZv5K+XkFqPbPp6s/7uuXiTtnhkaEAhZFDAZSHHNWtHspfBbcDJgUDfdxUbMsWI8HRqv4IX8q1l51qlsSb7kIds3rtfrYo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736832993; c=relaxed/simple; bh=1kWeMy8H18bHx7q6bxqI4S7xMp8TmEXRvurq+o8jSTk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=bwIZ1x5bXcRKDcbGKXpKCt3ts9PsyZJYHglc8cljsHWvizTVPdkQmnsDGuRpi0fH7CDPK3maNcrSrBnop1C29YjbupbPcx7lguY9Cp4psSKPtgs8KIOEbbEt5U/D7IL4z8+eu17XPiSdfHhXwhuZodEh7nOpAljsWucmiRlxb8A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=HikSzvI7; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="HikSzvI7" Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50E40bZB020725; Tue, 14 Jan 2025 05:36:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= /Ra3dSoqbIv2eF9zoZUbyQQPjXpOzfwJvCpeTMxHEKs=; b=HikSzvI7KYxlMco7 RYWzAkybYaofzND7NE4hK4kh74cceDeIxcHy4IlcELeV+V1szgEwQftpeoMU4ZxX I5vZm1eC4knIGqbT81HKE+xnKB7NP/T/S7DL4FTYVVSQLQp6k8hlGJ0JB6OvTIIV ogtxPXvzkGPqKoc7DrYPk8ot36bUWdSE1GZRtMUo5ZGxUkfriEokjDsR+THoxPFo 3etaL6pf3ZUxjT2Pq4NLi9xe0h3p0Klve1MwE/m7AFjjw78z1UPxTkdW6KVSr6YB EkcMcoBwvtfq0HISfK3vjQQEjxjnepwx64iXQBs1PRNTtxowDx9vO1yyLUvkocWX qu4VSA== Received: from nasanppmta05.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 445gh60526-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 14 Jan 2025 05:36:13 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA05.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 50E5aCok016202 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 14 Jan 2025 05:36:12 GMT Received: from la-sh002-lnx.ap.qualcomm.com (10.80.80.8) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Mon, 13 Jan 2025 21:36:06 -0800 From: "Jiao, Joey" Date: Tue, 14 Jan 2025 13:34:37 +0800 Subject: [PATCH 7/7] arm64: disable kcov instrument in header files 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: <20250114-kcov-v1-7-004294b931a2@quicinc.com> References: <20250114-kcov-v1-0-004294b931a2@quicinc.com> In-Reply-To: <20250114-kcov-v1-0-004294b931a2@quicinc.com> To: Dmitry Vyukov , Andrey Konovalov , Jonathan Corbet , Andrew Morton , Dennis Zhou , Tejun Heo , Christoph Lameter , Catalin Marinas , Will Deacon CC: , , , , , , X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1736832942; l=1362; i=quic_jiangenj@quicinc.com; s=20250114; h=from:subject:message-id; bh=1kWeMy8H18bHx7q6bxqI4S7xMp8TmEXRvurq+o8jSTk=; b=zPdx/wsH9uf3YlAIvy013JGGUIrnRUGzN+n5UmShLK05sjrO5Bv+UKhmFiYiSigdphGdNZ4mt wlcCgEsIO2HASI15aSluF7QMoXny39DoX3F20cozNtGxwEHgHdqrSVX X-Developer-Key: i=quic_jiangenj@quicinc.com; a=ed25519; pk=JPzmfEvx11SW1Q1qtMhFcAx46KP1Ui36jcetDgbev28= X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: SJSYjyfLnYMRCxOaFXFtA289YzGmtz-L X-Proofpoint-GUID: SJSYjyfLnYMRCxOaFXFtA289YzGmtz-L X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxscore=0 suspectscore=0 malwarescore=0 mlxlogscore=761 phishscore=0 clxscore=1015 spamscore=0 lowpriorityscore=0 priorityscore=1501 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2501140044 Disable instrument which causes recursive call to __sanitizer_cov_trace_pc Signed-off-by: Jiao, Joey --- arch/arm64/include/asm/percpu.h | 2 +- arch/arm64/include/asm/preempt.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/percpu.h b/arch/arm64/include/asm/percp= u.h index 9abcc8ef3087b7066c82db983ae2753f30607f7f..a40ff8168151bb481756d0f6cb3= 41aa8dc52a121 100644 --- a/arch/arm64/include/asm/percpu.h +++ b/arch/arm64/include/asm/percpu.h @@ -29,7 +29,7 @@ static inline unsigned long __hyp_my_cpu_offset(void) return read_sysreg(tpidr_el2); } =20 -static inline unsigned long __kern_my_cpu_offset(void) +static __no_sanitize_coverage inline unsigned long __kern_my_cpu_offset(vo= id) { unsigned long off; =20 diff --git a/arch/arm64/include/asm/preempt.h b/arch/arm64/include/asm/pree= mpt.h index 0159b625cc7f0e7d6996b34b4de8e71b04ca32e5..a8742a57481a8bf7f1e35b9cd8b= 0fd9a37f0ba78 100644 --- a/arch/arm64/include/asm/preempt.h +++ b/arch/arm64/include/asm/preempt.h @@ -8,7 +8,7 @@ #define PREEMPT_NEED_RESCHED BIT(32) #define PREEMPT_ENABLED (PREEMPT_NEED_RESCHED) =20 -static inline int preempt_count(void) +static __no_sanitize_coverage inline int preempt_count(void) { return READ_ONCE(current_thread_info()->preempt.count); } --=20 2.47.1