From patchwork Thu Jun 14 00:45:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 10463059 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 3135A603EE for ; Thu, 14 Jun 2018 00:47:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2386B28988 for ; Thu, 14 Jun 2018 00:47:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 180EE28BA8; Thu, 14 Jun 2018 00:47:11 +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 B2E7F28B9D for ; Thu, 14 Jun 2018 00:47:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936035AbeFNArK (ORCPT ); Wed, 13 Jun 2018 20:47:10 -0400 Received: from mail-qt0-f195.google.com ([209.85.216.195]:43727 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936032AbeFNArH (ORCPT ); Wed, 13 Jun 2018 20:47:07 -0400 Received: by mail-qt0-f195.google.com with SMTP id y89-v6so4257865qtd.10; Wed, 13 Jun 2018 17:47:07 -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=skdFtvuEd4XfN7iEwnmc0zziYX0losbSh01biLb02Y4=; b=pReF+5q+V73VtKzG7qkyKTLTe+2od5e1jQthl2mX/R/5dQtxtcExDRJCbJQXqIhtF3 cat817BegCGSKDIX/1MhNcwc59m257lA/4kWF6h4ZN47Nrl20pKHpSwiniIgylPgW9I4 JqCl8KSNK5i4czGihbp7XA11VqDoEBAT1ENS+QushZS6iZ+nb2Ciys5wqfhtzUAIyIil L6Du4ZP0RySVLZzrbf31EnXZh5ZdVREc9g+SKIOSfDSGMW2xGK0/+trBsZouv0McQJs/ MjQVbeTy3gCv8Y495XJmA+a8sk/imyqIT8V0Y+/jE+qbwqb/uZq5RhycMi6VUuAmuhAI QKdw== 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=skdFtvuEd4XfN7iEwnmc0zziYX0losbSh01biLb02Y4=; b=dSmvHR5rRKVxXPHlU3yA6TJN7RipVvXcUWnxC8IGcydNL2a/p9tPjkLC1CfVSl3Q0S wcvu9Vaxt1GoITYFv9F+u/IEbRDFc6VYg2HHllMWV6k6oalt26Nvz1PhCiLQD668QTm7 SouvWmiEo0wTtEy9kr/2oioYQV0cKgjFU56ygyYLC8frJ/SNDaLXr0GhHMm/pVVn5gjr FLCynPJ1ICl4s2ZfVGNpP9f5foSHKBAm3lksS04MSoDySz+HeKsJpUPB9FteMb3affu7 +4ixgRl9kSlPiDLv5NaM3mwvgRRFDqA3K7OyDGE07oH+F0iAFa9T6T4E5Qc00grtFZin mijw== X-Gm-Message-State: APt69E2bFD742cxu0ZKHzC1VfP/jpoAdLyi3/pfc/KsjokT0VVpLaBE/ xiADNw2u6SlxRN88/MlPhEo= X-Google-Smtp-Source: ADUXVKI+aeCSU0dGjGVNdfn81SmeTG0/qbCewlhDYT3WgP4fJCsPnbJ4IFAy+whlAubECXR/PQwqyg== X-Received: by 2002:ac8:43c7:: with SMTP id w7-v6mr355054qtn.371.1528937226665; Wed, 13 Jun 2018 17:47:06 -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 u31-v6sm3225898qtc.28.2018.06.13.17.47.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Jun 2018 17:47:06 -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 v13 11/24] selftests/vm: fix alloc_random_pkey() to make it really random Date: Wed, 13 Jun 2018 17:45:02 -0700 Message-Id: <1528937115-10132-12-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1528937115-10132-1-git-send-email-linuxram@us.ibm.com> References: <1528937115-10132-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 --- 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 42a91c7..c5f9776 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 @@ -576,13 +577,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; @@ -598,6 +601,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]);