All of lore.kernel.org
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: Shuah Khan <shuah.khan@hp.com>
Cc: fujita.tomonori@lab.ntt.co.jp, akpm@linux-foundation.org,
	paul.gortmaker@windriver.com, bhelgaas@google.com,
	amwang@redhat.com, LKML <linux-kernel@vger.kernel.org>,
	shuahkhan@gmail.com
Subject: Re: dma mapping error check analysis
Date: Fri, 17 Aug 2012 10:11:20 -0400	[thread overview]
Message-ID: <20120817141120.GD8093@phenom.dumpdata.com> (raw)
In-Reply-To: <1344638802.8018.18.camel@lorien2>

On Fri, Aug 10, 2012 at 04:46:42PM -0600, Shuah Khan wrote:
> I analyzed current calls to dma_map_single() and dma_map_page() in the kernel
> to see if dma mapping errors are checked after mapping routines return.
> 
> Reference linux-next August 6 2012.
> 
> This analysis stemmed from the discussion on my patch that disables swiotlb
> overflow as a first step towards removing the support all together. Please
> refer to thread below:
> 
> https://lkml.org/lkml/2012/7/24/391
> 
> The goal of this analysis is to find drivers that don't currently check dma
> mapping errors and fix them. I did a grep for dma_map_single() and
> dma_map_page() and looked at the code that calls these routines. I classified
> the results of dma mapping error check status as follows:
> 
> Broken:
> 1. No error checks
> 2. Partial checks - In that source file, not all calls are followed by checks.
> 3. Checks dma mapping errors, doesn't unmap already mapped pages when mapping
>    error occurs in the middle of a multiple mapping attempt.
> 
> The first two categories are classified as broken and need fixing.
> 
> The third one needs fixing, since it leaves dangling mapped pages, and holds
> on to them which is equivalent to memory leak. Some drivers release all mapped
> pages when the device closes, but others don't. Not doing unmap might be
> harmless on some architectures going by the comments I found in some source
> files.
> 
> Good:
> 1. Checks dma mapping errors and unmaps already mapped pages when mapping
>    error occurs in the middle of a multiple mapping attempt.
> 2. Checks dma mapping errors without unlikely()
> 3. Checks dma mapping errors with unlikely()
> 
> I lumped the above three cases as good cases. Using unlikely() is icing on the
> cake, and something we need to be concerned about compared to other problems in
> this area.
> 
> - dmap_map_single() - results
> No error checks - 195 (46%)
> Partial checks - 46 (11%)
> Doesn't unmap: 26 (6%)
> Good: 147 (35%)
> 
> - dma_map_page() - results
> No error checks: 61 (59%)
> Partial checks: 7 (.06%)
> Doesn't unmap: 15 (14.5%)
> Good: 20 (19%)
> 
> In summary a large % of the cases (> 50%) go unchecked. That raises the
> following questions:
> 
> When do mapping errors get detected?
> How often do these errors occur?
> Why don't we see failures related to missing dma mapping error checks?
> Are they silent failures?
> 
> Based on what I found, I am not too eager to remove swiotlb overflow support
> which would increase the probability of returning dma mapping errors.
> 
> However I propose the following to gather more information:
> 
> - Change swiotlb to log (pr_info or pr_debug) cases where overflow buffer is
>   triggered. (This is a delta on the disable swiotlb patch I sent a few weeks
>   ago - References in this posting).

As opposed to printk(KERN_ERR ? Why?

> - Change dma_map_single() and dma_map_page() to track how many times they
>   return before attempting to fix all the places that don't do dma mapping
>   error checks. (Maybe a counter that keeps track, pr_* is not an option).

Perhaps this should be done in the DMA debug API instead?

> 
> Comments, thoughts on the analysis and proposal are welcome.
> 
> -- Shuah

  reply	other threads:[~2012-08-17 14:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-10 22:46 dma mapping error check analysis Shuah Khan
2012-08-17 14:11 ` Konrad Rzeszutek Wilk [this message]
2012-08-17 18:02   ` Shuah Khan
2012-08-24 21:14 ` [PATCH] swiotlb: Add support to disable swiotlb overflow buffer with deprecation warning Shuah Khan
2012-08-25 18:25   ` Konrad Rzeszutek Wilk
2012-08-27 12:38     ` Shuah Khan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120817141120.GD8093@phenom.dumpdata.com \
    --to=konrad.wilk@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=amwang@redhat.com \
    --cc=bhelgaas@google.com \
    --cc=fujita.tomonori@lab.ntt.co.jp \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paul.gortmaker@windriver.com \
    --cc=shuah.khan@hp.com \
    --cc=shuahkhan@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.