Borislav Petkov
2020-May-23 07:59 UTC
[PATCH v3 47/75] x86/sev-es: Add Runtime #VC Exception Handler
On Tue, Apr 28, 2020 at 05:16:57PM +0200, Joerg Roedel wrote:> diff --git a/arch/x86/kernel/sev-es.c b/arch/x86/kernel/sev-es.c > index a4fa7f351bf2..bc3a58427028 100644 > --- a/arch/x86/kernel/sev-es.c > +++ b/arch/x86/kernel/sev-es.c > @@ -10,6 +10,7 @@ > #include <linux/sched/debug.h> /* For show_regs() */ > #include <linux/percpu-defs.h> > #include <linux/mem_encrypt.h> > +#include <linux/lockdep.h> > #include <linux/printk.h> > #include <linux/mm_types.h> > #include <linux/set_memory.h> > @@ -25,7 +26,7 @@ > #include <asm/insn-eval.h> > #include <asm/fpu/internal.h> > #include <asm/processor.h> > -#include <asm/trap_defs.h> > +#include <asm/traps.h> > #include <asm/svm.h> > > /* For early boot hypervisor communication in SEV-ES enabled guests */ > @@ -46,10 +47,26 @@ struct sev_es_runtime_data { > > /* Physical storage for the per-cpu IST stacks of the #VC handler */ > struct vmm_exception_stacks vc_stacks __aligned(PAGE_SIZE); > + > + /* Reserve on page per CPU as backup storage for the unencrypted GHCB */one> + struct ghcb backup_ghcb;I could use some text explaining what those backups are for?> + /* > + * Mark the per-cpu GHCBs as in-use to detect nested #VC exceptions. > + * There is no need for it to be atomic, because nothing is written to > + * the GHCB between the read and the write of ghcb_active. So it is safe > + * to use it when a nested #VC exception happens before the write. > + */Looks liks that is that text... support for nested #VC exceptions. I'm sure this has come up already but why do we even want to support nested #VCs? IOW, can we do without them first or are they absolutely necessary? I'm guessing VC exceptions inside the VC handler but what are the sensible use cases? Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette
Joerg Roedel
2020-Jun-11 11:48 UTC
[PATCH v3 47/75] x86/sev-es: Add Runtime #VC Exception Handler
On Sat, May 23, 2020 at 09:59:24AM +0200, Borislav Petkov wrote:> On Tue, Apr 28, 2020 at 05:16:57PM +0200, Joerg Roedel wrote: > > + /* > > + * Mark the per-cpu GHCBs as in-use to detect nested #VC exceptions. > > + * There is no need for it to be atomic, because nothing is written to > > + * the GHCB between the read and the write of ghcb_active. So it is safe > > + * to use it when a nested #VC exception happens before the write. > > + */ > > Looks liks that is that text... support for nested #VC exceptions. > I'm sure this has come up already but why do we even want to support > nested #VCs? IOW, can we do without them first or are they absolutely > necessary? > > I'm guessing VC exceptions inside the VC handler but what are the > sensible use cases?The most important use-case is #VC->NMI->#VC. When an NMI hits while the #VC handler uses the GHCB and the NMI handler causes another #VC, then the contents of the GHCB needs to be backed up, so that it doesn't destroy the GHCB contents of the first #VC handling path. Regards, Joerg
Joerg Roedel
2020-Jun-11 11:53 UTC
[PATCH v3 47/75] x86/sev-es: Add Runtime #VC Exception Handler
On Sat, May 23, 2020 at 09:59:24AM +0200, Borislav Petkov wrote:> On Tue, Apr 28, 2020 at 05:16:57PM +0200, Joerg Roedel wrote: > > + struct ghcb backup_ghcb; > > I could use some text explaining what those backups are for?I added another comment above that line to better explain why it is needed. Joerg
Sean Christopherson
2020-Jun-11 17:38 UTC
[PATCH v3 47/75] x86/sev-es: Add Runtime #VC Exception Handler
On Thu, Jun 11, 2020 at 01:48:31PM +0200, Joerg Roedel wrote:> On Sat, May 23, 2020 at 09:59:24AM +0200, Borislav Petkov wrote: > > On Tue, Apr 28, 2020 at 05:16:57PM +0200, Joerg Roedel wrote: > > > + /* > > > + * Mark the per-cpu GHCBs as in-use to detect nested #VC exceptions. > > > + * There is no need for it to be atomic, because nothing is written to > > > + * the GHCB between the read and the write of ghcb_active. So it is safe > > > + * to use it when a nested #VC exception happens before the write. > > > + */ > > > > Looks liks that is that text... support for nested #VC exceptions. > > I'm sure this has come up already but why do we even want to support > > nested #VCs? IOW, can we do without them first or are they absolutely > > necessary? > > > > I'm guessing VC exceptions inside the VC handler but what are the > > sensible use cases? > > The most important use-case is #VC->NMI->#VC. When an NMI hits while the > #VC handler uses the GHCB and the NMI handler causes another #VC, then > the contents of the GHCB needs to be backed up, so that it doesn't > destroy the GHCB contents of the first #VC handling path.Isn't it possible for the #VC handler to hit a #PF, e.g. on copy_from_user() in insn_fetch_from_user()? If that happens, what prevents the #PF handler from hitting a #VC? AIUI, do_vmm_communication() panics if the backup GHCB is already in use, e.g. #VC->#PF->#VC->NMI->#VC would be fatal.
Borislav Petkov
2020-Jun-12 13:13 UTC
[PATCH v3 47/75] x86/sev-es: Add Runtime #VC Exception Handler
On Thu, Jun 11, 2020 at 01:48:31PM +0200, Joerg Roedel wrote:> The most important use-case is #VC->NMI->#VC. When an NMI hits while the > #VC handler uses the GHCB and the NMI handler causes another #VC, then > the contents of the GHCB needs to be backed up, so that it doesn't > destroy the GHCB contents of the first #VC handling path.That's a good example, please add it to the next version of the patch, preferrably in a comment somewhere. Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette
Apparently Analagous Threads
- [PATCH v3 47/75] x86/sev-es: Add Runtime #VC Exception Handler
- [PATCH v3 47/75] x86/sev-es: Add Runtime #VC Exception Handler
- [PATCH v3 47/75] x86/sev-es: Add Runtime #VC Exception Handler
- [PATCH v3 47/75] x86/sev-es: Add Runtime #VC Exception Handler
- [PATCH v3 43/75] x86/sev-es: Setup per-cpu GHCBs for the runtime handler