From patchwork Mon Sep 4 08:14:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 9936809 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 609C4601EB for ; Mon, 4 Sep 2017 08:17:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 51ED628770 for ; Mon, 4 Sep 2017 08:17:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 46DF92877D; Mon, 4 Sep 2017 08:17:52 +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 4353228780 for ; Mon, 4 Sep 2017 08:17:47 +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 1domXL-0006mQ-AI; Mon, 04 Sep 2017 08:15:15 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1domXJ-0006k6-D1 for xen-devel@lists.xen.org; Mon, 04 Sep 2017 08:15:13 +0000 Received: from [85.158.137.68] by server-12.bemta-3.messagelabs.com id 8C/33-01916-09B0DA95; Mon, 04 Sep 2017 08:15:12 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpikeJIrShJLcpLzFFi42JxWrrBXncC99p Ig1MvuSyWfFzM4sDocXT3b6YAxijWzLyk/IoE1oz/ByUKLotWnHu2mq2B8Q1/FyMnh4SAv8T6 ObeYQWw2AT2JjbNfMYHYIgKyEqu75rCD2MwCn5gkGo45djFycAgLmEu8aMkCCbMIqEicnr2CF cTmFbCVOLHwHAvESHmJXW0XweKcAnYSZ1e/YQSxhYBqehYfZoawVSVev9jFAtErKHFy5hMWiF USEgdfvGCewMg7C0lqFpLUAkamVYzqxalFZalFuoZ6SUWZ6RkluYmZObqGBsZ6uanFxYnpqTm JScV6yfm5mxiBYcMABDsYl390OsQoycGkJMp7//GaSCG+pPyUyozE4oz4otKc1OJDjDIcHEoS vAe51kYKCRalpqdWpGXmAAMYJi3BwaMkwisHkuYtLkjMLc5Mh0idYlSUEud1A0kIgCQySvPg2 mBRc4lRVkqYlxHoECGegtSi3MwSVPlXjOIcjErCvHYgU3gy80rgpr8CWswEtLjq5RqQxSWJCC mpBkYxTYMb9uJ37Xcf5HWfcpGzPd2b7S/zwcfMez4ptS7wWmjqzfXcQHvGvG3HYg3WbDZmXq4 QZfaKdU1bk/X3DNv790uW6D7bwe12V+g926pLiYb1iZU7Su4aRRjk/XzD9tliuWn3VK/5Fopf v35deMv+xSd1uUOzzi5K6T+4Sbs5yi0hJNn17VwlluKMREMt5qLiRAA+24BGlQIAAA== X-Env-Sender: prvs=413848043=sergey.dyasli@citrix.com X-Msg-Ref: server-9.tower-31.messagelabs.com!1504512909!57475412!2 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 7723 invoked from network); 4 Sep 2017 08:15:11 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-9.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 4 Sep 2017 08:15:11 -0000 X-IronPort-AV: E=Sophos;i="5.41,473,1498521600"; d="scan'208";a="446424749" From: Sergey Dyasli To: Date: Mon, 4 Sep 2017 09:14:46 +0100 Message-ID: <20170904081452.12960-9-sergey.dyasli@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170904081452.12960-1-sergey.dyasli@citrix.com> References: <20170904081452.12960-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 v1 08/14] x86/np2m: add np2m_schedule() 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 --- RFC --> v1: - np2m_schedule() now accepts NP2M_SCHEDLE_IN/OUT xen/arch/x86/mm/p2m.c | 43 +++++++++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/p2m.h | 5 +++++ 2 files changed, 48 insertions(+) diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 053df0c9aa..e5d2fed361 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -1875,6 +1875,49 @@ p2m_get_p2m(struct vcpu *v) return p2m_get_nestedp2m(v); } +void np2m_schedule(int dir) +{ + struct nestedvcpu *nv = &vcpu_nestedhvm(current); + struct p2m_domain *p2m; + + ASSERT(dir == NP2M_SCHEDLE_IN || dir == NP2M_SCHEDLE_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 ( dir == NP2M_SCHEDLE_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 ( dir == NP2M_SCHEDLE_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); + } +} + 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 1a7002cbcd..f873dc4fd9 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -370,6 +370,11 @@ struct p2m_domain *p2m_get_nestedp2m(struct vcpu *v); */ struct p2m_domain *p2m_get_p2m(struct vcpu *v); +#define NP2M_SCHEDLE_IN 0 +#define NP2M_SCHEDLE_OUT 1 + +void np2m_schedule(int dir); + static inline bool_t p2m_is_hostp2m(const struct p2m_domain *p2m) { return p2m->p2m_class == p2m_host;