From patchwork Fri Sep 18 13:34:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Borisov X-Patchwork-Id: 11785149 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D718A1731 for ; Fri, 18 Sep 2020 13:34:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B63A823719 for ; Fri, 18 Sep 2020 13:34:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="MGqfV1/a" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726789AbgIRNeo (ORCPT ); Fri, 18 Sep 2020 09:34:44 -0400 Received: from mx2.suse.de ([195.135.220.15]:40920 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726130AbgIRNen (ORCPT ); Fri, 18 Sep 2020 09:34:43 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1600436081; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=uf3/cxuMREhuYZiRBGs+x/biWMU9I95orcNVsgV/3Tc=; b=MGqfV1/ac8eROggDfUHh4iXcqcQIb5eXtpsaaqFvXclNUAH6x56db+KMFn+UfCdyPgseFL GNy5DdWQd3EC0vjKHineKyI7UqAJJj7b/53Uk8iOarhM4bjSnY32/GxcciKS+wZgVXZCDE EdNnS5E32hdZHXPJFSjPec9djBc2RG8= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id BAC6FAFB8; Fri, 18 Sep 2020 13:35:15 +0000 (UTC) From: Nikolay Borisov To: linux-btrfs@vger.kernel.org Cc: Nikolay Borisov Subject: [PATCH 1/7] btrfs: Don't call readpage_end_io_hook for the btree inode Date: Fri, 18 Sep 2020 16:34:33 +0300 Message-Id: <20200918133439.23187-2-nborisov@suse.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200918133439.23187-1-nborisov@suse.com> References: <20200918133439.23187-1-nborisov@suse.com> Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Instead of relying on indirect calls to implement metadata buffer validation simply check if the inode whose page we are processing equals the btree inode. If it does call the necessary function. This is an improvement in 2 directions: 1. We aren't paying the penalty of indirect calls in a post-speculation attacks world. 2. The function is now named more explicitly so it's obvious what's going on This is in preparation to removing struct extent_io_ops altogether. Signed-off-by: Nikolay Borisov --- fs/btrfs/ctree.h | 2 ++ fs/btrfs/disk-io.c | 8 ++++---- fs/btrfs/disk-io.h | 4 +++- fs/btrfs/extent_io.c | 9 ++++++--- fs/btrfs/inode.c | 7 +++---- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 4e667b0565e0..0c58d96b9fb3 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -2962,6 +2962,8 @@ void btrfs_inode_safe_disk_i_size_write(struct btrfs_inode *inode, u64 btrfs_file_extent_end(const struct btrfs_path *path); /* inode.c */ +int btrfs_check_csum(struct btrfs_io_bio *io_bio, u64 phy_offset, + struct page *page, u64 start, u64 end, int mirror); struct extent_map *btrfs_get_extent_fiemap(struct btrfs_inode *inode, u64 start, u64 len); noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len, diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 160b485d2cc0..5ad11c38230f 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -524,9 +524,9 @@ static int check_tree_block_fsid(struct extent_buffer *eb) return 1; } -static int btree_readpage_end_io_hook(struct btrfs_io_bio *io_bio, - u64 phy_offset, struct page *page, - u64 start, u64 end, int mirror) +int btrfs_validate_metadata_buffer(struct btrfs_io_bio *io_bio, u64 phy_offset, + struct page *page, u64 start, u64 end, + int mirror) { u64 found_start; int found_level; @@ -4639,5 +4639,5 @@ static int btrfs_cleanup_transaction(struct btrfs_fs_info *fs_info) static const struct extent_io_ops btree_extent_io_ops = { /* mandatory callbacks */ .submit_bio_hook = btree_submit_bio_hook, - .readpage_end_io_hook = btree_readpage_end_io_hook, + .readpage_end_io_hook = NULL }; diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h index 89b6a709a184..bc2e49246199 100644 --- a/fs/btrfs/disk-io.h +++ b/fs/btrfs/disk-io.h @@ -76,7 +76,9 @@ void btrfs_btree_balance_dirty(struct btrfs_fs_info *fs_info); void btrfs_btree_balance_dirty_nodelay(struct btrfs_fs_info *fs_info); void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info, struct btrfs_root *root); - +int btrfs_validate_metadata_buffer(struct btrfs_io_bio *io_bio, u64 phy_offset, + struct page *page, u64 start, u64 end, + int mirror); #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS struct btrfs_root *btrfs_alloc_dummy_root(struct btrfs_fs_info *fs_info); #endif diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index afac70ef0cc5..5e47606f7786 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -2851,9 +2851,12 @@ static void end_bio_extent_readpage(struct bio *bio) mirror = io_bio->mirror_num; if (likely(uptodate)) { - ret = tree->ops->readpage_end_io_hook(io_bio, offset, - page, start, end, - mirror); + if (data_inode) + ret = btrfs_check_csum(io_bio, offset, page, + start, end, mirror); + else + ret = btrfs_validate_metadata_buffer(io_bio, + offset, page, start, end, mirror); if (ret) uptodate = 0; else diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index cb3fdd0798c6..23ac09aa813e 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2817,9 +2817,8 @@ static int check_data_csum(struct inode *inode, struct btrfs_io_bio *io_bio, * if there's a match, we allow the bio to finish. If not, the code in * extent_io.c will try to find good copies for us. */ -static int btrfs_readpage_end_io_hook(struct btrfs_io_bio *io_bio, - u64 phy_offset, struct page *page, - u64 start, u64 end, int mirror) +int btrfs_check_csum(struct btrfs_io_bio *io_bio, u64 phy_offset, + struct page *page, u64 start, u64 end, int mirror) { size_t offset = start - page_offset(page); struct inode *inode = page->mapping->host; @@ -10249,7 +10248,7 @@ static const struct file_operations btrfs_dir_file_operations = { static const struct extent_io_ops btrfs_extent_io_ops = { /* mandatory callbacks */ .submit_bio_hook = btrfs_submit_bio_hook, - .readpage_end_io_hook = btrfs_readpage_end_io_hook, + .readpage_end_io_hook = NULL }; /* From patchwork Fri Sep 18 13:34:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Borisov X-Patchwork-Id: 11785147 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9876C139A for ; Fri, 18 Sep 2020 13:34:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6C5C1235FA for ; Fri, 18 Sep 2020 13:34:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="MAsSq6+9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726796AbgIRNeo (ORCPT ); Fri, 18 Sep 2020 09:34:44 -0400 Received: from mx2.suse.de ([195.135.220.15]:40932 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726548AbgIRNen (ORCPT ); Fri, 18 Sep 2020 09:34:43 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1600436081; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=jbGnh8KERY1PqYaQkyR58qYXFslqhmCdFVNzsyQdxWg=; b=MAsSq6+9PAzbaCIowyNp80xK1KYUh/J5yGwRIB2z2XTafdbGB3eIOHcNJpdY+99wHforDx IScWaSk1q1uppXPV5rpmcpCvDaDNFeQ2m8hCgACXRmmIlR/79Y3erFucSC8eAFnGNXj/L+ BxS70DGc6t1aXq+cIcicdtxzDW2Gsjs= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 05385B1E1; Fri, 18 Sep 2020 13:35:16 +0000 (UTC) From: Nikolay Borisov To: linux-btrfs@vger.kernel.org Cc: Nikolay Borisov Subject: [PATCH 2/7] btrfs: Remove extent_io_ops::readpage_end_io_hook Date: Fri, 18 Sep 2020 16:34:34 +0300 Message-Id: <20200918133439.23187-3-nborisov@suse.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200918133439.23187-1-nborisov@suse.com> References: <20200918133439.23187-1-nborisov@suse.com> Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org It's no longer used so let's remove it. Signed-off-by: Nikolay Borisov --- fs/btrfs/disk-io.c | 4 +--- fs/btrfs/extent_io.h | 5 +---- fs/btrfs/inode.c | 4 +--- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 5ad11c38230f..73937954f464 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -4637,7 +4637,5 @@ static int btrfs_cleanup_transaction(struct btrfs_fs_info *fs_info) } static const struct extent_io_ops btree_extent_io_ops = { - /* mandatory callbacks */ - .submit_bio_hook = btree_submit_bio_hook, - .readpage_end_io_hook = NULL + .submit_bio_hook = btree_submit_bio_hook }; diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h index 133487a5e6b8..d9119bd555a9 100644 --- a/fs/btrfs/extent_io.h +++ b/fs/btrfs/extent_io.h @@ -77,13 +77,10 @@ typedef blk_status_t (extent_submit_bio_start_t)(void *private_data, struct extent_io_ops { /* - * The following callbacks must be always defined, the function + * The following callback must be always defined, the function * pointer will be called unconditionally. */ submit_bio_hook_t *submit_bio_hook; - int (*readpage_end_io_hook)(struct btrfs_io_bio *io_bio, u64 phy_offset, - struct page *page, u64 start, u64 end, - int mirror); }; diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 23ac09aa813e..41565c5a05ef 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -10246,9 +10246,7 @@ static const struct file_operations btrfs_dir_file_operations = { }; static const struct extent_io_ops btrfs_extent_io_ops = { - /* mandatory callbacks */ - .submit_bio_hook = btrfs_submit_bio_hook, - .readpage_end_io_hook = NULL + .submit_bio_hook = btrfs_submit_bio_hook }; /* From patchwork Fri Sep 18 13:34:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Borisov X-Patchwork-Id: 11785157 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4EE95618 for ; Fri, 18 Sep 2020 13:34:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2DB4323719 for ; Fri, 18 Sep 2020 13:34:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="PduFoUah" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726779AbgIRNen (ORCPT ); Fri, 18 Sep 2020 09:34:43 -0400 Received: from mx2.suse.de ([195.135.220.15]:40944 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725955AbgIRNen (ORCPT ); Fri, 18 Sep 2020 09:34:43 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1600436082; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=DBNhcXiXisJ2v9O2OLeEEgnsBC1wVEmDwVWAMLjns8I=; b=PduFoUah+Fj83G9uBzJ0WTc2x4nuPrv/t1sANKLpmmgcFXbjAMp+gcC94gi61L6u+6R4cm oTRsJ+M6cT2dJWwKn/VWxxobPuh09D8ksDwucOpfJO++T4D66F/wuE8N/vo6ipAkjJb4Ld hIOJBvKlrn0LEs39j/hWjshTpjjCitI= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 3D7B8B1E4; Fri, 18 Sep 2020 13:35:16 +0000 (UTC) From: Nikolay Borisov To: linux-btrfs@vger.kernel.org Cc: Nikolay Borisov Subject: [PATCH 3/7] btrfs: Call submit_bio_hook directly in submit_one_bio Date: Fri, 18 Sep 2020 16:34:35 +0300 Message-Id: <20200918133439.23187-4-nborisov@suse.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200918133439.23187-1-nborisov@suse.com> References: <20200918133439.23187-1-nborisov@suse.com> Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org BTRFS has 2 inode types (for the purposes of the code in submit_one_bio) - ordinary data inodes (including the freespace inode) and the btree inode. Both of these implement submit_bio_hook so btrfsic_submit_bio can never be called from submit_one_bio so just remove it. Signed-off-by: Nikolay Borisov --- fs/btrfs/extent_io.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 5e47606f7786..6e976bd86600 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -168,11 +168,8 @@ int __must_check submit_one_bio(struct bio *bio, int mirror_num, bio->bi_private = NULL; - if (tree->ops) - ret = tree->ops->submit_bio_hook(tree->private_data, bio, - mirror_num, bio_flags); - else - btrfsic_submit_bio(bio); + ret = tree->ops->submit_bio_hook(tree->private_data, bio, mirror_num, + bio_flags); return blk_status_to_errno(ret); } From patchwork Fri Sep 18 13:34:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Borisov X-Patchwork-Id: 11785155 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 263DB59D for ; Fri, 18 Sep 2020 13:34:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F3A7723719 for ; Fri, 18 Sep 2020 13:34:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="QnDZc+0g" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726821AbgIRNes (ORCPT ); Fri, 18 Sep 2020 09:34:48 -0400 Received: from mx2.suse.de ([195.135.220.15]:40956 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726768AbgIRNeo (ORCPT ); Fri, 18 Sep 2020 09:34:44 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1600436082; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=0qaYJoq+FQ7iTUNj0F3LUI4KfLa2Ry3PFjExuFLQRDU=; b=QnDZc+0gt4kt99jPO6gwI8ZfFLQync2cIZf6qGjcHKRItURc7ZkPqY4CB2ELYgJXnTa+Li hKZnZDJM3DxAVOaXzJtuXFlL8dzKDIZivMrEkvbax47eO0p1dq4Fq6kQY/Vtl+UWrwUq7j w1eM8hiZOQejrw0SGNBjGJOYFNNngNg= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 7AFD3B1EA; Fri, 18 Sep 2020 13:35:16 +0000 (UTC) From: Nikolay Borisov To: linux-btrfs@vger.kernel.org Cc: Nikolay Borisov Subject: [PATCH 4/7] btrfs: Don't opencode is_data_inode in end_bio_extent_readpage Date: Fri, 18 Sep 2020 16:34:36 +0300 Message-Id: <20200918133439.23187-5-nborisov@suse.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200918133439.23187-1-nborisov@suse.com> References: <20200918133439.23187-1-nborisov@suse.com> Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Use the is_data_inode helper. Signed-off-by: Nikolay Borisov --- fs/btrfs/extent_io.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 6e976bd86600..26b002e2f3b3 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -2816,8 +2816,7 @@ static void end_bio_extent_readpage(struct bio *bio) struct page *page = bvec->bv_page; struct inode *inode = page->mapping->host; struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); - bool data_inode = btrfs_ino(BTRFS_I(inode)) - != BTRFS_BTREE_INODE_OBJECTID; + bool data_inode = is_data_inode(inode); btrfs_debug(fs_info, "end_bio_extent_readpage: bi_sector=%llu, err=%d, mirror=%u", From patchwork Fri Sep 18 13:34:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Borisov X-Patchwork-Id: 11785145 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4303659D for ; Fri, 18 Sep 2020 13:34:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1DBDD23719 for ; Fri, 18 Sep 2020 13:34:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="qCSCKf82" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726802AbgIRNep (ORCPT ); Fri, 18 Sep 2020 09:34:45 -0400 Received: from mx2.suse.de ([195.135.220.15]:40968 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726770AbgIRNeo (ORCPT ); Fri, 18 Sep 2020 09:34:44 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1600436082; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=eDw+U32G1q1vPq2zVGpW1JiIg3H8wWeDPX5NRFpx0JI=; b=qCSCKf829iWKbc/KAQsye/Yge+yWrAqEF1tEzup83S04ReDSSaoPJDeXhCaAQB/Wgws6Yq 4zLGtumyRcljoT/8qTUZvwnmcoMIcXfr8UsFOOXru4KC8cLbvbV28UcXyQgriZmcGz1Bas p6gO+0ixkHEJnRM8tOJQPmPFj7I+xZU= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id B2AEEB23E; Fri, 18 Sep 2020 13:35:16 +0000 (UTC) From: Nikolay Borisov To: linux-btrfs@vger.kernel.org Cc: Nikolay Borisov Subject: [PATCH 5/7] btrfs: Stop calling submit_bio_hook for data inodes Date: Fri, 18 Sep 2020 16:34:37 +0300 Message-Id: <20200918133439.23187-6-nborisov@suse.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200918133439.23187-1-nborisov@suse.com> References: <20200918133439.23187-1-nborisov@suse.com> Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Instead export and rename the function to btrfs_submit_data_bio and call it directly in submit_one_bio. This avoids paying the cost for speculative attacks mitigations and improves code readability. Signed-off-by: Nikolay Borisov --- fs/btrfs/ctree.h | 2 ++ fs/btrfs/extent_io.c | 10 +++++++--- fs/btrfs/inode.c | 7 +++---- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 0c58d96b9fb3..5fc18b7ab771 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -2962,6 +2962,8 @@ void btrfs_inode_safe_disk_i_size_write(struct btrfs_inode *inode, u64 btrfs_file_extent_end(const struct btrfs_path *path); /* inode.c */ +blk_status_t btrfs_submit_data_bio(struct inode *inode, struct bio *bio, + int mirror_num, unsigned long bio_flags); int btrfs_check_csum(struct btrfs_io_bio *io_bio, u64 phy_offset, struct page *page, u64 start, u64 end, int mirror); struct extent_map *btrfs_get_extent_fiemap(struct btrfs_inode *inode, diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 26b002e2f3b3..8cabcb7642a9 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -168,8 +168,12 @@ int __must_check submit_one_bio(struct bio *bio, int mirror_num, bio->bi_private = NULL; - ret = tree->ops->submit_bio_hook(tree->private_data, bio, mirror_num, - bio_flags); + if (is_data_inode(tree->private_data)) + ret = btrfs_submit_data_bio(tree->private_data, bio, mirror_num, + bio_flags); + else + ret = tree->ops->submit_bio_hook(tree->private_data, bio, + mirror_num, bio_flags); return blk_status_to_errno(ret); } @@ -2880,7 +2884,7 @@ static void end_bio_extent_readpage(struct bio *bio) if (!btrfs_submit_read_repair(inode, bio, offset, page, start - page_offset(page), start, end, mirror, - tree->ops->submit_bio_hook)) { + btrfs_submit_data_bio)) { uptodate = !bio->bi_status; offset += len; continue; diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 41565c5a05ef..955a66207fec 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2169,9 +2169,8 @@ static blk_status_t btrfs_submit_bio_start(void *private_data, struct bio *bio, * * c-3) otherwise: async submit */ -static blk_status_t btrfs_submit_bio_hook(struct inode *inode, struct bio *bio, - int mirror_num, - unsigned long bio_flags) +blk_status_t btrfs_submit_data_bio(struct inode *inode, struct bio *bio, + int mirror_num, unsigned long bio_flags) { struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); @@ -10246,7 +10245,7 @@ static const struct file_operations btrfs_dir_file_operations = { }; static const struct extent_io_ops btrfs_extent_io_ops = { - .submit_bio_hook = btrfs_submit_bio_hook + .submit_bio_hook = NULL }; /* From patchwork Fri Sep 18 13:34:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Borisov X-Patchwork-Id: 11785153 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6A49859D for ; Fri, 18 Sep 2020 13:34:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4109723719 for ; Fri, 18 Sep 2020 13:34:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="OfBmgREz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726814AbgIRNer (ORCPT ); Fri, 18 Sep 2020 09:34:47 -0400 Received: from mx2.suse.de ([195.135.220.15]:40980 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726776AbgIRNeo (ORCPT ); Fri, 18 Sep 2020 09:34:44 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1600436082; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=pcETNj7xVcin9mXKhI0bL51K8ZiyB4lJNPb29avRk48=; b=OfBmgREzOkU66o09yzUzUBt805gGTVOoo/G62D57YXYALPgU6pjo3vXEDo2MeS8lWo6z0l U1aW1mvv9kbNxF6NKnn7gNQQ8jDYnz3mk8aYIjYOYq/3uXhF8xmZz/7OtIdsk1PYXjGUDA OGUyPr0tfxMudVT3150kn9WFEB5DFko= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id F0A99B18C; Fri, 18 Sep 2020 13:35:16 +0000 (UTC) From: Nikolay Borisov To: linux-btrfs@vger.kernel.org Cc: Nikolay Borisov Subject: [PATCH 6/7] btrfs: Call submit_bio_hook directly for metadata pages Date: Fri, 18 Sep 2020 16:34:38 +0300 Message-Id: <20200918133439.23187-7-nborisov@suse.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200918133439.23187-1-nborisov@suse.com> References: <20200918133439.23187-1-nborisov@suse.com> Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org No need to go through a function pointer indirection simply call submit_bio_hook directly by exporting and renaming the helper to btrfs_submit_metadata_bio. This makes the code more readable and should result in somewhat faster code due to no longer paying the price for specualtive attack mitigations that come with indirect function calls. Signed-off-by: Nikolay Borisov --- fs/btrfs/disk-io.c | 7 +++---- fs/btrfs/disk-io.h | 2 ++ fs/btrfs/extent_io.c | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 73937954f464..54f2b95cc305 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -815,9 +815,8 @@ static int check_async_write(struct btrfs_fs_info *fs_info, return 1; } -static blk_status_t btree_submit_bio_hook(struct inode *inode, struct bio *bio, - int mirror_num, - unsigned long bio_flags) +blk_status_t btrfs_submit_metadata_bio(struct inode *inode, struct bio *bio, + int mirror_num, unsigned long bio_flags) { struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); int async = check_async_write(fs_info, BTRFS_I(inode)); @@ -4637,5 +4636,5 @@ static int btrfs_cleanup_transaction(struct btrfs_fs_info *fs_info) } static const struct extent_io_ops btree_extent_io_ops = { - .submit_bio_hook = btree_submit_bio_hook + .submit_bio_hook = NULL }; diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h index bc2e49246199..fee69ced58b4 100644 --- a/fs/btrfs/disk-io.h +++ b/fs/btrfs/disk-io.h @@ -79,6 +79,8 @@ void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info, int btrfs_validate_metadata_buffer(struct btrfs_io_bio *io_bio, u64 phy_offset, struct page *page, u64 start, u64 end, int mirror); +blk_status_t btrfs_submit_metadata_bio(struct inode *inode, struct bio *bio, + int mirror_num, unsigned long bio_flags); #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS struct btrfs_root *btrfs_alloc_dummy_root(struct btrfs_fs_info *fs_info); #endif diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 8cabcb7642a9..4a00cfd4082f 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -172,8 +172,8 @@ int __must_check submit_one_bio(struct bio *bio, int mirror_num, ret = btrfs_submit_data_bio(tree->private_data, bio, mirror_num, bio_flags); else - ret = tree->ops->submit_bio_hook(tree->private_data, bio, - mirror_num, bio_flags); + ret = btrfs_submit_metadata_bio(tree->private_data, bio, + mirror_num, bio_flags); return blk_status_to_errno(ret); } From patchwork Fri Sep 18 13:34:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Borisov X-Patchwork-Id: 11785151 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 946FF59D for ; Fri, 18 Sep 2020 13:34:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 73C1423719 for ; Fri, 18 Sep 2020 13:34:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="cz8uTQE+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726807AbgIRNeq (ORCPT ); Fri, 18 Sep 2020 09:34:46 -0400 Received: from mx2.suse.de ([195.135.220.15]:40994 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726783AbgIRNep (ORCPT ); Fri, 18 Sep 2020 09:34:45 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1600436083; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=d+B9zBaBwdSLqva/gR80cZ2zWHYMQo4Jg1pvQm1xdjo=; b=cz8uTQE+CGz0J8X2W6rwEy1dkVHyfXfPrcx9GKvj3ZytiwenUu0KwzKJ2HMkssKmP2zlbT BTeweRSRmXTBnC+rTPZBBQM6qomPWY8tbK0BAr+JnsqqZMFM9ux0rVukOq3FYkbN2/Rjtu yoBmaMi25iiK9zzp3/cJbJDZLn6PyNQ= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 37EEAB25C; Fri, 18 Sep 2020 13:35:17 +0000 (UTC) From: Nikolay Borisov To: linux-btrfs@vger.kernel.org Cc: Nikolay Borisov Subject: [PATCH 7/7] btrfs: Remove struct extent_io_ops Date: Fri, 18 Sep 2020 16:34:39 +0300 Message-Id: <20200918133439.23187-8-nborisov@suse.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200918133439.23187-1-nborisov@suse.com> References: <20200918133439.23187-1-nborisov@suse.com> Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Signed-off-by: Nikolay Borisov --- fs/btrfs/ctree.h | 2 -- fs/btrfs/disk-io.c | 7 ------- fs/btrfs/extent-io-tree.h | 1 - fs/btrfs/extent_io.c | 2 -- fs/btrfs/inode.c | 16 ---------------- fs/btrfs/tests/inode-tests.c | 1 - 6 files changed, 29 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 5fc18b7ab771..8e811debae57 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -3576,9 +3576,7 @@ static inline int btrfs_defrag_cancelled(struct btrfs_fs_info *fs_info) /* Sanity test specific functions */ #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS -void btrfs_test_inode_set_ops(struct inode *inode); void btrfs_test_destroy_inode(struct inode *inode); - static inline int btrfs_is_testing(struct btrfs_fs_info *fs_info) { return test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state); diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 54f2b95cc305..85b59797a4a4 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -50,7 +50,6 @@ BTRFS_SUPER_FLAG_METADUMP |\ BTRFS_SUPER_FLAG_METADUMP_V2) -static const struct extent_io_ops btree_extent_io_ops; static void end_workqueue_fn(struct btrfs_work *work); static void btrfs_destroy_ordered_extents(struct btrfs_root *root); static int btrfs_destroy_delayed_refs(struct btrfs_transaction *trans, @@ -2066,8 +2065,6 @@ static void btrfs_init_btree_inode(struct btrfs_fs_info *fs_info) BTRFS_I(inode)->io_tree.track_uptodate = false; extent_map_tree_init(&BTRFS_I(inode)->extent_tree); - BTRFS_I(inode)->io_tree.ops = &btree_extent_io_ops; - BTRFS_I(inode)->root = btrfs_grab_root(fs_info->tree_root); memset(&BTRFS_I(inode)->location, 0, sizeof(struct btrfs_key)); set_bit(BTRFS_INODE_DUMMY, &BTRFS_I(inode)->runtime_flags); @@ -4634,7 +4631,3 @@ static int btrfs_cleanup_transaction(struct btrfs_fs_info *fs_info) return 0; } - -static const struct extent_io_ops btree_extent_io_ops = { - .submit_bio_hook = NULL -}; diff --git a/fs/btrfs/extent-io-tree.h b/fs/btrfs/extent-io-tree.h index 250b8cbaaf97..b1b737e7ef5b 100644 --- a/fs/btrfs/extent-io-tree.h +++ b/fs/btrfs/extent-io-tree.h @@ -62,7 +62,6 @@ struct extent_io_tree { u8 owner; spinlock_t lock; - const struct extent_io_ops *ops; }; struct extent_state { diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 4a00cfd4082f..b5e00b62bcb1 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -281,7 +281,6 @@ void extent_io_tree_init(struct btrfs_fs_info *fs_info, { tree->fs_info = fs_info; tree->state = RB_ROOT; - tree->ops = NULL; tree->dirty_bytes = 0; spin_lock_init(&tree->lock); tree->private_data = private_data; @@ -3056,7 +3055,6 @@ static int submit_extent_page(unsigned int opf, else contig = bio_end_sector(bio) == sector; - ASSERT(tree->ops); if (btrfs_bio_fits_in_stripe(page, page_size, bio, bio_flags)) can_merge = false; diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 955a66207fec..befbe19996b8 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -71,7 +71,6 @@ static const struct inode_operations btrfs_special_inode_operations; static const struct inode_operations btrfs_file_inode_operations; static const struct address_space_operations btrfs_aops; static const struct file_operations btrfs_dir_file_operations; -static const struct extent_io_ops btrfs_extent_io_ops; static struct kmem_cache *btrfs_inode_cachep; struct kmem_cache *btrfs_trans_handle_cachep; @@ -141,13 +140,6 @@ static inline void btrfs_cleanup_ordered_extents(struct btrfs_inode *inode, static int btrfs_dirty_inode(struct inode *inode); -#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS -void btrfs_test_inode_set_ops(struct inode *inode) -{ - BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops; -} -#endif - static int btrfs_init_inode_security(struct btrfs_trans_handle *trans, struct inode *inode, struct inode *dir, const struct qstr *qstr) @@ -3376,7 +3368,6 @@ static int btrfs_read_locked_inode(struct inode *inode, switch (inode->i_mode & S_IFMT) { case S_IFREG: inode->i_mapping->a_ops = &btrfs_aops; - BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops; inode->i_fop = &btrfs_file_operations; inode->i_op = &btrfs_file_inode_operations; break; @@ -6292,7 +6283,6 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry, if (err) goto out_unlock; - BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops; d_instantiate_new(dentry, inode); out_unlock: @@ -9504,7 +9494,6 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry, inode->i_fop = &btrfs_file_operations; inode->i_op = &btrfs_file_inode_operations; inode->i_mapping->a_ops = &btrfs_aops; - BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops; err = btrfs_init_inode_security(trans, inode, dir, &dentry->d_name); if (err) @@ -9826,7 +9815,6 @@ static int btrfs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode) inode->i_op = &btrfs_file_inode_operations; inode->i_mapping->a_ops = &btrfs_aops; - BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops; ret = btrfs_init_inode_security(trans, inode, dir, NULL); if (ret) @@ -10244,10 +10232,6 @@ static const struct file_operations btrfs_dir_file_operations = { .fsync = btrfs_sync_file, }; -static const struct extent_io_ops btrfs_extent_io_ops = { - .submit_bio_hook = NULL -}; - /* * btrfs doesn't support the bmap operation because swapfiles * use bmap to make a mapping of extents in the file. They assume diff --git a/fs/btrfs/tests/inode-tests.c b/fs/btrfs/tests/inode-tests.c index cc54d4973a74..e6719f7db386 100644 --- a/fs/btrfs/tests/inode-tests.c +++ b/fs/btrfs/tests/inode-tests.c @@ -949,7 +949,6 @@ static int test_extent_accounting(u32 sectorsize, u32 nodesize) } BTRFS_I(inode)->root = root; - btrfs_test_inode_set_ops(inode); /* [BTRFS_MAX_EXTENT_SIZE] */ ret = btrfs_set_extent_delalloc(BTRFS_I(inode), 0,