Hi, Currently TLS wraparound segments are a problem in Xen, since the kernel needs to be protected by keeping the user space segments out of kernel space. A few weeks ago Roland, Jakub and myself brainstormed about this problem. One of the things that came up is that the positive (glibc private data) and -ve (TLS) data are not generally used at the same time. This lead to one of us (I don''t remember whom, sorry) came up with the idea of "flipping the segment around" whenever a segment violation happens on a segment that should have been 4GB in size, and the fault happens on an address between 0 and TASK_SIZE. Having glanced briefly at some documentation on how the segments works, it looks like it should be possible to convert the positive (clipped) segment into an Expands-down segment, allowing TLS to work transparently without needing to emulate any instructions. Provided the segment doesn''t need to be "flipped" too often, this could provide for reasonably high performance TLS functionality, without the potential problems that instruction rewriting brings with it. What do you think ? -- "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." - Brian W. Kernighan ------------------------------------------------------- This SF.net email is sponsored by: IT Product Guide on ITManagersJournal Use IT products in your business? Tell us what you think of them. Give us Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more http://productguide.itmanagersjournal.com/guidepromo.tmpl _______________________________________________ Xen-devel mailing list Xen-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/xen-devel
> A few weeks ago Roland, Jakub and myself brainstormed > about this problem. One of the things that came up is > that the positive (glibc private data) and -ve (TLS) > data are not generally used at the same time.Well, that''s not really true. Small positive offsets are used all the time (every syscall, for example, and all of pthreads internals). Negative offsets are used for actual ELF TLS accesses (__thread variables), which now include `errno'' in the standard glibc build. So depending on your code one or the other might be most common, but you are unlikely ever to have a program run that doesn''t flip back and forth a fair bit. I really don''t have any clue what the fault-segment-flip-resume overhead vs the fault-emulate-resume overhead is. You''d just have to test it out. I am still brainstorming about this, but I will need to do some experiments to figure out how some other funny ways of using segments actually work. ------------------------------------------------------- This SF.net email is sponsored by: IT Product Guide on ITManagersJournal Use IT products in your business? Tell us what you think of them. Give us Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more http://productguide.itmanagersjournal.com/guidepromo.tmpl _______________________________________________ Xen-devel mailing list Xen-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/xen-devel
On Tue, Oct 19, 2004 at 12:45:01PM -0700, Roland McGrath wrote:> > A few weeks ago Roland, Jakub and myself brainstormed > > about this problem. One of the things that came up is > > that the positive (glibc private data) and -ve (TLS) > > data are not generally used at the same time. > > I am still brainstorming about this, but I will need to do some experiments > to figure out how some other funny ways of using segments actually work.If you allow modification of the user code by xen, then you can do some tricks. E.g. if an application doesn''t ever use %fs segment, you could rewrite the positive accesses from %gs segment prefix to %fs segment prefix and have %gs be an expand-down segment while %fs expand-up segment with the same base. The problem with this is that things break badly if the application wants to use %fs for its own purposes, or if it pokes at its own code (writing can be avoided by temporarily write protecting any pages where a rewrite has happened, but reading cannot). There is always the PaX trick - halving the address space and having non-overlapping %cs and %ds segments with some pages shared in between, but perhaps that''s too complicated. Jakub ------------------------------------------------------- This SF.net email is sponsored by: IT Product Guide on ITManagersJournal Use IT products in your business? Tell us what you think of them. Give us Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more http://productguide.itmanagersjournal.com/guidepromo.tmpl _______________________________________________ Xen-devel mailing list Xen-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/xen-devel
Yes, I think this would work! :-) I''ll play around with expands-down segments a bit and, if they work as desribed, I''ll add the flipping idea to Xen. I''m pretty sure it''ll save us quite a few emulations, particularly if the +ve offsets are accessed only infrequently. It''ll be interesting to see if it''s good enough to be able to remove the warning about /lib/tls. Thanks, Keir> Hi, > > Currently TLS wraparound segments are a problem in Xen, > since the kernel needs to be protected by keeping the > user space segments out of kernel space. > > A few weeks ago Roland, Jakub and myself brainstormed > about this problem. One of the things that came up is > that the positive (glibc private data) and -ve (TLS) > data are not generally used at the same time. > > This lead to one of us (I don''t remember whom, sorry) > came up with the idea of "flipping the segment around" > whenever a segment violation happens on a segment that > should have been 4GB in size, and the fault happens on > an address between 0 and TASK_SIZE. > > Having glanced briefly at some documentation on how > the segments works, it looks like it should be possible > to convert the positive (clipped) segment into an > Expands-down segment, allowing TLS to work transparently > without needing to emulate any instructions. > > Provided the segment doesn''t need to be "flipped" too > often, this could provide for reasonably high performance > TLS functionality, without the potential problems that > instruction rewriting brings with it. > > What do you think ?------------------------------------------------------- This SF.net email is sponsored by: IT Product Guide on ITManagersJournal Use IT products in your business? Tell us what you think of them. Give us Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more http://productguide.itmanagersjournal.com/guidepromo.tmpl _______________________________________________ Xen-devel mailing list Xen-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/xen-devel