Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758248AbcCVCbj (ORCPT ); Mon, 21 Mar 2016 22:31:39 -0400 Received: from mail-bn1bon0119.outbound.protection.outlook.com ([157.56.111.119]:49012 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1758054AbcCVCbh (ORCPT ); Mon, 21 Mar 2016 22:31:37 -0400 Authentication-Results: suse.cz; dkim=none (message not signed) header.d=none;suse.cz; dmarc=none action=none header.from=hpe.com; Message-ID: <56F0AE7C.9040204@hpe.com> Date: Mon, 21 Mar 2016 22:31:24 -0400 From: Waiman Long User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.12) Gecko/20130109 Thunderbird/10.0.12 MIME-Version: 1.0 To: Jan Kara CC: Alexander Viro , Jan Kara , Jeff Layton , "J. Bruce Fields" , Tejun Heo , Christoph Lameter , , , 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 References: <1458330244-46434-1-git-send-email-Waiman.Long@hpe.com> <1458330244-46434-2-git-send-email-Waiman.Long@hpe.com> <20160321094918.GG30819@quack.suse.cz> In-Reply-To: <20160321094918.GG30819@quack.suse.cz> Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [72.71.243.139] X-ClientProxiedBy: BY1PR14CA0036.namprd14.prod.outlook.com (25.161.91.46) To DF4PR84MB0315.NAMPRD84.PROD.OUTLOOK.COM (25.162.193.29) X-MS-Office365-Filtering-Correlation-Id: c185648c-d80c-4155-4c19-08d351fa1652 X-Microsoft-Exchange-Diagnostics: 1;DF4PR84MB0315;2:FMRzKpSVvCgb/kazfkzK+Rvk2IuXVAwjdeCS9o7ii3ZjKxLRqjgGjAdHTfdJK24yV6fVNGzqFDyFsw6x60aK9+jW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RCXcySosUS0hsjdR64AfVE8B2iW/y44u9Yb11c1gb/rUetkIEFFc0L4KPXwOfD6Gsj84/ur9sCdCLrb/WKU9EnF0dcaH5WuCDPn/VNZLqrlsVQeVI7QmiJMWRBWy6sQHCQwtz17McjKpM7bKRQLqbgx0iWw==;4:izohu9M6/c7H2nTNxmqvUz+mQMrdK/cV34cPqOYMYeMvoah12POAa2lRXXZyv+7AmCnfr9M7IzGbYgH7rY23eMLyvc6lLLS8IMpM1G7tZa3naFGzYnt0uwm5PxcOMM4osOkHsoLKvth5TgeO+hhGG5n6El2RWkin6ONOmjwy7FFmM2udzu4hKcN+bCprToStqKhcCpDkUV8YjFjVD0fnZQjae13HtqOOwP66OojA9g2Ewhi9x1HNSQQrMjTkevLjwt3hgwyNE/bINzvaxaDRxLJ6/SyeY+Yjei1lxkbEDA5jDzbPdiywikHvBfM9lY/zw+j/INSdAtyF9NRVOZ6Npx3dkIyXjzUXrW5JE4wUrXTxBy+5utMvI4u/JNYLR3wR X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046);SRVR:DF4PR84MB0315;BCL:0;PCL:0;RULEID:;SRVR:DF4PR84MB0315; X-Forefront-PRVS: 08897B549D X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(6049001)(52604005)(377454003)(377424004)(24454002)(5008740100001)(230700001)(117156001)(1096002)(586003)(42186005)(83506001)(33656002)(2906002)(65806001)(65956001)(66066001)(3846002)(77096005)(59896002)(6116002)(47776003)(2950100001)(4326007)(50986999)(87266999)(76176999)(86362001)(65816999)(54356999)(92566002)(4001350100001)(110136002)(64126003)(5004730100002)(189998001)(36756003)(80316001)(23756003)(81166005);DIR:OUT;SFP:1102;SCL:1;SRVR:DF4PR84MB0315;H:[192.168.142.141];FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-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hRyv6S3n98A6ZMVBRA3tT/XDRZbFNF5keHx2AtY?= =?iso-8859-1?Q?csdcUEl1Br+Fnl4HMml10jadNs++FV+UZxCztHyx+j9wvpxugrhp/al+aL?= =?iso-8859-1?Q?JzNgmWTyzaSKuVhfuoRDTs119VnlgK4lu7DZjsIPnJ20eYRmFqMFwsojU5?= =?iso-8859-1?Q?AYYv1Fpp4V6Kt8QygnaHHJzpjtl413eygmLspOWNrVLbAvOYW+j+3kaebr?= =?iso-8859-1?Q?zYM3OA2HKiW2CWPUKYLuha1zkKEzv0iZRKWDpzQdy+yAn5bHLk9W67wTNk?= =?iso-8859-1?Q?saE27gL60N//d0m8DtOpFyOAMjQ=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1;DF4PR84MB0315;5:9qkUKN/JF/lge2k36nymwOrhhPXJsyTGxcqI9toF+GFcM6crcTryI0kOqD79H55HsxFqhxE1fg0+lwpCWH1orVK82DZnWFmqI3zpBtWLrnMaRRSkTB3d3NZCaWfA4klon2m7gkhtMI0openHmlhe9Q==;24:9FDahmW2O1Cb4A25hn/7XvHpXFT2z2oOuuuETevuBq2wIE9C8UjwPaH9I/XcqoH3SvoGvIWnHgiWXITwRl+sfpxtK7XuKRTTurGZrOwsOY0= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: hpe.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Mar 2016 02:31:32.2692 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DF4PR84MB0315 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1331 Lines: 37 On 03/21/2016 05:49 AM, Jan Kara wrote: > 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 I am sorry for missing your previous comment. Yes, it is possible that the list is empty after the lock. So I should have checked for that before returning. Thanks for reminding me that. I will fix that later on. Cheers, Longman