Re: [PATCH] x86/mm: Flush before free in remove_pagetable()

From: Williams, Dan J
Date: Tue Aug 24 2021 - 12:45:10 EST


On Wed, 2021-08-18 at 15:10 -0700, Rick Edgecombe wrote:
>
> In remove_pagetable(), page tables may be freed before the TLB is
> flushed. The upper page tables are zapped before freeing the lower
> levels. However, without the flush the lower tables can still remain in
> paging-structure caches and so data that is written to the re-allocated
> page can control these mappings. For some reason there is only a flush
> lower down in remove_pte_table(), however, this will not be hit in the
> case of large pages on the direct map which is common.

It's also common for device-dax reconfiguration which we are in the
process of adding udev automation to replug devices from ZONE_DEVICE to
ZONE_{NORMAL,MOVABLE} automatically depending on what setup was
estabished on the previous boot. So even if unpriveleged userspace
can't force this, there may be more opportunities to find this gap in
the future.

>
> Currently remove_pagetable() is called from a few places in the
> hot unplug codepath and memremap unmapping operations.
>
> To properly tear down these mappings, gather the page tables using a
> simple linked list based in the table's struct page. Then flush the TLB
> before actually freeing the pages.
>
> Cc: stable@xxxxxxxxxxxxxxx
> Fixes: ae9aae9eda2d ("memory-hotplug: common APIs to support page tables hot-remove")
> Acked-by: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
> Signed-off-by: Rick Edgecombe <rick.p.edgecombe@xxxxxxxxx>

Acked-by: Dan Williams <dan.j.williams@xxxxxxxxx>