On Mon, May 13, 2019 at 7:40 AM Alexandre Chartre <alexandre.chartre@xxxxxxxxxx> wrote: > > From: Liran Alon <liran.alon@xxxxxxxxxx> > > KVM isolation enter/exit is done by switching between the KVM address > space and the kernel address space. > > Signed-off-by: Liran Alon <liran.alon@xxxxxxxxxx> > Signed-off-by: Alexandre Chartre <alexandre.chartre@xxxxxxxxxx> > --- > arch/x86/kvm/isolation.c | 30 ++++++++++++++++++++++++------ > arch/x86/mm/tlb.c | 1 + > include/linux/sched.h | 1 + > 3 files changed, 26 insertions(+), 6 deletions(-) > > diff --git a/arch/x86/kvm/isolation.c b/arch/x86/kvm/isolation.c > index db0a7ce..b0c789f 100644 > --- a/arch/x86/kvm/isolation.c > +++ b/arch/x86/kvm/isolation.c > @@ -1383,11 +1383,13 @@ static bool kvm_page_fault(struct pt_regs *regs, unsigned long error_code, > printk(KERN_DEFAULT "KVM isolation: page fault %ld at %pS on %lx (%pS) while switching mm\n" > " cr3=%lx\n" > " kvm_mm=%px pgd=%px\n" > - " active_mm=%px pgd=%px\n", > + " active_mm=%px pgd=%px\n" > + " kvm_prev_mm=%px pgd=%px\n", > error_code, (void *)regs->ip, address, (void *)address, > cr3, > &kvm_mm, kvm_mm.pgd, > - active_mm, active_mm->pgd); > + active_mm, active_mm->pgd, > + current->kvm_prev_mm, current->kvm_prev_mm->pgd); > dump_stack(); > > return false; > @@ -1649,11 +1651,27 @@ void kvm_may_access_sensitive_data(struct kvm_vcpu *vcpu) > kvm_isolation_exit(); > } > > +static void kvm_switch_mm(struct mm_struct *mm) > +{ > + unsigned long flags; > + > + /* > + * Disable interrupt before updating active_mm, otherwise if an > + * interrupt occurs during the switch then the interrupt handler > + * can be mislead about the mm effectively in use. > + */ > + local_irq_save(flags); > + current->kvm_prev_mm = current->active_mm; Peter's NAK aside, why on Earth is this in task_struct? You cannot possibly context switch while in isolation mode. --Andy