From patchwork Thu Jan 25 15:27:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 766816 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 71BEB6EB6D for ; Thu, 25 Jan 2024 15:26:12 +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=1706196374; cv=none; b=a9LG7KnhXyIImGe2x/6smTLTkI1oxA5ADIecOZpTL9aLxPiIbyjdzKJi+4B80ed0G99JGMAxTIdaRplvSX73gFiwrG5sPZj/uaZy27HeyYxss53lhx+WL5U4NqP27Y+P138si/aMaxnPB6CT55QgbzEdmQLPqWwOhc0y/kV60Wk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706196374; c=relaxed/simple; bh=7+2tR3u66bv4GLjuFdnhuZS81nyqklScPyEApxlpV9Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZAy4Ku9aYsoGw7QwXCPCaLM5PuA9kqiyHLXiY1hEP9wjt5LMOTsD7EDbqWh+2Hl1F9/CEgL0t8u/uYdHWkspTJ/3KLu6lNPl1B26YBF8A03+bQLT2TK8Nki7xLe0I4VvYpUtdf9+Unjsg3cw87UBuAMdpo99f8/ABWJBybfNrKY= 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=NEl0ptql; 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="NEl0ptql" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706196372; x=1737732372; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7+2tR3u66bv4GLjuFdnhuZS81nyqklScPyEApxlpV9Y=; b=NEl0ptqlv3LVMadVLcp8eKM7XQCgehh/S8IJKA4pfOyBoYauP5wHe5qv L/q+yU6v9CvUVnHqQmrEHJGN1WIM+6M8j2m8XWlHdaQkodyKIrQznxIy4 Xf0NjdWF5B3HdUzjzR2xwPsVYtI+wnrXa13oEyzGg3Urf0BFrAXjTsxM4 dlBUoWOy8yAtJgFEAcYUI0QkI8P7qcZnYc14mmAz8tmPb3OkddOJPqvvn banKtMFgbo0DYKFfwyEDrzxz3Vn3KJQq95eNI2XmkunfmSFCtYk2PAOkk zGcoT7VqTjyFTUPygDlS3KVEhB4UxKGYg2qNxz/oSeSbcecrbhJBifltF Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10964"; a="23651353" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="23651353" 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:12 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10964"; a="857099928" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="857099928" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmsmga004.fm.intel.com with ESMTP; 25 Jan 2024 07:26:10 -0800 From: Mathias Nyman To: Cc: linux-usb@vger.kernel.org, Mathias Nyman , Dan Carpenter Subject: [PATCH 2/4] xhci: fix off by one check when adding a secondary interrupter. Date: Thu, 25 Jan 2024 17:27:35 +0200 Message-Id: <20240125152737.2983959-3-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 The sanity check of interrupter index when adding a new interrupter is off by one. intr_num needs to be smaller than xhci->max_interrupter to fit the array of interrupters. Luckily this doesn't cause any real word harm as xhci_add_interrupter() is always called with a intr_num value smaller than xhci->max_interrupters in any current kernel. Should not be needed for stable as 6.7 kernel and older only supports one interrupter, with intr_num always being zero. Reported-by: Dan Carpenter Closes: https://lore.kernel.org/linux-usb/e9771296-586d-456a-ac24-a82de79bb2e6@moroto.mountain/ Fixes: 4bf398e15aa4 ("xhci: split allocate interrupter into separate alloacte and add parts") Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-mem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index d00d4d937236..a7716202a8dd 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2322,7 +2322,7 @@ xhci_add_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir, u64 erst_base; u32 erst_size; - if (intr_num > xhci->max_interrupters) { + if (intr_num >= xhci->max_interrupters) { xhci_warn(xhci, "Can't add interrupter %d, max interrupters %d\n", intr_num, xhci->max_interrupters); return -EINVAL; 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: