Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp5937619rwb; Wed, 21 Sep 2022 14:57:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4Sko6YEDciLB83SO5nsjvBEqGFbyodcWmizjtTKMi3+HNfiL7hj2foRnFTzqNqwbf02bAe X-Received: by 2002:a62:1dc5:0:b0:540:d8a4:a4ca with SMTP id d188-20020a621dc5000000b00540d8a4a4camr196473pfd.77.1663797448423; Wed, 21 Sep 2022 14:57:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663797448; cv=none; d=google.com; s=arc-20160816; b=udHPAhNgglau4IHjRNsuVUvRfWoN1S+T7dbp7ev1XKmMMa/rGimeB+BRECmJyF8NtU YPuwxJZrjjwAPieiPon5h02sHyJy4++xt43R3sF36oTrG014tFDF0hKXo0Jc9iySTE+M KOfqe0KO2GLHDOdzsuAdKbZ1wtFrH6SLlJ5/jG2rd6nTn/HpzbvAjHTCenqHyfLBdxbN llRoF132my4L9eZ39SG16EIucXH/stEgpHCy4j9RPgpuFI5T4gYAo/1rwH4Hj1/ZSTDi qYOlz2gAZma3pE0US4WVFknQYJrShXHiP4n1y79Dd1wXiM173cH8UPO1WPgAuuCw0yCm VeHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=NgbONa/JLrIJmOkn0CBqxCxDowwxjWoWs2Rsui1X0KI=; b=03TRDtT1KtLUnwL22M9zAgD157T7UpXov9ShnSO/S/O+mZ10FcX8A1nZwJep9ZMHFN 8wKVlSfdCrUck70hwvABc1jdthXGcMDWEWUNyOOxftFd+4eHsCJihN31ry4aQCXiSy38 sMMoaAErE/Djv0y3VDldEKSVI9MGEl+yn6lHoDXXN+Hj25LUX3XPr4MclXK2DJa2qbBL LjplWrIZQuZYCWsbqJRje+TFokrVDtgx1rvSTDWCJ9QCc17IqkCCrgvEJJGA2inK69ah wgo3XgwuCilQ5mkdpeaAo6YXwQfxKcZlzR6tbNwi8XVi9a9vk9KT6UQpdy80v2FJW9Dx d08A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=FWvucp8C; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u18-20020a170903125200b0017514e57d7esi4610733plh.576.2022.09.21.14.57.16; Wed, 21 Sep 2022 14:57:28 -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=FWvucp8C; 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 S230416AbiIUVvh (ORCPT + 99 others); Wed, 21 Sep 2022 17:51:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230340AbiIUVv1 (ORCPT ); Wed, 21 Sep 2022 17:51:27 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C5DAA6C4D for ; Wed, 21 Sep 2022 14:51:24 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id c24so6996475plo.3 for ; Wed, 21 Sep 2022 14:51:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date; bh=NgbONa/JLrIJmOkn0CBqxCxDowwxjWoWs2Rsui1X0KI=; b=FWvucp8C7NSejl3BHBuBIg1NxNS9DZ7c3Jqiurti4tcdCRdol5m+vQG7QltXtbcpzO 3W8gW2CM5N/6HEp9HPytppWqpt5fBPeCs+S6iBx4sgOwxARDlAap6uU8dwB7mR4Y517/ FXVYd6oYAFBlRI595Ey9sRfrSmUc4V/5ETJRgnmBaggNifM7/By7p2mz3nFaH6Cx0U+F 4i0qjMYR2VoMH7ymgzavCcCWQ52bQPD5/gPQhzyrqpv9jI5BPMMtE1pn+vP3+vRGQ7Jr hBwB1GqpxY+XzwuwUMUivArA4YEw91XTSZYBHS0hbbZgVbzHMz2fgrLg3bOv1uRCbGbU i8Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=NgbONa/JLrIJmOkn0CBqxCxDowwxjWoWs2Rsui1X0KI=; b=P7kMlOegkFD1XgAaMz0ZmOYTWvg8azuHR7k+mP6ofkX+bS1oAAFjEKNDpQHjhJlkaP 5oYWoIIm+EtXnZSt6wcrP3OoAzk7e5p76tOPYpc2xe2lv5KOMEamc2g5gsLfpQ+GA69Q tlm6aSMi0/4quAcOfJF+Hw9TMfMN6uxIlDzB8lDW1r7A56OwjqnslriU/gbF9lQfF4pR 1qQC2DT870lPfaRHTrrjNnKtrWEmPCvs94AAJJfvG3eUymyKZUyJux2jHJkgFEg83bD5 3e4s9eTeMFx9BCO8x92bIBip72yR6v/dWWBVEPipwfZW69YHEXXPF+22bQ5uE4Ds9uRz xYdQ== X-Gm-Message-State: ACrzQf0aA+zJi4xzjgPGszCoD/9aHWMpZF+x0FYs/3d3Rs4vP9E4Nn1l 3PCX5FfqU9yNayfIoc4c7SvE0g== X-Received: by 2002:a17:902:7e42:b0:178:489:86ac with SMTP id a2-20020a1709027e4200b00178048986acmr214779pln.68.1663797084005; Wed, 21 Sep 2022 14:51:24 -0700 (PDT) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id j6-20020a17090276c600b001789b724712sm2439580plt.232.2022.09.21.14.51.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Sep 2022 14:51:23 -0700 (PDT) Date: Wed, 21 Sep 2022 21:51:20 +0000 From: Sean Christopherson To: Vitaly Kuznetsov Cc: kvm@vger.kernel.org, Paolo Bonzini , Wanpeng Li , Jim Mattson , Michael Kelley , Siddharth Chandrasekaran , Yuan Yao , Maxim Levitsky , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma Subject: Re: [PATCH v10 25/39] KVM: selftests: Move the function doing Hyper-V hypercall to a common header Message-ID: References: <20220921152436.3673454-1-vkuznets@redhat.com> <20220921152436.3673454-26-vkuznets@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220921152436.3673454-26-vkuznets@redhat.com> X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_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 +Vipin On Wed, Sep 21, 2022, Vitaly Kuznetsov wrote: > 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 | 16 ++++++++++++++++ > .../selftests/kvm/x86_64/hyperv_features.c | 18 +----------------- > 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 f0a8a93694b2..285e9ff73573 100644 > --- a/tools/testing/selftests/kvm/include/x86_64/hyperv.h > +++ b/tools/testing/selftests/kvm/include/x86_64/hyperv.h > @@ -185,6 +185,22 @@ > /* 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; Newline after the variable declaration. > + /* 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) > + : "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 1144bd1ea626..c464d324cde0 100644 > --- a/tools/testing/selftests/kvm/x86_64/hyperv_features.c > +++ b/tools/testing/selftests/kvm/x86_64/hyperv_features.c > @@ -13,22 +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) > - : "cc", "memory", "r8", KVM_ASM_SAFE_CLOBBERS); > - return vector; > -} > - > struct msr_data { > uint32_t idx; > bool available; > @@ -78,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 Just out of sight here, but I broke this code in commit cc5851c6be86 ("KVM: selftests: Use exception fixup for #UD/#GP Hyper-V MSR/hcall tests"). I got too fancy and inverted the ud_expected logic when checking the result. The broken code skips the check when #UD _not_ expected. I.e. this if (hcall->ud_expected) GUEST_ASSERT_2(vector == UD_VECTOR, hcall->control, vector); else GUEST_ASSERT_2(!vector, hcall->control, vector); GUEST_ASSERT_2(!hcall->ud_expected || res == hcall->expect, hcall->expect, res); should be if (hcall->ud_expected) { GUEST_ASSERT_2(vector == UD_VECTOR, hcall->control, vector); } else { GUEST_ASSERT_2(!vector, hcall->control, vector); GUEST_ASSERT_2(res == hcall->expect, hcall->expect, res); } The reason I bring this up here is because of the reason the test passes: gcc zeros RAX before the hypercall (not entirely sure why), and so res=0 on #UD due to nothing changing RAX. But clang doesn't zero RAX and so the test fails due to RAX holding garbage (probably '1' from the lower 32 bits of HV_X64_MSR_HYPERCALL). So, what do you think about explicitly setting hv_status, e.g. to -EFAULT, prior to the hypercall, both to defend against selftest bugs and to verify that _KVM_ actually zeros the result?