kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [kvm-unit-tests PATCH v1] x86: efi: set up the IDT before accessing MSRs.
@ 2022-08-23  9:43 Vasant Karasulli
  2022-08-25 21:51 ` Sean Christopherson
  0 siblings, 1 reply; 4+ messages in thread
From: Vasant Karasulli @ 2022-08-23  9:43 UTC (permalink / raw)
  To: kvm
  Cc: seanjc, Thomas.Lendacky, bp, erdemaktas, jroedel, marcorr,
	pbonzini, rientjes, varad.gautam, zxwang42, Vasant Karasulli

Reading or writing MSR_IA32_APICBASE is typically an intercepted
operation and causes #VC exception when the test is launched as
an SEV-ES guest.

So calling pre_boot_apic_id() and reset_apic() before the IDT is
set up in setup_idt() and load_idt() might cause problems.

Hence move percpu data setup and reset_apic() call after
setup_idt() and load_idt().

Fixes: 3c50214c97f173f5e0f82c7f248a7c62707d8748 (x86: efi: Provide percpu storage)
Signed-off-by: Vasant Karasulli <vkarasulli@suse.de>
---
 lib/x86/setup.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/lib/x86/setup.c b/lib/x86/setup.c
index 7df0256..712e292 100644
--- a/lib/x86/setup.c
+++ b/lib/x86/setup.c
@@ -192,8 +192,6 @@ static void setup_segments64(void)
 	write_gs(KERNEL_DS);
 	write_ss(KERNEL_DS);

-	/* Setup percpu base */
-	wrmsr(MSR_GS_BASE, (u64)&__percpu_data[pre_boot_apic_id()]);

 	/*
 	 * Update the code segment by putting it on the stack before the return
@@ -322,7 +320,7 @@ efi_status_t setup_efi(efi_bootinfo_t *efi_bootinfo)
 		}
 		return status;
 	}
-
+
 	status = setup_rsdp(efi_bootinfo);
 	if (status != EFI_SUCCESS) {
 		printf("Cannot find RSDP in EFI system table\n");
@@ -344,14 +342,20 @@ efi_status_t setup_efi(efi_bootinfo_t *efi_bootinfo)
 	}

 	setup_gdt_tss();
-	/*
-	 * GS.base, which points at the per-vCPU data, must be configured prior
-	 * to resetting the APIC, which sets the per-vCPU APIC ops.
-	 */
 	setup_segments64();
-	reset_apic();
 	setup_idt();
 	load_idt();
+	/*
+	 * Load GS.base with the per-vCPU data.  This must be done after
+	 * loading the IDT as reading the APIC ID may #VC when running
+	 * as an SEV-ES guest
+	 */
+	wrmsr(MSR_GS_BASE, (u64)&__percpu_data[pre_boot_apic_id()]);
+	/*
+	 * Resetting the APIC sets the per-vCPU APIC ops and so must be
+	 * done after loading GS.base with the per-vCPU data.
+	 */
+	reset_apic();
 	mask_pic_interrupts();
 	setup_page_table();
 	enable_apic();
--
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [kvm-unit-tests PATCH v1] x86: efi: set up the IDT before accessing MSRs.
  2022-08-23  9:43 [kvm-unit-tests PATCH v1] x86: efi: set up the IDT before accessing MSRs Vasant Karasulli
@ 2022-08-25 21:51 ` Sean Christopherson
  2022-10-13 13:40   ` Vasant Karasulli
  0 siblings, 1 reply; 4+ messages in thread
From: Sean Christopherson @ 2022-08-25 21:51 UTC (permalink / raw)
  To: Vasant Karasulli
  Cc: kvm, Thomas.Lendacky, bp, erdemaktas, jroedel, marcorr, pbonzini,
	rientjes, varad.gautam, zxwang42

On Tue, Aug 23, 2022, Vasant Karasulli wrote:
> Reading or writing MSR_IA32_APICBASE is typically an intercepted
> operation and causes #VC exception when the test is launched as
> an SEV-ES guest.
> 
> So calling pre_boot_apic_id() and reset_apic() before the IDT is
> set up in setup_idt() and load_idt() might cause problems.
> 
> Hence move percpu data setup and reset_apic() call after
> setup_idt() and load_idt().
> 
> Fixes: 3c50214c97f173f5e0f82c7f248a7c62707d8748 (x86: efi: Provide percpu storage)
> Signed-off-by: Vasant Karasulli <vkarasulli@suse.de>
> ---

Reviewed-by: Sean Christopherson <seanjc@google.com>

>  lib/x86/setup.c | 20 ++++++++++++--------
>  1 file changed, 12 insertions(+), 8 deletions(-)
> 
> diff --git a/lib/x86/setup.c b/lib/x86/setup.c
> index 7df0256..712e292 100644
> --- a/lib/x86/setup.c
> +++ b/lib/x86/setup.c
> @@ -192,8 +192,6 @@ static void setup_segments64(void)
>  	write_gs(KERNEL_DS);
>  	write_ss(KERNEL_DS);
> 
> -	/* Setup percpu base */
> -	wrmsr(MSR_GS_BASE, (u64)&__percpu_data[pre_boot_apic_id()]);
> 
>  	/*
>  	 * Update the code segment by putting it on the stack before the return
> @@ -322,7 +320,7 @@ efi_status_t setup_efi(efi_bootinfo_t *efi_bootinfo)
>  		}
>  		return status;
>  	}
> -
> +

Huh.  This causes a conflict for me.  My local repo has a tab here that is
presumably being removed, but this patch doesn't have anything.  If I manually
add back the tab, all is well.  I suspect your client may be stripping trailing
whitespace.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [kvm-unit-tests PATCH v1] x86: efi: set up the IDT before accessing MSRs.
  2022-08-25 21:51 ` Sean Christopherson
@ 2022-10-13 13:40   ` Vasant Karasulli
  2022-10-21 20:45     ` Sean Christopherson
  0 siblings, 1 reply; 4+ messages in thread
From: Vasant Karasulli @ 2022-10-13 13:40 UTC (permalink / raw)
  To: Sean Christopherson; +Cc: kvm

Hi Sean,

> Reviewed-by: Sean Christopherson <seanjc@google.com>
>
> >  lib/x86/setup.c | 20 ++++++++++++--------
> >  1 file changed, 12 insertions(+), 8 deletions(-)
> >
> > diff --git a/lib/x86/setup.c b/lib/x86/setup.c
> > index 7df0256..712e292 100644
> > --- a/lib/x86/setup.c
> > +++ b/lib/x86/setup.c
> > @@ -192,8 +192,6 @@ static void setup_segments64(void)
> >  	write_gs(KERNEL_DS);
> >  	write_ss(KERNEL_DS);
> >
> > -	/* Setup percpu base */
> > -	wrmsr(MSR_GS_BASE, (u64)&__percpu_data[pre_boot_apic_id()]);
> >
> >  	/*
> >  	 * Update the code segment by putting it on the stack before the return
> > @@ -322,7 +320,7 @@ efi_status_t setup_efi(efi_bootinfo_t *efi_bootinfo)
> >  		}
> >  		return status;
> >  	}
> > -
> > +
>
> Huh.  This causes a conflict for me.  My local repo has a tab here that is
> presumably being removed, but this patch doesn't have anything.  If I manually
> add back the tab, all is well.  I suspect your client may be stripping trailing
> whitespace.

Yes, I think my client was stripping trailing whitespaces. Do you want me
to send a new version of the patch with that formatting?


Thanks,
Vasant Karasulli
Kernel generalist
www.suse.com<http://www.suse.com>
[https://www.suse.com/assets/img/social-platforms-suse-logo.png]<http://www.suse.com/>
SUSE - Open Source Solutions for Enterprise Servers & Cloud<http://www.suse.com/>
Modernize your infrastructure with SUSE Linux Enterprise servers, cloud technology for IaaS, and SUSE's software-defined storage.
www.suse.com


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [kvm-unit-tests PATCH v1] x86: efi: set up the IDT before accessing MSRs.
  2022-10-13 13:40   ` Vasant Karasulli
@ 2022-10-21 20:45     ` Sean Christopherson
  0 siblings, 0 replies; 4+ messages in thread
From: Sean Christopherson @ 2022-10-21 20:45 UTC (permalink / raw)
  To: Vasant Karasulli; +Cc: kvm

On Thu, Oct 13, 2022, Vasant Karasulli wrote:
> Hi Sean,
> 
> > Reviewed-by: Sean Christopherson <seanjc@google.com>
> >
> > >  lib/x86/setup.c | 20 ++++++++++++--------
> > >  1 file changed, 12 insertions(+), 8 deletions(-)
> > >
> > > diff --git a/lib/x86/setup.c b/lib/x86/setup.c
> > > index 7df0256..712e292 100644
> > > --- a/lib/x86/setup.c
> > > +++ b/lib/x86/setup.c
> > > @@ -192,8 +192,6 @@ static void setup_segments64(void)
> > >  	write_gs(KERNEL_DS);
> > >  	write_ss(KERNEL_DS);
> > >
> > > -	/* Setup percpu base */
> > > -	wrmsr(MSR_GS_BASE, (u64)&__percpu_data[pre_boot_apic_id()]);
> > >
> > >  	/*
> > >  	 * Update the code segment by putting it on the stack before the return
> > > @@ -322,7 +320,7 @@ efi_status_t setup_efi(efi_bootinfo_t *efi_bootinfo)
> > >  		}
> > >  		return status;
> > >  	}
> > > -
> > > +
> >
> > Huh.  This causes a conflict for me.  My local repo has a tab here that is
> > presumably being removed, but this patch doesn't have anything.  If I manually
> > add back the tab, all is well.  I suspect your client may be stripping trailing
> > whitespace.
> 
> Yes, I think my client was stripping trailing whitespaces. Do you want me
> to send a new version of the patch with that formatting?

No need, I'll put together a KUT PULL request next unless Paolo beats me to the
punch.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-10-21 20:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-23  9:43 [kvm-unit-tests PATCH v1] x86: efi: set up the IDT before accessing MSRs Vasant Karasulli
2022-08-25 21:51 ` Sean Christopherson
2022-10-13 13:40   ` Vasant Karasulli
2022-10-21 20:45     ` Sean Christopherson

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).