Commit Graph
664 Commits
Author SHA1 Message Date
Yuri Benditovich 0a6c5fc482 netkvm: remove spaces at the beginning of the line
Signed-off-by: Yuri Benditovich <[email protected]>
2024-01-22 14:18:30 +02:00
Yuri Benditovich c21e0accd4 netkvm: report correct TX queue size via WMI
Signed-off-by: Yuri Benditovich <[email protected]>
2024-01-22 14:18:30 +02:00
Yuri Benditovich f25ede16eb netkvm: add metrics for allocated shared memory for RX
Signed-off-by: Yuri Benditovich <[email protected]>
2024-01-22 14:18:30 +02:00
Yuri Benditovich 641cc937e0 netkvm: add metrics for copied Tx packets
Signed-off-by: Yuri Benditovich <[email protected]>
2024-01-22 14:18:30 +02:00
Yuri Benditovich 634e6b4670 netkvm: rework vendor specific WMI properties
Split tx,rx and rss statistics
Add property for [initial] configuration data
Make reset of statistics selective and explicit
Add metrics for:
- minimal number of rx buffers
- indications with 'resource' flag
- amount of allocated shared memory

Signed-off-by: Yuri Benditovich <[email protected]>
2024-01-22 14:18:30 +02:00
junjiehua 00d2037945 [netkvm] add a workaround for rx packet loss
Implemented a workaround for rx packet loss encountered with TCP_NODELAY. By default,
this feature is turned off to minimize the impact on CPU performance and network bandwidth.

To activate the feature, go to the network card properties and set the MinRxBufferPercent
to a value above 0. A good starting point is to set MinRxBufferPercent to 25% and then monitor
for any packet loss. If packet loss continues, incrementally adjust the value to 50%, then 75%,
and if necessary, up to the maximum of 100%.

In extreme cases, it may be required to not only adjust the  MinRxBufferPercent but also to increase
the number of queues and the size of each queue (queue_size).

It is important to note that this feature is only applicable to rx packet loss.

For more details, see [this thread](https://github.com/virtio-win/kvm-guest-drivers-windows/issues/1012).

Signed-off-by: junjiehua <[email protected]>
2024-01-18 11:21:17 +02:00
Yuri Benditovich c81ff1fa55 netkvm: (minor) define IsPowerOfTwo in common header
And remove the same definition from various files.

Signed-off-by: Yuri Benditovich <[email protected]>
2024-01-17 15:01:17 +02:00
zhangjianminng c408c18940 netkvm: add the feature of copy mapping
for the problem description
please visit #942

Signed-off-by:  Zhang JianMing <[email protected]>
2024-01-16 15:31:03 +02:00
zhangjianminng 6c2f08a4d9 netkvm: refactor BindToDescriptor return type to use NBMappingStatus enum
This commit updates the CNB::BindToDescriptor method signature, changing
the return type from a boolean to the newly introduced NBMappingStatus
enum. The updated method now returns one of the following statuses:

    NBMappingStatus::SUCCESS
    NBMappingStatus::NO_RESOURCE
    NBMappingStatus::FAILURE

This change allows for more detailed reporting of the binding operation
outcome, enabling the caller to distinguish between different failure
reasons beyond the previous binary success/failure indication. The
NBMappingStatus enum provides a clearer, more expressive way to handle
the results of the binding process.

Signed-off-by:  Zhang JianMing <[email protected]>
2024-01-16 15:31:03 +02:00
zhangjianminng 6d23a8260b netkvm: add CopyFromMdlChain function to CNB class
This commit introduces the CopyFromMdlChain function to the CNB class. The function is responsible for copying data from a Memory Descriptor List (MDL) chain to a specified destination buffer. A special focus has been given to ensuring the function handles the traversal of the MDL chain correctly, updating the Source MDL pointer and the Offset within the current MDL as it progresses through the chain.

Signed-off-by:  Zhang JianMing <[email protected]>
2024-01-16 15:31:03 +02:00
zhangjianminng a9d3c71d03 netkvm: define MAX_FRAGMENTS_IN_ONE_NB macro to cap SGTableCapacity
This commit introduces the MAX_FRAGMENTS_IN_ONE_NB macro, which
defines the maximum number of fragments in a single NET_BUFFER. It
is used to constrain the SGTableCapacity value, ensuring it does
not exceed the meaningful limit set by MAX_FRAGMENTS_IN_ONE_NB.

Signed-off-by:  Zhang JianMing <[email protected]>
2024-01-16 15:31:03 +02:00
zhangjianminng 19ee48c26f netkvm: add additional pages to TXManager for upcoming copy mechanism
This commit introduces extra pages within the TXManager module,
which are intended to support the copy mechanism that will be
implemented in subsequent updates. The addition of these pages lays
the groundwork for the new functionality and ensures that the
TXManager is prepared for the enhancements.

Signed-off-by:  Zhang JianMing <[email protected]>
2024-01-16 15:31:03 +02:00
Yuri Benditovich 359f42c102 netkvm: filter RX packets as early as possible
https://issues.redhat.com/browse/RHEL-20575

Currently the driver get RX descriptor from the rx virtQ,
analyses it (L2/L3), calculates hash and delivers to the
proper RSS queue. Later it extract the packet from the RSS
queue and checks whether it passes RX filters.
Now we move the filtering to the earliest stage - just after
basic analysis.
Note that in case of vhost there are no receive filters
configured by the host and typically the host does not work
in promiscuous mode, so it is redundant to calculate the hash
and trigger the RSS queue for packets that should be dropped.

Signed-off-by: Yuri Benditovich <[email protected]>
2024-01-16 10:17:40 +02:00
Yuri Benditovich 1af7dfdb9d netkvm: add comments for CLockFreeDynamicQueue
Notes about procedures and synchronization

Signed-off-by: Yuri Benditovich <[email protected]>
2023-12-31 13:25:11 +02:00
Yuri Benditovich 96d0d03b40 netkvm: delete unused functions
Signed-off-by: Yuri Benditovich <[email protected]>
2023-12-31 13:25:11 +02:00
Yuri Benditovich da89ff8406 netkvm: remove erroneous CParaNdisTX::BuildCancelList
https://issues.redhat.com/browse/RHEL-19833

Commit e8f319fdc0 in part of NBL cancellation was wrong.
NBLs not matching the CancelId are lost, they will not be
neither sent nor completed. Leave the cancellation path
not implemented (as it is optional).

Signed-off-by: Yuri Benditovich <[email protected]>
2023-12-31 13:25:11 +02:00
Yuri Benditovich 3743aa9df0 netkvm: remove query for OID_GEN_TRANSMIT_QUEUE_LENGTH
https://issues.redhat.com/browse/RHEL-19441
The response to the query is calculated incorrectly.
We can make it correct but I think that support for this
OID is not required, it is not in the list of mandatory
OIDs. In general the NDIS has the same knowledge about
how many packets are queued by the miniport.

Signed-off-by: Yuri Benditovich <[email protected]>
2023-12-19 15:57:52 +02:00
Yuri Benditovich 93015d29c4 netkvm: add statistics for TX events of interest
Adding statistics for failed TX packets
(ones that can't be mapped using available indirect area) and
minimal available TX descriptors (if one or more TX virtqueues
were completely filled by packets this field will be read as 0)
These statistics fields are printed on disable and also available
at run-time via WMI.

Signed-off-by: Yuri Benditovich <[email protected]>
2023-12-18 13:38:13 +02:00
Yuri Benditovich b0468b1b22 netkvm: fix assignment of TX m_FreeHWBuffers
The assignment of m_FreeHWBuffers etc is wrong. If one of
TX descriptors is not allocated we need to take this in
account.

Signed-off-by: Yuri Benditovich <[email protected]>
2023-12-18 13:38:13 +02:00
Yuri Benditovich 14b4ce09a0 netkvm: limit indirect area usage when needed
https://issues.redhat.com/browse/RHEL-19317

Virtio spec 1.2 says in
"2.7.5.3.1 Driver Requirements: Indirect Descriptors":
"A driver MUST NOT create a descriptor chain longer than the Queue Size
of the device."
In case the device reports TX queue size shorter than 256 the driver
still can create a chain of up to 256 descriptors in the _indirect_
area. This commit limits the usage of indirect area by the actual
number of the TX descriptors created for the queue.
Note that QEMU of the day is able to retrieve up to 1024 descriptors
regardless the TX queue size and also does not allow to configure
the TX queue size to less than 256, but not required to do so.

Signed-off-by: Yuri Benditovich <[email protected]>
2023-12-18 13:38:13 +02:00
Yuri Benditovich 84609ae0de netkvm: support of VF statistics
Currently in the statistics reported by the netkvm adapter does
not include the packets transmitted via VF and received from VF.
The commit fixes it: it maintains the VF statistics and on each call
adds the difference of first call it saves the statistics of VF,
on further calls if updates netkvm statistics.

Signed-off-by: Yuri Benditovich <[email protected]>
2023-07-02 12:57:58 +03:00
Yuri Benditovich 7ce3833594 netkvm: move SET_LINK IOCTL to separate procedure
Signed-off-by: Yuri Benditovich <[email protected]>
2023-07-02 12:57:58 +03:00
Yuri Benditovich 0e44fb5aa6 netkvm: external management of binding states
The protocol part (VF binding) is changed to change it's state
when required to do so by the protocol service.
Only VF removal changes the state of binding/netkvm adapter
without external request.

Signed-off-by: Yuri Benditovich <[email protected]>
2023-07-02 12:57:58 +03:00
Yuri Benditovich 4c4c84eff0 netkvm: fix RX packets counting in the protocol implementation
If the bound VF adapter reports a packet with RESOURCES flag
the protocol handler must never return it and also NDIS never
returns it, the VF driver retains the ownership. Fix the
counting for such packets. We can see sometimes such packets
at least with I350 VF.

Signed-off-by: Yuri Benditovich <[email protected]>
2023-07-02 12:57:58 +03:00
Yuri Benditovich 333aa33cc2 netkvm: fix memory leak in case of rejected binding
When the OS tries to bind the netkvm adapter to VIOPROT
the driver rejects the binding, but a memory leak happens.
Current commit solves it.

Signed-off-by: Yuri Benditovich <[email protected]>
2023-07-02 12:57:58 +03:00
Yuri Benditovich ba6d0f6eae netkvm: add control device to the driver
Control device lifecycle follows one of failover protocol, i.e.
created with first virtio-net device and deleted with the
removal of the last one. User-mode component can use device
IO controls to access it.

Signed-off-by: Yuri Benditovich <[email protected]>
2023-07-02 12:57:58 +03:00
Kfir Manor d018cb25fb netkvm: change RxCapacity maximum to 4096
resolve:
https://github.com/virtio-win/kvm-guest-drivers-windows/issues/831

The Problem, RxCapacity of size 1024 isn't enough for some situations

Fix, add higher RxCapacity values as options

Signed-off-by: Kfir Manor <[email protected]>
2023-02-15 13:50:05 +02:00
Kfir Manor 966e23c58c HBZ#2156297 netkvm: change RxCapacity minimum to 16
resolve:https://github.com/virtio-win/kvm-guest-drivers-windows/issues/830

The problem, RxCapacity of value 16 is in the inf file. But the minimum
of defaultConfiguration is 32, meaning that setting RxCapacity to 16 in
the device manager doesn't take effect.

Fix: change the minimum of defaultConfiguration to 16

Signed-off-by: Kfir Manor <[email protected]>
2023-02-15 13:50:05 +02:00
Yuri Benditovich 315c637bf5 Revert "netkvm: do not complete packets in sending path"
https://bugzilla.redhat.com/show_bug.cgi?id=2067167
https://bugzilla.redhat.com/show_bug.cgi?id=2063594

This reverts commit 5fcd9ea620.
Mentioned commit was intended to solve the problem
https://bugzilla.redhat.com/show_bug.cgi?id=1972487

But during later tests it was found that the commit has triggered
other problems in perf6 and mpe tests
We revert the commit and continue the investigation

Signed-off-by: Yuri Benditovich <[email protected]>
2022-04-06 10:47:54 +03:00
Yuri Benditovich 5fcd9ea620 netkvm: do not complete packets in sending path
https://bugzilla.redhat.com/show_bug.cgi?id=1972487
Complete packets (i.e. get buffers from TX queue and
process waiting list) only when called from DPC (on
TX completion DPC or RX DPC). According to the tests
thos solves assertion "pCurrentNetBufferList" in the
NDPROT630 driver.

Signed-off-by: Yuri Benditovich <[email protected]>
2022-01-17 10:48:15 +02:00
Kostiantyn Kostiuk 5f8e50aec7 NetKVM: Remove code for legacy OSes
Signed-off-by: Kostiantyn Kostiuk <[email protected]>
2022-01-11 09:47:09 +02:00
yach-yf e04ad11081 NetKVM: Fix dropping IPv6 IPsec packets.
Explicitly treat IPv6 ESP packet as usual packet (TCP, UDP, etc.).
ESP header should not be treated like other extension headers.
Because it does not start with 'Next Header' and 'Hdr Ext Len' fields and next header is encrypted.

Signed-off-by: yach-yf <[email protected]>
2021-09-24 11:02:28 +03:00
Kostiantyn Kostiuk 45e37d579a NetKVM: Use 'enum class' instead of 'enum' (CA warning 26812)
Update _tagPacketOffloadRequest enum.

Signed-off-by: Kostiantyn Kostiuk <[email protected]>
2021-09-19 09:40:30 +03:00
Kostiantyn Kostiuk 9b4b3998c8 NetKVM: Use 'enum class' instead of 'enum' (CA warning 26812)
Update _tagppResult enum.

Signed-off-by: Kostiantyn Kostiuk <[email protected]>
2021-09-19 09:40:30 +03:00
Kostiantyn Kostiuk 483395fcbe NetKVM: Use 'enum class' instead of 'enum' (CA warning 26812)
Update _tagSubmitTxPacketResult enum.

Signed-off-by: Kostiantyn Kostiuk <[email protected]>
2021-09-19 09:40:30 +03:00
Kostiantyn Kostiuk 4378dddc00 NetKVM: Fix SMNotifications enum value spelling
Signed-off-by: Kostiantyn Kostiuk <[email protected]>
2021-09-19 09:40:30 +03:00
Kostiantyn Kostiuk e5eaaf9f65 NetKVM: Use 'enum class' instead of 'enum' (CA warning 26812)
Updatee SMNotifications enum

Signed-off-by: Kostiantyn Kostiuk <[email protected]>
2021-09-19 09:40:30 +03:00
Kostiantyn Kostiuk e169859ae5 NetKVM: Use 'enum class' instead of 'enum' (CA warning 26812)
Update _tagPARANDIS_RSS_MODE enum.

Signed-off-by: Kostiantyn Kostiuk <[email protected]>
2021-09-19 09:40:30 +03:00
Kostiantyn Kostiuk bf50cc9a3a NetKVM: Use 'enum class' instead of 'enum' (CA warning 26812)
Update MiniportState enum

Signed-off-by: Kostiantyn Kostiuk <[email protected]>
2021-09-19 09:40:30 +03:00
Kostiantyn Kostiuk cab22f3507 NetKVM: Use 'enum class' instead of 'enum' (CA warning 26812)
Update FlowState enum

Signed-off-by: Kostiantyn Kostiuk <[email protected]>
2021-09-19 09:40:30 +03:00
Kostiantyn Kostiuk a5a72476c5 NetKVM: Use 'enum class' instead of 'enum' (CA warning 26812)
Update NotifyEvent enum

Signed-off-by: Kostiantyn Kostiuk <[email protected]>
2021-09-19 09:40:30 +03:00
Kostiantyn Kostiuk 119238e3d3 NetKVM: Use 'enum class' instead of 'enum' (CA warning 26812)
Update _etagHistoryLogOperation enum

Signed-off-by: Kostiantyn Kostiuk <[email protected]>
2021-09-19 09:40:30 +03:00
Yuri Benditovich 09c5d50c2c netkvm: prevent link error for __stdio_common_vsprintf
Depending on Visual Studio version the error can happen in
the build from Visual Studio. For details see
https://stackoverflow.com/questions/67740175/unresolved-external-symbol-stdio-common-vswprintf

Signed-off-by: Yuri Benditovich <[email protected]>
2021-09-13 10:44:20 +03:00
Viktor Prutyanov 2148fb1604 NetKVM: fix uninitialized variables (CA)
Signed-off-by: Viktor Prutyanov <[email protected]>
2021-09-12 09:10:39 +03:00
Viktor Prutyanov 4558fbfb25 NetKVM: fix uninitialized LIST_ENTRY variables (CA)
Signed-off-by: Viktor Prutyanov <[email protected]>
2021-09-12 09:10:39 +03:00
Viktor Prutyanov 90bc6b5c3a NetKVM: add status check (CA)
Signed-off-by: Viktor Prutyanov <[email protected]>
2021-09-12 09:04:22 +03:00
Viktor Prutyanov 95dcb7216b NetKVM: fix possible 'Nbl' NULL pointer usage (CA)
Protect NdisSendNetBufferLists from passing Nbl == NULL.

Signed-off-by: Viktor Prutyanov <[email protected]>
2021-09-12 09:04:22 +03:00
Viktor Prutyanov 3d54b6d5c0 NetKVM: fix possible arithmetic overflows (CA)
Value should be casted to wider type before calling operator.

Signed-off-by: Viktor Prutyanov <[email protected]>
2021-09-05 17:00:26 +03:00
Viktor Prutyanov ff9cf07442 NetKVM: fix comparison with wider type and uninitialized var (CodeQL)
- Comparison with wider type
- SM02323
- Uninitialized local variable

Signed-off-by: Viktor Prutyanov <[email protected]>
2021-09-05 17:00:26 +03:00
Sergey Bykov 0534862e89 NetKVM: Fix possible PF on ParaNdis6_CancelSendNetBufferLists path
Current implementation of CParaNdisTX::BuildCancelList may trigger page fault
and a bugcheck if m_SendQueue is already empty.

Trap:
2: kd> .trap ffffcc81`1b5d2520
NOTE: The trap frame does not contain all registers.
Some register values may be zeroed or incorrect.
rax=0000000000000000 rbx=0000000000000000 rcx=00000000000019a4
rdx=00000000000019a5 rsi=0000000000000000 rdi=0000000000000000
rip=fffff80eae479edf rsp=ffffcc811b5d26b0 rbp=ffffa4873a248ee8
 r8=ffffa487392bae80  r9=0000000000000002 r10=ffffa487391f0c30
r11=0000000000000001 r12=0000000000000000 r13=0000000000000000
r14=0000000000000000 r15=0000000000000000
iopl=0         nv up ei ng nz na po nc
netkvm!CNBL::MatchCancelID [inlined in
netkvm!CParaNdisTX::BuildCancelList+0x3f]:
fffff80e`ae479edf 488b4320        mov     rax,qword ptr [rbx+20h]
ds:00000000`00000020=????????????????
2: kd> r cr2
Last set context:
cr2=0000000000000020

Callstack:
2: kd> kc
  *** Stack trace for last set context - .thread/.cxr resets it
 # Call Site
00 netkvm!CNBL::MatchCancelID
01 netkvm!CParaNdisTX::BuildCancelList
02 netkvm!CParaNdisTX::CancelNBLs
03 netkvm!ParaNdis6_CancelSendNetBufferLists
04 NDIS!ndisMCancelSendNetBufferListsOnMiniport
05 nt!KeExpandKernelStackAndCalloutInternal
06 NDIS!ndisExpandStack
07 NDIS!ndisFilterCancelSendNetBufferLists
08 klim6
09 NDIS!ndisFInvokePause
0a NDIS!ndisPauseFilterInner
0b NDIS!ndisPauseFilter
0c NDIS!Ndis::BindEngine::Iterate
0d NDIS!Ndis::BindEngine::UpdateBindings
0e NDIS!Ndis::BindEngine::DispatchPendingWork
0f NDIS!Ndis::BindEngine::ApplyBindChanges
10 NDIS!ndisPnPRemoveDevice
11 NDIS!ndisPnPRemoveDeviceEx
12 NDIS!ndisPnPIrpRemoveDevice
13 NDIS!ndisPnPDispatch
14 nt!IopSynchronousCall
15 nt!IopRemoveDevice
16 nt!PnpRemoveLockedDeviceNode
17 nt!PnpDeleteLockedDeviceNode
18 nt!PnpDeleteLockedDeviceNodes
19 nt!PnpProcessQueryRemoveAndEject
1a nt!PnpProcessTargetDeviceEvent
1b nt!PnpDeviceEventWorker
1c nt!ExpWorkerThread
1d nt!PspSystemThreadStartup
1e nt!KiStartSystemThread

Queue state:
2: kd> dt netkvm!CLockFreeDynamicQueue<CNBL> 0xffffa4873a248ee8
   +0x000 m_Queue          : CLockFreeQueue<CNBL>
   +0x030 m_QueueFullList  :
CNdisList<CNBL,CRawAccess,CNonCountingObject>
   +0x048 m_QueueFullListLock : CNdisSpinLock
   +0x058 m_QueueFullListIsEmpty : 0n1
   +0x05c m_ElementCount   : 0n0
   +0x060 m_Size           : 0n8192

The fix is trivial: check if CNBL is empty before trying to access its fields.

Signed-off-by: Sergey Bykov <[email protected]>
2021-08-29 23:45:13 +03:00