Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1226549imm; Wed, 23 May 2018 12:23:17 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqiKx1yJr65PA3YbIDYQ/5Kp3F2SuvkvsMVwBOaaciX75rkCQkJUs05+9+Edxgce4J3ResG X-Received: by 2002:a63:7001:: with SMTP id l1-v6mr3366455pgc.358.1527103397163; Wed, 23 May 2018 12:23:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527103397; cv=none; d=google.com; s=arc-20160816; b=dQRXW0DmL9ivJq8HJkSABNDbKbOD2UDZweUwqBh7IjEsRFxSev8IMn8X6IOkN+9KMq 0EFHFKguxjkWeF52yM0hRWE0MJE5Lv8cyXP9DF/w82WHkxZr0q1H3b4x1MOwOMgdpYQb W59/Fc5avOBgoo6+ONoFY6ygEtYxAhuMunjgThiuTTdE2uBWWUr66yWhdxk36j4f+rWq O7TsrPqZcw3upHxyDzCwq6PKEl6MSBx7rxCYKntu1ani5aAlwwChpYqO2nWkLkV8WAQQ qs9/KvW4tvH1vWHI+DmrgMoYofJbMF1jVtLjb7VsSos4B6gT43OesWMDwydTzp/nLj6a h8Eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=H6mgmV8/OggXx1aUyaPUGADWvjLTqRBA4i0EflJ5zbI=; b=EsTg7WF1tGUo/jJTqpzyvABErosn8i/wynad+MnuglTJzdC8cB+CMdf3aEtXZcyZda hBk3bQcxT2DfwFJTf9Vztm+1YDqiHzwGkAB1F4evHNJbx/jRs9sXbjlCpVPzGi7IcJKY J+NSyE+hIKDItg1UNlGD0vNB382wC9vBLJcXYcbLYjc2Ix7I6GsSy9rNRdjLsp1evPqh 2Uhcq2C5NQF9WUQ+nNwqIVBFyB6Tc8B1aYlu//J00JJd65Qhz7ZTRsr4SGZJ0+Mp0Yf2 KFQLfv1REJ0AHeAyXJxmVp37NymhL7lRCnHdBF0guM323xTJZzZpbf+VMTvCTtwBlUWI Agwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BVC/5Jsh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p15-v6si14802063pgc.463.2018.05.23.12.23.02; Wed, 23 May 2018 12:23:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BVC/5Jsh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934669AbeEWTWp (ORCPT + 99 others); Wed, 23 May 2018 15:22:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:37676 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934287AbeEWTWl (ORCPT ); Wed, 23 May 2018 15:22:41 -0400 Received: from kernel.org (unknown [24.6.201.58]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DFD7320848; Wed, 23 May 2018 19:22:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527103361; bh=MEedVOg8W+Qjfd/RypPs53w/UiZN/khtxD18QfmpPe0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=BVC/5JshbCUXDqKd0RAkoNIDuCErAwH/A6hgznlpykShGgzimQ8YS/hhD85qw87HL ter+ILddmpiSgrqhGsqsP2QI/gnvOSHxpqiut6WBJDavnorVs52FpOFh6ZKOpuXUon XO6y2f+K50ll4TG66jXQXwSnxAvt2diQomRyCprY= Date: Wed, 23 May 2018 12:22:39 -0700 From: Shaohua Li To: Peter Zijlstra Cc: Matthew Wilcox , Sebastian Andrzej Siewior , linux-kernel@vger.kernel.org, tglx@linutronix.de, Ingo Molnar , linux-mm@kvack.org, linux-raid@vger.kernel.org, Anna-Maria Gleixner Subject: Re: [PATCH 3/8] md: raid5: use refcount_t for reference counting instead atomic_t Message-ID: <20180523192239.GA59657@kernel.org> References: <20180509193645.830-1-bigeasy@linutronix.de> <20180509193645.830-4-bigeasy@linutronix.de> <20180523132119.GC19987@bombadil.infradead.org> <20180523174904.GY12198@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180523174904.GY12198@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 23, 2018 at 07:49:04PM +0200, Peter Zijlstra wrote: > On Wed, May 23, 2018 at 06:21:19AM -0700, Matthew Wilcox wrote: > > On Wed, May 09, 2018 at 09:36:40PM +0200, Sebastian Andrzej Siewior wrote: > > > refcount_t type and corresponding API should be used instead of atomic_t when > > > the variable is used as a reference counter. This allows to avoid accidental > > > refcounter overflows that might lead to use-after-free situations. > > > > > > Most changes are 1:1 replacements except for > > > BUG_ON(atomic_inc_return(&sh->count) != 1); > > > > > > which has been turned into > > > refcount_inc(&sh->count); > > > BUG_ON(refcount_read(&sh->count) != 1); > > > > @@ -5387,7 +5387,8 @@ static struct stripe_head *__get_priority_stripe(struct > > +r5conf *conf, int group) > > sh->group = NULL; > > } > > list_del_init(&sh->lru); > > - BUG_ON(atomic_inc_return(&sh->count) != 1); > > + refcount_inc(&sh->count); > > + BUG_ON(refcount_read(&sh->count) != 1); > > return sh; > > } > > > > > > That's the only problematic usage. And I think what it's really saying is: > > > > BUG_ON(refcount_read(&sh->count) != 0); > > refcount_set(&sh->count, 1); > > > > With that, this looks like a reasonable use of refcount_t to me. > > I'm not so sure, look at: > > r5c_do_reclaim(): > > if (!list_empty(&sh->lru) && > !test_bit(STRIPE_HANDLE, &sh->state) && > atomic_read(&sh->count) == 0) { > r5c_flush_stripe(cond, sh) > > Which does: > > r5c_flush_stripe(): > > atomic_inc(&sh->count); > > Which is another inc-from-zero. Also, having sh's with count==0 in a > list is counter to the concept of refcounts and smells like usage-counts > to me. For refcount 0 really means deads and gone. > > If this really is supposed to be a refcount, someone more familiar with > the raid5 should do the patch and write a comprehensive changelog on it. I don't know what is changed in the refcount, such raid5 change has attempted before and didn't work. 0 for the stripe count is a valid usage and we do inc-from-zero in several places. Thanks, Shaohua