Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp361904pxb; Wed, 14 Apr 2021 17:53:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzexRtKeYcQGD1jR49yjzLgKon49l1auMBT4wOuShyWf48ZmkFiR/GSU5CiVsJBcflJ/waz X-Received: by 2002:a17:906:5d13:: with SMTP id g19mr775557ejt.206.1618447979843; Wed, 14 Apr 2021 17:52:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618447979; cv=none; d=google.com; s=arc-20160816; b=E2TXtxs1U4z1hUplbBEh59mBrOXby9+taAAf9X4LyIziIgVooNeZXTtnSOa24V0X/+ pb+dOaruk/PLBZVvyqnnEYxpI+SrAg9q1WAFwy3yH6W3+lhMDJrpFVp9lKzeMUEHflwt jOqRXA8whR7XuCWH8qL9GM3lKBWCz5Sv2MPcE/eyJuH1j8Bu67jS6EGUvnz/BCelJMt9 b6BeKBKC55JJIwetmpha4CK4RnBmN72BIm/EkxhPH+4SwBPqjM9atq92ygmnVH8ZaZ52 CmxsvU4Tj3j+N+7jhbBSVAI6LiYqhQSG3DIj4nwu9FXV20WNsGXNqVLBpQ0sSr8/251N d85Q== 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=fOJI4hThVgEOLJyImgusGGiOxy9mpTSNJ/Mrm5n5Wk0=; b=Lt0kqH4IBZYYA/PcLqOkdcShIDbxNc3i2Lms59ivIgd5yprOnehkDjEeyQCivg9kls 0Zigqmfej3DqOMZIOTGWIw60Rtb2psrw7pV+lTcb/MNl7YkTJVKB+ob5uOn35heWXAG5 ZfVB9eYt71456vsab0X69KFxNd+Fbo/XeNGDy3hhXcaq92wB4KhOB6H2RMIujZ2K3RJS ub4htvrGO31kQ4onMT2BRjqa1MloSwrICaTb11KqTsfdqTeNhlgSduI/HLJuhvm65uoF OEJIIBPQYJMn2EZEQqW90EUcNDxyC4Co/2FnGTz+J9ElNX7WwndPa+3r3wYwjLnji05s +NhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=lEI57So+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a15si972498edr.347.2021.04.14.17.52.37; Wed, 14 Apr 2021 17:52:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=lEI57So+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S230047AbhDOAuK (ORCPT + 99 others); Wed, 14 Apr 2021 20:50:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229815AbhDOAuI (ORCPT ); Wed, 14 Apr 2021 20:50:08 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02EC5C061756 for ; Wed, 14 Apr 2021 17:49:47 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id em21-20020a17090b0155b029014e204a81e6so3842227pjb.1 for ; Wed, 14 Apr 2021 17:49:46 -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=fOJI4hThVgEOLJyImgusGGiOxy9mpTSNJ/Mrm5n5Wk0=; b=lEI57So+mLNKqR8MOcAK5p3MZw4vqrkk9etbelECfBcXuY5eDWQoby3QMZLzSfY8Ld RvK2vdibjbtjGeqLJkWkmBpcWbieDeicodh6t61TVGzdFOeCO2Tfi3KhnWWSjua3I+7/ zjdNxm+qgvPvgZ9WsJ9ZUeZ5YYiuAJh6XbZ6tEsTahjj4Zht3bVEskNbzX1vDUHFjevH xvzIDu3EKHqfEu4p4n1g3O6vhoUbUZUSS7b6TvAcCczNn3L241mIvi8mFqtGd8FZSgLw Yy8ROdcJrDJ/TYNZnks+IkY99l1c7xmHX3Jt5yK9PVXmr+doXnNzkHsWhkATfYP4LBZn OCgg== 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=fOJI4hThVgEOLJyImgusGGiOxy9mpTSNJ/Mrm5n5Wk0=; b=g17Gd0BMsBMThS7zmfTghIPOfcP/D0glZiU85kNz8DAlx3olAU4GL7mrE+8HvI7nwS AmlmkeOWu4KRV+343O4DPQ/HrbkcyIqXha/0A69LqtrfrqKjWsG2S+edyMIb/MDKClQt 5qUzxnItEV1QjQpNjvB2JU3ITItnJPAFAlytYKr3yG0XsaNh/AViCc1UoazA8Fg7g9SU cUHMkAgxqjmPGwUH0l2/jWF6gKa2eFiqwjwT8ttO1JrF+/mOJ/3YB5zKBro/yO190UcB r+GEZfa9/X9WUZaz08qI+4Z3FRAd2wT+g7i/NYXLn64immBjS0qTORQOIRd8nDYL+by8 mqHQ== X-Gm-Message-State: AOAM530xGvurcKEttu2Ay3ADBHhtr41Md+eENNgiHdP+aEGOSfPItPT7 hrghls1B770HicI7BFZH7RMy9g== X-Received: by 2002:a17:90a:fa0c:: with SMTP id cm12mr915481pjb.54.1618447785825; Wed, 14 Apr 2021 17:49:45 -0700 (PDT) Received: from google.com (240.111.247.35.bc.googleusercontent.com. [35.247.111.240]) by smtp.gmail.com with ESMTPSA id z29sm589556pga.52.2021.04.14.17.49.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Apr 2021 17:49:45 -0700 (PDT) Date: Thu, 15 Apr 2021 00:49:41 +0000 From: Sean Christopherson To: Wanpeng Li Cc: LKML , kvm , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Michael Tokarev Subject: Re: [PATCH v2 0/3] KVM: Properly account for guest CPU time Message-ID: References: <1618298169-3831-1-git-send-email-wanpengli@tencent.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 14, 2021, Wanpeng Li wrote: > On Wed, 14 Apr 2021 at 01:25, Sean Christopherson wrote: > > > > On Tue, Apr 13, 2021, Wanpeng Li wrote: > > > The bugzilla https://bugzilla.kernel.org/show_bug.cgi?id=209831 > > > reported that the guest time remains 0 when running a while true > > > loop in the guest. > > > > > > The commit 87fa7f3e98a131 ("x86/kvm: Move context tracking where it > > > belongs") moves guest_exit_irqoff() close to vmexit breaks the > > > tick-based time accouting when the ticks that happen after IRQs are > > > disabled are incorrectly accounted to the host/system time. This is > > > because we exit the guest state too early. > > > > > > This patchset splits both context tracking logic and the time accounting > > > logic from guest_enter/exit_irqoff(), keep context tracking around the > > > actual vmentry/exit code, have the virt time specific helpers which > > > can be placed at the proper spots in kvm. In addition, it will not > > > break the world outside of x86. > > > > IMO, this is going in the wrong direction. Rather than separate context tracking, > > vtime accounting, and KVM logic, this further intertwines the three. E.g. the > > context tracking code has even more vtime accounting NATIVE vs. GEN vs. TICK > > logic baked into it. > > > > Rather than smush everything into context_tracking.h, I think we can cleanly > > split the context tracking and vtime accounting code into separate pieces, which > > will in turn allow moving the wrapping logic to linux/kvm_host.h. Once that is > > done, splitting the context tracking and time accounting logic for KVM x86 > > becomes a KVM detail as opposed to requiring dedicated logic in the context > > tracking code. > > > > I have untested code that compiles on x86, I'll send an RFC shortly. > > We need an easy to backport fix and then we might have some further > cleanups on top. I fiddled with this a bit today, I think I have something workable that will be a relatively clean and short backport. With luck, I'll get it posted tomorrow.