forked from mirrors/linux
		
	mm: factor out VMA stack and heap checks
Patch series "mm: convert to vma_is_initial_heap/stack()", v3. Add vma_is_initial_stack() and vma_is_initial_heap() helpers and use them to simplify code. This patch (of 4): Factor out VMA stack and heap checks and name them vma_is_initial_stack() and vma_is_initial_heap() for general use. Link: https://lkml.kernel.org/r/20230728050043.59880-1-wangkefeng.wang@huawei.com Link: https://lkml.kernel.org/r/20230728050043.59880-2-wangkefeng.wang@huawei.com Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com> Reviewed-by: David Hildenbrand <david@redhat.com> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Christian Göttsche <cgzones@googlemail.com> Cc: Alex Deucher <alexander.deucher@amd.com> Cc: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Christian Göttsche <cgzones@googlemail.com> Cc: Christian König <christian.koenig@amd.com> Cc: Daniel Vetter <daniel@ffwll.ch> Cc: David Airlie <airlied@gmail.com> Cc: Eric Paris <eparis@parisplace.org> Cc: Felix Kuehling <felix.kuehling@amd.com> Cc: "Pan, Xinhui" <Xinhui.Pan@amd.com> Cc: Paul Moore <paul@paul-moore.com> Cc: Stephen Smalley <stephen.smalley.work@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
		
							parent
							
								
									edb72f4e4f
								
							
						
					
					
						commit
						11250fd12e
					
				
					 3 changed files with 30 additions and 34 deletions
				
			
		|  | @ -236,21 +236,6 @@ static int do_maps_open(struct inode *inode, struct file *file, | ||||||
| 				sizeof(struct proc_maps_private)); | 				sizeof(struct proc_maps_private)); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /*
 |  | ||||||
|  * Indicate if the VMA is a stack for the given task; for |  | ||||||
|  * /proc/PID/maps that is the stack of the main task. |  | ||||||
|  */ |  | ||||||
| static int is_stack(struct vm_area_struct *vma) |  | ||||||
| { |  | ||||||
| 	/*
 |  | ||||||
| 	 * We make no effort to guess what a given thread considers to be |  | ||||||
| 	 * its "stack".  It's not even well-defined for programs written |  | ||||||
| 	 * languages like Go. |  | ||||||
| 	 */ |  | ||||||
| 	return vma->vm_start <= vma->vm_mm->start_stack && |  | ||||||
| 		vma->vm_end >= vma->vm_mm->start_stack; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| static void show_vma_header_prefix(struct seq_file *m, | static void show_vma_header_prefix(struct seq_file *m, | ||||||
| 				   unsigned long start, unsigned long end, | 				   unsigned long start, unsigned long end, | ||||||
| 				   vm_flags_t flags, unsigned long long pgoff, | 				   vm_flags_t flags, unsigned long long pgoff, | ||||||
|  | @ -327,13 +312,12 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma) | ||||||
| 			goto done; | 			goto done; | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		if (vma->vm_start <= mm->brk && | 		if (vma_is_initial_heap(vma)) { | ||||||
| 		    vma->vm_end >= mm->start_brk) { |  | ||||||
| 			name = "[heap]"; | 			name = "[heap]"; | ||||||
| 			goto done; | 			goto done; | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		if (is_stack(vma)) { | 		if (vma_is_initial_stack(vma)) { | ||||||
| 			name = "[stack]"; | 			name = "[stack]"; | ||||||
| 			goto done; | 			goto done; | ||||||
| 		} | 		} | ||||||
|  | @ -1971,9 +1955,9 @@ static int show_numa_map(struct seq_file *m, void *v) | ||||||
| 	if (file) { | 	if (file) { | ||||||
| 		seq_puts(m, " file="); | 		seq_puts(m, " file="); | ||||||
| 		seq_file_path(m, file, "\n\t= "); | 		seq_file_path(m, file, "\n\t= "); | ||||||
| 	} else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) { | 	} else if (vma_is_initial_heap(vma)) { | ||||||
| 		seq_puts(m, " heap"); | 		seq_puts(m, " heap"); | ||||||
| 	} else if (is_stack(vma)) { | 	} else if (vma_is_initial_stack(vma)) { | ||||||
| 		seq_puts(m, " stack"); | 		seq_puts(m, " stack"); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -121,19 +121,6 @@ unsigned long task_statm(struct mm_struct *mm, | ||||||
| 	return size; | 	return size; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static int is_stack(struct vm_area_struct *vma) |  | ||||||
| { |  | ||||||
| 	struct mm_struct *mm = vma->vm_mm; |  | ||||||
| 
 |  | ||||||
| 	/*
 |  | ||||||
| 	 * We make no effort to guess what a given thread considers to be |  | ||||||
| 	 * its "stack".  It's not even well-defined for programs written |  | ||||||
| 	 * languages like Go. |  | ||||||
| 	 */ |  | ||||||
| 	return vma->vm_start <= mm->start_stack && |  | ||||||
| 		vma->vm_end >= mm->start_stack; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| /*
 | /*
 | ||||||
|  * display a single VMA to a sequenced file |  * display a single VMA to a sequenced file | ||||||
|  */ |  */ | ||||||
|  | @ -171,7 +158,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma) | ||||||
| 	if (file) { | 	if (file) { | ||||||
| 		seq_pad(m, ' '); | 		seq_pad(m, ' '); | ||||||
| 		seq_file_path(m, file, ""); | 		seq_file_path(m, file, ""); | ||||||
| 	} else if (mm && is_stack(vma)) { | 	} else if (mm && vma_is_initial_stack(vma)) { | ||||||
| 		seq_pad(m, ' '); | 		seq_pad(m, ' '); | ||||||
| 		seq_puts(m, "[stack]"); | 		seq_puts(m, "[stack]"); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -833,6 +833,31 @@ static inline bool vma_is_anonymous(struct vm_area_struct *vma) | ||||||
| 	return !vma->vm_ops; | 	return !vma->vm_ops; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | /*
 | ||||||
|  |  * Indicate if the VMA is a heap for the given task; for | ||||||
|  |  * /proc/PID/maps that is the heap of the main task. | ||||||
|  |  */ | ||||||
|  | static inline bool vma_is_initial_heap(const struct vm_area_struct *vma) | ||||||
|  | { | ||||||
|  |        return vma->vm_start <= vma->vm_mm->brk && | ||||||
|  | 		vma->vm_end >= vma->vm_mm->start_brk; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /*
 | ||||||
|  |  * Indicate if the VMA is a stack for the given task; for | ||||||
|  |  * /proc/PID/maps that is the stack of the main task. | ||||||
|  |  */ | ||||||
|  | static inline bool vma_is_initial_stack(const struct vm_area_struct *vma) | ||||||
|  | { | ||||||
|  | 	/*
 | ||||||
|  | 	 * We make no effort to guess what a given thread considers to be | ||||||
|  | 	 * its "stack".  It's not even well-defined for programs written | ||||||
|  | 	 * languages like Go. | ||||||
|  | 	 */ | ||||||
|  |        return vma->vm_start <= vma->vm_mm->start_stack && | ||||||
|  | 	       vma->vm_end >= vma->vm_mm->start_stack; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| static inline bool vma_is_temporary_stack(struct vm_area_struct *vma) | static inline bool vma_is_temporary_stack(struct vm_area_struct *vma) | ||||||
| { | { | ||||||
| 	int maybe_stack = vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP); | 	int maybe_stack = vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Kefeng Wang
						Kefeng Wang