Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Test wanted] qemu: adjust the memory size for workarounding M1 panic #796

Merged
merged 2 commits into from
Apr 22, 2022

Conversation

AkihiroSuda
Copy link
Member

@AkihiroSuda AkihiroSuda commented Apr 14, 2022

Closes #795
Closes #713

Adjust the memory to be <= 3 GiB, only when all the following conditions are met:

  • Host OS < macOS 12.4
  • Host Arch == arm64
  • Accel == hvf
  • QEMU >= 7.0

This adjustment is required for avoiding host kernel panic. The issue was fixed in macOS 12.4 Beta 1.
See https://gitlab.com/qemu-project/qemu/-/issues/903#note_911000975


Help wanted: testing on M1 (especially M1 Max or Pro)

  • Hardware (e.g., MacBookPro 2021, M1 Pro): ...
  • macOS Version (e.g., 12.3.1): ...
  • Test matrix:
Guest memory 2 GiB 4 GiB 8 GiB
QEMU 6.2.0_1 ... ... ...
QEMU 7.0.0 ... ... ...

QEMU 7.0.0 can be installed by running brew install --build-from-source ./qemu.rb with qemu.rb from https://github.com/Homebrew/homebrew-core/pull/99652/files

@AkihiroSuda AkihiroSuda added help wanted Extra attention is needed platform/ARM labels Apr 14, 2022
@AkihiroSuda AkihiroSuda added this to the v0.10.0 milestone Apr 14, 2022
@AkihiroSuda
Copy link
Member Author

QEMU 7.0 is planned to be released today (https://wiki.qemu.org/Planning/7.0), so I'd like to merge this one and release Lima v0.10

cc @jandubois Probably, Rancher Desktop should continue bundling QEMU 6.2

pkg/qemu/qemu.go Outdated
if !macOSProductVersion.LessThan(*semver.New("12.4.0")) {
return memBytes
}
const safeSize = 1 << 31 // 2GiB
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the safeSize 2GiB and not e.g. 4GiB - 1 or something quite close to 4GiB?

If you ask for 3GiB, you get 3Gib, but if you ask for 5GiB you only get 2GiB, which seems weird. Shouldn't the default be the same as the highest value that we pass through untouched? If 4GiB - 1 doesn't work, then we should not allow that either.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We convert the number into MiB anyways before passing it to qemu, so technically our limit would be 4095MiB.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I suppose an "odd" memory size might not be "safe" under some conditions.
(I don't have M1 Pro/Max to confirm)

The user can still specify an odd memory size.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I suppose an "odd" memory size might not be "safe" under some conditions.

This sounds like a weird reason, as any number of things might not be "safe" either.

I could see the argument that we should change the default value to 2GiB if the user doesn't specify anything. But if the user specifies 3GiB, they get 3GiB, however, if they specify 4GiB, they only get 2GiB, that just feels wrong to me.

Since this is just a temporary workaround under limited conditions, I won't argue this too much, but ideally we should confirm if 4095MiB is safe or not, and use that if it doesn't show the issue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed to 4095 MiB.

jandubois
jandubois previously approved these changes Apr 19, 2022
Copy link
Member

@jandubois jandubois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not tested the code because I only have access to a single M1 machine right now, and don't want to change the installed version of QEMU.

Except for the safeSize value, everything else looks good to me.

@junnplus
Copy link
Contributor

I'll take some time to test it tonight.

@junnplus
Copy link
Contributor

Test Case 1:

[N] ❯ sw_vers
ProductName:    macOS
ProductVersion: 12.3.1
BuildVersion:   21E258

[N] ❯ _output/bin/limactl --version
limactl version 0.9.2-43-g1b99d48  # build (1b99d48f)

[N] ❯ qemu-system-aarch64 --version
QEMU emulator version 6.2.0  # brew 6.2.0_1

Work successfully on 8 GiB, 4 GiB, 2 GiB.

vm-2g      Running    127.0.0.1:55850    aarch64    4       2GiB      100GiB    /Users/jun/.lima/vm-2g
vm-4g      Running    127.0.0.1:56174    aarch64    4       4GiB      100GiB    /Users/jun/.lima/vm-4g
vm-8g      Running    127.0.0.1:56305    aarch64    4       8GiB      100GiB    /Users/jun/.lima/vm-8g

@junnplus
Copy link
Contributor

junnplus commented Apr 20, 2022

Test Case 2:

[N] ❯ sw_vers
ProductName:    macOS
ProductVersion: 12.3.1
BuildVersion:   21E258

[N] ❯ _output/bin/limactl --version
limactl version 0.9.2-43-g1b99d48  # build (1b99d48f)

[N] ❯ qemu-system-aarch64 --version
QEMU emulator version 7.0.0

Work successfully on 2 GiB. But 4GiB/8GiB directly caused the system to crash.

masOS error report: panic(cpu 3 caller 0xfffffe002397d814): vm_fault() KERN_FAILURE from guest fault on state 0xfffffe60fac98000 @sleh.c:3117 Debugger message: panic Memory ID: 0x6 OS release type: User OS version: 21E258 Kernel version: Darwin Kernel Version 21.4.0: Fri Mar 18 00:46:32 PDT 2022; root:xnu-8020.101.4~15/RELEASE_ARM64_T6000 Fileset Kernelcache UUID: 0631AF68D2B8D6FEA30E36D7895D4DB4 Kernel UUID: C342869F-FFB9-3CCE-A5A3-EA711C1E87F6 iBoot version: iBoot-7459.101.3 secure boot?: YES Paniclog version: 13 KernelCache slide: 0x000000001bf50000 KernelCache base: 0xfffffe0022f54000 Kernel slide: 0x000000001c700000 Kernel text base: 0xfffffe0023704000 Kernel text exec slide: 0x000000001c7e8000 Kernel text exec base: 0xfffffe00237ec000 mach_absolute_time: 0x182facfa3 Epoch Time: sec usec Boot : 0x62602044 0x0008735f Sleep : 0x00000000 0x00000000 Wake : 0x00000000 0x00000000 Calendar: 0x6260214b 0x00074135

Zone info:
Foreign : 0xfffffe002bc10000 - 0xfffffe002bc20000
Native : 0xfffffe1000670000 - 0xfffffe3000670000
Readonly: 0xfffffe14cd33c000 - 0xfffffe1666cd4000
Metadata: 0xfffffe861d504000 - 0xfffffe8629458000
Bitmaps : 0xfffffe8629458000 - 0xfffffe8634e70000

CORE 0 PVH locks held: None
CORE 1 PVH locks held: None
CORE 2 PVH locks held: None
CORE 3 PVH locks held: None
CORE 4 PVH locks held: None
CORE 5 PVH locks held: None
CORE 6 PVH locks held: None
CORE 7 PVH locks held: None
CORE 8 PVH locks held: None
CORE 9 PVH locks held: None
CORE 0: PC=0xfffffe00238b7754, LR=0xfffffe0023d523b0, FP=0xfffffe60fac73e20
CORE 1: PC=0xfffffe00237fce68, LR=0xfffffe00237fce68, FP=0x0000000000000000
CORE 2: PC=0xfffffe0023978238, LR=0xfffffe0023827e80, FP=0xfffffe60faf53e30
CORE 3 is the one that panicked. Check the full backtrace for details.
CORE 4: PC=0xfffffe002387b41c, LR=0xfffffe002387b418, FP=0xfffffe60e6cb3f00
CORE 5: PC=0xfffffe002387b418, LR=0xfffffe002387b418, FP=0xfffffe60fb01bf00
CORE 6: PC=0xfffffe002387b418, LR=0xfffffe002387b418, FP=0xfffffe60faf73f00
CORE 7: PC=0xfffffe002387b418, LR=0xfffffe002387b418, FP=0xfffffe60190a3f00
CORE 8: PC=0xfffffe002387b418, LR=0xfffffe002387b418, FP=0xfffffe60e6b63f00
CORE 9: PC=0xfffffe002387b418, LR=0xfffffe002387b418, FP=0xfffffe601941bf00
Compressor Info: 0% of compressed pages limit (OK) and 0% of segments limit (OK) with 0 swapfiles and OK swap space
Panicked task 0xfffffe29989e4cf0: 20327 pages, 10 threads: pid 4107: qemu-system-aarc
Panicked thread: 0xfffffe29983319b8, backtrace: 0xfffffe60e5213310, tid: 18780
lr: 0xfffffe0023845560 fp: 0xfffffe60e5213380
lr: 0xfffffe0023845228 fp: 0xfffffe60e52133f0
lr: 0xfffffe0023989ecc fp: 0xfffffe60e5213410
lr: 0xfffffe002397c05c fp: 0xfffffe60e5213480
lr: 0xfffffe0023979a98 fp: 0xfffffe60e5213540
lr: 0xfffffe00237f37f8 fp: 0xfffffe60e5213550
lr: 0xfffffe0023844eac fp: 0xfffffe60e52138f0
lr: 0xfffffe0023844eac fp: 0xfffffe60e5213960
lr: 0xfffffe002406eacc fp: 0xfffffe60e5213980
lr: 0xfffffe002397d814 fp: 0xfffffe60e52139e0
lr: 0xfffffe002397d3b0 fp: 0xfffffe60e5213a50
lr: 0xfffffe00237fe828 fp: 0xfffffe60e5213a60
lr: 0xfffffe00239921c0 fp: 0xfffffe60e5213e50
lr: 0xfffffe0023979ea8 fp: 0xfffffe60e5213f10
lr: 0xfffffe00237f37f8 fp: 0xfffffe60e5213f20

last started kext at 1769942507: com.apple.driver.driverkit.serial 6.0.0 (addr 0xfffffe00235df320, size 3416)
loaded kexts:
com.apple.filesystems.autofs 3.0
com.apple.UVCService 1
com.apple.driver.AppleTopCaseHIDEventDriver 5440.11
com.apple.driver.AppleBiometricServices 1
com.apple.driver.CoreKDL 1
com.apple.driver.usb.realtek8153patcher 5.0.0
com.apple.driver.DiskImages.ReadWriteDiskImage 493.0.0
com.apple.driver.DiskImages.UDIFDiskImage 493.0.0
com.apple.driver.DiskImages.RAMBackingStore 493.0.0
com.apple.driver.DiskImages.FileBackingStore 493.0.0
com.apple.driver.SEPHibernation 1
com.apple.driver.BCMWLANFirmware4387.Hashstore 1
com.apple.driver.AppleUSBDeviceNCM 5.0.0
com.apple.driver.AppleThunderboltIP 4.0.3
com.apple.driver.AppleFileSystemDriver 3.0.1
com.apple.nke.l2tp 1.9
com.apple.filesystems.tmpfs 1
com.apple.filesystems.lifs 1
com.apple.filesystems.apfs 1934.101.3
com.apple.IOTextEncryptionFamily 1.0.0
com.apple.filesystems.hfs.kext 583.100.10
com.apple.security.BootPolicy 1
com.apple.BootCache 40
com.apple.AppleFSCompression.AppleFSCompressionTypeZlib 1.0.0
com.apple.AppleFSCompression.AppleFSCompressionTypeDataless 1.0.0d1
com.apple.driver.AppleCS42L84Audio 540.34
com.apple.driver.ApplePMP 1
com.apple.driver.AppleSN012776Amp 540.34
com.apple.driver.AppleSmartIO2 1
com.apple.AppleEmbeddedSimpleSPINORFlasher 1
com.apple.driver.AppleT6000SOCTuner 1
com.apple.driver.AppleT6000CLPCv3 1
com.apple.driver.AppleSmartBatteryManager 161.0.0
com.apple.driver.AppleALSColorSensor 1.0.0d1
com.apple.driver.AppleAOPVoiceTrigger 140.1
com.apple.driver.AppleSPMIPMU 1.0.1
com.apple.driver.ApplePMPFirmware 1
com.apple.driver.AppleDPDisplayTCON 1
com.apple.driver.AppleAVD 560
com.apple.AGXG13X 190.17.3
com.apple.driver.AppleS5L8960XNCO 1
com.apple.driver.AppleSDXC 3.2.1
com.apple.driver.AppleEventLogHandler 1
com.apple.driver.AppleT6001PMGR 1
com.apple.driver.AppleAVE2 540.44.5
com.apple.driver.AppleMCDP29XXUpdateSupport 1
com.apple.driver.AppleSamsungSerial 1.0.0d1
com.apple.driver.AppleSerialShim 1
com.apple.driver.usb.AppleSynopsysUSB40XHCI 1
com.apple.driver.AppleProResHW 175.4.0
com.apple.driver.AppleJPEGDriver 4.8.1
com.apple.driver.AppleMobileDispT600X-DCP 140.0
com.apple.driver.AppleM68Buttons 1.0.0d1
com.apple.driver.AppleS8000AES 1
com.apple.driver.AppleS8000DWI 1.0.0d1
com.apple.driver.AppleInterruptControllerV2 1.0.0d1
com.apple.driver.AppleT8110DART 1
com.apple.driver.AppleBluetoothModule 1
com.apple.driver.AppleBCMWLANBusInterfacePCIe 1
com.apple.driver.AppleS5L8920XPWM 1.0.0d1
com.apple.driver.AudioDMAController-T600x 140.4
com.apple.driver.AppleT6000DART 1
com.apple.driver.AppleSPIMC 1
com.apple.driver.AppleS5L8940XI2C 1.0.0d2
com.apple.driver.AppleT6000 1
com.apple.iokit.IOUserEthernet 1.0.1
com.apple.driver.usb.AppleUSBUserHCI 1
com.apple.iokit.IOKitRegistryCompatibility 1
com.apple.iokit.EndpointSecurity 1
com.apple.driver.AppleDiskImages2 126.100.13
com.apple.AppleSystemPolicy 2.0.0
com.apple.nke.applicationfirewall 402
com.apple.kec.InvalidateHmac 1
com.apple.kec.AppleEncryptedArchive 1
com.apple.driver.driverkit.serial 6.0.0
com.apple.kext.triggers 1.0
com.apple.iokit.IOAVBFamily 1040.6
com.apple.plugin.IOgPTPPlugin 1040.3
com.apple.iokit.IOEthernetAVBController 1.1.0
com.apple.driver.AppleActuatorDriver 5440.11
com.apple.driver.AppleHIDKeyboard 228.1
com.apple.driver.AppleMultitouchDriver 5440.11
com.apple.driver.AppleHSBluetoothDriver 5440.11
com.apple.driver.IOBluetoothHIDDriver 9.0.0
com.apple.driver.AppleMesaSEPDriver 100.99
com.apple.iokit.IOBiometricFamily 1
com.apple.driver.usb.cdc.ecm 5.0.0
com.apple.driver.usb.cdc.acm 5.0.0
com.apple.driver.usb.serial 6.0.0
com.apple.driver.usb.IOUSBHostHIDDevice 1.2
com.apple.driver.usb.cdc 5.0.0
com.apple.driver.AppleUSBAudio 415.11
com.apple.iokit.IOAudioFamily 340.2
com.apple.vecLib.kext 1.2.0
com.apple.driver.DiskImages.KernelBacked 493.0.0
com.apple.driver.AppleSEPHDCPManager 1.0.1
com.apple.driver.AppleTrustedAccessory 1
com.apple.iokit.AppleSEPGenericTransfer 1
com.apple.driver.AppleXsanScheme 3
com.apple.driver.usb.networking 5.0.0
com.apple.driver.AppleThunderboltPCIDownAdapter 4.1.1
com.apple.driver.AppleThunderboltUSBDownAdapter 1.0.4
com.apple.driver.AppleThunderboltDPInAdapter 8.5.1
com.apple.driver.AppleThunderboltDPAdapterFamily 8.5.1
com.apple.nke.ppp 1.9
com.apple.driver.AppleHIDTransportSPI 5440.6
com.apple.driver.AppleHIDTransport 5440.6
com.apple.driver.AppleInputDeviceSupport 5440.6
com.apple.driver.AppleConvergedIPCOLYBTControl 1
com.apple.driver.AppleConvergedPCI 1
com.apple.driver.AppleBluetoothDebug 1
com.apple.driver.AppleBSDKextStarter 3
com.apple.driver.AppleDiagnosticDataAccessReadOnly 1.0.0
com.apple.filesystems.hfs.encodings.kext 1
com.apple.driver.AppleBTM 1.0.1
com.apple.driver.AppleCSEmbeddedAudio 540.34
com.apple.driver.AppleDCPDPTXProxy 1.0.0
com.apple.driver.DCPDPFamilyProxy 1
com.apple.driver.ApplePassthroughPPM 3.0
com.apple.driver.AppleAOPAudio 140.3
com.apple.driver.AppleEmbeddedAudio 540.34
com.apple.iokit.AppleARMIISAudio 140.2
com.apple.driver.AppleSPU 1
com.apple.AGXFirmwareKextG13XRTBuddy 190.17.3
com.apple.AGXFirmwareKextRTBuddy64 190.17.3
com.apple.iokit.IONVMeFamily 2.1.0
com.apple.driver.AppleNANDConfigAccess 1.0.0
com.apple.driver.AppleDialogPMU 1.0.1
com.apple.driver.AppleStockholmControl 1.0.0
com.apple.iokit.IOGPUFamily 35.29
com.apple.driver.ApplePMGR 1
com.apple.driver.AppleHPM 3.4.4
com.apple.driver.AppleT6000TypeCPhy 1
com.apple.driver.AppleT8103TypeCPhy 1
com.apple.driver.DCPAVFamilyProxy 1
com.apple.driver.AppleSART 1
com.apple.driver.AppleUSBXDCIARM 1.0
com.apple.driver.AppleUSBXDCI 1.0
com.apple.iokit.IOUSBDeviceFamily 2.0.0
com.apple.driver.usb.AppleSynopsysUSBXHCI 1
com.apple.driver.usb.AppleUSBXHCI 1.2
com.apple.driver.AppleEmbeddedUSBHost 1
com.apple.driver.usb.AppleUSBHub 1.2
com.apple.driver.usb.AppleUSBHostCompositeDevice 1.2
com.apple.driver.AppleSPMI 1.0.1
com.apple.iokit.IOMobileGraphicsFamily-DCP 343.0.0
com.apple.driver.AppleDCP 1
com.apple.driver.AppleFirmwareKit 1
com.apple.iokit.IOMobileGraphicsFamily 343.0.0
com.apple.driver.usb.AppleUSBHostPacketFilter 1.0
com.apple.driver.AppleARMWatchdogTimer 1
com.apple.driver.AppleDisplayCrossbar 1.0.0
com.apple.iokit.IODisplayPortFamily 1.0.0
com.apple.driver.AppleTypeCPhy 1
com.apple.driver.AppleThunderboltNHI 7.2.81
com.apple.driver.AppleT6000PCIeC 1
com.apple.iokit.IOThunderboltFamily 9.3.3
com.apple.driver.ApplePIODMA 1
com.apple.driver.AppleT600xPCIe 1
com.apple.driver.AppleMultiFunctionManager 1
com.apple.driver.AppleBluetoothDebugService 1
com.apple.driver.AppleBCMWLANCore 1.0.0
com.apple.iokit.IO80211Family 1200.12.2b1
com.apple.driver.IOImageLoader 1.0.0
com.apple.driver.AppleOLYHAL 1
com.apple.driver.corecapture 1.0.4
com.apple.driver.AppleEmbeddedPCIE 1
com.apple.driver.AppleMCA2-T600x 640.5
com.apple.driver.AppleEmbeddedAudioLibs 140.1
com.apple.driver.AppleFirmwareUpdateKext 1
com.apple.driver.AppleH13CameraInterface 6.44.0
com.apple.driver.AppleH10PearlCameraInterface 17.0.6
com.apple.driver.AppleGPIOICController 1.0.2
com.apple.driver.AppleFireStormErrorHandler 1
com.apple.driver.AppleMobileApNonce 1
com.apple.iokit.IOTimeSyncFamily 1040.3
com.apple.driver.DiskImages 493.0.0
com.apple.iokit.IOGraphicsFamily 594
com.apple.iokit.IOBluetoothSerialManager 9.0.0
com.apple.iokit.IOBluetoothHostControllerUSBTransport 9.0.0
com.apple.iokit.IOBluetoothHostControllerUARTTransport 9.0.0
com.apple.iokit.IOBluetoothHostControllerTransport 9.0.0
com.apple.driver.IOBluetoothHostControllerPCIeTransport 9.0.0
com.apple.iokit.IOBluetoothFamily 9.0.0
com.apple.driver.FairPlayIOKit 68.16.0
com.apple.iokit.CSRBluetoothHostControllerUSBTransport 9.0.0
com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport 9.0.0
com.apple.driver.AppleSSE 1.0
com.apple.driver.AppleSEPKeyStore 2
com.apple.driver.AppleUSBTDM 533.100.11
com.apple.iokit.IOUSBMassStorageDriver 210.101.2
com.apple.iokit.IOPCIFamily 2.9
com.apple.iokit.IOSCSIBlockCommandsDevice 456.100.7
com.apple.iokit.IOSCSIArchitectureModelFamily 456.100.7
com.apple.driver.AppleIPAppender 1.0
com.apple.driver.AppleFDEKeyStore 28.30
com.apple.driver.AppleEffaceableStorage 1.0
com.apple.driver.AppleCredentialManager 1.0
com.apple.driver.KernelRelayHost 1
com.apple.iokit.IOUSBHostFamily 1.2
com.apple.driver.AppleUSBHostMergeProperties 1.2
com.apple.driver.usb.AppleUSBCommon 1.0
com.apple.driver.AppleSMC 3.1.9
com.apple.driver.RTBuddy 1.0.0
com.apple.driver.AppleEmbeddedTempSensor 1.0.0
com.apple.driver.AppleARMPMU 1.0
com.apple.iokit.IOAccessoryManager 1.0.0
com.apple.driver.AppleOnboardSerial 1.0
com.apple.iokit.IOSkywalkFamily 1.0
com.apple.driver.mDNSOffloadUserClient 1.0.1b8
com.apple.iokit.IONetworkingFamily 3.4
com.apple.iokit.IOSerialFamily 11
com.apple.driver.AppleSEPManager 1.0.1
com.apple.driver.AppleA7IOP 1.0.2
com.apple.driver.IOSlaveProcessor 1
com.apple.driver.AppleBiometricSensor 2
com.apple.iokit.IOHIDFamily 2.0.0
com.apple.iokit.CoreAnalyticsFamily 1
com.apple.driver.AppleANELoadBalancer 5.64.2
com.apple.driver.AppleH11ANEInterface 5.64.2
com.apple.AUC 1.0
com.apple.iokit.IOAVFamily 1.0.0
com.apple.iokit.IOHDCPFamily 1.0.0
com.apple.iokit.IOCECFamily 1
com.apple.iokit.IOAudio2Family 1.0
com.apple.driver.AppleIISController 140.1
com.apple.driver.AppleAudioClockLibs 140.1
com.apple.driver.AppleM2ScalerCSCDriver 265.0.0
com.apple.iokit.IOSurface 302.14
com.apple.driver.IODARTFamily 1
com.apple.security.quarantine 4
com.apple.security.sandbox 300.0
com.apple.kext.AppleMatch 1.0.0d1
com.apple.driver.AppleMobileFileIntegrity 1.0.5
com.apple.security.AppleImage4 4.2.0
com.apple.kext.CoreTrust 1
com.apple.iokit.IOCryptoAcceleratorFamily 1.0.1
com.apple.driver.AppleARMPlatform 1.0.2
com.apple.iokit.IOStorageFamily 2.1
com.apple.iokit.IOSlowAdaptiveClockingFamily 1.0.0
com.apple.iokit.IOReportFamily 47
com.apple.kec.pthread 1
com.apple.kec.Libm 1
com.apple.kec.corecrypto 12.0

** Stackshot Succeeded ** Bytes Traced 356611 (Uncompressed 940800) **

Copy link
Contributor

@junnplus junnplus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed to get the MacOS version without handling newlines.

pkg/qemu/qemu.go Outdated
if err != nil {
return nil, fmt.Errorf("failed to execute %v: %w", cmd.Args, err)
}
ver, err := semver.NewVersion(string(b))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need remove trailing newline from string.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed

@AkihiroSuda
Copy link
Member Author

@junnplus Thanks a lot for testing. Could you try the latest revision?

@junnplus
Copy link
Contributor

junnplus commented Apr 21, 2022

@AkihiroSuda There is no problem with the macOS version parsing, but qemu cannot be started.

4GiB:

{"level":"debug","msg":"AES accelerator seems available, prioritizing [email protected] and [email protected]","time":"2022-04-21T14:35:19+08:00"}
{"level":"info","msg":"Starting QEMU (hint: to watch the boot progress, see \"/Users/jun/.lima/vm1-4g/serial.log\")","time":"2022-04-21T14:35:19+08:00"}
{"level":"debug","msg":"qCmd.Args: [/opt/homebrew/bin/qemu-system-aarch64 -m 4095 -cpu host -machine virt,accel=hvf,highmem=off -smp 4,sockets=1,cores=4,threads=1 -drive if=pflash,format=raw,readonly=on,file=/opt/homebrew/share/qemu/edk2-aarch64-code.fd -boot order=c,splash-time=0,menu=on -drive file=/Users/jun/.lima/vm1-4g/diffdisk,if=virtio -cdrom /Users/jun/.lima/vm1-4g/cidata.iso -netdev user,id=net0,net=192.168.5.0/24,dhcpstart=192.168.5.15,hostfwd=tcp:127.0.0.1:51224-:22 -device virtio-net-pci,netdev=net0,mac=52:55:55:d3:a0:d3 -device virtio-rng-pci -display none -vga none -device ramfb -device qemu-xhci,id=usb-bus -device usb-kbd,bus=usb-bus.0 -device usb-mouse,bus=usb-bus.0 -parallel none -chardev socket,id=char-serial,path=/Users/jun/.lima/vm1-4g/serial.sock,server=on,wait=off,logfile=/Users/jun/.lima/vm1-4g/serial.log -serial chardev:char-serial -chardev socket,id=char-qmp,path=/Users/jun/.lima/vm1-4g/qmp.sock,server=on,wait=off -qmp chardev:char-qmp -name lima-vm1-4g -pidfile /Users/jun/.lima/vm1-4g/qemu.pid]","time":"2022-04-21T14:35:19+08:00"}
{"level":"info","msg":"Waiting for the essential requirement 1 of 5: \"ssh\"","time":"2022-04-21T14:35:19+08:00"}
{"level":"debug","msg":"executing script \"ssh\"","time":"2022-04-21T14:35:19+08:00"}
{"level":"debug","msg":"qemu[stderr]: qemu-system-aarch64: Addressing limited to 32 bits, but memory exceeds it by 1073741824 bytes","time":"2022-04-21T14:35:19+08:00"}
{"level":"debug","msg":"qemu[stderr]: ","time":"2022-04-21T14:35:19+08:00"}
{"level":"debug","msg":"executing ssh for script \"ssh\": /opt/homebrew/bin/ssh [ssh -F /dev/null -o IdentityFile=\"/Users/jun/.lima/_config/user\" -o IdentityFile=\"/Users/jun/.ssh/github_id_rsa\" -o IdentityFile=\"/Users/jun/.ssh/id_ed25519\" -o IdentityFile=\"/Users/jun/.ssh/id_rsa\" -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o NoHostAuthenticationForLocalhost=yes -o GSSAPIAuthentication=no -o PreferredAuthentications=publickey -o Compression=no -o BatchMode=yes -o IdentitiesOnly=yes -o Ciphers=\"^[email protected],[email protected]\" -o User=jun -o ControlMaster=auto -o ControlPath=\"/Users/jun/.lima/vm1-4g/ssh.sock\" -o ControlPersist=5m -p 51224 127.0.0.1 -- /bin/bash]","time":"2022-04-21T14:35:19+08:00"}
{"error":"exit status 1","level":"info","msg":"QEMU has exited","time":"2022-04-21T14:35:19+08:00"}
{"level":"debug","msg":"stdout=\"\", stderr=\"ssh: connect to host 127.0.0.1 port 51224: Connection refused\\r\\n\", err=failed to execute script \"ssh\": stdout=\"\", stderr=\"ssh: connect to host 127.0.0.1 port 51224: Connection refused\\r\\n\": exit status 255","time":"2022-04-21T14:35:19+08:00"}

@junnplus
Copy link
Contributor

junnplus commented Apr 21, 2022

3GiB, 2.9GiB passes, neither 3.9GiB nor 3.5GiB, 3.1GiB work on QEMU 7.0.

@AkihiroSuda
Copy link
Member Author

Thanks, adjusted the safeSize to 3 GiB. This should work?

pkg/qemu/qemu.go Outdated
// This adjustment is required for avoiding host kernel panic. The issue was fixed in macOS 12.4 Beta 1.
// See https://github.com/lima-vm/lima/issues/795 https://gitlab.com/qemu-project/qemu/-/issues/903#note_911000975
func adjustMemBytesDarwinARM64HVF(memBytes int64, accel string, features *features) int64 {
if memBytes < (1 << 32) { // less than 4GiB
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this one have to be adjusted to 3GiB as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adjusted to 3 GiB

pkg/qemu/qemu.go Outdated
@@ -285,7 +356,8 @@ func Cmdline(cfg Config) (string, []string, error) {
// QEMU < 7.0 requires highmem=off to be set, otherwise fails with "VCPU supports less PA bits (36) than requested by the memory map (40)"
// https://github.com/lima-vm/lima/issues/680
// https://github.com/lima-vm/lima/pull/24
if !strings.Contains(string(features.MachineHelp), "virt-7.0") {
// But when the memory size is less than 4 GiB, we can always set highmem=off.
if !features.VersionGEQ7 || memBytes < (1<<32) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I wonder if this one is correct too; I couldn't find a definitive source, but I've seen comments that highmem=off limits memory on ARM to 3GiB.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adjusted to 3 GiB

@junnplus
Copy link
Contributor

adjusted the safeSize to 3 GiB. This should work?

@AkihiroSuda Works fine after adjusted to 3GiB. Tested on 3b32553

@AkihiroSuda
Copy link
Member Author

adjusted the safeSize to 3 GiB. This should work?

@AkihiroSuda Works fine after adjusted to 3GiB. Tested on 3b32553

Thank you! 👍

Adjust the memory to be <= 3 GiB, only when the following conditions are met:

- Host OS   <  macOS 12.4
- Host Arch == arm64
- Accel     == hvf
- QEMU      >= 7.0

This adjustment is required for avoiding host kernel panic. The issue was fixed in macOS 12.4 Beta 1.
See https://gitlab.com/qemu-project/qemu/-/issues/903#note_911000975

Signed-off-by: Akihiro Suda <[email protected]>
@AkihiroSuda
Copy link
Member Author

Pushed a cosmetic change from 3b32553.
No code change since 3b32553

$ git diff 3b32553 130b300
diff --git a/pkg/qemu/qemu.go b/pkg/qemu/qemu.go
index 77b7d7d..13e8218 100644
--- a/pkg/qemu/qemu.go
+++ b/pkg/qemu/qemu.go
@@ -262,9 +262,8 @@ func getMacOSProductVersion() (*semver.Version, error) {
        return verSem, nil
 }
 
-// adjustMemBytesDarwinARM64HVF adjusts the memory to be less than 3 GiB, only when the following conditions are met:
+// adjustMemBytesDarwinARM64HVF adjusts the memory to be <= 3 GiB, only when the following conditions are met:
 //
-// - memBytes  >  3 GiB
 // - Host OS   <  macOS 12.4
 // - Host Arch == arm64
 // - Accel     == hvf

Copy link
Contributor

@junnplus junnplus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed platform/ARM
Projects
None yet
3 participants