🐛 Ask for a pool of host memory where KVM maps no cached GPU memory

Linux's KVM on arm64 takes a cacheable VM_PFNMAP mapping as a memory slot
only where the CPU has stage-2 forced write-back and CACHE_DIC, and the VM
says so as KVM_CAP_ARM_CACHEABLE_PFNMAP_SUPPORTED. Every host mapping of a
Honeykrisp allocation is VM_PFNMAP, so on an M1 Pro under Fedora Asahi Remix
45 the reims-graphics device's first Shared pool piece failed
KVM_SET_USER_MEMORY_REGION2 with EINVAL, and QEMU exited
(steelbrain/reims-vgpu#174).

The device now sets the library's pool_host_memory where it runs under KVM on
an arm64 host and the VM does not answer the capability, which a kernel older
than it does not either: the pool's blocks are then memfds of the library's
that the GPU imports, which KVM maps as guest memory, cached, as it maps the
guest's RAM. The check is in reims-graphics-pci-kvm.c, which only targets
with KVM link, with its stub beside the others; it asks the VM through
kvm_vm_ioctl, since kvm_vm_check_extension is declared for per-target builds
alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 0d6ff26282)
This commit is contained in:
vintoware authored and Anees Iqbal committed 2026-12-02 01:48:46 -08:00
1 parent 14e100f44c
commit 5d0e52bd2d
4 files changed
+39

No files matched your search

+5
View File
@@ -16,3 +16,8 @@ const ReimsGraphicsPrefaultOps *reims_graphics_kvm_prefault_ops(void)
{
return NULL;
}
bool reims_graphics_kvm_pool_host_memory(void)
{
return false;
}
+15
View File
@@ -18,6 +18,21 @@
#include "reims-graphics-pci-prefault.h"
#include "trace.h"
bool reims_graphics_kvm_pool_host_memory(void)
{
#if defined(__aarch64__)
/*
* The capability is the VM's (KVM_CHECK_EXTENSION on the VM's fd);
* kvm_vm_check_extension is declared for per-target builds alone.
*/
return kvm_enabled() &&
kvm_vm_ioctl(kvm_state, KVM_CHECK_EXTENSION,
KVM_CAP_ARM_CACHEABLE_PFNMAP_SUPPORTED) <= 0;
#else
return false;
#endif
}
bool reims_graphics_kvm_disable_slot_zap_all(void)
{
#ifdef KVM_X86_QUIRK_SLOT_ZAP_ALL
+12
View File
@@ -29,4 +29,16 @@ bool reims_graphics_kvm_disable_slot_zap_all(void);
*/
const ReimsGraphicsPrefaultOps *reims_graphics_kvm_prefault_ops(void);
/*
* Whether the guest's Shared pool's blocks are to be host memory the GPU
* imports: under KVM on an arm64 host whose VM does not answer
* KVM_CAP_ARM_CACHEABLE_PFNMAP_SUPPORTED. KVM takes a cacheable VM_PFNMAP
* mapping, as a GPU driver's mapping of its own memory is, as guest memory
* only where the CPU has stage-2 forced write-back and CACHE_DIC, and a
* kernel that predates the capability answers none; elsewhere the pool's
* first piece's slot is refused, and QEMU exits. A memfd's mapping, as the
* guest's RAM's, is taken. False elsewhere.
*/
bool reims_graphics_kvm_pool_host_memory(void);
#endif
+7
View File
@@ -2634,6 +2634,13 @@ static void reims_graphics_pci_realize(PCIDevice *dev, Error **errp)
reims_graphics_pool_room_machine(&pool_base, &pool_room)) {
config.pool_physical_address = pool_base;
config.pool_physical_length = pool_room;
#ifdef CONFIG_LINUX
/*
* Blocks of host memory where KVM takes no cacheable mapping of the
* GPU's own memory as guest memory (reims_graphics_kvm_pool_host_memory).
*/
config.pool_host_memory = reims_graphics_kvm_pool_host_memory();
#endif
}
/* The windows' input runs from here on; the callbacks need the BHs. */