From 0de624aa4719ab43ea5465a4d34fd28d577f915d Mon Sep 17 00:00:00 2001 From: shurd Date: Wed, 29 Nov 2017 18:14:57 +0000 Subject: [PATCH] Ensure that ctx->ifc_cpus is always initialized If a device didn't support MSI-X, ctx->ifc_cpus would not be initialized, but the IRQ allocation routines still uses the value. Move the initialization to common code. Sponsored by: Limelight Networks --- sys/net/iflib.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/sys/net/iflib.c b/sys/net/iflib.c index c1ee25d5c0d4..2175bab7194c 100644 --- a/sys/net/iflib.c +++ b/sys/net/iflib.c @@ -4259,6 +4259,14 @@ iflib_device_register(device_t dev, void *sc, if_shared_ctx_t sctx, if_ctx_t *ct GROUPTASK_INIT(&ctx->ifc_admin_task, 0, _task_fn_admin, ctx); /* XXX format name */ taskqgroup_attach(qgroup_if_config_tqg, &ctx->ifc_admin_task, ctx, -1, "admin"); + + /* Set up cpu set. If it fails, zero out the set. */ + if (bus_get_cpus(dev, INTR_CPUS, sizeof(ctx->ifc_cpus), &ctx->ifc_cpus) != 0) { + device_printf(dev, "Unable to fetch CPU list\n"); + CPU_COPY(&all_cpus, &ctx->ifc_cpus); + } + MPASS(CPU_COUNT(&ctx->ifc_cpus) > 0); + /* ** Now setup MSI or MSI/X, should ** return us the number of supported @@ -4984,7 +4992,7 @@ find_nth(if_ctx_t ctx, cpuset_t *cpus, int qid) int i, cpuid, eqid, count; CPU_COPY(&ctx->ifc_cpus, cpus); - count = CPU_COUNT(&ctx->ifc_cpus); + count = CPU_COUNT(cpus); eqid = qid % count; /* clear up to the qid'th bit */ for (i = 0; i < eqid; i++) { @@ -5391,20 +5399,14 @@ iflib_msix_init(if_ctx_t ctx) #else queuemsgs = msgs - admincnt; #endif - if (bus_get_cpus(dev, INTR_CPUS, sizeof(ctx->ifc_cpus), &ctx->ifc_cpus) == 0) { #ifdef RSS - queues = imin(queuemsgs, rss_getnumbuckets()); + queues = imin(queuemsgs, rss_getnumbuckets()); #else - queues = queuemsgs; + queues = queuemsgs; #endif - queues = imin(CPU_COUNT(&ctx->ifc_cpus), queues); - device_printf(dev, "pxm cpus: %d queue msgs: %d admincnt: %d\n", - CPU_COUNT(&ctx->ifc_cpus), queuemsgs, admincnt); - } else { - device_printf(dev, "Unable to fetch CPU list\n"); - /* Figure out a reasonable auto config value */ - queues = min(queuemsgs, mp_ncpus); - } + queues = imin(CPU_COUNT(&ctx->ifc_cpus), queues); + device_printf(dev, "pxm cpus: %d queue msgs: %d admincnt: %d\n", + CPU_COUNT(&ctx->ifc_cpus), queuemsgs, admincnt); #ifdef RSS /* If we're doing RSS, clamp at the number of RSS buckets */ if (queues > rss_getnumbuckets())