lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZRLQCTh9zNIp9OH7@pc636>
Date:   Tue, 26 Sep 2023 14:35:21 +0200
From:   Uladzislau Rezki <urezki@...il.com>
To:     Jaeseon Sim <jason.sim@...sung.com>
Cc:     Uladzislau Rezki <urezki@...il.com>,
        "bhe@...hat.com" <bhe@...hat.com>,
        "akpm@...ux-foundation.org" <akpm@...ux-foundation.org>,
        "hch@...radead.org" <hch@...radead.org>,
        "lstoakes@...il.com" <lstoakes@...il.com>,
        "linux-mm@...ck.org" <linux-mm@...ck.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        Jaewon Kim <jaewon31.kim@...sung.com>
Subject: Re: [PATCH] mm/vmalloc: Remove WARN_ON_ONCE related to
 adjust_va_to_fit_type

On Tue, Sep 26, 2023 at 09:05:49PM +0900, Jaeseon Sim wrote:
> > > > We do not have above code anymore:
> > > Sorry, I tried to say it in a simplified way and it caused a misunderstanding.
> > > 
> > > <snip>
> > > static __always_inline int
> > > adjust_va_to_fit_type(struct rb_root *root, struct list_head *head,
> > > 		      struct vmap_area *va, unsigned long nva_start_addr,
> > > 		      unsigned long size)
> > > 
> > > 	} else if (type == NE_FIT_TYPE) {
> > > 		/*
> > > 		 * Split no edge of fit VA.
> > > 		 *
> > > 		 *     |       |
> > > 		 *   L V  NVA  V R
> > > 		 * |---|-------|---|
> > > 		 */
> > > 		lva = __this_cpu_xchg(ne_fit_preload_node, NULL);
> > > 		if (unlikely(!lva)) {
> > > 			/*
> > > 			 * For percpu allocator we do not do any pre-allocation
> > > 			 * and leave it as it is. The reason is it most likely
> > > 			 * never ends up with NE_FIT_TYPE splitting. In case of
> > > 			 * percpu allocations offsets and sizes are aligned to
> > > 			 * fixed align request, i.e. RE_FIT_TYPE and FL_FIT_TYPE
> > > 			 * are its main fitting cases.
> > > 			 *
> > > 			 * There are a few exceptions though, as an example it is
> > > 			 * a first allocation (early boot up) when we have "one"
> > > 			 * big free space that has to be split.
> > > 			 *
> > > 			 * Also we can hit this path in case of regular "vmap"
> > > 			 * allocations, if "this" current CPU was not preloaded.
> > > 			 * See the comment in alloc_vmap_area() why. If so, then
> > > 			 * GFP_NOWAIT is used instead to get an extra object for
> > > 			 * split purpose. That is rare and most time does not
> > > 			 * occur.
> > > 			 *
> > > 			 * What happens if an allocation gets failed. Basically,
> > > 			 * an "overflow" path is triggered to purge lazily freed
> > > 			 * areas to free some memory, then, the "retry" path is
> > > 			 * triggered to repeat one more time. See more details
> > > 			 * in alloc_vmap_area() function.
> > > 			 */
> > > 			lva = kmem_cache_alloc(vmap_area_cachep, GFP_NOWAIT);
> > > 			if (!lva)
> > > 				return -1;
> > > 		}
> > > <snip>
> > > 
> > > Above allocation fail will meet WARN_ON_ONCE in the current kernel now.
> > > Should It be handled by alloc_vmap_area()?, as you described in a comment.
> > > 
> > WARN_ONCE_ONCE() is a warning and not a panic, though your kernel config
> > considers it as a panic. Right, we go on retry path and we can remove
> 
> Right, only in case panic_on_warn is enabled..
> 
> > the warning only for GFP_NOWAIT-alloc-error. From the other hand we
> > should still have possibility to trigger a warning if an allocation
> > is not successful: no vmap space or low memory condition, thus no
> > physical memory.
> 
> Yes, but GFP_NOWAIT-alloc-error can easily occur for low-memory device.
>
Agree. You are really in a low memory condition. We end up here only if
pre-loading also has not succeeded, i.e. GFP_KERNEL also fails.

But i agree with you, we should "improve the warning" because we drain
and repeat.

> How about changing fix as below?:
> 
> <snip>
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -1468,6 +1468,7 @@ adjust_va_to_fit_type(struct rb_root *root, struct list_head *head,
>                  */
>                 va->va_start = nva_start_addr + size;
>         } else {
> +               WARN_ON_ONCE(1);
>                 return -1;
>         }
>  
> @@ -1522,7 +1523,7 @@ __alloc_vmap_area(struct rb_root *root, struct list_head *head,
>  
>         /* Update the free vmap_area. */
>         ret = adjust_va_to_fit_type(root, head, va, nva_start_addr, size);
> -       if (WARN_ON_ONCE(ret))
> +       if (ret)
>                 return vend;
>  
>  #if DEBUG_AUGMENT_LOWEST_MATCH_CHECK
> @@ -4143,7 +4144,7 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
>                 ret = adjust_va_to_fit_type(&free_vmap_area_root,
>                                             &free_vmap_area_list,
>                                             va, start, size);
> -               if (WARN_ON_ONCE(unlikely(ret)))
> +               if (unlikely(ret))
>                         /* It is a BUG(), but trigger recovery instead. */
>                         goto recovery;
>  
> <snip>
> It will WARN_ONCE_ONCE() only if classify_va_fit_type() is "(type == NOTHING_FIT)".
> 
This is good but i think it should be improved further. We need to
understand from the warning when no memory and when there is no a
vmap space, so:

- if NOTHING_FIT, we should WARN() for sure;
- Second place in the pcpu_get_vm_area(), we do not use NE_FIT. Only in
  the begging after boot, but potentially we can trigger -ENOMEM and we
  should warn in this case. Otherwise you just hide it;
- And last one if after repeating we still do not manage to allocate.

--
Uladzislau Rezki

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ