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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF349C77B7D for ; Wed, 10 May 2023 15:41:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2F0196B0071; Wed, 10 May 2023 11:41:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2A0B56B0072; Wed, 10 May 2023 11:41:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 168006B0074; Wed, 10 May 2023 11:41:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 08EAA6B0071 for ; Wed, 10 May 2023 11:41:21 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D5FEF1C6A3D for ; Wed, 10 May 2023 15:41:20 +0000 (UTC) X-FDA: 80774759520.09.9D0759B Received: from azure-sdnproxy.icoremail.net (azure-sdnproxy.icoremail.net [52.229.205.26]) by imf21.hostedemail.com (Postfix) with ESMTP id 4C17B1C0009 for ; Wed, 10 May 2023 15:41:16 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=pku.edu.cn header.s=dkim header.b=AUAyj4Rh; spf=pass (imf21.hostedemail.com: domain of lrh2000@pku.edu.cn designates 52.229.205.26 as permitted sender) smtp.mailfrom=lrh2000@pku.edu.cn; dmarc=pass (policy=none) header.from=pku.edu.cn ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1683733277; a=rsa-sha256; cv=none; b=sF24MNRbp0/l228uZPk6uSwxkmpB2f1Td5K/xcz6PvpXbruN1Tuuw2Ky2aUIMKyfSdAcCp uTzxT71d9IT/Lh9MSrHWHsHpaxanzuQJSD8sCiFLknmx/kMddQw1jSL/v/SG0+9M1RfcEK XvEcjjLjtNVcVrqziElWUN2Qk35PGmU= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=pku.edu.cn header.s=dkim header.b=AUAyj4Rh; spf=pass (imf21.hostedemail.com: domain of lrh2000@pku.edu.cn designates 52.229.205.26 as permitted sender) smtp.mailfrom=lrh2000@pku.edu.cn; dmarc=pass (policy=none) header.from=pku.edu.cn ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1683733277; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=f2kwca3p5lvmK1UKkYNiCNtEhFHRgCfnV1Hv36vabJE=; b=xUtpML/wKFpy5G4+N7kRnixpMRJovB3meEXuco9rfowVBbYDhP6midTZ9kAyjKANBd3vnI BLGl6/IetoA1DsJWoK1w3qGGEHqCnLwj9jzRIFmG8Pi1ZzZlXz8PHX15bdDxTiCp30jxz+ V077tRC5lFLdrO5yxXEqSrO801FPJ+k= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pku.edu.cn; s=dkim; h=Received:Date:From:To:Cc:Subject: Message-ID:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; bh=f2kwca3p5lvmK1UKkYNiCNtEhFHR gCfnV1Hv36vabJE=; b=AUAyj4Rh8ryw5jfWK+eYdxwMtpGmL+2cMOMiHRSIKmRO Ux8B+3fGADgsT9+Y57nXL03gP7QhZ/Koli5PlZj447yjYLzMU4pazuL1FRvlYgWL D3bj89QLxyVciAJ05H3DVZ5Q+FwurbUdFHFVvztcxIUAjDbvB1hFuVX9ikdiTHc= Received: from localhost (unknown [10.7.101.92]) by front02 (Coremail) with SMTP id 54FpogCXbjgRu1tkSAlvEw--.9090S2; Wed, 10 May 2023 23:41:10 +0800 (CST) Date: Wed, 10 May 2023 23:41:05 +0800 From: Ruihan Li To: Alan Stern Cc: linux-mm@kvack.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Pasha Tatashin , David Hildenbrand , Matthew Wilcox , Andrew Morton , Christoph Hellwig , Greg Kroah-Hartman , stable@vger.kernel.org, Ruihan Li Subject: Re: [PATCH 2/4] usb: usbfs: Use consistent mmap functions Message-ID: References: <20230510085527.57953-1-lrh2000@pku.edu.cn> <20230510085527.57953-3-lrh2000@pku.edu.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-CM-TRANSID:54FpogCXbjgRu1tkSAlvEw--.9090S2 X-Coremail-Antispam: 1UD129KBjvJXoWxAr4fXFWUAry5Jr4xtF48Crg_yoW5Xw4xpF W8t3yjkF4YqFyI9r12van8WFyfGwn5KFyUGryIv3sxu3W3Xr1SkFySkFy5ZF12yr10qr1I vFWqyw13u3W5uFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBY1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s1l1IIY67AE w4v_Jr0_Jr4l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2 IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM28EF7xvwVC2 z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2vYz4IE04k24V AvwVAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xf McIj6xIIjxv20xvE14v26r106r15McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7 v_Jr0_Gr1lF7xvr2IY64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E 8cxan2IY04v7MxkIecxEwVCm-wCF04k20xvY0x0EwIxGrwCF04k20xvE74AGY7Cv6cx26w 4UJr1UMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCj r7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6x IIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAI w20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x 0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7VU1c4S5UUUUU== X-CM-SenderInfo: yssqiiarrvmko6sn3hxhgxhubq/1tbiAgEHBVPy772BUwAGsm X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 4C17B1C0009 X-Stat-Signature: wa85efs41tuu4ib7rmk89d1seice9td8 X-HE-Tag: 1683733276-628285 X-HE-Meta: U2FsdGVkX18Pp5O4foPNDj4LkNqKsD5b6V3tHzPuIvfSyAynOgo6Z7q7mwj9cVanfFes5GWmm0KzAYMZZ92U65C1TNapie86azo7wq/bYeWP4RZG/1frMQ3jYIf5+3h63xG0EzP3M6hgGDMhgOaxdfv4+Dks5F56wvDpikS1XjmeqRweARxoWiXtLhNkd6FCSG6T2OPNLoLEaovCN4xl3j+YUkBaQP/GEwlEqblFfdh5vZxDZj1Bs5BK4kuR5cdYdyhG3vcc8Ay9W0USnwFseAbrvWuYS/DAmtfCqLcUydgFupCHOdl/jOifLq4IY+/FriOeiAyeKm7lFA5ECr8wmEyBa4+pnoPHzPryG9UOb6G/yQyEvpEEEIlAgBpd+jYel1yCQN00SAE1tZceDxjGnu21tzN0hTBOKVjapjCA2k4R5tWt0atYE2V6Llv155yGmQ4pmzec18zQZpma/dNCVAF+FO386cWFglSrLTzUUsAGfXhbuBj8BXzjfMl5u5j4V/kf0fTX1+21z2q2w+4BlbCTIHxu3cLdHGbbBaJr6mlsp2w87ewyBjDtrU96ZFLLW45dDHWTZOvpaDmaA7y4gcPL9+GN1idBqY3mQe2LyXLS2t4WYI65b1fh+Fg9+VNwAXO8z0mEnKhaBWVX5DuKDuSL1PmNz2FoJEa5YYxDMMM/KMEOSXJ3fiHE/Yq8Afgl0K085ysoi4Expu13BSBb97QYGK3SNUlnHvRYm24itkSsuf5oRiZwCS+Pyk5hsXwY9Glu1Qth2xoOvYO82B36LbwqGczcuOf+V4mSjg9F2zD/Ip2k78W9169US9/RMn6VnBW75BDerCFCEKtDwKSdiw+hLjYGjm2KbOYx0fnZNOzJyAcs8FpseIapBH8JCpPlkYWDqlChxxl6vpJ+nb0HRMqdHdqud6Ak1lrnG4bMgx/253cB7p8WoPJo/+yQll38IlebH2c1aGXlSDjkJmN 2hFc9h1k K1LefQOM2V8sb4o4kjpRRQn9C8bk2EIWzA4wJoHExAC1sREh+WYXlqOnf/jyNy79Hw9dUFm5T7MzmXyfz/iS7zMgsRiyIm9zEW38QFxaTD5pwxJXcvwhdtjIi0sSvhM5dgqTmWCazJndt5KyrtPdNMrgpP/0Ws2dmD+sJldTX963LHx454WEAI29gGydaykW2pXwV X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hi Alan, On Wed, May 10, 2023 at 10:38:48AM -0400, Alan Stern wrote: > On Wed, May 10, 2023 at 04:55:25PM +0800, Ruihan Li wrote: > > When hcd->localmem_pool is non-null, it is used to allocate DMA memory. > > In this case, the dma address will be properly returned (in dma_handle), > > and dma_mmap_coherent should be used to map this memory into the user > > space. However, the current implementation uses pfn_remap_range, which > > is supposed to map normal pages (instead of DMA pages). > > > > Instead of repeating the logic in the memory allocation function, this > > patch introduces a more robust solution. To address the previous issue, > > this patch checks the type of allocated memory by testing whether > > dma_handle is properly set. If dma_handle is properly returned, it means > > some DMA pages are allocated and dma_mmap_coherent should be used to map > > them. Otherwise, normal pages are allocated and pfn_remap_range should > > be called. This ensures that the correct mmap functions are used > > consistently, independently with logic details that determine which type > > of memory gets allocated. > > > > Fixes: a0e710a7def4 ("USB: usbfs: fix mmap dma mismatch") > > Cc: stable@vger.kernel.org > > Signed-off-by: Ruihan Li > > --- > > drivers/usb/core/devio.c | 10 ++++++++-- > > 1 file changed, 8 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c > > index b4cf9e860..5067030b7 100644 > > --- a/drivers/usb/core/devio.c > > +++ b/drivers/usb/core/devio.c > > @@ -235,7 +235,7 @@ static int usbdev_mmap(struct file *file, struct vm_area_struct *vma) > > size_t size = vma->vm_end - vma->vm_start; > > void *mem; > > unsigned long flags; > > - dma_addr_t dma_handle; > > + dma_addr_t dma_handle = DMA_MAPPING_ERROR; > > int ret; > > > > ret = usbfs_increase_memory_usage(size + sizeof(struct usb_memory)); > > @@ -265,7 +265,13 @@ static int usbdev_mmap(struct file *file, struct vm_area_struct *vma) > > usbm->vma_use_count = 1; > > INIT_LIST_HEAD(&usbm->memlist); > > > > - if (hcd->localmem_pool || !hcd_uses_dma(hcd)) { > > + /* In DMA-unavailable cases, hcd_buffer_alloc_pages allocates > > + * normal pages and assigns DMA_MAPPING_ERROR to dma_handle. Check > > + * whether we are in such cases, and then use remap_pfn_range (or > > + * dma_mmap_coherent) to map normal (or DMA) pages into the user > > + * space, respectively. > > + */ > > Another stylistic issue. For multi-line comments, the format we use is: > > /* > * Blah, blah, blah > * Blah, blah, blah > */ > > Alan Stern Yeah, I am pretty sure it is another style difference with the net subsystem. Again, in the next version, I'll follow the coding style that you have pointed out. Thanks, Ruihan Li