From patchwork Mon Mar 6 09:28:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Razvan Cojocaru X-Patchwork-Id: 9605457 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 9A4DB602B4 for ; Mon, 6 Mar 2017 09:30:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 721FE27F54 for ; Mon, 6 Mar 2017 09:30:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 644352832D; Mon, 6 Mar 2017 09:30:56 +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 940B827F54 for ; Mon, 6 Mar 2017 09:30:55 +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 1ckown-0003sS-00; Mon, 06 Mar 2017 09:28:52 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ckowl-0003sJ-7j for xen-devel@lists.xen.org; Mon, 06 Mar 2017 09:28:51 +0000 Received: from [85.158.143.35] by server-4.bemta-6.messagelabs.com id 67/08-25093-2DB2DB85; Mon, 06 Mar 2017 09:28:50 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprPIsWRWlGSWpSXmKPExsUSfTxjoe4l7b0 RBtO2M1os+biYxYHR4+ju30wBjFGsmXlJ+RUJrBmvDu1hK/giVzHlxhmWBsZrYl2MnBxCAu4S x//PZ+1i5AKy1zBKHL7/jwnCucoosW7eBCaIKjeJc+1X2SAS+xgllj2bDZZgEzCUWL2xhQ3EF hGQlrj2+TIjSBGzwGRGiT3zJgI57BzCAsESx41BSlgEVCXO/+tlAbF5BTwkDl19zAxiSwjISZ w8NpkVws6RaHh9GMjmALKlJP63KoFMlBBYwSKx6OJ6NogaGYlHE2+yTWAUWMDIsIpRozi1qCy 1SNfIUi+pKDM9oyQ3MTNH19DATC83tbg4MT01JzGpWC85P3cTIzCwGIBgB+OBRYGHGCU5mJRE eRdM2xkhxJeUn1KZkVicEV9UmpNafIhRhoNDSYJ3keGuCCHBotT01Iq0zBxgiMOkJTh4lER4b 4KkeYsLEnOLM9MhUqcYdTnmzN79hkmIJS8/L1VKnPc2SJEASFFGaR7cCFi8XWKUlRLmZQQ6So inILUoN7MEVf4VozgHo5Iw7wuQKTyZeSVwm14BHcEEdISfzE6QI0oSEVJSDYx5Peph3PvvSmy NObvjSI8N4+nth+w/WL6YN2HjkrfXr9pERDBt03BQlWOLdrdLDDzOr/Fa7Vxy8NrAU4ZLLt2W yfyf91DfxlyX+ejc/7cNDfb59v8q/m+aPCH8+17+JJ4d/4/NKfgwJ2f1uq8xApla94R85Z4Vv c6LT50v8/6h0KLuZxOD10grsRRnJBpqMRcVJwIA9xDXlbICAAA= X-Env-Sender: rcojocaru@bitdefender.com X-Msg-Ref: server-7.tower-21.messagelabs.com!1488792529!60844613!1 X-Originating-IP: [91.199.104.161] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 34874 invoked from network); 6 Mar 2017 09:28:49 -0000 Received: from mx01.bbu.dsd.mx.bitdefender.com (HELO mx01.bbu.dsd.mx.bitdefender.com) (91.199.104.161) by server-7.tower-21.messagelabs.com with DHE-RSA-AES128-GCM-SHA256 encrypted SMTP; 6 Mar 2017 09:28:49 -0000 Received: (qmail 17982 invoked from network); 6 Mar 2017 11:28:48 +0200 Received: from unknown (HELO mx-sr.buh.bitdefender.com) (10.17.80.103) by mx01.bbu.dsd.mx.bitdefender.com with AES256-GCM-SHA384 encrypted SMTP; 6 Mar 2017 11:28:48 +0200 Received: from smtp01.buh.bitdefender.com (smtp.bitdefender.biz [10.17.80.75]) by mx-sr.buh.bitdefender.com (Postfix) with ESMTP id 905527FC3B for ; Mon, 6 Mar 2017 11:28:48 +0200 (EET) Received: (qmail 7548 invoked from network); 6 Mar 2017 11:28:48 +0200 Received: from xen.dsd.ro (HELO xen.dsd.bitdefender.biz) (rcojocaru@bitdefender.com@10.10.14.109) by smtp01.buh.bitdefender.com with AES128-SHA256 encrypted SMTP; 6 Mar 2017 11:28:48 +0200 From: Razvan Cojocaru To: xen-devel@lists.xen.org Date: Mon, 6 Mar 2017 11:28:37 +0200 Message-Id: <1488792517-5368-1-git-send-email-rcojocaru@bitdefender.com> X-Mailer: git-send-email 1.9.1 X-BitDefender-Scanner: Clean, Agent: BitDefender qmail 3.1.6 on smtp01.buh.bitdefender.com, sigver: 7.70007 X-BitDefender-Spam: No (0) X-BitDefender-SpamStamp: Build: [Engines: 2.15.8.1074, Dats: 442423, Stamp: 3], Multi: [Enabled, t: (0.000011, 0.017666)], BW: [Enabled, t: (0.000009)], RBL DNSBL: [Disabled], APM: [Enabled, Score: 500, t: (0.005375), Flags: 85D2ED72; NN_NO_CONTENT_TYPE; NN_LEGIT_SUMM_400_WORDS; NN_NO_LINK_NMD; NN_LEGIT_BITDEFENDER; NN_LEGIT_S_SQARE_BRACKETS; NN_LEGIT_MAILING_LIST_TO], SGN: [Enabled, t: (0.010400,0.000234)], URL: [Enabled, t: (0.000005)], RTDA: [Enabled, t: (0.016003), Hit: No, Details: v2.4.3; Id: 11.5ev1g9.1bacose71.1qo1l], total: 0(775) X-BitDefender-CF-Stamp: none Cc: george.dunlap@eu.citrix.com, andrew.cooper3@citrix.com, tamas@tklengyel.com, Razvan Cojocaru , jbeulich@suse.com Subject: [Xen-devel] [PATCH] x86/mem_access: fixed vm_event emulation check with altp2m enabled 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 Currently, p2m_mem_access_emulate_check() uses p2m_get_mem_access() to check if the page restrictions have been lifted between the time of sending the vm_event out and the reception of the reply - in which case emulation is no longer required. Unfortunately, p2m_get_mem_access() uses p2m_get_hostp2m(d) which only checks the default EPT (view 0 in altp2m parlance). This patch fixes this by checking the active altp2m view instead, whenever applicable. Signed-off-by: Razvan Cojocaru Reviewed-by: Jan Beulich Acked-by: Tamas K Lengyel --- xen/arch/x86/mm/mem_access.c | 98 +++++++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 42 deletions(-) diff --git a/xen/arch/x86/mm/mem_access.c b/xen/arch/x86/mm/mem_access.c index 3ebeb4f..29a0c43 100644 --- a/xen/arch/x86/mm/mem_access.c +++ b/xen/arch/x86/mm/mem_access.c @@ -32,14 +32,68 @@ #include "mm-locks.h" +/* + * Get access type for a gfn. + * If gfn == INVALID_GFN, gets the default access type. + */ +static int _p2m_get_mem_access(struct p2m_domain *p2m, gfn_t gfn, + xenmem_access_t *access) +{ + p2m_type_t t; + p2m_access_t a; + mfn_t mfn; + + static const xenmem_access_t memaccess[] = { +#define ACCESS(ac) [p2m_access_##ac] = XENMEM_access_##ac + ACCESS(n), + ACCESS(r), + ACCESS(w), + ACCESS(rw), + ACCESS(x), + ACCESS(rx), + ACCESS(wx), + ACCESS(rwx), + ACCESS(rx2rw), + ACCESS(n2rwx), +#undef ACCESS + }; + + /* If request to get default access. */ + if ( gfn_eq(gfn, INVALID_GFN) ) + { + *access = memaccess[p2m->default_access]; + return 0; + } + + gfn_lock(p2m, gfn, 0); + mfn = p2m->get_entry(p2m, gfn_x(gfn), &t, &a, 0, NULL, NULL); + gfn_unlock(p2m, gfn, 0); + + if ( mfn_eq(mfn, INVALID_MFN) ) + return -ESRCH; + + if ( (unsigned) a >= ARRAY_SIZE(memaccess) ) + return -ERANGE; + + *access = memaccess[a]; + return 0; +} + bool p2m_mem_access_emulate_check(struct vcpu *v, const vm_event_response_t *rsp) { xenmem_access_t access; bool violation = 1; const struct vm_event_mem_access *data = &rsp->u.mem_access; + struct domain *d = v->domain; + struct p2m_domain *p2m = NULL; - if ( p2m_get_mem_access(v->domain, _gfn(data->gfn), &access) == 0 ) + if ( altp2m_active(d) ) + p2m = p2m_get_altp2m(v); + if ( !p2m ) + p2m = p2m_get_hostp2m(d); + + if ( _p2m_get_mem_access(p2m, _gfn(data->gfn), &access) == 0 ) { switch ( access ) { @@ -405,51 +459,11 @@ long p2m_set_mem_access_multi(struct domain *d, return rc; } -/* - * Get access type for a gfn. - * If gfn == INVALID_GFN, gets the default access type. - */ int p2m_get_mem_access(struct domain *d, gfn_t gfn, xenmem_access_t *access) { struct p2m_domain *p2m = p2m_get_hostp2m(d); - p2m_type_t t; - p2m_access_t a; - mfn_t mfn; - - static const xenmem_access_t memaccess[] = { -#define ACCESS(ac) [p2m_access_##ac] = XENMEM_access_##ac - ACCESS(n), - ACCESS(r), - ACCESS(w), - ACCESS(rw), - ACCESS(x), - ACCESS(rx), - ACCESS(wx), - ACCESS(rwx), - ACCESS(rx2rw), - ACCESS(n2rwx), -#undef ACCESS - }; - - /* If request to get default access. */ - if ( gfn_eq(gfn, INVALID_GFN) ) - { - *access = memaccess[p2m->default_access]; - return 0; - } - gfn_lock(p2m, gfn, 0); - mfn = p2m->get_entry(p2m, gfn_x(gfn), &t, &a, 0, NULL, NULL); - gfn_unlock(p2m, gfn, 0); - - if ( mfn_eq(mfn, INVALID_MFN) ) - return -ESRCH; - - if ( (unsigned) a >= ARRAY_SIZE(memaccess) ) - return -ERANGE; - - *access = memaccess[a]; - return 0; + return _p2m_get_mem_access(p2m, gfn, access); } /*