* Re: [PATCH] mm: enforce __must_check on VMA merge and split
2024-12-06 22:50 [PATCH] mm: enforce __must_check on VMA merge and split Lorenzo Stoakes
@ 2024-12-06 22:53 ` Lorenzo Stoakes
2024-12-09 13:51 ` Vlastimil Babka
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Lorenzo Stoakes @ 2024-12-06 22:53 UTC (permalink / raw)
To: Andrew Morton
Cc: Liam R . Howlett, Vlastimil Babka, Jann Horn, linux-mm,
linux-kernel
Andrew - I'm guessing this will hit mm-unstable alongside [0], but to be
clear this patch relies on that one, as that one fixes a case this check
would have highlighted :)
Thanks!
[0]:https://lore.kernel.org/linux-mm/20241206215229.244413-1-lorenzo.stoakes@oracle.com/
On Fri, Dec 06, 2024 at 10:50:36PM +0000, Lorenzo Stoakes wrote:
> It is of critical importance to check the return results on VMA merge (and
> split), failure to do so can result in use-after-free's. This bug has
> recurred, so have the compiler enforce this check to prevent any future
> repetition.
>
> Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
> ---
> mm/vma.c | 8 +++++---
> mm/vma.h | 26 +++++++++++++++-----------
> 2 files changed, 20 insertions(+), 14 deletions(-)
>
> diff --git a/mm/vma.c b/mm/vma.c
> index a06747845cac..543c102b4062 100644
> --- a/mm/vma.c
> +++ b/mm/vma.c
> @@ -447,8 +447,9 @@ void unmap_region(struct ma_state *mas, struct vm_area_struct *vma,
> * has already been checked or doesn't make sense to fail.
> * VMA Iterator will point to the original VMA.
> */
> -static int __split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma,
> - unsigned long addr, int new_below)
> +static __must_check int
> +__split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma,
> + unsigned long addr, int new_below)
> {
> struct vma_prepare vp;
> struct vm_area_struct *new;
> @@ -710,7 +711,8 @@ static bool can_merge_remove_vma(struct vm_area_struct *vma)
> * - The caller must hold a WRITE lock on the mm_struct->mmap_lock.
> * - vmi must be positioned within [@vmg->vma->vm_start, @vmg->vma->vm_end).
> */
> -static struct vm_area_struct *vma_merge_existing_range(struct vma_merge_struct *vmg)
> +static __must_check struct vm_area_struct *vma_merge_existing_range(
> + struct vma_merge_struct *vmg)
> {
> struct vm_area_struct *vma = vmg->vma;
> struct vm_area_struct *prev = vmg->prev;
> diff --git a/mm/vma.h b/mm/vma.h
> index 295d44ea54db..61ed044b6145 100644
> --- a/mm/vma.h
> +++ b/mm/vma.h
> @@ -139,9 +139,10 @@ void validate_mm(struct mm_struct *mm);
> #define validate_mm(mm) do { } while (0)
> #endif
>
> -int vma_expand(struct vma_merge_struct *vmg);
> -int vma_shrink(struct vma_iterator *vmi, struct vm_area_struct *vma,
> - unsigned long start, unsigned long end, pgoff_t pgoff);
> +__must_check int vma_expand(struct vma_merge_struct *vmg);
> +__must_check int vma_shrink(struct vma_iterator *vmi,
> + struct vm_area_struct *vma,
> + unsigned long start, unsigned long end, pgoff_t pgoff);
>
> static inline int vma_iter_store_gfp(struct vma_iterator *vmi,
> struct vm_area_struct *vma, gfp_t gfp)
> @@ -174,13 +175,14 @@ void unmap_region(struct ma_state *mas, struct vm_area_struct *vma,
> struct vm_area_struct *prev, struct vm_area_struct *next);
>
> /* We are about to modify the VMA's flags. */
> -struct vm_area_struct *vma_modify_flags(struct vma_iterator *vmi,
> +__must_check struct vm_area_struct
> +*vma_modify_flags(struct vma_iterator *vmi,
> struct vm_area_struct *prev, struct vm_area_struct *vma,
> unsigned long start, unsigned long end,
> unsigned long new_flags);
>
> /* We are about to modify the VMA's flags and/or anon_name. */
> -struct vm_area_struct
> +__must_check struct vm_area_struct
> *vma_modify_flags_name(struct vma_iterator *vmi,
> struct vm_area_struct *prev,
> struct vm_area_struct *vma,
> @@ -190,7 +192,7 @@ struct vm_area_struct
> struct anon_vma_name *new_name);
>
> /* We are about to modify the VMA's memory policy. */
> -struct vm_area_struct
> +__must_check struct vm_area_struct
> *vma_modify_policy(struct vma_iterator *vmi,
> struct vm_area_struct *prev,
> struct vm_area_struct *vma,
> @@ -198,7 +200,7 @@ struct vm_area_struct
> struct mempolicy *new_pol);
>
> /* We are about to modify the VMA's flags and/or uffd context. */
> -struct vm_area_struct
> +__must_check struct vm_area_struct
> *vma_modify_flags_uffd(struct vma_iterator *vmi,
> struct vm_area_struct *prev,
> struct vm_area_struct *vma,
> @@ -206,11 +208,13 @@ struct vm_area_struct
> unsigned long new_flags,
> struct vm_userfaultfd_ctx new_ctx);
>
> -struct vm_area_struct *vma_merge_new_range(struct vma_merge_struct *vmg);
> +__must_check struct vm_area_struct
> +*vma_merge_new_range(struct vma_merge_struct *vmg);
>
> -struct vm_area_struct *vma_merge_extend(struct vma_iterator *vmi,
> - struct vm_area_struct *vma,
> - unsigned long delta);
> +__must_check struct vm_area_struct
> +*vma_merge_extend(struct vma_iterator *vmi,
> + struct vm_area_struct *vma,
> + unsigned long delta);
>
> void unlink_file_vma_batch_init(struct unlink_vma_file_batch *vb);
>
> --
> 2.47.1
>
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] mm: enforce __must_check on VMA merge and split
2024-12-06 22:50 [PATCH] mm: enforce __must_check on VMA merge and split Lorenzo Stoakes
2024-12-06 22:53 ` Lorenzo Stoakes
@ 2024-12-09 13:51 ` Vlastimil Babka
2024-12-09 18:36 ` Liam R. Howlett
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Vlastimil Babka @ 2024-12-09 13:51 UTC (permalink / raw)
To: Lorenzo Stoakes, Andrew Morton
Cc: Liam R . Howlett, Jann Horn, linux-mm, linux-kernel
On 12/6/24 23:50, Lorenzo Stoakes wrote:
> It is of critical importance to check the return results on VMA merge (and
> split), failure to do so can result in use-after-free's. This bug has
> recurred, so have the compiler enforce this check to prevent any future
> repetition.
>
> Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
> ---
> mm/vma.c | 8 +++++---
> mm/vma.h | 26 +++++++++++++++-----------
> 2 files changed, 20 insertions(+), 14 deletions(-)
>
> diff --git a/mm/vma.c b/mm/vma.c
> index a06747845cac..543c102b4062 100644
> --- a/mm/vma.c
> +++ b/mm/vma.c
> @@ -447,8 +447,9 @@ void unmap_region(struct ma_state *mas, struct vm_area_struct *vma,
> * has already been checked or doesn't make sense to fail.
> * VMA Iterator will point to the original VMA.
> */
> -static int __split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma,
> - unsigned long addr, int new_below)
> +static __must_check int
> +__split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma,
> + unsigned long addr, int new_below)
> {
> struct vma_prepare vp;
> struct vm_area_struct *new;
> @@ -710,7 +711,8 @@ static bool can_merge_remove_vma(struct vm_area_struct *vma)
> * - The caller must hold a WRITE lock on the mm_struct->mmap_lock.
> * - vmi must be positioned within [@vmg->vma->vm_start, @vmg->vma->vm_end).
> */
> -static struct vm_area_struct *vma_merge_existing_range(struct vma_merge_struct *vmg)
> +static __must_check struct vm_area_struct *vma_merge_existing_range(
> + struct vma_merge_struct *vmg)
> {
> struct vm_area_struct *vma = vmg->vma;
> struct vm_area_struct *prev = vmg->prev;
> diff --git a/mm/vma.h b/mm/vma.h
> index 295d44ea54db..61ed044b6145 100644
> --- a/mm/vma.h
> +++ b/mm/vma.h
> @@ -139,9 +139,10 @@ void validate_mm(struct mm_struct *mm);
> #define validate_mm(mm) do { } while (0)
> #endif
>
> -int vma_expand(struct vma_merge_struct *vmg);
> -int vma_shrink(struct vma_iterator *vmi, struct vm_area_struct *vma,
> - unsigned long start, unsigned long end, pgoff_t pgoff);
> +__must_check int vma_expand(struct vma_merge_struct *vmg);
> +__must_check int vma_shrink(struct vma_iterator *vmi,
> + struct vm_area_struct *vma,
> + unsigned long start, unsigned long end, pgoff_t pgoff);
>
> static inline int vma_iter_store_gfp(struct vma_iterator *vmi,
> struct vm_area_struct *vma, gfp_t gfp)
> @@ -174,13 +175,14 @@ void unmap_region(struct ma_state *mas, struct vm_area_struct *vma,
> struct vm_area_struct *prev, struct vm_area_struct *next);
>
> /* We are about to modify the VMA's flags. */
> -struct vm_area_struct *vma_modify_flags(struct vma_iterator *vmi,
> +__must_check struct vm_area_struct
> +*vma_modify_flags(struct vma_iterator *vmi,
> struct vm_area_struct *prev, struct vm_area_struct *vma,
> unsigned long start, unsigned long end,
> unsigned long new_flags);
>
> /* We are about to modify the VMA's flags and/or anon_name. */
> -struct vm_area_struct
> +__must_check struct vm_area_struct
> *vma_modify_flags_name(struct vma_iterator *vmi,
> struct vm_area_struct *prev,
> struct vm_area_struct *vma,
> @@ -190,7 +192,7 @@ struct vm_area_struct
> struct anon_vma_name *new_name);
>
> /* We are about to modify the VMA's memory policy. */
> -struct vm_area_struct
> +__must_check struct vm_area_struct
> *vma_modify_policy(struct vma_iterator *vmi,
> struct vm_area_struct *prev,
> struct vm_area_struct *vma,
> @@ -198,7 +200,7 @@ struct vm_area_struct
> struct mempolicy *new_pol);
>
> /* We are about to modify the VMA's flags and/or uffd context. */
> -struct vm_area_struct
> +__must_check struct vm_area_struct
> *vma_modify_flags_uffd(struct vma_iterator *vmi,
> struct vm_area_struct *prev,
> struct vm_area_struct *vma,
> @@ -206,11 +208,13 @@ struct vm_area_struct
> unsigned long new_flags,
> struct vm_userfaultfd_ctx new_ctx);
>
> -struct vm_area_struct *vma_merge_new_range(struct vma_merge_struct *vmg);
> +__must_check struct vm_area_struct
> +*vma_merge_new_range(struct vma_merge_struct *vmg);
>
> -struct vm_area_struct *vma_merge_extend(struct vma_iterator *vmi,
> - struct vm_area_struct *vma,
> - unsigned long delta);
> +__must_check struct vm_area_struct
> +*vma_merge_extend(struct vma_iterator *vmi,
> + struct vm_area_struct *vma,
> + unsigned long delta);
>
> void unlink_file_vma_batch_init(struct unlink_vma_file_batch *vb);
>
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] mm: enforce __must_check on VMA merge and split
2024-12-06 22:50 [PATCH] mm: enforce __must_check on VMA merge and split Lorenzo Stoakes
2024-12-06 22:53 ` Lorenzo Stoakes
2024-12-09 13:51 ` Vlastimil Babka
@ 2024-12-09 18:36 ` Liam R. Howlett
2024-12-16 21:16 ` kernel test robot
2024-12-16 21:59 ` kernel test robot
4 siblings, 0 replies; 7+ messages in thread
From: Liam R. Howlett @ 2024-12-09 18:36 UTC (permalink / raw)
To: Lorenzo Stoakes
Cc: Andrew Morton, Vlastimil Babka, Jann Horn, linux-mm, linux-kernel
* Lorenzo Stoakes <lorenzo.stoakes@oracle.com> [241206 17:50]:
> It is of critical importance to check the return results on VMA merge (and
> split), failure to do so can result in use-after-free's. This bug has
> recurred, so have the compiler enforce this check to prevent any future
> repetition.
Reviewed-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
>
> Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
> ---
> mm/vma.c | 8 +++++---
> mm/vma.h | 26 +++++++++++++++-----------
> 2 files changed, 20 insertions(+), 14 deletions(-)
>
> diff --git a/mm/vma.c b/mm/vma.c
> index a06747845cac..543c102b4062 100644
> --- a/mm/vma.c
> +++ b/mm/vma.c
> @@ -447,8 +447,9 @@ void unmap_region(struct ma_state *mas, struct vm_area_struct *vma,
> * has already been checked or doesn't make sense to fail.
> * VMA Iterator will point to the original VMA.
> */
> -static int __split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma,
> - unsigned long addr, int new_below)
> +static __must_check int
> +__split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma,
> + unsigned long addr, int new_below)
> {
> struct vma_prepare vp;
> struct vm_area_struct *new;
> @@ -710,7 +711,8 @@ static bool can_merge_remove_vma(struct vm_area_struct *vma)
> * - The caller must hold a WRITE lock on the mm_struct->mmap_lock.
> * - vmi must be positioned within [@vmg->vma->vm_start, @vmg->vma->vm_end).
> */
> -static struct vm_area_struct *vma_merge_existing_range(struct vma_merge_struct *vmg)
> +static __must_check struct vm_area_struct *vma_merge_existing_range(
> + struct vma_merge_struct *vmg)
> {
> struct vm_area_struct *vma = vmg->vma;
> struct vm_area_struct *prev = vmg->prev;
> diff --git a/mm/vma.h b/mm/vma.h
> index 295d44ea54db..61ed044b6145 100644
> --- a/mm/vma.h
> +++ b/mm/vma.h
> @@ -139,9 +139,10 @@ void validate_mm(struct mm_struct *mm);
> #define validate_mm(mm) do { } while (0)
> #endif
>
> -int vma_expand(struct vma_merge_struct *vmg);
> -int vma_shrink(struct vma_iterator *vmi, struct vm_area_struct *vma,
> - unsigned long start, unsigned long end, pgoff_t pgoff);
> +__must_check int vma_expand(struct vma_merge_struct *vmg);
> +__must_check int vma_shrink(struct vma_iterator *vmi,
> + struct vm_area_struct *vma,
> + unsigned long start, unsigned long end, pgoff_t pgoff);
>
> static inline int vma_iter_store_gfp(struct vma_iterator *vmi,
> struct vm_area_struct *vma, gfp_t gfp)
> @@ -174,13 +175,14 @@ void unmap_region(struct ma_state *mas, struct vm_area_struct *vma,
> struct vm_area_struct *prev, struct vm_area_struct *next);
>
> /* We are about to modify the VMA's flags. */
> -struct vm_area_struct *vma_modify_flags(struct vma_iterator *vmi,
> +__must_check struct vm_area_struct
> +*vma_modify_flags(struct vma_iterator *vmi,
> struct vm_area_struct *prev, struct vm_area_struct *vma,
> unsigned long start, unsigned long end,
> unsigned long new_flags);
>
> /* We are about to modify the VMA's flags and/or anon_name. */
> -struct vm_area_struct
> +__must_check struct vm_area_struct
> *vma_modify_flags_name(struct vma_iterator *vmi,
> struct vm_area_struct *prev,
> struct vm_area_struct *vma,
> @@ -190,7 +192,7 @@ struct vm_area_struct
> struct anon_vma_name *new_name);
>
> /* We are about to modify the VMA's memory policy. */
> -struct vm_area_struct
> +__must_check struct vm_area_struct
> *vma_modify_policy(struct vma_iterator *vmi,
> struct vm_area_struct *prev,
> struct vm_area_struct *vma,
> @@ -198,7 +200,7 @@ struct vm_area_struct
> struct mempolicy *new_pol);
>
> /* We are about to modify the VMA's flags and/or uffd context. */
> -struct vm_area_struct
> +__must_check struct vm_area_struct
> *vma_modify_flags_uffd(struct vma_iterator *vmi,
> struct vm_area_struct *prev,
> struct vm_area_struct *vma,
> @@ -206,11 +208,13 @@ struct vm_area_struct
> unsigned long new_flags,
> struct vm_userfaultfd_ctx new_ctx);
>
> -struct vm_area_struct *vma_merge_new_range(struct vma_merge_struct *vmg);
> +__must_check struct vm_area_struct
> +*vma_merge_new_range(struct vma_merge_struct *vmg);
>
> -struct vm_area_struct *vma_merge_extend(struct vma_iterator *vmi,
> - struct vm_area_struct *vma,
> - unsigned long delta);
> +__must_check struct vm_area_struct
> +*vma_merge_extend(struct vma_iterator *vmi,
> + struct vm_area_struct *vma,
> + unsigned long delta);
>
> void unlink_file_vma_batch_init(struct unlink_vma_file_batch *vb);
>
> --
> 2.47.1
>
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] mm: enforce __must_check on VMA merge and split
2024-12-06 22:50 [PATCH] mm: enforce __must_check on VMA merge and split Lorenzo Stoakes
` (2 preceding siblings ...)
2024-12-09 18:36 ` Liam R. Howlett
@ 2024-12-16 21:16 ` kernel test robot
2024-12-16 21:59 ` kernel test robot
4 siblings, 0 replies; 7+ messages in thread
From: kernel test robot @ 2024-12-16 21:16 UTC (permalink / raw)
To: Lorenzo Stoakes; +Cc: oe-kbuild-all
Hi Lorenzo,
kernel test robot noticed the following build warnings:
[auto build test WARNING on akpm-mm/mm-everything]
url: https://github.com/intel-lab-lkp/linux/commits/Lorenzo-Stoakes/mm-enforce-__must_check-on-VMA-merge-and-split/20241207-065244
base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link: https://lore.kernel.org/r/20241206225036.273103-1-lorenzo.stoakes%40oracle.com
patch subject: [PATCH] mm: enforce __must_check on VMA merge and split
config: x86_64-randconfig-003-20241217 (https://download.01.org/0day-ci/archive/20241217/202412170520.Ldy6Uwt1-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241217/202412170520.Ldy6Uwt1-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202412170520.Ldy6Uwt1-lkp@intel.com/
All warnings (new ones prefixed by >>):
mm/vma.c: In function '__mmap_region':
>> mm/vma.c:2468:17: warning: ignoring return value of 'vma_merge_existing_range' declared with attribute 'warn_unused_result' [-Wunused-result]
2468 | vma_merge_existing_range(&vmg);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim +2468 mm/vma.c
52956b0d7fb92e Lorenzo Stoakes 2024-10-25 2434
0d11630cc50a62 Lorenzo Stoakes 2024-10-25 2435 unsigned long __mmap_region(struct file *file, unsigned long addr,
0d11630cc50a62 Lorenzo Stoakes 2024-10-25 2436 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff,
0d11630cc50a62 Lorenzo Stoakes 2024-10-25 2437 struct list_head *uf)
0d11630cc50a62 Lorenzo Stoakes 2024-10-25 2438 {
0d11630cc50a62 Lorenzo Stoakes 2024-10-25 2439 struct mm_struct *mm = current->mm;
0d11630cc50a62 Lorenzo Stoakes 2024-10-25 2440 struct vm_area_struct *vma = NULL;
0d11630cc50a62 Lorenzo Stoakes 2024-10-25 2441 int error;
0d11630cc50a62 Lorenzo Stoakes 2024-10-25 2442 VMA_ITERATOR(vmi, mm, addr);
0d11630cc50a62 Lorenzo Stoakes 2024-10-25 2443 MMAP_STATE(map, mm, &vmi, addr, len, pgoff, vm_flags, file);
52956b0d7fb92e Lorenzo Stoakes 2024-10-25 2444
0d11630cc50a62 Lorenzo Stoakes 2024-10-25 2445 error = __mmap_prepare(&map, uf);
0d11630cc50a62 Lorenzo Stoakes 2024-10-25 2446 if (error)
0d11630cc50a62 Lorenzo Stoakes 2024-10-25 2447 goto abort_munmap;
52956b0d7fb92e Lorenzo Stoakes 2024-10-25 2448
0d11630cc50a62 Lorenzo Stoakes 2024-10-25 2449 /* Attempt to merge with adjacent VMAs... */
0d11630cc50a62 Lorenzo Stoakes 2024-10-25 2450 if (map.prev || map.next) {
0d11630cc50a62 Lorenzo Stoakes 2024-10-25 2451 VMG_MMAP_STATE(vmg, &map, /* vma = */ NULL);
52956b0d7fb92e Lorenzo Stoakes 2024-10-25 2452
0d11630cc50a62 Lorenzo Stoakes 2024-10-25 2453 vma = vma_merge_new_range(&vmg);
0d11630cc50a62 Lorenzo Stoakes 2024-10-25 2454 }
0d11630cc50a62 Lorenzo Stoakes 2024-10-25 2455
0d11630cc50a62 Lorenzo Stoakes 2024-10-25 2456 /* ...but if we can't, allocate a new VMA. */
0d11630cc50a62 Lorenzo Stoakes 2024-10-25 2457 if (!vma) {
0d11630cc50a62 Lorenzo Stoakes 2024-10-25 2458 error = __mmap_new_vma(&map, &vma);
0d11630cc50a62 Lorenzo Stoakes 2024-10-25 2459 if (error)
0d11630cc50a62 Lorenzo Stoakes 2024-10-25 2460 goto unacct_error;
0d11630cc50a62 Lorenzo Stoakes 2024-10-25 2461 }
0d11630cc50a62 Lorenzo Stoakes 2024-10-25 2462
5ac87a885aecb3 Lorenzo Stoakes 2024-10-25 2463 /* If flags changed, we might be able to merge, so try again. */
5ac87a885aecb3 Lorenzo Stoakes 2024-10-25 2464 if (map.retry_merge) {
5ac87a885aecb3 Lorenzo Stoakes 2024-10-25 2465 VMG_MMAP_STATE(vmg, &map, vma);
5ac87a885aecb3 Lorenzo Stoakes 2024-10-25 2466
5ac87a885aecb3 Lorenzo Stoakes 2024-10-25 2467 vma_iter_config(map.vmi, map.addr, map.end);
5ac87a885aecb3 Lorenzo Stoakes 2024-10-25 @2468 vma_merge_existing_range(&vmg);
5ac87a885aecb3 Lorenzo Stoakes 2024-10-25 2469 }
5ac87a885aecb3 Lorenzo Stoakes 2024-10-25 2470
0d11630cc50a62 Lorenzo Stoakes 2024-10-25 2471 __mmap_complete(&map, vma);
0d11630cc50a62 Lorenzo Stoakes 2024-10-25 2472
0d11630cc50a62 Lorenzo Stoakes 2024-10-25 2473 return addr;
0d11630cc50a62 Lorenzo Stoakes 2024-10-25 2474
0d11630cc50a62 Lorenzo Stoakes 2024-10-25 2475 /* Accounting was done by __mmap_prepare(). */
0d11630cc50a62 Lorenzo Stoakes 2024-10-25 2476 unacct_error:
0d11630cc50a62 Lorenzo Stoakes 2024-10-25 2477 if (map.charged)
0d11630cc50a62 Lorenzo Stoakes 2024-10-25 2478 vm_unacct_memory(map.charged);
52956b0d7fb92e Lorenzo Stoakes 2024-10-25 2479 abort_munmap:
0d11630cc50a62 Lorenzo Stoakes 2024-10-25 2480 vms_abort_munmap_vmas(&map.vms, &map.mas_detach);
52956b0d7fb92e Lorenzo Stoakes 2024-10-25 2481 return error;
52956b0d7fb92e Lorenzo Stoakes 2024-10-25 2482 }
98aad6cab8cb2a Lorenzo Stoakes 2024-12-03 2483
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] mm: enforce __must_check on VMA merge and split
2024-12-06 22:50 [PATCH] mm: enforce __must_check on VMA merge and split Lorenzo Stoakes
` (3 preceding siblings ...)
2024-12-16 21:16 ` kernel test robot
@ 2024-12-16 21:59 ` kernel test robot
2024-12-16 22:14 ` Lorenzo Stoakes
4 siblings, 1 reply; 7+ messages in thread
From: kernel test robot @ 2024-12-16 21:59 UTC (permalink / raw)
To: Lorenzo Stoakes; +Cc: llvm, oe-kbuild-all
Hi Lorenzo,
kernel test robot noticed the following build warnings:
[auto build test WARNING on akpm-mm/mm-everything]
url: https://github.com/intel-lab-lkp/linux/commits/Lorenzo-Stoakes/mm-enforce-__must_check-on-VMA-merge-and-split/20241207-065244
base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link: https://lore.kernel.org/r/20241206225036.273103-1-lorenzo.stoakes%40oracle.com
patch subject: [PATCH] mm: enforce __must_check on VMA merge and split
config: x86_64-kexec (https://download.01.org/0day-ci/archive/20241217/202412170555.i4T2rEdD-lkp@intel.com/config)
compiler: clang version 19.1.3 (https://github.com/llvm/llvm-project ab51eccf88f5321e7c60591c5546b254b6afab99)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241217/202412170555.i4T2rEdD-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202412170555.i4T2rEdD-lkp@intel.com/
All warnings (new ones prefixed by >>):
In file included from mm/vma.c:7:
In file included from mm/vma_internal.h:12:
In file included from include/linux/backing-dev.h:16:
In file included from include/linux/writeback.h:13:
In file included from include/linux/blk_types.h:10:
In file included from include/linux/bvec.h:10:
In file included from include/linux/highmem.h:8:
In file included from include/linux/cacheflush.h:5:
In file included from arch/x86/include/asm/cacheflush.h:5:
In file included from include/linux/mm.h:2223:
include/linux/vmstat.h:504:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
504 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~ ^
505 | item];
| ~~~~
include/linux/vmstat.h:511:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
511 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~ ^
512 | NR_VM_NUMA_EVENT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~~
include/linux/vmstat.h:518:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
518 | return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
| ~~~~~~~~~~~ ^ ~~~
include/linux/vmstat.h:524:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
524 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~ ^
525 | NR_VM_NUMA_EVENT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~~
In file included from mm/vma.c:7:
In file included from mm/vma_internal.h:29:
include/linux/mm_inline.h:47:41: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
47 | __mod_lruvec_state(lruvec, NR_LRU_BASE + lru, nr_pages);
| ~~~~~~~~~~~ ^ ~~~
include/linux/mm_inline.h:49:22: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
49 | NR_ZONE_LRU_BASE + lru, nr_pages);
| ~~~~~~~~~~~~~~~~ ^ ~~~
>> mm/vma.c:2468:3: warning: ignoring return value of function declared with 'warn_unused_result' attribute [-Wunused-result]
2468 | vma_merge_existing_range(&vmg);
| ^~~~~~~~~~~~~~~~~~~~~~~~ ~~~~
7 warnings generated.
vim +/warn_unused_result +2468 mm/vma.c
52956b0d7fb92e3 Lorenzo Stoakes 2024-10-25 2434
0d11630cc50a625 Lorenzo Stoakes 2024-10-25 2435 unsigned long __mmap_region(struct file *file, unsigned long addr,
0d11630cc50a625 Lorenzo Stoakes 2024-10-25 2436 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff,
0d11630cc50a625 Lorenzo Stoakes 2024-10-25 2437 struct list_head *uf)
0d11630cc50a625 Lorenzo Stoakes 2024-10-25 2438 {
0d11630cc50a625 Lorenzo Stoakes 2024-10-25 2439 struct mm_struct *mm = current->mm;
0d11630cc50a625 Lorenzo Stoakes 2024-10-25 2440 struct vm_area_struct *vma = NULL;
0d11630cc50a625 Lorenzo Stoakes 2024-10-25 2441 int error;
0d11630cc50a625 Lorenzo Stoakes 2024-10-25 2442 VMA_ITERATOR(vmi, mm, addr);
0d11630cc50a625 Lorenzo Stoakes 2024-10-25 2443 MMAP_STATE(map, mm, &vmi, addr, len, pgoff, vm_flags, file);
52956b0d7fb92e3 Lorenzo Stoakes 2024-10-25 2444
0d11630cc50a625 Lorenzo Stoakes 2024-10-25 2445 error = __mmap_prepare(&map, uf);
0d11630cc50a625 Lorenzo Stoakes 2024-10-25 2446 if (error)
0d11630cc50a625 Lorenzo Stoakes 2024-10-25 2447 goto abort_munmap;
52956b0d7fb92e3 Lorenzo Stoakes 2024-10-25 2448
0d11630cc50a625 Lorenzo Stoakes 2024-10-25 2449 /* Attempt to merge with adjacent VMAs... */
0d11630cc50a625 Lorenzo Stoakes 2024-10-25 2450 if (map.prev || map.next) {
0d11630cc50a625 Lorenzo Stoakes 2024-10-25 2451 VMG_MMAP_STATE(vmg, &map, /* vma = */ NULL);
52956b0d7fb92e3 Lorenzo Stoakes 2024-10-25 2452
0d11630cc50a625 Lorenzo Stoakes 2024-10-25 2453 vma = vma_merge_new_range(&vmg);
0d11630cc50a625 Lorenzo Stoakes 2024-10-25 2454 }
0d11630cc50a625 Lorenzo Stoakes 2024-10-25 2455
0d11630cc50a625 Lorenzo Stoakes 2024-10-25 2456 /* ...but if we can't, allocate a new VMA. */
0d11630cc50a625 Lorenzo Stoakes 2024-10-25 2457 if (!vma) {
0d11630cc50a625 Lorenzo Stoakes 2024-10-25 2458 error = __mmap_new_vma(&map, &vma);
0d11630cc50a625 Lorenzo Stoakes 2024-10-25 2459 if (error)
0d11630cc50a625 Lorenzo Stoakes 2024-10-25 2460 goto unacct_error;
0d11630cc50a625 Lorenzo Stoakes 2024-10-25 2461 }
0d11630cc50a625 Lorenzo Stoakes 2024-10-25 2462
5ac87a885aecb3f Lorenzo Stoakes 2024-10-25 2463 /* If flags changed, we might be able to merge, so try again. */
5ac87a885aecb3f Lorenzo Stoakes 2024-10-25 2464 if (map.retry_merge) {
5ac87a885aecb3f Lorenzo Stoakes 2024-10-25 2465 VMG_MMAP_STATE(vmg, &map, vma);
5ac87a885aecb3f Lorenzo Stoakes 2024-10-25 2466
5ac87a885aecb3f Lorenzo Stoakes 2024-10-25 2467 vma_iter_config(map.vmi, map.addr, map.end);
5ac87a885aecb3f Lorenzo Stoakes 2024-10-25 @2468 vma_merge_existing_range(&vmg);
5ac87a885aecb3f Lorenzo Stoakes 2024-10-25 2469 }
5ac87a885aecb3f Lorenzo Stoakes 2024-10-25 2470
0d11630cc50a625 Lorenzo Stoakes 2024-10-25 2471 __mmap_complete(&map, vma);
0d11630cc50a625 Lorenzo Stoakes 2024-10-25 2472
0d11630cc50a625 Lorenzo Stoakes 2024-10-25 2473 return addr;
0d11630cc50a625 Lorenzo Stoakes 2024-10-25 2474
0d11630cc50a625 Lorenzo Stoakes 2024-10-25 2475 /* Accounting was done by __mmap_prepare(). */
0d11630cc50a625 Lorenzo Stoakes 2024-10-25 2476 unacct_error:
0d11630cc50a625 Lorenzo Stoakes 2024-10-25 2477 if (map.charged)
0d11630cc50a625 Lorenzo Stoakes 2024-10-25 2478 vm_unacct_memory(map.charged);
52956b0d7fb92e3 Lorenzo Stoakes 2024-10-25 2479 abort_munmap:
0d11630cc50a625 Lorenzo Stoakes 2024-10-25 2480 vms_abort_munmap_vmas(&map.vms, &map.mas_detach);
52956b0d7fb92e3 Lorenzo Stoakes 2024-10-25 2481 return error;
52956b0d7fb92e3 Lorenzo Stoakes 2024-10-25 2482 }
98aad6cab8cb2a0 Lorenzo Stoakes 2024-12-03 2483
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] mm: enforce __must_check on VMA merge and split
2024-12-16 21:59 ` kernel test robot
@ 2024-12-16 22:14 ` Lorenzo Stoakes
0 siblings, 0 replies; 7+ messages in thread
From: Lorenzo Stoakes @ 2024-12-16 22:14 UTC (permalink / raw)
To: kernel test robot; +Cc: llvm, oe-kbuild-all
I'm on annual leave so can't be responsive, however just to be clear...
On Tue, Dec 17, 2024 at 05:59:14AM +0800, kernel test robot wrote:
> Hi Lorenzo,
>
> kernel test robot noticed the following build warnings:
>
> [auto build test WARNING on akpm-mm/mm-everything]
[snip]
> >> mm/vma.c:2468:3: warning: ignoring return value of function declared with 'warn_unused_result' attribute [-Wunused-result]
> 2468 | vma_merge_existing_range(&vmg);
> | ^~~~~~~~~~~~~~~~~~~~~~~~ ~~~~
...this is a non-issue and produced by unfortunate commit ordering I
expect. This change was motivated by a fix that I applied that resolves
this line being mentioned here, which is already slated for hotfix and
present in mm-everything + mm-unstable (and mm-hotfixes-unstable).
Since it is a hotfix, the fix will go in first, and then the __must_check
change will go in after.
The __must_check fix is critical as it prevents this kind of issue from
ever arising again.
Thanks, Lorenzo
^ permalink raw reply [flat|nested] 7+ messages in thread