Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2692971ybl; Thu, 29 Aug 2019 11:33:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqykeDdwMlVoiuuLwXslb5OtWzMUN+6HJ14orllMDKWR3N1xnFpzsiVNadHKNvzSRnt9Gr93 X-Received: by 2002:a63:4522:: with SMTP id s34mr9487908pga.362.1567103608686; Thu, 29 Aug 2019 11:33:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567103608; cv=none; d=google.com; s=arc-20160816; b=dZQP7a9nJoQat6LG0d9PJTe5Kvspkm0pu0U9/7Y3v8HDVCd/VQJnPgPSiAp4/iSY44 xpKKnrsoY4aXO9AHIFNgDrQo9+Zg/LPORQKuN4vHaa/E1b7KECca/yhzqLrOH/pR8sFY Aj0/OzPNxL4GWoOs3js+c669/eAtCpRG3ELb+d7asBQ1aOHC97rZx7129QHfKnrTtdc0 AJoh8OAkKgo4jI2qMRQX3iw9eS0UWuxcqWk4Fle21gsamrbzbsdeGdrTPfEMgTfyAkw5 Bkfg2Mg9QptCyOQ/HN/pt0oDJ5pFuTSI/Esf1jukuXe2of3XRVpYXRt92ICBjlq+oZL8 Qt4w== 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=IL0SxgvaiE8A37Uuuv1LqDsyI7bC8KLurRrxiJJX71w=; b=diqyJiuUB58kDu5A2JDc9OT/fc0uYfwJdLaYVyvgVe8uaojltlCrnO+Uid4FRwO5OQ QmtSu0hYNGk7yTBsx6HKUHmGdnZyGrb7qOUyrtkzeKRjDdg8F1FpReV8azXuWF4sn+fy 9ibHZvM0jQM0Iippzkspea0OoCOcVRpljLmeXyoSM7/HZBSD97pKfufAyOgClLcQBCLL XK7x1aM0HDiaqk+zWEhPvBdAI8FDRzbqeBURkWUlGUsjzm+PTAIdpsZHjsdzAPTF9BEx vk/ewShne6RAbokOdfcIb7+iInTYnSiYMhoMYjmR7EfAEfDm7HkQUlNKrvQErHYk060k 5ueQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ExstUR2N; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p3si3383668pfn.55.2019.08.29.11.33.12; Thu, 29 Aug 2019 11:33:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ExstUR2N; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728888AbfH2SOe (ORCPT + 99 others); Thu, 29 Aug 2019 14:14:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:56154 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728836AbfH2SOb (ORCPT ); Thu, 29 Aug 2019 14:14:31 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 766CE2339E; Thu, 29 Aug 2019 18:14:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567102470; bh=bJlc/+TfIgbgjjmyWhzlBUWdW2bkR1oySzbllaFjg+k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ExstUR2N4UeW5Im0znp1kKz6YpCnKI3yNM+AnQ085ujM+IO87E0Bisf4B6x09hQZ/ wXms6Pk/W25mo1vBB/3xPJGRpnefsp9Cauz0bP+oFMfBWXWH1u7XiXQuxY7ZKRCSM/ nNPEoltKw2cXnToRXp1+OcgU1tm7qBa+ugE1ITC0= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Paolo Bonzini , Sasha Levin , kvm@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH AUTOSEL 5.2 34/76] selftests: kvm: fix vmx_set_nested_state_test Date: Thu, 29 Aug 2019 14:12:29 -0400 Message-Id: <20190829181311.7562-34-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190829181311.7562-1-sashal@kernel.org> References: <20190829181311.7562-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Paolo Bonzini [ Upstream commit c930e19790bbbff31c018009907c813fa0925f63 ] vmx_set_nested_state_test is trying to use the KVM_STATE_NESTED_EVMCS without enabling enlightened VMCS first. Correct the outcome of the test, and actually test that it succeeds after the capability is enabled. Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- .../kvm/x86_64/vmx_set_nested_state_test.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 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 a99fc66dafeb6..853e370e8a394 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 @@ -25,6 +25,8 @@ #define VMCS12_REVISION 0x11e57ed0 #define VCPU_ID 5 +bool have_evmcs; + void test_nested_state(struct kvm_vm *vm, struct kvm_nested_state *state) { vcpu_nested_state_set(vm, VCPU_ID, state, false); @@ -75,8 +77,9 @@ void set_default_vmx_state(struct kvm_nested_state *state, int size) { memset(state, 0, size); state->flags = KVM_STATE_NESTED_GUEST_MODE | - KVM_STATE_NESTED_RUN_PENDING | - KVM_STATE_NESTED_EVMCS; + KVM_STATE_NESTED_RUN_PENDING; + if (have_evmcs) + state->flags |= KVM_STATE_NESTED_EVMCS; state->format = 0; state->size = size; state->hdr.vmx.vmxon_pa = 0x1000; @@ -126,13 +129,19 @@ void test_vmx_nested_state(struct kvm_vm *vm) /* * 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. */ set_default_vmx_state(state, state_sz); state->hdr.vmx.vmxon_pa = -1ull; state->hdr.vmx.vmcs12_pa = -1ull; test_nested_state_expect_einval(vm, state); - state->flags = KVM_STATE_NESTED_EVMCS; + state->flags &= KVM_STATE_NESTED_EVMCS; + if (have_evmcs) { + test_nested_state_expect_einval(vm, state); + vcpu_enable_evmcs(vm, VCPU_ID); + } test_nested_state(vm, state); /* It is invalid to have vmxon_pa == -1ull and SMM flags non-zero. */ @@ -217,6 +226,8 @@ int main(int argc, char *argv[]) struct kvm_nested_state state; struct kvm_cpuid_entry2 *entry = kvm_get_supported_cpuid_entry(1); + have_evmcs = kvm_check_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS); + if (!kvm_check_cap(KVM_CAP_NESTED_STATE)) { printf("KVM_CAP_NESTED_STATE not available, skipping test\n"); exit(KSFT_SKIP); -- 2.20.1