Commit Graph

136 Commits

Author SHA1 Message Date
Baoquan He f0d10d2675 sysfs/cpu: Make crash_hotplug attribute world-readable
JIRA: https://issues.redhat.com/browse/RHEL-58641

Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

commit e777798e67d9ba46cf56ad49919c1e86c5ee3213
Author: Petr Tesarik <ptesarik@suse.com>
Date:   Thu Jul 11 12:34:09 2024 +0200

    sysfs/cpu: Make crash_hotplug attribute world-readable

    There is no reason to restrict access to this attribute, as it merely
    reports whether crash elfcorehdr is automatically updated on CPU hot
    plug/unplug and/or online/offline events.

    Note that since commit 79365026f8694 ("crash: add a new kexec flag for
    hotplug support"), this maps to the same flag which is world-accessible
    through /sys/devices/system/memory/crash_hotplug.

    Signed-off-by: Petr Tesarik <ptesarik@suse.com>
    Acked-by: Baoquan He <bhe@redhat.com>
    Acked-by: Sourabh Jain <sourabhjain@linux.ibm.com>
    Link: https://lore.kernel.org/r/20240711103409.319673-1-petr.tesarik@suse.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Baoquan He <bhe@redhat.com>
2024-12-23 09:35:36 +08:00
Baoquan He 930e56cdd6 crash: add a new kexec flag for hotplug support
JIRA: https://issues.redhat.com/browse/RHEL-58641

Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

commit 79365026f86948b52c3cb7bf099dded92c559b4c
Author: Sourabh Jain <sourabhjain@linux.ibm.com>
Date:   Tue Mar 26 11:24:09 2024 +0530

    crash: add a new kexec flag for hotplug support

    Commit a72bbec70da2 ("crash: hotplug support for kexec_load()")
    introduced a new kexec flag, `KEXEC_UPDATE_ELFCOREHDR`. Kexec tool uses
    this flag to indicate to the kernel that it is safe to modify the
    elfcorehdr of the kdump image loaded using the kexec_load system call.

    However, it is possible that architectures may need to update kexec
    segments other then elfcorehdr. For example, FDT (Flatten Device Tree)
    on PowerPC. Introducing a new kexec flag for every new kexec segment
    may not be a good solution. Hence, a generic kexec flag bit,
    `KEXEC_CRASH_HOTPLUG_SUPPORT`, is introduced to share the CPU/Memory
    hotplug support intent between the kexec tool and the kernel for the
    kexec_load system call.

    Now we have two kexec flags that enables crash hotplug support for
    kexec_load system call. First is KEXEC_UPDATE_ELFCOREHDR (only used in
    x86), and second is KEXEC_CRASH_HOTPLUG_SUPPORT (for all architectures).

    To simplify the process of finding and reporting the crash hotplug
    support the following changes are introduced.

    1. Define arch specific function to process the kexec flags and
       determine crash hotplug support

    2. Rename the @update_elfcorehdr member of struct kimage to
       @hotplug_support and populate it for both kexec_load and
       kexec_file_load syscalls, because architecture can update more than
       one kexec segment

    3. Let generic function crash_check_hotplug_support report hotplug
       support for loaded kdump image based on value of @hotplug_support

    To bring the x86 crash hotplug support in line with the above points,
    the following changes have been made:

    - Introduce the arch_crash_hotplug_support function to process kexec
      flags and determine crash hotplug support

    - Remove the arch_crash_hotplug_[cpu|memory]_support functions

    Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com>
    Acked-by: Baoquan He <bhe@redhat.com>
    Acked-by: Hari Bathini <hbathini@linux.ibm.com>
    Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
    Link: https://msgid.link/20240326055413.186534-3-sourabhjain@linux.ibm.com

Signed-off-by: Baoquan He <bhe@redhat.com>
2024-12-23 09:35:36 +08:00
Baoquan He 6ddb054bd6 crash: split crash dumping code out from kexec_core.c
JIRA: https://issues.redhat.com/browse/RHEL-58641

Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

Conflicts: There's conflict in last hunk of include/linux/kexec.h
           because of the fuzz caused by earlier back ported commits
           related to commit f4af41bf177a ("kexec: fix the unexpected
           kexec_dprintk() macro").

commit 02aff8480533817a29e820729360866441d7403d
Author: Baoquan He <bhe@redhat.com>
Date:   Wed Jan 24 13:12:44 2024 +0800

    crash: split crash dumping code out from kexec_core.c

    Currently, KEXEC_CORE select CRASH_CORE automatically because crash codes
    need be built in to avoid compiling error when building kexec code even
    though the crash dumping functionality is not enabled. E.g
    --------------------
    CONFIG_CRASH_CORE=y
    CONFIG_KEXEC_CORE=y
    CONFIG_KEXEC=y
    CONFIG_KEXEC_FILE=y
    ---------------------

    After splitting out crashkernel reservation code and vmcoreinfo exporting
    code, there's only crash related code left in kernel/crash_core.c. Now
    move crash related codes from kexec_core.c to crash_core.c and only build it
    in when CONFIG_CRASH_DUMP=y.

    And also wrap up crash codes inside CONFIG_CRASH_DUMP ifdeffery scope,
    or replace inappropriate CONFIG_KEXEC_CORE ifdef with CONFIG_CRASH_DUMP
    ifdef in generic kernel files.

    With these changes, crash_core codes are abstracted from kexec codes and
    can be disabled at all if only kexec reboot feature is wanted.

    Link: https://lkml.kernel.org/r/20240124051254.67105-5-bhe@redhat.com
    Signed-off-by: Baoquan He <bhe@redhat.com>
    Cc: Al Viro <viro@zeniv.linux.org.uk>
    Cc: Eric W. Biederman <ebiederm@xmission.com>
    Cc: Hari Bathini <hbathini@linux.ibm.com>
    Cc: Pingfan Liu <piliu@redhat.com>
    Cc: Klara Modin <klarasmodin@gmail.com>
    Cc: Michael Kelley <mhklinux@outlook.com>
    Cc: Nathan Chancellor <nathan@kernel.org>
    Cc: Stephen Rothwell <sfr@canb.auug.org.au>
    Cc: Yang Li <yang.lee@linux.alibaba.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Signed-off-by: Baoquan He <bhe@redhat.com>
2024-12-23 09:35:35 +08:00
Mark Langsdorf 83727d748d drivers: base: Implement weak arch_unregister_cpu()
JIRA: https://issues.redhat.com/browse/RHEL-54149

commit 866ec3008691ff205b171413c52c5f1f328a2f8b
Author: James Morse <james.morse@arm.com>
Date:   Tue Nov 21 13:44:31 2023 +0000

Add arch_unregister_cpu() to allow the ACPI machinery to call
unregister_cpu(). This is enough for arm64, riscv and loongarch, but
needs to be overridden by x86 and ia64 who need to do more work.

CC: Jean-Philippe Brucker <jean-philippe@linaro.org>
Signed-off-by: James Morse <james.morse@arm.com>
Reviewed-by: Shaoqin Huang <shahuang@redhat.com>
Signed-off-by: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
Reviewed-by: Gavin Shan <gshan@redhat.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/E1r5R3H-00CszC-2n@rmk-PC.armlinux.org.uk
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2024-08-22 11:21:45 -04:00
Mark Langsdorf a30839d7f1 drivers: base: Allow parts of GENERIC_CPU_DEVICES to be overridden
JIRA: https://issues.redhat.com/browse/RHEL-54149

commit 0949dd96dffec39683c6066cf8d0877cebc321ec
Author: James Morse <james.morse@arm.com>
Date:   Tue Nov 21 13:44:25 2023 +0000

Architectures often have extra per-cpu work that needs doing
before a CPU is registered, often to determine if a CPU is
hotpluggable.

To allow the ACPI architectures to use GENERIC_CPU_DEVICES, move
the cpu_register() call into arch_register_cpu(), which is made __weak
so architectures with extra work can override it.
This aligns with the way x86, ia64 and loongarch register hotplug CPUs
when they become present.

Signed-off-by: James Morse <james.morse@arm.com>
Reviewed-by: Shaoqin Huang <shahuang@redhat.com>
Reviewed-by: Gavin Shan <gshan@redhat.com>
Signed-off-by: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/E1r5R3B-00Csz6-Uh@rmk-PC.armlinux.org.uk
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2024-08-22 11:21:45 -04:00
Mark Langsdorf 573193ef89 drivers: base: Use present CPUs in GENERIC_CPU_DEVICES
JIRA: https://issues.redhat.com/browse/RHEL-54149

commit b0c69e1214bc20960c2ca68317b968e2a2057ed5
Author: James Morse <james.morse@arm.com>
Date:   Tue Nov 21 13:44:20 2023 +0000

Three of the five ACPI architectures create sysfs entries using
register_cpu() for present CPUs, whereas arm64, riscv and all
GENERIC_CPU_DEVICES do this for possible CPUs.

Registering a CPU is what causes them to show up in sysfs.

It makes very little sense to register all possible CPUs. Registering
a CPU is what triggers the udev notifications allowing user-space to
react to newly added CPUs.

To allow all five ACPI architectures to use GENERIC_CPU_DEVICES, change
it to use for_each_present_cpu().

Making the ACPI architectures use GENERIC_CPU_DEVICES is a pre-requisite
step to centralise their register_cpu() logic, before moving it into the
ACPI processor driver. When we add support for register CPUs from ACPI
in a later patch, we will avoid registering CPUs in this path.

Of the ACPI architectures that register possible CPUs, arm64 and riscv
do not support making possible CPUs present as they use the weak 'always
fails' version of arch_register_cpu().

Only two of the eight architectures that use GENERIC_CPU_DEVICES have a
distinction between present and possible CPUs.

The following architectures use GENERIC_CPU_DEVICES but are not SMP,
so possible == present:
 * m68k
 * microblaze
 * nios2

The following architectures use GENERIC_CPU_DEVICES and consider
possible == present:
 * csky: setup_smp()
 * processor_probe() sets possible for all CPUs and present for all CPUs
   except the boot cpu, which will have been done by
   init/main.c::start_kernel().

um appears to be a subarchitecture of x86.

The remaining architecture using GENERIC_CPU_DEVICES are:
 * openrisc and hexagon:
   where smp_init_cpus() makes all CPUs < NR_CPUS possible,
   whereas smp_prepare_cpus() only makes CPUs < setup_max_cpus present.

After this change, openrisc and hexagon systems that use the max_cpus
command line argument would not see the other CPUs present in sysfs.
This should not be a problem as these CPUs can't be brought online as
_cpu_up() checks cpu_present().

After this change, only CPUs which are present appear in sysfs.

Signed-off-by: James Morse <james.morse@arm.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Gavin Shan <gshan@redhat.com>
Signed-off-by: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/E1r5R36-00Csz0-Px@rmk-PC.armlinux.org.uk
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2024-08-22 11:21:45 -04:00
Mark Langsdorf db4e73f550 drivers/base/cpu: crash data showing should depends on KEXEC_CORE
JIRA: https://issues.redhat.com/browse/RHEL-26183

commit 4e9e2e4c65136dfd32dd0afe555961433d1cf906
Author: Baoquan He <bhe@redhat.com>
Date: Wed, 06 Dec 2023 16:12:48 +0000

After commit 88a6f8994421 ("crash: memory and CPU hotplug sysfs
attributes"), on x86_64, if only below kernel configs related to kdump are
set, compiling error are triggered.

----
CONFIG_CRASH_CORE=y
CONFIG_KEXEC_CORE=y
CONFIG_CRASH_DUMP=y
CONFIG_CRASH_HOTPLUG=y
------

------------------------------------------------------
drivers/base/cpu.c: In function `crash_hotplug_show':
drivers/base/cpu.c:309:40: error: implicit declaration of function `crash_hotplug_cpu_support'; did you mean `crash_hotplug_show'? [-Werror=implicit-function-declaration]
  309 |         return sysfs_emit(buf, "%d\n", crash_hotplug_cpu_support());
      |                                        ^~~~~~~~~~~~~~~~~~~~~~~~~
      |                                        crash_hotplug_show
cc1: some warnings being treated as errors
------------------------------------------------------

CONFIG_KEXEC is used to enable kexec_load interface, the
crash_notes/crash_notes_size/crash_hotplug showing depends on
CONFIG_KEXEC is incorrect. It should depend on KEXEC_CORE instead.

Fix it now.

Link: https://lkml.kernel.org/r/20231128055248.659808-1-bhe@redhat.com
Fixes: 88a6f8994421 ("crash: memory and CPU hotplug sysfs attributes")
Signed-off-by: Baoquan He <bhe@redhat.com>
Tested-by: Ignat Korchagin <ignat@cloudflare.com>	[compile-time only]
Tested-by: Alexander Gordeev <agordeev@linux.ibm.com>
Reviewed-by: Eric DeVolder <eric_devolder@yahoo.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2024-05-31 16:19:45 -04:00
Mark Langsdorf 013a5d02a3 crash: memory and CPU hotplug sysfs attributes
JIRA: https://issues.redhat.com/browse/RHEL-26183
Conflicts:
	Documentation/ABI/testing/sysfs-devices-system-cpu -
The crash_hotplug text was added to the end of the file
in upstream, so I did the same here.
	include/linux/kexec.h - minor context differences

commit 88a6f89944216b028d3872b0cec0f51a2f955460
Author: Eric DeVolder <eric.devolder@oracle.com>
Date: Thu, 24 Aug 2023 16:25:14 +0000

Introduce the crash_hotplug attribute for memory and CPUs for use by
userspace.  These attributes directly facilitate the udev rule for
managing userspace re-loading of the crash kernel upon hot un/plug
changes.

For memory, expose the crash_hotplug attribute to the
/sys/devices/system/memory directory.  For example:

 # udevadm info --attribute-walk /sys/devices/system/memory/memory81
  looking at device '/devices/system/memory/memory81':
    KERNEL=="memory81"
    SUBSYSTEM=="memory"
    DRIVER==""
    ATTR{online}=="1"
    ATTR{phys_device}=="0"
    ATTR{phys_index}=="00000051"
    ATTR{removable}=="1"
    ATTR{state}=="online"
    ATTR{valid_zones}=="Movable"

  looking at parent device '/devices/system/memory':
    KERNELS=="memory"
    SUBSYSTEMS==""
    DRIVERS==""
    ATTRS{auto_online_blocks}=="offline"
    ATTRS{block_size_bytes}=="8000000"
    ATTRS{crash_hotplug}=="1"

For CPUs, expose the crash_hotplug attribute to the
/sys/devices/system/cpu directory. For example:

 # udevadm info --attribute-walk /sys/devices/system/cpu/cpu0
  looking at device '/devices/system/cpu/cpu0':
    KERNEL=="cpu0"
    SUBSYSTEM=="cpu"
    DRIVER=="processor"
    ATTR{crash_notes}=="277c38600"
    ATTR{crash_notes_size}=="368"
    ATTR{online}=="1"

  looking at parent device '/devices/system/cpu':
    KERNELS=="cpu"
    SUBSYSTEMS==""
    DRIVERS==""
    ATTRS{crash_hotplug}=="1"
    ATTRS{isolated}==""
    ATTRS{kernel_max}=="8191"
    ATTRS{nohz_full}=="  (null)"
    ATTRS{offline}=="4-7"
    ATTRS{online}=="0-3"
    ATTRS{possible}=="0-7"
    ATTRS{present}=="0-3"

With these sysfs attributes in place, it is possible to efficiently
instruct the udev rule to skip crash kernel reloading for kernels
configured with crash hotplug support.

For example, the following is the proposed udev rule change for RHEL
system 98-kexec.rules (as the first lines of the rule file):

 # The kernel updates the crash elfcorehdr for CPU and memory changes
 SUBSYSTEM=="cpu", ATTRS{crash_hotplug}=="1", GOTO="kdump_reload_end"
 SUBSYSTEM=="memory", ATTRS{crash_hotplug}=="1", GOTO="kdump_reload_end"

When examined in the context of 98-kexec.rules, the above rules test if
crash_hotplug is set, and if so, the userspace initiated
unload-then-reload of the crash kernel is skipped.

CPU and memory checks are separated in accordance with CONFIG_HOTPLUG_CPU
and CONFIG_MEMORY_HOTPLUG kernel config options.  If an architecture
supports, for example, memory hotplug but not CPU hotplug, then the
/sys/devices/system/memory/crash_hotplug attribute file is present, but
the /sys/devices/system/cpu/crash_hotplug attribute file will NOT be
present.  Thus the udev rule skips userspace processing of memory hot
un/plug events, but the udev rule will evaluate false for CPU events, thus
allowing userspace to process CPU hot un/plug events (ie the
unload-then-reload of the kdump capture kernel).

Link: https://lkml.kernel.org/r/20230814214446.6659-5-eric.devolder@oracle.com
Signed-off-by: Eric DeVolder <eric.devolder@oracle.com>
Reviewed-by: Sourabh Jain <sourabhjain@linux.ibm.com>
Acked-by: Hari Bathini <hbathini@linux.ibm.com>
Acked-by: Baoquan He <bhe@redhat.com>
Cc: Akhil Raj <lf32.dev@gmail.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Borislav Petkov (AMD) <bp@alien8.de>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Dave Young <dyoung@redhat.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Mimi Zohar <zohar@linux.ibm.com>
Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Takashi Iwai <tiwai@suse.de>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Thomas Weißschuh <linux@weissschuh.net>
Cc: Valentin Schneider <vschneid@redhat.com>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2024-05-31 15:37:43 -04:00
Lucas Zampieri c644b7e89c Merge: x86/rfds: Mitigate Register File Data Sampling (RFDS)
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/3961

JIRA: https://issues.redhat.com/browse/RHEL-31226    
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/3961

RFDS (Register File Data Sampling - CVE-2023-28746) is a CPU
vulnerability that may allow userspace to infer kernel stale data
previously used in floating point registers, vector registers and
integer registers. RFDS only affects certain Intel Atom processors.

Intel released a microcode update that uses VERW instruction to clear the
affected CPU buffers. Unlike MDS, none of the affected cores support SMT.

This MR backports the upstream kernel mitigation to RHEL. New microcode
is also needed to complete the mitigation.

Signed-off-by: Waiman Long <longman@redhat.com>

Approved-by: Steve Best <sbest@redhat.com>
Approved-by: Chris von Recklinghausen <crecklin@redhat.com>
Approved-by: Rafael Aquini <aquini@redhat.com>
Approved-by: Josh Poimboeuf <jpoimboe@redhat.com>
Approved-by: David Arcari <darcari@redhat.com>
Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com>

Merged-by: Lucas Zampieri <lzampier@redhat.com>
2024-05-22 21:20:19 +00:00
Phil Auld 939a96eba0 tick/nohz: Fix cpu_is_hotpluggable() by checking with nohz subsystem
JIRA: https://issues.redhat.com/browse/RHEL-33787
Conflicts: Fuzz due to minor context difference.

commit 58d7668242647e661a20efe065519abd6454287e
Author: Joel Fernandes (Google) <joel@joelfernandes.org>
Date:   Tue Jan 24 17:31:26 2023 +0000

    tick/nohz: Fix cpu_is_hotpluggable() by checking with nohz subsystem

    For CONFIG_NO_HZ_FULL systems, the tick_do_timer_cpu cannot be offlined.
    However, cpu_is_hotpluggable() still returns true for those CPUs. This causes
    torture tests that do offlining to end up trying to offline this CPU causing
    test failures. Such failure happens on all architectures.

    Fix the repeated error messages thrown by this (even if the hotplug errors are
    harmless) by asking the opinion of the nohz subsystem on whether the CPU can be
    hotplugged.

    [ Apply Frederic Weisbecker feedback on refactoring tick_nohz_cpu_down(). ]

    For drivers/base/ portion:
    Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Acked-by: Frederic Weisbecker <frederic@kernel.org>
    Cc: Frederic Weisbecker <frederic@kernel.org>
    Cc: "Paul E. McKenney" <paulmck@kernel.org>
    Cc: Zhouyi Zhou <zhouzhouyi@gmail.com>
    Cc: Will Deacon <will@kernel.org>
    Cc: Marc Zyngier <maz@kernel.org>
    Cc: rcu <rcu@vger.kernel.org>
    Cc: stable@vger.kernel.org
    Fixes: 2987557f52 ("driver-core/cpu: Expose hotpluggability to the rest of the kernel")
    Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
    Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>

Signed-off-by: Phil Auld <pauld@redhat.com>
2024-04-23 11:49:40 -04:00
Waiman Long 5bc4b7e24a x86/rfds: Mitigate Register File Data Sampling (RFDS)
JIRA: https://issues.redhat.com/browse/RHEL-31226
Conflicts: A context diff in arch/x86/include/asm/msr-index.h due to
	   missing upstream commit b8d1d163604bd ("x86/apic: Don't
	   disable x2APIC if locked").

commit 8076fcde016c9c0e0660543e67bff86cb48a7c9c
Author: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
Date:   Mon, 11 Mar 2024 12:29:43 -0700

    x86/rfds: Mitigate Register File Data Sampling (RFDS)

    RFDS is a CPU vulnerability that may allow userspace to infer kernel
    stale data previously used in floating point registers, vector registers
    and integer registers. RFDS only affects certain Intel Atom processors.

    Intel released a microcode update that uses VERW instruction to clear
    the affected CPU buffers. Unlike MDS, none of the affected cores support
    SMT.

    Add RFDS bug infrastructure and enable the VERW based mitigation by
    default, that clears the affected buffers just before exiting to
    userspace. Also add sysfs reporting and cmdline parameter
    "reg_file_data_sampling" to control the mitigation.

    For details see:
    Documentation/admin-guide/hw-vuln/reg-file-data-sampling.rst

    Signed-off-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
    Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
    Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
    Acked-by: Josh Poimboeuf <jpoimboe@kernel.org>

Signed-off-by: Waiman Long <longman@redhat.com>
2024-04-02 10:25:55 -04:00
Jan Stancek bb8257dfab Merge: driver/base/cpu: Retry online operation if -EBUSY
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/3102

JIRA: https://issues.redhat.com/browse/RHEL-5737

commit 1fd7ab3facfc793c3f99d86752f8eb82db18e03d
Author: Waiman Long <longman@redhat.com>
Date:   Mon, 24 Jul 2023 10:38:26 -0400

    driver/base/cpu: Retry online operation if -EBUSY

    Booting the kernel with "maxcpus=1" is a common technique for CPU
    partitioning and isolation. It delays the CPU bringup process until
    when the bootup scripts are ready to bring CPUs online by writing 1 to
    /sys/device/system/cpu/cpu<X>/online. However, it was found that not
    all the CPUs were online after bootup. The collection of offline CPUs
    are different after every reboot.

    Further investigation reveals that some "online" write operations
    fail with an -EBUSY error. This error is returned when CPU hotplug is
    temporiarly disabled when cpu_hotplug_disable() is called.

    During bootup, the main caller of cpu_hotplug_disable() is
    pci_call_probe() for PCI device initialization. By measuring the times
    spent with cpu_hotplug_disabled set in a typical 2-socket server, most
    of them last less than 10ms.  However, there are a few that can last
    hundreds of ms. Note that the cpu_hotplug_disabled period of different
    devices can overlap leading to longer cpu_hotplug_disabled hold time.

    Since the CPU hotplug disable condition is transient and it is not
    that easy to modify all the existing bootup scripts to handle this
    condition, the kernel can help by retrying the online operation when
    an -EBUSY error is returned. This patch retries the online operation
    in cpu_subsys_online() when an -EBUSY error is returned for up to 5
    times after an exponentially increasing delay that can last a total of
    at least 620ms of waiting time by calling msleep().

    With this patch in place, booting up the patched kernel with "maxcpus=1"
    does not leave any CPU in an offline state in 10 reboot attempts.

    Reported-by: Vishal Agrawal <vagrawal@redhat.com>
    Signed-off-by: Waiman Long <longman@redhat.com>
    Link: https://lore.kernel.org/r/20230724143826.3996163-1-longman@redhat.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Waiman Long <longman@redhat.com>

Approved-by: Mark Langsdorf <mlangsdo@redhat.com>
Approved-by: John B. Wyatt IV <jwyatt@redhat.com>

Signed-off-by: Jan Stancek <jstancek@redhat.com>
2023-11-21 21:30:17 +01:00
Jan Stancek 151f2a0ce1 Merge: update drivers/base to v6.4
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/2940

JIRA: https://issues.redhat.com/browse/RHEL-1023

Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>

Approved-by: Phil Auld <pauld@redhat.com>
Approved-by: Tony Camuso <tcamuso@redhat.com>
Approved-by: Antoine Tenart <atenart@redhat.com>
Approved-by: Jocelyn Falempe <jfalempe@redhat.com>
Approved-by: Chris von Recklinghausen <crecklin@redhat.com>
Approved-by: Prarit Bhargava <prarit@redhat.com>
Approved-by: John W. Linville <linville@redhat.com>
Approved-by: Vladis Dronov <vdronov@redhat.com>
Approved-by: Donald Dutile <ddutile@redhat.com>
Approved-by: Eric Chanudet <echanude@redhat.com>

Signed-off-by: Jan Stancek <jstancek@redhat.com>
2023-11-19 13:07:01 +01:00
Mark Langsdorf 0753f4dc47 driver core: make struct bus_type.uevent() take a const *
JIRA: https://issues.redhat.com/browse/RHEL-1023
Conflicts:
	drivers/gpu/drm/drm_mipi_dsi.c - minor context
differences
	drivers/platform/x86/wmi.c - had to insert a const
in device_to_wblock()
	include/linux/hyperv.h - had to insert a const
in device_to_hv_device()
Omitted-fix: a69ea7a76d52353b17d7bedf43818c2578517e9e
	centos-9 doesn't support SuperH devices, so this
fix for the maple sub-componet of a SuperH isn't
necessary

commit 2a81ada32f0e584fc0c943e0d3a8c9f4fae411d6
Author: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date: Fri, 27 Jan 2023 13:45:52 +0000

The uevent() callback in struct bus_type should not be modifying the
device that is passed into it, so mark it as a const * and propagate the
function signature changes out into all relevant subsystems that use
this callback.

Acked-by: Rafael J. Wysocki <rafael@kernel.org>
Acked-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20230111113018.459199-16-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2023-10-23 10:35:56 -05:00
Waiman Long a9c8d298f1 driver core: cpu: Fix the fallback cpu_show_gds() name
JIRA: https://issues.redhat.com/browse/RHEL-8594
CVE: CVE-2023-20569

commit 3477144c878a52fc3938a529186e81ea030e7779
Author: Borislav Petkov (AMD) <bp@alien8.de>
Date:   Fri, 11 Aug 2023 11:32:09 +0200

    driver core: cpu: Fix the fallback cpu_show_gds() name

    In

      6524c798b727 ("driver core: cpu: Make cpu_show_not_affected() static")

    I fat-fingered the name of cpu_show_gds(). Usually, I'd rebase but since
    those are extraordinary embargoed times, the commit above was already
    pulled into another tree so no no.

    Therefore, fix it ontop.

    Fixes: 6524c798b727 ("driver core: cpu: Make cpu_show_not_affected() static")
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20230811095831.27513-1-bp@alien8.de

Signed-off-by: Waiman Long <longman@redhat.com>
2023-10-22 20:19:53 -04:00
Waiman Long e3ed7f8e75 driver core: cpu: Make cpu_show_not_affected() static
JIRA: https://issues.redhat.com/browse/RHEL-8594
CVE: CVE-2023-20569

commit 6524c798b727ffdb5c7eaed2f50e8e839997df8e
Author: Borislav Petkov (AMD) <bp@alien8.de>
Date:   Thu, 10 Aug 2023 13:22:29 +0200

    driver core: cpu: Make cpu_show_not_affected() static

    Fix a -Wmissing-prototypes warning and add the gather_data_sampling()
    stub macro call for real.

    Fixes: 0fddfe338210 ("driver core: cpu: Unify redundant silly stubs")
    Closes: https://lore.kernel.org/oe-kbuild-all/202308101956.oRj1ls7s-lkp@intel.com
    Reported-by: kernel test robot <lkp@intel.com>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/202308101956.oRj1ls7s-lkp@intel.com

Signed-off-by: Waiman Long <longman@redhat.com>
2023-10-22 20:19:53 -04:00
Waiman Long 917bca6e59 driver core: cpu: Unify redundant silly stubs
JIRA: https://issues.redhat.com/browse/RHEL-8594
CVE: CVE-2023-20569

commit 0fddfe338210aa018137c03030c581f5ea4be282
Author: Borislav Petkov (AMD) <bp@alien8.de>
Date:   Sat, 29 Jul 2023 17:20:33 +0200

    driver core: cpu: Unify redundant silly stubs

    Make them all a weak function, aliasing to a single function which
    issues the "Not affected" string.

    No functional changes.

    Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Reviewed-by: Nikolay Borisov <nik.borisov@suse.com>
    Link: https://lore.kernel.org/r/20230809102700.29449-3-bp@alien8.de

Signed-off-by: Waiman Long <longman@redhat.com>
2023-10-22 20:19:53 -04:00
Waiman Long e86b8e7755 x86/srso: Add a Speculative RAS Overflow mitigation
JIRA: https://issues.redhat.com/browse/RHEL-8594
CVE: CVE-2023-20569
Conflicts:
 1) Merge conflicts in
     - Documentation/admin-guide/hw-vuln/index.rst
     - arch/x86/kernel/cpu/bugs.c
     - arch/x86/kernel/cpu/common.c
     - drivers/base/cpu.c
    due to upstream merge conflict with commit 8974eb588283
    ("x86/speculation: Add Gather Data Sampling mitigation").
    The conflict resolution is based on upstream merge commit
    64094e7e3118 ("Merge tag 'gds-for-linus-2023-08-01' of
    git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip").
 2) A merge conflict in arch/x86/kernel/cpu/amd.c due to upstream merge
    conflict with commit 522b1d69219d ("x86/cpu/amd: Add a Zenbleed fix").
    as resolved in merge commit 138bcddb86d8 ("Merge tag 'x86_bugs_srso'
    of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip").

commit fb3bd914b3ec28f5fb697ac55c4846ac2d542855
Author: Borislav Petkov (AMD) <bp@alien8.de>
Date:   Wed, 28 Jun 2023 11:02:39 +0200

    x86/srso: Add a Speculative RAS Overflow mitigation

    Add a mitigation for the speculative return address stack overflow
    vulnerability found on AMD processors.

    The mitigation works by ensuring all RET instructions speculate to
    a controlled location, similar to how speculation is controlled in the
    retpoline sequence.  To accomplish this, the __x86_return_thunk forces
    the CPU to mispredict every function return using a 'safe return'
    sequence.

    To ensure the safety of this mitigation, the kernel must ensure that the
    safe return sequence is itself free from attacker interference.  In Zen3
    and Zen4, this is accomplished by creating a BTB alias between the
    untraining function srso_untrain_ret_alias() and the safe return
    function srso_safe_ret_alias() which results in evicting a potentially
    poisoned BTB entry and using that safe one for all function returns.

    In older Zen1 and Zen2, this is accomplished using a reinterpretation
    technique similar to Retbleed one: srso_untrain_ret() and
    srso_safe_ret().

    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>

Signed-off-by: Waiman Long <longman@redhat.com>
2023-10-22 20:19:52 -04:00
Waiman Long 393ea8e395 driver/base/cpu: Retry online operation if -EBUSY
JIRA: https://issues.redhat.com/browse/RHEL-5737

commit 1fd7ab3facfc793c3f99d86752f8eb82db18e03d
Author: Waiman Long <longman@redhat.com>
Date:   Mon, 24 Jul 2023 10:38:26 -0400

    driver/base/cpu: Retry online operation if -EBUSY

    Booting the kernel with "maxcpus=1" is a common technique for CPU
    partitioning and isolation. It delays the CPU bringup process until
    when the bootup scripts are ready to bring CPUs online by writing 1 to
    /sys/device/system/cpu/cpu<X>/online. However, it was found that not
    all the CPUs were online after bootup. The collection of offline CPUs
    are different after every reboot.

    Further investigation reveals that some "online" write operations
    fail with an -EBUSY error. This error is returned when CPU hotplug is
    temporiarly disabled when cpu_hotplug_disable() is called.

    During bootup, the main caller of cpu_hotplug_disable() is
    pci_call_probe() for PCI device initialization. By measuring the times
    spent with cpu_hotplug_disabled set in a typical 2-socket server, most
    of them last less than 10ms.  However, there are a few that can last
    hundreds of ms. Note that the cpu_hotplug_disabled period of different
    devices can overlap leading to longer cpu_hotplug_disabled hold time.

    Since the CPU hotplug disable condition is transient and it is not
    that easy to modify all the existing bootup scripts to handle this
    condition, the kernel can help by retrying the online operation when
    an -EBUSY error is returned. This patch retries the online operation
    in cpu_subsys_online() when an -EBUSY error is returned for up to 5
    times after an exponentially increasing delay that can last a total of
    at least 620ms of waiting time by calling msleep().

    With this patch in place, booting up the patched kernel with "maxcpus=1"
    does not leave any CPU in an offline state in 10 reboot attempts.

    Reported-by: Vishal Agrawal <vagrawal@redhat.com>
    Signed-off-by: Waiman Long <longman@redhat.com>
    Link: https://lore.kernel.org/r/20230724143826.3996163-1-longman@redhat.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Waiman Long <longman@redhat.com>
2023-09-20 21:55:38 -04:00
Waiman Long eb609d16e4 x86/speculation: Add Gather Data Sampling mitigation
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2229875
CVE: CVE-2022-40982
Conflicts:
 1) A merge conflict in arch/x86/include/asm/msr-index.h due to missing
    upstream commit b8d1d163604b ("x86/apic: Don't disable x2APIC
    if locked").

commit 8974eb588283b7d44a7c91fa09fcbaf380339f3a
Author: Daniel Sneddon <daniel.sneddon@linux.intel.com>
Date:   Wed, 12 Jul 2023 19:43:11 -0700

    x86/speculation: Add Gather Data Sampling mitigation

    Gather Data Sampling (GDS) is a hardware vulnerability which allows
    unprivileged speculative access to data which was previously stored in
    vector registers.

    Intel processors that support AVX2 and AVX512 have gather instructions
    that fetch non-contiguous data elements from memory. On vulnerable
    hardware, when a gather instruction is transiently executed and
    encounters a fault, stale data from architectural or internal vector
    registers may get transiently stored to the destination vector
    register allowing an attacker to infer the stale data using typical
    side channel techniques like cache timing attacks.

    This mitigation is different from many earlier ones for two reasons.
    First, it is enabled by default and a bit must be set to *DISABLE* it.
    This is the opposite of normal mitigation polarity. This means GDS can
    be mitigated simply by updating microcode and leaving the new control
    bit alone.

    Second, GDS has a "lock" bit. This lock bit is there because the
    mitigation affects the hardware security features KeyLocker and SGX.
    It needs to be enabled and *STAY* enabled for these features to be
    mitigated against GDS.

    The mitigation is enabled in the microcode by default. Disable it by
    setting gather_data_sampling=off or by disabling all mitigations with
    mitigations=off. The mitigation status can be checked by reading:

        /sys/devices/system/cpu/vulnerabilities/gather_data_sampling

    Signed-off-by: Daniel Sneddon <daniel.sneddon@linux.intel.com>
    Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
    Acked-by: Josh Poimboeuf <jpoimboe@kernel.org>

Signed-off-by: Waiman Long <longman@redhat.com>
2023-08-08 08:57:30 -04:00
Mark Langsdorf d78ad6020b driver core: cpu: don't hand-override the uevent bus_type callback.
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2178302

commit 2bc19066bda340540468ff88c2b1a798983bfd28
Author: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date: Fri, 10 Feb 2023 11:24:08 +0100

Instead of having to change the uevent bus_type callback by hand at
runtime, set it at build time based on the build configuration options,
making this much simpler to maintain and understand (and allow to make
the structure constant.)

Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Link: https://lore.kernel.org/r/20230210102408.1083177-1-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2023-06-08 12:33:14 -04:00
Mark Langsdorf 9886f0e9ca driver core: bus: add bus_get_dev_root() function
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2178302

commit 8c99377e614f8abfd881c34611002b2af5ab1ee8
Author: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date: Thu, 9 Feb 2023 10:35:56 +0100

Instead of poking around in the struct bus_type directly for the
dev_root pointer, provide a function to return it properly reference
counted, if it is present in the bus.  This will be needed to move the
pointer out of struct bus_type in the future.

Use the function in the driver core code at the same time it is
introduced to verify that it works properly.

Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Link: https://lore.kernel.org/r/20230209093556.19132-1-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2023-06-08 12:33:14 -04:00
Waiman Long 30505a352f x86/bugs: Report AMD retbleed vulnerability
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2090231
CVE: CVE-2022-23816
CVE: CVE-2022-23825
CVE: CVE-2022-29900
CVE: CVE-2022-29901

commit 6b80b59b3555706508008f1f127b5412c89c7fd8
Author: Alexandre Chartre <alexandre.chartre@oracle.com>
Date:   Tue, 14 Jun 2022 23:15:49 +0200

    x86/bugs: Report AMD retbleed vulnerability

    Report that AMD x86 CPUs are vulnerable to the RETBleed (Arbitrary
    Speculative Code Execution with Return Instructions) attack.

      [peterz: add hygon]
      [kim: invert parity; fam15h]

    Co-developed-by: Kim Phillips <kim.phillips@amd.com>
    Signed-off-by: Kim Phillips <kim.phillips@amd.com>
    Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Signed-off-by: Borislav Petkov <bp@suse.de>
    Reviewed-by: Josh Poimboeuf <jpoimboe@kernel.org>
    Signed-off-by: Borislav Petkov <bp@suse.de>

Signed-off-by: Waiman Long <longman@redhat.com>
2022-07-29 11:56:15 -04:00
Patrick Talbert ba60709985 Merge: Update drivers/base to v5.18
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/944

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2067284
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2067252
Omitted-fix: 68af28426b3ca1bf9ba21c7d8bdd0ff639e5134c
Requires substantial amd-pmc backport commits that are not in this MR or the centos-9 codebase yet.
Omitted-fix: b1f66033cd4e9ce8cbe2c74c98d4e04c0b2d7b40
Requires substantial amd-pmc backport commits that are not in this MR or the centos-9 codebase yet.
Omitted-fix: 753ee989f7cf0c0a76a7f56956827a8863a60f97
Fix for the previous omitted fix.
Omitted-fix: 32370191c0851da069d242f581cbe2fdb80040cb
Same fix as "platform/x86: amd-pmc: Set QOS during suspend on CZN w/ timer wakeup" but with a different commit hash

Update drivers/base subsystem to match Linux v5.18, including v5.17, v5.16, and v5.15. In general, all the commits applied cleanly, as would be expected with applying those commits to a v5.14 base.

A bunch of memory hotplug and memblock commits tangentially touched drivers/base in from v5.17 or v5.18, but David Hildebrand wrote them and can backport them better than I can, so I don't consider them to really be drivers/base commits. I pulled in a few commits that don't strictly touch drivers/base to finish out Luis Chamberlain's series on reworking the firmware loader.

A half-dozen MSI related commits that touched drivers/base in v5.17 were not backported, as they were part of a roughly 30 commit series that would be better handled by the PCI subsystem team.

Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>

Approved-by: Phil Auld <pauld@redhat.com>
Approved-by: David Arcari <darcari@redhat.com>
Approved-by: John W. Linville <linville@redhat.com>
Approved-by: Torez Smith <torez@redhat.com>

Conflicts:
- drivers/base/node.c: context differs due to MR !833.

Signed-off-by: Patrick Talbert <ptalbert@redhat.com>
2022-07-19 11:43:50 +02:00
Waiman Long 05e3b97051 x86/speculation/mmio: Add sysfs reporting for Processor MMIO Stale Data
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2090254
CVE: CVE-2022-21123
CVE: CVE-2022-21125
CVE: CVE-2022-21166

commit 8d50cdf8b8341770bc6367bce40c0c1bb0e1d5b3
Author: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
Date:   Thu, 19 May 2022 20:32:13 -0700

    x86/speculation/mmio: Add sysfs reporting for Processor MMIO Stale Data

    Add the sysfs reporting file for Processor MMIO Stale Data
    vulnerability. It exposes the vulnerability and mitigation state similar
    to the existing files for the other hardware vulnerabilities.

    Signed-off-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
    Signed-off-by: Borislav Petkov <bp@suse.de>

Signed-off-by: Waiman Long <longman@redhat.com>
2022-06-30 22:30:34 -04:00
Mark Langsdorf 0ddad73cfb driver: base: Prefer unsigned int to bare use of unsigned
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2067252

commit e7deeb9d79d8691f1e6c4c6707471ec3d7b9886b
Author: Jinchao Wang <wjc@cdjrlc.com>
Date: Tue, 29 Jun 2021 01:19:07 +0800

Fix checkpatch warnings:
    WARNING: Prefer 'unsigned int' to bare use of 'unsigned'

Signed-off-by: Jinchao Wang <wjc@cdjrlc.com>
Link: https://lore.kernel.org/r/20210628171907.63646-2-wjc@cdjrlc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2022-06-14 16:01:47 -05:00
Phil Auld 1cf795c344 sched/isolation: Use single feature type while referring to housekeeping cpumask
Bugzilla: http://bugzilla.redhat.com/2065222

commit 04d4e665a60902cf36e7ad39af1179cb5df542ad
Author: Frederic Weisbecker <frederic@kernel.org>
Date:   Mon Feb 7 16:59:06 2022 +0100

    sched/isolation: Use single feature type while referring to housekeeping cpumask

    Refer to housekeeping APIs using single feature types instead of flags.
    This prevents from passing multiple isolation features at once to
    housekeeping interfaces, which soon won't be possible anymore as each
    isolation features will have their own cpumask.

    Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Reviewed-by: Juri Lelli <juri.lelli@redhat.com>
    Reviewed-by: Phil Auld <pauld@redhat.com>
    Link: https://lore.kernel.org/r/20220207155910.527133-5-frederic@kernel.org

Signed-off-by: Phil Auld <pauld@redhat.com>
2022-03-31 10:40:39 -04:00
Rikard Falkeborn 5a576764e4 drivers/base: Constify static attribute_group structs
These are only used by putting their address in an array of pointers to
const struct attribute_group (either directly or via the
__ATTRIBUTE_GROUP macro). Make them const to allow the compiler to place
them in read-only memory.

Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com>
Link: https://lore.kernel.org/r/20210528213408.20067-1-rikard.falkeborn@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-04 15:06:28 +02:00
Colin Ian King 6b72cf1282 drivers/base/cpu: remove redundant assignment of variable retval
The variable retval is being initialized with a value that is never read
and it is being updated later with a new value.  Clean this up by
initializing retval to -ENOMEM and remove the assignment to retval
on the !dev failure path.

Kudos to Rafael for the improved fix suggestion.

Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Link: https://lore.kernel.org/r/20210218202837.516231-1-colin.king@canonical.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-03-23 14:56:50 +01:00
Joe Perches 948b3edba8 drivers core: Miscellaneous changes for sysfs_emit
Change additional instances that could use sysfs_emit and sysfs_emit_at
that the coccinelle script could not convert.

o macros creating show functions with ## concatenation
o unbound sprintf uses with buf+len for start of output to sysfs_emit_at
o returns with ?: tests and sprintf to sysfs_emit
o sysfs output with struct class * not struct device * arguments

Miscellanea:

o remove unnecessary initializations around these changes
o consistently use int len for return length of show functions
o use octal permissions and not S_<FOO>
o rename a few show function names so DEVICE_ATTR_<FOO> can be used
o use DEVICE_ATTR_ADMIN_RO where appropriate
o consistently use const char *output for strings
o checkpatch/style neatening

Signed-off-by: Joe Perches <joe@perches.com>
Link: https://lore.kernel.org/r/8bc24444fe2049a9b2de6127389b57edfdfe324d.1600285923.git.joe@perches.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-10-02 13:12:07 +02:00
Joe Perches aa838896d8 drivers core: Use sysfs_emit and sysfs_emit_at for show(device *...) functions
Convert the various sprintf fmaily calls in sysfs device show functions
to sysfs_emit and sysfs_emit_at for PAGE_SIZE buffer safety.

Done with:

$ spatch -sp-file sysfs_emit_dev.cocci --in-place --max-width=80 .

And cocci script:

$ cat sysfs_emit_dev.cocci
@@
identifier d_show;
identifier dev, attr, buf;
@@

ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
	<...
	return
-	sprintf(buf,
+	sysfs_emit(buf,
	...);
	...>
}

@@
identifier d_show;
identifier dev, attr, buf;
@@

ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
	<...
	return
-	snprintf(buf, PAGE_SIZE,
+	sysfs_emit(buf,
	...);
	...>
}

@@
identifier d_show;
identifier dev, attr, buf;
@@

ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
	<...
	return
-	scnprintf(buf, PAGE_SIZE,
+	sysfs_emit(buf,
	...);
	...>
}

@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@

ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
	<...
	return
-	strcpy(buf, chr);
+	sysfs_emit(buf, chr);
	...>
}

@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@

ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
	<...
	len =
-	sprintf(buf,
+	sysfs_emit(buf,
	...);
	...>
	return len;
}

@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@

ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
	<...
	len =
-	snprintf(buf, PAGE_SIZE,
+	sysfs_emit(buf,
	...);
	...>
	return len;
}

@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@

ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
	<...
	len =
-	scnprintf(buf, PAGE_SIZE,
+	sysfs_emit(buf,
	...);
	...>
	return len;
}

@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@

ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
	<...
-	len += scnprintf(buf + len, PAGE_SIZE - len,
+	len += sysfs_emit_at(buf, len,
	...);
	...>
	return len;
}

@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@

ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
	...
-	strcpy(buf, chr);
-	return strlen(buf);
+	return sysfs_emit(buf, chr);
}

Signed-off-by: Joe Perches <joe@perches.com>
Link: https://lore.kernel.org/r/3d033c33056d88bbe34d4ddb62afd05ee166ab9a.1600285923.git.joe@perches.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-10-02 13:09:10 +02:00
Mark Gross 7e5b3c267d x86/speculation: Add Special Register Buffer Data Sampling (SRBDS) mitigation
SRBDS is an MDS-like speculative side channel that can leak bits from the
random number generator (RNG) across cores and threads. New microcode
serializes the processor access during the execution of RDRAND and
RDSEED. This ensures that the shared buffer is overwritten before it is
released for reuse.

While it is present on all affected CPU models, the microcode mitigation
is not needed on models that enumerate ARCH_CAPABILITIES[MDS_NO] in the
cases where TSX is not supported or has been disabled with TSX_CTRL.

The mitigation is activated by default on affected processors and it
increases latency for RDRAND and RDSEED instructions. Among other
effects this will reduce throughput from /dev/urandom.

* Enable administrator to configure the mitigation off when desired using
  either mitigations=off or srbds=off.

* Export vulnerability status via sysfs

* Rename file-scoped macros to apply for non-whitelist table initializations.

 [ bp: Massage,
   - s/VULNBL_INTEL_STEPPING/VULNBL_INTEL_STEPPINGS/g,
   - do not read arch cap MSR a second time in tsx_fused_off() - just pass it in,
   - flip check in cpu_set_bug_bits() to save an indentation level,
   - reflow comments.
   jpoimboe: s/Mitigated/Mitigation/ in user-visible strings
   tglx: Dropped the fused off magic for now
 ]

Signed-off-by: Mark Gross <mgross@linux.intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Reviewed-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
Reviewed-by: Josh Poimboeuf <jpoimboe@redhat.com>
Tested-by: Neelima Krishnan <neelima.krishnan@intel.com>
2020-04-20 12:19:22 +02:00
Linus Torvalds 992a1a3b45 CPU (hotplug) updates:
- Support for locked CSD objects in smp_call_function_single_async()
     which allows to simplify callsites in the scheduler core and MIPS
 
   - Treewide consolidation of CPU hotplug functions which ensures the
     consistency between the sysfs interface and kernel state. The low level
     functions cpu_up/down() are now confined to the core code and not
     longer accessible from random code.
 -----BEGIN PGP SIGNATURE-----
 
 iQJHBAABCgAxFiEEQp8+kY+LLUocC4bMphj1TA10mKEFAl6B9VQTHHRnbHhAbGlu
 dXRyb25peC5kZQAKCRCmGPVMDXSYodCyD/0WFYAe7LkOfNjkbLa0IeuyLjF9rnCi
 ilcSXMLpaVwwoQvm7MopwkXUDdmEIyeJ0B641j3mC3AKCRap4+O36H2IEg2byrj7
 twOvQNCfxpVVmCCD11FTH9aQa74LEB6AikTgjevhrRWj6eHsal7c2Ak26AzCgrt+
 0eEkOAOWJbLAlbIiPdHlCZ3TMldcs3gg+lRSYd5QCGQVkZFnwpXzyOvpyJEUGGbb
 R/JuvwJoLhRMiYAJDILoQQQg/J07ODuivse/R8PWaH2djkn+2NyRGrD794PhyyOg
 QoTU0ZrYD3Z48ACXv+N3jLM7wXMcFzjYtr1vW1E3O/YGA7GVIC6XHGbMQ7tEihY0
 ajtwq8DcnpKtuouviYnf7NuKgqdmJXkaZjz3Gms6n8nLXqqSVwuQELWV2CXkxNe6
 9kgnnKK+xXMOGI4TUhN8bejvkXqRCmKMeQJcWyf+7RA9UIhAJw5o7WGo8gXfQWUx
 tazCqDy/inYjqGxckW615fhi2zHfemlYTbSzIGOuMB1TEPKFcrgYAii/VMsYHQVZ
 5amkYUXGQ5brlCOzOn38lzp5OkALBnFzD7xgvOcQgWT3ynVpdqADfBytXiEEHh4J
 KSkSgSSRcS58397nIxnDcJgJouHLvAWYyPZ4UC6mfynuQIic31qMHGVqwdbEKMY3
 4M5dGgqIfOBgYw==
 =jwCg
 -----END PGP SIGNATURE-----

Merge tag 'smp-core-2020-03-30' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull core SMP updates from Thomas Gleixner:
 "CPU (hotplug) updates:

   - Support for locked CSD objects in smp_call_function_single_async()
     which allows to simplify callsites in the scheduler core and MIPS

   - Treewide consolidation of CPU hotplug functions which ensures the
     consistency between the sysfs interface and kernel state. The low
     level functions cpu_up/down() are now confined to the core code and
     not longer accessible from random code"

* tag 'smp-core-2020-03-30' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (22 commits)
  cpu/hotplug: Ignore pm_wakeup_pending() for disable_nonboot_cpus()
  cpu/hotplug: Hide cpu_up/down()
  cpu/hotplug: Move bringup of secondary CPUs out of smp_init()
  torture: Replace cpu_up/down() with add/remove_cpu()
  firmware: psci: Replace cpu_up/down() with add/remove_cpu()
  xen/cpuhotplug: Replace cpu_up/down() with device_online/offline()
  parisc: Replace cpu_up/down() with add/remove_cpu()
  sparc: Replace cpu_up/down() with add/remove_cpu()
  powerpc: Replace cpu_up/down() with add/remove_cpu()
  x86/smp: Replace cpu_up/down() with add/remove_cpu()
  arm64: hibernate: Use bringup_hibernate_cpu()
  cpu/hotplug: Provide bringup_hibernate_cpu()
  arm64: Use reboot_cpu instead of hardconding it to 0
  arm64: Don't use disable_nonboot_cpus()
  ARM: Use reboot_cpu instead of hardcoding it to 0
  ARM: Don't use disable_nonboot_cpus()
  ia64: Replace cpu_down() with smp_shutdown_nonboot_cpus()
  cpu/hotplug: Create a new function to shutdown nonboot cpus
  cpu/hotplug: Add new {add,remove}_cpu() functions
  sched/core: Remove rq.hrtick_csd_pending
  ...
2020-03-30 18:06:39 -07:00
Qais Yousef 33c3736ec8 cpu/hotplug: Hide cpu_up/down()
Use separate functions for the device core to bring a CPU up and down.

Users outside the device core must use add/remove_cpu() which will take
care of extra housekeeping work like keeping sysfs in sync.

Make cpu_up/down() static and replace the extra layer of indirection.

[ tglx: Removed the extra wrapper functions and adjusted function names ]

Signed-off-by: Qais Yousef <qais.yousef@arm.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20200323135110.30522-18-qais.yousef@arm.com
2020-03-25 12:59:38 +01:00
Takashi Iwai 847e33867b drivers/base/cpu: Simplify s*nprintf() usages
Use the simpler sprintf() instead of snprintf() or scnprintf() in a
single-shot sysfs output callbacks where you are very sure that it
won't go over PAGE_SIZE buffer limit.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/20200311080207.12046-3-tiwai@suse.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-03-11 09:08:44 +01:00
Takashi Iwai 4636a04630 drivers/base/cpu: Use scnprintf() for avoiding potential buffer overflow
Since snprintf() returns the would-be-output size instead of the
actual output size, the succeeding calls may go beyond the given
buffer limit.  Fix it by replacing with scnprintf().

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/20200311080207.12046-2-tiwai@suse.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-03-11 09:08:44 +01:00
Vineela Tummalapalli db4d30fbb7 x86/bugs: Add ITLB_MULTIHIT bug infrastructure
Some processors may incur a machine check error possibly resulting in an
unrecoverable CPU lockup when an instruction fetch encounters a TLB
multi-hit in the instruction TLB. This can occur when the page size is
changed along with either the physical address or cache type. The relevant
erratum can be found here:

   https://bugzilla.kernel.org/show_bug.cgi?id=205195

There are other processors affected for which the erratum does not fully
disclose the impact.

This issue affects both bare-metal x86 page tables and EPT.

It can be mitigated by either eliminating the use of large pages or by
using careful TLB invalidations when changing the page size in the page
tables.

Just like Spectre, Meltdown, L1TF and MDS, a new bit has been allocated in
MSR_IA32_ARCH_CAPABILITIES (PSCHANGE_MC_NO) and will be set on CPUs which
are mitigated against this issue.

Signed-off-by: Vineela Tummalapalli <vineela.tummalapalli@intel.com>
Co-developed-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
Signed-off-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
2019-11-04 12:22:01 +01:00
Pawan Gupta 6608b45ac5 x86/speculation/taa: Add sysfs reporting for TSX Async Abort
Add the sysfs reporting file for TSX Async Abort. It exposes the
vulnerability and the mitigation state similar to the existing files for
the other hardware vulnerabilities.

Sysfs file path is:
/sys/devices/system/cpu/vulnerabilities/tsx_async_abort

Signed-off-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: Neelima Krishnan <neelima.krishnan@intel.com>
Reviewed-by: Mark Gross <mgross@linux.intel.com>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Josh Poimboeuf <jpoimboe@redhat.com>
2019-10-28 08:36:59 +01:00
Linus Torvalds fa4bff1650 Merge branch 'x86-mds-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 MDS mitigations from Thomas Gleixner:
 "Microarchitectural Data Sampling (MDS) is a hardware vulnerability
  which allows unprivileged speculative access to data which is
  available in various CPU internal buffers. This new set of misfeatures
  has the following CVEs assigned:

     CVE-2018-12126  MSBDS  Microarchitectural Store Buffer Data Sampling
     CVE-2018-12130  MFBDS  Microarchitectural Fill Buffer Data Sampling
     CVE-2018-12127  MLPDS  Microarchitectural Load Port Data Sampling
     CVE-2019-11091  MDSUM  Microarchitectural Data Sampling Uncacheable Memory

  MDS attacks target microarchitectural buffers which speculatively
  forward data under certain conditions. Disclosure gadgets can expose
  this data via cache side channels.

  Contrary to other speculation based vulnerabilities the MDS
  vulnerability does not allow the attacker to control the memory target
  address. As a consequence the attacks are purely sampling based, but
  as demonstrated with the TLBleed attack samples can be postprocessed
  successfully.

  The mitigation is to flush the microarchitectural buffers on return to
  user space and before entering a VM. It's bolted on the VERW
  instruction and requires a microcode update. As some of the attacks
  exploit data structures shared between hyperthreads, full protection
  requires to disable hyperthreading. The kernel does not do that by
  default to avoid breaking unattended updates.

  The mitigation set comes with documentation for administrators and a
  deeper technical view"

* 'x86-mds-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (23 commits)
  x86/speculation/mds: Fix documentation typo
  Documentation: Correct the possible MDS sysfs values
  x86/mds: Add MDSUM variant to the MDS documentation
  x86/speculation/mds: Add 'mitigations=' support for MDS
  x86/speculation/mds: Print SMT vulnerable on MSBDS with mitigations off
  x86/speculation/mds: Fix comment
  x86/speculation/mds: Add SMT warning message
  x86/speculation: Move arch_smt_update() call to after mitigation decisions
  x86/speculation/mds: Add mds=full,nosmt cmdline option
  Documentation: Add MDS vulnerability documentation
  Documentation: Move L1TF to separate directory
  x86/speculation/mds: Add mitigation mode VMWERV
  x86/speculation/mds: Add sysfs reporting for MDS
  x86/speculation/mds: Add mitigation control for MDS
  x86/speculation/mds: Conditionally clear CPU buffers on idle entry
  x86/kvm/vmx: Add MDS protection when L1D Flush is not active
  x86/speculation/mds: Clear CPU buffers on exit to user
  x86/speculation/mds: Add mds_clear_cpu_buffers()
  x86/kvm: Expose X86_FEATURE_MD_CLEAR to guests
  x86/speculation/mds: Add BUG_MSBDS_ONLY
  ...
2019-05-14 07:57:29 -07:00
Linus Torvalds e431f2d74e Driver core patches for 5.1-rc1
Here is the big driver core patchset for 5.1-rc1
 
 More patches than "normal" here this merge window, due to some work in
 the driver core by Alexander Duyck to rework the async probe
 functionality to work better for a number of devices, and independant
 work from Rafael for the device link functionality to make it work
 "correctly".
 
 Also in here is:
 	- lots of BUS_ATTR() removals, the macro is about to go away
 	- firmware test fixups
 	- ihex fixups and simplification
 	- component additions (also includes i915 patches)
 	- lots of minor coding style fixups and cleanups.
 
 All of these have been in linux-next for a while with no reported
 issues.
 
 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
 -----BEGIN PGP SIGNATURE-----
 
 iG0EABECAC0WIQT0tgzFv3jCIUoxPcsxR9QN2y37KQUCXH+euQ8cZ3JlZ0Brcm9h
 aC5jb20ACgkQMUfUDdst+ynyTgCfbV8CLums843sBnT8NnWrTMTdTCcAn1K4re0m
 ep8g+6oRLxJy414hogxQ
 =bLs2
 -----END PGP SIGNATURE-----

Merge tag 'driver-core-5.1-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core

Pull driver core updates from Greg KH:
 "Here is the big driver core patchset for 5.1-rc1

  More patches than "normal" here this merge window, due to some work in
  the driver core by Alexander Duyck to rework the async probe
  functionality to work better for a number of devices, and independant
  work from Rafael for the device link functionality to make it work
  "correctly".

  Also in here is:

   - lots of BUS_ATTR() removals, the macro is about to go away

   - firmware test fixups

   - ihex fixups and simplification

   - component additions (also includes i915 patches)

   - lots of minor coding style fixups and cleanups.

  All of these have been in linux-next for a while with no reported
  issues"

* tag 'driver-core-5.1-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core: (65 commits)
  driver core: platform: remove misleading err_alloc label
  platform: set of_node in platform_device_register_full()
  firmware: hardcode the debug message for -ENOENT
  driver core: Add missing description of new struct device_link field
  driver core: Fix PM-runtime for links added during consumer probe
  drivers/component: kerneldoc polish
  async: Add cmdline option to specify drivers to be async probed
  driver core: Fix possible supplier PM-usage counter imbalance
  PM-runtime: Fix __pm_runtime_set_status() race with runtime resume
  driver: platform: Support parsing GpioInt 0 in platform_get_irq()
  selftests: firmware: fix verify_reqs() return value
  Revert "selftests: firmware: remove use of non-standard diff -Z option"
  Revert "selftests: firmware: add CONFIG_FW_LOADER_USER_HELPER_FALLBACK to config"
  device: Fix comment for driver_data in struct device
  kernfs: Allocating memory for kernfs_iattrs with kmem_cache.
  sysfs: remove unused include of kernfs-internal.h
  driver core: Postpone DMA tear-down until after devres release
  driver core: Document limitation related to DL_FLAG_RPM_ACTIVE
  PM-runtime: Take suppliers into account in __pm_runtime_set_status()
  device.h: Add __cold to dev_<level> logging functions
  ...
2019-03-06 14:52:48 -08:00
Thomas Gleixner 8a4b06d391 x86/speculation/mds: Add sysfs reporting for MDS
Add the sysfs reporting file for MDS. It exposes the vulnerability and
mitigation state similar to the existing files for the other speculative
hardware vulnerabilities.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Jon Masters <jcm@redhat.com>
Tested-by: Jon Masters <jcm@redhat.com>
2019-03-06 21:52:14 +01:00
Sudeep Holla 85945c28b5 PM / core: Add support to skip power management in device/driver model
All device objects in the driver model contain fields that control the
handling of various power management activities. However, it's not
always useful. There are few instances where pseudo devices are added
to the model just to take advantage of many other features like
kobjects, udev events, and so on. One such example is cpu devices and
their caches.

The sysfs for the cpu caches are managed by adding devices with cpu
as the parent in cpu_device_create() when secondary cpu is brought
online. Generally when the secondary CPUs are hotplugged back in as part
of resume from suspend-to-ram, we call cpu_device_create() from the cpu
hotplug state machine while the cpu device associated with that CPU is
not yet ready to be resumed as the device_resume() call happens bit
later. It's not really needed to set the flag is_prepared for cpu
devices as they are mostly pseudo device and hotplug framework deals
with state machine and not managed through the cpu device.

This often results in annoying warning when resuming:
Enabling non-boot CPUs ...
CPU1: Booted secondary processor
 cache: parent cpu1 should not be sleeping
CPU1 is up
CPU2: Booted secondary processor
 cache: parent cpu2 should not be sleeping
CPU2 is up
.... and so on.

So in order to fix these kind of errors, we could just completely avoid
doing any power management related initialisations and operations if
they are not used by these devices.

Add no_pm flags to indicate that the device doesn't require any sort of
PM activities and all of them can be completely skipped. We can use the
same flag to also avoid adding not used *power* sysfs entries for these
devices. For now, lets use this for cpu cache devices.

Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
Tested-by: Eugeniu Rosca <erosca@de.adit-jv.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2019-02-19 10:42:43 +01:00
Mathieu Malaterre fa548d79d8 drivers: base: Use __printf markup to silence compiler
Silence warnings (triggered at W=1) by adding relevant __printf
attributes.

  drivers/base/cpu.c:432:2: warning: function '__cpu_device_create' might be a candidate for 'gnu_printf' format attribute [-Wsuggest-attribute=format]

Signed-off-by: Mathieu Malaterre <malat@debian.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-01-31 19:28:40 +01:00
Andi Kleen 17dbca1193 x86/speculation/l1tf: Add sysfs reporting for l1tf
L1TF core kernel workarounds are cheap and normally always enabled, However
they still should be reported in sysfs if the system is vulnerable or
mitigated. Add the necessary CPU feature/bug bits.

- Extend the existing checks for Meltdowns to determine if the system is
  vulnerable. All CPUs which are not vulnerable to Meltdown are also not
  vulnerable to L1TF

- Check for 32bit non PAE and emit a warning as there is no practical way
  for mitigation due to the limited physical address bits

- If the system has more than MAX_PA/2 physical memory the invert page
  workarounds don't protect the system against the L1TF attack anymore,
  because an inverted physical address will also point to valid
  memory. Print a warning in this case and report that the system is
  vulnerable.

Add a function which returns the PFN limit for the L1TF mitigation, which
will be used in follow up patches for sanity and range checks.

[ tglx: Renamed the CPU feature bit to L1TF_PTEINV ]

Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Josh Poimboeuf <jpoimboe@redhat.com>
Acked-by: Dave Hansen <dave.hansen@intel.com>
2018-06-20 19:10:00 +02:00
Konrad Rzeszutek Wilk c456442cd3 x86/bugs: Expose /sys/../spec_store_bypass
Add the sysfs file for the new vulerability. It does not do much except
show the words 'Vulnerable' for recent x86 cores.

Intel cores prior to family 6 are known not to be vulnerable, and so are
some Atoms and some Xeon Phi.

It assumes that older Cyrix, Centaur, etc. cores are immune.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Ingo Molnar <mingo@kernel.org>
2018-05-03 13:55:47 +02:00
Arvind Yadav 3aaba245df driver core: cpu: use put_device() if device_register fail
if device_register() returned an error! Always use put_device()
to give up the reference initialized.

Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-03-15 14:37:04 +01:00
Linus Torvalds 47fcc0360c Driver Core updates for 4.16-rc1
Here is the set of "big" driver core patches for 4.16-rc1.
 
 The majority of the work here is in the firmware subsystem, with reworks
 to try to attempt to make the code easier to handle in the long run, but
 no functional change.  There's also some tree-wide sysfs attribute
 fixups with lots of acks from the various subsystem maintainers, as well
 as a handful of other normal fixes and changes.
 
 And finally, some license cleanups for the driver core and sysfs code.
 
 All have been in linux-next for a while with no reported issues.
 
 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
 -----BEGIN PGP SIGNATURE-----
 
 iG0EABECAC0WIQT0tgzFv3jCIUoxPcsxR9QN2y37KQUCWnLvPw8cZ3JlZ0Brcm9h
 aC5jb20ACgkQMUfUDdst+ynNzACgkzjPoBytJWbpWFt6SR6L33/u4kEAnRFvVCGL
 s6ygQPQhZIjKk2Lxa2hC
 =Zihy
 -----END PGP SIGNATURE-----

Merge tag 'driver-core-4.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core

Pull driver core updates from Greg KH:
 "Here is the set of "big" driver core patches for 4.16-rc1.

  The majority of the work here is in the firmware subsystem, with
  reworks to try to attempt to make the code easier to handle in the
  long run, but no functional change. There's also some tree-wide sysfs
  attribute fixups with lots of acks from the various subsystem
  maintainers, as well as a handful of other normal fixes and changes.

  And finally, some license cleanups for the driver core and sysfs code.

  All have been in linux-next for a while with no reported issues"

* tag 'driver-core-4.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core: (48 commits)
  device property: Define type of PROPERTY_ENRTY_*() macros
  device property: Reuse property_entry_free_data()
  device property: Move property_entry_free_data() upper
  firmware: Fix up docs referring to FIRMWARE_IN_KERNEL
  firmware: Drop FIRMWARE_IN_KERNEL Kconfig option
  USB: serial: keyspan: Drop firmware Kconfig options
  sysfs: remove DEBUG defines
  sysfs: use SPDX identifiers
  drivers: base: add coredump driver ops
  sysfs: add attribute specification for /sysfs/devices/.../coredump
  test_firmware: fix missing unlock on error in config_num_requests_store()
  test_firmware: make local symbol test_fw_config static
  sysfs: turn WARN() into pr_warn()
  firmware: Fix a typo in fallback-mechanisms.rst
  treewide: Use DEVICE_ATTR_WO
  treewide: Use DEVICE_ATTR_RO
  treewide: Use DEVICE_ATTR_RW
  sysfs.h: Use octal permissions
  component: add debugfs support
  bus: simple-pm-bus: convert bool SIMPLE_PM_BUS to tristate
  ...
2018-02-01 10:00:28 -08:00
Linus Torvalds 40548c6b6c Merge branch 'x86-pti-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 pti updates from Thomas Gleixner:
 "This contains:

   - a PTI bugfix to avoid setting reserved CR3 bits when PCID is
     disabled. This seems to cause issues on a virtual machine at least
     and is incorrect according to the AMD manual.

   - a PTI bugfix which disables the perf BTS facility if PTI is
     enabled. The BTS AUX buffer is not globally visible and causes the
     CPU to fault when the mapping disappears on switching CR3 to user
     space. A full fix which restores BTS on PTI is non trivial and will
     be worked on.

   - PTI bugfixes for EFI and trusted boot which make sure that the user
     space visible page table entries have the NX bit cleared

   - removal of dead code in the PTI pagetable setup functions

   - add PTI documentation

   - add a selftest for vsyscall to verify that the kernel actually
     implements what it advertises.

   - a sysfs interface to expose vulnerability and mitigation
     information so there is a coherent way for users to retrieve the
     status.

   - the initial spectre_v2 mitigations, aka retpoline:

      + The necessary ASM thunk and compiler support

      + The ASM variants of retpoline and the conversion of affected ASM
        code

      + Make LFENCE serializing on AMD so it can be used as speculation
        trap

      + The RSB fill after vmexit

   - initial objtool support for retpoline

  As I said in the status mail this is the most of the set of patches
  which should go into 4.15 except two straight forward patches still on
  hold:

   - the retpoline add on of LFENCE which waits for ACKs

   - the RSB fill after context switch

  Both should be ready to go early next week and with that we'll have
  covered the major holes of spectre_v2 and go back to normality"

* 'x86-pti-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (28 commits)
  x86,perf: Disable intel_bts when PTI
  security/Kconfig: Correct the Documentation reference for PTI
  x86/pti: Fix !PCID and sanitize defines
  selftests/x86: Add test_vsyscall
  x86/retpoline: Fill return stack buffer on vmexit
  x86/retpoline/irq32: Convert assembler indirect jumps
  x86/retpoline/checksum32: Convert assembler indirect jumps
  x86/retpoline/xen: Convert Xen hypercall indirect jumps
  x86/retpoline/hyperv: Convert assembler indirect jumps
  x86/retpoline/ftrace: Convert ftrace assembler indirect jumps
  x86/retpoline/entry: Convert entry assembler indirect jumps
  x86/retpoline/crypto: Convert crypto assembler indirect jumps
  x86/spectre: Add boot time option to select Spectre v2 mitigation
  x86/retpoline: Add initial retpoline support
  objtool: Allow alternatives to be ignored
  objtool: Detect jumps to retpoline thunks
  x86/pti: Make unpoison of pgd for trusted boot work for real
  x86/alternatives: Fix optimize_nops() checking
  sysfs/cpu: Fix typos in vulnerability documentation
  x86/cpu/AMD: Use LFENCE_RDTSC in preference to MFENCE_RDTSC
  ...
2018-01-14 09:51:25 -08:00
Thomas Gleixner 87590ce6e3 sysfs/cpu: Add vulnerability folder
As the meltdown/spectre problem affects several CPU architectures, it makes
sense to have common way to express whether a system is affected by a
particular vulnerability or not. If affected the way to express the
mitigation should be common as well.

Create /sys/devices/system/cpu/vulnerabilities folder and files for
meltdown, spectre_v1 and spectre_v2.

Allow architectures to override the show function.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Linus Torvalds <torvalds@linuxfoundation.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: David Woodhouse <dwmw@amazon.co.uk>
Link: https://lkml.kernel.org/r/20180107214913.096657732@linutronix.de
2018-01-08 11:10:33 +01:00
Greg Kroah-Hartman 989d42e85d driver core: add SPDX identifiers to all driver core files
It's good to have SPDX identifiers in all files to make it easier to
audit the kernel tree for correct licenses.

Update the driver core files files with the correct SPDX license
identifier based on the license text in the file itself.  The SPDX
identifier is a legally binding shorthand, which can be used instead of
the full boiler plate text.

This work is based on a script and data from Thomas Gleixner, Philippe
Ombredanne, and Kate Stewart.

Cc: Johannes Berg <johannes@sipsolutions.net>
Cc: "Luis R. Rodriguez" <mcgrof@kernel.org>
Cc: William Breathitt Gray <vilhelm.gray@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Kate Stewart <kstewart@linuxfoundation.org>
Cc: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-12-07 18:36:43 +01:00