Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp7772678rwn; Wed, 14 Sep 2022 04:23:14 -0700 (PDT) X-Google-Smtp-Source: AA6agR7soRRf0s2uJO+pTsMUDveotQRj8ZK6e7SlF3Yk5MTWfKUBBCSUZ6SAwFGdWx6emYSqXYCR X-Received: by 2002:a63:a501:0:b0:434:ff77:1fda with SMTP id n1-20020a63a501000000b00434ff771fdamr30223032pgf.310.1663154594662; Wed, 14 Sep 2022 04:23:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663154594; cv=none; d=google.com; s=arc-20160816; b=VCVXvm87+vJ5h1pa4PHNVnFEOMcLYggCXgCk5pwl/6shszvqDP9P3VudBV7yVBC+lg +NrMGFLsNzZbKh/RYeiIuuc3dCB3VwY+OfsTJAAwKEnj4ZzLuuJufu9s9GEn4uStqa+g UzwKg2bVUJRSPomKUwWGJxi7ajXVDQHkOXqEaAziBOwRXrfXc97K1N409AAy+3MYhUNf 2q6xfu6AqVvdLIr/ZdjveHXfKbj/urhi9pU9AGI1qlnOxloe33j37I2FXUszmjTWB5r/ Ea866JbPLbm8uRWrEKEH0t5XhSddjnx9pwqSI9R4H0Z+XZCxoEQoGYdKE2qE4M9vArBX GcGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=Qtt84rpiBX1rB8oI1bPgpCDJnjiaHFCp6ogAgzm35pc=; b=wdH0hiaaHMXOuwYpwVBlpy7eyntrewDjEFtm5pXUuhWTsgmfnzFm7vxL0jwgbLO+mi ASyncfTCQyoqEGB2JdiC1rDAKjJgg3qq9ru+wkD71nfvMP+CC0rucSWTt9L/8qHie54A u1tOufU7Qk6efOWLLCC8OmpBIBrfBAXJ+vQsKhaxCxkcXhAt5ximoTtDKbTEIPrYQeUF qDrnIJPBWirjRX9KbV5WeL/Omu7MJQ/qGr1FqxLUUezT5qr00ZgGyy5PEV0NBMw1hjG4 7nq4YBO+a3CO2ihwjDnhJSY2nyvpHmtBqhIbOpKSE0CFa/yB+pEwFlEliqauZnngXuGN YuLA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y14-20020a17090abd0e00b002008429d42bsi14139097pjr.119.2022.09.14.04.23.03; Wed, 14 Sep 2022 04:23:14 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229636AbiINLKw (ORCPT + 99 others); Wed, 14 Sep 2022 07:10:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229472AbiINLKt (ORCPT ); Wed, 14 Sep 2022 07:10:49 -0400 Received: from mail.wantstofly.org (hmm.wantstofly.org [213.239.204.108]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B8E05E643; Wed, 14 Sep 2022 04:10:46 -0700 (PDT) Received: by mail.wantstofly.org (Postfix, from userid 1000) id DECA37F54E; Wed, 14 Sep 2022 14:10:44 +0300 (EEST) Date: Wed, 14 Sep 2022 14:10:44 +0300 From: Lennert Buytenhek To: Andy Shevchenko Cc: Ilpo =?iso-8859-1?Q?J=E4rvinen?= , Greg Kroah-Hartman , Jiri Slaby , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: I/O page faults from 8250_mid PCIe UART after TIOCVHANGUP Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Wed, Sep 14, 2022 at 01:09:40PM +0300, Andy Shevchenko wrote: > > On an Intel SoC with several 8250_mid PCIe UARTs built into the CPU, I > > can reliably trigger I/O page faults if I invoke TIOCVHANGUP on any of > > the UARTs and then re-open that UART. > > > > Invoking TIOCVHANGUP appears to clear the MSI address/data registers > > in the UART via tty_ioctl() -> tty_vhangup() -> __tty_hangup() -> > > uart_hangup() -> uart_shutdown() -> uart_port_shutdown() -> > > univ8250_release_irq() -> free_irq() -> irq_domain_deactivate_irq() -> > > __irq_domain_deactivate_irq() -> msi_domain_deactivate() -> > > __pci_write_msi_msg(): > > > > [root@icelake ~]# lspci -s 00:1a.0 -vv | grep -A1 MSI: > > Capabilities: [40] MSI: Enable+ Count=1/1 Maskable- 64bit- > > Address: fee00278 Data: 0000 > > [root@icelake ~]# cat hangup.c > > #include > > #include > > > > int main(int argc, char *argv[]) > > { > > ioctl(1, TIOCVHANGUP); > > > > return 0; > > } > > [root@icelake ~]# gcc -Wall -o hangup hangup.c > > [root@icelake ~]# ./hangup > /dev/ttyS4 > > [root@icelake ~]# lspci -s 00:1a.0 -vv | grep -A1 MSI: > > Capabilities: [40] MSI: Enable+ Count=1/1 Maskable- 64bit- > > Address: 00000000 Data: 0000 > > [root@icelake ~]# > > > > Opening the serial port device again while the UART is in this state > > then appears to cause the UART to generate an interrupt > > The interrupt is ORed three: DMA Tx, DMA Rx and UART itself. > Any of them can be possible, but to be sure, can you add: > > dev_info(p->dev, "FISR: %x\n", fisr); > > into dnv_handle_irq() before any other code and see which bits we > actually got there before the crash? > > (If it floods the logs, dev_info_ratelimited() may help) I think that that wouldn't report anything because when the UART is triggering an interrupt here, the MSI address/data are zero, so the IRQ handler is not actually invoked. If Ilpo doesn't beat me to it, I'll try adding some debug code to see exactly which UART register write in the tty open path is causing the UART to signal an interrupt before the IRQ handler is set up. (The IOMMU stops the write in this case, so the machine doesn't crash, we just get an I/O page fault warning in dmesg every time this happens.) > > before the > > MSI vector has been set up again, causing a DMA write to I/O virtual > > address zero: > > > > [root@icelake console]# echo > /dev/ttyS4 > > [ 979.463307] DMAR: DRHD: handling fault status reg 3 > > [ 979.469409] DMAR: [DMA Write NO_PASID] Request device [00:1a.0] fault addr 0x0 [fault reason 0x05] PTE Write access is not set > > > > I'm guessing there's something under tty_open() -> uart_open() -> > > tty_port_open() -> uart_port_activate() -> uart_port_startup() -> > > serial8250_do_startup() that triggers a UART interrupt before the > > MSI vector has been set up again. > > > > I did a quick search but it didn't seem like this is a known issue. > > Thanks for your report and reproducer! Yes, I also never heard about > such an issue before. Ilpo, who is doing more UART work nowadays, might > have an idea, I hope. Thank you!