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=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 4CC20C4BA24 for ; Thu, 27 Feb 2020 09:55:37 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1E96C222C2 for ; Thu, 27 Feb 2020 09:55:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="MwtBqEBC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1E96C222C2 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=UQrqV2cN86zLNoi7DgQrGGAKiFE4Y8feBu512n+htvY=; b=MwtBqEBCmZuf7K I1804N7YH7s4ox56ShqK9ai7o68/mPdeb8MLfvy9O+vgkG3lchcmaNE3Tx+3aS6YFixJAiVJq2JOC OeXnGWuw+r2xA2uBKicppyVEdNQ9YkeiIiy1wSYx86DV5yX7Vn5z6b3wBNCP1J6cG/nXXb1tSNWQq XpyOlAUPu5mzflvwlhKGtyBeBIY8BMGPEygw8l+FnUaz36HD+4kLaEmHq2nd9Jn2QFyet9g/6Z5j+ i+/fpxZmMDeBcxcBA33rEBmjAGqh1uV7NQeUAvS/abEHkjBEn5SZZGPU2271131wWq6dH0I9Pypdp 7dTYcQ2FpcUr2i/m7LRw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1j7FtB-0000yx-Vf; Thu, 27 Feb 2020 09:55:29 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1j7Ft8-0000yI-9V; Thu, 27 Feb 2020 09:55:27 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B70461FB; Thu, 27 Feb 2020 01:55:25 -0800 (PST) Received: from arrakis.emea.arm.com (arrakis.cambridge.arm.com [10.1.196.71]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4E7FB3F881; Thu, 27 Feb 2020 01:55:23 -0800 (PST) Date: Thu, 27 Feb 2020 09:55:21 +0000 From: Catalin Marinas To: Macpaul Lin Subject: Re: [PATCH v4] usb: gadget: f_fs: try to fix AIO issue under ARM 64 bit TAGGED mode Message-ID: <20200227095521.GA3281767@arrakis.emea.arm.com> References: <1582627315-21123-1-git-send-email-macpaul.lin@mediatek.com> <1582718512-28923-1-git-send-email-macpaul.lin@mediatek.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1582718512-28923-1-git-send-email-macpaul.lin@mediatek.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200227_015526_421408_D9B6A74F X-CRM114-Status: GOOD ( 21.90 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sasha Levin , Shen Jing , CC Hwang , Peter Chen , Mediatek WSD Upstream , Jerry Zhang , andreyknvl@google.com, linux-usb@vger.kernel.org, Loda Chou , linux-kernel@vger.kernel.org, stable@vger.kernel.org, Andrzej Pietrasiewicz , Miles Chen , John Stultz , Al Viro , Vincent Pelletier , Matthias Brugger , linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Feb 26, 2020 at 08:01:52PM +0800, Macpaul Lin wrote: > This issue was found when adbd trying to open functionfs with AIO mode. > Usually, we need to set "setprop sys.usb.ffs.aio_compat 0" to enable > adbd with AIO mode on Android. > > When adbd is opening functionfs, it will try to read 24 bytes at the > first read I/O control. If this reading has been failed, adbd will > try to send FUNCTIONFS_CLEAR_HALT to functionfs. When adbd is in AIO > mode, functionfs will be acted with asyncronized I/O path. After the > successful read transfer has been completed by gadget hardware, the > following series of functions will be called. > ffs_epfile_async_io_complete() -> ffs_user_copy_worker() -> > copy_to_iter() -> _copy_to_iter() -> copyout() -> > iterate_and_advance() -> iterate_iovec() > > Adding debug trace to these functions, it has been found that in > copyout(), access_ok() will check if the user space address is valid > to write. However if CONFIG_ARM64_TAGGED_ADDR_ABI is enabled, adbd > always passes user space address start with "0x3C" to gadget's AIO > blocks. This tagged address will cause access_ok() check always fail. > Which causes later calculation in iterate_iovec() turn zero. > Copyout() won't copy data to user space since the length to be copied > "v.iov_len" will be zero. Finally leads ffs_copy_to_iter() always return > -EFAULT, causes adbd cannot open functionfs and send > FUNCTIONFS_CLEAR_HALT. > > Signed-off-by: Macpaul Lin > Cc: Peter Chen > Cc: Catalin Marinas > Cc: Miles Chen > --- > Changes for v4: > - Abandon solution v3 by adding "TIF_TAGGED_ADDR" flag to gadget driver. > According to Catalin's suggestion, change the solution by untagging > user space address passed by AIO in gadget driver. Well, this was suggested in case you have a strong reason not to do the untagging in adbd. As I said, tagged pointers in user space were supported long before we introduced CONFIG_ARM64_TAGGED_ADDR_ABI. How did adb cope with such tagged pointers before? It was not supposed to pass them to the kernel. > diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c > index ce1d023..192935f 100644 > --- a/drivers/usb/gadget/function/f_fs.c > +++ b/drivers/usb/gadget/function/f_fs.c > @@ -715,7 +715,20 @@ static void ffs_epfile_io_complete(struct usb_ep *_ep, struct usb_request *req) > > static ssize_t ffs_copy_to_iter(void *data, int data_len, struct iov_iter *iter) > { > - ssize_t ret = copy_to_iter(data, data_len, iter); > + ssize_t ret; > + > +#if defined(CONFIG_ARM64) > + /* > + * Replace tagged address passed by user space application before > + * copying. > + */ > + if (IS_ENABLED(CONFIG_ARM64_TAGGED_ADDR_ABI) && > + (iter->type == ITER_IOVEC)) { > + *(unsigned long *)&iter->iov->iov_base = > + (unsigned long)untagged_addr(iter->iov->iov_base); > + } > +#endif > + ret = copy_to_iter(data, data_len, iter); Here you should probably drop all the #ifdefs and IS_ENABLED checks since untagged_addr() is defined globally as a no-op (and overridden by arm64 and sparc). Please don't send another patch until we understand (a) whether this is a user-space problem to fix or (b) if we fix it in the kernel, is this the only/right place? If we settle for the in-kernel untagging, do we explicitly untag the addresses in such kernel threads or we default to TIF_TAGGED_ADDR for all kernel threads, in case they ever call use_mm() (or we could even hook something in use_mm() to set this TIF flag temporarily). Looking for feedback from the Android folk and a better analysis of the possible solution. -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel