From patchwork Fri Dec 18 21:09:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Ostrovsky X-Patchwork-Id: 7888331 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 CAB21BEEE5 for ; Fri, 18 Dec 2015 21:11:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BAD132051A for ; Fri, 18 Dec 2015 21:11:31 +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 8E31820380 for ; Fri, 18 Dec 2015 21:11:30 +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 1aA2GO-0004Ae-Np; Fri, 18 Dec 2015 21:08:32 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aA2GN-0004AY-95 for xen-devel@lists.xen.org; Fri, 18 Dec 2015 21:08:31 +0000 Received: from [85.158.139.211] by server-2.bemta-5.messagelabs.com id DB/5F-31450-EC574765; Fri, 18 Dec 2015 21:08:30 +0000 X-Env-Sender: boris.ostrovsky@oracle.com X-Msg-Ref: server-10.tower-206.messagelabs.com!1450472908!11665868!1 X-Originating-IP: [156.151.31.81] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTU2LjE1MS4zMS44MSA9PiAyODgzMzk=\n X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 24009 invoked from network); 18 Dec 2015 21:08:29 -0000 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by server-10.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 18 Dec 2015 21:08:29 -0000 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id tBIL8PD9025285 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 18 Dec 2015 21:08:26 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0021.oracle.com (8.13.8/8.13.8) with ESMTP id tBIL8PrZ023852 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Fri, 18 Dec 2015 21:08:25 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by aserv0122.oracle.com (8.13.8/8.13.8) with ESMTP id tBIL8PPb011681; Fri, 18 Dec 2015 21:08:25 GMT Received: from ovs104.us.oracle.com (/10.149.76.204) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 18 Dec 2015 13:08:25 -0800 From: Boris Ostrovsky To: jbeulich@suse.com, andrew.cooper3@citrix.com Date: Fri, 18 Dec 2015 16:09:20 -0500 Message-Id: <1450472960-5524-1-git-send-email-boris.ostrovsky@oracle.com> X-Mailer: git-send-email 1.7.1 X-Source-IP: aserv0021.oracle.com [141.146.126.233] Cc: Boris Ostrovsky , roger.pau@citrix.com, xen-devel@lists.xen.org Subject: [Xen-devel] [PATCH v4] x86/HVM: Merge HVM and PVH 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: , MIME-Version: 1.0 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 The tables are almost identical and therefore there is little reason to keep both sets. PVH needs 3 extra hypercalls: * mmuext_op. MMUEXT_PIN_L_TABLE are required by control domain (dom0) when building guests. We add MMUEXT_UNPIN_TABLE for completeness. * platform_op. These are only available to privileged domains. We will (eventually) have privileged HVMlite guests and therefore shouldn't limit this to PVH only. * xenpmu_op. any guest with !has_vlapic() (i.e. PV, PVH and HVMlite) should be able to use it. Note that until recently PVH guests used mmuext_op's MMUEXT_INVLPG_MULTI and MMUEXT_TLB_FLUSH_MULTI commands but it has been determined that using the former was incorrect and using the latter is correct for now but is not guaranteed to work in the future. Signed-off-by: Boris Ostrovsky Reviewed-by: Andrew Cooper --- v4: * Bail out of do_mmuext_op() if we are trying to operate on a non-PV domain * Drop if_control_domain() test xen/arch/x86/hvm/hvm.c | 59 +++++--------------------------------- xen/arch/x86/mm.c | 24 ++++++++++++++++ xen/arch/x86/x86_64/compat/mm.c | 4 ++- xen/include/asm-x86/hypercall.h | 9 ++++++ 4 files changed, 44 insertions(+), 52 deletions(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index ed9bbc9..2620055 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -5181,6 +5181,9 @@ static hvm_hypercall_t *const hvm_hypercall64_table[NR_hypercalls] = { 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 }; @@ -5202,48 +5205,8 @@ static hvm_hypercall_t *const hvm_hypercall32_table[NR_hypercalls] = { HYPERCALL(sysctl), HYPERCALL(domctl), HYPERCALL(tmem_op), - [ __HYPERVISOR_arch_1 ] = (hvm_hypercall_t *)paging_domctl_continuation -}; - -static hvm_hypercall_t *const pvh_hypercall64_table[NR_hypercalls] = { - HYPERCALL(platform_op), - HYPERCALL(memory_op), - HYPERCALL(xen_version), - HYPERCALL(console_io), - [ __HYPERVISOR_grant_table_op ] = (hvm_hypercall_t *)hvm_grant_table_op, - HYPERCALL(vcpu_op), - HYPERCALL(mmuext_op), - HYPERCALL(xsm_op), - HYPERCALL(sched_op), - HYPERCALL(event_channel_op), - [ __HYPERVISOR_physdev_op ] = (hvm_hypercall_t *)hvm_physdev_op, - HYPERCALL(hvm_op), - HYPERCALL(sysctl), - HYPERCALL(domctl), - HYPERCALL(xenpmu_op), - [ __HYPERVISOR_arch_1 ] = (hvm_hypercall_t *)paging_domctl_continuation -}; - -extern int compat_mmuext_op(XEN_GUEST_HANDLE_PARAM(void) cmp_uops, - unsigned int count, - XEN_GUEST_HANDLE_PARAM(uint) pdone, - unsigned int foreigndom); -static hvm_hypercall_t *const pvh_hypercall32_table[NR_hypercalls] = { - HYPERCALL(platform_op), - COMPAT_CALL(memory_op), - HYPERCALL(xen_version), - HYPERCALL(console_io), - [ __HYPERVISOR_grant_table_op ] = - (hvm_hypercall_t *)hvm_grant_table_op_compat32, - COMPAT_CALL(vcpu_op), + COMPAT_CALL(platform_op), COMPAT_CALL(mmuext_op), - HYPERCALL(xsm_op), - COMPAT_CALL(sched_op), - HYPERCALL(event_channel_op), - [ __HYPERVISOR_physdev_op ] = (hvm_hypercall_t *)hvm_physdev_op_compat32, - HYPERCALL(hvm_op), - HYPERCALL(sysctl), - HYPERCALL(domctl), HYPERCALL(xenpmu_op), [ __HYPERVISOR_arch_1 ] = (hvm_hypercall_t *)paging_domctl_continuation }; @@ -5277,9 +5240,7 @@ int hvm_do_hypercall(struct cpu_user_regs *regs) if ( (eax & 0x80000000) && is_viridian_domain(currd) ) return viridian_hypercall(regs); - if ( (eax >= NR_hypercalls) || - !(is_pvh_domain(currd) ? pvh_hypercall32_table[eax] - : hvm_hypercall32_table[eax]) ) + if ( (eax >= NR_hypercalls) || !hvm_hypercall32_table[eax] ) { regs->eax = -ENOSYS; return HVM_HCALL_completed; @@ -5313,9 +5274,8 @@ int hvm_do_hypercall(struct cpu_user_regs *regs) #endif curr->arch.hvm_vcpu.hcall_64bit = 1; - regs->rax = (is_pvh_domain(currd) - ? pvh_hypercall64_table - : hvm_hypercall64_table)[eax](rdi, rsi, rdx, r10, r8, r9); + regs->rax = hvm_hypercall64_table[eax](rdi, rsi, rdx, r10, r8, r9); + curr->arch.hvm_vcpu.hcall_64bit = 0; #ifndef NDEBUG @@ -5359,10 +5319,7 @@ int hvm_do_hypercall(struct cpu_user_regs *regs) } #endif - regs->_eax = (is_pvh_vcpu(curr) - ? pvh_hypercall32_table - : hvm_hypercall32_table)[eax](ebx, ecx, edx, - esi, edi, ebp); + regs->_eax = hvm_hypercall32_table[eax](ebx, ecx, edx, esi, edi, ebp); #ifndef NDEBUG if ( !curr->arch.hvm_vcpu.hcall_preempted ) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 7323d9d..3c02f99 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -2997,6 +2997,12 @@ long do_mmuext_op( if ( (pg_owner = get_pg_owner(foreigndom)) == NULL ) return -ESRCH; + if ( !is_pv_domain(pg_owner) ) + { + put_pg_owner(pg_owner); + return -EINVAL; + } + rc = xsm_mmuext_op(XSM_TARGET, d, pg_owner); if ( rc ) { @@ -3019,6 +3025,23 @@ long do_mmuext_op( break; } + if ( has_hvm_container_domain(d) ) + { + switch ( op.cmd ) + { + case MMUEXT_PIN_L1_TABLE: + case MMUEXT_PIN_L2_TABLE: + case MMUEXT_PIN_L3_TABLE: + case MMUEXT_PIN_L4_TABLE: + case MMUEXT_UNPIN_TABLE: + break; + default: + MEM_LOG("Invalid extended pt command %#x", op.cmd); + rc = -EOPNOTSUPP; + goto done; + } + } + okay = 1; switch ( op.cmd ) @@ -3448,6 +3471,7 @@ long do_mmuext_op( break; } + done: if ( unlikely(!okay) && !rc ) rc = -EINVAL; if ( unlikely(rc) ) diff --git a/xen/arch/x86/x86_64/compat/mm.c b/xen/arch/x86/x86_64/compat/mm.c index 178e42d..58be8ad 100644 --- a/xen/arch/x86/x86_64/compat/mm.c +++ b/xen/arch/x86/x86_64/compat/mm.c @@ -215,13 +215,15 @@ int compat_update_va_mapping_otherdomain(unsigned long va, u32 lo, u32 hi, DEFINE_XEN_GUEST_HANDLE(mmuext_op_compat_t); -int compat_mmuext_op(XEN_GUEST_HANDLE_PARAM(mmuext_op_compat_t) cmp_uops, +int compat_mmuext_op(XEN_GUEST_HANDLE_PARAM(void) arg, unsigned int count, XEN_GUEST_HANDLE_PARAM(uint) pdone, unsigned int foreigndom) { unsigned int i, preempt_mask; int rc = 0; + XEN_GUEST_HANDLE_PARAM(mmuext_op_compat_t) cmp_uops = + guest_handle_cast(arg, mmuext_op_compat_t); XEN_GUEST_HANDLE_PARAM(mmuext_op_t) nat_ops; if ( unlikely(count == MMU_UPDATE_PREEMPTED) && diff --git a/xen/include/asm-x86/hypercall.h b/xen/include/asm-x86/hypercall.h index afa8ba9..945d58a 100644 --- a/xen/include/asm-x86/hypercall.h +++ b/xen/include/asm-x86/hypercall.h @@ -110,4 +110,13 @@ extern int arch_compat_vcpu_op( int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg); +extern int compat_mmuext_op( + XEN_GUEST_HANDLE_PARAM(void) arg, + unsigned int count, + XEN_GUEST_HANDLE_PARAM(uint) pdone, + unsigned int foreigndom); + +extern int compat_platform_op( + XEN_GUEST_HANDLE_PARAM(void) u_xenpf_op); + #endif /* __ASM_X86_HYPERCALL_H__ */