Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp763537yba; Wed, 15 May 2019 09:30:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqxc3lARrQt6lLqM7gml4fQAIX7vl11t1rARPXmWGyMIkihj3W+6nq9isCCTebnaLbJvHMaY X-Received: by 2002:aa7:8212:: with SMTP id k18mr47599459pfi.50.1557937844207; Wed, 15 May 2019 09:30:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557937844; cv=none; d=google.com; s=arc-20160816; b=ZqJyR4m4GnRRvYNqlVo168ummeFREpa7drbtt+Qy15l0pT5BWmw5BNKWd03J1TGDxh 0ZlJMejOj2sqPcwiMa0UOhzokyScS5g3RSlyEhelnishkYmNKpm+9pIXAyY23OJo8p02 6pCqTy6NN47xfKRF2kKEX0KPz0NtaDCAX+0vLy2Wa0c8QLL8XgwTzMxySFl+zFyzFAlB ZQysr62vwHSIqO9rj1A6GNGcZP43DhF3ktOQGeOcO2osgC/psnBAgQCHz/nCSyrN6YYs /y+HKrnTxHsII9sShsnQIB5AiMzMMaV9NObPcwcrs/zTGwylkBQtXPvD5eidNahhiN0Z TrOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=DlHR0MZOrOJNayVD0anwslNFUP/ZIvWEUuOkDFl+9uE=; b=kA11ofdC38WFfV+RMMKGYSFYwNoQohSRaI0x6WFZkVfpo0c9UTCxIku9SVYSxUae1E zdwNOF04N/5l+ZskYcqcT9q+ImI/HE/8GnhH2xeRHMPKxoBwBTr9UNMvxVqhzoFSlLDf skovjcl1ASjdF/idUK4P8Cgvh1tg+Vx3HIdcbPfIE/gUOCjq4VD5YIjZS7cGJokMjC6x J/AYHfTx0Fzq4cmKVfRHuwSM1bf8DlnmTG+mLDwTcoNb/sFyZ3TLVsV8USt+nAWTxxAg BYC2qRIwToSOqBNJ3v/eakTMz9LqBVmnOxIguJB4MupsHi6OR85qxRhx8+0ep/TAeGrw w2Mg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ce12si2234240plb.46.2019.05.15.09.30.29; Wed, 15 May 2019 09:30:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727305AbfEOQ3D (ORCPT + 99 others); Wed, 15 May 2019 12:29:03 -0400 Received: from ste-pvt-msa1.bahnhof.se ([213.80.101.70]:59389 "EHLO ste-pvt-msa1.bahnhof.se" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726283AbfEOQ3D (ORCPT ); Wed, 15 May 2019 12:29:03 -0400 Received: from localhost (localhost [127.0.0.1]) by ste-pvt-msa1.bahnhof.se (Postfix) with ESMTP id E5A0C3F9CD; Wed, 15 May 2019 18:28:59 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at bahnhof.se X-Spam-Flag: NO X-Spam-Score: -2.9 X-Spam-Level: X-Spam-Status: No, score=-2.9 tagged_above=-999 required=6.31 tests=[ALL_TRUSTED=-1, BAYES_00=-1.9] autolearn=ham autolearn_force=no Received: from ste-pvt-msa1.bahnhof.se ([127.0.0.1]) by localhost (ste-pvt-msa1.bahnhof.se [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id LKUIXh2AJKhb; Wed, 15 May 2019 18:28:59 +0200 (CEST) Received: from localhost (h-41-252.A163.priv.bahnhof.se [46.59.41.252]) (Authenticated sender: mb547485) by ste-pvt-msa1.bahnhof.se (Postfix) with ESMTPA id 181213F50A; Wed, 15 May 2019 18:28:58 +0200 (CEST) Date: Wed, 15 May 2019 18:28:58 +0200 From: Fredrik Noring To: Laurentiu Tudor Cc: Robin Murphy , "hch@lst.de" , "stern@rowland.harvard.edu" , "gregkh@linuxfoundation.org" , "linux-usb@vger.kernel.org" , "marex@denx.de" , "JuergenUrban@gmx.de" , Leo Li , "linux-kernel@vger.kernel.org" Subject: Re: [RFC PATCH v2 0/3] prerequisites for device reserved local mem rework Message-ID: <20190515162858.GB17162@sx9> References: <20190514143807.7745-1-laurentiu.tudor@nxp.com> <9d34015d-c219-179b-3141-4b0de3530ac3@arm.com> <20190514182931.GA2559@sx9> <0e5f3b86-7a80-eec7-691b-34a123194208@nxp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <0e5f3b86-7a80-eec7-691b-34a123194208@nxp.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Lauretniu, > I think that any recent kernel will do, so I'd say your current branch > should be fine. The kernel oopses with "unable to handle kernel paging request at virtual address 000aba0b" in hcd_alloc_coherent via usb_hcd_map_urb_for_dma. This relates to patch 2/3 that I didn't quite understand, where - retval = dma_declare_coherent_memory(dev, mem->start, - mem->start - mem->parent->start, - resource_size(mem)); becomes + retval = gen_pool_add_virt(hcd->localmem_pool, + (unsigned long)mem->start - + mem->parent->start, + mem->start, resource_size(mem), so that arguments two and three switch places. Given int dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr, dma_addr_t device_addr, size_t size); and int gen_pool_add_virt(struct gen_pool *pool, unsigned long virt, phys_addr_t phys size_t size, int nid) it seems that the device address (dma_addr_t device_addr) now becomes a virtual address (unsigned long virt). Is that intended? My corresponding patch is below for reference. I applied your 1/3 patch to test it. Fredrik diff --git a/drivers/usb/host/ohci-ps2.c b/drivers/usb/host/ohci-ps2.c --- a/drivers/usb/host/ohci-ps2.c +++ b/drivers/usb/host/ohci-ps2.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -92,12 +93,12 @@ static irqreturn_t ohci_ps2_irq(struct usb_hcd *hcd) return ohci_irq(hcd); /* Call normal IRQ handler. */ } -static int iopheap_alloc_coherent(struct platform_device *pdev, - size_t size, int flags) +static int iopheap_alloc_coherent(struct platform_device *pdev, size_t size) { struct device *dev = &pdev->dev; struct usb_hcd *hcd = platform_get_drvdata(pdev); struct ps2_hcd *ps2priv = hcd_to_priv(hcd); + int err; if (ps2priv->iop_dma_addr != 0) return 0; @@ -112,28 +113,37 @@ static int iopheap_alloc_coherent(struct platform_device *pdev, return -ENOMEM; } - if (dma_declare_coherent_memory(dev, - iop_bus_to_phys(ps2priv->iop_dma_addr), - ps2priv->iop_dma_addr, size, flags)) { - dev_err(dev, "dma_declare_coherent_memory failed\n"); - iop_free(ps2priv->iop_dma_addr); - ps2priv->iop_dma_addr = 0; - return -ENOMEM; + hcd->localmem_pool = devm_gen_pool_create(dev, + PAGE_SHIFT, dev_to_node(dev), DRV_NAME); + if (IS_ERR(hcd->localmem_pool)) { + err = PTR_ERR(hcd->localmem_pool); + goto out_err; + } + + err = gen_pool_add_virt(hcd->localmem_pool, ps2priv->iop_dma_addr, + iop_bus_to_phys(ps2priv->iop_dma_addr), size, dev_to_node(dev)); + if (err < 0) { + dev_err(dev, "gen_pool_add_virt failed with %d\n", err); + goto out_err; } return 0; + +out_err: + iop_free(ps2priv->iop_dma_addr); + ps2priv->iop_dma_addr = 0; + + return err; } static void iopheap_free_coherent(struct platform_device *pdev) { - struct device *dev = &pdev->dev; struct usb_hcd *hcd = platform_get_drvdata(pdev); struct ps2_hcd *ps2priv = hcd_to_priv(hcd); if (ps2priv->iop_dma_addr == 0) return; - dma_release_declared_memory(dev); iop_free(ps2priv->iop_dma_addr); ps2priv->iop_dma_addr = 0; } @@ -177,8 +187,7 @@ static int ohci_hcd_ps2_probe(struct platform_device *pdev) goto err; } - ret = iopheap_alloc_coherent(pdev, - DMA_BUFFER_SIZE, DMA_MEMORY_EXCLUSIVE); + ret = iopheap_alloc_coherent(pdev, DMA_BUFFER_SIZE); if (ret != 0) goto err_alloc_coherent;