Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1401511iog; Tue, 14 Jun 2022 05:31:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwt7tkOvv+QU9NOMWmT7sqFVaZqaNfzfALwhggOOUWZLiN4sSmbb+1QJYgVwWIr3p419YSj X-Received: by 2002:a17:907:62a8:b0:6fe:8b21:4a0d with SMTP id nd40-20020a17090762a800b006fe8b214a0dmr4134199ejc.84.1655209899835; Tue, 14 Jun 2022 05:31:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655209899; cv=none; d=google.com; s=arc-20160816; b=fkmHk373d3fIMdw4TRbpW2zGpYoQzTwVfu7V9MrLy2o9Yu9XsIO1x34PHH3iQmvdLb GaEAiOG9xATdQdriKbWE+OUDNXeAtX6QxFrkVuAstOVmBYyl9qEWbM5KGU6I4GytCYBr HHUUCRMSpJUgNHKlt/wQZK46eHS/h7up++SiwhmiIwJkTYKW376ugnzq71KugYVRXVzq ensOZpxJo6vo79iV/kfVqCfDUXkOgpN6O4UthTgtxGK/4A9evHQy3kKqoGqBzqU18q79 Y54TYyuZ7SZo1wQsgIP8mI531Zo+js0RQ9JERqEz1Ee4h6Ut4/9sCetiHNEAGmrmYbX1 ip2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=d25xRoBQKRAgDG7iS47n8JHMGxyJKkyKtJs+59Z9jLk=; b=J+7GV6a6u6a7phQQlsPHnOwaioy4VXUBphT2WCFlxoJJfhwltr+h3kSbBjUOzoL8RA RGHdbHfwvDlTswGGE5nUCl+dQPBRgvK+3Nf/oMPHp1cgB4KarCBi22f2KXB8LVP/4sCM DjQ4WsXz/863MBehf3zxD4rAQUiMgmm5gB/ee4P7yv7gg7qe/+TftPvlb+wLLR4zTYi4 Nid4MzTdCiPGxUV+KuX7y9eBt7Ip/3qOEey4HJvgEf9tbKgtDvCPpbbY0NIgBvFnWz+g 9M5MtgK6uKN7Euj0yWr1HABxhyxEgfdvwrllw9Y1MA7vbvSfc4UxWO/3buH5elpAuJpU k5lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=b8VFeUd9; 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 i22-20020aa7c716000000b0042dd46e6590si10634492edq.336.2022.06.14.05.31.08; Tue, 14 Jun 2022 05:31:39 -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=b8VFeUd9; 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 S1356806AbiFNMMw (ORCPT + 99 others); Tue, 14 Jun 2022 08:12:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356740AbiFNMMi (ORCPT ); Tue, 14 Jun 2022 08:12:38 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 44BA923BDC for ; Tue, 14 Jun 2022 05:12:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655208741; 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: in-reply-to:in-reply-to:references:references; bh=d25xRoBQKRAgDG7iS47n8JHMGxyJKkyKtJs+59Z9jLk=; b=b8VFeUd9emjza7UkBh4RnmFJ9W9xFqpUdqoZ9r2/74MtUxy8q+I6T7kX8NcxoPZRHGUlAq T5kMYXNo9rzfESQydzm5DGdPEsJTlVwsP0pxZUkaNVQpDZhZTNj3KUvFaYMsbqDIpI9Agb ESG+5tVe3LTTp1coOue95uOhuivoZeM= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-518-VjvkTzQ8PTOEym4gZjJ2kg-1; Tue, 14 Jun 2022 08:12:14 -0400 X-MC-Unique: VjvkTzQ8PTOEym4gZjJ2kg-1 Received: by mail-ed1-f72.google.com with SMTP id x15-20020a05640226cf00b004318eab9feaso6059914edd.12 for ; Tue, 14 Jun 2022 05:12:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=d25xRoBQKRAgDG7iS47n8JHMGxyJKkyKtJs+59Z9jLk=; b=6c4UzeXV/r132OXYiA51V692vR4MuKDNw/LQ2O0bvrsc6H0XNwKmVgLWeK+0SuCYFI dK57KiUm3ZmNOx3Wlv3HzectrbjqPcDVDyT/hh7WbX3uuZ87++pDENMjyMcdCWY7GV8P meVlP9JOFeQoyqqT9kOMV7RPSCo0+ZemKUJgtBTBOwOeQVsW3OJz0wJz4eBYBGHOLaZv 6dBrbNZycYDvnErcRCLTxOqQAOhkggnsGtAAXplIdQ1L5RT6zY1WHwSva4w6/Vsl2OOg WQwSwvRfDPT1OtH7uvZ4h8TUhliZURmnRkGWaHmYYNyjG4bxxe428aYOuNcWbgRvGMze NtPw== X-Gm-Message-State: AJIora//C++FeKR+9ulTuwhvE2f75VkA7cX9C/kdvSwWUqqqPY5zDuOc GBTvISzoW9VBhGK+GhkDSFyh9U93UeqtcdrCECMI4dsZDCqm7ncoNsWRRmGPTmcF1OqUV3aRCu1 uussrSWPvaZK3P9eBR+w9CQU0 X-Received: by 2002:a17:906:6a1a:b0:711:ec13:b7bc with SMTP id qw26-20020a1709066a1a00b00711ec13b7bcmr3968817ejc.688.1655208733223; Tue, 14 Jun 2022 05:12:13 -0700 (PDT) X-Received: by 2002:a17:906:6a1a:b0:711:ec13:b7bc with SMTP id qw26-20020a1709066a1a00b00711ec13b7bcmr3968803ejc.688.1655208732976; Tue, 14 Jun 2022 05:12:12 -0700 (PDT) Received: from fedora (nat-2.ign.cz. [91.219.240.2]) by smtp.gmail.com with ESMTPSA id j10-20020a50d00a000000b004319b12371asm7035004edf.47.2022.06.14.05.12.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jun 2022 05:12:12 -0700 (PDT) From: Vitaly Kuznetsov To: Paolo Bonzini , Anirudh Rayabharam Cc: mail@anirudhrb.com, kumarpraveen@linux.microsoft.com, wei.liu@kernel.org, robert.bradford@intel.com, liuwe@microsoft.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Ilias Stamatis , Maxim Levitsky Subject: Re: [PATCH] KVM: nVMX: Don't expose TSC scaling to L1 when on Hyper-V In-Reply-To: <592ab920-51f3-4794-331f-8737e1f5b20a@redhat.com> References: <20220613161611.3567556-1-anrayabh@linux.microsoft.com> <592ab920-51f3-4794-331f-8737e1f5b20a@redhat.com> Date: Tue, 14 Jun 2022 14:12:11 +0200 Message-ID: <87v8t3igv8.fsf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-4.0 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,T_SCC_BODY_TEXT_LINE 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 Paolo Bonzini writes: > On 6/13/22 18:16, Anirudh Rayabharam wrote: >> + if (!kvm_has_tsc_control) >> + msrs->secondary_ctls_high &= ~SECONDARY_EXEC_TSC_SCALING; >> + >> msrs->secondary_ctls_low = 0; >> msrs->secondary_ctls_high &= >> SECONDARY_EXEC_DESC | >> @@ -6667,8 +6670,7 @@ void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs, u32 ept_caps) >> SECONDARY_EXEC_RDRAND_EXITING | >> SECONDARY_EXEC_ENABLE_INVPCID | >> SECONDARY_EXEC_RDSEED_EXITING | >> - SECONDARY_EXEC_XSAVES | >> - SECONDARY_EXEC_TSC_SCALING; >> + SECONDARY_EXEC_XSAVES; >> >> /* > > This is wrong because it _always_ disables SECONDARY_EXEC_TSC_SCALING, > even if kvm_has_tsc_control == true. > > That said, I think a better implementation of this patch is to just add > a version of evmcs_sanitize_exec_ctrls that takes a struct > nested_vmx_msrs *, and call it at the end of nested_vmx_setup_ctl_msrs like > > evmcs_sanitize_nested_vmx_vsrs(msrs); > > Even better (but I cannot "mentally test it" offhand) would be just > > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > index e802f71a9e8d..b3425ce835c5 100644 > --- a/arch/x86/kvm/vmx/vmx.c > +++ b/arch/x86/kvm/vmx/vmx.c > @@ -1862,7 +1862,7 @@ int vmx_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) > * sanity checking and refuse to boot. Filter all unsupported > * features out. > */ > - if (!msr_info->host_initiated && > + if (static_branch_unlikely(&enable_evmcs) || > vmx->nested.enlightened_vmcs_enabled) > nested_evmcs_filter_control_msr(msr_info->index, > &msr_info->data); > > I cannot quite understand the host_initiated check, so I'll defer to > Vitaly on why it is needed. Most likely, removing it would cause some > warnings in QEMU with e.g. "-cpu Haswell,+vmx"; but I think it's a > userspace bug and we should remove that part of the condition. I forgot the details, of course, but 31de3d2500e4 says: ``` With fine grained VMX feature enablement QEMU>=4.2 tries to do KVM_SET_MSRS with default (matching CPU model) values and in case eVMCS is also enabled, fails. ``` so it certainly was a workaround for QEMU. -- Vitaly