From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DEF67E77188 for ; Tue, 14 Jan 2025 05:44:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 798086B0083; Tue, 14 Jan 2025 00:44:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 747F06B0085; Tue, 14 Jan 2025 00:44:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5E9086B008C; Tue, 14 Jan 2025 00:44:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 406DD6B0083 for ; Tue, 14 Jan 2025 00:44:40 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E5100120709 for ; Tue, 14 Jan 2025 05:44:39 +0000 (UTC) X-FDA: 83004967878.20.2F4D464 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf20.hostedemail.com (Postfix) with ESMTP id D91331C0012 for ; Tue, 14 Jan 2025 05:44:37 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=DL0uxWQR; spf=pass (imf20.hostedemail.com: domain of quic_jiangenj@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_jiangenj@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736833477; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=1Ho/hzWqKaR7WmES103bnR+aCJ3CIJMTmRLpOr/yJsM=; b=KEJdHoqatNgkKKdBreV+6Dza3OwBvmhISO6yIXomt/bM8mSLyG36xaSLzcwP9WDOAP/JIH HY4BOVhwg7SjmC7UoTII66U8XGktvmNvlI6GpA/y5+SFN8Xd/zVsqpu7CE3sBjGERKKtCV yvUqFxhCqju1EJPAdH6Kub+6evSbdl0= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=DL0uxWQR; spf=pass (imf20.hostedemail.com: domain of quic_jiangenj@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_jiangenj@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736833477; a=rsa-sha256; cv=none; b=Wibpj5UJJN1tv6xBoaGhUDDx3CFB6WrKa6Gldr9uu03AzPDZJLKmCHn2EThIqGkCxnLTbV 7UF1l+iZbC+wK3wnYW7XvXLK5OY6vvkEplLpYkzNutPyW4+lZfHhSqviTle4KMBy7Xc7sO +E5kszg4keCwpU1nnr1K0aC0emC7ekQ= Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50E2h0wH003293; Tue, 14 Jan 2025 05:44:24 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-type:date:from:in-reply-to:message-id:mime-version :references:subject:to; s=qcppdkim1; bh=1Ho/hzWqKaR7WmES103bnR+a CJ3CIJMTmRLpOr/yJsM=; b=DL0uxWQROXVP4FXGglVBielJfhdi78bFuHjfUfDr PU3RBaCvt1S5MJlWuRAJw6NeT88q1PvxF4OOWlSrUfytwhLlagTUY5/tOuKYeSVO ALBrQjc1I5K9eim2DziUQeZNgzjmmcspXTyiQ2C1Gd294dFVKRA0WSzWMaKKbIu5 s6fs2alPCgV/IOzkNC9DDi0TBaTHAoInWUzImd6HPss+gfFnqhoByWY+pXSC9Zq2 L77IYRiKb0ncm0qhIMMZjVA4nz1aJT23htAIJD9W9LS2XXEqLLJV0299cS3mfV0i 0lJwCwMKy3fKrmACh5HTciFWAcz8NPjz2b3nihUfZmzpXQ== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 445fcr8aka-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 14 Jan 2025 05:44:24 +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 50E5iNHN001341 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 14 Jan 2025 05:44:23 GMT Received: from hu-jiangenj-sha.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:44:14 -0800 Date: Tue, 14 Jan 2025 11:14:11 +0530 From: Joey Jiao To: Marco Elver CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: Re: [PATCH] kcov: add unique cover, edge, and cmp modes Message-ID: References: <20250110073056.2594638-1-quic_jiangenj@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: X-Originating-IP: [10.80.80.8] 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: 1ocO8HRdM0OP4OGLu_yO60qlBwPczBE- X-Proofpoint-GUID: 1ocO8HRdM0OP4OGLu_yO60qlBwPczBE- 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 spamscore=0 mlxscore=0 suspectscore=0 mlxlogscore=999 priorityscore=1501 clxscore=1015 adultscore=0 lowpriorityscore=0 malwarescore=0 phishscore=0 bulkscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2501140045 X-Rspamd-Queue-Id: D91331C0012 X-Rspamd-Server: rspam12 X-Stat-Signature: cx4noqckcf9s7448q6j9baer1dbafka3 X-Rspam-User: X-HE-Tag: 1736833477-898790 X-HE-Meta: U2FsdGVkX18uso6NeZSGGT2YtYxIEDHCeDeYvFar+F97+A77efCf8qbjQMb5A3ZmYAHF8MLtYvOYXJfKwPXxI7y8rt+kUSSIoq6pFto8vHLnECoin+lDs347qqwMgiwrFGVFa7qyq9IgsbKUmGdsh25/TKcDiCC3Yp+w4yfTVxwgZpJVyF/QxKLHsEPkRliz5tpenVOS4UFHAbuIfFDiKXPhnt+OdtCaDeDcaO3RjkxlMnz61QC6ZWLZyyR9zxOL0P0wSMxdAj6Mqf9OTczge+bUS0oK7CbrI7BxrC0LOwwxKlSMpWfaVrrFC3B0qZw73xcp70Lpn561qN+gC+JzTMtGs34esbrC1mUy0JtgTi3emrtnuQ65egfHJj46xzQoegjwkxvZwsOg/t9LXfDwTIqu3k7nnGJFldgrQazF9MEqM4nD5snPYrxJP1PuZZx4gQxNQFMMLayCVYVBZHXfquxSLBlvEPoJrzN5an/RxwjTtNYitnfrasa5/nx9IEsXuSjZnIiZGLeBnjfYnZGSfahbP2U6MPlYdTcmEzhZtIc+rxJT6E9amOmGtlp9suQSmbVz0zwixIU8MkSoZ+QDJZUwuKb5Q9lt18sL8CROwA+GwA8kCBpmh6mXABAJccCn4NQOW+jBW12hha3fi16BduaT5KgeiWcIHInSDoZAJMyveHxHzaVPD7l0aBbUV+53NeBzBgKgRLJEND7lPr1EsfJdwZ9fBGwcxX4ZiGhBbMPN7I09yUESynM6AoLCahhdfhVKIpgp9pwWZg6vUGEdDiUmw+cWlLjQLEC1ndIM2L/MLyD3Ussw/G7qHz1XOpDkOxMRvKTwF3/qzzXHaG/ZYhezC7TtVk/d4MxogIxmiaO/+LiE4com7XCQee83xRmfyOKXt+9qqlDauxdXUFh1ztBf+PnHfutaPjhFC1qBj9x7arG1OYZXbglaF+BR8rh4lRDRmcwDQMp+skLNRjW oVGc5uiQ d6Xdk5JKEmEINI5A7kOmziJju+EHYRVjTYh3zoJIu8EPtfhMooyhUZS1jxL3VDsNUkkyfls6sFh7X8NDUOw+905cEh4eK8azuSuHhlxTyivze45H0hWM2xw7HDj6DmrbZapyq/RuENtPQ3sqFqYRGm9Gco5tanvIhGqvTzcQafXaygM0z4T7hDi1jX8lhqtnDRaTO3tjGfPAks+OXDfeFUBNp/RWRyKZx+vqGG/w71H5OhBfG9vRKxGX5lEVLcawLb1zydJ9BEU+Kj0OL8iEDbSvVYoOcq8DJcWj2fNl0+nxRXrnoA/MX27BicP7d3HnzdDo2zOzESLB4LKCBfla+5HvJ2aNNAPIfyFWvsdSJ5iVHi7whRZAo9QrOZQHcC4YpE8o1Csu7LgW34dFvzX/n/9JXpROgSpkBXKju6aXYCWJdjUvG4J1FyRoS7g/ZgT6OZTgE X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Fri, Jan 10, 2025 at 10:22:44AM +0100, Marco Elver wrote: > On Fri, 10 Jan 2025 at 08:33, Joey Jiao wrote: > > > > From: "Jiao, Joey" > > > > The current design of KCOV risks frequent buffer overflows. To mitigate > > this, new modes are introduced: KCOV_TRACE_UNIQ_PC, KCOV_TRACE_UNIQ_EDGE, > > and KCOV_TRACE_UNIQ_CMP. These modes allow for the recording of unique > > PCs, edges, and comparison operands (CMP). > > There ought to be a cover letter explaining the motivation for this, > and explaining why the new modes would help. Ultimately, what are you > using KCOV for where you encountered this problem? > > > Key changes include: > > - KCOV_TRACE_UNIQ_[PC|EDGE] can be used together to replace KCOV_TRACE_PC. > > - KCOV_TRACE_UNIQ_CMP can be used to replace KCOV_TRACE_CMP mode. > > - Introduction of hashmaps to store unique coverage data. > > - Pre-allocated entries in kcov_map_init during KCOV_INIT_TRACE to avoid > > performance issues with kmalloc. > > - New structs and functions for managing memory and unique coverage data. > > - Example program demonstrating the usage of the new modes. > > This should be a patch series, carefully splitting each change into a > separate patch. > https://docs.kernel.org/process/submitting-patches.html#split-changes Done in `20250114-kcov-v1-0-004294b931a2@quicinc.com` > > > With the new hashmap and pre-alloced memory pool added, cover size can't > > be set to higher value like 1MB in KCOV_TRACE_PC or KCOV_TRACE_CMP modes > > in 2GB device with 8 procs, otherwise it causes frequent oom. > > > > For KCOV_TRACE_UNIQ_[PC|EDGE|CMP] modes, smaller cover size like 8KB can > > be used. > > > > Signed-off-by: Jiao, Joey > > As-is it's hard to review, and the motivation is unclear. A lot of > code was moved and changed, and reviewers need to understand why that > was done besides your brief explanation above. > > Generally, KCOV has very tricky constraints, due to being callable > from any context, including NMI. This means adding new dependencies > need to be carefully reviewed. For one, we can see this in genalloc's > header: > > > * The lockless operation only works if there is enough memory > > * available. If new memory is added to the pool a lock has to be > > * still taken. So any user relying on locklessness has to ensure > > * that sufficient memory is preallocated. > > * > > * The basic atomic operation of this allocator is cmpxchg on long. > > * On architectures that don't have NMI-safe cmpxchg implementation, > > * the allocator can NOT be used in NMI handler. So code uses the > > * allocator in NMI handler should depend on > > * CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG. > > And you are calling gen_pool_alloc() from __sanitizer_cov_trace_pc. > Which means this implementation is likely broken on > !CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG architectures (do we have > architectures like that, that support KCOV?). > > There are probably other sharp corners due to the contexts KCOV can > run in, but would simply ask you to carefully reason about why each > new dependency is safe. Need to investigate more on CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG.