Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 29F784028D9; Tue, 21 Jul 2026 17:22:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784654524; cv=none; b=H2crl4RUKbphPF0VpsN5zx8vaqV0kyoNKnuHZ8r0divRfze+PromTyufk0Sc7LmbGBqUuxX4qRhnl3wRzB3UG2VXn/piNvehQ7tbQqFwKvM1fkUW4e0FJK1ppHaNNxR4pafYopyn5DZ0hhjyP5/2E6E3ItHU4sAwDATJn/Jh4S8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784654524; c=relaxed/simple; bh=dRet471CatRlgx0WTVBjAPOXMtVV1uX+oSJsXrRUJ9o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JOO6Od8ioFw45OHPgSXQ0tJVZQg9P8XisbOscRo8t49IBGT5C51yfP9kioCygZZeUjruRmKlR6cu4Mp9Xz8zB975iTekhWsEAGvA95l3LjNCcxa38rx2bDFlJkHn8bk6UlyFg0FE/iLdVSgpmGstEr+FoY8smS7vAP9eKuXbKGQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=WdLt1JFE; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="WdLt1JFE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C64C1F000E9; Tue, 21 Jul 2026 17:22:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784654523; bh=5DwS6ZVroDiM3GDDiVJMeGSkZkKFu6UTCokpvb+YLKY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=WdLt1JFEfrKkMCLN1QcV37nWau+uf6AZbMAxpyQew8pgiNTGz6FwYbDi0ylO/piCt z7YbKjAmOBuy0H4ZvcEfIXbyi1ZgZxcenRvlZtegB8mzSFzR2YXh6UYN9NtVuz4Yiv HXJLfqB8t+wjM04/JHFU3lnLtxouMOvsu4DlL9Gs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Karl Mehltretter , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Kees Cook , Marco Elver , Peter Zijlstra , Andrew Morton Subject: [PATCH 7.1 1736/2077] kcov: use WRITE_ONCE() for selftest mode stores Date: Tue, 21 Jul 2026 17:23:29 +0200 Message-ID: <20260721152633.695528802@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152552.646164743@linuxfoundation.org> References: <20260721152552.646164743@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Karl Mehltretter commit 9a79524d1420e6b79a6868208c264f4518d1318e upstream. The KCOV selftest enables coverage by setting current->kcov_mode to KCOV_MODE_TRACE_PC without installing a coverage area. If an interrupt records coverage in that window, the access should fault and expose the bug. When building for QEMU raspi0 (Raspberry Pi Zero, ARMv6, CONFIG_CPU_V6K=y, CONFIG_CURRENT_POINTER_IN_TPIDRURO=y) with GCC 13.3.0, the store that enables the mode is removed. The generated kcov_init() code only stores zero after the wait loop: mrc 15, 0, r3, cr13, cr0, {3} str r4, [r3, #2028] where r4 is zero. There is no store of KCOV_MODE_TRACE_PC before the loop, so the selftest reports success without exercising coverage. Use WRITE_ONCE() for the temporary mode stores. With the same compiler and config, kcov_init() contains the intended mode store: mov r3, #2 mrc 15, 0, r2, cr13, cr0, {3} str r3, [r2, #2028] Now that the KCOV selftest is actually executed, it may expose KCOV instrumentation issues depending on the kernel config. That is expected for a selftest that was intended to catch coverage from interrupt paths. Link: https://lore.kernel.org/20260526114715.38280-1-kmehltretter@gmail.com Fixes: 6cd0dd934b03 ("kcov: Add interrupt handling self test") Assisted-by: Codex:gpt-5 Signed-off-by: Karl Mehltretter Reviewed-by: Alexander Potapenko Cc: Andrey Konovalov Cc: Dmitry Vyukov Cc: Kees Cook Cc: Marco Elver Cc: Peter Zijlstra Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- kernel/kcov.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/kernel/kcov.c +++ b/kernel/kcov.c @@ -1109,10 +1109,10 @@ static void __init selftest(void) * potentially traced functions in this region. */ start = jiffies; - current->kcov_mode = KCOV_MODE_TRACE_PC; + WRITE_ONCE(current->kcov_mode, KCOV_MODE_TRACE_PC); while ((jiffies - start) * MSEC_PER_SEC / HZ < 300) ; - current->kcov_mode = 0; + WRITE_ONCE(current->kcov_mode, 0); pr_err("done running self test\n"); } #endif