{"id":805239,"url":"http://patchwork.ozlabs.org/api/1.2/patches/805239/?format=json","web_url":"http://patchwork.ozlabs.org/project/linuxppc-dev/patch/1503553771-4483-1-git-send-email-mpe@ellerman.id.au/","project":{"id":2,"url":"http://patchwork.ozlabs.org/api/1.2/projects/2/?format=json","name":"Linux PPC development","link_name":"linuxppc-dev","list_id":"linuxppc-dev.lists.ozlabs.org","list_email":"linuxppc-dev@lists.ozlabs.org","web_url":"https://github.com/linuxppc/wiki/wiki","scm_url":"https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git","webscm_url":"https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git/","list_archive_url":"https://lore.kernel.org/linuxppc-dev/","list_archive_url_format":"https://lore.kernel.org/linuxppc-dev/{}/","commit_url_format":"https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git/commit/?id={}"},"msgid":"<1503553771-4483-1-git-send-email-mpe@ellerman.id.au>","list_archive_url":"https://lore.kernel.org/linuxppc-dev/1503553771-4483-1-git-send-email-mpe@ellerman.id.au/","date":"2017-08-24T05:49:31","name":"powerpc/xive: Fix the size of the cpumask used in xive_find_target_in_mask()","commit_ref":"a9dadc1c512807f955f0799e85830b420da47932","pull_url":null,"state":"accepted","archived":false,"hash":"d5f3f7b333046c651d31b4f00c08cba7d9df7a9c","submitter":{"id":46580,"url":"http://patchwork.ozlabs.org/api/1.2/people/46580/?format=json","name":"Michael Ellerman","email":"mpe@ellerman.id.au"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linuxppc-dev/patch/1503553771-4483-1-git-send-email-mpe@ellerman.id.au/mbox/","series":[],"comments":"http://patchwork.ozlabs.org/api/patches/805239/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/805239/checks/","tags":{},"related":[],"headers":{"Return-Path":"<linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org>","X-Original-To":["patchwork-incoming@ozlabs.org","linuxppc-dev@lists.ozlabs.org"],"Delivered-To":["patchwork-incoming@ozlabs.org","linuxppc-dev@lists.ozlabs.org","linuxppc-dev@ozlabs.org"],"Received":["from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68])\n\t(using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xdD1W3WYTz9t2Z\n\tfor <patchwork-incoming@ozlabs.org>;\n\tThu, 24 Aug 2017 15:51:11 +1000 (AEST)","from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 3xdD1W2LlpzDqm8\n\tfor <patchwork-incoming@ozlabs.org>;\n\tThu, 24 Aug 2017 15:51:11 +1000 (AEST)","from ozlabs.org (ozlabs.org [IPv6:2401:3900:2:1::2])\n\t(using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby lists.ozlabs.org (Postfix) with ESMTPS id 3xdCzj5LsRzDql8\n\tfor <linuxppc-dev@lists.ozlabs.org>;\n\tThu, 24 Aug 2017 15:49:37 +1000 (AEST)","by ozlabs.org (Postfix)\n\tid 3xdCzj4d4Kz9t34; Thu, 24 Aug 2017 15:49:37 +1000 (AEST)","by ozlabs.org (Postfix, from userid 1034)\n\tid 3xdCzj4FkKz9t3C; Thu, 24 Aug 2017 15:49:37 +1000 (AEST)"],"From":"Michael Ellerman <mpe@ellerman.id.au>","To":"linuxppc-dev@ozlabs.org","Subject":"[PATCH] powerpc/xive: Fix the size of the cpumask used in\n\txive_find_target_in_mask()","Date":"Thu, 24 Aug 2017 15:49:31 +1000","Message-Id":"<1503553771-4483-1-git-send-email-mpe@ellerman.id.au>","X-Mailer":"git-send-email 2.7.4","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","X-BeenThere":"linuxppc-dev@lists.ozlabs.org","X-Mailman-Version":"2.1.23","Precedence":"list","List-Id":"Linux on PowerPC Developers Mail List\n\t<linuxppc-dev.lists.ozlabs.org>","List-Unsubscribe":"<https://lists.ozlabs.org/options/linuxppc-dev>,\n\t<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=unsubscribe>","List-Archive":"<http://lists.ozlabs.org/pipermail/linuxppc-dev/>","List-Post":"<mailto:linuxppc-dev@lists.ozlabs.org>","List-Help":"<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=help>","List-Subscribe":"<https://lists.ozlabs.org/listinfo/linuxppc-dev>,\n\t<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=subscribe>","Cc":"clg@kaod.org","Errors-To":"linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org","Sender":"\"Linuxppc-dev\"\n\t<linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org>"},"content":"From: Cédric Le Goater <clg@kaod.org>\n\nWhen called from xive_irq_startup(), the size of the cpumask can be\nlarger than nr_cpu_ids. This can result in a WARN_ON such as:\n\n  WARNING: CPU: 10 PID: 1 at ../arch/powerpc/sysdev/xive/common.c:476 xive_find_target_in_mask+0x110/0x2f0\n  ...\n  NIP [c00000000008a310] xive_find_target_in_mask+0x110/0x2f0\n  LR [c00000000008a2e4] xive_find_target_in_mask+0xe4/0x2f0\n  Call Trace:\n    xive_find_target_in_mask+0x74/0x2f0 (unreliable)\n    xive_pick_irq_target.isra.1+0x200/0x230\n    xive_irq_startup+0x60/0x180\n    irq_startup+0x70/0xd0\n    __setup_irq+0x7bc/0x880\n    request_threaded_irq+0x14c/0x2c0\n    request_event_sources_irqs+0x100/0x180\n    __machine_initcall_pseries_init_ras_IRQ+0x104/0x134\n    do_one_initcall+0x68/0x1d0\n    kernel_init_freeable+0x290/0x374\n    kernel_init+0x24/0x170\n    ret_from_kernel_thread+0x5c/0x74\n\nThis happens because we're being called with our affinity mask set to\nirq_default_affinity. That in turn was populated using\ncpumask_setall(), which sets NR_CPUs worth of bits, not nr_cpu_ids\nworth. Finally cpumask_weight() will return > nr_cpu_ids when passed a\nmask which has > nr_cpu_ids bits set.\n\nFix it by limiting the value returned by cpumask_weight().\n\nSigned-off-by: Cédric Le Goater <clg@kaod.org>\n[mpe: Add change log details on actual cause]\nSigned-off-by: Michael Ellerman <mpe@ellerman.id.au>\n---\n arch/powerpc/sysdev/xive/common.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)","diff":"diff --git a/arch/powerpc/sysdev/xive/common.c b/arch/powerpc/sysdev/xive/common.c\nindex 0db4c45bc561..558df6542b1a 100644\n--- a/arch/powerpc/sysdev/xive/common.c\n+++ b/arch/powerpc/sysdev/xive/common.c\n@@ -447,7 +447,7 @@ static int xive_find_target_in_mask(const struct cpumask *mask,\n \tint cpu, first, num, i;\n \n \t/* Pick up a starting point CPU in the mask based on  fuzz */\n-\tnum = cpumask_weight(mask);\n+\tnum = min_t(int, cpumask_weight(mask), nr_cpu_ids);\n \tfirst = fuzz % num;\n \n \t/* Locate it */\n","prefixes":[]}