Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp20600pxy; Tue, 4 May 2021 17:32:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxRXxUir1Ml6vIJGdiWelWNU7I1HXrcBbKnaVKP/dCbl4pUfGPEhKubqmDqUK0D3G0pUiU X-Received: by 2002:a17:906:d8d4:: with SMTP id re20mr24188915ejb.505.1620174759279; Tue, 04 May 2021 17:32:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620174759; cv=none; d=google.com; s=arc-20160816; b=qz/3O+aAoUIl/bAwC2YPg6AdtVqXe4mzcLzx+KEiZfp1MJlfvwwPFLFq6WIpmFdRGH HO+fqzdrqspPGsYooM+BnhS1+fQ2T6zoEyqXIICHHqiGBh81byieT5vAF92Ia+/6VKGS xPdyqoCiF6lp3gttldFBvj4XxNIGtl/BBjHyjXI2wLKVTCZQsQABWjkdx9+hYY2S9D70 dxg/cdo38lrnKRmCCRM3iGr/6/L1cPkGjHrxNxA4biAuVHqa41+EP60FK9JxDq+mnj43 /ekd57tEFsImog7xxodRAgZcY/sNlgy8reocaBkhVsaXpLBcgJpCLQZgE4gP3cPY9fas jvoQ== 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=0QN4jbC2XDzCTKqJKIwYMySbYznFpDOgKP/XluafWZU=; b=RYTSvRbYZEfSFvw+zpEI/Qrmcaz7pl5aAmyFJvzyvhrWOpSlyHGV3yVRz8LocAayFq AxYxybkhbcFp/zt/Goezg0fIJuRwpi5XuP626n2WkkeQeIDpLx8yZcRpqF+U5ReN6iqG qGjReLz4XaSBBPXYQ8/v6z58JCQLPfV5RjG7rCfhHAOpusxRDsCyK6bn8DzVXyqIluHV +eMkArex6L/FdMGGPL+44GBoT29PH1oXvDEboB83NDQSJG3uqki8AZoeTWURKBYrkJnT BEPz+uyXtzgyAa+XrT8Kdq7dClbHPAs8IbfNiB+1c3FJaO7aFRaU9+5AP7pg02Krynj5 4Vjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Nn5hOoGm; 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 n17si3758102ejj.409.2021.05.04.17.32.15; Tue, 04 May 2021 17:32:39 -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=Nn5hOoGm; 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 S231592AbhEEA3D (ORCPT + 99 others); Tue, 4 May 2021 20:29:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231574AbhEEA25 (ORCPT ); Tue, 4 May 2021 20:28:57 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A20E8C061574 for ; Tue, 4 May 2021 17:28:01 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id s8-20020a5b04480000b029049fb35700b9so479799ybp.5 for ; Tue, 04 May 2021 17:28:01 -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=0QN4jbC2XDzCTKqJKIwYMySbYznFpDOgKP/XluafWZU=; b=Nn5hOoGm2H6xOXcTSFjsep8QNT9Tc5IjJJmH804MxiNQCAgI2DZ3pZvPd4Emefmitr Jf9LHMQbGI3U1TKY2yyQlJchNfLBiPU5M6q52rR9MVFGI30qsqJ4+ZBB1NFtjswlTaLb rY3jSU50FmWaybg6D6tCz6G/Dzt9KO699Br/uH1GKUpFD6FA7OEVxJs2eMtc+ta0Pqvq toHrgPd2xLUmJbziwFCKCijmheBInbJs/MIaw7tbvJoK7WSUaKemR1op1QewfhcDMObV JgF/L258QTN/x8R/1KNe3SwrvJQSKOtoWv4XJCnKu+rjHyb+5IvtT7qoQzIhnFsQpUtb 82Dw== 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=0QN4jbC2XDzCTKqJKIwYMySbYznFpDOgKP/XluafWZU=; b=Vz7xsKImT1Dffo1g6VONnbvSEU9ens5cmSgxpGvj570Uj4Brl2Y7TswXqRct4b7hkV 2JnSU3390ZkNhlxi2jx15V22GeThGaU37ce8crlV7LAcproXMBTL1x8hY7Nb1Dsvsgeu UxPTEd9cpyV756tbiromuSy1R+ld1Y4Pol46r/q1wNax6EN5NBw19N9Dt76fUIFtYXZ0 s4s5TaUYQco5rpojpD+JJd/NqitRBtTcCo159d3hgW0xKdMC3b+1T3sDv/Q8ITi6jufY Xei+T//Qf1d6zqm35H067XeQVe6R6kDanoo0IircgCznMUzDl43s1M5zpmLfAPKqokeo fSgg== X-Gm-Message-State: AOAM532/xv1FsbeoYdlOybi2Ldz1mJiORXXoGgtA3FBlAiH2Lm2GnKbB M4mjxEiuMHUeILZA7QYfxeQZviTh1/A= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:df57:48cb:ea33:a156]) (user=seanjc job=sendgmr) by 2002:a25:9982:: with SMTP id p2mr38767733ybo.457.1620174480927; Tue, 04 May 2021 17:28:00 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 4 May 2021 17:27:34 -0700 In-Reply-To: <20210505002735.1684165-1-seanjc@google.com> Message-Id: <20210505002735.1684165-8-seanjc@google.com> Mime-Version: 1.0 References: <20210505002735.1684165-1-seanjc@google.com> X-Mailer: git-send-email 2.31.1.527.g47e6f16901-goog Subject: [PATCH v4 7/8] context_tracking: KVM: Move guest enter/exit wrappers to KVM's domain 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 , Frederic Weisbecker Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Move the guest enter/exit wrappers to kvm_host.h so that KVM can manage its context tracking vs. vtime accounting without bleeding too many KVM details into the context tracking code. No functional change intended. Cc: Frederic Weisbecker Signed-off-by: Sean Christopherson --- include/linux/context_tracking.h | 45 -------------------------------- include/linux/kvm_host.h | 45 ++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 45 deletions(-) diff --git a/include/linux/context_tracking.h b/include/linux/context_tracking.h index aa58c2ac67ca..4d7fced3a39f 100644 --- a/include/linux/context_tracking.h +++ b/include/linux/context_tracking.h @@ -118,49 +118,4 @@ extern void context_tracking_init(void); static inline void context_tracking_init(void) { } #endif /* CONFIG_CONTEXT_TRACKING_FORCE */ -/* must be called with irqs disabled */ -static __always_inline void guest_enter_irqoff(void) -{ - /* - * This is running in ioctl context so its safe to assume that it's the - * stime pending cputime to flush. - */ - instrumentation_begin(); - vtime_account_guest_enter(); - instrumentation_end(); - - /* - * KVM does not hold any references to rcu protected data when it - * switches CPU into a guest mode. In fact switching to a guest mode - * is very similar to exiting to userspace from rcu point of view. In - * addition CPU may stay in a guest mode for quite a long time (up to - * one time slice). Lets treat guest mode as quiescent state, just like - * we do with user-mode execution. - */ - if (!context_tracking_guest_enter()) { - instrumentation_begin(); - rcu_virt_note_context_switch(smp_processor_id()); - instrumentation_end(); - } -} - -static __always_inline void guest_exit_irqoff(void) -{ - context_tracking_guest_exit(); - - instrumentation_begin(); - /* Flush the guest cputime we spent on the guest */ - vtime_account_guest_exit(); - instrumentation_end(); -} - -static inline void guest_exit(void) -{ - unsigned long flags; - - local_irq_save(flags); - guest_exit_irqoff(); - local_irq_restore(flags); -} - #endif diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index a9a7bcf6ebee..a6f47ed8b1e6 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -338,6 +338,51 @@ struct kvm_vcpu { struct kvm_dirty_ring dirty_ring; }; +/* must be called with irqs disabled */ +static __always_inline void guest_enter_irqoff(void) +{ + /* + * This is running in ioctl context so its safe to assume that it's the + * stime pending cputime to flush. + */ + instrumentation_begin(); + vtime_account_guest_enter(); + instrumentation_end(); + + /* + * KVM does not hold any references to rcu protected data when it + * switches CPU into a guest mode. In fact switching to a guest mode + * is very similar to exiting to userspace from rcu point of view. In + * addition CPU may stay in a guest mode for quite a long time (up to + * one time slice). Lets treat guest mode as quiescent state, just like + * we do with user-mode execution. + */ + if (!context_tracking_guest_enter()) { + instrumentation_begin(); + rcu_virt_note_context_switch(smp_processor_id()); + instrumentation_end(); + } +} + +static __always_inline void guest_exit_irqoff(void) +{ + context_tracking_guest_exit(); + + instrumentation_begin(); + /* Flush the guest cputime we spent on the guest */ + vtime_account_guest_exit(); + instrumentation_end(); +} + +static inline void guest_exit(void) +{ + unsigned long flags; + + local_irq_save(flags); + guest_exit_irqoff(); + local_irq_restore(flags); +} + static inline int kvm_vcpu_exiting_guest_mode(struct kvm_vcpu *vcpu) { /* -- 2.31.1.527.g47e6f16901-goog