Skip to content

Fix DR6/DR7 initialization

Xin Li (Intel) kvm lkml stable 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest2 patches 9 repliesIn review
  2. v32 patches 0 repliesSuperseded
  3. v22 patches 18 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v13 patches16 repliesSuperseded

Changes in v4 from the cover letter

*) Cc stable in the DR7 initialization patch for backporting, just in
case bit 10 of DR7 has become unreserved on new hardware, even though clearing it doesn't currently cause any real issues (Dave Hansen).

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2x86/traps: Initialize DR6 by writing its architectural reset valuearch/x86/include/uapi/asm/debugreg.h arch/x86/kernel/cpu/common.c arch/x86/kernel/traps.c+51 -286 replies
2/2x86/traps: Initialize DR7 by writing its architectural reset valuearch/x86/include/asm/debugreg.h arch/x86/include/asm/kvm_host.h arch/x86/kernel/cpu/common.c +4 more+22 -113 replies

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchSohil MehtaH. Peter Anvin (Intel)Peter Zijlstra (Intel)Sean Christopherson
1/2T-b R-b R-b A-b
2/2T-b R-b R-b A-b A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.

Read the v4 thread

Cover letter [PATCH v4 0/2] Fix DR6/DR7 initialization

Sohil reported seeing a split lock warning when running a test that generates userspace #DB:

x86/split lock detection: #DB: sigtrap_loop_64/4614 took a bus_lock trap at address: 0x4011ae

We investigated the issue and figured out:

1) The warning is a false positive.

2) It is not caused by the test itself.

3) It occurs even when Bus Lock Detection (BLD) is disabled.

4) It only happens on the first #DB on a CPU.

And the root cause is, at boot time, Linux zeros DR6. This leads to different DR6 values depending on whether the CPU supports BLD:

1) On CPUs with BLD support, DR6 becomes 0xFFFF07F0 (bit 11, DR6.BLD, is cleared).

2) On CPUs without BLD, DR6 becomes 0xFFFF0FF0.

Since only BLD-induced #DB exceptions clear DR6.BLD and other debug exceptions leave it unchanged, even if the first #DB is unrelated to BLD, DR6.BLD is still cleared. As a result, such a first #DB is misinterpreted as a BLD #DB, and a false warning is triggerred.

Fix the bug by initializing DR6 by writing its architectural reset value at boot time.

DR7 suffers from a similar issue, apply the same fix.

This patch set is based on tip/x86/urgent branch as of today.

Link to the previous patch set v3:
https://lore.kernel.org/all/[email protected]/

Change in v4:
*) Cc stable in the DR7 initialization patch for backporting, just in
case bit 10 of DR7 has become unreserved on new hardware, even though clearing it doesn't currently cause any real issues (Dave Hansen).

Xin Li (Intel) (2):
x86/traps: Initialize DR6 by writing its architectural reset value x86/traps: Initialize DR7 by writing its architectural reset value

 arch/x86/include/asm/debugreg.h      | 19 ++++++++++++----
 arch/x86/include/asm/kvm_host.h      |  2 +-
 arch/x86/include/uapi/asm/debugreg.h | 21 ++++++++++++++++-
 arch/x86/kernel/cpu/common.c         | 24 ++++++++------------
 arch/x86/kernel/kgdb.c               |  2 +-
 arch/x86/kernel/process_32.c         |  2 +-
 arch/x86/kernel/process_64.c         |  2 +-
 arch/x86/kernel/traps.c              | 34 +++++++++++++++++-----------
 arch/x86/kvm/x86.c                   |  4 ++--
 9 files changed, 72 insertions(+), 38 deletions(-)

base-commit: 2aebf5ee43bf0ed225a09a30cf515d9f2813b759

Signature · 1 line
2.49.0