From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753409AbcAOCdL (ORCPT ); Thu, 14 Jan 2016 21:33:11 -0500 Received: from LGEAMRELO12.lge.com ([156.147.23.52]:36079 "EHLO lgeamrelo12.lge.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751577AbcAOCdK (ORCPT ); Thu, 14 Jan 2016 21:33:10 -0500 X-Original-SENDERIP: 156.147.1.151 X-Original-MAILFROM: minchan@kernel.org X-Original-SENDERIP: 165.244.98.76 X-Original-MAILFROM: minchan@kernel.org X-Original-SENDERIP: 10.177.223.161 X-Original-MAILFROM: minchan@kernel.org Date: Fri, 15 Jan 2016 11:35:18 +0900 From: Minchan Kim To: Junil Lee CC: ngupta@vflare.org, sergey.senozhatsky.work@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] zsmalloc: fix migrate_zspage-zs_free race condition Message-ID: <20160115023518.GA10843@bbox> References: <1452818184-2994-1-git-send-email-junil0814.lee@lge.com> MIME-Version: 1.0 In-Reply-To: <1452818184-2994-1-git-send-email-junil0814.lee@lge.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-MIMETrack: Itemize by SMTP Server on LGEKRMHUB08/LGE/LG Group(Release 8.5.3FP6|November 21, 2013) at 2016/01/15 11:33:06, Serialize by Router on LGEKRMHUB08/LGE/LG Group(Release 8.5.3FP6|November 21, 2013) at 2016/01/15 11:33:06, Serialize complete at 2016/01/15 11:33:06 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Junil, On Fri, Jan 15, 2016 at 09:36:24AM +0900, Junil Lee wrote: > To prevent unlock at the not correct situation, tagging the new obj to > assure lock in migrate_zspage() before right unlock path. > > Two functions are in race condition by tag which set 1 on last bit of > obj, however unlock succrently when update new obj to handle before call > unpin_tag() which is right unlock path. > > summarize this problem by call flow as below: > > CPU0 CPU1 > migrate_zspage > find_alloced_obj() > trypin_tag() -- obj |= HANDLE_PIN_BIT > obj_malloc() -- new obj is not set zs_free > record_obj() -- unlock and break sync pin_tag() -- get lock > unpin_tag() It's really good catch! I think it should be stable material. For that, we should know this patch fixes what kinds of problem. What do you see problem? I mean please write down the oops you saw and verify that the patch fixes your problem. :) Minor nit below > > Signed-off-by: Junil Lee > --- > mm/zsmalloc.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c > index e7414ce..bb459ef 100644 > --- a/mm/zsmalloc.c > +++ b/mm/zsmalloc.c > @@ -1635,6 +1635,7 @@ static int migrate_zspage(struct zs_pool *pool, struct size_class *class, > free_obj = obj_malloc(d_page, class, handle); > zs_object_copy(free_obj, used_obj, class); > index++; > + free_obj |= BIT(HANDLE_PIN_BIT); > record_obj(handle, free_obj); I think record_obj should store free_obj to *handle with masking off least bit. IOW, how about this? record_obj(handle, obj) { *(unsigned long)handle = obj & ~(1<