From patchwork Tue Jul 25 18:28:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 9862711 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 544FE600F5 for ; Tue, 25 Jul 2017 18:31:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F6DA28462 for ; Tue, 25 Jul 2017 18:31:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4455628682; Tue, 25 Jul 2017 18:31:32 +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 C859328462 for ; Tue, 25 Jul 2017 18:31:31 +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 1da4aG-000824-Dr; Tue, 25 Jul 2017 18:29:28 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1da4aF-00081c-42 for xen-devel@lists.xen.org; Tue, 25 Jul 2017 18:29:27 +0000 Received: from [85.158.139.211] by server-13.bemta-5.messagelabs.com id 42/D5-01732-60E87795; Tue, 25 Jul 2017 18:29:26 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuphkeJIrShJLcpLzFFi42JxWrrBXpe1rzz SYNVic4slHxezODB6HN39mymAMYo1My8pvyKBNaPv/EWmgvsCFa1tzxkbGFfydDFyckgI+Evs 2fKOGcRmE9CX2P3iExOILSKgLnG64yJrFyMHB7OArsSqnxogprBAsMSVj1EgJouAqsT3D8UgJ q+Ap8SsgxkQ8+Qkzh//CTaPU8BLYtL6UywgthBQyeM195khbDWJa/2X2EFsXgFBiZMzn4DVMA tISBx88YJ5AiPvLCSpWUhSCxiZVjGqF6cWlaUW6RrrJRVlpmeU5CZm5ugaGpjq5aYWFyemp+Y kJhXrJefnbmIEhgwDEOxg3PvP6RCjJAeTkijvN93ySCG+pPyUyozE4oz4otKc1OJDjDIcHEoS vA09QDnBotT01Iq0zBxg8MKkJTh4lER4t4GkeYsLEnOLM9MhUqcYdTleTfj/jUmIJS8/L1VKn LcbpEgApCijNA9uBCySLjHKSgnzMgIdJcRTkFqUm1mCKv+KUZyDUUmYdxfIFJ7MvBK4Ta+Ajm ACOmLOjFKQI0oSEVJSDYwq3866GQTf6tz4NqWjaD/bzd0CCTd/zuR0DrzI17Gk/t+e7795T6W JTWTjmrVg66brT3jeXc+y+vRMuM07rsZL8PXS59+WXpJaZdWh2zDnUPnrzcrbdScJb5zz0Xlh +Xr5lmsPqtx83RNqmlYZhk5nEDm5WJuxIfF59G7jPTvVf/G2nFtueq1WiaU4I9FQi7moOBEAp p96Zp8CAAA= X-Env-Sender: prvs=3721034a5=Andrew.Cooper3@citrix.com X-Msg-Ref: server-6.tower-206.messagelabs.com!1501007363!101641426!2 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: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 34907 invoked from network); 25 Jul 2017 18:29:25 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-6.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 25 Jul 2017 18:29:25 -0000 X-IronPort-AV: E=Sophos;i="5.40,412,1496102400"; d="scan'208";a="441271814" From: Andrew Cooper To: Xen-devel Date: Tue, 25 Jul 2017 19:28:56 +0100 Message-ID: <1501007337-18353-3-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1501007337-18353-1-git-send-email-andrew.cooper3@citrix.com> References: <1501007337-18353-1-git-send-email-andrew.cooper3@citrix.com> MIME-Version: 1.0 Cc: Andrew Cooper Subject: [Xen-devel] [PATCH v2 2/3] x86/hvm: Rearange check_segment() to use a switch statement 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-Virus-Scanned: ClamAV using ClamSMTP This simplifies the logic by separating the x86_segment check from the type check. No functional change. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- xen/arch/x86/hvm/domain.c | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/xen/arch/x86/hvm/domain.c b/xen/arch/x86/hvm/domain.c index dca7a00..293956c 100644 --- a/xen/arch/x86/hvm/domain.c +++ b/xen/arch/x86/hvm/domain.c @@ -70,23 +70,38 @@ static int check_segment(struct segment_register *reg, enum x86_segment seg) return -EINVAL; } - if ( seg == x86_seg_cs && !(reg->attr.fields.type & 0x8) ) + switch ( seg ) { - gprintk(XENLOG_ERR, "Non-code segment provided for CS\n"); - return -EINVAL; - } + case x86_seg_cs: + if ( !(reg->attr.fields.type & 0x8) ) + { + gprintk(XENLOG_ERR, "Non-code segment provided for CS\n"); + return -EINVAL; + } + break; - if ( seg == x86_seg_ss && - ((reg->attr.fields.type & 0x8) || !(reg->attr.fields.type & 0x2)) ) - { - gprintk(XENLOG_ERR, "Non-writeable segment provided for SS\n"); - return -EINVAL; - } + case x86_seg_ss: + if ( (reg->attr.fields.type & 0x8) || !(reg->attr.fields.type & 0x2) ) + { + gprintk(XENLOG_ERR, "Non-writeable segment provided for SS\n"); + return -EINVAL; + } + break; - if ( reg->attr.fields.s && seg != x86_seg_ss && seg != x86_seg_cs && - (reg->attr.fields.type & 0x8) && !(reg->attr.fields.type & 0x2) ) - { - gprintk(XENLOG_ERR, "Non-readable segment provided for DS or ES\n"); + case x86_seg_ds: + case x86_seg_es: + if ( (reg->attr.fields.type & 0x8) && !(reg->attr.fields.type & 0x2) ) + { + gprintk(XENLOG_ERR, "Non-readable segment provided for DS or ES\n"); + return -EINVAL; + } + break; + + case x86_seg_tr: + break; + + default: + ASSERT_UNREACHABLE(); return -EINVAL; }