Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp352201rwb; Wed, 21 Sep 2022 23:55:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6opYfj7kE3XH1Tf6JVlWpKxlNxbBX8UBwZ299aeOTII0IYS8MrmIT4ubVZtTLNe7TUHOix X-Received: by 2002:a05:6402:40d1:b0:44f:e974:f981 with SMTP id z17-20020a05640240d100b0044fe974f981mr1804728edb.222.1663829756679; Wed, 21 Sep 2022 23:55:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663829756; cv=none; d=google.com; s=arc-20160816; b=yowgDZHr9BhgkENm54WSD1aF2WlSn179VeV7m9tiBHhg2SYhGLF/8ZL1IfDM2lTTbY QPwexj003ywec4B52x54KR8tPwqqgXNdzhNnVZRDVju9YOGXaQM8h0le1fLfWSbytSip fuDSXTQIvNM14H+1SxOVbpNNsz6KWoTLuGsiRtotNpltr87PimeKeEAEo8L28lwHEdRP pfYyxQnJ7D2JEuyhnHR6nifBCIFPqRmDGaKuULPILxwqiTaMR7hT534N9ofW1RS41Pfd +e+Jmkrwcj2fQ+Rn/IDeD6XBXscE5P6VE+zlVHIB2trJc+JkD/8Ddr/kY8runjsrDXr+ 1RIg== 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:mime-version:date :dkim-signature; bh=4iDTJKECWO4rLxGzUkSO8Tu4v7lUzS0hGoOt1ut+waY=; b=WsMESLAKRXC24Y2WC91pi9i8U4KQ0GqTuMLblk9l3U9r8m42b2qZ5LXHRtKC7pObDS sEzV3h120C6Vlgbog8PIIQOUPT9vRJ+8w3dfF+7ec9eaQgH7dnrxycpdwHxsrT9HQyx7 +E9mPcn+7NfWONdOKjvkyG/xjmZtvkqOm6V+RiB4jsbAA+K8W+0/BjM+5SjxFtkbdHlX Wk6CvFPX56dJnAKr20L5Zipzg6GSbXzuKPnzR4VVjPRMbjtS9tnZsI54qiwG/2VSphsX vFrQAE/zDoaFAuMbGa34L4a91zudKD4glipV2vvF0hxBkiRxQ8HDS5icAS4dEnG/SK0o llVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ZThArlHV; 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 e10-20020a17090658ca00b00772fe97b31esi5267755ejs.901.2022.09.21.23.55.31; Wed, 21 Sep 2022 23:55:56 -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=ZThArlHV; 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 S230296AbiIVGZn (ORCPT + 99 others); Thu, 22 Sep 2022 02:25:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229498AbiIVGZ2 (ORCPT ); Thu, 22 Sep 2022 02:25:28 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D77BCB0282 for ; Wed, 21 Sep 2022 23:25:07 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id d14-20020a170902cece00b001784b73823aso5318473plg.1 for ; Wed, 21 Sep 2022 23:25:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date; bh=4iDTJKECWO4rLxGzUkSO8Tu4v7lUzS0hGoOt1ut+waY=; b=ZThArlHV86jb7ZLKTGuuP8Sun6MJjKi6O4E8rRQiC4zgtbAru/Gwg1VKTbuvRAjMrd HL6s6tU5RDEKVqYeEPLIKORM8+MQNLBL1boFJ4wzYTbQ+axr7vlfxpbYv6bFx3uBOgdZ cc/VREPIcD5zeyF1ztUqitrhwnYAWBLp46BMIfUgsLzYuXJm+eXqEoBzuN1kneb2NPhb ncTQI8TzNarOqhSM7cAAmAOX6VqCidv8PjY+yza/9gzxdINAXr75MybfWmS2w1Gh31+x JjZIBdmW7SFxZIObthVxQz7bQ0tFs5X95ejRhAsgyg/lfS9JPa0+KlPmNef+p75kmONl B9Rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date; bh=4iDTJKECWO4rLxGzUkSO8Tu4v7lUzS0hGoOt1ut+waY=; b=cOC4i5E3RlzSPDzSV7x9Imwcru654MfwDiNA1etiarv1EvuAOl16G18sRyTXBfAdtD 4gw/WmvtY44l1NoSsTG/H6qMJnm8SPDmjP8ToHBlcs8FW7ODu+b4kR2cWZq6znIqJ4Mw RhzJhg9J03iAVTltEYRpE0S3os0nx/9j2D0wur7wqer/gwyJJ3SVO0wOyDs0OgOyerTI Ys+uQI2NtoHDCospuyOZCVqmNoBM80ix7FJaHDqjIhSK4Zv1jGSbndJN8YqvvJlSnzvn 22TdRPfRyhgMOBj8D0ehTIQetAJ/XGzruCblWtLePaqCLPUtlXDFS1B7FSuG0Qn007J4 03yw== X-Gm-Message-State: ACrzQf09kA//XxTGp+9BHH7bzWdF12xhmk0zAwAicdbOXREQPrKBW3zd kfLNbH1oRKgzfzc2NliY/9CSEkNLKvFs X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a17:90a:64c8:b0:202:6d4a:90f8 with SMTP id i8-20020a17090a64c800b002026d4a90f8mr2110134pjm.11.1663827906415; Wed, 21 Sep 2022 23:25:06 -0700 (PDT) Date: Wed, 21 Sep 2022 23:24:51 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.37.3.968.ga6b4b080e4-goog Message-ID: <20220922062451.2927010-1-vipinsh@google.com> Subject: [PATCH v2] KVM: selftests: Check result in hyperv_features.c test only for successful hypercalls From: Vipin Sharma To: seanjc@google.com, pbonzini@redhat.com Cc: jmattson@google.com, vkuznets@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma Content-Type: text/plain; charset="UTF-8" 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 Commit cc5851c6be86 ("KVM: selftests: Use exception fixup for #UD/#GP Hyper-V MSR/hcall tests") introduced a wrong guest assert in guest_hcall(). It is not checking the successful hypercall results and only checks the result when a fault happens. GUEST_ASSERT_2(!hcall->ud_expected || res == hcall->expect, hcall->expect, res); Correct the assertion by only checking results of the successful hypercalls. This issue was observed when this test started failing after building it in Clang. Above guest assert statement fails because "res" is not equal to "hcall->expect" when "hcall->ud_expected" is true. "res" gets some garbage value in Clang from the RAX register. In GCC, RAX is 0 because it using RAX for @output_address in the asm statement and resetting it to 0 before using it as output operand in the same asm statement. Clang is not using RAX for @output_address. Load RAX with some default input value so that the compiler cannot modify it or use it for anything else. This makes sure that KVM is correctly clearing up return value on successful hypercall and compiler cannot generate any false positive. Fixes: cc5851c6be86 ("KVM: selftests: Use exception fixup for #UD/#GP Hyper-V MSR/hcall tests") Signed-off-by: Vipin Sharma Suggested-by: Sean Christopherson Reviewed-by: Jim Mattson --- Jim's Reviewed-by is only for the code change and not shortlog message of v1. Also, there is one change in asm which was not present in v1 and not reviewed by Jim. But I am writing his name here so that it is not missed when patch is merged. v2: - Updated the shortlog message. - Using RAX register in hypercall asm as input operand also and initializing it with -EFAULT v1: https://lore.kernel.org/lkml/20220921231151.2321058-1-vipinsh@google.com/ tools/testing/selftests/kvm/x86_64/hyperv_features.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/hyperv_features.c b/tools/testing/selftests/kvm/x86_64/hyperv_features.c index 79ab0152d281..4d55e038c2d7 100644 --- a/tools/testing/selftests/kvm/x86_64/hyperv_features.c +++ b/tools/testing/selftests/kvm/x86_64/hyperv_features.c @@ -26,7 +26,8 @@ static inline uint8_t hypercall(u64 control, vm_vaddr_t input_address, : "=a" (*hv_status), "+c" (control), "+d" (input_address), KVM_ASM_SAFE_OUTPUTS(vector) - : [output_address] "r"(output_address) + : [output_address] "r"(output_address), + "a" (-EFAULT) : "cc", "memory", "r8", KVM_ASM_SAFE_CLOBBERS); return vector; } @@ -81,13 +82,13 @@ static void guest_hcall(vm_vaddr_t pgs_gpa, struct hcall_data *hcall) } vector = hypercall(hcall->control, input, output, &res); - if (hcall->ud_expected) + if (hcall->ud_expected) { GUEST_ASSERT_2(vector == UD_VECTOR, hcall->control, vector); - else + } else { GUEST_ASSERT_2(!vector, hcall->control, vector); + GUEST_ASSERT_2(res == hcall->expect, hcall->expect, res); + } - GUEST_ASSERT_2(!hcall->ud_expected || res == hcall->expect, - hcall->expect, res); GUEST_DONE(); } -- 2.37.3.968.ga6b4b080e4-goog