From patchwork Tue Jun 11 03:01:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13692786 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 C9D02C27C4F for ; Tue, 11 Jun 2024 03:02:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 541856B00A5; Mon, 10 Jun 2024 23:02:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4F10C6B00A6; Mon, 10 Jun 2024 23:02:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2A6AF6B00AB; Mon, 10 Jun 2024 23:02:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 01AEE6B00A5 for ; Mon, 10 Jun 2024 23:02:10 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A9F4E1C1D84 for ; Tue, 11 Jun 2024 03:02:10 +0000 (UTC) X-FDA: 82217108820.09.EF2272E Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf28.hostedemail.com (Postfix) with ESMTP id 17084C0017 for ; Tue, 11 Jun 2024 03:02:07 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=f6ZgZOTM; spf=none (imf28.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718074928; a=rsa-sha256; cv=none; b=mBSw2nKdzdHHOsOC/hdbyFiI5IE5xVnr3WLc5GNRGsHDsRmWQeQJrTb250XPC6GUzQ71MN G/VQQHA5r3aG3iWtdZXXyzCgiLhrK7QO3WI5ZrhGPbe1U+YXencxB6p+GE9jYuPCsq8av9 QwfXpmubTN3UymbXDzu4GK0B8Mvj8xc= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=f6ZgZOTM; spf=none (imf28.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=1718074928; 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=CX8GkoD1lrWdXbOILcd8kqt0xs0WnOHnk3dNstWrvmw=; b=KZrNOjAu7a5g4fYbMbk391cC9noZpr0MpkDeegRpf6MVaBCd9s7Brqsp3cMw4S9FIh2bZG YgbzNKeb84B1wmxaorP8g8s7X9WLkpwa0tgugNgWJsP8RDJZhiKHrWpWHbaNKdrqkuU8F7 4mSxRo73BnXoXhsPzGHjV9+//CzYxmY= 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=CX8GkoD1lrWdXbOILcd8kqt0xs0WnOHnk3dNstWrvmw=; b=f6ZgZOTMdrlAqlPZArCc35aXQc 0aob4eDMIoMJkwFReDEAOGuj6u8becvRxbtlACrVJNRLnjaLW8kM4gtbNmH4ipl+dTmUKXdu5cKNv O5uMhahpgsMC9NZ5XOYDrOB+nKftYJKZGKziK/q9RjP9A9KLWVM/fz2nN8JrEJxwjkZXavn3QC9js W9+kXvgP6ELe5TgSlYmME+GX9WbTTeey/kmwkOiwwROLeOIcCebexa14Nz+WIyUe4IS57A9xiTO1M Tu8jih2vYCWzTf1TkwiZDX9+KGmpENr+zcIl77MtyiPhvhlcOoq85yYBwz1WViJLPP7mrhR5zdBZn W72QhX4A==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1sGrls-00000007DDG-1iC3; Tue, 11 Jun 2024 03:02:04 +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 1/5] common: move mread() to generic helper _mread() Date: Mon, 10 Jun 2024 20:01:58 -0700 Message-ID: <20240611030203.1719072-2-mcgrof@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240611030203.1719072-1-mcgrof@kernel.org> References: <20240611030203.1719072-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 17084C0017 X-Rspam-User: X-Rspamd-Server: rspam12 X-Stat-Signature: 88gnrxwwc8j8bzaz736srzkpc93pon9q X-HE-Tag: 1718074927-409231 X-HE-Meta: U2FsdGVkX19xq5l7PRiaGAwhQtXuwgGPe/2rtp/0SLQppQfAL7p///TL23U32Z3q7v2cFAG2djYIQ1mTXSKAB4Xhulb8lr90nxpS/8tY3KFe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wh6Hn8zNZMlI4D/7znSr9U0Uz/1mhFXUNns0HM+FRuQ5aAcs72yHkdo09V5oMpGZu7vtsU9UyWVJIyb1pKPOhTZgLk2T3HXVXOqA2hbN4eMQfC+Te2lsEmpTPsS9ILwq5fHjneDwxfEt+9+cywNufbu/j9gL19Sr2lMfug1LUVsdk2TS6+G/7BaU1Wx4/N+x/5WK7FGiApiDZPl5+9s/2xkTyxGijqDTh3HKRANaVbGGAz3MuAYTMfZOiO9BRGuKIES 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" Signed-off-by: Luis Chamberlain Reviewed-by: Darrick J. Wong --- 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 }