Skip to content

Commit 09efefb

Browse files
committed
Inform openhcl about self hint and print it
1 parent 727fd7d commit 09efefb

File tree

8 files changed

+57
-0
lines changed

8 files changed

+57
-0
lines changed

openhcl/bootloader_fdt_parser/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ pub struct ParsedBootDtInfo {
169169
/// VTL2 range for private pool memory.
170170
#[inspect(iter_by_index)]
171171
pub private_pool_ranges: Vec<MemoryRangeWithNode>,
172+
/// Source of DMA hint calculation.
173+
pub dma_hint_self: bool,
172174
}
173175

174176
fn err_to_owned(e: fdt::parser::Error<'_>) -> anyhow::Error {
@@ -207,6 +209,7 @@ struct OpenhclInfo {
207209
memory_allocation_mode: MemoryAllocationMode,
208210
isolation: IsolationType,
209211
private_pool_ranges: Vec<MemoryRangeWithNode>,
212+
dma_hint_self: bool,
210213
}
211214

212215
fn parse_memory_openhcl(node: &Node<'_>) -> anyhow::Result<AddressRange> {
@@ -394,6 +397,11 @@ fn parse_openhcl(node: &Node<'_>) -> anyhow::Result<OpenhclInfo> {
394397
.transpose()
395398
.context("unable to read vtl0-alias-map")?;
396399

400+
let dma_hint_self = matches!(
401+
try_find_property(node, "dma-hint").and_then(|p| p.read_str().ok()),
402+
Some("self")
403+
);
404+
397405
// Extract vmbus mmio information from the overall memory map.
398406
let vtl0_mmio = memory
399407
.iter()
@@ -416,6 +424,7 @@ fn parse_openhcl(node: &Node<'_>) -> anyhow::Result<OpenhclInfo> {
416424
memory_allocation_mode,
417425
isolation,
418426
private_pool_ranges,
427+
dma_hint_self,
419428
})
420429
}
421430

@@ -509,6 +518,7 @@ impl ParsedBootDtInfo {
509518
let mut isolation = IsolationType::None;
510519
let mut vtl2_reserved_range = MemoryRange::EMPTY;
511520
let mut private_pool_ranges = Vec::new();
521+
let mut dma_hint_self = false;
512522

513523
let parser = Parser::new(raw)
514524
.map_err(err_to_owned)
@@ -538,6 +548,7 @@ impl ParsedBootDtInfo {
538548
memory_allocation_mode: n_memory_allocation_mode,
539549
isolation: n_isolation,
540550
private_pool_ranges: n_private_pool_ranges,
551+
dma_hint_self: n_dma_hint_self,
541552
} = parse_openhcl(&child)?;
542553
vtl0_mmio = n_vtl0_mmio;
543554
config_ranges = n_config_ranges;
@@ -548,6 +559,7 @@ impl ParsedBootDtInfo {
548559
isolation = n_isolation;
549560
vtl2_reserved_range = n_vtl2_reserved_range;
550561
private_pool_ranges = n_private_pool_ranges;
562+
dma_hint_self = n_dma_hint_self;
551563
}
552564

553565
_ if child.name.starts_with("memory@") => {
@@ -580,6 +592,7 @@ impl ParsedBootDtInfo {
580592
isolation,
581593
vtl2_reserved_range,
582594
private_pool_ranges,
595+
dma_hint_self,
583596
})
584597
}
585598
}
@@ -945,6 +958,7 @@ mod tests {
945958
range: MemoryRange::new(0x60000..0x70000),
946959
vnode: 0,
947960
}],
961+
dma_hint_self: false,
948962
};
949963

950964
let dt = build_dt(&orig_info).unwrap();

openhcl/openhcl_boot/src/dt.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,11 @@ pub fn write_dt(
483483
openhcl_builder = openhcl_builder.add_u64(p_vtl0_alias_map, data)?;
484484
}
485485

486+
if partition_info.dma_hint_self {
487+
let p_dma_hint = openhcl_builder.add_string("dma-hint")?;
488+
openhcl_builder = openhcl_builder.add_str(p_dma_hint, "self")?;
489+
}
490+
486491
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
487492
struct Vtl2MemoryEntry {
488493
range: MemoryRange,

openhcl/openhcl_boot/src/host_params/dt.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ impl PartitionInfo {
456456
.vtl2_used_ranges
457457
.extend(flatten_ranges(used_ranges.iter().copied()));
458458

459+
let mut vtl2_dma_hint_self = false;
459460
// Decide if we will reserve memory for a VTL2 private pool. Parse this
460461
// from the final command line, or the host provided device tree value.
461462
let vtl2_gpa_pool_size = {
@@ -472,6 +473,7 @@ impl PartitionInfo {
472473
{
473474
// If host did not provide the DMA hint value, re-evaluate
474475
// it internally if conditions satisfy.
476+
vtl2_dma_hint_self = true;
475477
vtl2_calculate_dma_hint(parsed.cpu_count(), storage)
476478
} else {
477479
hostval
@@ -512,6 +514,7 @@ impl PartitionInfo {
512514
.extend(flatten_ranges(used_ranges.iter().copied()));
513515

514516
storage.vtl2_pool_memory = pool;
517+
storage.dma_hint_self = vtl2_dma_hint_self;
515518
}
516519

517520
// If we can trust the host, use the provided alias map
@@ -540,6 +543,7 @@ impl PartitionInfo {
540543
entropy,
541544
vtl0_alias_map: _,
542545
nvme_keepalive,
546+
dma_hint_self,
543547
} = storage;
544548

545549
assert!(!vtl2_used_ranges.is_empty());
@@ -562,6 +566,7 @@ impl PartitionInfo {
562566
*gic = parsed.gic.clone();
563567
*entropy = parsed.entropy.clone();
564568
*nvme_keepalive = parsed.nvme_keepalive;
569+
*dma_hint_self = vtl2_dma_hint_self;
565570

566571
Ok(Some(storage))
567572
}

openhcl/openhcl_boot/src/host_params/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ pub struct PartitionInfo {
9595
pub vtl0_alias_map: Option<u64>,
9696
/// Host is compatible with DMA preservation / NVMe keep-alive.
9797
pub nvme_keepalive: bool,
98+
/// DMA hint was calculated in boot-shim instead of host.
99+
pub dma_hint_self: bool,
98100
}
99101

100102
impl PartitionInfo {
@@ -126,6 +128,7 @@ impl PartitionInfo {
126128
entropy: None,
127129
vtl0_alias_map: None,
128130
nvme_keepalive: false,
131+
dma_hint_self: false,
129132
}
130133
}
131134

openhcl/openhcl_boot/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,7 @@ mod test {
956956
entropy: None,
957957
vtl0_alias_map: None,
958958
nvme_keepalive: false,
959+
dma_hint_self: false,
959960
}
960961
}
961962

openhcl/openhcl_dma_manager/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,20 @@ impl OpenhclDmaManager {
407407

408408
Ok(())
409409
}
410+
411+
/// Return shared pool size in bytes.
412+
pub fn shared_pool_size(&self) -> u64 {
413+
self.shared_pool
414+
.as_ref()
415+
.map_or(0, |pool| pool.total_size())
416+
}
417+
418+
/// Return private pool size in bytes.
419+
pub fn private_pool_size(&self) -> u64 {
420+
self.private_pool
421+
.as_ref()
422+
.map_or(0, |pool| pool.total_size())
423+
}
410424
}
411425

412426
/// A spawner for creating DMA clients.

openhcl/underhill_core/src/worker.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,6 +1518,14 @@ async fn new_underhill_vm(
15181518
.context("failed to restore global dma manager")?;
15191519
}
15201520

1521+
// Print important info about DMA sizes.
1522+
tracing::info!(
1523+
dma_hint_self = boot_info.dma_hint_self,
1524+
shared_pool_size = shared_pool_size,
1525+
private_pool_size = dma_manager.private_pool_size(),
1526+
"dma pool"
1527+
);
1528+
15211529
// Test with the highest VTL for which we have a GuestMemory object
15221530
let highest_vtl_gm = gm.vtl1().unwrap_or(gm.vtl0());
15231531

vm/page_pool_alloc/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ pub struct PagePool {
504504
inner: Arc<PagePoolInner>,
505505
#[inspect(iter_by_index)]
506506
ranges: Vec<MemoryRange>,
507+
total_len: u64,
507508
}
508509

509510
impl PagePool {
@@ -557,6 +558,7 @@ impl PagePool {
557558
mapping,
558559
}),
559560
ranges: memory.to_vec(),
561+
total_len: total_len as u64,
560562
})
561563
}
562564

@@ -621,6 +623,11 @@ impl PagePool {
621623
Ok(())
622624
}
623625
}
626+
627+
/// Returns the total size of the pool in bytes.
628+
pub fn total_size(&self) -> u64 {
629+
self.total_len
630+
}
624631
}
625632

626633
/// A spawner for [`PagePoolAllocator`] instances.

0 commit comments

Comments
 (0)