Received: by 10.223.176.46 with SMTP id f43csp3259171wra; Mon, 22 Jan 2018 10:58:48 -0800 (PST) X-Google-Smtp-Source: AH8x225iU3kcPsGgzQueRa0H7rhneESQtjMix0Wbs6J1znrYRSR3ZbQJVmuT0+sjPhFRXjMtCpnT X-Received: by 10.36.198.197 with SMTP id j188mr9536810itg.76.1516647528032; Mon, 22 Jan 2018 10:58:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516647527; cv=none; d=google.com; s=arc-20160816; b=N9gTWjFhiawq7US9tm1JVcjZynqEDq0cKnsvYfIht+Hm+T6f7h2Ff+/+Q9zqy0de4h Ciq7i92sMSS9lCgm2bC5HEHAMbY8Uz6hnYYUt+Z0kJZhQGRztNL04SnLypItRGQb95zn /pwGQ6mzEL+XFkufB8IEq4+FOnbGZkilWPZN0v8AfplSf18V4yjVVfBRjQ0ddM6GFY80 cyFqq3emAL31LohBIEUK1fSTsgUa41UhxU1tBc5yvqfnAAV1zOUSZgdwSnxQJz0y58fP my9E6JF6vDOyCi9d6qipJPkHiA0wm8rCiq3I7osKLhbq5EjsEMKXq9IwVuOZbw6tK2NX 5nRg== 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=fWHL5QmkDMJrXPtsZoafS43KyToG0aJDduxEPvi2xdA=; b=vNgaKqBmMqzT4l1OLQIs/LzKD/5Psuyaq8yAFZxQ3BRY4WVWcU5ap+l9Vglvaq+AGa ipHIsZsDYMrmtqoYqIZWznVOkWLYTWiTxh5uwDNPpnaU7yUm1OVH85eio9yEOlEyE4Za Vj8p8Xk8pbpmt55hpSu2D5hVAssQI5UTcHi9cEuGvsdfsKgtXXOxTxdAcmeCCzyLbIx2 dn2bgYs2iN47fgXmTwKFFwGg9dDCKvh2N2q1HRgwOce0az87MTSee62MIvkoEzBvq+5K kNBElfGUVq8KHQCcwx8iYpcE+A7qD2ef7tgIoXlD2If9+7qIgGlr1VnFTa75HcCErUOL jadw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=ry85BsV+; 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 p42si13200331ioi.340.2018.01.22.10.58.34; Mon, 22 Jan 2018 10:58:47 -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=ry85BsV+; 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 S1751771AbeAVS5s (ORCPT + 99 others); Mon, 22 Jan 2018 13:57:48 -0500 Received: from mail-qt0-f196.google.com ([209.85.216.196]:35972 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751156AbeAVSxO (ORCPT ); Mon, 22 Jan 2018 13:53:14 -0500 Received: by mail-qt0-f196.google.com with SMTP id z11so23462210qtm.3; Mon, 22 Jan 2018 10:53:13 -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=fWHL5QmkDMJrXPtsZoafS43KyToG0aJDduxEPvi2xdA=; b=ry85BsV+jwj1ZexmmsmKtlhu5DzRNR0Wta1Wdein2lMFkzFkZjJO78utSGTl3MKlce 8W7JmkaA9ehGYTYbL35PCqt7KPAZey8sSia3PLJFRxuUmsew9ua9Mkh3CqjVt+pzPnSV SgutuDGmvgX40oNFsIsRdCurERAGsUbaxHP9qSUqOoKVbAdK87CdZTuPaq/dwR3M7PJI jFM/IFOW7BBkdKShg0d1ebYQnrWnGxtOrODmdo0yHnF1kInOzHTkUxhHc47vtztn8DKC qVOBUcmxyo3+KU+Gjudb6zkEMzYo80TAE/IAIyOxBsQL/ld+7Mo8OnUM85ufmKFGOuXY V+tQ== 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=fWHL5QmkDMJrXPtsZoafS43KyToG0aJDduxEPvi2xdA=; b=Bi56+vAz+rFNd/dZW318y/xULwA/UxGc/DsEzABeJfyh7AqDLPM6vbfQJuahQGIGGH ex9vHKuSPt+Tq+SGscZFndQWsmCGEdMgwJX21YlorNhhT+p84B9uKMCtDB1Dnhp29nbJ vVFcPENEJemY02dGc/VGjcJgkDFaoX+8q1F/SW+cDqeZvjRJoKxEFgG/oJLxnOKrTp5g X811M/fkYgp3O/ay2WzmtwVN4BU2FdpvebyQ7hH9aMLJ9GAEvMR4w8MSVtrKCpzoonWX KRbEntvwZvUjWpUcrTbv7S+MJjk/OKyI/RG4WBuTtdLB3tfHzrTNVs7Rwx9fr3loeLPT sSJA== X-Gm-Message-State: AKwxytesIkgEZL4oxzz6GniZORZnegCwGxU1e5dtImJCKTHpkfPjhorb UIx7HyZSZOrifwvzJq6aiPo= X-Received: by 10.55.123.69 with SMTP id w66mr11278864qkc.326.1516647193464; Mon, 22 Jan 2018 10:53:13 -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 o20sm10790061qkl.14.2018.01.22.10.53.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Jan 2018 10:53:13 -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 v10 09/24] selftests/vm: fix alloc_random_pkey() to make it really random Date: Mon, 22 Jan 2018 10:52:02 -0800 Message-Id: <1516647137-11174-10-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1516647137-11174-1-git-send-email-linuxram@us.ibm.com> References: <1516647137-11174-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. 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