<div dir="ltr">Hi Arun,<div><br></div><div>Thanks for your responses. Here&#39;s some additional details.</div><div><br></div><div>We were calling memblock_reserve() very early in the game when even kernel is calling to do the reservation.</div><div>The reason I think memblock_reserve() was not working was that kernel was already reserving a big chunk (0 to 0xbfffffff). Our page which was falling in between would become a no-op.</div><div>Call to request_mem_region() fails when the page is already reserved by the kernel.</div><div>It&#39;s only when we removed it does the call to request_mem_region() succeed.</div><div><br></div><div>About the corruption, What my understanding was, it cannot be caused by any application, since it will not have any privilege to modify the text segment. But are you saying that any application can still do it via /dev/mem route? In our system we have couple of other suspects as well which can cause such a corruption (DMA, DSP etc), It is unlike a standard linux machine running some application.</div><div><br></div><div>Another question, will the removed page be off-limits to the buddy allocator as well if we call it soon enough?</div><div>(That&#39;s what it looks like based on our tests but would be good to get a confirmation of it)</div><div>Since the problem is not easy to reproduce, it&#39;s difficult to be certain that we have successfully avoided the corruption. (We ran 300+ iterations of a test successfully. The problem could be seen within 20-80 iterations)</div><div><br></div><div>-Thanks</div><div>Nikhil</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 3, 2016 at 6:15 PM, Arun Sudhilal <span dir="ltr">&lt;<a href="mailto:getarunks@gmail.com" target="_blank">getarunks@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Mon, Oct 3, 2016 at 6:02 PM, Arun Sudhilal &lt;<a href="mailto:getarunks@gmail.com">getarunks@gmail.com</a>&gt; wrote:<br>
&gt; Hello Nikhil,<br>
&gt;<br>
</span><span class="">&gt; On Wed, Sep 28, 2016 at 6:55 PM, Nikhil Utane<br>
&gt; &lt;<a href="mailto:nikhil.subscribed@gmail.com">nikhil.subscribed@gmail.com</a>&gt; wrote:<br>
&gt;&gt; base1 = 0xA4D000; size1=0x1000;<br>
&gt;&gt; memblock_reserve (base1, size1);<br>
<br>
</span>Most probably your memblock_reserve() function is not affecting. It<br>
depends on when you are calling this function as explained<br>
earlier(after or before hand-off to buddy allocator).<br>
<br>
Lets say you are calling it pretty late and if<br>
CONFIG_ARCH_DISCARD_MEMBLOCK is disabled in your build,<br>
memblock_reserve() just go ahead and modifies the memblock structures<br>
but does not have any effect as buddy allocator has already taken<br>
control of memory management. That might be the reason you were not<br>
able to make this page reserved.<br>
<div class="HOEnZb"><div class="h5"><br>
&gt;&gt;<br>
&gt;&gt; (In a separate static driver code)<br>
&gt;&gt; request_mem_region_exclusive (0x00A4D000, 4096, &quot;csSIGILL&quot;)<br>
&gt;<br>
&gt; Thanks for details. Looks strange.<br>
&gt; One possible case I can think of is, when you use<br>
&gt; request_mem_region_exclusive, user space cannot access it using<br>
&gt; /dev/mem. May be any of your user space task is corrupting this region<br>
&gt; before. now he is not able to access this location because you have<br>
&gt; marked it as EXCLUSIVE for kernel.<br>
&gt;<br>
&gt;&gt;<br>
&gt;&gt; If a driver requests for a memory region, shouldn&#39;t the kernel then not<br>
&gt;&gt; allocate it for any other purpose?<br>
&gt; To remove pages from kernel allocation, you need to have only<br>
&gt; successful invocation of memblock_reserve() function.<br>
&gt;<br>
&gt; Regards,<br>
&gt; Arun<br>
&gt;<br>
&gt;&gt;<br>
&gt;&gt; -Regards<br>
&gt;&gt; Nikhil<br>
&gt;&gt;<br>
&gt;&gt; On Wed, Sep 28, 2016 at 3:12 PM, Arun Sudhilal &lt;<a href="mailto:getarunks@gmail.com">getarunks@gmail.com</a>&gt; wrote:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Hello Nikhil,<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; On Wed, Sep 28, 2016 at 2:41 PM, Nikhil Utane<br>
&gt;&gt;&gt; &lt;<a href="mailto:nikhil.subscribed@gmail.com">nikhil.subscribed@gmail.com</a>&gt; wrote:<br>
&gt;&gt;&gt; &gt; Arun,<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; What seems to have done the trick is calling memblock_remove() followed<br>
&gt;&gt;&gt; &gt; by a<br>
&gt;&gt;&gt; &gt; call to request_mem_region(). This creates a hole which can be confirmed<br>
&gt;&gt;&gt; &gt; in<br>
&gt;&gt;&gt; &gt; the output of /proc/iomem.<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; Do you see any issue with this approach?<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; I really don&#39;t know how it works for you. Marking address of a page as<br>
&gt;&gt;&gt; iomem.  How buddy allocator ignores this page?<br>
&gt;&gt;&gt; request_mem_region() is a way of managing IO resource memory, to avoid<br>
&gt;&gt;&gt; two drivers using same IO memory. It has not relation with buddy<br>
&gt;&gt;&gt; allocator.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Can you post code snippet?<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Regards,<br>
&gt;&gt;&gt; Arun<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; -Thanks<br>
&gt;&gt;&gt; &gt; Nikhil<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; On Tue, Sep 27, 2016 at 4:14 PM, Arun Sudhilal &lt;<a href="mailto:getarunks@gmail.com">getarunks@gmail.com</a>&gt;<br>
&gt;&gt;&gt; &gt; wrote:<br>
&gt;&gt;&gt; &gt;&gt;<br>
&gt;&gt;&gt; &gt;&gt; Hello Nikhil,<br>
&gt;&gt;&gt; &gt;&gt;<br>
&gt;&gt;&gt; &gt;&gt; On Fri, Sep 9, 2016 at 7:01 AM, Nikhil Utane<br>
&gt;&gt;&gt; &gt;&gt; &lt;<a href="mailto:nikhil.subscribed@gmail.com">nikhil.subscribed@gmail.com</a>&gt; wrote:<br>
&gt;&gt;&gt; &gt;&gt; &gt; I want to reserve a physical memory page with a fixed PFN. I do not<br>
&gt;&gt;&gt; &gt;&gt; &gt; want<br>
&gt;&gt;&gt; &gt;&gt; &gt; this page to be used by anyone else. I am calling memblock_reserve()<br>
&gt;&gt;&gt; &gt;&gt; &gt; to<br>
&gt;&gt;&gt; &gt;&gt; &gt; supposedly reserve the page. I am writing some content into this<br>
&gt;&gt;&gt; &gt;&gt; &gt; page.<br>
&gt;&gt;&gt; &gt;&gt; &gt; What<br>
&gt;&gt;&gt; &gt;&gt; &gt; I see is that during some runs the content of this page is modified<br>
&gt;&gt;&gt; &gt;&gt; &gt; (either<br>
&gt;&gt;&gt; &gt;&gt; &gt; fully or sometimes partially). In few runs, I see it as intact. Is it<br>
&gt;&gt;&gt; &gt;&gt; &gt; expected that even after calling memblock_reserve() the kernel can<br>
&gt;&gt;&gt; &gt;&gt; &gt; allocate<br>
&gt;&gt;&gt; &gt;&gt; &gt; this physical page for any other purpose? How is memblock_remove()<br>
&gt;&gt;&gt; &gt;&gt; &gt; different<br>
&gt;&gt;&gt; &gt;&gt; &gt; from memblock_reserve? I tried reading up but didn&#39;t see any useful<br>
&gt;&gt;&gt; &gt;&gt; &gt; information. What I understood is memblock_remove will completely<br>
&gt;&gt;&gt; &gt;&gt; &gt; remove<br>
&gt;&gt;&gt; &gt;&gt; &gt; from kernel&#39;s allocation mechanism. Should I then be using remove<br>
&gt;&gt;&gt; &gt;&gt; &gt; instead of<br>
&gt;&gt;&gt; &gt;&gt; &gt; reserve?<br>
&gt;&gt;&gt; &gt;&gt;<br>
&gt;&gt;&gt; &gt;&gt; when a DT entry is added to  #reserved-memory node, what<br>
&gt;&gt;&gt; &gt;&gt; drivers/of/fdt.c does is to call memblock_remove() and<br>
&gt;&gt;&gt; &gt;&gt; memblock_reserve().<br>
&gt;&gt;&gt; &gt;&gt; This happens after the memblock driver is initialized but before buddy<br>
&gt;&gt;&gt; &gt;&gt; allocator up. Did you try this approach? This should work for you.<br>
&gt;&gt;&gt; &gt;&gt;<br>
&gt;&gt;&gt; &gt;&gt; Only option once the kernel boot is complete is to try out the<br>
&gt;&gt;&gt; &gt;&gt; technique what mm/memory_hotplug.c does while offline memory.<br>
&gt;&gt;&gt; &gt;&gt; isolate_page_range and then migrate.<br>
&gt;&gt;&gt; &gt;&gt;<br>
&gt;&gt;&gt; &gt;&gt; Regards,<br>
&gt;&gt;&gt; &gt;&gt; Arun<br>
&gt;&gt;&gt; &gt;&gt;<br>
&gt;&gt;&gt; &gt;&gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt; -Thanks<br>
&gt;&gt;&gt; &gt;&gt; &gt; Nikhil<br>
&gt;&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt; ______________________________<wbr>_________________<br>
&gt;&gt;&gt; &gt;&gt; &gt; Kernelnewbies mailing list<br>
&gt;&gt;&gt; &gt;&gt; &gt; <a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.<wbr>org</a><br>
&gt;&gt;&gt; &gt;&gt; &gt; <a href="https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" rel="noreferrer" target="_blank">https://lists.kernelnewbies.<wbr>org/mailman/listinfo/<wbr>kernelnewbies</a><br>
&gt;&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
</div></div></blockquote></div><br></div>