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. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@xxxxxxxxx. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@xxxxxxxxx"> email@xxxxxxxxx </a>