From patchwork Thu Oct 29 02:37:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greentime Hu X-Patchwork-Id: 11865081 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2109E61C for ; Thu, 29 Oct 2020 02:38:12 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8E3742075E for ; Thu, 29 Oct 2020 02:38:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="EN+pLiub"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="LVDiaDb7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8E3742075E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=biKVfKKnmp7uUxv6PXRFVcQqiooOi8Vxf2Bl3vTnp1U=; b=EN+pLiub993QSTyfNJ1/EG0HYd CLeE+b1ErmWXcPlSAqMsaM6ExV2f/w5ukWAiewxOxJ9mIbJGRfHUM7K252FvWXQY6PD1z+L+FTXN3 WDhTsyfbkGH3lB7M88E1nbTacABKx+OwEYwB/q6S/DcHxzRpJkTUh5KyohkEKwYx/0A1NZmdShzKM +h5cVVfSJn3gpzEm7Pb4IcaccxuUJjWapneFj3zOJQPtPPiz9C1rj9WbSf505tUCXazXNSytAT8s6 FKSqjUIZBnIYLapDoxgZgE9SQ0EKvQmuHGz0YbSVpoFw9eINWM1xKOY5hFSXxNVVuA/l7yJDWXY/7 24W0OqOQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kXxp2-0000k9-2i; Thu, 29 Oct 2020 02:37:52 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kXxoz-0000jY-I1 for linux-riscv@lists.infradead.org; Thu, 29 Oct 2020 02:37:50 +0000 Received: by mail-pf1-x441.google.com with SMTP id 133so1090734pfx.11 for ; Wed, 28 Oct 2020 19:37:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=8BJM60PKaoEKj00yNY+zacUHj7sixX+JrHufabOqrIM=; b=LVDiaDb7DqbpKD1Pmlk5RxehD/gQit+lY8i95m/E2twOa1WzIC/CtYY09vh+hUbvqx Q9fjGzTerOmg9h583YjWmq0DVGTSm7eAdFqktip14MD4rSIvjcdzGSFkXnhB5+IG5OAK ofWzSiHneNymFpbAMRrby4PTWKPOd1xzxopvCq7wanOMcH5tpM7Zat17ChGIareyNMy9 Bew82f+hNhHp21jXD/unV2kB0SkLdut1qvLM6eb6WCBZ68jtFrNQXcLZz8ueIfBWFmm3 RYzOLRcUqny4fxaTJAEVHS/7cLEuRgouG4hYR7i2ihyIxBimZUQrkKfSuCdZ57+PWRA3 qhZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=8BJM60PKaoEKj00yNY+zacUHj7sixX+JrHufabOqrIM=; b=bzoOVtFWKAlG6/aPH9QSdaJlUrylAVv4mayypIKKEVD+lFFslVA3Tl95nFGSzg6oIr tcSPx42gMsIHTOdrE0Q8S7TyEa6m0Wsa4UClC/Kz5ocL+Em7TeHHUuQFS0GqG9dL17NA uYw9hgbhdzXw6AlB+9aphiyXINheSVCb1AuIuSU17qrEjs4NdioJp7an0zRZ8Vix6mTO fQmQ76giamDgGPkAyguLBD6mz81wiOq5N2fim4W+B7VolZKaw7R7k8Okq2yhAuIAHggd nDjlOpzcpve9q8TdGw6/e1iQWcG6SiRusQfSchcD+ioxZ0bAyTt0nW3OPP9j7Z9Wq+LR 4Ybg== X-Gm-Message-State: AOAM533nCXdHAs0ieCJgRjsYgNXJtpY3PAmH/6+f5r+bbmrXO22Yc6Yd 7AIhWbxNw+2Ywfcvs7QJ8aNOhw== X-Google-Smtp-Source: ABdhPJxcHklV3nxy/AFIGb3+KF+AnR/snc5d+2hO0JSkM2y4CVGmn6OHasonAgvQZizKx8zTnvarxg== X-Received: by 2002:a63:ca52:: with SMTP id o18mr2111302pgi.422.1603939065984; Wed, 28 Oct 2020 19:37:45 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id bx24sm718945pjb.20.2020.10.28.19.37.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 19:37:45 -0700 (PDT) From: Greentime Hu To: tglx@linutronix.de, jason@lakedaemon.net, maz@kernel.org, palmer@dabbelt.com, paul.walmsley@sifive.com, anup@brainfault.org, atish.patra@wdc.com, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [RFC PATCH] irqchip/sifive-plic: Fix getting wrong chip_data when interrupt is hierarchy Date: Thu, 29 Oct 2020 10:37:38 +0800 Message-Id: <20201029023738.127472-1-greentime.hu@sifive.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201028_223749_614951_B199800C X-CRM114-Status: GOOD ( 13.96 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:441 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Greentime Hu Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org This oops is caused by a wrong chip_data and it is because plic_irq_unmask uses irq_get_chip_data(irq_data->irq) to get the chip_data. However it may get another irq_data with the same irq_data->irq if it is hierarchy. In this case, it will get irq_data of sifive_gpio_irqchip instead of plic_chip so that it will get a wrong chip_data and then the wrong lmask of it to cause this oops. To fix this issue, we can use irq_data_get_irq_chip_data(irq_data) to get the correct chip_data of plic_chip. (gdb) p d $11 = (struct irq_data *) 0xffffffe1f695f620 (gdb) p *d $9 = { mask = 0, irq = 57, hwirq = 6, common = 0xffffffe1f695f600, chip = 0xffffffe0018b5630 , domain = 0xffffffe1f692c400, parent_data = 0xffffffe1f68482c0, chip_data = 0xffffffe1f564a820 } (gdb) p d $6 = (struct irq_data *) 0xffffffe1f68482c0 (gdb) p *d $7 = { mask = 0, irq = 57, hwirq = 29, common = 0xffffffe1f695f600, chip = 0xffffffe0018b5070 , domain = 0xffffffe1f6635e00, parent_data = 0x0, chip_data = 0xffffffe1f660f1a0 } [ 3.030165] ------------[ cut here ]------------ [ 3.034614] WARNING: CPU: 1 PID: 1 at drivers/irqchip/irq-sifive-plic.c:125 plic_irq_unmask+0xc4/0x114 [ 3.043887] Modules linked in: [ 3.046932] CPU: 1 PID: 1 Comm: swapper/0 Not tainted 5.9.0 #1 [ 3.052748] epc: ffffffe000588e90 ra : ffffffe000588e88 sp : ffffffe1f6753940 [ 3.059869] gp : ffffffe001978f48 tp : ffffffe1f6748000 t0 : ffffffe001995cb0 [ 3.067080] t1 : ffffffe001995be8 t2 : 73616d61202c343a s0 : ffffffe1f67539a0 [ 3.074288] s1 : ffffffe1f4968140 a0 : 00000000000000b2 a1 : 0000000000000000 [ 3.081497] a2 : 00000000000000c2 a3 : 0000000000000000 a4 : 381c5a89432fe900 [ 3.088707] a5 : 0000000000000004 a6 : 0000000000000000 a7 : 00000000000001aa [ 3.095916] s2 : ffffffe1f5901020 s3 : ffffffe00197a0a8 s4 : ffffffe001978b0c [ 3.103125] s5 : ffffffe00197a1f0 s6 : 0000000000000008 s7 : ffffffe1f4983c9c [ 3.110335] s8 : ffffffe1f4983c68 s9 : ffffffe1f4983c00 s10: ffffffe00000117c [ 3.117544] s11: 0000000000000000 t3 : 0000000000000007 t4 : 0000000000000000 [ 3.124753] t5 : 66666666663a6b73 t6 : ffffffe001988479 [ 3.130052] status: 0000000200000100 badaddr: ffffffe001978b0c cause: 0000000000000003 [ 3.137959] ---[ end trace dbc1129f842ecba3 ]--- Fixes: f1ad1133b18f ("irqchip/sifive-plic: Add support for multiple PLICs") Signed-off-by: Greentime Hu Reviewed-by: Anup Patel Reviewed-by: Atish Patra Acked-by: Palmer Dabbelt --- drivers/irqchip/irq-sifive-plic.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c index 4048657ece0a..6f432d2a5ceb 100644 --- a/drivers/irqchip/irq-sifive-plic.c +++ b/drivers/irqchip/irq-sifive-plic.c @@ -99,7 +99,7 @@ static inline void plic_irq_toggle(const struct cpumask *mask, struct irq_data *d, int enable) { int cpu; - struct plic_priv *priv = irq_get_chip_data(d->irq); + struct plic_priv *priv = irq_data_get_irq_chip_data(d); writel(enable, priv->regs + PRIORITY_BASE + d->hwirq * PRIORITY_PER_ID); for_each_cpu(cpu, mask) { @@ -115,7 +115,7 @@ static void plic_irq_unmask(struct irq_data *d) { struct cpumask amask; unsigned int cpu; - struct plic_priv *priv = irq_get_chip_data(d->irq); + struct plic_priv *priv = irq_data_get_irq_chip_data(d); cpumask_and(&amask, &priv->lmask, cpu_online_mask); cpu = cpumask_any_and(irq_data_get_affinity_mask(d), @@ -127,7 +127,7 @@ static void plic_irq_unmask(struct irq_data *d) static void plic_irq_mask(struct irq_data *d) { - struct plic_priv *priv = irq_get_chip_data(d->irq); + struct plic_priv *priv = irq_data_get_irq_chip_data(d); plic_irq_toggle(&priv->lmask, d, 0); } @@ -138,7 +138,7 @@ static int plic_set_affinity(struct irq_data *d, { unsigned int cpu; struct cpumask amask; - struct plic_priv *priv = irq_get_chip_data(d->irq); + struct plic_priv *priv = irq_data_get_irq_chip_data(d); cpumask_and(&amask, &priv->lmask, mask_val);