Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp48710ybm; Tue, 26 May 2020 10:25:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJymxbWSUISdnFyUrjoMRbyOS2fZmsZSCJEJy06ebJdthhIk4NH4g+974gAi4mkuOvzVXc8A X-Received: by 2002:a50:c057:: with SMTP id u23mr22167435edd.293.1590513940076; Tue, 26 May 2020 10:25:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590513940; cv=none; d=google.com; s=arc-20160816; b=ga/P/WG13RRsouSKUIlmS93RE/pfCR47LRmqUc0FGrohoZmXYm9Dc1gzvW0pmm51w4 mfSbcRgBz5kO8RU/leLW1YyfN/q/wNpxnFuDIe9qqfdyjXVqhLAJnyRVt//ab9yZdJV9 Zf5ogd2weuw2ynTKT8atO4F6i5v81XNl21k3ZiEVpvo3wjhoeznyNi2OLT7ExN8FL8J1 sgp4DcfxgEgkLe/3M3tPsExP6Oru7bIC7hn00gtwOVuRVJ/cuuEq7YOB7ZTuYnirP6T5 dHv6WETK6OR9xBuiJmt9C7HWBPOZp1kpjXrFjRdxDq6R7ZtmiFYyP4BPwZ6mqMUbFKiy mIeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=GDbyJndkmjGJJsOxmeTncLZsYKOCmTuobVM5LeRDFNU=; b=B7JkA+lmPPmyAb87cuE3MlMxo2FakbyC1nhQGjNJW9roevipFq2Oe56EMEGbULuipf srFVQbpKAqbGruB+zlcMPrhuKDeK/9wneOQV8j05fdJS2qZGmXMO/PCm/YpvKaJh9skO SgCFqn3kKK7B7y8NxJ2NZe66DB5TgzyDoNjBfxyc1zX1mrKqb/nfiua4hKcLYuHPbF2/ /o+t84UI6vsGLVdhUXw5xNwxBLIRq02E1GMscT29Xl6lXFzJwoQL3vIh2Pnv//ggX/sv j6/N3pWZPJVEZm6/wYPd4QaxKXRYpQ/PkmHuWa9omp5rv+OnC98IljYGOkZAuitfkpB9 OBnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="hLEICB/H"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ci10si259035ejc.170.2020.05.26.10.25.16; Tue, 26 May 2020 10:25:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="hLEICB/H"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389210AbgEZRX1 (ORCPT + 99 others); Tue, 26 May 2020 13:23:27 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:43804 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2389171AbgEZRXY (ORCPT ); Tue, 26 May 2020 13:23:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590513802; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GDbyJndkmjGJJsOxmeTncLZsYKOCmTuobVM5LeRDFNU=; b=hLEICB/H81ywO5WgoAQZRSCCZR7L6IoEoFX9quxLvbruT7RTAVdf9KKigGuk/djGdo4zQ3 odwTMTQqsLvKoXpJpCkWAahhy6ZauHdGLafeBsHOLw4Ib9YGAmsGZh7I6nQ05i6b5dF5Mk D/l5vy0+704PB8iIsM828S/6quuCp6s= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-236-C6WpyyQvMuqzwdGnmJQDGg-1; Tue, 26 May 2020 13:23:16 -0400 X-MC-Unique: C6WpyyQvMuqzwdGnmJQDGg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B1533835B40; Tue, 26 May 2020 17:23:15 +0000 (UTC) Received: from virtlab511.virt.lab.eng.bos.redhat.com (virtlab511.virt.lab.eng.bos.redhat.com [10.19.152.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id 26E4810013DB; Tue, 26 May 2020 17:23:15 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: vkuznets@redhat.com, mlevitsk@redhat.com, Sean Christopherson , Jim Mattson Subject: [PATCH 09/28] KVM: nSVM: extract load_nested_vmcb_control Date: Tue, 26 May 2020 13:22:49 -0400 Message-Id: <20200526172308.111575-10-pbonzini@redhat.com> In-Reply-To: <20200526172308.111575-1-pbonzini@redhat.com> References: <20200526172308.111575-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When restoring SVM nested state, the control state cache in svm->nested will have to be filled, but the save state will not have to be moved into svm->vmcb. Therefore, pull the code that handles the control area into a separate function. Signed-off-by: Paolo Bonzini --- arch/x86/kvm/svm/nested.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index d2fc3c4aa00b..ea00dcd8c39b 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -228,6 +228,23 @@ static bool nested_vmcb_checks(struct vmcb *vmcb) return true; } +static void load_nested_vmcb_control(struct vcpu_svm *svm, + struct vmcb_control_area *control) +{ + svm->nested.nested_cr3 = control->nested_cr3; + + svm->nested.vmcb_msrpm = control->msrpm_base_pa & ~0x0fffULL; + svm->nested.vmcb_iopm = control->iopm_base_pa & ~0x0fffULL; + + /* cache intercepts */ + svm->nested.intercept_cr = control->intercept_cr; + svm->nested.intercept_dr = control->intercept_dr; + svm->nested.intercept_exceptions = control->intercept_exceptions; + svm->nested.intercept = control->intercept; + + svm->vcpu.arch.tsc_offset += control->tsc_offset; +} + void enter_svm_guest_mode(struct vcpu_svm *svm, u64 vmcb_gpa, struct vmcb *nested_vmcb) { @@ -235,15 +252,16 @@ void enter_svm_guest_mode(struct vcpu_svm *svm, u64 vmcb_gpa, is_intercept(svm, INTERCEPT_VINTR) || is_intercept(svm, INTERCEPT_IRET); + svm->nested.vmcb = vmcb_gpa; if (kvm_get_rflags(&svm->vcpu) & X86_EFLAGS_IF) svm->vcpu.arch.hflags |= HF_HIF_MASK; else svm->vcpu.arch.hflags &= ~HF_HIF_MASK; - if (nested_vmcb->control.nested_ctl & SVM_NESTED_CTL_NP_ENABLE) { - svm->nested.nested_cr3 = nested_vmcb->control.nested_cr3; + load_nested_vmcb_control(svm, &nested_vmcb->control); + + if (nested_vmcb->control.nested_ctl & SVM_NESTED_CTL_NP_ENABLE) nested_svm_init_mmu_context(&svm->vcpu); - } /* Load the nested guest state */ svm->vmcb->save.es = nested_vmcb->save.es; @@ -274,25 +292,15 @@ void enter_svm_guest_mode(struct vcpu_svm *svm, u64 vmcb_gpa, svm->vcpu.arch.dr6 = nested_vmcb->save.dr6; svm->vmcb->save.cpl = nested_vmcb->save.cpl; - svm->nested.vmcb_msrpm = nested_vmcb->control.msrpm_base_pa & ~0x0fffULL; - svm->nested.vmcb_iopm = nested_vmcb->control.iopm_base_pa & ~0x0fffULL; - - /* cache intercepts */ - svm->nested.intercept_cr = nested_vmcb->control.intercept_cr; - svm->nested.intercept_dr = nested_vmcb->control.intercept_dr; - svm->nested.intercept_exceptions = nested_vmcb->control.intercept_exceptions; - svm->nested.intercept = nested_vmcb->control.intercept; - svm_flush_tlb(&svm->vcpu); - svm->vmcb->control.int_ctl = nested_vmcb->control.int_ctl | V_INTR_MASKING_MASK; if (nested_vmcb->control.int_ctl & V_INTR_MASKING_MASK) svm->vcpu.arch.hflags |= HF_VINTR_MASK; else svm->vcpu.arch.hflags &= ~HF_VINTR_MASK; - svm->vcpu.arch.tsc_offset += nested_vmcb->control.tsc_offset; svm->vmcb->control.tsc_offset = svm->vcpu.arch.tsc_offset; + svm->vmcb->control.int_ctl = nested_vmcb->control.int_ctl | V_INTR_MASKING_MASK; svm->vmcb->control.virt_ext = nested_vmcb->control.virt_ext; svm->vmcb->control.int_vector = nested_vmcb->control.int_vector; svm->vmcb->control.int_state = nested_vmcb->control.int_state; @@ -313,8 +321,6 @@ void enter_svm_guest_mode(struct vcpu_svm *svm, u64 vmcb_gpa, */ recalc_intercepts(svm); - svm->nested.vmcb = vmcb_gpa; - /* * If L1 had a pending IRQ/NMI before executing VMRUN, * which wasn't delivered because it was disallowed (e.g. -- 2.26.2