Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp995784pxb; Wed, 1 Sep 2021 14:49:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxpHBIRaEnfyHMgtPbqlXjdhCz6B0BQxVhpGWLeGvt0vRh3C4UXKzuPYqRoSDNqKXu+wdcA X-Received: by 2002:a17:906:32c9:: with SMTP id k9mr1776036ejk.218.1630532957158; Wed, 01 Sep 2021 14:49:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630532957; cv=none; d=google.com; s=arc-20160816; b=uwvdYkjIjFFpRYE+gEyr6HeQ/H4CFTTcz9uNPnWt2ygW16qS+guuGBlVwWrF+4puRS eUA05mkP3HGaqAd+D1NYIuGbC2Wu7Yym30B50sKX1PQTu3PQsWEy5jYYjoT9O3n6tRqS 9FxA4EaWJV/acly9E3Fj3NL4fWqHKc+ugEWs7zeHC0Nya1GUomiC66ZfaKB8h6hoAyfY Hj2lmz86qKMmD0gu+B/Au7mYYCyn5x65sg0Zi+DCmdwKgRqGK8pX7tgnZM+Z+J8EHGhZ KFriGtvXB9F0pY2rv9BgQ2A8A7Tem6/CtEeIs+ZZ151G8R5YVHcrrRjv6sXzvHM2kidT aK4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date; bh=s9KRfhJJ8Rl82o9uM9W8u6q355WGsgMEiMPskfuks/Q=; b=DdlR2XhuHLd5KS4sPhOtPQ180zZdoOTN0zCEablJ3gpTLxRmQEE7JL/rIZc+U+u07y eufXuwEU3ooXL3T3z1Rg+us53U6I6I9dOPw9VmUP3j7URDG1/0ZSpzReRtW4AnJGBcSe aErAIQvoaV7or3FvSHvVF+4UDTZqpXBH9K5IKJA0wtAALEh2fbyY1xAi2bNLFLX09gyj IcyhezNn8PnzOzyTfT3SdAcO94em19/7NfEbSGnlwH+fbeh8Z5VWbFNTm+cPWz8FAVzS a/4EegXxGLhVPoNrOf14pN5OgvQYdsi+2ctR0YQ0PXnT9hfY1wxVAHpb4KeiPHG93+Ne nG8g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n10si820989edx.387.2021.09.01.14.48.53; Wed, 01 Sep 2021 14:49:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242469AbhIAHFH (ORCPT + 99 others); Wed, 1 Sep 2021 03:05:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:51626 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232463AbhIAHFD (ORCPT ); Wed, 1 Sep 2021 03:05:03 -0400 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 643D26101A; Wed, 1 Sep 2021 07:04:07 +0000 (UTC) Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mLKI1-008M8k-I8; Wed, 01 Sep 2021 08:04:05 +0100 Date: Wed, 01 Sep 2021 08:03:52 +0100 Message-ID: <87bl5cwzdz.wl-maz@kernel.org> From: Marc Zyngier To: Leo Yan Cc: Thomas Gleixner , Catalin Marinas , Will Deacon , linux-kernel@vger.kernel.org, Orito Takao Subject: Re: [RFC PATCH] irqchip/gic, gic-v3: Ensure data visibility in peripheral In-Reply-To: <20210901063115.383026-1-leo.yan@linaro.org> References: <20210901063115.383026-1-leo.yan@linaro.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: leo.yan@linaro.org, tglx@linutronix.de, catalin.marinas@arm.com, will@kernel.org, linux-kernel@vger.kernel.org, orito.takao@socionext.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 01 Sep 2021 07:31:15 +0100, Leo Yan wrote: > > When an interrupt line is assered, GIC handles interrupt with the flow > (with EOImode == 1): > > gic_handle_irq() > `> do_read_iar() => Change int state to active > `> gic_write_eoir() => Drop int priority > `> handle_domain_irq() > `> generic_handle_irq_desc() > `> handle_fasteoi_irq() > `> handle_irq_event() => Peripheral handler and > de-assert int line > `> cond_unmask_eoi_irq() > `> chip->irq_eoi() > `> gic_eoimode1_eoi_irq() => Change int state to inactive > > In this flow, it has no explicit memory barrier between the functions > handle_irq_event() and chip->irq_eoi(), it's possible that the > outstanding data has not reached device in handle_irq_event() but the > callback chip->irq_eoi() is invoked, this can lead to state transition > for level triggered interrupt: > > Flow | Interrupt state in GIC > ---------------------------------+------------------------------------- > Interrupt line is asserted | 'inactive' -> 'pending' > do_read_iar() | 'pending' -> 'pending & active' > handle_irq_event() | Write peripheral register but it's > | not visible for device, so the > | interrupt line is still asserted > chip->irq_eoi() | 'pending & active' -> 'pending' > ... > Produce spurious interrupt | > with interrupt ID: 1024 | 1024? Surely not. > | Finally the peripheral reigster is > | updated and the interrupt line is > | deasserted: 'pending' -> 'inactive' > > To avoid this potential issue, this patch adds wmb() barrier prior to > invoke EOI operation, this can make sure the interrupt line is > de-asserted in peripheral before deactivating interrupt in GIC. At the > end, this can avoid spurious interrupt. If you want to ensure completion of device-specific writes, why isn't this the job of the device driver to implement whatever semantic it desires? What if the interrupt is (shock, horror!) driven by a system register instead? I think this is merely papering over a driver bug, and adds a significant cost to all interrupts for no good reasons. M. -- Without deviation from the norm, progress is not possible.