lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <6fc16f3048719058bccce9d488bcb75252f49031.camel@infradead.org>
Date:   Fri, 10 Feb 2023 08:55:48 +0000
From:   David Woodhouse <dwmw2@...radead.org>
To:     Thomas Gleixner <tglx@...utronix.de>,
        Usama Arif <usama.arif@...edance.com>, kim.phillips@....com
Cc:     arjan@...ux.intel.com, mingo@...hat.com, bp@...en8.de,
        dave.hansen@...ux.intel.com, hpa@...or.com, x86@...nel.org,
        pbonzini@...hat.com, paulmck@...nel.org,
        linux-kernel@...r.kernel.org, kvm@...r.kernel.org,
        rcu@...r.kernel.org, mimoja@...oja.de, hewenliang4@...wei.com,
        thomas.lendacky@....com, seanjc@...gle.com, pmenzel@...gen.mpg.de,
        fam.zheng@...edance.com, punit.agrawal@...edance.com,
        simon.evans@...edance.com, liangma@...ngbit.com
Subject: Re: [External] Re: [PATCH v8 8/9] x86/mtrr: Avoid repeated save of
 MTRRs on boot-time CPU bringup

On Fri, 2023-02-10 at 00:50 +0100, Thomas Gleixner wrote:
> On Thu, Feb 09 2023 at 20:32, Usama Arif wrote:
> > On 09/02/2023 18:31, Thomas Gleixner wrote:
> > > >         first_cpu = cpumask_first(cpu_online_mask);
> > > >         smp_call_function_single(first_cpu, mtrr_save_fixed_ranges, NULL, 1);
> > > 
> > > So why is this relevant after the initial bringup? The BP MTRRs have
> > > been saved already above, no?
> > > 
> > 
> > I will let David confirm if this is correct and why he did it, but this 
> > is what I thought while reviewing before posting v4:
> > 
> > - At initial boot (system_state < SYSTEM_RUNNING), when mtrr_save_state 
> > is called in do_cpu_up at roughly the same time so MTRR is going to be 
> > the same, we can just save it once and then reuse for other secondary 
> > cores as it wouldn't have changed for the rest of the do_cpu_up calls.
> > 
> > - When the system is running and you offline and then online a CPU, you 
> > want to make sure that hotplugged CPU gets the current MTRR (which might 
> > have changed since boot?), incase the MTRR has changed after the system 
> > has been booted, you save the MTRR of the first online CPU. When the 
> > hotplugged CPU runs its initialisation code, its fixed-range MTRRs will 
> > be updated with the newly saved fixed-range MTRRs.
> 
> I knew that already :) But seriously:
> 
> If the MTRRs are changed post boot then the cached values want to be
> updated too.

They are, aren't they? The only way we come out of mtrr_save_state()
without calling mtrr_save_fixed_ranges() — either directly or via
smp_call_function_single() — is if they've already been saved once
*and* system_state < SYSTEM_RUNNING.

I suppose we could make that clearer by moving the definition of the
mtrr_saved flags inside the if (system_state < SYSTEM_RUNNING) block?

@@ -721,11 +721,20 @@ void __init mtrr_bp_init(void)
  */
 void mtrr_save_state(void)
 {
 	int first_cpu;
 
 	if (!mtrr_enabled())
 		return;
 
+	if (system_state < SYSTEM_RUNNING) {
+		static bool mtrr_saved;
+		if (!mtrr_saved) {
+			mtrr_save_fixed_ranges(NULL);
+			mtrr_saved = true;
+		}
+		return;
+	}
+
 	first_cpu = cpumask_first(cpu_online_mask);
 	smp_call_function_single(first_cpu, mtrr_save_fixed_ranges, NULL, 1);
 }


Download attachment "smime.p7s" of type "application/pkcs7-signature" (5965 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ