From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12A56C3527E for ; Tue, 5 Apr 2022 11:58:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345939AbiDELwI (ORCPT ); Tue, 5 Apr 2022 07:52:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244832AbiDEIwm (ORCPT ); Tue, 5 Apr 2022 04:52:42 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D2CA22510; Tue, 5 Apr 2022 01:44:30 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id CB61BB81B13; Tue, 5 Apr 2022 08:39:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2106FC385A0; Tue, 5 Apr 2022 08:39:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649147952; bh=bnnoCddCoFF9JIvsJlyIPMA2p/VXKxiztej60jk8rlE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SXB0B6823bByp5g/iZOTVnBIYNVbWp1xPG+ZDVf82R/7FOoBIQyZ3IQiu447kqdBj Z2yet/QcPN+83s0aJKIzZ/wtWCaXhD+Xsfk/cPZOAE0N0BS6vF2D+3UTzuixmfMCEh osTGyfxwcbEokld/6mOi6sPVXhFG8iTt6+eE7Yvs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johannes Thumshirn , Josef Bacik , Niels Dossche , Niels Dossche , David Sterba Subject: [PATCH 5.16 0181/1017] btrfs: extend locking to all space_info members accesses Date: Tue, 5 Apr 2022 09:18:14 +0200 Message-Id: <20220405070359.610075798@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@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: Niels Dossche commit 06bae876634ebf837ba70ea3de532b288326103d upstream. bytes_pinned is always accessed under space_info->lock, except in btrfs_preempt_reclaim_metadata_space, however the other members are accessed under that lock. The reserved member of the rsv's are also partially accessed under a lock and partially not. Move all these accesses into the same lock to ensure consistency. This could potentially race and lead to a flush instead of a commit but it's not a big problem as it's only for preemptive flush. CC: stable@vger.kernel.org # 5.15+ Reviewed-by: Johannes Thumshirn Reviewed-by: Josef Bacik Signed-off-by: Niels Dossche Signed-off-by: Niels Dossche Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/space-info.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -1059,7 +1059,6 @@ static void btrfs_preempt_reclaim_metada trans_rsv->reserved; if (block_rsv_size < space_info->bytes_may_use) delalloc_size = space_info->bytes_may_use - block_rsv_size; - spin_unlock(&space_info->lock); /* * We don't want to include the global_rsv in our calculation, @@ -1090,6 +1089,8 @@ static void btrfs_preempt_reclaim_metada flush = FLUSH_DELAYED_REFS_NR; } + spin_unlock(&space_info->lock); + /* * We don't want to reclaim everything, just a portion, so scale * down the to_reclaim by 1/4. If it takes us down to 0,