Received: by 10.213.65.68 with SMTP id h4csp3428imn; Fri, 16 Mar 2018 15:15:50 -0700 (PDT) X-Google-Smtp-Source: AG47ELuoqp3pwWjva48HbLX0I3jMluIuSODG6AD8yJ5gqpfd5rPfAglDJLNLuzktczMXBcsKCu91 X-Received: by 10.98.133.193 with SMTP id m62mr2946898pfk.74.1521238550579; Fri, 16 Mar 2018 15:15:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521238550; cv=none; d=google.com; s=arc-20160816; b=lX/tkGZoqC1n0fdlhhYgYCkWCTCeG0xAtvE30gV74nuZgMaRBS5a1xL1DyTgKIo3gQ +IzaUJk5OvSjS8UfTmmGM4jGfQJnB8gZu5y1ci5vspLxGHaGnYGxVeJCgmZPi9YnsiGS JrtQhG5Ft9PjA9mbnERVv0Tj2tWuu0JzaWtTDevK+mY9K0+8v6UuS4it3qEr3Y7lHr0H /gEIO2i9wusOj0imjBgtsb3gj5eixuXsw3be1+etJ6rno8uomvV6kMCkTLjwOY1dibX6 xd6JHfk29tLX5aMYcvN0o8mi/msysz6PgjJa/mtp5NJWAqYiX5QcIza1zZTPm03D9SUp +72A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:cc:references:to:subject:arc-authentication-results; bh=4OFfBTNOK4ZOT4fSgL2LgBhIekc73xC2AwFPfISLeGI=; b=zKhOjf+guJOjAUNCVLOyn/iIkcvS5nUMpYx341X0my+rjzvTFgq04immGPMRfq3mbq 7TvYAPNKgh3Bbo/pDY6KQjIJirYexPa64Hbzvm9IsMt7zzb9GMX21qZfOFGEPVJjWXK/ lg0XuXlxyCP6cBj62w9xaNydXTc3qGx7q31jSZdZe8ffd0K4fiwPQU1cz9tdtjHkD1ip hDZts+0ZHY6nAA8eqqN3XreEvd97H44wfhFURa70wa/LD8pnUKejWX6kzzOkBPCD5yhm uv7mdwWztLavUnvmqMQo8q5ZBcHEH+YO6Y2zyTHHnqXTSeGlczOClQBU3SiGGq5dxLam UDmA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m16si5705993pgc.754.2018.03.16.15.15.36; Fri, 16 Mar 2018 15:15:50 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752306AbeCPWNR (ORCPT + 99 others); Fri, 16 Mar 2018 18:13:17 -0400 Received: from mga14.intel.com ([192.55.52.115]:50632 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750915AbeCPWNP (ORCPT ); Fri, 16 Mar 2018 18:13:15 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Mar 2018 15:13:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,317,1517904000"; d="scan'208";a="25370198" Received: from ray.jf.intel.com (HELO [10.7.201.16]) ([10.7.201.16]) by orsmga007.jf.intel.com with ESMTP; 16 Mar 2018 15:13:13 -0700 Subject: Re: [PATCH v12 09/22] selftests/vm: fix alloc_random_pkey() to make it really random To: Ram Pai , shuahkh@osg.samsung.com, linux-kselftest@vger.kernel.org References: <1519264541-7621-1-git-send-email-linuxram@us.ibm.com> <1519264541-7621-10-git-send-email-linuxram@us.ibm.com> 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, 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, arnd@arndb.de From: Dave Hansen Message-ID: <9e410d84-3cd3-edf5-4699-26fcc2bbb393@intel.com> Date: Fri, 16 Mar 2018 15:13:06 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <1519264541-7621-10-git-send-email-linuxram@us.ibm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02/21/2018 05:55 PM, Ram Pai wrote: > alloc_random_pkey() was allocating the same pkey every time. > Not all pkeys were geting tested. fixed it. ... > @@ -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(); The srand() is probably useful, but won't this always just do a single alloc_pkey() now? That seems like it will mean we always use the first one the kernel gives us, which isn't random. > - 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; > } This belonged in the pkey_reg_t patch, I think.