From patchwork Thu Feb 22 09:39:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13566956 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D5284C54791 for ; Thu, 22 Feb 2024 09:42:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Cnr8LSOT6Y7gUC9Thg2PzO4DDndZz4AGeHKL8hYJBck=; b=NaB4v2QfC+kURq 5OdpycDnZTJBqqsiOT4xn/Tse7duj9z0kKGPIidBd3XLzCHBPCKN6UyUIoq5RRSJ4snExctJoVpPB TAGfuiLIrknZ2uxO34gxb860tXpLEWXIwdMx2oHmzqUtvWgIYBCs+0EH0YeGJFKNsTipIcHQjiwbN mfK7rRiTza1zsAyqYeZx1B3UZZK9CyGpN/VGCLXyBMg2d1GS6HMwSWWHvb530oXvM46/hYBD/wyto 3U33hdQllNXyqmObak6GCk46eU5K8uaMs5EjIjnnchEmJZYYDuZwQweAYMRQcIUcciDl7/dz2RQVE 4x3rN+WAnpEJ6p96/F4A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rd5an-00000004J5H-07Or; Thu, 22 Feb 2024 09:42:13 +0000 Received: from mail-oi1-x230.google.com ([2607:f8b0:4864:20::230]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rd5Zp-00000004IJY-3rnm for linux-arm-kernel@lists.infradead.org; Thu, 22 Feb 2024 09:41:16 +0000 Received: by mail-oi1-x230.google.com with SMTP id 5614622812f47-3c15dd2a1fdso3038998b6e.2 for ; Thu, 22 Feb 2024 01:41:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1708594873; x=1709199673; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yFOwokt/Qs+I70jfKIbSgbLogS64uTxBCY4KGhVh6mo=; b=ArcypjQ+wa4Ai2PACOe/KLochhsT2x/S3JOYDsueVLGLeCJynie3Pl81Sdi01y3cX8 9wjTwIvPXGXK/jErl1HOO8vYNCTfEtfIl7dlB2nz6daWcf1z24CYOHOsH6FzPPvr090u EBcWn8/O6NoAa1odZo7/XjxQuRf2gbLxvZf/NjGPwl+v2O1z5GRsOTkiYBpXkzaUO3H4 ZjmqurFgyu5+OJ8TmvU/D/eE8oE4uE4eNijFXZYeUQLZwsXtyXeUIeJmjjNyWImh3Y1+ 4QQcpY/RbmjROM8YCwQ7hsqhjB9v0vPRgY26g0S/l7Yhgr1FK8w8+9YtUlaOvXX97/x6 XkrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708594873; x=1709199673; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yFOwokt/Qs+I70jfKIbSgbLogS64uTxBCY4KGhVh6mo=; b=QA8djxhAUDvcXSY6aPN0Fy0lOtjUTrMskr7UZ70xsAZ4lYsHS7/D8Bem4UFUTxRHoj iMpWRq2c7d1SQhJBfXaD9Q3ZSFKAF5/W4BdFWW9pKYlH81Ok19A3yZcAEs6k2AY8yv+f Jfjq0pxr7lWjYOk+IogqI6QdcUfEefVwzDivFFNk5k+uvHdqJbjogrAGcV1QqnqcMehM RfYi+dUtNwrf9LQvNE6lOMH6YHcRY2i5IMA4nRlx7GTPE5qwUSs+6rxyk1ZejHDvKzlp FqLx03uOl8bskWQNuUXilw9XYyqd4B8Kl4bGl1+A3tdBeKqLtvQppZsRScDeSk3AkXZV MURg== X-Forwarded-Encrypted: i=1; AJvYcCWFNVD6YOlKnZblRlvXtB5FzQ+iiLLPnV5fJ4cSi5xhD+19oe86rAU6BRvMV6SLsFZ6ZXiJOmZM053GvQeoJmjwL7GZSl9pxkwDQmLOP1p1hvP144U= X-Gm-Message-State: AOJu0YwgzjFTjU60dpmLzG0iGqO0QWJZDwgSD4skfDE1mYTNxGu0klyh Ice7odFFOqcNZDrxzI/rnq8yWD6lfC1cAanviyS1uScYWIHIAPVHWAqrLCC6Rn0= X-Google-Smtp-Source: AGHT+IGSHWVbV1tcxeH3+z11dMA97PdpaF9ANlA0nsm0f5BLNAt/QDzUFxbA279Ntl5owUYgn9cD2g== X-Received: by 2002:a05:6808:2e93:b0:3c1:3f84:7a95 with SMTP id gt19-20020a0568082e9300b003c13f847a95mr25335778oib.14.1708594873059; Thu, 22 Feb 2024 01:41:13 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.165.210]) by smtp.gmail.com with ESMTPSA id n15-20020a05680803af00b003c17c2b8d09sm130699oie.31.2024.02.22.01.41.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 01:41:12 -0800 (PST) From: Anup Patel To: Palmer Dabbelt , Paul Walmsley , Thomas Gleixner , Rob Herring , Krzysztof Kozlowski , Frank Rowand , Conor Dooley Cc: Marc Zyngier , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Atish Patra , Andrew Jones , Sunil V L , Saravana Kannan , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Anup Patel Subject: [PATCH v14 07/18] irqchip/sifive-plic: Improve locking safety by using irqsave/irqrestore Date: Thu, 22 Feb 2024 15:09:55 +0530 Message-Id: <20240222094006.1030709-8-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222094006.1030709-1-apatel@ventanamicro.com> References: <20240222094006.1030709-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240222_014114_203925_6AF1EB60 X-CRM114-Status: GOOD ( 14.26 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Now that PLIC driver is probed as a regular platform driver, the lock dependency validator complains about the safety of handler->enable_lock usage: [ 0.956775] Possible interrupt unsafe locking scenario: [ 0.956998] CPU0 CPU1 [ 0.957247] ---- ---- [ 0.957439] lock(&handler->enable_lock); [ 0.957607] local_irq_disable(); [ 0.957793] lock(&irq_desc_lock_class); [ 0.958021] lock(&handler->enable_lock); [ 0.958246] [ 0.958342] lock(&irq_desc_lock_class); [ 0.958501] *** DEADLOCK *** To address above, use raw_spin_lock_irqsave/unlock_irqrestore() instead of raw_spin_lock/unlock(). Signed-off-by: Anup Patel --- drivers/irqchip/irq-sifive-plic.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c index e6d23fde51ed..175d02f7fd64 100644 --- a/drivers/irqchip/irq-sifive-plic.c +++ b/drivers/irqchip/irq-sifive-plic.c @@ -103,9 +103,11 @@ static void __plic_toggle(void __iomem *enable_base, int hwirq, int enable) static void plic_toggle(struct plic_handler *handler, int hwirq, int enable) { - raw_spin_lock(&handler->enable_lock); + unsigned long flags; + + raw_spin_lock_irqsave(&handler->enable_lock, flags); __plic_toggle(handler->enable_base, hwirq, enable); - raw_spin_unlock(&handler->enable_lock); + raw_spin_unlock_irqrestore(&handler->enable_lock, flags); } static inline void plic_irq_toggle(const struct cpumask *mask, @@ -236,6 +238,7 @@ static int plic_irq_set_type(struct irq_data *d, unsigned int type) static int plic_irq_suspend(void) { unsigned int i, cpu; + unsigned long flags; u32 __iomem *reg; struct plic_priv *priv; @@ -253,12 +256,12 @@ static int plic_irq_suspend(void) if (!handler->present) continue; - raw_spin_lock(&handler->enable_lock); + raw_spin_lock_irqsave(&handler->enable_lock, flags); for (i = 0; i < DIV_ROUND_UP(priv->nr_irqs, 32); i++) { reg = handler->enable_base + i * sizeof(u32); handler->enable_save[i] = readl(reg); } - raw_spin_unlock(&handler->enable_lock); + raw_spin_unlock_irqrestore(&handler->enable_lock, flags); } return 0; @@ -267,6 +270,7 @@ static int plic_irq_suspend(void) static void plic_irq_resume(void) { unsigned int i, index, cpu; + unsigned long flags; u32 __iomem *reg; struct plic_priv *priv; @@ -284,12 +288,12 @@ static void plic_irq_resume(void) if (!handler->present) continue; - raw_spin_lock(&handler->enable_lock); + raw_spin_lock_irqsave(&handler->enable_lock, flags); for (i = 0; i < DIV_ROUND_UP(priv->nr_irqs, 32); i++) { reg = handler->enable_base + i * sizeof(u32); writel(handler->enable_save[i], reg); } - raw_spin_unlock(&handler->enable_lock); + raw_spin_unlock_irqrestore(&handler->enable_lock, flags); } }