Skip to content

Commit f6d5eb4

Browse files
committed
Make savestate optional. Fix test. Have subchannel read from primary.
1 parent 7ea1ffb commit f6d5eb4

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ impl PrimaryChannelState {
800800
tx_spread_sent: bool,
801801
guest_link_down: bool,
802802
pending_link_action: Option<bool>,
803-
packet_filter: u32,
803+
packet_filter: Option<u32>,
804804
) -> Result<Self, NetRestoreError> {
805805
// Restore control messages.
806806
let control_messages_len = control_messages.iter().map(|msg| msg.data.len()).sum();
@@ -880,6 +880,8 @@ impl PrimaryChannelState {
880880
PendingLinkAction::Default
881881
};
882882

883+
let packet_filter = packet_filter.unwrap_or(rndisprot::NPROTO_PACKET_FILTER);
884+
883885
Ok(Self {
884886
guest_vf_state,
885887
is_data_path_switched: None,
@@ -1198,7 +1200,24 @@ impl VmbusDevice for Nic {
11981200
.adapter
11991201
.num_sub_channels_opened
12001202
.fetch_add(1, Ordering::SeqCst);
1201-
let packet_filter = rndisprot::NDIS_PACKET_TYPE_NONE; // No traffic until guest sets filter.
1203+
1204+
let packet_filter = if channel_idx == 0 {
1205+
// No rx traffic on primary channel until guest sets filter.
1206+
rndisprot::NDIS_PACKET_TYPE_NONE
1207+
} else {
1208+
// Subchannel inherits the packet filter of the primary channel.
1209+
// Stop the primary worker task temporarily to safely access the state.
1210+
let coordinator = self.coordinator.state_mut().unwrap();
1211+
coordinator.workers[0].stop().await;
1212+
let packet_filter = coordinator.workers[0]
1213+
.state()
1214+
.unwrap()
1215+
.channel
1216+
.packet_filter;
1217+
coordinator.workers[0].start();
1218+
packet_filter
1219+
};
1220+
12021221
let r = self.insert_worker(channel_idx, open_request, state, true, packet_filter);
12031222
if channel_idx != 0
12041223
&& num_opened + 1 == self.coordinator.state_mut().unwrap().num_queues as usize
@@ -1829,7 +1848,7 @@ impl Nic {
18291848
tx_spread_sent: primary.tx_spread_sent,
18301849
guest_link_down: !primary.guest_link_up,
18311850
pending_link_action,
1832-
packet_filter: primary.packet_filter,
1851+
packet_filter: Some(primary.packet_filter),
18331852
})
18341853
}
18351854
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pub struct ReadyPrimary {
121121
#[mesh(15)]
122122
pub pending_link_action: Option<bool>,
123123
#[mesh(16)]
124-
pub packet_filter: u32,
124+
pub packet_filter: Option<u32>,
125125
}
126126

127127
#[derive(Debug, Protobuf)]

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4356,6 +4356,29 @@ async fn set_rss_parameter_bufs_not_evenly_divisible(driver: DefaultDriver) {
43564356
.await
43574357
.expect("association packet");
43584358

4359+
// Set packet filter
4360+
channel
4361+
.send_rndis_control_message(
4362+
rndisprot::MESSAGE_TYPE_SET_MSG,
4363+
rndisprot::SetRequest {
4364+
request_id: 0,
4365+
oid: rndisprot::Oid::OID_GEN_CURRENT_PACKET_FILTER,
4366+
information_buffer_length: size_of::<u32>() as u32,
4367+
information_buffer_offset: size_of::<rndisprot::SetRequest>() as u32,
4368+
device_vc_handle: 0,
4369+
},
4370+
&rndisprot::NPROTO_PACKET_FILTER.to_le_bytes(),
4371+
)
4372+
.await;
4373+
4374+
let set_complete: rndisprot::SetComplete = channel
4375+
.read_rndis_control_message(rndisprot::MESSAGE_TYPE_SET_CMPLT)
4376+
.await
4377+
.unwrap();
4378+
4379+
assert_eq!(set_complete.request_id, 0);
4380+
assert_eq!(set_complete.status, rndisprot::STATUS_SUCCESS);
4381+
43594382
let message = NvspMessage {
43604383
header: protocol::MessageHeader {
43614384
message_type: protocol::MESSAGE5_TYPE_SUB_CHANNEL,

0 commit comments

Comments
 (0)