Re: [PATCH] kfifo: overflow of unsigned integer

From: Cong WANG
Date: Fri Feb 09 2007 - 20:56:44 EST


2007/2/9, Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>:
On Thu, 8 Feb 2007 20:16:55 +0800 "Cong WANG" <xiyou.wangcong@xxxxxxxxx> wrote:

> 2007/2/8, Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>:
> > On Thu, 8 Feb 2007 17:07:28 +0800 "Cong WANG" <xiyou.wangcong@xxxxxxxxx> wrote:
> >
> > > Kfifo is a ring-buffer in kernel which can be used as a lock-free way
> > > for concurrent read/write when there are only one producer and one
> > > consumer. Details of its design can be found in kernel/kfifo.c and
> > > include/linux/kfifo.h.
> > >
> > > You will find that the 'in' and 'out' fields of 'struct kfifo' are
> > > both represented as 'unsigned int' and in most cases 'in' is larger
> > > than 'out' and their difference will NOT be over 'size'.
> > >
> > > Now the problem is that 'in' will be *smaller* than 'out' when 'in'
> > > overflows and 'out' doesn't (Yes, this may occur quietly.). This is
> > > NOT what we expect, though it may not cause any serious problems if we
> > > carefully use kfifo*() functions. And this is really a bug.
> >
> > You seem to be saying that it's not a bug, but it's a bug.
> >
> > Exactly what goes wrong?
>
> I wrote a module on my machine to test this bug. And when the overflow
> occurs, I cann't put any data into the fifo even though it is not
> full.

Why did you remove the mailing list? Please don't do that.

Sorry. I used the poor 'reply'.


I can't find any bug.

I converted the code so that it'll run in userspace:

http://userweb.kernel.org/~akpm/kfifo.c
http://userweb.kernel.org/~akpm/kfifo.h

Please see if you can reproduce the problem with that setup and then let's
see if we can understand what's going on, and fix it.



Thanks for your work. And you are right.

I think the OLD /proc API which I used in my module confused my eyes.
I got completely lost by that. OLD /proc API is very bad, isn't it?

BTW, can you tell me which way do you use to exchange information
between user-space and kernel-space when debugging the kernel?

Thanks again! And have a nice day!
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/