Skip to content

Commit f3421f1

Browse files
authored
Revert "netvsp: handle RNDIS packet filter OID for stopping Rx (#1873) (#1927)"
This reverts commit d806090.
1 parent 227a082 commit f3421f1

File tree

4 files changed

+18
-382
lines changed

4 files changed

+18
-382
lines changed

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

Lines changed: 18 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -147,19 +147,11 @@ const LINK_DELAY_DURATION: Duration = Duration::from_secs(5);
147147
#[cfg(test)]
148148
const LINK_DELAY_DURATION: Duration = Duration::from_millis(333);
149149

150-
#[derive(Default, PartialEq)]
151-
struct CoordinatorMessageUpdateType {
152-
/// Update guest VF state based on current availability and the guest VF state tracked by the primary channel.
153-
/// This includes adding the guest VF device and switching the data path.
154-
guest_vf_state: bool,
155-
/// Update the receive filter for all channels.
156-
filter_state: bool,
157-
}
158-
159150
#[derive(PartialEq)]
160151
enum CoordinatorMessage {
161-
/// Update network state.
162-
Update(CoordinatorMessageUpdateType),
152+
/// Update guest VF state based on current availability and the guest VF state tracked by the primary channel.
153+
/// This includes adding the guest VF device and switching the data path.
154+
UpdateGuestVfState,
163155
/// Restart endpoints and resume processing. This will also attempt to set VF and data path state to match current
164156
/// expectations.
165157
Restart,
@@ -390,7 +382,6 @@ struct NetChannel<T: RingMem> {
390382
pending_send_size: usize,
391383
restart: Option<CoordinatorMessage>,
392384
can_use_ring_size_opt: bool,
393-
packet_filter: u32,
394385
}
395386

396387
/// Buffers used during packet processing.
@@ -1373,7 +1364,6 @@ impl Nic {
13731364
pending_send_size: 0,
13741365
restart: None,
13751366
can_use_ring_size_opt,
1376-
packet_filter: rndisprot::NDIS_PACKET_TYPE_NONE,
13771367
},
13781368
state,
13791369
coordinator_send: self.coordinator_send.clone().unwrap(),
@@ -1463,7 +1453,6 @@ impl Nic {
14631453
mut control: RestoreControl<'_>,
14641454
state: saved_state::SavedState,
14651455
) -> Result<(), NetRestoreError> {
1466-
let mut saved_packet_filter = 0u32;
14671456
if let Some(state) = state.open {
14681457
let open = match &state.primary {
14691458
saved_state::Primary::Version => vec![true],
@@ -1548,12 +1537,8 @@ impl Nic {
15481537
tx_spread_sent,
15491538
guest_link_down,
15501539
pending_link_action,
1551-
packet_filter,
15521540
} = ready;
15531541

1554-
// If saved state does not have a packet filter set, default to directed, multicast, and broadcast.
1555-
saved_packet_filter = packet_filter.unwrap_or(rndisprot::NPROTO_PACKET_FILTER);
1556-
15571542
let version = check_version(version)
15581543
.ok_or(NetRestoreError::UnsupportedVersion(version))?;
15591544

@@ -1636,11 +1621,6 @@ impl Nic {
16361621
self.insert_worker(channel_idx as u16, &request.unwrap(), state, false)?;
16371622
}
16381623
}
1639-
for worker in self.coordinator.state_mut().unwrap().workers.iter_mut() {
1640-
if let Some(worker_state) = worker.state_mut() {
1641-
worker_state.channel.packet_filter = saved_packet_filter;
1642-
}
1643-
}
16441624
} else {
16451625
control
16461626
.restore(&[false])
@@ -1802,11 +1782,6 @@ impl Nic {
18021782
PrimaryChannelGuestVfState::Restoring(saved_state) => saved_state,
18031783
};
18041784

1805-
let worker_0_packet_filter = coordinator.workers[0]
1806-
.state()
1807-
.unwrap()
1808-
.channel
1809-
.packet_filter;
18101785
saved_state::Primary::Ready(saved_state::ReadyPrimary {
18111786
version: ready.buffers.version as u32,
18121787
receive_buffer: ready.buffers.recv_buffer.saved_state(),
@@ -1836,7 +1811,6 @@ impl Nic {
18361811
tx_spread_sent: primary.tx_spread_sent,
18371812
guest_link_down: !primary.guest_link_up,
18381813
pending_link_action,
1839-
packet_filter: Some(worker_0_packet_filter),
18401814
})
18411815
}
18421816
};
@@ -2620,12 +2594,7 @@ impl<T: RingMem> NetChannel<T> {
26202594
if primary.rndis_state == RndisState::Operational {
26212595
if self.guest_vf_is_available(Some(vfid), buffers.version, buffers.ndis_config)? {
26222596
primary.guest_vf_state = PrimaryChannelGuestVfState::AvailableAdvertised;
2623-
return Ok(Some(CoordinatorMessage::Update(
2624-
CoordinatorMessageUpdateType {
2625-
guest_vf_state: true,
2626-
..Default::default()
2627-
},
2628-
)));
2597+
return Ok(Some(CoordinatorMessage::UpdateGuestVfState));
26292598
} else if let Some(true) = primary.is_data_path_switched {
26302599
tracing::error!(
26312600
"Data path switched, but current guest negotiation does not support VTL0 VF"
@@ -2765,7 +2734,10 @@ impl<T: RingMem> NetChannel<T> {
27652734
// flag on inband packets and won't send a completion
27662735
// packet.
27672736
primary.guest_vf_state = PrimaryChannelGuestVfState::AvailableAdvertised;
2768-
self.send_coordinator_update_vf();
2737+
// restart will also add the VF based on the guest_vf_state
2738+
if self.restart.is_none() {
2739+
self.restart = Some(CoordinatorMessage::UpdateGuestVfState);
2740+
}
27692741
} else if let Some(true) = primary.is_data_path_switched {
27702742
tracing::error!(
27712743
"Data path switched, but current guest negotiation does not support VTL0 VF"
@@ -2813,18 +2785,12 @@ impl<T: RingMem> NetChannel<T> {
28132785
tracing::trace!(?request, "handling control message MESSAGE_TYPE_SET_MSG");
28142786

28152787
let status = match self.adapter.handle_oid_set(primary, request.oid, reader) {
2816-
Ok((restart_endpoint, packet_filter)) => {
2788+
Ok(restart_endpoint) => {
28172789
// Restart the endpoint if the OID changed some critical
28182790
// endpoint property.
28192791
if restart_endpoint {
28202792
self.restart = Some(CoordinatorMessage::Restart);
28212793
}
2822-
if let Some(filter) = packet_filter {
2823-
if self.packet_filter != filter {
2824-
self.packet_filter = filter;
2825-
self.send_coordinator_update_filter();
2826-
}
2827-
}
28282794
rndisprot::STATUS_SUCCESS
28292795
}
28302796
Err(err) => {
@@ -3008,31 +2974,6 @@ impl<T: RingMem> NetChannel<T> {
30082974
}
30092975
Ok(())
30102976
}
3011-
3012-
fn send_coordinator_update_message(&mut self, guest_vf: bool, packet_filter: bool) {
3013-
if self.restart.is_none() {
3014-
self.restart = Some(CoordinatorMessage::Update(CoordinatorMessageUpdateType {
3015-
guest_vf_state: guest_vf,
3016-
filter_state: packet_filter,
3017-
}));
3018-
} else if let Some(CoordinatorMessage::Restart) = self.restart {
3019-
// If a restart message is pending, do nothing.
3020-
// A restart will try to switch the data path based on primary.guest_vf_state.
3021-
// A restart will apply packet filter changes.
3022-
} else if let Some(CoordinatorMessage::Update(ref mut update)) = self.restart {
3023-
// Add the new update to the existing message.
3024-
update.guest_vf_state |= guest_vf;
3025-
update.filter_state |= packet_filter;
3026-
}
3027-
}
3028-
3029-
fn send_coordinator_update_vf(&mut self) {
3030-
self.send_coordinator_update_message(true, false);
3031-
}
3032-
3033-
fn send_coordinator_update_filter(&mut self) {
3034-
self.send_coordinator_update_message(false, true);
3035-
}
30362977
}
30372978

30382979
/// Writes an RNDIS message to `writer`.
@@ -3350,14 +3291,13 @@ impl Adapter {
33503291
primary: &mut PrimaryChannelState,
33513292
oid: rndisprot::Oid,
33523293
reader: impl MemoryRead + Clone,
3353-
) -> Result<(bool, Option<u32>), OidError> {
3294+
) -> Result<bool, OidError> {
33543295
tracing::debug!(?oid, "oid set");
33553296

33563297
let mut restart_endpoint = false;
3357-
let mut packet_filter = None;
33583298
match oid {
33593299
rndisprot::Oid::OID_GEN_CURRENT_PACKET_FILTER => {
3360-
packet_filter = self.oid_set_packet_filter(reader)?;
3300+
// TODO
33613301
}
33623302
rndisprot::Oid::OID_TCP_OFFLOAD_PARAMETERS => {
33633303
self.oid_set_offload_parameters(reader, primary)?;
@@ -3384,7 +3324,7 @@ impl Adapter {
33843324
return Err(OidError::UnknownOid);
33853325
}
33863326
}
3387-
Ok((restart_endpoint, packet_filter))
3327+
Ok(restart_endpoint)
33883328
}
33893329

33903330
fn oid_set_rss_parameters(
@@ -3442,15 +3382,6 @@ impl Adapter {
34423382
Ok(())
34433383
}
34443384

3445-
fn oid_set_packet_filter(
3446-
&self,
3447-
reader: impl MemoryRead + Clone,
3448-
) -> Result<Option<u32>, OidError> {
3449-
let filter: rndisprot::RndisPacketFilterOidValue = reader.clone().read_plain()?;
3450-
tracing::debug!(filter, "set packet filter");
3451-
Ok(Some(filter))
3452-
}
3453-
34543385
fn oid_set_offload_parameters(
34553386
&self,
34563387
reader: impl MemoryRead + Clone,
@@ -3941,26 +3872,8 @@ impl Coordinator {
39413872
}
39423873
sleep_duration = None;
39433874
}
3944-
Message::Internal(CoordinatorMessage::Update(update_type)) => {
3945-
if update_type.filter_state {
3946-
self.stop_workers().await;
3947-
let worker_0_packet_filter =
3948-
self.workers[0].state().unwrap().channel.packet_filter;
3949-
self.workers.iter_mut().skip(1).for_each(|worker| {
3950-
if let Some(state) = worker.state_mut() {
3951-
state.channel.packet_filter = worker_0_packet_filter;
3952-
tracing::debug!(
3953-
packet_filter = ?worker_0_packet_filter,
3954-
channel_idx = state.channel_idx,
3955-
"update packet filter"
3956-
);
3957-
}
3958-
});
3959-
}
3960-
3961-
if update_type.guest_vf_state {
3962-
self.update_guest_vf_state(state).await;
3963-
}
3875+
Message::Internal(CoordinatorMessage::UpdateGuestVfState) => {
3876+
self.update_guest_vf_state(state).await;
39643877
}
39653878
Message::UpdateFromEndpoint(EndpointAction::RestartRequired) => self.restart = true,
39663879
Message::UpdateFromEndpoint(EndpointAction::LinkStatusNotify(connect)) => {
@@ -4393,18 +4306,13 @@ impl Coordinator {
43934306
self.num_queues = num_queues;
43944307
}
43954308

4396-
let worker_0_packet_filter = self.workers[0].state().unwrap().channel.packet_filter;
43974309
// Provide the queue and receive buffer ranges for each worker.
43984310
for ((worker, queue), rx_buffer) in self.workers.iter_mut().zip(queues).zip(rx_buffers) {
43994311
worker.task_mut().queue_state = Some(QueueState {
44004312
queue,
44014313
target_vp_set: false,
44024314
rx_buffer_range: rx_buffer,
44034315
});
4404-
// Update the receive packet filter for the subchannel worker.
4405-
if let Some(worker) = worker.state_mut() {
4406-
worker.channel.packet_filter = worker_0_packet_filter;
4407-
}
44084316
}
44094317

44104318
Ok(())
@@ -5012,13 +4920,6 @@ impl<T: 'static + RingMem> NetChannel<T> {
50124920
data: &mut ProcessingData,
50134921
epqueue: &mut dyn net_backend::Queue,
50144922
) -> Result<bool, WorkerError> {
5015-
if self.packet_filter == rndisprot::NDIS_PACKET_TYPE_NONE {
5016-
tracing::trace!(
5017-
packet_filter = self.packet_filter,
5018-
"rx packet not processed"
5019-
);
5020-
return Ok(false);
5021-
}
50224923
let n = epqueue
50234924
.rx_poll(&mut data.rx_ready)
50244925
.map_err(WorkerError::Endpoint)?;
@@ -5161,7 +5062,10 @@ impl<T: 'static + RingMem> NetChannel<T> {
51615062
_ => (),
51625063
};
51635064
if queue_switch_operation {
5164-
self.send_coordinator_update_vf();
5065+
// A restart will also try to switch the data path based on primary.guest_vf_state.
5066+
if self.restart.is_none() {
5067+
self.restart = Some(CoordinatorMessage::UpdateGuestVfState)
5068+
};
51655069
} else {
51665070
self.send_completion(transaction_id, &[])?;
51675071
}

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,6 @@ open_enum! {
751751
DEFAULT = 0x80,
752752
RSS_CAPABILITIES = 0x88,
753753
RSS_PARAMETERS = 0x89,
754-
OID_REQUEST = 0x96,
755754
OFFLOAD = 0xA7,
756755
OFFLOAD_ENCAPSULATION = 0xA8,
757756
}
@@ -1083,14 +1082,3 @@ open_enum! {
10831082
BINARY = 4,
10841083
}
10851084
}
1086-
1087-
pub type RndisPacketFilterOidValue = u32;
1088-
1089-
// Rndis Packet Filter Flags (OID_GEN_CURRENT_PACKET_FILTER)
1090-
pub const NDIS_PACKET_TYPE_NONE: u32 = 0x00000000;
1091-
pub const NDIS_PACKET_TYPE_DIRECTED: u32 = 0x00000001;
1092-
pub const NDIS_PACKET_TYPE_MULTICAST: u32 = 0x00000002;
1093-
pub const NDIS_PACKET_TYPE_ALL_MULTICAST: u32 = 0x00000004;
1094-
pub const NDIS_PACKET_TYPE_BROADCAST: u32 = 0x00000008;
1095-
pub const NPROTO_PACKET_FILTER: u32 =
1096-
NDIS_PACKET_TYPE_DIRECTED | NDIS_PACKET_TYPE_ALL_MULTICAST | NDIS_PACKET_TYPE_BROADCAST;

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ pub struct ReadyPrimary {
120120
pub guest_link_down: bool,
121121
#[mesh(15)]
122122
pub pending_link_action: Option<bool>,
123-
#[mesh(16)]
124-
pub packet_filter: Option<u32>,
125123
}
126124

127125
#[derive(Debug, Protobuf)]

0 commit comments

Comments
 (0)