From patchwork Thu Jan 25 15:27:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 766815 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 64FD26EB7B; Thu, 25 Jan 2024 15:26:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706196377; cv=none; b=rVMFY6H8/oHL3HdCa7hOgqVEgiPJp7SItWokgu/HR82mipab3Qq59cj7qhtIt+SEHYMgS4o43wksDtqkAnCLhU5gJ45Q6VcfcAtW/AdnXEM8F09tyw3WcEWGES40wrVOvtRm2TWmu/GFA4W/yk/JS5ZoXq59NQSdH8Tpcn6kjOw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706196377; c=relaxed/simple; bh=tJN0S6rY1/CKU1dDI8IfHzyyHIeGZm28jyMc1dSzveM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZxIpghVA+esk/Wq0ChoUWYi4HKjgeH9vjEDvrRdCCIFEPoIkMHQQ+SwqMVl8oVbDbx+JitD0BSzPY/QQldpBe0TW/Wm/gyzb6q2RuwhOP/nVmrM0qnuSM0GM1XJjr4422cYs4mjR5SL+b1Iy60KIbRXavpAUObgEuHfWb+pLPAo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=jxuWOugE; arc=none smtp.client-ip=192.198.163.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="jxuWOugE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706196376; x=1737732376; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tJN0S6rY1/CKU1dDI8IfHzyyHIeGZm28jyMc1dSzveM=; b=jxuWOugEr3u57w4WFJBifkE3iQnzJbIBfvm64/vI8GL53gdNny+V2Rgy KDGTWKIzBaoqQFEquakSCyEUzdFzsc8E996CQBSnMhdEChuaSC++FAf+y RP8Q3wgSZATuLAVkzETZ+SbjjYrZb3RgHQaB5l4wplf0Lay/MfBFs9JD1 fijkCwCZQN3ryoUj5Hrk6xYA+/1Q9gXlDUkwrkuWIwVCNE8aO7pIIRcw9 HW3bmzkK7DW4OCGn93+xUnrSsMI7TWPGDv1FA9BvL1cpsH/plZfq85Zyn O6Y4KPeGd+bsbsQYh8LNOh3FzLyXg2o4itCPUa2cuyLc2Y1hQiuEuoXaS A==; X-IronPort-AV: E=McAfee;i="6600,9927,10964"; a="23651369" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="23651369" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jan 2024 07:26:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10964"; a="857099933" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="857099933" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmsmga004.fm.intel.com with ESMTP; 25 Jan 2024 07:26:14 -0800 From: Mathias Nyman To: Cc: linux-usb@vger.kernel.org, Michal Pecio , stable@vger.kernel.org, Mathias Nyman Subject: [PATCH 4/4] xhci: handle isoc Babble and Buffer Overrun events properly Date: Thu, 25 Jan 2024 17:27:37 +0200 Message-Id: <20240125152737.2983959-5-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240125152737.2983959-1-mathias.nyman@linux.intel.com> References: <20240125152737.2983959-1-mathias.nyman@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Michal Pecio xHCI 4.9 explicitly forbids assuming that the xHC has released its ownership of a multi-TRB TD when it reports an error on one of the early TRBs. Yet the driver makes such assumption and releases the TD, allowing the remaining TRBs to be freed or overwritten by new TDs. The xHC should also report completion of the final TRB due to its IOC flag being set by us, regardless of prior errors. This event cannot be recognized if the TD has already been freed earlier, resulting in "Transfer event TRB DMA ptr not part of current TD" error message. Fix this by reusing the logic for processing isoc Transaction Errors. This also handles hosts which fail to report the final completion. Fix transfer length reporting on Babble errors. They may be caused by device malfunction, no guarantee that the buffer has been filled. Signed-off-by: Michal Pecio Cc: stable@vger.kernel.org Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-ring.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 41be7d31a36e..f0d8a607ff21 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -2394,9 +2394,13 @@ static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, case COMP_BANDWIDTH_OVERRUN_ERROR: frame->status = -ECOMM; break; - case COMP_ISOCH_BUFFER_OVERRUN: case COMP_BABBLE_DETECTED_ERROR: + sum_trbs_for_length = true; + fallthrough; + case COMP_ISOCH_BUFFER_OVERRUN: frame->status = -EOVERFLOW; + if (ep_trb != td->last_trb) + td->error_mid_td = true; break; case COMP_INCOMPATIBLE_DEVICE_ERROR: case COMP_STALL_ERROR: