From 7c39e88ba6079ebb6bc9fa1e60c7233c656d9adb Mon Sep 17 00:00:00 2001 From: ae Date: Wed, 17 Aug 2016 20:21:33 +0000 Subject: [PATCH] Teach netisr_get_cpuid() to limit a given value to supported by netisr. Use netisr_get_cpuid() in netisr_select_cpuid() to limit cpuid value returned by protocol to be sure that it is not greather than nws_count. PR: 211836 Reviewed by: adrian MFC after: 3 days --- sys/net/if_epair.c | 4 ++-- sys/net/netisr.c | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/sys/net/if_epair.c b/sys/net/if_epair.c index 86e83799b75c..6ac65c68a7ef 100644 --- a/sys/net/if_epair.c +++ b/sys/net/if_epair.c @@ -807,9 +807,9 @@ epair_clone_create(struct if_clone *ifc, char *name, size_t len, caddr_t params) * cache locality but we can at least allow parallelism. */ sca->cpuid = - netisr_get_cpuid(sca->ifp->if_index % netisr_get_cpucount()); + netisr_get_cpuid(sca->ifp->if_index); scb->cpuid = - netisr_get_cpuid(scb->ifp->if_index % netisr_get_cpucount()); + netisr_get_cpuid(scb->ifp->if_index); /* Initialise pseudo media types. */ ifmedia_init(&sca->media, 0, epair_media_change, epair_media_status); diff --git a/sys/net/netisr.c b/sys/net/netisr.c index 24ac96c09715..755c288d2269 100644 --- a/sys/net/netisr.c +++ b/sys/net/netisr.c @@ -272,10 +272,7 @@ u_int netisr_get_cpuid(u_int cpunumber) { - KASSERT(cpunumber < nws_count, ("%s: %u > %u", __func__, cpunumber, - nws_count)); - - return (nws_array[cpunumber]); + return (nws_array[cpunumber % nws_count]); } /* @@ -810,10 +807,12 @@ netisr_select_cpuid(struct netisr_proto *npp, u_int dispatch_policy, * dispatch. In the queued case, fall back on the SOURCE * policy. */ - if (*cpuidp != NETISR_CPUID_NONE) + if (*cpuidp != NETISR_CPUID_NONE) { + *cpuidp = netisr_get_cpuid(*cpuidp); return (m); + } if (dispatch_policy == NETISR_DISPATCH_HYBRID) { - *cpuidp = curcpu; + *cpuidp = netisr_get_cpuid(curcpu); return (m); } policy = NETISR_POLICY_SOURCE;