Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp961525ybl; Thu, 23 Jan 2020 10:55:28 -0800 (PST) X-Google-Smtp-Source: APXvYqxgGlhdcgfIlRw57VZt5z9rJyv/mACC1o7wMRXl/kN9he9AS4apcxNaRksXyqqj8vU/ki8m X-Received: by 2002:aca:ab0e:: with SMTP id u14mr11840005oie.1.1579805727954; Thu, 23 Jan 2020 10:55:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579805727; cv=none; d=google.com; s=arc-20160816; b=n+zrNRfdVxmOkUmZhHlho37qRQ0crwdNWqlRvAUoBFv1pTtsBeQDhoqg014cTsILwd 8PohD6RKkNYfcHZLdB0B/z37lZHbLHxgQMGYyhA3R2pLfHVd5nU+SiygrZUs8sPuUhXs BTa8HbYBUCtPthRANjXb1jJqwG/YgNZPC5FX5IWis4kjRpgP+qSBMFp7Tzl9j2PsXgGa PV0UnT7ZguoX0AdzNPHHHCwJYlPA7Ni3EFPBUPeLYPehr6ExBxEf3YJaKUquPceMulQX nnxjd8TgwnsC+4eQ25RMFbDvpTGlR0wqoXjL4rXZsvJPUYvgmrH+OjK90HyXYW7ByAhp MS9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :dlp-reaction:dlp-version:dlp-product:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from; bh=GtZGvblqSrwAr405EQ5//ONCvqgq9fIOm8QqITLdaMM=; b=n39hETtzhsihsNqTCo6nXCpDXCnaL6uDyYeiSiIaY+Vn+iy0Af4wNO1z/5ovHzYik7 72Qfjbt2z0rLd4O3bM0FTv8zc6/42T3A5HrznmEOn/jV20SNFrLjdSRO2Pk4w6tMFd2D vD7lDGWZlxDr7JzM3lPA37xEK/yYQmW0yxkxcFiwvJ9KUODGl+Z3cs5s1zTGZJ1Pupje cv+3C6wK4qqlDzeTPOdKfTxMP8ZD+nKme51rLZUCzPKn1/2zZCpyYrVuTqB9VhBJtsa0 aUvK/zvk+X0yiTrTYY+/Sgtv2hvB5pg8BEYZGjRYp5KuFqBKEqenhkQ5VxkCFtsoUqhD Jb5g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t1si166099otq.148.2020.01.23.10.55.15; Thu, 23 Jan 2020 10:55:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728831AbgAWSyR convert rfc822-to-8bit (ORCPT + 99 others); Thu, 23 Jan 2020 13:54:17 -0500 Received: from mga05.intel.com ([192.55.52.43]:59071 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727590AbgAWSyQ (ORCPT ); Thu, 23 Jan 2020 13:54:16 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Jan 2020 10:54:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,354,1574150400"; d="scan'208";a="221697238" Received: from orsmsx103.amr.corp.intel.com ([10.22.225.130]) by fmsmga007.fm.intel.com with ESMTP; 23 Jan 2020 10:54:15 -0800 Received: from orsmsx102.amr.corp.intel.com ([169.254.3.100]) by ORSMSX103.amr.corp.intel.com ([169.254.5.147]) with mapi id 14.03.0439.000; Thu, 23 Jan 2020 10:54:15 -0800 From: "Yang, Fei" To: Felipe Balbi , John Stultz , lkml CC: Anurag Kumar Vulisha , Thinh Nguyen , Tejas Joglekar , "Andrzej Pietrasiewicz" , Jack Pham , Todd Kjos , Greg KH , "Linux USB List" , stable , "John Stultz" Subject: RE: [RFC][PATCH 1/2] usb: dwc3: gadget: Check for IOC/LST bit in both event->status and TRB->ctrl fields Thread-Topic: [RFC][PATCH 1/2] usb: dwc3: gadget: Check for IOC/LST bit in both event->status and TRB->ctrl fields Thread-Index: AQHV0XMMDal2ka/y0kSxMT/Pi5VKVaf4X3SAgAA3SWA= Date: Thu, 23 Jan 2020 18:54:15 +0000 Message-ID: <02E7334B1630744CBDC55DA8586225837F9EE439@ORSMSX102.amr.corp.intel.com> References: <20200122222645.38805-1-john.stultz@linaro.org> <20200122222645.38805-2-john.stultz@linaro.org> <87tv4m4ov2.fsf@kernel.org> In-Reply-To: <87tv4m4ov2.fsf@kernel.org> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.2.0.6 dlp-reaction: no-action x-originating-ip: [10.22.254.138] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org >> The present code in dwc3_gadget_ep_reclaim_completed_trb() will check >> for IOC/LST bit in the event->status and returns if IOC/LST bit is >> set. This logic doesn't work if multiple TRBs are queued per request >> and the IOC/LST bit is set on the last TRB of that request. >> Consider an example where a queued request has multiple queued TRBs >> and IOC/LST bit is set only for the last TRB. In this case, the Core >> generates XferComplete/XferInProgress events only for the last TRB >> (since IOC/LST are set only for the last TRB). As per the logic in >> dwc3_gadget_ep_reclaim_completed_trb() event->status is checked for >> IOC/LST bit and returns on the first TRB. This makes the remaining >> TRBs left unhandled. >> To aviod this, changed the code to check for IOC/LST bits in both > avoid > >> event->status & TRB->ctrl. This patch does the same. > > We don't need to check both. It's very likely that checking the TRB is enough. > >> At a practical level, this patch resolves USB transfer stalls seen >> with adb on dwc3 based HiKey960 after functionfs gadget added >> scatter-gather support around v4.20. > > Right, I remember asking for tracepoint data showing this problem happening. It's the best way to figure out what's really going on. > > Before we accept these two patches, could you collect dwc3 tracepoint data and share here? I should have replied to this one. Sorry for the confusion on the other thread. I have sent tracepoints long time ago for this problem, but the tracepoints did help much on debugging the issue, so I'm not going to send again. But the problem is really obvious though. In function dwc3_gadget_ep_reclaim_trb_sg(), the for_each_sg loop doesn't get a chance to iterate through all TRBs in the sg list, because this function only gets called when the last TRB in the list is completed (because of setting IOC), so at this moment event->status has IOC bit set. The consequence is that, when the for_each_sg loop trying to reclaim the first TRB in the sg list, the call dwc3_gadget_ep_reclaim_completed_trb() returns 1 (if (event-status & DEPEVT_STATUS_IOC) return 1;), thus the for loop is terminated before the rest of the TRBs are reclaimed. static int dwc3_gadget_ep_reclaim_trb_sg(struct dwc3_ep *dep, struct dwc3_request *req, const struct dwc3_event_depevt *event, int status) { struct dwc3_trb *trb = &dep->trb_pool[dep->trb_dequeue]; struct scatterlist *sg = req->sg; struct scatterlist *s; unsigned int pending = req->num_pending_sgs; unsigned int i; int ret = 0; for_each_sg(sg, s, pending, i) { trb = &dep->trb_pool[dep->trb_dequeue]; if (trb->ctrl & DWC3_TRB_CTRL_HWO) break; req->sg = sg_next(s); req->num_pending_sgs--; ret = dwc3_gadget_ep_reclaim_completed_trb(dep, req, trb, event, status, true); if (ret) break; } return ret; }