Hello,
> On 19. Dec 2025, at 19:37, Joelle van Dyne <[email protected]> wrote:
>
> The IPA granule is the smallest page size hv_vm_map() support. For Venus, we
> need to support 4KiB pages. macOS 26 introduces a public API for setting
> the granule size. We can only use this when compiled with macOS 26 SDK and
> run on macOS 26+. Otherwise, we fall back to an older, private, API which
> achieves the same purpose.
>
Let’s have an HVF_NO_PRIVATE_API define (or the opposite) to have a single
toggle to disable all private API use at build time
> +
> + /* older macOS need to use a private API */
> + if (!set_ipa_granule) {
> + set_ipa_granule = dlsym(RTLD_NEXT, "_hv_vm_config_set_ipa_granule");
> + }
> + if (set_ipa_granule) {
> + return set_ipa_granule(config, ipa_granule_size);
> + } else if (ipa_granule_size != page_size) {
> + error_report("Failed to find _hv_vm_config_set_ipa_granule");
> + return HV_UNSUPPORTED;
> + }
> +
> + return HV_SUCCESS;
> +}
> +
> +hv_return_t hvf_arch_vm_create(MachineState *ms, uint32_t pa_range,
> + uint32_t ipa_granule_size)
> {
> hv_return_t ret;
> hv_vm_config_t config = hv_vm_config_create();
> @@ -891,6 +932,13 @@ hv_return_t hvf_arch_vm_create(MachineState *ms,
> uint32_t pa_range)
> }
> chosen_ipa_bit_size = pa_range;
>
The PA range is actually different depending on the IPA granule size.
An example from M4 Max:
% sysctl -a | grep ipa
kern.hv.ipa_size_16k: 4398046511104
kern.hv.ipa_size_4k: 1099511627776
> + if (ipa_granule_size) {
> + ret = hvf_set_ipa_granule(config, ipa_granule_size);
> + if (ret != HV_SUCCESS) {
> + goto cleanup;
> + }
> + }
> +
> ret = hv_vm_create(config);
>