From patchwork Sat Dec 22 00:32:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10741215 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F39A06C5 for ; Sat, 22 Dec 2018 00:32:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E1ED42886C for ; Sat, 22 Dec 2018 00:32:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D5BBB28875; Sat, 22 Dec 2018 00:32:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4BF9C2886C for ; Sat, 22 Dec 2018 00:32:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731366AbeLVAcn (ORCPT ); Fri, 21 Dec 2018 19:32:43 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:39402 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729898AbeLVAcn (ORCPT ); Fri, 21 Dec 2018 19:32:43 -0500 Received: by mail-pl1-f195.google.com with SMTP id 101so3183084pld.6 for ; Fri, 21 Dec 2018 16:32:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=d7iHM5nLbDRxmJ20nr7hNqRFGC7ZA3c51ZpjPe91NqI=; b=jzt+X0Na20LoyPQxUaEItDq7w+/Of3/KnP/RaDRYR6HEsyEw12Tc2eeNo6agA20T1i 0gmd0ScOPy7l5fFFrzzGEOXk0aoTwSMbkXQrXN5GQSB/nIN+X7h/szRx+jc3JkQlEdPU BxkJdV8/voPuxnxuAA5MpB1x0LxW+NNHmgrwCDE9nhxoEm8yvjT7Qq4Kjn64JQVopsFk KwFkGFtZKVREWTDdqP0saF+In1b+NkRIFfLKRw/TIPEdvH+eqVk+ypc+Mp65YD+NeAq8 gPahUH38a/7zcRVLcM9PBItvpaorHU3k58J9d7/Mgc6XYyVi5Lilpbfpva2tw9HRpBRr 7iXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=d7iHM5nLbDRxmJ20nr7hNqRFGC7ZA3c51ZpjPe91NqI=; b=FiEu02x/5YACZkNE3IOvg/0jtIr4/frfMPBSsRQyiMUP9qMdtnr36G3MWEjKO02LoZ E7Xm7R3kOA8N6nx3jWGv747XLWgXTrBglzHx2RJfldio9IBRyqjwQQFzC1QsQsnxJLWE 7k/A8jRArq6BizdsGA4QsnP6ZZ9Dnuo/39rJ15n8ev6ihcDsiST4S/i8IGrcLgyGnjvg EbJV5kx6FpNjIdNQL4Q6SUS+tLWwNF+v55Sesr+a46rdy8QcREHyLQc9gOjLF4BtAD4G aO8TA6iCGsB+8qyEv4MBZgLOuBk0bzm9SYn9Px0jwNY0CySA1noxEk8AkHQFd2QjHWst WHWw== X-Gm-Message-State: AJcUukcM4/8xooqdZFXGA8DXfxNy3c5qRLnkNRjrCTMj7gX4EfhLErZo 7+gI2fmBOODKRlksQOZXcO2VfOO7oldCtQ== X-Google-Smtp-Source: ALg8bN4VwczWvd7qURt2i+plcytyoa47ZZlnIEWG34lP2XzXfS/NNK57yqHnWUoa75NheixXgRSXJQ== X-Received: by 2002:a17:902:aa0a:: with SMTP id be10mr4539950plb.266.1545438762168; Fri, 21 Dec 2018 16:32:42 -0800 (PST) Received: from vader.thefacebook.com ([2620:10d:c090:200::6:5261]) by smtp.gmail.com with ESMTPSA id c23sm31142445pfi.83.2018.12.21.16.32.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Dec 2018 16:32:41 -0800 (PST) From: Omar Sandoval To: linux-xfs@vger.kernel.org Cc: kernel-team@fb.com Subject: [PATCH] xfs: reallocate realtime summary cache on growfs Date: Fri, 21 Dec 2018 16:32:38 -0800 Message-Id: <1f6a98905845d1b03cf0aa96539715d29da32034.1545438588.git.osandov@fb.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Omar Sandoval At mount time, we allocate m_rsum_cache with the number of realtime bitmap blocks. However, xfs_growfs_rt() can increase the number of realtime bitmap blocks. Using the cache after this happens may access out of the bounds of the cache. Fix it by reallocating the cache in this case. Fixes: 355e3532132b ("xfs: cache minimum realtime summary level") Signed-off-by: Omar Sandoval Reviewed-by: Darrick J. Wong --- Hi, This is a quick for for my previous patch which is queued up for 4.21, based on xfs-linux/for-next. This is bad timing with the holidays coming up, but growfs on a realtime volume is probably pretty rare :) Thanks! fs/xfs/xfs_rtalloc.c | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index afe4d29f7ab4..ac0fcdad0c4e 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -861,6 +861,21 @@ xfs_growfs_rt_alloc( return error; } +static void +xfs_alloc_rsum_cache( + xfs_mount_t *mp, /* file system mount structure */ + xfs_extlen_t rbmblocks) /* number of rt bitmap blocks */ +{ + /* + * The rsum cache is initialized to all zeroes, which is trivially a + * lower bound on the minimum level with any free extents. We can + * continue without the cache if it couldn't be allocated. + */ + mp->m_rsum_cache = kmem_zalloc_large(rbmblocks, KM_SLEEP); + if (!mp->m_rsum_cache) + xfs_warn(mp, "could not allocate realtime summary cache"); +} + /* * Visible (exported) functions. */ @@ -889,6 +904,7 @@ xfs_growfs_rt( xfs_extlen_t rsumblocks; /* current number of rt summary blks */ xfs_sb_t *sbp; /* old superblock */ xfs_fsblock_t sumbno; /* summary block number */ + uint8_t *rsum_cache; /* old summary cache */ sbp = &mp->m_sb; /* @@ -945,6 +961,11 @@ xfs_growfs_rt( error = xfs_growfs_rt_alloc(mp, rsumblocks, nrsumblocks, mp->m_rsumip); if (error) return error; + + rsum_cache = mp->m_rsum_cache; + if (nrbmblocks != sbp->sb_rbmblocks) + xfs_alloc_rsum_cache(mp, nrbmblocks); + /* * Allocate a new (fake) mount/sb. */ @@ -1070,6 +1091,20 @@ xfs_growfs_rt( */ kmem_free(nmp); + /* + * If we had to allocate a new rsum_cache, we either need to free the + * old one (if we succeeded) or free the new one and restore the old one + * (if there was an error). + */ + if (rsum_cache != mp->m_rsum_cache) { + if (error) { + kmem_free(mp->m_rsum_cache); + mp->m_rsum_cache = rsum_cache; + } else { + kmem_free(rsum_cache); + } + } + return error; } @@ -1217,14 +1252,7 @@ xfs_rtmount_inodes( return error; } ASSERT(mp->m_rsumip != NULL); - /* - * The rsum cache is initialized to all zeroes, which is trivially a - * lower bound on the minimum level with any free extents. We can - * continue without the cache if it couldn't be allocated. - */ - mp->m_rsum_cache = kmem_zalloc_large(sbp->sb_rbmblocks, KM_SLEEP); - if (!mp->m_rsum_cache) - xfs_warn(mp, "could not allocate realtime summary cache"); + xfs_alloc_rsum_cache(mp, sbp->sb_rbmblocks); return 0; }