Michal Hocko
2018-Apr-20 13:08 UTC
[PATCH] kvmalloc: always use vmalloc if CONFIG_DEBUG_VM
On Thu 19-04-18 12:12:38, Mikulas Patocka wrote: [...]> From: Mikulas Patocka <mpatocka at redhat.com> > Subject: [PATCH] kvmalloc: always use vmalloc if CONFIG_DEBUG_VM > > The kvmalloc function tries to use kmalloc and falls back to vmalloc if > kmalloc fails. > > Unfortunatelly, some kernel code has bugs - it uses kvmalloc and then > uses DMA-API on the returned memory or frees it with kfree. Such bugs were > found in the virtio-net driver, dm-integrity or RHEL7 powerpc-specific > code. > > These bugs are hard to reproduce because vmalloc falls back to kmalloc > only if memory is fragmented. > > In order to detect these bugs reliably I submit this patch that changes > kvmalloc to always use vmalloc if CONFIG_DEBUG_VM is turned on.No way. This is just wrong! First of all, you will explode most likely on many allocations of small sizes. Second, CONFIG_DEBUG_VM tends to be enabled quite often.> Signed-off-by: Mikulas Patocka <mpatocka at redhat.com>Nacked-by: Michal Hocko <mhocko at suse.com>> --- > mm/util.c | 2 ++ > 1 file changed, 2 insertions(+) > > Index: linux-2.6/mm/util.c > ==================================================================> --- linux-2.6.orig/mm/util.c 2018-04-18 15:46:23.000000000 +0200 > +++ linux-2.6/mm/util.c 2018-04-18 16:00:43.000000000 +0200 > @@ -395,6 +395,7 @@ EXPORT_SYMBOL(vm_mmap); > */ > void *kvmalloc_node(size_t size, gfp_t flags, int node) > { > +#ifndef CONFIG_DEBUG_VM > gfp_t kmalloc_flags = flags; > void *ret; > > @@ -426,6 +427,7 @@ void *kvmalloc_node(size_t size, gfp_t f > */ > if (ret || size <= PAGE_SIZE) > return ret; > +#endif > > return __vmalloc_node_flags_caller(size, node, flags, > __builtin_return_address(0));-- Michal Hocko SUSE Labs
Matthew Wilcox
2018-Apr-20 13:41 UTC
[PATCH] kvmalloc: always use vmalloc if CONFIG_DEBUG_VM
On Fri, Apr 20, 2018 at 03:08:52PM +0200, Michal Hocko wrote:> > In order to detect these bugs reliably I submit this patch that changes > > kvmalloc to always use vmalloc if CONFIG_DEBUG_VM is turned on. > > No way. This is just wrong! First of all, you will explode most likely > on many allocations of small sizes. Second, CONFIG_DEBUG_VM tends to be > enabled quite often.I think it'll still suit Mikulas' debugging needs if we always use vmalloc for sizes above PAGE_SIZE?
Michal Hocko
2018-Apr-20 13:49 UTC
[PATCH] kvmalloc: always use vmalloc if CONFIG_DEBUG_VM
On Fri 20-04-18 06:41:36, Matthew Wilcox wrote:> On Fri, Apr 20, 2018 at 03:08:52PM +0200, Michal Hocko wrote: > > > In order to detect these bugs reliably I submit this patch that changes > > > kvmalloc to always use vmalloc if CONFIG_DEBUG_VM is turned on. > > > > No way. This is just wrong! First of all, you will explode most likely > > on many allocations of small sizes. Second, CONFIG_DEBUG_VM tends to be > > enabled quite often. > > I think it'll still suit Mikulas' debugging needs if we always use > vmalloc for sizes above PAGE_SIZE?Even if that was the case then this doesn't sounds like CONFIG_DEBUG_VM material. We do not want a completely different behavior when the config is enabled. If we really need some better fallback testing coverage then the fault injection, as suggested by Vlastimil, sounds much more reasonable to me -- Michal Hocko SUSE Labs
Mikulas Patocka
2018-Apr-20 20:54 UTC
[PATCH] kvmalloc: always use vmalloc if CONFIG_DEBUG_VM
On Fri, 20 Apr 2018, Michal Hocko wrote:> On Thu 19-04-18 12:12:38, Mikulas Patocka wrote: > [...] > > From: Mikulas Patocka <mpatocka at redhat.com> > > Subject: [PATCH] kvmalloc: always use vmalloc if CONFIG_DEBUG_VM > > > > The kvmalloc function tries to use kmalloc and falls back to vmalloc if > > kmalloc fails. > > > > Unfortunatelly, some kernel code has bugs - it uses kvmalloc and then > > uses DMA-API on the returned memory or frees it with kfree. Such bugs were > > found in the virtio-net driver, dm-integrity or RHEL7 powerpc-specific > > code. > > > > These bugs are hard to reproduce because vmalloc falls back to kmalloc > > only if memory is fragmented. > > > > In order to detect these bugs reliably I submit this patch that changes > > kvmalloc to always use vmalloc if CONFIG_DEBUG_VM is turned on. > > No way. This is just wrong! First of all, you will explode most likely > on many allocations of small sizes. Second, CONFIG_DEBUG_VM tends to be > enabled quite often.You're an evil person who doesn't want to fix bugs. You refused to fix vmalloc(GFP_NOIO) misbehavior a year ago (did you make some progress with it since that time?) and you refuse to fix kvmalloc misuses. I tried this patch on text-only virtual machine and /proc/vmallocinfo shows 614kB more memory. I tried it on a desktop machine with the chrome browser open and /proc/vmallocinfo space is increased by 7MB. So no - this won't exhaust memory and kill the machine. Arguing that this increases memory consumption is as bogus as arguing that CONFIG_LOCKDEP increses memory consumption. No one is forcing you to enable CONFIG_LOCKDEP and no one is forcing you to enable this kvmalloc test too. Mikulas
Matthew Wilcox
2018-Apr-20 21:02 UTC
[PATCH] kvmalloc: always use vmalloc if CONFIG_DEBUG_VM
On Fri, Apr 20, 2018 at 04:54:53PM -0400, Mikulas Patocka wrote:> On Fri, 20 Apr 2018, Michal Hocko wrote: > > No way. This is just wrong! First of all, you will explode most likely > > on many allocations of small sizes. Second, CONFIG_DEBUG_VM tends to be > > enabled quite often. > > You're an evil person who doesn't want to fix bugs.Steady on. There's no need for that. Michal isn't evil. Please apologise.> You refused to fix vmalloc(GFP_NOIO) misbehavior a year ago (did you make > some progress with it since that time?) and you refuse to fix kvmalloc > misuses.I understand you're frustrated, but this is not the way to get the problems fixed.> I tried this patch on text-only virtual machine and /proc/vmallocinfo > shows 614kB more memory. I tried it on a desktop machine with the chrome > browser open and /proc/vmallocinfo space is increased by 7MB. So no - this > won't exhaust memory and kill the machine.This is good data, thank you for providing it.> Arguing that this increases memory consumption is as bogus as arguing that > CONFIG_LOCKDEP increses memory consumption. No one is forcing you to > enable CONFIG_LOCKDEP and no one is forcing you to enable this kvmalloc > test too.I think there's a real problem which is that CONFIG_DEBUG_VM is too broad. It inserts code in a *lot* of places, some of which is quite expensive. We would do better to split it into more granular pieces ... although an explosion of configuration options isn't great either. Maybe just CONFIG_DEBUG_VM and CONFIG_DEBUG_VM_EXPENSIVE. Michal may be wrong, but he's not evil.
Seemingly Similar Threads
- [PATCH] kvmalloc: always use vmalloc if CONFIG_DEBUG_VM
- [PATCH] kvmalloc: always use vmalloc if CONFIG_DEBUG_VM
- [PATCH] kvmalloc: always use vmalloc if CONFIG_DEBUG_VM
- [PATCH] kvmalloc: always use vmalloc if CONFIG_DEBUG_VM
- [PATCH] kvmalloc: always use vmalloc if CONFIG_DEBUG_VM