Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8100495imu; Tue, 4 Dec 2018 03:01:33 -0800 (PST) X-Google-Smtp-Source: AFSGD/Wk7d+WdLaB/F0MAxpfXqaPqLNISbvMmgvTbCWh/VGoCqxXiM/PkgrY8I7NJSFjqNPZt7Ha X-Received: by 2002:a17:902:9006:: with SMTP id a6mr7711616plp.334.1543921293166; Tue, 04 Dec 2018 03:01:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543921293; cv=none; d=google.com; s=arc-20160816; b=mscFPV+QsDer77MDbt5/7R60j3FPDudeT+Dj7J9PJqKAKgc9f8Nagq0P6411klM2VU OB9JzR9xZ4Oql3Ht6hgHGuL6VUj5glht4kw/ReSlcCFASv/xIxG0yNaR2/w5wasmEg1N x65xMtKtG34mm4VZREBEhw4u6pkT+EX56ObSTQ3hExtcrDy6nJ85hnYNarus9li+11hq 9bq8jn0T5RS/H9SVMeVW58lanQo8W8zgz125u36mfp2BGZVuZx8+4eZIB93CzZP5OFZJ XCBuBA8AswhWH/7TVaTZvSalOzhOZRn0LDvbDz7WfXH8qZ77QU7lcHIeAjA9VA2Yf4if Dr/w== 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=HFgwfGfKaG05mfrZPQ56qiLj1pef3LHbN2eKJr8aqXQ=; b=fNuMc7CQp9tRg+gkesS5rNJ+7eUkMLJch/C0VFYoDRkXEGCICRgiIR0+JjL77UfZ7P psycEsheOOqGYdQj9Vg76wIA7ZTPDe3EBtnDVab2pAlSTX3Qm6f0rruIM8QEtbbWC8fD XxwY8ZhhdrO4qEJhziIsAfzt7nVeSt0JAtvE9wq/lLcp8TGTVSnsAcwxO/HSR9DYenUz FgBtnb9nCMvviTouopxTqE8+m3ne0hSRM5AxTwQq212grJW07C+Xv+98Gfr5AHpX72kg tfQ/m1sO5DORsPI/N/9YAyMIcN1gkL8TGTXlNnqCM7mWBcJ6QdCxCyYmCPH5Jcbiw13g 7ppQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HY1JCOFs; 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 u8si15751933pgl.25.2018.12.04.03.01.17; Tue, 04 Dec 2018 03:01:33 -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=HY1JCOFs; 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 S1726927AbeLDK6X (ORCPT + 99 others); Tue, 4 Dec 2018 05:58:23 -0500 Received: from mail.kernel.org ([198.145.29.99]:42662 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726415AbeLDK6U (ORCPT ); Tue, 4 Dec 2018 05:58:20 -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 46BE1214DB; Tue, 4 Dec 2018 10:58:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543921099; bh=Lv8h2rowhYwKBV5JuVzF/XbTgptd22+XCxgGiFlIEdE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HY1JCOFsk5lQCuD0yA5xbqNTSGeHxnmX8ZpKx6zF8PJBwGmrXOocs+WZpawUipkxU k6HLU38N4ogzELKkRoJbeJMN5aEZaROe1WacMpWLZVtu37c95bWzRor4+Op+8tqb0N 4I9FGSIGIMKzzqAMsa407iG8qW2N0NiMWVM7x1uU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tim Chen , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Andy Lutomirski , Linus Torvalds , Jiri Kosina , Tom Lendacky , Josh Poimboeuf , Andrea Arcangeli , David Woodhouse , Andi Kleen , Dave Hansen , Casey Schaufler , Asit Mallick , Arjan van de Ven , Jon Masters , Waiman Long , Dave Stewart , Kees Cook Subject: [PATCH 4.19 036/139] x86/speculation: Move STIPB/IBPB string conditionals out of cpu_show_common() Date: Tue, 4 Dec 2018 11:48:37 +0100 Message-Id: <20181204103651.471509429@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: Tim Chen tim.c.chen@linux.intel.com commit a8f76ae41cd633ac00be1b3019b1eb4741be3828 upstream The Spectre V2 printout in cpu_show_common() handles conditionals for the various mitigation methods directly in the sprintf() argument list. That's hard to read and will become unreadable if more complex decisions need to be made for a particular method. Move the conditionals for STIBP and IBPB string selection into helper functions, so they can be extended later on. Signed-off-by: Tim Chen 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: 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/20181125185003.874479208@linutronix.de Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/cpu/bugs.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -842,6 +842,22 @@ static ssize_t l1tf_show_state(char *buf } #endif +static char *stibp_state(void) +{ + if (x86_spec_ctrl_base & SPEC_CTRL_STIBP) + return ", STIBP"; + else + return ""; +} + +static char *ibpb_state(void) +{ + if (boot_cpu_has(X86_FEATURE_USE_IBPB)) + return ", IBPB"; + else + return ""; +} + static ssize_t cpu_show_common(struct device *dev, struct device_attribute *attr, char *buf, unsigned int bug) { @@ -863,9 +879,9 @@ static ssize_t cpu_show_common(struct de case X86_BUG_SPECTRE_V2: return sprintf(buf, "%s%s%s%s%s%s\n", spectre_v2_strings[spectre_v2_enabled], - boot_cpu_has(X86_FEATURE_USE_IBPB) ? ", IBPB" : "", + ibpb_state(), boot_cpu_has(X86_FEATURE_USE_IBRS_FW) ? ", IBRS_FW" : "", - (x86_spec_ctrl_base & SPEC_CTRL_STIBP) ? ", STIBP" : "", + stibp_state(), boot_cpu_has(X86_FEATURE_RSB_CTXSW) ? ", RSB filling" : "", spectre_v2_module_string());