Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752647AbcCUJs7 (ORCPT ); Mon, 21 Mar 2016 05:48:59 -0400 Received: from mx2.suse.de ([195.135.220.15]:57138 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752281AbcCUJsx (ORCPT ); Mon, 21 Mar 2016 05:48:53 -0400 Date: Mon, 21 Mar 2016 10:49:18 +0100 From: Jan Kara To: Waiman Long Cc: Alexander Viro , Jan Kara , Jeff Layton , "J. Bruce Fields" , Tejun Heo , Christoph Lameter , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Ingo Molnar , Peter Zijlstra , Andi Kleen , Dave Chinner , Boqun Feng , Scott J Norton , Douglas Hatch Subject: Re: [PATCH v6 1/4] lib/percpu-list: Per-cpu list with associated per-cpu locks Message-ID: <20160321094918.GG30819@quack.suse.cz> References: <1458330244-46434-1-git-send-email-Waiman.Long@hpe.com> <1458330244-46434-2-git-send-email-Waiman.Long@hpe.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1458330244-46434-2-git-send-email-Waiman.Long@hpe.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1070 Lines: 33 On Fri 18-03-16 15:44:01, Waiman Long wrote: > +static __always_inline bool > +__pcpu_list_next_cpu(struct pcpu_list_head *head, struct pcpu_list_state *state) > +{ > + if (state->lock) > + spin_unlock(state->lock); > +next_cpu: > + /* > + * for_each_possible_cpu(cpu) > + */ > + state->cpu = cpumask_next(state->cpu, cpu_possible_mask); > + if (state->cpu >= nr_cpu_ids) > + return false; /* All the per-cpu lists iterated */ > + > + state->head = &per_cpu_ptr(head, state->cpu)->list; > + if (list_empty(state->head)) > + goto next_cpu; > + > + state->lock = &per_cpu_ptr(head, state->cpu)->lock; > + spin_lock(state->lock); > + state->curr = list_entry(state->head->next, > + struct pcpu_list_node, list); > + return true; Waiman, I repeat it for the third time as you keep ignoring it: This is *racy*. The list for state->cpu can be empty by the time you acquire state->lock and thus state->curr will point somewhere around the head of the list but definitely not to a list member where it should. Honza -- Jan Kara SUSE Labs, CR