From nobody Wed Oct 8 20:02:01 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 E2DAB2690D9; Wed, 25 Jun 2025 12:51:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750855897; cv=none; b=FlK8S5EPf7X7iEH8MO3Mzya7wyez21mZxpGIQyMR4HSs0llANdxix7fT1VJYZVDuC1fJriRTAEAZmiq0ljhvjwL+xNBlv5ZkyIb/bUEVjp8j8sgK/7GNAKZUOi6DPQXxWSTK6VfV/MlCRbE/8WnMWm0KiyFUlHzZuJsaQA+yDwk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750855897; c=relaxed/simple; bh=JBGJGaeeS2Xh+9NuK95zkFteMkIrn0EoxQT+TmlJxJw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cONbAwR20mwaYe440PvVGBVg4/enyGIm4HohIYTdDW3ybquT4ZH02WfV65+ODrW+v/d1ZwPkUlJfqkmYgG0cQA4YKP50eIVpBThoHyl4QQZXYKi/3mthRgwk3djR+vW4L/K4InWNTv5BhTDwiktSUf5+xrCID5zPPOqfItt9c8o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.helo=mgamail.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=OGf3flOo; arc=none smtp.client-ip=192.198.163.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.helo=mgamail.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="OGf3flOo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750855895; x=1782391895; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JBGJGaeeS2Xh+9NuK95zkFteMkIrn0EoxQT+TmlJxJw=; b=OGf3flOotByhWvHsaA8W7eaCA+31beF3DtQOXdxZKJqOTSj+qSHYX6rD PWTCY5IMRcIo+INV8wzrw32Gf+xxMIEzQroysKAT6LjoCmLvgIi9D/LSb IKpUw/u48pTApceYKj/p13ECL6eUrCRwqS1jQXWZ+3UKB5IVaFhw3oQN4 wdVbX365cV9sWb/eFnikkvbZ2tRUVG5mBSxHoLPpObBbOZX8fXysiieHF /c0WAb1mDDjZ54t9WG8jeGmVmlMXuBlM+W2STY9IGx4Aqrd4Uh7SV5ots VihYJMtfCCWfZ/WiKaOGeuBBgsskoSKLxShnzbsJ+R1tHVM1cb/vIY9zX A==; X-CSE-ConnectionGUID: oXDHpOEjTjqzuPqI1fHiNA== X-CSE-MsgGUID: /KDpINrSTseSrU8KIHmcmQ== X-IronPort-AV: E=McAfee;i="6800,10657,11474"; a="53189653" X-IronPort-AV: E=Sophos;i="6.16,264,1744095600"; d="scan'208";a="53189653" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2025 05:51:34 -0700 X-CSE-ConnectionGUID: L1tUn7Q9TjGwT50+hm6f4g== X-CSE-MsgGUID: 3EBtIhOgQVmo93lCwbOuXQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,264,1744095600"; d="scan'208";a="151830982" Received: from black.fi.intel.com ([10.237.72.28]) by fmviesa007.fm.intel.com with ESMTP; 25 Jun 2025 05:51:23 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 26D4F79C; Wed, 25 Jun 2025 15:51:13 +0300 (EEST) From: "Kirill A. Shutemov" To: Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Peter Zijlstra , Ard Biesheuvel , "Paul E. McKenney" , Josh Poimboeuf , Xiongwei Song , Xin Li , "Mike Rapoport (IBM)" , Brijesh Singh , Michael Roth , Tony Luck , Alexey Kardashevskiy , Alexander Shishkin Cc: Jonathan Corbet , Sohil Mehta , Ingo Molnar , Pawan Gupta , Daniel Sneddon , Kai Huang , Sandipan Das , Breno Leitao , Rick Edgecombe , Alexei Starovoitov , Hou Tao , Juergen Gross , Vegard Nossum , Kees Cook , Eric Biggers , Jason Gunthorpe , "Masami Hiramatsu (Google)" , Andrew Morton , Luis Chamberlain , Yuntao Wang , Rasmus Villemoes , Christophe Leroy , Tejun Heo , Changbin Du , Huang Shijie , Geert Uytterhoeven , Namhyung Kim , Arnaldo Carvalho de Melo , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, linux-mm@kvack.org, "Kirill A. Shutemov" Subject: [PATCHv7 13/16] x86/traps: Handle LASS thrown #SS Date: Wed, 25 Jun 2025 15:51:06 +0300 Message-ID: <20250625125112.3943745-15-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250625125112.3943745-1-kirill.shutemov@linux.intel.com> References: <20250625125112.3943745-1-kirill.shutemov@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" LASS throws a #GP for any violations except for stack register accesses, in which case it throws a #SS instead. Handle this similarly to how other LASS violations are handled. In case of FRED, before handling #SS as LASS violation, kernel has to check if there's a fixup for the exception. It can address #SS due to invalid user context on ERETU[1]. See 5105e7687ad3 ("x86/fred: Fixup fault on ERETU by jumping to fred_entrypoint_user") for more details. Co-developed-by: Alexander Shishkin Signed-off-by: Alexander Shishkin Signed-off-by: Kirill A. Shutemov Reviewed-by: Xin Li (Intel) --- arch/x86/kernel/traps.c | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index e2ad760b17ea..f1f92e1ba524 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -418,12 +418,6 @@ DEFINE_IDTENTRY_ERRORCODE(exc_segment_not_present) SIGBUS, 0, NULL); } =20 -DEFINE_IDTENTRY_ERRORCODE(exc_stack_segment) -{ - do_error_trap(regs, error_code, "stack segment", X86_TRAP_SS, SIGBUS, - 0, NULL); -} - DEFINE_IDTENTRY_ERRORCODE(exc_alignment_check) { char *str =3D "alignment check"; @@ -866,6 +860,39 @@ DEFINE_IDTENTRY_ERRORCODE(exc_general_protection) cond_local_irq_disable(regs); } =20 +#define SSFSTR "stack segment fault" + +DEFINE_IDTENTRY_ERRORCODE(exc_stack_segment) +{ + if (user_mode(regs)) + goto error_trap; + + if (cpu_feature_enabled(X86_FEATURE_FRED) && + fixup_exception(regs, X86_TRAP_SS, error_code, 0)) + return; + + if (cpu_feature_enabled(X86_FEATURE_LASS)) { + enum kernel_gp_hint hint; + unsigned long gp_addr; + + hint =3D get_kernel_gp_address(regs, &gp_addr); + if (hint !=3D GP_NO_HINT) { + printk(SSFSTR ", %s 0x%lx", kernel_gp_hint_help[hint], + gp_addr); + } + + if (hint !=3D GP_NON_CANONICAL) + gp_addr =3D 0; + + die_addr(SSFSTR, regs, error_code, gp_addr); + return; + } + +error_trap: + do_error_trap(regs, error_code, "stack segment", X86_TRAP_SS, SIGBUS, + 0, NULL); +} + static bool do_int3(struct pt_regs *regs) { int res; --=20 2.47.2