Bug 232081 - 12.0-BETA8 crashes under 11.2+Bhyve on Phenom-II (unemulated clflush [ebx])
Summary: 12.0-BETA8 crashes under 11.2+Bhyve on Phenom-II (unemulated clflush [ebx])
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: amd64 Any
: --- Affects Only Me
Assignee: Konstantin Belousov
URL:
Keywords: patch, regression
Depends on:
Blocks:
 
Reported: 2018-10-08 19:03 UTC by Poul-Henning Kamp
Modified: 2019-04-09 19:12 UTC (History)
5 users (show)

See Also:


Attachments
Tweak cache features bits before ifuncs are resolved. (855 bytes, patch)
2018-10-09 10:19 UTC, Konstantin Belousov
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Poul-Henning Kamp freebsd_committer freebsd_triage 2018-10-08 19:03:19 UTC
12.0-ALPHA8 on Phenom-II crashes with unemulated "clflush BYTE PTR [ebx]


Host:
-----
        FreeBSD 11.2-RELEASE-p4 FreeBSD 11.2-RELEASE-p4 #0: Thu Sep 27 08:16:24 UTC 2018 amd64

        CPU: AMD Phenom(tm) II X6 1075T Processor (3013.98-MHz K8-class CPU)
          Origin="AuthenticAMD"  Id=0x100fa0  Family=0x10  Model=0xa  Stepping=0
          Features=0x178bfbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CLFLUSH,MMX,FXSR,SSE,SSE2,HTT>
          Features2=0x802009<SSE3,MON,CX16,POPCNT>
          AMD Features=0xee500800<SYSCALL,NX,MMX+,FFXSR,Page1GB,RDTSCP,LM,3DNow!+,3DNow!>
          AMD Features2=0x837ff<LAHF,CMP,SVM,ExtAPIC,CR8,ABM,SSE4A,MAS,Prefetch,OSVW,IBS,SKINIT,WDT,NodeId>
          SVM: NP,NRIP,NAsids=64
          TSC: P-state invariant, performance statistics
        real memory  = 34359738368 (32768 MB)
        avail memory = 33279193088 (31737 MB)

Guest:
------
        12.0-ALPHA8-amd64-20180928-r338991


Result:
-------

        Host:
        -----

                Launching virtual machine "vm14_fbsd" ...
                Failed to emulate instruction [0x0f 0xae 0x3b 0x8b 0x04 0x25 0xf8 0x5d 0xb8 0x81 0x48 0x01 0xc3 0x4c 0x39] at 0xffffffff8104abb0

        Guest:
        ------
                CPU: AMD Phenom(tm) II X6 1075T Processor (3013.42-MHz K8-class CPU)
                  Origin="AuthenticAMD"  Id=0x100fa0  Family=0x10  Model=0xa  Stepping=0
                  Features=0x1783fbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,MMX,FXSR,SSE,SSE2,HTT>
                  Features2=0x80802001<SSE3,CX16,POPCNT,HV>
                  AMD Features=0xe6500800<SYSCALL,NX,MMX+,FFXSR,Page1GB,LM,3DNow!+,3DNow!>
                  AMD Features2=0x31fb<LAHF,CMP,ExtAPIC,CR8,ABM,SSE4A,MAS,Prefetch,SKINIT,WDT>
                  TSC: P-state invariant
                [...]
                ACPI APIC Table: <BHYVE  BVMADT  >
                FreeBSD/SMP: Multiprocessor System Detected: 4 CPUs
                FreeBSD/SMP: 4 package(s) x 1 core(s)
                arc4random: no preloaded entropy cache
Comment 1 Andriy Gapon freebsd_committer freebsd_triage 2018-10-08 21:17:24 UTC
I suspect that the issue was uncovered by base r338807.
It seems that CPUID_CLFSH feature is advertised to the guest because the host supports it.  But there is some special code in initializecpucache() that clears the flag for VM guests.  But ifuncs are resolved before initializecpucache() is called.  So, clflush gets enabled since the switch to ifuncs.

I guess that if bhyve does not emulate clflush and if the hardware does not support it in virtualized mode, then bhyve should clear CPUID_CLFSH.
Comment 2 Andriy Gapon freebsd_committer freebsd_triage 2018-10-09 07:12:18 UTC
Also, it seems that hw.clflush_disable=1, which is also handled by initializecpucache(), would be ignored now.
Comment 3 Konstantin Belousov freebsd_committer freebsd_triage 2018-10-09 10:19:00 UTC
Created attachment 197961 [details]
Tweak cache features bits before ifuncs are resolved.

The patch should be applied to the guest.

Lack of the clflush emulation is still the bug.
Comment 4 Konstantin Belousov freebsd_committer freebsd_triage 2018-10-09 14:24:05 UTC
Also see https://reviews.freebsd.org/D17482
Comment 5 John Baldwin freebsd_committer freebsd_triage 2018-10-11 18:01:23 UTC
I do think we'd like to get both patches into 12.0 so that existing 10.x/11.x hosts can run 12.0 guests.
Comment 6 commit-hook freebsd_committer freebsd_triage 2018-10-12 15:30:46 UTC
A commit references this bug:

Author: kib
Date: Fri Oct 12 15:30:15 UTC 2018
New revision: 339331
URL: https://svnweb.freebsd.org/changeset/base/339331

Log:
  bhyve: emulate CLFLUSH and CLFLUSHOPT.

  Apparently CLFLUSH on mmio can cause VM exit, as reported in the PR.
  I do not see that anything useful can be done except emulating page
  faults on invalid addresses.

  Due to the instruction encoding pecularity, also emulate SFENCE.

  PR:	232081
  Reported by:	phk
  Reviewed by:	araujo, avg, jhb (all: previous version)
  Sponsored by:	The FreeBSD Foundation
  Approved by:	re (gjb)
  MFC after:	1 week
  Differential revision:	https://reviews.freebsd.org/D17482

Changes:
  head/sys/amd64/vmm/vmm_instruction_emul.c
Comment 7 commit-hook freebsd_committer freebsd_triage 2018-10-12 16:01:16 UTC
A commit references this bug:

Author: kib
Date: Fri Oct 12 16:00:21 UTC 2018
New revision: 339333
URL: https://svnweb.freebsd.org/changeset/base/339333

Log:
  Call initializecpucache() before ifuncs are resolved.

  The function tweaks CPU capabilities based on the VM platform and
  tunables, which affected selection of the cache flush method before
  ifuncs were used, and should affect the cache flush in the same way
  after ifunc.

  PR:	232081
  Reported by:	phk
  Analyzed by:	avg
  Sponsored by:	The FreeBSD Foundation
  Approved by:	re (gjb)

Changes:
  head/sys/amd64/amd64/machdep.c
Comment 8 Poul-Henning Kamp freebsd_committer freebsd_triage 2018-10-18 20:23:50 UTC
Tried FreeBSD 12.0-ALPHA10 as guest, and that boots fine

Thanks!