From: Andrew Cooper Subject: [PATCH] x86/xsave: Expose xsave_cntxt_size to avoid reloading xcr0 Date: Wed, 4 Jun 2014 12:56:42 +0100 Message-ID: <1401883002-5481-1-git-send-email-andrew.cooper3@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Xen-devel Cc: Andrew Cooper , Keir Fraser , Jan Beulich List-Id: xen-devel@lists.xenproject.org xstate_ctxt_size(xfeature_mask) is runtime constant after boot. There is no need to reload xcr0 twice for this basic bounds check. Also annotate xfeature_mask as __read_mostly as it is only ever written once. Signed-off-by: Andrew Cooper CC: Keir Fraser CC: Jan Beulich --- xen/arch/x86/domctl.c | 3 +-- xen/arch/x86/xstate.c | 4 ++-- xen/include/asm-x86/xstate.h | 1 + 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c index 8f5b287..75b0522 100644 --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -1145,8 +1145,7 @@ long arch_do_domctl( ret = -EINVAL; if ( evc->size < 2 * sizeof(uint64_t) || - evc->size > 2 * sizeof(uint64_t) + - xstate_ctxt_size(xfeature_mask) ) + evc->size > 2 * sizeof(uint64_t) + xsave_cntxt_size ) goto vcpuextstate_out; receive_buf = xmalloc_bytes(evc->size); diff --git a/xen/arch/x86/xstate.c b/xen/arch/x86/xstate.c index e202344..86ea244 100644 --- a/xen/arch/x86/xstate.c +++ b/xen/arch/x86/xstate.c @@ -21,10 +21,10 @@ bool_t __read_mostly cpu_has_xsaveopt; * the supported and enabled features on the processor, including the * XSAVE.HEADER. We only enable XCNTXT_MASK that we have known. */ -static u32 __read_mostly xsave_cntxt_size; +u32 __read_mostly xsave_cntxt_size; /* A 64-bit bitmask of the XSAVE/XRSTOR features supported by processor. */ -u64 xfeature_mask; +u64 __read_mostly xfeature_mask; /* Cached xcr0 for fast read */ static DEFINE_PER_CPU(uint64_t, xcr0); diff --git a/xen/include/asm-x86/xstate.h b/xen/include/asm-x86/xstate.h index 8d21349..e0abeef 100644 --- a/xen/include/asm-x86/xstate.h +++ b/xen/include/asm-x86/xstate.h @@ -39,6 +39,7 @@ #define XSTATE_NONLAZY (XSTATE_LWP | XSTATE_BNDREGS | XSTATE_BNDCSR) #define XSTATE_LAZY (XSTATE_ALL & ~XSTATE_NONLAZY) +extern u32 xsave_cntxt_size; extern u64 xfeature_mask; /* extended state save area */ -- 1.7.10.4