linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: Peter Zijlstra <peterz@infradead.org>
Cc: linux-kernel@vger.kernel.org,
	Andy Lutomirski <luto@amacapital.net>,
	Dave Hansen <dave@sr71.net>, Brian Gerst <brgerst@gmail.com>,
	Borislav Petkov <bp@alien8.de>, "H . Peter Anvin" <hpa@zytor.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Oleg Nesterov <oleg@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	"Chang S . Bae" <chang.seok.bae@intel.com>,
	Andy Lutomirski <luto@kernel.org>,
	Fenghua Yu <fenghua.yu@intel.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Uros Bizjak <ubizjak@gmail.com>
Subject: [PATCH] x86/fpu: Clarify FPU context cacheline alignment
Date: Thu, 10 Apr 2025 12:54:58 +0200	[thread overview]
Message-ID: <Z_ejggklB5-IWB5W@gmail.com> (raw)
In-Reply-To: <20250410103057.GE30687@noisy.programming.kicks-ass.net>


* Peter Zijlstra <peterz@infradead.org> wrote:

> On Thu, Apr 10, 2025 at 12:10:56PM +0200, Ingo Molnar wrote:
> > 
> > * Peter Zijlstra <peterz@infradead.org> wrote:
> > 
> > > On Wed, Apr 09, 2025 at 11:11:23PM +0200, Ingo Molnar wrote:
> > > 
> > > > diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
> > > > index 5ea7e5d2c4de..b7f7c9c83409 100644
> > > > --- a/arch/x86/include/asm/processor.h
> > > > +++ b/arch/x86/include/asm/processor.h
> > > > @@ -514,12 +514,9 @@ struct thread_struct {
> > > >  
> > > >  	struct thread_shstk	shstk;
> > > >  #endif
> > > > -
> > > > -	/* Floating point and extended processor state */
> > > > -	struct fpu		*fpu;
> > > >  };
> > > >  
> > > > -#define x86_task_fpu(task) ((task)->thread.fpu)
> > > > +#define x86_task_fpu(task)	((struct fpu *)((void *)(task) + sizeof(*(task))))
> > > 
> > > Doesn't our FPU state need to be cacheline aligned?
> > 
> > Yeah, and we do have a check for that:
> > 
> > +       BUILD_BUG_ON(sizeof(*dst) % SMP_CACHE_BYTES != 0);
> 
> Ah, missed that. Clearly I need to improve my reading skillz :-)

Admittedly it's written a bit obtusely - how about the patch below?

Thanks,

	Ingo

============================>
From: Ingo Molnar <mingo@kernel.org>
Date: Thu, 10 Apr 2025 12:52:16 +0200
Subject: [PATCH] x86/fpu: Clarify FPU context cacheline alignment

Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Uros Bizjak <ubizjak@gmail.com>
---
 arch/x86/kernel/fpu/core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index d0a45f6492cb..3a19877a314e 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -607,7 +607,8 @@ int fpu_clone(struct task_struct *dst, unsigned long clone_flags, bool minimal,
 	 * We allocate the new FPU structure right after the end of the task struct.
 	 * task allocation size already took this into account.
 	 *
-	 * This is safe because task_struct size is a multiple of cacheline size.
+	 * This is safe because task_struct size is a multiple of cacheline size,
+	 * thus x86_task_fpu() will always be cacheline aligned as well.
 	 */
 	struct fpu *dst_fpu = (void *)dst + sizeof(*dst);
 

  reply	other threads:[~2025-04-10 10:55 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-09 21:11 [PATCH -v5 0/8] sched: Make task_struct::thread constant size, x86/fpu: Remove thread::fpu Ingo Molnar
2025-04-09 21:11 ` [PATCH 1/8] x86/fpu: Introduce the x86_task_fpu() helper method Ingo Molnar
2025-04-14  7:34   ` [tip: x86/merge] " tip-bot2 for Ingo Molnar
2025-04-09 21:11 ` [PATCH 2/8] x86/fpu: Convert task_struct::thread.fpu accesses to use x86_task_fpu() Ingo Molnar
2025-04-14  7:34   ` [tip: x86/merge] " tip-bot2 for Ingo Molnar
2025-04-09 21:11 ` [PATCH 3/8] x86/fpu: Make task_struct::thread constant size Ingo Molnar
2025-04-14  7:34   ` [tip: x86/merge] " tip-bot2 for Ingo Molnar
2025-04-09 21:11 ` [PATCH 4/8] x86/fpu: Remove the thread::fpu pointer Ingo Molnar
2025-04-10  7:39   ` Peter Zijlstra
2025-04-10 10:10     ` Ingo Molnar
2025-04-10 10:30       ` Peter Zijlstra
2025-04-10 10:54         ` Ingo Molnar [this message]
2025-04-14  7:34           ` [tip: x86/merge] x86/fpu: Clarify FPU context cacheline alignment tip-bot2 for Ingo Molnar
2025-04-10 10:51       ` [PATCH 4/8] x86/fpu: Remove the thread::fpu pointer Ingo Molnar
2025-04-10 14:04       ` Oleg Nesterov
2025-04-14  7:34   ` [tip: x86/merge] " tip-bot2 for Ingo Molnar
2025-04-09 21:11 ` [PATCH 5/8] x86/fpu: Push 'fpu' pointer calculation into the fpu__drop() call Ingo Molnar
2025-04-14  7:34   ` [tip: x86/merge] " tip-bot2 for Ingo Molnar
2025-04-09 21:11 ` [PATCH 6/8] x86/fpu: Make sure x86_task_fpu() doesn't get called for PF_KTHREAD|PF_USER_WORKER tasks during exit Ingo Molnar
2025-04-11 15:22   ` Chang S. Bae
2025-04-12  8:37     ` Ingo Molnar
2025-04-14  7:34   ` [tip: x86/merge] " tip-bot2 for Ingo Molnar
2025-04-09 21:11 ` [PATCH 7/8] x86/fpu: Remove init_task FPU state dependencies, add debugging warning for PF_KTHREAD tasks Ingo Molnar
2025-04-14  7:34   ` [tip: x86/merge] " tip-bot2 for Ingo Molnar
2025-04-09 21:11 ` [PATCH 8/8] x86/fpu: Use 'fpstate' variable names consistently Ingo Molnar
2025-04-14  7:34   ` [tip: x86/merge] " tip-bot2 for Ingo Molnar
2025-04-22 16:11 ` [PATCH -v5 0/8] sched: Make task_struct::thread constant size, x86/fpu: Remove thread::fpu Oleg Nesterov
2025-04-22 20:09   ` Ingo Molnar
2025-04-22 17:01 ` question about switch_fpu_prepare/switch_fpu_finish Oleg Nesterov
2025-04-22 20:11   ` Ingo Molnar
2025-05-03 14:38 ` [PATCH tip/x86/fpu 1/6] x86/fpu: simplify the switch_fpu_prepare() + switch_fpu_finish() logic Oleg Nesterov
2025-05-04  8:54   ` [tip: x86/fpu] x86/fpu: Simplify " tip-bot2 for Oleg Nesterov
2025-05-03 14:38 ` [PATCH tip/x86/fpu 2/6] x86/fpu: kill x86_init_fpu Oleg Nesterov
2025-05-04  8:54   ` [tip: x86/fpu] x86/fpu: Remove x86_init_fpu tip-bot2 for Oleg Nesterov
2025-05-03 14:38 ` [PATCH tip/x86/fpu 3/6] x86/fpu: kill DEFINE_EVENT(x86_fpu, x86_fpu_copy_src) Oleg Nesterov
2025-05-04  8:54   ` [tip: x86/fpu] x86/fpu: Remove " tip-bot2 for Oleg Nesterov
2025-05-03 14:38 ` [PATCH tip/x86/fpu 4/6] x86/fpu: arch_dup_task_struct: always use memcpy_and_pad() Oleg Nesterov
2025-05-04  8:54   ` [tip: x86/fpu] x86/fpu: Always use memcpy_and_pad() in arch_dup_task_struct() tip-bot2 for Oleg Nesterov
2025-05-03 14:38 ` [PATCH tip/x86/fpu 5/6] x86/fpu: fpu__drop: check TIF_NEED_FPU_LOAD instead of PF_KTHREAD|PF_USER_WORKER Oleg Nesterov
2025-05-04  8:54   ` [tip: x86/fpu] x86/fpu: Check TIF_NEED_FPU_LOAD instead of PF_KTHREAD|PF_USER_WORKER in fpu__drop() tip-bot2 for Oleg Nesterov
2025-05-03 14:39 ` [PATCH tip/x86/fpu 6/6] x86/fpu: shift fpregs_assert_state_consistent() from arch_exit_work() to its caller Oleg Nesterov
2025-05-04  8:36   ` Ingo Molnar
2025-05-04  8:54   ` [tip: x86/fpu] x86/fpu: Shift " tip-bot2 for Oleg Nesterov

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=Z_ejggklB5-IWB5W@gmail.com \
    --to=mingo@kernel.org \
    --cc=bp@alien8.de \
    --cc=brgerst@gmail.com \
    --cc=chang.seok.bae@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=dave@sr71.net \
    --cc=fenghua.yu@intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=luto@kernel.org \
    --cc=oleg@redhat.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=ubizjak@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).