Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5771652imm; Mon, 23 Jul 2018 05:56:08 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc7/wXg0Juzbo9SHvbB0Hnvc2DbNSr2hoOei7viMXcisvIw7yUYWAphH6bqeic++xPLRcKo X-Received: by 2002:a62:6547:: with SMTP id z68-v6mr13224587pfb.20.1532350568432; Mon, 23 Jul 2018 05:56:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532350568; cv=none; d=google.com; s=arc-20160816; b=I8Pb8l9eZS1D7nIFDs0aLuVH06dT+0EIdC7gZiYNteFSiPPdeHXo5DGX0b7gzWTJ8V i+HeVMAJS9++MXo6SDAPxw3ynL42mfAE8bg9Rp8Fnve00AXQFDrIM8HlRjJK6y16UJf+ jJiAR9UEVV+Xz6sFKksJd8aWpbnUkZhNSiS4ccLTF9l8QsStDOgiYAiQZjpby+MsMtUU ojV67LuncuWrkj5kGe3t4hqk2Sk6TZ3bNr2pG7mhQbh+NQHPolATv9J575a2oXSI3q5Q pnPxVEUdvzPlwP3aQmHUA8qGwJ/8RDyG1JKeR22EvXugEp8Dx9HA8LYOXHmZhd7bp1la bnnA== 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 :arc-authentication-results; bh=KBrQWIipjrqg0ZG9O+s+OQZCTkvUzKdIHWs6b4mQmKw=; b=r9PB3wUTKIA0HCzBBlIncovYTy/UmRBcVuPoIDFssRzNDxRS77ywC9jDNg0OecKq6k o1PQ2hWjmqdLuyg4zD/BVlgYar4ZjZhwNE3MDgSpmeO4GAUEM/OwfZnAgW1Y66YnRfnD lr30PrQsFhi3w4kYs5IJ3XcTq0aFQYvfXoWWYQH8vQPyYdhJaOhj2qCiDpy8UFd043q7 d+Cmi1S9Oc2mhsnvTrh+GPm11p1s0SD+dfvVDgM8FNUU+Q1LOxx2LcCFHVmbZfLjwQC3 kOkKZ7OlkXBlmarm/46cUaWfJlhfdJs0IoXGCDkbv4yC52m2IRLqSWRGZxVOVhRhbb8M TRYQ== ARC-Authentication-Results: i=1; mx.google.com; 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 h25-v6si8794879pgh.119.2018.07.23.05.55.54; Mon, 23 Jul 2018 05:56:08 -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; 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 S2389098AbeGWNrb (ORCPT + 99 others); Mon, 23 Jul 2018 09:47:31 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:50966 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388007AbeGWNrb (ORCPT ); Mon, 23 Jul 2018 09:47:31 -0400 Received: from localhost (LFbn-1-12238-233.w90-92.abo.wanadoo.fr [90.92.53.233]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id CECEDC7A; Mon, 23 Jul 2018 12:44:47 +0000 (UTC) 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 , David Woodhouse , "Srivatsa S. Bhat" , "Matt Helsley (VMware)" , Alexey Makhalov , Bo Gan Subject: [PATCH 4.4 050/107] x86/bugs: Concentrate bug reporting into a separate function Date: Mon, 23 Jul 2018 14:41:44 +0200 Message-Id: <20180723122415.469938978@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180723122413.003644357@linuxfoundation.org> References: <20180723122413.003644357@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.4-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: David Woodhouse Signed-off-by: Greg Kroah-Hartman Signed-off-by: Srivatsa S. Bhat Reviewed-by: Matt Helsley (VMware) Reviewed-by: Alexey Makhalov Reviewed-by: Bo Gan 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_KAISER)) - return sprintf(buf, "Mitigation: PTI\n"); + + switch (bug) { + case X86_BUG_CPU_MELTDOWN: + if (boot_cpu_has(X86_FEATURE_KAISER)) + 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