From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 517EBC07E9A for ; Wed, 14 Jul 2021 14:27:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3CF8461260 for ; Wed, 14 Jul 2021 14:27:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239471AbhGNOaJ (ORCPT ); Wed, 14 Jul 2021 10:30:09 -0400 Received: from mga11.intel.com ([192.55.52.93]:18328 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239468AbhGNOaI (ORCPT ); Wed, 14 Jul 2021 10:30:08 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10044"; a="207336122" X-IronPort-AV: E=Sophos;i="5.84,239,1620716400"; d="scan'208";a="207336122" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jul 2021 07:27:17 -0700 X-IronPort-AV: E=Sophos;i="5.84,239,1620716400"; d="scan'208";a="505293086" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jul 2021 07:27:15 -0700 Received: from andy by smile with local (Exim 4.94.2) (envelope-from ) id 1m3fqv-00DLwd-RZ; Wed, 14 Jul 2021 17:27:09 +0300 Date: Wed, 14 Jul 2021 17:27:09 +0300 From: Andy Shevchenko To: David Jeffery Cc: linux-usb@vger.kernel.org, loberman@redhat.com, emilne@redhat.com, apanagio@redhat.com, torez@redhat.com Subject: Re: [PATCH] usb: ehci: Prevent missed ehci interrupts with edge-triggered MSI Message-ID: References: <20210714140309.GA27799@redhat> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210714140309.GA27799@redhat> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org On Wed, Jul 14, 2021 at 10:03:09AM -0400, David Jeffery wrote: Thanks, I have few minor comments, after addressing them feel free to add Reviewed-by: Andy Shevchenko > When MSI is used by the ehci driver, it can cause interrupts to be lost which ehci -> EHCI everywhere? > results in ehci only continuing to work due to its polling fallback. But the > reliance of polling drasticly reduces performance of any I/O through ehci. > > Interrupts are lost as ehci's interrupt handler does not safely handle > edge-triggered interrupts. It fails to ensure all interrupt status bits are > cleared, which works with level-triggered interrupts but not the Drop trailing white space here and double spaces in the couple of places above? > edge-triggered interrupts typical from using MSI. > > To fix this problem, check if the driver may have raced with the hardware > setting additional interrupt status bits and clear status until it is in a > stable state. Fixes tag? > Signed-off-by: David Jeffery > Tested-by: Laurence Oberman > --- > > This is an alternative to reverting 306c54d0edb6ba94d39877524dddebaad7770cf2 > which is the patch that allowed MSI to be used with ehci. Thanks! > > ehci-hcd.c | 16 +++++++++++++--- > 1 file changed, 13 insertions(+), 3 deletions(-) > > diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c > index 36f5bf6a0752..2283205d4b40 100644 > --- a/drivers/usb/host/ehci-hcd.c > +++ b/drivers/usb/host/ehci-hcd.c > @@ -704,14 +704,18 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd) > { > struct ehci_hcd *ehci = hcd_to_ehci (hcd); > u32 status, masked_status, pcd_status = 0, cmd; > + u32 current_status; Perhaps u32 status, current_status, masked_status, pcd_status = 0; u32 cmd; ? > int bh; > > spin_lock(&ehci->lock); > > - status = ehci_readl(ehci, &ehci->regs->status); > + status = 0; > > + current_status = ehci_readl(ehci, &ehci->regs->status); > +restart: > + status |= current_status; > /* e.g. cardbus physical eject */ > - if (status == ~(u32) 0) { > + if (current_status == ~(u32) 0) { > ehci_dbg (ehci, "device removed\n"); > goto dead; > } > @@ -720,7 +724,7 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd) > * We don't use STS_FLR, but some controllers don't like it to > * remain on, so mask it out along with the other status bits. > */ > - masked_status = status & (INTR_MASK | STS_FLR); > + masked_status = current_status & (INTR_MASK | STS_FLR); > > /* Shared IRQ? */ > if (!masked_status || unlikely(ehci->rh_state == EHCI_RH_HALTED)) { > @@ -730,6 +734,12 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd) > > /* clear (just) interrupts */ > ehci_writel(ehci, masked_status, &ehci->regs->status); > + > + /* for edge interrupts, don't race with an interrupt bit being raised */ for -> For > + current_status = ehci_readl(ehci, &ehci->regs->status); > + if (current_status & INTR_MASK) > + goto restart; > + > cmd = ehci_readl(ehci, &ehci->regs->command); > bh = 0; -- With Best Regards, Andy Shevchenko