Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1398952ybf; Sun, 1 Mar 2020 08:24:44 -0800 (PST) X-Google-Smtp-Source: ADFU+vtUyrA5/ZOzrXggoHrD06zVomLUhCSnqjb2snjApAFJljUchxYdpyEmFixDS5aQtzEAB5YJ X-Received: by 2002:aca:ad54:: with SMTP id w81mr1759826oie.172.1583079884729; Sun, 01 Mar 2020 08:24:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583079884; cv=none; d=google.com; s=arc-20160816; b=hjQw4v7erT0QgV61r6jpAQ4y/lAVBWgPGcek5WY8mWV7pIh7MocHT4uexcmakEQoxd OPAg+qkR8I34yL28rxTX/xtIN703t37+1eB3VL+B5nyf9xu7400gxgx+BXwf0NQn9Jkl ns0et5yXAncj0F51eA3HztT1vrbxQBGfGgb3tcMDxCJElHgYhJehc4D+v9Mhhj7EpV2I 38luhzbD/v7yELUUPiM8+x2i/jnBX1x3SwYEP8K5pvsjvdzKw/R3wrRkjpHbqCqyNETH yxB9VYL4ASeICdRagZkAtRFrq3fSSn9oZzXK4utJPH872+2mZ5YKtxcuFmjwP16nCYZM q6pg== 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=l75YHuHCJPf5NKCnDm87HGExQ9J1GGx9GGiE0t5xAbk=; b=kJOwGLI9A3SVQnqbFBjlngYvwgziZT0d1MlnkBs9AkPhrLvP95utIX4iGj2bOSvCku V122aemp3mt7mndz3sJrfxI3FTf/lN9DGERMXoLslOWar+sUSCLDY7ZHEJpS81BBjn5+ OTCiZ8GZ/RRDMbsYyO7NH5weLqS6LTY/nxUrxAYrRQt3TTCk4vcjkRlOs30W2fLO6WI2 iqijOwQw4gVnkVDpAeFwIhsgIH3bxu/hWrIWPSCQHxO7NmTPgOLnvEqfC+ygUgrJLb4l pp3qv5kBgZCWDwHqCuuJZtjVQgft0MIwnQWZnhq+iSNFK8nFhFy3yOlI1nCbzquQgke9 m1YQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=d+Bm1Mor; 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 l9si4841809oti.229.2020.03.01.08.24.32; Sun, 01 Mar 2020 08:24:44 -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=d+Bm1Mor; 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 S1726816AbgCAQYW (ORCPT + 99 others); Sun, 1 Mar 2020 11:24:22 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:41974 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726448AbgCAQYV (ORCPT ); Sun, 1 Mar 2020 11:24:21 -0500 Received: by mail-pg1-f194.google.com with SMTP id b1so4147483pgm.8; Sun, 01 Mar 2020 08:24:20 -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=l75YHuHCJPf5NKCnDm87HGExQ9J1GGx9GGiE0t5xAbk=; b=d+Bm1MorZjylipRacIUl+2VL5/L1ANg8064s0fc8D/CmdOrbrTijHYJCWTsQx0uFys 9pPtIn4M5cP8tH/whXEnCOBdcoh6S6tkLw74LOqZNOZirAJ97RZimkVSOUGWS0LgVlYT lnFlxwi85w2fps21LXI4O33VHsXErfDOV4yrKjum4uzjp/ISC8KlE0iPQBQD6PgG8m9A ymZBvS/2CTZOlw3qCVIpUeT/4Nqs4R6FoMHuE5y2kjt2hiHsA0z8RfUuS3nVJIm48CYT WmD0YeNyPg4r7skRsWbgXutG2wV372/wjFfqWyq+se8fqF2JyA9tJWXxkF+u3+RNFPVd e7Rg== 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=l75YHuHCJPf5NKCnDm87HGExQ9J1GGx9GGiE0t5xAbk=; b=MgQ5P5JRoQvpfFZixT+LlA26KS8jYLzZ5sMNyn2fPhumqDYZbekjs/WnZU1I7z4fjt GXqG6s8J/sbnDBcgqxpVAQurQ+i3IeVWKE7pd54sc/PlJs2jHjJW8KNCfr9b43+y1VtK BBfihPV8h3nLnXIMRZI3PDG82o7H2FV4clEgYIf9B2l2o5WVdkytA6gv9WgylF1TRuOZ rCzaAsTy0tjO7GeFOhY+xjSugqFn04FR5QrVJT0XSEHYV7joYAoV0i6wsEhmb9mxwQE3 xSlIJh6fg5//C9mkbgDRY93gxxIaxio65FjgK0P5gIC6gToS5kM5FeZwRk2c1dE7ZfVh d2sw== X-Gm-Message-State: APjAAAXuMGBpt5E5IxEQRn7R75bLtiw+05YawLS91nCPX6WPGQZjsvzE Nr2xwvhEv1za1LUZntl7Vu8= X-Received: by 2002:a62:e30f:: with SMTP id g15mr13785771pfh.124.1583079860264; Sun, 01 Mar 2020 08:24:20 -0800 (PST) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id hg11sm8758778pjb.14.2020.03.01.08.24.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 01 Mar 2020 08:24:19 -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> 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/W8Vk BIsJMaWOhks//7d92Uf3EArDlDShwR2+D+AMon8NULuLBHiEUQ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FOkynOs3pVbcbq1pxbhk3TRWCGRU5JolI4ohy/7JV1TVbjiDI HP/aVnm6NC8of26P40Pg8EdAhajZnHHjA7FrJXsy3cyIGqvg9os4rNkUWmrCfLLsZDHD8FnU mDW4+i+XlNFUPUYMrIKi9joBhu18ssf5i5Q= Message-ID: <28e29bb7-b536-dd0f-d410-f4add6b2a9ab@roeck-us.net> Date: Sun, 1 Mar 2020 08:24:18 -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 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 ? Updating DWC2_USB_DMA_ALIGN to dma_get_cache_alignment() was part of my initial fix, but then I abandoned it because I thought, well, the existing alignment works, so that can't be the problem. Anyway, using ____cacheline_aligned is an excellent idea. I'll make the changes suggested above for the next version of my series. Thanks, Guenter