Skip to content

Commit 0c5f83c

Browse files
Mel Gormantorvalds
authored andcommitted
mm: numa: do not clear PTE for pte_numa update
The TLB must be flushed if the PTE is updated but change_pte_range is clearing the PTE while marking PTEs pte_numa without necessarily flushing the TLB if it reinserts the same entry. Without the flush, it's conceivable that two processors have different TLBs for the same virtual address and at the very least it would generate spurious faults. This patch only unmaps the pages in change_pte_range for a full protection change. [riel@redhat.com: write pte_numa pte back to the page tables] Signed-off-by: Mel Gorman <mgorman@suse.de> Signed-off-by: Rik van Riel <riel@redhat.com> Reviewed-by: Rik van Riel <riel@redhat.com> Cc: Alex Thorlton <athorlton@sgi.com> Cc: Chegu Vinod <chegu_vinod@hp.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 5a6dac3 commit 0c5f83c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

mm/mprotect.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,19 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
5252
pte_t ptent;
5353
bool updated = false;
5454

55-
ptent = ptep_modify_prot_start(mm, addr, pte);
5655
if (!prot_numa) {
56+
ptent = ptep_modify_prot_start(mm, addr, pte);
5757
ptent = pte_modify(ptent, newprot);
5858
updated = true;
5959
} else {
6060
struct page *page;
6161

62+
ptent = *pte;
6263
page = vm_normal_page(vma, addr, oldpte);
6364
if (page) {
6465
if (!pte_numa(oldpte)) {
6566
ptent = pte_mknuma(ptent);
67+
set_pte_at(mm, addr, pte, ptent);
6668
updated = true;
6769
}
6870
}
@@ -79,7 +81,10 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
7981

8082
if (updated)
8183
pages++;
82-
ptep_modify_prot_commit(mm, addr, pte, ptent);
84+
85+
/* Only !prot_numa always clears the pte */
86+
if (!prot_numa)
87+
ptep_modify_prot_commit(mm, addr, pte, ptent);
8388
} else if (IS_ENABLED(CONFIG_MIGRATION) && !pte_file(oldpte)) {
8489
swp_entry_t entry = pte_to_swp_entry(oldpte);
8590

0 commit comments

Comments
 (0)