Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp2030384rwn; Fri, 16 Sep 2022 04:49:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6SMon250/L4mF8/ecqvBWOzWiXVVmh7jGvyz/2P5LBhey7kdzQ4OFM2YMnnpodmMJ7z15q X-Received: by 2002:a50:c8c3:0:b0:44c:5cb6:5484 with SMTP id k3-20020a50c8c3000000b0044c5cb65484mr3611174edh.285.1663328972898; Fri, 16 Sep 2022 04:49:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663328972; cv=none; d=google.com; s=arc-20160816; b=zQuItNwhmsEDmaoKov441Drfj8OJ5g/L/EbCaHAiHCuAE2LYxuGp6d6Vl7+ASYPe6Q Qy+b6uEWNONoxYpM49h4V2r57DabYmR1OKZL4Qy7dRPQbXvo8SAAgd6QP2F6++UUPxEt YimOEKKl3se40UuIOPFuEhkbjR8SCyQEcZQ0vU6Twbk1R+vMLOW00c2QJeiOxiqVqJGn deBT///WOZLH1onnvs6wW5CXX+us7WlWI0zglgU9cxC8a9Z515zwU8evH1IaSup1e6Ag rM/6WD7eYZiJkvZRh4hf4HbhcEPc51Hb1+GNDYSQqziNM4FueMsprLV9+eoWWwjTRW5E 8bDQ== 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=CIKq+3N9UR02vJ9gr+joaZgQkhsKiC95ns5wD6zU9m0=; b=yF0BxrdZme7cil4lGb7YCJ6VCDls2Q1FF03nBjLpnsgy2o3RyGnhHrSstEDUGV3cJw 7l4DUrsNbaKnEAOFdJYdrW+BF8OdVjjiBbmpCHlc7AROX0gP1R91ZkA8fegL/m2S1yDo Z1g6kVzAleRyqcb4sE2DFImgURtqJjXIhbhHZbbUClObpi2YngUu0OMWQO+P9PXizP5w yGS2ctWN8xvC06iLsfht9Ne8BBcfBqRZA4ZPa6+wYnZ86G/vMY/b33X13BDOCJBGWzi7 8k/+2YzdYVp9x39Nc80mm0FeEdEhJRQM19P/Ts4pESb0Wjx65W+STjj55ceseiX7zvgZ ZKKA== 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 k20-20020a170906579400b007771bc8dbb4si15041886ejq.781.2022.09.16.04.49.04; Fri, 16 Sep 2022 04:49:32 -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 S230389AbiIPLrS (ORCPT + 99 others); Fri, 16 Sep 2022 07:47:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229899AbiIPLrN (ORCPT ); Fri, 16 Sep 2022 07:47:13 -0400 Received: from mail.wantstofly.org (hmm.wantstofly.org [213.239.204.108]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3FA24E620; Fri, 16 Sep 2022 04:47:11 -0700 (PDT) Received: by mail.wantstofly.org (Postfix, from userid 1000) id AEFC67F505; Fri, 16 Sep 2022 14:47:08 +0300 (EEST) Date: Fri, 16 Sep 2022 14:47:08 +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> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <7fd034a9-c1e1-2dca-693b-129c9d2649@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 Thu, Sep 15, 2022 at 07:27:45PM +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.) > Reported-by: Lennert Buytenhek Could you make this buytenh@arista.com ?