Re: [PATCH 17/19] x86, mpx: rewrite unmap code

Thomas Gleixner
2015-05-18T21:55:16Z

On Fri, 8 May 2015, Dave Hansen wrote:
> The MPX code needs to clear out bounds tables for memory which
> is no longer in use. We do this when a userspace mapping is
> torn down (unmapped).
>
> There are two modes:
> 1. An entire bounds table becomes unused, and can be freed
> and its pointer removed from the bounds directory. This
> happens either when a large mapping is torn down, or when
> a small mapping is torn down and it is the last mapping
> "covered" by a bounds table.
> 2. Only part of a bounds table becomes unused, in which case
> we free the backing memory as if MADV_DONTNEED was called.
>
> The old code was a spaghetti mess of "edge" bounds tables
> where the edges were handled specially, even if we were
> unmapping an entire one. Non-edge bounds tables are always
> fully unmapped, but share a different code path from the edge
> ones. The old code had a bug where it was unmapping too much
> memory. I worked on fixing it for two days and gave up.
>
> I didn't write the original code. I didn't particularly like
> it, but it worked, so I left it. After my debug session, I
> realized it was undebuggagle *and* buggy, so out it went.
>
> I also wrote a new unmapping test program which uncovers bugs
> pretty nicely.

Very appreciated. This is really readable now.

Reviewed-by: Thomas Gleixner <tglx@linutronix.de>