From patchwork Mon Jul 22 20:25:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 13739082 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 73770C3DA5D for ; Mon, 22 Jul 2024 20:25:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EA0D26B0085; Mon, 22 Jul 2024 16:25:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E504F6B0088; Mon, 22 Jul 2024 16:25:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D17DD6B0089; Mon, 22 Jul 2024 16:25:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id B415E6B0085 for ; Mon, 22 Jul 2024 16:25:15 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 72152161988 for ; Mon, 22 Jul 2024 20:25:15 +0000 (UTC) X-FDA: 82368518190.25.71A8F40 Received: from out-182.mta1.migadu.com (out-182.mta1.migadu.com [95.215.58.182]) by imf05.hostedemail.com (Postfix) with ESMTP id 00545100020 for ; Mon, 22 Jul 2024 20:25:11 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=IOi5c60b; spf=pass (imf05.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.182 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721679866; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=8/k2ZwHfUaSJhfPH5Zkk+TCGlgAiYiwAht3Bf0GZAMY=; b=aQNnsQzE5FV1mkvq9/NbT7i6mNd3pyiFAV1HzdQrl4f+ujWqSX/uLQLobvPc6TGsblgzkc 1WAOy9Zn7z4wmmkJ9hRG8qTx1HczwHV9G5rPt4myDXOvSEZCIcA+cQaiIvwHYBTdRCIt7Q HeyZW9kgWefn+EImqWqALIYqyTPhNnI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721679866; a=rsa-sha256; cv=none; b=zShhSygtRUpQ3ZEi7hA3ZmdMNVu6UvI5Pw7fTlN7PDrVE5eogKQrqlJfIoLFbM3ZHgN6GC XfYOXuUOWKKAgjdoA+ZZNONUCpucE/IMlJDZGYwc9h0qEWi/cNOT6rAMlITfVuAxsWFj3+ XzLcQPN2rHmoS3ZkBvsgZ0ZDLoYN04c= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=IOi5c60b; spf=pass (imf05.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.182 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Envelope-To: dvyukov@google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1721679910; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=8/k2ZwHfUaSJhfPH5Zkk+TCGlgAiYiwAht3Bf0GZAMY=; b=IOi5c60blghNxdAKiJv2T7ykwod346m3RprJaQT200nmUaMO4fYCJO3KbwAVxgZju4yFwQ Xo0d3AKE6QGLODNleLlLwNTUUgXZKXqVwsR2n7u1aGNNeZQ8qd4gqD2pjLGnpiVu4+Mi9Q MYJqmuNWVxP3QuLnvrCFTSQPipqGDcQ= X-Envelope-To: akpm@linux-foundation.org X-Envelope-To: andreyknvl@gmail.com X-Envelope-To: nogikh@google.com X-Envelope-To: elver@google.com X-Envelope-To: glider@google.com X-Envelope-To: kasan-dev@googlegroups.com X-Envelope-To: linux-mm@kvack.org X-Envelope-To: tglx@linutronix.de X-Envelope-To: mingo@redhat.com X-Envelope-To: bp@alien8.de X-Envelope-To: dave.hansen@linux.intel.com X-Envelope-To: x86@kernel.org X-Envelope-To: linux-kernel@vger.kernel.org X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: andrey.konovalov@linux.dev To: Dmitry Vyukov , Andrew Morton Cc: Andrey Konovalov , Aleksandr Nogikh , Marco Elver , Alexander Potapenko , kasan-dev@googlegroups.com, linux-mm@kvack.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] x86, kcov: ignore stack trace coverage Date: Mon, 22 Jul 2024 22:25:02 +0200 Message-Id: <20240722202502.70301-1-andrey.konovalov@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Stat-Signature: ykci5dmosxuzewk8dbhohmrti7arcer4 X-Rspamd-Queue-Id: 00545100020 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1721679911-561098 X-HE-Meta: U2FsdGVkX1/rT5AlXDwFJQlnlUnpMxTABNPYXbSMYJ7/fGgRbitGslAGC/mhEN0CCr8OOp5xoa0HnI1E0/J2HcGPvZ8KQwC7ka+3oSpGT+DI2MmtptwGFkBz6R7aX9F7EFESme2hvssGxlHA+Vkpz/9D7SAS2495Teq8i/u79tBwad7gxu783R+E4MuCxr1q58pWnUKECTPfHmaDi0qP090igO/wsg5D2WQBlUqy1KzcZrZ8bRPwBhWe01WdzhnJr47UpNZQfuVAvMjKe3l2L8Z1E7PwmA0lhMp1lttucF3pVrbKXLo1fQPTmFp7uUOxo+DBHSmMTo/PjEiDEojyZG8Tct3nysvU3Jsrv69o+oQMMQPert7BigT0T2cr5i7RocaRzUQ1jQZH/9zHpX6IjFU8eHy6eDEnysfxpodzf2ohcW+zR0EpbmuynJVWs5hNJ4IAAKolbqvZpZJpAix/2Exmt70XpkwPvt1ChJr/QU1KeSRUyyStuHC+ZT2TJvQLBXK0nUPEHGzGHo4b5P45bze7OzdkDfw5Jlu7eNE3GL+72T77Ri+7+e9rqvGQzwupQOfKPALAhW44+mHklbztNHHbTCh/vql0mtrrHA1n+gcAEeU4TelV99VNqRMVLaT4MExfZTVI6Vy+Z83bt3LwiygOognbWxspG8VkrtQ1GEf+hdxS4xVUSypxJ5RGIaAl5m4eURBi2vfoEtL8vt5TGKGyo0yrBvNKTOkeho6JFEdo3ClgevURhZltKJFKDC1bLx2gRBy3I19ipcib019ZoQcx8b1/KM2tYgrVpYVgCCXakWKR9HRsq2p4eB2J8MIu3eEjmYd4ITNvAfgPDeE26fGyM0V9dELJyfZ1c4w9qh0YukGqJb4TsGZar00vN+APm3o1HOONSfNcV7Rkw++QhECwxIGewI+oyNAkinyuFXFzG1JgrLS6MoSuiIymtYtIlXndoYCdd1cLWp9es6i X3DD62Ym BPCwBXpL8TxYsDK5DQ4TRln5cRcIZe0b/r+hhj5q726EAQatqJo1hQEbi4cBVxtpGGwTLpiIlsJW1NxFMGO3A+uXxnJgoY5Ijxb1KeKoBeV2ZezMaCmi/va0eq2bJNjr4XJp822D9fRwoxjM= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Andrey Konovalov When a multitude of kernel debugging options are enabled, they often collect and save the current stack trace. The coverage produced by the related routines is not relevant for the KCOV's intended use case (guiding the fuzzing process). Thus, disable instrumentation of the x86 stack trace collection code. KCOV instrumentaion of the generic kernel/stacktrace.c was already disabled in commit 43e76af85fa7 ("kcov: ignore fault-inject and stacktrace"). This patch is an x86-specific addition. In addition to freeing up the KCOV buffer capacity for holding more relevant coverage, this patch also speeds up the kernel boot time with the config from the syzbot USB fuzzing instance by ~25%. Fixes: 43e76af85fa7 ("kcov: ignore fault-inject and stacktrace") Signed-off-by: Andrey Konovalov --- I'm not sure whether it makes sense to backport this patch to stable kernels, but I do think that it makes sense to take it into mainline as a fix: currently, the USB fuzzing instance is choking on the amount of coverage produced by KCOV and thus doesn't perform well. For reference, without this patch, for the following program: r0 = syz_usb_connect_ath9k(0x3, 0x5a, &(0x7f0000000080)={{0x12, 0x1, 0x200, 0xff, 0xff, 0xff, 0x40, 0xcf3, 0x9271, 0x108, 0x1, 0x2, 0x3, 0x1, [{{0x9, 0x2, 0x48, 0x1, 0x1, 0x0, 0x80, 0xfa, {{0x9, 0x4, 0x0, 0x0, 0x6, 0xff, 0x0, 0x0, 0x0, "", {{0x9, 0x5, 0x1, 0x2, 0x200, 0x0, 0x0, 0x0, ""}, {0x9, 0x5, 0x82, 0x2, 0x200, 0x0, 0x0, 0x0, ""}, {0x9, 0x5, 0x83, 0x3, 0x40, 0x1, 0x0, 0x0, ""}, {0x9, 0x5, 0x4, 0x3, 0x40, 0x1, 0x0, 0x0, ""}, {0x9, 0x5, 0x5, 0x2, 0x200, 0x0, 0x0, 0x0, ""}, {0x9, 0x5, 0x6, 0x2, 0x200, 0x0, 0x0, 0x0, ""}}}}}}]}}, 0x0) KCOV produces ~500k coverage entries. Here are the top ones sorted by the number of occurrences: 23027 /home/user/src/arch/x86/kernel/unwind_orc.c:99 17335 /home/user/src/arch/x86/kernel/unwind_orc.c:100 16460 /home/user/src/arch/x86/include/asm/stacktrace.h:60 (discriminator 3) 16460 /home/user/src/arch/x86/include/asm/stacktrace.h:60 16191 /home/user/src/security/tomoyo/domain.c:183 (discriminator 1) 16128 /home/user/src/security/tomoyo/domain.c:184 (discriminator 8) 11384 /home/user/src/arch/x86/kernel/unwind_orc.c:109 11155 /home/user/src/arch/x86/include/asm/stacktrace.h:59 10997 /home/user/src/arch/x86/kernel/unwind_orc.c:665 10768 /home/user/src/include/asm-generic/rwonce.h:67 9994 /home/user/src/arch/x86/kernel/unwind_orc.c:390 9994 /home/user/src/arch/x86/kernel/unwind_orc.c:389 ... With this patch, the number of entries drops to ~140k. (For reference, here are the top entries with this patch applied: 16191 /home/user/src/security/tomoyo/domain.c:183 (discriminator 1) 16128 /home/user/src/security/tomoyo/domain.c:184 (discriminator 8) 3528 /home/user/src/security/tomoyo/domain.c:173 (discriminator 2) 3528 /home/user/src/security/tomoyo/domain.c:173 3528 /home/user/src/security/tomoyo/domain.c:171 (discriminator 5) 2877 /home/user/src/lib/vsprintf.c:646 2672 /home/user/src/lib/vsprintf.c:651 2672 /home/user/src/lib/vsprintf.c:649 2230 /home/user/src/lib/vsprintf.c:2559 ... I'm not sure why tomoyo produces such a large number of entries, but that will require a separate fix anyway if it's unintended.) --- arch/x86/kernel/Makefile | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index 20a0dd51700a..241e21723fa5 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile @@ -40,6 +40,14 @@ KMSAN_SANITIZE_sev.o := n KCOV_INSTRUMENT_head$(BITS).o := n KCOV_INSTRUMENT_sev.o := n +# These produce large amounts of uninteresting coverage. +KCOV_INSTRUMENT_dumpstack.o := n +KCOV_INSTRUMENT_dumpstack_$(BITS).o := n +KCOV_INSTRUMENT_stacktrace.o := n +KCOV_INSTRUMENT_unwind_orc.o := n +KCOV_INSTRUMENT_unwind_frame.o := n +KCOV_INSTRUMENT_unwind_guess.o := n + CFLAGS_irq.o := -I $(src)/../include/asm/trace obj-y += head_$(BITS).o