Re: + hugetlb-handle-nodemask_alloc-failure-correctly.patch addedto -mm tree

From: David Rientjes
Date: Thu Jan 06 2011 - 19:42:19 EST


On Thu, 6 Jan 2011, akpm@xxxxxxxxxxxxxxxxxxxx wrote:

> diff -puN mm/hugetlb.c~hugetlb-handle-nodemask_alloc-failure-correctly mm/hugetlb.c
> --- a/mm/hugetlb.c~hugetlb-handle-nodemask_alloc-failure-correctly
> +++ a/mm/hugetlb.c
> @@ -1374,14 +1374,19 @@ static ssize_t nr_hugepages_store_common
> struct hstate *h;
> NODEMASK_ALLOC(nodemask_t, nodes_allowed, GFP_KERNEL | __GFP_NORETRY);
>
> + if (!nodes_allowed) {
> + err = -ENOMEM;
> + goto out;
> + }
> +
> err = strict_strtoul(buf, 10, &count);
> if (err)
> - goto out;
> + goto out_free_mask;
>
> h = kobj_to_hstate(kobj, &nid);
> if (h->order >= MAX_ORDER) {
> err = -EINVAL;
> - goto out;
> + goto out_free_mask;
> }
>
> if (nid == NUMA_NO_NODE) {
> @@ -1409,8 +1414,9 @@ static ssize_t nr_hugepages_store_common
> NODEMASK_FREE(nodes_allowed);
>
> return len;
> -out:
> +out_free_mask:
> NODEMASK_FREE(nodes_allowed);
> +out:
> return err;
> }
>
> @@ -1886,6 +1892,12 @@ static int hugetlb_sysctl_handler_common
> if (write) {
> NODEMASK_ALLOC(nodemask_t, nodes_allowed,
> GFP_KERNEL | __GFP_NORETRY);
> +
> + if (!nodes_allowed) {
> + ret = -ENOMEM;
> + goto out;
> + }
> +
> if (!(obey_mempolicy &&
> init_nodemask_of_mempolicy(nodes_allowed))) {
> NODEMASK_FREE(nodes_allowed);

This patch is wrong, both functions may handle a NULL nodes_allowed, which
is why the __GFP_NORETRY is explicitly part of the gfp mask.

In both functions, init_nodemask_of_mempolicy() will immediately return
false if the mask is NULL. If so, it is set to node_states[N_HIGH_MEMORY]
in the caller and we're careful to avoid calling the NODMASK_FREE() in
that case. They are carefully coded in this way so they operate over all
nodes with memory rather than failing with -ENOMEM.

[ On a seperate topic, all users of NODEMASK_ALLOC() that may gracefully
fail and have error handling should also use __GFP_NORETRY, such as in
all the cpuset users. ]
--
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/