Received: by 10.223.185.116 with SMTP id b49csp696086wrg; Wed, 21 Feb 2018 05:33:29 -0800 (PST) X-Google-Smtp-Source: AH8x227Mlbk4GgC057ZGxe3/yi/a3EVZH065cBQxE2v+B8GJpPxBo6fi92mhnueVvxGarqSpwUJs X-Received: by 10.99.8.4 with SMTP id 4mr2763171pgi.289.1519220009843; Wed, 21 Feb 2018 05:33:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519220009; cv=none; d=google.com; s=arc-20160816; b=IsxBzknCjCoN+m09V0S6ho9dwTfDCyQYEbMIy71t4gzDd1r7VoEMNGJKajVtl8XDlf zmG50u3hqJqqrZtV29/mXHstJXOXzSPEX+Nw8r37szlpPiwLy1FyrfoGwNZdhcdrSCMH 5AW1g6nSo5GA8wtI/kDOMZaEyYiS4JHuLBmJELeZ3rYacsgr4UekNALNwwnGI58W7AGV mCDv0dsEJ6jk64Bha9tYFbg4U02InCyovpToV++ud+qS8yyND/3zQLI6tvX1Jkp0600R I/ElxtVI/1MlguG7ZpNenWlldqlVLVgagDWHHQKfElliGWDfg65nTggr+g1lGWr9sqEC xwWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=rz5MshDy8zEB+rPDtuXCDPczHieCfYcqEV7sROw+BgI=; b=doVMkLhLXfa3BHuLyfAbAvhZgNXlEesupf3NDZDihlRv3asK8pgQUsqyTWKBmgDew3 XHiSIyiskNdPHM37lFTpfh5Cc4uaBqMtgpHpldXKyLYBJuwuQ5a8EH70dIFoVMQ9LjhN EGi8N57A69BIVgI57NTvaEG8/JYZWhrzWJl63pMJidkt/nsKSp8JJ5px+Icw5qDRxCJp KS8XncPZp5Ttt0dhrvSGWCQp3G07A5XMzbLneIOHjKGa3Kb/+NdPrPPB+DTm226QrPqY 7OhEQdTt4Y/1JDMDn33zItMwL/sCYzPUCiw2ccZ2gm6oYtlIpY0iePb/cZX2/RKaMv3b djxw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n5-v6si9702024plp.347.2018.02.21.05.33.15; Wed, 21 Feb 2018 05:33:29 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965354AbeBUNIy (ORCPT + 99 others); Wed, 21 Feb 2018 08:08:54 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:42614 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936134AbeBUNIu (ORCPT ); Wed, 21 Feb 2018 08:08:50 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 8B02411EA; Wed, 21 Feb 2018 13:08:49 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andreas Gruenbacher , Bob Peterson Subject: [PATCH 4.15 073/163] gfs2: Fixes to "Implement iomap for block_map" Date: Wed, 21 Feb 2018 13:48:22 +0100 Message-Id: <20180221124534.510590725@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180221124529.931834518@linuxfoundation.org> References: <20180221124529.931834518@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Andreas Gruenbacher commit 49edd5bf429c405b3a7f75503845d9f66a47dd4b upstream. It turns out that commit 3974320ca6 "Implement iomap for block_map" introduced a few bugs that trigger occasional failures with xfstest generic/476: In gfs2_iomap_begin, we jump to do_alloc when we determine that we are beyond the end of the allocated metadata (height > ip->i_height). There, we can end up calling hole_size with a metapath that doesn't match the current metadata tree, which doesn't make sense. After untangling the code at do_alloc, fix this by checking if the block we are looking for is within the range of allocated metadata. In addition, add a BUG() in case gfs2_iomap_begin is accidentally called for reading stuffed files: this is handled separately. Make sure we don't truncate iomap->length for reads beyond the end of the file; in that case, the entire range counts as a hole. Finally, revert to taking a bitmap write lock when doing allocations. It's unclear why that change didn't lead to any failures during testing. Signed-off-by: Andreas Gruenbacher Signed-off-by: Bob Peterson Signed-off-by: Greg Kroah-Hartman --- fs/gfs2/bmap.c | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -736,7 +736,7 @@ int gfs2_iomap_begin(struct inode *inode __be64 *ptr; sector_t lblock; sector_t lend; - int ret; + int ret = 0; int eob; unsigned int len; struct buffer_head *bh; @@ -748,12 +748,14 @@ int gfs2_iomap_begin(struct inode *inode goto out; } - if ((flags & IOMAP_REPORT) && gfs2_is_stuffed(ip)) { - gfs2_stuffed_iomap(inode, iomap); - if (pos >= iomap->length) - return -ENOENT; - ret = 0; - goto out; + if (gfs2_is_stuffed(ip)) { + if (flags & IOMAP_REPORT) { + gfs2_stuffed_iomap(inode, iomap); + if (pos >= iomap->length) + ret = -ENOENT; + goto out; + } + BUG_ON(!(flags & IOMAP_WRITE)); } lblock = pos >> inode->i_blkbits; @@ -764,7 +766,7 @@ int gfs2_iomap_begin(struct inode *inode iomap->type = IOMAP_HOLE; iomap->length = (u64)(lend - lblock) << inode->i_blkbits; iomap->flags = IOMAP_F_MERGED; - bmap_lock(ip, 0); + bmap_lock(ip, flags & IOMAP_WRITE); /* * Directory data blocks have a struct gfs2_meta_header header, so the @@ -807,27 +809,28 @@ int gfs2_iomap_begin(struct inode *inode iomap->flags |= IOMAP_F_BOUNDARY; iomap->length = (u64)len << inode->i_blkbits; - ret = 0; - out_release: release_metapath(&mp); - bmap_unlock(ip, 0); + bmap_unlock(ip, flags & IOMAP_WRITE); out: trace_gfs2_iomap_end(ip, iomap, ret); return ret; do_alloc: - if (!(flags & IOMAP_WRITE)) { - if (pos >= i_size_read(inode)) { + if (flags & IOMAP_WRITE) { + ret = gfs2_iomap_alloc(inode, iomap, flags, &mp); + } else if (flags & IOMAP_REPORT) { + loff_t size = i_size_read(inode); + if (pos >= size) ret = -ENOENT; - goto out_release; - } - ret = 0; - iomap->length = hole_size(inode, lblock, &mp); - goto out_release; + else if (height <= ip->i_height) + iomap->length = hole_size(inode, lblock, &mp); + else + iomap->length = size - pos; + } else { + if (height <= ip->i_height) + iomap->length = hole_size(inode, lblock, &mp); } - - ret = gfs2_iomap_alloc(inode, iomap, flags, &mp); goto out_release; }