From patchwork Tue Nov 1 14:54:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitaly Kuznetsov X-Patchwork-Id: 13723 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3023070wru; Tue, 1 Nov 2022 08:01:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM60or23VOUsxVOqroaUd7+KP6joK3WqykmmkJiGC/zpK14CxobGPWTSqZ5Kczb3mVy+dwCF X-Received: by 2002:a05:6402:1e89:b0:461:a8b5:402a with SMTP id f9-20020a0564021e8900b00461a8b5402amr19887473edf.336.1667314915561; Tue, 01 Nov 2022 08:01:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667314915; cv=none; d=google.com; s=arc-20160816; b=TPafu0lvbzsbhGKl3qlbQzVCqNqtON1FWmNJgKDmQM9rQ8aZHH2WuupriW8Bskh/1q gVAQD+t9jBDORgmqTcorfB7LT0Ji56CLNYplb+Lhr2HIP/PMWxwPKAvouRzpKP5gNzrf o/zNUf0MDf8iNQeSLbi8yMzdiTdXgS/2YxV7fNuoOtfylHfjOoWH28A+3qjqpkz4sbbv qkW56wqREAd2B2eyS7p2tz+qcqcgdutWg3vYnvPavX/9Jj8X0tcinhuU+YB/UCpD3+Up NndleJXgOZmugBQHGYcznd+t0y+DFqjqn/Ej1wzOXEkybk8pLAutEsx+Km5Ij7W5RbGK fVLw== 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=qQcK4l9u4I2Idc0ITAw2pfMb8xlkAKdpiWoA98ORrTk=; b=tB+bFwbZhWj2QmaAK07qscSFCssJYuFiRsF7RWauEMl5w2j4GeAOtCCDj0GSvQuUKA qh0IqSBsXe2Kj4t3wKDSuTNNo+alfB4aPtVqe/7pTJ/TpkeOqV5ncCNB11+sLRn+DcuU zPDRwo2/QdiuKipMCv+A/UeSbzkbJLxBBK9LMRVaz0L4NAWcws7jl8J3eU0rqQzWqj7z uPLXU6H1fOvmR3XURAq3OwoG8xDSH1SbDrR4tGQXvpIwAAmcqPRBWB80yjodF8GeciiF f8EX3LsREhSjk/bgYkNt/kYUHUi7HLY4nClt9ijb9kJtKK8OAeJTNN81T4kwealt1rps kH7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ReCLmFTG; 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 dt12-20020a170906b78c00b0078d9c0e896bsi9631960ejb.525.2022.11.01.08.01.28; Tue, 01 Nov 2022 08:01:55 -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=ReCLmFTG; 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 S231378AbiKAO7W (ORCPT + 99 others); Tue, 1 Nov 2022 10:59:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231361AbiKAO6c (ORCPT ); Tue, 1 Nov 2022 10:58:32 -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 8EBA96306 for ; Tue, 1 Nov 2022 07:56:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667314569; 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=qQcK4l9u4I2Idc0ITAw2pfMb8xlkAKdpiWoA98ORrTk=; b=ReCLmFTGgkeiYRpCDdo4jldsG+9II0XyeeKg4HBcHfV2AsNKBi9wDv3V7qZFQ9x2+zgFfW WvEQ2NqMCA7GMePvaM5y6ZGan7g4K4GoCXWuKOAv56nK3pcu1bpVUo+TGQZzJxoU8J1Usd e40tU0EygpW9MBHiHICaQqFgczxleWQ= 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-278-O7tw50eVOlC97IovxvtRXQ-1; Tue, 01 Nov 2022 10:56:07 -0400 X-MC-Unique: O7tw50eVOlC97IovxvtRXQ-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 8DD961C004F5; Tue, 1 Nov 2022 14:56:06 +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 5CF08C15BA5; Tue, 1 Nov 2022 14:56:04 +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 32/48] KVM: selftests: Move the function doing Hyper-V hypercall to a common header Date: Tue, 1 Nov 2022 15:54:10 +0100 Message-Id: <20221101145426.251680-33-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?1748306404890416093?= X-GMAIL-MSGID: =?utf-8?q?1748306404890416093?= All Hyper-V specific tests issuing hypercalls need this. Reviewed-by: Maxim Levitsky Reviewed-by: Sean Christopherson Signed-off-by: Vitaly Kuznetsov --- .../selftests/kvm/include/x86_64/hyperv.h | 18 ++++++++++++++++++ .../selftests/kvm/x86_64/hyperv_features.c | 19 +------------------ 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/hyperv.h b/tools/testing/selftests/kvm/include/x86_64/hyperv.h index f0a8a93694b2..40f8b1b423fc 100644 --- a/tools/testing/selftests/kvm/include/x86_64/hyperv.h +++ b/tools/testing/selftests/kvm/include/x86_64/hyperv.h @@ -185,6 +185,24 @@ /* hypercall options */ #define HV_HYPERCALL_FAST_BIT BIT(16) +static inline uint8_t hyperv_hypercall(u64 control, vm_vaddr_t input_address, + vm_vaddr_t output_address, + uint64_t *hv_status) +{ + uint8_t vector; + + /* Note both the hypercall and the "asm safe" clobber r9-r11. */ + asm volatile("mov %[output_address], %%r8\n\t" + KVM_ASM_SAFE("vmcall") + : "=a" (*hv_status), + "+c" (control), "+d" (input_address), + KVM_ASM_SAFE_OUTPUTS(vector) + : [output_address] "r"(output_address), + "a" (-EFAULT) + : "cc", "memory", "r8", KVM_ASM_SAFE_CLOBBERS); + return vector; +} + /* Proper HV_X64_MSR_GUEST_OS_ID value */ #define HYPERV_LINUX_OS_ID ((u64)0x8100 << 48) diff --git a/tools/testing/selftests/kvm/x86_64/hyperv_features.c b/tools/testing/selftests/kvm/x86_64/hyperv_features.c index 71bb91602a7f..5ff4ff2365bb 100644 --- a/tools/testing/selftests/kvm/x86_64/hyperv_features.c +++ b/tools/testing/selftests/kvm/x86_64/hyperv_features.c @@ -13,23 +13,6 @@ #include "processor.h" #include "hyperv.h" -static inline uint8_t hypercall(u64 control, vm_vaddr_t input_address, - vm_vaddr_t output_address, uint64_t *hv_status) -{ - uint8_t vector; - - /* Note both the hypercall and the "asm safe" clobber r9-r11. */ - asm volatile("mov %[output_address], %%r8\n\t" - KVM_ASM_SAFE("vmcall") - : "=a" (*hv_status), - "+c" (control), "+d" (input_address), - KVM_ASM_SAFE_OUTPUTS(vector) - : [output_address] "r"(output_address), - "a" (-EFAULT) - : "cc", "memory", "r8", KVM_ASM_SAFE_CLOBBERS); - return vector; -} - struct msr_data { uint32_t idx; bool available; @@ -79,7 +62,7 @@ static void guest_hcall(vm_vaddr_t pgs_gpa, struct hcall_data *hcall) input = output = 0; } - vector = hypercall(hcall->control, input, output, &res); + vector = hyperv_hypercall(hcall->control, input, output, &res); if (hcall->ud_expected) { GUEST_ASSERT_2(vector == UD_VECTOR, hcall->control, vector); } else {