Received: by 2002:ab2:69cc:0:b0:1fd:c486:4f03 with SMTP id n12csp234113lqp; Tue, 11 Jun 2024 02:55:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXmjmyQqWnRaDzmqOmNAehvQP3/pTu2KzplMA7ahqa4UBBXRgh6rVxqBoBvvZsFzUwgTZqRHseBtfYWN93AWNfX2pb53fKRcH8SIhYCKw== X-Google-Smtp-Source: AGHT+IEBCxSPcxfdh44Z9PV6LuokCFdXnvQQ2AYratUhD0CBzSqY7QvSHWNf5a1oJDtHRsYkcpva X-Received: by 2002:a05:6a00:2d09:b0:704:205d:2323 with SMTP id d2e1a72fcca58-704205d3c2bmr10254662b3a.32.1718099751360; Tue, 11 Jun 2024 02:55:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718099751; cv=pass; d=google.com; s=arc-20160816; b=o9p4ZRwMXaSDE0+J/nvqJdCFR2/x2stZkFezobqfpZ4nS3FUJN1AgJhaJQLCIcoJo5 8pX69U/GxDOYV155Q5blfginGsNxok3yJCkAu7a9lWku482yrvgXaYphMT7lH8U/p1Xp XMm6gaWyqqW8TOOGxErQVZhFwWC2K/4zgc4Nk9gYGcXa30zifed2MfTDCTA+Wpr/X/tR obAoeYKOU3K4z3Qb7dXBEeGV9636Yh1FL/TdokAZIq1CHCS4P1HXTimrOb9umBCZywpd N802tULuVJwL7oDghIA5JtPGuMk1Ix3U1sp6xV5Y0s9F3f+AZfXHP8EYUUHz40jCG1r/ 5fxg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=+rt7Mipe8sWYGdIRzG0MkGoo+3Z/PRr0+fx5ZM1nCaw=; fh=YldBIbbYVtl3IJcOtPN7cyJgLzvsh4ExiMFKPtNrS4k=; b=Pk0sxG8/skRK48UtHe4Yzf/ZE0TNfKk33btRRI2NSbY8W/qMtl0dBeLIaenM7IoerW uut3OFbxP6JnjRWN/Bh6Wff8n92uv6XX2KfT8rJaVeED3jnrYL3AmXESZkAMnzfimN3c HN+S8I9G9bhJgoKeB8ffgRNtGhrktWOBvcA56omws+wPJCvWof5W2b77BVjYOZ9ibKDL 4Y+m5LjT6XUZVnlHFxgnipjOsMn04nqn+huz6i9J8zRHI5Sj2+81D+4ketZpOYyK4I6I T9hmQBQ2qhe7QB3Md7TnOAooCUq0MloAIXwzGW/vU//TF1dJyfhwNHpYJYuVqkMoyHdR VVtA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=tURrsmZA; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-209564-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-209564-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id d2e1a72fcca58-703fd3b4076si6577564b3a.127.2024.06.11.02.55.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 02:55:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-209564-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=tURrsmZA; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-209564-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-209564-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 4CBF5B21DE0 for ; Tue, 11 Jun 2024 09:30:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D0ED2176ACE; Tue, 11 Jun 2024 09:29:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="tURrsmZA" Received: from mail-ua1-f45.google.com (mail-ua1-f45.google.com [209.85.222.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 61FA316F8F0 for ; Tue, 11 Jun 2024 09:29:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718098196; cv=none; b=MzBIhZOcIfiwNxILq9iYAT1eqggsBPPRvjJmittMoi/Q1Ea0OO0JMtr5N9l6YJe5gyvdZrxt6faL6Xj5qL4mKFXppXJo2gxxppfSM5JY4tIcTWIehfsoMl69vUwwGqFGZiRs9V4O1fSxtnUo/k13s9jSqo11boidp+5DzYPswYM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718098196; c=relaxed/simple; bh=3Aoz75UnNeUnvxc1QOtRosq9IqKP7sN+gEDcX5YvvgA=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=in6d8CbvJuIlvIFt6kNxg5zEwSlQCDcZdSzEYk/iyqtBtnXm9h8XgnPWJ+g5CLGDi6jzrkVB4F4bOwOmKwU8uyvcjqSLVTo5866PzyRJb4Ykqmsdmczh835fM39iZF2TfRIvqoIjErKrbhRFrjPEUjlXWlOddJJPuQFGsmO+3W4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=tURrsmZA; arc=none smtp.client-ip=209.85.222.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ua1-f45.google.com with SMTP id a1e0cc1a2514c-80acfd81899so248457241.1 for ; Tue, 11 Jun 2024 02:29:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718098194; x=1718702994; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=+rt7Mipe8sWYGdIRzG0MkGoo+3Z/PRr0+fx5ZM1nCaw=; b=tURrsmZAWpKl1eZ+fV2RRmBzCEipcNwupSyOgTb7T3KOgWh1Jdp2VH/CnLC/Hr1oWd jWnPe33+SdptdeqqkebyAe9EqXq+jm8nRqQhscdoxwh4YgCzYJO/H7jHatmCxoBSBX3L 1WI244myU+BrLnvquRqeYtdoHTTNJZm8hJO0MCq3GInu2Qjd/E+6+Ll0O2c0zkIQBAQZ PXDOz6kGnKfqORa3YjktjpFyYey49nxMZoS7tCSs5AEQZ+bi2oVjaeeZYbr4uzDQzcQT ZtkbjFapLBkCWWgKbpENFMUKWgyyuc/Vmr7sCLuoV6MffsCd+H2dCANaFAoFq/zf4Pha ffSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718098194; x=1718702994; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+rt7Mipe8sWYGdIRzG0MkGoo+3Z/PRr0+fx5ZM1nCaw=; b=W4NiCIRh/wzeRXF3DBlaR/moILemxdCjRGzbY601XUsXWTjza8vvXcgp4smS/JBGyI VfZxsYA2dMgQoRmJo20Df+VXvieYR6Fa1DzVCxpT6j6uCm+NhH11ZvIMNiwsbBjggCpm TPbI53owBvdLjLivXIBUihHKe/3CKpaaoRjUHDYGye7Qjuru70EgSMmwC6dwos0KbI2z i2unqXvEDLvIRp7W6EE88aNp/Op96zDlrqbxCCQOBGCL91FBb79Jjfv6nZ7+GUd5A44Y xUGUGOqz42EdQ95gv9PkVid23xzjrbb2l+GNdmC20jciLzrP1Khh17V6VtIRYI/aIkRQ PwaQ== X-Forwarded-Encrypted: i=1; AJvYcCXy6kgNDermsAL58Bp7fmWy/BYzzWRO18DYWM/uBIFL+iXTZaVHKvDFxrkxHUI9Dqk0aN9InxG62mnyl/A0YFGe5VBP8YPK+/XlO/BN X-Gm-Message-State: AOJu0Yw9PmXia2QOh86c2cB9eWlh1n32uKXb8x9nuNPhTc6fyjsUfxre qF/rUziEkfOSzaC/BySsbCpcbi7nLINrqSxkb02EmqWcpwwMBEozhh1fLKx6AU/AEBrmxMAkAJV Zs/BQPBaY3yaFGKyzTwd4/Q6uWDirp5eOCKkz X-Received: by 2002:a05:6102:2373:b0:48c:3ed0:fc1f with SMTP id ada2fe7eead31-48c3ed0fe39mr7197711137.19.1718098194047; Tue, 11 Jun 2024 02:29:54 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <7662127c97e29da1a748ad1c1539dd7b65b737b2.1718092070.git.dvyukov@google.com> In-Reply-To: <7662127c97e29da1a748ad1c1539dd7b65b737b2.1718092070.git.dvyukov@google.com> From: Marco Elver Date: Tue, 11 Jun 2024 11:29:16 +0200 Message-ID: Subject: Re: [PATCH v2 2/4] kcov: add interrupt handling self test To: Dmitry Vyukov Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, syzkaller@googlegroups.com, glider@google.com, nogikh@google.com, tarasmadan@google.com Content-Type: text/plain; charset="UTF-8" On Tue, 11 Jun 2024 at 09:50, Dmitry Vyukov wrote: > > Add a boot self test that can catch sprious coverage from interrupts. > The coverage callback filters out interrupt code, but only after the > handler updates preempt count. Some code periodically leaks out > of that section and leads to spurious coverage. > Add a best-effort (but simple) test that is likely to catch such bugs. > If the test is enabled on CI systems that use KCOV, they should catch > any issues fast. > > Signed-off-by: Dmitry Vyukov > Reviewed-by: Alexander Potapenko > Cc: x86@kernel.org > Cc: linux-kernel@vger.kernel.org > Cc: syzkaller@googlegroups.com Reviewed-by: Marco Elver > --- > > Changed since v1: > - renamed KCOV_TEST to KCOV_SELFTEST > - improved the config description > - loop for exactly 300ms in the test > > In my local testing w/o the previous fix, > it immidiatly produced the following splat: > > kcov: running selftest > BUG: TASK stack guard page was hit at ffffc90000147ff8 > Oops: stack guard page: 0000 [#1] PREEMPT SMP KASAN PTI > ... > kvm_set_cpu_l1tf_flush_l1d+0x5/0x20 > sysvec_call_function+0x15/0xb0 > asm_sysvec_call_function+0x1a/0x20 > kcov_init+0xe4/0x130 > do_one_initcall+0xbc/0x470 > kernel_init_freeable+0x4fc/0x930 > kernel_init+0x1c/0x2b0 > --- > kernel/kcov.c | 31 +++++++++++++++++++++++++++++++ > lib/Kconfig.debug | 8 ++++++++ > 2 files changed, 39 insertions(+) > > diff --git a/kernel/kcov.c b/kernel/kcov.c > index c3124f6d5536..72a5bf55107f 100644 > --- a/kernel/kcov.c > +++ b/kernel/kcov.c > @@ -11,6 +11,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -1057,6 +1058,32 @@ u64 kcov_common_handle(void) > } > EXPORT_SYMBOL(kcov_common_handle); > > +#ifdef CONFIG_KCOV_SELFTEST > +static void __init selftest(void) > +{ > + unsigned long start; > + > + pr_err("running self test\n"); > + /* > + * Test that interrupts don't produce spurious coverage. > + * The coverage callback filters out interrupt code, but only > + * after the handler updates preempt count. Some code periodically > + * leaks out of that section and leads to spurious coverage. > + * It's hard to call the actual interrupt handler directly, > + * so we just loop here for a bit waiting for a timer interrupt. > + * We set kcov_mode to enable tracing, but don't setup the area, > + * so any attempt to trace will crash. Note: we must not call any > + * potentially traced functions in this region. > + */ > + start = jiffies; > + current->kcov_mode = KCOV_MODE_TRACE_PC; > + while ((jiffies - start) * MSEC_PER_SEC / HZ < 300) > + ; > + current->kcov_mode = 0; > + pr_err("done running self test\n"); > +} > +#endif > + > static int __init kcov_init(void) > { > int cpu; > @@ -1076,6 +1103,10 @@ static int __init kcov_init(void) > */ > debugfs_create_file_unsafe("kcov", 0600, NULL, NULL, &kcov_fops); > > +#ifdef CONFIG_KCOV_SELFTEST > + selftest(); > +#endif > + > return 0; > } > > diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug > index 59b6765d86b8..695a437a52d9 100644 > --- a/lib/Kconfig.debug > +++ b/lib/Kconfig.debug > @@ -2171,6 +2171,14 @@ config KCOV_IRQ_AREA_SIZE > soft interrupts. This specifies the size of those areas in the > number of unsigned long words. > > +config KCOV_SELFTEST > + bool "Perform short selftests on boot" > + depends on KCOV > + help > + Run short KCOV coverage collection selftests on boot. > + On test failure, causes the kernel to panic. Recommended to be > + enabled, ensuring critical functionality works as intended. > + > menuconfig RUNTIME_TESTING_MENU > bool "Runtime Testing" > default y > -- > 2.45.2.505.gda0bf45e8d-goog >