mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Miaohe Lin <linmiaohe@huawei.com>
To: Borislav Petkov <bp@alien8.de>
Cc: "x86@kernel.org" <x86@kernel.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	"tglx@linutronix.de" <tglx@linutronix.de>,
	"mingo@redhat.com" <mingo@redhat.com>,
	Dave Hansen <dave.hansen@linux.intel.com>, <hpa@zytor.com>
Subject: Re: [BUG Report] undefined reference to `convert_to_fxsr'
Date: Sat, 7 Jan 2023 10:10:18 +0800	[thread overview]
Message-ID: <d312c572-f232-a4e9-2ecc-023050528a29@huawei.com> (raw)
In-Reply-To: <Y7dZwWsiUfHKxN3S@zn.tnic>

On 2023/1/6 7:14, Borislav Petkov wrote:
> On Tue, Jan 03, 2023 at 11:05:01AM +0800, Miaohe Lin wrote:
>> Yes, it still reproduces in my working server. It might be the problem of gcc
>> version.
> 
> What is that compiler you're using? Where did you get the package from? Does it
> have some out-of-tree patches in it?

My compiler is gcc 7.3.0:

linux-rtfsc:/home/linmiaohe/linux # gcc --version
gcc (GCC) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

linux-rtfsc:/home/linmiaohe/linux #

And I cloned the code from https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git. It's a
clean git repo without applying any out-of-tree patch to it.

> 
>> I think it's because convert_to_fxsr() is only defined when CONFIG_X86_32 or
>> CONFIG_IA32_EMULATION is enabled.
> 
> No, convert_to_fxsr() is part of arch/x86/kernel/fpu/regset.c which is built-in
> unconditionally.
> 
> What happens is this here:
> 
> bool fpu__restore_sig(void __user *buf, int ia32_frame)
> 
> 	...
> 
>         } else {
>                 success = __fpu_restore_sig(buf, buf_fx, ia32_fxstate);
>         }
> 
> That ia32_fxstate is false because
> 
>         ia32_frame &= (IS_ENABLED(CONFIG_X86_32) ||
>                        IS_ENABLED(CONFIG_IA32_EMULATION));
> 
> 
> neither of those config items are set...
> 
>         /*
>          * Only FXSR enabled systems need the FX state quirk.
>          * FRSTOR does not need it and can use the fast path.
>          */
>         if (ia32_frame && use_fxsr()) {
>                 buf_fx = buf + sizeof(struct fregs_state);
>                 size += sizeof(struct fregs_state);
>                 ia32_fxstate = true;
> 		^^^^^^^^^^^^^^^^^^^
> 
> ... so this doesn't happen.
> 
>         }
> 
> Then, in __fpu_restore_sig() you have:
> 
>         if (likely(!ia32_fxstate)) {
>                 /* Restore the FPU registers directly from user memory. */
>                 return restore_fpregs_from_user(buf_fx, user_xfeatures, fx_only,
>                                                 state_size);
>         }
> 
> and since ia32_fxstate is false, we return here, the compiler sees that
> everything behind that code is dead code and eliminates it.

Many thanks for your explanation! It's really helpful. I checked generated asm code
and I found calling to convert_to_fxsr is not eliminated as expected:

objdump -S arch/x86/kernel/fpu/signal.o

 3fc:   e9 00 00 00 00          jmpq   401 <__fpu_restore_sig+0x401>
                        fpregs->xsave.header.xfeatures |= XFEATURE_MASK_FPSSE;
 401:   48 83 8d 40 02 00 00    orq    $0x3,0x240(%rbp)
 408:   03
        convert_to_fxsr(&fpregs->fxsave, &env);
	^^^^^^^^^^^^^^^
 409:   48 8d 74 24 10          lea    0x10(%rsp),%rsi

linux-rtfsc:/home/linmiaohe/linux # objdump -S arch/x86/kernel/fpu/signal.o | grep convert_to_fxsr
	convert_to_fxsr(&fpregs->fxsave, &env);
linux-rtfsc:/home/linmiaohe/linux #

And if I compile the code with below patch, convert_to_fxsr is eliminated:

linux-rtfsc:/home/linmiaohe/linux # objdump -S arch/x86/kernel/fpu/signal.o | grep convert_to_fxsr
linux-rtfsc:/home/linmiaohe/linux #

diff --git a/arch/x86/include/asm/fpu/signal.h b/arch/x86/include/asm/fpu/signal.h
index 611fa41711af..77ea052a8967 100644
--- a/arch/x86/include/asm/fpu/signal.h
+++ b/arch/x86/include/asm/fpu/signal.h
@@ -20,8 +20,14 @@

 extern void convert_from_fxsr(struct user_i387_ia32_struct *env,
                              struct task_struct *tsk);
+#if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
 extern void convert_to_fxsr(struct fxregs_state *fxsave,
                            const struct user_i387_ia32_struct *env);
+#else
+static inline void convert_to_fxsr(struct fxregs_state *fxsave,
+                                  const struct user_i387_ia32_struct *env)
+{}
+#endif

 unsigned long
 fpu__alloc_mathframe(unsigned long sp, int ia32_frame,
-- 
2.27.0

> 
> Your compiler doesn't, apparently.
> 
> It does remove it from regset.c, though, as it sees it is an unused function,
> which leads to this undefined reference.
> 
> So it looks like a funky compiler to me...

It seems another issue with old compiler. Sigh... :(

Thanks,
Miaohe Lin


  reply	other threads:[~2023-01-07  2:10 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-28 12:31 Miaohe Lin
2022-12-28 12:39 ` Borislav Petkov
2022-12-29  1:50   ` Miaohe Lin
2022-12-29 15:17     ` Borislav Petkov
2022-12-30  1:49       ` Miaohe Lin
2022-12-30 11:16         ` Borislav Petkov
2023-01-03  3:05           ` Miaohe Lin
2023-01-05 23:14             ` Borislav Petkov
2023-01-07  2:10               ` Miaohe Lin [this message]
2023-01-07 11:07                 ` Borislav Petkov
2023-01-09  1:48                   ` Miaohe Lin
2023-01-09 11:49                     ` Borislav Petkov
2023-01-09 12:32                       ` Miaohe Lin
2023-01-09 17:09                         ` Nathan Chancellor
2023-01-10  1:13                           ` Miaohe Lin
2022-12-30 12:20         ` Borislav Petkov

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=d312c572-f232-a4e9-2ecc-023050528a29@huawei.com \
    --to=linmiaohe@huawei.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.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

all inboxes | Powered by JetHome®