From 44bb3dd9095e1c70f17f7960ea269e4bb1cd446f Mon Sep 17 00:00:00 2001 From: Xiong Zhang Date: Tue, 23 Apr 2019 17:09:50 +0800 Subject: src/linux.rs: Modify socket instead of add socket when remove other sockets When an ill socket is detected, it will be removed from poll_context and control_sockets, then the remaining good sockets should change their indices, So modify should be used instead of add, as all of them have been added into poll_context already, the add will return an error. This change is merge of another change at I977be57ea0898cc8226505f7d3da103a46ea626c that was identical to this one except it contained the following similar commit message: linux: when renumbering control sockets, use modify instead of add In some circumstances, a VM control socket will get removed from the list of control sockets in the run_control loop. Usually, the last control socket in the list gets removed, but if that is not the case, the control sockets will get reordered to fill in the gap in the list. The `add` method of `PollContext` was used to change the token used for a given control socket, when `modify` should have been used instead. The problem with using `add` when a control socket is already part of a `PollContext` is that it will return an error and terminate crosvm. This CL fixes that issue. BUG=none TEST="crosvm run --vfio=$GVT_UUID", then run many gpu workloads in guest TEST=crosvm run --gpu Change-Id: Ic00a781d8839e652e2a8fd54ccd8e55849fa20bb Signed-off-by: Xiong Zhang Signed-off-by: Zach Reizner Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1581151 Tested-by: Zach Reizner Tested-by: kokoro Commit-Queue: Zach Reizner Reviewed-by: Zach Reizner --- src/linux.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/linux.rs') diff --git a/src/linux.rs b/src/linux.rs index 271cc5b..9de014a 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -41,7 +41,8 @@ use sys_util::{ self, block_signal, clear_signal, drop_capabilities, error, flock, get_blocked_signals, get_group_id, get_user_id, getegid, geteuid, info, register_signal_handler, set_cpu_affinity, validate_raw_fd, warn, EventFd, FlockOperation, GuestAddress, GuestMemory, Killable, - MemoryMapping, PollContext, PollToken, Protection, SignalFd, Terminal, TimerFd, SIGRTMIN, + MemoryMapping, PollContext, PollToken, Protection, SignalFd, Terminal, TimerFd, WatchingEvents, + SIGRTMIN, }; use vhost; use vm_control::{ @@ -1740,7 +1741,11 @@ fn run_control( control_sockets.swap_remove(index); if let Some(socket) = control_sockets.get(index) { poll_ctx - .add(socket, Token::VmControl { index }) + .modify( + socket, + WatchingEvents::empty().set_read(), + Token::VmControl { index }, + ) .map_err(Error::PollContextAdd)?; } } -- cgit 1.4.1