linux-efi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Lutomirski <luto@amacapital.net>
To: Arvind Sankar <nivedita@alum.mit.edu>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	Andy Lutomirski <luto@kernel.org>, Ingo Molnar <mingo@redhat.com>,
	Ard Biesheuvel <ardb@kernel.org>,
	linux-efi <linux-efi@vger.kernel.org>,
	Hans de Goede <hdegoede@redhat.com>
Subject: Re: [PATCH 1/3] efi/x86: simplify 64-bit EFI firmware call wrapper
Date: Sat, 28 Dec 2019 13:29:00 +0800	[thread overview]
Message-ID: <F8539C65-87F2-460C-A3CB-474C4D1BC08B@amacapital.net> (raw)
In-Reply-To: <20191228044357.GA1194635@rani.riverdale.lan>


> On Dec 28, 2019, at 12:44 PM, Arvind Sankar <nivedita@alum.mit.edu> wrote:
> 

>> 
>> Does the UEFI spec explicitly state what FP state can be used by the
>> EFI functions?
> 
> For 32-bit, it requires the following for boot services and runtime
> services:
> 
> * Direction flag in EFLAGs clear

Check.

> * 4 KiB, or more, of available stack space

There ought to be.

> * The stack must be 16-byte aligned

Nope. The asm needs to do this for runtime services. The kernel runs with 8-byte stack alignment.

> * Floating-point control word must be initialized to 0x027F (all exceptions masked, double-
>  precision, round-to-nearest)

Ingo, surely kernel_fpu_begin() does this.  But I can’t find any code that does this. Please tell me I’m just missing it because I’m on my phone.

Presumably the code ought to optimize it by saving regs, then checking for unexpected values, then doing FNINIT and STMXCSR if the state is bad.

> * Multimedia-extensions control word (if supported) must be initialized to 0x1F80 (all
>  exceptions masked, round-to-nearest, flush to zero for masked underflow)

Ditto.

> * CR0.EM must be zero
> * CR0.TS must be zero

Check, on modern kernels anyway.

> 
> We don't actually align the stack for 32-bit mode before calling, do we?
> 
> No FP registers are clobbered except the floating point status register.

I don’t believe this for a minute :).

> 
> For 64-bit:
> * Direction flag in EFLAGs clear
> * 4 KiB, or more, of available stack space

Check.

> * The stack must be 16-byte aligned

Nope. We need to align it. Does the EFI runtime service code do this?

> * Floating-point control word must be initialized to 0x037F (all exceptions masked, double-
>  extended-precision, round-to-nearest)
> * Multimedia-extensions control word (if supported) must be initialized to 0x1F80 (all exceptions
>  masked, round-to-nearest, flush to zero for masked underflow)

See above.

> * CR0.EM must be zero
> * CR0.TS must be zero
> 
> xmm0-5 (and the FP status register) may be clobbered, the rest of the FP
> registers are preserved.

Seems reasonable.

  reply	other threads:[~2019-12-28  5:29 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-26 15:14 [PATCH 0/3] efi/x86: clean up and simplify runtime call wrappers Ard Biesheuvel
2019-12-26 15:14 ` [PATCH 1/3] efi/x86: simplify 64-bit EFI firmware call wrapper Ard Biesheuvel
2019-12-27  2:42   ` Andy Lutomirski
2019-12-27 17:51   ` Arvind Sankar
2019-12-27 18:08     ` Arvind Sankar
2019-12-27 18:13       ` Ard Biesheuvel
2019-12-28  3:25         ` Andy Lutomirski
2019-12-28  4:43           ` Arvind Sankar
2019-12-28  5:29             ` Andy Lutomirski [this message]
2019-12-28  6:35               ` Arvind Sankar
2019-12-28  7:03                 ` Andy Lutomirski
2019-12-28  8:51                   ` Ard Biesheuvel
2019-12-28  9:00                     ` Andy Lutomirski
2019-12-28  9:27                       ` Ard Biesheuvel
2019-12-26 15:14 ` [PATCH 2/3] efi/x86: simplify i386 efi_call_phys() " Ard Biesheuvel
2019-12-26 15:14 ` [PATCH 3/3] efi/x86: simplify mixed mode " Ard Biesheuvel
2019-12-27  2:56   ` Andy Lutomirski
2019-12-27  8:04     ` Ard Biesheuvel
2019-12-27  4:34   ` Arvind Sankar
2019-12-27  8:05     ` Ard Biesheuvel
2019-12-27 12:52       ` Arvind Sankar

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=F8539C65-87F2-460C-A3CB-474C4D1BC08B@amacapital.net \
    --to=luto@amacapital.net \
    --cc=ard.biesheuvel@linaro.org \
    --cc=ardb@kernel.org \
    --cc=hdegoede@redhat.com \
    --cc=linux-efi@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=nivedita@alum.mit.edu \
    /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).