Re: [PATCH] memory-hotplug: don't BUG() in register_memory_resource()

From: Andrew Morton
Date: Mon Dec 21 2015 - 18:06:55 EST


On Mon, 21 Dec 2015 11:13:15 +0100 Vitaly Kuznetsov <vkuznets@xxxxxxxxxx> wrote:

> Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> writes:
>
> > On Fri, 18 Dec 2015 15:50:24 +0100 Vitaly Kuznetsov <vkuznets@xxxxxxxxxx> wrote:
> >
> >> Out of memory condition is not a bug and while we can't add new memory in
> >> such case crashing the system seems wrong. Propagating the return value
> >> from register_memory_resource() requires interface change.
> >>
> >> --- a/mm/memory_hotplug.c
> >> +++ b/mm/memory_hotplug.c
> >> +static int register_memory_resource(u64 start, u64 size,
> >> + struct resource **resource)
> >> {
> >> struct resource *res;
> >> res = kzalloc(sizeof(struct resource), GFP_KERNEL);
> >> - BUG_ON(!res);
> >> + if (!res)
> >> + return -ENOMEM;
> >>
> >> res->name = "System RAM";
> >> res->start = start;
> >> @@ -140,9 +142,10 @@ static struct resource *register_memory_resource(u64 start, u64 size)
> >> if (request_resource(&iomem_resource, res) < 0) {
> >> pr_debug("System RAM resource %pR cannot be added\n", res);
> >> kfree(res);
> >> - res = NULL;
> >> + return -EEXIST;
> >> }
> >> - return res;
> >> + *resource = res;
> >> + return 0;
> >> }
> >
> > Was there a reason for overwriting the request_resource() return
> > value?
> > Ordinarily it should be propagated back to callers.
> >
> > Please review.
> >
>
> This is a nice-to-have addition but it will break at least ACPI
> memhotplug: request_resource() has the following:
>
> conflict = request_resource_conflict(root, new);
> return conflict ? -EBUSY : 0;
>
> so we'll end up returning -EBUSY from register_memory_resource() and
> add_memory(), at the same time acpi_memory_enable_device() counts on
> -EEXIST:
>
> result = add_memory(node, info->start_addr, info->length);
>
> /*
> * If the memory block has been used by the kernel, add_memory()
> * returns -EEXIST. If add_memory() returns the other error, it
> * means that this memory block is not used by the kernel.
> */
> if (result && result != -EEXIST)
> continue;
>
> So I see 3 options here:
> 1) Keep the overwrite
> 2) Change the request_resource() return value to -EEXIST
> 3) Adapt all add_memory() call sites to -EBUSY.
>
> Please let me know your preference.

urgh, what a mess. We should standardize on EBUSY or EEXIST, I don't
see that it matter much which is chosen. And for robustness the
callers should be checking for (err < 0) unless there's a very good
reason otherwise.

But it doesn't seem terribly important.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/