Opened 3 months ago

Closed 3 months ago

Last modified 3 months ago

#73519 closed defect (duplicate)

qemu @10.2 fails on Monterey arm64, but a patch works

Reported by: peterwwillis (Peter W) Owned by: raimue (Rainer Müller)
Priority: Normal Milestone:
Component: ports Version:
Keywords: monterey arm64 haspatch Cc: herbygillot (Herby Gillot)
Port: qemu

Description

I was trying to install 'colima' port on Monterey, and it pulled in qemu, but a build of qemu failed at a compile step.

I sicked an AI agent on it (copilot w/Sonnet 4.6) and it figured out the issue, wrote a patch, compiled it, installed it, and everything ended up working fine. It did all this in a matter of minutes! So I'm sharing the fix here in case someone more familiar with MacPorts patching/fixing wants to apply it. (Thanks very much for the awesome project!)

---

# Installing colima via MacPorts on macOS Monterey (M1 / Apple Silicon)

## Problem

sudo port install colima fails on macOS 12 Monterey with Apple Silicon (arm64) because:

  1. No pre-built binary exists for qemu on darwin_21 arm64 (Monterey Apple Silicon).
  2. Building from source failsqemu 10.2.0 uses Apple Hypervisor Framework APIs introduced in macOS 13:
  • hv_vm_config_create()
  • hv_vm_config_set_ipa_size()
  • hv_vm_config_get_default_ipa_size()
  • hv_vm_config_get_max_ipa_size()

MacPorts builds qemu using the macOS 12.3 SDK (-isysroot MacOSX12.sdk), which doesn't have hv_vm_config.h.

Error seen:

../qemu-10.2.0/target/arm/hvf/hvf.c:833:23: error: call to undeclared function

'hv_vm_config_get_default_ipa_size'; ISO C99 and later do not support implicit

function declarations [-Wimplicit-function-declaration]

---

## Fix

Patch target/arm/hvf/hvf.c in the qemu source tree to guard the macOS 13+ API calls with #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 130000, falling back to:

  • Hardcoded 36 bit IPA size (correct for M1 on Monterey's HVF)
  • hv_vm_create(NULL) (the pre-macOS-13 calling convention)

## Why 36 bits?

The patch includes a hard-coded value of '36'.

On Apple M1 running macOS Monterey, the HVF (Apple Hypervisor Framework) exposes a fixed 36-bit IPA (Intermediate Physical Address) space = 64 GB of addressable guest physical memory. This is the value that hv_vm_config_get_default_ipa_size and hv_vm_config_get_max_ipa_size would return on macOS 13+ for M1 hardware.

---

## Steps

### 1. Attempt install (will fail)

sudo port install colima

# → fails building qemu; accept the dependency prompt with 'y'

### 2. Check the build log for the actual error

grep -E "Error:|error:|Failed|failed|FAILED" \
  /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_emulators_qemu/qemu/main.log \
  | tail -20

### 3. Apply the patch to hvf.c

The source will be in the MacPorts build directory. Apply the patch (attached)

### 4. Build qemu (resuming from patched source)

sudo port -n build qemu

### 5. Install qemu

sudo port -n install qemu

### 6. Install colima (lima builds from source; colima builds from source)

sudo port install colima

Lima and colima will build from source (no pre-built binaries for darwin_21 arm64), but both build successfully without issues.

### 7. Verify

colima version
# colima version v0.10.0

---

Attachments (1)

qemu_10.2_monterey_arm64_fix.patch (1.9 KB) - added by peterwwillis (Peter W) 3 months ago.
Patch to make qemu build succeed on monterey arm64

Download all attachments as: .zip

Change History (6)

Changed 3 months ago by peterwwillis (Peter W)

Patch to make qemu build succeed on monterey arm64

comment:1 Changed 3 months ago by ryandesign (Ryan Carsten Schmidt)

Keywords: haspatch added; qemu removed
Summary: Qemu 10.2 fails on Monterey arm64, but a patch worksqemu @10.2 fails on Monterey arm64, but a patch works

Where is the #endif corresponding to the #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 130000 you added on line 845?

Have you already submitted this patch to the developers of qemu? What is the URL? Did they agree it is correct and will they incorporate it into the next version?

comment:2 Changed 3 months ago by ryandesign (Ryan Carsten Schmidt)

Cc: herbygillot added
Owner: set to raimue
Status: newassigned

Duplicate of #71857 which proposed a different patch. Did you test that one?

comment:3 Changed 3 months ago by ryandesign (Ryan Carsten Schmidt)

Resolution: duplicate
Status: assignedclosed

comment:4 Changed 3 months ago by peterwwillis (Peter W)

My bad, I did not see the other ticket when I looked, not sure why. I reviewed their patch and actually it looks like it introduces a possible bug, as it skips chosen_ipa_bit_size = pa_range; in the else stanza, but then again maybe a further code review would show if that has an impact or not, as it looks like a global? My patch also patches hvf_arm_get_default_ipa_bit_size and hvf_arm_get_max_ipa_bit_size; I have not confirmed that this is absolutely necessary, but I think it depends on what version of the SDK you have installed

Re: the patch view, for some reason the web ui here obscures the entire patch. If you click the link in "Download in other formats: Original format", the entire patch shows up

I did not try to submit patch to Qemu, as their download page (https://www.qemu.org/download/#macos) says "QEMU requires the most recent macOS version that is currently available. Support for the last previous version will be dropped two years after the current version has been released or when Apple drops support for it, whatever comes first."

I assumed Monterey had been too long ago... it looks like EOL was September 2024, so technically it has not been two years yet. I could try them and see if you want?

comment:5 Changed 3 months ago by peterwwillis (Peter W)

Reading #71857 further, it looks like those additional functions do need to be patched: https://trac.macports.org/ticket/71857#comment:4

Note: See TracTickets for help on using tickets.