From patchwork Mon Nov 6 08:57:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 834615 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yVqCb2zR7z9s81 for ; Mon, 6 Nov 2017 21:52:59 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Lwnv5Mxc"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3yVqCb1rJ5zDrJx for ; Mon, 6 Nov 2017 21:52:59 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Lwnv5Mxc"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:400d:c09::243; helo=mail-qk0-x243.google.com; envelope-from=ram.n.pai@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Lwnv5Mxc"; dkim-atps=neutral Received: from mail-qk0-x243.google.com (mail-qk0-x243.google.com [IPv6:2607:f8b0:400d:c09::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3yVmjR6d6kzDq78 for ; Mon, 6 Nov 2017 20:00:11 +1100 (AEDT) Received: by mail-qk0-x243.google.com with SMTP id x195so4397575qkb.12 for ; Mon, 06 Nov 2017 01:00:11 -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=ykZ663WQ1xhd3Yc6fBndDmWdsEbDVweOM64ri1Zv2uY=; b=Lwnv5MxcQlaiz+Wv+KJ40f2nSef5q7sbKNtrUL7E+4YKWf0HAGSVM5O10xo3O7rkLE lgOPQc4mksEA0GiX2EzivuTFJvk1paWPVe07+fw+gkO/BY8uYYvb0u144MFhNnYilA1M 7kmhU8oHSlxCcj+sFR+NWuVn4K8uzELsx7SnN7NnoSERiklazigzHcUrumuOmtasyiJJ Or1Wa3S9lUgV2ZbVWKWMC/cKPiOL0UWdeTENG++QFcyyp/D69e/fPbs66P58GJomjiwg e9959za0IEZ6/e71at6MyR5uPnFH/Vhq9IoZf6b1uCAskOVz+/XOongMmfjpUiI4eT35 3c9g== 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=ykZ663WQ1xhd3Yc6fBndDmWdsEbDVweOM64ri1Zv2uY=; b=KsWYl6KW9NktYo6JHMTE11/AQ2zsgVVdtB9lFAB/aUMEQwD4WVNRbEYM8rygwVLf3m xsRupvk1igxeGlIroHl7BZ00315qoLSf3Yfl2ldN+1nonnEpUJFk+9ra98Av4EQKyGoy LWhOd46XA6TXDzNnlNs0T43EtlRTwP95LSWweXuGKu0/dWiMHTR04oZgJ8LY1fpaCqOa 9AYgKFfaLZyvqqZTilQrAOfc2RpLxjW859eVHoOVfkKGzXSQ/grKEi/FX4DnZbWusVxh H9/IqrcW9XuvYpDd3oYVPsYf+ec3F5ZMRT4CgQwde+MilG74Zy5kNNfXyTmSNcSc/Sa6 BzBw== X-Gm-Message-State: AJaThX60wQifSIhgHnc3JRV/85NhOKLSz9wTz0i+gnUGrJQJmPVcqScQ 2TkOU90P6g15k1LtypSgLPQ= X-Google-Smtp-Source: ABhQp+RgzXhBPAM0X+M4jv/88RbxudqAgSxZekjAX2JeZ1/r8ngWYTmcyS2/4eJfbpHWYd4zv0Bv+w== X-Received: by 10.55.42.139 with SMTP id q11mr4721378qkq.285.1509958810064; Mon, 06 Nov 2017 01:00:10 -0800 (PST) Received: from localhost.localdomain (50-39-103-96.bvtn.or.frontiernet.net. [50.39.103.96]) by smtp.gmail.com with ESMTPSA id r26sm8001094qki.42.2017.11.06.01.00.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Nov 2017 01:00:09 -0800 (PST) From: Ram Pai To: mpe@ellerman.id.au, mingo@redhat.com, akpm@linux-foundation.org, corbet@lwn.net, arnd@arndb.de Subject: [PATCH v9 40/51] selftest/vm: fix alloc_random_pkey() to make it really random Date: Mon, 6 Nov 2017 00:57:32 -0800 Message-Id: <1509958663-18737-41-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1509958663-18737-1-git-send-email-linuxram@us.ibm.com> References: <1509958663-18737-1-git-send-email-linuxram@us.ibm.com> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, ebiederm@xmission.com, linux-doc@vger.kernel.org, x86@kernel.org, dave.hansen@intel.com, linux-kernel@vger.kernel.org, linuxram@us.ibm.com, mhocko@kernel.org, linux-mm@kvack.org, paulus@samba.org, aneesh.kumar@linux.vnet.ibm.com, linux-kselftest@vger.kernel.org, bauerman@linux.vnet.ibm.com, linuxppc-dev@lists.ozlabs.org, khandual@linux.vnet.ibm.com Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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 2823d4d..1a14027 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; }