IMO, the CPU behavior is a bug, even if the behavior is working as intended for
the microarchitecture. I.e. this should be treated as an erratum.
- apic->regs = (void *)get_zeroed_page(GFP_KERNEL_ACCOUNT);
+ if (kvm_x86_ops.alloc_apic_backing_page)
+ apic->regs = kvm_x86_ops.alloc_apic_backing_page(vcpu);
This can be a static_call().
This isn't "finding" anything, it's identifying which of the two pages is
_guaranteed_ to be unaligned. The whole function needs a much bigger comment to
explain what's going on.
+ pfn = page_to_pfn(p);
+ if (IS_ALIGNED(__pfn_to_phys(pfn), PMD_SIZE)) {
+ pfn++;
+ __free_page(p);
+ } else {
+ __free_page(pfn_to_page(pfn + 1));
+ }
+
+ return pfn_to_page(pfn);
+}