[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZAx6Egh6U5SCZEby@zn.tnic>
Date: Sat, 11 Mar 2023 13:54:42 +0100
From: Borislav Petkov <bp@...en8.de>
To: Rick Edgecombe <rick.p.edgecombe@...el.com>
Cc: x86@...nel.org, "H . Peter Anvin" <hpa@...or.com>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, linux-kernel@...r.kernel.org,
linux-doc@...r.kernel.org, linux-mm@...ck.org,
linux-arch@...r.kernel.org, linux-api@...r.kernel.org,
Arnd Bergmann <arnd@...db.de>,
Andy Lutomirski <luto@...nel.org>,
Balbir Singh <bsingharora@...il.com>,
Cyrill Gorcunov <gorcunov@...il.com>,
Dave Hansen <dave.hansen@...ux.intel.com>,
Eugene Syromiatnikov <esyr@...hat.com>,
Florian Weimer <fweimer@...hat.com>,
"H . J . Lu" <hjl.tools@...il.com>, Jann Horn <jannh@...gle.com>,
Jonathan Corbet <corbet@....net>,
Kees Cook <keescook@...omium.org>,
Mike Kravetz <mike.kravetz@...cle.com>,
Nadav Amit <nadav.amit@...il.com>,
Oleg Nesterov <oleg@...hat.com>, Pavel Machek <pavel@....cz>,
Peter Zijlstra <peterz@...radead.org>,
Randy Dunlap <rdunlap@...radead.org>,
Weijiang Yang <weijiang.yang@...el.com>,
"Kirill A . Shutemov" <kirill.shutemov@...ux.intel.com>,
John Allen <john.allen@....com>, kcc@...gle.com,
eranian@...gle.com, rppt@...nel.org, jamorris@...ux.microsoft.com,
dethoma@...rosoft.com, akpm@...ux-foundation.org,
Andrew.Cooper3@...rix.com, christina.schimpe@...el.com,
david@...hat.com, debug@...osinc.com
Subject: Re: [PATCH v7 38/41] x86/fpu: Add helper for initing features
On Mon, Feb 27, 2023 at 02:29:54PM -0800, Rick Edgecombe wrote:
> Subject: Re: [PATCH v7 38/41] x86/fpu: Add helper for initing features
"initializing"
> If an xfeature is saved in a buffer, the xfeature's bit will be set in
> xsave->header.xfeatures. The CPU may opt to not save the xfeature if it
> is in it's init state. In this case the xfeature buffer address cannot
"its"
> be retrieved with get_xsave_addr().
>
> Future patches will need to handle the case of writing to an xfeature
> that may not be saved. So provide helpers to init an xfeature in an
> xsave buffer.
>
> This could of course be done directly by reaching into the xsave buffer,
> however this would not be robust against future changes to optimize the
> xsave buffer by compacting it. In that case the xsave buffer would need
> to be re-arranged as well. So the logic properly belongs encapsulated
> in a helper where the logic can be unified.
>
> Tested-by: Pengfei Xu <pengfei.xu@...el.com>
> Tested-by: John Allen <john.allen@....com>
> Tested-by: Kees Cook <keescook@...omium.org>
> Acked-by: Mike Rapoport (IBM) <rppt@...nel.org>
> Reviewed-by: Kees Cook <keescook@...omium.org>
> Signed-off-by: Rick Edgecombe <rick.p.edgecombe@...el.com>
>
> ---
> v2:
> - New patch
> ---
> arch/x86/kernel/fpu/xstate.c | 58 +++++++++++++++++++++++++++++-------
> arch/x86/kernel/fpu/xstate.h | 6 ++++
> 2 files changed, 53 insertions(+), 11 deletions(-)
>
> diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
> index 13a80521dd51..3ff80be0a441 100644
> --- a/arch/x86/kernel/fpu/xstate.c
> +++ b/arch/x86/kernel/fpu/xstate.c
> @@ -934,6 +934,24 @@ static void *__raw_xsave_addr(struct xregs_state *xsave, int xfeature_nr)
> return (void *)xsave + xfeature_get_offset(xcomp_bv, xfeature_nr);
> }
>
> +static int xsave_buffer_access_checks(int xfeature_nr)
Function name needs a verb.
> +{
> + /*
> + * Do we even *have* xsave state?
> + */
That comment is superfluous.
> + if (!boot_cpu_has(X86_FEATURE_XSAVE))
check_for_deprecated_apis: WARNING: arch/x86/kernel/fpu/xstate.c:942: Do not use boot_cpu_has() - use cpu_feature_enabled() instead.
> + return 1;
> +
> + /*
> + * We should not ever be requesting features that we
Please use passive voice in your commit message: no "we" or "I", etc,
and describe your changes in imperative mood.
> + * have not enabled.
> + */
> + if (WARN_ON_ONCE(!xfeature_enabled(xfeature_nr)))
> + return 1;
> +
> + return 0;
> +}
> +
> /*
> * Given the xsave area and a state inside, this function returns the
> * address of the state.
> @@ -954,17 +972,7 @@ static void *__raw_xsave_addr(struct xregs_state *xsave, int xfeature_nr)
> */
> void *get_xsave_addr(struct xregs_state *xsave, int xfeature_nr)
> {
> - /*
> - * Do we even *have* xsave state?
> - */
> - if (!boot_cpu_has(X86_FEATURE_XSAVE))
> - return NULL;
> -
> - /*
> - * We should not ever be requesting features that we
> - * have not enabled.
> - */
> - if (WARN_ON_ONCE(!xfeature_enabled(xfeature_nr)))
> + if (xsave_buffer_access_checks(xfeature_nr))
> return NULL;
>
> /*
> @@ -984,6 +992,34 @@ void *get_xsave_addr(struct xregs_state *xsave, int xfeature_nr)
> return __raw_xsave_addr(xsave, xfeature_nr);
> }
>
> +/*
> + * Given the xsave area and a state inside, this function
> + * initializes an xfeature in the buffer.
s/this function initializes/initialize/
> + *
> + * get_xsave_addr() will return NULL if the feature bit is
> + * not present in the header. This function will make it so
> + * the xfeature buffer address is ready to be retrieved by
> + * get_xsave_addr().
So users of get_xsave_addr() would have to know that they would need to
call init_xfeature()?
I think the better approach would be:
void *get_xsave_addr(struct xregs_state *xsave, int xfeature_nr, bool init)
and then that @init controls whether get_xsave_addr() should init the
buffer.
And then you don't have to have a bunch of small functions here and
there and know when to call what but get_xsave_addr() would simply DTRT.
Thx.
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
Powered by blists - more mailing lists