From patchwork Sat Nov 5 04:56:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 15882 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp808569wru; Fri, 4 Nov 2022 21:58:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM63dZqTGccKvVI4fODU2SX1MGT0KppsrLduckOI7euvOGi/mxqKB4b/M6hAmFn5kJmKgmKt X-Received: by 2002:a63:4549:0:b0:46e:e3b7:88f5 with SMTP id u9-20020a634549000000b0046ee3b788f5mr33298932pgk.102.1667624313267; Fri, 04 Nov 2022 21:58:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667624313; cv=none; d=google.com; s=arc-20160816; b=wM9wOcG/0hfwfWkgP3cZqpmwVz4viF+NH1A4YLNbO+WmdWHJ2Hj5UlBYjRVQc+3xQR ScIvs/qi0lhU8weEmGCh3TZ/iLmxNkUu0oebAnyPRXv8P4jYU9HiFw+F1x5jiQfIdWEP K7/9N714bGaEBppCWY0OQW/8+uZrQr3pTUcqSoNyVKy1GetCx6e20D6R8xZwKOHdQFEG 6c5e11n0uJ+sooxEVHa10vE2d0930t+pCvj3mTZgBGMhAlBJcXVjUVZ/Jex5pIoxnOz6 NJ+gBDff/MbBq6bugNIevqanbTJRCFNKi9YdGkRAD+zZBBo9CuIdwPYJKvXYlN9ieZSz ABGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=BXjcYNaRFsRiTOYj/VSeDrYfnk14qW8dp0T0QhmC01U=; b=1ICAXI7XFB/Lh0mBzARL2Dgb7h6Z4mJEPQE964a0qlk+TKk+cGmieq4G6PmmrrP/9q ru7sCgLwdNB6exD4sNRpOI9gsOScokpmQNCYLTlFOvISWvSMlbUd2wNTVI340gLFsKyG 4pdaKINhIdPy+42mtDds5B1O+mHaCKGUaDHnQyfYyKtl5VmwkbsLK53+t7Qb5fBE+T1g uUk2p8rWotfW9yvY0h/gdM0gjJf4lrzi9psELIoE8bI+H1quWrz01rqFAVmkbHkce+Wm RO0EQGMIDwJzfYTmbdiqaaatbf/fexJUrJHIbFzfDFkEmoG86KH3URL+/Md4HE/mDKpE 1UmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=VEy7ANYL; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p20-20020a056a000b5400b005633c373dcbsi1695690pfo.147.2022.11.04.21.58.18; Fri, 04 Nov 2022 21:58:33 -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=@google.com header.s=20210112 header.b=VEy7ANYL; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229608AbiKEE5P (ORCPT + 99 others); Sat, 5 Nov 2022 00:57:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229587AbiKEE5M (ORCPT ); Sat, 5 Nov 2022 00:57:12 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEB8F31DD7 for ; Fri, 4 Nov 2022 21:57:11 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id k131-20020a628489000000b0056b3e1a9629so3264885pfd.8 for ; Fri, 04 Nov 2022 21:57:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=BXjcYNaRFsRiTOYj/VSeDrYfnk14qW8dp0T0QhmC01U=; b=VEy7ANYLdY2iq6bTxxUDZH6+XSU2Nro3Rt2zHGVMA4QIhELj/IrEYMVaEzZGGn3ZuK /aVN+XLpm2LmvYFvB2Gd10hGP/dFIqYq2yj+yM9Gndo6RtIm08NiZCTylamQCEAUGEos KHPhMs/vHmbr50DuZRCNLnCw0oCUd7D4i0lsFgypH9fASd2wgsXDKOa3p1Ze7zQ7lI05 G5o9g23jHCJmOenZVwLG2uLqyO8mKbn1UZW6eXIb+/c0Y7bpFnNrqHaliPBbJL7u8fBY LF44uC5ML5UeFa6fZChqUid+ocL/63nXT436SgeFZcuIMiYYwh4bRNYoRzNT3A/7jpGO DLGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BXjcYNaRFsRiTOYj/VSeDrYfnk14qW8dp0T0QhmC01U=; b=kITcq5n4GdBmJPsb6b3TrPMC8SkKskyydw6s/5SC08wKBLRaZDQ5ONMlYtsicIgmdL rXxBVNBoduiKUo1uoYdxXsH1cOdKNw/2u3Yt2zbDRvtijBHOgiZB7PA8MCXAX3KsHoTD /eX/vBlfkSEnbulNVg+fANkAlkFRfRAEYjgWp2kRxp2MgXgX4zhsl1BsSjP+mXiJyvXB rLhqi4+Iii9PdZDwAOFVR++Y3fbBRvyneNBHpfdADsfRnnAsv0CXcHBmYI9mM5NshFWx ODmR19OVrRNdytjEByG4CGv3fC19tt5sg6GNolSlHROMqTp3JQMoC/Zg/qnt2A5yGE1X a8Tg== X-Gm-Message-State: ACrzQf2NH9DhJI9VkzVl536V561vE91iKwehIMMN//+ZYZth4U6k75HE Dh/LALMkIGVppvxPJM2NnKag5IZ7PTM8 X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a17:902:e883:b0:186:99e3:c079 with SMTP id w3-20020a170902e88300b0018699e3c079mr433741plg.149.1667624231359; Fri, 04 Nov 2022 21:57:11 -0700 (PDT) Date: Fri, 4 Nov 2022 21:56:59 -0700 In-Reply-To: <20221105045704.2315186-1-vipinsh@google.com> Mime-Version: 1.0 References: <20221105045704.2315186-1-vipinsh@google.com> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog Message-ID: <20221105045704.2315186-2-vipinsh@google.com> Subject: [PATCH 1/6] KVM: x86: hyper-v: Use common code for hypercall userspace exit From: Vipin Sharma To: seanjc@google.com, pbonzini@redhat.com, vkuznets@redhat.com Cc: dmatlack@google.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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?1748630831506386963?= X-GMAIL-MSGID: =?utf-8?q?1748630831506386963?= Remove duplicate code to exit to userspace for hyper-v hypercalls and use a common place to exit. Signed-off-by: Vipin Sharma Suggested-by: Sean Christopherson --- arch/x86/kvm/hyperv.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c index 0adf4a437e85..db2f96a0ae23 100644 --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -2270,14 +2270,7 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu) ret = HV_STATUS_INVALID_HYPERCALL_INPUT; break; } - vcpu->run->exit_reason = KVM_EXIT_HYPERV; - vcpu->run->hyperv.type = KVM_EXIT_HYPERV_HCALL; - vcpu->run->hyperv.u.hcall.input = hc.param; - vcpu->run->hyperv.u.hcall.params[0] = hc.ingpa; - vcpu->run->hyperv.u.hcall.params[1] = hc.outgpa; - vcpu->arch.complete_userspace_io = - kvm_hv_hypercall_complete_userspace; - return 0; + goto hypercall_userspace_exit; case HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST: if (unlikely(hc.var_cnt)) { ret = HV_STATUS_INVALID_HYPERCALL_INPUT; @@ -2336,14 +2329,7 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu) ret = HV_STATUS_OPERATION_DENIED; break; } - vcpu->run->exit_reason = KVM_EXIT_HYPERV; - vcpu->run->hyperv.type = KVM_EXIT_HYPERV_HCALL; - vcpu->run->hyperv.u.hcall.input = hc.param; - vcpu->run->hyperv.u.hcall.params[0] = hc.ingpa; - vcpu->run->hyperv.u.hcall.params[1] = hc.outgpa; - vcpu->arch.complete_userspace_io = - kvm_hv_hypercall_complete_userspace; - return 0; + goto hypercall_userspace_exit; } default: ret = HV_STATUS_INVALID_HYPERCALL_CODE; @@ -2352,6 +2338,15 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu) hypercall_complete: return kvm_hv_hypercall_complete(vcpu, ret); + +hypercall_userspace_exit: + vcpu->run->exit_reason = KVM_EXIT_HYPERV; + vcpu->run->hyperv.type = KVM_EXIT_HYPERV_HCALL; + vcpu->run->hyperv.u.hcall.input = hc.param; + vcpu->run->hyperv.u.hcall.params[0] = hc.ingpa; + vcpu->run->hyperv.u.hcall.params[1] = hc.outgpa; + vcpu->arch.complete_userspace_io = kvm_hv_hypercall_complete_userspace; + return 0; } void kvm_hv_init_vm(struct kvm *kvm) From patchwork Sat Nov 5 04:57:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 15883 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp808683wru; Fri, 4 Nov 2022 21:58:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5GaRUXZF0GRmP4Vmh8jBuEHAgHO00MgGV2806dIMwEiYe/ch4uLGaCvwWrPA6VUPE+lqF3 X-Received: by 2002:a17:902:b28c:b0:186:708e:6ed7 with SMTP id u12-20020a170902b28c00b00186708e6ed7mr38628414plr.98.1667624333670; Fri, 04 Nov 2022 21:58:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667624333; cv=none; d=google.com; s=arc-20160816; b=sofjigwmb8duc65b6v80/HqmRIgWvKoQ0jylnwKAhYqjfh+rQZMVqSPbqQQ4fJhal5 Dd9LqkbClfG5t6figO8zAAUxiJdmNyJsrxzIIHW+lIkS2gXAUHcf5QnrbdUrspBKI9ie DBYxDTgSW3jQF31XWXN3+imuMQBxGWcNw36JMcp64K7ECjdL7JXtnOzCCB5oTyYY1ook 1H2kYxt5OB/XXHdGzYRJpb14FlfTNryKrknDCEFVCIiX77R8bOpyXhxPNTKxVKyH2E/z c39HAHBX4GidgedNlBTFhj90XypgXyNBQtaBoKiKRIiV2cC2R32Yfec2RK3UMdS8+Gbq NCLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=BW+rPCZyrgfGjBQ3NJWBgC70ZM2E4N7Rxm+O8srguEk=; b=sAkrrTUHlFyiX7kb7/OqqzkuZiZXlXazwMuu0WrySMBLhiogAl8vsDnIpAK6gxjZ93 fqzcb7ybdf04ewLn+Pfnw3gt/Qtm68uuOgO8HVsz0oS3PuwqG9sD1HLHlziru7vE/61I NeeywY/mM79BtyDWaoDhbEWXT4XQkBBIEdLrb03X+VHIgBLirD7+g6k5Dw5OKhVAceN2 Q33QtOKm8vXrKkxHlL5QsZFINiIGC8BNYeno4oWxshe1LOfDsHasLENb3d1tAFiTjkrc ud3qZqoLZoqkM1gEnGYiIkiULW2mwfApn9domdLsv1ek7Kyou1YWwJEfkB/6Mv6Kdaom q/kA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=pAlbE6bc; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l72-20020a63914b000000b004703fc2ac2fsi1715309pge.877.2022.11.04.21.58.41; Fri, 04 Nov 2022 21:58:53 -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=@google.com header.s=20210112 header.b=pAlbE6bc; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229563AbiKEE5S (ORCPT + 99 others); Sat, 5 Nov 2022 00:57:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229595AbiKEE5O (ORCPT ); Sat, 5 Nov 2022 00:57:14 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5F0231DD7 for ; Fri, 4 Nov 2022 21:57:13 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-36fde8f2cdcso62957267b3.23 for ; Fri, 04 Nov 2022 21:57:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=BW+rPCZyrgfGjBQ3NJWBgC70ZM2E4N7Rxm+O8srguEk=; b=pAlbE6bcgnNjnuoJ+rX9hnRtuqI6cTg40qoUAFHN13LuRDcL3E92YcRjLGNk/oYc1n lMjbz30yCvufkdfqXQA3/fxMYImVQZbw8fw0LLfvujVII+d/gJtZGk5OZx3Y6xX2UlKX clwas/NpZLJ4598nf/qr4z3AU+hMroJYTuPVhS9X4Wn2eWqc7fHYGbaHKeSCL2ATiJNu 8TZHj0l1n2OEFVQXolbTx96GQC5QgT9/DCwhp9kQQSokd2g6V9quOCvzJSUgR82+Y64R w+kULRNopwY+6Gwt94hupB3kAPy6suRLjrZ8REtS5eZPl30kqte/ubZfadv4N4iqV7V5 Sdpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BW+rPCZyrgfGjBQ3NJWBgC70ZM2E4N7Rxm+O8srguEk=; b=VimZXBP1J0OP+En9F0vCkD2cfTnxTwDj5WCeL/fOWO/nI2+H6G8Va9/oRVmdSrOoaN +32XbNWUSgeQ+BViLycF5rGJVyAlR1O+sptqT4qVVGvBkCdXMs/HVJ8ORJscM7+FpIW/ 1Oi8am4bMQAeYoxnjo4Sy8SF50+d7ZGiFcziuhE/Mrmx3URZ6RY4A91kAivJ4NF8KR9s JIG2CEPxw1CUZd4YiZEoRr7soIYDTqTwrJMLCIehdaZuyRo9aMV28xSVu+/cvWaT/kze vQoQ9wghc8ROhva6Du4NVu09ZFsuK6XDKwbShgz3y7FzPlEfLEweE2sLkKPTkIAIKdBX ENrg== X-Gm-Message-State: ACrzQf2J2QjoZtxQ1eRPeCaWf6FIm3hmcQgEicrffRDEu9q5pFowyJ4F u0nzhaTcwPTLk1kDpOjT1ZfRhaQhHWpz X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a5b:a0f:0:b0:691:6fea:deda with SMTP id k15-20020a5b0a0f000000b006916feadedamr37985774ybq.377.1667624233167; Fri, 04 Nov 2022 21:57:13 -0700 (PDT) Date: Fri, 4 Nov 2022 21:57:00 -0700 In-Reply-To: <20221105045704.2315186-1-vipinsh@google.com> Mime-Version: 1.0 References: <20221105045704.2315186-1-vipinsh@google.com> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog Message-ID: <20221105045704.2315186-3-vipinsh@google.com> Subject: [PATCH 2/6] KVM: x86: hyper-v: Add extended hypercall support in Hyper-v From: Vipin Sharma To: seanjc@google.com, pbonzini@redhat.com, vkuznets@redhat.com Cc: dmatlack@google.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable 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?1748630853175596514?= X-GMAIL-MSGID: =?utf-8?q?1748630853175596514?= Add support for extended hypercall in Hyper-v. Hyper-v TLFS 6.0b describes hypercalls above call code 0x8000 as extended hypercalls. A Hyper-v hypervisor's guest VM finds availability of extended hypercalls via CPUID.0x40000003.EBX BIT(20). If the bit is set then the guest can call extended hypercalls. All extended hypercalls will exit to userspace by default. This allows for easy support of future hypercalls without being dependent on KVM releases. If there will be need to process the hypercall in KVM instead of userspace then KVM can create a capability which userspace can query to know which hypercalls can be handled by the KVM and enable handling of those hypercalls. Signed-off-by: Vipin Sharma --- arch/x86/kvm/hyperv.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c index db2f96a0ae23..85c6100f4451 100644 --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -40,6 +40,12 @@ #define KVM_HV_MAX_SPARSE_VCPU_SET_BITS DIV_ROUND_UP(KVM_MAX_VCPUS, 64) +/* + * The TLFS carves out 64 possible extended hypercalls, numbered sequentially + * after the base capabilities extended hypercall. + */ +#define HV_EXT_CALL_MAX (HV_EXT_CALL_QUERY_CAPABILITIES + 64) + static void stimer_mark_pending(struct kvm_vcpu_hv_stimer *stimer, bool vcpu_kick); @@ -2178,6 +2184,9 @@ static bool hv_check_hypercall_access(struct kvm_vcpu_hv *hv_vcpu, u16 code) case HVCALL_SEND_IPI: return hv_vcpu->cpuid_cache.enlightenments_eax & HV_X64_CLUSTER_IPI_RECOMMENDED; + case HV_EXT_CALL_QUERY_CAPABILITIES ... HV_EXT_CALL_MAX: + return hv_vcpu->cpuid_cache.features_ebx & + HV_ENABLE_EXTENDED_HYPERCALLS; default: break; } @@ -2331,6 +2340,12 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu) } goto hypercall_userspace_exit; } + case HV_EXT_CALL_QUERY_CAPABILITIES ... HV_EXT_CALL_MAX: + if (unlikely(hc.fast)) { + ret = HV_STATUS_INVALID_PARAMETER; + break; + } + goto hypercall_userspace_exit; default: ret = HV_STATUS_INVALID_HYPERCALL_CODE; break; @@ -2489,6 +2504,7 @@ int kvm_get_hv_cpuid(struct kvm_vcpu *vcpu, struct kvm_cpuid2 *cpuid, ent->ebx |= HV_POST_MESSAGES; ent->ebx |= HV_SIGNAL_EVENTS; + ent->ebx |= HV_ENABLE_EXTENDED_HYPERCALLS; ent->edx |= HV_X64_HYPERCALL_XMM_INPUT_AVAILABLE; ent->edx |= HV_FEATURE_FREQUENCY_MSRS_AVAILABLE; From patchwork Sat Nov 5 04:57:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 15884 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp808743wru; Fri, 4 Nov 2022 21:59:09 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7v3IKadMmcM6SrnXHGJCJiStF7+VfrVuwGAWCegteV2yLoJESJfIzSzTjSzTdbz8ZT9dEV X-Received: by 2002:a63:c04b:0:b0:46f:c183:242d with SMTP id z11-20020a63c04b000000b0046fc183242dmr25405039pgi.287.1667624348874; Fri, 04 Nov 2022 21:59:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667624348; cv=none; d=google.com; s=arc-20160816; b=Ynns+IA6xgiGFuBpvolEvWJ1EYIhswDEx39HKe8tUxBJgN1rRAHP7g7G54RsKXTRqR FXPrW/jS/ndN82rvQqQARO+B3b5FWCyVf05tdFyvztm1Rpc0RFAxEJJOGcmV8MjNU8vd dm8tLkx7szOqVYMo/j6n+gTFIsRaH3HDbp4aIaceYWicf2LupZ3e1AWHzFATt+Glh66K V+XydB5I3dHS5pHgGlVquIEvDbDp5PIW9xB7BaEtwT1V1J83zWx+oAu5CZiXBjI8EY7h a5zL3dFELxgR7tn52ggUCs6/2Bayx83r/2z+FFOHYK2XfQZQsYpDzemqoFBzZPjOafC4 xV2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=n6Upwu++k4u4pvTQ5ggpu28fN9WErU6ZbFJtDquZjUo=; b=DY8fvxFJB5LKG99FzoWe31RMPGFd7xXyEhFL+2va0CrzUcn5O03VYJfvX1mWyWajQa K4UnqnEmrpwvjWE+r6fboI0FqGsrR+IVBUoNW0EhXQWB5mDitt8DhoIIb0FC0tr47SOT UukgggfpZg98KrmFTPrZrysaQWcCbzHnbJKD7xRBobK54Vx7uZTFmD5T8TTDpmG/hrla G2Yvhe+pJ7Tf2QwlQGYmB4Sg9/W8HlJkmn/8XOSoUCDfhueh9714I559C9j+H0uYrqGH BijcNlJMWNITkab7s1uyTvZlBf5UMd8/eSC+Ci4+Y7qnFaOuTC++3JwX7NNaUYFJK0xQ Y+4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=gwunFD8X; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q12-20020a63cc4c000000b0046abab88fd9si1908496pgi.677.2022.11.04.21.58.56; Fri, 04 Nov 2022 21:59:08 -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=@google.com header.s=20210112 header.b=gwunFD8X; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229645AbiKEE5W (ORCPT + 99 others); Sat, 5 Nov 2022 00:57:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229603AbiKEE5P (ORCPT ); Sat, 5 Nov 2022 00:57:15 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2090E31F9D for ; Fri, 4 Nov 2022 21:57:15 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id g66-20020a636b45000000b0043a256d3639so3442308pgc.12 for ; Fri, 04 Nov 2022 21:57:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=n6Upwu++k4u4pvTQ5ggpu28fN9WErU6ZbFJtDquZjUo=; b=gwunFD8XRkB8tadYDha1qv/kRbDMr1XGQO+PmaHs5uPp80MzHt+AYtQBb1FEzg2RAR irHZokc2miBdZR7YaSYRWxBK9nEUsVNpZAOBvsupFTUytJOg0+ds2NYQoQyerq34hC+Y p1PkX1fGoXWBXXMPOx0mOyo/iwgTfnPgZzICMEnTkZu0mWKshtik31He5oszFlNyrz43 e7QeYPXeLdVF52hlBSFEjC/RJ3015l9aQEm4B7lVy9hj/5RtnywsGszEMFAL6k32tKvw jceiWseFi+j95U9168l+lnNladYXUm0KgO269XNo2V/8aVxzeNpZrKZFTqCmuY9a3kQ9 e2eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=n6Upwu++k4u4pvTQ5ggpu28fN9WErU6ZbFJtDquZjUo=; b=FBg/pknOhYhIdmfjEnJVvHXFd72lJl4uvDqEJXfgBcVxcjHSS0FCD7N+Pn0gTcw8eX ZX6h8iX72oGUcK5zDipBosDNUUeDEMc+xdmaC9fjgnFHiT0NQbaqPu9EJ5Vqm7cQ1sY9 unHsZvKqyzWmjfGssEuLV1vxOfkSuzbNOLinLE38iJCGKri1NEfj5IVI8XyJkZpIfSOD sHW9jSL4yAEFzEB9k9ulnhn7g/JFeASJ+T/Fof3ewhMJJ7f5lPxHCvmUljXY87UPgtT/ Hy39z7PSp8ARkWTNFiweMsD08NKHUrDxL6TFGVfDepcGzKy8uFgX9sOnxzfTXWPlN5lJ yB2Q== X-Gm-Message-State: ACrzQf2f2rW9tUnP7ZxhltpOKBubcHSFwTCEZKd4IxokGFRT1ywF5DL/ hvBG+ke0Yx2sIrFkaeNUsvrN5+Q3QOZc X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a05:6a00:2409:b0:54e:a3ad:d32d with SMTP id z9-20020a056a00240900b0054ea3add32dmr38883061pfh.70.1667624234662; Fri, 04 Nov 2022 21:57:14 -0700 (PDT) Date: Fri, 4 Nov 2022 21:57:01 -0700 In-Reply-To: <20221105045704.2315186-1-vipinsh@google.com> Mime-Version: 1.0 References: <20221105045704.2315186-1-vipinsh@google.com> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog Message-ID: <20221105045704.2315186-4-vipinsh@google.com> Subject: [PATCH 3/6] KVM: selftests: Test Hyper-V extended hypercall enablement From: Vipin Sharma To: seanjc@google.com, pbonzini@redhat.com, vkuznets@redhat.com Cc: dmatlack@google.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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?1748630869295286554?= X-GMAIL-MSGID: =?utf-8?q?1748630869295286554?= Test Extended hypercall CPUID enablement Signed-off-by: Vipin Sharma --- tools/testing/selftests/kvm/include/x86_64/hyperv.h | 4 ++++ tools/testing/selftests/kvm/x86_64/hyperv_features.c | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/tools/testing/selftests/kvm/include/x86_64/hyperv.h b/tools/testing/selftests/kvm/include/x86_64/hyperv.h index b66910702c0a..075fd29071a6 100644 --- a/tools/testing/selftests/kvm/include/x86_64/hyperv.h +++ b/tools/testing/selftests/kvm/include/x86_64/hyperv.h @@ -110,6 +110,7 @@ #define HV_ACCESS_STATS BIT(8) #define HV_DEBUGGING BIT(11) #define HV_CPU_MANAGEMENT BIT(12) +#define HV_ENABLE_EXTENDED_HYPERCALLS BIT(20) #define HV_ISOLATION BIT(22) /* HYPERV_CPUID_FEATURES.EDX */ @@ -164,6 +165,9 @@ #define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE 0x00af #define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_LIST 0x00b0 +/* Extended hypercalls */ +#define HV_EXT_CALL_QUERY_CAPABILITIES 0x8001 + #define HV_FLUSH_ALL_PROCESSORS BIT(0) #define HV_FLUSH_ALL_VIRTUAL_ADDRESS_SPACES BIT(1) #define HV_FLUSH_NON_GLOBAL_MAPPINGS_ONLY BIT(2) diff --git a/tools/testing/selftests/kvm/x86_64/hyperv_features.c b/tools/testing/selftests/kvm/x86_64/hyperv_features.c index 05b32e550a80..6b443ce456b6 100644 --- a/tools/testing/selftests/kvm/x86_64/hyperv_features.c +++ b/tools/testing/selftests/kvm/x86_64/hyperv_features.c @@ -602,6 +602,15 @@ static void guest_test_hcalls_access(void) hcall->expect = HV_STATUS_SUCCESS; break; case 19: + hcall->control = HV_EXT_CALL_QUERY_CAPABILITIES; + hcall->expect = HV_STATUS_ACCESS_DENIED; + break; + case 20: + feat->ebx |= HV_ENABLE_EXTENDED_HYPERCALLS; + hcall->control = HV_EXT_CALL_QUERY_CAPABILITIES | HV_HYPERCALL_FAST_BIT; + hcall->expect = HV_STATUS_INVALID_PARAMETER; + break; + case 21: kvm_vm_free(vm); return; } From patchwork Sat Nov 5 04:57:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 15885 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp809788wru; Fri, 4 Nov 2022 22:02:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6jJiJtjrHI4923RNDHjm4RBoRAhk2+rhYOIT7MrrOlgoLj2QJyZcjcjqJEQAX2V+NjqY15 X-Received: by 2002:a63:2544:0:b0:46f:ed91:33ca with SMTP id l65-20020a632544000000b0046fed9133camr18449837pgl.383.1667624530977; Fri, 04 Nov 2022 22:02:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667624530; cv=none; d=google.com; s=arc-20160816; b=QUuKvaqwecQqYnu8elWtEwZ+k0XhC85JFTm7WsAOafVlyTKIVnrzFZSDIbjpH9KOF4 lwIkXH5lqfNYG0PZ5jfbmKizm1M5K/xrCeAZvt7KekXS9/BYavemln8q19qfyVzl8j53 BgZGXuKeCuEwOb9IrKqfKC6Qe9J2BoYvLauu9FJ/PZUEHETBEhQEzLbKoX7wydTKJ3fg lWzQ+DYl8uuh1dL9BUwvobATncobMPuLZNz8e+h+YV4wR0AVh3qH0Lv/Pe/QC6fBqCgZ SDw2jYAP6pSJ6yl697ohG6TU3l0cPrjFTxS0kkYIP0JLh+Jzpasji604kOYIHj7Yk5G/ PEYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=gZsOXIQ/ETlFCBETTe/elKVE4lpjamgAUlI2bZ+SvJc=; b=lK4qH28PfPdW2cT5ltwjO5FKK7KzL5XdQ4gA5Pm1beYl1Ivx1ZGeMCHu/SWWsf6Ez0 5cqxVgcdXHSQdJT28fl9q4squh2KOHjbsXdBQFYW3Vy72znIlRG1hC9t6H3IGcQlUaxI HO3VmZMx58L+IQTkvWKp64C5EQ/AmIyaw9pFABRzljdLELgehnLSKLX51JAMgSlzAfjn P49l7MQS2gQt4Ep4oEaeHjf/YiWsUtTMxeExTDi52x3qTPMzjBEwf4hRMZqBZSixkvSw uren/5+47FiZRfE9xIwf2PM3u/VeWVfBleflMfxbO32WQYulEPyEMkOuZLhsAqeE12Qb HCUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=jB5l9Hay; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f7-20020a656287000000b0046ff26f21f0si1811882pgv.503.2022.11.04.22.01.57; Fri, 04 Nov 2022 22:02: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=@google.com header.s=20210112 header.b=jB5l9Hay; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229679AbiKEE5a (ORCPT + 99 others); Sat, 5 Nov 2022 00:57:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229628AbiKEE5S (ORCPT ); Sat, 5 Nov 2022 00:57:18 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A26432BBD for ; Fri, 4 Nov 2022 21:57:17 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id f186-20020a636ac3000000b0044adaa7d347so3430935pgc.14 for ; Fri, 04 Nov 2022 21:57:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=gZsOXIQ/ETlFCBETTe/elKVE4lpjamgAUlI2bZ+SvJc=; b=jB5l9Hayd7t9U2kjL83ltyjH3Fv+WtodRQcAlUj5Es6ZLiwVw+6vA0eIgG4QChDpWm qp97gIUIxTuhE8CWduUzsHWOHOaOc0cDlf58T7tROsRAsdnWkInlARWh8Q7AI3SF+UOf XIDyiMmkY9dKUGQuS0BWS6DlZ6s2LhcRrdf3AxedTUAp9uyDF8HyV7cPWu76Tc62OWgE +r333jvm8DKwfwdSxuekRtSS1+lkpnMhLgp9Re9QXOozWKUs8BUraLGvXaClX120fr+w iJm8sdJwJif+9C4KMMhykA94EhrQ4CEwxShXIwEqo6OQdiOR62eTPe43L1+UURPdKGE8 lhLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gZsOXIQ/ETlFCBETTe/elKVE4lpjamgAUlI2bZ+SvJc=; b=rNt96UsOHl2Gl0ojXiG178CfuGn3K2308uXQJcx7kW6X9+tXFjOylu4WycNrzd7vv7 pJWWnQn0oTXxbnvsggqLuEbl+nX9b8v8pabU7fN9PloJNyC5p8N0jYnE4irtHlLAtH/o TptwRryC/6vD3QnxxAZqRr8uAiMBHkUHcbRin14qjNPvk/DoZUH4s6c+RRBJpXhcRTJo nhYAIc8MZHNtsgz/x1ByjIUetcG4h/Q0y8GThcVmM/cI/N09RCRyzEoTwq9cA8ApTWEm +WZN+d6HYclJX+bwipngFKQJwwmuYA5mHv3la6GA4/5i02oNVFRXyhSivFNgEO6QgGCx VJnw== X-Gm-Message-State: ACrzQf1078+OLxQvoTZu25jiHVkOpNGL3FTxAUjCkY+gDYO+iFfP/3Q3 j0y9QXHO/BLwxdyUhJpHN7RJk5Mt94R8 X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a05:6a00:218a:b0:56d:1bb6:af4f with SMTP id h10-20020a056a00218a00b0056d1bb6af4fmr36690480pfi.11.1667624236628; Fri, 04 Nov 2022 21:57:16 -0700 (PDT) Date: Fri, 4 Nov 2022 21:57:02 -0700 In-Reply-To: <20221105045704.2315186-1-vipinsh@google.com> Mime-Version: 1.0 References: <20221105045704.2315186-1-vipinsh@google.com> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog Message-ID: <20221105045704.2315186-5-vipinsh@google.com> Subject: [PATCH 4/6] KVM: selftests: Make Hyper-V guest OS ID common From: Vipin Sharma To: seanjc@google.com, pbonzini@redhat.com, vkuznets@redhat.com Cc: dmatlack@google.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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?1748631060499294492?= X-GMAIL-MSGID: =?utf-8?q?1748631060499294492?= Make guest OS ID calculation common to all hyperv tests and similar to hv_generate_guest_id(). Signed-off-by: Vipin Sharma --- tools/testing/selftests/kvm/include/x86_64/hyperv.h | 10 ++++++++++ tools/testing/selftests/kvm/x86_64/hyperv_clock.c | 2 +- tools/testing/selftests/kvm/x86_64/hyperv_features.c | 6 ++---- tools/testing/selftests/kvm/x86_64/hyperv_svm_test.c | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/hyperv.h b/tools/testing/selftests/kvm/include/x86_64/hyperv.h index 075fd29071a6..9d8c325af1d9 100644 --- a/tools/testing/selftests/kvm/include/x86_64/hyperv.h +++ b/tools/testing/selftests/kvm/include/x86_64/hyperv.h @@ -9,6 +9,10 @@ #ifndef SELFTEST_KVM_HYPERV_H #define SELFTEST_KVM_HYPERV_H +#include + +#define HV_LINUX_VENDOR_ID 0x8100 + #define HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS 0x40000000 #define HYPERV_CPUID_INTERFACE 0x40000001 #define HYPERV_CPUID_VERSION 0x40000002 @@ -189,4 +193,10 @@ /* hypercall options */ #define HV_HYPERCALL_FAST_BIT BIT(16) +static inline uint64_t hv_linux_guest_id(void) +{ + return ((uint64_t)HV_LINUX_VENDOR_ID << 48) | + ((uint64_t)LINUX_VERSION_CODE << 16); +} + #endif /* !SELFTEST_KVM_HYPERV_H */ diff --git a/tools/testing/selftests/kvm/x86_64/hyperv_clock.c b/tools/testing/selftests/kvm/x86_64/hyperv_clock.c index d576bc8ce823..f9112c5dc3f7 100644 --- a/tools/testing/selftests/kvm/x86_64/hyperv_clock.c +++ b/tools/testing/selftests/kvm/x86_64/hyperv_clock.c @@ -104,7 +104,7 @@ static void guest_main(struct ms_hyperv_tsc_page *tsc_page, vm_paddr_t tsc_page_ /* Set Guest OS id to enable Hyper-V emulation */ GUEST_SYNC(1); - wrmsr(HV_X64_MSR_GUEST_OS_ID, (u64)0x8100 << 48); + wrmsr(HV_X64_MSR_GUEST_OS_ID, hv_linux_guest_id()); GUEST_SYNC(2); check_tsc_msr_rdtsc(); diff --git a/tools/testing/selftests/kvm/x86_64/hyperv_features.c b/tools/testing/selftests/kvm/x86_64/hyperv_features.c index 6b443ce456b6..b5a42cf1ad9d 100644 --- a/tools/testing/selftests/kvm/x86_64/hyperv_features.c +++ b/tools/testing/selftests/kvm/x86_64/hyperv_features.c @@ -13,8 +13,6 @@ #include "processor.h" #include "hyperv.h" -#define LINUX_OS_ID ((u64)0x8100 << 48) - static inline uint8_t hypercall(u64 control, vm_vaddr_t input_address, vm_vaddr_t output_address, uint64_t *hv_status) { @@ -71,7 +69,7 @@ static void guest_hcall(vm_vaddr_t pgs_gpa, struct hcall_data *hcall) GUEST_ASSERT(hcall->control); - wrmsr(HV_X64_MSR_GUEST_OS_ID, LINUX_OS_ID); + wrmsr(HV_X64_MSR_GUEST_OS_ID, hv_linux_guest_id()); wrmsr(HV_X64_MSR_HYPERCALL, pgs_gpa); if (!(hcall->control & HV_HYPERCALL_FAST_BIT)) { @@ -169,7 +167,7 @@ static void guest_test_msrs_access(void) */ msr->idx = HV_X64_MSR_GUEST_OS_ID; msr->write = 1; - msr->write_val = LINUX_OS_ID; + msr->write_val = hv_linux_guest_id(); msr->available = 1; break; case 3: diff --git a/tools/testing/selftests/kvm/x86_64/hyperv_svm_test.c b/tools/testing/selftests/kvm/x86_64/hyperv_svm_test.c index a380ad7bb9b3..2c13a144b04c 100644 --- a/tools/testing/selftests/kvm/x86_64/hyperv_svm_test.c +++ b/tools/testing/selftests/kvm/x86_64/hyperv_svm_test.c @@ -69,7 +69,7 @@ static void __attribute__((__flatten__)) guest_code(struct svm_test_data *svm) GUEST_SYNC(1); - wrmsr(HV_X64_MSR_GUEST_OS_ID, (u64)0x8100 << 48); + wrmsr(HV_X64_MSR_GUEST_OS_ID, hv_linux_guest_id()); GUEST_ASSERT(svm->vmcb_gpa); /* Prepare for L2 execution. */ From patchwork Sat Nov 5 04:57:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 15887 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp820588wru; Fri, 4 Nov 2022 22:32:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6RHoCyxZ8v6HiEnFGuyYroZnaSzA1Cb6VkPJU+eXEMosfWG1ZvvsiZKglkkz8zLftaut8J X-Received: by 2002:a05:6402:31e7:b0:464:6485:419b with SMTP id dy7-20020a05640231e700b004646485419bmr229726edb.382.1667626373738; Fri, 04 Nov 2022 22:32:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667626373; cv=none; d=google.com; s=arc-20160816; b=YVyQoW5U3zTTeQpotu/2m+d7K9Ik3Sx+5cjsl9jOYaTKGwXhZijG8vgk8lsCv6jC7W lyun4iPWFIqCQV14BCE4KQJ5NvYfzd/F7sY9c9fczyXD5PsramN8z86fFdXH3ZyIOg0V h72sQVoa57kRamByxBaFhZY9lO+Y6FoyNglIJEumV+iV+F71DGLEGUMwhQIBsKSdK5zN ElkK59IcUByR8uzD5qHoqmfKhWeIuo/U/+W57t/MQTXK/DcfgWi0O1FbOD4CXTQ71i9/ +9CHNNWW0MUvDy6MqiBDrH5wKXkbbDrVkwMTQm3Cuil+xFR3TwAsSN09lbvKvCmOTKc4 RfAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=WSg0IO7Xl+tozOh4xkbrWeBiwBnKrWj4O0/zH/r779g=; b=OQrOZN4iArK1Uq/wg+yga97mOLOAC64XDqq/SGgNKovJ/0SqFYgfeoZE8Ib1/joJEt G4260koBKmQlzMxEoAYlOmsZhZ97l3XtXcEWL89V5qJ1avAufKvB0bRbOEgjd4GrOmeU lUth8r1QmaKqjme9U5z1lZ8OfMoO2wHWzdULytwe36wfpJktiMuA6ohe92lYWb/S9IAg lX1HXCPtu4FtRNhm0UwxkF8kwdIh6IlJJJBcKBMjJanji22ECTs8Vm9JuhDcu34IhnjL uwDdfMEDVDKhVuMPZPy66eb2Ci1NmiccKulEtU709DUFGcw1D/6StXLLkoHgKkAh2ir6 qFLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=NOQmhkl2; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l21-20020a17090615d500b0078df1c345dasi989564ejd.534.2022.11.04.22.32.30; Fri, 04 Nov 2022 22:32:53 -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=@google.com header.s=20210112 header.b=NOQmhkl2; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229670AbiKEE5d (ORCPT + 99 others); Sat, 5 Nov 2022 00:57:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229593AbiKEE53 (ORCPT ); Sat, 5 Nov 2022 00:57:29 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C94E3F04A for ; Fri, 4 Nov 2022 21:57:19 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-3735edd4083so63088497b3.0 for ; Fri, 04 Nov 2022 21:57:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=WSg0IO7Xl+tozOh4xkbrWeBiwBnKrWj4O0/zH/r779g=; b=NOQmhkl231fjcgvdKUOzvyqky4m6MkeFoOb9YJMy3HeukRVol0YITwYGZxrAlAi1cj mFEKmkYeBHVPyFal3aNYHbnNAyvjJOzq/WYv39vZcBU6tYStPLObeOHlDcCEJ+78d3Ov DwYNm/O5Wce+rPgWTe/K57ztOSfjOabLgjFtrJURD7fGF4BqpahbuVQ4bYQZgJ+OZVK4 aIuToHu+DtIPXdheLe9xhldM9vXJlgsCj52tIJLpFdzQklrBCGg2lvY8FSkPZ8ziUT/x HxSDQgc/j2X2x/o+6bFoK893dTYDyG1lZTrP6nVyHjJbDsL1zveXVc7qTbQf2j3dqVSv oklg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=WSg0IO7Xl+tozOh4xkbrWeBiwBnKrWj4O0/zH/r779g=; b=nfVuuVXkxr8LvoT1JLkdTPBd82jrayVYjEfbeVQ94Ao7jfRsHxMvsxzBi2WcUeNtXr zDcVPrpLdZMMLJ5KfVeI3CX4DJyuiOmOM906GHz6ziWFGjBPXh+D+/e3bvUXmUtWvGlH tCxTxV67Z6O4asXziDvyz39FEugpxrp60EEBm2NMf9JbJyqNaU9mzDu1S0SDDS06VL0J dnsRDnBkuawCjB/f3qE4kcBc3YZry2TxsnJDjDRwWD2hDAUo3XLA8x3ob3n+fbyxATZz QaLpzEUrbT78dBg42eosGJZEaTTGNVYsTChWNsaTSm02OADqTP+J9cMT5OmvUI/kGLoK 9ZEw== X-Gm-Message-State: ACrzQf2le4TpDadnUjgxbpziajEs7x7HjKe9ghAZSgK49qttEn3SFzb4 AY0GTL4TLE5oalhqG8OBou2Jf17U6pxi X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a81:1d95:0:b0:370:744a:5a07 with SMTP id d143-20020a811d95000000b00370744a5a07mr401209ywd.334.1667624238317; Fri, 04 Nov 2022 21:57:18 -0700 (PDT) Date: Fri, 4 Nov 2022 21:57:03 -0700 In-Reply-To: <20221105045704.2315186-1-vipinsh@google.com> Mime-Version: 1.0 References: <20221105045704.2315186-1-vipinsh@google.com> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog Message-ID: <20221105045704.2315186-6-vipinsh@google.com> Subject: [PATCH 5/6] KVM: selftests: Move hypercall() to hyper.h From: Vipin Sharma To: seanjc@google.com, pbonzini@redhat.com, vkuznets@redhat.com Cc: dmatlack@google.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable 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?1748632992499487995?= X-GMAIL-MSGID: =?utf-8?q?1748632992499487995?= hypercall() can be used by other hyperv tests, move it to hyperv.h. Signed-off-by: Vipin Sharma --- .../selftests/kvm/include/x86_64/hyperv.h | 17 +++++++++++++++++ .../selftests/kvm/x86_64/hyperv_features.c | 17 ----------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/hyperv.h b/tools/testing/selftests/kvm/include/x86_64/hyperv.h index 9d8c325af1d9..87d8d9e444f7 100644 --- a/tools/testing/selftests/kvm/include/x86_64/hyperv.h +++ b/tools/testing/selftests/kvm/include/x86_64/hyperv.h @@ -199,4 +199,21 @@ static inline uint64_t hv_linux_guest_id(void) ((uint64_t)LINUX_VERSION_CODE << 16); } +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; +} + #endif /* !SELFTEST_KVM_HYPERV_H */ diff --git a/tools/testing/selftests/kvm/x86_64/hyperv_features.c b/tools/testing/selftests/kvm/x86_64/hyperv_features.c index b5a42cf1ad9d..31b22ee07dfb 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; From patchwork Sat Nov 5 04:57:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 15886 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp818424wru; Fri, 4 Nov 2022 22:27:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6CXLrUpOsPqw4ZJ1JWqfk6W9CzgX1ue2CIEppsSKCHYpgSiBdkjSbjydbbe/CxZkBXzKMX X-Received: by 2002:a50:a406:0:b0:463:4fe5:67d1 with SMTP id u6-20020a50a406000000b004634fe567d1mr30695404edb.151.1667626021320; Fri, 04 Nov 2022 22:27:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667626021; cv=none; d=google.com; s=arc-20160816; b=Vzx6K7fBfTTro6KVCBBn620CfSZNG9dZHOzfiqOH6FWOkUWwLLKtGXLgAQcjq4IKC8 9Qy0gQjXUvVwGwl9g9Q4S7sDXAr6IcLjfEHmTsLRi5LqTbeYb5Kc7fk+Uu0fIrj2RPZB ByOkWSjCp74ZPV6Culq/k30bBBuZdC+i86ILsDNXaCbBcRIH2mW4UD81J0CJzRAVDX8/ YSkLMO0eoyikCKJlsTsIFRDVOvpqJa2PpFJ2sXBAiwbGI7Xq8cnofTfhkO5dpfgOp1Yw 2i3fFyKL4il1LBGJgIwJ8O1o3b2QqJG3FKAOlX0V2X+i66oDlAPkgIIQdz83aUuoJgNJ NIoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=X3X2UKpD6zQllEjbrRaWm6/Z/akGwGuBaRDivMqgr8Q=; b=GO1VTOcMBNU53ZmPu6HVu3AubVu48aoY9v6VLfUmG7nU2dFgjyoPj8JXasFeOcz3R4 SRLGk1lfjCBIcEzxkjDmGsSUYGi1JcFhfHDxrB3Fd/8fek6CPeVtp/NlZb21jKpFULyT EN/gIRLD2V4XVBcqOJ1dFJsv9LfMOSmxBWxFsN70IjmoznzXqT0wj7/cKBJyjuhBMWJF DukAOWNVYqfruWkh8ul57nppk40Pd6159/uiBfksZKit8bfPlbGRiqOWmARFsXhtF+jW MW/8xK7SJJ78CtLYxSqSt639tbxR3km7U+0FdENzQUOhEmydElj08LFgHzarWq7mNN/O NR+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=VIDKnr7o; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bx25-20020a0564020b5900b004636ec90769si1625572edb.33.2022.11.04.22.26.24; Fri, 04 Nov 2022 22:27:01 -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=@google.com header.s=20210112 header.b=VIDKnr7o; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229677AbiKEE5i (ORCPT + 99 others); Sat, 5 Nov 2022 00:57:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229688AbiKEE5a (ORCPT ); Sat, 5 Nov 2022 00:57:30 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7C703FBA3 for ; Fri, 4 Nov 2022 21:57:20 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 130-20020a251188000000b006be249d0a70so6671207ybr.2 for ; Fri, 04 Nov 2022 21:57:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=X3X2UKpD6zQllEjbrRaWm6/Z/akGwGuBaRDivMqgr8Q=; b=VIDKnr7oA7dLSPu4w5AAFufkeugCkvAQRahHYHsXU5b9ZNq9wL+25O2wkVs8e4PuC/ TIJU6QavnK5/6WXiX/z9atzSeOYxxN2Nahv0m5k7qcjby/QI2LB0B60VwSJuUofBe8em QZwLj+BchqaqON0RTYkdrbnmiWpM1oP2EzCivxaSYZCgA87PmcETZGVQ3ccF2fMpcAHr cWZeisWkQyc0Bk7fNgQz6qQKy2M19Ta0hRC7betzNIFuIaGk36E2vtSNpwnC3DqcfDDu Dwzt+dxRSAdJmPdzr4nc0zgX4yVx5+c9+sFuFsL6dSSHjP6Azofe0euBAVXD71zZyScL XXTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=X3X2UKpD6zQllEjbrRaWm6/Z/akGwGuBaRDivMqgr8Q=; b=YZ52WhFmpmJAi6pl+6pz4rgNSUZwowp7XP0M/47wIGaiVPguQGMjy5GejkUXCdCCgr Cr4D3vNiieG16xJ4lGeAprvXgjDP9NhC3xeQBO6bcWy1STBvR7dIu9JR5Vn67AZS6V73 1auEN1I7BmxIgZeHV5YiixscpAr4+dEEq5G9JmNbL69+0YN34KR1c0zBmc7YjIf1mptA 7r6rXGeykgLfqRHZEbxxvQuUtpPnghdMdyzpDtQAfkawm1ob3EaUzhvdCBSnGCbz9+0J ZGICQQS7KiD635wLyXvSOev04Fuvib1dgyKFWud0ONQ7dBoXfwOwu4YCf+OvQpm5/pWZ AYjQ== X-Gm-Message-State: ACrzQf1AFBuWbanSQXdIU6uU3xlGXRqYBNGFXxmXkmf2oW4Dc+dut5J6 rBXnPzx7sEpae0w1JQh23SIc+FGY0rKU X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a25:af12:0:b0:6cb:b5d7:d64d with SMTP id a18-20020a25af12000000b006cbb5d7d64dmr38476719ybh.510.1667624240120; Fri, 04 Nov 2022 21:57:20 -0700 (PDT) Date: Fri, 4 Nov 2022 21:57:04 -0700 In-Reply-To: <20221105045704.2315186-1-vipinsh@google.com> Mime-Version: 1.0 References: <20221105045704.2315186-1-vipinsh@google.com> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog Message-ID: <20221105045704.2315186-7-vipinsh@google.com> Subject: [PATCH 6/6] KVM: selftests: Test Hyper-V extended hypercall exit to userspace From: Vipin Sharma To: seanjc@google.com, pbonzini@redhat.com, vkuznets@redhat.com Cc: dmatlack@google.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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?1748632622621229890?= X-GMAIL-MSGID: =?utf-8?q?1748632622621229890?= Hyper-V extended hypercalls by default exit to userspace. Verify userspace gets the call, update the result and then guest verifies result it received. Signed-off-by: Vipin Sharma --- tools/testing/selftests/kvm/.gitignore | 1 + tools/testing/selftests/kvm/Makefile | 1 + .../kvm/x86_64/hyperv_extended_hcalls.c | 90 +++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 tools/testing/selftests/kvm/x86_64/hyperv_extended_hcalls.c diff --git a/tools/testing/selftests/kvm/.gitignore b/tools/testing/selftests/kvm/.gitignore index 2f0d705db9db..ffe06dd1cc6e 100644 --- a/tools/testing/selftests/kvm/.gitignore +++ b/tools/testing/selftests/kvm/.gitignore @@ -24,6 +24,7 @@ /x86_64/kvm_pv_test /x86_64/hyperv_clock /x86_64/hyperv_cpuid +/x86_64/hyperv_extended_hcalls /x86_64/hyperv_features /x86_64/hyperv_svm_test /x86_64/max_vcpuid_cap_test diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile index 0172eb6cb6ee..366345099363 100644 --- a/tools/testing/selftests/kvm/Makefile +++ b/tools/testing/selftests/kvm/Makefile @@ -85,6 +85,7 @@ TEST_GEN_PROGS_x86_64 += x86_64/emulator_error_test TEST_GEN_PROGS_x86_64 += x86_64/fix_hypercall_test TEST_GEN_PROGS_x86_64 += x86_64/hyperv_clock TEST_GEN_PROGS_x86_64 += x86_64/hyperv_cpuid +TEST_GEN_PROGS_x86_64 += x86_64/hyperv_extended_hcalls TEST_GEN_PROGS_x86_64 += x86_64/hyperv_features TEST_GEN_PROGS_x86_64 += x86_64/hyperv_svm_test TEST_GEN_PROGS_x86_64 += x86_64/kvm_clock_test diff --git a/tools/testing/selftests/kvm/x86_64/hyperv_extended_hcalls.c b/tools/testing/selftests/kvm/x86_64/hyperv_extended_hcalls.c new file mode 100644 index 000000000000..d378877235d4 --- /dev/null +++ b/tools/testing/selftests/kvm/x86_64/hyperv_extended_hcalls.c @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Test Hyper-V extended hypercalls + * + * Copyright 2020 Google LLC + * Author: Vipin Sharma + */ + +#include "kvm_util.h" +#include "processor.h" +#include "hyperv.h" + +/* Any value is fine */ +#define EXT_CAPABILITIES 0xbull + +static void guest_code(vm_vaddr_t pgs_gpa, vm_vaddr_t output_pg_gva) +{ + uint64_t res, vector; + uint64_t *output_gva; + + wrmsr(HV_X64_MSR_GUEST_OS_ID, hv_linux_guest_id()); + wrmsr(HV_X64_MSR_HYPERCALL, pgs_gpa); + + output_gva = (uint64_t *)output_pg_gva; + + vector = hypercall(HV_EXT_CALL_QUERY_CAPABILITIES, pgs_gpa, + pgs_gpa + 4096, &res); + + GUEST_ASSERT_1(!vector, vector); + GUEST_ASSERT_2(res == HV_STATUS_SUCCESS, res, HV_STATUS_SUCCESS); + + /* TLFS states output will be a uint64_t value */ + GUEST_ASSERT_2(*output_gva == EXT_CAPABILITIES, *output_gva, + EXT_CAPABILITIES); + + GUEST_DONE(); +} + +static void guest_extended_hcall_test(void) +{ + struct kvm_vcpu *vcpu; + struct kvm_run *run; + struct kvm_vm *vm; + struct ucall uc; + vm_vaddr_t hcall_page; + uint64_t *outval; + + vm = vm_create_with_one_vcpu(&vcpu, guest_code); + run = vcpu->run; + vcpu_enable_cap(vcpu, KVM_CAP_HYPERV_ENFORCE_CPUID, 1); + vcpu_set_hv_cpuid(vcpu); + + /* Hypercall input/output */ + hcall_page = vm_vaddr_alloc_pages(vm, 2); + memset(addr_gva2hva(vm, hcall_page), 0x0, 2 * getpagesize()); + vcpu_args_set(vcpu, 2, addr_gva2gpa(vm, hcall_page), hcall_page + 4096); + + vcpu_run(vcpu); + + TEST_ASSERT((run->exit_reason == KVM_EXIT_HYPERV), + "unexpected exit reason: %u (%s)", run->exit_reason, + exit_reason_str(run->exit_reason)); + + outval = addr_gpa2hva(vm, run->hyperv.u.hcall.params[1]); + *outval = EXT_CAPABILITIES; + run->hyperv.u.hcall.result = HV_STATUS_SUCCESS; + + vcpu_run(vcpu); + + TEST_ASSERT((run->exit_reason == KVM_EXIT_IO), + "unexpected exit reason: %u (%s)", run->exit_reason, + exit_reason_str(run->exit_reason)); + + switch (get_ucall(vcpu, &uc)) { + case UCALL_ABORT: + REPORT_GUEST_ASSERT_2(uc, "arg1 = %ld, arg2 = %ld"); + break; + case UCALL_DONE: + break; + default: + TEST_FAIL("Unhandled ucall: %ld", uc.cmd); + } + + kvm_vm_free(vm); +} + +int main(void) +{ + guest_extended_hcall_test(); +}