Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp4840304rwj; Tue, 20 Dec 2022 16:03:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf5nsgeLQNHcfYDdTN22kBqvr7SVz2DFlYDzm1HYu3OchGZHSi6jmEbJEmAi2TKHT2TsV3oT X-Received: by 2002:a17:902:cf03:b0:186:8568:be7e with SMTP id i3-20020a170902cf0300b001868568be7emr61387212plg.15.1671581022152; Tue, 20 Dec 2022 16:03:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671581022; cv=none; d=google.com; s=arc-20160816; b=CDd8NPY37nGzXMxaoGO/hy9vdj/vl/nXHu9gF7/2zxx/AjKUpUBAqAbqzRM6iS5dzz ZhN0WCv/b32KwpVJmGbjq2egOqKK46zb27d/IURnJWFTeEmWNKg1cFM8C/jccX/ji47Q qaq+BMmNdqSI602Ze24bY4dG2DRWhFe4YLxqw6WQgfbm1K0rLp6EQOTbXMjPtSv6TIxz 25B8NWUr2wP9fZsS7g4dLr8Pz+pOJCkX9oKvCH469h3o5XGXiYyH/nhtRymNLnjQ4dmI p0CEDZY6jKD0jZhU1oW7AfcMmLKzUJsJl7irVTAzVhsHBu+MCyChdT4Vh80rVI3m6K6J GcqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=/lhPmtQgl/IJPDhv6NELGDuHRTBu3I0donBbwWDLdR0=; b=VJ/viRDhW6tRxuIjUSa23hfIMktCOEa6fhmlMS86kMVa5DRwOymF/0zOMuna0OGIMy HSPUdiD7YFt9tRkDvY1hZmrdfS3rXniw5ahbbDgtS8mVyYFDMzX/8CaCeO+ZJxXD5M1r P62zVHFE0VRl2MslZ2qBzMMmdIue1x0ZUww129yjzR7Ei7WcXt9JUo48GHt6bRVyRkoi 6phoZMgMLtdoZJ5YKcvHywYv5+nU4rvhWxpq6xXm9aMLwQOtpFlFs/zYzYzpbCJTtbki 12bvkYas/6fWeqRXpMg1KDNfOn0f2vf2dPsKV2nM4bxdaNw2DyvyRz1ZZ5wpnYZ3n33Q xvCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=D0hceBkT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p17-20020a170902f09100b001865c1ecf30si13603578pla.176.2022.12.20.16.03.30; Tue, 20 Dec 2022 16:03:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=D0hceBkT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234175AbiLTXGO (ORCPT + 68 others); Tue, 20 Dec 2022 18:06:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229756AbiLTXGN (ORCPT ); Tue, 20 Dec 2022 18:06:13 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82D043BF; Tue, 20 Dec 2022 15:06:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Sender:Reply-To:Content-ID:Content-Description; bh=/lhPmtQgl/IJPDhv6NELGDuHRTBu3I0donBbwWDLdR0=; b=D0hceBkT1mABNuA0N726RESH8f 7gs47AzhPRyEEjy3FokVywzS95ehk4c63TaIyJfuttSfJJRmrgLrnW3+p8GQD5Z8ljXYbuKPnuoCK Nvz8Z3zIB3dUVbygEvyiI9+sWoYRa+l16n6eplmcZfc+q8HlSwngOA5G5IHEEeW30rwkAO4jTY7fZ Rya+w2ZhdXTIcvfz+Y8fSmc+lLFlZF4Tx9oTgoinDQm2Z3qFV+IvBXOQjlWXgCi9HyYohUHT4q0tj Qpv+huA4Lri7C0GK/cQoIjuR9GzJZov7PIxbexSKiqEiN9AWGiyBKeiSnRbCyeU5R6PsMQds/WBg8 tH5FAMjw==; Received: from [2601:1c2:d80:3110::a2e7] by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1p7lgT-005ep6-0H; Tue, 20 Dec 2022 23:06:05 +0000 Message-ID: Date: Tue, 20 Dec 2022 15:06:02 -0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [PATCH] USB: Improve usb_fill_* documentation Content-Language: en-US To: Ricardo Ribalda , Greg Kroah-Hartman , Laurent Pinchart , Christoph Hellwig , Alan Stern Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org References: <20221220-usb-dmadoc-v1-0-28386d2eb6cd@chromium.org> From: Randy Dunlap In-Reply-To: <20221220-usb-dmadoc-v1-0-28386d2eb6cd@chromium.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/20/22 14:52, Ricardo Ribalda wrote: > Make the developer aware of the requirements of transfer buffer. > > The buffer must be DMAble, if the developer uses an invalid buffer, data > corruption might happen. > > Signed-off-by: Ricardo Ribalda > --- > USB: Improve usb_fill_* documentation > > After trying to "cleanup" the uvc code, I was patiently explained about > the requirements of the urb transfer buffers. > > Lets make this explicit, so other developers do not make the same mistake. > > To: Alan Stern > To: Christoph Hellwig > To: Laurent Pinchart > To: Greg Kroah-Hartman > Cc: linux-usb@vger.kernel.org > Cc: linux-kernel@vger.kernel.org > --- > include/linux/usb.h | 27 ++++++++++++++++++++++++--- > 1 file changed, 24 insertions(+), 3 deletions(-) > > diff --git a/include/linux/usb.h b/include/linux/usb.h > index 7d5325d47c45..033ca69b563d 100644 > --- a/include/linux/usb.h > +++ b/include/linux/usb.h > @@ -1627,13 +1627,20 @@ struct urb { > * @dev: pointer to the struct usb_device for this urb. > * @pipe: the endpoint pipe > * @setup_packet: pointer to the setup_packet buffer > - * @transfer_buffer: pointer to the transfer buffer > + * @transfer_buffer: pointer to the transfer buffer. Must be suitable for DMA. > * @buffer_length: length of the transfer buffer > * @complete_fn: pointer to the usb_complete_t function > * @context: what to set the urb context to. > * > * Initializes a control urb with the proper information needed to submit > * it to a device. > + * > + * The transfer buffer might be filled via DMA. The simplest way to get > + * a buffer that can be DMAed to, is allocatiing it via kmalloc() or allocating > + * equivalent, even for very small buffers. If transfer_buffer is embedded > + * in a bigger structure, there is a risk that the previous and following > + * fields are left in a corrupted state by the DMA engine, if the platform > + * is not cache coherent. > */ > static inline void usb_fill_control_urb(struct urb *urb, > struct usb_device *dev, > @@ -1658,13 +1665,20 @@ static inline void usb_fill_control_urb(struct urb *urb, > * @urb: pointer to the urb to initialize. > * @dev: pointer to the struct usb_device for this urb. > * @pipe: the endpoint pipe > - * @transfer_buffer: pointer to the transfer buffer > + * @transfer_buffer: pointer to the transfer buffer. Must be suitable for DMA. > * @buffer_length: length of the transfer buffer > * @complete_fn: pointer to the usb_complete_t function > * @context: what to set the urb context to. > * > * Initializes a bulk urb with the proper information needed to submit it > * to a device. > + * > + * The transfer buffer might be filled via DMA. The simplest way to get > + * a buffer that can be DMAed to, is allocatiing it via kmalloc() or allocating > + * equivalent, even for very small buffers. If transfer_buffer is embedded > + * in a bigger structure, there is a risk that the previous and following > + * fields are left in a corrupted state by the DMA engine, if the platform > + * is not cache coherent. > */ > static inline void usb_fill_bulk_urb(struct urb *urb, > struct usb_device *dev, > @@ -1687,7 +1701,7 @@ static inline void usb_fill_bulk_urb(struct urb *urb, > * @urb: pointer to the urb to initialize. > * @dev: pointer to the struct usb_device for this urb. > * @pipe: the endpoint pipe > - * @transfer_buffer: pointer to the transfer buffer > + * @transfer_buffer: pointer to the transfer buffer. Must be suitable for DMA. > * @buffer_length: length of the transfer buffer > * @complete_fn: pointer to the usb_complete_t function > * @context: what to set the urb context to. > @@ -1697,6 +1711,13 @@ static inline void usb_fill_bulk_urb(struct urb *urb, > * Initializes a interrupt urb with the proper information needed to submit > * it to a device. > * > + * The transfer buffer might be filled via DMA. The simplest way to get > + * a buffer that can be DMAed to, is allocatiing it via kmalloc() or allocating > + * equivalent, even for very small buffers. If transfer_buffer is embedded > + * in a bigger structure, there is a risk that the previous and following > + * fields are left in a corrupted state by the DMA engine, if the platform > + * is not cache coherent. > + * > * Note that High Speed and SuperSpeed(+) interrupt endpoints use a logarithmic > * encoding of the endpoint interval, and express polling intervals in > * microframes (eight per millisecond) rather than in frames (one per > > --- > base-commit: b6bb9676f2165d518b35ba3bea5f1fcfc0d969bf > change-id: 20221220-usb-dmadoc-29384acebd48 > > Best regards, Thanks. -- ~Randy