From: Dave Hansen <dave.hansen@linux.intel.com> To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Dave Hansen <dave.hansen@linux.intel.com>, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, luto@kernel.org Subject: [RFC][PATCH 5/8] x86/fpu: XSAVE buffer access routine rename Date: Tue, 22 Jun 2021 15:25:04 -0700 [thread overview] Message-ID: <20210622222504.E8874E6D@viggo.jf.intel.com> (raw) In-Reply-To: <20210622222455.E901B5AC@viggo.jf.intel.com> From: Dave Hansen <dave.hansen@linux.intel.com> get_xsave_addr() sounds like it works on generic XSAVE buffers. It does not. It only works on kernel XSAVE buffers which are part of the FPU fpstate. Give it a better name: get_fpstate_addr(). Also add warnings to it in case non-fpstate features are requested (NULL should be returned for these, but WARN() anyway). Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@redhat.com> Cc: Borislav Petkov <bp@alien8.de> Cc: x86@kernel.org Cc: Andy Lutomirski <luto@kernel.org> --- b/arch/x86/include/asm/fpu/xstate.h | 2 +- b/arch/x86/kernel/fpu/xstate.c | 11 ++++++----- b/arch/x86/kvm/x86.c | 8 ++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff -puN arch/x86/include/asm/fpu/xstate.h~get_xsave_addr-warning arch/x86/include/asm/fpu/xstate.h --- a/arch/x86/include/asm/fpu/xstate.h~get_xsave_addr-warning 2021-06-22 14:49:11.268051751 -0700 +++ b/arch/x86/include/asm/fpu/xstate.h 2021-06-22 14:49:11.279051751 -0700 @@ -134,7 +134,7 @@ extern u64 xstate_fx_sw_bytes[USER_XSTAT extern void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask); -void *get_xsave_addr(struct xregs_state *xsave, int xfeature_nr); +void *get_fpstate_addr(struct xregs_state *xsave, int xfeature_nr); int xfeature_size(int xfeature_nr); int copy_uabi_from_kernel_to_xstate(struct xregs_state *xsave, const void *kbuf); int copy_sigframe_from_user_to_xstate(struct xregs_state *xsave, const void __user *ubuf); diff -puN arch/x86/kernel/fpu/xstate.c~get_xsave_addr-warning arch/x86/kernel/fpu/xstate.c --- a/arch/x86/kernel/fpu/xstate.c~get_xsave_addr-warning 2021-06-22 14:49:11.270051751 -0700 +++ b/arch/x86/kernel/fpu/xstate.c 2021-06-22 14:49:11.279051751 -0700 @@ -878,7 +878,8 @@ static void *__raw_xsave_addr(struct xre } /* * Given the xsave area and a state inside, this function returns the - * address of the state. + * address of the state. This only works on kernel fpstate, not on + * generic buffers created with XSAVE*. * * This is the API that is called to get xstate address in either * standard format or compacted format of xsave area. @@ -894,7 +895,7 @@ static void *__raw_xsave_addr(struct xre * address of the state in the xsave area, or NULL if the * field is not present in the xsave buffer. */ -void *get_xsave_addr(struct xregs_state *xsave, int xfeature_nr) +void *get_fpstate_addr(struct xregs_state *xsave, int xfeature_nr) { /* * Do we even *have* xsave state? @@ -906,8 +907,8 @@ void *get_xsave_addr(struct xregs_state * We should not ever be requesting features that we * have not enabled. */ - WARN_ONCE(!(xfeatures_mask_all & BIT_ULL(xfeature_nr)), - "get of unsupported state"); + WARN_ONCE(!(xfeatures_mask_fpstate() & BIT_ULL(xfeature_nr)), + "get of unsupported fpstate"); /* * This assumes the last 'xsave*' instruction to * have requested that 'xfeature_nr' be saved. @@ -924,7 +925,7 @@ void *get_xsave_addr(struct xregs_state return __raw_xsave_addr(xsave, xfeature_nr); } -EXPORT_SYMBOL_GPL(get_xsave_addr); +EXPORT_SYMBOL_GPL(get_fpstate_addr); #ifdef CONFIG_ARCH_HAS_PKEYS diff -puN arch/x86/kvm/x86.c~get_xsave_addr-warning arch/x86/kvm/x86.c --- a/arch/x86/kvm/x86.c~get_xsave_addr-warning 2021-06-22 14:49:11.274051751 -0700 +++ b/arch/x86/kvm/x86.c 2021-06-22 14:49:11.284051751 -0700 @@ -4602,7 +4602,7 @@ static void fill_xsave(u8 *dest, struct memcpy(dest + offset, &vcpu->arch.pkru, sizeof(vcpu->arch.pkru)); } else { - src = get_xsave_addr(xsave, xfeature_nr); + src = get_fpstate_addr(xsave, xfeature_nr); if (src) memcpy(dest + offset, src, size); } @@ -4645,7 +4645,7 @@ static void load_xsave(struct kvm_vcpu * memcpy(&vcpu->arch.pkru, src + offset, sizeof(vcpu->arch.pkru)); } else { - void *dest = get_xsave_addr(xsave, xfeature_nr); + void *dest = get_fpstate_addr(xsave, xfeature_nr); if (dest) memcpy(dest, src + offset, size); @@ -10479,11 +10479,11 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcp */ if (init_event) kvm_put_guest_fpu(vcpu); - mpx_state_buffer = get_xsave_addr(&vcpu->arch.guest_fpu->state.xsave, + mpx_state_buffer = get_fpstate_addr(&vcpu->arch.guest_fpu->state.xsave, XFEATURE_BNDREGS); if (mpx_state_buffer) memset(mpx_state_buffer, 0, sizeof(struct mpx_bndreg_state)); - mpx_state_buffer = get_xsave_addr(&vcpu->arch.guest_fpu->state.xsave, + mpx_state_buffer = get_fpstate_addr(&vcpu->arch.guest_fpu->state.xsave, XFEATURE_BNDCSR); if (mpx_state_buffer) memset(mpx_state_buffer, 0, sizeof(struct mpx_bndcsr)); _
WARNING: multiple messages have this Message-ID (diff)
From: Dave Hansen <dave.hansen@linux.intel.com> To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org,Dave Hansen <dave.hansen@linux.intel.com>,tglx@linutronix.de,mingo@redhat.com,bp@alien8.de,x86@kernel.org,luto@kernel.org Subject: [RFC][PATCH 5/8] x86/fpu: XSAVE buffer access routine rename Date: Tue, 22 Jun 2021 15:25:04 -0700 [thread overview] Message-ID: <20210622222504.E8874E6D@viggo.jf.intel.com> (raw) In-Reply-To: <20210622222455.E901B5AC@viggo.jf.intel.com> From: Dave Hansen <dave.hansen@linux.intel.com> get_xsave_addr() sounds like it works on generic XSAVE buffers. It does not. It only works on kernel XSAVE buffers which are part of the FPU fpstate. Give it a better name: get_fpstate_addr(). Also add warnings to it in case non-fpstate features are requested (NULL should be returned for these, but WARN() anyway). Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@redhat.com> Cc: Borislav Petkov <bp@alien8.de> Cc: x86@kernel.org Cc: Andy Lutomirski <luto@kernel.org> --- b/arch/x86/include/asm/fpu/xstate.h | 2 +- b/arch/x86/kernel/fpu/xstate.c | 11 ++++++----- b/arch/x86/kvm/x86.c | 8 ++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff -puN arch/x86/include/asm/fpu/xstate.h~get_xsave_addr-warning arch/x86/include/asm/fpu/xstate.h --- a/arch/x86/include/asm/fpu/xstate.h~get_xsave_addr-warning 2021-06-22 14:49:11.268051751 -0700 +++ b/arch/x86/include/asm/fpu/xstate.h 2021-06-22 14:49:11.279051751 -0700 @@ -134,7 +134,7 @@ extern u64 xstate_fx_sw_bytes[USER_XSTAT extern void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask); -void *get_xsave_addr(struct xregs_state *xsave, int xfeature_nr); +void *get_fpstate_addr(struct xregs_state *xsave, int xfeature_nr); int xfeature_size(int xfeature_nr); int copy_uabi_from_kernel_to_xstate(struct xregs_state *xsave, const void *kbuf); int copy_sigframe_from_user_to_xstate(struct xregs_state *xsave, const void __user *ubuf); diff -puN arch/x86/kernel/fpu/xstate.c~get_xsave_addr-warning arch/x86/kernel/fpu/xstate.c --- a/arch/x86/kernel/fpu/xstate.c~get_xsave_addr-warning 2021-06-22 14:49:11.270051751 -0700 +++ b/arch/x86/kernel/fpu/xstate.c 2021-06-22 14:49:11.279051751 -0700 @@ -878,7 +878,8 @@ static void *__raw_xsave_addr(struct xre } /* * Given the xsave area and a state inside, this function returns the - * address of the state. + * address of the state. This only works on kernel fpstate, not on + * generic buffers created with XSAVE*. * * This is the API that is called to get xstate address in either * standard format or compacted format of xsave area. @@ -894,7 +895,7 @@ static void *__raw_xsave_addr(struct xre * address of the state in the xsave area, or NULL if the * field is not present in the xsave buffer. */ -void *get_xsave_addr(struct xregs_state *xsave, int xfeature_nr) +void *get_fpstate_addr(struct xregs_state *xsave, int xfeature_nr) { /* * Do we even *have* xsave state? @@ -906,8 +907,8 @@ void *get_xsave_addr(struct xregs_state * We should not ever be requesting features that we * have not enabled. */ - WARN_ONCE(!(xfeatures_mask_all & BIT_ULL(xfeature_nr)), - "get of unsupported state"); + WARN_ONCE(!(xfeatures_mask_fpstate() & BIT_ULL(xfeature_nr)), + "get of unsupported fpstate"); /* * This assumes the last 'xsave*' instruction to * have requested that 'xfeature_nr' be saved. @@ -924,7 +925,7 @@ void *get_xsave_addr(struct xregs_state return __raw_xsave_addr(xsave, xfeature_nr); } -EXPORT_SYMBOL_GPL(get_xsave_addr); +EXPORT_SYMBOL_GPL(get_fpstate_addr); #ifdef CONFIG_ARCH_HAS_PKEYS diff -puN arch/x86/kvm/x86.c~get_xsave_addr-warning arch/x86/kvm/x86.c --- a/arch/x86/kvm/x86.c~get_xsave_addr-warning 2021-06-22 14:49:11.274051751 -0700 +++ b/arch/x86/kvm/x86.c 2021-06-22 14:49:11.284051751 -0700 @@ -4602,7 +4602,7 @@ static void fill_xsave(u8 *dest, struct memcpy(dest + offset, &vcpu->arch.pkru, sizeof(vcpu->arch.pkru)); } else { - src = get_xsave_addr(xsave, xfeature_nr); + src = get_fpstate_addr(xsave, xfeature_nr); if (src) memcpy(dest + offset, src, size); } @@ -4645,7 +4645,7 @@ static void load_xsave(struct kvm_vcpu * memcpy(&vcpu->arch.pkru, src + offset, sizeof(vcpu->arch.pkru)); } else { - void *dest = get_xsave_addr(xsave, xfeature_nr); + void *dest = get_fpstate_addr(xsave, xfeature_nr); if (dest) memcpy(dest, src + offset, size); @@ -10479,11 +10479,11 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcp */ if (init_event) kvm_put_guest_fpu(vcpu); - mpx_state_buffer = get_xsave_addr(&vcpu->arch.guest_fpu->state.xsave, + mpx_state_buffer = get_fpstate_addr(&vcpu->arch.guest_fpu->state.xsave, XFEATURE_BNDREGS); if (mpx_state_buffer) memset(mpx_state_buffer, 0, sizeof(struct mpx_bndreg_state)); - mpx_state_buffer = get_xsave_addr(&vcpu->arch.guest_fpu->state.xsave, + mpx_state_buffer = get_fpstate_addr(&vcpu->arch.guest_fpu->state.xsave, XFEATURE_BNDCSR); if (mpx_state_buffer) memset(mpx_state_buffer, 0, sizeof(struct mpx_bndcsr)); _
next prev parent reply other threads:[~2021-06-22 22:25 UTC|newest] Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-06-22 22:24 [RFC][PATCH 0/8] x86/pkeys: remove PKRU from kernel XSAVE buffer Dave Hansen 2021-06-22 22:24 ` Dave Hansen 2021-06-22 22:24 ` [RFC][PATCH 1/8] x86/pkeys: add PKRU storage outside of task " Dave Hansen 2021-06-22 22:24 ` Dave Hansen 2021-06-22 22:24 ` [RFC][PATCH 2/8] x86/fpu: hook up PKRU into signal user ABIs Dave Hansen 2021-06-22 22:24 ` Dave Hansen 2021-06-22 22:25 ` [RFC][PATCH 3/8] x86/fpu: separate the setup of xfeatures not in fpstate Dave Hansen 2021-06-22 22:25 ` Dave Hansen 2021-06-22 22:25 ` [RFC][PATCH 4/8] x86/fpu: remove PKRU from FPU user state clearing Dave Hansen 2021-06-22 22:25 ` Dave Hansen 2021-06-22 22:25 ` Dave Hansen [this message] 2021-06-22 22:25 ` [RFC][PATCH 5/8] x86/fpu: XSAVE buffer access routine rename Dave Hansen 2021-06-22 22:25 ` [RFC][PATCH 6/8] x86/fpu: update xstate size calculations for non-XSAVE-managed features Dave Hansen 2021-06-22 22:25 ` Dave Hansen 2021-06-22 22:25 ` [RFC][PATCH 7/8] x86/fpu: actually stop using XSAVE on PKRU Dave Hansen 2021-06-22 22:25 ` Dave Hansen 2021-06-22 22:25 ` [RFC][PATCH 8/8] x86/pkeys: remove init_pkru_value variable Dave Hansen 2021-06-22 22:25 ` Dave Hansen
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210622222504.E8874E6D@viggo.jf.intel.com \ --to=dave.hansen@linux.intel.com \ --cc=bp@alien8.de \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mm@kvack.org \ --cc=luto@kernel.org \ --cc=mingo@redhat.com \ --cc=tglx@linutronix.de \ --cc=x86@kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.