From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 966D0C47084 for ; Tue, 25 May 2021 16:16:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7C1F86140F for ; Tue, 25 May 2021 16:16:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233316AbhEYQRk (ORCPT ); Tue, 25 May 2021 12:17:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:46563 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233278AbhEYQRi (ORCPT ); Tue, 25 May 2021 12:17:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621959362; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MWKQ2FRMeKpEI6HlpFxdCErCeQjuf2CVv/zTj1uud2U=; b=EvsFY6In6o0WBxbfLtfT4ka4o+Nss/AbgXmoHs4E/2dxQJ8cPARIac2UxOrlvf9ZACme79 O4MsWjWUMkvznkXFGBJCAwNq7kb3VMdSmm3bZZPVvHf79yZfEbZP4XM2MoXjNx0TdEu7aj 3Q7W4/7zlYINkbOZjOjcMVYw8mOKPqs= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-264-nxLO7va6NMu_VMedZRpnDw-1; Tue, 25 May 2021 12:15:59 -0400 X-MC-Unique: nxLO7va6NMu_VMedZRpnDw-1 Received: by mail-ej1-f69.google.com with SMTP id dt6-20020a170906b786b02903dc2a6918d6so4055427ejb.1 for ; Tue, 25 May 2021 09:15:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:references:from:subject:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=MWKQ2FRMeKpEI6HlpFxdCErCeQjuf2CVv/zTj1uud2U=; b=XnB6hU9N2lK4P1W+dudLqnUKBPy7kQu2bjX5Ej4sFk0rGEEB87j24ikZOn1o9177ae 9QlH/zwzoZGKRgq5vXsgdHcyjYZd9mtRhhl2ynIcet/9OETRPZvS0SN5R6tbfIM5sjJO W9Jh5WZUTaZE3m57qH3QfAVPWTlVfuxRkEHeREbUHmFoxm9qKISoy5Esg6IJcaFj+hzp tNpoN9sAykAf0SNOwzCUDVEmtA4J/Tcbo5VZIDtLVmhSuLfNQDl4h1Ey+q8YnWe8ocEm WGRUVGV7TfAKCoqfzuH7xH37sRWhbe0SQf3YniE0TpL3AqKqaK4XfbxDrxaf1duyrO9I OVXA== X-Gm-Message-State: AOAM532yGhODitrcArnhIIMw7WGOHcYtshgSOOjwww4y95E0CWJqbqxm WPj3/xSxx7XJEiixKqDi1lYiRN79DzXHMtV4k/2/eiG347DnzqhKDziwzWUENKlYSEJLy3EOIrQ ZVb/NK5L7cvGlaZWK/sU692WV X-Received: by 2002:a17:906:3644:: with SMTP id r4mr29254821ejb.140.1621959358263; Tue, 25 May 2021 09:15:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx2Pf5t+DkvwwiPx0XllA23W7L/9RiYDfji124wzQSvXBcL3fzCNNBoTyrr73mQ0LIqxj2Slw== X-Received: by 2002:a17:906:3644:: with SMTP id r4mr29254792ejb.140.1621959358110; Tue, 25 May 2021 09:15:58 -0700 (PDT) Received: from ?IPv6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id gt37sm1929280ejc.68.2021.05.25.09.15.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 25 May 2021 09:15:57 -0700 (PDT) To: Sean Christopherson , "Stamatis, Ilias" Cc: "mlevitsk@redhat.com" , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "jmattson@google.com" , "Woodhouse, David" , "vkuznets@redhat.com" , "joro@8bytes.org" , "mtosatti@redhat.com" , "zamsden@gmail.com" , "wanpengli@tencent.com" References: <20210521102449.21505-1-ilstam@amazon.com> <20210521102449.21505-10-ilstam@amazon.com> <2b3bc8aff14a09c4ea4a1b648f750b5ffb1a15a0.camel@redhat.com> <8a13dedc5bc118072d1e79d8af13b5026de736b3.camel@amazon.com> From: Paolo Bonzini Subject: Re: [PATCH v3 09/12] KVM: VMX: Remove vmx->current_tsc_ratio and decache_tsc_multiplier() Message-ID: <0220f903-2915-f072-b1da-0b58fc07f416@redhat.com> Date: Tue, 25 May 2021 18:15:53 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 25/05/21 17:58, Sean Christopherson wrote: >> The right place for the hw multiplier >> field to be updated is inside set_tsc_khz() in common code when the ratio >> changes. Sort of, the problem is that you have two VMCS's to update. If properly fixed, the cache is useful to fix the issue with KVM_SET_TSC_KHZ needing to update both of them. For that to work, you'd have to move the cache to struct loaded_vmcs. So you can: 1) move the cached tsc_ratio to struct loaded_vmcs 2) add a function in common code (update_tsc_parameters or something like that) to update both the offset and the ratio depending on is_guest_mode() 3) call that function from nested vmentry/vmexit And at that point the cache will do its job and figure out whether a vmwrite is needed, on both vmentry and vmexit. I actually like the idea of storing the expected value in kvm_vcpu and the current value in loaded_vmcs. We might use it for other things such as reload_vmcs01_apic_access_page perhaps. Paolo >> However, this requires adding another vendor callback etc. As all >> this is further refactoring I believe it's better to leave this series as is - >> ie only touching code that is directly related to nested TSC scaling and not >> try to do everything as part of the same series. > But it directly impacts your code, e.g. the nested enter/exit flows would need > to dance around the decache silliness. And I believe it even more directly > impacts this series: kvm_set_tsc_khz() fails to handle the case where userspace > invokes KVM_SET_TSC_KHZ while L2 is active. >