Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2957651rdb; Tue, 13 Feb 2024 02:28:19 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU2NBB+qOB24AKVCa0OVruJ3RRh9gtel3kpKi8LcJmyybEpPgCWDqXCQC2q0k+8Is+gB73yW2vTdpBrcKtefxwHrruMos8L2GFD8XoWXQ== X-Google-Smtp-Source: AGHT+IFB01nXvHwYDlXf+5h3GLyuqJUt1j3v/w3M1dNAWjRIkfT7bOevm2JNNXxfMVQeP9dqOLjz X-Received: by 2002:a17:902:d2c5:b0:1d9:bd7d:3c79 with SMTP id n5-20020a170902d2c500b001d9bd7d3c79mr10200307plc.26.1707820098956; Tue, 13 Feb 2024 02:28:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707820098; cv=pass; d=google.com; s=arc-20160816; b=ler/psO7v6EpLmp6V9z9pMOvXrrH+yQ9SJynCZ1dgA3cK+hQWv6612Ts7oCGz22xTo 72/aaQRLHDoPHROJFL7SMck+wGM/xVkLRCkXM4q0+S6EvWUKwnq/CB1H/Mb5JhukEIsz zzTRI9Mp9vP6VdtbKIjMoq2ySbYDsrktKHKdVmFF/nr+3N8RbRnYqynda3h2uQz8DZLj 5KvZ2dCyFztY7tcdcsM/yWSvpvsW/1S5RbNZT684P0FTkEgBzOfnvndDClejHQsTqcv6 8+E7+g5LZX7HGSKP0uoDhGWf7k3fvK7RFQCbXeUrWlufnBHod3DNi59i2GXmNDZg5Msh YMTg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:references:in-reply-to:subject:cc:to:dkim-signature :dkim-signature:from; bh=OirENwRVffLhqg4vLQeXmmc6qTeG6AWtBgzm4/Fep7o=; fh=WYtfMGLnRNi8qWPnOhQNR0Z89mrrGOvErJyyYPea064=; b=hA8/kqAk6z3tWGKlhiiJzp47S5Rm4DObaBcv7/KwZmUNGql7j2uA5yD1vR+Vse1beF ki00JXnAYma7uR4dgS/GGyO/8d2birlNQvM0TnCbBzgseDk5tutmy4+GHBhVH4pihUpV zZ/yZzVtHKG0ldqTP0TpsgacQRVkn6DtTlF+oBqbuSpxAUCoHz2ToAF/Lzw0a4lgoJn4 WuT5O+VejTHLuTNbDkOof3vZ2zoEpfOXC+pzS2WLMpO+sjdh9DOVtVsNgwaM9ADD9rbu LCVqtRV22iBkcLQ+Q60dKt4qLDhmSUXT3GDokcE9lNfI4fyAJol8sqeT6XY+X39rggl1 UO2Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=GwkPBvLE; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-63338-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63338-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de X-Forwarded-Encrypted: i=2; AJvYcCUaauFp2QgPI9huAX4jOSXoPe3QluzFythSvqjTd/2Iei32UqLZxklE8MpRWLvRuUSgPK3SdBbwUOUCkM7GQSp08NLP+IiPsQGbQCnrZg== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id n5-20020a170902d2c500b001db2aefa918si1351409plc.159.2024.02.13.02.28.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 02:28:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-63338-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=GwkPBvLE; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-63338-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63338-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 748E9288C79 for ; Tue, 13 Feb 2024 10:26:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4193D2263A; Tue, 13 Feb 2024 10:26:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="GwkPBvLE"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="FTIkVehm" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 04308225CE; Tue, 13 Feb 2024 10:26:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707820004; cv=none; b=Yyb4xzoZIaFkgfmItnJAf/URA4B73uf1k4p2ahxCb/YdYvG1zeEuJAc7X2x2TLaLAUbot4eVg9kv0kgAjX9DJASgbBxyTb99lbhCpLh+wH+G4SBZY45YLv8hWA49mTYGi0etingxREW71H0lecNt9x8PyiSpiIxaNtjpTwU17G8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707820004; c=relaxed/simple; bh=aBnhq06nlMMvbU7IDlpipxtNtoUmHZ45y8K4GgkpUWs=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=Zxil/62HoUGi1RceahtHa18EnjErE2kcV21abwz1qTGp6FYQnSArIH1TAybzu1LIHmgPJ45WP/q2jprxmSxaG1vqj6mmvHWAFSRUx1vDpVKTTrJOaVmDcT4n5gp1rvI5YS50Cp5/skl71JMNQbfWVDLKPrQ8EWe0vjQi3OpWIuw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=GwkPBvLE; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=FTIkVehm; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1707820001; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=OirENwRVffLhqg4vLQeXmmc6qTeG6AWtBgzm4/Fep7o=; b=GwkPBvLE/NQAAT43xtyROcGSWgUiucZZB2ec2g3VMikr5ObnhcXmo+RS5IDSmyM1OUGiEd 7xS8uBH10ljyxTHAf0TgsO0vUhc8J3cUumyVjdF+tArJNZ5Cb6qbN81/2L4SUuNb1n+xeM lTUKLPRc+bLsZCgPNl5jfAbi8uQEAR9a7o0M/zk8iHPMQOA0sGKzpV8m4ycyLpvhMqIrTG BzH2/fE2hX0EICezQmdB7T4kOaTHuSMg8g41lIojVhpEATsMu34Fr+weMIBkrFDgJ1m7zJ smGA9OsZA5tjREuhcauzD90erNoGucb+l9Ok3++FJGDwNXwNBXF9bmy5HX/vxA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1707820001; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=OirENwRVffLhqg4vLQeXmmc6qTeG6AWtBgzm4/Fep7o=; b=FTIkVehmdBJJQ8PbMU0GBBiXWHp+VmaePW7Fc9q0HvKZTnjeSpYgSUQrZkAOitKr3WDpHK rs9WULSDRQ3oSFCA== To: Nam Cao , Palmer Dabbelt , Paul Walmsley , Samuel Holland , Marc Zyngier , Guo Ren , linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Cc: Nam Cao , stable@vger.kernel.org Subject: Re: [PATCH v2] irqchip/sifive-plic: enable interrupt if needed before EOI In-Reply-To: <20240131081933.144512-1-namcao@linutronix.de> References: <20240131081933.144512-1-namcao@linutronix.de> Date: Tue, 13 Feb 2024 11:26:40 +0100 Message-ID: <87wmr8hd7j.ffs@tglx> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain Nam! On Wed, Jan 31 2024 at 09:19, Nam Cao wrote: > RISC-V PLIC cannot "end-of-interrupt" (EOI) disabled interrupts, as > explained in the description of Interrupt Completion in the PLIC spec: > > "The PLIC signals it has completed executing an interrupt handler by > writing the interrupt ID it received from the claim to the claim/complete > register. The PLIC does not check whether the completion ID is the same > as the last claim ID for that target. If the completion ID does not match > an interrupt source that *is currently enabled* for the target, the > completion is silently ignored." > > Commit 69ea463021be ("irqchip/sifive-plic: Fixup EOI failed when masked") > ensured that EOI is successful by enabling interrupt first, before EOI. > > Commit a1706a1c5062 ("irqchip/sifive-plic: Separate the enable and mask > operations") removed the interrupt enabling code from the previous > commit, because it assumes that interrupt should already be enabled at the > point of EOI. However, this is incorrect: there is a window after a hart > claiming an interrupt and before irq_desc->lock getting acquired, > interrupt can be disabled during this window. Thus, EOI can be invoked > while the interrupt is disabled, effectively nullify this EOI. This > results in the interrupt never gets asserted again, and the device who > uses this interrupt appears frozen. Nice detective work! > Make sure that interrupt is really enabled before EOI. > > Fixes: a1706a1c5062 ("irqchip/sifive-plic: Separate the enable and mask operations") > Cc: > Signed-off-by: Nam Cao > --- > v2: > - add unlikely() for optimization > - re-word commit message to make it clearer > > drivers/irqchip/irq-sifive-plic.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c > index e1484905b7bd..0a233e9d9607 100644 > --- a/drivers/irqchip/irq-sifive-plic.c > +++ b/drivers/irqchip/irq-sifive-plic.c > @@ -148,7 +148,13 @@ static void plic_irq_eoi(struct irq_data *d) > { > struct plic_handler *handler = this_cpu_ptr(&plic_handlers); > > - writel(d->hwirq, handler->hart_base + CONTEXT_CLAIM); > + if (unlikely(irqd_irq_disabled(d))) { > + plic_toggle(handler, d->hwirq, 1); > + writel(d->hwirq, handler->hart_base + CONTEXT_CLAIM); > + plic_toggle(handler, d->hwirq, 0); It's unfortunate to have this condition in the hotpath, though it should be cache hot, easy to predict and compared to the writel() completely in the noise. > + } else { > + writel(d->hwirq, handler->hart_base + CONTEXT_CLAIM); > + } > } Can the RISCV folks please have a look at this? Thanks, tglx