From patchwork Tue Jul 17 13:49:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 10529471 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 146B8600F4 for ; Tue, 17 Jul 2018 13:50:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF45528D8A for ; Tue, 17 Jul 2018 13:50:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E3A4F29203; Tue, 17 Jul 2018 13:50:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8DD5A28D8A for ; Tue, 17 Jul 2018 13:50:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731696AbeGQOXK (ORCPT ); Tue, 17 Jul 2018 10:23:10 -0400 Received: from mail-qt0-f196.google.com ([209.85.216.196]:42529 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731691AbeGQOXK (ORCPT ); Tue, 17 Jul 2018 10:23:10 -0400 Received: by mail-qt0-f196.google.com with SMTP id z8-v6so881768qto.9; Tue, 17 Jul 2018 06:50:24 -0700 (PDT) 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=FeGpiu1Y+ZJGOtPccstDsWizLEy9IUvJYYDUD6ACH84=; b=maTew+RbEN8JQSkcgdiDxI2AFRG/BgE/VUs8PSVHGmuSa/vM9XSyVw4cN2h311AViS 7OGAlxWxxpLs7tqoIbGGUuNDgAp6LCtz4FgkdXNKfRKd+R+R6DQlqivwZtzDrkCQXj5z G28TP9tGF4Lx/NzWKJQ/eHzdq/GRawg2Z+w3e3bR6HSD7ktCO3zNGWWmQbxaPV8NNIab ZPbYL7qknGE8UjYf/TUeVTEpTVDHJybAA+wsxSpWYgI54Sy4/jDj2h3mSiFwSmgvcXsM 4vSN0uluDGCPMNa/U9JND/m71eIN3KrOIWPet+DyVj1bauQAhTgnPbxeoL/g1H0cPyOM EkgQ== 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=FeGpiu1Y+ZJGOtPccstDsWizLEy9IUvJYYDUD6ACH84=; b=Xm6Ipp2k8u3HTHHX+RnU+4QxRafUlv9ZDRupuwzF+wF7YAHx/IcsN6/0LkNErpTlWQ xV4E4V0IHZFtUO623ho5xxOYqedSyWFgsx3FsTl7zIyy9RNJ15tao2bX6yAYQpDq0A2c 5SlibsXDRb/ZpOr9kBxVbtCHy5t/v96tYPUhStzVLkWARDeUBCksSfhsbuEfFMF5hxrG hexgpMAh6EWIR9fv9mieh9zls7i957ICS9mpSsmUc8kG1Xr/GsWCtnD5F3s+ztjKIoDH ADm6YAEd0OwG+iEZMH2mekYcjPiCj6Un4/olpQCYktpgyqd40yW3JHkVQdn+iFeKlFL2 PTJw== X-Gm-Message-State: AOUpUlG2WXyteRbpooBQgsjR8g74T7s30IIxZE1zm8FS9ha4jFOXElhS UBsXNYhFwnVh3+ghCmKNTWU= X-Google-Smtp-Source: AAOMgpeNYbwcdbhYHHDpmxSXuQQeApPEOBr2fx625UD8uc5gXELWR53vZ8iTU70RsAmu3GOQcylYuw== X-Received: by 2002:ac8:2c72:: with SMTP id e47-v6mr1639637qta.60.1531835424044; Tue, 17 Jul 2018 06:50:24 -0700 (PDT) Received: from localhost.localdomain (50-39-100-161.bvtn.or.frontiernet.net. [50.39.100.161]) by smtp.gmail.com with ESMTPSA id s83-v6sm640937qki.20.2018.07.17.06.50.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jul 2018 06:50:23 -0700 (PDT) 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, mingo@redhat.com, dave.hansen@intel.com, mhocko@kernel.org, bauerman@linux.vnet.ibm.com, linuxram@us.ibm.com, fweimer@redhat.com, msuchanek@suse.de, aneesh.kumar@linux.vnet.ibm.com Subject: [PATCH v14 10/22] selftests/vm: fix alloc_random_pkey() to make it really random Date: Tue, 17 Jul 2018 06:49:13 -0700 Message-Id: <1531835365-32387-11-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1531835365-32387-1-git-send-email-linuxram@us.ibm.com> References: <1531835365-32387-1-git-send-email-linuxram@us.ibm.com> Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Acked-by: Dave Hansen --- tools/testing/selftests/vm/protection_keys.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) diff --git a/tools/testing/selftests/vm/protection_keys.c b/tools/testing/selftests/vm/protection_keys.c index 8fa4f74..2565b4c 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 @@ -573,13 +574,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; @@ -595,6 +598,7 @@ 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]);