Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3102957ybi; Thu, 18 Jul 2019 21:05:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqyUjbV4paNeXyMQw/fI+vKA08JBqmTn5Q24DoTdS1cKOKABQTCpAIg1y8WFBK4zFr43Ymol X-Received: by 2002:a17:902:86:: with SMTP id a6mr55056458pla.244.1563509117619; Thu, 18 Jul 2019 21:05:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563509117; cv=none; d=google.com; s=arc-20160816; b=Um3XvibBrbheLxOtjBY+iNSH8JKbR7Z4Fch9VjVyllJJTvxY1DQP+2VRUcSOkVrXHB B6jHGYMdRFP0TG0kY9mvB8EDErHSimtmbetw7GNa0FJb4QpRb1N7OQu5N+cnlcBZksPF vDGfd5uneLF8IFIdX2+cacF7r8Y8dcVvXxuT5VnzfT0k0A/lE/BM+jmZBEVJ52DO1cz1 iTKGZbEhLRyGNs2HyNIxZw0Qs5pz+3NLbjNST/xA6cpnNwkU/Y0VinYHOUdWkRUIgiAO 0X4WZtE6fvHMyFJzZ6D9ALYZV75hYN+uhrgaGHDVE7+zqjFLUpEf1+NgNp+rlBXxGSio C2zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=GSFcd+jQ2UeJAmOpsBzqpR5G9IiFO+cFAS/NUnO8RHA=; b=Q6353Y4wtj2WK75QofDl6K6ZPoRVrZmdOsfs1mOtIJ6utRczgzJuyTx7rlUC5eWrUQ kdfcH9tYZbLt9xi4fjXmDX8nMnfVbNAlsYCtO+oEwtzmUIWOdeSurx8Dt9VEYzHRtcms 6PTXgoG0Qi2kUZP1tfsbVu+JB9phhxj8V4OCcdd8NjrG/5SIfLgN4xB9B4ZS4z5YAa7O tNvxf7rJ3CiBHTdITRWiKnCxAAWDzXSgSvX2RQf8ZaWzw4ZtmPypm5+/OANMyBuh8Vdl VjiqZjRen8MZiw5iaTiS6m+R9OZ2W9I9YQ5dr96kE5HvFZuxH99ufdxXIg9S/Q+RPd61 NYfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=C67vdf5t; 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 br15si371714pjb.43.2019.07.18.21.05.02; Thu, 18 Jul 2019 21:05: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=C67vdf5t; 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 S1730704AbfGSEDx (ORCPT + 99 others); Fri, 19 Jul 2019 00:03:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:35898 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730663AbfGSEDt (ORCPT ); Fri, 19 Jul 2019 00:03:49 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AA24A21873; Fri, 19 Jul 2019 04:03:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563509028; bh=6t3CAgcV6XpPNrDoO83vKqpOcFu/CSfxU4by1Tzh9ak=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C67vdf5t9Z+5JwrG1y3twhkSetpI6EVw3xCtdQmcE7Trf5CVxTneLRZoB6rkxkBQb HbtdGkEetDPQavYNjmcM6kj+tABVi6YLfjBrIGUVKoKxPLXRVb+9bk/m+VrsWiWZxT k0zOabNveYOB2fr8BZ66m8dgPHd+oveUrvAOrLWc= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Daniel Rosenberg , Chao Yu , Jaegeuk Kim , Sasha Levin , linux-f2fs-devel@lists.sourceforge.net Subject: [PATCH AUTOSEL 5.1 028/141] f2fs: Fix accounting for unusable blocks Date: Fri, 19 Jul 2019 00:00:53 -0400 Message-Id: <20190719040246.15945-28-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190719040246.15945-1-sashal@kernel.org> References: <20190719040246.15945-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Daniel Rosenberg [ Upstream commit a4c3ecaaadac5693f555cfef1c9eecf4c39df818 ] Fixes possible underflows when dealing with unusable blocks. Signed-off-by: Daniel Rosenberg Reviewed-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/f2fs.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 2ba2478d0663..f1157d5c62bb 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1761,8 +1761,12 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, if (!__allow_reserved_blocks(sbi, inode, true)) avail_user_block_count -= F2FS_OPTION(sbi).root_reserved_blocks; - if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) - avail_user_block_count -= sbi->unusable_block_count; + if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) { + if (avail_user_block_count > sbi->unusable_block_count) + avail_user_block_count -= sbi->unusable_block_count; + else + avail_user_block_count = 0; + } if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) { diff = sbi->total_valid_block_count - avail_user_block_count; if (diff > *count) @@ -1958,7 +1962,7 @@ static inline int inc_valid_node_count(struct f2fs_sb_info *sbi, struct inode *inode, bool is_inode) { block_t valid_block_count; - unsigned int valid_node_count; + unsigned int valid_node_count, user_block_count; int err; if (is_inode) { @@ -1985,10 +1989,11 @@ static inline int inc_valid_node_count(struct f2fs_sb_info *sbi, if (!__allow_reserved_blocks(sbi, inode, false)) valid_block_count += F2FS_OPTION(sbi).root_reserved_blocks; + user_block_count = sbi->user_block_count; if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) - valid_block_count += sbi->unusable_block_count; + user_block_count -= sbi->unusable_block_count; - if (unlikely(valid_block_count > sbi->user_block_count)) { + if (unlikely(valid_block_count > user_block_count)) { spin_unlock(&sbi->stat_lock); goto enospc; } -- 2.20.1