From patchwork Tue Sep 2 15:13:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 4826391 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E87779F32F for ; Tue, 2 Sep 2014 15:15:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C3F26201B9 for ; Tue, 2 Sep 2014 15:15:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9EA91200F4 for ; Tue, 2 Sep 2014 15:15:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754320AbaIBPOH (ORCPT ); Tue, 2 Sep 2014 11:14:07 -0400 Received: from mail-wg0-f52.google.com ([74.125.82.52]:35222 "EHLO mail-wg0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754227AbaIBPOD (ORCPT ); Tue, 2 Sep 2014 11:14:03 -0400 Received: by mail-wg0-f52.google.com with SMTP id m15so7017782wgh.23 for ; Tue, 02 Sep 2014 08:14:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=vXD4oGTlICn6MkrxYM0D5PtW+3YjP0ifWjWHAXgeG6s=; b=usUtKXw57e29EDktzQLt2FhzhUSUGyEwecsyKr1Dwh2ufK5WNw1teEVo01hfXJju9B Mt8EsO3ctOMXrOE8XUxo2+l0n9OezB4YdSXujZxdJYZ5XNiP8JC6IgBvszYhuk1f6a6y QLRTg7Psgtzwg8ePeBH2SRlZvzVZv/RbFwpflE5zDA4G87UGSujFG1kvYgt8q+CoLIS2 VdJIQzz/c+ceOEptMy0xrptQrRWwYvT2wh/E+UMzmEOmFGhaJjiA4EYn/dSQXZ6OV/09 cQs6nrfR+Vhh5MKb4v6Yq2+jfZPhuH4HLt6zLTQp76Ha2GFmiMCcHjPHu0tcoLBHtvD+ AtMg== X-Received: by 10.180.198.232 with SMTP id jf8mr28435910wic.37.1409670841283; Tue, 02 Sep 2014 08:14:01 -0700 (PDT) Received: from playground.station (net-37-116-208-41.cust.vodafonedsl.it. [37.116.208.41]) by mx.google.com with ESMTPSA id xm4sm34892944wib.9.2014.09.02.08.13.59 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Sep 2014 08:14:00 -0700 (PDT) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: jroedel@suse.de, agraf@suse.de, valentine.sinitsyn@gmail.com, jan.kiszka@siemens.com, gleb@cloudius-systems.com, avi@cloudius-systems.com Subject: [PATCH 2/4] KVM: nSVM: propagate the NPF EXITINFO to the guest Date: Tue, 2 Sep 2014 17:13:48 +0200 Message-Id: <1409670830-14544-3-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1409670830-14544-1-git-send-email-pbonzini@redhat.com> References: <1409670830-14544-1-git-send-email-pbonzini@redhat.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-8.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is similar to what the EPT code does with the exit qualification. This allows the guest to see a valid value for bits 33:32. Signed-off-by: Paolo Bonzini --- arch/x86/kvm/paging_tmpl.h | 6 ++++++ arch/x86/kvm/svm.c | 26 ++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h index 410776528265..99d4c4e836a0 100644 --- a/arch/x86/kvm/paging_tmpl.h +++ b/arch/x86/kvm/paging_tmpl.h @@ -322,8 +322,14 @@ retry_walk: real_gfn = mmu->translate_gpa(vcpu, gfn_to_gpa(table_gfn), PFERR_USER_MASK|PFERR_WRITE_MASK); + + /* + * Can this happen (except if the guest is playing TOCTTOU games)? + * We should have gotten a nested page fault on table_gfn instead. + */ if (unlikely(real_gfn == UNMAPPED_GVA)) goto error; + real_gfn = gpa_to_gfn(real_gfn); host_addr = gfn_to_hva_prot(vcpu->kvm, real_gfn, diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 8ef704037370..bd78a3baca31 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -1974,10 +1974,28 @@ static void nested_svm_inject_npf_exit(struct kvm_vcpu *vcpu, { struct vcpu_svm *svm = to_svm(vcpu); - svm->vmcb->control.exit_code = SVM_EXIT_NPF; - svm->vmcb->control.exit_code_hi = 0; - svm->vmcb->control.exit_info_1 = fault->error_code; - svm->vmcb->control.exit_info_2 = fault->address; + /* + * We can keep the value that the processor stored in the VMCB, + * but make up something sensible if we hit the WARN. + */ + if (WARN_ON(svm->vmcb->control.exit_code != SVM_EXIT_NPF)) { + svm->vmcb->control.exit_code = SVM_EXIT_NPF; + svm->vmcb->control.exit_code_hi = 0; + svm->vmcb->control.exit_info_1 = (1ULL << 32); + svm->vmcb->control.exit_info_2 = fault->address; + } + + /* + * The present bit is always zero for page structure faults on real + * hardware, but we compute it as 1 in fault->error_code. We can + * just keep the original exit info for page structure faults---but + * not for other faults, because the processor's error code might + * be wrong if we have just created a shadow PTE. + */ + if (svm->vmcb->control.exit_info_1 & (1ULL << 32)) { + svm->vmcb->control.exit_info_1 &= ~0xffffffffULL; + svm->vmcb->control.exit_info_1 |= fault->error_code; + } nested_svm_vmexit(svm); }