mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dave Hansen <dave.hansen@intel.com>
To: Naresh Kamboju <naresh.kamboju@linaro.org>,
	X86 ML <x86@kernel.org>, open list <linux-kernel@vger.kernel.org>,
	lkft-triage@lists.linaro.org,
	Linux Regressions <regressions@lists.linux.dev>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Arnd Bergmann <arnd@arndb.de>,
	Dan Carpenter <dan.carpenter@linaro.org>,
	Anders Roxell <anders.roxell@linaro.org>
Subject: Re: Bad FPU state detected at restore_fpregs_from_fpstate, reinitializing FPU registers. WARNING: at arch/x86/mm/extable.c:127 fixup_exception
Date: Thu, 13 Jun 2024 12:43:35 -0700	[thread overview]
Message-ID: <a984d174-0842-407f-8af9-ed1c506e442b@intel.com> (raw)
In-Reply-To: <CA+G9fYv57AhE8CX+T_-OP_yi8tzNXpzS_OGZvjyKKgMDKUN4UA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 338 bytes --]

Does this fix it?

I think moving the explicit 'struct fpu' out of task_struct took the
knowledge away from the compiler on how to keep the XSAVE buffer
aligned.  Once that happened, we ended up with unaligned XSAVE
operations and bad things happened.

Also, open-coding "task + sizeof(*task)" in three different places seems
suboptimal.

[-- Attachment #2: debug-32bit-fpregs.patch --]
[-- Type: text/x-patch, Size: 2502 bytes --]



---

 b/arch/x86/include/asm/processor.h |    7 ++++++-
 b/arch/x86/kernel/fpu/core.c       |   11 +++--------
 b/arch/x86/kernel/fpu/init.c       |    2 +-
 3 files changed, 10 insertions(+), 10 deletions(-)

diff -puN arch/x86/kernel/fpu/core.c~debug-32bit-fpregs arch/x86/kernel/fpu/core.c
--- a/arch/x86/kernel/fpu/core.c~debug-32bit-fpregs	2024-06-13 10:39:30.819589794 -0700
+++ b/arch/x86/kernel/fpu/core.c	2024-06-13 12:37:46.166450575 -0700
@@ -57,7 +57,7 @@ struct fpu *x86_task_fpu(struct task_str
 	if (WARN_ON_ONCE(task->flags & PF_KTHREAD))
 		return NULL;
 
-	return (void *)task + sizeof(*task);
+	return __x86_task_fpu(task);
 }
 #endif
 
@@ -594,13 +594,8 @@ static int update_fpu_shstk(struct task_
 int fpu_clone(struct task_struct *dst, unsigned long clone_flags, bool minimal,
 	      unsigned long ssp)
 {
-	/*
-	 * 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.
-	 */
-	struct fpu *dst_fpu = (void *)dst + sizeof(*dst);
+	/* 'dst' is partially built, disable debugging:  */
+	struct fpu *dst_fpu = __x86_task_fpu(dst);
 
 	BUILD_BUG_ON(sizeof(*dst) % SMP_CACHE_BYTES != 0);
 
diff -puN arch/x86/include/asm/processor.h~debug-32bit-fpregs arch/x86/include/asm/processor.h
--- a/arch/x86/include/asm/processor.h~debug-32bit-fpregs	2024-06-13 11:09:19.508181013 -0700
+++ b/arch/x86/include/asm/processor.h	2024-06-13 12:36:24.480086965 -0700
@@ -504,10 +504,15 @@ struct thread_struct {
 #endif
 };
 
+/* XSAVE requrires 64-byte alignment: */
+#define fpu_align(x) ALIGN(x, 64)
+
+#define __x86_task_fpu(task)	((struct fpu *)((void *)(task) + fpu_align(sizeof(*(task)))))
+
 #ifdef CONFIG_X86_DEBUG_FPU
 extern struct fpu *x86_task_fpu(struct task_struct *task);
 #else
-# define x86_task_fpu(task)	((struct fpu *)((void *)(task) + sizeof(*(task))))
+#define x86_task_fpu(task)	__x86_task_fpu(task)
 #endif
 
 /*
diff -puN arch/x86/kernel/fpu/init.c~debug-32bit-fpregs arch/x86/kernel/fpu/init.c
--- a/arch/x86/kernel/fpu/init.c~debug-32bit-fpregs	2024-06-13 11:55:22.597114454 -0700
+++ b/arch/x86/kernel/fpu/init.c	2024-06-13 12:39:15.924492560 -0700
@@ -158,7 +158,7 @@ static void __init fpu__init_task_struct
 {
 	int task_size = sizeof(struct task_struct);
 
-	task_size += sizeof(struct fpu);
+	task_size += fpu_align(sizeof(struct fpu));
 
 	/*
 	 * Subtract off the static size of the register state.
_

      reply	other threads:[~2024-06-13 19:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-12 11:56 Naresh Kamboju
2024-06-13 19:43 ` Dave Hansen [this message]

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=a984d174-0842-407f-8af9-ed1c506e442b@intel.com \
    --to=dave.hansen@intel.com \
    --cc=anders.roxell@linaro.org \
    --cc=arnd@arndb.de \
    --cc=bp@alien8.de \
    --cc=dan.carpenter@linaro.org \
    --cc=dave.hansen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkft-triage@lists.linaro.org \
    --cc=naresh.kamboju@linaro.org \
    --cc=peterz@infradead.org \
    --cc=regressions@lists.linux.dev \
    --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

all inboxes | Powered by JetHome®