* [PATCH v2 0/4] mm: convert to vma_is_initial_heap/stack()
@ 2023-07-19 7:51 Kefeng Wang
2023-07-19 7:51 ` [PATCH v2 1/4] mm: factor out VMA stack and heap checks Kefeng Wang
` (3 more replies)
0 siblings, 4 replies; 17+ messages in thread
From: Kefeng Wang @ 2023-07-19 7:51 UTC (permalink / raw)
To: Andrew Morton
Cc: Kefeng Wang, selinux, linux-kernel, dri-devel, linux-perf-users,
linux-mm, amd-gfx, linux-fsdevel
Add vma_is_initial_stack() and vma_is_initial_heap() helper and use
them to simplify code.
v2:
- address comments per David Hildenbrand and Christian Göttsche
- fix selinux build
Kefeng Wang (4):
mm: factor out VMA stack and heap checks
drm/amdkfd: use vma_is_initial_stack() and vma_is_initial_heap()
selinux: use vma_is_initial_stack() and vma_is_initial_heap()
perf/core: use vma_is_initial_stack() and vma_is_initial_heap()
drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 5 +----
fs/proc/task_mmu.c | 24 ++++--------------------
fs/proc/task_nommu.c | 15 +--------------
include/linux/mm.h | 21 +++++++++++++++++++++
kernel/events/core.c | 22 +++++++---------------
security/selinux/hooks.c | 7 ++-----
6 files changed, 36 insertions(+), 58 deletions(-)
--
2.27.0
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v2 1/4] mm: factor out VMA stack and heap checks
2023-07-19 7:51 [PATCH v2 0/4] mm: convert to vma_is_initial_heap/stack() Kefeng Wang
@ 2023-07-19 7:51 ` Kefeng Wang
2023-07-19 8:18 ` David Hildenbrand
2023-07-19 7:51 ` [PATCH v2 2/4] drm/amdkfd: use vma_is_initial_stack() and vma_is_initial_heap() Kefeng Wang
` (2 subsequent siblings)
3 siblings, 1 reply; 17+ messages in thread
From: Kefeng Wang @ 2023-07-19 7:51 UTC (permalink / raw)
To: Andrew Morton
Cc: Kefeng Wang, David Hildenbrand, selinux, linux-kernel, dri-devel,
linux-perf-users, linux-mm, amd-gfx, linux-fsdevel,
Christian Göttsche
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="yes", Size: 4093 bytes --]
Factor out VMA stack and heap checks and name them
vma_is_initial_stack() and vma_is_initial_heap() for
general use.
Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: David Hildenbrand <david@redhat.com>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
fs/proc/task_mmu.c | 24 ++++--------------------
fs/proc/task_nommu.c | 15 +--------------
include/linux/mm.h | 21 +++++++++++++++++++++
3 files changed, 26 insertions(+), 34 deletions(-)
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 507cd4e59d07..bf25178ae66a 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -236,21 +236,6 @@ static int do_maps_open(struct inode *inode, struct file *file,
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,
unsigned long start, unsigned long end,
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;
}
- if (vma->vm_start <= mm->brk &&
- vma->vm_end >= mm->start_brk) {
+ if (vma_is_initial_heap(vma)) {
name = "[heap]";
goto done;
}
- if (is_stack(vma)) {
+ if (vma_is_initial_stack(vma)) {
name = "[stack]";
goto done;
}
@@ -1971,9 +1955,9 @@ static int show_numa_map(struct seq_file *m, void *v)
if (file) {
seq_puts(m, " file=");
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");
- } else if (is_stack(vma)) {
+ } else if (vma_is_initial_stack(vma)) {
seq_puts(m, " stack");
}
diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
index 2c8b62265981..a8ac0dd8041e 100644
--- a/fs/proc/task_nommu.c
+++ b/fs/proc/task_nommu.c
@@ -121,19 +121,6 @@ unsigned long task_statm(struct mm_struct *mm,
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
*/
@@ -171,7 +158,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
if (file) {
seq_pad(m, ' ');
seq_file_path(m, file, "");
- } else if (mm && is_stack(vma)) {
+ } else if (mm && vma_is_initial_stack(vma)) {
seq_pad(m, ' ');
seq_puts(m, "[stack]");
}
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 2dd73e4f3d8e..51f8c573db74 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -822,6 +822,27 @@ static inline bool vma_is_anonymous(struct vm_area_struct *vma)
return !vma->vm_ops;
}
+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)
{
int maybe_stack = vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP);
--
2.27.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v2 2/4] drm/amdkfd: use vma_is_initial_stack() and vma_is_initial_heap()
2023-07-19 7:51 [PATCH v2 0/4] mm: convert to vma_is_initial_heap/stack() Kefeng Wang
2023-07-19 7:51 ` [PATCH v2 1/4] mm: factor out VMA stack and heap checks Kefeng Wang
@ 2023-07-19 7:51 ` Kefeng Wang
2023-07-19 8:18 ` David Hildenbrand
2023-07-19 14:24 ` Felix Kuehling
2023-07-19 7:51 ` [PATCH v2 3/4] selinux: " Kefeng Wang
2023-07-19 7:51 ` [PATCH v2 4/4] perf/core: " Kefeng Wang
3 siblings, 2 replies; 17+ messages in thread
From: Kefeng Wang @ 2023-07-19 7:51 UTC (permalink / raw)
To: Andrew Morton
Cc: Kefeng Wang, selinux, Felix Kuehling, Pan, Xinhui, linux-kernel,
dri-devel, linux-perf-users, linux-mm, amd-gfx, linux-fsdevel,
Alex Deucher, Christian König
Use the helpers to simplify code.
Cc: Felix Kuehling <Felix.Kuehling@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: "Christian König" <christian.koenig@amd.com>
Cc: "Pan, Xinhui" <Xinhui.Pan@amd.com>
Cc: David Airlie <airlied@gmail.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
index 5ff1a5a89d96..0b7bfbd0cb66 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
@@ -2621,10 +2621,7 @@ svm_range_get_range_boundaries(struct kfd_process *p, int64_t addr,
return -EFAULT;
}
- *is_heap_stack = (vma->vm_start <= vma->vm_mm->brk &&
- vma->vm_end >= vma->vm_mm->start_brk) ||
- (vma->vm_start <= vma->vm_mm->start_stack &&
- vma->vm_end >= vma->vm_mm->start_stack);
+ *is_heap_stack = vma_is_initial_heap(vma) || vma_is_initial_stack(vma);
start_limit = max(vma->vm_start >> PAGE_SHIFT,
(unsigned long)ALIGN_DOWN(addr, 2UL << 8));
--
2.27.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v2 3/4] selinux: use vma_is_initial_stack() and vma_is_initial_heap()
2023-07-19 7:51 [PATCH v2 0/4] mm: convert to vma_is_initial_heap/stack() Kefeng Wang
2023-07-19 7:51 ` [PATCH v2 1/4] mm: factor out VMA stack and heap checks Kefeng Wang
2023-07-19 7:51 ` [PATCH v2 2/4] drm/amdkfd: use vma_is_initial_stack() and vma_is_initial_heap() Kefeng Wang
@ 2023-07-19 7:51 ` Kefeng Wang
2023-07-19 8:18 ` David Hildenbrand
2023-07-19 9:02 ` Christian Göttsche
2023-07-19 7:51 ` [PATCH v2 4/4] perf/core: " Kefeng Wang
3 siblings, 2 replies; 17+ messages in thread
From: Kefeng Wang @ 2023-07-19 7:51 UTC (permalink / raw)
To: Andrew Morton
Cc: Kefeng Wang, Paul Moore, selinux, Stephen Smalley, linux-kernel,
dri-devel, linux-perf-users, linux-mm, amd-gfx, linux-fsdevel,
Eric Paris
Use the helpers to simplify code.
Cc: Paul Moore <paul@paul-moore.com>
Cc: Stephen Smalley <stephen.smalley.work@gmail.com>
Cc: Eric Paris <eparis@parisplace.org>
Acked-by: Paul Moore <paul@paul-moore.com>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
security/selinux/hooks.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index d06e350fedee..ee8575540a8e 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -3762,13 +3762,10 @@ static int selinux_file_mprotect(struct vm_area_struct *vma,
if (default_noexec &&
(prot & PROT_EXEC) && !(vma->vm_flags & VM_EXEC)) {
int rc = 0;
- if (vma->vm_start >= vma->vm_mm->start_brk &&
- vma->vm_end <= vma->vm_mm->brk) {
+ if (vma_is_initial_heap(vma)) {
rc = avc_has_perm(sid, sid, SECCLASS_PROCESS,
PROCESS__EXECHEAP, NULL);
- } else if (!vma->vm_file &&
- ((vma->vm_start <= vma->vm_mm->start_stack &&
- vma->vm_end >= vma->vm_mm->start_stack) ||
+ } else if (!vma->vm_file && (vma_is_initial_stack(vma) ||
vma_is_stack_for_current(vma))) {
rc = avc_has_perm(sid, sid, SECCLASS_PROCESS,
PROCESS__EXECSTACK, NULL);
--
2.27.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v2 4/4] perf/core: use vma_is_initial_stack() and vma_is_initial_heap()
2023-07-19 7:51 [PATCH v2 0/4] mm: convert to vma_is_initial_heap/stack() Kefeng Wang
` (2 preceding siblings ...)
2023-07-19 7:51 ` [PATCH v2 3/4] selinux: " Kefeng Wang
@ 2023-07-19 7:51 ` Kefeng Wang
2023-07-19 8:21 ` David Hildenbrand
2023-07-19 9:29 ` Peter Zijlstra
3 siblings, 2 replies; 17+ messages in thread
From: Kefeng Wang @ 2023-07-19 7:51 UTC (permalink / raw)
To: Andrew Morton
Cc: Kefeng Wang, selinux, linux-kernel, dri-devel, linux-perf-users,
linux-mm, Peter Zijlstra, amd-gfx, linux-fsdevel,
Arnaldo Carvalho de Melo
Use the helpers to simplify code, also kill unneeded goto cpy_name.
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
kernel/events/core.c | 22 +++++++---------------
1 file changed, 7 insertions(+), 15 deletions(-)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 78ae7b6f90fd..d59f6327472f 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -8685,22 +8685,14 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
}
name = (char *)arch_vma_name(vma);
- if (name)
- goto cpy_name;
-
- if (vma->vm_start <= vma->vm_mm->start_brk &&
- vma->vm_end >= vma->vm_mm->brk) {
- name = "[heap]";
- goto cpy_name;
+ if (!name) {
+ if (vma_is_initial_heap(vma))
+ name = "[heap]";
+ else if (vma_is_initial_stack(vma))
+ name = "[stack]";
+ else
+ name = "//anon";
}
- if (vma->vm_start <= vma->vm_mm->start_stack &&
- vma->vm_end >= vma->vm_mm->start_stack) {
- name = "[stack]";
- goto cpy_name;
- }
-
- name = "//anon";
- goto cpy_name;
}
cpy_name:
--
2.27.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH v2 1/4] mm: factor out VMA stack and heap checks
2023-07-19 7:51 ` [PATCH v2 1/4] mm: factor out VMA stack and heap checks Kefeng Wang
@ 2023-07-19 8:18 ` David Hildenbrand
0 siblings, 0 replies; 17+ messages in thread
From: David Hildenbrand @ 2023-07-19 8:18 UTC (permalink / raw)
To: Kefeng Wang, Andrew Morton
Cc: selinux, linux-kernel, dri-devel, linux-perf-users, linux-mm,
amd-gfx, linux-fsdevel, Christian Göttsche
On 19.07.23 09:51, Kefeng Wang wrote:
> Factor out VMA stack and heap checks and name them
> vma_is_initial_stack() and vma_is_initial_heap() for
> general use.
>
> Cc: Christian Göttsche <cgzones@googlemail.com>
> Cc: David Hildenbrand <david@redhat.com>
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> ---
[...]
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 2dd73e4f3d8e..51f8c573db74 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -822,6 +822,27 @@ static inline bool vma_is_anonymous(struct vm_area_struct *vma)
> return !vma->vm_ops;
> }
>
Worth adding a similar comment like for vma_is_initial_stack() ?
> +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)
> {
> int maybe_stack = vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP);
Reviewed-by: David Hildenbrand <david@redhat.com>
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v2 2/4] drm/amdkfd: use vma_is_initial_stack() and vma_is_initial_heap()
2023-07-19 7:51 ` [PATCH v2 2/4] drm/amdkfd: use vma_is_initial_stack() and vma_is_initial_heap() Kefeng Wang
@ 2023-07-19 8:18 ` David Hildenbrand
2023-07-19 14:24 ` Felix Kuehling
1 sibling, 0 replies; 17+ messages in thread
From: David Hildenbrand @ 2023-07-19 8:18 UTC (permalink / raw)
To: Kefeng Wang, Andrew Morton
Cc: selinux, Felix Kuehling, Pan, Xinhui, linux-kernel, dri-devel,
linux-perf-users, linux-mm, amd-gfx, linux-fsdevel, Alex Deucher,
Christian König
On 19.07.23 09:51, Kefeng Wang wrote:
> Use the helpers to simplify code.
>
> Cc: Felix Kuehling <Felix.Kuehling@amd.com>
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Cc: "Christian König" <christian.koenig@amd.com>
> Cc: "Pan, Xinhui" <Xinhui.Pan@amd.com>
> Cc: David Airlie <airlied@gmail.com>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> ---
> drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
> index 5ff1a5a89d96..0b7bfbd0cb66 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
> @@ -2621,10 +2621,7 @@ svm_range_get_range_boundaries(struct kfd_process *p, int64_t addr,
> return -EFAULT;
> }
>
> - *is_heap_stack = (vma->vm_start <= vma->vm_mm->brk &&
> - vma->vm_end >= vma->vm_mm->start_brk) ||
> - (vma->vm_start <= vma->vm_mm->start_stack &&
> - vma->vm_end >= vma->vm_mm->start_stack);
> + *is_heap_stack = vma_is_initial_heap(vma) || vma_is_initial_stack(vma);
>
> start_limit = max(vma->vm_start >> PAGE_SHIFT,
> (unsigned long)ALIGN_DOWN(addr, 2UL << 8));
Certainly a valid refactoring, although questionable if such code should
care about that.
Reviewed-by: David Hildenbrand <david@redhat.com>
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v2 3/4] selinux: use vma_is_initial_stack() and vma_is_initial_heap()
2023-07-19 7:51 ` [PATCH v2 3/4] selinux: " Kefeng Wang
@ 2023-07-19 8:18 ` David Hildenbrand
2023-07-19 9:02 ` Christian Göttsche
1 sibling, 0 replies; 17+ messages in thread
From: David Hildenbrand @ 2023-07-19 8:18 UTC (permalink / raw)
To: Kefeng Wang, Andrew Morton
Cc: Paul Moore, selinux, Stephen Smalley, linux-kernel, dri-devel,
linux-perf-users, linux-mm, amd-gfx, linux-fsdevel, Eric Paris
On 19.07.23 09:51, Kefeng Wang wrote:
> Use the helpers to simplify code.
>
> Cc: Paul Moore <paul@paul-moore.com>
> Cc: Stephen Smalley <stephen.smalley.work@gmail.com>
> Cc: Eric Paris <eparis@parisplace.org>
> Acked-by: Paul Moore <paul@paul-moore.com>
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> ---
> security/selinux/hooks.c | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> index d06e350fedee..ee8575540a8e 100644
> --- a/security/selinux/hooks.c
> +++ b/security/selinux/hooks.c
> @@ -3762,13 +3762,10 @@ static int selinux_file_mprotect(struct vm_area_struct *vma,
> if (default_noexec &&
> (prot & PROT_EXEC) && !(vma->vm_flags & VM_EXEC)) {
> int rc = 0;
> - if (vma->vm_start >= vma->vm_mm->start_brk &&
> - vma->vm_end <= vma->vm_mm->brk) {
> + if (vma_is_initial_heap(vma)) {
> rc = avc_has_perm(sid, sid, SECCLASS_PROCESS,
> PROCESS__EXECHEAP, NULL);
> - } else if (!vma->vm_file &&
> - ((vma->vm_start <= vma->vm_mm->start_stack &&
> - vma->vm_end >= vma->vm_mm->start_stack) ||
> + } else if (!vma->vm_file && (vma_is_initial_stack(vma) ||
> vma_is_stack_for_current(vma))) {
> rc = avc_has_perm(sid, sid, SECCLASS_PROCESS,
> PROCESS__EXECSTACK, NULL);
Reviewed-by: David Hildenbrand <david@redhat.com>
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v2 4/4] perf/core: use vma_is_initial_stack() and vma_is_initial_heap()
2023-07-19 7:51 ` [PATCH v2 4/4] perf/core: " Kefeng Wang
@ 2023-07-19 8:21 ` David Hildenbrand
2023-07-19 9:29 ` Peter Zijlstra
1 sibling, 0 replies; 17+ messages in thread
From: David Hildenbrand @ 2023-07-19 8:21 UTC (permalink / raw)
To: Kefeng Wang, Andrew Morton
Cc: selinux, linux-kernel, dri-devel, linux-perf-users, linux-mm,
Peter Zijlstra, amd-gfx, linux-fsdevel, Arnaldo Carvalho de Melo
On 19.07.23 09:51, Kefeng Wang wrote:
> Use the helpers to simplify code, also kill unneeded goto cpy_name.
>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> ---
> kernel/events/core.c | 22 +++++++---------------
> 1 file changed, 7 insertions(+), 15 deletions(-)
>
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 78ae7b6f90fd..d59f6327472f 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -8685,22 +8685,14 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
> }
>
> name = (char *)arch_vma_name(vma);
> - if (name)
> - goto cpy_name;
> -
> - if (vma->vm_start <= vma->vm_mm->start_brk &&
> - vma->vm_end >= vma->vm_mm->brk) {
> - name = "[heap]";
> - goto cpy_name;
> + if (!name) {
> + if (vma_is_initial_heap(vma))
> + name = "[heap]";
> + else if (vma_is_initial_stack(vma))
> + name = "[stack]";
> + else
> + name = "//anon";
> }
> - if (vma->vm_start <= vma->vm_mm->start_stack &&
> - vma->vm_end >= vma->vm_mm->start_stack) {
> - name = "[stack]";
> - goto cpy_name;
> - }
> -
> - name = "//anon";
> - goto cpy_name;
If you're removing that goto, maybe also worth removing the goto at the
end of the previous if branch.
Reviewed-by: David Hildenbrand <david@redhat.com>
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v2 3/4] selinux: use vma_is_initial_stack() and vma_is_initial_heap()
2023-07-19 7:51 ` [PATCH v2 3/4] selinux: " Kefeng Wang
2023-07-19 8:18 ` David Hildenbrand
@ 2023-07-19 9:02 ` Christian Göttsche
2023-07-19 10:22 ` Kefeng Wang
1 sibling, 1 reply; 17+ messages in thread
From: Christian Göttsche @ 2023-07-19 9:02 UTC (permalink / raw)
To: Kefeng Wang
Cc: Paul Moore, selinux, Stephen Smalley, linux-kernel, dri-devel,
linux-perf-users, linux-mm, amd-gfx, linux-fsdevel, Eric Paris,
Andrew Morton
On Wed, 19 Jul 2023 at 09:40, Kefeng Wang <wangkefeng.wang@huawei.com> wrote:
>
> Use the helpers to simplify code.
>
> Cc: Paul Moore <paul@paul-moore.com>
> Cc: Stephen Smalley <stephen.smalley.work@gmail.com>
> Cc: Eric Paris <eparis@parisplace.org>
> Acked-by: Paul Moore <paul@paul-moore.com>
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> ---
> security/selinux/hooks.c | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> index d06e350fedee..ee8575540a8e 100644
> --- a/security/selinux/hooks.c
> +++ b/security/selinux/hooks.c
> @@ -3762,13 +3762,10 @@ static int selinux_file_mprotect(struct vm_area_struct *vma,
> if (default_noexec &&
> (prot & PROT_EXEC) && !(vma->vm_flags & VM_EXEC)) {
> int rc = 0;
> - if (vma->vm_start >= vma->vm_mm->start_brk &&
> - vma->vm_end <= vma->vm_mm->brk) {
> + if (vma_is_initial_heap(vma)) {
This seems to change the condition from
vma->vm_start >= vma->vm_mm->start_brk && vma->vm_end <= vma->vm_mm->brk
to
vma->vm_start <= vma->vm_mm->brk && vma->vm_end >= vma->vm_mm->start_brk
(or AND arguments swapped)
vma->vm_end >= vma->vm_mm->start_brk && vma->vm_start <= vma->vm_mm->brk
Is this intended?
> rc = avc_has_perm(sid, sid, SECCLASS_PROCESS,
> PROCESS__EXECHEAP, NULL);
> - } else if (!vma->vm_file &&
> - ((vma->vm_start <= vma->vm_mm->start_stack &&
> - vma->vm_end >= vma->vm_mm->start_stack) ||
> + } else if (!vma->vm_file && (vma_is_initial_stack(vma) ||
> vma_is_stack_for_current(vma))) {
> rc = avc_has_perm(sid, sid, SECCLASS_PROCESS,
> PROCESS__EXECSTACK, NULL);
> --
> 2.27.0
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v2 4/4] perf/core: use vma_is_initial_stack() and vma_is_initial_heap()
2023-07-19 7:51 ` [PATCH v2 4/4] perf/core: " Kefeng Wang
2023-07-19 8:21 ` David Hildenbrand
@ 2023-07-19 9:29 ` Peter Zijlstra
2023-07-19 10:26 ` Kefeng Wang
1 sibling, 1 reply; 17+ messages in thread
From: Peter Zijlstra @ 2023-07-19 9:29 UTC (permalink / raw)
To: Kefeng Wang
Cc: selinux, linux-kernel, dri-devel, linux-perf-users, linux-mm,
amd-gfx, linux-fsdevel, Andrew Morton, Arnaldo Carvalho de Melo
On Wed, Jul 19, 2023 at 03:51:14PM +0800, Kefeng Wang wrote:
> Use the helpers to simplify code, also kill unneeded goto cpy_name.
Grrr.. why am I only getting 4/4 ?
I'm going to write a bot that auto NAKs all partial series :/
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v2 3/4] selinux: use vma_is_initial_stack() and vma_is_initial_heap()
2023-07-19 9:02 ` Christian Göttsche
@ 2023-07-19 10:22 ` Kefeng Wang
2023-07-19 15:25 ` Paul Moore
0 siblings, 1 reply; 17+ messages in thread
From: Kefeng Wang @ 2023-07-19 10:22 UTC (permalink / raw)
To: Christian Göttsche
Cc: Paul Moore, selinux, Stephen Smalley, linux-kernel, dri-devel,
linux-perf-users, linux-mm, amd-gfx, linux-fsdevel, Eric Paris,
Andrew Morton
On 2023/7/19 17:02, Christian Göttsche wrote:
> On Wed, 19 Jul 2023 at 09:40, Kefeng Wang <wangkefeng.wang@huawei.com> wrote:
>>
>> Use the helpers to simplify code.
>>
>> Cc: Paul Moore <paul@paul-moore.com>
>> Cc: Stephen Smalley <stephen.smalley.work@gmail.com>
>> Cc: Eric Paris <eparis@parisplace.org>
>> Acked-by: Paul Moore <paul@paul-moore.com>
>> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
>> ---
>> security/selinux/hooks.c | 7 ++-----
>> 1 file changed, 2 insertions(+), 5 deletions(-)
>>
>> diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
>> index d06e350fedee..ee8575540a8e 100644
>> --- a/security/selinux/hooks.c
>> +++ b/security/selinux/hooks.c
>> @@ -3762,13 +3762,10 @@ static int selinux_file_mprotect(struct vm_area_struct *vma,
>> if (default_noexec &&
>> (prot & PROT_EXEC) && !(vma->vm_flags & VM_EXEC)) {
>> int rc = 0;
>> - if (vma->vm_start >= vma->vm_mm->start_brk &&
>> - vma->vm_end <= vma->vm_mm->brk) {
>> + if (vma_is_initial_heap(vma)) {
>
> This seems to change the condition from
>
> vma->vm_start >= vma->vm_mm->start_brk && vma->vm_end <= vma->vm_mm->brk
>
> to
>
> vma->vm_start <= vma->vm_mm->brk && vma->vm_end >= vma->vm_mm->start_brk
>
> (or AND arguments swapped)
>
> vma->vm_end >= vma->vm_mm->start_brk && vma->vm_start <= vma->vm_mm->brk
>
> Is this intended?
The new condition is to check whether there is intersection between
[startbrk,brk] and [vm_start,vm_end], it contains orignal check, so
I think it is ok, but for selinux check, I am not sure if there is
some other problem.
>
>> rc = avc_has_perm(sid, sid, SECCLASS_PROCESS,
>> PROCESS__EXECHEAP, NULL);
>> - } else if (!vma->vm_file &&
>> - ((vma->vm_start <= vma->vm_mm->start_stack &&
>> - vma->vm_end >= vma->vm_mm->start_stack) ||
>> + } else if (!vma->vm_file && (vma_is_initial_stack(vma) ||
>> vma_is_stack_for_current(vma))) {
>> rc = avc_has_perm(sid, sid, SECCLASS_PROCESS,
>> PROCESS__EXECSTACK, NULL);
>> --
>> 2.27.0
>>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v2 4/4] perf/core: use vma_is_initial_stack() and vma_is_initial_heap()
2023-07-19 9:29 ` Peter Zijlstra
@ 2023-07-19 10:26 ` Kefeng Wang
0 siblings, 0 replies; 17+ messages in thread
From: Kefeng Wang @ 2023-07-19 10:26 UTC (permalink / raw)
To: Peter Zijlstra
Cc: selinux, linux-kernel, dri-devel, linux-perf-users, linux-mm,
amd-gfx, linux-fsdevel, Andrew Morton, Arnaldo Carvalho de Melo
On 2023/7/19 17:29, Peter Zijlstra wrote:
> On Wed, Jul 19, 2023 at 03:51:14PM +0800, Kefeng Wang wrote:
>> Use the helpers to simplify code, also kill unneeded goto cpy_name.
>
> Grrr.. why am I only getting 4/4 ?
>
> I'm going to write a bot that auto NAKs all partial series :/
Sorry, I should add all to cc list, here is all patches linke[1]
[1]
https://lore.kernel.org/linux-mm/20230719075127.47736-1-wangkefeng.wang@huawei.com/
Thanks.
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v2 2/4] drm/amdkfd: use vma_is_initial_stack() and vma_is_initial_heap()
2023-07-19 7:51 ` [PATCH v2 2/4] drm/amdkfd: use vma_is_initial_stack() and vma_is_initial_heap() Kefeng Wang
2023-07-19 8:18 ` David Hildenbrand
@ 2023-07-19 14:24 ` Felix Kuehling
1 sibling, 0 replies; 17+ messages in thread
From: Felix Kuehling @ 2023-07-19 14:24 UTC (permalink / raw)
To: Kefeng Wang, Andrew Morton
Cc: selinux, Pan, Xinhui, linux-kernel, dri-devel, linux-perf-users,
linux-mm, amd-gfx, linux-fsdevel, Alex Deucher,
Christian König
Am 2023-07-19 um 03:51 schrieb Kefeng Wang:
> Use the helpers to simplify code.
>
> Cc: Felix Kuehling <Felix.Kuehling@amd.com>
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Cc: "Christian König" <christian.koenig@amd.com>
> Cc: "Pan, Xinhui" <Xinhui.Pan@amd.com>
> Cc: David Airlie <airlied@gmail.com>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
> ---
> drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
> index 5ff1a5a89d96..0b7bfbd0cb66 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
> @@ -2621,10 +2621,7 @@ svm_range_get_range_boundaries(struct kfd_process *p, int64_t addr,
> return -EFAULT;
> }
>
> - *is_heap_stack = (vma->vm_start <= vma->vm_mm->brk &&
> - vma->vm_end >= vma->vm_mm->start_brk) ||
> - (vma->vm_start <= vma->vm_mm->start_stack &&
> - vma->vm_end >= vma->vm_mm->start_stack);
> + *is_heap_stack = vma_is_initial_heap(vma) || vma_is_initial_stack(vma);
>
> start_limit = max(vma->vm_start >> PAGE_SHIFT,
> (unsigned long)ALIGN_DOWN(addr, 2UL << 8));
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v2 3/4] selinux: use vma_is_initial_stack() and vma_is_initial_heap()
2023-07-19 10:22 ` Kefeng Wang
@ 2023-07-19 15:25 ` Paul Moore
2023-07-20 8:28 ` Kefeng Wang
0 siblings, 1 reply; 17+ messages in thread
From: Paul Moore @ 2023-07-19 15:25 UTC (permalink / raw)
To: Kefeng Wang, Christian Göttsche
Cc: selinux, Stephen Smalley, linux-kernel, dri-devel,
linux-perf-users, linux-mm, amd-gfx, linux-fsdevel, Eric Paris,
Andrew Morton
On Wed, Jul 19, 2023 at 6:23 AM Kefeng Wang <wangkefeng.wang@huawei.com> wrote:
> On 2023/7/19 17:02, Christian Göttsche wrote:
> > On Wed, 19 Jul 2023 at 09:40, Kefeng Wang <wangkefeng.wang@huawei.com> wrote:
> >>
> >> Use the helpers to simplify code.
> >>
> >> Cc: Paul Moore <paul@paul-moore.com>
> >> Cc: Stephen Smalley <stephen.smalley.work@gmail.com>
> >> Cc: Eric Paris <eparis@parisplace.org>
> >> Acked-by: Paul Moore <paul@paul-moore.com>
> >> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> >> ---
> >> security/selinux/hooks.c | 7 ++-----
> >> 1 file changed, 2 insertions(+), 5 deletions(-)
> >>
> >> diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> >> index d06e350fedee..ee8575540a8e 100644
> >> --- a/security/selinux/hooks.c
> >> +++ b/security/selinux/hooks.c
> >> @@ -3762,13 +3762,10 @@ static int selinux_file_mprotect(struct vm_area_struct *vma,
> >> if (default_noexec &&
> >> (prot & PROT_EXEC) && !(vma->vm_flags & VM_EXEC)) {
> >> int rc = 0;
> >> - if (vma->vm_start >= vma->vm_mm->start_brk &&
> >> - vma->vm_end <= vma->vm_mm->brk) {
> >> + if (vma_is_initial_heap(vma)) {
> >
> > This seems to change the condition from
> >
> > vma->vm_start >= vma->vm_mm->start_brk && vma->vm_end <= vma->vm_mm->brk
> >
> > to
> >
> > vma->vm_start <= vma->vm_mm->brk && vma->vm_end >= vma->vm_mm->start_brk
> >
> > (or AND arguments swapped)
> >
> > vma->vm_end >= vma->vm_mm->start_brk && vma->vm_start <= vma->vm_mm->brk
> >
> > Is this intended?
>
> The new condition is to check whether there is intersection between
> [startbrk,brk] and [vm_start,vm_end], it contains orignal check, so
> I think it is ok, but for selinux check, I am not sure if there is
> some other problem.
This particular SELinux vma check is see if the vma falls within the
heap; can you confirm that this change preserves this?
--
paul-moore.com
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v2 3/4] selinux: use vma_is_initial_stack() and vma_is_initial_heap()
2023-07-19 15:25 ` Paul Moore
@ 2023-07-20 8:28 ` Kefeng Wang
2023-07-20 21:16 ` Paul Moore
0 siblings, 1 reply; 17+ messages in thread
From: Kefeng Wang @ 2023-07-20 8:28 UTC (permalink / raw)
To: Paul Moore, Christian Göttsche
Cc: selinux, Stephen Smalley, linux-kernel, dri-devel,
linux-perf-users, linux-mm, amd-gfx, linux-fsdevel, Eric Paris,
Andrew Morton
On 2023/7/19 23:25, Paul Moore wrote:
> On Wed, Jul 19, 2023 at 6:23 AM Kefeng Wang <wangkefeng.wang@huawei.com> wrote:
>> On 2023/7/19 17:02, Christian Göttsche wrote:
>>> On Wed, 19 Jul 2023 at 09:40, Kefeng Wang <wangkefeng.wang@huawei.com> wrote:
>>>>
>>>> Use the helpers to simplify code.
>>>>
>>>> Cc: Paul Moore <paul@paul-moore.com>
>>>> Cc: Stephen Smalley <stephen.smalley.work@gmail.com>
>>>> Cc: Eric Paris <eparis@parisplace.org>
>>>> Acked-by: Paul Moore <paul@paul-moore.com>
>>>> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
>>>> ---
>>>> security/selinux/hooks.c | 7 ++-----
>>>> 1 file changed, 2 insertions(+), 5 deletions(-)
>>>>
>>>> diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
>>>> index d06e350fedee..ee8575540a8e 100644
>>>> --- a/security/selinux/hooks.c
>>>> +++ b/security/selinux/hooks.c
>>>> @@ -3762,13 +3762,10 @@ static int selinux_file_mprotect(struct vm_area_struct *vma,
>>>> if (default_noexec &&
>>>> (prot & PROT_EXEC) && !(vma->vm_flags & VM_EXEC)) {
>>>> int rc = 0;
>>>> - if (vma->vm_start >= vma->vm_mm->start_brk &&
>>>> - vma->vm_end <= vma->vm_mm->brk) {
>>>> + if (vma_is_initial_heap(vma)) {
>>>
>>> This seems to change the condition from
>>>
>>> vma->vm_start >= vma->vm_mm->start_brk && vma->vm_end <= vma->vm_mm->brk
>>>
>>> to
>>>
>>> vma->vm_start <= vma->vm_mm->brk && vma->vm_end >= vma->vm_mm->start_brk
>>>
>>> (or AND arguments swapped)
>>>
>>> vma->vm_end >= vma->vm_mm->start_brk && vma->vm_start <= vma->vm_mm->brk
>>>
>>> Is this intended?
>>
>> The new condition is to check whether there is intersection between
>> [startbrk,brk] and [vm_start,vm_end], it contains orignal check, so
>> I think it is ok, but for selinux check, I am not sure if there is
>> some other problem.
>
> This particular SELinux vma check is see if the vma falls within the
> heap; can you confirm that this change preserves this?
Yes, within is one case of new vma scope check.
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v2 3/4] selinux: use vma_is_initial_stack() and vma_is_initial_heap()
2023-07-20 8:28 ` Kefeng Wang
@ 2023-07-20 21:16 ` Paul Moore
0 siblings, 0 replies; 17+ messages in thread
From: Paul Moore @ 2023-07-20 21:16 UTC (permalink / raw)
To: Kefeng Wang
Cc: selinux, Stephen Smalley, linux-kernel, dri-devel,
linux-perf-users, linux-mm, amd-gfx, linux-fsdevel, Eric Paris,
Andrew Morton, Christian Göttsche
On Thu, Jul 20, 2023 at 4:28 AM Kefeng Wang <wangkefeng.wang@huawei.com> wrote:
> On 2023/7/19 23:25, Paul Moore wrote:
> > On Wed, Jul 19, 2023 at 6:23 AM Kefeng Wang <wangkefeng.wang@huawei.com> wrote:
> >> On 2023/7/19 17:02, Christian Göttsche wrote:
> >>> On Wed, 19 Jul 2023 at 09:40, Kefeng Wang <wangkefeng.wang@huawei.com> wrote:
> >>>>
> >>>> Use the helpers to simplify code.
> >>>>
> >>>> Cc: Paul Moore <paul@paul-moore.com>
> >>>> Cc: Stephen Smalley <stephen.smalley.work@gmail.com>
> >>>> Cc: Eric Paris <eparis@parisplace.org>
> >>>> Acked-by: Paul Moore <paul@paul-moore.com>
> >>>> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> >>>> ---
> >>>> security/selinux/hooks.c | 7 ++-----
> >>>> 1 file changed, 2 insertions(+), 5 deletions(-)
> >>>>
> >>>> diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> >>>> index d06e350fedee..ee8575540a8e 100644
> >>>> --- a/security/selinux/hooks.c
> >>>> +++ b/security/selinux/hooks.c
> >>>> @@ -3762,13 +3762,10 @@ static int selinux_file_mprotect(struct vm_area_struct *vma,
> >>>> if (default_noexec &&
> >>>> (prot & PROT_EXEC) && !(vma->vm_flags & VM_EXEC)) {
> >>>> int rc = 0;
> >>>> - if (vma->vm_start >= vma->vm_mm->start_brk &&
> >>>> - vma->vm_end <= vma->vm_mm->brk) {
> >>>> + if (vma_is_initial_heap(vma)) {
> >>>
> >>> This seems to change the condition from
> >>>
> >>> vma->vm_start >= vma->vm_mm->start_brk && vma->vm_end <= vma->vm_mm->brk
> >>>
> >>> to
> >>>
> >>> vma->vm_start <= vma->vm_mm->brk && vma->vm_end >= vma->vm_mm->start_brk
> >>>
> >>> (or AND arguments swapped)
> >>>
> >>> vma->vm_end >= vma->vm_mm->start_brk && vma->vm_start <= vma->vm_mm->brk
> >>>
> >>> Is this intended?
> >>
> >> The new condition is to check whether there is intersection between
> >> [startbrk,brk] and [vm_start,vm_end], it contains orignal check, so
> >> I think it is ok, but for selinux check, I am not sure if there is
> >> some other problem.
> >
> > This particular SELinux vma check is see if the vma falls within the
> > heap; can you confirm that this change preserves this?
>
> Yes, within is one case of new vma scope check.
Thanks for the confirmation.
--
paul-moore.com
^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2023-07-21 8:18 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-19 7:51 [PATCH v2 0/4] mm: convert to vma_is_initial_heap/stack() Kefeng Wang
2023-07-19 7:51 ` [PATCH v2 1/4] mm: factor out VMA stack and heap checks Kefeng Wang
2023-07-19 8:18 ` David Hildenbrand
2023-07-19 7:51 ` [PATCH v2 2/4] drm/amdkfd: use vma_is_initial_stack() and vma_is_initial_heap() Kefeng Wang
2023-07-19 8:18 ` David Hildenbrand
2023-07-19 14:24 ` Felix Kuehling
2023-07-19 7:51 ` [PATCH v2 3/4] selinux: " Kefeng Wang
2023-07-19 8:18 ` David Hildenbrand
2023-07-19 9:02 ` Christian Göttsche
2023-07-19 10:22 ` Kefeng Wang
2023-07-19 15:25 ` Paul Moore
2023-07-20 8:28 ` Kefeng Wang
2023-07-20 21:16 ` Paul Moore
2023-07-19 7:51 ` [PATCH v2 4/4] perf/core: " Kefeng Wang
2023-07-19 8:21 ` David Hildenbrand
2023-07-19 9:29 ` Peter Zijlstra
2023-07-19 10:26 ` Kefeng Wang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).