Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1182014pxb; Thu, 15 Apr 2021 16:38:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyqwlFKVFBkylRwoETU9irWFUHI1HV8KH19rEYnLavxfTCbqYR0pwrYkbvy/X9jPAu51Sq0 X-Received: by 2002:a17:906:6683:: with SMTP id z3mr5983598ejo.390.1618529915595; Thu, 15 Apr 2021 16:38:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618529915; cv=none; d=google.com; s=arc-20160816; b=WW37bepSgf4PXODyQ6cAEeABTF1Cf9DTlytM0nim8uqDfiCgu96PmTq5pRTwluCIoo 5TZHDo1J8wJek4YGPusdI/2s1+zME/ALVwkZfUvDnhwQIJr1tpFjZA0xsIN3o3EgXpal A55b7KcrPSYAHdjXeMIaMvza+GqJLLCFK8a9aHWrP39oNcKAlmjXKI2GK+qeFU9KGvpj HJNbzw8J0wRxObhNORuq7y357gIyJ6BEKQ93UAX1f+suUEvDB79qC055lhB68LYa2P9K CzY+U83rBYnZGUkP2rQJG/XyTeM3mmB8z0xR7L0aV6t4hjZtaU8f153hbB1s4lZov4qw Chcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:reply-to:dkim-signature; bh=CDwOh0IaNcX9UTyCuJ5raB5qoSEoFUMF7dTqu9Of2Ts=; b=uNJ0czHE0DAUcj2tE3YIQS4FeiC8kcEniEWOHK6nGk1PhJKAfl1V2KYdHhMUqPYKnL GSmQNIQJyX9mzOokJPGzCXq6ufzQVef7ZQlEq6fooV8HaQU7v4ph/Vy+AiCeFy2/wbrn F23s3rlA1G20WIni8ot+74GIBRWdiyxHRnSC9v3sRv1egmzH4C4C3YLIockx7uPXeTok 6txiyKOnA+N6odpnVPnhtsdbDbvc8uVoW1Hs3R4yZpEwsHElf8XvAcsI+H97YS3LV6JA FSz5QAxKY/xFINjXL6eaX8Y+/lGCFi2rNvbYfa/ZL3oamzEpXMqrH9Q/1c+LFgf5zvrO SeQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=lCEbzxTs; 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 p2si3536906ejb.4.2021.04.15.16.38.09; Thu, 15 Apr 2021 16:38:35 -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=lCEbzxTs; 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 S236019AbhDOWVs (ORCPT + 99 others); Thu, 15 Apr 2021 18:21:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236895AbhDOWVo (ORCPT ); Thu, 15 Apr 2021 18:21:44 -0400 Received: from mail-qv1-xf4a.google.com (mail-qv1-xf4a.google.com [IPv6:2607:f8b0:4864:20::f4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF395C06175F for ; Thu, 15 Apr 2021 15:21:18 -0700 (PDT) Received: by mail-qv1-xf4a.google.com with SMTP id ch4-20020a05621413e4b029019a62faaea4so2778592qvb.3 for ; Thu, 15 Apr 2021 15:21:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=CDwOh0IaNcX9UTyCuJ5raB5qoSEoFUMF7dTqu9Of2Ts=; b=lCEbzxTsjVC2q/MVHl7FRpujXgUXcFG8C46zRmpuIcruXU/6VkHbQYSNS+tYU/BApW DHoFCG1brARGrYVwHDCVJfZYQLaWOr4nEHaLOF6dpBzWtcjIxL3lSWY8+PLlRl4Fxafu 5h+9VSGPVxUZjEk+KQy1w1ihTt7dQiu5iiOg6+WH/DBehbWOJ/OJB5xmPlG56fLNSAZH IMjKH6L4HjImCvJSnXXtkkLMp1SvoD3eMpjgzAIeXYeYDIO2FVOjIbgKX0SQWguccYRJ W0lnPa9n+A+yWuhLsRrCB6q9KrAe+fTDw3TXY66O1oyudFe4loCqxDB1cL+NpzVvU9O8 Ao2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=CDwOh0IaNcX9UTyCuJ5raB5qoSEoFUMF7dTqu9Of2Ts=; b=tJFMwwzTx4B+XbWCn/cA1VbcmIc2z7W9I48PrFLoVfdCpcsDbhaZqWG5AwamVFQQOF vxdRkKYUXSSDCZG6vKyrPhbV/Dsh0PkP/sE8Fq8OO0IEnuMrTbnoXKad4pquBkad1zuy 60J+eeCrlWQOidvLLgr9a6P/c0yxFnIRh/A3wklrvEhqsNwLxDZo36KK1NBjMXBWnQRW MjBrfzu+VrU2zCrW3n1gLpHew7H3jIjFJ6bUtckw69jp7xDJo4Z+SnS/NwEwnnXB2U+8 DicwgwxY3S1b35gIQtseD0VgQzm/k8VlsRQEvAwaXz5KjZ7fuP9u3iscom0Vcv0Aclo+ 6ykg== X-Gm-Message-State: AOAM530yva1GLdZJe0IQfW2jB8pFldfarkSvnqqi/OkV/kF/AGKCLHoh zD0ULf55uwd82QhuzwNeoZ/GSojc+PE= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:6c93:ada0:6bbf:e7db]) (user=seanjc job=sendgmr) by 2002:a0c:e444:: with SMTP id d4mr5446587qvm.51.1618525277964; Thu, 15 Apr 2021 15:21:17 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 15 Apr 2021 15:20:59 -0700 In-Reply-To: <20210415222106.1643837-1-seanjc@google.com> Message-Id: <20210415222106.1643837-3-seanjc@google.com> Mime-Version: 1.0 References: <20210415222106.1643837-1-seanjc@google.com> X-Mailer: git-send-email 2.31.1.368.gbe11c130af-goog Subject: [PATCH v3 2/9] context_tracking: Move guest exit vtime accounting to separate helpers From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Gleixner , Michael Tokarev , Christian Borntraeger Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wanpeng Li Provide separate vtime accounting functions for guest exit instead of open coding the logic within the context tracking code. This will allow KVM x86 to handle vtime accounting slightly differently when using tick-based accounting. Suggested-by: Thomas Gleixner Cc: Thomas Gleixner Cc: Michael Tokarev Cc: Christian Borntraeger Signed-off-by: Wanpeng Li Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson --- include/linux/context_tracking.h | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/include/linux/context_tracking.h b/include/linux/context_tracking.h index 200d30cb3a82..7cf03a8e5708 100644 --- a/include/linux/context_tracking.h +++ b/include/linux/context_tracking.h @@ -137,15 +137,20 @@ static __always_inline void context_tracking_guest_exit_irqoff(void) __context_tracking_exit(CONTEXT_GUEST); } -static __always_inline void guest_exit_irqoff(void) +static __always_inline void vtime_account_guest_exit(void) { - context_tracking_guest_exit_irqoff(); - - instrumentation_begin(); if (vtime_accounting_enabled_this_cpu()) vtime_guest_exit(current); else current->flags &= ~PF_VCPU; +} + +static __always_inline void guest_exit_irqoff(void) +{ + context_tracking_guest_exit_irqoff(); + + instrumentation_begin(); + vtime_account_guest_exit(); instrumentation_end(); } @@ -166,12 +171,17 @@ static __always_inline void guest_enter_irqoff(void) static __always_inline void context_tracking_guest_exit_irqoff(void) { } -static __always_inline void guest_exit_irqoff(void) +static __always_inline void vtime_account_guest_exit(void) { - instrumentation_begin(); - /* Flush the guest cputime we spent on the guest */ vtime_account_kernel(current); current->flags &= ~PF_VCPU; +} + +static __always_inline void guest_exit_irqoff(void) +{ + instrumentation_begin(); + /* Flush the guest cputime we spent on the guest */ + vtime_account_guest_exit(); instrumentation_end(); } #endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */ -- 2.31.1.368.gbe11c130af-goog