2020-03-09 00:42:34

by Thomas Gleixner

[permalink] [raw]
Subject: [patch part-II V2 11/13] x86/speculation/mds: Mark mds_user_clear_cpu_buffers() __always_inline

Prevent the compiler from uninlining and creating traceable/probable
functions as this is invoked _after_ context tracking switched to
CONTEXT_USER and rcu idle.

Signed-off-by: Thomas Gleixner <[email protected]>
---
arch/x86/include/asm/nospec-branch.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

--- a/arch/x86/include/asm/nospec-branch.h
+++ b/arch/x86/include/asm/nospec-branch.h
@@ -319,7 +319,7 @@ DECLARE_STATIC_KEY_FALSE(mds_idle_clear)
* combination with microcode which triggers a CPU buffer flush when the
* instruction is executed.
*/
-static inline void mds_clear_cpu_buffers(void)
+static __always_inline void mds_clear_cpu_buffers(void)
{
static const u16 ds = __KERNEL_DS;

@@ -340,7 +340,7 @@ static inline void mds_clear_cpu_buffers
*
* Clear CPU buffers if the corresponding static key is enabled
*/
-static inline void mds_user_clear_cpu_buffers(void)
+static __always_inline void mds_user_clear_cpu_buffers(void)
{
if (static_branch_likely(&mds_user_clear))
mds_clear_cpu_buffers();


2020-03-10 13:51:06

by Alexandre Chartre

[permalink] [raw]
Subject: Re: [patch part-II V2 11/13] x86/speculation/mds: Mark mds_user_clear_cpu_buffers() __always_inline


On 3/8/20 11:24 PM, Thomas Gleixner wrote:
> Prevent the compiler from uninlining and creating traceable/probable
> functions as this is invoked _after_ context tracking switched to
> CONTEXT_USER and rcu idle.
>
> Signed-off-by: Thomas Gleixner <[email protected]>
> ---
> arch/x86/include/asm/nospec-branch.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> --- a/arch/x86/include/asm/nospec-branch.h
> +++ b/arch/x86/include/asm/nospec-branch.h
> @@ -319,7 +319,7 @@ DECLARE_STATIC_KEY_FALSE(mds_idle_clear)
> * combination with microcode which triggers a CPU buffer flush when the
> * instruction is executed.
> */
> -static inline void mds_clear_cpu_buffers(void)
> +static __always_inline void mds_clear_cpu_buffers(void)
> {
> static const u16 ds = __KERNEL_DS;
>
> @@ -340,7 +340,7 @@ static inline void mds_clear_cpu_buffers
> *
> * Clear CPU buffers if the corresponding static key is enabled
> */
> -static inline void mds_user_clear_cpu_buffers(void)
> +static __always_inline void mds_user_clear_cpu_buffers(void)
> {
> if (static_branch_likely(&mds_user_clear))
> mds_clear_cpu_buffers();
>

Reviewed-by: Alexandre Chartre <[email protected]>

I am just wondering if it would be worth defining a new function attribute to
identify functions which shouldn't be trace/probe more clearly. For example:

#define no_trace_and_probe __always_inline

static no_trace_and_probe void mds_user_clear_cpu_buffers(void)
{
...
}

I am just concerned that overtime we might forgot that a function is defined
__always_inline just because it shouldn't be traced/probed.

alex.

2020-03-10 16:40:26

by Thomas Gleixner

[permalink] [raw]
Subject: Re: [patch part-II V2 11/13] x86/speculation/mds: Mark mds_user_clear_cpu_buffers() __always_inline

Alexandre Chartre <[email protected]> writes:
> On 3/8/20 11:24 PM, Thomas Gleixner wrote:
>> -static inline void mds_user_clear_cpu_buffers(void)
>> +static __always_inline void mds_user_clear_cpu_buffers(void)
>> {
>> if (static_branch_likely(&mds_user_clear))
>> mds_clear_cpu_buffers();
>>
>
> Reviewed-by: Alexandre Chartre <[email protected]>
>
> I am just wondering if it would be worth defining a new function attribute to
> identify functions which shouldn't be trace/probe more clearly. For example:
>
> #define no_trace_and_probe __always_inline
>
> static no_trace_and_probe void mds_user_clear_cpu_buffers(void)
> {
> ...
> }
>
> I am just concerned that overtime we might forgot that a function is defined
> __always_inline just because it shouldn't be traced/probed.

True, for exactly that reason we are reconsidering the whole annotation
business by putting stuff into a separate section so we get tools
support for finding things which escape. See the discussion at:

https://lore.kernel.org/lkml/[email protected]/

Peter and I are working on this right now, so you might end up reviewing
this pile in different form yet another time :(

Thanks,

tglx