Skip to content

Commit 05bde6c

Browse files
authored
vmbus_server: support VTL2 channels for vmbusproxy. (#916)
This change makes it possible for vmbusproxy to offer channels to VTL2. Previously, vmbusproxy ignored an offer's target VTL and would always offer to VTL0.
1 parent 057ed6a commit 05bde6c

File tree

3 files changed

+43
-19
lines changed

3 files changed

+43
-19
lines changed

openvmm/hvlite_core/src/worker/dispatch.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,10 +1678,15 @@ impl InitializedVm {
16781678
#[cfg(windows)]
16791679
if let Some(proxy_handle) = vmbus_cfg.vmbusproxy_handle {
16801680
vmbus_proxy = Some(
1681-
vmbus
1682-
.start_kernel_proxy(&vmbus_driver, proxy_handle)
1683-
.await
1684-
.context("failed to start the vmbus proxy")?,
1681+
vmbus_server::ProxyIntegration::start(
1682+
&vmbus_driver,
1683+
proxy_handle,
1684+
vmbus.control(),
1685+
vtl2_vmbus.as_ref().map(|server| server.control().clone()),
1686+
Some(&gm),
1687+
)
1688+
.await
1689+
.context("failed to start the vmbus proxy")?,
16851690
)
16861691
}
16871692

vm/devices/vmbus/vmbus_server/src/lib.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -569,15 +569,6 @@ impl VmbusServer {
569569
let _ = self.task.await;
570570
}
571571

572-
#[cfg(windows)]
573-
pub async fn start_kernel_proxy(
574-
&self,
575-
driver: &(impl pal_async::driver::SpawnDriver + Clone),
576-
handle: ProxyHandle,
577-
) -> std::io::Result<ProxyIntegration> {
578-
ProxyIntegration::start(driver, handle, self.control(), Some(&self.control.mem)).await
579-
}
580-
581572
/// Returns an object that can be used to offer channels.
582573
pub fn control(&self) -> Arc<VmbusServerControl> {
583574
self.control.clone()

vm/devices/vmbus/vmbus_server/src/proxyintegration.rs

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ impl ProxyIntegration {
6767
driver: &(impl SpawnDriver + Clone),
6868
handle: ProxyHandle,
6969
server: Arc<VmbusServerControl>,
70+
vtl2_server: Option<Arc<VmbusServerControl>>,
7071
mem: Option<&GuestMemory>,
7172
) -> io::Result<Self> {
7273
let mut proxy = VmbusProxy::new(driver, handle)?;
@@ -79,7 +80,7 @@ impl ProxyIntegration {
7980
driver
8081
.spawn(
8182
"vmbus_proxy",
82-
proxy_thread(driver.clone(), proxy, server, cancel_ctx),
83+
proxy_thread(driver.clone(), proxy, server, vtl2_server, cancel_ctx),
8384
)
8485
.detach();
8586

@@ -98,15 +99,21 @@ struct ProxyTask {
9899
gpadls: Arc<Mutex<HashMap<u64, HashSet<GpadlId>>>>,
99100
proxy: Arc<VmbusProxy>,
100101
server: Arc<VmbusServerControl>,
102+
vtl2_server: Option<Arc<VmbusServerControl>>,
101103
}
102104

103105
impl ProxyTask {
104-
fn new(control: Arc<VmbusServerControl>, proxy: Arc<VmbusProxy>) -> Self {
106+
fn new(
107+
server: Arc<VmbusServerControl>,
108+
vtl2_server: Option<Arc<VmbusServerControl>>,
109+
proxy: Arc<VmbusProxy>,
110+
) -> Self {
105111
Self {
106112
channels: Arc::new(Mutex::new(HashMap::new())),
107113
gpadls: Arc::new(Mutex::new(HashMap::new())),
108114
proxy,
109-
server: control,
115+
server,
116+
vtl2_server,
110117
}
111118
}
112119

@@ -213,12 +220,31 @@ impl ProxyTask {
213220
offer: vmbus_proxy::vmbusioctl::VMBUS_CHANNEL_OFFER,
214221
incoming_event: Event,
215222
) -> Option<mesh::Receiver<ChannelRequest>> {
223+
let server = match offer.TargetVtl {
224+
0 => self.server.as_ref(),
225+
2 => {
226+
if let Some(server) = self.vtl2_server.as_ref() {
227+
server
228+
} else {
229+
tracing::error!(?offer, "VTL2 offer without VTL2 server");
230+
return None;
231+
}
232+
}
233+
_ => {
234+
tracing::error!(?offer, "unsupported offer VTL");
235+
return None;
236+
}
237+
};
238+
216239
let channel_type = if offer.ChannelFlags & VMBUS_CHANNEL_ENUMERATE_DEVICE_INTERFACE != 0 {
217240
let pipe_mode = u32::from_ne_bytes(offer.UserDefined[..4].try_into().unwrap());
218241
let message_mode = match pipe_mode {
219242
vmbus_proxy::vmbusioctl::VMBUS_PIPE_TYPE_BYTE => false,
220243
vmbus_proxy::vmbusioctl::VMBUS_PIPE_TYPE_MESSAGE => true,
221-
_ => panic!("BUGBUG: unsupported"),
244+
_ => {
245+
tracing::error!(?offer, "unsupported offer pipe mode");
246+
return None;
247+
}
222248
};
223249
ChannelType::Pipe { message_mode }
224250
} else {
@@ -244,7 +270,8 @@ impl ProxyTask {
244270
};
245271
let (request_send, request_recv) = mesh::channel();
246272
let (server_request_send, server_request_recv) = mesh::channel();
247-
let recv = self.server.send.call_failable(
273+
274+
let recv = server.send.call_failable(
248275
OfferRequest::Offer,
249276
OfferInfo {
250277
params: offer.into(),
@@ -429,11 +456,12 @@ async fn proxy_thread(
429456
spawner: impl Spawn,
430457
proxy: VmbusProxy,
431458
server: Arc<VmbusServerControl>,
459+
vtl2_server: Option<Arc<VmbusServerControl>>,
432460
mut cancel: CancelContext,
433461
) {
434462
let (send, recv) = mesh::channel();
435463
let proxy = Arc::new(proxy);
436-
let task = Arc::new(ProxyTask::new(server, Arc::clone(&proxy)));
464+
let task = Arc::new(ProxyTask::new(server, vtl2_server, Arc::clone(&proxy)));
437465
let offers = task.run_offers(send);
438466
let requests = task.run_channel_requests(spawner, recv);
439467
let cancellation = async {

0 commit comments

Comments
 (0)