From patchwork Mon Sep 26 17:52:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Lai X-Patchwork-Id: 9351101 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 D603C6077B for ; Mon, 26 Sep 2016 17:52:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C659328159 for ; Mon, 26 Sep 2016 17:52:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B7A4528A17; Mon, 26 Sep 2016 17:52:22 +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 3D84228A27 for ; Mon, 26 Sep 2016 17:52:22 +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 1boa2Q-0004j1-4g; Mon, 26 Sep 2016 17:49:58 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1boa2O-0004ic-RT for xen-devel@lists.xensource.com; Mon, 26 Sep 2016 17:49:56 +0000 Received: from [85.158.137.68] by server-12.bemta-3.messagelabs.com id 7C/D5-09160-4CF59E75; Mon, 26 Sep 2016 17:49:56 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmplkeJIrShJLcpLzFFi42Jpa+uQ0D0U/zL cYPpTNYt7U96zOzB6bO/bxR7AGMWamZeUX5HAmvHk5hymghnqFfte/WdvYLwi38XIySEkUCFx b+NsNhBbQoBX4siyGawQdoDE5UOnmGBqFh66w9jFyAVkL2OUWHBkHhtEokTi/pQmFhCbTUBVY vm5SYwgtoiAosS61e/A4swCbhJfLr9jB7GFBcwlTsxrAFvAAlR/4/AiZhCbV8BFYuXdq+wQi+ Ukbp7rBItzCrhK7Ji+E+oIF4mOjl3sExj5FzAyrGJUL04tKkst0jXVSyrKTM8oyU3MzNE1NDD Wy00tLk5MT81JTCrWS87P3cQIDJ56BgbGHYyXvzodYpTkYFIS5RX0fxkuxJeUn1KZkVicEV9U mpNafIhRhoNDSYI3MQ4oJ1iUmp5akZaZAwxjmLQEB4+SCO8SkDRvcUFibnFmOkTqFKOilDhvC EhCACSRUZoH1waLnUuMslLCvIwMDAxCPAWpRbmZJajyrxjFORiVhHmNQabwZOaVwE1/BbSYCW jx0hMvQBaXJCKkpBoYs8wXz/uzhCuzIKJILqjX9e4Xvw2PozOmf3ng4jTjr9/s80e/nzxwUve ae5rvnuSdlVH+h47ucLkw5VvbxtSA/3MO9H1h5jt3bF+S9MSOwFUXa1ZueuzMvCk5XZbPed2D SU8e8C9xYil2+e3xUva8wwGB7IYFWmwTrcu7Wf65HXrxIaNepzf+ihJLcUaioRZzUXEiAMTRu yKYAgAA X-Env-Sender: pclai@intel.com X-Msg-Ref: server-7.tower-31.messagelabs.com!1474912192!55205651!1 X-Originating-IP: [134.134.136.24] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTM0LjEzNC4xMzYuMjQgPT4gMzkwOTcx\n X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 44464 invoked from network); 26 Sep 2016 17:49:54 -0000 Received: from mga09.intel.com (HELO mga09.intel.com) (134.134.136.24) by server-7.tower-31.messagelabs.com with DHE-RSA-CAMELLIA256-SHA encrypted SMTP; 26 Sep 2016 17:49:54 -0000 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP; 26 Sep 2016 10:49:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.30,400,1470726000"; d="scan'208"; a="1036729241" Received: from scymds02.sc.intel.com ([10.82.195.37]) by orsmga001.jf.intel.com with ESMTP; 26 Sep 2016 10:49:51 -0700 Received: from pclaidev.sc.intel.com (pclaidev.sc.intel.com [143.183.85.56]) by scymds02.sc.intel.com with ESMTP id u8QHnpf7016592; Mon, 26 Sep 2016 10:49:51 -0700 Received: by pclaidev.sc.intel.com (Postfix, from userid 1002) id 5867F201ED; Mon, 26 Sep 2016 10:52:06 -0700 (PDT) From: Paul Lai To: xen-devel@lists.xensource.com Date: Mon, 26 Sep 2016 10:52:06 -0700 Message-Id: <1474912326-16045-2-git-send-email-paul.c.lai@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1474912326-16045-1-git-send-email-paul.c.lai@intel.com> References: <1474912326-16045-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 v6] 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. In do_altp2m_op(), during the sanity check of the passed command, return -ENONSYS if not a valid command. In do_altp2m_op(), when evaluating a command, ASSERT_UNREACHABLE() if the command is not recognizable. The sanity check above should have triggered the return of -ENOSYS. Changes since last version: Fixing fall through in switch statement above ASSERT_UNREACHABLE() (in do_altp2m_op()). Make hvm_funcs.altp2m_supported "bool" instead of "bool_t". Make hvm_altp2m_supported() and altp2m_vcpu_emulate_ve() return bool (rather than return void()). Signed-off-by: Paul Lai Acked-by: Jan Beulich --- xen/arch/x86/hvm/hvm.c | 47 ++++++++++++++++++++----------------------- xen/include/asm-x86/hvm/hvm.h | 26 +++++++++++++++++++----- 2 files changed, 43 insertions(+), 30 deletions(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 7bad845..3a4ea56 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -1959,11 +1959,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 */ @@ -5308,12 +5308,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 ) @@ -5430,6 +5443,9 @@ 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)); + break; + default: + ASSERT_UNREACHABLE(); } out: @@ -5954,25 +5970,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..b1be6bd 100644 --- a/xen/include/asm-x86/hvm/hvm.h +++ b/xen/include/asm-x86/hvm/hvm.h @@ -100,7 +100,7 @@ struct hvm_function_table { bool_t pvh_supported; /* Necessary hardware support for alternate p2m's? */ - bool_t altp2m_supported; + bool altp2m_supported; /* Indicate HAP capabilities. */ unsigned int hap_capabilities; @@ -593,19 +593,35 @@ static inline bool_t hvm_is_singlestep_supported(void) } /* returns true if hardware supports alternate p2m's */ -static inline bool_t hvm_altp2m_supported(void) +static inline bool hvm_altp2m_supported(void) { return hvm_funcs.altp2m_supported; } /* 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 altp2m_vcpu_emulate_ve(struct vcpu *v) +{ + if ( hvm_funcs.altp2m_vcpu_emulate_ve ) + { + hvm_funcs.altp2m_vcpu_emulate_ve(v); + return true; + } + return false; +} /* Check CR4/EFER values */ const char *hvm_efer_valid(const struct vcpu *v, uint64_t value,