From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964916AbdJQMFz (ORCPT ); Tue, 17 Oct 2017 08:05:55 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:37587 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753378AbdJQMFx (ORCPT ); Tue, 17 Oct 2017 08:05:53 -0400 X-AuditID: cbfec7f1-f793a6d00000326b-ac-59e5f21de0ab MIME-version: 1.0 Content-type: text/plain; charset="utf-8"; format="flowed" Subject: Re: [PATCH] xhci: Set DMA parameters appropriately To: Robin Murphy , mathias.nyman@intel.com, gregkh@linuxfoundation.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, hch@lst.de, iommu@lists.linux-foundation.org From: Marek Szyprowski Message-id: <913baa50-555c-eced-1bc4-3cb8ae47bdd0@samsung.com> Date: Tue, 17 Oct 2017 14:05:48 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 In-reply-to: <6b85dd6d-9728-e4f7-30f2-55d9f6f10372@arm.com> Content-transfer-encoding: 8bit Content-language: en-US X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprHKsWRmVeSWpSXmKPExsWy7djP87qyn55GGlxaoWnRvHg9m8XK1UeZ LBbst7a4vGsOm8WiZa3MFs2bprBaHPzwhNWB3WPNvDWMHov3vGTy2D93DbvH5BvLGT1232xg 8/i8SS6ALYrLJiU1J7MstUjfLoEr43RfE1PBNqmKNf8+MTYwvhPtYuTkkBAwkWhduJQVwhaT uHBvPVsXIxeHkMBSRonPexaxQDifGSXebbzCAtPxruUwVNUyRokjPffAErwCghI/JkPYzAJW Es/+tYKNFRJ4zigx9bILiC0sYC3RveodO4gtIhAnsfvBFCaI+myJB7u3MYPYbAKGEl1vu9gg ZtpJLHq/H8jm4GARUJX48iwWJCwqECOxevEOsFWcQ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PYkU Yk0sK67MPcQowcGsJMK769bTSCHelMTKqtSi/Pii0pzU4kOM0hwsSuK8vXtWRwoJpCeWpGan phakFsFkmTg4pRoYRdKrgy3kpS+8vbdYIobryONVu4N3Ci7lrvv/chPnk6jgWQbSXvqnL2wo ONe1o2fFt42GVUt+dU0T2/9F2bbe5m39xCnWyjODrh7i8Nheb3Ko//2xL3f0RfXFd7b+K/26 IPKpVJGbzvIPmx8/DetpTpw5L8P6ybXOX5/45qzis2L6aTSVld/ATomlOCPRUIu5qDgRAGlG 8reKAgAA X-CMS-MailID: 20171017120549eucas1p185bb108839beada14f4decd04c6886fb X-Msg-Generator: CA X-Sender-IP: 182.198.249.179 X-Local-Sender: =?UTF-8?B?TWFyZWsgU3p5cHJvd3NraRtTUlBPTC1LZXJuZWwgKFRQKRs=?= =?UTF-8?B?7IK87ISx7KCE7J6QG1NlbmlvciBTb2Z0d2FyZSBFbmdpbmVlcg==?= X-Global-Sender: =?UTF-8?B?TWFyZWsgU3p5cHJvd3NraRtTUlBPTC1LZXJuZWwgKFRQKRtT?= =?UTF-8?B?YW1zdW5nIEVsZWN0cm9uaWNzG1NlbmlvciBTb2Z0d2FyZSBFbmdpbmVlcg==?= X-Sender-Code: =?UTF-8?B?QzEwG0VIURtDMTBDRDAyQ0QwMjczOTI=?= CMS-TYPE: 201P X-CMS-RootMailID: 20171011135703epcas1p246932a3a94ed2f137c0187bdab883ad8 X-RootMTR: 20171011135703epcas1p246932a3a94ed2f137c0187bdab883ad8 References: <347776be09eb0ca947c1c8ced46ee3ca92d92e28.1507730115.git.robin.murphy@arm.com> <1cde45f2-cdd5-6210-dc00-49637132b897@samsung.com> <6b85dd6d-9728-e4f7-30f2-55d9f6f10372@arm.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Robin, On 2017-10-13 12:48, Robin Murphy wrote: > On 13/10/17 09:15, Marek Szyprowski wrote: >> On 2017-10-11 15:56, Robin Murphy wrote: >>> xHCI requires that data buffers do not cross 64KB boundaries (and are >>> thus at most 64KB long as well) - whilst xhci_queue_{bulk,isoc}_tx() >>> already split their input buffers into individual TRBs as necessary, >>> it's still a good idea to advertise the limitations via the standard DMA >>> API mechanism, so that most producers like the block layer and the DMA >>> mapping implementations can lay things out correctly to begin with. >>> >>> Signed-off-by: Robin Murphy >>> --- >>>   drivers/usb/host/xhci.c | 4 ++++ >>>   drivers/usb/host/xhci.h | 3 +++ >>>   2 files changed, 7 insertions(+) >>> >>> diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c >>> index 74b4500641c2..1e7e1e3d8c48 100644 >>> --- a/drivers/usb/host/xhci.c >>> +++ b/drivers/usb/host/xhci.c >>> @@ -4883,6 +4883,10 @@ int xhci_gen_setup(struct usb_hcd *hcd, >>> xhci_get_quirks_t get_quirks) >>>           dma_set_coherent_mask(dev, DMA_BIT_MASK(32)); >>>       } >>>   +    dev->dma_parms = &xhci->dma_parms; >>> +    dma_set_max_seg_size(dev, SZ_64K); >>> +    dma_set_seg_boundary(dev, SZ_64K - 1); >>> + >>>       xhci_dbg(xhci, "Calling HCD init\n"); >>>       /* Initialize HCD and host controller data structures. */ >>>       retval = xhci_init(hcd); >>> diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h >>> index 7ef69ea0b480..afcae4cc908d 100644 >>> --- a/drivers/usb/host/xhci.h >>> +++ b/drivers/usb/host/xhci.h >>> @@ -1767,6 +1767,9 @@ struct xhci_hcd { >>>       struct dma_pool    *small_streams_pool; >>>       struct dma_pool    *medium_streams_pool; >>>   +    /* DMA alignment restrictions */ >>> +    struct device_dma_parameters dma_parms; >>> + >>>       /* Host controller watchdog timer structures */ >>>       unsigned int        xhc_state; >>> >> Are you sure that xhci_hcd life time is proper to keep dma_parms? It looks >> that when driver gets removed and xhci_hcd is freed, the dma_parms will >> point to freed memory. Maybe it would make sense to clear dev->dma_parms >> somewhere or definitely change the way dma_parms are allocated? > AFAICS it lives until the last usb_put_hcd() call, which is pretty much > the last thing in the drivers' .remove paths, so it looks to follow the > standard paradigm evidenced by other dma_parms users. Any dangling > pointer after the driver has been unbound will be reinitialised by a > subsequent probe, and anyone using an unbound device for DMA API calls > is very wrong anyway. Okay. >> On the other hand 64K is the default segment size if no dma_parms are >> provided, so there is very little value added by this patch. > I prefer to explicitly set the segment size for cleanliness and to > emphasize the difference between "whatever the default value is is fine" > and "we have a real hardware limit of 64K". What really matters here > though is the non-default segment boundary mask - that's the motiviation > for the patch. Okay. What about other type of USB HCD (EHCI, OHCI, UHCI)? Best regards -- Marek Szyprowski, PhD Samsung R&D Institute Poland