Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1134959imm; Wed, 23 May 2018 10:49:43 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqvVePUQtIEMP02vg5NoejAwenHd5H9iJpAw1IRS8d3KOo4K07nY0djDvKratVsKlmV4iU5 X-Received: by 2002:a17:902:758d:: with SMTP id j13-v6mr3948423pll.188.1527097783571; Wed, 23 May 2018 10:49:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527097783; cv=none; d=google.com; s=arc-20160816; b=U6UkhaRXfUxzES7zlaRJzHsPGl1ZBUv23r/J/gE8CMTnOKhA2b0RDnTC76GtpjvD72 Mno4XW8Dy967HdNu796BjH2HSZcY8wuyUrNX7uXRvLqQx9Wvw+sNWJp3yV2Ct8c7CWjh W1RRr8kJuXDuJjzNMpBQ/pIWr+F9t8GZqjl8XtcNeVEiZAraA3M+8DpPGg6HKHUQJ8Qu 1EOxrg4R0tPG7lp4FlyhanVs2Jsg/YBGXcLn09t75jTu5xPdmsYVPSc7pJ2v4XBwdwE7 Bj5lb5hELSztwRc4Fs+xWdCDpAW9OGwzlCmVmzo31Rz3OzHLsIZ44xoeTHt6t0iUe/ut C5rA== 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=iIDcgh5llbXV2Z6fxJuMbVxwGQXkcz2tkdUIN9Mo22o=; b=E5X/rDFHDns5z1qtc4kvkuROhHJd8tCwbPNZ94Szd6HgX8D9SgOeVWsAqWEplwqj+f 88wjhpwKLASWw7rq8OVgpy25eszvnbl0Jlc9wv2YS9+nx0xgi5HIXE7MTCnZrP0QeKvq fccZ2jUvWRyen7ryWWYAR5VfHRjQDWDNlhG5foYClel6UBQrl3NvwzrPg/Dm2LJ4WJ/I WroGLx/DiTiiWfBQ8CA3lihe5XOwcADf7TLnZB/dNsgsP/7+QwqAuBuWNjdFupCGBg+8 gpB+Tvvnb0WtjAOmao2z5EGr761RVeOdqE+03ExIvob+/npoqjRI2D1FpS+5tq+4J0n8 SHVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=W+SIKISP; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f2-v6si15560963pgq.444.2018.05.23.10.49.29; Wed, 23 May 2018 10:49:43 -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=fail header.i=@infradead.org header.s=merlin.20170209 header.b=W+SIKISP; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933890AbeEWRtR (ORCPT + 99 others); Wed, 23 May 2018 13:49:17 -0400 Received: from merlin.infradead.org ([205.233.59.134]:49106 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933144AbeEWRtN (ORCPT ); Wed, 23 May 2018 13:49:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=iIDcgh5llbXV2Z6fxJuMbVxwGQXkcz2tkdUIN9Mo22o=; b=W+SIKISP608Rd/UukXX8ZO8qz oMY/kpDsISfQILYrPc15zCWorKZRQVikx6JizQr6SLftP7XQSkjzJsqKXTz0+3w4SCQcY45zjq9DG 8x9NSWMpbiOEchnYKaQQftiFqc6Wdf32WkQlNlAgn6nN+bWqei2e03y2gDZZY9EaCkALe1pOhUalr jdqaUWpEEWmlnB5m43xbcBiP/3dgrBd4EqbcFQ1IHL0NMLENzxjOVNTpb/hXzSVFOpuRMm2B2L88f Bh2oYWGgBDRDB9zFsi6YIcFz3Ryp0VYaWVN6AQykmIYPt2AqOI15UBeL45dIYWnjWktvrpBaK+2hi hZqGpckaw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fLXso-0007EC-8I; Wed, 23 May 2018 17:49:06 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 6717F2029F1C0; Wed, 23 May 2018 19:49:04 +0200 (CEST) Date: Wed, 23 May 2018 19:49:04 +0200 From: Peter Zijlstra To: Matthew Wilcox Cc: Sebastian Andrzej Siewior , linux-kernel@vger.kernel.org, tglx@linutronix.de, Ingo Molnar , linux-mm@kvack.org, Shaohua Li , 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: <20180523174904.GY12198@hirez.programming.kicks-ass.net> References: <20180509193645.830-1-bigeasy@linutronix.de> <20180509193645.830-4-bigeasy@linutronix.de> <20180523132119.GC19987@bombadil.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180523132119.GC19987@bombadil.infradead.org> User-Agent: Mutt/1.9.5 (2018-04-13) 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 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.