2010-07-22 22:52:19

by Mario 'BitKoenig' Holbe

[permalink] [raw]
Subject: b43 wireless driver inhibits access to /dev/hwrng

Hello,

the b43 wireless driver inhibits access to /dev/hwrng while the wireless
network interface is down. When the interface is up, /dev/hwrng is
accessible:

root@ideapad ~ # uname -a
Linux ideapad 2.6.35-rc5-686 #1 SMP Tue Jul 13 16:16:00 UTC 2010 i686 GNU/Linux
root@ideapad ~ # grep name /proc/cpuinfo
model name : VIA Nano processor U2250 (1.6GHz Capable)
root@ideapad ~ # lsmod | grep via.rng
via_rng 1243 0
rng_core 2912 2 via_rng,b43
root@ideapad ~ # hexdump -n 10 /dev/hwrng
0000000 81f2 8497 71bb d900 f89f
000000a
root@ideapad ~ # ifconfig wlan0 down
root@ideapad ~ # hexdump -n 10 /dev/hwrng
hexdump: /dev/hwrng: No such device
root@ideapad ~ # ifconfig wlan0 up
root@ideapad ~ # hexdump -n 10 /dev/hwrng
0000000 86fc 5d33 4dec d97d da7b
000000a
root@ideapad ~ #

Aside from such a side-effect being heavily unexpected, this effect is
particularly annoying because it renders rngd failing to start at boot
time - especially when using NetworkManager which is usually started
later than the classic ifupdown methods.

I have no idea whether this issue belongs to the b43 driver or to the
rng core.


Thanks for your work & best regards
Mario
--
The only thing to be scared of, son, is tomorrow.
I don't live for tomorrow. Never saw the fun in it.
-- Denny Crane, Boston Legal


Attachments:
(No filename) (1.33 kB)
signature.asc (482.00 B)
Digital signature
Download all attachments

2010-07-23 14:45:15

by John W. Linville

[permalink] [raw]
Subject: Re: b43 wireless driver inhibits access to /dev/hwrng

On Fri, Jul 23, 2010 at 12:52:12AM +0200, Mario 'BitKoenig' Holbe wrote:
> Hello,
>
> the b43 wireless driver inhibits access to /dev/hwrng while the wireless
> network interface is down. When the interface is up, /dev/hwrng is
> accessible:

<snip>

> I have no idea whether this issue belongs to the b43 driver or to the
> rng core.

The hwrng driver is provided by the b43 hardware, which is shutdown
when the network interface is down. I'm not sure how one could expect
this to work.

John
--
John W. Linville Someday the world will need a hero, and you
[email protected] might be all we have. Be ready.

2010-07-23 15:31:18

by Mario 'BitKoenig' Holbe

[permalink] [raw]
Subject: Re: b43 wireless driver inhibits access to /dev/hwrng

On Fri, Jul 23, 2010 at 10:32:19AM -0400, John W. Linville wrote:
> The hwrng driver is provided by the b43 hardware, which is shutdown
> when the network interface is down. I'm not sure how one could expect
> this to work.

Nope. It's provided by the VIA PadLock hardware (through the via-rng
driver). I'm not sure how one could expect this not to work when the
network interface provided by the b43 driver is down.

Well, maybe let's try to become a bit less offensive... :)
Probably there are two Hardware RNGs on that machine: one provided by
VIA PadLock through via-rng, one provided by BCM4312 through b43:
hw_random/via-rng.c: err = hwrng_register(&via_rng);
b43/main.c: err = hwrng_register(&wl->rng);

But at least now it's a bit more likely that the problem is located in
the rng core which should not render /dev/hwrng inaccessible when only
one of the RNGs unregisters.

However, what I don't fully understand is: I find only one way where b43
unregisters its RNG, which is via
b43_remove() -> b43_rng_exit() -> hwrng_unregister()
And, I'm really not sure if I got this right, but... I guess,
b43_remove() is only called when the module is removed from the kernel
and not when the network interface is shut down.

So, maybe it's not really rng core's fault?
I guess, b43 just stops delivering data through b43_rng_read() when the
hardware is shut down and instead returns ENODEV (which is btw. what I
get when I'm trying to read /dev/hwrng while b43 is down), and the rng
core just delivers this error up when it's trying to deliver the read
request to the b43 RNG.


Mario
--
User sind wie ideale Gase - sie verteilen sich gleichmaessig ueber alle Platten


Attachments:
(No filename) (1.64 kB)
signature.asc (482.00 B)
Digital signature
Download all attachments

2010-07-23 17:45:15

by John W. Linville

[permalink] [raw]
Subject: Re: b43 wireless driver inhibits access to /dev/hwrng

On Fri, Jul 23, 2010 at 05:31:02PM +0200, Mario 'BitKoenig' Holbe wrote:
> On Fri, Jul 23, 2010 at 10:32:19AM -0400, John W. Linville wrote:
> > The hwrng driver is provided by the b43 hardware, which is shutdown
> > when the network interface is down. I'm not sure how one could expect
> > this to work.
>
> Nope. It's provided by the VIA PadLock hardware (through the via-rng
> driver). I'm not sure how one could expect this not to work when the
> network interface provided by the b43 driver is down.

Alright, sorry I overlooked that. Although it still looks to me like
your current_rng must be the b43-provided one, or else you wouldn't
be experiencing this issue.

> Well, maybe let's try to become a bit less offensive... :)
> Probably there are two Hardware RNGs on that machine: one provided by
> VIA PadLock through via-rng, one provided by BCM4312 through b43:
> hw_random/via-rng.c: err = hwrng_register(&via_rng);
> b43/main.c: err = hwrng_register(&wl->rng);
>
> But at least now it's a bit more likely that the problem is located in
> the rng core which should not render /dev/hwrng inaccessible when only
> one of the RNGs unregisters.
>
> However, what I don't fully understand is: I find only one way where b43
> unregisters its RNG, which is via
> b43_remove() -> b43_rng_exit() -> hwrng_unregister()
> And, I'm really not sure if I got this right, but... I guess,
> b43_remove() is only called when the module is removed from the kernel
> and not when the network interface is shut down.
>
> So, maybe it's not really rng core's fault?
> I guess, b43 just stops delivering data through b43_rng_read() when the
> hardware is shut down and instead returns ENODEV (which is btw. what I
> get when I'm trying to read /dev/hwrng while b43 is down), and the rng
> core just delivers this error up when it's trying to deliver the read
> request to the b43 RNG.

Yes, I believe this is what the b43 hwrng is doing. I suspect you
need/want a way to influence current_rng to favor via-rng. You may
want to reference Documentation/hw_random.txt for further information.

Good luck!

John
--
John W. Linville Someday the world will need a hero, and you
[email protected] might be all we have. Be ready.

2010-07-23 18:21:31

by Mario 'BitKoenig' Holbe

[permalink] [raw]
Subject: Re: b43 wireless driver inhibits access to /dev/hwrng

On Fri, Jul 23, 2010 at 01:32:46PM -0400, John W. Linville wrote:
> Alright, sorry I overlooked that. Although it still looks to me like
> your current_rng must be the b43-provided one, or else you wouldn't
> be experiencing this issue.

Yes. Unfortunately, the b43 module is loaded earlier than the via-rng
module: the former gets loaded via udev autodetection, the latter gets
loaded via my /etc/modules. Thus, the rng core selects b43 as the
"current" RNG.

> > I guess, b43 just stops delivering data through b43_rng_read() when the
> > hardware is shut down and instead returns ENODEV (which is btw. what I
> > get when I'm trying to read /dev/hwrng while b43 is down), and the rng
> Yes, I believe this is what the b43 hwrng is doing. I suspect you
> need/want a way to influence current_rng to favor via-rng. You may

Yes, once knowing what happens it was easy to find a work-around:

root@ideapad ~ # cat /etc/modprobe.d/local-b43-workaround.conf
# Work-around: b43 provides a Hardware RNG as well, but returns ENODEV
# on read() when the BCM4312 hardware is down.
# Ensure via-rng is loaded before this module. This way hw_random/core
# delivers read()s on /dev/hwrng to via-rng.
install b43 modprobe via-rng; modprobe --ignore-install b43 $CMDLINE_OPTS

> want to reference Documentation/hw_random.txt for further information.

Indeed, setting /sys/devices/virtual/misc/hw_random/rng_current would
probably be a cleaner solution :) Thanks for that.

However, I still somehow feel like this is a bug - either in the rng
core or in b43. One of both should IMHO be changed: either the rng core
to respect drivers not currently delivering data or (probably cleaner)
to provide an interface to suspend a driver, or the b43 driver to
unregister its rng when the hardware is shut down (or power it up when
the rng is accessed? probably a bit oversized :)).

Unfortunately, Documentation/hw_random.txt has no usage guidelines for
the rng core, i.e. how drivers should behave when no data is available.
It talks about a `hardware "has-data" flag', but I cannot find such a
thing in the code.


Thanks for your help and patience
Mario
--
File names are infinite in length where infinity is set to 255 characters.
-- Peter Collinson, "The Unix File System"


Attachments:
(No filename) (2.24 kB)
signature.asc (482.00 B)
Digital signature
Download all attachments

2010-07-31 06:15:43

by Pavel Machek

[permalink] [raw]
Subject: Re: b43 wireless driver inhibits access to /dev/hwrng

On Fri 2010-07-23 10:32:19, John W. Linville wrote:
> On Fri, Jul 23, 2010 at 12:52:12AM +0200, Mario 'BitKoenig' Holbe wrote:
> > Hello,
> >
> > the b43 wireless driver inhibits access to /dev/hwrng while the wireless
> > network interface is down. When the interface is up, /dev/hwrng is
> > accessible:
>
> <snip>
>
> > I have no idea whether this issue belongs to the b43 driver or to the
> > rng core.
>
> The hwrng driver is provided by the b43 hardware, which is shutdown
> when the network interface is down. I'm not sure how one could expect
> this to work.

Well... either don't provide hwrng interface, or power up enough of
b43 hardware when user opens /dev/hwrng...?
Pavel

--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html