Skip to contentSkip to conversation

mm: Fix modifying of page protection by insert_pfn()

PATCH Applied Jan Kara 5 participants 10 messages Mar 11, 2019 – Mar 28, 2019

Subsystems (3)
lore
Share & tools
lore

Jan Kara

author
#0 lore raw

PATCH 1/1 mm: Fix modifying of page protection by insert_pfn()

Aneesh has reported that PPC triggers the following warning when excercising DAX code:

[c00000000007610c] set_pte_at+0x3c/0x190
LR [c000000000378628] insert_pfn+0x208/0x280

Call Trace:

[c0000002125df980] [8000000000000104] 0x8000000000000104 (unreliable) [c0000002125df9c0] [c000000000378488] insert_pfn+0x68/0x280 [c0000002125dfa30] [c0000000004a5494] dax_iomap_pte_fault.isra.7+0x734/0xa40 [c0000002125dfb50] [c000000000627250] __xfs_filemap_fault+0x280/0x2d0 [c0000002125dfbb0] [c000000000373abc] do_wp_page+0x48c/0xa40 [c0000002125dfc00] [c000000000379170] __handle_mm_fault+0x8d0/0x1fd0 [c0000002125dfd00] [c00000000037a9b0] handle_mm_fault+0x140/0x250 [c0000002125dfd40] [c000000000074bb0] __do_page_fault+0x300/0xd60 [c0000002125dfe20] [c00000000000acf4] handle_page_fault+0x18

Now that is WARN_ON in set_pte_at which is

        VM_WARN_ON(pte_hw_valid(*ptep) && !pte_protnone(*ptep));

The problem is that on some architectures set_pte_at() cannot cope with a situation where there is already some (different) valid entry present.

Use ptep_set_access_flags() instead to modify the pfn which is built to deal with modifying existing PTE.

Fixes b2770da64254 "mm: add vm_insert_mixed_mkwrite()"
---
 mm/memory.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
mm/memory.c +6 -5
index 47fe250307c7..ab650c21bccd 100644
@@ -1549,10 +1549,12 @@ static vm_fault_t insert_pfn(struct vm_area_struct *vma, unsigned long addr,
 				WARN_ON_ONCE(!is_zero_pfn(pte_pfn(*pte)));
 				goto out_unlock;
 			}
-			entry = *pte;
-			goto out_mkwrite;
-		} else
-			goto out_unlock;
+			entry = pte_mkyoung(*pte);
+			entry = maybe_mkwrite(pte_mkdirty(entry), vma);
+			if (ptep_set_access_flags(vma, addr, pte, entry, 1))
+				update_mmu_cache(vma, addr, pte);
+		}
+		goto out_unlock;
 	}
 
 	/* Ok, finally just insert the thing.. */
@@ -1561,7 +1563,6 @@ static vm_fault_t insert_pfn(struct vm_area_struct *vma, unsigned long addr,
 	else
 		entry = pte_mkspecial(pfn_t_pte(pfn, prot));
 
-out_mkwrite:
 	if (mkwrite) {
 		entry = pte_mkyoung(entry);
 		entry = maybe_mkwrite(pte_mkdirty(entry), vma);
Signature · 1 line
2.16.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 18 lines · Jan Kara

Aneesh has reported that PPC triggers the following warning when excercising DAX code:

[c00000000007610c] set_pte_at+0x3c/0x190
LR [c000000000378628] insert_pfn+0x208/0x280

Call Trace:

[c0000002125df980] [8000000000000104] 0x8000000000000104 (unreliable) [c0000002125df9c0] [c000000000378488] insert_pfn+0x68/0x280 [c0000002125dfa30] [c0000000004a5494] dax_iomap_pte_fault.isra.7+0x734/0xa40 [c0000002125dfb50] [c000000000627250] __xfs_filemap_fault+0x280/0x2d0 [c0000002125dfbb0] [c000000000373abc] do_wp_page+0x48c/0xa40 [c0000002125dfc00] [c000000000379170] __handle_mm_fault+0x8d0/0x1fd0 [c0000002125dfd00] [c00000000037a9b0] handle_mm_fault+0x140/0x250 [c0000002125dfd40] [c000000000074bb0] __do_page_fault+0x300/0xd60 [c0000002125dfe20] [c00000000000acf4] handle_page_fault+0x18

Now that is WARN_ON in set_pte_at which is

Quoted 8 lines
        VM_WARN_ON(pte_hw_valid(*ptep) && !pte_protnone(*ptep));

The problem is that on some architectures set_pte_at() cannot cope with a situation where there is already some (different) valid entry present.

Use ptep_set_access_flags() instead to modify the pfn which is built to deal with modifying existing PTE.

Quoted 39 lines
Fixes b2770da64254 "mm: add vm_insert_mixed_mkwrite()"
---
 mm/memory.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
mm/memory.c +6 -5
index 47fe250307c7..ab650c21bccd 100644
@@ -1549,10 +1549,12 @@ static vm_fault_t insert_pfn(struct vm_area_struct *vma, unsigned long addr,
 				WARN_ON_ONCE(!is_zero_pfn(pte_pfn(*pte)));
 				goto out_unlock;
 			}
-			entry = *pte;
-			goto out_mkwrite;
-		} else
-			goto out_unlock;
+			entry = pte_mkyoung(*pte);
+			entry = maybe_mkwrite(pte_mkdirty(entry), vma);
+			if (ptep_set_access_flags(vma, addr, pte, entry, 1))
+				update_mmu_cache(vma, addr, pte);
+		}
+		goto out_unlock;
 	}
 
 	/* Ok, finally just insert the thing.. */
@@ -1561,7 +1563,6 @@ static vm_fault_t insert_pfn(struct vm_area_struct *vma, unsigned long addr,
 	else
 		entry = pte_mkspecial(pfn_t_pte(pfn, prot));
 
-out_mkwrite:
 	if (mkwrite) {
 		entry = pte_mkyoung(entry);
 		entry = maybe_mkwrite(pte_mkdirty(entry), vma);
Signature · 1 line
2.16.4
Acked-by on v1 1/1
#2 lore raw
In reply to Jan Kara
Quoted 24 lines · Jan Kara

Aneesh has reported that PPC triggers the following warning when excercising DAX code:

[c00000000007610c] set_pte_at+0x3c/0x190
LR [c000000000378628] insert_pfn+0x208/0x280

Call Trace:

[c0000002125df980] [8000000000000104] 0x8000000000000104 (unreliable) [c0000002125df9c0] [c000000000378488] insert_pfn+0x68/0x280 [c0000002125dfa30] [c0000000004a5494] dax_iomap_pte_fault.isra.7+0x734/0xa40 [c0000002125dfb50] [c000000000627250] __xfs_filemap_fault+0x280/0x2d0 [c0000002125dfbb0] [c000000000373abc] do_wp_page+0x48c/0xa40 [c0000002125dfc00] [c000000000379170] __handle_mm_fault+0x8d0/0x1fd0 [c0000002125dfd00] [c00000000037a9b0] handle_mm_fault+0x140/0x250 [c0000002125dfd40] [c000000000074bb0] __do_page_fault+0x300/0xd60 [c0000002125dfe20] [c00000000000acf4] handle_page_fault+0x18

Now that is WARN_ON in set_pte_at which is

        VM_WARN_ON(pte_hw_valid(*ptep) && !pte_protnone(*ptep));

The problem is that on some architectures set_pte_at() cannot cope with a situation where there is already some (different) valid entry present.

Quoted 7 lines

Use ptep_set_access_flags() instead to modify the pfn which is built to deal with modifying existing PTE.

Fixes b2770da64254 "mm: add vm_insert_mixed_mkwrite()"

Andrew, can you pick this up?

author
#3 lore raw
Quoted 28 lines · Dan Williams
Quoted 27 lines · Jan Kara

Aneesh has reported that PPC triggers the following warning when excercising DAX code:

[c00000000007610c] set_pte_at+0x3c/0x190
LR [c000000000378628] insert_pfn+0x208/0x280

Call Trace:

[c0000002125df980] [8000000000000104] 0x8000000000000104 (unreliable) [c0000002125df9c0] [c000000000378488] insert_pfn+0x68/0x280 [c0000002125dfa30] [c0000000004a5494] dax_iomap_pte_fault.isra.7+0x734/0xa40 [c0000002125dfb50] [c000000000627250] __xfs_filemap_fault+0x280/0x2d0 [c0000002125dfbb0] [c000000000373abc] do_wp_page+0x48c/0xa40 [c0000002125dfc00] [c000000000379170] __handle_mm_fault+0x8d0/0x1fd0 [c0000002125dfd00] [c00000000037a9b0] handle_mm_fault+0x140/0x250 [c0000002125dfd40] [c000000000074bb0] __do_page_fault+0x300/0xd60 [c0000002125dfe20] [c00000000000acf4] handle_page_fault+0x18

Now that is WARN_ON in set_pte_at which is

        VM_WARN_ON(pte_hw_valid(*ptep) && !pte_protnone(*ptep));

The problem is that on some architectures set_pte_at() cannot cope with a situation where there is already some (different) valid entry present.

Use ptep_set_access_flags() instead to modify the pfn which is built to deal with modifying existing PTE.

Quoted 8 lines
Quoted 4 lines
Fixes b2770da64254 "mm: add vm_insert_mixed_mkwrite()"

Andrew, can you pick this up?

Andrew, ping?

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
maintainer
#4 lore raw
Quoted 34 lines · On Wed, 27 Mar 2019 18:33:32 +0100 Jan Kara <[email protected]> wrote:
Quoted 33 lines · Dan Williams
Quoted 31 lines · Jan Kara

Aneesh has reported that PPC triggers the following warning when excercising DAX code:

[c00000000007610c] set_pte_at+0x3c/0x190
LR [c000000000378628] insert_pfn+0x208/0x280

Call Trace:

[c0000002125df980] [8000000000000104] 0x8000000000000104 (unreliable) [c0000002125df9c0] [c000000000378488] insert_pfn+0x68/0x280 [c0000002125dfa30] [c0000000004a5494] dax_iomap_pte_fault.isra.7+0x734/0xa40 [c0000002125dfb50] [c000000000627250] __xfs_filemap_fault+0x280/0x2d0 [c0000002125dfbb0] [c000000000373abc] do_wp_page+0x48c/0xa40 [c0000002125dfc00] [c000000000379170] __handle_mm_fault+0x8d0/0x1fd0 [c0000002125dfd00] [c00000000037a9b0] handle_mm_fault+0x140/0x250 [c0000002125dfd40] [c000000000074bb0] __do_page_fault+0x300/0xd60 [c0000002125dfe20] [c00000000000acf4] handle_page_fault+0x18

Now that is WARN_ON in set_pte_at which is

        VM_WARN_ON(pte_hw_valid(*ptep) && !pte_protnone(*ptep));

The problem is that on some architectures set_pte_at() cannot cope with a situation where there is already some (different) valid entry present.

Use ptep_set_access_flags() instead to modify the pfn which is built to deal with modifying existing PTE.

Fixes b2770da64254 "mm: add vm_insert_mixed_mkwrite()"
Quoted 5 lines
Quoted 3 lines

Andrew, can you pick this up?

Andrew, ping?

I merged this a couple of weeks ago and it's in the queue for 5.1.

#5 lore raw
Quoted 36 lines · Andrew Morton
Quoted 34 lines · On Wed, 27 Mar 2019 18:33:32 +0100 Jan Kara <[email protected]> wrote:
Quoted 33 lines · Dan Williams
Quoted 31 lines · Jan Kara

Aneesh has reported that PPC triggers the following warning when excercising DAX code:

[c00000000007610c] set_pte_at+0x3c/0x190
LR [c000000000378628] insert_pfn+0x208/0x280

Call Trace:

[c0000002125df980] [8000000000000104] 0x8000000000000104 (unreliable) [c0000002125df9c0] [c000000000378488] insert_pfn+0x68/0x280 [c0000002125dfa30] [c0000000004a5494] dax_iomap_pte_fault.isra.7+0x734/0xa40 [c0000002125dfb50] [c000000000627250] __xfs_filemap_fault+0x280/0x2d0 [c0000002125dfbb0] [c000000000373abc] do_wp_page+0x48c/0xa40 [c0000002125dfc00] [c000000000379170] __handle_mm_fault+0x8d0/0x1fd0 [c0000002125dfd00] [c00000000037a9b0] handle_mm_fault+0x140/0x250 [c0000002125dfd40] [c000000000074bb0] __do_page_fault+0x300/0xd60 [c0000002125dfe20] [c00000000000acf4] handle_page_fault+0x18

Now that is WARN_ON in set_pte_at which is

         VM_WARN_ON(pte_hw_valid(*ptep) && !pte_protnone(*ptep));

The problem is that on some architectures set_pte_at() cannot cope with a situation where there is already some (different) valid entry present.

Use ptep_set_access_flags() instead to modify the pfn which is built to deal with modifying existing PTE.

Fixes b2770da64254 "mm: add vm_insert_mixed_mkwrite()"
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Andrew, can you pick this up?

Andrew, ping?

I merged this a couple of weeks ago and it's in the queue for 5.1.

I noticed that we need similar change for pmd and pud updates. I will send a patch for that.

-aneesh

author
#6 lore raw
Quoted 41 lines · Aneesh Kumar K.V
Quoted 40 lines · Andrew Morton
Quoted 38 lines · On Wed, 27 Mar 2019 18:33:32 +0100 Jan Kara <[email protected]> wrote:
Quoted 36 lines · Dan Williams
Quoted 24 lines · Jan Kara

Aneesh has reported that PPC triggers the following warning when excercising DAX code:

[c00000000007610c] set_pte_at+0x3c/0x190
LR [c000000000378628] insert_pfn+0x208/0x280

Call Trace:

[c0000002125df980] [8000000000000104] 0x8000000000000104 (unreliable) [c0000002125df9c0] [c000000000378488] insert_pfn+0x68/0x280 [c0000002125dfa30] [c0000000004a5494] dax_iomap_pte_fault.isra.7+0x734/0xa40 [c0000002125dfb50] [c000000000627250] __xfs_filemap_fault+0x280/0x2d0 [c0000002125dfbb0] [c000000000373abc] do_wp_page+0x48c/0xa40 [c0000002125dfc00] [c000000000379170] __handle_mm_fault+0x8d0/0x1fd0 [c0000002125dfd00] [c00000000037a9b0] handle_mm_fault+0x140/0x250 [c0000002125dfd40] [c000000000074bb0] __do_page_fault+0x300/0xd60 [c0000002125dfe20] [c00000000000acf4] handle_page_fault+0x18

Now that is WARN_ON in set_pte_at which is

         VM_WARN_ON(pte_hw_valid(*ptep) && !pte_protnone(*ptep));

The problem is that on some architectures set_pte_at() cannot cope with a situation where there is already some (different) valid entry present.

Quoted 7 lines

Use ptep_set_access_flags() instead to modify the pfn which is built to deal with modifying existing PTE.

Fixes b2770da64254 "mm: add vm_insert_mixed_mkwrite()"

Andrew, can you pick this up?

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Andrew, ping?

I merged this a couple of weeks ago and it's in the queue for 5.1.

I noticed that we need similar change for pmd and pud updates. I will send a patch for that.

Yes, it is needed there as well. Thanks for fixing this.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
author
#7 lore raw
In reply to Andrew Morton
Quoted 36 lines · Andrew Morton
Quoted 34 lines · On Wed, 27 Mar 2019 18:33:32 +0100 Jan Kara <[email protected]> wrote:
Quoted 33 lines · Dan Williams
Quoted 31 lines · Jan Kara

Aneesh has reported that PPC triggers the following warning when excercising DAX code:

[c00000000007610c] set_pte_at+0x3c/0x190
LR [c000000000378628] insert_pfn+0x208/0x280

Call Trace:

[c0000002125df980] [8000000000000104] 0x8000000000000104 (unreliable) [c0000002125df9c0] [c000000000378488] insert_pfn+0x68/0x280 [c0000002125dfa30] [c0000000004a5494] dax_iomap_pte_fault.isra.7+0x734/0xa40 [c0000002125dfb50] [c000000000627250] __xfs_filemap_fault+0x280/0x2d0 [c0000002125dfbb0] [c000000000373abc] do_wp_page+0x48c/0xa40 [c0000002125dfc00] [c000000000379170] __handle_mm_fault+0x8d0/0x1fd0 [c0000002125dfd00] [c00000000037a9b0] handle_mm_fault+0x140/0x250 [c0000002125dfd40] [c000000000074bb0] __do_page_fault+0x300/0xd60 [c0000002125dfe20] [c00000000000acf4] handle_page_fault+0x18

Now that is WARN_ON in set_pte_at which is

        VM_WARN_ON(pte_hw_valid(*ptep) && !pte_protnone(*ptep));

The problem is that on some architectures set_pte_at() cannot cope with a situation where there is already some (different) valid entry present.

Use ptep_set_access_flags() instead to modify the pfn which is built to deal with modifying existing PTE.

Fixes b2770da64254 "mm: add vm_insert_mixed_mkwrite()"
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Andrew, can you pick this up?

Andrew, ping?

I merged this a couple of weeks ago and it's in the queue for 5.1.

Ah, sorry. I didn't find any email about this in my archives. Not sure what happened. Thanks for merging the patch!

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
maintainer
#8 lore raw
In reply to Jan Kara

Hi,

[This is an automated email]

This commit has been processed because it contains a "Fixes:" tag, fixing commit: b2770da64254 mm: add vm_insert_mixed_mkwrite().

The bot has tested the following trees: v5.0.3, v4.19.30, v4.14.107.

v5.0.3: Build OK!
v4.19.30: Failed to apply! Possible dependencies:

    f2c57d91b0d9 ("mm: Fix warning in insert_pfn()")

v4.14.107: Failed to apply! Possible dependencies:

    f2c57d91b0d9 ("mm: Fix warning in insert_pfn()")

How should we proceed with this patch?

--
Thanks,
Sasha

author
#9 lore raw
Quoted 11 lines · Sasha Levin

Hi,

[This is an automated email]

This commit has been processed because it contains a "Fixes:" tag, fixing commit: b2770da64254 mm: add vm_insert_mixed_mkwrite().

The bot has tested the following trees: v5.0.3, v4.19.30, v4.14.107.

v5.0.3: Build OK!
v4.19.30: Failed to apply! Possible dependencies:

Quoted 7 lines
    f2c57d91b0d9 ("mm: Fix warning in insert_pfn()")

v4.14.107: Failed to apply! Possible dependencies:

    f2c57d91b0d9 ("mm: Fix warning in insert_pfn()")

How should we proceed with this patch?

I'd say apply also f2c57d91b0d9 to both trees. Nice automation BTW :).

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR