Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2079168imj; Sun, 17 Feb 2019 22:50:52 -0800 (PST) X-Google-Smtp-Source: AHgI3IZdVKXmsoiPcZv8uBCnfXau/D6Lr7Q3+qxKQvc8ht2PHarP8k+9qtI/V7fhX8cMHPOh1YZy X-Received: by 2002:a63:470a:: with SMTP id u10mr8093718pga.17.1550472652368; Sun, 17 Feb 2019 22:50:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550472652; cv=none; d=google.com; s=arc-20160816; b=GYJ6fJppXGfUray+lu/qPdXtVcfOh88xwHm0gTl95l2mYkaUaWJAvlwRWidPvkbV6y /FUjCRFOy6EgS/IotyjYnSwuER7/mG/elql69U7BjNI7htJqUm2eb4AXU+RJ9cwES4ru 2ya7A/e0XoiEOaEoNnpsgMlN7o1CF27sCW283BUvq8M3p5i5xXmHzQ4mQE7zr2lmxXBc sm1E4Er4/V1LvEVemGvExjcR0+z4OIwCvAtTSY0zXR54kD1GK4Gp8H8UV9MEIVGK9WSO DbOsEFnu+LFiD/zz45nHhuyJqg9oz8vavQr8hsG2p2PZy4gvFdCbzUxirLxp0g0SsmiA Q+WA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=8hbDqxOO4NouF7QGrJnOvW/BRunl0M03IW0+VFuzZic=; b=ywfEoAaW156IDg9psOiYzWPqNRMy2YWpSASGBmNu/1uZCtGjHYP5cVmKTjG5e3VqF2 GeiiUBsM8bCUlKVy+KEQK8oJQo7qWHQDvu9JxWPey5B64E0d8AFgkdol8MzgiAAcmwoj DTrYR/hte8ywuA85JbmPbYXX7ppO3tpJPA9Hn31Pf8AbnnwLFc5PLBuQHKlVueH1h5zF tMUM1WUzyRGSYvm+o6tNub3DXHmVay9mxdYWU/sFDlFgYfr+j865y4HxdsqNwIMHt0LX SpCJgNhDhkms+SThN5PY2dSOE4rF5573bn9e2RE5jHODi0JoXw/Pk/MejImwmTX/PvqN zQoA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s5si12722341plr.211.2019.02.17.22.50.36; Sun, 17 Feb 2019 22:50:52 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728546AbfBRGqy (ORCPT + 99 others); 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 ); 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 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 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 X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mail.dev.tdt.de Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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)) -- 2.11.0