Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp4142393pxb; Mon, 27 Sep 2021 10:14:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJww2yDwDIw2hOnFicTHJSJ86ZrJhZJey4i39NORtkYuoi3I0RXDvP2QzHD8zkVxMqwpqRss X-Received: by 2002:a63:6981:: with SMTP id e123mr628695pgc.419.1632762877441; Mon, 27 Sep 2021 10:14:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632762877; cv=none; d=google.com; s=arc-20160816; b=iLlwjbw+uPziE6WpwT10V0/Gvs2u89vy8lTqp2lMJI26XfSGO4bvL5xjxP0VEHtRBc gGD/GSTmD83qcUJUhBQ2qqd/mapcQEuIaHooloM82BOsigXS9plU6h48yh7mRlgUkWRZ OvkQQbTZr6sJegFG2VKKzndbT5yaszklWwkfP0he31oAia3Nx3QTPz2DZIn5hWnZfzp2 L1kh4nypVq/9rwcUoDm+fi3WWy1XRbSXKDtTA4V+ooQ2xyh/1R4okLRxhgNz6M/4kbSi U/0UQ+Y+TkTS1XLXDD+/avvJzsLYSv23tl5tTLqOPrZUp9RRhv38BwvoCYeXkRIU+B63 D0eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=oa/asFgShjhHCk8y3jdYSlGc1DV6BqUHlYryg3Bocu4=; b=PYxU8w+UGy8yXFUj+hrZ3b/a/4GdRplg1rtxuHzqLDX7mFcof1ytj1VejlYrU4FHho zUb8q00ohHjME0jsmbs6mc3qI+pYzUfmF+drXCJlBFyZGlUV1CNePAlgKY16U6zWCmxW GOq7Df05VAUvkG005ADWPZLEf4emAI5w5KKCF9kbv75kotW6T0Qy7AqjTEmj6VI0Iri+ gk5/GwlUNZIidk2CY2nXYSaZkUvz5TsoJ6udlCkFLWM20Ckm9VEE91UI91kQyJZ+q6hv AOJ5vCtL/w7VnU8IuBCWyZv3vsGvWS429YADCFirOHWVKM3DX9chZ66AB9aGnpf3ektY ldww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2OUFDUMk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e14si25927161plh.325.2021.09.27.10.14.24; Mon, 27 Sep 2021 10:14:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2OUFDUMk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236679AbhI0RPO (ORCPT + 99 others); Mon, 27 Sep 2021 13:15:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:54838 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236192AbhI0RMb (ORCPT ); Mon, 27 Sep 2021 13:12:31 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5B64C61213; Mon, 27 Sep 2021 17:08:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632762527; bh=E8aPjYdnOHSBPnhGxzMwiXBMLYSvhwuyvXW32MYEFP8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2OUFDUMkcuNLW/EY02enJ62J0pDdce2Z53G4A5Kn60l8b7QgcfEJoa/Xv3y6wI9fL ZKYIJiEUSSLlUeHmlVuWXmAHNy/BkERtZI83G7IMJ0EWhwaFqmVl2cZbiS4PFV9T6o Hos8pDvJbzyvk8+yEiGprVJHPSCrHstYoH3bLEqs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eli V , Anand Jain , Qu Wenruo , David Sterba Subject: [PATCH 5.10 025/103] btrfs: prevent __btrfs_dump_space_info() to underflow its free space Date: Mon, 27 Sep 2021 19:01:57 +0200 Message-Id: <20210927170226.596035148@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210927170225.702078779@linuxfoundation.org> References: <20210927170225.702078779@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Qu Wenruo commit 0619b7901473c380abc05d45cf9c70bee0707db3 upstream. It's not uncommon where __btrfs_dump_space_info() gets called under over-commit situations. In that case free space would underflow as total allocated space is not enough to handle all the over-committed space. Such underflow values can sometimes cause confusion for users enabled enospc_debug mount option, and takes some seconds for developers to convert the underflow value to signed result. Just output the free space as s64 to avoid such problem. Reported-by: Eli V Link: https://lore.kernel.org/linux-btrfs/CAJtFHUSy4zgyhf-4d9T+KdJp9w=UgzC2A0V=VtmaeEpcGgm1-Q@mail.gmail.com/ CC: stable@vger.kernel.org # 5.4+ Reviewed-by: Anand Jain Signed-off-by: Qu Wenruo Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/space-info.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -417,9 +417,10 @@ static void __btrfs_dump_space_info(stru { lockdep_assert_held(&info->lock); - btrfs_info(fs_info, "space_info %llu has %llu free, is %sfull", + /* The free space could be negative in case of overcommit */ + btrfs_info(fs_info, "space_info %llu has %lld free, is %sfull", info->flags, - info->total_bytes - btrfs_space_info_used(info, true), + (s64)(info->total_bytes - btrfs_space_info_used(info, true)), info->full ? "" : "not "); btrfs_info(fs_info, "space_info total=%llu, used=%llu, pinned=%llu, reserved=%llu, may_use=%llu, readonly=%llu",