[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <c98e68f0-e5e2-482d-9a64-ad8164e4bae8@intel.com>
Date: Mon, 3 Nov 2025 12:45:35 -0800
From: Dave Hansen <dave.hansen@...el.com>
To: Pawan Gupta <pawan.kumar.gupta@...ux.intel.com>, x86@...nel.org,
"H. Peter Anvin" <hpa@...or.com>, Josh Poimboeuf <jpoimboe@...nel.org>,
David Kaplan <david.kaplan@....com>, Sean Christopherson
<seanjc@...gle.com>, Paolo Bonzini <pbonzini@...hat.com>,
Borislav Petkov <bp@...en8.de>, Dave Hansen <dave.hansen@...ux.intel.com>
Cc: linux-kernel@...r.kernel.org, kvm@...r.kernel.org,
Asit Mallick <asit.k.mallick@...el.com>, Tao Zhang <tao1.zhang@...el.com>
Subject: Re: [PATCH v3 3/3] x86/vmscape: Remove LFENCE from BHB clearing long
loop
On 10/27/25 16:43, Pawan Gupta wrote:
> Long loop is used to clear the branch history when switching from a guest
> to host userspace. The LFENCE barrier is not required in this case as ring
> transition itself acts as a barrier.
>
> Move the prologue, LFENCE and epilogue out of __CLEAR_BHB_LOOP macro to
> allow skipping the LFENCE in the long loop variant. Rename the long loop
> function to clear_bhb_long_loop_no_barrier() to reflect the change.
Too. Much. Assembly.
Is there a reason we can't do more of this in C? Can we have _one_
assembly function, please? One that takes the loop counts? No macros, no
duplication functions. Just one:
void __clear_bhb_loop(int inner, int outer);
Then we have sensible code that looks like this:
void clear_bhb_loop()
{
__clear_bhb_loop(inner, outer);
lfence();
}
void clear_bhb_loop_nofence()
{
__clear_bhb_loop(inner, outer);
}
We don't need a short and a long *version*. We just have one function
(or pair of functions) that gets called that works everywhere.
Actually, if you just used global variables and called the assembly one:
extern void clear_bhb_loop_nofence();
then the other implementation would just be:
void clear_bhb_loop()
{
__clear_bhb_loop(inner, outer);
lfence();
}
Then we have *ONE* assembly function instead of four.
Right? What am I missing?
Does the LFENCE *need* to be before that last pop and RET?
Powered by blists - more mailing lists