From patchwork Tue Mar 8 15:30:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Malcolm Crossley X-Patchwork-Id: 8535191 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 266CEC0553 for ; Tue, 8 Mar 2016 15:33:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 47887201C8 for ; Tue, 8 Mar 2016 15:33:44 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id B8F4C20131 for ; Tue, 8 Mar 2016 15:33:38 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1adJas-0008Dh-RR; Tue, 08 Mar 2016 15:30:42 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1adJar-0008Db-5p for xen-devel@lists.xen.org; Tue, 08 Mar 2016 15:30:41 +0000 Received: from [85.158.139.211] by server-13.bemta-5.messagelabs.com id D1/68-24225-020FED65; Tue, 08 Mar 2016 15:30:40 +0000 X-Env-Sender: prvs=868dfebbc=malcolm.crossley@citrix.com X-Msg-Ref: server-11.tower-206.messagelabs.com!1457451037!15415399!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 8.11; banners=-,-,- X-VirusChecked: Checked Received: (qmail 42182 invoked from network); 8 Mar 2016 15:30:39 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-11.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 8 Mar 2016 15:30:39 -0000 X-IronPort-AV: E=Sophos;i="5.22,556,1449532800"; d="scan'208";a="344057447" From: Malcolm Crossley To: , , , Date: Tue, 8 Mar 2016 15:30:28 +0000 Message-ID: <1457451028-3808-1-git-send-email-malcolm.crossley@citrix.com> X-Mailer: git-send-email 1.7.12.4 MIME-Version: 1.0 X-DLP: MIA2 Cc: Malcolm Crossley , xen-devel@lists.xen.org Subject: [Xen-devel] [PATCH] xen: Restore p2m_access_t enum order to allow bitmask semantics 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: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Nested hap code assumed implict bitmask semantics of the p2m_access_t enum prior to C/S 4c63692d7c38c5ac414fe97f8ef37b66e05abe5c The change to the enum ordering broke this assumption and caused functional problems for the nested hap code. As it may be error prone to audit and find all other p2m_access users assuming bitmask semantics, instead restore the previous enum order and make it explict that bitmask semantics are to be preserved for the read, write and execute access types. Signed-off-by: Malcolm Crossley Reviewed-by: Andrew Cooper Reviewed-by: George Dunlap --- xen/arch/x86/mm/hap/nested_hap.c | 2 +- xen/include/xen/p2m-common.h | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/xen/arch/x86/mm/hap/nested_hap.c b/xen/arch/x86/mm/hap/nested_hap.c index 0dbae13..9cee5a0 100644 --- a/xen/arch/x86/mm/hap/nested_hap.c +++ b/xen/arch/x86/mm/hap/nested_hap.c @@ -263,7 +263,7 @@ nestedhvm_hap_nested_page_fault(struct vcpu *v, paddr_t *L2_gpa, switch ( p2ma_10 ) { - case p2m_access_rwx ... p2m_access_n: + case p2m_access_n ... p2m_access_rwx: break; case p2m_access_rx2rw: p2ma_10 = p2m_access_rx; diff --git a/xen/include/xen/p2m-common.h b/xen/include/xen/p2m-common.h index 8b70459..6374a5b 100644 --- a/xen/include/xen/p2m-common.h +++ b/xen/include/xen/p2m-common.h @@ -15,14 +15,15 @@ * default. */ typedef enum { - p2m_access_rwx = 0, /* The default access type when not used. */ - p2m_access_wx = 1, - p2m_access_rx = 2, - p2m_access_x = 3, - p2m_access_rw = 4, - p2m_access_w = 5, - p2m_access_r = 6, - p2m_access_n = 7, /* No access allowed. */ + /* Code uses bottom three bits with bitmask semantics */ + p2m_access_n = 0, /* No access allowed. */ + p2m_access_r = 1 << 0, + p2m_access_w = 1 << 1, + p2m_access_x = 1 << 2, + p2m_access_rw = p2m_access_r | p2m_access_w, + p2m_access_rx = p2m_access_r | p2m_access_x, + p2m_access_wx = p2m_access_w | p2m_access_x, + p2m_access_rwx = p2m_access_r | p2m_access_w | p2m_access_x, p2m_access_rx2rw = 8, /* Special: page goes from RX to RW on write */ p2m_access_n2rwx = 9, /* Special: page goes from N to RWX on access, *