From patchwork Tue Jun 22 22:25:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Hansen X-Patchwork-Id: 12338687 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66346C49EA7 for ; Tue, 22 Jun 2021 22:25:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1A23F61026 for ; Tue, 22 Jun 2021 22:25:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1A23F61026 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D8E236B0072; Tue, 22 Jun 2021 18:25:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D63FC6B0074; Tue, 22 Jun 2021 18:25:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BDD576B0075; Tue, 22 Jun 2021 18:25:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0117.hostedemail.com [216.40.44.117]) by kanga.kvack.org (Postfix) with ESMTP id 834516B0072 for ; Tue, 22 Jun 2021 18:25:51 -0400 (EDT) Received: from smtpin37.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id BC27922AA1 for ; Tue, 22 Jun 2021 22:25:51 +0000 (UTC) X-FDA: 78282793302.37.51417DA Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by imf13.hostedemail.com (Postfix) with ESMTP id 307A5E000249 for ; Tue, 22 Jun 2021 22:25:50 +0000 (UTC) IronPort-SDR: V1C0CV/7SuVUYrp4lpyn8OinuYQ2d5YV3Ib91phL17ovqYk0zvZZNoHDOhIWx/OLMhvZZKh4EB vZ7V91f9IDGw== X-IronPort-AV: E=McAfee;i="6200,9189,10023"; a="205326084" X-IronPort-AV: E=Sophos;i="5.83,292,1616482800"; d="scan'208";a="205326084" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2021 15:25:49 -0700 IronPort-SDR: JbEyR7KJ/ldBklaL0PzCOkqiGNzYB5CUx4zRF5B5cbrxvRjFKnHGlLv6Pr0+9J0jlrj51QaGC6 RosnMYr0Z0XA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,292,1616482800"; d="scan'208";a="555930353" Received: from viggo.jf.intel.com (HELO localhost.localdomain) ([10.54.77.144]) by orsmga004.jf.intel.com with ESMTP; 22 Jun 2021 15:25:49 -0700 Subject: [RFC][PATCH 5/8] x86/fpu: XSAVE buffer access routine rename To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org,Dave Hansen ,tglx@linutronix.de,mingo@redhat.com,bp@alien8.de,x86@kernel.org,luto@kernel.org From: Dave Hansen Date: Tue, 22 Jun 2021 15:25:04 -0700 References: <20210622222455.E901B5AC@viggo.jf.intel.com> In-Reply-To: <20210622222455.E901B5AC@viggo.jf.intel.com> Message-Id: <20210622222504.E8874E6D@viggo.jf.intel.com> Authentication-Results: imf13.hostedemail.com; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=intel.com (policy=none); spf=none (imf13.hostedemail.com: domain of dave.hansen@linux.intel.com has no SPF policy when checking 192.55.52.120) smtp.mailfrom=dave.hansen@linux.intel.com X-Stat-Signature: okirxx8z65n4h83fwjh9fwqk4ytr7wgg X-Rspamd-Queue-Id: 307A5E000249 X-Rspamd-Server: rspam06 X-HE-Tag: 1624400750-960070 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Dave Hansen 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 Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: x86@kernel.org Cc: Andy Lutomirski --- 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));