RFC: i386: kill !4KSTACKS
Quoted 1 line
Please don't tell me to "care for closed-source drivers".
ndiswrapper is NOT closed source. And I'm not asking you to "care".
Quoted 2 lines
I don't want the pain of debugging crashes on the machines which run unknown code in kernel space.
I'm not asking you to debug crashes. I'm simply requesting that the kernel stack size situation remain as it is: with 8K as the default and 4K configurable.
Quoted 1 line
vda
I code, therefore I am
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 3 lines · Alex Davis
Quoted 1 line
Please don't tell me to "care for closed-source drivers".
ndiswrapper is NOT closed source. And I'm not asking you to "care".
While ndiswrapper might not be closed source, I would not call the windows driver it loads open source ...
There is really no difference between madwifi+closed source hal to ndiswrapper+windows driver.
Both are just as (non-)debuggable.
Ok, madwifi exposes more of it's driver source to us, but still.
// Stefan
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (MingW32)
iD8DBQFDGyrOBrn2kJu9P78RAvIxAJ426eTZbTtB5v92A+ipxsKEFW4sPACgnYna iXGFMduZgJ92UriSHvwTW3g=
=YcU6
-----END PGP SIGNATURE-----
Quoted 10 lines · * Stefan Smietanowski ([email protected]) wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1Quoted 3 lines · Alex Davis
Quoted 1 line
Please don't tell me to "care for closed-source drivers".
ndiswrapper is NOT closed source. And I'm not asking you to "care".
While ndiswrapper might not be closed source, I would not call the windows driver it loads open source ...
Would it be possible for ndiswrapper to provide a seperate stack to the windows code so this problem is seperable?
How debuggable is stack overrun? I mean if I am the unlucky admin who decides to setup a crypto/raid/stripe/thing setup which runs out of stack somewhere how easy will it be for someone who doesn't know the innards to know what happened as opposed to running into a random oops?
Dave
--
-----Open up your eyes, open up your mind, open up your code -------
/ Dr. David Alan Gilbert | Running GNU/Linux on Alpha,68K| Happy \ \ gro.gilbert @ treblig.org | MIPS,x86,ARM,SPARC,PPC & HPPA | In Hex / \ _________________________|_____ http://www.treblig.org |_______/
Quoted 3 lines · Alex Davis
I'm not asking you to debug crashes. I'm simply requesting that the kernel stack size situation remain as it is: with 8K as the default and 4K configurable.
How about the relevant question - why hasn't someone fixed ndiswrapper yet - its been pending for months.
Quoted 7 lines · Alan Cox
Quoted 3 lines · Alex Davis
I'm not asking you to debug crashes. I'm simply requesting that the kernel stack size situation remain as it is: with 8K as the default and 4K configurable.
How about the relevant question - why hasn't someone fixed ndiswrapper yet - its been pending for months.
AFAIK with interrupt stacks it shouldn't be a big issue to switch to a private bigger stack. ndiswrapper just needs to have its own private way to do "current" which accesses thread_info at the bottom of the stack. The old problem used to be that interrupts use current too, but the i386 irq stack code solves this already.
I suppose the real reason is that most people who are capable to do these are too scared of the general concept of ndiswrapper and don't touch it with a fire pole, and the others are unable to do it.
BTW Windows actually seems to have 12k of stack so even 8k is not quite safe (if that word can be applied to ndiswrapper at all)
In general I think 4k stack is a bad move though - the VM stalls argument is a red hering because if that really was such a big issue (which my perception is that it is not) then it has to be fixed for other architectures which need double page stack (like x86-64) anyways. And the problem of running with tight stack is that you'll always run into corner cases (e.g. involving more complicated stacking cases or error handling paths etc.) where you overflow and which will be hard to fix.
Running with tight stack is just a fundamentally fragile configuration and will come back to bite you later. Even with 8k we regularly had overflows reported and with 4k it will be much worse.
-Andi
Quoted 3 lines · Andi Kleen
Running with tight stack is just a fundamentally fragile configuration and will come back to bite you later. Even with 8k we regularly had overflows reported and with 4k it will be much worse.
I think one of the reasons is:
"No matter how big stack is, there are always careless code which can overflow it. 4k, 8k, 64k (hypotetically), we still must keep stack size in mind when coding.
So, since we already are writing stack size aware code, why not pick minimum realistically working stack size? Looks like we can make 4k stack work, and it's naturally smallest sensible (and in fact easiest to allocate/manage) stack for i386. So be it, let's use 4k."
I suspect Windows went the opposite way. I bet they already went thru several iterations of "ouch these drivers from BogoSoft can overflow stack on nt N, let's bump up stack size for our new shiny nt N+1".
--
vda
Quoted 11 lines · Denis Vlasenko
I think one of the reasons is:
"No matter how big stack is, there are always careless code which can overflow it. 4k, 8k, 64k (hypotetically), we still must keep stack size in mind when coding.
So, since we already are writing stack size aware code, why not pick minimum realistically working stack size? Looks like we can make 4k stack work, and it's naturally smallest sensible (and in fact easiest to allocate/manage) stack for i386. So be it, let's use 4k."
Better engineering is to take the minimum size and then add some safety margin. Running with the minimum only is ok when you have the infrastructure to prove maximum stack usage, but Linux is far too complex for that. In general running with no safety margin is not a good idea.
BTW your minimum doesn't seem to be everybody's minimum - everytime you see someone advocating the smallest stacks they go "it's fine for us, but don't use A, B, C, D" (and I expect these lists to get longer with more experience).
The trend in Linux clearly seems to be towards more complex code. While that is not always a good thing but it seems to be unstoppable (everybody wants their favourite features and the merging machinery is well oiled and in full action). And doing all that will need more stack space over time so shrinking is clearly the wrong strategic direction.
At some point we undoubtedly will need to increase it further, the logical point would be when Linux switches to larger softpage sizes.
-Andi
Quoted 3 lines · Andi Kleen
At some point we undoubtedly will need to increase it further, the logical point would be when Linux switches to larger softpage sizes.
Is this really a "when"?
Hugh and wli were both working on this and IIRC neither could show enough justification to get people interested in it and get it merged (maybe apart from helping stupidly sized PAE systems limp along)
And that was even before page size reductions and objrmap came along, which makes the potential gain even smaller.
Are there still good reasons to have such a thing?
Nick
Signature · 5 lines
SUSE Labs, Novell Inc. Send instant messages to your online friends http://au.messenger.yahoo.com
Quoted 2 lines
Are there still good reasons to have such a thing?
I think so yes. It just doesn't make much sense to handle larger 64bit setups with multiple GB of memory with 4K pages. While larger softpage size will not increase TLB usage it will give you less cache use and in general less cycles while accessing mem_map and while doing VM operations in general. Other benefits are faster TLB flush (I saw some bottlenecks with that in 2.4 on large systems)
Simple example: you have to handle a few GB of memory in the LRU list. Doing it with half as many objects (8k page instead of 4k) is much more efficient.
-Andi
Quoted 1 line · Nick Piggin
Are there still good reasons to have such a thing?
Bigger block sizes was one of their features.
Quoted 3 lines · Andi Kleen
AFAIK with interrupt stacks it shouldn't be a big issue to switch to a private bigger stack. ndiswrapper just needs to have its own private way to do "current" which accesses
thread_infoat the bottom of the stack.
I am developer of ndiswrapper and just caught up with this discussion. I am interested in providing private stack for ndiswrapper. I am not familiar with linux kernel internals to understand your proposal. Could you give me details please: If you can give a rough sketch of idea, I can implement it. Better yet, if you (or anyone else) can provide an implementation (not necessarily against ndsiwrapper, but a proof of concept), it will be greatly appreciated - this should also help any other projects that need more than 4k stack.
Thanks,
Giri.
2005/9/6, Giridhar Pemmasani <[email protected]>:
Quoted 6 lines
Quoted 3 lines · Andi Kleen
AFAIK with interrupt stacks it shouldn't be a big issue to switch to a private bigger stack. ndiswrapper just needs to have its own private way to do "current" which accesses
thread_infoat the bottom of the stack.
Quoted 9 lines
I am developer of ndiswrapper and just caught up with this discussion. I am interested in providing private stack for ndiswrapper. I am not familiar with linux kernel internals to understand your proposal. Could you give me details please: If you can give a rough sketch of idea, I can implement it. Better yet, if you (or anyone else) can provide an implementation (not necessarily against ndsiwrapper, but a proof of concept), it will be greatly appreciated - this should also help any other projects that need more than 4k stack.
You may take a look at how the IRQ stacks work on x86, e.g.
http://lxr.linux.no/source/arch/i386/kernel/irq.c#L48
The idea of switching stacks first sounds appealing, but it is not that trivial. The tricky part comes with current/current_thread_info. After you switched to a private stack and called some Windows driver function, that code may call back to the ndiswrapper API which, in turn, may jump into some kernel functions. If that kernel code calls current_thread_info while your differently sized stack is active, current_thread_info will not be able to evaluate a correct thread_info address (see http://lxr.linux.no/source/include/asm-i386/thread_info.h#L88).
The only way I see is to switch stacks back on ndiswrapper API entry. But managing all those stacks correctly is challenging, as you will likely not want to create a new stack on each switching point. Rather, maintaining them per context (IRQ, tasklet, kernel thread, user process, <stuff I forgot>) is required in order to save memory and avoid shortages in atomic contexts.
Jan
Quoted 3 lines · Jan Kiszka
The only way I see is to switch stacks back on ndiswrapper API entry. But managing all those stacks correctly is challenging, as you will likely not want to create a new stack on each switching point. Rather,
This is what I had in mind before I saw this thread here. I, in fact, did some work along those lines, but it is even more complicated than you mentioned here: Windows uses different calling conventions (STDCALL, FASTCALL, CDECL) so switching stacks by copying arguments/results gets complicated. So I gave up on that approach. For X86-64 drivers we use similar approach, but for that there is only one calling convention and we don't need to switch stacks, but reshuffle arguments on stack / in registers.
I am still hoping that Andi's approach is possible (I don't understand how we can make kernel see current info from private stack).
Giri
Quoted 15 lines · Giridhar Pemmasani
Quoted 3 lines · Jan Kiszka
The only way I see is to switch stacks back on ndiswrapper API entry. But managing all those stacks correctly is challenging, as you will likely not want to create a new stack on each switching point. Rather,
This is what I had in mind before I saw this thread here. I, in fact, did some work along those lines, but it is even more complicated than you mentioned here: Windows uses different calling conventions (STDCALL, FASTCALL, CDECL) so switching stacks by copying arguments/results gets complicated. So I gave up on that approach. For X86-64 drivers we use similar approach, but for that there is only one calling convention and we don't need to switch stacks, but reshuffle arguments on stack / in registers.
Quoted 4 lines
I am still hoping that Andi's approach is possible (I don't understand how we can make kernel see current info from private stack).
Giri
You can't without copying info from one stack to another. There are other problems, also, the only place you can get data for a stack in the kernel dynamically is from kmalloc(GFP_ATOMIC). Other kmalloc() data are paged which may (will) cause a double-fault if you use it for a stack. You are not going to get much more than a page of GFP_ATOMIC data so you can't really make a larger stack than the existing process/kernel stack.
I have tried to just allocate data when a module is installed (in the .bss or .data segments as static data). Unfortunately, some kernel code traps this as a "triple fault" if I try to use it for a stack, even though the kernel segments for ES, SS, DS, all point to the same area(s).
I think the purpose of compressing the stack was to get rid of NDIS, but that's only a theory. Currently, they did a good job of it!
Cheers,
Dick Johnson
Penguin : Linux version 2.6.13 on an i686 machine (5589.54 BogoMips). Warning : 98.36% of all statistics are fiction.
.
I apologize for the following. I tried to kill it with the above dot :
****************************************************************
The information transmitted in this message is confidential and may be privileged. Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited. If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to [email protected] - and destroy all copies of this information, including any attachments, without reading or disclosing them.
Thank you.
Quoted 1 line · linux-os (Dick Johnson)
I think
... and we have clear winner for the most incredible statement made on l-k.
2005/9/6, Giridhar Pemmasani <[email protected]>:
Quoted 15 lines
Quoted 3 lines · Jan Kiszka
The only way I see is to switch stacks back on ndiswrapper API entry. But managing all those stacks correctly is challenging, as you will likely not want to create a new stack on each switching point. Rather,
This is what I had in mind before I saw this thread here. I, in fact, did some work along those lines, but it is even more complicated than you mentioned here: Windows uses different calling conventions (STDCALL, FASTCALL, CDECL) so switching stacks by copying arguments/results gets complicated. So I gave up on that approach. For X86-64 drivers we use similar approach, but for that there is only one calling convention and we don't need to switch stacks, but reshuffle arguments on stack / in registers.
Quoted 3 lines
I am still hoping that Andi's approach is possible (I don't understand how we can make kernel see current info from private stack).
The more I think about this the more it becomes clear that this path will be too winding, especially when compared to the effort needed to patch 8K (or more) back into the kernel as an intermediate workaround.
Moving the Windows code out of the kernel to userspace should be more helpful on the long term. It would take a small stub, something like tun/tap devices with wireless extensions, plus something to forward PCI interrupts, and you could start hacking the wrapper in a save harbour. If libusb is already prepared for such a task is not yet clear to me (at least it is lacking USB 2.0 according to the docs). But time will likely solve this as well.
Jan
Quoted 32 lines · Jan Kiszka
2005/9/6, Giridhar Pemmasani <[email protected]>:
Quoted 15 lines
Quoted 3 lines · Jan Kiszka
The only way I see is to switch stacks back on ndiswrapper API entry. But managing all those stacks correctly is challenging, as you will likely not want to create a new stack on each switching point. Rather,
This is what I had in mind before I saw this thread here. I, in fact, did some work along those lines, but it is even more complicated than you mentioned here: Windows uses different calling conventions (STDCALL, FASTCALL, CDECL) so switching stacks by copying arguments/results gets complicated. So I gave up on that approach. For X86-64 drivers we use similar approach, but for that there is only one calling convention and we don't need to switch stacks, but reshuffle arguments on stack / in registers.
Quoted 3 lines
I am still hoping that Andi's approach is possible (I don't understand how we can make kernel see current info from private stack).
The more I think about this the more it becomes clear that this path will be too winding, especially when compared to the effort needed to patch 8K (or more) back into the kernel as an intermediate workaround.
Moving the Windows code out of the kernel to userspace should be more helpful on the long term. It would take a small stub, something like tun/tap devices with wireless extensions, plus something to forward PCI interrupts, and you could start hacking the wrapper in a save harbour. If libusb is already prepared for such a task is not yet clear to me (at least it is lacking USB 2.0 according to the docs). But time will likely solve this as well.
Quoted 2 lines
Jan
-
The attached device-driver allocates a 0x4000 length stack in an ioctl() procedure, uses that stack, then returns to the old stack before returning from the ioctl(). Since the data-space for the stack is allocated only once (when the module is installed), the runtime overhead is not very great. The driver runs on 2.6.13.
This just shows that it can be done! This doesn't mean that one should actually do this!
Script started on Tue 06 Sep 2005 04:09:32 PM EDT
[root@chaos driver]# make install
Analogic StkDev : Initialization complete
[root@chaos driver]# ./tester
[root@chaos driver]# ./tester
[root@chaos driver]# ./tester
[root@chaos driver]# make remove
StkDev 6020 0 - Live 0xf0a34000
Analogic StkDev : Initialization complete
Doing something scary on the new stack!!
Actually survived!
Doing something scary on the new stack!!
Actually survived!
Doing something scary on the new stack!!
Actually survived!
Analogic StkDev : Module removed
[root@chaos driver]# exit
Script done on Tue 06 Sep 2005 04:09:55 PM EDT
Cheers,
Dick Johnson
Penguin : Linux version 2.6.13 on an i686 machine (5589.54 BogoMips). Warning : 98.36% of all statistics are fiction.
.
I apologize for the following. I tried to kill it with the above dot :
****************************************************************
The information transmitted in this message is confidential and may be privileged. Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited. If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to [email protected] - and destroy all copies of this information, including any attachments, without reading or disclosing them.
Thank you.
Quoted 18 lines · Jan Kiszka
2005/9/6, Giridhar Pemmasani <[email protected]>:
Quoted 16 lines
Quoted 3 lines · Jan Kiszka
The only way I see is to switch stacks back on ndiswrapper API entry. But managing all those stacks correctly is challenging, as you will likely not want to create a new stack on each switching point. Rather,
This is what I had in mind before I saw this thread here. I, in fact, did some work along those lines, but it is even more complicated than you mentioned here: Windows uses different calling conventions (STDCALL, FASTCALL, CDECL) so switching stacks by copying arguments/results gets complicated. So I gave up on that approach. For X86-64 drivers we use similar approach, but for that there is only one calling convention and we don't need to switch stacks, but reshuffle arguments on stack / in registers.
Quoted 8 lines
Quoted 3 lines
I am still hoping that Andi's approach is possible (I don't understand how we can make kernel see current info from private stack).
The more I think about this the more it becomes clear that this path will be too winding, especially when compared to the effort needed to patch 8K (or more) back into the kernel as an intermediate workaround.
Is there a technical reason ("hard to implement" is a practical reason) why all stacks need to be the same size?
Signature · 3 lines
-bill davidsen ([email protected]) "The secret to procrastination is to put things off until the last possible moment - but no longer" -me
2005/9/7, Bill Davidsen <[email protected]>:
Quoted 24 lines
Quoted 23 lines · Jan Kiszka
2005/9/6, Giridhar Pemmasani <[email protected]>:
Quoted 19 lines
Quoted 3 lines · Jan Kiszka
The only way I see is to switch stacks back on ndiswrapper API entry. But managing all those stacks correctly is challenging, as you will likely not want to create a new stack on each switching point. Rather,
This is what I had in mind before I saw this thread here. I, in fact, did some work along those lines, but it is even more complicated than you mentioned here: Windows uses different calling conventions (STDCALL, FASTCALL, CDECL) so switching stacks by copying arguments/results gets complicated. So I gave up on that approach. For X86-64 drivers we use similar approach, but for that there is only one calling convention and we don't need to switch stacks, but reshuffle arguments on stack / in registers.
I am still hoping that Andi's approach is possible (I don't understand how we can make kernel see current info from private stack).
Quoted 7 lines
Quoted 3 lines
The more I think about this the more it becomes clear that this path will be too winding, especially when compared to the effort needed to patch 8K (or more) back into the kernel as an intermediate workaround.
Is there a technical reason ("hard to implement" is a practical reason) why all stacks need to be the same size?
Because of
static inline struct thread_info *current_thread_info(void)
{
struct thread_info *ti;
__asm__("andl %%esp,%0; ":"=r" (ti) : "" (~(THREAD_SIZE - 1)));
return ti;
}[include/asm-i386/thread_info.h]
which assumes that it can "round down" the stack pointer and then will find the thread_info of the current context there. Only works for identically sized stacks. Note that this function is heavily used in the kernel, either directly or indirectly. You cannot avoid it.
My current assessment regarding differently sized threads for
ndiswrapper: not feasible with vanilla kernels.
Jan
Quoted 13 lines
Quoted 2 lines
Is there a technical reason ("hard to implement" is a practical reason) why all stacks need to be the same size?
Because of
static inline struct
thread_info*current_thread_info(void){ struct thread_info *ti; __asm__("andl %%esp,%0; ":"=r" (ti) : "" (~(THREAD_SIZE - 1))); return ti; }[
include/asm-i386/thread_info.h]
Quoted 7 lines
which assumes that it can "round down" the stack pointer and then will find the
thread_infoof the current context there. Only works for identically sized stacks. Note that this function is heavily used in the kernel, either directly or indirectly. You cannot avoid it.My current assessment regarding differently sized threads for
ndiswrapper: not feasible with vanilla kernels.
If so, it is not because of this. It just means you have to go back to the idea of switching back to the original stack when the Windows driver calls into the ndis API. (It must have been way too late last night when I claimed the second stack switch wasn't necessary.)
Other issues:
- Use a semaphore to serialize access to a single ndis stack... any spinlock or interrupt state issues? (I didn't notice any.)
- Copy parameters across the stack switch - a little tricky, but far from the trickiest bit of glue in the kernel
- Preempt - looks like it has to be disabled from switching to the ndis stack to switching back because of the thread_info problem
- It is best for Linux when life is a little hard for binary-only drivers, but not completely impossible. When the smoke clears, ndis wrapper will be slightly slower than before and we will be slightly closer to having some native drivers. In the meantime, keeping the thing alive without impacting core is an interesting puzzle.
Regards,
Daniel
On Wednesday 07 September 2005 15:52, Daniel Phillips wrote:
Ah, there's another issue: an interrupt can come in when esp is on the ndis stack and above THREAD_SIZE, so do_IRQ will not find thread_info. Sorry, this one is nasty.
Regards,
Daniel
2005/9/7, Daniel Phillips <[email protected]>:
Quoted 5 lines · Daniel Phillips
Ah, there's another issue: an interrupt can come in when esp is on the ndis stack and above
THREAD_SIZE, sodo_IRQwill not findthread_info. Sorry, this one is nasty.
Oh, you already got it as well.
Jan
2005/9/7, Daniel Phillips <[email protected]>:
Quoted 18 lines
Quoted 18 lines
Quoted 2 lines
Is there a technical reason ("hard to implement" is a practical reason) why all stacks need to be the same size?
Because of
static inline struct
thread_info*current_thread_info(void){ struct thread_info *ti; __asm__("andl %%esp,%0; ":"=r" (ti) : "" (~(THREAD_SIZE - 1))); return ti; }[
include/asm-i386/thread_info.h]which assumes that it can "round down" the stack pointer and then will find the
thread_infoof the current context there. Only works for identically sized stacks. Note that this function is heavily used in the kernel, either directly or indirectly. You cannot avoid it.
Quoted 7 lines
Quoted 2 lines
My current assessment regarding differently sized threads for
ndiswrapper: not feasible with vanilla kernels.If so, it is not because of this. It just means you have to go back to the idea of switching back to the original stack when the Windows driver calls into the ndis API. (It must have been way too late last night when I claimed the second stack switch wasn't necessary.)
That alone doesn't help. You would also have to disable at least bh while windows functions are being executed, otherwise the scheduler may crash when trying to switch to some other task. Even worse with 4K
stacks: take a look at how do_IRQ works, the common interrupt entry point. It calls current_thread_info, thus expects to preempt normal kernel stacks. So, should we execute Windows driver code with IRQs off? I don't think so.
Quoted 5 lines
Other issues:
- Use a semaphore to serialize access to a single ndis stack... any spinlock or interrupt state issues? (I didn't notice any.)
Too simple approach. You cannot deny that two or more functions of ndiswrapper or the windows driver are being executed concurrently.
Quoted 4 lines
- Copy parameters across the stack switch - a little tricky, but far from the trickiest bit of glue in the kernel
Quoted 8 lines
- Preempt - looks like it has to be disabled from switching to the ndis stack to switching back because of the
thread_infoproblem- It is best for Linux when life is a little hard for binary-only drivers, but not completely impossible. When the smoke clears, ndis wrapper will be slightly slower than before and we will be slightly closer to having some native drivers. In the meantime, keeping the thing alive without impacting core is an interesting puzzle.
Ndiswrapper is already slower than native drivers are, also due to horribly implemented Windows drivers btw (the ndis model itself isn't that bad, though).
After all the issues coming up, I'm even more convinced that any effort on stack switching is better spent on moving ndiswrapper to userspace - also expensive but safer in many ways.
Jan
Quoted 3 lines · Jan Kiszka
Ndiswrapper is already slower than native drivers are, also due to horribly implemented Windows drivers btw (the ndis model itself isn't that bad, though).
Do you have any evidence to back your claims? What tests did you do to say that ndiswrapper is slower than native driver? Under X86-64 there is some overhead due to reshuffling of arguments, but it is so little that I doubt if it can be measured.
I agree that some drivers, especially old drivers, are nasty from ndiswrapper's point of view (e.g., a driver uses exception handling mechanism through "fs" register, which won't work in Linux kernel space, and another driver allocates huge chunk of memory in atomic context etc.), but they are valid under Windows.
I have seen some FUD about ndiswrapper - either on madwifi or acx100 project sites sometime back there was a list of reasons why one shouldn't use ndiswrapper, one of them is the overhead due to binary emulation. And that was from a WINE developer! If someone has ideological/moral/ethical/operational etc issues against using ndiswrapper, that is perfectly valid. But if you accept that NDIS isn't bad, I don't see why ndiswrapper would suck (the idea I mean). I myself have gripes with NDIS for wireless devices though - no support for monitor mode, quality level etc.
Before someone jumps, let me clarify that although I toil with development of ndiswrapper, I encourage people to use open source drivers when there is a choice (e.g., prism54, hostap drivers). But, as pointed out by others, there is lot of wireless networking hardware with no specifications and drivers. ndiswrapper is just for such and should a vendor provide documentation, I am sure someone will write open source driver for it. In my experience, however, vendors don't seem to be interested much with Linux support. I have requested quite a few of them to send me sample cards (the ones for which no native drivers exist) so ndiswrpaper can support them. Except for US Robotics, not a single vendor cared. A D-Link tech support guy even laughed at the idea!
In short, if you are buying hardware to run Linux, check first if there are open source drivers for it. However, if you have a wireless card that doesn't have native drivers, and if you can't/won't change hardware and you want to use it under Linux, then ndiswrapper may get the job done.
Not all of the contents in this article is in response to the quoted article, but I just wanted to clear some misconceptions about goals/use of ndiswrapper that I have noticed.
Thanks
Giri
2005/9/7, Giridhar Pemmasani <[email protected]>:
Quoted 10 lines
Quoted 3 lines · Jan Kiszka
Ndiswrapper is already slower than native drivers are, also due to horribly implemented Windows drivers btw (the ndis model itself isn't that bad, though).
Do you have any evidence to back your claims? What tests did you do to say that ndiswrapper is slower than native driver? Under X86-64 there is some overhead due to reshuffling of arguments, but it is so little that I doubt if it can be measured.
Giri, I'm not attacking your project. You know I'm sharing your pragmatic view. Performance is a pure technical issue.
Yes, I can provide some numbers around atheros devices (10-20% speed-up). And yes, I can explain why ndiswrapper suffers from certain differences of the NDIS driver model compared to the one of Linux (just consider what had to be moved to tasklets). But I think this would better be continued on the ndiswrapper list than here.
Jan
On Thu, 8 Sep 2005 01:25:20 +0200, Jan Kiszka <[email protected]> said:
Jan> Yes, I can provide some numbers around atheros devices (10-20% Jan> speed-up). And yes, I can explain why ndiswrapper suffers from
Are you comparing atheros Windows driver with ndiswrapper or madwifi with ndiswrapper? If it is latter, it is understandable. If it is former, it is not what I heard from others.
Signature · 1 line
Giri
Quoted 16 lines · Jan Kiszka
2005/9/7, Bill Davidsen <[email protected]>:
Quoted 3 lines
Is there a technical reason ("hard to implement" is a practical reason) why all stacks need to be the same size?
Because of
static inline struct
thread_info*current_thread_info(void){ struct thread_info *ti; __asm__("andl %%esp,%0; ":"=r" (ti) : "" (~(THREAD_SIZE - 1))); return ti; }
Quoted 6 lines
[
include/asm-i386/thread_info.h]which assumes that it can "round down" the stack pointer and then will find the
thread_infoof the current context there. Only works for identically sized stacks. Note that this function is heavily used in the kernel, either directly or indirectly. You cannot avoid it.
Avoiding it isn't necessary, a config option to read a variable THREAD_SIZE would solve this part of it. I looked at the implications of this, and other than a slight overhead it looks as if the problem is where to put the size :-( I think it could be done given that all threads of a process would have the same size, but I am *not* suggesting that it should be done.
Quoted 3 lines
My current assessment regarding differently sized threads for
ndiswrapper: not feasible with vanilla kernels.
Have to agree, it would take way more effort than it's worth, given that the need can be avoided by allowing user config of the stack size. It does look relatively easy to allow larger stack sizes, though. Wasn't there one driver so ill-behaved it wouldn't even run in an 8k stack?
Andi made the point that allocating server size memory in 4k blocks results in a lot of them, resulting in increased overhead in some places. Thinking about configuring the stack size, maybe it would be useful to make memory allocation block size independent of the hardware and let both be set over a wide range in config.
Signature · 3 lines
-bill davidsen ([email protected]) "The secret to procrastination is to put things off until the last possible moment - but no longer" -me
Quoted 3 lines · Giridhar Pemmasani
Quoted 2 lines · Jan Kiszka
The only way I see is to switch stacks back on ndiswrapper API entry. But managing all those stacks correctly is challenging,
There are only two stacks involved, the normal kernel stack and your new ndis stack. You save ESP of the kernel stack at the base of the ndis stack. When the Windows code calls your api, you get the ndis ESP, load the kernel ESP from the base of the ndis stack, push the ndis ESP so you can get back to the ndis code later, and continue on your merry way.
Quoted 2 lines
Quoted 2 lines
as you will likely not want to create a new stack on each switching point...
You will allocate your own stack once on driver initialization.
Quoted 5 lines
This is what I had in mind before I saw this thread here. I, in fact, did some work along those lines, but it is even more complicated than you mentioned here: Windows uses different calling conventions (STDCALL, FASTCALL, CDECL) so switching stacks by copying arguments/results gets complicated.
I missed something there. You would switch stacks before calling the Windows code and after the Windows code calls you (and respective returns) so you are always in your own code when you switch, hence you know how to copy the parameters.
Quoted 2 lines
I am still hoping that Andi's approach is possible (I don't understand how we can make kernel see current info from private stack).
He suggested you use your own private variant of current which would presumeably read a copy of current you stored at the bottom of your own stack. But I don't see why your code would ever need current while you are on the private ndis stack.
Andi, their stack will have to have a valid thread_info->task because interrupts will use it. Out of interest, could you please explain what for?
Code like u32 stack[THREAD_SIZE/sizeof(u32)] is violated by a different sized stack, but apparently not in any way that matters.
By the way, I use ndis_wrapper, thanks a lot you guys!
Regards,
Daniel
Quoted 3 lines · Daniel Phillips
Andi, their stack will have to have a valid
thread_info->taskbecause interrupts will use it. Out of interest, could you please explain what for?
No, with 4k interrupts run on their own stack with their own thread_info Or rather they mostly do. Currently do_IRQ does irq_enter which refers thread_info before switching to the interrupt stack, that order would likely need to be
exchanged.
-Andi
Quoted 9 lines · Andi Kleen
Quoted 3 lines · Daniel Phillips
Andi, their stack will have to have a valid
thread_info->taskbecause interrupts will use it. Out of interest, could you please explain what for?No, with 4k interrupts run on their own stack with their own
thread_infoOr rather they mostly do. Currentlydo_IRQdoesirq_enterwhich refersthread_infobefore switching to the interrupt stack, that order would likely need to be exchanged.
But then how would thread_info->task on the irq stack ever get initialized?
My "what for" question was re why interrupt routines even need a valid current. I see one answer out there on the web: statistical profiling. Is that it?
Regards,
Daniel
Quoted 5 lines · Daniel Phillips
But then how would
thread_info->taskon the irq stack ever get initialized?My "what for" question was re why interrupt routines even need a valid current. I see one answer out there on the web: statistical profiling. Is that it?
scheduler_tick - This is called from the timer interrupt, and it definitely needs a valid current.
-- Steve
Daniel> There are only two stacks involved, the normal kernel Daniel> stack and your new ndis stack. You save ESP of the kernel Daniel> stack at the base of the ndis stack. When the Windows Daniel> code calls your api, you get the ndis ESP, load the kernel Daniel> ESP from the base of the ndis stack, push the ndis ESP so Daniel> you can get back to the ndis code later, and continue on Daniel> your merry way.
[...]
Daniel> You will allocate your own stack once on driver Daniel> initialization.
I'm not quite sure it's this trivial. Obviously there are more than two stacks involved, since there is more than one kernel stack! (One per task plus IRQ stacks) This is more than just a theoretical problem. It seems entirely possible that more than one task could be in the driver, and clearly they each need their own stack.
So it's going to be at least a little harder than allocating a single stack for NDIS use when the driver starts up.
I personally like the idea raised elsewhere in this thread of running the Windows driver in userspace by proxying interrupts, PCI access, etc. That seems more robust and probably allows some cool reverse engineering hacks.
- R.
Quoted 10 lines · Roland Dreier
Daniel> There are only two stacks involved, the normal kernel Daniel> stack and your new ndis stack. You save ESP of the kernel Daniel> stack at the base of the ndis stack. When the Windows Daniel> code calls your api, you get the ndis ESP, load the kernel Daniel> ESP from the base of the ndis stack, push the ndis ESP so Daniel> you can get back to the ndis code later, and continue on Daniel> your merry way.
[...]
Quoted 8 lines
Daniel> You will allocate your own stack once on driver Daniel> initialization.
I'm not quite sure it's this trivial. Obviously there are more than two stacks involved, since there is more than one kernel stack! (One per task plus IRQ stacks) This is more than just a theoretical problem. It seems entirely possible that more than one task could be in the driver, and clearly they each need their own stack.
Semaphore :-)
Do you expect this to be heavily contended? On a very quick run through the code, it seems you don't hold any spinlocks going into the driver from process context. Interrupts... they better fit into a 4K stack or it's game over. Preemption while on the ndis stack... you can always disable preemption in this region, but the semaphore should protect you. Task killed while preempted... I dunno.
Quoted 7 lines
So it's going to be at least a little harder than allocating a single stack for NDIS use when the driver starts up.
I personally like the idea raised elsewhere in this thread of running the Windows driver in userspace by proxying interrupts, PCI access, etc. That seems more robust and probably allows some cool reverse engineering hacks.
I expect the userspace approach will be a lot more work and a lot more overhead too, but then again it sounds like loads of fun.
Regards,
Daniel
On Tue, 6 Sep 2005 18:19:45 -0400, Daniel Phillips <[email protected]> said:
Daniel> There are only two stacks involved, the normal kernel stack Daniel> and your new ndis stack. You save ESP of the kernel stack
Sadly, that is not the case: Some drivers, especially USB drivers, create multiple threads (those threads are created through ndiswrapper, so if any massaging needs to be done, ndiswrapper can do that). However, it is not multiple threads that is the problem, but switching of stacks. On transition from Windows function to Linux function, we need to copy the arguments that are in Windows stack into Linux stack so Linux function gets the arguments. We need to do same thing in the reverse direction. As mentioned before, this gets complicated with different calling conventions and different number of arguments to functions. Moreover, if Linux kernel decides to suspend a thread while it is executing Windows function, kernel sees an invalid stack.
Daniel> You will allocate your own stack once on driver Daniel> initialization.
Rather, whenever a new thread is created.
Daniel> I missed something there. You would switch stacks before Daniel> calling the Windows code and after the Windows code calls Daniel> you (and respective returns) so you are always in your own Daniel> code when you switch, hence you know how to copy the Daniel> parameters.
This is not impossible, but messy (even if the very idea ndiswrapper itself sounds scary to some).
Daniel> By the way, I use ndis_wrapper, thanks a lot you guys!
Good to know you are happy.
Signature · 1 line
Giri
Quoted 1 line · Daniel Phillips
There are only two stacks involved, the normal kernel stack and your new ndis stack. You save ESP of the kernel stack at the base of the ndis stack. When the Windows code calls your api, you get the ndis ESP, load the kernel ESP from the base of the ndis stack, push the ndis ESP so you can get back to the ndis code later, and continue on your merry way.
With CONFIG_PREEMPT, this will still cause trouble due to lack of "current" task info on the NDIS stack.
One option is to copy (duplicate) the bottom-of-stack info when switching to the NDIS stack.
Another option is to stick a Mutex around any use of the NDIS stack when calling into the foreign driver (might be done like this already??), which will prevent PREEMPTion during the call.
Cheers
Quoted 10 lines · Mark Lord
Quoted 5 lines · Daniel Phillips
There are only two stacks involved, the normal kernel stack and your new ndis stack. You save ESP of the kernel stack at the base of the ndis stack. When the Windows code calls your api, you get the ndis ESP, load the kernel ESP from the base of the ndis stack, push the ndis ESP so you can get back to the ndis code later, and continue on your merry way.
With
CONFIG_PREEMPT, this will still cause trouble due to lack of "current" task info on the NDIS stack.
Quoted 6 lines
One option is to copy (duplicate) the bottom-of-stack info when switching to the NDIS stack.
Another option is to stick a Mutex around any use of the NDIS stack when calling into the foreign driver (might be done like this already??), which will prevent PREEMPTion during the call.
Isn't it bad to rely on taking a lock disabling preemption as a side effect? For example it will break on PREEMPT_RT (not merged yet, but still...). If you really just need preemption disabled/reenabled can't you just do it explicitly?
Lee
Quoted 6 lines · Mark Lord
Quoted 5 lines · Daniel Phillips
There are only two stacks involved, the normal kernel stack and your new ndis stack. You save ESP of the kernel stack at the base of the ndis stack. When the Windows code calls your api, you get the ndis ESP, load the kernel ESP from the base of the ndis stack, push the ndis ESP so you can get back to the ndis code later, and continue on your merry way.
I must have been smoking something when I convinced myself that the driver can't call into the kernel without switching back to the kernel stack. But this is wrong, as long as ->task and ->previous_esp are initialized, staying on the bigger stack looks fine (previous_esp is apparently used only for backtrace).
Quoted 5 lines
With
CONFIG_PREEMPT, this will still cause trouble due to lack of "current" task info on the NDIS stack.One option is to copy (duplicate) the bottom-of-stack info when switching to the NDIS stack.
Yes, just like do_IRQ.
Quoted 2 lines
Another option is to stick a Mutex around any use of the NDIS stack when calling into the foreign driver (might be done like this already??),
There is no mutex now, but this is the easy way to get by with just one ndis stack.
Quoted 1 line
which will prevent PREEMPTion during the call.
We have preempt_enable/disable for that. But I am not sure preemption needs to be disabled.
Regards,
Daniel
Quoted 3 lines · Daniel Phillips
...as long as ->task and ->previous_esp are initialized, staying on the bigger stack looks fine (
previous_espis apparently used only for backtrace) ... just likedo_IRQ.
Ahem, but let me note before somebody else does: it isn't interrupt context, it is normal process context - while an interrupt can ignore most of the thread_info fields, a normal process has to worry about all 9. To be on the safe side, the first 8 need to be copied into and out of the ndis stack, with preempt disabled until after the stack switch.
Regards,
Daniel
Quoted 11 lines · Alex Davis
Quoted 1 line
Please don't tell me to "care for closed-source drivers".
ndiswrapper is NOT closed source. And I'm not asking you to "care".
Quoted 2 lines
I don't want the pain of debugging crashes on the machines which run unknown code in kernel space.
I'm not asking you to debug crashes. I'm simply requesting that the kernel stack size situation remain as it is: with 8K as the default and 4K configurable.
I can be happy with 4K as the default, everything I use *except* ndiswrapper seems to run fine (I don't currently need fancy filesystems) but laptops seem to include a lot of unsupported hardware, which can't be replaced due to resources (money, slots, batter life).
Signature · 3 lines
-bill davidsen ([email protected]) "The secret to procrastination is to put things off until the last possible moment - but no longer" -me
Quoted 9 lines · --- Bill Davidsen
Quoted 8 lines · Alex Davis
Quoted 1 line
Please don't tell me to "care for closed-source drivers".
ndiswrapper is NOT closed source. And I'm not asking you to "care".
Quoted 2 lines
I don't want the pain of debugging crashes on the machines which run unknown code in kernel space.
Quoted 9 lines
Quoted 3 lines
I'm not asking you to debug crashes. I'm simply requesting that the kernel stack size situation remain as it is: with 8K as the default and 4K configurable.
I can be happy with 4K as the default, everything I use *except* ndiswrapper seems to run fine (I don't currently need fancy filesystems) but laptops seem to include a lot of unsupported hardware, which can't be replaced due to resources (money, slots, batter life).
I could live with any default, as long as it's configurable. The intent here, however, is to take away the option. That's what I have an issue with.
Is there any problem caused by letting stack size be configurable to any (sane) arbitrary maximum value (e.g. 32K)?
Quoted 4 lines
-bill davidsen ([email protected])
"The secret to procrastination is to put things off until the
last possible moment - but no longer" -me
I code, therefore I am
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com