kvm-guest-drivers-windows
kvm-guest-drivers-windows copied to clipboard
Tx no map - testing with DMAR with mapping disable for non-IP packets
@YanVugenfirer The motivation of this PR is first of all to test it and get closer to the root cause. Will we enable DMAR for Win10 or not - this is for later decision. If we don't - this is also OK. Let it run, then we'll discuss it.
@YanVugenfirer Also, there is an open question "where is the break-even" between mapping and copy. The mapping/unmapping operation is heavy and we definitely loose performance on short packets.
/gemini summary
Summary of Changes
This pull request introduces a mechanism to conditionally skip DMA remapping (DMAR) for transmit (Tx) packets in the NetKVM driver, primarily for testing and performance evaluation. It implements logic to determine when mapping can be bypassed, opting instead to copy packet data for specific scenarios, such as short packets without complex offloads. Additionally, it enhances logging and provides utilities to manage network protocol bindings, facilitating the testing of this DMAR behavior.
Highlights
- Conditional DMA Remapping Bypass: Implemented new logic within the
CNBL::CheckMappingNeeded()method to determine if DMA remapping (DMAR) is necessary for outgoing packets. This decision is based on factors such as packet size (if it's smaller than the maximum size for in-descriptor data), the absence of Large Send Offload (LSO), Checksum Offload (CSO), and UDP Segmentation Offload (USO), and thebAnyLayoutcontext flag. If mapping is deemed unnecessary, am_SkipMappingflag is set. - Packet Copying for Unmapped Packets: Modified the
CNBL::StartMapping()process to conditionally bypass the Scatter/Gather List (SGL) building. IfCheckMappingNeeded()indicates that mapping is not required, the packet data is directly handled (implicitly copied into the descriptor's header area byCNB::CopyHeadersandCNB::FillDescriptorSGList), avoiding the overhead associated with SGL creation and DMA mapping. This also includes a newcopiedTxPacketsstatistic for such cases. - DMAR Test Mode Activation: The
DmaRemappingCompatibleregistry setting innetkvm-base.txthas been explicitly changed fromINX_NETKVM_DMAREMAPto2. This change likely enables a specific test or permissive mode for DMAR, allowing the driver to exercise the new conditional mapping logic without strict enforcement of DMAR by the system. - Enhanced Debugging and Testing Utilities: Added new command-line options (
lfor log,zfor remove) to theProtocolServiceutility. These options enable logging of interface table information toc:\netkvmp.logand, for the 'z' option, allow for the dynamic collection and removal of 'ndistest' protocols. This provides a robust mechanism for setting up and tearing down specific network test environments, crucial for validating the DMAR bypass behavior.
Changelog
- NetKVM/Common/ParaNdis-TX.h
- Added
CheckMappingNeeded()andMappingNeeded()methods toCNBLfor conditional mapping decisions. - Introduced a new
m_SkipMappingboolean member toCNBLto store the mapping decision. - Modified
CNB::GetSGLLength()to safely handle a potentially nullm_SGLby returning 1. - Added
MaxSizeForPacketData()method toCParaNdisTXto expose the maximum packet data size that can fit in a descriptor's header area.
- Added
- NetKVM/Common/ParaNdis-VirtQueue.h
- Added
GetMaxSizeForPacketData()method toCTXVirtQueueto retrieve the maximum packet data size. - Introduced
m_MaxSizeForPacketDatamember toCTXVirtQueueto store this size.
- Added
- NetKVM/Common/ParaNdis_TX.cpp
- Implemented the core logic for
CNBL::CheckMappingNeeded()to determine if mapping can be skipped based on packet length, LSO, CSO, USO, andbAnyLayout. - Modified
CNBL::StartMapping()to conditionally callNB->ScheduleBuildSGListForTx()or directly callNB->MappingDone(nullptr)based on thebMappingNeededflag. - Adjusted
CNB::FillDescriptorSGList()to handle cases where the entire packet is headers (i.e., copied) by returningSUCCESSand incrementingcopiedTxPackets. - Modified
CNB::CopyHeaders()to copyMaxSizeof data if mapping is not needed, otherwise copyETH_HEADER_SIZE. - Updated
CNB::BindToDescriptor()to only returnFAILUREifm_SGLis null and mapping was actually required (m_ParentNBL->MappingNeeded()). - Wrapped
m_Historycleanup inCNBL::~CNBL()with#if NBL_MAINTAIN_HISTORY.
- Implemented the core logic for
- NetKVM/Common/ParaNdis_VirtQueue.cpp
- Initialized
m_MaxSizeForPacketDatainCTXVirtQueue::PrepareBuffers()using theMaxEthHeadersSize()of the first transmit descriptor.
- Initialized
- NetKVM/ProtocolService/Log.h
- Declared
extern FILE *LogFile;. - Modified the
Logmacro to write output toLogFileif it's open, otherwise fall back toOutputDebugStringA.
- Declared
- NetKVM/ProtocolService/Names.h
- Added
bsCollectProtocolsto thetBindingStateenum.
- Added
- NetKVM/ProtocolService/ProtocolService.cpp
- Defined
LogFileandListOfTestProtocolsglobal variables. - Implemented
AddToListfunction to collect 'ndistest' protocols. - Modified
CNetCfg::CheckBindingto handle the newbsCollectProtocolsstate by callingAddToList. - Updated
CInterfaceTable::Dumpto accept an optionaltBindingStateargument, allowing it to collect protocols. - Added new command-line options
l(log) andz(remove) tomain()for dumping interface tables to a log file and removing collected test protocols usingnetcfg -u.
- Defined
- NetKVM/netkvm-base.txt
- Changed the
DmaRemappingCompatibleregistry value fromINX_NETKVM_DMAREMAPto2.
- Changed the
Activity
- On May 18, 2025, @ybendito clarified that the PR's motivation is to test DMAR and investigate the performance trade-off between mapping and copying for short packets, emphasizing that the decision to enable DMAR for Win10 is a later consideration.
- On July 3, 2025, @kostyanf14 requested a summary of the pull request.