From patchwork Mon Apr 10 06:30:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Herrenschmidt X-Patchwork-Id: 748846 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3w1gPN0d41z9s7m for ; Mon, 10 Apr 2017 16:33:44 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3w1gPM6thFzDqMJ for ; Mon, 10 Apr 2017 16:33:43 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from ozlabs.org (ozlabs.org [103.22.144.67]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3w1gKr5CM6zDqFJ for ; Mon, 10 Apr 2017 16:30:40 +1000 (AEST) Received: from ozlabs.org (ozlabs.org [103.22.144.67]) by bilbo.ozlabs.org (Postfix) with ESMTP id 3w1gKr40H8z8vHF for ; Mon, 10 Apr 2017 16:30:40 +1000 (AEST) Received: by ozlabs.org (Postfix) id 3w1gKr3Btnz9s7m; Mon, 10 Apr 2017 16:30:40 +1000 (AEST) Delivered-To: linuxppc-dev@ozlabs.org Received: from gate.crashing.org (gate.crashing.org [63.228.1.57]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3w1gKq6Fsbz9s7p for ; Mon, 10 Apr 2017 16:30:39 +1000 (AEST) Received: from pasglop.au.ibm.com (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.13.8) with ESMTP id v3A6U4v5009845; Mon, 10 Apr 2017 01:30:10 -0500 From: Benjamin Herrenschmidt To: linuxppc-dev@ozlabs.org Subject: [PATCH v2 3/3] powerpc/xive: Extra sanity checks on cpu numbers Date: Mon, 10 Apr 2017 16:30:01 +1000 Message-Id: <20170410063001.7235-3-benh@kernel.crashing.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170410063001.7235-1-benh@kernel.crashing.org> References: <20170410063001.7235-1-benh@kernel.crashing.org> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" When targetting interrupts we do various manipulations of cpu numbers and CPU masks. This adds some sanity checking to ensure we don't break assumptions and manpulate cpu numbers that are out of bounds of the various cpumasks. Signed-off-by: Benjamin Herrenschmidt --- arch/powerpc/sysdev/xive/common.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/sysdev/xive/common.c b/arch/powerpc/sysdev/xive/common.c index f37d257..f78a779 100644 --- a/arch/powerpc/sysdev/xive/common.c +++ b/arch/powerpc/sysdev/xive/common.c @@ -421,8 +421,10 @@ static void xive_dec_target_count(int cpu) struct xive_cpu *xc = per_cpu(xive_cpu, cpu); struct xive_q *q = &xc->queue[xive_irq_priority]; - if (WARN_ON(cpu < 0)) + if (unlikely(WARN_ON(cpu < 0 || !xc))) { + pr_err("%s: cpu=%d xc=%p\n", __func__, cpu, xc); return; + } /* * We increment the "pending count" which will be used @@ -446,8 +448,14 @@ static int xive_find_target_in_mask(const struct cpumask *mask, /* Locate it */ cpu = cpumask_first(mask); - for (i = 0; i < first; i++) + for (i = 0; i < first && cpu < nr_cpu_ids; i++) cpu = cpumask_next(cpu, mask); + + /* Sanity check */ + if (WARN_ON(cpu >= nr_cpu_ids)) + cpu = cpumask_first(cpu_online_mask); + + /* Remember first one to handle wrap-around */ first = cpu; /* @@ -540,6 +548,12 @@ static unsigned int xive_irq_startup(struct irq_data *d) pr_warn("XIVE: irq %d started with broken affinity\n", d->irq); } + + /* Sanity check */ + if (WARN_ON(target == XIVE_INVALID_TARGET || + target >= nr_cpu_ids)) + target = smp_processor_id(); + xd->target = target; /* @@ -670,6 +684,10 @@ static int xive_irq_set_affinity(struct irq_data *d, if (target == XIVE_INVALID_TARGET) return -ENXIO; + /* Sanity check */ + if (WARN_ON(target >= nr_cpu_ids)) + target = smp_processor_id(); + old_target = xd->target; /*