Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8129799imu; Tue, 4 Dec 2018 03:31:32 -0800 (PST) X-Google-Smtp-Source: AFSGD/Wlue+YIqac6G8xTNvoHWME8RqERngHUv+/BIdSDUZp+shbLV8DCiLdcn8yAogQgGhliGPw X-Received: by 2002:a62:509b:: with SMTP id g27mr19933945pfj.48.1543923092799; Tue, 04 Dec 2018 03:31:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543923092; cv=none; d=google.com; s=arc-20160816; b=fK/50mH2CdD+u6OIx5MxMbD+3I7KQzCOyWr9Bkg68YWo2Ge+vCjdw2FJrd23vgGBww pHTKJJgX0Y4YbYse4a7/N+YW+Ea6TPidW1woulbMD+Cf/g/nRERxK4S51dODb0iO2hSs dblgeOEzmKPyHq+GsZvCsgK9CiT17iVTNTzGG9YBRMkrEUAp3nllc6CSeUZLbWlXpMu5 QnYzHaoqT8hbDJpbW4SSdPskKof92ypjvCvw8agIz10tgz4tILn2SYX026vQcLvoROw1 efjMILxjm6FxYCpnOKyFXhfWuhfcx3xtCjYhADWiaoKYO0ZVPd+hpVXRDSBQtuoLZzMD 9ZNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=DOZuSy7Z6jaRmR/qectWfsAlB9k1klUnkUtux5nCccA=; b=qPfeYTAkA4P5DaGFD9rB8hNmflC8Oek3aMI02m6auKN4Tyk+fGZmI2h4zD2gcAVX3O 0HXWcd3fNOtcl5O9K/mKf6DiKBW6iiKb0gC7xT/kNd3Po5wljKWzhpTR4foPCRv8ROIX dv0PGMPHtptmlOpOgxfMNLsCIInOOh+iKeTWDPbok6UFy7shqAMH8RQjhGHmWtgGONMh vWE7Zc3RE7nqeMT7e15FgttGtHf5qz4erIXQABaRNVSL/UOsG+hPVzaXvEGz+hA+qMCH ZE+EgRbftt/D1zi5maSN8V/EWB6ePPUZEXs/yc2dygJuRwmoXb+g3NVUSWPynDOL1oZ4 ryLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aSN57Gvn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m65si17786076pfg.282.2018.12.04.03.31.16; Tue, 04 Dec 2018 03:31:32 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aSN57Gvn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726663AbeLDK5K (ORCPT + 99 others); Tue, 4 Dec 2018 05:57:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:40808 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726637AbeLDK5I (ORCPT ); Tue, 4 Dec 2018 05:57:08 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3C02F214DE; Tue, 4 Dec 2018 10:57:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543921026; bh=7ZJ4dh7R3YJuN/oWkklL3Y090lNfWbxip7obHAcXnBA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aSN57Gvnn7e4rofeFak7iRndB48jSQ61Yi9f2ZXkmbyyRWyYY3aywb3HH8h+qCfAX ayoTa+01C5VuFBmiB2qFy55IFE/vvH4tzvJMaCx2mMBd4AbtOWfzlnGa7DQJuZdJ1u oVSB26MwtBIeJ77Zo11Ov1asnwzhaOEdz6D+W+QQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Andy Lutomirski , Linus Torvalds , Jiri Kosina , Tom Lendacky , Josh Poimboeuf , Andrea Arcangeli , David Woodhouse , Tim Chen , Andi Kleen , Dave Hansen , Casey Schaufler , Asit Mallick , Arjan van de Ven , Jon Masters , Waiman Long , Dave Stewart , Kees Cook Subject: [PATCH 4.19 052/139] x86/speculation: Avoid __switch_to_xtra() calls Date: Tue, 4 Dec 2018 11:48:53 +0100 Message-Id: <20181204103652.116493899@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181204103649.950154335@linuxfoundation.org> References: <20181204103649.950154335@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Thomas Gleixner tglx@linutronix.de commit 5635d99953f04b550738f6f4c1c532667c3fd872 upstream The TIF_SPEC_IB bit does not need to be evaluated in the decision to invoke __switch_to_xtra() when: - CONFIG_SMP is disabled - The conditional STIPB mode is disabled The TIF_SPEC_IB bit still controls IBPB in both cases so the TIF work mask checks might invoke __switch_to_xtra() for nothing if TIF_SPEC_IB is the only set bit in the work masks. Optimize it out by masking the bit at compile time for CONFIG_SMP=n and at run time when the static key controlling the conditional STIBP mode is disabled. Signed-off-by: Thomas Gleixner Reviewed-by: Ingo Molnar Cc: Peter Zijlstra Cc: Andy Lutomirski Cc: Linus Torvalds Cc: Jiri Kosina Cc: Tom Lendacky Cc: Josh Poimboeuf Cc: Andrea Arcangeli Cc: David Woodhouse Cc: Tim Chen Cc: Andi Kleen Cc: Dave Hansen Cc: Casey Schaufler Cc: Asit Mallick Cc: Arjan van de Ven Cc: Jon Masters Cc: Waiman Long Cc: Greg KH Cc: Dave Stewart Cc: Kees Cook Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/20181125185005.374062201@linutronix.de Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/thread_info.h | 13 +++++++++++-- arch/x86/kernel/process.h | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) --- a/arch/x86/include/asm/thread_info.h +++ b/arch/x86/include/asm/thread_info.h @@ -147,9 +147,18 @@ struct thread_info { _TIF_FSCHECK) /* flags to check in __switch_to() */ -#define _TIF_WORK_CTXSW \ +#define _TIF_WORK_CTXSW_BASE \ (_TIF_IO_BITMAP|_TIF_NOCPUID|_TIF_NOTSC|_TIF_BLOCKSTEP| \ - _TIF_SSBD|_TIF_SPEC_IB) + _TIF_SSBD) + +/* + * Avoid calls to __switch_to_xtra() on UP as STIBP is not evaluated. + */ +#ifdef CONFIG_SMP +# define _TIF_WORK_CTXSW (_TIF_WORK_CTXSW_BASE | _TIF_SPEC_IB) +#else +# define _TIF_WORK_CTXSW (_TIF_WORK_CTXSW_BASE) +#endif #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY) #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW) --- a/arch/x86/kernel/process.h +++ b/arch/x86/kernel/process.h @@ -2,6 +2,8 @@ // // Code shared between 32 and 64 bit +#include + void __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p); /* @@ -14,6 +16,19 @@ static inline void switch_to_extra(struc unsigned long next_tif = task_thread_info(next)->flags; unsigned long prev_tif = task_thread_info(prev)->flags; + if (IS_ENABLED(CONFIG_SMP)) { + /* + * Avoid __switch_to_xtra() invocation when conditional + * STIPB is disabled and the only different bit is + * TIF_SPEC_IB. For CONFIG_SMP=n TIF_SPEC_IB is not + * in the TIF_WORK_CTXSW masks. + */ + if (!static_branch_likely(&switch_to_cond_stibp)) { + prev_tif &= ~_TIF_SPEC_IB; + next_tif &= ~_TIF_SPEC_IB; + } + } + /* * __switch_to_xtra() handles debug registers, i/o bitmaps, * speculation mitigations etc.