From patchwork Tue Oct 16 21:29:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Mattson X-Patchwork-Id: 10644223 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9D83B109C for ; Tue, 16 Oct 2018 21:29:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B3892A9D3 for ; Tue, 16 Oct 2018 21:29:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 799EA2A9DF; Tue, 16 Oct 2018 21:29:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D52E2A9D3 for ; Tue, 16 Oct 2018 21:29:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727017AbeJQFWF (ORCPT ); Wed, 17 Oct 2018 01:22:05 -0400 Received: from mail-it1-f202.google.com ([209.85.166.202]:37629 "EHLO mail-it1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726936AbeJQFWF (ORCPT ); Wed, 17 Oct 2018 01:22:05 -0400 Received: by mail-it1-f202.google.com with SMTP id y73-v6so27374154ita.2 for ; Tue, 16 Oct 2018 14:29:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Lz14G+tECSYvrr2AFJEm/F7tRZzrUrUogAk5E8VBy/E=; b=mORBkI73YP2DFK75juvTSCWIEdNQpTBkRhYLnlSqbYlNuFjl2B8REZhF7tSy8I+g5u lzI9BxVh1IoIgkR6bdxHxEuk1mFaEEE91mGRSM5WYy4lp7ZBDxA4QpKMUFANaCOeVUsa QKM89SaX41rPhjXjo5Axk39RVvZYGIt+8I+zD2624XH5xRIteTZdwBgq90UGsN+zO66z SB4IsviDemEjNNYW0dN8ELftSvn/7TtfIj1oIbWB5LVuAcINr3TJSLsnUHAnKnCjrGoD E6+oVfD0EviquYPDly3c4ZxlIcW6bZf3L0XV1mscTSU56Vrq4FoTM6U2Eu9+GaY3ffXm QI1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Lz14G+tECSYvrr2AFJEm/F7tRZzrUrUogAk5E8VBy/E=; b=VrgDzXeM569RiHwEq2CacnwpedRrVxB1vFLTaRqAjDSjsaGCTgYbYAZU7r33Borsu3 xqoO2kjl2TM34E533zZ4efBphYoa6OC0VIGqPZweF5nzbZyma1idZ65UVqAKhmcuseV6 X3xKiBR6EXhQryoT9Miecm/R6qwwv0PJZz5KA/udAEBpeyD8A/8EEZbL7l+r64FeZ7jm LNVpNP/Cit4Dobssl9lIrCX5t2/D5j9bBD9Rtk2TbsatVPKqhXH5hzY3IStwjO5Db6PJ THB+SG8GlagXbQ1E8wlCWWDIu5AT6RXMki5FDx1VXNwzaAZYdS7C8VHtvMy9I2JRjDtA C7uQ== X-Gm-Message-State: ABuFfoiEk4WeSFxCsINBUDut7EBo93M9IBgXkJ2rr6wvcSU4MPcDn58S Ygr102SfcGPTdgqel6j0uzG8rTZ2lFKRn3OjJLWXbKc2Zo2yU02eeJkiU5FRi7XN8CqEc01hlTQ 9Vv1BgSDTnxqKGh14Qeq+Z5Au6LbzwAGVEqekVxPbaEt09cWjPUtrFgocGL+LfJk= X-Google-Smtp-Source: ACcGV629QeUL7Ji8HdZgP4nSDVOT1xgkajsgN1Uq7izKpAvUe1q++j17Ridos1g4a9ljsnwbTt4/nRQk8uC09g== X-Received: by 2002:a24:fe01:: with SMTP id w1-v6mr21448680ith.0.1539725386134; Tue, 16 Oct 2018 14:29:46 -0700 (PDT) Date: Tue, 16 Oct 2018 14:29:21 -0700 In-Reply-To: <20181016212924.130307-1-jmattson@google.com> Message-Id: <20181016212924.130307-4-jmattson@google.com> Mime-Version: 1.0 References: <20181016212924.130307-1-jmattson@google.com> X-Mailer: git-send-email 2.19.1.331.ge82ca0e54c-goog Subject: [PATCH v2 4/7] kvm: x86: Add payload operands to kvm_multiple_exception From: Jim Mattson To: kvm@vger.kernel.org Cc: Peter Shier , Liran Alon , Paolo Bonzini , Jim Mattson Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP kvm_multiple_exception now takes two additional operands: has_payload and payload, so that updates to CR2 (and DR6 under VMX) can be delayed until the exception is delivered. This is necessary to properly emulate VMX or SVM hardware behavior for nested virtualization. The new behavior is triggered by vcpu->kvm->arch.exception_payload_enabled, which will (later) be set by a new per-VM capability, KVM_CAP_EXCEPTION_PAYLOAD. Reported-by: Jim Mattson Suggested-by: Paolo Bonzini Signed-off-by: Jim Mattson --- arch/x86/kvm/x86.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 851dabef7ff3..dcd2cd6351fb 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -402,7 +402,7 @@ static int exception_type(int vector) static void kvm_multiple_exception(struct kvm_vcpu *vcpu, unsigned nr, bool has_error, u32 error_code, - bool reinject) + bool has_payload, unsigned long payload, bool reinject) { u32 prev_nr; int class1, class2; @@ -424,6 +424,14 @@ static void kvm_multiple_exception(struct kvm_vcpu *vcpu, */ WARN_ON_ONCE(vcpu->arch.exception.pending); vcpu->arch.exception.injected = true; + if (WARN_ON_ONCE(has_payload)) { + /* + * A reinjected event has already + * delivered its payload. + */ + has_payload = false; + payload = 0; + } } else { vcpu->arch.exception.pending = true; vcpu->arch.exception.injected = false; @@ -431,8 +439,8 @@ static void kvm_multiple_exception(struct kvm_vcpu *vcpu, vcpu->arch.exception.has_error_code = has_error; vcpu->arch.exception.nr = nr; vcpu->arch.exception.error_code = error_code; - vcpu->arch.exception.has_payload = false; - vcpu->arch.exception.payload = 0; + vcpu->arch.exception.has_payload = has_payload; + vcpu->arch.exception.payload = payload; return; } @@ -468,13 +476,13 @@ static void kvm_multiple_exception(struct kvm_vcpu *vcpu, void kvm_queue_exception(struct kvm_vcpu *vcpu, unsigned nr) { - kvm_multiple_exception(vcpu, nr, false, 0, false); + kvm_multiple_exception(vcpu, nr, false, 0, false, 0, false); } EXPORT_SYMBOL_GPL(kvm_queue_exception); void kvm_requeue_exception(struct kvm_vcpu *vcpu, unsigned nr) { - kvm_multiple_exception(vcpu, nr, false, 0, true); + kvm_multiple_exception(vcpu, nr, false, 0, false, 0, true); } EXPORT_SYMBOL_GPL(kvm_requeue_exception); @@ -521,13 +529,13 @@ EXPORT_SYMBOL_GPL(kvm_inject_nmi); void kvm_queue_exception_e(struct kvm_vcpu *vcpu, unsigned nr, u32 error_code) { - kvm_multiple_exception(vcpu, nr, true, error_code, false); + kvm_multiple_exception(vcpu, nr, true, error_code, false, 0, false); } EXPORT_SYMBOL_GPL(kvm_queue_exception_e); void kvm_requeue_exception_e(struct kvm_vcpu *vcpu, unsigned nr, u32 error_code) { - kvm_multiple_exception(vcpu, nr, true, error_code, true); + kvm_multiple_exception(vcpu, nr, true, error_code, false, 0, true); } EXPORT_SYMBOL_GPL(kvm_requeue_exception_e);