From mboxrd@z Thu Jan 1 00:00:00 1970 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 6AFD2C25B76 for ; Tue, 11 Jun 2024 14:28:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E03A66B0096; Tue, 11 Jun 2024 10:28:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DB3376B0098; Tue, 11 Jun 2024 10:28:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C7AC86B0099; Tue, 11 Jun 2024 10:28:33 -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 A8EE66B0096 for ; Tue, 11 Jun 2024 10:28:33 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 60B49141500 for ; Tue, 11 Jun 2024 14:28:33 +0000 (UTC) X-FDA: 82218838506.19.79A708A Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf02.hostedemail.com (Postfix) with ESMTP id 937C880008 for ; Tue, 11 Jun 2024 14:28:31 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=RGrjD9ej; spf=pass (imf02.hostedemail.com: domain of djwong@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=djwong@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718116111; a=rsa-sha256; cv=none; b=WQ2BEiuWNOfLIGDXuVIgLubIF2Hq9lXt7SVsphIuRmBVrxoKp792LweBJ5wU6wIFoT/iPN 2qBfV3m2fjW8ew9t0f0eFUUG4dV6/UVuxRTUixFLGHY+WqYuSQpixSjrgpqGMJaqFdB+6F Sbd85j+9lBdlKWaMiES0g/CvZkEu27s= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=RGrjD9ej; spf=pass (imf02.hostedemail.com: domain of djwong@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=djwong@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718116111; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=XUXlqFnLQfWhS7Cc3Zacw7zH9iynl62c8TZFUZkUOm4=; b=VagT5f4+ZlCUMbTvfYJxtz3UoVL7X4sZvIB0jA5ks90iLf7JYhZzMkuRezdEq3yKuSzp94 bSIHs/eGs2Y0gfr1qjPk9rbfqcm70Q+xTiyyCx7oDpfLPyZN3SR6nWagnV6IkNeiOen1bW fiexva/PgEcqMm7cCNTHDk0WA3FsZPg= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 89AD060EA5; Tue, 11 Jun 2024 14:28:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 36295C2BD10; Tue, 11 Jun 2024 14:28:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718116110; bh=u6IPxDchDXd4e1F8IfxVMsgtYMnGEwTTN8nDGvge/mM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=RGrjD9ejdq2ZY0D6fhhoXuAdwQkd6ho9NU+Mq6pzK3fQjKvs4gy6LS5N/Xs0xS2wX z9uVJMQUU+iHSKPrLjYlvsDEdhmH3EgwwW43kbJN0y9cIZN7kl+GTLyJzqKKAHGDIQ kbCdaprZKgpEe5pL7hKigA95eyi2Y5m5Ud+tnBpAJh8W7FAKCO0UIfpTwPptUJZVzm SDGE1iIz59SJoDHeZLn/MOkvJi1syGluHg1+zZczR0CTpHyNjPb0/mDo96PZb9YyGG XXXcugQH0wm0qAASFDhB8qb6ALKfhttxqJMyJM7CcSs3gNjd3raVREDqRv4NMhhkdX txfcsE5RVFT3A== Date: Tue, 11 Jun 2024 07:28:29 -0700 From: "Darrick J. Wong" To: Luis Chamberlain Cc: patches@lists.linux.dev, fstests@vger.kernel.org, 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 Subject: Re: [PATCH 1/5] common: move mread() to generic helper _mread() Message-ID: <20240611142829.GG52977@frogsfrogsfrogs> References: <20240611030203.1719072-1-mcgrof@kernel.org> <20240611030203.1719072-2-mcgrof@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240611030203.1719072-2-mcgrof@kernel.org> X-Stat-Signature: 5ct8w9abdtt5ee6d64x66ce87e7oq54t X-Rspamd-Queue-Id: 937C880008 X-Rspamd-Server: rspam04 X-Rspam-User: X-HE-Tag: 1718116111-767538 X-HE-Meta: U2FsdGVkX1+Is9qwdeLoEYU4DUlLIY/VsNwvm/FAGWQLr2zJvnWaQVSjEBCN6+MmnHWYiSsmWshThrIa6jxr/lrHuR7uWbhZR5oEHb+O+CQAnl06UeVDC46b5iM6M0eEGF+NdpnBxT3dxesQDBiAIYd3JfikN6IxIYvCxNEju42NAozhIIERfx8G8aaNrezMR85IRnoonkI0GWF3gjTz4+0YPNHXYL8Ecnvpc9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ogofilter, 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: On Mon, Jun 10, 2024 at 08:01:58PM -0700, Luis Chamberlain wrote: > 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 Looks ok, Reviewed-by: Darrick J. Wong --D > --- > 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 > } > -- > 2.43.0 > >