Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp832933ybf; Fri, 28 Feb 2020 08:28:53 -0800 (PST) X-Google-Smtp-Source: APXvYqxyMSNUpuWGeuJpFyV8eRjpOpajMfDiu6fN0a+nxXoaHBob8rW/4haPucY5f3F4vc+/pvb4 X-Received: by 2002:aca:c415:: with SMTP id u21mr3771711oif.49.1582907333081; Fri, 28 Feb 2020 08:28:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582907333; cv=none; d=google.com; s=arc-20160816; b=z1dhevmc2h3IFxeZoErGFR+VG2sAvIzAwhxypjMrlCj0anG3E2ak/DTEn9flCb1X89 cB/0L7+M2STEBIsNI6ymLxfhoS1rGCCvBD1MXveV+xg7KMHofSz6wFljII1mnzFnEIGh bw/BR1AzPooVJGIcKARM6yyG3Y9osyZeJPe+6jbfKG+iwEFrPRSBYy1tCtFoDY08XEy5 ATnK7r1B8hnXRYn0cwSFtWa9dbJEUrvbussqJVQQyUAiRgLhmQ/sMfz5tkeqnz5JfCUz +b/reNTcQiDAoz7Bmuu6ZL0HWn0PEGY6FVaxJOdypQgO1UZUNvOmqrDVhhK7ZtzEj0yz s//w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:cc:to:subject; bh=lTAoMw8dQ/ULPLsgrS2KT1ASLKB7uRfTr8l/GFKSk9E=; b=kFuWoWOQlBqLmnAHEbvQDbla1otYGse6XJrTzK9WoyKuoNgrIh02wfw/ew1eX4dN7X 9+ivX6Rj9S0P6LmhyoJqbuIXS422H0THLll/etgx+RrFu+CWbnufTJx3E0/Z1NpH4CzG FfNoHo2liMLb1Frx6jatD66aMbhk9QUZsdDU7sBeKIZcET/OqLq4t5geUCcx/JSXqoL/ 1rslomLKF52AmFfOQVozwdZ7QLsdyUkymaQWalQW6MY3K2D4HCQ4tmmZG8FpSQIoU9oz Srg9w0LfQJut2wkhgZiwVROvP16827e1eX3MA8CJv4DoLBZOPaZyXinhPF3WyTg4NLXr 1jvA== 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 z73si2122859oia.40.2020.02.28.08.28.41; Fri, 28 Feb 2020 08:28:53 -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 S1726671AbgB1Q11 (ORCPT + 99 others); Fri, 28 Feb 2020 11:27:27 -0500 Received: from mout.kundenserver.de ([212.227.17.24]:60955 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725730AbgB1Q10 (ORCPT ); Fri, 28 Feb 2020 11:27:26 -0500 Received: from [192.168.1.183] ([37.4.249.171]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MJV5K-1inyfA4AHY-00JvWc; Fri, 28 Feb 2020 17:26:49 +0100 Subject: Re: [RFT PATCH 1/4] usb: dwc2: Simplify and fix DMA alignment code To: Doug Anderson , Guenter Roeck Cc: Minas Harutyunyan , Greg Kroah-Hartman , =?UTF-8?B?QW50dGkgU2VwcMOkbMOk?= , Boris ARZUR , linux-usb@vger.kernel.org, LKML , Felipe Balbi , Martin Schiller , Nicolas Saenz Julienne References: <20200226210414.28133-1-linux@roeck-us.net> <20200226210414.28133-2-linux@roeck-us.net> From: Stefan Wahren Openpgp: pre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jQkJKIAXwFpv+W8CWLqzDWOvdlrDaTaVMscFTeH5W6Uprl65jqFQGMp cRGCs8GCUW13H0IyOtQtwWXA4ny+SL81pviAmaSXU8laKaRu91VOVaF9f4sAEQEAAcLBXwQY AQIACQUCW3qAEwIbDAAKCRCUgewPEZDy2+oXD/9cHHRkBZOfkmSq14Svx062PtU0KV470TSn p/jWoYJnKIw3G0mXIRgrtH2dPwpIgVjsYyRSVMKmSpt5ZrDf9NtTbNWgk8VoLeZzYEo+J3oP qFrTMs3aYYv7e4+JK695YnmQ+mOD9nia915tr5AZj95UfSTlyUmyic1d8ovsf1fP7XCUVRFc RjfNfDF1oL/pDgMP5GZ2OwaTejmyCuHjM8IR1CiavBpYDmBnTYk7Pthy6atWvYl0fy/CqajT Ksx7+p9xziu8ZfVX+iKBCc+He+EDEdGIDhvNZ/IQHfOB2PUXWGS+s9FNTxr/A6nLGXnA9Y6w 93iPdYIwxS7KXLoKJee10DjlzsYsRflFOW0ZOiSihICXiQV1uqM6tzFG9gtRcius5UAthWaO 1OwUSCQmfCOm4fvMIJIA9rxtoS6OqRQciF3crmo0rJCtN2awZfgi8XEif7d6hjv0EKM9XZoi AZYZD+/iLm5TaKWN6oGIti0VjJv8ZZOZOfCb6vqFIkJW+aOu4orTLFMz28aoU3QyWpNC8FFm dYsVua8s6gN1NIa6y3qa/ZB8bA/iky59AEz4iDIRrgUzMEg8Ak7Tfm1KiYeiTtBDCo25BvXj bqsyxkQD1nkRm6FAVzEuOPIe8JuqW2xD9ixGYvjU5hkRgJp3gP5b+cnG3LPqquQ2E6goKUML AQ== Message-ID: Date: Fri, 28 Feb 2020 17:26:47 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US X-Provags-ID: V03:K1:8Ci6HbpqEwshCElsKWJpQlfMV5T1blfqm6rwrhbJ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fLqmeq8mZ5HlfNTCaaBnFoY7b4tMVGKZeyDN9Kcabr Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Doug, [add Nicolas the new BCM2835 maintainer] Am 27.02.20 um 23:06 schrieb Doug Anderson: > Hi, > > On Wed, Feb 26, 2020 at 1:04 PM Guenter Roeck wrote: >> The code to align buffers for DMA was first introduced with commit >> 3bc04e28a030 ("usb: dwc2: host: Get aligned DMA in a more supported way"). >> It was updated with commit 56406e017a88 ("usb: dwc2: Fix DMA alignment >> to start at allocated boundary") because it did not really align buffers to >> DMA boundaries but to word offsets. This was then optimized in commit >> 1e111e885238 ("usb: dwc2: Fix inefficient copy of unaligned buffers") >> to only copy actual data rather than the whole buffer. Commit 4a4863bf2e79 >> ("usb: dwc2: Fix DMA cache alignment issues") changed this further to add >> a padding at the end of the buffer to ensure that the old data pointer is >> not in the same cache line as the buffer. >> >> This last commit states "Otherwise, the stored_xfer_buffer gets corrupted >> for IN URBs on non-cache-coherent systems". However, such corruptions are >> still observed. This suggests that the commit may have been hiding a >> problem rather than fixing it. Further analysis shows that this is indeed >> the case: The code in dwc2_hc_start_transfer() assumes that the transfer >> size is a multiple of wMaxPacketSize, and rounds up the transfer size >> communicated to the chip accordingly. Added debug code confirms that >> the chip does under some circumstances indeed send more data than requested >> in the urb receive buffer size. >> >> On top of that, it turns out that buffers are still not guaranteed to be >> aligned to dma_get_cache_alignment(), but to DWC2_USB_DMA_ALIGN (4). >> Further debugging shows that packets aligned to DWC2_USB_DMA_ALIGN >> but not to dma_get_cache_alignment() are indeed common and work just fine. >> This suggests that commit 56406e017a88 was not really necessary because >> even without it packets were already aligned to DWC2_USB_DMA_ALIGN. >> >> To simplify the code, move the old data pointer back to the beginning of >> the new buffer, restoring most of the original commit. Stop aligning the >> buffer to dma_get_cache_alignment() since it isn't needed and only makes >> the code more complex. Instead, ensure that the allocated buffer is a >> multiple of wMaxPacketSize to ensure that the chip does not write beyond >> the end of the buffer. > I do like the cleanliness of being able to easily identify the old > buffer (AKA by putting it first) and I agree that the existing code > was only really guaranteeing 4-byte alignment and if we truly needed > more alignment then we'd be allocating a lot more bounce buffers > (which is pretty expensive). > > ...but the argument in commit 56406e017a88 ("usb: dwc2: Fix DMA > alignment to start at allocated boundary") is still a compelling one. > Maybe at least put a comment in the code next to the "#define > DWC2_USB_DMA_ALIGN" saying that we think that this is enough alignment > for anyone using dwc2's built-in DMA logic? > > >> Cc: Douglas Anderson >> Cc: Boris Arzur >> Fixes: 56406e017a88 ("usb: dwc2: Fix DMA alignment to start at allocated boundary") >> Signed-off-by: Guenter Roeck >> --- >> drivers/usb/dwc2/hcd.c | 67 ++++++++++++++++++++++-------------------- >> 1 file changed, 35 insertions(+), 32 deletions(-) > Sorry for such a mess and thank you for all the work tracking down and > documenting all the problems. Clearly deep understanding of DMA is > not something I can claim. :( > > A few points of order first: > * Although get_maintainer doesn't identify him, it has seemed like > Felipe Balbi lands most of the dwc2 things. Probably a good idea to > CC him. > * I have historically found Stefan Wahren interested in dwc2 fixes and > willing to test them on Raspberry Pi w/ various peripherals. i'm not the BCM2835 maintainer anymore, but will give it a try. Regards Stefan