154fcf3a78
To clean up the per CPU insanity of UP which causes sparse to be rightfully unhappy and prevents the usage of the generic per CPU accessors on cpu_info it is necessary to include <linux/percpu.h> into <asm/msr.h>. Including <linux/percpu.h> into <asm/msr.h> is impossible because it ends up in header dependency hell. The problem is that <asm/processor.h> includes <asm/msr.h>. The inclusion of <linux/percpu.h> results in a compile fail where the compiler cannot longer handle an include in <asm/cpufeature.h> which references boot_cpu_data which is defined in <asm/processor.h>. The only reason why <asm/msr.h> is included in <asm/processor.h> are the set/get_debugctlmsr() inlines. They are defined there because <asm/processor.h> is such a nice dump ground for everything. In fact they belong obviously into <asm/debugreg.h>. Move them to <asm/debugreg.h> and fix up the resulting damage which is just exposing the reliance on random include chains. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Ingo Molnar <mingo@kernel.org> Link: https://lore.kernel.org/r/20240304005104.454678686@linutronix.de
51 lines
1.2 KiB
C
51 lines
1.2 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* This file is part of the Linux kernel.
|
|
*
|
|
* Copyright (c) 2011, Intel Corporation
|
|
* Authors: Fenghua Yu <fenghua.yu@intel.com>,
|
|
* H. Peter Anvin <hpa@linux.intel.com>
|
|
*/
|
|
#include <linux/printk.h>
|
|
|
|
#include <asm/processor.h>
|
|
#include <asm/archrandom.h>
|
|
#include <asm/sections.h>
|
|
|
|
/*
|
|
* RDRAND has Built-In-Self-Test (BIST) that runs on every invocation.
|
|
* Run the instruction a few times as a sanity check. Also make sure
|
|
* it's not outputting the same value over and over, which has happened
|
|
* as a result of past CPU bugs.
|
|
*
|
|
* If it fails, it is simple to disable RDRAND and RDSEED here.
|
|
*/
|
|
|
|
void x86_init_rdrand(struct cpuinfo_x86 *c)
|
|
{
|
|
enum { SAMPLES = 8, MIN_CHANGE = 5 };
|
|
unsigned long sample, prev;
|
|
bool failure = false;
|
|
size_t i, changed;
|
|
|
|
if (!cpu_has(c, X86_FEATURE_RDRAND))
|
|
return;
|
|
|
|
for (changed = 0, i = 0; i < SAMPLES; ++i) {
|
|
if (!rdrand_long(&sample)) {
|
|
failure = true;
|
|
break;
|
|
}
|
|
changed += i && sample != prev;
|
|
prev = sample;
|
|
}
|
|
if (changed < MIN_CHANGE)
|
|
failure = true;
|
|
|
|
if (failure) {
|
|
clear_cpu_cap(c, X86_FEATURE_RDRAND);
|
|
clear_cpu_cap(c, X86_FEATURE_RDSEED);
|
|
pr_emerg("RDRAND is not reliable on this platform; disabling.\n");
|
|
}
|
|
}
|