Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

td-shim: use fixed-size array for ACPI table installation #704

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions td-shim/src/bin/td-shim/acpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,32 @@
// SPDX-License-Identifier: BSD-2-Clause-Patent
extern crate alloc;

use alloc::vec::Vec;
use td_shim_interface::acpi::{calculate_checksum, Rsdp, Xsdt};

use super::*;

#[derive(Default)]
const ACPI_MAX_TABLES: usize = 128;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if VMM inputs more table number > ACPI_MAX_TABLES?


pub struct AcpiTables<'a> {
acpi_memory: &'a mut [u8],
pa: u64,
size: usize,
fadt: Option<(usize, usize)>, // FADT offset in acpi memory
dsdt: Option<usize>, // DSDT offset in acpi memory
table_offset: Vec<usize>,
table_offsets: [usize; ACPI_MAX_TABLES],
num_tables: usize,
}

impl<'a> AcpiTables<'a> {
pub fn new(td_acpi_mem: &'a mut [u8], pa: u64) -> Self {
AcpiTables {
acpi_memory: td_acpi_mem,
pa,
..Default::default()
size: 0,
fadt: None,
dsdt: None,
table_offsets: [0; ACPI_MAX_TABLES],
num_tables: 0,
}
}

Expand Down Expand Up @@ -53,7 +58,7 @@ impl<'a> AcpiTables<'a> {
.expect("Unable to add table into XSDT");
}

for offset in &self.table_offset {
for offset in &self.table_offsets[..self.num_tables] {
xsdt.add_table(self.offset_to_address(*offset))
.expect("Unable to add table into XSDT");
}
Expand Down Expand Up @@ -102,7 +107,7 @@ impl<'a> AcpiTables<'a> {
} else if &header.signature == b"DSDT" {
self.dsdt = Some(self.size);
} else {
for offset in &self.table_offset {
for offset in &self.table_offsets[..self.num_tables] {
// Safe because it's reading data from our own buffer.
let table_header = GenericSdtHeader::read_from(
&self.acpi_memory[*offset..*offset + size_of::<GenericSdtHeader>()],
Expand All @@ -116,7 +121,11 @@ impl<'a> AcpiTables<'a> {
return;
}
}
self.table_offset.push(self.size);
if self.num_tables >= ACPI_MAX_TABLES {
panic!("Number of ACPI table exceeds limit 0x{:X}", ACPI_MAX_TABLES,);
}
self.table_offsets[self.num_tables] = self.size;
self.num_tables += 1;
}

self.acpi_memory[self.size..self.size + table.len()].copy_from_slice(table);
Expand Down