Commit 7237e16
authored
virtio-nic: in-repo tests and a better device state FSM (#1064)
VirtIO 1.2 states clearly that a driver MUST NOT clear bits from
device_status (except, implicitly, by writing RESET aka 0 to
device_status to.. do a device reset). Since this is the only way to
clear a bit, bits that *are* set can be set at most once. Our old FSM
accepted whatever status a guest happened to provide and stored that; a
guest could intentionally or unintentionally clear NEEDS_RESET even,
though it would be very much in error at that point.
Instead of this very lax treatment of device_status, be more clear that
FEATURES_OK can be toggled to set only once (which fixes a bug on its
own), and if a guest tries clearing a status bit by any means other than
reset, set NEEDS_RESET and demand a reset outright.
Along with this, `viona.rs` gets a very simple driver to exercise some
usage patterns we've seen in starting up virtio NIC devices.
`basic_operation_multiqueue` fails without the device state FSM
improvements, a reflection of the bug mentioned above; since FEATURES_OK
is set before DEVICE_OK, the final status write including DEVICE_OK
would cause a second attempt to apply the negotiated features. We would
then try to set up all the virtqueues again, which fails because the
virtqueues were just taken out of the RESET state when the driver
initialized them, and we come to rest with the NIC in NEEDS_RESET.
Linux (and BSDs, and illumos) clearly do not care about this, as such
instances proceed to network seemingly without issue. Windows seems to
have a periodic task that notices the NEEDS_RESET bit and obliges. It
resets the NIC, which fails to ever come up correctly, and dutifully
stops networking (#1048).
Commenting out parts of prior patches (957f5c4, 1df49a4, 45af0f7) also
cause these new tests to fail; they are collectively as necessary as it
seemed for correct operation in the face of resets.
Finally, one of the new tests verifies that a device in NEEDS_RESET
cannot have the bit inappropriately cleared without reset. This tripped
over a deadlock if a virtqueue is set with an inappropriate size. That
is fixed in this patch as well.1 parent 5372135 commit 7237e16
5 files changed
Lines changed: 786 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
263 | 263 | | |
264 | 264 | | |
265 | 265 | | |
| 266 | + | |
| 267 | + | |
266 | 268 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
658 | 658 | | |
659 | 659 | | |
660 | 660 | | |
661 | | - | |
| 661 | + | |
662 | 662 | | |
663 | 663 | | |
664 | 664 | | |
665 | | - | |
| 665 | + | |
666 | 666 | | |
667 | 667 | | |
668 | 668 | | |
| |||
1051 | 1051 | | |
1052 | 1052 | | |
1053 | 1053 | | |
| 1054 | + | |
1054 | 1055 | | |
1055 | 1056 | | |
1056 | 1057 | | |
1057 | 1058 | | |
1058 | 1059 | | |
1059 | | - | |
1060 | | - | |
1061 | | - | |
1062 | | - | |
1063 | | - | |
1064 | | - | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
1065 | 1109 | | |
1066 | 1110 | | |
| 1111 | + | |
| 1112 | + | |
1067 | 1113 | | |
1068 | 1114 | | |
1069 | 1115 | | |
| |||
1130 | 1176 | | |
1131 | 1177 | | |
1132 | 1178 | | |
| 1179 | + | |
1133 | 1180 | | |
1134 | 1181 | | |
1135 | 1182 | | |
| |||
1514 | 1561 | | |
1515 | 1562 | | |
1516 | 1563 | | |
| 1564 | + | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
| 1568 | + | |
1517 | 1569 | | |
1518 | 1570 | | |
1519 | 1571 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1015 | 1015 | | |
1016 | 1016 | | |
1017 | 1017 | | |
1018 | | - | |
1019 | | - | |
1020 | | - | |
1021 | | - | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
1022 | 1023 | | |
1023 | 1024 | | |
1024 | 1025 | | |
| |||
0 commit comments