Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp484019rwb; Tue, 4 Oct 2022 06:47:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4p9hZGkyH0VC9Z3FAAkk00AdGCv4k6GChqJT/mkQIrudfLnuEdQeGTgAG1s0GKBkcPEsNs X-Received: by 2002:a17:907:a48:b0:77c:51b0:5aeb with SMTP id be8-20020a1709070a4800b0077c51b05aebmr20008282ejc.61.1664891230069; Tue, 04 Oct 2022 06:47:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664891230; cv=none; d=google.com; s=arc-20160816; b=b+e/IgHlAVqofxBiWLm2vWNlya4oEIIduCQgmq2zd314LcfycbcDWjkoSEtM5P+MMn uFDH9AEsu9CsBEenQW1vrAaVh/g2nIpXlgTOr5BB0zz0A92AkIeOorI+9yPq9jKJ5VM5 YhtD6v8DkKtiX2Y5Ikr9b9JDlVLtoW7ukjNM03K1yBnMg5m0EQ9AQkdHyIjBpUWoZ9RU X270+0wf/cxE3QPMvBYesmCjOKSJrXsmjyKj/0tjgfCEhdyT65sAdSoIgzq021o2T9NM sCT+KUmOmiIJbmk7PB3Lujom3/d6alLToQw+JjDiSeum9JxFzPcFW1WvMyiAq/svLDjz l3zA== 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=8SJZaLliBDTJ2OenxBQMaGzRSU0FBn525QV6K9dfVAQ=; b=KcHsq0YeqMXOkSQ6VB42Vm+yb0+cAaaMTOhQdYMID2/5WB40AAxsjLQvKBZv/atQdX uDkucgyUmADc5MxEG/pVPRpy6C2mSlXFLTbmoWrPlVZSDo0qG0aritcYDIo7NpgNBi6U FTeo7kOMnKWNH/yLeRX2JcNl/E54Dui1QyoaaO2FYrcrn7HXSEXU8TxyU1d/eCz9rIhl J2RwGSOiF+0l85epHTVOpTyZz4py16bmX+BHLcBj4je6TcyOkNKqMFuqa1qT5zo91h/L hxQuIRC36nA5QaQvtXOg49IBOOSCVe8mD+uCz9hz3MJsBphcO6XP+no3NZKbLMrhP44x 953Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=X1JepB+b; 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 dt14-20020a170907728e00b00730c1850171si10995989ejc.800.2022.10.04.06.46.45; Tue, 04 Oct 2022 06:47:10 -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=X1JepB+b; 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 S230212AbiJDMov (ORCPT + 99 others); Tue, 4 Oct 2022 08:44:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230178AbiJDMoX (ORCPT ); Tue, 4 Oct 2022 08:44:23 -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 1726F5D114 for ; Tue, 4 Oct 2022 05:43:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664887281; 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=8SJZaLliBDTJ2OenxBQMaGzRSU0FBn525QV6K9dfVAQ=; b=X1JepB+bExcmD65f2GRKOxAIgju6lLuOJ0TUxs9cDgwH21wknnkr25/BQ/qYjTUgqNyFxC 13DNUov2QYe8DmwVmbMNQ2Q8DyybkKee2MO/ar8kh5BIbaviOCRuHZj6oO8MmYdHDzd9hT 9UESMhnJkIbKtPGgVZp5044qZw6OdDU= 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-453-DOsKC8dFOWW4Lzp-ictNPQ-1; Tue, 04 Oct 2022 08:41:18 -0400 X-MC-Unique: DOsKC8dFOWW4Lzp-ictNPQ-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 DDB1D185A7AA; Tue, 4 Oct 2022 12:41:17 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.192.255]) by smtp.corp.redhat.com (Postfix) with ESMTP id E13007AE5; Tue, 4 Oct 2022 12:41:15 +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 32/46] KVM: selftests: Move the function doing Hyper-V hypercall to a common header Date: Tue, 4 Oct 2022 14:39:42 +0200 Message-Id: <20221004123956.188909-33-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 All Hyper-V specific tests issuing hypercalls need this. Reviewed-by: Maxim Levitsky 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 { -- 2.37.3