From patchwork Mon Jun 20 14:58:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 9187725 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3E8046075E for ; Mon, 20 Jun 2016 15:01:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C5F420747 for ; Mon, 20 Jun 2016 15:01:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 204112793B; Mon, 20 Jun 2016 15:01:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DC3F720747 for ; Mon, 20 Jun 2016 15:01:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932715AbcFTPAd (ORCPT ); Mon, 20 Jun 2016 11:00:33 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:35015 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752897AbcFTPAF (ORCPT ); Mon, 20 Jun 2016 11:00:05 -0400 Received: by mail-wm0-f65.google.com with SMTP id a66so9652959wme.2; Mon, 20 Jun 2016 07:58:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=+bPyf+Fh/WJ8UizfEjgDq/Q6LVyYbJQLDvEqLYlkYRQ=; b=SpZBqE63xIDIiAGq86/cIRPindMiyvRC69fZW+STAwkVJXgEv3umt33WZ3VAM2Fywg kEPhWfDwExc7niuoo9mZ2s2qbouZfdPxdhIOgzoSr5mea02IaBjDThe8vW0YsrPFQ5Vl yvfJ9P7N2H0GbGYEseEN9rI6Wy7k+pMC8HIjp3JrmDCnXeBrfPJWIXWUx7qypes98Vts iyACH4KsU8e1uqK3zPUO/3Ct1wsRDcyFW8c5uZEuJsdo4zgx8oY0hUvQekBGPq+DTSc2 Tar49CFmhmBLbvC39eALIdrRL6WiEF1yvyPPEuvbM1zklC9M1kCHo9/Nbet0JEginFGi smVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=+bPyf+Fh/WJ8UizfEjgDq/Q6LVyYbJQLDvEqLYlkYRQ=; b=ewnx7H580HvsVXFtUYc+zNmZxkY1vNGEr8YhqlcNXTsqZdP3pJRyCIaK2pZOVol+/p V5yF+Dbx/mUtIwwOYjhSXJVO3DD+T8RrhSoQgE3sGR6FlFRSH1NU3l4+yGOgGjXEVa/d YUFmOV+1PyZ8Q3yqckDR6IpYYv8s6tBl8NGJjoiS9t1aMvz5fHRjBd20vScRrED5VK4A CKOAJL920pnSGh7ZzpEeVsenVhExFZL/monBo4HNvL6hAVzMQdnC9z9LW79eg+cXhoyP 7+GcP3RDLFGwFN5TYBJXI5GFjCSAhA3yKYjPkqYprZeSzWq6O/iSy2AFfCiTtddBsHsw nUPQ== X-Gm-Message-State: ALyK8tI4NlPDVzUk/GlqXQ7JVDB7q1mTLCe/p+ab6JbxSNxKm23PoYS08yNTogQw9IA7Ig== X-Received: by 10.194.203.105 with SMTP id kp9mr15859544wjc.70.1466434720026; Mon, 20 Jun 2016 07:58:40 -0700 (PDT) Received: from donizetti.lan (94-39-188-118.adsl-ull.clienti.tiscali.it. [94.39.188.118]) by smtp.gmail.com with ESMTPSA id r127sm7987845wmf.21.2016.06.20.07.58.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Jun 2016 07:58:39 -0700 (PDT) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Andy Lutomirski , Peter Zijlstra , Rik van Riel , "H. Peter Anvin" , Ingo Molnar , Thomas Gleixner Subject: [PATCH 3/2] context_tracking: move rcu_virt_note_context_switch out of kvm_host.h Date: Mon, 20 Jun 2016 16:58:31 +0200 Message-Id: <1466434712-31440-4-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1466434712-31440-1-git-send-email-pbonzini@redhat.com> References: <1466434712-31440-1-git-send-email-pbonzini@redhat.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Make kvm_guest_{enter,exit} and __kvm_guest_{enter,exit} trivial wrappers around the code in context_tracking.h. Name the context_tracking.h functions consistently with what those for kernel<->user switch. Cc: Andy Lutomirski Cc: Peter Zijlstra Cc: Rik van Riel Cc: H. Peter Anvin Cc: Ingo Molnar Cc: Thomas Gleixner Signed-off-by: Paolo Bonzini Reviewed-by: Rik van Riel --- include/linux/context_tracking.h | 38 ++++++++++++++++++++++++++++++++++---- include/linux/kvm_host.h | 25 ++++--------------------- 2 files changed, 38 insertions(+), 25 deletions(-) diff --git a/include/linux/context_tracking.h b/include/linux/context_tracking.h index d9aef2a0ec8e..c78fc27418f2 100644 --- a/include/linux/context_tracking.h +++ b/include/linux/context_tracking.h @@ -99,7 +99,8 @@ static inline void context_tracking_init(void) { } #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN -static inline void guest_enter(void) +/* must be called with irqs disabled */ +static inline void guest_enter_irqoff(void) { if (vtime_accounting_cpu_enabled()) vtime_guest_enter(current); @@ -108,9 +109,19 @@ static inline void guest_enter(void) if (context_tracking_is_enabled()) __context_tracking_enter(CONTEXT_GUEST); + + /* 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_cpu_is_enabled()) + rcu_virt_note_context_switch(smp_processor_id()); } -static inline void guest_exit(void) +static inline void guest_exit_irqoff(void) { if (context_tracking_is_enabled()) __context_tracking_exit(CONTEXT_GUEST); @@ -122,7 +133,7 @@ static inline void guest_exit(void) } #else -static inline void guest_enter(void) +static inline void guest_enter_irqoff(void) { /* * This is running in ioctl context so its safe @@ -131,9 +142,10 @@ static inline void guest_enter(void) */ vtime_account_system(current); current->flags |= PF_VCPU; + rcu_virt_note_context_switch(smp_processor_id()); } -static inline void guest_exit(void) +static inline void guest_exit_irqoff(void) { /* Flush the guest cputime we spent on the guest */ vtime_account_system(current); @@ -141,4 +153,22 @@ static inline void guest_exit(void) } #endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */ +static inline void guest_enter(void) +{ + unsigned long flags; + + local_irq_save(flags); + guest_enter_irqoff(); + local_irq_restore(flags); +} + +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 1c9c973a7dd9..30c9224545b1 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -870,40 +870,23 @@ static inline void kvm_iommu_unmap_pages(struct kvm *kvm, /* must be called with irqs disabled */ static inline void __kvm_guest_enter(void) { - guest_enter(); - /* 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_cpu_is_enabled()) - rcu_virt_note_context_switch(smp_processor_id()); + guest_enter_irqoff(); } /* must be called with irqs disabled */ static inline void __kvm_guest_exit(void) { - guest_exit(); + guest_exit_irqoff(); } static inline void kvm_guest_enter(void) { - unsigned long flags; - - local_irq_save(flags); - __kvm_guest_enter(); - local_irq_restore(flags); + guest_enter(); } static inline void kvm_guest_exit(void) { - unsigned long flags; - - local_irq_save(flags); - __kvm_guest_exit(); - local_irq_restore(flags); + guest_exit(); } /*