Skip to contentSkip to conversation

mm/arch: Fix a few collide definition on private use of VM_FAULT_*

PATCH Applied Peter Xu 3 participants 11 messages Feb 5, 2023 – Feb 9, 2023

Subsystems (5)
lore
Share & tools
lore

Peter Xu

author
#0 lore raw

cover mm/arch: Fix a few collide definition on private use of VM_FAULT_*

I noticed a few collision usage on VM_FAULT_* definition in the page fault path on arm/arm64/s390 where the VM_FAULT_* can overlap with the generic definition of vm_fault_reason.

The major overlapped part being VM_FAULT_HINDEX_MASK which is used only by the hugetlb hwpoisoning.

I'm not sure whether any of them can have a real impact, but that does not look like to be expected. I didn't copy stable, if anyone thinks it should please shoot. Nor did I test them in any form - I just changed the allocations from top bits and added a comment for each of them.

Please have a look, thanks.

Peter Xu (3):
mm/arm: Define private VM_FAULT_* reasons from top bits mm/arm64: Define private VM_FAULT_* reasons from top bits mm/s390: Define private VM_FAULT_* reasons from top bits

 arch/arm/mm/fault.c   |  8 ++++++--
 arch/arm64/mm/fault.c |  8 ++++++--
 arch/s390/mm/fault.c  | 14 +++++++++-----
 3 files changed, 21 insertions(+), 9 deletions(-)
Signature · 1 line
2.37.3
author
#1 lore raw

PATCH 1/3 mm/arm: Define private VM_FAULT_* reasons from top bits

The current definition already collapse with the generic definition of vm_fault_reason. Move the private definitions to allocate bits from the top of uint so they won't collapse anymore.

---
 arch/arm/mm/fault.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
arch/arm/mm/fault.c +6 -2
index 2418f1efabd8..67879d995835 100644
@@ -216,8 +216,12 @@ void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
 }
 
 #ifdef CONFIG_MMU
-#define VM_FAULT_BADMAP		((__force vm_fault_t)0x010000)
-#define VM_FAULT_BADACCESS	((__force vm_fault_t)0x020000)
+/*
+ * Allocate private vm_fault_reason from top.  Please make sure it won't
+ * collide with vm_fault_reason.
+ */
+#define VM_FAULT_BADMAP		((__force vm_fault_t)0x80000000)
+#define VM_FAULT_BADACCESS	((__force vm_fault_t)0x40000000)
 
 static inline bool is_permission_fault(unsigned int fsr)
 {
Signature · 1 line
2.37.3
author
#2 lore raw

PATCH 2/3 mm/arm64: Define private VM_FAULT_* reasons from top bits

In reply to Peter Xu

The current definition already collapse with the generic definition of vm_fault_reason. Move the private definitions to allocate bits from the top of uint so they won't collapse anymore.

---
 arch/arm64/mm/fault.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
arch/arm64/mm/fault.c +6 -2
index 596f46dabe4e..44fd16f58f94 100644
@@ -480,8 +480,12 @@ static void do_bad_area(unsigned long far, unsigned long esr,
 	}
 }
 
-#define VM_FAULT_BADMAP		0x010000
-#define VM_FAULT_BADACCESS	0x020000
+/*
+ * Allocate private vm_fault_reason from top.  Please make sure it won't
+ * collide with vm_fault_reason.
+ */
+#define VM_FAULT_BADMAP		((__force vm_fault_t)0x80000000)
+#define VM_FAULT_BADACCESS	((__force vm_fault_t)0x40000000)
 
 static vm_fault_t __do_page_fault(struct mm_struct *mm, unsigned long addr,
 				  unsigned int mm_flags, unsigned long vm_flags,
Signature · 1 line
2.37.3
author
#3 lore raw

PATCH 3/3 mm/s390: Define private VM_FAULT_* reasons from top bits

In reply to Peter Xu

The current definition already collapse with the generic definition of vm_fault_reason. Move the private definitions to allocate bits from the top of uint so they won't collapse anymore.

---
 arch/s390/mm/fault.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
arch/s390/mm/fault.c +9 -5
index 9649d9382e0a..cebfbd6dcbaf 100644
@@ -46,11 +46,15 @@
 #define __SUBCODE_MASK 0x0600
 #define __PF_RES_FIELD 0x8000000000000000ULL
 
-#define VM_FAULT_BADCONTEXT	((__force vm_fault_t) 0x010000)
-#define VM_FAULT_BADMAP		((__force vm_fault_t) 0x020000)
-#define VM_FAULT_BADACCESS	((__force vm_fault_t) 0x040000)
-#define VM_FAULT_SIGNAL		((__force vm_fault_t) 0x080000)
-#define VM_FAULT_PFAULT		((__force vm_fault_t) 0x100000)
+/*
+ * Allocate private vm_fault_reason from top.  Please make sure it won't
+ * collide with vm_fault_reason.
+ */
+#define VM_FAULT_BADCONTEXT	((__force vm_fault_t) 0x80000000)
+#define VM_FAULT_BADMAP		((__force vm_fault_t) 0x40000000)
+#define VM_FAULT_BADACCESS	((__force vm_fault_t) 0x20000000)
+#define VM_FAULT_SIGNAL		((__force vm_fault_t) 0x10000000)
+#define VM_FAULT_PFAULT		((__force vm_fault_t) 0x8000000)
 
 enum fault_type {
 	KERNEL_FAULT,
Signature · 1 line
2.37.3
maintainer Applied
#4 lore raw

Re: [PATCH 3/3] mm/s390: Define private VM_FAULT_* reasons from top bits

Quoted 8 lines · Peter Xu

The current definition already collapse with the generic definition of vm_fault_reason. Move the private definitions to allocate bits from the top of uint so they won't collapse anymore.

---
 arch/s390/mm/fault.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

Thanks a lot!

Applied.

#5 lore raw
In reply to Peter Xu
Quoted 11 lines · Peter Xu

I noticed a few collision usage on VM_FAULT_* definition in the page fault path on arm/arm64/s390 where the VM_FAULT_* can overlap with the generic definition of vm_fault_reason.

The major overlapped part being VM_FAULT_HINDEX_MASK which is used only by the hugetlb hwpoisoning.

I'm not sure whether any of them can have a real impact, but that does not look like to be expected. I didn't copy stable, if anyone thinks it should please shoot. Nor did I test them in any form - I just changed the allocations from top bits and added a comment for each of them.

This seems like a bad way to do it. Why not just put these VM_FAULT_* definitions in linux/mm_types.h? Then we'll see them when adding new VM_FAULT codes. Sure, they won't be used by every architecture, but so what?

author
#6 lore raw
Quoted 13 lines · Matthew Wilcox
Quoted 11 lines · Peter Xu

I noticed a few collision usage on VM_FAULT_* definition in the page fault path on arm/arm64/s390 where the VM_FAULT_* can overlap with the generic definition of vm_fault_reason.

The major overlapped part being VM_FAULT_HINDEX_MASK which is used only by the hugetlb hwpoisoning.

I'm not sure whether any of them can have a real impact, but that does not look like to be expected. I didn't copy stable, if anyone thinks it should please shoot. Nor did I test them in any form - I just changed the allocations from top bits and added a comment for each of them.

Quoted 4 lines

This seems like a bad way to do it. Why not just put these VM_FAULT_* definitions in linux/mm_types.h? Then we'll see them when adding new VM_FAULT codes. Sure, they won't be used by every architecture, but so what?

My initial version actually contains a few VM_FAULT_PRIVATE_N there, but I noticed only the minority uses that, especially there's s390 which takes 5 entries. I didn't had my mind straight on which's the best to go, then I removed them and posted this simpler version, with comment on each to fix the issues, more in a sense of raising the problem first.

I agree it isn't a problem at all, not until 32 bits all used up. But that seems to slightly encourage more archs from using the new private entries which I wanted to avoid.

If to take a closer look, we may not really need that much private entries. With s390, what I read is:

- VM_FAULT_BADMAP could be replaced directly with VM_FAULT_SIGSEGV?
- VM_FAULT_PFAULT could be replaced directly with VM_FAULT_BADCONTEXT?

Then if I'm not wrong we can already reduce 5->3 private entries.

I didn't directly change that because I am not 100% confident and I can't test them myself. It'll be great if arch people can have a look at either s390 and arm to see whether there's chance of simplifcations first. So the patchset is more of raising the collision issue first, meanwhile great to attract attention for arch people to refactor upon it.

I can also try to reduce the private entries and introduce PRIVATE entries accordingly as you suggested, but I'll need more help on reviews and tests than this one.

Thanks,

Signature · 1 line
Peter Xu
#7 lore raw
Quoted 14 lines · Peter Xu
Quoted 13 lines · Matthew Wilcox
Quoted 11 lines · Peter Xu

I noticed a few collision usage on VM_FAULT_* definition in the page fault path on arm/arm64/s390 where the VM_FAULT_* can overlap with the generic definition of vm_fault_reason.

The major overlapped part being VM_FAULT_HINDEX_MASK which is used only by the hugetlb hwpoisoning.

I'm not sure whether any of them can have a real impact, but that does not look like to be expected. I didn't copy stable, if anyone thinks it should please shoot. Nor did I test them in any form - I just changed the allocations from top bits and added a comment for each of them.

Quoted 6 lines
Quoted 4 lines

This seems like a bad way to do it. Why not just put these VM_FAULT_* definitions in linux/mm_types.h? Then we'll see them when adding new VM_FAULT codes. Sure, they won't be used by every architecture, but so what?

My initial version actually contains a few VM_FAULT_PRIVATE_N there, but I

That wasn't what I meant. I meant putting VM_FAULT_BADMAP and VM_FAULT_SIGSEGV in mm_types.h. Not having "Here is a range of reserved arch private ones".

author
#8 lore raw
Quoted 3 lines · Matthew Wilcox

That wasn't what I meant. I meant putting VM_FAULT_BADMAP and VM_FAULT_SIGSEGV in mm_types.h. Not having "Here is a range of reserved arch private ones".

VM_FAULT_SIGSEGV is there already; I assume you meant adding them all directly into vm_fault_reason.

Then I don't think it's a good idea..

Currently vm_fault_reason is a clear interface for handle_mm_fault() for not only arch pffault handlers but also soft faults like GUP.

If handle_mm_fault() doesn't return VM_FAULT_BADMAP at all, I don't think we should have it as public API at all. When arch1 people reading the VM_FAULT_ documents, it shouldn't care about some fault reason that only happens with arch2. Gup shouldn't care about it either.

Logically a new page fault handler should handle all the retval of vm_fault_reason afaiu. That shouldn't include e.g. VM_FAULT_BADMAP either.

Thanks,

Signature · 1 line
Peter Xu
#9 lore raw
Quoted 13 lines · Peter Xu
Quoted 3 lines · Matthew Wilcox

That wasn't what I meant. I meant putting VM_FAULT_BADMAP and VM_FAULT_SIGSEGV in mm_types.h. Not having "Here is a range of reserved arch private ones".

VM_FAULT_SIGSEGV is there already; I assume you meant adding them all directly into vm_fault_reason.

Then I don't think it's a good idea..

Currently vm_fault_reason is a clear interface for handle_mm_fault() for not only arch pffault handlers but also soft faults like GUP.

Quoted 7 lines

If handle_mm_fault() doesn't return VM_FAULT_BADMAP at all, I don't think we should have it as public API at all. When arch1 people reading the VM_FAULT_ documents, it shouldn't care about some fault reason that only happens with arch2. Gup shouldn't care about it either.

Logically a new page fault handler should handle all the retval of vm_fault_reason afaiu. That shouldn't include e.g. VM_FAULT_BADMAP either.

Hmm, right. Looking specifically at how s390 uses VM_FAULT_BADMAP, it just seems to be a badly structured fault.c. Seems to me that do_fault_error() should take an extra si_code argument, and instead of returning VM_FAULT_BADACCESS / VM_FAULT_BADMAP from various functions, those functions should call do_fault_error() directly, passing it VM_FAULT_SIGSEGV and the appropriate si_code.

But this is all on the s390 people to fix; I don't want to break their arch by trying it myself.

maintainer
#10 lore raw
Quoted 29 lines · Matthew Wilcox
Quoted 13 lines · Peter Xu
Quoted 3 lines · Matthew Wilcox

That wasn't what I meant. I meant putting VM_FAULT_BADMAP and VM_FAULT_SIGSEGV in mm_types.h. Not having "Here is a range of reserved arch private ones".

VM_FAULT_SIGSEGV is there already; I assume you meant adding them all directly into vm_fault_reason.

Then I don't think it's a good idea..

Currently vm_fault_reason is a clear interface for handle_mm_fault() for not only arch pffault handlers but also soft faults like GUP.

Quoted 7 lines

If handle_mm_fault() doesn't return VM_FAULT_BADMAP at all, I don't think we should have it as public API at all. When arch1 people reading the VM_FAULT_ documents, it shouldn't care about some fault reason that only happens with arch2. Gup shouldn't care about it either.

Logically a new page fault handler should handle all the retval of vm_fault_reason afaiu. That shouldn't include e.g. VM_FAULT_BADMAP either.

Hmm, right. Looking specifically at how s390 uses VM_FAULT_BADMAP, it just seems to be a badly structured fault.c. Seems to me that do_fault_error() should take an extra si_code argument, and instead of returning VM_FAULT_BADACCESS / VM_FAULT_BADMAP from various functions, those functions should call do_fault_error() directly, passing it VM_FAULT_SIGSEGV and the appropriate si_code.

Quoted 2 lines

But this is all on the s390 people to fix; I don't want to break their arch by trying it myself.

Yes, will take a look at it. For now I will apply Peter's patch in order to get rid of the collision.