All of lore.kernel.org
 help / color / mirror / Atom feed
From: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
To: tsbogend@alpha.franken.de
Cc: jeff@garzik.org, linux-kernel@vger.kernel.org,
	jens.axboe@oracle.com, akpm@linux-foundation.org
Subject: Re: cdrom: use kmalloced buffers instead of buffers on stack
Date: Tue, 22 Apr 2008 20:47:01 +0900	[thread overview]
Message-ID: <20080422204637G.tomof@acm.org> (raw)
In-Reply-To: <20080422054857.GA5940@alpha.franken.de>

On Tue, 22 Apr 2008 07:48:58 +0200
tsbogend@alpha.franken.de (Thomas Bogendoerfer) wrote:

> On Mon, Apr 21, 2008 at 10:01:26PM -0400, Jeff Garzik wrote:
> > >    cdrom: use kmalloced buffers instead of buffers on stack
> > >    
> > >    If cdrom commands are issued to a scsi drive in most cases the buffer 
> > >    will be
> > >    filled via dma.  This leads to bad stack corruption on non coherent 
> > >    platforms,
> > >    because the buffers are neither cache line aligned nor is the size a 
> > >    multiple
> > >    of the cache line size.  Using kmalloced buffers avoids this.
> > >    
> > >    Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
> > >    Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
> > >---
> > > drivers/cdrom/cdrom.c |  274 
> > > ++++++++++++++++++++++++++++++++-----------------
> > > 1 files changed, 181 insertions(+), 93 deletions(-)
> > 
> > Eh... AFAICS this is only really useful in two of the cases converted.
> > 
> > For all the other cases (<= 32 bytes), it is _far_ less complex, far 
> > less code to simply communicate the additional alignment requirements to 
> > the compiler.
> > 
> > What about __attribute__ __aligned__?  Was that tried?
> 
> I used that while narrowing down the bug. But not only the alignment is
> important, but also size needs to be a multiple of the cache line size.
> Which means it needs to be 128 bytes for most SGI machines. That
> and the following in DMA-mapping.txt
> 
> "This rule also means that you may use neither kernel image addresses
> (items in data/text/bss segments), nor module image addresses, nor
> stack addresses for DMA."
> 
> let me choose the kmalloc() solution.

Can we advertise such architecture's dma restrictions? For example, if
we can update dma_pad_mask and dma_alignment in request_queue,
blk_rq_map_kern uses a proper bounce buffer for such
architectures. Then we can avoid putting extra complexity in uppper
drivers such as cdrom.c

  parent reply	other threads:[~2008-04-22 11:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <200804220100.m3M10sva024025@hera.kernel.org>
2008-04-22  2:01 ` cdrom: use kmalloced buffers instead of buffers on stack Jeff Garzik
2008-04-22  2:03   ` David Miller
2008-04-22  5:48   ` Thomas Bogendoerfer
2008-04-22  6:33     ` Jens Axboe
2008-04-22 11:47     ` FUJITA Tomonori [this message]
2008-04-22 11:55       ` Jens Axboe
2008-04-22 11:59         ` FUJITA Tomonori
2008-04-22 12:04           ` Jens Axboe
2008-04-22 12:25             ` FUJITA Tomonori
2008-04-22 12:30               ` Jens Axboe

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=20080422204637G.tomof@acm.org \
    --to=fujita.tomonori@lab.ntt.co.jp \
    --cc=akpm@linux-foundation.org \
    --cc=jeff@garzik.org \
    --cc=jens.axboe@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tsbogend@alpha.franken.de \
    /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.