Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp719327pxj; Fri, 11 Jun 2021 09:44:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqKIZH0klFzORkLXgCyiXAsO17vmjrZwYJcGLBBu35Ua8DcOkNDJmvkGtDxrfRV729C6bL X-Received: by 2002:a05:6402:170e:: with SMTP id y14mr4824832edu.367.1623429859206; Fri, 11 Jun 2021 09:44:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623429859; cv=none; d=google.com; s=arc-20160816; b=MoW1dn61xJ9Gxw4Zl50PZrHA3QO8FNlYWHc0805riMy9vTCfl/PAyEUIJ0tpKovF8f SMpbPFZMa8PiJ2/BxeJtzuJ9N/MW+E1ifkJnzykz5HSplxhsjuInR1/C2cpvwN4Fw41F Vl7xHWAis25V9qkq/vENyQhY4JDFeJK2wz911dehT7tsTg5j2OhhzKySev2YkGi8nv/G TT8bhIprHoIWPXTg18jr/OtGsKkp4PXhJDWkFB+oHvpKqXRY2RXpQzjlUmhfrNvpbtXu +PnvnEguVEglSF7lKlDkaWIYPe1kbpmRtuhgjfVXS6o5eAe5Kz0g6I+PiLOKFK0eWsgd Ym4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:in-reply-to:references:date:from:cc :to:subject:ironport-sdr:ironport-sdr; bh=FKbyAn3mQR0x1rPgut2RfBTbxXsv6knYBx+4DRZmeGU=; b=C+1XJrjVSO1h1Z5t7wrNB2uUps5B0xwvUPKpVmIwCZVkyjN2eywH1QJrwjgEe7yZpB rgmgcGIo68wWeGBBxsYTJ7yaaIYKCWnmTxm8bMtshOk3lKuE3oaZMY2IZ4Azg6pIsGIE jN5tLpWU9KS1xkDE1+Ib0xJw61LnIZe02rMnThaG8Yx5ktcgAiq3zPSvGs1d2D/kN+gE HtQdVTqBjaDHs2m0Mc/oAbMCzGnLy8aYVsc/jf7bkGzovlc+VXRzjTkr/TyR3BhiiouH QKQla/6xGk+H8qMph5PCAc/166WfmR8k+LlZdVE7q/KQmiKSTzoV08ujcb2tROnqjvOH zKPA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j6si5138991edq.137.2021.06.11.09.43.52; Fri, 11 Jun 2021 09:44:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230488AbhFKQn4 (ORCPT + 99 others); Fri, 11 Jun 2021 12:43:56 -0400 Received: from mga02.intel.com ([134.134.136.20]:45506 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230469AbhFKQn4 (ORCPT ); Fri, 11 Jun 2021 12:43:56 -0400 IronPort-SDR: 9Ihj0pBvveyWhdD0hJqBhiL+M2lBDIaSdhCIvzjAcO1QozvVgXdIwEeeiDkVe4z1BxejhoR9ZZ gMITm2IW33LQ== X-IronPort-AV: E=McAfee;i="6200,9189,10012"; a="192670773" X-IronPort-AV: E=Sophos;i="5.83,265,1616482800"; d="scan'208";a="192670773" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jun 2021 09:41:56 -0700 IronPort-SDR: lUbd/cezG/WIoeYhLWfpKT7TAWTnR53Ta8JFebAxza+auFaTWefdJRvLcFLUEX09wp+JBQJF5w nHDtT76H4G8g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,265,1616482800"; d="scan'208";a="420122331" Received: from viggo.jf.intel.com (HELO localhost.localdomain) ([10.54.77.144]) by orsmga002.jf.intel.com with ESMTP; 11 Jun 2021 09:41:56 -0700 Subject: [PATCH 1/4] selftests/vm/pkeys: Fix alloc_random_pkey() to make it really, really random To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Dave Hansen , tglx@linutronix.de, linuxram@us.ibm.com, sandipan@linux.ibm.com, akpm@linux-foundation.org, fweimer@redhat.com, desnesn@linux.vnet.ibm.com, mingo@kernel.org, bauerman@linux.ibm.com, aneesh.kumar@linux.ibm.com, mpe@ellerman.id.au, mhocko@kernel.org, msuchanek@suse.de, shuah@kernel.org, x86@kernel.org From: Dave Hansen Date: Fri, 11 Jun 2021 09:41:55 -0700 References: <20210611164153.91B76FB8@viggo.jf.intel.com> In-Reply-To: <20210611164153.91B76FB8@viggo.jf.intel.com> Message-Id: <20210611164155.192D00FF@viggo.jf.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dave Hansen The "random" pkey allocation code currently does the good old: srand((unsigned int)time(NULL)); *But*, it unfortunately does this on every random pkey allocation. There may be thousands of these a second. time() has a one second resolution. So, each time alloc_random_pkey() is called, the PRNG is *RESET* to time(). This is nasty. Normally, if you do: srand(); foo = rand(); bar = rand(); You'll be quite guaranteed that 'foo' and 'bar' are different. But, if you do: srand(1); foo = rand(); srand(1); bar = rand(); You are quite guaranteed that 'foo' and 'bar' are the *SAME*. The recent "fix" effectively forced the test case to use the same "random" pkey for the whole test, unless the test run crossed a second boundary. Only run srand() once at program startup. This explains some very odd and persistent test failures I've been seeing. Fixes: 6e373263ce07 ("selftests/vm/pkeys: fix alloc_random_pkey() to make it really random") Signed-off-by: Dave Hansen Signed-off-by: Thomas Gleixner Cc: Ram Pai Cc: Sandipan Das Cc: Andrew Morton Cc: Florian Weimer Cc: "Desnes A. Nunes do Rosario" Cc: Ingo Molnar Cc: Thiago Jung Bauermann Cc: "Aneesh Kumar K.V" Cc: Michael Ellerman Cc: Michal Hocko Cc: Michal Suchanek Cc: Shuah Khan Cc: x86@kernel.org --- b/tools/testing/selftests/vm/protection_keys.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff -puN tools/testing/selftests/vm/protection_keys.c~selftests_vm_pkeys_Fix_alloc_random_pkey_to_make_it_really_really_random-1 tools/testing/selftests/vm/protection_keys.c --- a/tools/testing/selftests/vm/protection_keys.c~selftests_vm_pkeys_Fix_alloc_random_pkey_to_make_it_really_really_random-1 2021-06-11 09:41:31.385468066 -0700 +++ b/tools/testing/selftests/vm/protection_keys.c 2021-06-11 09:41:31.389468066 -0700 @@ -561,7 +561,6 @@ int alloc_random_pkey(void) int nr_alloced = 0; int random_index; memset(alloced_pkeys, 0, sizeof(alloced_pkeys)); - srand((unsigned int)time(NULL)); /* allocate every possible key and make a note of which ones we got */ max_nr_pkey_allocs = NR_PKEYS; @@ -1552,6 +1551,8 @@ int main(void) int nr_iterations = 22; int pkeys_supported = is_pkeys_supported(); + srand((unsigned int)time(NULL)); + setup_handlers(); printf("has pkeys: %d\n", pkeys_supported); _