Re: [PATCH v3 40/75] x86/sev-es: Compile early handler code into kernel image

2020-06-11 Thread Joerg Roedel
On Thu, Jun 04, 2020 at 05:19:53PM +0200, Borislav Petkov wrote:
> On Thu, Jun 04, 2020 at 01:54:13PM +0200, Joerg Roedel wrote:
> > It is not only the trace-point, this would also eliminate exception
> > handling in case the MSR access triggers a #GP. The "Unhandled MSR
> > read/write" messages would turn into a "General Protection Fault"
> > message.
> 
> But the early ones can trigger a #GP too. And there we can't handle
> those #GPs.
> 
> Why would the late ones need exception handling all of a sudden? And
> for the GHCB MSR, of all MSRs which the SEV-ES guest has used so far to
> bootstrap?!

For example when there is a bug in the code which triggers an SEV-ES-only
code-path at runtime on bare-metal or in a non-SEV-ES VM. When the MSR
is accessed accidentially in that code-path the exception handling will
be helpful.


Joerg


Re: [PATCH v3 40/75] x86/sev-es: Compile early handler code into kernel image

2020-06-04 Thread Borislav Petkov
On Thu, Jun 04, 2020 at 01:54:13PM +0200, Joerg Roedel wrote:
> It is not only the trace-point, this would also eliminate exception
> handling in case the MSR access triggers a #GP. The "Unhandled MSR
> read/write" messages would turn into a "General Protection Fault"
> message.

But the early ones can trigger a #GP too. And there we can't handle
those #GPs.

Why would the late ones need exception handling all of a sudden? And
for the GHCB MSR, of all MSRs which the SEV-ES guest has used so far to
bootstrap?!

-- 
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette


Re: [PATCH v3 40/75] x86/sev-es: Compile early handler code into kernel image

2020-06-04 Thread Joerg Roedel
On Wed, May 20, 2020 at 11:14:15AM +0200, Borislav Petkov wrote:
> On Tue, Apr 28, 2020 at 05:16:50PM +0200, Joerg Roedel wrote:
> > +static inline u64 sev_es_rd_ghcb_msr(void)
> > +{
> > +   return native_read_msr(MSR_AMD64_SEV_ES_GHCB);
> > +}
> > +
> > +static inline void sev_es_wr_ghcb_msr(u64 val)
> > +{
> > +   u32 low, high;
> > +
> > +   low  = (u32)(val);
> > +   high = (u32)(val >> 32);
> > +
> > +   native_write_msr(MSR_AMD64_SEV_ES_GHCB, low, high);
> > +}
> 
> Instead of duplicating those two, you can lift the ones in the
> compressed image into sev-es.h and use them here. I don't care one bit
> about the MSR tracepoints in native_*_msr().

It is not only the trace-point, this would also eliminate exception
handling in case the MSR access triggers a #GP. The "Unhandled MSR
read/write" messages would turn into a "General Protection Fault"
message.


Joerg


Re: [PATCH v3 40/75] x86/sev-es: Compile early handler code into kernel image

2020-05-20 Thread Borislav Petkov
On Tue, Apr 28, 2020 at 05:16:50PM +0200, Joerg Roedel wrote:
> +static inline u64 sev_es_rd_ghcb_msr(void)
> +{
> + return native_read_msr(MSR_AMD64_SEV_ES_GHCB);
> +}
> +
> +static inline void sev_es_wr_ghcb_msr(u64 val)
> +{
> + u32 low, high;
> +
> + low  = (u32)(val);
> + high = (u32)(val >> 32);
> +
> + native_write_msr(MSR_AMD64_SEV_ES_GHCB, low, high);
> +}

Instead of duplicating those two, you can lift the ones in the
compressed image into sev-es.h and use them here. I don't care one bit
about the MSR tracepoints in native_*_msr().

> +static enum es_result vc_write_mem(struct es_em_ctxt *ctxt,
> +char *dst, char *buf, size_t size)
> +{
> + unsigned long error_code = X86_PF_PROT | X86_PF_WRITE;
> + char __user *target = (char __user *)dst;
> + u64 d8;
> + u32 d4;
> + u16 d2;
> + u8  d1;
> +
> + switch (size) {
> + case 1:
> + memcpy(, buf, 1);
> + if (put_user(d1, target))
> + goto fault;
> + break;
> + case 2:
> + memcpy(, buf, 2);
> + if (put_user(d2, target))
> + goto fault;
> + break;
> + case 4:
> + memcpy(, buf, 4);
> + if (put_user(d4, target))
> + goto fault;
> + break;
> + case 8:
> + memcpy(, buf, 8);
> + if (put_user(d8, target))
> + goto fault;

Ok, those (and below) memcpys get nicely optimized to MOVs by the
compiler here.

-- 
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette