From patchwork Wed Dec 16 17:08:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 7863961 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id DE653BEEE1 for ; Wed, 16 Dec 2015 17:10:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 11FE6201EF for ; Wed, 16 Dec 2015 17:10:25 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1E7DE2017D for ; Wed, 16 Dec 2015 17:10:24 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1a9FZS-0004jm-U0; Wed, 16 Dec 2015 17:08:58 +0000 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1a9FZG-0004Wc-Qd for linux-arm-kernel@lists.infradead.org; Wed, 16 Dec 2015 17:08:48 +0000 Received: by mail-wm0-x234.google.com with SMTP id p187so10228270wmp.0 for ; Wed, 16 Dec 2015 09:08:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=F3bi1+cbDqTH/f5MBleULAwOgH4VFJbN5YEoen104MI=; b=bIw0Zovsh+PupbciQD5iZfq9VmzyHqDaLdwdw07Sl0IGpw3fvrOmnorBHRM5DNUEoA 9ac5Y2tBtfxP/1I9RZemQYrx4VaxckQl3QSpDIo4VY0mXpckmdAQNYV0cu9HL9AnxkZe aTWs2N3aY6qZZyP8c5jUQ++2S1fahqoVssMbo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=F3bi1+cbDqTH/f5MBleULAwOgH4VFJbN5YEoen104MI=; b=ccq4e7WNceHVR90TSw+aeP/SNgLko8KGqF1n3pil3Xwg9jOgifFohW1S5QtQU/E6Rm Bi1PSXS4N4BD8HxAeP/auej0WKzT1J7/XoKD4TXYOTIAsz6O7wvs5HUzaz+fKrjqkYLp Qs29eynB1AOnSIsyGcsllCXElHqZLXa9BlhfxGUs6+ItL7Wf0LfIvGkLyaenKuj+oGV8 qb8ni9M/H4hwZp7M54QoEchVzJ4j5quyAtU2shbFE/n0YIu8eGhm8ZYlApfTNgCXUyTz ltgjIqsKXPrp0PEN8piK+tJYpVBm+tVlbvEsq58UKNPnIMZK1TwUOyv8JLpod1FjKJBi hn7Q== X-Gm-Message-State: ALoCoQnzQ4ZK8+EG3TiyQ8gn2Izb5JK9qn3KKXp857eUhAOJ/716LMsEulgfmgX7SSd8ryQ2/ZzM1IEddITU69U+/vX1vt9k+Q== X-Received: by 10.194.178.70 with SMTP id cw6mr52070288wjc.73.1450285707366; Wed, 16 Dec 2015 09:08:27 -0800 (PST) Received: from wychelm.lan (cpc4-aztw19-0-0-cust71.18-1.cable.virginm.net. [82.33.25.72]) by smtp.gmail.com with ESMTPSA id 186sm8228936wmv.9.2015.12.16.09.08.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Dec 2015 09:08:26 -0800 (PST) From: Daniel Thompson To: Russell King Subject: [PATCH 2/2] irqchip/gic: Identify and report any reserved SGI IDs Date: Wed, 16 Dec 2015 17:08:06 +0000 Message-Id: <1450285686-844-3-git-send-email-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1450285686-844-1-git-send-email-daniel.thompson@linaro.org> References: <1450285686-844-1-git-send-email-daniel.thompson@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151216_090847_032322_B697C6B8 X-CRM114-Status: GOOD ( 17.02 ) X-Spam-Score: -2.7 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Thompson , linaro-kernel@lists.linaro.org, Jason Cooper , patches@linaro.org, Marc Zyngier , linux-kernel@vger.kernel.org, Thomas Gleixner , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP It is possible for the secure world to reserve certain SGI IDs for itself. Currently we have limited visibility of which IDs are safe to use for IPIs. Modify the GIC initialization code to actively search for reserved SGI IDs and report if any are found. Warn even more loudly if the reserved SGIs overlap with the normal IPI range. When run on an Inforce IFC6410 (Snapdragon 600) this code produces the following messages: ~~~ cut here ~~~ CPU0: Detected reserved SGI IDs: 14-15 CPU1: Detected reserved SGI IDs: 15 CPU2: Detected reserved SGI IDs: 15 CPU3: Detected reserved SGI IDs: 15 ~~~ cut here ~~~ Signed-off-by: Daniel Thompson --- drivers/irqchip/irq-gic.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c index abf2ffaed392..541622da7049 100644 --- a/drivers/irqchip/irq-gic.c +++ b/drivers/irqchip/irq-gic.c @@ -490,6 +490,7 @@ static void gic_cpu_init(struct gic_chip_data *gic) void __iomem *base = gic_data_cpu_base(gic); unsigned int cpu_mask, cpu = smp_processor_id(); int i; + DECLARE_BITMAP(sgi_mask, 16); /* * Setting up the CPU map is only relevant for the primary GIC @@ -511,6 +512,58 @@ static void gic_cpu_init(struct gic_chip_data *gic) for (i = 0; i < NR_GIC_CPU_IF; i++) if (i != cpu) gic_cpu_map[i] &= ~cpu_mask; + + /* + * Fiddle with the SGI set/clear registers to try identify + * any IPIs that are reserved for secure world. + */ + bitmap_fill(sgi_mask, 16); + + for (i = 0; i < 16; i++) { + void __iomem *set_reg = + dist_base + GIC_DIST_SGI_PENDING_SET + (i & ~3); + void __iomem *clear_reg = + dist_base + GIC_DIST_SGI_PENDING_CLEAR + (i & ~3); + unsigned long mask = cpu_mask << (8*(i%4)); + unsigned long flags, pending, after_clear, after_set; + + local_irq_save(flags); + + /* record original value */ + pending = readl_relaxed(set_reg); + + /* clear, test, set, and test again */ + writel_relaxed(mask, clear_reg); + after_clear = readl_relaxed(set_reg); + writel_relaxed(mask, set_reg); + after_set = readl_relaxed(set_reg); + + /* restore original value */ + writel_relaxed(mask & ~pending, clear_reg); + + local_irq_restore(flags); + + if (mask & ~after_clear && mask & after_set) + clear_bit(i, sgi_mask); + } + + /* + * Show the SGI mask if it is "interesting". Here interesting + * means that the set/clear register is implemented + * (mask is not full) and it tells us that the secure world + * has reserved some SGIs (mask is not empty). + */ + if (!bitmap_full(sgi_mask, 16) && !bitmap_empty(sgi_mask, 16)) + pr_info("CPU%d: Detected reserved SGI IDs: %*pbl\n", + cpu, 16, sgi_mask); + + /* + * Yell if the reserved IDs make the system unviable. + */ + if (!bitmap_full(sgi_mask, 16) && + find_first_bit(sgi_mask, 16) < NR_IPI) + pr_crit("CPU%d: Not enough SGI IDs; expect failure\n", + cpu); } gic_cpu_config(dist_base, NULL);