Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp10985955rwb; Fri, 25 Nov 2022 09:46:59 -0800 (PST) X-Google-Smtp-Source: AA0mqf46fuWfDDhkLQT8n/CuslVVLfagq7eLpq7CI+ZYPH6oa5TqeiNhMnwp9ylvmVZ59L26qFji X-Received: by 2002:a17:902:e40a:b0:189:7cf:91ce with SMTP id m10-20020a170902e40a00b0018907cf91cemr32814957ple.155.1669398419640; Fri, 25 Nov 2022 09:46:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669398419; cv=none; d=google.com; s=arc-20160816; b=SNJvgqhY6nlKoc+FFdzLbq8fHzyq3aXxBrASzwAUCwxkwA8EVw1FtujzXSgYVAGlnY cU2FZ+YVxJyBsJ+e2w1Pe3MGdbFj1Q3GiCsHO11wQ2mmorWsE0RpVCOQxxlJdtB34fve upoqCLKndgARIxNjlT91Usk1jH0/sIUKoc3/kAhQtUcGfbkQCTUuMU7qen5LYcEp+dGK BiAbAnyjQ/v9qiZeAmSvpZkZfr9FtL/I27GVFaOcA3aW08+6lhZXPS+wnduHjKE3nqL/ 4ELbKvwRd1DbjLBjJzRUmgl/MkCZIBdbkmCeFSMA6kLQ+nu+8DDlvtzF7uQLg6Es1dWm yRIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=lXbFx4TDUVZVlZDC1XJ2usb/1mpokpQm7jkDk24Hu+k=; b=OA4/z4b8PrbV4JmVsPSmBaEGcp/BCZgwpoHe9uSL0s8MKJ5gGPwnUaseMfrSzbyoc9 1xuIwgwZNWQIMVKHh4csAah7mhvXjOkW+xCUitWm+xw1tJgOzfLnpGYog14WQxhJRO30 0M3iyHYGC7HZPZiLx8J6OBKdwaFTi+q8YKWia39EXzXf0iJElkMtuq8QJylF9YZuk5Yy VUNJm4Yg+zrhijAD8vl4kra+ORNsp6c3iYlpgLgqrKsIUmH3R2Clbfc3UyzY02K7noij hg0dvEwmGqJ81VsVKM7Prnn2dh0U4E5IjLPF7X2mMl7Quu0H+iGVkT0pKGbKah7Wzcp9 +svQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p8-20020a056a000b4800b00561cb07c77csi5320300pfo.232.2022.11.25.09.46.47; Fri, 25 Nov 2022 09:46:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229875AbiKYRCv (ORCPT + 85 others); Fri, 25 Nov 2022 12:02:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229608AbiKYRCu (ORCPT ); Fri, 25 Nov 2022 12:02:50 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C537C1F2D6 for ; Fri, 25 Nov 2022 09:02:47 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E59622B; Fri, 25 Nov 2022 09:02:53 -0800 (PST) Received: from [10.57.71.118] (unknown [10.57.71.118]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D9FE23F73B; Fri, 25 Nov 2022 09:02:45 -0800 (PST) Message-ID: Date: Fri, 25 Nov 2022 17:02:41 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: [PATCH] iommu/mediatek: Fix crash on isr after kexec() Content-Language: en-GB To: Ricardo Ribalda , Joerg Roedel , Matthias Brugger , Yong Wu , Will Deacon Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org References: <20221125-mtk-iommu-v1-0-bb5ecac97a28@chromium.org> From: Robin Murphy In-Reply-To: <20221125-mtk-iommu-v1-0-bb5ecac97a28@chromium.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022-11-25 16:28, Ricardo Ribalda wrote: > If the system is rebooted via isr(), the IRQ handler might be triggerd > before the domain is initialized. Resulting on an invalid memory access > error. > > Fix: > [ 0.500930] Unable to handle kernel read from unreadable memory at virtual address 0000000000000070 > [ 0.501166] Call trace: > [ 0.501174] report_iommu_fault+0x28/0xfc > [ 0.501180] mtk_iommu_isr+0x10c/0x1c0 Hmm, shouldn't we clear any pending faults at probe in mtk_iommu_hw_init(), before the IRQ is requested? mtk_iommu_isr() might still want to be robust against a spurious interrupt, but then it can simply return without doing anything at all if the domain is NULL, since we'll know that's the case. Thanks, Robin. (It might be nice if request_irq() had a flag to say "if this IRQ looks pending already just clear it" for drivers that know it could only be spurious at that point; kexec seems to lead to this problem quite a lot...) > Signed-off-by: Ricardo Ribalda > --- > To: Yong Wu > To: Joerg Roedel > To: Will Deacon > To: Robin Murphy > To: Matthias Brugger > Cc: iommu@lists.linux.dev > Cc: linux-mediatek@lists.infradead.org > Cc: linux-arm-kernel@lists.infradead.org > Cc: linux-kernel@vger.kernel.org > --- > drivers/iommu/mtk_iommu.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c > index 2ab2ecfe01f8..17f6be5a5097 100644 > --- a/drivers/iommu/mtk_iommu.c > +++ b/drivers/iommu/mtk_iommu.c > @@ -454,7 +454,7 @@ static irqreturn_t mtk_iommu_isr(int irq, void *dev_id) > fault_larb = data->plat_data->larbid_remap[fault_larb][sub_comm]; > } > > - if (report_iommu_fault(&dom->domain, bank->parent_dev, fault_iova, > + if (dom && report_iommu_fault(&dom->domain, bank->parent_dev, fault_iova, > write ? IOMMU_FAULT_WRITE : IOMMU_FAULT_READ)) { > dev_err_ratelimited( > bank->parent_dev, > > --- > base-commit: 4312098baf37ee17a8350725e6e0d0e8590252d4 > change-id: 20221125-mtk-iommu-13023f971298 > > Best regards,