Skip to contentSkip to conversation

x86: Align incw instruction to avoid split lock

PATCH Applied Junming Liu 2 participants 2 messages Jan 24, 2022 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: Align incw instruction to avoid split lock

A split lock is any atomic operation whose operand crosses two cache lines. Since the operand spans two cache lines and the operation must be atomic, the system locks the bus while the CPU accesses the two cache lines. The bus lock operation is heavy weight and can cause severe performance degradation.

Here's the log when run x86 test cases:

[ 3572.765921] x86/split lock detection: #AC: qemu-system-x86/24383

took a split_lock trap at address: 0x400306

Root caused 'cpu_online_count' spans two cache lines, "lock incw cpu_online_count" instruction causes split lock. 'cpu_online_count' is the type of word(two bytes) and therefore it needs to be aligned to 2 bytes to avoid split lock.

---
 x86/cstart.S   | 1 +
 x86/cstart64.S | 1 +
 2 files changed, 2 insertions(+)
x86/cstart.S +1 -0
index 2c0eec7..6db6a38 100644
@@ -143,6 +143,7 @@ ap_init:
 online_cpus:
 	.fill (max_cpus + 7) / 8, 1, 0
 
+.align 2
 cpu_online_count:	.word 1
 
 .code16
x86/cstart64.S +1 -0
index ff79ae7..7272452 100644
@@ -256,4 +256,5 @@ ap_init:
 	jne 1b
 	ret
 
+.align 2
 cpu_online_count:	.word 1
Signature · 1 line
2.17.1
maintainer Applied
#1 lore raw
Quoted 38 lines · Junming Liu

A split lock is any atomic operation whose operand crosses two cache lines. Since the operand spans two cache lines and the operation must be atomic, the system locks the bus while the CPU accesses the two cache lines. The bus lock operation is heavy weight and can cause severe performance degradation.

Here's the log when run x86 test cases:

[ 3572.765921] x86/split lock detection: #AC: qemu-system-x86/24383

took a split_lock trap at address: 0x400306

Root caused 'cpu_online_count' spans two cache lines, "lock incw cpu_online_count" instruction causes split lock. 'cpu_online_count' is the type of word(two bytes) and therefore it needs to be aligned to 2 bytes to avoid split lock.

---
  x86/cstart.S   | 1 +
  x86/cstart64.S | 1 +
  2 files changed, 2 insertions(+)
x86/cstart.S +1 -0
index 2c0eec7..6db6a38 100644
@@ -143,6 +143,7 @@ ap_init:
  online_cpus:
  	.fill (max_cpus + 7) / 8, 1, 0
 
+.align 2
  cpu_online_count:	.word 1
 
  .code16
x86/cstart64.S +0 -0
index ff79ae7..7272452 100644

x86/cstart64.S ap_init: · line 260

Quoted 5 lines
x86/cstart64.S +1 -0
@@ -256,4 +256,5 @@ ap_init:
  	jne 1b
  	ret
 
+.align 2
  cpu_online_count:	.word 1

Queued, thanks.

Paolo