From patchwork Sat Jun 15 00:29:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13699197 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 B7F74C27C6E for ; Sat, 15 Jun 2024 00:38:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D87A16B016C; Fri, 14 Jun 2024 20:32:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8AF666B0171; Fri, 14 Jun 2024 20:32:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EAA936B016E; Fri, 14 Jun 2024 20:31:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id E7FBB6B0266 for ; Fri, 14 Jun 2024 20:29:43 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 9EB0CA2127 for ; Sat, 15 Jun 2024 00:29:43 +0000 (UTC) X-FDA: 82231239846.11.164FA00 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf11.hostedemail.com (Postfix) with ESMTP id 125C540002 for ; Sat, 15 Jun 2024 00:29:41 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=ivWZ2hSG; spf=none (imf11.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718411379; h=from:from:sender: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=7tr+VAt/VPGCgpSRMR8yi7xw9PLDWB0hThmICKV/0J4=; b=8Us7JZEgMs/0HxxbZxZLo8NYXYbya/11mbOzyybOfPp7iDdnSI+Sk2WGAYrw1i/xxPYpup ODk9skEnbgeYokFpH39euibcfZNT+5uvfhhiDELnaF6fvKN/UJDNfxVnF0dhTvliMXZPaf ytH1QYQ8QQmLe01M6Gi4u+iwxM5bb78= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718411379; a=rsa-sha256; cv=none; b=5FBL4ujUjktIn9Uru3GoAqiPJ0iqFTG8O8yhtkNNzBZyOaUp0qorDE+YucCb+MY+NiC5mq 7fzqA1Zs1Og2yXm7RS01ESPn7WDVbNOXHoKrClTJ+tDV9l+JHqxQPD26e5A4ObGtjzLicZ +RGNy06Umyc/ohfMr5LitqvHINiOlPI= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=ivWZ2hSG; spf=none (imf11.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=7tr+VAt/VPGCgpSRMR8yi7xw9PLDWB0hThmICKV/0J4=; b=ivWZ2hSG8ZKwP7fFVjGd1XYOM2 NVjY6JTV4uvms7kpXWLbOIZJE4j2Bl8KCRcs7ua+7wg9AxO1tVPSpjYk12PKR3ADghR6XqylLEl8C hBhSmojLlpSCJpZcTYNQVDzjAFtwWXFQFEvmPvixUSScnAMe3uEWXMCQ5Dh8oZpR0qY8T1Xpx17Th RZ+QtX9426rYymJ3iUWg6rxdFjRBh8nJpKmEosAF6ET+ffK3p+JKXPeGYFa4m7gsUBLAv6/m8VQ6G 7JMWxzu1mlTLFw7JCura3zeNhkuwKl9EbVWd5hJRuFAvBbkAUi0g+bz1gqKyNShHkQ304jiZKNjSh qo0KzjmQ==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1sIHIV-00000004KkI-3ZVc; Sat, 15 Jun 2024 00:29:35 +0000 From: Luis Chamberlain To: patches@lists.linux.dev, fstests@vger.kernel.org Cc: linux-xfs@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, akpm@linux-foundation.org, ziy@nvidia.com, vbabka@suse.cz, seanjc@google.com, willy@infradead.org, david@redhat.com, hughd@google.com, linmiaohe@huawei.com, muchun.song@linux.dev, osalvador@suse.de, p.raghav@samsung.com, da.gomez@samsung.com, hare@suse.de, john.g.garry@oracle.com, mcgrof@kernel.org, "Darrick J . Wong" Subject: [PATCH v2 1/5] common: move mread() to generic helper _mread() Date: Fri, 14 Jun 2024 17:29:30 -0700 Message-ID: <20240615002935.1033031-2-mcgrof@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240615002935.1033031-1-mcgrof@kernel.org> References: <20240615002935.1033031-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 125C540002 X-Stat-Signature: wge454j5t5mp713gk6ksog4pojtojfem X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1718411381-695695 X-HE-Meta: U2FsdGVkX1+K3JO7vb8+5ypXdVgvvs7tBlPdvvnuBi0dsyCcHqMeHA43nujLkEeJIk8ogNIV6lJuMZkD8H2qbFfhuneZZc/3chQ9DT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438g8oQdhfDXKSTHqK6XoM0Ofwx0U+yWPk9xI6D5UDGpIEqyUws4ozvfr2hCGQAACo43kYQz7J23rycxkmMEbuZXc0kmaHS9FgQtQ3IMzlh3xWUnjNkji0TDX/icGCufEdtrFi8TR5A9EQ9k9Z0LwDr+kcIfxztg7e3H/toQxMOHRDfXa5MUjKCQIjRAn4ewqYC4QX1MuVtPoRsNRUdqsV/be23ttyMxsc+rL2IXjQfWgfydoolRzOh5zRzjpQ0w7fq0yj9lrSzoZlXaZSuH1Ex4SPUnCbZtj X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: We want a shared way to use mmap in a way that we can test for the SIGBUS, provide a shared routine which other tests can leverage. Suggested-by: Darrick J. Wong Reviewed-by: Darrick J. Wong Signed-off-by: Luis Chamberlain --- common/rc | 28 ++++++++++++++++++++++++++++ tests/generic/574 | 36 ++++-------------------------------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/common/rc b/common/rc index 163041fea5b9..fa7942809d6c 100644 --- a/common/rc +++ b/common/rc @@ -52,6 +52,34 @@ _pwrite_byte() { $XFS_IO_PROG $xfs_io_args -f -c "pwrite -S $pattern $offset $len" "$file" } +_round_up_to_page_boundary() +{ + local n=$1 + local page_size=$(_get_page_size) + + echo $(( (n + page_size - 1) & ~(page_size - 1) )) +} + +_mread() +{ + local file=$1 + local offset=$2 + local length=$3 + local map_len=$(_round_up_to_page_boundary $(_get_filesize $file)) + + # Some callers expect xfs_io to crash with SIGBUS due to the mread, + # causing the shell to print "Bus error" to stderr. To allow this + # message to be redirected, execute xfs_io in a new shell instance. + # However, for this to work reliably, we also need to prevent the new + # shell instance from optimizing out the fork and directly exec'ing + # xfs_io. The easiest way to do that is to append 'true' to the + # commands, so that xfs_io is no longer the last command the shell sees. + # Don't let it write core files to the filesystem. + bash -c "trap '' SIGBUS; ulimit -c 0; $XFS_IO_PROG -r $file \ + -c 'mmap -r 0 $map_len' \ + -c 'mread -v $offset $length'; true" +} + # mmap-write a byte into a range of a file _mwrite_byte() { local pattern="$1" diff --git a/tests/generic/574 b/tests/generic/574 index cb42baaa67aa..d44c23e5abc2 100755 --- a/tests/generic/574 +++ b/tests/generic/574 @@ -52,34 +52,6 @@ setup_zeroed_file() cmp $fsv_orig_file $fsv_file } -round_up_to_page_boundary() -{ - local n=$1 - local page_size=$(_get_page_size) - - echo $(( (n + page_size - 1) & ~(page_size - 1) )) -} - -mread() -{ - local file=$1 - local offset=$2 - local length=$3 - local map_len=$(round_up_to_page_boundary $(_get_filesize $file)) - - # Some callers expect xfs_io to crash with SIGBUS due to the mread, - # causing the shell to print "Bus error" to stderr. To allow this - # message to be redirected, execute xfs_io in a new shell instance. - # However, for this to work reliably, we also need to prevent the new - # shell instance from optimizing out the fork and directly exec'ing - # xfs_io. The easiest way to do that is to append 'true' to the - # commands, so that xfs_io is no longer the last command the shell sees. - # Don't let it write core files to the filesystem. - bash -c "trap '' SIGBUS; ulimit -c 0; $XFS_IO_PROG -r $file \ - -c 'mmap -r 0 $map_len' \ - -c 'mread -v $offset $length'; true" -} - corruption_test() { local block_size=$1 @@ -142,7 +114,7 @@ corruption_test() fi # Reading the full file via mmap should fail. - mread $fsv_file 0 $file_len >/dev/null 2>$tmp.err + _mread $fsv_file 0 $file_len >/dev/null 2>$tmp.err if ! grep -q 'Bus error' $tmp.err; then echo "Didn't see SIGBUS when reading file via mmap" cat $tmp.err @@ -150,7 +122,7 @@ corruption_test() # Reading just the corrupted part via mmap should fail. if ! $is_merkle_tree; then - mread $fsv_file $zap_offset $zap_len >/dev/null 2>$tmp.err + _mread $fsv_file $zap_offset $zap_len >/dev/null 2>$tmp.err if ! grep -q 'Bus error' $tmp.err; then echo "Didn't see SIGBUS when reading corrupted part via mmap" cat $tmp.err @@ -174,10 +146,10 @@ corrupt_eof_block_test() head -c $zap_len /dev/zero | tr '\0' X \ | _fsv_scratch_corrupt_bytes $fsv_file $file_len - mread $fsv_file $file_len $zap_len >$tmp.out 2>$tmp.err + _mread $fsv_file $file_len $zap_len >$tmp.out 2>$tmp.err head -c $file_len /dev/zero >$tmp.zeroes - mread $tmp.zeroes $file_len $zap_len >$tmp.zeroes_out + _mread $tmp.zeroes $file_len $zap_len >$tmp.zeroes_out grep -q 'Bus error' $tmp.err || diff $tmp.out $tmp.zeroes_out }