Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp507387pxb; Wed, 3 Nov 2021 07:48:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCepkVHMR3uDB8RZp/p4C5wJTa4k8frJkY+Hqvs5XjOrWVSmtCwyqruG/VMr95+I/HABNW X-Received: by 2002:a05:6e02:1846:: with SMTP id b6mr6564395ilv.164.1635950930500; Wed, 03 Nov 2021 07:48:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635950930; cv=none; d=google.com; s=arc-20160816; b=gvaAr/ox44hbcrWEOLmGw9PrJhGteOT2UAqR+vZpmvy+VRqBG6OYuSBNp53Fk4ORmM 6fDDpdB2f0zaHYh/Lnh0BnMU4/dXwA1XeQR5yXrViFEZG6hn8zgf1WJQc1BWaZNeVtMj UotaCfpFcDqG8yE8etSFNvXtafSo9RmTbfdnbJPrl9iuwM0Od0u23I/HDggVnc3vSNS7 25WFAc0AkIGIweNOITTGqdCDl52GIMDOOUIvRzBDCgP6tY9pkze8KnKZgOH+h6DSN9S6 59/rTJ2ONYPmM3nCTUhGAoHl0r5OHEaafOFbyEaV8e3uSDam6g9mQkuf86/EIwMsOk1R r1TA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9QcVev1Ykpkrc32brdMrevNpi1w0zxnAXd00Dazz9is=; b=eViJ4cPCuRmjYstth8zMp7UweA50u9ej6Ssxrc4nJqFLUCsmuIlbx0TNzuWKhbXJOc injA7bwKPCtRkDw5Sfz8OlsvAsRCeYsBfbNOdlO3y1BwVZuRWCt79S7L+vPbzfma+g+u IEWCJXssJfEZ3tEWR23aVS5o/freBlsKJ7zsGJhdGxIt5pS8aPkFooYYaSt3RFEE4SfS jtE5TE5H89CxNMfFV6RKyzwVAT3XkM1W6v60EWPT6Zapn8zhcIYKZgopGq0l4LyPorsU 8yWMszZE+ssIranuHcQEf79i3fHtmQwmMHIJmvhXxFw74xUNZimVCNF8bxxU6xTgRCbH b9Eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dK+FbNW4; 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 z1si4693933ioq.24.2021.11.03.07.48.38; Wed, 03 Nov 2021 07:48:50 -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=dK+FbNW4; 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 S231924AbhKCOJJ (ORCPT + 99 others); Wed, 3 Nov 2021 10:09:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:41929 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231514AbhKCOJD (ORCPT ); Wed, 3 Nov 2021 10:09:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635948386; 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=9QcVev1Ykpkrc32brdMrevNpi1w0zxnAXd00Dazz9is=; b=dK+FbNW4dZnZugnN0Euvus1c+cQ8Mij3AiPg8aIpgkDIYED+2lvPl3NbVMc0VO+lfkQE9J fCkdRkk2zRyCRDppIqQz1XpJF6bxLowGzP2TBZdJxZ3Dj66vCkTVMcSEK9dY7Ty6aTFygd +RTFvgmP0a8gxW59W48Rx+ertCXnxwg= 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-111-JR-doC3aPiWFWe5aS_4eKg-1; Wed, 03 Nov 2021 10:06:25 -0400 X-MC-Unique: JR-doC3aPiWFWe5aS_4eKg-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 C6244100CFB2; Wed, 3 Nov 2021 14:06:23 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id B9DBE100239F; Wed, 3 Nov 2021 14:06:22 +0000 (UTC) From: Emanuele Giuseppe Esposito To: kvm@vger.kernel.org Cc: Paolo Bonzini , Maxim Levitsky , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org, Emanuele Giuseppe Esposito Subject: [PATCH v5 4/7] nSVM: use vmcb_save_area_cached in nested_vmcb_valid_sregs() Date: Wed, 3 Nov 2021 10:05:24 -0400 Message-Id: <20211103140527.752797-5-eesposit@redhat.com> In-Reply-To: <20211103140527.752797-1-eesposit@redhat.com> References: <20211103140527.752797-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that struct vmcb_save_area_cached contains the required vmcb fields values (done in nested_load_save_from_vmcb12()), check them to see if they are correct in nested_vmcb_valid_sregs(). While at it, rename nested_vmcb_valid_sregs in nested_vmcb_check_save. _nested_vmcb_check_save takes the additional @save parameter, so it is helpful when we want to check a non-svm save state, like in svm_set_nested_state. The reason for that is that save is the L1 state, not L2, so we just check it. Signed-off-by: Emanuele Giuseppe Esposito --- arch/x86/kvm/svm/nested.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index 162b338a6c74..64fb43234e06 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -245,8 +245,8 @@ static bool nested_vmcb_check_controls(struct kvm_vcpu *vcpu, } /* Common checks that apply to both L1 and L2 state. */ -static bool nested_vmcb_valid_sregs(struct kvm_vcpu *vcpu, - struct vmcb_save_area *save) +static bool _nested_vmcb_check_save(struct kvm_vcpu *vcpu, + struct vmcb_save_area_cached *save) { /* * FIXME: these should be done after copying the fields, @@ -286,6 +286,14 @@ static bool nested_vmcb_valid_sregs(struct kvm_vcpu *vcpu, return true; } +static bool nested_vmcb_check_save(struct kvm_vcpu *vcpu) +{ + struct vcpu_svm *svm = to_svm(vcpu); + struct vmcb_save_area_cached *save = &svm->nested.save; + + return _nested_vmcb_check_save(vcpu, save); +} + static void _nested_copy_vmcb_control_to_cache(struct vmcb_control_area *to, struct vmcb_control_area *from) @@ -694,7 +702,7 @@ int nested_svm_vmrun(struct kvm_vcpu *vcpu) nested_copy_vmcb_control_to_cache(svm, &vmcb12->control); nested_copy_vmcb_save_to_cache(svm, &vmcb12->save); - if (!nested_vmcb_valid_sregs(vcpu, &vmcb12->save) || + if (!nested_vmcb_check_save(vcpu) || !nested_vmcb_check_controls(vcpu, &svm->nested.ctl)) { vmcb12->control.exit_code = SVM_EXIT_ERR; vmcb12->control.exit_code_hi = 0; @@ -1330,6 +1338,7 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu, &user_kvm_nested_state->data.svm[0]; struct vmcb_control_area *ctl; struct vmcb_save_area *save; + struct vmcb_save_area_cached save_cached; unsigned long cr0; int ret; @@ -1397,10 +1406,11 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu, * Validate host state saved from before VMRUN (see * nested_svm_check_permissions). */ + _nested_copy_vmcb_save_to_cache(&save_cached, save); if (!(save->cr0 & X86_CR0_PG) || !(save->cr0 & X86_CR0_PE) || (save->rflags & X86_EFLAGS_VM) || - !nested_vmcb_valid_sregs(vcpu, save)) + !_nested_vmcb_check_save(vcpu, &save_cached)) goto out_free; /* -- 2.27.0