From patchwork Wed Jul 3 11:33:26 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: 11029361 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 3B4A214DB for ; Wed, 3 Jul 2019 11:35:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 28229286E0 for ; Wed, 3 Jul 2019 11:35:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C98128969; Wed, 3 Jul 2019 11:35:22 +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 A4D09286E0 for ; Wed, 3 Jul 2019 11:35:20 +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 1hidWN-0004V7-1o; Wed, 03 Jul 2019 11:33:55 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hidWL-0004Ux-J5 for xen-devel@lists.xenproject.org; Wed, 03 Jul 2019 11:33:53 +0000 X-Inumbo-ID: 6e646504-9d86-11e9-8cd7-bf073077d379 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 6e646504-9d86-11e9-8cd7-bf073077d379; Wed, 03 Jul 2019 11:33:52 +0000 (UTC) Authentication-Results: esa5.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 (esa5.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=esa5.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="roger.pau@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa5.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=esa5.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 (esa5.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=esa5.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 29wQgf3/gOW/m6CSt0hTXNcaOrDfQOCLEBzUvnp3IPcVBiwPVi1PsdGsPuOaqiOjq4xH0dRcKU 67z1UXmUaRuQxV+3awv4XvyG6KE/47Xk3yyA8jvCFWH7uqQJ6qPddTP2nciMj6qTqj32rQC1Bf NVWvZJrbF34njGuyokAUJzhpcd7HDgxZqwYjeKF7UjZyh/Mp1wdtBm4dYgagDdSecqMqpaDffH ujMAp2cbR5h5qZmvOfEvIyG/M+aqMCBKB4bNfv09XLboLrcZVjmd3S/R3B8Ougm3K1/VLfKNX7 D9A= X-SBRS: 2.7 X-MesageID: 2567772 X-Ironport-Server: esa5.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="2567772" From: Roger Pau Monne To: Date: Wed, 3 Jul 2019 13:33:26 +0200 Message-ID: <20190703113326.2344-1-roger.pau@citrix.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2] 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 add a check to ensure p2m_entry_modify is never called with level == 0. That should allow to catch future errors related to the level parameter. Fixes: c7a4c088ad1c ('x86/mm: split p2m ioreq server pages special handling into helper') Signed-off-by: Roger Pau Monné Reviewed-by: Jan Beulich Reviewed-by: Kevin Tian --- Cc: Jun Nakajima Cc: Kevin Tian Cc: George Dunlap Cc: Jan Beulich Cc: Andrew Cooper Cc: Wei Liu --- Changes since v1: - Check level is != 0 in p2m_entry_modify. - Expand digits of hash id. --- xen/arch/x86/mm/p2m-ept.c | 2 +- xen/include/asm-x86/p2m.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) 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..aff34e3adf 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -946,6 +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); BUG_ON(level > 1 && (nt == p2m_ioreq_server || nt == p2m_map_foreign)); if ( level != 1 || (nt == ot && mfn_eq(nfn, ofn)) )