All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/15] x86/split_lock: Enable #AC exception for split locked accesses
@ 2018-05-14 18:52 Fenghua Yu
  2018-05-14 18:52 ` [PATCH 01/15] x86/split_lock: Add CONFIG and enumerate #AC exception for split locked access feature Fenghua Yu
                   ` (15 more replies)
  0 siblings, 16 replies; 31+ messages in thread
From: Fenghua Yu @ 2018-05-14 18:52 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Ashok Raj,
	Ravi V Shankar, Tony Luck, Dave Hansen, Rafael Wysocki,
	Arjan van de Ven, Alan Cox
  Cc: x86, linux-kernel, Fenghua Yu

When executing an atomic instruction, sometimes the data access crosses
the cache line boundary. This causes performance degradation. Intel
introduces mechanism to detect such split lock issue via alignment check
fault.

Instructions that may cause split lock issue include lock add, lock btc,
xchg, lsl, far call, ltr, etc.

To detect split lock, a new control bit (bit 29) in TEST_CTL MSR 0x33
will be introduced in future x86 processors. When the bit 29 is set,
the processor causes #AC(0) exception for split locked accesses at all
CPL.

BIOS or hardware may set or clear the control bit depending on
platforms. To avoid disturbing BIOS/hardware setting, by default,
kernel keeps split lock BIOS setting.

Kernel can override BIOS setting by explicitly enabling or disabling
the feature using kernel parameters "split_lock_ac=on" or
"split_lock_ac=off".

When an instruction accesses split locked data and triggers #AC
exception, the faulting instruction is handled as follows:
- the faulting instruction is re-executed when the instruction is
  from kernel.
- user process gets SIGBUS signal when the faulting instruction is
  from the user process. This behavior can be changed to re-execute
  the faulting user instruction by sysfs interface
  /sys/kernel/split_lock/user_mode.

We do see #AC exception is triggered and causes system hang in BIOS path
(e.g. during system reboot) after kernel enables the feature. Instead of
debugging potential system hangs due to split locked accesses in various
buggy BIOSes, kernel only maintains enabled feature in the kernel domain.
Once it's out of the kernel domain (i.e. S3, S4, S5, efi runtime
services, kexec, kdump, CPU offline, etc), kernel restores to BIOS
setting. When returning from BIOS, kernel restores to kernel setting.

Since kernel doesn't know when SMI comes, it's impossible for kernel
to disable split lock #AC before entering SMI. So SMI handler may
inherit kernel's split lock setting and kernel tester may end up
debug split lock issues in SMI.

In cases when user does want to detect and fix split lock #AC bang
in BIOS (e.g. in real time), the user can enable split lock #AC
using sysfs interface /sys/kernel/split_lock/bios.

The bit 29 specification in MSR TEST_CTL is published in the latest
Intel Architecture Instruction Set Extensions and Future Features
Programming Reference.

Tests:
- /sys/kernel/split_lock/test_kernel (in patche 14) tests kernel
  space split lock.
- selftest (in patch 15) tests user space split lock.
- perf traces two events exceptions:split_lock_user and exceptions:
  split_lock_kernel.
- S3, S4, S5, CPU hotplug, kexec tests with split lock eanbled.

Fenghua Yu (15):
  x86/split_lock: Add CONFIG and enumerate #AC exception for split
    locked access feature
  x86/split_lock: Set up #AC exception for split locked accesses
  x86/split_lock: Handle #AC exception for split lock in kernel mode
  x86/split_lock: Use non locked bit set instruction in set_cpu_cap
  x86/split_lock: Use non atomic set and clear bit instructions to clear
    cpufeature
  x86/split_lock: Save #AC setting for split lock in BIOS in boot time
    and restore the setting in reboot
  x86/split_lock: Handle suspend/hibernate and resume
  x86/split_lock: Set split lock during EFI runtime service
  x86/split_lock: Explicitly enable or disable #AC for split locked
    accesses
  x86/split_lock: Add a sysfs interface to allow user to enable or
    disable split lock during run time
  x86/split_lock: Add sysfs interface to control user mode behavior
  x86/split_lock: Add sysfs interface to show and control BIOS split
    lock setting
  x86/split_lock: Trace #AC exception for split lock
  x86/split_lock: Add CONFIG and testing sysfs interface
  x86/split_lock: Add split lock user space test in selftest

 Documentation/admin-guide/kernel-parameters.txt    |  11 +
 arch/x86/Kconfig                                   |  22 +
 arch/x86/include/asm/cpu.h                         |  14 +
 arch/x86/include/asm/cpufeature.h                  |   3 +-
 arch/x86/include/asm/efi.h                         |   5 +
 arch/x86/include/asm/msr-index.h                   |   5 +
 arch/x86/include/asm/trace/common.h                |   8 +
 arch/x86/include/asm/trace/exceptions.h            |  21 +-
 arch/x86/kernel/cpu/Makefile                       |   1 +
 arch/x86/kernel/cpu/common.c                       |   3 +
 arch/x86/kernel/cpu/cpuid-deps.c                   |  10 +-
 arch/x86/kernel/cpu/split_lock.c                   | 606 +++++++++++++++++++++
 arch/x86/kernel/traps.c                            |  12 +
 tools/testing/selftests/x86/Makefile               |   3 +-
 tools/testing/selftests/x86/split_lock_user_test.c | 187 +++++++
 15 files changed, 901 insertions(+), 10 deletions(-)
 create mode 100644 arch/x86/kernel/cpu/split_lock.c
 create mode 100644 tools/testing/selftests/x86/split_lock_user_test.c

-- 
2.5.0

^ permalink raw reply	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2018-05-16 21:35 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-14 18:52 [PATCH 0/15] x86/split_lock: Enable #AC exception for split locked accesses Fenghua Yu
2018-05-14 18:52 ` [PATCH 01/15] x86/split_lock: Add CONFIG and enumerate #AC exception for split locked access feature Fenghua Yu
2018-05-15 15:36   ` Dave Hansen
2018-05-15 15:41     ` Fenghua Yu
2018-05-15 15:54       ` Dave Hansen
2018-05-14 18:52 ` [PATCH 02/15] x86/split_lock: Set up #AC exception for split locked accesses Fenghua Yu
2018-05-14 18:52 ` [PATCH 03/15] x86/split_lock: Handle #AC exception for split lock in kernel mode Fenghua Yu
2018-05-15 15:51   ` Dave Hansen
2018-05-15 16:35     ` Luck, Tony
2018-05-15 17:21     ` Fenghua Yu
2018-05-16 16:44       ` Dave Hansen
2018-05-16 21:35         ` Fenghua Yu
2018-05-14 18:52 ` [PATCH 04/15] x86/split_lock: Use non locked bit set instruction in set_cpu_cap Fenghua Yu
2018-05-14 18:52 ` [PATCH 05/15] x86/split_lock: Use non atomic set and clear bit instructions to clear cpufeature Fenghua Yu
2018-05-14 18:52 ` [PATCH 06/15] x86/split_lock: Save #AC setting for split lock in BIOS in boot time and restore the setting in reboot Fenghua Yu
2018-05-14 18:52 ` [PATCH 07/15] x86/split_lock: Handle suspend/hibernate and resume Fenghua Yu
2018-05-14 21:42   ` Rafael J. Wysocki
2018-05-14 18:52 ` [PATCH 08/15] x86/split_lock: Set split lock during EFI runtime service Fenghua Yu
2018-05-14 18:52 ` [PATCH 09/15] x86/split_lock: Explicitly enable or disable #AC for split locked accesses Fenghua Yu
2018-05-15 16:15   ` Dave Hansen
2018-05-15 17:29     ` Fenghua Yu
2018-05-16 16:37       ` Dave Hansen
2018-05-14 18:52 ` [PATCH 10/15] x86/split_lock: Add a sysfs interface to allow user to enable or disable split lock during run time Fenghua Yu
2018-05-14 18:52 ` [PATCH 11/15] x86/split_lock: Add sysfs interface to control user mode behavior Fenghua Yu
2018-05-14 18:52 ` [PATCH 12/15] x86/split_lock: Add sysfs interface to show and control BIOS split lock setting Fenghua Yu
2018-05-14 18:52 ` [PATCH 13/15] x86/split_lock: Trace #AC exception for split lock Fenghua Yu
2018-05-14 18:52 ` [PATCH 14/15] x86/split_lock: Add CONFIG and testing sysfs interface Fenghua Yu
2018-05-14 18:52 ` [PATCH 15/15] x86/split_lock: Add split lock user space test in selftest Fenghua Yu
2018-05-15 15:10 ` [PATCH 0/15] x86/split_lock: Enable #AC exception for split locked accesses Dave Hansen
2018-05-15 16:26   ` Alan Cox
2018-05-15 16:30     ` Dave Hansen

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.