2006-08-08 13:16:49

by Marco Pracucci

[permalink] [raw]
Subject: [Bluez-devel] "File descriptor in bad state" on sdp_connect()

Hi,

I have a problem with multiple concurrent calls to sdp_connect(). In
particular, I have a simple application that search a service on
different remote devices: the searches are done concurrently (until 7 in
parallel), each from within a different pthread. I have experienced
that, with a lot of Bluetooth dongles (example Surecom, D-Link), it
occurs an "File descriptor in bad state" error. Debugging the
sdp_connect() function I have founded that the error occurs on connect()
system call.

Has anyone had a similar problem?
Do you have any suggestion?

Thanks,
Marco Pracucci


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel


2006-08-16 20:21:18

by Fabrizio Guglielmino

[permalink] [raw]
Subject: Re: [Bluez-devel] "File descriptor in bad state" on sdp_connect()

Hi Ulisses,
I have been outside for a few days...and now I'm reading all the mail
about sdp_connect problem.
if I find the time I install the patch on a development system so I
try to contribute to the final version.

bye


Il giorno 11/ago/06, alle ore 22:09, Ulisses Furquim ha scritto:

> On 8/11/06, Marcel Holtmann <[email protected]> wrote:
>> look into l2cap_conn_del() and check what happens if l2cap_data is
>> NULL.
>> This doesn't change the behavior.
>
> Doooh. Right. We shouldn't be calling l2cap_conn_del() at all if
> l2cap_data is NULL so it doesn't change any behavior and we actually
> save one function call. :-)
>
> Regards,
>
> -- Ulisses
>
> ----------------------------------------------------------------------
> ---
> Using Tomcat but need to do more? Need to support web services,
> security?
> Get stuff done quickly with pre-integrated technology to make your
> job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache
> Geronimo
> http://sel.as-us.falkag.net/sel?
> cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Bluez-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
>


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

2006-08-11 20:09:40

by Ulisses Furquim

[permalink] [raw]
Subject: Re: [Bluez-devel] "File descriptor in bad state" on sdp_connect()

On 8/11/06, Marcel Holtmann <[email protected]> wrote:
> look into l2cap_conn_del() and check what happens if l2cap_data is NULL.
> This doesn't change the behavior.

Doooh. Right. We shouldn't be calling l2cap_conn_del() at all if
l2cap_data is NULL so it doesn't change any behavior and we actually
save one function call. :-)

Regards,

-- Ulisses

2006-08-11 22:01:57

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [Bluez-devel] "File descriptor in bad state" on sdp_connect()

Hi Ulisses,

> > The attached patch should not change any behavior, but keep track of
> > L2CAP connections in creation state. Please test and check the output of
> > dmesg.
>
> Hmm.. actually it changes the behavior a little bit. This part:
>
> default:
> conn = hcon->l2cap_data;
> if (!conn)
> break;
>
> spin_lock_bh(&l2cap_conn_lock);
> list_del(&conn->list);
> spin_unlock_bh(&l2cap_conn_lock);
>
> l2cap_conn_del(hcon, bt_err(status));
> break;
>
> should be like the following code. Otherwise we end up not calling
> l2cap_conn_del() on hcon, right? (or am I missing anything?)
>
> default:
> if ((conn = hcon->l2cap_data)) {
> spin_lock_bh(&l2cap_conn_lock);
> list_del(&conn->list);
> spin_unlock_bh(&l2cap_conn_lock);
> }
> l2cap_conn_del(hcon, bt_err(status));
> break;

look into l2cap_conn_del() and check what happens if l2cap_data is NULL.
This doesn't change the behavior.

Regards

Marcel



-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

2006-08-11 19:03:26

by Ulisses Furquim

[permalink] [raw]
Subject: Re: [Bluez-devel] "File descriptor in bad state" on sdp_connect()

Hi Marcel,

On 8/10/06, Marcel Holtmann <[email protected]> wrote:
> The attached patch should not change any behavior, but keep track of
> L2CAP connections in creation state. Please test and check the output of
> dmesg.

Hmm.. actually it changes the behavior a little bit. This part:

default:
conn = hcon->l2cap_data;
if (!conn)
break;

spin_lock_bh(&l2cap_conn_lock);
list_del(&conn->list);
spin_unlock_bh(&l2cap_conn_lock);

l2cap_conn_del(hcon, bt_err(status));
break;

should be like the following code. Otherwise we end up not calling
l2cap_conn_del() on hcon, right? (or am I missing anything?)

default:
if ((conn = hcon->l2cap_data)) {
spin_lock_bh(&l2cap_conn_lock);
list_del(&conn->list);
spin_unlock_bh(&l2cap_conn_lock);
}
l2cap_conn_del(hcon, bt_err(status));
break;

Best regards,

-- Ulisses

2006-08-10 17:28:24

by Ulisses Furquim

[permalink] [raw]
Subject: Re: [Bluez-devel] "File descriptor in bad state" on sdp_connect()

Hi Marcel,

On 8/10/06, Marcel Holtmann <[email protected]> wrote:
> > - trying to list_del() the same list entry twice leading us to a page fault
>
> where do we delete the entry twice?

On the first version of the patch (the one you sent to the list) there
was a list_del() inside l2cap_conn_del(). This list_del() was causing
a page fault trying to dereference prev and next pointers that were
poisoned because of a previous list_del().

> > - we've forgotten to INIT_LIST_HEAD() our l2cap_conn->list leading us
> > to a NULL pointer dereference
>
> This must be another bug, because it is not needed to init the list item
> itself. You only have to init the list head.

Hmm.. I think you're right as we already declare our list head with
LIST_HEAD(). I was seeing a NULL pointer dereference inside
list_del(), tough. Weird.

> The attached patch should not change any behavior, but keep track of
> L2CAP connections in creation state. Please test and check the output of
> dmesg.

Ok.

-- Ulisses

2006-08-10 16:38:39

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [Bluez-devel] "File descriptor in bad state" on sdp_connect()

Hi Ulisses,

> > > > please redo the patch against 2.6.18-rc4 and I will do some additional
> > > > testing.
> > >
> > > Done. Here is the same patch against 2.6.18-rc4.
> >
> > I tested this patch on my Quad G5. I don't see any timer issues, but it
> > also doesn't work either.
>
> Damn it. You don't have an HCI dump while l2test is running, do you?
> (or even l2test output, debug messages..). Thanks.

now my machine freezed when I tried to get a hcidump for you. However I
remember seeing the Command Disallowed error and after the Connect
Complete, I didn't see the additional Create Connection.

Regards

Marcel



-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

2006-08-10 12:41:55

by Ulisses Furquim

[permalink] [raw]
Subject: Re: [Bluez-devel] "File descriptor in bad state" on sdp_connect()

Hi Marcel,

On 8/9/06, Marcel Holtmann <[email protected]> wrote:
> > > please redo the patch against 2.6.18-rc4 and I will do some additional
> > > testing.
> >
> > Done. Here is the same patch against 2.6.18-rc4.
>
> I tested this patch on my Quad G5. I don't see any timer issues, but it
> also doesn't work either.

Damn it. You don't have an HCI dump while l2test is running, do you?
(or even l2test output, debug messages..). Thanks.

Regards,

-- Ulisses

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

2006-08-10 00:49:43

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [Bluez-devel] "File descriptor in bad state" on sdp_connect()

Hi Ulisses,

> > > I've done some modifications (and also included some bits from -mh)
> > > and it seems to be working. However, I'm hitting a kernel bug at
> > > kernel/timer.c inside cascade() from time to time. I haven't found
> > > what is causing this yet, but the patch I'm sending is against 2.6.17
> > > and I haven't tested with latest git snapshot so maybe this issue is
> > > already fixed upstream (kernel/timer.c:cascade() was changed [1]).
> >
> > please redo the patch against 2.6.18-rc4 and I will do some additional
> > testing.
>
> Done. Here is the same patch against 2.6.18-rc4.

I tested this patch on my Quad G5. I don't see any timer issues, but it
also doesn't work either.

Regards

Marcel



-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

2006-08-09 21:52:38

by Ulisses Furquim

[permalink] [raw]
Subject: Re: [Bluez-devel] "File descriptor in bad state" on sdp_connect()

Hi Marcel,

On 8/9/06, Marcel Holtmann <[email protected]> wrote:
> > I've done some modifications (and also included some bits from -mh)
> > and it seems to be working. However, I'm hitting a kernel bug at
> > kernel/timer.c inside cascade() from time to time. I haven't found
> > what is causing this yet, but the patch I'm sending is against 2.6.17
> > and I haven't tested with latest git snapshot so maybe this issue is
> > already fixed upstream (kernel/timer.c:cascade() was changed [1]).
>
> please redo the patch against 2.6.18-rc4 and I will do some additional
> testing.

Done. Here is the same patch against 2.6.18-rc4.

Regards,

-- Ulisses


Attachments:
(No filename) (656.00 B)
l2cap-handle-multiple-connects-2.6.18-rc4.patch (3.04 kB)
Download all attachments

2006-08-09 21:56:41

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [Bluez-devel] "File descriptor in bad state" on sdp_connect()

Hi Ulisses,

> > I have had a similar problem ....I've discovered (with Marcel help) is a
> > problem in l2cap layer.
> > l2cap kernel module do not handle multiple connect, Marcel send to me a
> > patch I am trying to make to work
> > but I'm very busy with my job and is not still clear where the patch
> > hangs the system.
>
> We thought we had a deadlock somewhere but it wasn't the case. We had
> two problems:
>
> - trying to list_del() the same list entry twice leading us to a page fault
> - we've forgotten to INIT_LIST_HEAD() our l2cap_conn->list leading us
> to a NULL pointer dereference
>
> I've done some modifications (and also included some bits from -mh)
> and it seems to be working. However, I'm hitting a kernel bug at
> kernel/timer.c inside cascade() from time to time. I haven't found
> what is causing this yet, but the patch I'm sending is against 2.6.17
> and I haven't tested with latest git snapshot so maybe this issue is
> already fixed upstream (kernel/timer.c:cascade() was changed [1]).

please redo the patch against 2.6.18-rc4 and I will do some additional
testing.

Regards

Marcel



-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

2006-08-09 15:06:10

by Ulisses Furquim

[permalink] [raw]
Subject: Re: [Bluez-devel] "File descriptor in bad state" on sdp_connect()

Hi Fabrizio,

On 8/8/06, Fabrizio Guglielmino <[email protected]> wrote:
> I have had a similar problem ....I've discovered (with Marcel help) is a
> problem in l2cap layer.
> l2cap kernel module do not handle multiple connect, Marcel send to me a
> patch I am trying to make to work
> but I'm very busy with my job and is not still clear where the patch
> hangs the system.

We thought we had a deadlock somewhere but it wasn't the case. We had
two problems:

- trying to list_del() the same list entry twice leading us to a page fault
- we've forgotten to INIT_LIST_HEAD() our l2cap_conn->list leading us
to a NULL pointer dereference

I've done some modifications (and also included some bits from -mh)
and it seems to be working. However, I'm hitting a kernel bug at
kernel/timer.c inside cascade() from time to time. I haven't found
what is causing this yet, but the patch I'm sending is against 2.6.17
and I haven't tested with latest git snapshot so maybe this issue is
already fixed upstream (kernel/timer.c:cascade() was changed [1]).
Marcel, do you have any idea of what might be happening?

If anyone wants to give this beast a try you're warned that it might
lock up your system. FWIW, a quick test can be done using l2test from
CVS like:

$ ./l2test -m bd_addr1 bd_addr2 ...

Best regards,

-- Ulisses


[1] http://www.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blobdiff;h=b650f04888ed6dbc6abb07adcee5c58a8f27c374;hp=9062a82ee8ec40d9a6ef985c625bd8daaf5778c5;hb=a2c348fe0117adced11e374329a5ea3f7c43cb41;f=kernel/timer.c


Attachments:
(No filename) (1.52 kB)
l2cap-handle-multiple-connects.patch (4.89 kB)
Download all attachments

2006-08-08 12:19:41

by Fabrizio Guglielmino

[permalink] [raw]
Subject: Re: [Bluez-devel] "File descriptor in bad state" on sdp_connect()

Hi,
I have had a similar problem ....I've discovered (with Marcel help) is a
problem in l2cap layer.
l2cap kernel module do not handle multiple connect, Marcel send to me a
patch I am trying to make to work
but I'm very busy with my job and is not still clear where the patch
hangs the system.

You can found some information searching in old messages....

Ciao
Fabrizio


Marco Pracucci ha scritto:
> Hi,
>
> I have a problem with multiple concurrent calls to sdp_connect(). In
> particular, I have a simple application that search a service on
> different remote devices: the searches are done concurrently (until 7 in
> parallel), each from within a different pthread. I have experienced
> that, with a lot of Bluetooth dongles (example Surecom, D-Link), it
> occurs an "File descriptor in bad state" error. Debugging the
> sdp_connect() function I have founded that the error occurs on connect()
> system call.
>
> Has anyone had a similar problem?
> Do you have any suggestion?
>
> Thanks,
> Marco Pracucci
>
>
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Bluez-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
>
>
>


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

2006-08-08 13:13:33

by Ulisses Furquim

[permalink] [raw]
Subject: Re: [Bluez-devel] "File descriptor in bad state" on sdp_connect()

Hi Peter,

On 8/8/06, Peter Wippich <[email protected]> wrote:
> > I have a problem with multiple concurrent calls to sdp_connect(). In
> > particular, I have a simple application that search a service on
> > different remote devices: the searches are done concurrently (until 7 in
> > parallel), each from within a different pthread. I have experienced
> > that, with a lot of Bluetooth dongles (example Surecom, D-Link), it
> > occurs an "File descriptor in bad state" error. Debugging the
> > sdp_connect() function I have founded that the error occurs on connect()
> > system call.
> >
> This problem has been discussed here several times for various
> applications. It is not related to SDP but to the general problem that
> (all ?) commercial available Bluetooth adaptors do not support multiple
> (concurrent) connection requests. The only solution is to serialize the
> connect requests. Until now nobody voluntered to do this in the kernel.

I'm working on this right now. I think I've found the problems with
that Marcel Holtmann's patch. I'm gonna test it a little bit more and
then I'll send the patch to the list. :-)

Regards,

-- Ulisses

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

2006-08-08 11:43:55

by Peter Wippich

[permalink] [raw]
Subject: Re: [Bluez-devel] "File descriptor in bad state" on sdp_connect()


Hi Marco,

On Tue, 8 Aug 2006, Marco Pracucci wrote:

> Hi,
>
> I have a problem with multiple concurrent calls to sdp_connect(). In
> particular, I have a simple application that search a service on
> different remote devices: the searches are done concurrently (until 7 in
> parallel), each from within a different pthread. I have experienced
> that, with a lot of Bluetooth dongles (example Surecom, D-Link), it
> occurs an "File descriptor in bad state" error. Debugging the
> sdp_connect() function I have founded that the error occurs on connect()
> system call.
>
This problem has been discussed here several times for various
applications. It is not related to SDP but to the general problem that
(all ?) commercial available Bluetooth adaptors do not support multiple
(concurrent) connection requests. The only solution is to serialize the
connect requests. Until now nobody voluntered to do this in the kernel.

Ciao,

Peter


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel