usb dwc2 fix

This commit is contained in:
Peter Robinson 2019-06-10 13:00:34 +01:00
parent 1149ccac54
commit de507cfd5d
2 changed files with 110 additions and 0 deletions

View File

@ -580,6 +580,9 @@ Patch527: v2-powerpc-mm-mark-more-tlb-functions-as-__always_inline.patch
Patch530: crypto-ghash-fix-unaligned-memory-access-in-ghash_setkey.patch
# https://patchwork.kernel.org/patch/10817377/
Patch532: usb-dwc2-Fix-DMA-cache-alignment-issues.patch
# END OF PATCH DEFINITIONS
%endif

View File

@ -0,0 +1,107 @@
From patchwork Mon Feb 18 06:37:30 2019
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Martin Schiller <ms@dev.tdt.de>
X-Patchwork-Id: 10817377
Return-Path: <linux-usb-owner@kernel.org>
Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org
[172.30.200.125])
by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A292C1399
for <patchwork-linux-usb@patchwork.kernel.org>;
Mon, 18 Feb 2019 06:47:00 +0000 (UTC)
Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1])
by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F0912A092
for <patchwork-linux-usb@patchwork.kernel.org>;
Mon, 18 Feb 2019 06:47:00 +0000 (UTC)
Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486)
id 82B232A0EF; Mon, 18 Feb 2019 06:47:00 +0000 (UTC)
X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on
pdx-wl-mail.web.codeaurora.org
X-Spam-Level:
X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI,
RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD7AC2A092
for <patchwork-linux-usb@patchwork.kernel.org>;
Mon, 18 Feb 2019 06:46:59 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
id S1728527AbfBRGqy (ORCPT
<rfc822;patchwork-linux-usb@patchwork.kernel.org>);
Mon, 18 Feb 2019 01:46:54 -0500
Received: from host-88-217-225-28.customer.m-online.net ([88.217.225.28]:29120
"EHLO mail.dev.tdt.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org
with ESMTP id S1725836AbfBRGqx (ORCPT
<rfc822;linux-usb@vger.kernel.org>); Mon, 18 Feb 2019 01:46:53 -0500
X-Greylist: delayed 552 seconds by postgrey-1.27 at vger.kernel.org;
Mon, 18 Feb 2019 01:46:53 EST
Received: from localhost.localdomain (unknown [10.2.3.20])
by mail.dev.tdt.de (Postfix) with ESMTPSA id 69723204C2;
Mon, 18 Feb 2019 06:37:39 +0000 (UTC)
From: Martin Schiller <ms@dev.tdt.de>
To: hminas@synopsys.com, gregkh@linuxfoundation.org,
felipe.balbi@linux.intel.com, a.seppala@gmail.com,
dianders@chromium.org
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
Martin Schiller <ms@dev.tdt.de>
Subject: [PATCH] usb: dwc2: Fix DMA cache alignment issues
Date: Mon, 18 Feb 2019 07:37:30 +0100
Message-Id: <20190218063730.26870-1-ms@dev.tdt.de>
X-Mailer: git-send-email 2.11.0
Sender: linux-usb-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-usb.vger.kernel.org>
X-Mailing-List: linux-usb@vger.kernel.org
X-Virus-Scanned: ClamAV using ClamSMTP
Insert a padding between data and the stored_xfer_buffer pointer to
ensure they are not on the same cache line.
Otherwise, the stored_xfer_buffer gets corrupted for IN URBs on
non-cache-coherent systems. (In my case: Lantiq xRX200 MIPS)
Fixes: 3bc04e28a030 ("usb: dwc2: host: Get aligned DMA in a more supported way")
Fixes: 56406e017a88 ("usb: dwc2: Fix DMA alignment to start at allocated boundary")
Signed-off-by: Martin Schiller <ms@dev.tdt.de>
Tested-by: Douglas Anderson <dianders@chromium.org>
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Acked-by: Minas Harutyunyan <hminas@synopsys.com>
---
drivers/usb/dwc2/hcd.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index dd82fa516f3f..f3035dd4db25 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -2664,8 +2664,10 @@ static void dwc2_free_dma_aligned_buffer(struct urb *urb)
return;
/* Restore urb->transfer_buffer from the end of the allocated area */
- memcpy(&stored_xfer_buffer, urb->transfer_buffer +
- urb->transfer_buffer_length, sizeof(urb->transfer_buffer));
+ memcpy(&stored_xfer_buffer,
+ PTR_ALIGN(urb->transfer_buffer + urb->transfer_buffer_length,
+ dma_get_cache_alignment()),
+ sizeof(urb->transfer_buffer));
if (usb_urb_dir_in(urb)) {
if (usb_pipeisoc(urb->pipe))
@@ -2697,6 +2699,7 @@ static int dwc2_alloc_dma_aligned_buffer(struct urb *urb, gfp_t mem_flags)
* DMA
*/
kmalloc_size = urb->transfer_buffer_length +
+ (dma_get_cache_alignment() - 1) +
sizeof(urb->transfer_buffer);
kmalloc_ptr = kmalloc(kmalloc_size, mem_flags);
@@ -2707,7 +2710,8 @@ static int dwc2_alloc_dma_aligned_buffer(struct urb *urb, gfp_t mem_flags)
* Position value of original urb->transfer_buffer pointer to the end
* of allocation for later referencing
*/
- memcpy(kmalloc_ptr + urb->transfer_buffer_length,
+ memcpy(PTR_ALIGN(kmalloc_ptr + urb->transfer_buffer_length,
+ dma_get_cache_alignment()),
&urb->transfer_buffer, sizeof(urb->transfer_buffer));
if (usb_urb_dir_out(urb))