From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9ACD9C4338F for ; Wed, 18 Aug 2021 11:37:25 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 61EAA6102A for ; Wed, 18 Aug 2021 11:37:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 61EAA6102A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=marcan.st Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:Cc:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=CA6PHxmugEUd1JVqyBNRX4aLnSx2bjNvVnQ095FrBlA=; b=jXq1eHtJhU/2/mGcYUTfzUWO0Y nbrzEh0PKmGkHLJc+MLqBP6G61NLh92pMmkAIgx1ZgCA/oPCXYH4NxpDD5wtDjAX5i0lDmIdG+2VK QSGE0Wz93AhY+VN08/uHaNX59vhIGLM6reSRZgYNoiuwIcxJXD8j0S3tlZ+fdTe1pvgtASsZn4PES lJdaFihvhhmOyILCv48VNNq5kW491TYf5L8LN+Kr/3VnrX9d1W5G3QcE+0lXFfjh5QAtqWizXHBeQ pNhQtcVZLTqCOpuVph/4+sNa0rDoWkJQVBLdkKEugVj+qon5doiItNXuPXr24TjcaL7kircN1ORez oML6C7lQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mGJqr-005LZU-NO; Wed, 18 Aug 2021 11:35:21 +0000 Received: from marcansoft.com ([212.63.210.85] helo=mail.marcansoft.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mGJql-005LY1-Gf for linux-arm-kernel@lists.infradead.org; Wed, 18 Aug 2021 11:35:19 +0000 Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: marcan@marcan.st) by mail.marcansoft.com (Postfix) with ESMTPSA id 5FEF341F72; Wed, 18 Aug 2021 11:35:07 +0000 (UTC) Subject: Re: [PATCH] irqchip/apple-aic: fix irq_disable from within irq handlers To: Sven Peter Cc: Thomas Gleixner , Marc Zyngier , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <20210812100942.17206-1-sven@svenpeter.dev> From: Hector Martin Message-ID: <9b2805ec-e5b4-bb1b-abee-0bff7e3dbf24@marcan.st> Date: Wed, 18 Aug 2021 20:35:04 +0900 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <20210812100942.17206-1-sven@svenpeter.dev> Content-Language: es-ES X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210818_043515_774977_11C78ADE X-CRM114-Status: GOOD ( 26.20 ) 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: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org *Puts on kernel maintainer hat again* Sorry for the delay. I've been spending too much time on hardware RE recently... On 12/08/2021 19.09, Sven Peter wrote: > When disable_irq_nosync for an interrupt is called from within its > interrupt handler, this interrupt is only marked as disabled with the > intention to mask it when it triggers again. > The AIC hardware however automatically masks the interrupt when it is read. > aic_irq_eoi then unmasks it again if it's not disabled *and* not masked. > This results in a state mismatch between the hardware state and the > state kept in irq_data: The hardware interrupt is masked but > IRQD_IRQ_MASKED is not set. Any further calls to unmask_irq will directly > return and the interrupt can never be enabled again. > > Fix this by keeping the hardware and irq_data state in sync by unmasking in > aic_irq_eoi if and only if the irq_data state also assumes the interrupt to > be unmasked. > > Fixes: 76cde2639411 ("irqchip/apple-aic: Add support for the Apple Interrupt Controller") > Signed-off-by: Sven Peter > --- > drivers/irqchip/irq-apple-aic.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/irqchip/irq-apple-aic.c b/drivers/irqchip/irq-apple-aic.c > index b8c06bd8659e..6fc145aacaf0 100644 > --- a/drivers/irqchip/irq-apple-aic.c > +++ b/drivers/irqchip/irq-apple-aic.c > @@ -226,7 +226,7 @@ static void aic_irq_eoi(struct irq_data *d) > * Reading the interrupt reason automatically acknowledges and masks > * the IRQ, so we just unmask it here if needed. > */ > - if (!irqd_irq_disabled(d) && !irqd_irq_masked(d)) > + if (!irqd_irq_masked(d)) > aic_irq_unmask(d); > } > > Looks good to me. I can't remember exactly where this code came from, but looking again at the irqchip code it's clear that the mask state and hardware mask always have to be in sync. Acked-by: Hector Martin -- Hector Martin (marcan@marcan.st) Public Key: https://mrcn.st/pub _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D3D7C4338F for ; Wed, 18 Aug 2021 11:43:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 033E761075 for ; Wed, 18 Aug 2021 11:43:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235900AbhHRLnw (ORCPT ); Wed, 18 Aug 2021 07:43:52 -0400 Received: from marcansoft.com ([212.63.210.85]:60726 "EHLO mail.marcansoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233798AbhHRLnv (ORCPT ); Wed, 18 Aug 2021 07:43:51 -0400 X-Greylist: delayed 484 seconds by postgrey-1.27 at vger.kernel.org; Wed, 18 Aug 2021 07:43:50 EDT Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: marcan@marcan.st) by mail.marcansoft.com (Postfix) with ESMTPSA id 5FEF341F72; Wed, 18 Aug 2021 11:35:07 +0000 (UTC) Subject: Re: [PATCH] irqchip/apple-aic: fix irq_disable from within irq handlers To: Sven Peter Cc: Thomas Gleixner , Marc Zyngier , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <20210812100942.17206-1-sven@svenpeter.dev> From: Hector Martin Message-ID: <9b2805ec-e5b4-bb1b-abee-0bff7e3dbf24@marcan.st> Date: Wed, 18 Aug 2021 20:35:04 +0900 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <20210812100942.17206-1-sven@svenpeter.dev> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: es-ES Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org *Puts on kernel maintainer hat again* Sorry for the delay. I've been spending too much time on hardware RE recently... On 12/08/2021 19.09, Sven Peter wrote: > When disable_irq_nosync for an interrupt is called from within its > interrupt handler, this interrupt is only marked as disabled with the > intention to mask it when it triggers again. > The AIC hardware however automatically masks the interrupt when it is read. > aic_irq_eoi then unmasks it again if it's not disabled *and* not masked. > This results in a state mismatch between the hardware state and the > state kept in irq_data: The hardware interrupt is masked but > IRQD_IRQ_MASKED is not set. Any further calls to unmask_irq will directly > return and the interrupt can never be enabled again. > > Fix this by keeping the hardware and irq_data state in sync by unmasking in > aic_irq_eoi if and only if the irq_data state also assumes the interrupt to > be unmasked. > > Fixes: 76cde2639411 ("irqchip/apple-aic: Add support for the Apple Interrupt Controller") > Signed-off-by: Sven Peter > --- > drivers/irqchip/irq-apple-aic.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/irqchip/irq-apple-aic.c b/drivers/irqchip/irq-apple-aic.c > index b8c06bd8659e..6fc145aacaf0 100644 > --- a/drivers/irqchip/irq-apple-aic.c > +++ b/drivers/irqchip/irq-apple-aic.c > @@ -226,7 +226,7 @@ static void aic_irq_eoi(struct irq_data *d) > * Reading the interrupt reason automatically acknowledges and masks > * the IRQ, so we just unmask it here if needed. > */ > - if (!irqd_irq_disabled(d) && !irqd_irq_masked(d)) > + if (!irqd_irq_masked(d)) > aic_irq_unmask(d); > } > > Looks good to me. I can't remember exactly where this code came from, but looking again at the irqchip code it's clear that the mask state and hardware mask always have to be in sync. Acked-by: Hector Martin -- Hector Martin (marcan@marcan.st) Public Key: https://mrcn.st/pub