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=-18.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 07DD6C433ED for ; Tue, 20 Apr 2021 23:26:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C273E60C3E for ; Tue, 20 Apr 2021 23:26:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234423AbhDTX1M (ORCPT ); Tue, 20 Apr 2021 19:27:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234280AbhDTX1L (ORCPT ); Tue, 20 Apr 2021 19:27:11 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41B3AC061763 for ; Tue, 20 Apr 2021 16:26:39 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id h20so20560833plr.4 for ; Tue, 20 Apr 2021 16:26: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=0qlu9dhH/WkK2RT8ePKeim6dOFYFhQZ+dnqPgQR/Yhk=; b=SiLphwB7uAPiunj9/PliCt/W2Hn46mXxDXNjCyVoFFOHOGxOfdQeNQUdpqsV7EKlhi Ts42KxEYJAYi+XUDl3yTsubuMM5oerCqemxsX4hh2XnKowqrwpOkUp83Rkb9dH7NKD+6 anv/8V7l3+86kX6ADNPSnN4VskoiKyCyGtTlB3dipFLK5zo63k68lT9B/CRq40fHJdsH GHKtM4ZmyBoNvra+VVhVMObAyMF3bUMpXiLCz3J5yrfxU2ldDRrispu0bi2t3MsGj4dU zWWbT6X7CyQ7oERMwtvQcrmHCX/j3snVGCUSn+2gah7pGRhfhRsnBbuUtWUHFuINGcCU Shww== 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=0qlu9dhH/WkK2RT8ePKeim6dOFYFhQZ+dnqPgQR/Yhk=; b=GojIEMybh83SyYkyAfxszYtlFRJXKR4VLLhXgs5DkAhK+qKqEHXfv9A1eJpPrf6YcQ uLNri4k84LxV9hlhy9gpP41IF04pciy/0AueMHKqg6EJpyGAbbEtpStZ+FY6iMF3iSSa VNX9VD2PaGoJe8IyTwYOtXjGskY/raAKG4kcrtpLFFIPnluS31kMpT3cYVfHHcZY6pQ7 JM5cjks0mYB5V7nW+qH7so0bGpEbfY7LB7E0NcZ/OVLjqmW+fQ+8zzQKvnEhyc0QZXga Ktxjii3tZnYNTq+gPJiBcfaDshiv+znzQn3tFiQhFcFhN3kdjOe3oQHySJh/kRbQQl4f Ec6Q== X-Gm-Message-State: AOAM5321YwddeAsn8YW8Eq5QmeGxFcePWsEFuwNuAOKqJp6ZXz0iEsxJ 9/eYFbcG0cKgI6diRixYua1v5Q== X-Google-Smtp-Source: ABdhPJz5sZLLgPRQUdnzKngA02RMKJA94LBFbrExxAIBAVhr4QcTLL7+6YS18cRFkdIGidUyZVR9+Q== X-Received: by 2002:a17:902:e8ca:b029:ec:bec2:ba6b with SMTP id v10-20020a170902e8cab02900ecbec2ba6bmr3661376plg.42.1618961198626; Tue, 20 Apr 2021 16:26: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 l22sm176699pjc.13.2021.04.20.16.26.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Apr 2021 16:26:37 -0700 (PDT) Date: Tue, 20 Apr 2021 23:26:34 +0000 From: Sean Christopherson To: Frederic Weisbecker Cc: Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Gleixner , Michael Tokarev , Christian Borntraeger Subject: Re: [PATCH v3 3/9] KVM: x86: Defer tick-based accounting 'til after IRQ handling Message-ID: References: <20210415222106.1643837-1-seanjc@google.com> <20210415222106.1643837-4-seanjc@google.com> <20210420231402.GA8720@lothringen> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210420231402.GA8720@lothringen> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 21, 2021, Frederic Weisbecker wrote: > On Thu, Apr 15, 2021 at 03:21:00PM -0700, Sean Christopherson wrote: > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > > index 16fb39503296..e4d475df1d4a 100644 > > --- a/arch/x86/kvm/x86.c > > +++ b/arch/x86/kvm/x86.c > > @@ -9230,6 +9230,14 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) > > local_irq_disable(); > > kvm_after_interrupt(vcpu); > > > > + /* > > + * When using tick-based accounting, wait until after servicing IRQs to > > + * account guest time so that any ticks that occurred while running the > > + * guest are properly accounted to the guest. > > + */ > > + if (!vtime_accounting_enabled_this_cpu()) > > + vtime_account_guest_exit(); > > Can we rather have instead: > > static inline void tick_account_guest_exit(void) > { > if (!vtime_accounting_enabled_this_cpu()) > current->flags &= ~PF_VCPU; > } > > It duplicates a bit of code but I think this will read less confusing. Either way works for me. I used vtime_account_guest_exit() to try to keep as many details as possible inside vtime, e.g. in case the implemenation is tweaked in the future. But I agree that pretending KVM isn't already deeply intertwined with the details is a lie.