In-place check: the dma-buf class's export carries the device-address flag its imports carry

On the Iris Xe (ANV, Mesa 26.2.6) the check's DmaBuf class stayed Unchecked for every access
and row end, so a guest's surfaces over dma-buf pages took the shadow (the reims guest counted 756
of 786 shadows there). ExportedPages::make exported its pages fine, but their no-copy buffer was
refused (Unsupported, HostMemory, NotRepresentable) both pointer-first and dma-buf-only (probe
job 7595), so the class had no pages to check.

The cause, measured by a matrix of exports and imports of a dma-buf of the device's own memory
(probe job 7667, every host-visible type, 1, 2, 5 and 6, against every other, each with and
without VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT): ANV takes the import exactly where its
device-address flag matches the allocation's, and refuses it with
VK_ERROR_INVALID_EXTERNAL_HANDLE where it differs, whatever the memory types. The export was
allocated without the flag; import_dma_buf imports a buffer's dma-buf with it (bufferDeviceAddress
is enabled there), and every block of the runtime's own carries it (BlockMaker::make_as).

- ExportedPages::make allocates with the device-address flag where the device enables
  bufferDeviceAddress, as every allocation of the runtime's does.
- import_dma_buf gives an image's dedicated import the flag too, so every import of one dma-buf
  (the check's buffer and its textures' images share one) and the device's own allocation of it
  agree.
- ExportedPages::make takes a host-cached type first, system memory before device-local: on the
  Iris every host-visible type is device-local, so the old rule (cached system memory, else
  system memory, else the first) took type 1, which is uncached, and the whole check took 19.0 s
  there (job 7667). RADV and NVIDIA, whose cached types are system memory, keep the type they
  had.
- CHECK_VERSION 9: a record of 8 holds the DmaBuf class unchecked on ANV, which the check now
  answers.
- The check's device test (the_in_place_check_imports_its_dma_buf_pages_as_dma_bufs) passed where
  the device exported pages it then refused to import, as "exports no dma-buf pages"; such a
  refusal now fails it. Before this fix that is what the Iris did (job 7595: both imports
  refused).
- The module doc no longer says ANV takes its own mapped allocation's pointer: lavapipe does
  (job 7573), ANV refuses it (job 7667).

Verified with the flag fix alone (job 7667, ms01 Iris, release --cfg m2v_gpu at the probe tree
c2e854b698): the device test passed, with "pointer-first import over the dma-buf true, dma-buf-only
true; the DmaBuf verdicts [Passed, Failed, Failed, Passed, Passed, Passed, Passed, Passed]" (rows
inside lines: reads, renders, writes, buffer writes; then rows on lines) and the guest's 234x18
BGRA8Unorm texture at 1024-byte rows in place. A fresh check answered DmaBuf as Fresh and Pointer
answer (renders and writes Failed only for rows inside lines). The cached type and the test's
refusal check: pending (next Iris run).

(cherry picked from commit 8bbc7686c038ae7ca309361aced2219e434f5d1c)
This commit is contained in:
Anees Iqbal committed 2026-11-08 01:56:14 -08:00
1 parent 5afaff4b8e
commit aafecf768a
4 files changed
+53 -29

No files matched your search

+25 -14
View File
@@ -1528,11 +1528,18 @@ unsafe impl Send for ExportedPages {}
impl ExportedPages {
/// `length` bytes of host-visible, host-coherent memory, exported as a dma-buf and mapped, of
/// the first such type that is host-cached and not device-local where one is (system memory as
/// the CPU caches it, as a guest's pages are; the check reads every byte back, which took 3.1 s
/// for a 3840x2160 surface's 33 MB through RADV's uncached type on the Radeon 780M, against
/// 7.2 ms cached), else not device-local; `None` where the device imports no dma-bufs, makes no
/// images over them, exports no such memory but as a dedicated allocation, or refuses it.
/// the first such type that is host-cached, one that is not device-local before one that is,
/// else the first that is not device-local, else the first: memory as the CPU caches it, as a
/// guest's pages are, which the check reads every byte of back. That took 3.1 s for a
/// 3840x2160 surface's 33 MB through RADV's uncached type on the Radeon 780M, against 7.2 ms
/// cached; and on the Iris Xe (ANV), whose host-visible types are all device-local, the whole
/// check took 19.0 s over its first type, which is uncached. Allocated with the device-address
/// flag where the device enables `bufferDeviceAddress`, as each of the runtime's allocations
/// and imports is: ANV (Mesa 26.2.6) refuses an import of a dma-buf of its own memory whose
/// flag differs from the allocation's (`VK_ERROR_INVALID_EXTERNAL_HANDLE`, of every memory
/// type), which left the check's class unchecked there. `None` where the device imports no
/// dma-bufs, makes no images over them, exports no such memory but as a dedicated allocation,
/// or refuses it.
pub(super) fn make(device: &Device, length: u64) -> Option<ExportedPages> {
let shared = device.shared();
let importer = shared.host_import.as_ref().ok()?;
@@ -1570,23 +1577,27 @@ impl ExportedPages {
.map_while(|index| memory.type_flags(index).map(|flags| (index, flags)))
.filter(|(_, flags)| flags.contains(wanted))
.collect();
let system = |cached: bool| {
types.iter().find(|(_, flags)| {
!flags.contains(vk::MemoryPropertyFlags::DEVICE_LOCAL)
&& (!cached || flags.contains(vk::MemoryPropertyFlags::HOST_CACHED))
// Host-cached first, then system memory first; the first of the best.
(types.iter())
.min_by_key(|(_, flags)| {
(
!flags.contains(vk::MemoryPropertyFlags::HOST_CACHED),
flags.contains(vk::MemoryPropertyFlags::DEVICE_LOCAL),
)
})
};
system(true)
.or(system(false))
.or(types.first())
.map(|&(index, _)| index)?
};
let raw_device = shared.vk();
let mut export = vk::ExportMemoryAllocateInfo::default().handle_types(DMA_BUF);
let info = vk::MemoryAllocateInfo::default()
let mut flags =
vk::MemoryAllocateFlagsInfo::default().flags(vk::MemoryAllocateFlags::DEVICE_ADDRESS);
let mut info = vk::MemoryAllocateInfo::default()
.allocation_size(length)
.memory_type_index(type_index)
.push_next(&mut export);
if shared.device_address {
info = info.push_next(&mut flags);
}
// SAFETY: the device is live; the type exports dma-bufs of a buffer's memory (above).
let memory = unsafe { crate::creation::allocate_memory(raw_device, &info) }.ok()?;
let free = || {
@@ -127,10 +127,12 @@
//! waiter's `vkAllocateCommandBuffers` faulted on the magic (an M3 Max under MoltenVK 1.4.2,
//! one run of three), where the same work with no check running did not in 30 000 rounds.
//! - **Its dma-bufs.** The runtime runs no `udmabuf` code, so the dma-buf class's pages are an
//! allocation of the device's own, host-visible and exported as a dma-buf, mapped, and imported
//! only as that dma-buf (`HostMemory::dma_buf_only`), never by their pointer, which a driver may
//! take too (ANV's own mapped allocation); the check's source answers each request over them
//! with that dma-buf. The buffer's import, the image and its first move are the product's.
//! allocation of the device's own, host-visible and exported as a dma-buf, mapped
//! (`dma_buf::ExportedPages`: host-cached where a type is, and with the device-address flag its
//! imports carry), and imported only as that dma-buf (`HostMemory::dma_buf_only`), never by
//! their pointer, which a driver may take too (lavapipe takes its own mapped allocation's; ANV
//! refuses it); the check's source answers each request over them with that dma-buf. The
//! buffer's import, the image and its first move are the product's.
use crate::check_draw::CheckDraw;
use crate::device::holds::Holder;
+12 -9
View File
@@ -2010,8 +2010,12 @@ impl Memory {
/// Import the dma-buf `fd`, `size` bytes, as memory of the best type of `class` among
/// `allowed` (the types both the dma-buf and what is bound in it take): the memory and its
/// type, the caller's to free (`dma_buf.rs`'s `DmaBufPages`), in no block and never mapped.
/// For a buffer, allocated with the device-address flag where the device enables
/// `bufferDeviceAddress`; for `image`, its dedicated allocation (`size` its requirements').
/// Allocated with the device-address flag where the device enables `bufferDeviceAddress`, as
/// every block of the runtime's is (`BlockMaker::make_as`), and for `image` as its dedicated
/// allocation (`size` its requirements'): every import of one dma-buf, a buffer's and its
/// textures' images', and the device's own allocation of it agree, as ANV (Mesa 26.2.6)
/// refuses an import of memory it holds whose flag differs (`VK_ERROR_INVALID_EXTERNAL_HANDLE`,
/// of every memory type: `dma_buf::ExportedPages`).
/// Refused when no type of `class` is among `allowed`, else with the failure of the last type
/// tried.
///
@@ -2058,13 +2062,12 @@ impl Memory {
.allocation_size(size)
.memory_type_index(type_index)
.push_next(&mut import);
match image {
Some(image) => {
dedicated = dedicated.image(image);
info = info.push_next(&mut dedicated);
}
None if self.device_address => info = info.push_next(&mut flags),
None => {}
if let Some(image) = image {
dedicated = dedicated.image(image);
info = info.push_next(&mut dedicated);
}
if self.device_address {
info = info.push_next(&mut flags);
}
// SAFETY: `info` and its chain live for the call; the type index is the device's and
// allows the dma-buf (and the image, unbound and made for dma-bufs, whose size this
@@ -310,7 +310,8 @@ fn texture_ids_keep_metals_order_while_the_in_place_check_runs() {
/// A no-copy buffer of `length` bytes over an allocation of `device`'s own exported as a dma-buf
/// and mapped (`dma_buf::ExportedPages`, the check's dma-buf pages), with a source of that
/// dma-buf, imported only as it where `only` (`HostMemory::dma_buf_only`), else as any no-copy
/// buffer's pages are, the pointer first. `None` where the device exports no such pages.
/// buffer's pages are, the pointer first. `None` where the device exports no such pages; pages it
/// exports but refuses to import fail the test, as the check's class would stay unchecked.
#[cfg(target_os = "linux")]
fn exported_buffer(device: &Device, length: u64, only: bool) -> Option<Buffer> {
let exported = crate::dma_buf::ExportedPages::make(device, length)?;
@@ -331,7 +332,14 @@ fn exported_buffer(device: &Device, length: u64, only: bool) -> Option<Buffer> {
};
let descriptor = BufferDescriptor::new(length, ResourceOptions::shared(), contents)
.with_placement(AddressPlacement::Outside);
device.new_buffer_with_descriptor(descriptor).ok()
match device.new_buffer_with_descriptor(descriptor) {
Ok(buffer) => Some(buffer),
Err(error) => panic!(
"{}: the device exports dma-buf pages it refuses to import (dma-buf only {only}): \
{error:?}",
device.name()
),
}
}
/// The device's check imports its dma-buf class's pages only as their dma-buf, never by their