Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2643969rda; Wed, 25 Oct 2023 08:26:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFoy1BsXvHK/PjYP01uy9TnQlkD1BdhNfIreX00ndS6ia1ZFr5Ho2r6L4rx7ZtZ7aNk9I2Z X-Received: by 2002:a25:5014:0:b0:d9a:44fe:be93 with SMTP id e20-20020a255014000000b00d9a44febe93mr14503019ybb.26.1698247586478; Wed, 25 Oct 2023 08:26:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698247586; cv=none; d=google.com; s=arc-20160816; b=qXHI3dRa0zjCDXotMdHCkcOcnrXLDYiinjiIXB9j39G/ifvXZbLD3V8gho2uSG+nKs mfRarLHMpSlB0jkzNystbiHgpPTRpURJxqatqpMaph9PY3KKfruWXpjdNBfv0IRMrjL8 59ladvVe85v+rr4/hYrUUxeptlCBJ6qb+FRkce3ZdDPMuyZNWjU/BD4VLYoEs1BUDY4/ TwOUsLaMpdETQQZVjvKGxk8LRI7rywSj2wczUO+/udZFQbj8f3Jss7VeV5sSXPwQCCHD Z2ma6O7JS06/mxfc1BCQ1nORjd7EQPW6x1vUAeJ/eqZ2U32oUnHTrDmOtaE5GI1vOViV ZVOw== 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=6ogZQrurRkWocGHPi25OqCYHrWbleHCNHLEdRKHHa8c=; fh=WR6Fy7kGCroNKSS5jHjX5LaQseGeTC3TD3lkK7gcJQQ=; b=X7Gp7F2LXV5QBjhUMSAjLOUtnV0X9Lvqt+jqdVuaq8R168j4xj/K+zmSZfUvln3FPP qka2sOstucx6kz7ddcrdH7jp4e0tnDDPMQOxL/IyIxDsZJGQiBeKAd3GF4WdeYhCLQUn M8z8HLFMBoED94G+FZPXkiuTDLkY1nH6Dj4IOKm/z3DEcrb7tiSntRNr5dQd/eP2toEg C+EeQgTapHPoF2MFUXhdYRodZp2+F4dEcUFSC2jUsvhU7tZWiGXRGGBk+pj7aYrGFy2Z PcRCcGMwYVgZ4e9Ydfv8NzllPvMVwU9cLPbzl1R06bX74pFT7Zv+GPGEeu1QwtxN0l3y Ah/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BdWGdzPH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id t11-20020a252d0b000000b00d73a641fd3asi10911787ybt.166.2023.10.25.08.26.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 08:26:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BdWGdzPH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id E93AD8087278; Wed, 25 Oct 2023 08:25:52 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235076AbjJYPZk (ORCPT + 99 others); Wed, 25 Oct 2023 11:25:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235008AbjJYPZh (ORCPT ); Wed, 25 Oct 2023 11:25:37 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5A9D184 for ; Wed, 25 Oct 2023 08:24:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698247460; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6ogZQrurRkWocGHPi25OqCYHrWbleHCNHLEdRKHHa8c=; b=BdWGdzPH77VBiR77r2/scWoCJb18wcU/WEPDAgYU5383F+RQFmeTWzzoEHnlho74sJbniU yuRuV0ZsFa4DFKhMO8w9fEQNwTQCPk54JvH43lDAmuYEHJWMnrtZ/GGj7jL3OOHihup3HM aWDPN+6ZjQKxCXWeeQfb3KUDMfHRa/A= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-221-nMYyCbkrOMW6cihJ1gFdZw-1; Wed, 25 Oct 2023 11:24:19 -0400 X-MC-Unique: nMYyCbkrOMW6cihJ1gFdZw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9236D3C0FC8C; Wed, 25 Oct 2023 15:24:18 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.226.101]) by smtp.corp.redhat.com (Postfix) with ESMTP id A50572166B26; Wed, 25 Oct 2023 15:24:17 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson , Maxim Levitsky Cc: linux-kernel@vger.kernel.org Subject: [PATCH 09/14] KVM: selftests: Fix vmxon_pa == vmcs12_pa == -1ull vmx_set_nested_state_test for !eVMCS case Date: Wed, 25 Oct 2023 17:24:01 +0200 Message-ID: <20231025152406.1879274-10-vkuznets@redhat.com> In-Reply-To: <20231025152406.1879274-1-vkuznets@redhat.com> References: <20231025152406.1879274-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Wed, 25 Oct 2023 08:25:53 -0700 (PDT) The "vmxon_pa == vmcs12_pa == -1ull" test happens to work by accident: as Enlightened VMCS is always supported, set_default_vmx_state() adds 'KVM_STATE_NESTED_EVMCS' to 'flags' and the following branch of vmx_set_nested_state() is executed: if ((kvm_state->flags & KVM_STATE_NESTED_EVMCS) && (!guest_can_use(vcpu, X86_FEATURE_VMX) || !vmx->nested.enlightened_vmcs_enabled)) return -EINVAL; as 'enlightened_vmcs_enabled' is false. In fact, "vmxon_pa == vmcs12_pa == -1ull" is a valid state when not tainted by wrong flags so the test should aim for this branch: if (kvm_state->hdr.vmx.vmxon_pa == INVALID_GPA) return 0; Test all this properly: - Without KVM_STATE_NESTED_EVMCS in the flags, the expected return value is '0'. - With KVM_STATE_NESTED_EVMCS flag (when supported) set, the expected return value is '-EINVAL' prior to enabling eVMCS and '0' after. Signed-off-by: Vitaly Kuznetsov --- .../kvm/x86_64/vmx_set_nested_state_test.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c b/tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c index 41ea7028a1f8..67a62a5a8895 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c @@ -125,21 +125,25 @@ void test_vmx_nested_state(struct kvm_vcpu *vcpu) /* * Setting vmxon_pa == -1ull and vmcs_pa == -1ull exits early without - * setting the nested state but flags other than eVMCS must be clear. - * The eVMCS flag can be set if the enlightened VMCS capability has - * been enabled. + * setting the nested state. When the eVMCS flag is not set, the + * expected return value is '0'. */ set_default_vmx_state(state, state_sz); + state->flags = 0; state->hdr.vmx.vmxon_pa = -1ull; state->hdr.vmx.vmcs12_pa = -1ull; - test_nested_state_expect_einval(vcpu, state); + test_nested_state(vcpu, state); - state->flags &= KVM_STATE_NESTED_EVMCS; + /* + * When eVMCS is supported, the eVMCS flag can only be set if the + * enlightened VMCS capability has been enabled. + */ if (have_evmcs) { + state->flags = KVM_STATE_NESTED_EVMCS; test_nested_state_expect_einval(vcpu, state); vcpu_enable_evmcs(vcpu); + test_nested_state(vcpu, state); } - test_nested_state(vcpu, state); /* It is invalid to have vmxon_pa == -1ull and SMM flags non-zero. */ state->hdr.vmx.smm.flags = 1; -- 2.41.0