From patchwork Mon Feb 15 07:42:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 8310781 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 E00A3C02AA for ; Mon, 15 Feb 2016 07:45:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C4420204C9 for ; Mon, 15 Feb 2016 07:45:30 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7A778204AF for ; Mon, 15 Feb 2016 07:45:29 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aVDny-0002pQ-Hj; Mon, 15 Feb 2016 07:42:46 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aVDnw-0002pL-TH for xen-devel@lists.xenproject.org; Mon, 15 Feb 2016 07:42:45 +0000 Received: from [85.158.139.211] by server-13.bemta-5.messagelabs.com id 07/B7-09478-47181C65; Mon, 15 Feb 2016 07:42:44 +0000 X-Env-Sender: JBeulich@suse.com X-Msg-Ref: server-15.tower-206.messagelabs.com!1455522161!13946865!1 X-Originating-IP: [137.65.248.74] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 62286 invoked from network); 15 Feb 2016 07:42:42 -0000 Received: from prv-mh.provo.novell.com (HELO prv-mh.provo.novell.com) (137.65.248.74) by server-15.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 15 Feb 2016 07:42:42 -0000 Received: from INET-PRV-MTA by prv-mh.provo.novell.com with Novell_GroupWise; Mon, 15 Feb 2016 00:42:40 -0700 Message-Id: <56C18F7D02000078000D1E93@prv-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 14.2.0 Date: Mon, 15 Feb 2016 00:42:37 -0700 From: "Jan Beulich" To: "xen-devel" Mime-Version: 1.0 Cc: Andrew Cooper , Keir Fraser Subject: [Xen-devel] [PATCH] x86/HVM: fold hypercall tables X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 In order to reduce the risk of unintentionally adding a function pointer to just one of the two tables, merge them into one, with each entry pair getting generated by a single macro invocation (at once dropping all explicit casting outside the macro definition). Signed-off-by: Jan Beulich x86/HVM: fold hypercall tables In order to reduce the risk of unintentionally adding a function pointer to just one of the two tables, merge them into one, with each entry pair getting generated by a single macro invocation (at once dropping all explicit casting outside the macro definition). Signed-off-by: Jan Beulich --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -5191,13 +5191,6 @@ static long hvm_physdev_op(int cmd, XEN_ } } -typedef unsigned long hvm_hypercall_t( - unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, - unsigned long); - -#define HYPERCALL(x) \ - [ __HYPERVISOR_ ## x ] = (hvm_hypercall_t *) do_ ## x - static long hvm_grant_table_op_compat32(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) uop, unsigned int count) @@ -5242,35 +5235,34 @@ static long hvm_physdev_op_compat32( } } -static hvm_hypercall_t *const hvm_hypercall64_table[NR_hypercalls] = { - [ __HYPERVISOR_memory_op ] = (hvm_hypercall_t *)hvm_memory_op, - [ __HYPERVISOR_grant_table_op ] = (hvm_hypercall_t *)hvm_grant_table_op, - HYPERCALL(vcpu_op), - [ __HYPERVISOR_physdev_op ] = (hvm_hypercall_t *)hvm_physdev_op, - HYPERCALL(xen_version), - HYPERCALL(console_io), - HYPERCALL(event_channel_op), - HYPERCALL(sched_op), - HYPERCALL(set_timer_op), - HYPERCALL(xsm_op), - HYPERCALL(hvm_op), - HYPERCALL(sysctl), - HYPERCALL(domctl), - HYPERCALL(tmem_op), - HYPERCALL(platform_op), - HYPERCALL(mmuext_op), - HYPERCALL(xenpmu_op), - [ __HYPERVISOR_arch_1 ] = (hvm_hypercall_t *)paging_domctl_continuation -}; - -#define COMPAT_CALL(x) \ - [ __HYPERVISOR_ ## x ] = (hvm_hypercall_t *) compat_ ## x +typedef unsigned long hvm_hypercall_t( + unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, + unsigned long); -static hvm_hypercall_t *const hvm_hypercall32_table[NR_hypercalls] = { - [ __HYPERVISOR_memory_op ] = (hvm_hypercall_t *)hvm_memory_op_compat32, - [ __HYPERVISOR_grant_table_op ] = (hvm_hypercall_t *)hvm_grant_table_op_compat32, +#define HYPERCALL(x) \ + [ __HYPERVISOR_ ## x ] = { (hvm_hypercall_t *) do_ ## x, \ + (hvm_hypercall_t *) do_ ## x } + +#define COMPAT_CALL(x) \ + [ __HYPERVISOR_ ## x ] = { (hvm_hypercall_t *) do_ ## x, \ + (hvm_hypercall_t *) compat_ ## x } + +#define do_memory_op hvm_memory_op +#define compat_memory_op hvm_memory_op_compat32 +#define do_physdev_op hvm_physdev_op +#define compat_physdev_op hvm_physdev_op_compat32 +#define do_grant_table_op hvm_grant_table_op +#define compat_grant_table_op hvm_grant_table_op_compat32 +#define do_arch_1 paging_domctl_continuation + +static const struct { + hvm_hypercall_t *native; + hvm_hypercall_t *compat; +} hypercall_table[NR_hypercalls] = { + COMPAT_CALL(memory_op), + COMPAT_CALL(grant_table_op), COMPAT_CALL(vcpu_op), - [ __HYPERVISOR_physdev_op ] = (hvm_hypercall_t *)hvm_physdev_op_compat32, + COMPAT_CALL(physdev_op), COMPAT_CALL(xen_version), HYPERCALL(console_io), HYPERCALL(event_channel_op), @@ -5284,9 +5276,20 @@ static hvm_hypercall_t *const hvm_hyperc COMPAT_CALL(platform_op), COMPAT_CALL(mmuext_op), HYPERCALL(xenpmu_op), - [ __HYPERVISOR_arch_1 ] = (hvm_hypercall_t *)paging_domctl_continuation + HYPERCALL(arch_1) }; +#undef do_memory_op +#undef compat_memory_op +#undef do_physdev_op +#undef compat_physdev_op +#undef do_grant_table_op +#undef compat_grant_table_op +#undef do_arch_1 + +#undef HYPERCALL +#undef COMPAT_CALL + extern const uint8_t hypercall_args_table[], compat_hypercall_args_table[]; int hvm_do_hypercall(struct cpu_user_regs *regs) @@ -5316,7 +5319,7 @@ int hvm_do_hypercall(struct cpu_user_reg if ( (eax & 0x80000000) && is_viridian_domain(currd) ) return viridian_hypercall(regs); - if ( (eax >= NR_hypercalls) || !hvm_hypercall32_table[eax] ) + if ( (eax >= NR_hypercalls) || !hypercall_table[eax].native ) { regs->eax = -ENOSYS; return HVM_HCALL_completed; @@ -5350,7 +5353,7 @@ int hvm_do_hypercall(struct cpu_user_reg #endif curr->arch.hvm_vcpu.hcall_64bit = 1; - regs->rax = hvm_hypercall64_table[eax](rdi, rsi, rdx, r10, r8, r9); + regs->rax = hypercall_table[eax].native(rdi, rsi, rdx, r10, r8, r9); curr->arch.hvm_vcpu.hcall_64bit = 0; @@ -5395,7 +5398,7 @@ int hvm_do_hypercall(struct cpu_user_reg } #endif - regs->_eax = hvm_hypercall32_table[eax](ebx, ecx, edx, esi, edi, ebp); + regs->_eax = hypercall_table[eax].compat(ebx, ecx, edx, esi, edi, ebp); #ifndef NDEBUG if ( !curr->arch.hvm_vcpu.hcall_preempted ) --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -5191,13 +5191,6 @@ static long hvm_physdev_op(int cmd, XEN_ } } -typedef unsigned long hvm_hypercall_t( - unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, - unsigned long); - -#define HYPERCALL(x) \ - [ __HYPERVISOR_ ## x ] = (hvm_hypercall_t *) do_ ## x - static long hvm_grant_table_op_compat32(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) uop, unsigned int count) @@ -5242,35 +5235,34 @@ static long hvm_physdev_op_compat32( } } -static hvm_hypercall_t *const hvm_hypercall64_table[NR_hypercalls] = { - [ __HYPERVISOR_memory_op ] = (hvm_hypercall_t *)hvm_memory_op, - [ __HYPERVISOR_grant_table_op ] = (hvm_hypercall_t *)hvm_grant_table_op, - HYPERCALL(vcpu_op), - [ __HYPERVISOR_physdev_op ] = (hvm_hypercall_t *)hvm_physdev_op, - HYPERCALL(xen_version), - HYPERCALL(console_io), - HYPERCALL(event_channel_op), - HYPERCALL(sched_op), - HYPERCALL(set_timer_op), - HYPERCALL(xsm_op), - HYPERCALL(hvm_op), - HYPERCALL(sysctl), - HYPERCALL(domctl), - HYPERCALL(tmem_op), - HYPERCALL(platform_op), - HYPERCALL(mmuext_op), - HYPERCALL(xenpmu_op), - [ __HYPERVISOR_arch_1 ] = (hvm_hypercall_t *)paging_domctl_continuation -}; - -#define COMPAT_CALL(x) \ - [ __HYPERVISOR_ ## x ] = (hvm_hypercall_t *) compat_ ## x +typedef unsigned long hvm_hypercall_t( + unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, + unsigned long); -static hvm_hypercall_t *const hvm_hypercall32_table[NR_hypercalls] = { - [ __HYPERVISOR_memory_op ] = (hvm_hypercall_t *)hvm_memory_op_compat32, - [ __HYPERVISOR_grant_table_op ] = (hvm_hypercall_t *)hvm_grant_table_op_compat32, +#define HYPERCALL(x) \ + [ __HYPERVISOR_ ## x ] = { (hvm_hypercall_t *) do_ ## x, \ + (hvm_hypercall_t *) do_ ## x } + +#define COMPAT_CALL(x) \ + [ __HYPERVISOR_ ## x ] = { (hvm_hypercall_t *) do_ ## x, \ + (hvm_hypercall_t *) compat_ ## x } + +#define do_memory_op hvm_memory_op +#define compat_memory_op hvm_memory_op_compat32 +#define do_physdev_op hvm_physdev_op +#define compat_physdev_op hvm_physdev_op_compat32 +#define do_grant_table_op hvm_grant_table_op +#define compat_grant_table_op hvm_grant_table_op_compat32 +#define do_arch_1 paging_domctl_continuation + +static const struct { + hvm_hypercall_t *native; + hvm_hypercall_t *compat; +} hypercall_table[NR_hypercalls] = { + COMPAT_CALL(memory_op), + COMPAT_CALL(grant_table_op), COMPAT_CALL(vcpu_op), - [ __HYPERVISOR_physdev_op ] = (hvm_hypercall_t *)hvm_physdev_op_compat32, + COMPAT_CALL(physdev_op), COMPAT_CALL(xen_version), HYPERCALL(console_io), HYPERCALL(event_channel_op), @@ -5284,9 +5276,20 @@ static hvm_hypercall_t *const hvm_hyperc COMPAT_CALL(platform_op), COMPAT_CALL(mmuext_op), HYPERCALL(xenpmu_op), - [ __HYPERVISOR_arch_1 ] = (hvm_hypercall_t *)paging_domctl_continuation + HYPERCALL(arch_1) }; +#undef do_memory_op +#undef compat_memory_op +#undef do_physdev_op +#undef compat_physdev_op +#undef do_grant_table_op +#undef compat_grant_table_op +#undef do_arch_1 + +#undef HYPERCALL +#undef COMPAT_CALL + extern const uint8_t hypercall_args_table[], compat_hypercall_args_table[]; int hvm_do_hypercall(struct cpu_user_regs *regs) @@ -5316,7 +5319,7 @@ int hvm_do_hypercall(struct cpu_user_reg if ( (eax & 0x80000000) && is_viridian_domain(currd) ) return viridian_hypercall(regs); - if ( (eax >= NR_hypercalls) || !hvm_hypercall32_table[eax] ) + if ( (eax >= NR_hypercalls) || !hypercall_table[eax].native ) { regs->eax = -ENOSYS; return HVM_HCALL_completed; @@ -5350,7 +5353,7 @@ int hvm_do_hypercall(struct cpu_user_reg #endif curr->arch.hvm_vcpu.hcall_64bit = 1; - regs->rax = hvm_hypercall64_table[eax](rdi, rsi, rdx, r10, r8, r9); + regs->rax = hypercall_table[eax].native(rdi, rsi, rdx, r10, r8, r9); curr->arch.hvm_vcpu.hcall_64bit = 0; @@ -5395,7 +5398,7 @@ int hvm_do_hypercall(struct cpu_user_reg } #endif - regs->_eax = hvm_hypercall32_table[eax](ebx, ecx, edx, esi, edi, ebp); + regs->_eax = hypercall_table[eax].compat(ebx, ecx, edx, esi, edi, ebp); #ifndef NDEBUG if ( !curr->arch.hvm_vcpu.hcall_preempted )