<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, May 12, 2020 at 9:27 AM Gedare Bloom <<a href="mailto:gedare@rtems.org" target="_blank">gedare@rtems.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Thu, May 7, 2020 at 9:59 PM Hesham Almatary<br>
<<a href="mailto:hesham.almatary@cl.cam.ac.uk" target="_blank">hesham.almatary@cl.cam.ac.uk</a>> wrote:<br>
><br>
> Hello Utkarsh,<br>
><br>
> I'd suggest you don't spend too much efforts on setting up BBB<br>
> hardware if you haven't already. Debugging on QEMU with GDB is way<br>
> easier, and you can consider either qemu-xilinx-zynq-a9 or rpi2 BSPs.<br>
> Later, you can move your code to BBB if you want, since both are based<br>
> on ARMv7.<br>
+1<br>
<br>
Past work has also used psim successfully I thought? Or am I mistaken there.<br>
<br>
><br>
> On Thu, 7 May 2020 at 18:26, Utkarsh Rai <<a href="mailto:utkarsh.rai60@gmail.com" target="_blank">utkarsh.rai60@gmail.com</a>> wrote:<br>
> ><br>
> > Hello,<br>
> > This is to ensure that all the interested parties are on the same page before I start my project and can give their invaluable feedback.<br>
Excellent, thank you for getting the initiative.<br>
<br>
I'll be taking on the primary mentorship for your project, with<br>
support from the co-mentors (Peter, Hesham, Sebastian). For now, I<br>
prefer you to continue to make your presence on the mailing list. We<br>
will establish other forms of communication as needed and will take on<br>
IRC meetings once coding begins in earnest.<br>
<br>
> > My GSoC project, providing user-configurable thread stack protection, requires adding architecture-specific low-level support as well as high-level API support. I will be starting my project with ARMv7-A (on BBB) based MMU since RTEMS already has quite mature support for it. As already mentioned in my proposal I will be focusing more on the High-level interface and let it drive whatever further low-level support is needed.<br>
> > Once the application uses MMU for thread stack address generation each thread will be automatically protected as the page tables other than that of the executing thread would be made dormant. When the user has to share thread stacks they will have to obtain the stack attributes of the threads to be shared by pthread_attr_getstack() and then get a file descriptor of the memory to be mapped by a call to shm_open() and finally map this to the stack of the other thread through<br>
> > mmap(), this is the POSIX compliant way I could think of. Now at the low level, it means mapping the page table of the thread to be shared into the address space of the executing thread. This is an area where the low-level support has to be provided. At the high-level, this means providing support to mmap and shared-memory interface as mmap provides support for a file by simply<br>
> > copying the memory from the file to the destination. For shared memory objects it can<br>
> > provide read/write access but cannot provide restriction of write/read access. One of the areas that I have to look into more detail is thread context-switch, as after every context switch the TLBs need to be flushed and reinitialized lest we get an invalid address for the executing thread. Since context-switch is low-level architecture-specific, this also has to be provided with more support.<br>
<br>
This is really dense text. Try to break apart your writing a little<br>
bit to help clarify your thoughts. You should also translate some of<br>
your proposal into a wiki page if you haven't started that yet, and a<br>
blog post. Both of those will help to focus your thoughts into words.<br>
<br>
"mapping the page table" is not meaningful to me. I think you mean<br>
something like "mapping a page from the page table"? </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> Will the design<br>
support sharing task stacks using MPUs with 4 regions? 8? (It seems<br>
challenging to me, but might be possible in some limited<br>
configurations. Having support for those kinds of targets might still<br>
be useful, with the caveat that sharing stacks is not possible.) <br></blockquote><div> </div><div>I will have to look into this in a bit more detail before I can give you a comprehensive answer.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
The first step is to get a BSP running that has sufficient<br>
capabilities for you to test out memory protection with. Do a little<br>
bit of digging, but definitely simulation is the way to go.<br></blockquote><div> </div><div>As suggested by Hesham, I have been able to run the qemu-Xilinx-zynq-a9 BSP on qemu and I have learned how to debug it through GDB.</div><div>The BSP supports memory protection and as pointed out once I get it done on this, I can move my code for other BSP with ARMv7 (RPI, BBB ).</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
The second step from my perspective is to determine how to introduce<br>
strict isolation between task stacks. Don't worry about sharing at<br>
this stage, but rather can you completely isolate tasks? Then you can<br>
start to poke holes in the isolation.<br></blockquote><div> </div><div> My understanding of this is that to completely isolate the tasks and page tables of the task will be placed in two separate regions (user and system mode respectively), the page tables will be accessed only by the kernel code and not by the application. This will prevent dormant tasks from interfering with the current task through the application code.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
As you say, you'll also need to start to understand the context switch<br>
code. Start looking into it to determine where you might think to<br>
implement changing the address space of the executing thread. Another<br>
challenge is that RTEMS can dispatch to a new task from the interrupt<br>
handler, which may cause some problems for you as well to handle. </blockquote><div> </div><div> The above way of page-table and task separation should handle the interrupt case as most of the interrupts are executed in the system mode.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Have you figured out where in the code thread stacks are allocated?<br>
How do you plan to make the thread stacks known to other threads?<br></blockquote><div> </div><div>If I understand your question correctly this would be useful during stack sharing. Stack sharing, as I described earlier would be through explicit calls to mmap(), shm_open(). For obtaining the thread stack size and address the user will first have to make a call to pthread_attr_getstack*(). Now, this can return the attributes the user explicitly sets during pthread_create(), or as the RTEMS docs describe the memory will be allocated from the RTEMS workspace area as described <a href="https://docs.rtems.org/branches/master/c-user/config/task-stack-alloc.html" target="_blank">here</a>. I will have to look into it more detail as this is BSP specific and any stack configuration will have to be done after the initialization of the MPU.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">TLB shootdown can be extremely expensive. Try to find ways to optimize<br>
that cost earlier rather than later. (One of those cases where<br>
premature optimization will be acceptable.) Tagged TLB architectures<br>
or those with "superpages" may incur less overhead if you can<br>
selectively shoot-down the entry (entries) used for task stacks.<br></blockquote><div><br></div><div>Added to my TO-DO list. </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
A final thought is that the method to configure this support is<br>
necessary. Configuration is undergoing some heavy changes lately, and<br>
application-level configuration is going to be completely different in<br>
rtems6. You may want to consider raising a new thread with CC to<br>
Sebastian to get his input on how the best way to configure something<br>
like this might look, now and in the future. I would have leaned<br>
toward a high-level configure switch (--enable-task-protection) in the<br>
past, but now I don't know. This capability is however something that<br>
should be considered disabled by default due to the extra overhead. </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Gedare<br>
<br>
> > Kindly provide your feedback if I have missed something or I have a wrong idea about it.<br>
> ><br>
> > Regards,<br>
> > Utkarsh Rai.<br>
> ><br>
> > _______________________________________________<br>
> > devel mailing list<br>
> > <a href="mailto:devel@rtems.org" target="_blank">devel@rtems.org</a><br>
> > <a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.rtems.org/mailman/listinfo/devel</a><br>
> _______________________________________________<br>
> devel mailing list<br>
> <a href="mailto:devel@rtems.org" target="_blank">devel@rtems.org</a><br>
> <a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.rtems.org/mailman/listinfo/devel</a><br>
</blockquote></div></div>