From: Sohil Mehta <sohil.mehta@intel.com>
To: Lijun Pan <lijun.pan@intel.com>,
Rick Edgecombe <rick.p.edgecombe@intel.com>, <tglx@linutronix.de>,
<mingo@redhat.com>, <bp@alien8.de>, <x86@kernel.org>,
<hpa@zytor.com>, <dave.hansen@linux.intel.com>, <luto@kernel.org>,
<peterz@infradead.org>
Cc: <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] x86: Use __fpu_invalidate_fpregs_state() in exec
Date: Fri, 18 Aug 2023 14:56:32 -0700 [thread overview]
Message-ID: <96d2a7b5-bb7a-01e7-fab0-d4874818dc64@intel.com> (raw)
In-Reply-To: <9e9c629f-eab0-6643-4e47-0a4b39e2a3f8@intel.com>
On 8/18/2023 12:35 PM, Lijun Pan wrote:
> So, I am thinking if it is more rigorous to have both
> (__cpu_invalidate_fpregs_state, __fpu_invalidate_fpregs_state)
> invalidated, similarly as fpregs_state_valid checks both conditions.
>
> code changes like below:
> diff --git a/arch/x86/kernel/fpu/context.h b/arch/x86/kernel/fpu/context.h
> index 958accf2ccf0..fd3304bed0a2 100644
> --- a/arch/x86/kernel/fpu/context.h
> +++ b/arch/x86/kernel/fpu/context.h
> @@ -19,8 +19,8 @@
> * FPU state for a task MUST let the rest of the kernel know that the
> * FPU registers are no longer valid for this task.
> *
> - * Either one of these invalidation functions is enough. Invalidate
> - * a resource you control: CPU if using the CPU for something else
> + * To be more rigorous and to prevent from future corner case, Invalidate
> + * both resources you control: CPU if using the CPU for something else
> * (with preemption disabled), FPU for the current task, or a task that
> * is prevented from running by the current task.
> */
This is a general comment in the header to guide multiple scenarios. I
am not sure if invalidating both would be feasible in all scenarios. For
example, in cases such as the fpu_idle_fpregs() there is no task fpu
available.
I think the current issue stems from the fact that the code in exec()
doesn't really control the CPU. It is mostly running with preemption
enabled which can cause the CPUs to change as described in Rick's
scenario. Thus clearing CPU1's FPU pointer in step 4 seems unnecessary.
An extra invalidation probably won't impact performance for such a rare
scenario. However, replacing it with __fpu_invalidate_fpregs_state() to
invalidate the task's fpu state looks correct to me.
Maybe, we can expand the comment above to specify exactly when a
particular invalidation is expected vs when both are expected.
> diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
> index 97a899bf98b9..08b9cef0e076 100644
> --- a/arch/x86/kernel/fpu/core.c
> +++ b/arch/x86/kernel/fpu/core.c
> @@ -725,6 +725,7 @@ static void fpu_reset_fpregs(void)
>
> fpregs_lock();
> fpu__drop(fpu);
> + __fpu_invalidate_fpregs_state(fpu);
> /*
> * This does not change the actual hardware registers. It just
> * resets the memory image and sets TIF_NEED_FPU_LOAD so a
>
> Thanks,
> Lijun
>
next prev parent reply other threads:[~2023-08-18 21:57 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-18 17:03 [PATCH] x86: Use __fpu_invalidate_fpregs_state() in exec Rick Edgecombe
2023-08-18 19:35 ` Lijun Pan
2023-08-18 21:56 ` Sohil Mehta [this message]
2023-08-24 0:04 ` Lijun Pan
2023-08-18 23:35 ` Sohil Mehta
2023-08-22 20:10 ` Sohil Mehta
2023-08-24 9:11 ` [tip: x86/urgent] x86/fpu: Invalidate FPU state correctly on exec() tip-bot2 for Rick Edgecombe
2023-08-24 15:22 ` Edgecombe, Rick P
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=96d2a7b5-bb7a-01e7-fab0-d4874818dc64@intel.com \
--to=sohil.mehta@intel.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=lijun.pan@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rick.p.edgecombe@intel.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.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