mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-09 20:04:20 +00:00
devices: vhost-user: wl: fix shared memory
Fix shared memory support for vhost-user wl implementation. Handle set_slave_req_fd being called before get_shared_memory_regions and make sure the wl device only tries to get its shared memory mapper once. BUG=None TEST=crosvm device wl Change-Id: I724712399bd6a9ffbffb22dd69d431f54df58282 Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3965812 Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org> Commit-Queue: David Stevens <stevensd@chromium.org>
This commit is contained in:
parent
cf303afa83
commit
e72be7b593
2 changed files with 24 additions and 21 deletions
|
@ -372,7 +372,6 @@ where
|
|||
mem: Option<GuestMemory>,
|
||||
backend: Box<dyn VhostUserBackend>,
|
||||
ops: O,
|
||||
shmid: Option<u8>,
|
||||
}
|
||||
|
||||
impl DeviceRequestHandler<VhostUserRegularOps> {
|
||||
|
@ -400,7 +399,6 @@ where
|
|||
mem: None,
|
||||
backend,
|
||||
ops,
|
||||
shmid: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -648,7 +646,10 @@ impl<O: VhostUserPlatformOps> VhostUserSlaveReqHandlerMut for DeviceRequestHandl
|
|||
}
|
||||
|
||||
fn set_slave_req_fd(&mut self, ep: Box<dyn Endpoint<SlaveReq>>) {
|
||||
let conn = VhostBackendReqConnection::new(Slave::new(ep), self.shmid);
|
||||
let conn = VhostBackendReqConnection::new(
|
||||
Slave::new(ep),
|
||||
self.backend.get_shared_memory_region().map(|r| r.id),
|
||||
);
|
||||
self.backend.set_backend_req_connection(conn);
|
||||
}
|
||||
|
||||
|
@ -684,7 +685,6 @@ impl<O: VhostUserPlatformOps> VhostUserSlaveReqHandlerMut for DeviceRequestHandl
|
|||
|
||||
fn get_shared_memory_regions(&mut self) -> VhostResult<Vec<VhostSharedMemoryRegion>> {
|
||||
Ok(if let Some(r) = self.backend.get_shared_memory_region() {
|
||||
self.shmid = Some(r.id);
|
||||
vec![VhostSharedMemoryRegion::new(r.id, r.length)]
|
||||
} else {
|
||||
Vec::new()
|
||||
|
|
|
@ -224,22 +224,22 @@ impl VhostUserBackend for WlBackend {
|
|||
..
|
||||
} = self;
|
||||
|
||||
let mapper = {
|
||||
match &mut self.backend_req_conn {
|
||||
VhostBackendReqConnectionState::Connected(request) => {
|
||||
request.take_shmem_mapper()?
|
||||
}
|
||||
VhostBackendReqConnectionState::NoConnection => {
|
||||
bail!("No backend request connection found")
|
||||
}
|
||||
}
|
||||
};
|
||||
#[cfg(feature = "minigbm")]
|
||||
let gralloc = RutabagaGralloc::new().context("Failed to initailize gralloc")?;
|
||||
let wlstate = self
|
||||
.wlstate
|
||||
.get_or_insert_with(|| {
|
||||
Rc::new(RefCell::new(wl::WlState::new(
|
||||
let wlstate = match &self.wlstate {
|
||||
None => {
|
||||
let mapper = {
|
||||
match &mut self.backend_req_conn {
|
||||
VhostBackendReqConnectionState::Connected(request) => {
|
||||
request.take_shmem_mapper()?
|
||||
}
|
||||
VhostBackendReqConnectionState::NoConnection => {
|
||||
bail!("No backend request connection found")
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let wlstate = Rc::new(RefCell::new(wl::WlState::new(
|
||||
wayland_paths.take().expect("WlState already initialized"),
|
||||
mapper,
|
||||
*use_transition_flags,
|
||||
|
@ -248,9 +248,12 @@ impl VhostUserBackend for WlBackend {
|
|||
#[cfg(feature = "minigbm")]
|
||||
gralloc,
|
||||
None, /* address_offset */
|
||||
)))
|
||||
})
|
||||
.clone();
|
||||
)));
|
||||
self.wlstate = Some(wlstate.clone());
|
||||
wlstate
|
||||
}
|
||||
Some(state) => state.clone(),
|
||||
};
|
||||
let (handle, registration) = AbortHandle::new_pair();
|
||||
match idx {
|
||||
0 => {
|
||||
|
|
Loading…
Reference in a new issue