NetBSD Problem Report #52919

From paul@whooppee.com  Fri Jan 12 09:46:47 2018
Return-Path: <paul@whooppee.com>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id D7A077A1C4
	for <gnats-bugs@gnats.NetBSD.org>; Fri, 12 Jan 2018 09:46:47 +0000 (UTC)
Message-Id: <20180112094644.2461D16E48@speedy.whooppee.com>
Date: Fri, 12 Jan 2018 17:46:44 +0800 (+08)
From: paul@whooppee.com
Reply-To: paul@whooppee.com
To: gnats-bugs@NetBSD.org
Subject: modular procfs gets cpuinfo wrong
X-Send-Pr-Version: 3.95

>Number:         52919
>Category:       kern
>Synopsis:       modular procfs gets cpuinfo wrong
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    pgoyette
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jan 12 09:50:00 +0000 2018
>Closed-Date:    Mon Jul 16 07:11:37 +0000 2018
>Last-Modified:  Mon Jul 16 07:11:37 +0000 2018
>Originator:     Paul Goyette
>Release:        NetBSD 8.99.7
>Organization:
+------------------+--------------------------+----------------------------+
| Paul Goyette     | PGP Key fingerprint:     | E-mail addresses:          |
| (Retired)        | FA29 0E3B 35AF E8AE 6651 | paul at whooppee dot com   |
| Kernel Developer | 0786 F758 55DE 53BA 7731 | pgoyette at netbsd dot org |
+------------------+--------------------------+----------------------------+
>Environment:


System: NetBSD speedy.whooppee.com 8.99.7 NetBSD 8.99.7 (SPEEDY 2017-11-29 22:03:05 UTC) #0: Wed Nov 29 23:14:50 UTC 2017 paul@speedy.whooppee.com:/build/netbsd-local/obj/amd64/sys/arch/amd64/compile/SPEEDY amd64
Architecture: x86_64
Machine: amd64
>Description:
Due to conditional compilation of the struct cpu_info structure, some fields
can be misaligned between kernel and module, resulting in wrong data being
referenced.  For example, on x86, the XEN and SVS kernel options control the
inclusion of certain fields, and a modular cpuinfo reports various incorrect
values:

processor       : 15
vendor_id       : ÿÿÿÿ
cpu family      : 2
model           : 15
model name      : Intel(R) Core(TM) i7-6900K CPU @ 3.20GHz
stepping        : 0
cpu MHz         : 3483.18
apicid          : 15
initial apicid  : 15
fpu             : yes
fpu_exception   : yes
cpuid level     : 570624
wp              : yes
flags           : fpu apic mtrr pge mca pat pse36 pn clflush dts acpi mmx mmxext monitor ace cmp_legacy 3dnowprefetch osvw cqm xsaveopt cqm_llc cqm_occup_llc dtherm ida arat pln pts 
clflush size    : 524288

Compare the vendor_id, family, model, stepping, and cache-line size to the
output returned by cpuctl:

cpu0: highest basic info 00000014
cpu0: highest extended info 80000008
cpu0: "Intel(R) Core(TM) i7-6900K CPU @ 3.20GHz"
cpu0: Intel Xeon E[57] v4 (Broadwell), Core i7-69xx Extreme (686-class), 3198.27 MHz
cpu0: family 0x6 model 0x4f stepping 0x1 (id 0x406f1)
cpu0: features 0xbfebfbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE>
cpu0: features 0xbfebfbff<MCA,CMOV,PAT,PSE36,CLFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2>
cpu0: features 0xbfebfbff<SS,HTT,TM,SBF>
cpu0: features1 0x7ffefbbf<SSE3,PCLMULQDQ,DTES64,MONITOR,DS-CPL,VMX,EST,TM2>
cpu0: features1 0x7ffefbbf<SSSE3,SDBG,FMA,CX16,xTPR,PDCM,PCID,DCA,SSE41,SSE42>
cpu0: features1 0x7ffefbbf<X2APIC,MOVBE,POPCNT,DEADLINE,AES,XSAVE,OSXSAVE,AVX>
cpu0: features1 0x7ffefbbf<F16C,RDRAND>
cpu0: features2 0x2c100800<SYSCALL/SYSRET,XD,P1GB,RDTSCP,EM64T>
cpu0: features3 0x121<LAHF,LZCNT,PREFETCHW>
cpu0: features5 0x21cbfbb<FSGSBASE,TSCADJUST,BMI1,HLE,AVX2,SMEP,BMI2,ERMS>
cpu0: features5 0x21cbfbb<INVPCID,RTM,QM,FPUCSDS,PQE,RDSEED,ADX,SMAP,PT>
cpu0: xsave features 0x7<x87,SSE,AVX>
cpu0: xsave instructions 0x1<XSAVEOPT>
cpu0: xsave area size: current 832, maximum 832, xgetbv enabled
cpu0: enabled xsave 0x7<x87,SSE,AVX>
cpu0: I-cache 32KB 64B/line 8-way, D-cache 32KB 64B/line 8-way
cpu0: L2 cache 256KB 64B/line 8-way
cpu0: L3 cache 20MB 64B/line 20-way
cpu0: 64B prefetching
cpu0: ITLB 64 4KB entries 8-way, 2M/4M: 8 entries
cpu0: DTLB 64 4KB entries 4-way
cpu0: L2 STLB 1536 4KB entries 6-way
cpu0: L1 1GB page DTLB 4 1GB entries 4-way
cpu0: Initial APIC ID 0
cpu0: Cluster/Package ID 0
cpu0: Core ID 0
cpu0: SMT ID 0
cpu0: DSPM-eax 0x77<DTS,IDA,ARAT,PLN,ECMD,PTM>
cpu0: DSPM-ecx 0x9<HWF,EPB>
cpu0: SEF highest subleaf 00000000
cpu0: microcode version 0xb000021, platform ID 2

(Note also that the text version of the processor name has the correct
CPU speed - 3.20GHz, yet the numeric version reports 3843.18MHz

A built-in version of the same module reports correct values, since the
kernel and module code are built with the same options, resulting in no
mis-alignment.

>How-To-Repeat:
(For example) build a x86 kernel with SVS, DIAGNOSTIC, and LOCKDEBUG, but
without a built-in procfs.  Boot the kernel, mount /proc (ie, autoload the
procfs module), and `cat /proc/cpuinfo`

Please note that I have not exhaustively investigated other processor
architectures to determine what, if any, alignment issue might exist.

>Fix:
1. Update the structure definition to be insensitive to kernel options,
   (ie, include all fields, whether or not they're used), or
2. Include (a copy of) the MD routines for loading the cpuinfo structure
   within the module itself, or
3. Other alternatives?


>Release-Note:

>Audit-Trail:
From: "Paul Goyette" <pgoyette@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/52919 CVS commit: src/sys/arch/x86/include
Date: Mon, 16 Jul 2018 07:07:30 +0000

 Module Name:	src
 Committed By:	pgoyette
 Date:		Mon Jul 16 07:07:30 UTC 2018

 Modified Files:
 	src/sys/arch/x86/include: cpu.h

 Log Message:
 More rearrangement of struct cpu_info to keep all the un-conditional
 members at fixed locations.

 Should address my PR kern/52919

 OK maxv@

 XXX kernel version bump coming momentarily.


 To generate a diff of this commit:
 cvs rdiff -u -r1.95 -r1.96 src/sys/arch/x86/include/cpu.h

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

Responsible-Changed-From-To: kern-bug-people->pgoyette
Responsible-Changed-By: pgoyette@NetBSD.org
Responsible-Changed-When: Mon, 16 Jul 2018 07:11:37 +0000
Responsible-Changed-Why:
I'll fix it.


State-Changed-From-To: open->closed
State-Changed-By: pgoyette@NetBSD.org
State-Changed-When: Mon, 16 Jul 2018 07:11:37 +0000
State-Changed-Why:
It's fixed.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.43 2018/01/16 07:36:43 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.