Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1432706ybf; Sun, 1 Mar 2020 09:14:31 -0800 (PST) X-Google-Smtp-Source: APXvYqy8+q6NsaX9S1K37+Vp98ZxlQTGxbDp3L8HMkO//jNTVd1nMO1SHth1SlRqL14XvORspCFc X-Received: by 2002:a9d:61c5:: with SMTP id h5mr10547755otk.85.1583082871619; Sun, 01 Mar 2020 09:14:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583082871; cv=none; d=google.com; s=arc-20160816; b=H4HUwwV4iusFFCgJb9C++OmQG6U8ycOO7urdUQ9TT4tSNjoqQefTsc40+h8fcWeI1P sKEv5cWFGyBk0QOCTDvbZSdGyTGegA+CUop+DpDUUQcXJIu0/2CHeGe5F+bt7aAS2TgN WmoISuVxwfGJ9d8OR+qXglhKN/9rJ7yAtMuzTVbXDzIh1S3dxKoWSt6NHij/mPf5klPp WCslnbR9R1MJiuvnqNzyruMA4kJIrfWdDeqdori6Fk4PZkT6yZyZh9eh3ySQXInWFxGE tYVfBnmfbDacpXDs1KPnMWxSCWogOY473jcw1FcbuCeXA4EKFRCJ/x1zlQiTNsIjCotl Batg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:from:references:cc:to:subject:dkim-signature; bh=QF8QmRyf6dwW5QCdyss9EsW25WHFrHI0jJ5KlIw2iDY=; b=a+EUXxYDfFov3nl2Zirdm2jZaOsGHTkyF40sVjobkTiZAD3TrmCwnqFeB+WKeb6/p7 XwOQwyZtrt7l7E/kiT2MtvY9a2NaDNEdnuwV8atH1Cjno5N4Ytgi8xLYZMwBN6NntA8c roOxtcPmw+SHE4yEwF7w0SIEJvlmaTQXoafTGoGf7Le12nwtNQ0zfBhwMW6d3vc3wb+G TT2lIJT673hwBgrOL5g8ME1z5yQl2rJp0M/32XlOH5DuRRlRi3sYGsRtyXGskFKbzEJJ BvGZNKgk4Bu4We0fLOQyoNUpgGhjS4B98fd5tOCWdAk3xAlPsnObHCzmSH48IlKYY3Oz bGuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=KWdVHETP; 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 r12si133428otp.98.2020.03.01.09.14.16; Sun, 01 Mar 2020 09:14:31 -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; dkim=fail header.i=@gmail.com header.s=20161025 header.b=KWdVHETP; 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 S1726465AbgCARNg (ORCPT + 99 others); Sun, 1 Mar 2020 12:13:36 -0500 Received: from mail-pj1-f67.google.com ([209.85.216.67]:51694 "EHLO mail-pj1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726146AbgCARNf (ORCPT ); Sun, 1 Mar 2020 12:13:35 -0500 Received: by mail-pj1-f67.google.com with SMTP id fa20so3395068pjb.1; Sun, 01 Mar 2020 09:13:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:cc:references:from:autocrypt:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=QF8QmRyf6dwW5QCdyss9EsW25WHFrHI0jJ5KlIw2iDY=; b=KWdVHETPWB4+DY5T5jIS1A2T5KjQELIoAlQSrtH21Logzw6+vLNOjPsLiaL4qNwInJ Rs79Xv0cgpSLDlYOiGkStL6nFeWXqutJ3tpWAwCiCZCQ62+UVAbqfgbrNvnVOUxTjDTW tW8FylBczeEmQ2oVuB0lBU5qbRvWWlSE7CQjf347ZmB5Cwosdj47svbgEayLmjIKDu1N 4jjMZr4WfYuJnH13q+4joUZD/ZVYUEZSkKIGor6myjkUwA4npAY2Pdg6hUdmQu8fS8/U SNeCZq+8TPf2quzy2de9lAyOaouuFbIdCQLzsJbbGqvzXGWaV6yRMBiqoKEl8IHpLR/z dSSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:cc:references:from:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=QF8QmRyf6dwW5QCdyss9EsW25WHFrHI0jJ5KlIw2iDY=; b=JyV1afNHVIA8o9aZ2XN/W8N2yv0ehFiftZd+TElHyUuuEhTswyR+/TD/k3Xsob6xAg 3S6WnoPeWjazA4ZaAz/1ootIG26BpoNURJdN6sDPq6J0SlAdhBdl8rnUCdWosi/vhUQS OkNiqQJxx5FAdEU4QBz7LBcaXrTOIqOoOV3xL4NaL/wi3Tt8gMQYju3bipDUK3iW41ge Mmc/zZeP/xLs3tbIZ1yClxQCzjG7c4u9WTljKkVjfAlvFMiMKtKC7JZx+rSFeKEBs4zu vbus4o5WRm2P5hk7dqfXWd14R//jV7y3edIU4bGcBfRIji5UFeW56RF2vvljcZDj++TC UZgA== X-Gm-Message-State: APjAAAUFIgUWmHkaAcl93mCuOvciGEzEP4yKddcNN+Xjp5tUBGypV70y nBVL7Ju6IRq89nxmUffsOCY= X-Received: by 2002:a17:902:8ec9:: with SMTP id x9mr14010520plo.182.1583082814141; Sun, 01 Mar 2020 09:13:34 -0800 (PST) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id v9sm8966937pja.26.2020.03.01.09.13.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 01 Mar 2020 09:13:33 -0800 (PST) Subject: Re: [RFT PATCH 1/4] usb: dwc2: Simplify and fix DMA alignment code To: =?UTF-8?B?QW50dGkgU2VwcMOkbMOk?= Cc: Doug Anderson , Minas Harutyunyan , Greg Kroah-Hartman , Boris ARZUR , linux-usb@vger.kernel.org, LKML , Felipe Balbi , Stefan Wahren , Martin Schiller References: <20200226210414.28133-1-linux@roeck-us.net> <20200226210414.28133-2-linux@roeck-us.net> <20200228175905.GB3188@roeck-us.net> <62d81632-4a6f-b2d8-e420-b58fb6c9d044@roeck-us.net> <28e29bb7-b536-dd0f-d410-f4add6b2a9ab@roeck-us.net> From: Guenter Roeck Autocrypt: addr=linux@roeck-us.net; keydata= xsFNBE6H1WcBEACu6jIcw5kZ5dGeJ7E7B2uweQR/4FGxH10/H1O1+ApmcQ9i87XdZQiB9cpN RYHA7RCEK2dh6dDccykQk3bC90xXMPg+O3R+C/SkwcnUak1UZaeK/SwQbq/t0tkMzYDRxfJ7 nyFiKxUehbNF3r9qlJgPqONwX5vJy4/GvDHdddSCxV41P/ejsZ8PykxyJs98UWhF54tGRWFl 7i1xvaDB9lN5WTLRKSO7wICuLiSz5WZHXMkyF4d+/O5ll7yz/o/JxK5vO/sduYDIlFTvBZDh gzaEtNf5tQjsjG4io8E0Yq0ViobLkS2RTNZT8ICq/Jmvl0SpbHRvYwa2DhNsK0YjHFQBB0FX IdhdUEzNefcNcYvqigJpdICoP2e4yJSyflHFO4dr0OrdnGLe1Zi/8Xo/2+M1dSSEt196rXaC kwu2KgIgmkRBb3cp2vIBBIIowU8W3qC1+w+RdMUrZxKGWJ3juwcgveJlzMpMZNyM1jobSXZ0 VHGMNJ3MwXlrEFPXaYJgibcg6brM6wGfX/LBvc/haWw4yO24lT5eitm4UBdIy9pKkKmHHh7s jfZJkB5fWKVdoCv/omy6UyH6ykLOPFugl+hVL2Prf8xrXuZe1CMS7ID9Lc8FaL1ROIN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Ldertmw7eyAYOo4RuWJguYMg5DRnBk WkRwrSuCn7UG+qVWZeKEsFKFOkynOs3pVbcbq1pxbhk3TRWCGRU5JolI4ohy/7JV1TVbjiDI HP/aVnm6NC8of26P40Pg8EdAhajZnHHjA7FrJXsy3cyIGqvg9os4rNkUWmrCfLLsZDHD8FnU mDW4+i+XlNFUPUYMrIKi9joBhu18ssf5i5Q= Message-ID: Date: Sun, 1 Mar 2020 09:13:31 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/1/20 8:51 AM, Antti Seppälä wrote: > On Sun, 1 Mar 2020 at 18:24, Guenter Roeck wrote: >> >> Hi Antti, >> >> On 3/1/20 7:51 AM, Antti Seppälä wrote: >>> On Sat, 29 Feb 2020 at 18:33, Antti Seppälä wrote: >>>> >>>> On Sat, 29 Feb 2020 at 17:25, Guenter Roeck wrote: >>>>> >>>>> Sigh. It would have been too simple. Too bad I can't test myself. >>>>> I'd like to know if this is because URB_NO_TRANSFER_DMA_MAP is set on a >>>>> transfer, or because the beginning of the buffer indeed needs to be aligned >>>>> to the DMA cache line size on that system. In the latter case, the question >>>>> is why the alignment to DWC2_USB_DMA_ALIGN (=4) works. In the former case, >>>>> question would be why the realignment does any good in the first place. >>>>> >>>>> Any chance you can add some test code to help figuring out what exactly >>>>> goes wrong ? >>>>> >>>> >>>> Sure, I can try to help. Just let me know what code you would like to >>>> insert and where and I'll see what I can do. >>>> >>> >>> So I did some further research on this and it turns out that: >>> - URB_NO_TRANSFER_DMA_MAP is not set on the offending transfers so >>> the issue really is buffer alignment >>> - DWC2_USB_DMA_ALIGN=4 "works" because in my limited testcase (usb >>> 4g-dongle utilized via qmi-wwan) all transfers are unaligned. That is, >>> every urb->transfer_buffer is misaligned by 2 bytes == unaligned >>> - I can fix both issues and thus make the patch work on MIPS by >>> modifying it like this: >>> >>> -#define DWC2_USB_DMA_ALIGN 4 >>> +#define DWC2_USB_DMA_ALIGN dma_get_cache_alignment() >>> >>> struct dma_aligned_buffer { >>> void *old_xfer_buffer; >>> - u8 data[0]; >>> + u8 data[0] ____cacheline_aligned; >>> }; >>> >> >> Thanks for the additional testing. That means that the existing code >> is already broken, or am I missing something ? >> > > Yes, I believe the existing code is broken if 4 byte aligned transfers > occur. I seem to have no easy way to prove that though as none of my > devices generate those. > I did see this a lot when connecting USB drives. I'll re-test next week and provide more details. I do have some concern because I also saw transfers with URB_NO_TRANSFER_DMA_MAP set but transfer_buffer was not DMA aligned. However, it may well be that the provided DMA buffer _was_ aligned in that situation. I'll re-test that and let you know. Thanks, Guenter