From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 381BAC48BDF for ; Tue, 22 Jun 2021 10:12:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1B7D3613B2 for ; Tue, 22 Jun 2021 10:12:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229812AbhFVKPJ (ORCPT ); Tue, 22 Jun 2021 06:15:09 -0400 Received: from new4-smtp.messagingengine.com ([66.111.4.230]:57793 "EHLO new4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229612AbhFVKPI (ORCPT ); Tue, 22 Jun 2021 06:15:08 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailnew.nyi.internal (Postfix) with ESMTP id 947F35806DB; Tue, 22 Jun 2021 06:12:52 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Tue, 22 Jun 2021 06:12:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kroah.com; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm1; bh=pQtzM1DqFDdfzJczHbE0hVR7RaJ +DVrWztT+rRlCQh0=; b=YzHFOu2SxOl0BCAJy9jZozNGYJZ0wrl8O0jKdRapOvb KT3zjqk39Ymny9tI2CDMukLxeWkDtCcJqlcRTDTcGeVr1BSngaJEwCeB29nwpxIC yGuzvksRqr0yzcXk35nit/65T9VWhdDkdASeL+gspkvJoOa6IkWzb40RSGLhikK7 cO5YO0QbXXFKMRMoclll2kG4sTAULr//wrD2F6Th0zXocozQvADZ2jovNQa4BXVk m+nqZsVW90AS0H/oQI7qp8imm8YsSQ5zQrYIAMBVVwqzhTPNlcMN1kWbYcS2tqjL brQMvFwlX5th0/UT/qk/DRK03E7eMJNbNmlvmYN2SEQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=pQtzM1 DqFDdfzJczHbE0hVR7RaJ+DVrWztT+rRlCQh0=; b=kSixDL1BIp5Sj4eeF2VUnQ kBTRdHv/l7Tu8RpL7Iqpqx5KgWdTiwPDLn5ZL13eAcB8MSZM4hHOZK5Na2NznlMA ltIkJJBx9A+WfDXKf1lVmTB+srpRzXKohgvHwcbWlvPe43qpQ188z7AEqqIQM81t lUM9TMGCmV/2ZlTRG4TRENfR8ReQyw6f0oaGr1y/zMQ+UHfw8JU8ADnkBIZklXEK NPDw0W86KqXbPjjhegPy9PtcO/lyW6PDF/QpMSg4kqVKSOVikaxni8EeLRYXiQQy e9bkpsywCyK7kLZfk/l+G7Qu3EFzZQlQRNb2Ju0MnI4/F9v2/RMNvhmDqUUzBIyw == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfeeguddgvdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefirhgvghcu mffjuceoghhrvghgsehkrhhorghhrdgtohhmqeenucggtffrrghtthgvrhhnpeevueehje fgfffgiedvudekvdektdelleelgefhleejieeugeegveeuuddukedvteenucevlhhushht vghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehgrhgvgheskhhrohgrhh drtghomh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 22 Jun 2021 06:12:50 -0400 (EDT) Date: Tue, 22 Jun 2021 12:12:46 +0200 From: Greg KH To: David Laight Cc: 'Mauro Carvalho Chehab' , "linux-usb@vger.kernel.org" , "linuxarm@huawei.com" , "mauro.chehab@huawei.com" , Laurent Pinchart , Mauro Carvalho Chehab , "linux-kernel@vger.kernel.org" , "linux-media@vger.kernel.org" , "stable@vger.kernel.org" Subject: Re: [PATCH v3] media: uvc: don't do DMA on stack Message-ID: References: <6832dffafd54a6a95b287c4a1ef30250d6b9237a.1624282817.git.mchehab+huawei@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org On Tue, Jun 22, 2021 at 08:07:12AM +0000, David Laight wrote: > From: Mauro Carvalho Chehab > > Sent: 21 June 2021 14:40 > > > > As warned by smatch: > > drivers/media/usb/uvc/uvc_v4l2.c:911 uvc_ioctl_g_input() error: doing dma on the stack (&i) > > drivers/media/usb/uvc/uvc_v4l2.c:943 uvc_ioctl_s_input() error: doing dma on the stack (&i) > > > > those two functions call uvc_query_ctrl passing a pointer to > > a data at the DMA stack. those are used to send URBs via > > usb_control_msg(). Using DMA stack is not supported and should > > not work anymore on modern Linux versions. > > > > So, use a kmalloc'ed buffer. > ... > > + buf = kmalloc(1, GFP_KERNEL); > > + if (!buf) > > + return -ENOMEM; > > + > > ret = uvc_query_ctrl(chain->dev, UVC_GET_CUR, chain->selector->id, > > chain->dev->intfnum, UVC_SU_INPUT_SELECT_CONTROL, > > - &i, 1); > > + buf, 1); > > Thought... > > Is kmalloc(1, GFP_KERNEL) guaranteed to return a pointer into > a cache line that will not be accessed by any other code? > > (This is slightly weaker than requiring a cache-line aligned > pointer - but very similar.) > > Without that guarantee you can't use the returned buffer for > read dma unless the memory accesses are coherent. For USB buffers, that should be fine, we have been doing this for decades now... thanks, greg k-h