Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp2708557rwi; Tue, 1 Nov 2022 10:44:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4oBWPOsxpOgIQGSJ4O0qn7NilAL3drVRDW46tMR4U6UoJ5M4s4mhxii2cO/6nUymapIfYd X-Received: by 2002:a05:6a00:248c:b0:56d:b13b:e672 with SMTP id c12-20020a056a00248c00b0056db13be672mr6616377pfv.47.1667324663370; Tue, 01 Nov 2022 10:44:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667324663; cv=none; d=google.com; s=arc-20160816; b=wg/zFmD49OqvqzLfTNW9GN2eEkbV4fxtv39/iI3dch67RSiedHSRY9Xi49IEIlj5oL Vq7m9hE6FVBAqzgOdXevsF/Xxzntq2YZDSYDOrLn8Pv8LY8k5VAjnWLMMtqD0Sbeewe3 4YpOakGycZYUNN//QZnJPmOBdgjKUaTcnb58mtC/+qnIbqkCQ3ONKzRl/ao8ZU1HiSp9 C0TzqAA2nn47Ckpvbe7M17xLf7REGXWuLsOb2dSzqbIz16b7Zl+XO1S3H7uZIxNrn8gc Zl4pJdTGzA3BKVCx9ZIPodSC3EENiUd7eQRbx2KjAgcXFGk1jdG0YMAE4U5XI39s/qtY AoCQ== 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=A4QtUNj00AFef6/SLaxc9/EwfiEMk/XY7VysTIRCNPk=; b=qT+phrR7DRbAJ1g/VCGtA8E4x3k8Ygh96sqYfbXEnoioI1Lozl8jt2VKEY1j/Zu8uX mNZJ7gyjYHG2dKXXfwfSs6Tm9GdjOhKUnI0gRH+ncJBYXRt883QyMHlpBTWzkhUgmCIE dp16XLCg/cQJr5HqavAUDZ9CfBNpD6a3mqKyPna3LYCqUOsE35wW7M0o7n5Gua+Tia9+ gLTNjVma+nsetBsqkmrHsKPGbUt2ou/U13oXQQ3I3iDzYuWp9QCb5is2CKHSG0t+nhEZ DLNBvcOyoBSMm3sP71iuxd/xtO2ZqT4rVgvSVeJBa6yrfKxwAwcTmCAgjNtDvSguAhVU T4Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=GsJToAMu; 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 x142-20020a633194000000b00434dd5dc135si12712950pgx.855.2022.11.01.10.44.09; Tue, 01 Nov 2022 10:44:23 -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=GsJToAMu; 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 S230179AbiKAR0f (ORCPT + 96 others); Tue, 1 Nov 2022 13:26:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229516AbiKAR0b (ORCPT ); Tue, 1 Nov 2022 13:26:31 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E8C91A215 for ; Tue, 1 Nov 2022 10:26:31 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id r61-20020a17090a43c300b00212f4e9cccdso19436337pjg.5 for ; Tue, 01 Nov 2022 10:26:31 -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:message-id:reply-to; bh=A4QtUNj00AFef6/SLaxc9/EwfiEMk/XY7VysTIRCNPk=; b=GsJToAMuJ29wa7MEmx4mYyei/7wv80A0LVzK56seJd3rF4Iza7U3ZPb2voZV21TLTN RxpDgA2RSMWks/aF2G1p1yac9G/1umJFalIjnM0nXDpvs8UOdNk7V54bFdBfr34nX38e IQXZHEYQL81ulw6Uymt/PPeYXF0F3z62tB5HDbR5bjJHaCzZOtdxavohIZJCCqGp8dq3 lWca2/vOzct4CEreWPEW2kTLPa1KAz6yPdkGtc+Nyc71IcwQcGBbEb8l8yakRNIBUKEn 9YvwySYx/6EYUSNoFfcEHRtZd7HxydbrpvsFNsDcM6LomZIXAmeUXQpZo3bOdnz84whe TtaA== 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 :message-id:reply-to; bh=A4QtUNj00AFef6/SLaxc9/EwfiEMk/XY7VysTIRCNPk=; b=iOw2pJMmjizub3KYxNFWlAdn0ypVF/im9nQyTCLC1WjjqjAIQh4HRGMgTLqgkdzbY7 oNhXgI+Oe60DT1CcoGeSZTAR9G1lMG0iSLLgbju/qBaASM85ztVJjFILT1nHZ4boaGdu V5MxmlW81xwbr2K5WlvahJOY6Lnd/dWwM7IsOzLkI1cFRngSN0cGvmQ7kuJGZvfMO0bY dxyRHYj9gGxjkbAKA7oa1GmLx6NnUdn7dSzxNcncEBDT+ORk8kt70TSRZcCRTrI4MjXo wqLQpFGfKNg1aYcOe4tugPMezOadRAAUhm8timL1AkY6R+W/AHc5VqWkcKKFQKL6Sr6/ 8jtg== X-Gm-Message-State: ACrzQf24xk8N9XvVGrUyd51RviNOgNULLkrIlz6RPFRcE/De4fbYo6ZW tG9phT7zQRnslFXAGNmgOgj20g== X-Received: by 2002:a17:902:d54a:b0:186:a43b:8e with SMTP id z10-20020a170902d54a00b00186a43b008emr21216723plf.36.1667323590558; Tue, 01 Nov 2022 10:26:30 -0700 (PDT) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id r7-20020aa79ec7000000b0056da63c8515sm2984440pfq.91.2022.11.01.10.26.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Nov 2022 10:26:30 -0700 (PDT) Date: Tue, 1 Nov 2022 17:26:26 +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 Subject: Re: [PATCH v13 45/48] KVM: selftests: Introduce rdmsr_from_l2() and use it for MSR-Bitmap tests Message-ID: References: <20221101145426.251680-1-vkuznets@redhat.com> <20221101145426.251680-46-vkuznets@redhat.com> <87bkpqskr2.fsf@ovpn-194-149.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87bkpqskr2.fsf@ovpn-194-149.brq.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=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 On Tue, Nov 01, 2022, Vitaly Kuznetsov wrote: > Sean Christopherson writes: > > > On Tue, Nov 01, 2022, Vitaly Kuznetsov wrote: > >> Hyper-V MSR-Bitmap tests do RDMSR from L2 to exit to L1. While 'evmcs_test' > >> correctly clobbers all GPRs (which are not preserved), 'hyperv_svm_test' > >> does not. Introduce and use common rdmsr_from_l2() to avoid code > >> duplication and remove hardcoding of MSRs. > >> > >> Signed-off-by: Vitaly Kuznetsov > >> --- > >> .../selftests/kvm/include/x86_64/processor.h | 9 +++++++ > >> .../testing/selftests/kvm/x86_64/evmcs_test.c | 24 ++++--------------- > >> .../selftests/kvm/x86_64/hyperv_svm_test.c | 8 +++---- > >> 3 files changed, 17 insertions(+), 24 deletions(-) > >> > >> diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h > >> index fbaf0b6cec4b..a14b7e4ea7c4 100644 > >> --- a/tools/testing/selftests/kvm/include/x86_64/processor.h > >> +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h > >> @@ -520,6 +520,15 @@ static inline void cpu_relax(void) > >> "hlt\n" \ > >> ) > >> > >> +/* Exit to L1 from L2 with RDMSR instruction */ > >> +static inline void rdmsr_from_l2(uint32_t msr) > > > > I would prefer keeping this helper out of common x86-64 code, even if it means > > duplicating code across multiple Hyper-V tests until the L1 VM-Enter/VM-Exit > > sequences get cleaned up. The name is misleading, e.g. it doesn't really read > > the MSR since there are no outputs > > It's somewhat similar to vmcall()/vmmcall() which are only used to exit > from L2 to L1 (and thus nobody complained that all the register values > are random) and not issue a hypercall and return some value. Sort of. VMCALL/VMMCALL are unique in that they have no meaning (ignoring VMX's STM) other than what is given to them by the hypervisor/software on VM-Exit. RDMSR on the other hand (and literally every other instruction), has architecturally defined behavior and thus expectations beyond generating a VM-Exit. I do think we should clean up the VMCALL/VMMCALL code to remove the clobbers if/when the VM-Enter/VM-Exit sequences are fixed, and maybe make them more generic, e.g. to allow reusing helpers for L1 and L2. But, because the meaning of VMCALL/VMMCALL is software-defined, we'll always need a selftests specific L2=>L1 hypercall, e.g. to ensure L0 forwards the hypercall to L1.