Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5391326yba; Mon, 13 May 2019 10:02:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqwqK/QK2ZFQsMQS1DO3m71+j17/cG5owHn+NwtYPWx4yskSOSRfFf/macMjKJfNxy21y6u9 X-Received: by 2002:aa7:8d89:: with SMTP id i9mr35343419pfr.77.1557766975366; Mon, 13 May 2019 10:02:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557766975; cv=none; d=google.com; s=arc-20160816; b=l4QC/ZYxfoNgoEYhtTUCct4UAeI7OpPrWyi08kgPN+isJypHieuRzCGUb4GayhGLlx wnIJOmXBOBMDVBmMiJO7xj7hEWn1XhC6D+/f3NTn1uU/+juarkVCkJe0sBrsRX2FJ/k5 hs/uRcm+hf+paRDHj3CASwAxRCcjKhf29sUWxyp4dyE9WcmFs/jy0lyWSr2N6kB34pwD QprCuumpoYoRlvjLfjP0AdEUsevGsm4+jV1JqUq/tE/ZHk6BBAGxYU2ixNPHwhGMbpqS SFduh+gdzMUXFCpBAgE9oEJVDJRWzH6eayAJC0Dk/bVbvhztyqdsSUYceyuT3y4V0RYq F9oQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Ljy/U+bZu7KOD/jm5h/Nov5oW0yZ5jBLjvuaOwjQBsk=; b=G2EGr6TvKutkjfqDC+l9oY5j0bOFm75Kw3KmIcjJzFRdB8m94COeW4uRbgx7i/tJYu Z7XyvTyCYmMuV1Qu/4sLUksvE3S3Uc4gzJMx6LRO9hZ5QO8i8HZPO2HqOvtqfw5mQoaa rdu2G00EaXhVXWi6L5gCEYVicuYipCyBD3GcYh5eBmCg3XtXhir6OYZsI7z3q7suh0w8 4qG3pO+Lkh/pYKjgxqUP9gJ4UBdnV7Q3sNtzABse61OvxmVKccmjdOKEUvvhLJvOK4fV TPWpaUv19HTzwtILx4TFBVzDlkuDOMfKPfPVyDbifzG+YBFKCeZ9ML17qCIwxHSATQaI qI+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=k+z5lpyb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u7si12335804pgi.339.2019.05.13.10.02.38; Mon, 13 May 2019 10:02:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=k+z5lpyb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730246AbfEMQBe (ORCPT + 99 others); Mon, 13 May 2019 12:01:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:43392 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729726AbfEMQBd (ORCPT ); Mon, 13 May 2019 12:01:33 -0400 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 80629216E3 for ; Mon, 13 May 2019 16:01:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557763292; bh=lEibKcwC5gVE6uqe1w9PcI6jNFCNtyn0TO/fffg8YH8=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=k+z5lpybKEi6mIpFrCN17wQ9GoetmotYQ4i88fejJcVpMaoHOZbrljm2PEWhDSswf 06cEs3sA7iEdSg/w9f9tzMdQIooZs+IfZ3+LMzAYVslGXnDJ50vPScbKZ3yfmR0j61 V+5Fh+Qm2y15i11H0UpnUapfNJQgFELWxccdwEPU= Received: by mail-wm1-f48.google.com with SMTP id o189so14476556wmb.1 for ; Mon, 13 May 2019 09:01:32 -0700 (PDT) X-Gm-Message-State: APjAAAVabzk9T5/5m1nMh9gXwlgbCyBbK9FIJc0dYvikofp5kdGywWUq WUB/oLzavTLF277Y2VLZMwc6HKZiwmDubw3ZiNMPAQ== X-Received: by 2002:a7b:c844:: with SMTP id c4mr5457540wml.108.1557763286508; Mon, 13 May 2019 09:01:26 -0700 (PDT) MIME-Version: 1.0 References: <1557758315-12667-1-git-send-email-alexandre.chartre@oracle.com> <1557758315-12667-26-git-send-email-alexandre.chartre@oracle.com> In-Reply-To: <1557758315-12667-26-git-send-email-alexandre.chartre@oracle.com> From: Andy Lutomirski Date: Mon, 13 May 2019 09:01:14 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC KVM 25/27] kvm/isolation: implement actual KVM isolation enter/exit To: Alexandre Chartre Cc: Paolo Bonzini , Radim Krcmar , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Dave Hansen , Andrew Lutomirski , Peter Zijlstra , kvm list , X86 ML , Linux-MM , LKML , Konrad Rzeszutek Wilk , jan.setjeeilers@oracle.com, Liran Alon , Jonathan Adams Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 13, 2019 at 7:40 AM Alexandre Chartre wrote: > > From: Liran Alon > > KVM isolation enter/exit is done by switching between the KVM address > space and the kernel address space. > > Signed-off-by: Liran Alon > Signed-off-by: Alexandre Chartre > --- > 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