virtio-win / kvm-guest-drivers-windows

Windows paravirtualized drivers for QEMU\KVM
https://www.linux-kvm.org/page/WindowsGuestDrivers
BSD 3-Clause "New" or "Revised" License
2.07k stars 386 forks source link

In the scenario of continuous transmission of small TCP packets, this may result in excessive paging. ultimately leading to packet loss in netkvm driver #972

Open zjmletang opened 1 year ago

zjmletang commented 1 year ago

Describe the bug the maximum number of fragments that can be accommodated by one descriptor is 256.However, in the scenario of sending small TCP packets, one NB_BUFF may have more than 256 fragments, which can cause sending to fail. //related code virtio_get_indirect_page_capacity() {

return PAGE_SIZE / sizeof(struct vring_desc);

}

//related code

bool CTXDescriptor::AddDataChunk(const PHYSICAL_ADDRESS &PA, ULONG Length)

{ if (m_CurrVirtioSGLEntry < m_VirtioSGLSize) { m_VirtioSGL[m_CurrVirtioSGLEntry].physAddr = PA; m_VirtioSGL[m_CurrVirtioSGLEntry].length = Length; m_CurrVirtioSGLEntry++; DPrintf(0, "zjm current < viritoSGLSize [%d] [%d] Length [%d]\n", m_CurrVirtioSGLEntry, m_VirtioSGLSize, Length);

    return true;
}

else { DPrintf(0, "zjm current > viritoSGLSize fail [%d] [%d]\n", m_CurrVirtioSGLEntry, m_VirtioSGLSize); // it may happen }

return false;

}

To Reproduce just like https://github.com/virtio-win/kvm-guest-drivers-windows/issues/942. The issue 942 primarily emphasizes the limitations on the network card hardware, while this case mainly illustrates the limitations of our own driver. However, the method of reproduction is the same.

ybendito commented 12 months ago

@zjmletang !IUC, we need the steps to reproduce the case when we get more than 256 fragments.

zjmletang commented 12 months ago

@ybendito We can reproduce this issue by continuously sending extremely short TCP packets, with the occurrence being guaranteed. The code has been included in the attachment. You can see the results in the screenshot below, where I've printed out NumberOfElements of m_SGL in the driver. It can be observed that for packets of length 1515, there are 524 fragments in the driver. Test Environment: Windows Server 2019,AliCloud VM demo.zip

image

Why would I mention TSO (TCP Segmentation Offload)? Because in practice, the use of extremely short packets is less common. However, when TSO is enabled, scenarios involving short packets could also likely result in more than 256 fragments. Such practical scenarios are quite prevalent.