From patchwork Tue Jun 23 19:57:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 223310 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A28AC433E0 for ; Tue, 23 Jun 2020 21:00:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 18A2920663 for ; Tue, 23 Jun 2020 21:00:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592946031; bh=WUZmUys8GXwbBRoi2bD5fzkBN59mbeajwnIIzjFuBIQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=xHro86W7KpAQfSSKCuUQb5tKmygfX8TjB9g2tgtQ3pc4PBQ8BwoLiOwI3YN437BT4 JYyI7ECXuqbRq+20P8SlmVaXmlqM/HgBuqj7pxTcQyd1JTzgmrrTgBTsxjbwKD98ZV 1Fsl8gB5YL5QQ8AcVvB9aj5CJGh5aUkqMW093whY= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403816AbgFWVAW (ORCPT ); Tue, 23 Jun 2020 17:00:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:36296 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392207AbgFWUkT (ORCPT ); Tue, 23 Jun 2020 16:40:19 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B29E420675; Tue, 23 Jun 2020 20:40:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592944819; bh=WUZmUys8GXwbBRoi2bD5fzkBN59mbeajwnIIzjFuBIQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U3pqO4zHl1fYbA4Zr/Gvncs4bHdBkPl6tfrCHqL0MYC20rs3uIDeEmxlyR7zMqDu6 ffAkXv/cbeYdLLQYbO0BhGTLqxtbybLNqZpFznXSJyipaeLkoPPphFZcAlb0EmhL9J XOpGpHnEQXszE5Cezm1dQM5qvqCbM9DNeYJpyAjE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ram Pai , Sandipan Das , Andrew Morton , Dave Hansen , Florian Weimer , "Desnes A. Nunes do Rosario" , Ingo Molnar , Thiago Jung Bauermann , "Aneesh Kumar K.V" , Michael Ellerman , Michal Hocko , Michal Suchanek , Shuah Khan , Linus Torvalds , Sasha Levin Subject: [PATCH 4.19 138/206] selftests/vm/pkeys: fix alloc_random_pkey() to make it really random Date: Tue, 23 Jun 2020 21:57:46 +0200 Message-Id: <20200623195323.775979164@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200623195316.864547658@linuxfoundation.org> References: <20200623195316.864547658@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Ram Pai [ Upstream commit 6e373263ce07eeaa6410843179535fbdf561fc31 ] alloc_random_pkey() was allocating the same pkey every time. Not all pkeys were geting tested. This fixes it. Signed-off-by: Ram Pai Signed-off-by: Sandipan Das Signed-off-by: Andrew Morton Acked-by: Dave Hansen Cc: Dave Hansen Cc: Florian Weimer Cc: "Desnes A. Nunes do Rosario" Cc: Ingo Molnar Cc: Thiago Jung Bauermann Cc: "Aneesh Kumar K.V" Cc: Michael Ellerman Cc: Michal Hocko Cc: Michal Suchanek Cc: Shuah Khan Link: http://lkml.kernel.org/r/0162f55816d4e783a0d6e49e554d0ab9a3c9a23b.1585646528.git.sandipan@linux.ibm.com Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- tools/testing/selftests/x86/protection_keys.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/x86/protection_keys.c b/tools/testing/selftests/x86/protection_keys.c index 5d546dcdbc805..b8778960da106 100644 --- a/tools/testing/selftests/x86/protection_keys.c +++ b/tools/testing/selftests/x86/protection_keys.c @@ -24,6 +24,7 @@ #define _GNU_SOURCE #include #include +#include #include #include #include @@ -612,10 +613,10 @@ int alloc_random_pkey(void) 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)