Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp786230imm; Mon, 21 May 2018 14:25:43 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoTTkd19DRWAuB+B7w3x4MU/9jhoIWT1r6QrGDIhF6wyQJF0QzEjT/AlfH9FM4LMg6co0WJ X-Received: by 2002:a63:90c4:: with SMTP id a187-v6mr10520270pge.179.1526937943784; Mon, 21 May 2018 14:25:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526937943; cv=none; d=google.com; s=arc-20160816; b=DjOyBd2Jc99qsAsDvP5z2E20xFYfii23snmxopUBcuF8Z/g6DhK0GSihLNYxSq3SjK G/JFwEA7/QBTxUsH4al+uLKpb2zaKCYneM8biTlRH6/r0PVYtMKI+d7GZ8p9DOgPUOnS AxlicV75KL1tgJoUyUXdQGun3im1b+pguf98sJ7J0TUSIcCVT/0i9ci801h13R/irIAe pZyhA7RCdufsqi9BJAntHYYb7xvE0FW8KiNgNnUwArBHc2R6DlXRYQQoPTFoDYa2DIrw TCxH0FI1P/hGXABIdxqZIDC49vazGr+M3VMcBNTTD3M4pUkrYee2syVjO9fa8HsP8kCj z/7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=SFZ72aKgdLEFVjnlEWyx3VYdg9ROgRJOwewNUsZ9u2E=; b=BT1xuU5F8cGplJHKGbOe9p4IiraQmMXQU4p5g8ePKPAjgii8neCskFw/s2cAfTb6v3 LhcuLVU3mpvrSESOeB6j1eBYXSAbgsqf+kbMut1kM6hfjAFV5oVAW6o32Vp+jnhsBIrM BHbcnrgDHjrKbRmC2zRmSoGzkxMDyMH+ZbE/cVleMKpIjZkYud5fmGFB3s/rjHHNY94U uGTLonLtJ3QCHnm8fk94M18lnaEXTuRMDyzKu2gCesUp+6wbzUJPGO3PuIv5S6uchWIm kux40xIRwKOueyKISTQxMAzKf4DeeydfrTcCh+sQMQZCpdrbO+sCnfC/Fq5JHoc9NJBf 7VFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=a4ut+8qi; 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 f39-v6si15171854plb.572.2018.05.21.14.25.28; Mon, 21 May 2018 14:25:43 -0700 (PDT) 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=a4ut+8qi; 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 S932411AbeEUVZS (ORCPT + 99 others); Mon, 21 May 2018 17:25:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:40108 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932383AbeEUVZN (ORCPT ); Mon, 21 May 2018 17:25:13 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (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 71C5E20871; Mon, 21 May 2018 21:25:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1526937913; bh=ignwjmpe9v3YQEHsgqxwqBxIIKW/pc58ixNmC3O+0vc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a4ut+8qiL19irAk6nc2Oz9WbIBLOB4Dh7uXi9kh9QxRIBgKOwO+NJyUu6E7/gT3p1 AzxemirgvZVF+gA9qW0m3f/CPrwRNaBoxxLL9sKRHnnY9J/pjnzYQW33kcDGDGXRr8 f0ndDdq+41xT5egcz8qNPbRLCcToDmtsJz2T0Oxo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Borislav Petkov , Konrad Rzeszutek Wilk , Thomas Gleixner , Ingo Molnar Subject: [PATCH 4.16 064/110] x86/bugs: Concentrate bug reporting into a separate function Date: Mon, 21 May 2018 23:12:01 +0200 Message-Id: <20180521210511.863181479@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180521210503.823249477@linuxfoundation.org> References: <20180521210503.823249477@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Konrad Rzeszutek Wilk commit d1059518b4789cabe34bb4b714d07e6089c82ca1 upstream Those SysFS functions have a similar preamble, as such make common code to handle them. Suggested-by: Borislav Petkov Signed-off-by: Konrad Rzeszutek Wilk Signed-off-by: Thomas Gleixner Reviewed-by: Borislav Petkov Reviewed-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/cpu/bugs.c | 46 +++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -314,30 +314,48 @@ retpoline_auto: #undef pr_fmt #ifdef CONFIG_SYSFS -ssize_t cpu_show_meltdown(struct device *dev, struct device_attribute *attr, char *buf) + +ssize_t cpu_show_common(struct device *dev, struct device_attribute *attr, + char *buf, unsigned int bug) { - if (!boot_cpu_has_bug(X86_BUG_CPU_MELTDOWN)) + if (!boot_cpu_has_bug(bug)) return sprintf(buf, "Not affected\n"); - if (boot_cpu_has(X86_FEATURE_PTI)) - return sprintf(buf, "Mitigation: PTI\n"); + + switch (bug) { + case X86_BUG_CPU_MELTDOWN: + if (boot_cpu_has(X86_FEATURE_PTI)) + return sprintf(buf, "Mitigation: PTI\n"); + + break; + + case X86_BUG_SPECTRE_V1: + return sprintf(buf, "Mitigation: __user pointer sanitization\n"); + + case X86_BUG_SPECTRE_V2: + return sprintf(buf, "%s%s%s%s\n", spectre_v2_strings[spectre_v2_enabled], + boot_cpu_has(X86_FEATURE_USE_IBPB) ? ", IBPB" : "", + boot_cpu_has(X86_FEATURE_USE_IBRS_FW) ? ", IBRS_FW" : "", + spectre_v2_module_string()); + + default: + break; + } + return sprintf(buf, "Vulnerable\n"); } +ssize_t cpu_show_meltdown(struct device *dev, struct device_attribute *attr, char *buf) +{ + return cpu_show_common(dev, attr, buf, X86_BUG_CPU_MELTDOWN); +} + ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr, char *buf) { - if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V1)) - return sprintf(buf, "Not affected\n"); - return sprintf(buf, "Mitigation: __user pointer sanitization\n"); + return cpu_show_common(dev, attr, buf, X86_BUG_SPECTRE_V1); } ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr, char *buf) { - if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V2)) - return sprintf(buf, "Not affected\n"); - - return sprintf(buf, "%s%s%s%s\n", spectre_v2_strings[spectre_v2_enabled], - boot_cpu_has(X86_FEATURE_USE_IBPB) ? ", IBPB" : "", - boot_cpu_has(X86_FEATURE_USE_IBRS_FW) ? ", IBRS_FW" : "", - spectre_v2_module_string()); + return cpu_show_common(dev, attr, buf, X86_BUG_SPECTRE_V2); } #endif