mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kai Huang <kai.huang@intel.com>
To: tglx@kernel.org, mingo@redhat.com, peterz@infradead.org,
	bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com,
	seanjc@google.com, pbonzini@redhat.com
Cc: x86@kernel.org, darwi@linutronix.de, david.kaplan@amd.com,
	kees@kernel.org, linux-kernel@vger.kernel.org,
	Kai Huang <kai.huang@intel.com>
Subject: [PATCH] x86/cpu: Align the vmx_capability array to size of unsigned long
Date: Mon, 23 Mar 2026 21:25:27 +1300	[thread overview]
Message-ID: <20260323082527.732899-1-kai.huang@intel.com> (raw)

A WARNING splat was triggered during system boot with a kernel built
with CONFIG_DEBUG_ATOMIC=y and CONFIG_DEBUG_ATOMIC_LARGEST_ALIGN=y on
one Intel platform:

  systemd[1]: DMI BIOS Extension table does not indicate virtualization.
  ------------[ cut here ]------------
  (unsigned long)v & mask
  WARNING: ./include/linux/instrumented.h:67 at show_cpuinfo+0x4e9/0x620, CPU#133: systemd/1
  ...
  RIP: 0010:show_cpuinfo+0x4e9/0x620
  ...
  Call Trace:
   <TASK>
   seq_read_iter+0x130/0x4b0
   ? rw_verify_area+0x15b/0x200
   vfs_read+0x224/0x350
   ksys_read+0x61/0xd0
   do_syscall_64+0x12c/0x1510

show_cpuinfo() calls test_bit() for each bit in the cpuinfo_x86's
vmx_capability array to print the supported VMX feature names in
/proc/cpuinfo.

Per Documentation/atomic_bitops.txt, test_bit() is an atomic bitops, and
it requires the provided address to be aligned to size of unsigned long.
Commit 80047d84eed2 ("atomic: add alignment check to instrumented atomic
operations") added the WARN() if the alignment check fails.

The vmx_capability is an array of type __u32 thus it's only naturally
aligned to 4-bytes, causing the above WARNING splat.

On x86, it is necessary to ensure the "true" atomic bitops only operate
on the address that is aligned to unsigned long, otherwise the atomic
instruction may end up crossing cacheline boundary, causing a full bus
lock.  If the kernel has enabled split lock detection, a full bus lock
can cause #AC split lock exception, resulting in kernel panic.

The cpuinfo_x86's x86_capability array once was only aligned to __u32
too.  The commit db8c33f8b5be ("x86/cpu: Align the x86_capability array
to size of unsigned long") changed the alignment for x86_capability in
order to support split lock detection in the kernel.

However, this particular WARNING splat caused by test_bit() is more like
a false positive, since test_bit() is a non-RMW operation and x86
implements it using BT (bit test) instruction, which can never be used
with LOCK prefix.  Except for the test_bit(), there's no other atomic
bitops is used to access vmx_capability array.

But it's still better to get rid of the WARNING.  For simplicity, align
the vmx_capability array to size of unsigned long, following the change
to x86_capability.

Note:

Commit 80047d84eed2 ("atomic: add alignment check to instrumented atomic
operations") was merged later than the vmx_capability was added.  And
there's no real harm here, hence no 'Fixes' tag.

Signed-off-by: Kai Huang <kai.huang@intel.com>
---
 arch/x86/include/asm/processor.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 10b5355b323e..7ef10f638161 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -150,7 +150,11 @@ struct cpuinfo_x86 {
 	int			x86_tlbsize;
 #endif
 #ifdef CONFIG_X86_VMX_FEATURE_NAMES
-	__u32			vmx_capability[NVMXINTS];
+	/* See the comment of 'x86_capability_alignment' below */
+	union {
+		__u32		vmx_capability[NVMXINTS];
+		unsigned long	vmx_capability_alignment;
+	};
 #endif
 	__u8			x86_virt_bits;
 	__u8			x86_phys_bits;

base-commit: fde794883717fd67a5521fa69881afd8c8979764
-- 
2.53.0


                 reply	other threads:[~2026-03-23  8:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260323082527.732899-1-kai.huang@intel.com \
    --to=kai.huang@intel.com \
    --cc=bp@alien8.de \
    --cc=darwi@linutronix.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=david.kaplan@amd.com \
    --cc=hpa@zytor.com \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    --cc=seanjc@google.com \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    /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

all inboxes | Powered by JetHome®