Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp836787imm; Wed, 23 May 2018 06:23:15 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqKxdlcFRgYiiBD4CtAkvdCd42fMsrtNosL6EZhFGTwBHEEoqE8fjCcTW8/zH6i37EoLtVz X-Received: by 2002:a17:902:2f84:: with SMTP id t4-v6mr3086316plb.24.1527081795656; Wed, 23 May 2018 06:23:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527081795; cv=none; d=google.com; s=arc-20160816; b=wvhYxJhmgIpqYzA7yRw7B5Ewlujq3Q+sLpqAtCOMhaGHsfo0gsIJOOAwpkpDUmmrMz d4rRRELA0c6cXzycyFapb7Txeca8U5Xdu2TvZhV/BfS0z9zJ69BzyHiSS/wnKDviGqm3 Wm3YW/g7ESrE3fvOgzT+1r6S/wsYYQJ1MSpc3tRP1Kf1nib8yH3Qhtm8mTJiqDEv6J1q GC3aAJ/OWPiznYpKHu9tXm80D/txWFSDctWR1P36I2GXY3r8BfQ7uc41rtuUXIExf3DO kugrIZLa3Cyob//77s2p+plNQC41cXHbFXvGJnaprWzfVUiO2FpjVKQnFFe8M99Xcp4w 144w== 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=n1/nYbRONYOQ5y0bmbJk/Kphro5MROE/HidO6X4If50=; b=zG4Z+b0knXdcc4MkDuw5i5LSJtPY88IT0Z2UmGnEfJV47VCJ2tFKT/ING4felGbDTv QS3ZcNJlKl1E+wvAw75BvvvAM4t3Bqfx7P1rGLUsrAk6KQaSO+9vK9p0VmTHaFrOCkFP 50TRVKB9+cfe7OfjgyOMY/IwJrGY9a99kKPd93A32Jn/BwO38ospRUnVzAGkyZYHd6zg 9sfhtJaORnl3ms8htkKRO9yjnVBTui3Xmnz9eliBzkwNtRgpwysGVArDZ5SO1/lWriMc MPFGwJ2o1i69DFa4m2nr6T2pDEc41SoisiQv0fBtXHkQAUbXcEq9NhJmY0BXXa6cTK92 LGGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=h5mvmkqE; 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 f5-v6si18635501plj.86.2018.05.23.06.23.00; Wed, 23 May 2018 06:23:15 -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=bombadil.20170209 header.b=h5mvmkqE; 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 S932965AbeEWNV1 (ORCPT + 99 others); Wed, 23 May 2018 09:21:27 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:44882 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932844AbeEWNVW (ORCPT ); Wed, 23 May 2018 09:21:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.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=n1/nYbRONYOQ5y0bmbJk/Kphro5MROE/HidO6X4If50=; b=h5mvmkqEltep7xUlI8XGGIRgk P04BI9xT6KUH1kGexDIji472wq2Mfkc2407e+Ly/zQTTbE/hECn1gJMMuDBuJXIbL0PU7pOdXwTdo BMlerSn1egl+DsnqqrsSZjzT1rJcQ76eXTpob3M3NiREzq3+qIJ+O9a/F49ymNBf9aQL82b/bSo+Z 8u96yHQQPxjV3+dDB/fz2Mu8m/Hi1NsGhUwRwvMmyRTqGUEQ/RbBgpOZ1nHUc3iiQ6ai0trPc6dXH uwiCFl0k3z2Hu4o6WVlADlFbq+ZRWPNXdR/IPIEv1DR4GadjdKJoaa34M0J5+1ffE/0Avs0/gWk6R YXOoawIBg==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fLThf-0007It-Jp; Wed, 23 May 2018 13:21:19 +0000 Date: Wed, 23 May 2018 06:21:19 -0700 From: Matthew Wilcox To: Sebastian Andrzej Siewior Cc: linux-kernel@vger.kernel.org, tglx@linutronix.de, Peter Zijlstra , 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: <20180523132119.GC19987@bombadil.infradead.org> References: <20180509193645.830-1-bigeasy@linutronix.de> <20180509193645.830-4-bigeasy@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180509193645.830-4-bigeasy@linutronix.de> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.