Skip to content

Commit

Permalink
vmbus: pass channel GuestMemory for SimpleVmbusDevice::open (#455) (#472
Browse files Browse the repository at this point in the history
)

Simple vmbus devices may also need to do DMA, plumb the associated guest
memory object to the `SimpleVmbusDevice::open` call. A upcoming change
to implement AK cert renewal for the GED needs this.

Cherry pick of #455
  • Loading branch information
chris-oo authored Dec 13, 2024
1 parent e4eb460 commit 4bae562
Show file tree
Hide file tree
Showing 19 changed files with 42 additions and 4 deletions.
6 changes: 6 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2228,6 +2228,7 @@ dependencies = [
"async-trait",
"get_protocol",
"get_resources",
"guestmem",
"guid",
"inspect",
"mesh",
Expand All @@ -2248,6 +2249,7 @@ dependencies = [
"futures",
"get_protocol",
"get_resources",
"guestmem",
"guid",
"inspect",
"mesh",
Expand Down Expand Up @@ -2276,6 +2278,7 @@ dependencies = [
"async-trait",
"get_protocol",
"get_resources",
"guestmem",
"inspect",
"serde",
"serde_json",
Expand Down Expand Up @@ -2890,6 +2893,7 @@ dependencies = [
"async-trait",
"futures",
"futures-concurrency",
"guestmem",
"hyperv_ic_protocol",
"hyperv_ic_resources",
"inspect",
Expand Down Expand Up @@ -7523,6 +7527,7 @@ version = "0.0.0"
dependencies = [
"async-trait",
"bitfield-struct",
"guestmem",
"guid",
"inspect",
"open_enum",
Expand Down Expand Up @@ -7736,6 +7741,7 @@ version = "0.0.0"
dependencies = [
"anyhow",
"async-trait",
"guestmem",
"inspect",
"inspect_counters",
"serial_core",
Expand Down
1 change: 1 addition & 0 deletions vm/devices/get/guest_crash_device/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ rust-version.workspace = true
[dependencies]
get_protocol.workspace = true
get_resources.workspace = true
guestmem.workspace = true
guid.workspace = true
inspect.workspace = true
mesh.workspace = true
Expand Down
1 change: 1 addition & 0 deletions vm/devices/get/guest_crash_device/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ impl SimpleVmbusDevice for GuestCrashDevice {
fn open(
&mut self,
channel: vmbus_channel::RawAsyncChannel<GpadlRingMem>,
_guest_memory: guestmem::GuestMemory,
) -> Result<Self::Runner, ChannelOpenError> {
let pipe = MessagePipe::new(channel)?;
Ok(GuestCrashChannel {
Expand Down
1 change: 1 addition & 0 deletions vm/devices/get/guest_emulation_device/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ rust-version.workspace = true
get_protocol.workspace = true
get_resources.workspace = true

guestmem.workspace = true
power_resources.workspace = true
video_core.workspace = true
vmbus_async.workspace = true
Expand Down
12 changes: 10 additions & 2 deletions vm/devices/get/guest_emulation_device/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use get_resources::ged::GuestEmulationRequest;
use get_resources::ged::ModifyVtl2SettingsError;
use get_resources::ged::SaveRestoreError;
use get_resources::ged::Vtl0StartError;
use guestmem::GuestMemory;
use guid::Guid;
use inspect::Inspect;
use inspect::InspectMut;
Expand Down Expand Up @@ -248,9 +249,10 @@ impl SimpleVmbusDevice for GuestEmulationDevice {
fn open(
&mut self,
channel: RawAsyncChannel<GpadlRingMem>,
guest_memory: GuestMemory,
) -> Result<Self::Runner, ChannelOpenError> {
let pipe = MessagePipe::new(channel)?;
Ok(GedChannel::new(pipe))
Ok(GedChannel::new(pipe, guest_memory))
}

async fn run(
Expand Down Expand Up @@ -294,6 +296,11 @@ pub struct GedChannel<T: RingMem = GpadlRingMem> {
vtl0_start_report: Option<Result<(), Vtl0StartError>>,
#[inspect(with = "Option::is_some")]
modify: Option<mesh::OneshotSender<Result<(), ModifyVtl2SettingsError>>>,
// TODO: allow unused temporarily as a follow up change will use it to
// implement AK cert renewal.
#[inspect(skip)]
#[allow(dead_code)]
gm: GuestMemory,
}

struct InProgressSave {
Expand All @@ -308,13 +315,14 @@ enum GedState {
}

impl<T: RingMem + Unpin> GedChannel<T> {
fn new(channel: MessagePipe<T>) -> Self {
fn new(channel: MessagePipe<T>, guest_memory: GuestMemory) -> Self {
Self {
channel,
save: None,
state: GedState::Init,
vtl0_start_report: None,
modify: None,
gm: guest_memory,
}
}

Expand Down
3 changes: 2 additions & 1 deletion vm/devices/get/guest_emulation_device/src/test_utilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use get_protocol::HostRequests;
use get_protocol::SecureBootTemplateType;
use get_protocol::UefiConsoleMode;
use get_resources::ged::GuestEmulationRequest;
use guestmem::GuestMemory;
use mesh::rpc::RpcSend;
use pal_async::task::Spawn;
use pal_async::task::Task;
Expand Down Expand Up @@ -276,7 +277,7 @@ pub fn create_host_channel(
task.insert(
spawn,
"automated GED host channel",
GedChannel::new(host_vmbus),
GedChannel::new(host_vmbus, GuestMemory::empty()),
);
task.start();

Expand Down
1 change: 1 addition & 0 deletions vm/devices/get/guest_emulation_log/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ rust-version.workspace = true
[dependencies]
get_protocol.workspace = true
get_resources.workspace = true
guestmem.workspace = true
vmbus_async.workspace = true
vmbus_channel.workspace = true
vmbus_ring.workspace = true
Expand Down
1 change: 1 addition & 0 deletions vm/devices/get/guest_emulation_log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ impl SimpleVmbusDevice for GuestEmulationLog {
fn open(
&mut self,
channel: RawAsyncChannel<GpadlRingMem>,
_guest_memory: guestmem::GuestMemory,
) -> Result<Self::Runner, ChannelOpenError> {
let pipe = MessagePipe::new(channel)?;
Ok(GelChannel::new(pipe))
Expand Down
1 change: 1 addition & 0 deletions vm/devices/hyperv_ic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"
rust-version.workspace = true

[dependencies]
guestmem.workspace = true
hyperv_ic_protocol.workspace = true
hyperv_ic_resources.workspace = true
vmbus_async.workspace = true
Expand Down
1 change: 1 addition & 0 deletions vm/devices/hyperv_ic/src/shutdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ impl SimpleVmbusDevice for ShutdownIc {
fn open(
&mut self,
channel: RawAsyncChannel<GpadlRingMem>,
_guest_memory: guestmem::GuestMemory,
) -> Result<Self::Runner, ChannelOpenError> {
self.open_channel(channel, None)
}
Expand Down
1 change: 1 addition & 0 deletions vm/devices/pci/vpci/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,7 @@ impl SimpleVmbusDevice for VpciChannel {
fn open(
&mut self,
channel: RawAsyncChannel<GpadlRingMem>,
_guest_memory: guestmem::GuestMemory,
) -> Result<Self::Runner, ChannelOpenError> {
Ok(VpciChannelState {
conn: Connection {
Expand Down
1 change: 1 addition & 0 deletions vm/devices/serial/vmbus_serial_host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"
rust-version.workspace = true

[dependencies]
guestmem.workspace = true
serial_core.workspace = true
vmbus_async.workspace = true
vmbus_channel.workspace = true
Expand Down
1 change: 1 addition & 0 deletions vm/devices/serial/vmbus_serial_host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ impl SimpleVmbusDevice for Serial {
fn open(
&mut self,
channel: RawAsyncChannel<GpadlRingMem>,
_guest_memory: guestmem::GuestMemory,
) -> Result<Self::Runner, ChannelOpenError> {
let pipe = MessagePipe::new(channel)?;
Ok(SerialChannel::new(pipe))
Expand Down
1 change: 1 addition & 0 deletions vm/devices/uidevices/src/keyboard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ impl SimpleVmbusDevice for Keyboard {
fn open(
&mut self,
channel: RawAsyncChannel<GpadlRingMem>,
_guest_memory: guestmem::GuestMemory,
) -> Result<Self::Runner, ChannelOpenError> {
let pipe = MessagePipe::new_raw(channel)?;
Ok(KeyboardChannel::new(pipe, ChannelState::default()))
Expand Down
1 change: 1 addition & 0 deletions vm/devices/uidevices/src/mouse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ impl SimpleVmbusDevice for Mouse {
fn open(
&mut self,
channel: RawAsyncChannel<GpadlRingMem>,
_guest_memory: guestmem::GuestMemory,
) -> Result<Self::Runner, ChannelOpenError> {
let pipe = MessagePipe::new(channel)?;
Ok(MouseChannel::new(pipe, ChannelState::default()))
Expand Down
1 change: 1 addition & 0 deletions vm/devices/uidevices/src/video/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ impl SimpleVmbusDevice for Video {
fn open(
&mut self,
channel: RawAsyncChannel<GpadlRingMem>,
_guest_memory: guestmem::GuestMemory,
) -> Result<Self::Runner, ChannelOpenError> {
let pipe = MessagePipe::new(channel)?;
Ok(VideoChannel::new(pipe, ChannelState::default()))
Expand Down
1 change: 1 addition & 0 deletions vm/devices/vmbus/vmbfs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ rust-version.workspace = true
vmbfs_resources.workspace = true
vm_resource.workspace = true

guestmem.workspace = true
vmbus_async.workspace = true
vmbus_channel.workspace = true
vmcore.workspace = true
Expand Down
1 change: 1 addition & 0 deletions vm/devices/vmbus/vmbfs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ impl SimpleVmbusDevice for VmbfsDevice {
fn open(
&mut self,
channel: vmbus_channel::RawAsyncChannel<GpadlRingMem>,
_guest_memory: guestmem::GuestMemory,
) -> Result<Self::Runner, vmbus_channel::channel::ChannelOpenError> {
Ok(VmbfsChannel {
state: State::VersionRequest,
Expand Down
10 changes: 9 additions & 1 deletion vm/devices/vmbus/vmbus_channel/src/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::gpadl_ring::gpadl_channel;
use crate::gpadl_ring::GpadlRingMem;
use crate::RawAsyncChannel;
use async_trait::async_trait;
use guestmem::GuestMemory;
use inspect::Inspect;
use inspect::InspectMut;
use mesh::payload::Protobuf;
Expand Down Expand Up @@ -61,6 +62,7 @@ pub trait SimpleVmbusDevice: 'static + Send {
fn open(
&mut self,
channel: RawAsyncChannel<GpadlRingMem>,
guest_memory: GuestMemory,
) -> Result<Self::Runner, ChannelOpenError>;

/// Runs an open channel until `stop` is signaled.
Expand Down Expand Up @@ -224,7 +226,13 @@ impl<T: SimpleVmbusDevice> VmbusDevice for SimpleDeviceWrapper<T> {
) -> Result<(), anyhow::Error> {
assert!(self.running);
let channel = self.build_channel(open_request)?;
let runner = self.device.task_mut().0.open(channel)?;
let gm = self
.resources
.offer_resources
.guest_memory(open_request)
.clone();
let runner = self.device.task_mut().0.open(channel, gm)?;

self.insert_runner(runner);
self.device.start();
Ok(())
Expand Down

0 comments on commit 4bae562

Please sign in to comment.