Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1372382imm; Tue, 3 Jul 2018 09:59:30 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKGTss2xgH9Xb2mtTZ9xa9k50EjTi48dzqZB4v4wuwHFm/r3Ya5d+QP9dHYbg+aY71huM2b X-Received: by 2002:a63:85c8:: with SMTP id u191-v6mr26218504pgd.36.1530637170174; Tue, 03 Jul 2018 09:59:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530637170; cv=none; d=google.com; s=arc-20160816; b=nSZd14gnxjtCjOAwgbeMZgINEGVyGuekrxEbesEx5A4/f/pgO9bE20qCk0dUY15BZ+ i2W3X5Hg83IXvTkbVwXgWKWUS8npuGXspMiBo7w8M8dyCqCbG7qes3XN3b0bPz0Fu5r3 OGFzdMeAhguynYflnJ42I0Op5i/w0RXpnD683MzShWqExUsqC022HFM1BxVSQEO+b0eO uLwJz9ldi01EjwLuEqf0qSz7amHbRpFpmO1IT6CiyoBGwOKCMSUt7KiIGwQTlSt81Brw jDXoyc7V9ip3mvpSGiM5ISzocj2PAlXyu6TjUoTQIrrh9Z5Kv/KfBlXy3x/T9f/EqFI/ BBsg== 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:arc-authentication-results; bh=nGDu7yBtWKRj1lp/2nn0Xddy2IyjxDR0tFQ64Uq+jiw=; b=B4FKkej7gB+pmpc93j31iR67AE5gXXRqsy8mxIV83I/krJkAyHqVaepEyqGKxhMGOv 0dMxEqJOt8Omd1nghEfjGWVnevV1TfZZpofnHS//FNwC48Vu2NrOujBarTmNB5BgNbXX 1waVC8ansUHVYcnAHyK8Vx8/AV1wUAwvBzV56qfoWT41uQp4kvRlXwItSHbkr0ZLrZKq bf5y13tUT2t5+2zHuJifvE/U4LwJNJtT7NnjKRRWD9d8aSdd2xTXXjafWnJBc5Dw0ftQ 2akRPxoBwGWizK3p9HUFUBCcbWbBxveuJ9gZ5/DF8oEU29czzYwBRZlwYtg1HLzf3/4E lv/g== 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 17-v6si1515410pfn.37.2018.07.03.09.59.15; Tue, 03 Jul 2018 09:59:30 -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 S934052AbeGCQ5c (ORCPT + 99 others); Tue, 3 Jul 2018 12:57:32 -0400 Received: from pio-pvt-msa2.bahnhof.se ([79.136.2.41]:51788 "EHLO pio-pvt-msa2.bahnhof.se" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932410AbeGCQ5b (ORCPT ); Tue, 3 Jul 2018 12:57:31 -0400 X-Greylist: delayed 566 seconds by postgrey-1.27 at vger.kernel.org; Tue, 03 Jul 2018 12:57:31 EDT Received: from localhost (localhost [127.0.0.1]) by pio-pvt-msa2.bahnhof.se (Postfix) with ESMTP id D03303FA3E; Tue, 3 Jul 2018 18:48:03 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at bahnhof.se Received: from pio-pvt-msa2.bahnhof.se ([127.0.0.1]) by localhost (pio-pvt-msa2.bahnhof.se [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1hiKflV9wt_7; Tue, 3 Jul 2018 18:47:58 +0200 (CEST) Received: from localhost.localdomain (h-155-4-135-114.NA.cust.bahnhof.se [155.4.135.114]) (Authenticated sender: mb547485) by pio-pvt-msa2.bahnhof.se (Postfix) with ESMTPA id 453443F935; Tue, 3 Jul 2018 18:47:54 +0200 (CEST) Date: Tue, 3 Jul 2018 18:47:51 +0200 From: Fredrik Noring To: Robin Murphy Cc: hch@lst.de, m.szyprowski@samsung.com, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, JuergenUrban@gmx.de, "Maciej W. Rozycki" Subject: Re: [PATCH] dma-mapping: Relax warnings for per-device areas Message-ID: <20180703164750.GB17378@localhost.localdomain> References: <1f8262d206c6886072d04cc93454f6e3f812bd20.1530623284.git.robin.murphy@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1f8262d206c6886072d04cc93454f6e3f812bd20.1530623284.git.robin.murphy@arm.com> User-Agent: Mutt/1.9.1 (2017-09-22) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thank you Robin, On Tue, Jul 03, 2018 at 02:08:30PM +0100, Robin Murphy wrote: > The reasons why dma_free_attrs() should not be called from IRQ context > are not necessarily obvious and somewhat buried in the development > history, so let's start by documenting the warning itself to help anyone > who does happen to hit it and wonder what the deal is. > > However, this check turns out to be slightly over-restrictive for the > way that per-device memory has been spliced into the general API, since > for that case we know that dma_declare_coherent_memory() has created an > appropriate CPU mapping for the entire area and nothing dynamic should > be happening. Given that the usage model for per-device memory is often > more akin to streaming DMA than 'real' coherent DMA (e.g. allocating and > freeing space to copy short-lived packets in and out), it is also > somewhat more reasonable for those operations to happen in IRQ handlers > for such devices. > > A somewhat similar line of reasoning also applies at the other end for > the mask check in dma_alloc_attrs() too - indeed, a device which cannot > access anything other than its own local memory probably *shouldn't* > have a valid mask for the general coherent DMA API. > > Therefore, let's move the per-device area hooks up ahead of the assorted > checks, so that they get a chance to resolve the request before we get > as far as definite "you're doing it wrong" territory. I have tested this patch and it corrects both problems with the PS2 OHCI driver. I believe there is a fair chance that drivers/usb/host/ohci-sm501.c and drivers/usb/host/ohci-tmio.c are fixed as well, since they are similar. Tested-by: Fredrik Noring Fredrik > Reported-by: Fredrik Noring > Signed-off-by: Robin Murphy > --- > include/linux/dma-mapping.h | 19 +++++++++++++------ > 1 file changed, 13 insertions(+), 6 deletions(-) > > diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h > index f9cc309507d9..ffeca3ab59c0 100644 > --- a/include/linux/dma-mapping.h > +++ b/include/linux/dma-mapping.h > @@ -512,12 +512,12 @@ static inline void *dma_alloc_attrs(struct device *dev, size_t size, > const struct dma_map_ops *ops = get_dma_ops(dev); > void *cpu_addr; > > - BUG_ON(!ops); > - WARN_ON_ONCE(dev && !dev->coherent_dma_mask); > - > if (dma_alloc_from_dev_coherent(dev, size, dma_handle, &cpu_addr)) > return cpu_addr; > > + BUG_ON(!ops); > + WARN_ON_ONCE(dev && !dev->coherent_dma_mask); > + > /* let the implementation decide on the zone to allocate from: */ > flag &= ~(__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM); > > @@ -537,12 +537,19 @@ static inline void dma_free_attrs(struct device *dev, size_t size, > { > const struct dma_map_ops *ops = get_dma_ops(dev); > > - BUG_ON(!ops); > - WARN_ON(irqs_disabled()); > - > if (dma_release_from_dev_coherent(dev, get_order(size), cpu_addr)) > return; > > + BUG_ON(!ops); > + /* > + * On non-coherent platforms which implement DMA-coherent buffers via > + * non-cacheable remaps, ops->free() may call vunmap(). Thus arriving > + * here in IRQ context is a) at risk of a BUG_ON() or trying to sleep > + * on some machines, and b) an indication that the driver is probably > + * misusing the coherent API anyway. > + */ > + WARN_ON(irqs_disabled()); > + > if (!ops->free || !cpu_addr) > return; > > -- > 2.17.1.dirty >