From patchwork Tue Jul 18 10:34:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 9847691 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 9665D602C8 for ; Tue, 18 Jul 2017 10:36:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 935142853A for ; Tue, 18 Jul 2017 10:36:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8836E2854A; Tue, 18 Jul 2017 10:36:48 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 244A82853A for ; Tue, 18 Jul 2017 10:36:48 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dXPq0-0006C9-NG; Tue, 18 Jul 2017 10:34:44 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dXPpy-0006AJ-Q2 for xen-devel@lists.xen.org; Tue, 18 Jul 2017 10:34:42 +0000 Received: from [85.158.139.211] by server-13.bemta-5.messagelabs.com id 2E/2C-01732-244ED695; Tue, 18 Jul 2017 10:34:42 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprIIsWRWlGSWpSXmKPExsXitHRDpK7jk9x Ig3N7NC2WfFzM4sDocXT3b6YAxijWzLyk/IoE1oyvbW2sBadFK3a+nsfWwPicv4uRk0NCwF/i 0aRFjCA2m4CexMbZr5hAbBEBWYnVXXPYQWxmgU9MEg3HHEFsYQF7if99q1hAbBYBVYndHd9YQ WxeAVuJyZu+MEHMlJfY1XYRLM4pYCcx73knWL0QUM3qC7tYIWxVidcvdrFA9ApKnJz5hAVil4 TEwRcvmCcw8s5CkpqFJLWAkWkVo0ZxalFZapGuoYleUlFmekZJbmJmjq6hgalebmpxcWJ6ak5 iUrFecn7uJkZg8DAAwQ7Gs6c9DzFKcjApifKuPpAbKcSXlJ9SmZFYnBFfVJqTWnyIUYaDQ0mC 9+gjoJxgUWp6akVaZg4wjGHSEhw8SiK8QY+B0rzFBYm5xZnpEKlTjLocryb8/8YkxJKXn5cqJ c77A2SGAEhRRmke3AhYTF1ilJUS5mUEOkqIpyC1KDezBFX+FaM4B6OSMO8WkCk8mXklcJteAR 3BBHSEsG8OyBEliQgpqQZGodYqgcX7jRfW3L39YEHBBu0JbW9KP/6bfT9qdXDvckep91nBkur 7V+7wfG74yXQa+4GT/myujEJW2hVKzWzX385u3zzNme2o2sqQKy2Xu5sOnLltYyVQJvvar37i Qu97wfHcrkcVblduFHl3pupp5N0vvIyfnZt0A/ZedD0nUZ8laTejtjRfiaU4I9FQi7moOBEAw 1zg1qQCAAA= X-Env-Sender: prvs=365bef495=sergey.dyasli@citrix.com X-Msg-Ref: server-11.tower-206.messagelabs.com!1500374079!83584998!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 58076 invoked from network); 18 Jul 2017 10:34:41 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-11.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 18 Jul 2017 10:34:41 -0000 X-IronPort-AV: E=Sophos;i="5.40,377,1496102400"; d="scan'208";a="431880777" From: Sergey Dyasli To: Date: Tue, 18 Jul 2017 11:34:24 +0100 Message-ID: <20170718103429.25020-8-sergey.dyasli@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170718103429.25020-1-sergey.dyasli@citrix.com> References: <20170718103429.25020-1-sergey.dyasli@citrix.com> MIME-Version: 1.0 Cc: Sergey Dyasli , Kevin Tian , Jun Nakajima , George Dunlap , Andrew Cooper , Tim Deegan , Jan Beulich , Boris Ostrovsky , Suravee Suthikulpanit Subject: [Xen-devel] [PATCH RFC 07/12] x86/np2m: add np2m_schedule_in/out() X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP np2m maintenance is required for a nested vcpu during scheduling: 1. On schedule-out: clear pCPU's bit in p2m->dirty_cpumask to prevent useless IPIs. 2. On schedule-in: check if np2m is up to date and wasn't flushed. Signed-off-by: Sergey Dyasli --- xen/arch/x86/mm/p2m.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/p2m.h | 3 +++ 2 files changed, 55 insertions(+) diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 3d65899b05..4b83d4a4f1 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -1880,6 +1880,58 @@ p2m_get_p2m(struct vcpu *v) return p2m_get_nestedp2m(v); } +static void np2m_schedule(bool sched_out) +{ + struct nestedvcpu *nv = &vcpu_nestedhvm(current); + struct p2m_domain *p2m; + bool sched_in = !sched_out; + + if ( !nestedhvm_enabled(current->domain) || + !nestedhvm_vcpu_in_guestmode(current) || + !nestedhvm_paging_mode_hap(current) ) + return; + + p2m = nv->nv_p2m; + if ( p2m ) + { + bool np2m_valid; + + p2m_lock(p2m); + np2m_valid = p2m->np2m_base == nhvm_vcpu_p2m_base(current) && + nv->np2m_generation == p2m->np2m_generation; + if ( sched_out && np2m_valid ) + { + /* + * The np2m is up to date but this vCPU will no longer use it, + * which means there are no reasons to send a flush IPI. + */ + cpumask_clear_cpu(current->processor, p2m->dirty_cpumask); + } + else if ( sched_in ) + { + if ( !np2m_valid ) + { + /* This vCPU's np2m was flushed while it was not runnable */ + hvm_asid_flush_core(); + vcpu_nestedhvm(current).nv_p2m = NULL; + } + else + cpumask_set_cpu(current->processor, p2m->dirty_cpumask); + } + p2m_unlock(p2m); + } +} + +void np2m_schedule_out(void) +{ + np2m_schedule(true); +} + +void np2m_schedule_in(void) +{ + np2m_schedule(false); +} + unsigned long paging_gva_to_gfn(struct vcpu *v, unsigned long va, uint32_t *pfec) diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index eedc7fd412..801a11a960 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -370,6 +370,9 @@ struct p2m_domain *p2m_get_nestedp2m(struct vcpu *v); */ struct p2m_domain *p2m_get_p2m(struct vcpu *v); +void np2m_schedule_out(void); +void np2m_schedule_in(void); + static inline bool_t p2m_is_hostp2m(const struct p2m_domain *p2m) { return p2m->p2m_class == p2m_host;