From nobody Thu Mar 5 06:30:48 2026 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (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 8506926FA5B for ; Mon, 16 Feb 2026 17:37:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771263452; cv=none; b=KczmPtzh5joFU+LIbd9aL/FO2IXjylqZ4jdCy1DEgoxvC4Nb7NUYNR8/PtYswpLyQojciNDh+W/h7XMAa/e7RR5qfTsrQmx52xseS/awCnqUQJJlLgjNXWlNmnW6OHVRoALJeio/w0+21i5k8d8WTx+Ng2l3MpdoYgnYMVbLglk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771263452; c=relaxed/simple; bh=rQKhB9JdZiNJrrGwmga29AvVsWuvPM0AXufNQXL4yqQ=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=nz6wXlGqRtF3N/JFrHG8eaEO3O796A0/mHNF7Zi+8GOtzkqdOF036ILUz07CMQzX64/hcx+8Ivv3OyCDBvfmentY1F1w0FFRZo+gsGh5Pmyq7ymnAxO0w10OUukazr0rQPPYoAYDj33es16/2vrFzZVCcGA4WP1/RSHLBtoQPuE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--nogikh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=F+4qYhP2; arc=none smtp.client-ip=209.85.128.74 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=flex--nogikh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="F+4qYhP2" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-4836e35292cso28249705e9.1 for ; Mon, 16 Feb 2026 09:37:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1771263449; x=1771868249; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=+CGgBuWMwayfOcIDbZ2XGNgXYWYl77pKODg5gAEKr8g=; b=F+4qYhP2rTemcIf2j6YfrXXrPc89AW2nR97jAWSv3FdZgqxDVSWfLRkPjX3ZLu58bG F9ajPVaRxxWu/VAo0C5EFcAAftAPfbTrzEWjcYIuSMVNMl7Aa8UFWT5W3RUSSTF/4orX jg/XvN2mG1Jfr8DIz+RcqqQSmsSaEYf98SQSG7AFZS8u/mPY+nEK9Xb0NCgoT+3setfj Si5rsMOm+n9ApqWzXMSja9RK2L/ItMrPB8SyJJUhUHbMnqnAWRqqs+5ctBVZC6o/0Vyi +zBtBXBJh0YqelDEZKQ9E/qQolBvnyGVJ+OOE5aEF0hyCSdlU9xMzgabDyJnHZnFYgGF cOiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771263449; x=1771868249; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=+CGgBuWMwayfOcIDbZ2XGNgXYWYl77pKODg5gAEKr8g=; b=d3EHnzObvvoZ7MlRkVE7yVvNqNBpcvzod4OGkTy+w3qE9duQ3+4Ov+Gy66q297jFUM XTTwgaa6EV6xOFX0aloQUmb5OJ7fgfczOXLuwlAvRGJ/ilmSAreWyM1j78hMSVlN4OFj OyHJd0GDY7OKBfzwxNbDDFBPeufXHNAAj30/3F1t4D38zvuI5hULIr5yrZJQh56lktdS yQuk5gPPaacgKUhcgWzxeVgjU0So8CMrB1EyMI0MOfmcZncoK91ersBter/auDa3HDX6 B9Fwwdj5uQHRPJb6nu9PebfOmUR1MFI/wWWit/Cxs47bYcJAp/BsCjsm8PF/RF+4NiQ6 1FNg== X-Forwarded-Encrypted: i=1; AJvYcCVuu1p5j07oMVB27AcBbXzHTVcWGyhYroQquzAITMSirfZeQhgOVp4yUa5BixxvKWR0012s/hR2N95tgGI=@vger.kernel.org X-Gm-Message-State: AOJu0Yxp6fnm2Gt5VbxtjJG4MJBXnP+Z/17B3J6A/yTtz+P4iTLlQjbN b+JRu2v1v47gBVNDwCUNNHgeOPcyr9qQbbIYPyTIHJQXch/pPou2P9Oc7LiROkPJTXuHOf56FqK xAumQMg== X-Received: from wmog12.prod.google.com ([2002:a05:600c:310c:b0:47e:e20e:e9a5]) (user=nogikh job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:c04b:20b0:483:7eea:b185 with SMTP id 5b1f17b1804b1-4837eeab9e2mr101249885e9.16.1771263448876; Mon, 16 Feb 2026 09:37:28 -0800 (PST) Date: Mon, 16 Feb 2026 18:37:16 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.53.0.273.g2a3d683680-goog Message-ID: <20260216173716.2279847-1-nogikh@google.com> Subject: [PATCH] x86/kexec: Disable KCOV instrumentation after load_segments() From: Aleksandr Nogikh To: tglx@kernel.org, mingo@redhat.com, bp@alien8.de Cc: x86@kernel.org, linux-kernel@vger.kernel.org, dvyukov@google.com, kasan-dev@googlegroups.com, Aleksandr Nogikh , stable@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The load_segments() function changes segment registers, invalidating GS base (which KCOV relies on for per-cpu data). When CONFIG_KCOV is enabled, any subsequent instrumented C code call (e.g. native_gdt_invalidate()) begins crashing the kernel in an endless loop. To reproduce the problem, it's sufficient to do kexec on a KCOV-instrumented kernel: $ kexec -l /boot/otherKernel $ kexec -e (additional problems arise when the kernel is booting into a crash kernel) Disabling instrumentation for the individual functions would be too fragile, so let's fix the bug by disabling KCOV instrumentation for the whole machine_kexec_64.c and physaddr.c. The problem is not relevant for 32 bit kernels as CONFIG_KCOV is not supported there. Signed-off-by: Aleksandr Nogikh Cc: stable@vger.kernel.org Reviewed-by: Dmitry Vyukov --- arch/x86/kernel/Makefile | 4 ++++ arch/x86/mm/Makefile | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index e9aeeeafad173..5703fa6027866 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile @@ -43,6 +43,10 @@ KCOV_INSTRUMENT_dumpstack_$(BITS).o :=3D n KCOV_INSTRUMENT_unwind_orc.o :=3D n KCOV_INSTRUMENT_unwind_frame.o :=3D n KCOV_INSTRUMENT_unwind_guess.o :=3D n +# When a kexec kernel is loaded, calling load_segments() breaks all +# subsequent KCOV instrumentation until new kernel takes control. +# Keep KCOV instrumentation disabled to prevent kernel crashes. +KCOV_INSTRUMENT_machine_kexec_64.o :=3D n =20 CFLAGS_head32.o :=3D -fno-stack-protector CFLAGS_head64.o :=3D -fno-stack-protector diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile index 5b9908f13dcfd..a678a38a40266 100644 --- a/arch/x86/mm/Makefile +++ b/arch/x86/mm/Makefile @@ -4,6 +4,10 @@ KCOV_INSTRUMENT_tlb.o :=3D n KCOV_INSTRUMENT_mem_encrypt.o :=3D n KCOV_INSTRUMENT_mem_encrypt_amd.o :=3D n KCOV_INSTRUMENT_pgprot.o :=3D n +# When a kexec kernel is loaded, calling load_segments() breaks all +# subsequent KCOV instrumentation until new kernel takes control. +# Keep KCOV instrumentation disabled to prevent kernel crashes. +KCOV_INSTRUMENT_physaddr.o :=3D n =20 KASAN_SANITIZE_mem_encrypt.o :=3D n KASAN_SANITIZE_mem_encrypt_amd.o :=3D n --=20 2.53.0.273.g2a3d683680-goog