From: Borislav Petkov <bp@alien8.de>
To: Juergen Gross <jgross@suse.com>
Cc: xen-devel@lists.xenproject.org, x86@kernel.org,
linux-kernel@vger.kernel.org,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>,
Dave Hansen <dave.hansen@linux.intel.com>,
"H. Peter Anvin" <hpa@zytor.com>
Subject: Re: [PATCH v3 08/10] x86/mtrr: let cache_aps_delayed_init replace mtrr_aps_delayed_init
Date: Wed, 28 Sep 2022 01:16:50 +0200 [thread overview]
Message-ID: <YzOEYsqM0UEsiFuS@zn.tnic> (raw)
In-Reply-To: <314e3bd3-3405-c0c3-225c-646d88cbfb1a@suse.com>
On Tue, Sep 27, 2022 at 02:21:17PM +0200, Juergen Gross wrote:
> So replacing the bool with "(system_state != SYSTEM_RUNNING)" is fine
> with you right now? We can later switch that to the "more elegant"
> solution when it shows up.
Ok, I think I have something. And it was staring me straight in the
face but I didn't see it: the MTRR code needs a hotplug notifier. In
that notifier it can do the immediate, i.e., non-delayed init while the
delayed init becomes the default, see below.
And ignore the pr_info debugging gunk pls.
mtrr_ap_init() becomes the notifier callback. It doesn't need to be
called in identify_secondary_cpu() anymore as in the init case that
function doesn't do anything - delayed=true - and in the hotplug case
the notifier runs.
mtrr_aps_init() - "aps" in plural - does the delayed init after all CPUs
have been brought online after the box has booted. That might need some
renaming.
And yes, there's a lot more to cleanup after this. This code has grown
wart after wart over the years...
Fun.
---
diff --git a/arch/x86/include/asm/mtrr.h b/arch/x86/include/asm/mtrr.h
index 76d726074c16..1a3dad244bba 100644
--- a/arch/x86/include/asm/mtrr.h
+++ b/arch/x86/include/asm/mtrr.h
@@ -42,8 +42,6 @@ extern int mtrr_add_page(unsigned long base, unsigned long size,
extern int mtrr_del(int reg, unsigned long base, unsigned long size);
extern int mtrr_del_page(int reg, unsigned long base, unsigned long size);
extern void mtrr_centaur_report_mcr(int mcr, u32 lo, u32 hi);
-extern void mtrr_ap_init(void);
-extern void set_mtrr_aps_delayed_init(void);
extern void mtrr_aps_init(void);
extern void mtrr_bp_restore(void);
extern int mtrr_trim_uncached_memory(unsigned long end_pfn);
@@ -83,8 +81,6 @@ static inline int mtrr_trim_uncached_memory(unsigned long end_pfn)
static inline void mtrr_centaur_report_mcr(int mcr, u32 lo, u32 hi)
{
}
-#define mtrr_ap_init() do {} while (0)
-#define set_mtrr_aps_delayed_init() do {} while (0)
#define mtrr_aps_init() do {} while (0)
#define mtrr_bp_restore() do {} while (0)
# endif
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index 3e508f239098..deef1b5b27cc 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -1948,7 +1948,6 @@ void identify_secondary_cpu(struct cpuinfo_x86 *c)
#ifdef CONFIG_X86_32
enable_sep_cpu();
#endif
- mtrr_ap_init();
validate_apic_and_package_id(c);
x86_spec_ctrl_setup_ap();
update_srbds_msr();
diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.c b/arch/x86/kernel/cpu/mtrr/mtrr.c
index 2746cac9d8a9..abbf7cb8a430 100644
--- a/arch/x86/kernel/cpu/mtrr/mtrr.c
+++ b/arch/x86/kernel/cpu/mtrr/mtrr.c
@@ -69,7 +69,6 @@ unsigned int mtrr_usage_table[MTRR_MAX_VAR_RANGES];
static DEFINE_MUTEX(mtrr_mutex);
u64 size_or_mask, size_and_mask;
-static bool mtrr_aps_delayed_init;
static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __ro_after_init;
@@ -176,7 +175,7 @@ static int mtrr_rendezvous_handler(void *info)
if (data->smp_reg != ~0U) {
mtrr_if->set(data->smp_reg, data->smp_base,
data->smp_size, data->smp_type);
- } else if (mtrr_aps_delayed_init || !cpu_online(smp_processor_id())) {
+ } else if (!cpu_online(smp_processor_id())) {
mtrr_if->set_all();
}
return 0;
@@ -784,13 +783,16 @@ void __init mtrr_bp_init(void)
}
}
-void mtrr_ap_init(void)
+static int mtrr_ap_init(unsigned int cpu)
{
+ pr_info("%s: single AP entry, use_intel: %d, mtrr_enabled: %d, mtrr_aps_delayed_init\n",
+ __func__, use_intel(), mtrr_enabled());
+
if (!mtrr_enabled())
- return;
+ return 1;
- if (!use_intel() || mtrr_aps_delayed_init)
- return;
+ if (!use_intel())
+ return 1;
/*
* Ideally we should hold mtrr_mutex here to avoid mtrr entries
@@ -806,6 +808,8 @@ void mtrr_ap_init(void)
* lock to prevent mtrr entry changes
*/
set_mtrr_from_inactive_cpu(~0U, 0, 0, 0);
+
+ return 0;
}
/**
@@ -820,37 +824,24 @@ void mtrr_save_state(void)
return;
first_cpu = cpumask_first(cpu_online_mask);
- smp_call_function_single(first_cpu, mtrr_save_fixed_ranges, NULL, 1);
-}
-void set_mtrr_aps_delayed_init(void)
-{
- if (!mtrr_enabled())
- return;
- if (!use_intel())
- return;
+ pr_info("%s: first_cpu: %d\n", __func__, first_cpu);
- mtrr_aps_delayed_init = true;
+ smp_call_function_single(first_cpu, mtrr_save_fixed_ranges, NULL, 1);
}
/*
- * Delayed MTRR initialization for all AP's
+ * Delayed MTRR initialization for all APs
*/
void mtrr_aps_init(void)
{
- if (!use_intel() || !mtrr_enabled())
- return;
+ pr_info("%s: entry, use_intel: %d, mtrr_enabled: %d, mtrr_aps_delayed_init\n",
+ __func__, use_intel(), mtrr_enabled());
- /*
- * Check if someone has requested the delay of AP MTRR initialization,
- * by doing set_mtrr_aps_delayed_init(), prior to this point. If not,
- * then we are done.
- */
- if (!mtrr_aps_delayed_init)
+ if (!use_intel() || !mtrr_enabled())
return;
set_mtrr(~0U, 0, 0, 0);
- mtrr_aps_delayed_init = false;
}
void mtrr_bp_restore(void)
@@ -869,6 +860,10 @@ static int __init mtrr_init_finialize(void)
if (use_intel()) {
if (!changed_by_mtrr_cleanup)
mtrr_state_warn();
+
+ cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "x86/mtrr:online",
+ mtrr_ap_init, NULL);
+
return 0;
}
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index f24227bc3220..171acef35201 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -1428,7 +1428,7 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus)
uv_system_init();
- set_mtrr_aps_delayed_init();
+ pr_info("%s: set_mtrr_aps_delayed_init\n", __func__);
smp_quirk_init_udelay();
@@ -1439,7 +1439,7 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus)
void arch_thaw_secondary_cpus_begin(void)
{
- set_mtrr_aps_delayed_init();
+ pr_info("%s: set_mtrr_aps_delayed_init\n", __func__);
}
void arch_thaw_secondary_cpus_end(void)
diff --git a/kernel/cpu.c b/kernel/cpu.c
index bbad5e375d3b..fc14601b908c 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -591,6 +591,8 @@ static int bringup_cpu(unsigned int cpu)
struct task_struct *idle = idle_thread_get(cpu);
int ret;
+ pr_info("%s: CPU%d\n", __func__, cpu);
+
/*
* Reset stale stack state from the last time this CPU was online.
*/
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
next prev parent reply other threads:[~2022-09-27 23:17 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-08 8:49 [PATCH v3 00/10] x86: make pat and mtrr independent from each other Juergen Gross
2022-09-08 8:49 ` [PATCH v3 01/10] x86/mtrr: add comment for set_mtrr_state() serialization Juergen Gross
2022-09-08 8:49 ` [PATCH v3 02/10] x86/mtrr: remove unused cyrix_set_all() function Juergen Gross
2022-09-08 8:49 ` [PATCH v3 03/10] x86/mtrr: replace use_intel() with a local flag Juergen Gross
2022-09-11 10:16 ` Borislav Petkov
2022-09-12 9:10 ` Juergen Gross
2022-09-19 19:10 ` Borislav Petkov
2022-09-28 10:17 ` Juergen Gross
2022-09-08 8:49 ` [PATCH v3 04/10] x86: move some code out of arch/x86/kernel/cpu/mtrr Juergen Gross
2022-09-11 11:02 ` Borislav Petkov
2022-09-12 9:11 ` Juergen Gross
2022-09-08 8:49 ` [PATCH v3 05/10] x86/mtrr: split generic_set_all() Juergen Gross
2022-09-19 19:25 ` Borislav Petkov
2022-09-08 8:49 ` [PATCH v3 06/10] x86/mtrr: remove set_all callback from struct mtrr_ops Juergen Gross
2022-09-08 8:49 ` [PATCH v3 07/10] x86/mtrr: simplify mtrr_bp_init() Juergen Gross
2022-09-26 18:40 ` Borislav Petkov
2022-09-08 8:49 ` [PATCH v3 08/10] x86/mtrr: let cache_aps_delayed_init replace mtrr_aps_delayed_init Juergen Gross
2022-09-26 21:11 ` Borislav Petkov
2022-09-27 8:57 ` Juergen Gross
2022-09-27 10:10 ` Borislav Petkov
2022-09-27 10:14 ` Juergen Gross
2022-09-27 11:19 ` Borislav Petkov
2022-09-27 11:25 ` Juergen Gross
2022-09-27 12:13 ` Borislav Petkov
2022-09-27 12:21 ` Juergen Gross
2022-09-27 23:16 ` Borislav Petkov [this message]
2022-09-28 5:30 ` Juergen Gross
2022-09-28 6:16 ` Juergen Gross
2022-09-28 10:48 ` Borislav Petkov
2022-09-28 11:14 ` Juergen Gross
2022-09-28 11:22 ` Borislav Petkov
2022-09-28 13:43 ` Juergen Gross
2022-09-28 16:12 ` Borislav Petkov
2022-09-28 16:32 ` Juergen Gross
2022-09-28 16:39 ` Borislav Petkov
2022-09-29 8:26 ` Juergen Gross
2022-09-30 11:55 ` Borislav Petkov
2022-09-30 13:11 ` Juergen Gross
2022-09-30 13:25 ` Borislav Petkov
2022-09-08 8:49 ` [PATCH v3 09/10] x86/mtrr: add a stop_machine() handler calling only cache_cpu_init() Juergen Gross
2022-09-08 8:49 ` [PATCH v3 10/10] x86: decouple pat and mtrr handling Juergen Gross
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YzOEYsqM0UEsiFuS@zn.tnic \
--to=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=jgross@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®