Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp681547pxb; Tue, 5 Apr 2022 18:33:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxN89bslyYEv9fW7vMJo10xQUaObc+jrdPrPO2lJW7YQ9MAXqI+7kl8Yy2KRv/LMnJgCpDt X-Received: by 2002:a17:90b:124c:b0:1bc:369b:7db5 with SMTP id gx12-20020a17090b124c00b001bc369b7db5mr7166028pjb.179.1649208836797; Tue, 05 Apr 2022 18:33:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649208836; cv=none; d=google.com; s=arc-20160816; b=sMEgTgtkWBzUbnw77nBsCOZH7TzivDZceFidtoFvce2voVaAk4si7+MhUB8f/dc3Gs 6G4VHOfpszZ9wH9NQ5uGDjnxUlw/WLWWzzo+1GjMhFo9OBNGPS/Z8IlzhQP+bbfxIjp6 AmG237fNUPNlZmK32Go8VjTW8tksR8Nr7rHKZagFrE0N7fMSzb9HZFKjs5X2NZOE8jYp KFxIRmNs0Y1UJwQnc9wh+rlOFlelpJ6wPZFlRE4ocJiO5Ji2mwwF8W28Jx6woqySzYpt vgppLplbkR6Kd+9/nER3DuBmYqpxqd51eo515dxHlCoYxIEyc0RzaimBG6zEQ/Ur9EbE x0CA== 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=fsNmBVXOlvR5kbHV3ZL8IT2+LyH2B8kvB0m3qpAcsMo=; b=T8Hgn7LY6bDHLtYUkN/T+6ks2ZQq6UYHD0uHkacnDh6xfCFkNMinGjzpY20DXAhhco kRr92iE539+wU6H9s+yTgM70cFB3kKPjFc+OD67LSPaIu3Mnvbaq+gkVJ/t6LoXW5bWj jxcI9ZHxuRlsDYDG1u2lIuJeNh9ZvkGO62/ZNXcK8RzaSMVi1vMBkAEpIljdDZWXTibh KqEcnPZQ5TVr0I4Y/FU/2bq8Qur68BkFD3J12jwHdjtyydvu7gto+uFFXo6CcKQmiSdz V7bNq1lTfKaz1lVPLEAMIItKDmZMQYlPOxwHGzgvs0ZDDsBHAoIXYbLMxRpS4ULIGPCa 6B/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SXB0B682; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w16-20020a1709026f1000b00156285b953esi13551542plk.506.2022.04.05.18.33.42; Tue, 05 Apr 2022 18:33:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SXB0B682; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1345462AbiDELv4 (ORCPT + 99 others); Tue, 5 Apr 2022 07:51:56 -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 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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,