From patchwork Fri May 12 02:42:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Xiong Y" X-Patchwork-Id: 9721183 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 15FB460236 for ; Thu, 11 May 2017 10:40:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A3B528687 for ; Thu, 11 May 2017 10:40:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 08D5A28689; Thu, 11 May 2017 10:40:51 +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=-1.0 required=2.0 tests=BAYES_00, DATE_IN_FUTURE_12_24, RCVD_IN_DNSWL_MED autolearn=no 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 D85CE2868F for ; Thu, 11 May 2017 10:40:49 +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 1d8lUN-0003LP-Tk; Thu, 11 May 2017 10:38:31 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d8lUN-0003LJ-7P for xen-devel@lists.xen.org; Thu, 11 May 2017 10:38:31 +0000 Received: from [85.158.139.211] by server-1.bemta-5.messagelabs.com id C9/DB-01992-62F34195; Thu, 11 May 2017 10:38:30 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrNLMWRWlGSWpSXmKPExsVywNwkQlfNXiT S4PccZoslHxezODB6HN39mymAMYo1My8pvyKBNaNn9wW2grnGFadfv2duYFyp1sXIxSEkMJ1R 4sumFYxdjJwcEgK8EkeWzWCFsP0lHu9vYYYoamGU+Dl3KxNIgk1AW2Lt31NsILaIgLTEtc+XG UGKmAUOMUqsntcP1i0sECCxtWEL2FQWAVWJxXMWADVwcPAKuEs8OxsEsUBO4ua5TmYQmxMofO jaATBbSMBN4uSFdewTGHkXMDKsYtQoTi0qSy3SNTbQSyrKTM8oyU3MzNE1NDDVy00tLk5MT81 JTCrWS87P3cQIDIh6BgbGHYwTVvkdYpTkYFIS5W3/IxwpxJeUn1KZkVicEV9UmpNafIhRhoND SYL3u61IpJBgUWp6akVaZg4wNGHSEhw8SiK8/0HSvMUFibnFmekQqVOMuhy75r57zyTEkpefl yolzstvB1QkAFKUUZoHNwIWJ5cYZaWEeRkZGBiEeApSi3IzS1DlXzGKczAqCfPagkzhycwrgd v0CugIJqAj+kHu5y0uSURISTUwhqfpLf/p3JvoxG7jY3AjcadX/8E54bm/ugyT3xhdiu50kHj /TE3u0A4ha9vtR5niZFebTJad2hR5Z/qa6UYVF0LtIubY7j6whTvTXdG3y6lt/fmvqgzCW4rl la4VvVqZvap/x5lf+Z7b0uJ/9p9+d4GVh6VfvErZxeSwnq3Zv40nl5rWzhRRYinOSDTUYi4qT gQAa47M9Y4CAAA= X-Env-Sender: xiong.y.zhang@intel.com X-Msg-Ref: server-6.tower-206.messagelabs.com!1494499106!97334615!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 22173 invoked from network); 11 May 2017 10:38:29 -0000 Received: from mga01.intel.com (HELO mga01.intel.com) (192.55.52.88) by server-6.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 11 May 2017 10:38:29 -0000 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 May 2017 03:38:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,323,1491289200"; d="scan'208";a="855520396" Received: from test-optiplex-7040.bj.intel.com ([10.238.154.174]) by FMSMGA003.fm.intel.com with ESMTP; 11 May 2017 03:38:24 -0700 From: Xiong Zhang To: xen-devel@lists.xen.org Date: Fri, 12 May 2017 10:42:57 +0800 Message-Id: <1494556977-20432-1-git-send-email-xiong.y.zhang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494457022-5199-1-git-send-email-xiong.y.zhang@intel.com> References: <1494457022-5199-1-git-send-email-xiong.y.zhang@intel.com> Cc: andrew.cooper3@citrix.com, george.dunlap@citrix.com, paul.durrant@citrix.com, yu.c.zhang@linux.intel.com, zhiyuan.lv@intel.com, JBeulich@suse.com, Xiong Zhang Subject: [Xen-devel] [PATCH V4] x86/ioreq_server: Make p2m_finish_type_change actually work 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 Commit 6d774a951696 ("x86/ioreq server: synchronously reset outstanding p2m_ioreq_server entries when an ioreq server unmaps") introduced p2m_finish_type_change(), which was meant to synchronously finish a previously initiated type change over a gpfn range. It did this by calling get_entry(), checking if it was the appropriate type, and then calling set_entry(). Unfortunately, a previous commit (1679e0df3df6 "x86/ioreq server: asynchronously reset outstanding p2m_ioreq_server entries") modified get_entry() to always return the new type after the type change, meaning that p2m_finish_type_change() never changed any entries. Which means when an ioreq server was detached and then re-attached (as happens in XenGT on reboot) the re-attach failed. Fix this by using the existing p2m-specific recalculation logic instead of doing a read-check-write loop. Fix: 'commit 6d774a951696 ("x86/ioreq server: synchronously reset outstanding p2m_ioreq_server entries when an ioreq server unmaps")' Signed-off-by: Xiong Zhang Signed-off-by: Yu Zhang Reviewed-by: George Dunlap Reviewed-by: Jan Beulich --- v1: Add ioreq_pre_recalc query flag to get the old p2m_type.(Jan) v2: Add p2m->recalc() hook to change gfn p2m_type. (George) v3: Make commit message clearer. (George) Keep the name of p2m-specific recal function unchanged. (Jan) v4: Move version info below S-o-B and handle return value of p2m->recalc. (Jan) --- xen/arch/x86/hvm/dm.c | 5 +++-- xen/arch/x86/mm/p2m-ept.c | 1 + xen/arch/x86/mm/p2m-pt.c | 1 + xen/arch/x86/mm/p2m.c | 35 +++++++++++++++++++++++------------ xen/include/asm-x86/p2m.h | 7 ++++--- 5 files changed, 32 insertions(+), 17 deletions(-) diff --git a/xen/arch/x86/hvm/dm.c b/xen/arch/x86/hvm/dm.c index d72b7bd..99bf66a 100644 --- a/xen/arch/x86/hvm/dm.c +++ b/xen/arch/x86/hvm/dm.c @@ -412,8 +412,9 @@ static int dm_op(domid_t domid, first_gfn <= p2m->max_mapped_pfn ) { /* Iterate p2m table for 256 gfns each time. */ - p2m_finish_type_change(d, _gfn(first_gfn), 256, - p2m_ioreq_server, p2m_ram_rw); + rc = p2m_finish_type_change(d, _gfn(first_gfn), 256); + if ( rc < 0 ) + break; first_gfn += 256; diff --git a/xen/arch/x86/mm/p2m-ept.c b/xen/arch/x86/mm/p2m-ept.c index f37a1f2..09efba7 100644 --- a/xen/arch/x86/mm/p2m-ept.c +++ b/xen/arch/x86/mm/p2m-ept.c @@ -1238,6 +1238,7 @@ int ept_p2m_init(struct p2m_domain *p2m) p2m->set_entry = ept_set_entry; p2m->get_entry = ept_get_entry; + p2m->recalc = resolve_misconfig; p2m->change_entry_type_global = ept_change_entry_type_global; p2m->change_entry_type_range = ept_change_entry_type_range; p2m->memory_type_changed = ept_memory_type_changed; diff --git a/xen/arch/x86/mm/p2m-pt.c b/xen/arch/x86/mm/p2m-pt.c index 5079b59..2eddeee 100644 --- a/xen/arch/x86/mm/p2m-pt.c +++ b/xen/arch/x86/mm/p2m-pt.c @@ -1153,6 +1153,7 @@ void p2m_pt_init(struct p2m_domain *p2m) { p2m->set_entry = p2m_pt_set_entry; p2m->get_entry = p2m_pt_get_entry; + p2m->recalc = do_recalc; p2m->change_entry_type_global = p2m_pt_change_entry_type_global; p2m->change_entry_type_range = p2m_pt_change_entry_type_range; p2m->write_p2m_entry = paging_write_p2m_entry; diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 1d57e5c..668c5a6 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -1011,33 +1011,44 @@ void p2m_change_type_range(struct domain *d, p2m_unlock(p2m); } -/* 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) +/* + * Finish p2m type change for gfns which are marked as need_recalc in a range. + * Returns: 0/1 for success, negative for failure + */ +int p2m_finish_type_change(struct domain *d, + gfn_t first_gfn, unsigned long max_nr) { 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; - - ASSERT(ot != nt); - ASSERT(p2m_is_changeable(ot) && p2m_is_changeable(nt)); + int rc = 0; p2m_lock(p2m); last_gfn = min(last_gfn, p2m->max_mapped_pfn); while ( gfn <= last_gfn ) { - get_gfn_query_unlocked(d, gfn, &t); - - if ( t == ot ) - p2m_change_type_one(d, gfn, t, nt); + rc = p2m->recalc(p2m, gfn); + /* + * ept->recalc could return 0/1/-ENOMEM. pt->recalc could return + * 0/-ENOMEM/-ENOENT, -ENOENT isn't an error as we are looping + * gfn here. + */ + if ( rc == -ENOENT) + rc = 0; + else if ( rc < 0 ) + { + gdprintk(XENLOG_ERR, "p2m->recalc failed! Dom%d gfn=%lx\n", + d->domain_id, gfn); + break; + } gfn++; } p2m_unlock(p2m); + + return rc; } /* diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index 7574a9b..d7d47fe 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -246,6 +246,8 @@ struct p2m_domain { p2m_query_t q, unsigned int *page_order, bool_t *sve); + int (*recalc)(struct p2m_domain *p2m, + unsigned long gfn); void (*enable_hardware_log_dirty)(struct p2m_domain *p2m); void (*disable_hardware_log_dirty)(struct p2m_domain *p2m); void (*flush_hardware_cached_dirty)(struct p2m_domain *p2m); @@ -607,10 +609,9 @@ int p2m_change_type_one(struct domain *d, unsigned long gfn, p2m_type_t ot, p2m_type_t nt); /* Synchronously change the p2m type for a range of gfns */ -void p2m_finish_type_change(struct domain *d, +int p2m_finish_type_change(struct domain *d, gfn_t first_gfn, - unsigned long max_nr, - p2m_type_t ot, p2m_type_t nt); + unsigned long max_nr); /* Report a change affecting memory types. */ void p2m_memory_type_changed(struct domain *d);