* [PATCH] ppc highmem fix
@ 2005-10-10 23:20 Paolo Galtieri
2005-10-10 23:38 ` Paolo Galtieri
0 siblings, 1 reply; 3+ messages in thread
From: Paolo Galtieri @ 2005-10-10 23:20 UTC (permalink / raw)
To: Linux Kernel
I've noticed that the calculations for seg_size and nr_segs in
__dma_sync_page_highmem() (arch/ppc/kernel/dma-mapping.c) are wrong.
The incorrect calculations can result in either an oops or a panic when
running fsck depending on the size of the partition. The problem with
the
seg_size calculation is that it can result in a negative number if size
is offset > size. The problem with the nr_segs caculation is returns
the
wrong number of segments, e.g. it returns 1 when size is 200 and offset
is 4095, when it should return 2 or more.
Here is the patch to fix the problem.
--- linux-2.6.14-rc3-git8/arch/ppc/kernel/dma-mapping.c 2005-10-10
13:55:37.000000000 -0700
+++ linux-2.6.14/arch/ppc/kernel/dma-mapping.c 2005-10-10
13:57:51.000000000 -0700
@@ -401,10 +401,10 @@
static inline void __dma_sync_page_highmem(struct page *page,
unsigned long offset, size_t size, int direction)
{
- size_t seg_size = min((size_t)PAGE_SIZE, size) - offset;
+ size_t seg_size = min((size_t)(PAGE_SIZE - offset), size);
size_t cur_size = seg_size;
unsigned long flags, start, seg_offset = offset;
- int nr_segs = PAGE_ALIGN(size + (PAGE_SIZE - offset))/PAGE_SIZE;
+ int nr_segs = 1 + ((size - seg_size) + PAGE_SIZE - 1)/PAGE_SIZE;
int seg_nr = 0;
local_irq_save(flags);
Paolo Galtieri (pgaltieri@mvista.com)
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] ppc highmem fix 2005-10-10 23:20 [PATCH] ppc highmem fix Paolo Galtieri @ 2005-10-10 23:38 ` Paolo Galtieri 2005-10-11 9:38 ` Benjamin Herrenschmidt 0 siblings, 1 reply; 3+ messages in thread From: Paolo Galtieri @ 2005-10-10 23:38 UTC (permalink / raw) To: Linux Kernel On Mon, 2005-10-10 at 16:20 -0700, Paolo Galtieri wrote: > I've noticed that the calculations for seg_size and nr_segs in > __dma_sync_page_highmem() (arch/ppc/kernel/dma-mapping.c) are wrong. > The incorrect calculations can result in either an oops or a panic when > running fsck depending on the size of the partition. The problem with > the > seg_size calculation is that it can result in a negative number if size > is offset > size. The problem with the nr_segs caculation is returns > the > wrong number of segments, e.g. it returns 1 when size is 200 and offset > is 4095, when it should return 2 or more. > > Here is the patch to fix the problem. > > --- linux-2.6.14-rc3-git8/arch/ppc/kernel/dma-mapping.c 2005-10-10 > 13:55:37.000000000 -0700 > +++ linux-2.6.14/arch/ppc/kernel/dma-mapping.c 2005-10-10 > 13:57:51.000000000 -0700 > @@ -401,10 +401,10 @@ > static inline void __dma_sync_page_highmem(struct page *page, > unsigned long offset, size_t size, int direction) > { > - size_t seg_size = min((size_t)PAGE_SIZE, size) - offset; > + size_t seg_size = min((size_t)(PAGE_SIZE - offset), size); > size_t cur_size = seg_size; > unsigned long flags, start, seg_offset = offset; > - int nr_segs = PAGE_ALIGN(size + (PAGE_SIZE - offset))/PAGE_SIZE; > + int nr_segs = 1 + ((size - seg_size) + PAGE_SIZE - 1)/PAGE_SIZE; > int seg_nr = 0; > > local_irq_save(flags); > > > Paolo Galtieri (pgaltieri@mvista.com) > I want to apologize in advance for the previous post. When I included the patch inline I dropped the tabs :-(. Here is the correct patch with tabs: --- linux-2.6.14-rc3-git8/arch/ppc/kernel/dma-mapping.c 2005-10-10 13:55:37.000000000 -0700 +++ linux-2.6.14/arch/ppc/kernel/dma-mapping.c 2005-10-10 13:57:51.000000000 -0700 @@ -401,10 +401,10 @@ static inline void __dma_sync_page_highmem(struct page *page, unsigned long offset, size_t size, int direction) { - size_t seg_size = min((size_t)PAGE_SIZE, size) - offset; + size_t seg_size = min((size_t)(PAGE_SIZE - offset), size); size_t cur_size = seg_size; unsigned long flags, start, seg_offset = offset; - int nr_segs = PAGE_ALIGN(size + (PAGE_SIZE - offset))/PAGE_SIZE; + int nr_segs = 1 + ((size - seg_size) + PAGE_SIZE - 1)/PAGE_SIZE; int seg_nr = 0; local_irq_save(flags); Paolo ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ppc highmem fix 2005-10-10 23:38 ` Paolo Galtieri @ 2005-10-11 9:38 ` Benjamin Herrenschmidt 0 siblings, 0 replies; 3+ messages in thread From: Benjamin Herrenschmidt @ 2005-10-11 9:38 UTC (permalink / raw) To: Paolo Galtieri; +Cc: Linus Torvalds, Andrew Morton, Linux Kernel On Mon, 2005-10-10 at 16:38 -0700, Paolo Galtieri wrote: > On Mon, 2005-10-10 at 16:20 -0700, Paolo Galtieri wrote: > > I've noticed that the calculations for seg_size and nr_segs in > > __dma_sync_page_highmem() (arch/ppc/kernel/dma-mapping.c) are wrong. > > The incorrect calculations can result in either an oops or a panic when > > running fsck depending on the size of the partition. The problem with > > the > > seg_size calculation is that it can result in a negative number if size > > is offset > size. The problem with the nr_segs caculation is returns > > the > > wrong number of segments, e.g. it returns 1 when size is 200 and offset > > is 4095, when it should return 2 or more. > > > > Here is the patch to fix the problem. Looks good, should probably still make it to 2.6.14, Andrew, Linus ? (Paolo, can you send them a clean patch ?) Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org> > > --- linux-2.6.14-rc3-git8/arch/ppc/kernel/dma-mapping.c 2005-10-10 > > 13:55:37.000000000 -0700 > > +++ linux-2.6.14/arch/ppc/kernel/dma-mapping.c 2005-10-10 > > 13:57:51.000000000 -0700 > > @@ -401,10 +401,10 @@ > > static inline void __dma_sync_page_highmem(struct page *page, > > unsigned long offset, size_t size, int direction) > > { > > - size_t seg_size = min((size_t)PAGE_SIZE, size) - offset; > > + size_t seg_size = min((size_t)(PAGE_SIZE - offset), size); > > size_t cur_size = seg_size; > > unsigned long flags, start, seg_offset = offset; > > - int nr_segs = PAGE_ALIGN(size + (PAGE_SIZE - offset))/PAGE_SIZE; > > + int nr_segs = 1 + ((size - seg_size) + PAGE_SIZE - 1)/PAGE_SIZE; > > int seg_nr = 0; > > > > local_irq_save(flags); > > > > > > Paolo Galtieri (pgaltieri@mvista.com) > > > > I want to apologize in advance for the previous post. When I included > the patch inline I dropped the tabs :-(. Here is the correct patch with > tabs: > > --- linux-2.6.14-rc3-git8/arch/ppc/kernel/dma-mapping.c 2005-10-10 > 13:55:37.000000000 -0700 > +++ linux-2.6.14/arch/ppc/kernel/dma-mapping.c 2005-10-10 > 13:57:51.000000000 -0700 > @@ -401,10 +401,10 @@ > static inline void __dma_sync_page_highmem(struct page *page, > unsigned long offset, size_t size, int direction) > { > - size_t seg_size = min((size_t)PAGE_SIZE, size) - offset; > + size_t seg_size = min((size_t)(PAGE_SIZE - offset), size); > size_t cur_size = seg_size; > unsigned long flags, start, seg_offset = offset; > - int nr_segs = PAGE_ALIGN(size + (PAGE_SIZE - offset))/PAGE_SIZE; > + int nr_segs = 1 + ((size - seg_size) + PAGE_SIZE - 1)/PAGE_SIZE; > int seg_nr = 0; > > local_irq_save(flags); > > Paolo > > - > 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/ ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-10-11 9:52 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2005-10-10 23:20 [PATCH] ppc highmem fix Paolo Galtieri 2005-10-10 23:38 ` Paolo Galtieri 2005-10-11 9:38 ` Benjamin Herrenschmidt
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®