From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752014AbdBXAKb (ORCPT ); Thu, 23 Feb 2017 19:10:31 -0500 Received: from mail-wr0-f195.google.com ([209.85.128.195]:34715 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751936AbdBXAKY (ORCPT ); Thu, 23 Feb 2017 19:10:24 -0500 Date: Fri, 24 Feb 2017 03:10:09 +0300 From: "Kirill A. Shutemov" To: Dave Hansen Cc: linux-kernel@vger.kernel.org, x86@kernel.org, shuah@kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH 2/2] selftests, x86, pkeys: test with random, unallocated protection keys Message-ID: <20170224001009.GB26920@node.shutemov.name> References: <20170223222603.A022ED65@viggo.jf.intel.com> <20170223222604.D3AE8473@viggo.jf.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170223222604.D3AE8473@viggo.jf.intel.com> User-Agent: Mutt/1.5.23.1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 23, 2017 at 02:26:04PM -0800, Dave Hansen wrote: > > > Shuah, I assume you'll take this patch in through the selftests tree. > > -- > From: Dave Hansen > > The kernel pkeys code had a minor bug where it did some large shifts > to an integer which is undefined behavior in C. It didn't cause any > real harm, but it is screwy behavior that the kernel should have > rejected. > > Add a test case for this. > > Signed-off-by: Dave Hansen > ec: Kirill A. Shutemov > Cc: Shuah Khan > Cc: linux-kselftest@vger.kernel.org > Cc: linux-kernel@vger.kernel.org > Cc: x86@kernel.org > --- > > b/tools/testing/selftests/x86/protection_keys.c | 25 ++++++++++++++++++++++++ > 1 file changed, 25 insertions(+) > > diff -puN tools/testing/selftests/x86/protection_keys.c~pkeys-better-selftests-of-random-pkey tools/testing/selftests/x86/protection_keys.c > --- a/tools/testing/selftests/x86/protection_keys.c~pkeys-better-selftests-of-random-pkey 2017-02-23 14:21:05.168391529 -0800 > +++ b/tools/testing/selftests/x86/protection_keys.c 2017-02-23 14:23:03.244671815 -0800 > @@ -1123,6 +1123,30 @@ void test_pkey_syscalls_on_non_allocated > } > > /* Assumes that all pkeys other than 'pkey' are unallocated */ > +void test_pkey_syscalls_on_non_allocated_random_pkey(int *ptr, u16 pkey) > +{ > + int err; > + int nr_tests = 0; > + > + while (nr_tests < 1000) { > + int test_pkey = rand(); rand(3) doesn't generate negative numbers. Would be good to cover this case too. int test_pkey = rand() - RAND_MAX/2; ? Otherwise looks good to me. -- Kirill A. Shutemov