Re: quick hack to support "option VIMAGE" on USB Ethernet

From: (wrong string) 小野寛生 <hiroo.ono+freebsd_at_gmail.com>
Date: Sun, 16 Feb 2014 19:20:46 +0900
Hello,

The problem of USB ethernet device with VIMAGE kernel still remains
with 10.0-RELEASE and I think I have found the reason and a fix.

I have filed a patch and backtrace as a followup to the PR
http://www.freebsd.org/cgi/query-pr.cgi?pr=kern/183835

I will repeat the explanation here.
The problem occur when ue_attach_post_task() (in
sys/dev/usb/net/usb_ethernet.c) is called.

ue_attach_post_task() calls if_alloc() (in sys/net/if.c)
and ether_attach() (in sys/net/if_ethersubr.c), which finally refer V_if_index.

The problem is that curvnet is NULL when ue_attach_post_task()
is invoked, and with VIMAGE, V_if_index is defined to
	VNET(if_index)	=> VNET_VNET(curvnet, if_index)
			=> (*VNET_VNET_PTR((curvnet), if_index))
			=> (*_VNET_PTR((curvnet)->vnet_data_base, if_index))
	and so on.

For device attach, the following code in device_probe_and_attach()
(in kern/subr_bus.c)

	CURVNET_SET_QUIET(vnet0);
	error = device_attach(dev);
	CURVNET_RESTORE();

should assign curvnet to vnet0, but it is not the case for ue device.

As an example of USB ethernet device, with if_axe, device_attach(dev)
is axe_attach() (in sys/dev/usb/net/if_axe.c).
axe_attach() calls uether_ifattach() (in sys/dev/usb/net/usb_ethernet.c)
(other USB ethernet devices' *_attach() also call this function),
which *queues* (not calls) ue_attach_post_task().
As ue_attach_post_task is called from usb_process (not from uther_ifattach),
it is not assured that curvnet is properly assigned.

2013-08-14 4:08 GMT+09:00 Craig Rodrigues <rodrigc_at_freebsd.org>:
> On Mon, Aug 12, 2013 at 8:57 PM, YAMAMOTO Shigeru <shigeru_at_iij.ad.jp> wrote:
>
>>
>> My try is,
>> 1) I try to enable "option VIMAGE" at r254236_at_HEAD.
>> It causes panic at accessing V_if_index in ifindex_alloc_locked().
>>
>
> Can you provide the kernel backtrace for this panic?
> It would be interesting to see where we need to initialize currvnet for USB
> Ethernet.
> I thought we already handled that case in subr_bus.c
>
> --
> Craig
> _______________________________________________
> freebsd-current_at_freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-current
> To unsubscribe, send any mail to "freebsd-current-unsubscribe_at_freebsd.org"
Received on Sun Feb 16 2014 - 09:20:47 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:46 UTC