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=-13.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 D427AC2B9F8 for ; Tue, 25 May 2021 16:34:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B33C46141D for ; Tue, 25 May 2021 16:34:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233245AbhEYQgK (ORCPT ); Tue, 25 May 2021 12:36:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231235AbhEYQgJ (ORCPT ); Tue, 25 May 2021 12:36:09 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FACFC061756 for ; Tue, 25 May 2021 09:34:39 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id ne24-20020a17090b3758b029015f2dafecb0so12319371pjb.4 for ; Tue, 25 May 2021 09:34:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=dXoi1LYFfpdbKWHNrkGgXE8yw6j2AtvMSaL5M8EYa9I=; b=ODZN+ptaC53QKg9tJEuMjkU3m5Yx14qJPW5cYXiVRcY8+hX/rwhVtCsH+c63nNBFS9 AtZ/xK5eopky4Yx7CM092gDOdFWH7gCsKLsYCj29/GTXKzklI5saaEXu5PxdW/UrkIU/ UfhIlam+PSaIBYZrmTQYnV55nlmHUpwMSsTmI3okckkiL+tzVbqlWsuT/08RJ7cYAFN9 rkxm0UDy/Ie/Flsm+v76JpOA8Oh+ozNH3dhH3hiSluAbK+riAo2EQX0EICSoZTLPF9iQ wxsFhNsIKFmctQn7DdM9DyqUizZiMV2pYq1EIP0TcztGQlQLXBWD22F7pdybFjh10o7q 9j6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=dXoi1LYFfpdbKWHNrkGgXE8yw6j2AtvMSaL5M8EYa9I=; b=DDWR6XubHNOakhK8BtGF8qfI3+UYiQ5904SCWaXrqpSQdJqhrsgqv+NSM7RoU1O04k VcDB0WjNslJQNSnSQxSXVt+uhh2MomFj5SjlmXK11TpDMIhjcDr2eidibR1SGQ0hZjnV fTMAllJI+2CHcQFoJh2J/WtCMFsvN3mHhk6csJERW1AX7ZeQSE4TLfMvfqTqfMUjFk92 fFRWZ+sd8LmH9bgXHc8nDGzWdwVAWTZsThSQki5MBWiQA2c9YEv1GjMA8OksO74TTHnv hKxLkKdO2Y3Xb8vEmDlI+pPTmUhVjrmntbRQK7nBpW55lh3OD1lVrR0NBE9ssM6fUJGn YJNA== X-Gm-Message-State: AOAM533z+l+Ubc09kFPz80ajq5mnIS7qMwkPy3ASlL3IhBPMlbDVEdir aPXRDzSorK38bUY5iDXtFqmo+w== X-Google-Smtp-Source: ABdhPJzEA1uqEwImTdL1LFcJBjNgn+HaTWAVrJOuGRaq71ZArHvalHJi9+QWbOpqw8wQJU6ukS046w== X-Received: by 2002:a17:90a:7a89:: with SMTP id q9mr5628234pjf.0.1621960478568; Tue, 25 May 2021 09:34:38 -0700 (PDT) Received: from google.com (240.111.247.35.bc.googleusercontent.com. [35.247.111.240]) by smtp.gmail.com with ESMTPSA id s184sm14527003pgc.29.2021.05.25.09.34.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 May 2021 09:34:37 -0700 (PDT) Date: Tue, 25 May 2021 16:34:34 +0000 From: Sean Christopherson To: Paolo Bonzini Cc: "Stamatis, Ilias" , "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" Subject: Re: [PATCH v3 09/12] KVM: VMX: Remove vmx->current_tsc_ratio and decache_tsc_multiplier() Message-ID: References: <20210521102449.21505-1-ilstam@amazon.com> <20210521102449.21505-10-ilstam@amazon.com> <2b3bc8aff14a09c4ea4a1b648f750b5ffb1a15a0.camel@redhat.com> <8a13dedc5bc118072d1e79d8af13b5026de736b3.camel@amazon.com> <0220f903-2915-f072-b1da-0b58fc07f416@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0220f903-2915-f072-b1da-0b58fc07f416@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 25, 2021, Paolo Bonzini wrote: > 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. vmcs01 and vmcs02 will get updated at enter/exit, if there's no caching then it all Just Works. > 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. I'm not necessarily opposed to aggressively shadowing the VMCS, but if we go that route then it should be a standalone series that implements a framework that can be easily extended to arbitrary fields. Adding fields to loaded_vmcs one at a time will be tedious and error prone. E.g. what makes TSC_MULTIPLIER more special than TSC_OFFSET, GUEST_IA32_PAT, GUEST_IA32_DEBUGCTL, GUEST_BNDCFGS, and other number of fields that are likely to persist for a given vmcs02? The current caching logic is just plain ugly and should not exist.