Received: by 10.223.185.116 with SMTP id b49csp1382444wrg; Wed, 21 Feb 2018 18:02:16 -0800 (PST) X-Google-Smtp-Source: AH8x225wGTYfkK1bccdmivSGYGZgYfGTmgfyoFUNzh4zuww5TMamKBIpRHuuHEWfg0F8h/sl7sh4 X-Received: by 10.98.3.131 with SMTP id 125mr5235656pfd.65.1519264936710; Wed, 21 Feb 2018 18:02:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519264936; cv=none; d=google.com; s=arc-20160816; b=lBYR+ttxgU9t9/r9SkPWQoe+K//xDyVSzx3mZi6CVZCbYIpcy96SfTsQz7RajugmbO aenH9zrWKqnByX8CS5vsqOQFu5dQv9nXJg3n3D1BbhvG+ZkQP2V21t//h3p9B2J38Odh 4hA9o20GqrFlFuH39NQSNIGXLqVwoyWp5mvgsn/QbSfwXPcbYBokodtHsoIU8HVMzssQ rRHxCCgSBu8LWrf+KzkJseMvK/CrL9P1eVrNv+fg5sArjJOImGvRVFKFg4Qe2zEHwTZk HNzGwARSL5wA86bIiXYUhazOb0zZWV/O9fjN+zUqtSgN5SMvg9VtY1x1msBDTG9AIULg YGNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=7xKgqSqcRIsQRJ4PDARkJQ+Z3wnVKS/JxlX+sw99kO0=; b=Jk4HdrSRBDA0A0sgmZyOS0A8D0KxZ2/MnljVTHcWtfM0zsnl1YhkekVFmNC5xvirpY oG2OrhwKJ3ZZo5OW3z+vZBTwnzupz4obpFEFskhVKfBbfZ0wPi1ZyNdP8GmRLGt6Dz7u 59p9v1Y4Z2FXkkabW1FEvRnlJWib2Msx4H4lrxmCgTlWh97GmfVg9K2ltwPP5/zWF8iM Y8sZ6FP+WiCKZDx6vUTBq+ImWucUWyCOq0fKo7pEepDEmdRcKNEhLnr5kcqY0yUUIvz2 uZcEF6YP+4o9flZhTuR56AgGa/k8O6/qjj0YG6IW43/8nAcnks3aO0sHXV6SyjomxiQc E5EQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=WpMWJwIz; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 7-v6si2976702pll.775.2018.02.21.18.02.01; Wed, 21 Feb 2018 18:02:16 -0800 (PST) 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; dkim=fail header.i=@gmail.com header.s=20161025 header.b=WpMWJwIz; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752201AbeBVCAh (ORCPT + 99 others); Wed, 21 Feb 2018 21:00:37 -0500 Received: from mail-qk0-f193.google.com ([209.85.220.193]:34583 "EHLO mail-qk0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751998AbeBVB4l (ORCPT ); Wed, 21 Feb 2018 20:56:41 -0500 Received: by mail-qk0-f193.google.com with SMTP id l206so4650858qke.1; Wed, 21 Feb 2018 17:56:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=7xKgqSqcRIsQRJ4PDARkJQ+Z3wnVKS/JxlX+sw99kO0=; b=WpMWJwIzwGyP3yW0F/AycUqpZmnueeBG5PqevJT0YNvLgQQqx6Sm8viK5cdgG/Cta8 1g2ygveOmpCBxKxkgLVMtpzweNFcsNYxgitAGFLqNL0wv5afY8pwA93DdO3JBno7Vg8s sJHCWUAyJ51QqdxIZrvKysj7sITwvUCfZqaqS4KU59dxFwnf+oPVwpNhuF6FYnftoBCl Lwlq26HR3JrwsDZadkaD1DW0oF0fvHNbgV28YX8nT+9jZoPXXMNvWSbaKMAGAl7q31c/ +aiLEQtiUph/OPWqIw4cbpyhC4ZMNLvvW5R3YU9yPQ9+QOu0WcWvOqiSvaquaZkrkZkj a6Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=7xKgqSqcRIsQRJ4PDARkJQ+Z3wnVKS/JxlX+sw99kO0=; b=coPvkg/Lelhp+jtpc5AzxDf3LzBIChgzcP8jekdkYUUWJD/hJpZLdD24qG7G+xDYi7 hBxQ/NAvkhHos6UmaBjvJoaBL/QULRY2vXuvk+EdB6cyhdr66clCB9CQikrAZ80oJw+T GQ5Lb4OzWH8QxRZEc0OaN6VaqrjZyek20zjwpQ4WCCxGZAUOAqw4JHWEkKnYxCtvvy52 M58LR8Lw72dCtE7TOfV5TPRZmYd2+lWDWfBnrtSrZAlHF2BEN6RqIppbAoUzid1bGC+h virGnD3YYS5FTHmWPNeHi6EjFMx7CDRapI+DoxljrYiYC5xlNuulzM+keA+BAEyfDJPH RcmA== X-Gm-Message-State: APf1xPAbySa73G62vhBtGgbZT0fSiZ1MTc26fYNlh46Qf8AA5O3tGu2x W5cIzlc8WHCs15S6jXJNE5cpWzR1 X-Received: by 10.55.204.71 with SMTP id r68mr8486482qki.356.1519264600325; Wed, 21 Feb 2018 17:56:40 -0800 (PST) Received: from localhost.localdomain (50-39-100-161.bvtn.or.frontiernet.net. [50.39.100.161]) by smtp.gmail.com with ESMTPSA id n29sm14182630qtf.18.2018.02.21.17.56.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Feb 2018 17:56:39 -0800 (PST) From: Ram Pai To: shuahkh@osg.samsung.com, linux-kselftest@vger.kernel.org Cc: mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, x86@kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, akpm@linux-foundation.org, dave.hansen@intel.com, benh@kernel.crashing.org, paulus@samba.org, khandual@linux.vnet.ibm.com, aneesh.kumar@linux.vnet.ibm.com, bsingharora@gmail.com, hbabu@us.ibm.com, mhocko@kernel.org, bauerman@linux.vnet.ibm.com, ebiederm@xmission.com, linuxram@us.ibm.com, arnd@arndb.de Subject: [PATCH v12 09/22] selftests/vm: fix alloc_random_pkey() to make it really random Date: Wed, 21 Feb 2018 17:55:28 -0800 Message-Id: <1519264541-7621-10-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1519264541-7621-1-git-send-email-linuxram@us.ibm.com> References: <1519264541-7621-1-git-send-email-linuxram@us.ibm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org alloc_random_pkey() was allocating the same pkey every time. Not all pkeys were geting tested. fixed it. cc: Dave Hansen cc: Florian Weimer Signed-off-by: Ram Pai --- tools/testing/selftests/vm/protection_keys.c | 10 +++++++--- 1 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/vm/protection_keys.c b/tools/testing/selftests/vm/protection_keys.c index aaf9f09..2e4b636 100644 --- a/tools/testing/selftests/vm/protection_keys.c +++ b/tools/testing/selftests/vm/protection_keys.c @@ -24,6 +24,7 @@ #define _GNU_SOURCE #include #include +#include #include #include #include @@ -602,13 +603,15 @@ int alloc_random_pkey(void) int alloced_pkeys[NR_PKEYS]; 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; - max_nr_pkey_allocs = 1; for (i = 0; i < max_nr_pkey_allocs; i++) { int new_pkey = alloc_pkey(); + if (new_pkey < 0) break; alloced_pkeys[nr_alloced++] = new_pkey; @@ -624,13 +627,14 @@ int alloc_random_pkey(void) /* go through the allocated ones that we did not want and free them */ for (i = 0; i < nr_alloced; i++) { int free_ret; + if (!alloced_pkeys[i]) continue; free_ret = sys_pkey_free(alloced_pkeys[i]); pkey_assert(!free_ret); } - dprintf1("%s()::%d, ret: %d pkey_reg: 0x%x shadow: 0x%x\n", __func__, - __LINE__, ret, __rdpkey_reg(), shadow_pkey_reg); + dprintf1("%s()::%d, ret: %d pkey_reg: 0x%x shadow: 0x%016lx\n", + __func__, __LINE__, ret, __rdpkey_reg(), shadow_pkey_reg); return ret; } -- 1.7.1