Skip to content

Commit 2fd20d1

Browse files
committed
Remove packet_filter from insert_worker and nic open. Coordinator update holds filter value.
1 parent 0384296 commit 2fd20d1

File tree

1 file changed

+30
-47
lines changed
  • vm/devices/net/netvsp/src

1 file changed

+30
-47
lines changed

vm/devices/net/netvsp/src/lib.rs

Lines changed: 30 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ struct CoordinatorMessageUpdateType {
153153
/// This includes adding the guest VF device and switching the data path.
154154
guest_vf_state: bool,
155155
/// Update the receive filter for all channels.
156-
filter_state: bool,
156+
filter_state: Option<u32>,
157157
}
158158

159159
#[derive(PartialEq)]
@@ -1191,39 +1191,28 @@ impl VmbusDevice for Nic {
11911191
open_request: &OpenRequest,
11921192
) -> Result<(), ChannelOpenError> {
11931193
// Start the coordinator task if this is the primary channel.
1194-
let (state, packet_filter) = if channel_idx == 0 {
1194+
let state = if channel_idx == 0 {
11951195
self.insert_coordinator(1, false);
11961196
// No rx traffic on primary channel until guest sets the packet filter.
1197-
(WorkerState::Init(None), rndisprot::NDIS_PACKET_TYPE_NONE)
1197+
WorkerState::Init(None)
11981198
} else {
11991199
self.coordinator.stop().await;
12001200
// Get the buffers created when the primary channel was opened.
12011201
let buffers = self.coordinator.state().unwrap().buffers.clone().unwrap();
12021202
// Get the packet filter of the primary channel.
1203-
self.coordinator.state_mut().unwrap().workers[0]
1204-
.stop()
1205-
.await;
1206-
let packet_filter = self.coordinator.state().unwrap().workers[0]
1207-
.state()
1208-
.unwrap()
1209-
.channel
1210-
.packet_filter;
1211-
(
1212-
WorkerState::Ready(ReadyState {
1213-
state: ActiveState::new(None, buffers.recv_buffer.count),
1214-
buffers,
1215-
data: ProcessingData::new(),
1216-
}),
1217-
packet_filter,
1218-
)
1203+
WorkerState::Ready(ReadyState {
1204+
state: ActiveState::new(None, buffers.recv_buffer.count),
1205+
buffers,
1206+
data: ProcessingData::new(),
1207+
})
12191208
};
12201209

12211210
let num_opened = self
12221211
.adapter
12231212
.num_sub_channels_opened
12241213
.fetch_add(1, Ordering::SeqCst);
12251214

1226-
let r = self.insert_worker(channel_idx, open_request, state, true, packet_filter);
1215+
let r = self.insert_worker(channel_idx, open_request, state, true);
12271216
if channel_idx != 0
12281217
&& num_opened + 1 == self.coordinator.state_mut().unwrap().num_queues as usize
12291218
{
@@ -1363,7 +1352,6 @@ impl Nic {
13631352
open_request: &OpenRequest,
13641353
state: WorkerState,
13651354
start: bool,
1366-
packet_filter: u32,
13671355
) -> Result<(), OpenError> {
13681356
let coordinator = self.coordinator.state_mut().unwrap();
13691357

@@ -1395,7 +1383,7 @@ impl Nic {
13951383
pending_send_size: 0,
13961384
restart: None,
13971385
can_use_ring_size_opt,
1398-
packet_filter,
1386+
packet_filter: rndisprot::NDIS_PACKET_TYPE_NONE,
13991387
},
14001388
state,
14011389
coordinator_send: self.coordinator_send.clone().unwrap(),
@@ -1485,7 +1473,6 @@ impl Nic {
14851473
mut control: RestoreControl<'_>,
14861474
state: saved_state::SavedState,
14871475
) -> Result<(), NetRestoreError> {
1488-
let mut channel_packet_filter = 0u32; // set to primary packet filter
14891476
if let Some(state) = state.open {
14901477
let open = match &state.primary {
14911478
saved_state::Primary::Version => vec![true],
@@ -1635,7 +1622,6 @@ impl Nic {
16351622
pending_link_action,
16361623
packet_filter,
16371624
)?;
1638-
channel_packet_filter = primary.packet_filter;
16391625
active.primary = Some(primary);
16401626
}
16411627

@@ -1654,13 +1640,7 @@ impl Nic {
16541640

16551641
for (channel_idx, (state, request)) in states.into_iter().zip(requests).enumerate() {
16561642
if let Some(state) = state {
1657-
self.insert_worker(
1658-
channel_idx as u16,
1659-
&request.unwrap(),
1660-
state,
1661-
false,
1662-
channel_packet_filter,
1663-
)?;
1643+
self.insert_worker(channel_idx as u16, &request.unwrap(), state, false)?;
16641644
}
16651645
}
16661646
} else {
@@ -2835,9 +2815,7 @@ impl<T: RingMem> NetChannel<T> {
28352815
if restart_endpoint {
28362816
self.restart = Some(CoordinatorMessage::Restart);
28372817
}
2838-
if packet_filter.is_some() {
2839-
self.send_coordinator_update_filter();
2840-
}
2818+
self.send_coordinator_update_filter(packet_filter);
28412819
rndisprot::STATUS_SUCCESS
28422820
}
28432821
Err(err) => {
@@ -3022,7 +3000,7 @@ impl<T: RingMem> NetChannel<T> {
30223000
Ok(())
30233001
}
30243002

3025-
fn send_coordinator_update_message(&mut self, guest_vf: bool, packet_filter: bool) {
3003+
fn send_coordinator_update_message(&mut self, guest_vf: bool, packet_filter: Option<u32>) {
30263004
if self.restart.is_none() {
30273005
self.restart = Some(CoordinatorMessage::Update(CoordinatorMessageUpdateType {
30283006
guest_vf_state: guest_vf,
@@ -3035,16 +3013,18 @@ impl<T: RingMem> NetChannel<T> {
30353013
} else if let Some(CoordinatorMessage::Update(ref mut update)) = self.restart {
30363014
// Add the new update to the existing message.
30373015
update.guest_vf_state |= guest_vf;
3038-
update.filter_state |= packet_filter;
3016+
if packet_filter.is_some() {
3017+
update.filter_state = packet_filter;
3018+
}
30393019
}
30403020
}
30413021

30423022
fn send_coordinator_update_vf(&mut self) {
3043-
self.send_coordinator_update_message(true, false);
3023+
self.send_coordinator_update_message(true, None);
30443024
}
30453025

3046-
fn send_coordinator_update_filter(&mut self) {
3047-
self.send_coordinator_update_message(false, true);
3026+
fn send_coordinator_update_filter(&mut self, packet_filter: Option<u32>) {
3027+
self.send_coordinator_update_message(false, packet_filter);
30483028
}
30493029
}
30503030

@@ -3960,15 +3940,18 @@ impl Coordinator {
39603940
sleep_duration = None;
39613941
}
39623942
Message::Internal(CoordinatorMessage::Update(update_type)) => {
3963-
if update_type.filter_state {
3943+
if let Some(packet_filter) = update_type.filter_state {
39643944
self.stop_workers().await;
3965-
if let Some(packet_filter) = self.primary_mut().map(|p| p.packet_filter) {
3966-
self.workers.iter_mut().for_each(|worker| {
3967-
if let Some(state) = worker.state_mut() {
3968-
state.channel.packet_filter = packet_filter;
3969-
}
3970-
});
3971-
}
3945+
self.workers.iter_mut().for_each(|worker| {
3946+
if let Some(state) = worker.state_mut() {
3947+
state.channel.packet_filter = packet_filter;
3948+
tracing::debug!(
3949+
?packet_filter,
3950+
channel_idx = state.channel_idx,
3951+
"update packet filter"
3952+
);
3953+
}
3954+
});
39723955
}
39733956

39743957
if update_type.guest_vf_state {

0 commit comments

Comments
 (0)