From patchwork Wed Apr 5 08:59:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Zhang X-Patchwork-Id: 9663483 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 C67D060365 for ; Wed, 5 Apr 2017 09:20:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3EB4A284DB for ; Wed, 5 Apr 2017 09:20:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 33888285AE; Wed, 5 Apr 2017 09:20:34 +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.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID 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 18F7D284DB for ; Wed, 5 Apr 2017 09:20:28 +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 1cvh5m-00054k-Gz; Wed, 05 Apr 2017 09:19:06 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cvh5l-00054X-1D for xen-devel@lists.xen.org; Wed, 05 Apr 2017 09:19:05 +0000 Received: from [193.109.254.147] by server-4.bemta-6.messagelabs.com id 50/27-03012-886B4E85; Wed, 05 Apr 2017 09:19:04 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrPLMWRWlGSWpSXmKPExsVywNwkQrd925M IgwXftS2WfFzM4sDocXT3b6YAxijWzLyk/IoE1ozOZ3OYC2bIVsx6tJS5gfGrSBcjFweLwH4m iWOXW5m7GDk5hASmMUrc/xsJYksI8EocWTaDFcL2k3h27hcTSIOQQDujxLbGTSwgCTYBbYkfq 38zgtgiAtIS1z5fZgQpYhaYwijRO282WJGwQKLEio3zgBIcQOtUJaZ3SYOEeQW8JObP+8gGsU BO4uSxyawTGHkWMDKsYtQoTi0qSy3SNbLUSyrKTM8oyU3MzNE1NDDTy00tLk5MT81JTCrWS87 P3cQI9DwDEOxgPLAo8BCjJAeTkiivgs+TCCG+pPyUyozE4oz4otKc1OJDjDIcHEoSvI+3AOUE i1LTUyvSMnOAIQiTluDgURLhVdwKlOYtLkjMLc5Mh0idYtTlmDN79xsmIZa8/LxUKXHeEyAzB ECKMkrz4EbA4uESo6yUMC8j0FFCPAWpRbmZJajyrxjFORiVhHmNQVbxZOaVwG16BXQEE9ART+ 48BDmiJBEhJdXAKFngqFYbdq2l3fu4buTzY0u7PO5KfQifuYJF9+OCK8l1Pw/OOhqnsUKSpcI uKlx5nfbdpMNte1T/HLTWcvl+Qauf2/ZkfrENu9nCQwuPMK8U3WlRZvbl1ZSftgyiYeHddr+K 2L7fj03847V7x2cG2WetMdvctzZLiszoML2tct1dc62Be/w+JZbijERDLeai4kQA5IGcjIICA AA= X-Env-Sender: yu.c.zhang@linux.intel.com X-Msg-Ref: server-15.tower-27.messagelabs.com!1491383941!42874783!1 X-Originating-IP: [192.55.52.88] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTkyLjU1LjUyLjg4ID0+IDM3NDcyNQ==\n X-StarScan-Received: X-StarScan-Version: 9.4.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 51924 invoked from network); 5 Apr 2017 09:19:03 -0000 Received: from mga01.intel.com (HELO mga01.intel.com) (192.55.52.88) by server-15.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 5 Apr 2017 09:19:03 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1491383943; x=1522919943; h=from:to:cc:subject:date:message-id; bh=BcOdmT4ZgYAqpc2Q91k5IeNDQAKGL60gS/gb/Emz+rE=; b=r93P2q6vf8KLXfyMvX/ABv4mQ16CUfIh7QQ4lpZt3f5FZPyleN311FZY jLPlODWoAqu0DMkJKYROmTxcqpu9sQ==; Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Apr 2017 02:19:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,278,1486454400"; d="scan'208";a="69615914" Received: from zhangyu-optiplex-9020.bj.intel.com ([10.238.135.159]) by orsmga002.jf.intel.com with ESMTP; 05 Apr 2017 02:18:59 -0700 From: Yu Zhang To: xen-devel@lists.xen.org Date: Wed, 5 Apr 2017 16:59:50 +0800 Message-Id: <1491382790-30066-1-git-send-email-yu.c.zhang@linux.intel.com> X-Mailer: git-send-email 1.9.1 Cc: George Dunlap , Andrew Cooper , zhiyuan.lv@intel.com, Jan Beulich Subject: [Xen-devel] [PATCH RFC] x86/ioreq server: Optimize p2m cleaning up code in p2m_finish_type_change(). 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: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Previously, p2m_finish_type_change() is triggered to iterate and clean up the p2m table when an ioreq server unmaps from memory type HVMMEM_ioreq_server. And the current iteration number is set to 256 And after these iterations, hypercall pre-emption is checked. But it is likely that no p2m change is performed for the just finished iterations, which means p2m_finish_type_change() will return quite soon. So in such scenario, we can allow the p2m iteration to continue, without checking the hypercall pre-emption. Signed-off-by: Yu Zhang --- Note: this patch shall only be accepted after previous x86/ioreq server patches be merged. Cc: Jan Beulich Cc: Andrew Cooper Cc: George Dunlap --- xen/arch/x86/hvm/dm.c | 5 ++++- xen/arch/x86/mm/p2m.c | 9 ++++++++- xen/include/asm-x86/p2m.h | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/hvm/dm.c b/xen/arch/x86/hvm/dm.c index d72b7bd..3aa1286 100644 --- a/xen/arch/x86/hvm/dm.c +++ b/xen/arch/x86/hvm/dm.c @@ -411,14 +411,17 @@ static int dm_op(domid_t domid, while ( read_atomic(&p2m->ioreq.entry_count) && first_gfn <= p2m->max_mapped_pfn ) { + bool changed = false; + /* Iterate p2m table for 256 gfns each time. */ p2m_finish_type_change(d, _gfn(first_gfn), 256, - p2m_ioreq_server, p2m_ram_rw); + p2m_ioreq_server, p2m_ram_rw, &changed); first_gfn += 256; /* Check for continuation if it's not the last iteration. */ if ( first_gfn <= p2m->max_mapped_pfn && + changed && hypercall_preempt_check() ) { rc = -ERESTART; diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 0daaa86..b171a4b 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -1034,12 +1034,13 @@ void p2m_change_type_range(struct domain *d, /* Synchronously modify the p2m type for a range of gfns from ot to nt. */ void p2m_finish_type_change(struct domain *d, gfn_t first_gfn, unsigned long max_nr, - p2m_type_t ot, p2m_type_t nt) + p2m_type_t ot, p2m_type_t nt, bool *changed) { struct p2m_domain *p2m = p2m_get_hostp2m(d); p2m_type_t t; unsigned long gfn = gfn_x(first_gfn); unsigned long last_gfn = gfn + max_nr - 1; + bool is_changed = false; ASSERT(ot != nt); ASSERT(p2m_is_changeable(ot) && p2m_is_changeable(nt)); @@ -1052,12 +1053,18 @@ void p2m_finish_type_change(struct domain *d, get_gfn_query_unlocked(d, gfn, &t); if ( t == ot ) + { p2m_change_type_one(d, gfn, t, nt); + is_changed = true; + } gfn++; } p2m_unlock(p2m); + + if ( changed ) + *changed = is_changed; } /* diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index 0e670af..2e02538 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -615,7 +615,7 @@ int p2m_change_type_one(struct domain *d, unsigned long gfn, void p2m_finish_type_change(struct domain *d, gfn_t first_gfn, unsigned long max_nr, - p2m_type_t ot, p2m_type_t nt); + p2m_type_t ot, p2m_type_t nt, bool *changed); /* Report a change affecting memory types. */ void p2m_memory_type_changed(struct domain *d);