From: Michael Ellerman <mpe@ellerman.id.au>
To: Aleksa Sarai <cyphar@cyphar.com>
Cc: mingo@redhat.com, peterz@infradead.org,
alexander.shishkin@linux.intel.com, jolsa@redhat.com,
namhyung@kernel.org, christian@brauner.io, keescook@chromium.org,
linux@rasmusvillemoes.dk, viro@zeniv.linux.org.uk,
torvalds@linux-foundation.org, linux-api@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] usercopy: Avoid soft lockups in test_check_nonzero_user()
Date: Sat, 12 Oct 2019 20:54:51 +1100 [thread overview]
Message-ID: <87tv8euw44.fsf@mpe.ellerman.id.au> (raw)
In-Reply-To: <20191011034810.xkmz3e4l5ezxvq57@yavin.dot.cyphar.com>
Aleksa Sarai <cyphar@cyphar.com> writes:
> On 2019-10-11, Michael Ellerman <mpe@ellerman.id.au> wrote:
>> On a machine with a 64K PAGE_SIZE, the nested for loops in
>> test_check_nonzero_user() can lead to soft lockups, eg:
...
>> diff --git a/lib/test_user_copy.c b/lib/test_user_copy.c
>> index 950ee88cd6ac..9fb6bc609d4c 100644
>> --- a/lib/test_user_copy.c
>> +++ b/lib/test_user_copy.c
>> @@ -47,9 +47,26 @@ static bool is_zeroed(void *from, size_t size)
>> static int test_check_nonzero_user(char *kmem, char __user *umem, size_t size)
>> {
>> int ret = 0;
>> - size_t start, end, i;
>> - size_t zero_start = size / 4;
>> - size_t zero_end = size - zero_start;
>> + size_t start, end, i, zero_start, zero_end;
>> +
>> + if (test(size < 1024, "buffer too small"))
>> + return -EINVAL;
>> +
>> + /*
>> + * We want to cross a page boundary to exercise the code more
>> + * effectively. We assume the buffer we're passed has a page boundary at
>> + * size / 2. We also don't want to make the size we scan too large,
>> + * otherwise the test can take a long time and cause soft lockups. So
>> + * scan a 1024 byte region across the page boundary.
>> + */
>> + start = size / 2 - 512;
>> + size = 1024;
>
> I don't think it's necessary to do "size / 2" here -- you can just use
> PAGE_SIZE directly and check above that "size == 2*PAGE_SIZE" (not that
> this check is exceptionally necessary -- since there's only one caller
> of this function and it's in the same file).
OK, like this?
diff --git a/lib/test_user_copy.c b/lib/test_user_copy.c
index 950ee88cd6ac..48bc669b2549 100644
--- a/lib/test_user_copy.c
+++ b/lib/test_user_copy.c
@@ -47,9 +47,25 @@ static bool is_zeroed(void *from, size_t size)
static int test_check_nonzero_user(char *kmem, char __user *umem, size_t size)
{
int ret = 0;
- size_t start, end, i;
- size_t zero_start = size / 4;
- size_t zero_end = size - zero_start;
+ size_t start, end, i, zero_start, zero_end;
+
+ if (test(size < 2 * PAGE_SIZE, "buffer too small"))
+ return -EINVAL;
+
+ /*
+ * We want to cross a page boundary to exercise the code more
+ * effectively. We also don't want to make the size we scan too large,
+ * otherwise the test can take a long time and cause soft lockups. So
+ * scan a 1024 byte region across the page boundary.
+ */
+ size = 1024;
+ start = PAGE_SIZE - (size / 2);
+
+ kmem += start;
+ umem += start;
+
+ zero_start = size / 4;
+ zero_end = size - zero_start;
/*
* We conduct a series of check_nonzero_user() tests on a block of memory
cheers
next prev parent reply other threads:[~2019-10-12 9:55 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-01 1:10 [PATCH v4 0/4] lib: introduce copy_struct_from_user() helper Aleksa Sarai
2019-10-01 1:10 ` [PATCH v4 1/4] " Aleksa Sarai
2019-10-01 1:58 ` Kees Cook
2019-10-01 2:31 ` Christian Brauner
2019-10-01 16:28 ` Kees Cook
2019-10-10 11:19 ` Michael Ellerman
2019-10-10 11:40 ` Aleksa Sarai
2019-10-10 16:43 ` Kees Cook
2019-10-11 2:24 ` [PATCH] usercopy: Avoid soft lockups in test_check_nonzero_user() Michael Ellerman
2019-10-11 3:48 ` Aleksa Sarai
2019-10-11 9:43 ` Christian Brauner
2019-10-16 12:28 ` Michael Ellerman
2019-10-16 12:45 ` Christian Brauner
2019-10-12 9:54 ` Michael Ellerman [this message]
2019-10-12 10:12 ` Aleksa Sarai
2019-10-16 12:27 ` [PATCH v2] " Michael Ellerman
2019-10-16 12:36 ` Aleksa Sarai
2019-10-16 12:50 ` Christian Brauner
2019-10-16 13:03 ` Christian Brauner
2019-10-16 22:00 ` Michael Ellerman
2019-10-17 6:09 ` Christian Brauner
2019-10-23 2:23 ` Michael Ellerman
2019-10-01 1:10 ` [PATCH v4 2/4] clone3: switch to copy_struct_from_user() Aleksa Sarai
2019-10-01 2:32 ` Christian Brauner
2019-10-01 1:10 ` [PATCH v4 3/4] sched_setattr: " Aleksa Sarai
2019-10-01 2:33 ` Christian Brauner
2019-10-01 1:10 ` [PATCH v4 4/4] perf_event_open: " Aleksa Sarai
2019-10-01 2:36 ` Christian Brauner
2019-10-01 16:01 ` [PATCH v4 0/4] lib: introduce copy_struct_from_user() helper Christian Brauner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87tv8euw44.fsf@mpe.ellerman.id.au \
--to=mpe@ellerman.id.au \
--cc=alexander.shishkin@linux.intel.com \
--cc=christian@brauner.io \
--cc=cyphar@cyphar.com \
--cc=jolsa@redhat.com \
--cc=keescook@chromium.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox