Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp688673ybp; Fri, 11 Oct 2019 02:45:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqwqqd8bxzu6OxxSNuIZL9ehZO9cFb4eDh529AzkhM8xMPivRhkBihckHW/G8BZrnsAUzCgP X-Received: by 2002:a17:906:7e49:: with SMTP id z9mr12678243ejr.315.1570787141431; Fri, 11 Oct 2019 02:45:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570787141; cv=none; d=google.com; s=arc-20160816; b=Orp0VSD9r2DlzbcBHvdk8EE/Zh2WYCz0HWdtHrwc+WKXc/BgLaW861XdvKuSDH3yBQ T6duqFy5KCgR6u3FRZORgamnclrnop+9c+v2SEacPJvA2uO3RyU0pXzeAW0LYZKvaIgR 13woCo5JE1lrll1GZ7Bqt2aTf8b57ReYYEd9+c3Kgdf5b0xTOErcyvvmyPd5GqAeJRb8 ACRAUYgTm9nSJxwN6tsc0QQ/sWpSV/7de5u0/LZEJSlJKnsucVEUBAEdequZem2tKIoJ f0/s4HPSrG6uOkgRKqJkaCelImEFa/NFfArRI8Y78k0z2/kcadxrHRJU51JoNOoDwY4c 200A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=no0+tHOSr5LOpQKZH/yuZugHtoH25vonluLdlgGJfdA=; b=S2myXw9zsFNYT9k5vqpJEVrhe9RCk0d4tlwAcHyWvCGpMofzYNHW2nR/dmysrFEpZ3 YHVZsJsU+qbcwMXcuPJo2tC7KqOuidkLZswWzYCwGyMmUKVBi0ETJi/wo8CVNh9OBkgr yypTbb0k/pAumehqzhWnGgc6M8NRNUIgkV1oyO378DOk8AN21w1/FBLcn+W+HaqZTTvf 1Xg7+m4Ey+csmI2+gYW8tNqiCDjGIHbOzE5n6ZT272V0SwLm9thQE9KtatBo7wFh+c7T uFI8OguHxrqv0W+sggDVZWCfwQlIFLlMRq4tG+q2KgyhzybEMzJ/0jvvmFZ0CoJMsT+P D2kg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a16si4920091ejb.54.2019.10.11.02.45.17; Fri, 11 Oct 2019 02:45:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727807AbfJKJny (ORCPT + 99 others); Fri, 11 Oct 2019 05:43:54 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:34614 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727167AbfJKJnx (ORCPT ); Fri, 11 Oct 2019 05:43:53 -0400 Received: from v22018046084765073.goodsrv.de ([185.183.158.195] helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iIrSS-0004HM-7S; Fri, 11 Oct 2019 09:43:36 +0000 Date: Fri, 11 Oct 2019 11:43:34 +0200 From: Christian Brauner To: Aleksa Sarai , Michael Ellerman Cc: mingo@redhat.com, peterz@infradead.org, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, keescook@chromium.org, linux@rasmusvillemoes.dk, viro@zeniv.linux.org.uk, torvalds@linux-foundation.org, libc-alpha@sourceware.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] usercopy: Avoid soft lockups in test_check_nonzero_user() Message-ID: <20191011094333.7hovhhacrvlf6uq6@wittgenstein> References: <20191010114007.o3bygjf4jlfk242e@yavin.dot.cyphar.com> <20191011022447.24249-1-mpe@ellerman.id.au> <20191011034810.xkmz3e4l5ezxvq57@yavin.dot.cyphar.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20191011034810.xkmz3e4l5ezxvq57@yavin.dot.cyphar.com> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 11, 2019 at 02:48:10PM +1100, Aleksa Sarai wrote: > On 2019-10-11, Michael Ellerman wrote: > > On a machine with a 64K PAGE_SIZE, the nested for loops in > > test_check_nonzero_user() can lead to soft lockups, eg: > > > > watchdog: BUG: soft lockup - CPU#4 stuck for 22s! [modprobe:611] > > Modules linked in: test_user_copy(+) vmx_crypto gf128mul crc32c_vpmsum virtio_balloon ip_tables x_tables autofs4 > > CPU: 4 PID: 611 Comm: modprobe Tainted: G L 5.4.0-rc1-gcc-8.2.0-00001-gf5a1a536fa14-dirty #1151 > > ... > > NIP __might_sleep+0x20/0xc0 > > LR __might_fault+0x40/0x60 > > Call Trace: > > check_zeroed_user+0x12c/0x200 > > test_user_copy_init+0x67c/0x1210 [test_user_copy] > > do_one_initcall+0x60/0x340 > > do_init_module+0x7c/0x2f0 > > load_module+0x2d94/0x30e0 > > __do_sys_finit_module+0xc8/0x150 > > system_call+0x5c/0x68 > > > > Even with a 4K PAGE_SIZE the test takes multiple seconds. Instead > > tweak it to only scan a 1024 byte region, but make it cross the > > page boundary. > > > > Fixes: f5a1a536fa14 ("lib: introduce copy_struct_from_user() helper") > > Suggested-by: Aleksa Sarai > > Signed-off-by: Michael Ellerman > > --- > > lib/test_user_copy.c | 23 ++++++++++++++++++++--- > > 1 file changed, 20 insertions(+), 3 deletions(-) > > > > How does this look? It runs in < 1s on my machine here. > > > > cheers > > > > 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). Michael, in case you resend, can you make my life a little easier and do it on top of https://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux.git/log/?h=copy_struct_from_user please. I have a fix from Aleksa sitting in there laready that _might_ cause a conflict otherwise. Christian