From patchwork Thu Jan 18 22:19:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Chinner X-Patchwork-Id: 13523242 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA065C47DAF for ; Thu, 18 Jan 2024 22:22:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 40D4E6B007E; Thu, 18 Jan 2024 17:22:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3BC616B0078; Thu, 18 Jan 2024 17:22:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 284946B0080; Thu, 18 Jan 2024 17:22:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 06D686B0078 for ; Thu, 18 Jan 2024 17:22:25 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id CA415C0305 for ; Thu, 18 Jan 2024 22:22:24 +0000 (UTC) X-FDA: 81693856608.12.AC47ACD Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) by imf21.hostedemail.com (Postfix) with ESMTP id BA3511C0017 for ; Thu, 18 Jan 2024 22:22:22 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=fromorbit-com.20230601.gappssmtp.com header.s=20230601 header.b=NJ5Kv4Mv; dmarc=pass (policy=quarantine) header.from=fromorbit.com; spf=pass (imf21.hostedemail.com: domain of david@fromorbit.com designates 209.85.215.179 as permitted sender) smtp.mailfrom=david@fromorbit.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1705616542; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=SIYg4fbOx5xpSV7xBsoY4WQ6ng+5chM3y1Ni3HkVJSg=; b=2g3arzSUHKufHKmEO2jq2svTJutBEZ+COxmPIwXcQHPVuT3AZENm0RtgGdXHiqSCvWZz7t T2vz44lXqYt97GiVXScEfy6SACXZ160J5IzCR/fGRFL2tYRdve8Ggemu7CcCik5Raii+gr b1ml/Z6KIviVAsSu06uxeg2mWlH0Xlc= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=fromorbit-com.20230601.gappssmtp.com header.s=20230601 header.b=NJ5Kv4Mv; dmarc=pass (policy=quarantine) header.from=fromorbit.com; spf=pass (imf21.hostedemail.com: domain of david@fromorbit.com designates 209.85.215.179 as permitted sender) smtp.mailfrom=david@fromorbit.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705616542; a=rsa-sha256; cv=none; b=GJ08wGzP86zQaX1uKftf1cGmuWckl1xztUYoEkm0VL8G9sTANGxgqZax6/7xwD6YKr2NvY RczETg6yeyhsCHxJamcvnv19a/u92JrHx2E+MV7d3HmXNuw8g6/qDzII+b5lxUanJHQC8e rBJ1cvzY4tu5Qqez/TTvuFSoYfqrwk8= Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-5cf450eba00so151358a12.0 for ; Thu, 18 Jan 2024 14:22:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fromorbit-com.20230601.gappssmtp.com; s=20230601; t=1705616541; x=1706221341; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SIYg4fbOx5xpSV7xBsoY4WQ6ng+5chM3y1Ni3HkVJSg=; b=NJ5Kv4MvgKgRN/bdkZP0ovnh3b3nJrlcOJDZUgCY1upj/skqt7PTYQvvCMdYZGOJk8 G5sLhNqvJVOaVJUOh7HGafF5gl90uQ02yQal/Vh4B4Z+sNfRsNRLxIE0E2bB4ASUqOw+ 2xQi0eGD0pD2A71ZDYE4nuh9eEGH1sPA2OpnnQj85mkgFm3NKNWJCSe0DBWo1G52Gy8e UybipwFqaF5pRb4oo4cVt/kHoHMMANMe9JJzWhksVzs5n46byN8Nwa7pzl9uN8rbBRdH Qm9uoCEnE+0bvynxzdbXtO7XzB/zWZcn/oFdFX8maTl44q7PZX+lwSj+e0eIEwTtThNR X0Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705616541; x=1706221341; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SIYg4fbOx5xpSV7xBsoY4WQ6ng+5chM3y1Ni3HkVJSg=; b=E4aO/86hpraH3HT8zlx4OT8exuvdkwDNqdqEARjsowLht5MI3Z513alHhNwhPsMrYQ dsoDY2zBRdkxgBzxa3eZYB+S4FY3YalPNm3TEhb2aSAUuOpoTXk5TD5hYkas0PRIRaHs XW1mjjF3aTQNfQxpiZ2BpnIqJNvkyiWaAFyJNLeJcNbAs63dhsuD98CufzqepWMW/zn/ MQ84dQKJhtYfPhBdmU2q/AEw0pT/z3sKWQuzr3CNXPDlcv3/0Jate2TZ2X8WXTSFrEmb eICp60TYF57DOFrWgwTmk5zi3oTGSe845FnEaKbbWk4izgq3gZfV0bWcrIa/NXB+LzI3 OeoQ== X-Gm-Message-State: AOJu0YzghSnJenK5KG3XhPW52ypHieWCV5BSCxtrVpG7cNgbKiim0lT1 vZDpvfnVsZmrSGNSgm82sJX8h1qR/HGLxQP8iSWYdcwPUZSu0TePEDUsgUSNOvY= X-Google-Smtp-Source: AGHT+IFvJI+inGv4x/2Vzu4CfgzR5ivHLaCvAfCWUVCseYlv9qmktZULfGpdbMDYc55IPbpJDykUzw== X-Received: by 2002:a17:902:ee8a:b0:1d5:7220:9ff with SMTP id a10-20020a170902ee8a00b001d5722009ffmr1594374pld.117.1705616541575; Thu, 18 Jan 2024 14:22:21 -0800 (PST) Received: from dread.disaster.area (pa49-180-249-6.pa.nsw.optusnet.com.au. [49.180.249.6]) by smtp.gmail.com with ESMTPSA id p12-20020a170902eacc00b001d71729ec9csm531276pld.188.2024.01.18.14.22.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 14:22:21 -0800 (PST) Received: from [192.168.253.23] (helo=devoid.disaster.area) by dread.disaster.area with esmtp (Exim 4.96) (envelope-from ) id 1rQamB-00CCGN-0h; Fri, 19 Jan 2024 09:22:18 +1100 Received: from dave by devoid.disaster.area with local (Exim 4.97) (envelope-from ) id 1rQamA-0000000HMlm-2z8S; Fri, 19 Jan 2024 09:22:18 +1100 From: Dave Chinner To: linux-xfs@vger.kernel.org Cc: willy@infradead.org, linux-mm@kvack.org Subject: [PATCH 1/3] xfs: unmapped buffer item size straddling mismatch Date: Fri, 19 Jan 2024 09:19:39 +1100 Message-ID: <20240118222216.4131379-2-david@fromorbit.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240118222216.4131379-1-david@fromorbit.com> References: <20240118222216.4131379-1-david@fromorbit.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: BA3511C0017 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: jorztkxi3qnpf71tzuerinjxr91ondqe X-HE-Tag: 1705616542-394970 X-HE-Meta: U2FsdGVkX1/as4uTvNRlc28XPbqJ8scXzuhspPCOxWONdzwer6P0RP8bGgHC0z4BkU+Ahq78sZv8xAdnQ/W9YEReHeY7Ct1g1uQdkqbJy+iHgPuvEMyxIOUsVfBzOFz3smrhjLoj6ZWqH0/W4lhNB80ggBadiq1wGHAGNGa/M48/6f+pi3cDry2jq3eGkq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kaJ7EjbxZECiSGodJbD8Ntj2OG9NhMsBWEJjeU0P7aBD+a4ZHf4J/pmDqbIVpGEs3cJOOjYNsFxCuPyA1uYTYzVf3qQFpTWma+OX+f2DiUpQ7828Y67tSD2mEjbljaBdRLVaxE5u51xhsuWOJO3tgYI7okAO0MDoIHSUAxiok3mLm0QYgDcJKiKLpaGic7Mxp3j5RAN5dg+Hrdenok= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000092, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Dave Chinner We never log large contiguous regions of unmapped buffers, so this bug is never triggered by the current code. However, the slowpath for formatting buffer straddling regions is broken. That is, the size and shape of the log vector calculated across a straddle does not match how the formatting code formats a straddle. This results in a log vector with an uninitialised iovec and this causes a crash when xlog_write_full() goes to copy the iovec into the journal. Whilst touching this code, don't bother checking mapped or single folio buffers for discontiguous regions because they don't have them. This significantly reduces the overhead of this check when logging large buffers as calling xfs_buf_offset() is not free and it occurs a *lot* in those cases. Fixes: 929f8b0deb83 ("xfs: optimise xfs_buf_item_size/format for contiguous regions") Signed-off-by: Dave Chinner Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_buf_item.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/fs/xfs/xfs_buf_item.c b/fs/xfs/xfs_buf_item.c index 43031842341a..83a81cb52d8e 100644 --- a/fs/xfs/xfs_buf_item.c +++ b/fs/xfs/xfs_buf_item.c @@ -56,6 +56,10 @@ xfs_buf_log_format_size( (blfp->blf_map_size * sizeof(blfp->blf_data_map[0])); } +/* + * We only have to worry about discontiguous buffer range straddling on unmapped + * buffers. Everything else will have a contiguous data region we can copy from. + */ static inline bool xfs_buf_item_straddle( struct xfs_buf *bp, @@ -65,6 +69,9 @@ xfs_buf_item_straddle( { void *first, *last; + if (bp->b_page_count == 1 || !(bp->b_flags & XBF_UNMAPPED)) + return false; + first = xfs_buf_offset(bp, offset + (first_bit << XFS_BLF_SHIFT)); last = xfs_buf_offset(bp, offset + ((first_bit + nbits) << XFS_BLF_SHIFT)); @@ -132,11 +139,13 @@ xfs_buf_item_size_segment( return; slow_scan: - /* Count the first bit we jumped out of the above loop from */ - (*nvecs)++; - *nbytes += XFS_BLF_CHUNK; + ASSERT(bp->b_addr == NULL); last_bit = first_bit; + nbits = 1; while (last_bit != -1) { + + *nbytes += XFS_BLF_CHUNK; + /* * This takes the bit number to start looking from and * returns the next set bit from there. It returns -1 @@ -151,6 +160,8 @@ xfs_buf_item_size_segment( * else keep scanning the current set of bits. */ if (next_bit == -1) { + if (first_bit != last_bit) + (*nvecs)++; break; } else if (next_bit != last_bit + 1 || xfs_buf_item_straddle(bp, offset, first_bit, nbits)) { @@ -162,7 +173,6 @@ xfs_buf_item_size_segment( last_bit++; nbits++; } - *nbytes += XFS_BLF_CHUNK; } }