From: Shuah Khan <shuah.khan@hp.com>
To: Konrad Rzeszutek Wilk <konrad@kernel.org>, akpm@linux-foundation.org
Cc: konrad.wilk@oracle.com, tglx@linutronix.de, mingo@redhat.com,
hpa@zytor.com, rob@landley.net, stern@rowland.harvard.edu,
joerg.roedel@amd.com, bhelgaas@google.com,
LKML <linux-kernel@vger.kernel.org>,
linux-doc@vger.kernel.org, devel@linuxdriverproject.org,
x86@kernel.org, shuahkhan@gmail.com
Subject: Re: [PATCH v3] dma-debug: New interfaces to debug dma mapping errors
Date: Thu, 04 Oct 2012 16:16:40 -0600 [thread overview]
Message-ID: <1349389000.2547.20.camel@lorien2> (raw)
In-Reply-To: <20121004140156.GG9158@phenom.dumpdata.com>
On Thu, 2012-10-04 at 10:01 -0400, Konrad Rzeszutek Wilk wrote:
> On Wed, Oct 03, 2012 at 02:45:11PM -0700, Andrew Morton wrote:
> > On Wed, 03 Oct 2012 08:55:59 -0600
> > Shuah Khan <shuah.khan@hp.com> wrote:
> >
> > > A recent dma mapping error analysis effort showed that a large percentage
> > > of dma_map_single() and dma_map_page() returns are not checked for mapping
> > > errors.
> > >
> > > Reference:
> > > http://linuxdriverproject.org/mediawiki/index.php/DMA_Mapping_Error_Analysis
> > >
> > > Adding support for tracking dma mapping and unmapping errors to help assess
> > > the following:
> > >
> > > When do dma 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?
> >
> > This seems to be a strange way of addressing kernel programming errors.
> > Instead of fixing them up, we generate lots of statistics about how
> > often they happen!
>
> And by using this we can fix the drivers.
Sorry I was out sick for a bit and catching up. Several drivers are
missing checks for mapping errors and in several cases in addition to
missing mapping error checks, drivers are not doing unmap as they
should. Is is very likely the result of cut and paste as you pointed
out. After the analysis, I realized it is worth while spending time to
provide debug infrastructure driver writers can use to find problems and
continue to use it when new mapping code gets added to an existing
driver and/or a new driver is written.
> >
> > Would it not be better to find and fix the buggy code sites? A
> > coccinelle script wold probably help here.
>
> That is the end goal (fixing the buggy code sites). Shuah has
> identified the bad culprits.
I compiled a list and documented it for review. We have to start fixing
them.
>
> >
> > And let's also look at *why* we keep doing this. Partly it's because
> > these things are self-propagating - people copy-n-paste bad code so we
> > get more bad code.
>
>
> And this patch will now tell the poor engineers that write new code that
> they pasted bad code.
>
> >
> >
> > Another reason surely is the poor documentation. Suppose our diligent
> > programmer goes to the dma_map_single() definition site:
> >
> > #define dma_map_single(d, a, s, r) dma_map_single_attrs(d, a, s, r, NULL)
> >
> > No documentation at all. Because it's a stupid macro it doesn't even
> > give the types and names of the arguments or the type of the return
> > value.
> >
> > So he goes to dma_map_single_attrs() and finds that is altogether
> > undocmented.
> >
> > So he goes into Documentation/DMA-API-HOWTO.txt, searches for
> > "dma_map_single" and finds
> >
> > : To map a single region, you do:
> > :
> > : struct device *dev = &my_dev->dev;
> > : dma_addr_t dma_handle;
> > : void *addr = buffer->ptr;
> > : size_t size = buffer->len;
> > :
> > : dma_handle = dma_map_single(dev, addr, size, direction);
> > :
> > : and to unmap it:
> > :
> > : dma_unmap_single(dev, dma_handle, size, direction);
> >
> >
> > So it is hardly surprising that we keep screwing this up!
>
> Right, so that should be also modified (Thank you for looking at that)!
>
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at http://vger.kernel.org/majordomo-info.html
> > Please read the FAQ at http://www.tux.org/lkml/
> >
next prev parent reply other threads:[~2012-10-04 22:16 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-17 0:52 [PATCH] dma-debug: New interfaces to debug dma mapping errors Shuah Khan
2012-09-17 2:07 ` Greg KH
2012-09-17 14:45 ` Shuah Khan
2012-09-17 15:25 ` Greg KH
2012-09-17 13:39 ` Konrad Rzeszutek Wilk
2012-09-17 15:52 ` Shuah Khan
2012-09-17 17:23 ` Konrad Rzeszutek Wilk
2012-09-17 22:45 ` Shuah Khan
2012-09-18 13:34 ` Joerg Roedel
2012-09-18 19:42 ` Shuah Khan
2012-09-18 19:45 ` Konrad Rzeszutek Wilk
2012-09-18 20:34 ` Shuah Khan
2012-09-19 13:08 ` Joerg Roedel
2012-09-19 19:16 ` Shuah Khan
2012-09-26 1:05 ` [PATCH v2] " Shuah Khan
2012-09-26 13:12 ` Konrad Rzeszutek Wilk
2012-09-26 16:23 ` Shuah Khan
2012-09-27 10:20 ` Joerg Roedel
2012-09-27 14:13 ` Shuah Khan
2012-10-03 14:55 ` [PATCH v3] " Shuah Khan
2012-10-03 21:45 ` Andrew Morton
2012-10-04 14:01 ` Konrad Rzeszutek Wilk
2012-10-04 22:16 ` Shuah Khan [this message]
2012-10-04 17:38 ` Konrad Rzeszutek Wilk
2012-10-04 22:19 ` Shuah Khan
2012-10-05 1:23 ` [PATCH v4] " Shuah Khan
2012-10-05 22:51 ` Andrew Morton
2012-10-08 17:07 ` Shuah Khan
2012-10-09 21:02 ` Andrew Morton
2012-10-10 21:50 ` 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=1349389000.2547.20.camel@lorien2 \
--to=shuah.khan@hp.com \
--cc=akpm@linux-foundation.org \
--cc=bhelgaas@google.com \
--cc=devel@linuxdriverproject.org \
--cc=hpa@zytor.com \
--cc=joerg.roedel@amd.com \
--cc=konrad.wilk@oracle.com \
--cc=konrad@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=rob@landley.net \
--cc=shuahkhan@gmail.com \
--cc=stern@rowland.harvard.edu \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).