Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1922920rdb; Wed, 31 Jan 2024 13:22:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IFUcZMEogAjyXOS8CQZx1odGN4Qd+nPhaDUjxOP8rU4uiCLyd1fdNTYg0We1CnDi5EQY0ua X-Received: by 2002:a17:903:41cc:b0:1d9:119e:af44 with SMTP id u12-20020a17090341cc00b001d9119eaf44mr2788831ple.12.1706736143523; Wed, 31 Jan 2024 13:22:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706736143; cv=pass; d=google.com; s=arc-20160816; b=PJcLdOLxwebnQX+U8xvpNNKOd9slO/DB8l0lT7OTllIFUDkqmIUU236KBdkFl6xNgr Joigk8w9S+nboHdIFZLHpsF9XFsp/MYAo/Y9tHCX9c+iXGNKf5w60dYj45RDjUbxQfgU VzLQzrWXj56PaLyUzMFMfz6mpA7/d5R8iAzBnE9OQ/7ZO/jUxFu0emwoBSArAZu6HkkW PXO65UYMf9AgKFt8mLj4mI5giIngtvsDe3XBSI22prcVC4bADKMZTl16l1gO/kcAJz6X bOS9LaE1/jFtX9yzAz5+xPSnbGWPc42RUiPoqEZkgJeuBFAZylRs+Zu/ObTAMUh87165 +b5A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=tAc/BpUlP6JWj2PO2N6/n4mFJ6+KExcnIVmTPNc0ooQ=; fh=3GX/DPIIKGuvprCHxNjcWWiA0gtZ0vtF7rDsFn1VOpM=; b=ZLi6gXJkY7hVrH9wP3vMJQveRqr61iy0jP82SExH40laqLKEn4ehHoHAJP6t2aq1A/ LT8mIxW62c19hnUuMNgn1kt1//XuYGi/x3m40gef5rDCCl7mrbRQiMb+q1IRgd8k4vGT XB16bAyTMaCJBhk8oRIWTsj//RBOARkuANEfHO97evBG4bxPk+EvNyjoLZ+BHg/JWj3S I/6p01lhHrEkcVKMndyASwSlkvRBPDbwUScPUX7UNrGTkihhW6KTPIQbdkP+caYOK+LK WGwulL2P6HDlJXRXSxhCD1XVFe1PejeNf2NXC8dDI2WMwa3LMOXYvhvbiiNDoF7futHQ RT8Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=dWffANnj; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-47132-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47132-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de X-Forwarded-Encrypted: i=1; AJvYcCUTOvbVo2k/8tirSXqJYb1Ay7LQXM5QvPEtJk+e7okBu7eok/f/HOiCkPsQHC2DrLlVj3cBdiQhbEqwCLTaiW7fipJ4/ZCKmsOYU7ecyA== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id m11-20020a1709026bcb00b001d904d7c449si4302976plt.271.2024.01.31.13.22.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 13:22:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47132-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=dWffANnj; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-47132-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47132-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de 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 9621FB26D96 for ; Wed, 31 Jan 2024 21:18:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D5D363C6AB; Wed, 31 Jan 2024 21:14:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="dWffANnj"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Aqk0lW1T" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 4997B3A8F7; Wed, 31 Jan 2024 21:14:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706735692; cv=none; b=O6I47rM7+SGsBEW4wBeqS6JKiCM+G5a0ygw21O2i3Gj4ofVPdYqsuSyLC3x16PIb9Rn3E3eztKCrPPce3FJRZzRe/HmL6637t7PD7xGGPncVxN3grTuGnIT/PTqh2bFZ76SQ/+LnPucrOUdODePw9A+BMqk4ZImg71ntDw54g50= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706735692; c=relaxed/simple; bh=U5IgXWowfrjTzYoY/QLY47QukxAnN7ONoB7mMgK1hJA=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=g8v7r5qkHXnQU7wtg6khzdb+nvH//WQj+2iL2erQFsAEcf4fphtpA542Fk6xv+d9suKjkcxOf0aftDwahSMMU8mdhuxrq2ia8RqeuGgJ7+boBWZaBwLWZLKfkOg0JpxA7FTwWPNZfa7AoO/GufWNDunJoWaTlgkUvPKnik3H5Is= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=dWffANnj; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Aqk0lW1T; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Wed, 31 Jan 2024 21:14:48 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706735688; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tAc/BpUlP6JWj2PO2N6/n4mFJ6+KExcnIVmTPNc0ooQ=; b=dWffANnjspD1MAxbR6qm6sVXVEm2wwtOs9ItyA4+VJfzpELwB93jQPBsL2rzd9fcgeq0vu EGJ2boFGiwU7cDyuz+kSDZodu2wRx8LTD3zmW/76papWfHVIm6FUvvZayeSvihfMt6Al6t 7dzbjmcOTzKu60UMNkO//Cy5YlivvumEJ9RMjcC4xClUUHPSAm5QQx4R37NxXCFvpuJRAL 1X/cVKpgkdGBX6FHHBMCfvrmWybkwsZtWlKmdww63KrC1JPuJOpdWBv0bBxei9z8wddSYs inEUbKQbJt7RboX+cmClxfEekSMfq90q+7rNML1GWbHmta8j1nBNX3C5t3Gg8Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706735688; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tAc/BpUlP6JWj2PO2N6/n4mFJ6+KExcnIVmTPNc0ooQ=; b=Aqk0lW1TD8149uv5wJW7llpd/RF6BOeg5sruZchpuyJyTxzkFVa5Y5EwpHFN+AVpGfV/np zza03tpU8wwNwJAQ== From: "tip-bot2 for H. Peter Anvin (Intel)" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/fred] x86/fred: Allow single-step trap and NMI when starting a new task Cc: "H. Peter Anvin (Intel)" , Xin Li , Thomas Gleixner , "Borislav Petkov (AMD)" , Shan Kang , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231205105030.8698-21-xin3.li@intel.com> References: <20231205105030.8698-21-xin3.li@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <170673568812.398.17348163499438310254.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit The following commit has been merged into the x86/fred branch of tip: Commit-ID: ad41a14cc2d66229479d73e4a7dc1fda26827666 Gitweb: https://git.kernel.org/tip/ad41a14cc2d66229479d73e4a7dc1fda26827666 Author: H. Peter Anvin (Intel) AuthorDate: Tue, 05 Dec 2023 02:50:09 -08:00 Committer: Borislav Petkov (AMD) CommitterDate: Wed, 31 Jan 2024 22:02:00 +01:00 x86/fred: Allow single-step trap and NMI when starting a new task Entering a new task is logically speaking a return from a system call (exec, fork, clone, etc.). As such, if ptrace enables single stepping a single step exception should be allowed to trigger immediately upon entering user space. This is not optional. NMI should *never* be disabled in user space. As such, this is an optional, opportunistic way to catch errors. Allow single-step trap and NMI when starting a new task, thus once the new task enters user space, single-step trap and NMI are both enabled immediately. Signed-off-by: H. Peter Anvin (Intel) Signed-off-by: Xin Li Signed-off-by: Thomas Gleixner Signed-off-by: Borislav Petkov (AMD) Tested-by: Shan Kang Link: https://lore.kernel.org/r/20231205105030.8698-21-xin3.li@intel.com --- arch/x86/kernel/process_64.c | 38 +++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index 4f87f59..c075591 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -56,6 +56,7 @@ #include #include #include +#include #ifdef CONFIG_IA32_EMULATION /* Not included via unistd.h */ #include @@ -528,7 +529,7 @@ void x86_gsbase_write_task(struct task_struct *task, unsigned long gsbase) static void start_thread_common(struct pt_regs *regs, unsigned long new_ip, unsigned long new_sp, - unsigned int _cs, unsigned int _ss, unsigned int _ds) + u16 _cs, u16 _ss, u16 _ds) { WARN_ON_ONCE(regs != current_pt_regs()); @@ -545,11 +546,36 @@ start_thread_common(struct pt_regs *regs, unsigned long new_ip, loadsegment(ds, _ds); load_gs_index(0); - regs->ip = new_ip; - regs->sp = new_sp; - regs->cs = _cs; - regs->ss = _ss; - regs->flags = X86_EFLAGS_IF; + regs->ip = new_ip; + regs->sp = new_sp; + regs->csx = _cs; + regs->ssx = _ss; + /* + * Allow single-step trap and NMI when starting a new task, thus + * once the new task enters user space, single-step trap and NMI + * are both enabled immediately. + * + * Entering a new task is logically speaking a return from a + * system call (exec, fork, clone, etc.). As such, if ptrace + * enables single stepping a single step exception should be + * allowed to trigger immediately upon entering user space. + * This is not optional. + * + * NMI should *never* be disabled in user space. As such, this + * is an optional, opportunistic way to catch errors. + * + * Paranoia: High-order 48 bits above the lowest 16 bit SS are + * discarded by the legacy IRET instruction on all Intel, AMD, + * and Cyrix/Centaur/VIA CPUs, thus can be set unconditionally, + * even when FRED is not enabled. But we choose the safer side + * to use these bits only when FRED is enabled. + */ + if (cpu_feature_enabled(X86_FEATURE_FRED)) { + regs->fred_ss.swevent = true; + regs->fred_ss.nmi = true; + } + + regs->flags = X86_EFLAGS_IF | X86_EFLAGS_FIXED; } void