From patchwork Wed Jul 3 09:43:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 11029245 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2447D1580 for ; Wed, 3 Jul 2019 09:45:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 15B9628895 for ; Wed, 3 Jul 2019 09:45:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 096A7288A2; Wed, 3 Jul 2019 09:45:16 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3505828780 for ; Wed, 3 Jul 2019 09:45:15 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hibnm-0002qZ-NZ; Wed, 03 Jul 2019 09:43:46 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hibnl-0002qT-I3 for xen-devel@lists.xenproject.org; Wed, 03 Jul 2019 09:43:45 +0000 X-Inumbo-ID: 0bd12d4f-9d77-11e9-8980-bc764e045a96 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 0bd12d4f-9d77-11e9-8980-bc764e045a96; Wed, 03 Jul 2019 09:43:44 +0000 (UTC) Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=roger.pau@citrix.com; spf=Pass smtp.mailfrom=roger.pau@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa3.hc3370-68.iphmx.com: no sender authenticity information available from domain of roger.pau@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="roger.pau@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa3.hc3370-68.iphmx.com: domain of roger.pau@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="roger.pau@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa3.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: dfxBY5OlyMg3r00Z3HrHB9J8Pj0ij5eERtf4MygBtPdRIxyZvFWbhc5kYlj7fpBXkn9ATs4Son 3MtK7+WwcNIixAHM9+sGunyrRl6jcqv/iPCBMlifnkQwfzx+Wjwz+Y3MWnwIb6YKlGUaNDxVsq EPeFATEwmVbbR5r3Rxa6hHfKUExRMFebKVRgWKesfpVJhoXHSVbW8eabTY0WdgibkjVs2GCfrp nxzKFwP0Y+psdrF6gXxURLz9pWVdxCK6lhXAE9LEVVVBcmt206xixHzoA74P1ybhu11DGIrpUL plQ= X-SBRS: 2.7 X-MesageID: 2547509 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.63,446,1557201600"; d="scan'208";a="2547509" From: Roger Pau Monne To: Date: Wed, 3 Jul 2019 11:43:22 +0200 Message-ID: <20190703094322.1551-1-roger.pau@citrix.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) MIME-Version: 1.0 Subject: [Xen-devel] [PATCH] x86/ept: pass correct level to p2m_entry_modify X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Kevin Tian , Jun Nakajima , Wei Liu , George Dunlap , Andrew Cooper , Jan Beulich , Roger Pau Monne Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP EPT differs from NPT and shadow when translating page orders to levels in the physmap page tables. EPT page tables level for order 0 pages is 0, while NPT and shadow instead use 1, ie: EPT page tables levels starts at 0 while NPT and shadow starts at 1. Fix the p2m_entry_modify call in atomic_write_ept_entry to always add one to the level, in order to match NPT and shadow usage. While there also fix p2m_entry_modify BUG condition to trigger when foreign or ioreq entries with level different than 0 are attempted. That should allow to catch future errors related to the level parameter. Fixes: c7a4c0 ('x86/mm: split p2m ioreq server pages special handling into helper') Signed-off-by: Roger Pau Monné --- Cc: Jun Nakajima Cc: Kevin Tian Cc: George Dunlap Cc: Jan Beulich Cc: Andrew Cooper Cc: Wei Liu --- xen/arch/x86/mm/p2m-ept.c | 2 +- xen/include/asm-x86/p2m.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/mm/p2m-ept.c b/xen/arch/x86/mm/p2m-ept.c index e3044bee2e..6b8468c793 100644 --- a/xen/arch/x86/mm/p2m-ept.c +++ b/xen/arch/x86/mm/p2m-ept.c @@ -51,7 +51,7 @@ static int atomic_write_ept_entry(struct p2m_domain *p2m, int level) { int rc = p2m_entry_modify(p2m, new.sa_p2mt, entryptr->sa_p2mt, - _mfn(new.mfn), _mfn(entryptr->mfn), level); + _mfn(new.mfn), _mfn(entryptr->mfn), level + 1); if ( rc ) return rc; diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index 09ef7e02fd..756929d5c0 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -946,7 +946,7 @@ static inline int p2m_entry_modify(struct p2m_domain *p2m, p2m_type_t nt, p2m_type_t ot, mfn_t nfn, mfn_t ofn, unsigned int level) { - BUG_ON(level > 1 && (nt == p2m_ioreq_server || nt == p2m_map_foreign)); + BUG_ON(level != 1 && (nt == p2m_ioreq_server || nt == p2m_map_foreign)); if ( level != 1 || (nt == ot && mfn_eq(nfn, ofn)) ) return 0;