From: "Liang, Kan" <kan.liang@linux.intel.com>
To: Thomas Gleixner <tglx@linutronix.de>,
LKML <linux-kernel@vger.kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>,
Dave Hansen <dave.hansen@linux.intel.com>,
Fenghua Yu <fenghua.yu@intel.com>,
Tony Luck <tony.luck@intel.com>,
Yu-cheng Yu <yu-cheng.yu@intel.com>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Borislav Petkov <bp@suse.de>,
Peter Zijlstra <peterz@infradead.org>
Subject: Re: [patch V2 32/52] x86/fpu/xstate: Sanitize handling of independent features
Date: Wed, 16 Jun 2021 16:04:13 -0400 [thread overview]
Message-ID: <7309d6fa-dd25-ac31-7b05-d88f59d18213@linux.intel.com> (raw)
In-Reply-To: <20210614155356.961460910@linutronix.de>
On 6/14/2021 11:44 AM, Thomas Gleixner wrote:
> The copy functions for the independent features are horribly named and the
> supervisor and independent part is just overengineered.
>
> The point is that the supplied mask has either to be a subset of the
> independent feature or a subset of the task->fpu.xstate managed features.
>
> Rewrite it so it checks check for invalid overlaps of these areas in the
> caller supplied feature mask. Rename it so it follows the new naming
> convention for these operations. Mop up the function documentation.
>
> This allows to use that function for other purposes as well.
>
> Suggested-by: Peter Zijlstra <peterz@infradead.org>
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: Kan Liang <kan.liang@linux.intel.com>
> ---
> arch/x86/events/intel/lbr.c | 6 +-
> arch/x86/include/asm/fpu/xstate.h | 5 +-
> arch/x86/kernel/fpu/xstate.c | 93 +++++++++++++++++++-------------------
> 3 files changed, 53 insertions(+), 51 deletions(-)
>
> --- a/arch/x86/events/intel/lbr.c
> +++ b/arch/x86/events/intel/lbr.c
> @@ -491,7 +491,7 @@ static void intel_pmu_arch_lbr_xrstors(v
> {
> struct x86_perf_task_context_arch_lbr_xsave *task_ctx = ctx;
>
> - copy_kernel_to_independent_supervisor(&task_ctx->xsave, XFEATURE_MASK_LBR);
> + xrstors_from_kernel(&task_ctx->xsave, XFEATURE_MASK_LBR);
> }
>
> static __always_inline bool lbr_is_reset_in_cstate(void *ctx)
> @@ -576,7 +576,7 @@ static void intel_pmu_arch_lbr_xsaves(vo
> {
> struct x86_perf_task_context_arch_lbr_xsave *task_ctx = ctx;
>
> - copy_independent_supervisor_to_kernel(&task_ctx->xsave, XFEATURE_MASK_LBR);
> + xsaves_to_kernel(&task_ctx->xsave, XFEATURE_MASK_LBR);
> }
>
> static void __intel_pmu_lbr_save(void *ctx)
> @@ -992,7 +992,7 @@ static void intel_pmu_arch_lbr_read_xsav
> intel_pmu_store_lbr(cpuc, NULL);
> return;
> }
> - copy_independent_supervisor_to_kernel(&xsave->xsave, XFEATURE_MASK_LBR);
> + xsaves_to_kernel(&xsave->xsave, XFEATURE_MASK_LBR);
>
> intel_pmu_store_lbr(cpuc, xsave->lbr.entries);
> }
I tested the LBR Xsave feature on a Alder Lake machine. It looks good.
However, when I did other CPU hotplug test, it gave me an Oops.
$ sudo bash -c 'echo 0 > /sys/devices/system/cpu/cpu1/online'
$ sudo bash -c 'echo 1 > /sys/devices/system/cpu/cpu1/online'
[ 108.912963] IRQ 132: no longer affine to CPU1
[ 108.913010] IRQ148: set affinity failed(-22).
[ 108.913038] IRQ149: set affinity failed(-22).
[ 108.913050] IRQ150: set affinity failed(-22).
[ 108.917436] smpboot: CPU 1 is now offline
[ 111.191655] x86: Booting SMP configuration:
[ 111.191661] smpboot: Booting Node 0 Processor 1 APIC 0x1
[ 111.200452] BUG: unable to handle page fault for address:
ffffffff996a96a0
[ 111.207312] #PF: supervisor write access in kernel mode
[ 111.207325] #PF: error_code(0x0003) - permissions violation
[ 111.207335] PGD 40a02b067 P4D 40a02b067 PUD 40a02c063 PMD 106bdb063
PTE 8000000409ea9161
[ 111.218116] Oops: 0003 [#1] PREEMPT SMP NOPTI
[ 111.218137] CPU: 1 PID: 0 Comm: swapper/1 Not tainted
5.13.0-rc5-perf+ #123
[ 111.218156] RIP: 0010:fpu__init_cpu_xstate+0x3e/0x130
[ 111.218184] Code: 00 00 00 48 8b 05 02 08 66 01 48 85 c0 0f 84 a7 00
00 00 55 48 89 c6 4889 e5 53 81 e6 00 01 00 00 0f 85 b5 00 00 00 80 e4
fe <48> 89 05 db 07 66 01 9c 58 0f 1f 4400 00 48 89 c3 fa 66 0f 1f 44
[ 111.218195] RSP: 0000:ffffa466401abec0 EFLAGS: 00010002
[ 111.273756] RAX: 0000000000000207 RBX: 0000000000000008 RCX:
0000000000000000
[ 111.273764] RDX: 0000000000310800 RSI: 0000000000000000 RDI:
0000000080050033
[ 111.273772] RBP: ffffa466401abec8 R08: 00000000fffffe00 R09:
ffff98729f686078
[ 111.273778] R10: ffffffff99826000 R11: ffffa466401abdde R12:
0000000000000001
[ 111.273783] R13: 0000000000000000 R14: ffff986f00c20000 R15:
000000000000b000
[ 111.273789] FS: 0000000000000000(0000) GS:ffff98729f680000(0000)
knlGS:0000000000000000
[ 111.273798] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 111.273805] CR2: ffffffff996a96a0 CR3: 000000040a026001 CR4:
0000000000330ea0
[ 111.273813] DR0: 0000000000000000 DR1: 0000000000000000 DR2:
0000000000000000
[ 111.273817] DR3: 0000000000000000 DR6: 00000000ffff07f0 DR7:
0000000000000400
[ 111.273834] invalid opcode: 0000 [#2] PREEMPT SMP NOPTI
[ 111.273843] CPU: 1 PID: 0 Comm: swapper/1 Not tainted
5.13.0-rc5-perf+ #123
Thanks,
Kan
next prev parent reply other threads:[~2021-06-16 20:04 UTC|newest]
Thread overview: 87+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-14 15:44 [patch V2 00/52] x86/fpu: Spring cleaning and PKRU sanitizing Thomas Gleixner
2021-06-14 15:44 ` [patch V2 01/52] x86/fpu: Make init_fpstate correct with optimized XSAVE Thomas Gleixner
2021-06-14 19:15 ` Borislav Petkov
2021-06-14 15:44 ` [patch V2 02/52] x86/fpu: Fix copy_xstate_to_kernel() gap handling Thomas Gleixner
2021-06-15 11:07 ` Borislav Petkov
2021-06-15 12:47 ` Thomas Gleixner
2021-06-15 12:59 ` Borislav Petkov
2021-06-16 22:02 ` Thomas Gleixner
2021-06-14 15:44 ` [patch V2 03/52] x86/pkeys: Revert a5eff7259790 ("x86/pkeys: Add PKRU value to init_fpstate") Thomas Gleixner
2021-06-15 13:15 ` Borislav Petkov
2021-06-14 15:44 ` [patch V2 04/52] x86/fpu: Mark various FPU states __ro_after_init Thomas Gleixner
2021-06-14 15:44 ` [patch V2 05/52] x86/fpu: Remove unused get_xsave_field_ptr() Thomas Gleixner
2021-06-14 15:44 ` [patch V2 06/52] x86/fpu: Move inlines where they belong Thomas Gleixner
2021-06-14 15:44 ` [patch V2 07/52] x86/fpu: Limit xstate copy size in xstateregs_set() Thomas Gleixner
2021-06-14 15:44 ` [patch V2 08/52] x86/fpu: Sanitize xstateregs_set() Thomas Gleixner
2021-06-15 17:40 ` Borislav Petkov
2021-06-15 21:32 ` Thomas Gleixner
2021-06-14 15:44 ` [patch V2 09/52] x86/fpu: Reject invalid MXCSR values in copy_kernel_to_xstate() Thomas Gleixner
2021-06-16 15:02 ` Borislav Petkov
2021-06-16 23:51 ` Thomas Gleixner
2021-06-14 15:44 ` [patch V2 10/52] x86/fpu: Simplify PTRACE_GETREGS code Thomas Gleixner
2021-06-14 15:44 ` [patch V2 11/52] x86/fpu: Rewrite xfpregs_set() Thomas Gleixner
2021-06-16 15:22 ` Borislav Petkov
2021-06-14 15:44 ` [patch V2 12/52] x86/fpu: Fail ptrace() requests that try to set invalid MXCSR values Thomas Gleixner
2021-06-16 15:31 ` Borislav Petkov
2021-06-14 15:44 ` [patch V2 13/52] x86/fpu: Clean up fpregs_set() Thomas Gleixner
2021-06-16 15:42 ` Borislav Petkov
2021-06-14 15:44 ` [patch V2 14/52] x86/fpu: Make copy_xstate_to_kernel() usable for [x]fpregs_get() Thomas Gleixner
2021-06-16 16:13 ` Borislav Petkov
2021-06-17 12:42 ` Thomas Gleixner
2021-06-14 15:44 ` [patch V2 15/52] x86/fpu: Use copy_uabi_xstate_to_membuf() in xfpregs_get() Thomas Gleixner
2021-06-17 8:59 ` Borislav Petkov
2021-06-18 11:19 ` Borislav Petkov
2021-06-18 13:25 ` [PATCH] selftests/x86/ptrace_syscall: Add a PTRACE_GETFPREGS test Borislav Petkov
2021-06-14 15:44 ` [patch V2 16/52] x86/fpu: Use copy_uabi_xstate_to_membuf() in fpregs_get() Thomas Gleixner
2021-06-17 11:50 ` Borislav Petkov
2021-06-17 12:43 ` Thomas Gleixner
2021-06-14 15:44 ` [patch V2 17/52] x86/fpu: Remove fpstate_sanitize_xstate() Thomas Gleixner
2021-06-14 15:44 ` [patch V2 18/52] x86/fpu: Get rid of using_compacted_format() Thomas Gleixner
2021-06-17 11:59 ` Borislav Petkov
2021-06-14 15:44 ` [patch V2 19/52] x86/kvm: Avoid looking up PKRU in XSAVE buffer Thomas Gleixner
2021-06-17 12:09 ` Borislav Petkov
2021-06-14 15:44 ` [patch V2 20/52] x86/fpu: Cleanup arch_set_user_pkey_access() Thomas Gleixner
2021-06-17 12:22 ` Borislav Petkov
2021-06-17 12:49 ` Thomas Gleixner
2021-06-14 15:44 ` [patch V2 21/52] x86/fpu: Get rid of copy_supervisor_to_kernel() Thomas Gleixner
2021-06-17 12:41 ` Borislav Petkov
2021-06-14 15:44 ` [patch V2 22/52] x86/fpu: Rename copy_xregs_to_kernel() and copy_kernel_to_xregs() Thomas Gleixner
2021-06-17 12:48 ` Borislav Petkov
2021-06-14 15:44 ` [patch V2 23/52] x86/fpu: Rename copy_user_to_xregs() and copy_xregs_to_user() Thomas Gleixner
2021-06-14 15:44 ` [patch V2 24/52] x86/fpu: Rename fxregs related copy functions Thomas Gleixner
2021-06-14 15:44 ` [patch V2 25/52] x86/fpu: Rename fregs " Thomas Gleixner
2021-06-14 15:44 ` [patch V2 26/52] x86/fpu: Rename xstate copy functions which are related to UABI Thomas Gleixner
2021-06-14 15:44 ` [patch V2 27/52] x86/fpu: Deduplicate copy_uabi_from_user/kernel_to_xstate() Thomas Gleixner
2021-06-14 15:44 ` [patch V2 28/52] x86/fpu: Rename copy_fpregs_to_fpstate() to save_fpregs_to_fpstate() Thomas Gleixner
2021-06-14 15:44 ` [patch V2 29/52] x86/fpu: Rename copy_kernel_to_fpregs() to restore_fpregs_from_kernel() Thomas Gleixner
2021-06-14 15:44 ` [patch V2 30/52] x86/fpu: Rename initstate copy functions Thomas Gleixner
2021-06-14 15:44 ` [patch V2 31/52] x86/fpu: Rename "dynamic" XSTATEs to "independent" Thomas Gleixner
2021-06-14 15:44 ` [patch V2 32/52] x86/fpu/xstate: Sanitize handling of independent features Thomas Gleixner
2021-06-16 20:04 ` Liang, Kan [this message]
2021-06-17 7:15 ` Thomas Gleixner
2021-06-14 15:44 ` [patch V2 33/52] x86/pkeys: Move read_pkru() and write_pkru() Thomas Gleixner
2021-06-14 15:44 ` [patch V2 34/52] x86/fpu: Differentiate "copy" versus "move" of fpregs Thomas Gleixner
2021-06-18 12:21 ` Thomas Gleixner
2021-06-14 15:44 ` [patch V2 35/52] x86/cpu: Sanitize X86_FEATURE_OSPKE Thomas Gleixner
2021-06-14 15:44 ` [patch V2 36/52] x86/pkru: Provide pkru_get_init_value() Thomas Gleixner
2021-06-14 15:44 ` [patch V2 37/52] x86/pkru: Provide pkru_write_default() Thomas Gleixner
2021-06-14 15:44 ` [patch V2 38/52] x86/cpu: Write the default PKRU value when enabling PKE Thomas Gleixner
2021-06-14 15:44 ` [patch V2 39/52] x86/fpu: Use pkru_write_default() in copy_init_fpstate_to_fpregs() Thomas Gleixner
2021-06-14 15:44 ` [patch V2 40/52] x86/fpu: Rename fpu__clear_all() to fpu_flush_thread() Thomas Gleixner
2021-06-14 15:44 ` [patch V2 41/52] x86/fpu: Clean up the fpu__clear() variants Thomas Gleixner
2021-06-14 15:44 ` [patch V2 42/52] x86/fpu: Rename __fpregs_load_activate() to fpregs_restore_userregs() Thomas Gleixner
2021-06-14 15:44 ` [patch V2 43/52] x86/fpu: Move FXSAVE_LEAK quirk info __copy_kernel_to_fpregs() Thomas Gleixner
2021-06-14 15:44 ` [patch V2 44/52] x86/fpu: Rename xfeatures_mask_user() to xfeatures_mask_uabi() Thomas Gleixner
2021-06-14 15:44 ` [patch V2 45/52] x86/fpu: Dont restore PKRU in fpregs_restore_userspace() Thomas Gleixner
2021-06-16 0:52 ` Yu, Yu-cheng
2021-06-16 8:56 ` Thomas Gleixner
2021-06-14 15:44 ` [patch V2 46/52] x86/fpu: Add PKRU storage outside of task XSAVE buffer Thomas Gleixner
2021-06-14 15:44 ` [patch V2 47/52] x86/fpu: Hook up PKRU into ptrace() Thomas Gleixner
2021-06-14 19:29 ` [patch V2-A " Thomas Gleixner
2021-06-14 15:44 ` [patch V2 48/52] x86/fpu: Mask PKRU from kernel XRSTOR[S] operations Thomas Gleixner
2021-06-14 15:44 ` [patch V2 49/52] x86/fpu: Remove PKRU handling from switch_fpu_finish() Thomas Gleixner
2021-06-14 15:44 ` [patch V2 50/52] x86/fpu: Dont store PKRU in xstate in fpu_reset_fpstate() Thomas Gleixner
2021-06-14 15:44 ` [patch V2 51/52] x86/pkru: Remove xstate fiddling from write_pkru() Thomas Gleixner
2021-06-14 15:45 ` [patch V2 52/52] x86/fpu: Mark init_fpstate __ro_after_init Thomas Gleixner
2021-06-14 20:15 ` [patch] x86/fpu: x86/fpu: Preserve supervisor states in sanitize_restored_user_xstate() Thomas Gleixner
2021-06-16 0:50 ` [patch V2 00/52] x86/fpu: Spring cleaning and PKRU sanitizing Yu, Yu-cheng
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=7309d6fa-dd25-ac31-7b05-d88f59d18213@linux.intel.com \
--to=kan.liang@linux.intel.com \
--cc=bigeasy@linutronix.de \
--cc=bp@suse.de \
--cc=dave.hansen@linux.intel.com \
--cc=fenghua.yu@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=tony.luck@intel.com \
--cc=yu-cheng.yu@intel.com \
/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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).