From patchwork Wed Jan 10 04:58:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Theodore Ts'o X-Patchwork-Id: 10153951 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5336F60223 for ; Wed, 10 Jan 2018 04:58:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 452EB27F60 for ; Wed, 10 Jan 2018 04:58:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3997E27F82; Wed, 10 Jan 2018 04:58:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E413C27F60 for ; Wed, 10 Jan 2018 04:58:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932501AbeAJE6R (ORCPT ); Tue, 9 Jan 2018 23:58:17 -0500 Received: from imap.thunk.org ([74.207.234.97]:57510 "EHLO imap.thunk.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932424AbeAJE6R (ORCPT ); Tue, 9 Jan 2018 23:58:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=thunk.org; s=ef5046eb; 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=ulEdh83ijzy0aDYj4iAglBWn8mZ0EH9GFKs5NVospTM=; b=mLQKz2tcSTnhqAQYOD/N7qT2Ff /ZhxdmECH7yZwhqocALthx6Y13V6111Xdam2BaFuBDMeGDSPBbXIRnQaphoGpM6yjAcnO96CEQ85T orOkhyf14uVNihjQmBaxdsJZOZd4gWBsuWAsd2qh9M2hjqHBfzvHUYGY9ucmHOHbWeVA=; Received: from root (helo=callcc.thunk.org) by imap.thunk.org with local-esmtp (Exim 4.89) (envelope-from ) id 1eZ8Ss-0000Xd-0d; Wed, 10 Jan 2018 04:58:14 +0000 Received: by callcc.thunk.org (Postfix, from userid 15806) id 017A3C00226; Tue, 9 Jan 2018 23:58:12 -0500 (EST) Date: Tue, 9 Jan 2018 23:58:12 -0500 From: Theodore Ts'o To: Jiang Biao Cc: linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, ebiggers@google.com, akpm@linux-foundation.org, jack@suse.cz, zhong.weidong@zte.com.cn Subject: Re: [PATCH v2] fs/mbcache: make sure mb_cache_count() not return negative value. Message-ID: <20180110045812.GD5809@thunk.org> References: <1515454691-69220-1-git-send-email-jiang.biao2@zte.com.cn> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1515454691-69220-1-git-send-email-jiang.biao2@zte.com.cn> User-Agent: Mutt/1.9.2 (2017-12-15) X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: tytso@thunk.org X-SA-Exim-Scanned: No (on imap.thunk.org); SAEximRunCond expanded to false Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP I think I've found the cause of it, but having a sanity check is a good idea. I've simplified the patch and its description, though. This is what I have in my tree. - Ted commit 252194e48f00d146de303822bba8c3568ca127cd Author: Jiang Biao Date: Tue Jan 9 23:57:52 2018 -0500 mbcache: make sure c_entry_count is not decremented past zero Signed-off-by: Jiang Biao Signed-off-by: Theodore Ts'o CC: Eric Biggers CC: Andrew Morton CC: Jan Kara diff --git a/fs/mbcache.c b/fs/mbcache.c index 0851af5c1c3d..f2f15b747bed 100644 --- a/fs/mbcache.c +++ b/fs/mbcache.c @@ -239,7 +239,9 @@ void mb_cache_entry_delete(struct mb_cache *cache, u32 key, u64 value) spin_lock(&cache->c_list_lock); if (!list_empty(&entry->e_list)) { list_del_init(&entry->e_list); - cache->c_entry_count--; + if (!WARN_ONCE(cache->c_entry_count == 0, + "mbcache: attempt to decrement c_entry_count past zero")) + cache->c_entry_count--; atomic_dec(&entry->e_refcnt); } spin_unlock(&cache->c_list_lock);