Skip to content

Commit 096c3a4

Browse files
authored
vmbus_server: move SINT constant to vmbus_core (#2340)
This change moves the `SINT` constant to the `vmbus_core` crate, so it can be used in other places. It also renames it to `VMBUS_SINT` for clarity.
1 parent c552f9a commit 096c3a4

File tree

4 files changed

+49
-31
lines changed

4 files changed

+49
-31
lines changed

vm/devices/vmbus/vmbus_core/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ use zerocopy::Immutable;
2222
use zerocopy::IntoBytes;
2323
use zerocopy::KnownLayout;
2424

25+
/// The standard, non-redirected synthetic interrupt used by VMBus.
26+
pub const VMBUS_SINT: u8 = 2;
27+
2528
#[derive(Debug)]
2629
pub struct TaggedStream<T, S>(Option<T>, S);
2730

vm/devices/vmbus/vmbus_server/src/channels.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ pub mod saved_state;
66
mod tests;
77

88
use crate::Guid;
9-
use crate::SINT;
109
use crate::SynicMessage;
1110
use crate::monitor::AssignedMonitors;
1211
use crate::protocol::Version;
@@ -37,6 +36,7 @@ use vmbus_core::HvsockConnectRequest;
3736
use vmbus_core::HvsockConnectResult;
3837
use vmbus_core::MaxVersionInfo;
3938
use vmbus_core::OutgoingMessage;
39+
use vmbus_core::VMBUS_SINT;
4040
use vmbus_core::VersionInfo;
4141
use vmbus_core::protocol;
4242
use vmbus_core::protocol::ChannelId;
@@ -867,7 +867,7 @@ impl Channel {
867867

868868
let channel_id = entry.id();
869869
entry.insert(offer_id);
870-
let connection_id = ConnectionId::new(channel_id.0, assigned_channels.vtl, SINT);
870+
let connection_id = ConnectionId::new(channel_id.0, assigned_channels.vtl, VMBUS_SINT);
871871

872872
// Allocate a monitor ID if the channel uses MNF.
873873
// N.B. If the synic doesn't support MNF or MNF is disabled by the server, use_mnf should
@@ -2111,7 +2111,7 @@ impl<'a, N: 'a + Notifier> ServerWithNotifier<'a, N> {
21112111
{
21122112
target_info.sint()
21132113
} else {
2114-
SINT
2114+
VMBUS_SINT
21152115
};
21162116

21172117
let target_vtl = if message.multiclient
@@ -2205,7 +2205,7 @@ impl<'a, N: 'a + Notifier> ServerWithNotifier<'a, N> {
22052205
return;
22062206
}
22072207

2208-
if request.target_sint != SINT {
2208+
if request.target_sint != VMBUS_SINT {
22092209
tracelimit::warn_ratelimited!(
22102210
target_vtl = request.target_vtl,
22112211
target_sint = request.target_sint,

vm/devices/vmbus/vmbus_server/src/channels/tests.rs

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fn test_version_negotiation_multiclient_vtl() {
8888
let mut env = TestEnv::new();
8989

9090
let target_info = TargetInfo::new()
91-
.with_sint(SINT)
91+
.with_sint(VMBUS_SINT)
9292
.with_vtl(2)
9393
.with_feature_flags(FeatureFlags::new().into());
9494

@@ -133,7 +133,7 @@ fn test_version_negotiation_feature_flags() {
133133

134134
// Test with no feature flags.
135135
let mut target_info = TargetInfo::new()
136-
.with_sint(SINT)
136+
.with_sint(VMBUS_SINT)
137137
.with_vtl(0)
138138
.with_feature_flags(FeatureFlags::new().into());
139139
test_initiate_contact(
@@ -399,7 +399,7 @@ fn test_channel_lifetime_helper(version: Version, feature_flags: FeatureFlags) {
399399
.unwrap();
400400

401401
let mut target_info = TargetInfo::new()
402-
.with_sint(SINT)
402+
.with_sint(VMBUS_SINT)
403403
.with_vtl(2)
404404
.with_feature_flags(FeatureFlags::new().into());
405405
if version >= Version::Copper {
@@ -788,12 +788,12 @@ fn test_save_restore_with_connection() {
788788
env.gpadl(3, 31);
789789

790790
// Test Opening, Open, and Closing save for reserved channels
791-
env.open_reserved(7, 1, SINT.into());
792-
env.open_reserved(8, 2, SINT.into());
793-
env.open_reserved(9, 3, SINT.into());
791+
env.open_reserved(7, 1, VMBUS_SINT.into());
792+
env.open_reserved(8, 2, VMBUS_SINT.into());
793+
env.open_reserved(9, 3, VMBUS_SINT.into());
794794
env.c().open_complete(offer_id8, 0);
795795
env.c().open_complete(offer_id9, 0);
796-
env.close_reserved(9, 3, SINT.into());
796+
env.close_reserved(9, 3, VMBUS_SINT.into());
797797

798798
// Revoke an offer but don't have the "guest" release it, so we can then mark it as
799799
// reoffered.
@@ -853,7 +853,7 @@ fn test_save_restore_with_connection() {
853853

854854
// Check reserved channels have been restored to the same state
855855
env.c().open_complete(offer_id7, 0);
856-
env.close_reserved(8, 2, SINT.into());
856+
env.close_reserved(8, 2, VMBUS_SINT.into());
857857
env.c().close_complete(offer_id8);
858858
env.c().close_complete(offer_id9);
859859

@@ -1146,7 +1146,7 @@ fn test_pending_messages() {
11461146

11471147
env.notifier.messages.clear();
11481148
env.notifier.pend_messages = true;
1149-
env.open_reserved(2, 4, SINT.into());
1149+
env.open_reserved(2, 4, VMBUS_SINT.into());
11501150
env.c().open_complete(offer_id2, protocol::STATUS_SUCCESS);
11511151

11521152
// Reserved channel message should not be queued, but just discarded if it cannot be sent.
@@ -1297,18 +1297,24 @@ fn test_reserved_channels() {
12971297
env.notifier.messages.clear();
12981298

12991299
// Open responses should be sent to the provided target
1300-
env.open_reserved(1, 1, SINT.into());
1300+
env.open_reserved(1, 1, VMBUS_SINT.into());
13011301
env.c().open_complete(offer_id1, 0);
13021302
env.notifier.check_message_with_target(
13031303
OutgoingMessage::new(&protocol::OpenResult {
13041304
channel_id: ChannelId(1),
13051305
..FromZeros::new_zeroed()
13061306
}),
1307-
MessageTarget::ReservedChannel(offer_id1, ConnectionTarget { vp: 1, sint: SINT }),
1307+
MessageTarget::ReservedChannel(
1308+
offer_id1,
1309+
ConnectionTarget {
1310+
vp: 1,
1311+
sint: VMBUS_SINT,
1312+
},
1313+
),
13081314
);
1309-
env.open_reserved(2, 2, SINT.into());
1315+
env.open_reserved(2, 2, VMBUS_SINT.into());
13101316
env.c().open_complete(offer_id2, 0);
1311-
env.open_reserved(3, 3, SINT.into());
1317+
env.open_reserved(3, 3, VMBUS_SINT.into());
13121318
env.c().open_complete(offer_id3, 0);
13131319

13141320
// This should fail
@@ -1319,7 +1325,7 @@ fn test_reserved_channels() {
13191325
env.complete_reset();
13201326

13211327
// Closing while disconnected should work
1322-
env.close_reserved(2, 2, SINT.into());
1328+
env.close_reserved(2, 2, VMBUS_SINT.into());
13231329
env.c().close_complete(offer_id2);
13241330

13251331
env.notifier.messages.clear();
@@ -1332,20 +1338,26 @@ fn test_reserved_channels() {
13321338
env.c().gpadl_create_complete(offer_id2, GpadlId(10), 0);
13331339

13341340
// Reopening the same offer should work
1335-
env.open_reserved(2, 3, SINT.into());
1341+
env.open_reserved(2, 3, VMBUS_SINT.into());
13361342
env.c().open_complete(offer_id2, 0);
13371343

13381344
env.notifier.messages.clear();
13391345

13401346
// The channel should still be open after disconnect/reconnect
13411347
// and close responses should be sent to the provided target
1342-
env.close_reserved(1, 4, SINT.into());
1348+
env.close_reserved(1, 4, VMBUS_SINT.into());
13431349
env.c().close_complete(offer_id1);
13441350
env.notifier.check_message_with_target(
13451351
OutgoingMessage::new(&protocol::CloseReservedChannelResponse {
13461352
channel_id: ChannelId(1),
13471353
}),
1348-
MessageTarget::ReservedChannel(offer_id1, ConnectionTarget { vp: 4, sint: SINT }),
1354+
MessageTarget::ReservedChannel(
1355+
offer_id1,
1356+
ConnectionTarget {
1357+
vp: 4,
1358+
sint: VMBUS_SINT,
1359+
},
1360+
),
13491361
);
13501362
env.teardown_gpadl(1, 10);
13511363
env.c().gpadl_teardown_complete(offer_id1, GpadlId(10));
@@ -1371,7 +1383,7 @@ fn test_disconnected_reset() {
13711383

13721384
env.gpadl(1, 10);
13731385
env.c().gpadl_create_complete(offer_id1, GpadlId(10), 0);
1374-
env.open_reserved(1, 1, SINT.into());
1386+
env.open_reserved(1, 1, VMBUS_SINT.into());
13751387
env.c().open_complete(offer_id1, 0);
13761388

13771389
env.c().handle_unload();
@@ -1394,13 +1406,13 @@ fn test_disconnected_reset() {
13941406

13951407
env.gpadl(2, 20);
13961408
env.c().gpadl_create_complete(offer_id2, GpadlId(20), 0);
1397-
env.open_reserved(2, 2, SINT.into());
1409+
env.open_reserved(2, 2, VMBUS_SINT.into());
13981410
env.c().open_complete(offer_id2, 0);
13991411

14001412
env.c().handle_unload();
14011413
env.complete_reset();
14021414

1403-
env.close_reserved(2, 2, SINT.into());
1415+
env.close_reserved(2, 2, VMBUS_SINT.into());
14041416
env.c().close_complete(offer_id2);
14051417
env.c().gpadl_teardown_complete(offer_id2, GpadlId(20));
14061418

@@ -1511,7 +1523,7 @@ fn test_server_monitor_page_helper(provide_guest_pages: bool) {
15111523
protocol::InitiateContact {
15121524
version_requested: version as u32,
15131525
interrupt_page_or_target_info: TargetInfo::new()
1514-
.with_sint(SINT)
1526+
.with_sint(VMBUS_SINT)
15151527
.with_vtl(0)
15161528
.with_feature_flags(feature_flags.into())
15171529
.into(),
@@ -1998,7 +2010,10 @@ fn test_reinitiate_contact() {
19982010
protocol::MessageType::INITIATE_CONTACT,
19992011
protocol::InitiateContact {
20002012
version_requested: Version::Win10 as u32,
2001-
interrupt_page_or_target_info: TargetInfo::new().with_sint(SINT).with_vtl(0).into(),
2013+
interrupt_page_or_target_info: TargetInfo::new()
2014+
.with_sint(VMBUS_SINT)
2015+
.with_vtl(0)
2016+
.into(),
20022017
child_to_parent_monitor_page_gpa: 0x123f000,
20032018
parent_to_child_monitor_page_gpa: 0x321f000,
20042019
..FromZeros::new_zeroed()
@@ -2500,7 +2515,7 @@ impl TestEnv {
25002515
initiate_contact: protocol::InitiateContact {
25012516
version_requested: version as u32,
25022517
interrupt_page_or_target_info: TargetInfo::new()
2503-
.with_sint(SINT)
2518+
.with_sint(VMBUS_SINT)
25042519
.with_vtl(0)
25052520
.with_feature_flags(feature_flags.into())
25062521
.into(),

vm/devices/vmbus/vmbus_server/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ use vmbus_core::HvsockConnectResult;
8383
use vmbus_core::MaxVersionInfo;
8484
use vmbus_core::OutgoingMessage;
8585
use vmbus_core::TaggedStream;
86+
use vmbus_core::VMBUS_SINT;
8687
use vmbus_core::VersionInfo;
8788
use vmbus_core::protocol;
8889
pub use vmbus_core::protocol::GpadlId;
@@ -99,7 +100,6 @@ use vmcore::synic::MessagePort;
99100
use vmcore::synic::MonitorPageGpas;
100101
use vmcore::synic::SynicPortAccess;
101102

102-
const SINT: u8 = 2;
103103
pub const REDIRECT_SINT: u8 = 7;
104104
pub const REDIRECT_VTL: Vtl = Vtl::Vtl2;
105105
const SHARED_EVENT_CONNECTION_ID: u32 = 2;
@@ -463,7 +463,7 @@ impl<T: SpawnDriver + Clone> VmbusServerBuilder<T> {
463463
let (redirect_vtl, redirect_sint) = if self.use_message_redirect {
464464
(REDIRECT_VTL, REDIRECT_SINT)
465465
} else {
466-
(self.vtl, SINT)
466+
(self.vtl, VMBUS_SINT)
467467
};
468468

469469
// If this server is not for VTL2, use a server-specific connection ID rather than the
@@ -1792,11 +1792,11 @@ impl ServerTaskInner {
17921792
let (target_vtl, target_sint) = if open_params.flags.redirect_interrupt() {
17931793
(self.redirect_vtl, self.redirect_sint)
17941794
} else {
1795-
(self.vtl, SINT)
1795+
(self.vtl, VMBUS_SINT)
17961796
};
17971797

17981798
let guest_event_port = self.synic.new_guest_event_port(
1799-
VmbusServer::get_child_event_port_id(open_params.channel_id, SINT, self.vtl),
1799+
VmbusServer::get_child_event_port_id(open_params.channel_id, VMBUS_SINT, self.vtl),
18001800
target_vtl,
18011801
target_vp,
18021802
target_sint,

0 commit comments

Comments
 (0)