lkml.org 
[lkml]   [2013]   [Aug]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] cpuset: mm: Reduce large amounts of memory barrier related damage v3
On Thu, Aug 29, 2013 at 11:43:42AM +0200, Peter Zijlstra wrote:
> > diff --git a/mm/mempolicy.c b/mm/mempolicy.c
> > index 7431001..ae880c3 100644
> > --- a/mm/mempolicy.c
> > +++ b/mm/mempolicy.c
> > @@ -1755,22 +1755,24 @@ unsigned slab_node(void)
> > }
> >
> > /* Do static interleaving for a VMA with known offset. */
> > -static unsigned offset_il_node(struct mempolicy *pol,
> > +static unsigned int offset_il_node(struct mempolicy *pol,
> > struct vm_area_struct *vma, unsigned long off)
> > {
> > - unsigned nnodes = nodes_weight(pol->v.nodes);
> > - unsigned target;
> > - int c;
> > - int nid = -1;
> > + unsigned int nr_nodes, target;
> > + int i, nid;
> >
> > - if (!nnodes)
> > +again:
> > + nr_nodes = nodes_weight(pol->v.nodes);
> > + if (!nr_nodes)
> > return numa_node_id();
> > - target = (unsigned int)off % nnodes;
> > - c = 0;
> > - do {
> > + target = (unsigned int)off % nr_nodes;
> > + for (i = 0, nid = first_node(pol->v.nodes); i < target; i++)
> > nid = next_node(nid, pol->v.nodes);
> > - c++;
> > - } while (c <= target);
> > +
> > + /* Policy nodemask can potentially update in parallel */
> > + if (unlikely(!node_isset(nid, pol->v.nodes)))
> > + goto again;
> > +
> > return nid;
> > }
>
> So I explicitly didn't use the node_isset() test because that's more
> likely to trigger than the nid >= MAX_NUMNODES test. Its fine to return
> a node that isn't actually part of the mask anymore -- a race is a race
> anyway.

Oh more importantly, if nid does indeed end up being >= MAX_NUMNODES as
is possible with next_node() the node_isset() test will be out-of-bounds
and can crash itself.


\
 
 \ /
  Last update: 2013-08-30 14:41    [W:0.099 / U:0.132 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site