Re: [PATCH 5.15 00/78] 5.15.55-rc1 review

From: Linus Torvalds
Date: Wed Jul 13 2022 - 14:33:47 EST

On Wed, Jul 13, 2022 at 6:34 AM Guenter Roeck <linux@xxxxxxxxxxxx> wrote:
> Looking into the log, I don't think that message is related to the crash.
> ...
> [ 105.653777] Modules linked in: x86_pkg_temp_thermal
> [ 105.902123] ---[ end trace cec99cae36bcbfd7 ]---
> [ 105.902124] RIP: 0010:xaddw_ax_dx+0x9/0x10 <--- crash
> [ 105.902126] Code: 00 0f bb d0 c3 cc cc cc cc 48 0f bb d0 c3 cc cc

Yeah, the code you snipped, shows

20: 66 0f c1 d0 xadd %dx,%ax
24: c3 ret
25: cc int3
26: cc int3
27: cc int3
28: cc int3
29:* 0f 1f 80 00 00 00 00 nopl 0x0(%rax) <-- trapping instruction
30: 0f c1 d0 xadd %edx,%eax
33: c3 ret
34: cc int3
35: cc int3
36: cc int3
37: cc int3
38: 48 0f c1 d0 xadd %rdx,%rax
3c: c3 ret
3d: cc int3

and that's a bit odd.

It says "xaddw_ax_dx+0x9/0x10", but I think somebody jumped to
"xaddw_ax_dx+8", hit the 'int3', and the RIP points to the next
instruction (because that's how int3 works).

And the fastop code says:

* fastop functions have a special calling convention:
* Moreover, they are all exactly FASTOP_SIZE bytes long,

but that is clearly *NOT* the case for xaddw_ax_dx, because it's 16
bytes in size, and the other ones are 8 bytes. That's where the "nopl"
comes from: it's the alignment instruction to the next fastop

Compare that to the word-sized 'xaddl' case rigth afterwards: that one
*is* just 8 bytes in size, so the 64-byte 'xaddq' comes 8 bytes aftrer
it, and there's no 7-byte padding nop-instruction.

So I think that that is where the "xaddw_ax_dx+8" comes from: some
code assumes that FASTOP_SIZE is 8, but that xaddw_ax_dx case was
actually 9 bytes and thus got that "int3 + padding" in the next 8

The whole kvm x86 emulation thiing is quite complicated and has lots
of instruction size #defines and magic.

I'm not familiar enough with it to go "Ahh, it's obviously XYZ", but
I'm sure PeterZ and Borislav know exactly what's going on.