Commit Graph
506 Commits
Author SHA1 Message Date
Yuri Benditovich e941c70b75 netkvm: make ParaNdis_PerformPacketAnalysis static inline
The procedure was in glocal scope without a reason. Moving
it to RX area and making static inline.

Signed-off-by: Yuri Benditovich <[email protected]>
2019-12-23 09:57:33 +02:00
Yuri Benditovich c69786e3c2 netkvm: make ParaNdis_GetScalingDataForPacket inline
The procedure was in global scope, but used only with RX/RSS.
Making it static inline.

Signed-off-by: Yuri Benditovich <[email protected]>
2019-12-23 09:57:33 +02:00
Yuri Benditovich 45416ef95c netkvm: remove duplicated prototypes of procedures
Signed-off-by: Yuri Benditovich <[email protected]>
2019-12-23 09:57:33 +02:00
Yuri Benditovich e16e6e6e8e netkvm: make ParaNdis_QueueRSSDpc static inline
This procedure was placed in global scope without a reason.
Making it static and inline. It is required and used only
with RSS, so removing the body if no RSS.

Signed-off-by: Yuri Benditovich <[email protected]>
2019-12-23 09:57:33 +02:00
Yuri Benditovich 5d6a2e2a8c netkvm: remove wrong prototype of procedure
There is no procedure with such prototype. Removing it.

Signed-off-by: Yuri Benditovich <[email protected]>
2019-12-23 09:57:33 +02:00
Yuri Benditovich 1f29c5c4ee netkvm: move ParaNdis_SetupRSSQueueMap to RSS scope
Due to historical reasons the procedure was placed
in common scope. Moving it to RSS area.

Signed-off-by: Yuri Benditovich <[email protected]>
2019-12-23 09:57:33 +02:00
Yuri Benditovich 5ddf9c08b3 netkvm: move forward definition of PARANDIS_ADAPTER
Moving forward definition from ParaNdis_GuestAnnounce.h to
common scope. Other components will use it also.

Signed-off-by: Yuri Benditovich <[email protected]>
2019-12-23 09:57:33 +02:00
Yuri Benditovich 1dfac98666 netkvm: make crash handler to work again
In previous commit with WPP support the code stopped calling
ParaNdis_DebugInitialize, so crash callback does not work
anymore. Making it work again and including virtio printouts
into driver logs.

Signed-off-by: Yuri Benditovich <[email protected]>
2019-12-23 09:57:33 +02:00
Yuri Benditovich fde22b8423 netkvm: assume 'any layout' for version 1 device
VIRTIO_F_ANY_LAYOUT is only for legacy devices. For devices
with VIRTIO_F_VERSION_1 we do not need to use separate SG
entry for virtio-net header on TX.

Signed-off-by: Yuri Benditovich <[email protected]>
2019-12-23 09:57:33 +02:00
Yuri Benditovich c9558d88dc netkvm: fix table printout template in case of WPP
Trace procedure from header file does not work in case of WPP.
Fixing it by less complicated way than involving H file into
WPP processing: just define WPP procedure to be used from
the template. At the same time we define trace procedure that
does not add the functiona name, we use it in this template
printout and will also use in other places.

Signed-off-by: Yuri Benditovich <[email protected]>
2019-12-23 09:57:33 +02:00
Yuri Benditovich 1f72e39791 netkvm: reduce double copy for UDP and IP packets in TX path
Currently we copy UDP and IP packets with checksumming to
headers buffer of 4K (most of cases entire packets). We do
not tell that to anyone, so later we describe the IP/UDP payload
in SG table and qemu copies the same data again from original
buffers of the packets.
Set the copied size correctly and avoid double copy.
For further optimization: we actually need from 40 to ~300 bytes
(without preliminary knowledge) to populate IP checksum, so the
size of copied data can be reduced.

Signed-off-by: Yuri Benditovich <[email protected]>
2019-12-23 09:57:33 +02:00
Yuri Benditovich b918f4ebda netkvm: make CNB::Copy to return copied size
Currently the procedure returns bool that tells whether
all the max size was copied (usually no) and never check
the result as this does not matter.
Return number of copied bytes instead, this will be relevant.

Signed-off-by: Yuri Benditovich <[email protected]>
2019-12-23 09:57:33 +02:00
Yuri Benditovich 6edb2bc92a netkvm: small optimization in RX path
Currently in RX patch processing we do RX queue reset unconditionally
even if we already know that we need to respawn the RX DPC.
Queue reset tries to enable interrupts/event for the queue, which is
redundant if we anyway are going to respawn the DPC.
Do it only in case we did not recognize pending packets yet.

Signed-off-by: Yuri Benditovich <[email protected]>
2019-12-23 09:57:33 +02:00
Yuri Benditovich e5c1c0f049 netkvm(arm64): Turn off the control queue for ARM64
Due to unknown reason, on real ARM64 machines it is found
that the control queue does not function correctly. Until
it is investigated, we turn off the control queue for ARM64.
This disables also related features like dynamic offloads
and multiqueue.

Signed-off-by: Yuri Benditovich <[email protected]>
2019-12-23 09:57:33 +02:00
Yuri Benditovich 3529c23ce6 netkvm(arm64): copy RX data to cached RAM before indication
On ARM there is problem of unaligned access to the network data
buffer, which is received by allocation of shared memory.
Until the root cause solved we can copy RX data from original
shared buffer to cached system RAM to prevent the exception
in case of unalignhed access.

Signed-off-by: Yuri Benditovich <[email protected]>
2019-12-23 09:57:33 +02:00
Yuri Benditovich dc06366b32 netkvm: move ParaNdis_ReceiveQueueAddBuffer to RX area
The procedure is used only inside RX, making it static inline.

Signed-off-by: Yuri Benditovich <[email protected]>
2019-12-23 09:57:33 +02:00
Yuri Benditovich fc16d5878e netkvm: move ParaNdis_ResetRxClassification to RX area
Signed-off-by: Yuri Benditovich <[email protected]>
2019-12-23 09:57:33 +02:00
Yuri Benditovich 9364ac6f24 netkvm: make ParaNdis_UnbindRxBufferFromPacket static
The procedure is used only inside RX, no reason to publish.

Signed-off-by: Yuri Benditovich <[email protected]>
2019-12-23 09:57:33 +02:00
Yuri Benditovich 7150e2b380 netkvm: make ParaNdis_BindRxBufferToPacket static
The procedure is used only inside RX, no reason to publish.

Signed-off-by: Yuri Benditovich <[email protected]>
2019-12-23 09:57:33 +02:00
Yuri Benditovich 465161ca3b netkvm: make ParaNdis_FreeRxBufferDescriptor static
The procedure is used only inside RX, no reason to publish.

Signed-off-by: Yuri Benditovich <[email protected]>
2019-12-23 09:57:33 +02:00
Yuri Benditovich 3177419a99 netkvm: change default speed to 10 Gbps
https://bugzilla.redhat.com/show_bug.cgi?id=1711743
Default speed of 100 Gbps and 40 Gbps causes degradation
in preformance tests, so changing it to 10 Gbps. Still
can be configured by QEMU command line.

Signed-off-by: Yuri Benditovich <[email protected]>
2019-11-26 11:46:42 +02:00
Yuri Benditovich fd1bf265b5 netkvm: Increase timeout of control command completion
https://bugzilla.redhat.com/show_bug.cgi?id=1716248
Previous commit 2eea7a77b7 sets timeout on waiting
for response on control command. The command stops waiting
after 1,000 attempts to get the response with 1 microsecond
wait between attempts. The intention was to prevent infinite
wait in case of unexpected IOCTL after the miniport received
shutdown indication (note that NDIS should not call adapter's
callbacks after that, see
https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/ndis/nc-ndis-miniport_shutdown).
In this case the control queue is not initialized and
the QEMU does not receive the command and does not send
the response. But in case the limit is not sufficient and
the timeout happens during regular initialization flow and
QEMU does send the response, further commands might be
executed incorrectly and cause unpredictable result and
loss of functionality. Example of such case is sending
VIRTIO_NET_CTRL_MQ when the VM uses only part of queues (the
QEMU issues rollback, prints error message etc).
We increase the limit to 500,000 attempts.

Signed-off-by: Yuri Benditovich <[email protected]>
2019-06-06 16:32:19 +03:00
Yuri Benditovich 27d4c3029a netkvm: RSC support according to virtio spec
Removed support for RSC implemented in private qemu patch.
Now the driver supports RSC according to the virtio spec
and upstream qemu code. The RSC feature is supported for
V1 device and for legacy device as well.

Signed-off-by: Yuri Benditovich <[email protected]>
2019-06-01 22:12:55 +03:00
Yuri Benditovich 52508c0d79 netkvm: Make virtio_net header in TX buffer to be aligned on 8 bytes
Virtio-net header in TX direction is at (pages start)+ 4 bytes.
This causes misaligment exception when preparing the packet.
Even this is probably bug of ARM64 code generation, the simplest
solution is to make the virtio-net header to be always at +8 bytes.

Signed-off-by: Yuri Benditovich <[email protected]>
2019-04-23 16:40:12 +03:00
Yuri Benditovich 8a54920763 netkvm: fix unaligned access when comparing ethernet address
The macro ETH_COMPARE_NETWORK_ADDRESSES_EQ causes unaligned
access exception on ARM64. To solve this, we will use this
macro on non-ARM systems and on ARM64 systems will use
byte-by-byte comparison.
2019-04-23 16:40:12 +03:00
Yuri Benditovich cf7599d0af netkvm: support checksumming of unaligned buffers for ARM64
Signed-off-by: Yuri Benditovich <[email protected]>
2019-04-23 16:40:12 +03:00
Yuri Benditovich 241cab0b48 netkvm: align indirect area of RX ring to 8 bytes
Prevent ARM64 misalignment exception

Signed-off-by: Yuri Benditovich <[email protected]>
2019-04-23 16:40:12 +03:00
Yuri Benditovich 2df3d57351 netkvm: workaround for SDV of DDK 1809
The SDV build (msbuild /t:sdv /inputs:"/check") crashes
on this line. This looks like a bug of SDV, but we change
it in order to make transition to 2017 faster.

Signed-off-by: Yuri Benditovich <[email protected]>
2019-04-23 16:40:12 +03:00
Yuri Benditovich 8a7005b1cf netkvm: Fix functionality with single MSIX vector
https://bugzilla.redhat.com/show_bug.cgi?id=1666940
Set clear and simple rule for assignment of vectors to queues
and translation of MSIX messages to queues:
in case of one or two vectors they are assigned
to TX/RX queues and CX reuses the last vector. In this case
we do not spawn DPC for CX and process it during regular
RX/TX processing. For case of 3 and more vectors the processing
is the same as before.

Signed-off-by: Yuri Benditovich <[email protected]>
2019-01-30 12:47:35 +02:00
yuchenlin 2eea7a77b7 NetKVM: Prevent hanging in SendControlMessage
Windows with NetKVM has a little chance hang during shutdown.

If the NetKVM has not initialized yet (or reset), QEMU will ignore
the control message. It will cause driver hanging in infinite while loop
for waiting response (which leads to windows hang in shutdown). In our
test, there is a little chance to receive an OID for setting multicast list
after device reset. To make symptom more clear, I have added some log.
Below is the log and call stack when this situation happens:

Logs:

[ParaNdis_OnShutdown]=>
Common [ParaNdis_ResetVirtIONetDevice] Done
[ParaNdis_OnOidSetMulticastList] Go
[ParaNdis_UpdateDeviceFilters] Do
[CParaNdisCX::SendControlMessage] enter: 4277 - cls: 0, cmd: 0
CParaNdisCX::SendControlMessage - ERROR: in while
Assertion: *** DPC watchdog timeout
    This is NOT a break in update time
    This is most likely a BUG in an ISR
    Perform a stack trace to find the culprit
    The period will be doubled on continuation
    Use gh to continue!!

Call stack:

kd> k
ChildEBP RetAddr
8b582530 83ab50be nt!KeAccumulateTicks+0x3c5
8b582570 83ab4f6b nt!KeUpdateRunTime+0x145
8b5825c8 83ab9c17 nt!KeUpdateSystemTime+0x613
8b5825c8 83a10122 nt!KeUpdateSystemTimeAssist+0x13
8b582680 8e16db70 hal!HalpTscStallExecutionProcessor+0xc0
WARNING: Stack unwind information not available. Following frames may be
wrong.
8b582700 8e16b216 netkvm+0x4b70
8b582730 8e16c418 netkvm+0x2216
8b582740 8e16f219 netkvm+0x3418
8b582750 8e17740f netkvm+0x6219
8b5827a8 880fc32b netkvm+0xe40f
8b5827f0 880a8ce3 ndis!ndisMDoOidRequest+0x3a1
8b582818 880a87ff ndis!ndisFQueueRequestOnNext+0x21e
8b582880 8df21086 ndis!NdisFOidRequest+0x181
8b5828a0 880fc961 pacer!PcFilterRequest+0x78
8b582900 880a8c5c ndis!ndisFDoOidRequest+0x1a2
8b582928 880a87ff ndis!ndisFQueueRequestOnNext+0x197
8b582990 8df15b22 ndis!NdisFOidRequest+0x181
8b5829b0 880fc961 wfplwf!FilterOidRequest+0x50
8b582a10 880a7799 ndis!ndisFDoOidRequest+0x1a2
8b582a3c 8810d602 ndis!ndisQueueRequestOnTop+0x224
8b582ab0 8810d686 ndis!ndisMOidRequest+0x1dd
8b582ac0 882a4646 ndis!NdisOidRequest+0xf
8b582b7c 88254d1d tcpip!FlpNdisRequestUnderReference+0x7d
8b582bb8 8825523b tcpip!FlpMulticastListSet+0xa1
8b582bc4 88251a2e tcpip!FlpSerializedNdisDeleteGroupWorker+0xd
8b582bec 83c4f460 tcpip!FlpSerializedNdisRequestWorkerRoutine+0x41
8b582c00 83ab7aab nt!IopProcessWorkItem+0x23
8b582c50 83c43f5e nt!ExpWorkerThread+0x10d
8b582c90 83aeb219 nt!PspSystemThreadStartup+0x9e
00000000 00000000 nt!KiThreadStartup+0x19

Signed-off-by: yuchenlin <[email protected]>
2018-12-13 12:03:49 +02:00
Yuri Benditovich 6172c77cce netkvm: return queued TX packets on hot unplug
https://bugzilla.redhat.com/show_bug.cgi?id=1517107
Return queued TX packets in case of surprise removal.
Packets that may be under mapping will not enter send
queue and will be also returned to NDIS.

Signed-off-by: Yuri Benditovich <[email protected]>
2018-11-01 17:27:34 +02:00
Yuri Benditovich 924c534b46 netkvm: split code of DoPendingTasks to allow code reuse
Part of the code moved to separate procedure which will
be later reused in hot unplug flow

Signed-off-by: Yuri Benditovich <[email protected]>
2018-11-01 17:27:34 +02:00
Yuri Benditovich 9e803146bf netkvm: introduce 'kill' flow of TX queue
Upon surprise removal all the packets in use must be
collected and completed and further regular releases
disallowed even if the procedure will be called by
misunderstanding. Current commit adds the queue interface
that allows collecting used TX descriptors without using
GetBuf as these packets are not completed by the device.

Signed-off-by: Yuri Benditovich <[email protected]>
2018-11-01 17:27:34 +02:00
Yuri Benditovich 104495627e netkvm: split ReleaseTransmitBuffers code to allow code reuse
The code moved to separate procedure, later it will be reused

Signed-off-by: Yuri Benditovich <[email protected]>
2018-11-01 17:27:34 +02:00
Yuri Benditovich eca70d3528 netkvm: fix support for speed/duplex configuration
WHCK requires adapter speed to be equal to maximal speed, so
it fails with default run of qemu.
In addition, it is easy to have meaningless speed report
with parameters provided in qemu command line, as there is
almost no validation of values received from the configuration.
Current commit sets following order of assignment and report:
At the beginning we set adapter speed as default=100 Gbps.
We do not assign invalid values from device configuration.
We always use the same value for reports of current speed
and of maximal speed.

Signed-off-by: Yuri Benditovich <[email protected]>
2018-10-18 10:46:58 +03:00
Yuri Benditovich efcadfc983 netkvm: use const qualifier for const string
Signed-off-by: Yuri Benditovich <[email protected]>
2018-10-18 10:46:58 +03:00
Basil Salman 9c1cbd3b7a [NetKVM] Code analysis: Warning C28023
SDV code analysis threw warning C28023:  The function being assigned or
passed should have a _Function_class_ annotation for at least one of the
class(es) in: 'KDEFERRED_ROUTINE' line 47 in file netkvm\common\parandis-cx.cpp
The warning was generated because KeInitializeDPc function requires its
second argument to be a function with KDEFERRED_ROUTINE class, and
MiniportMSIInterruptCXDpc function that is passed as the second argument
was not declared with that function class.
so proper declaration was added to the function.

Signed-off-by: Basil Salman <[email protected]>
2018-10-04 15:41:27 +03:00
Basil Salman e6b30f6be8 [NetKVM] Code analysis: Caller fails to hold lock
SDV code analysis threw warning C26110: Caller failing to hold
lock LockedContext line 324 before it being destructed at the
end of the block, The lock is actually being held locked but
SDV does not seem to recognize that due to encapsulation.
so the warning was suppressed.

Signed-off-by: Basil Salman <[email protected]>
2018-10-04 15:41:27 +03:00
Basil Salman f5b1c3be9e [NetKVM] Code analysis: using uninitialized memory
SDV code analysis threw a warning regading using uninitialized memory
'addr' line 384 in parandis-virtio.cpp.
line 384 prints the address of the block that was freed using
NdisFreeMemoryWithTagPriority the line before, this was not a problem
since it only prints the address that pointer addr points to. and since
NdisFreeMemoryWithTagPriority is a void function that can't fail,
switching the lines and printing before the actual free, shall eliminate
the warning without affecting the code's functionality.

Signed-off-by: Basil Salman <[email protected]>
2018-10-04 15:41:27 +03:00
Yuri Benditovich f81cf0050c netkvm: fix error flow on power on
If power on procedure fails, it still must resume the
state machine, otherwise following pause flow never
completes.

Signed-off-by: Yuri Benditovich <[email protected]>
2018-09-26 11:53:05 +03:00
Sameeh Jubran fc8a5735e3 NetKVM: Interrupts: Drop unneeded report interrupt logic
Now that in MSI interrupts we have a separate DPC for CX, we don't need
to check if an interrupt was reported or report an interrupt for any of
the paths as we already used this flag for CX only when MSI interrupts
are used.

For legacy interrupt we always set the report interrupt flag and then
clear it in CX handling, this work is superfluous as we always want to
check if CX has any work to do with legacy interrupts. Setting and
unsetting this flag constantly is a good example of race conditions that
might lead us to miss some interrupts for cx.

These race conditions were initially reported and discussed in the
following pull request:

https://github.com/virtio-win/kvm-guest-drivers-windows/pull/281

Signed-off-by: Sameeh Jubran <[email protected]>
2018-09-17 16:58:51 +03:00
Sameeh Jubran 861e27206e NetKVM: CX: Use separate DPC
This commit separates the CX path handeling to a standalone DPC, the
motive to do this is that sometimes we can miss Control interrupts due to
the way it is implemented today.

The issue is disscussed in great detail here:
https://github.com/virtio-win/kvm-guest-drivers-windows/pull/281

Signed-off-by: Sameeh Jubran <[email protected]>
2018-09-17 16:58:51 +03:00
Yuri Benditovich fa1cf3dd46 netkvm: add printout for RSC related features
Indicate presence of host features:
VIRTIO_NET_F_GUEST_RSC4
VIRTIO_NET_F_GUEST_RSC6
VIRTIO_NET_F_CTRL_GUEST_OFFLOADS

Signed-off-by: Yuri Benditovich <[email protected]>
2018-09-17 15:23:02 +03:00
Yuri Benditovich 9e8405f6a3 netkvm: fix compilation problem without WPP
Use FIELD_OFFSET instead of offsetof

Signed-off-by: Yuri Benditovich <[email protected]>
2018-09-17 15:22:50 +03:00
Basil Salman 01b109c534 NetKVM: added VIRTIO_CONFIG_S_NEEDS_RESET event to debug log
In case of a Reset event, the driver now prints a message
to debug log.

Signed-off-by: Basil Salman <[email protected]>
2018-09-12 18:56:38 +03:00
Sameeh Jubran 1741d661d8 NetKVM: Implement VIRTIO_CONFIG_S_NEEDS_RESET as needed by spec
The VIRTIO 1.0 spec adds the DEVICE_NEEDS_RESET bit to the device's
status. This commit enables the driver to respods appropriately to
RESET request by the device.

Upon receiving such notification from the device in the control queue we
do the following steps in the following order:

* On Control interrupt read the device status and check that
  VIRTIO_CONFIG_S_NEEDS_RESET bit is set and VIRTIO 1.0 is supported.
* Update the state machine that the device needs a reset, the state
  machine updates all queues using the obervee/oberver logic that they
  can't touch the hardware.
* Lastly the flag bDeviceNeedsReset is set to true. By setting this flag
  to true we inform Windows that the ParaNdis6_Reset should be called by
  NDIS. This happens beacuse in ParaNdis6_CheckForHang we return the value
  of the bDeviceNeedsReset flag which if set instructs Windows to call
  reset function. The ParaNdis6_CheckForHang is called periodically by
  NDIS every few seconds.

Signed-off-by: Sameeh Jubran <[email protected]>
Signed-off-by: Basil Salman <[email protected]>
2018-09-12 18:56:38 +03:00
Sameeh Jubran 70439e79d6 NetKVM: Add ReadDeviceStatus function
Signed-off-by: Sameeh Jubran <[email protected]>
2018-09-12 18:56:38 +03:00
Sameeh Jubran f895b6e933 NetKVM: Add NeedsReset/PowerOn logic to the State Machine
This patch enables the state machine to notify all of it's observers
when the device needs a reset or when the device has been powered on.

Signed-off-by: Sameeh Jubran <[email protected]>
2018-09-12 18:56:38 +03:00
Sameeh Jubran 99199cfa7e NetKVM: Guest Announce: Make sure CX exists
In the CX DPC path we execute the GuestAnnounce feature without checking
if CX was actually acked. This commit adds this check.

Signed-off-by: Sameeh Jubran <[email protected]>
2018-08-15 09:42:00 +03:00
Sameeh Jubran 331d0abfd7 NetKVM: Fix a typo
Signed-off-by: Sameeh Jubran <[email protected]>
2018-08-15 09:42:00 +03:00