From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753628AbdJKJXM convert rfc822-to-8bit (ORCPT ); Wed, 11 Oct 2017 05:23:12 -0400 Received: from smtp-out6.electric.net ([192.162.217.182]:57008 "EHLO smtp-out6.electric.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752486AbdJKJXJ (ORCPT ); Wed, 11 Oct 2017 05:23:09 -0400 From: David Laight To: "'Robin Murphy'" , "mathias.nyman@intel.com" , "gregkh@linuxfoundation.org" CC: "linux-usb@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "angelsl@in04.sg" Subject: RE: [PATCH] xhci: Cope with VIA VL805 readahead Thread-Topic: [PATCH] xhci: Cope with VIA VL805 readahead Thread-Index: AQHTQfMDLh/q5kThTUmZcX3U065zS6LeX4Rg Date: Wed, 11 Oct 2017 09:23:03 +0000 Message-ID: <063D6719AE5E284EB5DD2968C1650D6DD0090E41@AcuExch.aculab.com> References: <7116a80607dfa5e9e648de240abef8fa7402cf73.1507658807.git.robin.murphy@arm.com> In-Reply-To: <7116a80607dfa5e9e648de240abef8fa7402cf73.1507658807.git.robin.murphy@arm.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.202.99.200] Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-Outbound-IP: 156.67.243.126 X-Env-From: David.Laight@ACULAB.COM X-Proto: esmtps X-Revdns: X-HELO: AcuExch.aculab.com X-TLS: TLSv1:AES128-SHA:128 X-Authenticated_ID: X-PolicySMART: 3396946, 3397078 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Robin Murphy > Sent: 10 October 2017 19:09 > > The VIA VL805 host controller is well-known for causing problems on > systems with IOMMUs enabled, ranging from triggering endless streams of > fault messages to locking itself up completely. It appears that the root > of the problem might be an over-aggressive prefetching of TRBs, wherein > consuming commands near the end of a queue segment causes it to read off > the end of the segment, even across a page boundary. This blows up when > DMA mapping ops are backed by an IOMMU, since there is no guarantee that > addresses outside the allocated segment are accessible at all. > > Some trial-and-error investigation reveals that we can avoid such > cross-page reads by not using the last few TRBs in a segment; to that > end, factor out the implicit index of the end-of-segemnt link TRB, and > implement a quirk to move it slightly further forward when necessary. Does this fix all of your problems? Or is there a second issue when the iommu is disabled? ... > +unsigned int xhci_segment_link_idx(struct xhci_hcd *xhci) > +{ > + if (xhci->quirks & XHCI_READAHEAD_QUIRK) > + return TRBS_PER_SEGMENT - 4; > + > + return TRBS_PER_SEGMENT - 1; > +} There is no point calculating this every time it is needed. Save the value in the xhci structure. I wonder whether it is actually worth just setting TRBS_PER_SEGMENT to 252 but allocating a full page (256 TRBs) (ie doing it unconditionally for all devices). I suspect the performance drop will be immeasurable small. David