Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1417023ybf; Sun, 1 Mar 2020 08:52:56 -0800 (PST) X-Google-Smtp-Source: APXvYqyXhPSPVuFhthowRxg/EFkEQgW2ZtBhCmmI6QWjHCg9WYRH0vZc/FAb4xwH0I7wVGllxR8J X-Received: by 2002:a9d:64d8:: with SMTP id n24mr9681140otl.71.1583081576801; Sun, 01 Mar 2020 08:52:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583081576; cv=none; d=google.com; s=arc-20160816; b=LqM5AnvHeUHMvFKDzQaKQ1KVCzMLvpibdLY8ZqRZr5uWo4dUg4IsGnLz3tgTyQiprQ U0qC53UhyWOjgwdVh3AyzaMDwkp7sLliJnR0yCyNFbsKEGqUXh3n7DWLFcfqhVO1nEvX VIAq3VJQ2+wklcOhqJvfHi76ObiHR4bKhYjv93Xh9k2QWhxHEym0qBCnP6bmgzwxYVsv 4+F9eo08smTmjRX9srVwYFSAvHkH0rBWLdvnUXDHzlBSl1pR30wdKkOteNpvQ3kGphQr tcS0bE2vcvjQTqVd8ZzMxJ9UsLQvefFsf8v6/GWCC1d6ghF+jXF4gb5y+Z7IEDrsf2+h ZFjA== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=LwKzNUI6J0auIJ5BlaThpyOtWbiBMINS20BDjkZqn68=; b=Pm/akt64idaLHpXFuot/mNpXej3f8LxUGE7e6BuCYq2/WAaqRMBAfk5cQETKjF8l/y hu4w84+/KZJ+FFDjuwreKSWEDyDJSTsEIrpaAu/TsUfus53C8MqoOgu29DKeO9D0Bt4B yVKtOS92UGR0opj2UM4c5Dw1DkkHLTOYqf8lyagWXnExx6te11WxGe7jXsbRReLEtE6b KKLsx8gfSq6WknKMlWszW7OdhKiZmHMuhehoA8N3xF4zuWCvwkKVmtZNC2Ey5r1y5+n1 /RfaAI442Ky9nWZkgeork6YJIsEk9vLakyx1ELLEqIWBv92sVsBtjKnB5xk83aSOFLsN JJIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=YEleoFK1; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 24si4579822oiq.162.2020.03.01.08.52.40; Sun, 01 Mar 2020 08:52:56 -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=pass header.i=@gmail.com header.s=20161025 header.b=YEleoFK1; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726536AbgCAQwe (ORCPT + 99 others); Sun, 1 Mar 2020 11:52:34 -0500 Received: from mail-io1-f67.google.com ([209.85.166.67]:38139 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726204AbgCAQwe (ORCPT ); Sun, 1 Mar 2020 11:52:34 -0500 Received: by mail-io1-f67.google.com with SMTP id s24so8962616iog.5; Sun, 01 Mar 2020 08:52:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=LwKzNUI6J0auIJ5BlaThpyOtWbiBMINS20BDjkZqn68=; b=YEleoFK19OCp6RJkkVCvc2R2r4JjO+s54QzexWKkW+eRs7qRf6BzXyVyVbWBX432DW bauQ9+Wf0IP9DUm023ovyON1Up7H5SjQTOHCz33zjgHsmU/+npfQuFrgTJv61WnbpDpA BkXevIkLcmHNDs/cG1zaCZZ/SPEq6QODO9WH4E5nFau5gN7uq+laqgGzROL7DnwgNwVL h61SSIKwl5h3A7/gRwVu9Dfp5c17Ug5ZlSQ6i8wPJrWudPB/inTrFrrL0lKCmVpePW51 dTyTG2s3wm22FmLoFRb4lwQ1NtflvrsPoyLpTBEo9D8HEM2VgC5RVmIIt9vXHsW2sEP8 IwiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=LwKzNUI6J0auIJ5BlaThpyOtWbiBMINS20BDjkZqn68=; b=UG4RNMTxN09aL8nnQMiQoSa96ryskedOH8CIACvIqE6ztiIe9Tpu2GWk8cmZCA79/d MrjmQ64RmnfO7grd6geQslxoBF9b4Zf+OKxXFVDpsDnX+Y7r2jonwiWq2FZjj+xuCafN fG1zzdoaQDoD/0NKaAWkW2ofDZT1DtarmtCbFS+7cqaQpxcjOEx2nTdeMECvMXeczb90 GMHgvEDCv+RmJokavLSVZ2OHF0v8J0uwNhRN/tMeUyFF5UL7F453e2eQIPjzMjhFe8r/ eizNHXhaRT03kK4Z57JjUmfwDBDFK1wy7sfqnPffLGf2USjxrHrK71FLKM/kioP6JfN8 CeBg== X-Gm-Message-State: APjAAAUbiGSYeRTL8Of22OUSg2WpNLj28g1CFP+oW7GyTHDFEARHTWqp xzbIyGN+cWx3bkTO+iF/Kqbdr3ztpE9HKxRv+f4= X-Received: by 2002:a6b:b642:: with SMTP id g63mr10002372iof.122.1583081552244; Sun, 01 Mar 2020 08:52:32 -0800 (PST) MIME-Version: 1.0 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> In-Reply-To: <28e29bb7-b536-dd0f-d410-f4add6b2a9ab@roeck-us.net> From: =?UTF-8?B?QW50dGkgU2VwcMOkbMOk?= Date: Sun, 1 Mar 2020 18:51:55 +0200 Message-ID: Subject: Re: [RFT PATCH 1/4] usb: dwc2: Simplify and fix DMA alignment code To: Guenter Roeck Cc: Doug Anderson , Minas Harutyunyan , Greg Kroah-Hartman , Boris ARZUR , linux-usb@vger.kernel.org, LKML , Felipe Balbi , Stefan Wahren , Martin Schiller Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 1 Mar 2020 at 18:24, Guenter Roeck wrote: > > Hi Antti, > > On 3/1/20 7:51 AM, Antti Sepp=C3=A4l=C3=A4 wrote: > > On Sat, 29 Feb 2020 at 18:33, Antti Sepp=C3=A4l=C3=A4 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 a= ligned > >>> to the DMA cache line size on that system. In the latter case, the qu= estion > >>> is why the alignment to DWC2_USB_DMA_ALIGN (=3D4) works. In the forme= r case, > >>> question would be why the realignment does any good in the first plac= e. > >>> > >>> Any chance you can add some test code to help figuring out what exact= ly > >>> 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=3D4 "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 =3D=3D 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. > 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. > Great. In the meanwhile I'll continue testing and will report back if I find anything new. --=20 Antti