Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp448706rwb; Tue, 4 Oct 2022 06:20:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM465UYTR5I0fF9oY3knZwh+Iy8bPEvsaDLehb84qZVHtVTRQ3ZKkzfJKuvywRtq6BXdUC3R X-Received: by 2002:a05:6a00:16c4:b0:535:890:d4a with SMTP id l4-20020a056a0016c400b0053508900d4amr27741619pfc.0.1664889626687; Tue, 04 Oct 2022 06:20:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664889626; cv=none; d=google.com; s=arc-20160816; b=IAsEBh51aEwLLkzhUefMcygqdqTt93LDhuNCXdM7vm/GutZmkfLd7yVqxFKsayFCe7 Jwv2YKmc/1zZdikNIW9vN2hD61rtdgEwKB+rZxJOAKu8WB9taRJr61zpa0316zggd40H z+AziWmt0LK9v1n0UoaCJt3ljSCeKRpq3UhFKmh+3Fb+uVFIOCtZXE9rqCx2/q3vMs0j Tu0L+NclmVqgJ74UBD9gMIhIlhyDx7eys7Jxtl1daTyr/hx65kNL0o/LXPdcwUWhsRe2 dOOjmwDbygfS24r2PyGjNNQ80q4zEYqo7sXmo5wEqNU2sA+802tAbHdO0ThIL/DjJCdj wn/A== 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=09XJyzSez+6GqiCdpIbI3kFHoxvPAlPhj5NVUNRTUjk=; b=yc4e+tg3L9kOalADtqU0xQRNygjJ5gCG619LGtVlISKRouKqxfMmxPtSObvXLjLtis eH4NuhoEH5RQqd27voTyLPP7rTGVZj5vrJNaz56d3xTl2LQSVq/G2ulPb6Hh/urzTm0Z 8Gbr+j8lJczj5a7Roh1Sj8xskxZ8UJ/uzLk8MJjUiSs7N9dEfdd7B9WsHopz0o0hmo0M q5sjuuUJ1k2pL2UQqu2F8Wl1UhKWs+GGv/CDCC+xfI3zNaJCtO+O9lkYHT5tNM+Ks2C7 TJKERI+ag+X0rBgaNpKYHRpgrR2P5ATA1xYOnREVDpiJhWG3kk7OhCLjQLQzISmiT89Q ouVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GVvN4Kcq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u7-20020a170902e5c700b0017f61b0bc5bsi5509197plf.557.2022.10.04.06.20.13; Tue, 04 Oct 2022 06:20:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GVvN4Kcq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S230039AbiJDM7I (ORCPT + 99 others); Tue, 4 Oct 2022 08:59:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230282AbiJDM5v (ORCPT ); Tue, 4 Oct 2022 08:57:51 -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 8673913E12 for ; Tue, 4 Oct 2022 05:55:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664888104; 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=09XJyzSez+6GqiCdpIbI3kFHoxvPAlPhj5NVUNRTUjk=; b=GVvN4KcqBXG5YfTIyVUgxaN6PlYFxTsOMPlRWaH59gFkDrhOEe4rYz5/4LjH9sq0sxx9Vt 2+R44lCAtYx2zHSQZeQnoA4bmOffrhAZImt/cXvtglUDbl2HoGI48lCdLK/j8r6TEmcOH2 ncJpVtGyi+I/mcFgvvUaQL1UaPgLKpg= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-425-P_j5_PSJOV27hV5gi4RGQg-1; Tue, 04 Oct 2022 08:41:43 -0400 X-MC-Unique: P_j5_PSJOV27hV5gi4RGQg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7BA013C0F244; Tue, 4 Oct 2022 12:41:42 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.192.255]) by smtp.corp.redhat.com (Postfix) with ESMTP id 217417AE5; Tue, 4 Oct 2022 12:41:39 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson Cc: Wanpeng Li , Jim Mattson , Michael Kelley , Siddharth Chandrasekaran , Yuan Yao , Maxim Levitsky , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v11 41/46] KVM: selftests: Split off load_evmcs() from load_vmcs() Date: Tue, 4 Oct 2022 14:39:51 +0200 Message-Id: <20221004123956.188909-42-vkuznets@redhat.com> In-Reply-To: <20221004123956.188909-1-vkuznets@redhat.com> References: <20221004123956.188909-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In preparation to putting Hyper-V specific test pages to a dedicated struct, move eVMCS load logic from load_vmcs(). Tests call load_vmcs() directly and the only one which needs 'enlightened' version is evmcs_test so there's not much gain in having this merged. Temporary pass both GPA and HVA to load_evmcs(). Signed-off-by: Vitaly Kuznetsov --- .../selftests/kvm/include/x86_64/evmcs.h | 10 ++++++ tools/testing/selftests/kvm/lib/x86_64/vmx.c | 33 ++++++++----------- .../testing/selftests/kvm/x86_64/evmcs_test.c | 4 +-- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/evmcs.h b/tools/testing/selftests/kvm/include/x86_64/evmcs.h index 2530b5aeb4ba..59b60d45b8f6 100644 --- a/tools/testing/selftests/kvm/include/x86_64/evmcs.h +++ b/tools/testing/selftests/kvm/include/x86_64/evmcs.h @@ -256,6 +256,16 @@ static inline int evmcs_vmptrld(uint64_t vmcs_pa, void *vmcs) return 0; } +static inline bool load_evmcs(uint64_t enlightened_vmcs_gpa, void *enlightened_vmcs) +{ + if (evmcs_vmptrld(enlightened_vmcs_gpa, enlightened_vmcs)) + return false; + + current_evmcs->revision_id = EVMCS_VERSION; + + return true; +} + static inline int evmcs_vmptrst(uint64_t *value) { *value = current_vp_assist->current_nested_vmcs & diff --git a/tools/testing/selftests/kvm/lib/x86_64/vmx.c b/tools/testing/selftests/kvm/lib/x86_64/vmx.c index 80a568c439b8..f8acbc7c8d7d 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/vmx.c +++ b/tools/testing/selftests/kvm/lib/x86_64/vmx.c @@ -169,26 +169,19 @@ bool prepare_for_vmx_operation(struct vmx_pages *vmx) bool load_vmcs(struct vmx_pages *vmx) { - if (!enable_evmcs) { - /* Load a VMCS. */ - *(uint32_t *)(vmx->vmcs) = vmcs_revision(); - if (vmclear(vmx->vmcs_gpa)) - return false; - - if (vmptrld(vmx->vmcs_gpa)) - return false; - - /* Setup shadow VMCS, do not load it yet. */ - *(uint32_t *)(vmx->shadow_vmcs) = - vmcs_revision() | 0x80000000ul; - if (vmclear(vmx->shadow_vmcs_gpa)) - return false; - } else { - if (evmcs_vmptrld(vmx->enlightened_vmcs_gpa, - vmx->enlightened_vmcs)) - return false; - current_evmcs->revision_id = EVMCS_VERSION; - } + /* Load a VMCS. */ + *(uint32_t *)(vmx->vmcs) = vmcs_revision(); + if (vmclear(vmx->vmcs_gpa)) + return false; + + if (vmptrld(vmx->vmcs_gpa)) + return false; + + /* Setup shadow VMCS, do not load it yet. */ + *(uint32_t *)(vmx->shadow_vmcs) = + vmcs_revision() | 0x80000000ul; + if (vmclear(vmx->shadow_vmcs_gpa)) + return false; return true; } diff --git a/tools/testing/selftests/kvm/x86_64/evmcs_test.c b/tools/testing/selftests/kvm/x86_64/evmcs_test.c index 9007fb04343b..5a4c8b1873aa 100644 --- a/tools/testing/selftests/kvm/x86_64/evmcs_test.c +++ b/tools/testing/selftests/kvm/x86_64/evmcs_test.c @@ -81,10 +81,10 @@ void guest_code(struct vmx_pages *vmx_pages) enable_vp_assist(vmx_pages->vp_assist_gpa, vmx_pages->vp_assist); evmcs_enable(); - GUEST_ASSERT(vmx_pages->vmcs_gpa); GUEST_ASSERT(prepare_for_vmx_operation(vmx_pages)); GUEST_SYNC(3); - GUEST_ASSERT(load_vmcs(vmx_pages)); + GUEST_ASSERT(load_evmcs(vmx_pages->enlightened_vmcs_gpa, + vmx_pages->enlightened_vmcs)); GUEST_ASSERT(vmptrstz() == vmx_pages->enlightened_vmcs_gpa); GUEST_SYNC(4); -- 2.37.3