From patchwork Tue Nov 1 14:54:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitaly Kuznetsov X-Patchwork-Id: 13731 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3024317wru; Tue, 1 Nov 2022 08:03:32 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7+EQhS2bUVzl737eVxWi7lu5gTBacEAPWbMQ38AHcjAr5HbKLyxKKHmhvMQcKtJE6VQjdd X-Received: by 2002:a17:907:a40f:b0:7ad:b9b7:582c with SMTP id sg15-20020a170907a40f00b007adb9b7582cmr16295542ejc.347.1667315012562; Tue, 01 Nov 2022 08:03:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667315012; cv=none; d=google.com; s=arc-20160816; b=ypiBdeVnwTYjDWBOOFY67AnLy0Pe1FQbwfil9n5JpVTWfu2DW+H5LjngdqjTiBxTfW V4D46zOuLByxd6wLH3ai/BIFeyHoNU0nZ1nubdGzjEUkIagUUYQRZLsD3iKi45Tua9zi UAjxgU5H2jES/pq74KFW0YceeTMtpZWML2V1l8jtKZc2YoAOztOp05t7ARY0tAKAe9Lh HwjMy6mOP2qGLK6dDSBqbGElH41oNHiPpp+bbExLZsjEV2HqqfClEKQigVArwB4BRP7O +uuXoJ/EhDSzhFWSwc6SL+BR4uDojSKJI0eQ+UNA3ipUQkFULN5Rxxv2kVWlJW4LazBI sbEQ== 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=PNvFTxM57Y73cI9t4AF88vWy8qZeNx5swgKu92YcL80=; b=Na67rcGnPhB9xGTAmq7FpYi1ZWgcCtPfURuRlW7mLBAVpJKmU8K9VOCPZ8wQDMpDwR QR+HDdhKPHaJTUVlNDeh4u8dXPbdl8nFEHKKdIcjcqqlBbjJ/yw2+3adbhLa7AcxIXhk ORxiImb+RXquS+b8sxhvJvO6f/CfNmbyvct9jdjPc/sIwmlUGcc2PGEAmIPt3/73noCU uunPO1NrBuVJiIuTrJBh3geIVJygb9ERDKL/vRXvYsspG8oy66FR0fKm1xqx2ESf5xYj 1Pa+wOORZCRXAL6MgX+sE2vSWVVc4I9vzfWrOkjTanmqiU9K8nO57eCXFo9i/sjCuDMt /cwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KH0a9sH+; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jl12-20020a17090775cc00b0078e1b6060f7si9636037ejc.299.2022.11.01.08.03.06; Tue, 01 Nov 2022 08:03:32 -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=KH0a9sH+; 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 S230438AbiKAPC1 (ORCPT + 99 others); Tue, 1 Nov 2022 11:02:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231371AbiKAPBv (ORCPT ); Tue, 1 Nov 2022 11:01:51 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 633F81E3CC for ; Tue, 1 Nov 2022 07:57:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667314606; 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=PNvFTxM57Y73cI9t4AF88vWy8qZeNx5swgKu92YcL80=; b=KH0a9sH+REv9Nny/1TOGNgwQ4S+E2XCY0uPbJJXF5JbsXKMnDELhQ5M5A/x8JNHtEnwGrv 9ANAEf9HzjV8mN5HZT4HYrp5Y/S4dQoFpqSInQoydxaPZgpQ7R4IbUdbKu2zRJAwV/2YpK FYgtgGCdhcbIvt3WFOxDDekJnpL/LaQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-336-7SUJriguPcyMk6Bex0JHtw-1; Tue, 01 Nov 2022 10:56:45 -0400 X-MC-Unique: 7SUJriguPcyMk6Bex0JHtw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 45A18857F92; Tue, 1 Nov 2022 14:56:45 +0000 (UTC) Received: from ovpn-194-149.brq.redhat.com (ovpn-194-149.brq.redhat.com [10.40.194.149]) by smtp.corp.redhat.com (Postfix) with ESMTP id 23687C15BA5; Tue, 1 Nov 2022 14:56:43 +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 v13 41/48] KVM: selftests: Split off load_evmcs() from load_vmcs() Date: Tue, 1 Nov 2022 15:54:19 +0100 Message-Id: <20221101145426.251680-42-vkuznets@redhat.com> In-Reply-To: <20221101145426.251680-1-vkuznets@redhat.com> References: <20221101145426.251680-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748306506403131673?= X-GMAIL-MSGID: =?utf-8?q?1748306506403131673?= 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(). Reviewed-by: Sean Christopherson 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 d21049c38fc5..40e4f427a3ec 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/vmx.c +++ b/tools/testing/selftests/kvm/lib/x86_64/vmx.c @@ -171,26 +171,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);