Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp2167860rwn; Fri, 16 Sep 2022 06:41:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4QVpIVa+e6OTKAFF33nZbK+7h8xaYBv2USUNAzlAiPGTBx0PiURy97Xq+MuvKZzaqP/YJv X-Received: by 2002:aa7:9dde:0:b0:53e:5af7:ac10 with SMTP id g30-20020aa79dde000000b0053e5af7ac10mr5004469pfq.16.1663335689211; Fri, 16 Sep 2022 06:41:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663335689; cv=none; d=google.com; s=arc-20160816; b=R0PKQyv27QqLD5DzgAWEyKeAcQo6J+0dJFv0E6tTsJe6KRtrkVNyS/L63gYoAb1VaF INCsK+g5dr14oWDklsski1ftcE2/y/tnLRqaoN2YS3b4l35rQhhLMeE6dvwX+Vrc4sIp 3XxWEzjLRMD0EzeD/QWCssqWJSkQCbuK+Q+aLd1Ngs1UvKrC+We9RiFXtmoQUptFdAyd i7sv5TJntrhDOE5SECDmp1zgMhqQkcWeQKWSyU5p6a8rNDzOS9m+/ZKPMqsNC87wXnn0 7JNw0Rb1nWE498yG8OCYZnV7XPgtpoNxfe3+CwT/9fx1/Vb47E17YnaPKviUDcTYnXE/ 8WEQ== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=SsnJRY2Kex2ZNXystfYwdskm4OmIhMcSdqowKAkl8Ts=; b=dRlRRk0YghKvnPHP/80hlBVaQgzyNpjm9a3ajiUdNKfLRMozMeK4zfmmOjEU5JMyqA M6oiyYJCJEXh5CgdrI/Q6/0IchGvaOUWM7tqcMHxAVg4z30r7lRI4nfLwG0LFAvywwOv IVYWJwrY3/jr2QKnWyn/Y555EIfl6cKNNRdqSvjoyTKwWiJ2s6KvmaFTRvXHWI5SpQaA Kasp0H9auR7UvfFcDa2wqOlmA5XURcMgI5lbKP+s2+hAVNEpL7WDqovhqApAs01NCMT9 CmmwaLutW/kY8Djy7Xm0WRo6w9akAznNkM9fBpLMrZ8orWjYVS+hDHC78425RwdQgDvM xPaA== 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 j22-20020a633c16000000b0043462b7aad0si24533839pga.64.2022.09.16.06.41.11; Fri, 16 Sep 2022 06:41:29 -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 S229532AbiIPNSz (ORCPT + 99 others); Fri, 16 Sep 2022 09:18:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231444AbiIPNSu (ORCPT ); Fri, 16 Sep 2022 09:18:50 -0400 Received: from mail.wantstofly.org (hmm.wantstofly.org [213.239.204.108]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C519EA3D44; Fri, 16 Sep 2022 06:18:47 -0700 (PDT) Received: by mail.wantstofly.org (Postfix, from userid 1000) id 2D4807F505; Fri, 16 Sep 2022 16:18:46 +0300 (EEST) Date: Fri, 16 Sep 2022 16:18:46 +0300 From: Lennert Buytenhek To: Ilpo =?iso-8859-1?Q?J=E4rvinen?= Cc: Greg Kroah-Hartman , Jiri Slaby , linux-serial , LKML , Andy Shevchenko Subject: Re: I/O page faults from 8250_mid PCIe UART after TIOCVHANGUP Message-ID: References: <7fd034a9-c1e1-2dca-693b-129c9d2649@linux.intel.com> <421c541b-25d7-a1de-8c21-5a164dcf24ef@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <421c541b-25d7-a1de-8c21-5a164dcf24ef@linux.intel.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS 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 Fri, Sep 16, 2022 at 03:02:04PM +0300, Ilpo J?rvinen 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. > > > > > > > > Ah, indeed. Then you may disable MSI (in 8250_mid) and see that anyway? > > > > > > > > > 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.) > > > > > > > > And I believe you are not using that UART as debug console, so it won't > > > > dead lock itself. It's then better than I assumed. > > > > > > > > > > > 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. > > > > > > The patch below seems to avoid the faults. [...] > > > > Thanks for the fix! > > > > > > > [...] I'm far from sure if it's the > > > best fix though as I don't fully understand what causes the faults during > > > the THRE tests because the port->irq is disabled by the THRE test block. > > > > If the IRQ hasn't been set up yet, the UART will have zeroes in its MSI > > address/data registers. Disabling the IRQ at the interrupt controller > > won't stop the UART from performing a DMA write to the address programmed > > in its MSI address register (zero) when it wants to signal an interrupt. > > > > (These UARTs (in Ice Lake-D) implement PCI 2.1 style MSI without masking > > capability, so there is no way to mask the interrupt at the source PCI > > function level, except disabling the MSI capability entirely, but that > > would cause it to fall back to INTx# assertion, and the PCI specification > > prohibits disabling the MSI capability as a way to mask a function's > > interrupt service request.) (In other words, disabling the IRQ at the interrupt controller doesn't prevent the device from signaling an interrupt, and signaling an interrupt without a proper MSI target address configured in the device's MSI address register is what is causing the I/O page fault.) > > > Reported-by: Lennert Buytenhek > > > > Could you make this buytenh@arista.com ? > > Sure. Should I add Tested-by as well? OK! Tested-by: Lennert Buytenhek