From patchwork Wed Mar 20 15:32:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 31917 Received: (qmail 82081 invoked by alias); 20 Mar 2019 15:32:55 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 82070 invoked by uid 89); 20 Mar 2019 15:32:54 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-15.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: EUR03-AM5-obe.outbound.protection.outlook.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sc1jkqno+5ZHVDcSTQe/jQFQXcKnK3hx7kqzvOXsoa0=; b=qcjyRMLg4PAzUDW2ht9cZAViNDiwMTOxnlbVaUoSFkOmtDfrvKk2wNdmCeMENAHC54vylWsGqtOww9k/yNmpVsrl9bkYQzNmahuLKgWf0nxDNMgoCAvfMWU6jHfUdGQyqEIr9/zwv48Kcj9MwskuVH9oNFgXw7QazZ2pEa9hILk= From: Wilco Dijkstra To: Adhemerval Zanella CC: nd , "libc-alpha@sourceware.org" Subject: Re: [PATCH v2 4/6] Do not use HP_TIMING_NOW for random bits Date: Wed, 20 Mar 2019 15:32:50 +0000 Message-ID: References: , <6ea276af-aa62-2bfe-ee6c-83c8eeaf283a@linaro.org> In-Reply-To: <6ea276af-aa62-2bfe-ee6c-83c8eeaf283a@linaro.org> authentication-results: spf=none (sender IP is ) smtp.mailfrom=Wilco.Dijkstra@arm.com; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 MIME-Version: 1.0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED Hi Adhemerval, > +# include > +# define RANDOM_BITS(Var) ((Var) = random_bits ()) > > This define is not used (removed above). > I think we need to still define it if we eventually decide to sync it back > to gnulib. Well this is the question - do we really need all this clutter just for gnulib? It looks to me we should keep the code as clean as possible (so we don't need any the !_LIBC code given these files are always in LIBC). > I fact the new line should not be added, since random_time_bits should already > get the random_bits() value. In any case I think we can remove random_time_bits > altogether and just call RANDOM_BITS on value instead. Agreed. > And it seems 'value' is static by design, but I do agree there is no impeding > reason to continue to do so. Indeed. --- these changes to gnulib, we could just add random_bits to gnulib. -  value += random_time_bits ^ __getpid (); -  value += random_bits () ^ __getpid (); +  RANDOM_BITS (value); +  value ^= __getpid (); +  /* Shuffle the lower bits to minimize the pid bias due low maximum value.  */ +  value = (value << 24) | (value >> 8); random_bits already does that shuffle, so doing it again doesn't help. It's better to avoid the aliasing of getpid with the random bits, eg. value ^= __get_pid << 32 so we end up with more than 32 random bits. Wilco diff --git a/sysdeps/posix/tempname.c b/sysdeps/posix/tempname.c index 5217cb38e1..d062e4b82f 100644 --- a/sysdeps/posix/tempname.c +++ b/sysdeps/posix/tempname.c @@ -73,6 +73,13 @@  #ifdef _LIBC  # include  # define RANDOM_BITS(Var) ((Var) = random_bits ()) +# else +# define RANDOM_BITS(Var) \ +    {                                                                         \ +      struct timeval tv;                                                      \ +      __gettimeofday (&tv, NULL);                                             \ +      (Var) = ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec;                      \ +    }  #endif   I don't see the point of this, especially using gettimeofday. If we want to export