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 C2C63412C05; Fri, 7 Aug 2026 14:58:55 +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=1786114737; cv=none; b=OgGdjoqVORKI0vzglbOrPQmsQTkDHJAnSU4xhR7dbFzQJveIZd4Vr1qDIQntvBvzOtSjCZvlrpardcOI+zCwruPYkJBGXnw68hk0Nbfw+w+5vMJc0Dn4+sgIGUGS1pdnQtzB8rIj57/jKmoVB5/UdbPfHxseyvOIn1CF0N0yWCU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786114737; c=relaxed/simple; bh=2cceA43Bvcs90RuHdzA+hzc2nUGRRKBcDkCKCMVZNnI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WveIWqupYupnKD95zNWlR/e8rMvtF0/kSstEqpOW3Hxm5r0IBRiw/4kxcsZR7KDcPal84u5jeWsUm87JpFN8dE2P4hdIAc7LRElaKdvEKm+KN41lesYmdeTPHit+zMJ9doUINlQOAKs5r+51gJlLoPDHaKACtf0hQy3wcOFBnR0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Qx3XVMsh; 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="Qx3XVMsh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2A0B41F00A3A; Fri, 7 Aug 2026 14:58:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1786114735; bh=Yu5JQYF+siK4yJD95lKaho3BGQ4cK+c5+3GhWzZLgaw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Qx3XVMshMMJDsVI99zEaRIiZbdOw7l0lo/47cMeTdlW7UUx9ur9hrjQDgbsKKrQbU 5aVqs8p9j8B7lKMPP0LHb6GNCXdeYtbHzGgcLNWfT+/A+QunS5+o/iRf8bws34NBHB LcyYT+Mrg4pOvuS38EqQFFXfIZYnDkNgX2w6n/zE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Andy Shevchenko , David Gow , Shuah Khan , Sasha Levin Subject: [PATCH 6.18 003/396] kunit: tool: Terminate kernel under test on SIGINT Date: Fri, 7 Aug 2026 16:32:43 +0200 Message-ID: <20260807143424.348751824@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260807143424.272339768@linuxfoundation.org> References: <20260807143424.272339768@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 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: David Gow [ Upstream commit 8f260b02eeeffbf2263c2b82b6e3e32fd73cde2b ] kunit.py will attempt to catch SIGINT / ^C in order to ensure the TTY isn't messed up, but never actually attempts to terminate the running kernel (be it UML or QEMU). This can lead to a bit of frustration if the kernel has crashed or hung. Terminate the kernel process in the signal handler, if it's running. This requires plumbing through the process handle in a few more places (and having some checks to see if the kernel is still running in places where it may have already been killed). Reported-by: Andy Shevchenko Closes: https://lore.kernel.org/all/aaFmiAmg9S18EANA@smile.fi.intel.com/ Signed-off-by: David Gow Reviewed-by: Andy Shevchenko Tested-by: Andy Shevchenko Signed-off-by: Shuah Khan Signed-off-by: Sasha Levin --- tools/testing/kunit/kunit_kernel.py | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/tools/testing/kunit/kunit_kernel.py b/tools/testing/kunit/kunit_kernel.py index b610fcf0715a..2869fcb199ff 100644 --- a/tools/testing/kunit/kunit_kernel.py +++ b/tools/testing/kunit/kunit_kernel.py @@ -16,7 +16,7 @@ import shutil import signal import sys import threading -from typing import Iterator, List, Optional, Tuple +from typing import Iterator, List, Optional, Tuple, Any from types import FrameType import kunit_config @@ -265,6 +265,7 @@ class LinuxSourceTree: if kconfig_add: kconfig = kunit_config.parse_from_string('\n'.join(kconfig_add)) self._kconfig.merge_in_entries(kconfig) + self._process : Optional[subprocess.Popen[Any]] = None def arch(self) -> str: return self._arch @@ -364,36 +365,45 @@ class LinuxSourceTree: args.append('kunit.filter_action=' + filter_action) args.append('kunit.enable=1') - process = self._ops.start(args, build_dir) - assert process.stdout is not None # tell mypy it's set + self._process = self._ops.start(args, build_dir) + assert self._process is not None # tell mypy it's set + assert self._process.stdout is not None # tell mypy it's set # Enforce the timeout in a background thread. def _wait_proc() -> None: try: - process.wait(timeout=timeout) + if self._process: + self._process.wait(timeout=timeout) except Exception as e: print(e) - process.terminate() - process.wait() + if self._process: + self._process.terminate() + self._process.wait() waiter = threading.Thread(target=_wait_proc) waiter.start() output = open(get_outfile_path(build_dir), 'w') try: # Tee the output to the file and to our caller in real time. - for line in process.stdout: + for line in self._process.stdout: output.write(line) yield line # This runs even if our caller doesn't consume every line. finally: # Flush any leftover output to the file - output.write(process.stdout.read()) + if self._process: + if self._process.stdout: + output.write(self._process.stdout.read()) + self._process.stdout.close() + self._process = None output.close() - process.stdout.close() waiter.join() self._restore_terminal_if_tty() def signal_handler(self, unused_sig: int, unused_frame: Optional[FrameType]) -> None: logging.error('Build interruption occurred. Cleaning console.') + if self._process: + self._process.terminate() + self._process.wait() self._restore_terminal_if_tty() -- 2.53.0