public inbox for linux-efi@vger.kernel.org
 help / color / mirror / Atom feed
From: Borislav Petkov <bp-l3A5Bk7waGM@public.gmane.org>
To: Alex Thorlton <athorlton-sJ/iWh9BUns@public.gmane.org>
Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Matt Fleming
	<matt-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org>,
	Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>,
	Ingo Molnar <mingo-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
	"H. Peter Anvin" <hpa-YMNOUZJC4hwAvxtiuMwx3w@public.gmane.org>,
	x86-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
	linux-efi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Russ Anderson <rja-sJ/iWh9BUns@public.gmane.org>,
	Dimitri Sivanich <sivanich-sJ/iWh9BUns@public.gmane.org>,
	mike travis <travis-sJ/iWh9BUns@public.gmane.org>,
	Nathan Zimmer <nzimmer-sJ/iWh9BUns@public.gmane.org>
Subject: Re: [BUG] x86/efi: MMRs no longer properly mapped after switch to isolated page table
Date: Tue, 3 May 2016 11:48:20 +0200	[thread overview]
Message-ID: <20160503094820.GA27503@pd.tnic> (raw)
In-Reply-To: <20160503001036.GX113599-7ppMa7wkY9tKToyKb8PD+Zs2JHu2awxn0E9HWUfgJXw@public.gmane.org>

On Mon, May 02, 2016 at 07:10:36PM -0500, Alex Thorlton wrote:
> +#define uv_call_virt(f, args...) \
> +({                                                                     \
> +       efi_status_t __s;                                               \
> +       kernel_fpu_begin();                                             \
> +       __s = ((efi_##f##_t __attribute__((regparm(0)))*)               \
> +               f)(args);                                               \
> +       kernel_fpu_end();                                               \
> +       __s;                                                            \
> +})

Right, can you use the EFI-ones in
drivers/firmware/efi/runtime-wrappers.c directly?

 (So they're going to land there, I'm staring at latest -tip and those calls
  have become all fancy now:

#define efi_call_virt(f, args...)                                       \
({                                                                      \
        efi_status_t __s;                                               \
        unsigned long flags;                                            \
        arch_efi_call_virt_setup();                                     \
        local_save_flags(flags);                                        \
        __s = arch_efi_call_virt(f, args);                              \
        efi_call_virt_check_flags(flags, __stringify(f));               \
        arch_efi_call_virt_teardown();                                  \
        __s;                                                            \
})

with efi_call_virt_check_flags() checking for IRQ flags corruption... And so
on, but that's beside the point... )

> +
>  /* Use this macro if your virtual call does not return any value */
>  #define __efi_call_virt(f, args...) \
>  ({                                                                     \
> @@ -104,6 +114,32 @@ struct efi_scratch {
>         __s;                                                            \
>  })
>  
> +#define uv_call_virt(f, ...)                                           \
> +({                                                                     \
> +       efi_status_t __s;                                               \
> +                                                                       \
> +       efi_sync_low_kernel_mappings();                                 \
> +       preempt_disable();                                              \
> +       __kernel_fpu_begin();                                           \
> +                                                                       \
> +       if (efi_scratch.use_pgd) {                                      \
> +               efi_scratch.prev_cr3 = read_cr3();                      \
> +               write_cr3((unsigned long)efi_scratch.efi_pgt);          \
> +               __flush_tlb_all();                                      \
> +       }                                                               \
> +                                                                       \
> +       __s = efi_call((void *)f, __VA_ARGS__); \
> +                                                                       \
> +       if (efi_scratch.use_pgd) {                                      \
> +               write_cr3(efi_scratch.prev_cr3);                        \
> +               __flush_tlb_all();                                      \
> +       }                                                               \
> +                                                                       \
> +       __kernel_fpu_end();                                             \
> +       preempt_enable();                                               \
> +       __s;                                                            \
> +})
> +
>  /*
>   * All X86_64 virt calls return non-void values. Thus, use non-void call for
>   * virt calls that would be void on X86_32.
> 
> diff --git a/arch/x86/platform/uv/bios_uv.c b/arch/x86/platform/uv/bios_uv.c
> index 1584cbe..6e99f81 100644
> --- a/arch/x86/platform/uv/bios_uv.c
> +++ b/arch/x86/platform/uv/bios_uv.c
> @@ -39,8 +39,8 @@ s64 uv_bios_call(enum uv_bios_cmd which, u64 a1, u64 a2, u64 a3, u64 a4, u64 a5)
>                  */
>                 return BIOS_STATUS_UNIMPLEMENTED;
>  
> -       ret = efi_call((void *)__va(tab->function), (u64)which,
> -                       a1, a2, a3, a4, a5);
> +       ret = uv_call_virt(tab->function, (u64)which, a1, a2, a3, a4, a5);
> +

That could be simply

		efi_call_virt(tab->function, ...)

methinks.

>         return ret;
>  }
>  EXPORT_SYMBOL_GPL(uv_bios_call);
> --->8
> 
> Note that the only change I made to efi_call_virt was to change
> efi.systab->runtime->f to simply f in the efi_call line.  This works up
> until we try to do callbacks from a loaded module.  When we try that we
> hit this:
> 
> [   56.232086] BUG: unable to handle kernel paging request at ffffffff8106148f
> [   56.239880] IP: [<fffffffedbb408ce>] 0xfffffffedbb408ce
> [   56.245721] PGD 8698e0067 PUD 1a08063 PMD 10001e1 

PMD looks ok to me.

Have you tried CONFIG_EFI_PGT_DUMP ? It will dump to dmesg so you might
be able to spot stuff.

Also, you could dump them from debugfs *right* before loading the module
and then look at stuff.

Also 2, booting with efi=debug should give you how the EFI regions get
mapped.

...

> The bad paging request here appears to be on the:
> 
> if (efi_scratch.use_pgd)
> 
> Line of uv_call_virt.  It looks like it's having trouble accessing the
> efi_scratch struct using the EFI page table.  I'm not sure why this
> is an issue with callbacks from modules and not with the ones in
> uv_system_init and friends.

Just this one module or all modules doing EFI calls?

> I'll keep investigating the module issue.  Looks like we're getting
> closer to sorting this out!
> 
> Let me know if you have thoughts about the way I'm getting stuff
> working.  I'm thinking there's probably a better way to do this than by
> copying the whole efi_call_virt macro - this was a quick and dirty
> solution.

Yeah, try using the generic facilities. We should be able to accomodate
all users...

HTH.

-- 
Regards/Gruss,
    Boris.

SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
-- 

  parent reply	other threads:[~2016-05-03  9:48 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-27 15:41 [BUG] x86/efi: MMRs no longer properly mapped after switch to isolated page table Alex Thorlton
2016-04-27 18:23 ` Alex Thorlton
2016-04-27 22:51 ` Borislav Petkov
     [not found]   ` <20160427225122.GG21282-fF5Pk5pvG8Y@public.gmane.org>
2016-04-28  1:41     ` Alex Thorlton
     [not found]       ` <20160428014128.GF113599-7ppMa7wkY9tKToyKb8PD+Zs2JHu2awxn0E9HWUfgJXw@public.gmane.org>
2016-04-28 12:57         ` Borislav Petkov
2016-04-29 15:41           ` Alex Thorlton
     [not found]             ` <20160429154119.GI113599-7ppMa7wkY9tKToyKb8PD+Zs2JHu2awxn0E9HWUfgJXw@public.gmane.org>
2016-04-30 22:12               ` Matt Fleming
     [not found]                 ` <20160430221209.GO2839-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org>
2016-05-02 21:39                   ` Alex Thorlton
     [not found]                     ` <20160502213931.GT113599-7ppMa7wkY9tKToyKb8PD+Zs2JHu2awxn0E9HWUfgJXw@public.gmane.org>
2016-05-02 22:17                       ` Mike Travis
2016-05-09 21:55                       ` Matt Fleming
     [not found]                         ` <20160509215524.GQ2839-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org>
2016-05-10 17:35                           ` Alex Thorlton
2016-05-02 10:02               ` Borislav Petkov
     [not found]                 ` <20160502100222.GB25669-fF5Pk5pvG8Y@public.gmane.org>
2016-05-02 22:27                   ` Alex Thorlton
     [not found]                     ` <20160502222719.GW113599-7ppMa7wkY9tKToyKb8PD+Zs2JHu2awxn0E9HWUfgJXw@public.gmane.org>
2016-05-03  0:10                       ` Alex Thorlton
     [not found]                         ` <20160503001036.GX113599-7ppMa7wkY9tKToyKb8PD+Zs2JHu2awxn0E9HWUfgJXw@public.gmane.org>
2016-05-03  9:48                           ` Borislav Petkov [this message]
     [not found]                             ` <20160503094820.GA27503-fF5Pk5pvG8Y@public.gmane.org>
2016-05-03 18:47                               ` Alex Thorlton
     [not found]                                 ` <20160503184751.GE113599-7ppMa7wkY9tKToyKb8PD+Zs2JHu2awxn0E9HWUfgJXw@public.gmane.org>
2016-05-04 10:36                                   ` Borislav Petkov
     [not found]                                     ` <20160504103636.GA21554-fF5Pk5pvG8Y@public.gmane.org>
2016-05-04 16:32                                       ` Alex Thorlton
     [not found] ` <20160427154132.GB113599-7ppMa7wkY9tKToyKb8PD+Zs2JHu2awxn0E9HWUfgJXw@public.gmane.org>
2016-04-29  9:01   ` Matt Fleming
     [not found]     ` <20160429090115.GB2839-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org>
2016-04-29 15:45       ` Alex Thorlton

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=20160503094820.GA27503@pd.tnic \
    --to=bp-l3a5bk7wagm@public.gmane.org \
    --cc=athorlton-sJ/iWh9BUns@public.gmane.org \
    --cc=hpa-YMNOUZJC4hwAvxtiuMwx3w@public.gmane.org \
    --cc=linux-efi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=matt-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org \
    --cc=mingo-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=nzimmer-sJ/iWh9BUns@public.gmane.org \
    --cc=rja-sJ/iWh9BUns@public.gmane.org \
    --cc=sivanich-sJ/iWh9BUns@public.gmane.org \
    --cc=tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org \
    --cc=travis-sJ/iWh9BUns@public.gmane.org \
    --cc=x86-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.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