From patchwork Mon Jul 18 09:51:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 9234327 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 3C0B9607FF for ; Mon, 18 Jul 2016 09:55:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 29EAC201F5 for ; Mon, 18 Jul 2016 09:55:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E925228C8; Mon, 18 Jul 2016 09:55:18 +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 93E24263DC for ; Mon, 18 Jul 2016 09:55:14 +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 1bP5Dv-00077r-Ec; Mon, 18 Jul 2016 09:52:27 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bP5Dt-00073r-Lj for xen-devel@lists.xen.org; Mon, 18 Jul 2016 09:52:25 +0000 Received: from [193.109.254.147] by server-11.bemta-14.messagelabs.com id 53/2A-01707-9D6AC875; Mon, 18 Jul 2016 09:52:25 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuplkeJIrShJLcpLzFFi42JxWrrBXvfGsp5 wgyPNKhZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8aGza0sBTtkKlZe2MbUwPhBrIuRk0NCwF/i 9ckWRhCbTUBfYveLT0wgtoiAusTpjousXYwcHMwCfhKHHviChIUFvCXufpjEDmKzCKhK/F/5B szmFfCUuPRxESvESDmJ88d/MoO0cgLFZ/eLg5hCAh4SH98rglQICahJXOu/BNUpKHFy5hMWEJ tZQELi4IsXzBBTuCVun57KPIGRbxaSsllIyhYwMq1iVC9OLSpLLdK10EsqykzPKMlNzMzRNTQ 00ctNLS5OTE/NSUwq1kvOz93ECAwmBiDYwbhxkvMhRkkOJiVRXqsFPeFCfEn5KZUZicUZ8UWl OanFhxhlODiUJHgnLwXKCRalpqdWpGXmAMMaJi3BwaMkwmsDkuYtLkjMLc5Mh0idYlSUEudtB 0kIgCQySvPg2mCxdIlRVkqYlxHoECGegtSi3MwSVPlXjOIcjErCvK0gU3gy80rgpr8CWswEtN hAtRtkcUkiQkqqgVFbrkubNV2/4GXQEit2mfYZWcsYwx2zzk8IcDzd8V394caqq2H1b6YlJn7 NMnn47PhHGcHMFX/m/0mUD48Oipkkkrjfa/K9w/cPem2MyJF81H4o+qKzxhzGDDGDoz/5Wdv1 46337V19jtHY5218/K/123r+xChKff0euKZbrd5s0a/e0zOe8iuxFGckGmoxFxUnAgDTBjGro AIAAA== X-Env-Sender: prvs=0008e1294=Andrew.Cooper3@citrix.com X-Msg-Ref: server-13.tower-27.messagelabs.com!1468835539!54516342!6 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.77; banners=-,-,- X-VirusChecked: Checked Received: (qmail 55398 invoked from network); 18 Jul 2016 09:52:24 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-13.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 18 Jul 2016 09:52:24 -0000 X-IronPort-AV: E=Sophos;i="5.28,383,1464652800"; d="scan'208";a="373756601" From: Andrew Cooper To: Xen-devel Date: Mon, 18 Jul 2016 10:51:45 +0100 Message-ID: <1468835505-7278-10-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1468835505-7278-1-git-send-email-andrew.cooper3@citrix.com> References: <1468835505-7278-1-git-send-email-andrew.cooper3@citrix.com> MIME-Version: 1.0 X-DLP: MIA2 Cc: Andrew Cooper , Jan Beulich Subject: [Xen-devel] [PATCH 9/9] x86/hypercall: Reduce the size of the hypercall tables 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 The highest populated entry in each hypercall table is currently at index 49. There is no need to extend both to tables to 64 entries. Range check eax against the hypercall table array size, and use a BUILD_BUG_ON() to ensure that the hypercall tables don't grow larger than the args table. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich --- xen/arch/x86/hvm/hvm.c | 8 ++++++-- xen/arch/x86/hypercall.c | 14 ++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 198fe34..df177da 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -4094,7 +4094,7 @@ static long hvm_physdev_op_compat32( #define compat_grant_table_op hvm_grant_table_op_compat32 #define do_arch_1 paging_domctl_continuation -static const hypercall_table_t hvm_hypercall_table[NR_hypercalls] = { +static const hypercall_table_t hvm_hypercall_table[] = { COMPAT_CALL(memory_op), COMPAT_CALL(grant_table_op), COMPAT_CALL(vcpu_op), @@ -4153,7 +4153,11 @@ int hvm_do_hypercall(struct cpu_user_regs *regs) if ( (eax & 0x80000000) && is_viridian_domain(currd) ) return viridian_hypercall(regs); - if ( (eax >= NR_hypercalls) || !hvm_hypercall_table[eax].native ) + BUILD_BUG_ON(ARRAY_SIZE(hvm_hypercall_table) > + ARRAY_SIZE(hypercall_args_table)); + + if ( (eax >= ARRAY_SIZE(hvm_hypercall_table)) || + !hvm_hypercall_table[eax].native ) { regs->eax = -ENOSYS; return HVM_HCALL_completed; diff --git a/xen/arch/x86/hypercall.c b/xen/arch/x86/hypercall.c index 373bedf..1bf0a1c 100644 --- a/xen/arch/x86/hypercall.c +++ b/xen/arch/x86/hypercall.c @@ -82,7 +82,7 @@ const hypercall_args_t hypercall_args_table[NR_hypercalls] = #define do_arch_1 paging_domctl_continuation -static const hypercall_table_t pv_hypercall_table[NR_hypercalls] = { +static const hypercall_table_t pv_hypercall_table[] = { COMPAT_CALL(set_trap_table), HYPERCALL(mmu_update), COMPAT_CALL(set_gdt), @@ -147,7 +147,11 @@ long pv_hypercall(struct cpu_user_regs *regs) ASSERT(curr->arch.flags & TF_kernel_mode); - if ( (eax >= NR_hypercalls) || !pv_hypercall_table[eax].native ) + BUILD_BUG_ON(ARRAY_SIZE(pv_hypercall_table) > + ARRAY_SIZE(hypercall_args_table)); + + if ( (eax >= ARRAY_SIZE(pv_hypercall_table)) || + !pv_hypercall_table[eax].native ) return -ENOSYS; if ( !is_pv_32bit_vcpu(curr) ) @@ -255,7 +259,8 @@ void arch_do_multicall_call(struct mc_state *state) { struct multicall_entry *call = &state->call; - if ( (call->op < NR_hypercalls) && pv_hypercall_table[call->op].native ) + if ( (call->op < ARRAY_SIZE(pv_hypercall_table)) && + pv_hypercall_table[call->op].native ) call->result = pv_hypercall_table[call->op].native( call->args[0], call->args[1], call->args[2], call->args[3], call->args[4], call->args[5]); @@ -267,7 +272,8 @@ void arch_do_multicall_call(struct mc_state *state) { struct compat_multicall_entry *call = &state->compat_call; - if ( (call->op < NR_hypercalls) && pv_hypercall_table[call->op].compat ) + if ( (call->op < ARRAY_SIZE(pv_hypercall_table)) && + pv_hypercall_table[call->op].compat ) call->result = pv_hypercall_table[call->op].compat( call->args[0], call->args[1], call->args[2], call->args[3], call->args[4], call->args[5]);