Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2345858ybz; Thu, 23 Apr 2020 16:27:05 -0700 (PDT) X-Google-Smtp-Source: APiQypJ1h/hjk0aFDDfEJv4FngOUvoiFxItHW4s6zZp9kxya9zBYEeRT489CqNPLir/HLYe93Yj3 X-Received: by 2002:a05:6402:3041:: with SMTP id bu1mr5046079edb.145.1587684425051; Thu, 23 Apr 2020 16:27:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587684425; cv=none; d=google.com; s=arc-20160816; b=GOjQ+VwKdbv7Q6l2PAlpPn0BjWI2fPZXNKkaROc+tmGP+od6PAf9VqXAbduYAkpENF foPE+V/5ALy/IOxGKIEDEUHqPJyQgLxPualWDNvI8angH1ylEjVtKHqZ03XzaZoH98Pr KWWGSDfdjSz0qoaEKr2jpbcbzOfZsxuluZrlp9THNPocJjpM8+5+wP3UIe5GzwdNMddK AS0vPf/o/wChAeYM+GwTrV+TTNQtJLOQAh4zxXM9oqmBjAjE6K/Ncqqs38lxd8P39bPb 8xO6qC0YA/ifrf6xo4HLYK8OTaxg1rZPE3fRvXOZziR5VoDgSUAPsrYebYOop/LqaAmn bBzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=6mf1zLlVB9bdFLa8JrUigOhcG1CmiBhKgy6e0HSnIkQ=; b=vv8EAPyj3eKGLN7FaPftr7F2Tko7F6KHYxqSnGpojs1mUFgDIAcoicgPraANHQJvZX M7/NvQpStpIDgA1Pm/UZ16WgoDL4PGcHtGiry/7vuGyPrpmlXG8byoW04vH66FcbiduO XPLy/McPW5aEAYPNxHtmqiZ4KOWuaL+F10SYpQUUh526Yluo3BvMiR07eMBIr/Qvxkei O9x9N0aj1k+2Ky+kfj8ND82qLIxLM1kGR67wcGX0zvPKLDqQ3GB61s+HDZCETHTUtwMP +UHH1KK7CqfhTrmZmbH8wBkJiSsMyUObV3TokVYoE1dIo6uIgcuzIEVI+fDJY3Fb3X9F +t6A== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o6si2082183ejb.97.2020.04.23.16.26.41; Thu, 23 Apr 2020 16:27:05 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730011AbgDWXYs (ORCPT + 99 others); Thu, 23 Apr 2020 19:24:48 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:48288 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728137AbgDWXG3 (ORCPT ); Thu, 23 Apr 2020 19:06:29 -0400 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1jRkvJ-0004aU-Mc; Fri, 24 Apr 2020 00:06:25 +0100 Received: from ben by deadeye with local (Exim 4.93) (envelope-from ) id 1jRkvI-00E6gv-Ny; Fri, 24 Apr 2020 00:06:24 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, Denis Kirjanov , "Greg Kroah-Hartman" , "David Sterba" , "Liu Bo" , "Ben Hutchings" Date: Fri, 24 Apr 2020 00:04:22 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 035/245] Btrfs: memset to avoid stale content in btree leaf In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.83-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Liu Bo commit 851cd173f06045816528176001cf82948282029c upstream. This is an additional patch to "Btrfs: memset to avoid stale content in btree node block". This uses memset to initialize the unused space in a leaf to avoid potential stale content, which may be incurred by pushing items between sibling leaves. Signed-off-by: Liu Bo Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman Signed-off-by: Ben Hutchings --- fs/btrfs/ctree.c | 14 -------------- fs/btrfs/ctree.h | 15 +++++++++++++++ fs/btrfs/extent_io.c | 18 +++++++++++++----- 3 files changed, 28 insertions(+), 19 deletions(-) --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -1721,20 +1721,6 @@ int btrfs_realloc_node(struct btrfs_tran return err; } -/* - * The leaf data grows from end-to-front in the node. - * this returns the address of the start of the last item, - * which is the stop of the leaf data stack - */ -static inline unsigned int leaf_data_end(struct btrfs_root *root, - struct extent_buffer *leaf) -{ - u32 nr = btrfs_header_nritems(leaf); - if (nr == 0) - return BTRFS_LEAF_DATA_SIZE(root); - return btrfs_item_offset_nr(leaf, nr - 1); -} - /* * search for key in the extent_buffer. The items start at offset p, --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -3036,6 +3036,21 @@ static inline unsigned long btrfs_leaf_d return offsetof(struct btrfs_leaf, items); } +/* + * The leaf data grows from end-to-front in the node. + * this returns the address of the start of the last item, + * which is the stop of the leaf data stack + */ +static inline unsigned int leaf_data_end(struct btrfs_root *root, + struct extent_buffer *leaf) +{ + u32 nr = btrfs_header_nritems(leaf); + + if (nr == 0) + return BTRFS_LEAF_DATA_SIZE(root); + return btrfs_item_offset_nr(leaf, nr - 1); +} + /* struct btrfs_file_extent_item */ BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8); BTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_bytenr, --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -3617,8 +3617,10 @@ static noinline_for_stack int write_one_ struct block_device *bdev = fs_info->fs_devices->latest_bdev; struct extent_io_tree *tree = &BTRFS_I(fs_info->btree_inode)->io_tree; u64 offset = eb->start; + u32 nritems; unsigned long i, num_pages; unsigned long bio_flags = 0; + unsigned long start, end; int rw = (epd->sync_io ? WRITE_SYNC : WRITE) | REQ_META; int ret = 0; @@ -3628,15 +3630,21 @@ static noinline_for_stack int write_one_ if (btrfs_header_owner(eb) == BTRFS_TREE_LOG_OBJECTID) bio_flags = EXTENT_BIO_TREE_LOG; - /* set btree node beyond nritems with 0 to avoid stale content */ + /* set btree blocks beyond nritems with 0 to avoid stale content. */ + nritems = btrfs_header_nritems(eb); if (btrfs_header_level(eb) > 0) { - u32 nritems; - unsigned long end; - - nritems = btrfs_header_nritems(eb); end = btrfs_node_key_ptr_offset(nritems); memset_extent_buffer(eb, 0, end, eb->len - end); + } else { + /* + * leaf: + * header 0 1 2 .. N ... data_N .. data_2 data_1 data_0 + */ + start = btrfs_item_nr_offset(nritems); + end = btrfs_leaf_data(eb) + + leaf_data_end(fs_info->tree_root, eb); + memset_extent_buffer(eb, 0, start, end - start); } for (i = 0; i < num_pages; i++) {