From patchwork Wed Sep 7 22:04:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Lai X-Patchwork-Id: 9320123 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 9ACF060752 for ; Wed, 7 Sep 2016 22:04:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6DC3629443 for ; Wed, 7 Sep 2016 22:04:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 628EE29444; Wed, 7 Sep 2016 22:04:08 +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 E4DE429442 for ; Wed, 7 Sep 2016 22:04:07 +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 1bhkv5-0003Sl-Oy; Wed, 07 Sep 2016 22:02:11 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bhkv4-0003S3-5z for xen-devel@lists.xensource.com; Wed, 07 Sep 2016 22:02:10 +0000 Received: from [85.158.139.211] by server-6.bemta-5.messagelabs.com id CC/DB-29022-16E80D75; Wed, 07 Sep 2016 22:02:09 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmplkeJIrShJLcpLzFFi42I5YG6irZvQdyH c4H6bocW9Ke/ZHRg9tvftYg9gjGLNzEvKr0hgzVi08ihTwVb5iuXzbrI3MC6R7GLk5BASqJT4 fOMRK4gtIcArcWTZDCjbV2LFvJmMEDUVEl/+LAayuYDspYwSa38cYoFIlEic2/CfDcRmE1CVW H5uEliDiICixLrV78BqmAXcJL5cfsfexcjBISxgJbHqEdheFqDyq09/g5XwCjhLrNx9lgVir5 zEzXOdzCA2p4CLxKlDC9ggVjlLvL/1k3UCI/8CRoZVjBrFqUVlqUW6RqZ6SUWZ6RkluYmZObq GBqZ6uanFxYnpqTmJScV6yfm5mxiBwVPPwMC4g3FXu98hRkkOJiVRXp/iC+FCfEn5KZUZicUZ 8UWlOanFhxhlODiUJHjn9wLlBItS01Mr0jJzgGEMk5bg4FES4T0JkuYtLkjMLc5Mh0idYlSUE udNB0kIgCQySvPg2mCxc4lRVkqYl5GBgUGIpyC1KDezBFX+FaM4B6OSMO9EkCk8mXklcNNfAS 1mAlosdOo8yOKSRISUVAOj76HZXQqLyxrzfhXPvdW+IV7Z46pWSHCeKdtvBt3sEzv8OX8sfHo g0nN3kiBPybrLvFzC0svCg49mnLgtzRcas7J2TWD13VkXsj7dT+ya6xLoMyVVdfGh/8Eiu2Qj JxQKXwqK9Vt9ITGlO/9o4YQpe+bGeE7z38xzca+v7lyJhHD2hqm70g2UWIozEg21mIuKEwEWl LgCmAIAAA== X-Env-Sender: pclai@intel.com X-Msg-Ref: server-8.tower-206.messagelabs.com!1473285726!58194100!1 X-Originating-IP: [192.55.52.43] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 33578 invoked from network); 7 Sep 2016 22:02:08 -0000 Received: from mga05.intel.com (HELO mga05.intel.com) (192.55.52.43) by server-8.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 7 Sep 2016 22:02:08 -0000 Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP; 07 Sep 2016 15:02:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.30,297,1470726000"; d="scan'208";a="5762275" Received: from scymds01.sc.intel.com ([10.82.194.37]) by fmsmga006.fm.intel.com with ESMTP; 07 Sep 2016 15:02:05 -0700 Received: from pclaidev.sc.intel.com (pclaidev.sc.intel.com [143.183.85.54]) by scymds01.sc.intel.com with ESMTP id u87M25Xe011252; Wed, 7 Sep 2016 15:02:05 -0700 Received: by pclaidev.sc.intel.com (Postfix, from userid 1002) id 2E08120110; Wed, 7 Sep 2016 15:04:26 -0700 (PDT) From: Paul Lai To: xen-devel@lists.xensource.com Date: Wed, 7 Sep 2016 15:04:24 -0700 Message-Id: <1473285866-6868-3-git-send-email-paul.c.lai@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1473285866-6868-1-git-send-email-paul.c.lai@intel.com> References: <1473285866-6868-1-git-send-email-paul.c.lai@intel.com> Cc: ravi.sahita@intel.com, george.dunlap@citrix.com, jbeulich@suse.com Subject: [Xen-devel] [PATCH Altp2m cleanup v4 2/4] altp2m cleanup work 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: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Indent goto labels by one space Inline (header) altp2m functions Define default behavior in switch Define max and min for range of altp2m macroed values Signed-off-by: Paul Lai --- xen/arch/x86/hvm/hvm.c | 46 ++++++++++++++++++++----------------------- xen/include/asm-x86/hvm/hvm.h | 19 +++++++++++++++--- 2 files changed, 37 insertions(+), 28 deletions(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 787f055..e63ef0b 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -1942,11 +1942,11 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned long gla, * Otherwise, this is an error condition. */ rc = fall_through; -out_put_gfn: + out_put_gfn: __put_gfn(p2m, gfn); if ( ap2m_active ) __put_gfn(hostp2m, gfn); -out: + out: /* All of these are delayed until we exit, since we might * sleep on event ring wait queues, and we must not hold * locks in such circumstance */ @@ -5291,12 +5291,25 @@ static int do_altp2m_op( return -EFAULT; if ( a.pad1 || a.pad2 || - (a.version != HVMOP_ALTP2M_INTERFACE_VERSION) || - (a.cmd < HVMOP_altp2m_get_domain_state) || - (a.cmd > HVMOP_altp2m_change_gfn) ) + (a.version != HVMOP_ALTP2M_INTERFACE_VERSION) ) return -EINVAL; - d = (a.cmd != HVMOP_altp2m_vcpu_enable_notify) ? + switch ( a.cmd ) + { + case HVMOP_altp2m_get_domain_state: + case HVMOP_altp2m_set_domain_state: + case HVMOP_altp2m_vcpu_enable_notify: + case HVMOP_altp2m_create_p2m: + case HVMOP_altp2m_destroy_p2m: + case HVMOP_altp2m_switch_p2m: + case HVMOP_altp2m_set_mem_access: + case HVMOP_altp2m_change_gfn: + break; + default: + return -ENOSYS; + } + + d = ( a.cmd != HVMOP_altp2m_vcpu_enable_notify ) ? rcu_lock_domain_by_any_id(a.domain) : rcu_lock_current_domain(); if ( d == NULL ) @@ -5413,6 +5426,8 @@ static int do_altp2m_op( rc = p2m_change_altp2m_gfn(d, a.u.change_gfn.view, _gfn(a.u.change_gfn.old_gfn), _gfn(a.u.change_gfn.new_gfn)); + default: + ASSERT_UNREACHABLE(); } out: @@ -5937,25 +5952,6 @@ void hvm_toggle_singlestep(struct vcpu *v) v->arch.hvm_vcpu.single_step = !v->arch.hvm_vcpu.single_step; } -void altp2m_vcpu_update_p2m(struct vcpu *v) -{ - if ( hvm_funcs.altp2m_vcpu_update_p2m ) - hvm_funcs.altp2m_vcpu_update_p2m(v); -} - -void altp2m_vcpu_update_vmfunc_ve(struct vcpu *v) -{ - if ( hvm_funcs.altp2m_vcpu_update_vmfunc_ve ) - hvm_funcs.altp2m_vcpu_update_vmfunc_ve(v); -} - -bool_t altp2m_vcpu_emulate_ve(struct vcpu *v) -{ - if ( hvm_funcs.altp2m_vcpu_emulate_ve ) - return hvm_funcs.altp2m_vcpu_emulate_ve(v); - return 0; -} - int hvm_set_mode(struct vcpu *v, int mode) { diff --git a/xen/include/asm-x86/hvm/hvm.h b/xen/include/asm-x86/hvm/hvm.h index 81b60d5..ed043b2 100644 --- a/xen/include/asm-x86/hvm/hvm.h +++ b/xen/include/asm-x86/hvm/hvm.h @@ -599,13 +599,26 @@ static inline bool_t hvm_altp2m_supported(void) } /* updates the current hardware p2m */ -void altp2m_vcpu_update_p2m(struct vcpu *v); +static inline void altp2m_vcpu_update_p2m(struct vcpu *v) +{ + if ( hvm_funcs.altp2m_vcpu_update_p2m ) + hvm_funcs.altp2m_vcpu_update_p2m(v); +} /* updates VMCS fields related to VMFUNC and #VE */ -void altp2m_vcpu_update_vmfunc_ve(struct vcpu *v); +static inline void altp2m_vcpu_update_vmfunc_ve(struct vcpu *v) +{ + if ( hvm_funcs.altp2m_vcpu_update_vmfunc_ve ) + hvm_funcs.altp2m_vcpu_update_vmfunc_ve(v); +} /* emulates #VE */ -bool_t altp2m_vcpu_emulate_ve(struct vcpu *v); +static inline bool_t altp2m_vcpu_emulate_ve(struct vcpu *v) +{ + if ( hvm_funcs.altp2m_vcpu_emulate_ve ) + return hvm_funcs.altp2m_vcpu_emulate_ve(v); + return false; +} /* Check CR4/EFER values */ const char *hvm_efer_valid(const struct vcpu *v, uint64_t value,