From 657ad7efb539dd186cec1fd33cf31ba710f5dfb1 Mon Sep 17 00:00:00 2001 From: Yuri Benditovich Date: Mon, 6 May 2024 10:22:20 +0300 Subject: [PATCH] netkvm: fix affinity of poll handlers https://issues.redhat.com/browse/RHEL-33334 Fix wrong affinity assignment. Signed-off-by: Yuri Benditovich --- NetKVM/Common/ndis56common.h | 3 ++- NetKVM/wlh/ParaNdis6_RSS.cpp | 5 +---- NetKVM/wlh/ParaNdis_Poll.cpp | 38 +++++++++++++++++++++++------------- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/NetKVM/Common/ndis56common.h b/NetKVM/Common/ndis56common.h index 076d79308..75420c83e 100755 --- a/NetKVM/Common/ndis56common.h +++ b/NetKVM/Common/ndis56common.h @@ -130,7 +130,7 @@ static bool FORCEINLINE CheckOSNdisVersion(UCHAR osmajor, UCHAR osminor) typedef struct _PARANDIS_ADAPTER PARANDIS_ADAPTER; void ParaNdisPollNotify(PARANDIS_ADAPTER *, UINT Index, const char *Origin); -void ParaNdisPollSetAffinity(PARANDIS_ADAPTER *, const CCHAR *Indices, CCHAR Size); +void ParaNdisPollSetAffinity(PARANDIS_ADAPTER *); void RxPoll(PARANDIS_ADAPTER* pContext, UINT BundleIndex, NDIS_POLL_RECEIVE_DATA& RxData); #include "ParaNdis-SM.h" @@ -186,6 +186,7 @@ struct NdisPollHandler void Unregister(); void EnableNotification(BOOLEAN Enable); void HandlePoll(NDIS_POLL_DATA* PollData); + bool UpdateAffinity(const PROCESSOR_NUMBER&); }; struct CPUPathBundle : public CPlacementAllocatable { diff --git a/NetKVM/wlh/ParaNdis6_RSS.cpp b/NetKVM/wlh/ParaNdis6_RSS.cpp index 151c35fc4..848864e01 100644 --- a/NetKVM/wlh/ParaNdis6_RSS.cpp +++ b/NetKVM/wlh/ParaNdis6_RSS.cpp @@ -567,10 +567,7 @@ NDIS_STATUS ParaNdis6_RSSSetParameters( PARANDIS_ADAPTER *pContext, SetDeviceRSSSettings(pContext); if (pContext->bPollModeEnabled) { - ParaNdisPollSetAffinity( - pContext, - RSSParameters->RSSScalingSettings.QueueIndirectionTable, - RSSParameters->ReceiveQueuesNumber); + ParaNdisPollSetAffinity(pContext); } } diff --git a/NetKVM/wlh/ParaNdis_Poll.cpp b/NetKVM/wlh/ParaNdis_Poll.cpp index 0c19ed7e0..285acdbbb 100644 --- a/NetKVM/wlh/ParaNdis_Poll.cpp +++ b/NetKVM/wlh/ParaNdis_Poll.cpp @@ -42,27 +42,37 @@ static void UpdatePollAffinities(PPARANDIS_ADAPTER pContext) DPrintf(0, "updated #%d affinities\n", done); } -void ParaNdisPollSetAffinity(PARANDIS_ADAPTER* pContext, const CCHAR* Indices, CCHAR Size) +bool NdisPollHandler::UpdateAffinity(const PROCESSOR_NUMBER& Number) +{ + if (Number.Group != m_ProcessorNumber.Group || Number.Number != m_ProcessorNumber.Number) + { + m_ProcessorNumber = Number; + m_UpdateAffinity = true; + DPrintf(POLL_PRINT_LEVEL, "[%s] #%d => %d:%d\n", __FUNCTION__, m_Index, Number.Group, Number.Number); + return true; + } + return false; +} + +void ParaNdisPollSetAffinity(PARANDIS_ADAPTER* pContext) { bool needUpdate = false; - for (CCHAR i = 0; i < Size && i < ARRAYSIZE(pContext->PollHandlers); ++i) + const auto& rssSettings = pContext->RSSParameters.ActiveRSSScalingSettings; + + for (ULONG i = 0; i <= rssSettings.RSSHashMask; ++i) { - LONG index = Indices[i]; - if (index >= 0) + CCHAR index = rssSettings.QueueIndirectionTable[i]; + const PROCESSOR_NUMBER& procNo = rssSettings.IndirectionTable[i]; + if (index < ARRAYSIZE(pContext->PollHandlers)) { - PROCESSOR_NUMBER number; - if (KeGetProcessorNumberFromIndex(index, &number) == STATUS_SUCCESS) + NdisPollHandler* poll = &pContext->PollHandlers[index]; + if (poll->UpdateAffinity(procNo)) { - NdisPollHandler* poll = &pContext->PollHandlers[i]; - if (number.Group != poll->m_ProcessorNumber.Group || number.Number != poll->m_ProcessorNumber.Number) - { - poll->m_ProcessorNumber = number; - poll->m_UpdateAffinity = true; - needUpdate = true; - } + needUpdate = true; } } } + if (needUpdate) { NDIS_HANDLE hwo = NdisAllocateIoWorkItem(pContext->MiniportHandle); @@ -139,7 +149,7 @@ void NdisPollHandler::HandlePoll(NDIS_POLL_DATA* PollData) #else -void ParaNdisPollSetAffinity(PARANDIS_ADAPTER*, const CCHAR*, CCHAR) +void ParaNdisPollSetAffinity(PARANDIS_ADAPTER*) { }