Bug 205347 - cpuid_eax(0x00000006) returns 0 vs native_cpuid which returns correct value.
Summary: cpuid_eax(0x00000006) returns 0 vs native_cpuid which returns correct value.
Status: NEW
Alias: None
Product: Virtualization
Classification: Unclassified
Component: Xen (show other bugs)
Hardware: Intel Linux
: P1 normal
Assignee: virtualization_xen
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-10-28 13:10 UTC by Rushikesh
Modified: 2019-10-29 13:54 UTC (History)
1 user (show)

See Also:
Kernel Version: 4.19
Subsystem:
Regression: No
Bisected commit-id:


Attachments
eax.c (699 bytes, text/plain)
2019-10-28 13:10 UTC, Rushikesh
Details

Description Rushikesh 2019-10-28 13:10:47 UTC
Created attachment 285695 [details]
eax.c

attached is a piece of code in a sample kernel module

The output is

[63291.688755] cpuid_eax 6	: 0
[63291.688759] native_cpuid a 77 b 2 c 9 d 0


Because of this, the system is not able to access Thermal and Power Management Leaf. Ref. arch/x86/kernel/cpu/common.c
Comment 1 Rushikesh 2019-10-28 13:12:25 UTC
Additional information - the kernel is running as Dom0 kernel for XCP-NG (previously XenServer) host.
Comment 2 Borislav Petkov 2019-10-29 08:45:58 UTC
1. Try the latest kernel
2. If it still gives 0, it is most likely the pvops thing
Comment 3 Rushikesh 2019-10-29 09:08:29 UTC
1. Do you mean 4.19.81 or 5.3.8?
2. arch/x86/include/asm/processor.h has both cpuid_eax and native_cpuid. cpuid_eax eventually calls native_cpuid yet fails to give right answer for eax.
Comment 4 Borislav Petkov 2019-10-29 10:41:20 UTC
(In reply to Rushikesh from comment #3)
> 1. Do you mean 4.19.81 or 5.3.8?

5.3.8.

> 2. arch/x86/include/asm/processor.h has both cpuid_eax and native_cpuid.
> cpuid_eax eventually calls native_cpuid yet fails to give right answer for
> eax.

Are you sure it does that? IOW, do you have CONFIG_PARAVIRT_XXL enabled in your .config?
Comment 5 Rushikesh 2019-10-29 11:13:17 UTC
1. Ok

2.

Following is the CONFIG

# grep CONFIG_PARAVIRT /boot/config-4.19.0+1 
CONFIG_PARAVIRT=y
# CONFIG_PARAVIRT_DEBUG is not set
CONFIG_PARAVIRT_SPINLOCKS=y
# CONFIG_PARAVIRT_TIME_ACCOUNTING is not set
CONFIG_PARAVIRT_CLOCK=y


Im certain that cpuid_eax does not work but native_cpuid works. I tried all the functions via a kernel modules with op=0x06.
[ 8079.168863] cpuid_eax 6	: 0
[ 8079.168864] cpuid		: a 0 b 0 c 0 d 0
[ 8079.168866] cpuid_count	: a 0 b 0 c 0 d 0
[ 8079.168866] native_cpuid	: a 77 b 2 c 9 d 0
[ 8079.168868] __cpuid		: a 0 b 0 c 0 d 0


only native_cpuid is giving valid EAX. And since https://elixir.bootlin.com/linux/v4.19/source/arch/x86/kernel/cpuid.c#L60 also refers cpuid_count function, Thermal management is turned off.

I was able to modify cpuid.ko with native_cpuid and get a modified coretemp.ko to work and show thermal information. Ref: https://github.com/xcp-ng/xcp/issues/249

Additionally, found an older bug https://bugzilla.kernel.org/show_bug.cgi?id=198667 which was giving oops because coretemp misread the EAX. In case of 4.19.0+1, coretemp does not load at all.
Comment 6 Borislav Petkov 2019-10-29 12:30:08 UTC
(In reply to Rushikesh from comment #5)
> CONFIG_PARAVIRT=y

You have CONFIG_PARAVIRT=y which means, cpuid_eax() calls the pv_ops variant, which apparently doesn't emulate that leaf. That's for xen people to decide whether they wanna expose that leaf and support thermal stuff in dom0. Or maybe that has happened already but you'd need to test the newest kernel to find out.
Comment 7 Rushikesh 2019-10-29 13:54:09 UTC
I was expecting consistent behavior of cpuid_eax() and native_cpuid(). Both are kernel functions from single file arch/x86/include/asm/processor.h and doing same thing but different outputs.

Interestingly the call flow is cpuid_eax() -> cpuid() -> __cpuid() -> native_cpuid().

Thermal management was supported & working while Dom0 was on kernel 4.4 and most of the users reported that it stopped working after upgrade to 4.19. I'm not sure if its the case with all 4.19 users.

I'll report back the behavior on 5.3.8 in few days.

Note You need to log in before you can comment on or make changes to this bug.