Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1493247rdb; Tue, 30 Jan 2024 23:24:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IErVYTY7pEJ151nVdwEW5KkDHPttMFRsU3LlhzHscYt1Asu4+6H+WfeoJwNHm8vZrX+2IGa X-Received: by 2002:a17:90a:fe08:b0:295:e025:1ca1 with SMTP id ck8-20020a17090afe0800b00295e0251ca1mr746100pjb.18.1706685891373; Tue, 30 Jan 2024 23:24:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706685891; cv=pass; d=google.com; s=arc-20160816; b=turl9FbxExSopQCLftoF8sTELxDzdy/ahAqZaBUJPingEfQbzfVt2fujTlkObuGAP+ fCiordZwK7P/NuM+VdYpbA7QgzD7CvF2BmtB+YoGPY7uCk93xpdnBIAav3NGSD1g6mf3 cvWbArCAPIbQEFd8Xt5jOnzdF5lNCyeZwT3GleEutMZoyd9MuB+0EBZ/0Ur96943kDnd m9GF/EN4aqLQHUfFdlUBhsLFVbKovu5RuoBTuILM8RNhO+95LkcsX5pPnYYBAofLSwB7 MYxLE40PJhMhhq5OwrTaCFwljTLJpJm85h7Pm3ec+SySeWob/T5cdy4aBpmFuoK4rZe6 H6lw== 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=zF1Go/6lOrWvy4qrZ4cIvQh0vUnrkdsyBnpdaBvTUNI=; fh=iOnV/FSp58jtK5hgVpPA6JDKDvtTW2/eca6p3p3UHCg=; b=kqqSKBEkewvwPQzHkaM4stkUcr/2iY1fZoT5EnwsBL+EWnhrN7o5WK7/eycyOpoIaY aY7YCOPT7VGdsszuld9srozAO+twVl/vRVPgdDvYnfjNHRMoHn6+5N/rq0oSfSfCompR nSnU6qcrmskSKyBekIxSic/KZ5s6AN49nBLP+0bJpZt9ztK5KK0pAluFDx7cd9JOcKot EWf0PmFJu8d6v/4XDUnAlpnrgQZWmwL6H+O5/99Hu+FtVhoW/KEIMwPEXcfFaqPJtRcN CHsYg/P4dagBc7Nf0/VfI591nIsRtaK4h4CY+A3x8vHLyGq/SzkA7X7h+I6+b+wmvh4T vFmg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Myk1FS8D; 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-45906-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45906-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; AJvYcCUVI4YWrvFk9dyF8oh340m9GYj2aCjpvnedxBHAap1wl9pDVXhVItyMATGrJHRTVwJkJ3rPn6ptlOgmqXy9KFPInpqOTt+A+oWLhqavEg== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id a7-20020a17090a854700b0028b21dd5308si662346pjw.37.2024.01.30.23.24.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 23:24:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45906-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Myk1FS8D; 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-45906-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45906-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 6D4DE286EB2 for ; Wed, 31 Jan 2024 07:24:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C7F0776040; Wed, 31 Jan 2024 07:21:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Myk1FS8D"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="1K4JHwTg" 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 C046A52F7F; Wed, 31 Jan 2024 07:21:21 +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=1706685683; cv=none; b=ZaOydPa8H03nfpiZwFX9TMOOTf1roERFZfCsu2m34e9pnhIps64KVv5KfK8AhlE2cfca6NfzL2MSPru8ZaXpy9K/Y5g7QTGZNm4nnFZcyKs+k6obdjbCfxb/dkd9PdkYgDyAAoI29YjpoHZ0XBg3vlEbqDliLFZX0EDYY1szH18= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706685683; c=relaxed/simple; bh=BVE+H4HR/ek0gZCHDa9dRrc1IIcoGkKt/+aoHxHvWJ4=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=qyHX+tSI1g3NDldJ/rVu25peJjnkwMrIHmu6AT77oX10wXSNq+OTnhFweuNvJeq0yZS7+OVHAssy8qhdfv0dglOSa4L9ipwV1XP3fCLXaW7KmLsYZB+sydrJJFhBeqfSQdaYXq/gPkjc+VJDQT624xg2wVQJWcc2cktKifpyhCY= 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=Myk1FS8D; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=1K4JHwTg; 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 07:21:19 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706685679; 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=zF1Go/6lOrWvy4qrZ4cIvQh0vUnrkdsyBnpdaBvTUNI=; b=Myk1FS8DvXTHOUcti4rSMCnJ+k1CEiUwlivE2KHOniZ0dGV1kvCADWuXoJcK/Ku29pytbJ tokVTTgBPEqngHMzVJmMvVIGwhoRWBNdLKlM3D270HZ8mF5dpQDxFzYW2eMTFWKJCLrTJ+ ezbuVKdRtfXc5BjDpawH2mbPdnkXCxVVA+RZ3q6POQP5c588Fm0YBYYBHXSUj2vEvn8vGU e6GxfAGA88PK5iiqsASECtim/JkfspEr4wGX5MbNofPVMCJgIYyF2fviC9SpxSr1j/nKf2 K3s3lSLQqOp0g8Oma7vq+fVsFvnw5YQ8dnCMFB+H8dgImD+yYQpbpzsYgYu2/A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706685679; 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=zF1Go/6lOrWvy4qrZ4cIvQh0vUnrkdsyBnpdaBvTUNI=; b=1K4JHwTgw/tW+WAI7wqrtrMuVlFExFw6KYCNYCAP1mhp0uT0IepZMNk82/PkVgPRJsCt+N MgE9DXiMISEfUODA== 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 , 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: <170668567906.398.14619800062896956268.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: f102fe126d2811eded63d700fbe27527d936af74 Gitweb: https://git.kernel.org/tip/f102fe126d2811eded63d700fbe27527d936af74 Author: H. Peter Anvin (Intel) AuthorDate: Tue, 05 Dec 2023 02:50:09 -08:00 Committer: Borislav Petkov (AMD) CommitterDate: Tue, 30 Jan 2024 18:20:35 +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 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