From patchwork Mon Oct 17 23:05:23 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan McGee X-Patchwork-Id: 120444 X-Patchwork-Delegate: benh@kernel.crashing.org Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [IPv6:::1]) by ozlabs.org (Postfix) with ESMTP id 57EDE10086A for ; Wed, 19 Oct 2011 02:05:06 +1100 (EST) Received: from mail-gy0-f179.google.com (mail-gy0-f179.google.com [209.85.160.179]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (verified OK)) by ozlabs.org (Postfix) with ESMTPS id B71DCB70B7 for ; Tue, 18 Oct 2011 10:05:41 +1100 (EST) Received: by gyg8 with SMTP id 8so3831988gyg.38 for ; Mon, 17 Oct 2011 16:05:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=8eGbE+YycF9c/6MiR2vMeP7IbOQYfi2oXcaOpgvJ/D4=; b=YtY4len9gJWQ8nilE94wweHVRWU3gc92RZuYbZiVd/fs8329nZTripFu2E12c9vbkE J8HfG9UNhDJEDlVmiZgV+yuz7CwgCRYs0W9qag1OdCjuDeIAGA0FVm+yNsA1c0saB481 B3ryjXt/9kIsV+0QxVL0ePldaRO2aguLqKOPU= Received: by 10.151.43.17 with SMTP id v17mr78491ybj.79.1318892737908; Mon, 17 Oct 2011 16:05:37 -0700 (PDT) Received: from localhost (c-71-194-41-240.hsd1.il.comcast.net. [71.194.41.240]) by mx.google.com with ESMTPS id g38sm156939ann.4.2011.10.17.16.05.36 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 17 Oct 2011 16:05:37 -0700 (PDT) From: Dan McGee To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH] powerpc/mm: remove hack in mmap randomize layout Date: Mon, 17 Oct 2011 18:05:23 -0500 Message-Id: <1318892723-19401-1-git-send-email-dpmcgee@gmail.com> X-Mailer: git-send-email 1.7.7 In-Reply-To: <20111017.185357.1185691091043314919.davem@davemloft.net> References: <20111017.185357.1185691091043314919.davem@davemloft.net> X-Mailman-Approved-At: Wed, 19 Oct 2011 02:04:31 +1100 Cc: paulus@samba.org, linux-kernel@vger.kernel.org, David Miller X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Since commit 8a0a9bd4db63bc45e301, this comment in mmap_rnd() does not hold true as the value returned by get_random_int() will in fact be different every single call. Remove the comment and simplify the code back to its original desired form. This reverts commit a5adc91a4b44b5d1 which is no longer necessary and also fixes the sparc code that copied this same adjustment. Signed-off-by: Dan McGee --- arch/powerpc/mm/mmap_64.c | 14 +++----------- arch/sparc/kernel/sys_sparc_64.c | 6 +++--- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c index 5a783d8..67a42ed 100644 --- a/arch/powerpc/mm/mmap_64.c +++ b/arch/powerpc/mm/mmap_64.c @@ -53,14 +53,6 @@ static inline int mmap_is_legacy(void) return sysctl_legacy_va_layout; } -/* - * Since get_random_int() returns the same value within a 1 jiffy window, - * we will almost always get the same randomisation for the stack and mmap - * region. This will mean the relative distance between stack and mmap will - * be the same. - * - * To avoid this we can shift the randomness by 1 bit. - */ static unsigned long mmap_rnd(void) { unsigned long rnd = 0; @@ -68,11 +60,11 @@ static unsigned long mmap_rnd(void) if (current->flags & PF_RANDOMIZE) { /* 8MB for 32bit, 1GB for 64bit */ if (is_32bit_task()) - rnd = (long)(get_random_int() % (1<<(22-PAGE_SHIFT))); + rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT))); else - rnd = (long)(get_random_int() % (1<<(29-PAGE_SHIFT))); + rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT))); } - return (rnd << PAGE_SHIFT) * 2; + return rnd << PAGE_SHIFT; } static inline unsigned long mmap_base(void) diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c index 908b47a..c2c03c8 100644 --- a/arch/sparc/kernel/sys_sparc_64.c +++ b/arch/sparc/kernel/sys_sparc_64.c @@ -368,11 +368,11 @@ static unsigned long mmap_rnd(void) if (current->flags & PF_RANDOMIZE) { unsigned long val = get_random_int(); if (test_thread_flag(TIF_32BIT)) - rnd = (val % (1UL << (22UL-PAGE_SHIFT))); + rnd = (val % (1UL << (23UL-PAGE_SHIFT))); else - rnd = (val % (1UL << (29UL-PAGE_SHIFT))); + rnd = (val % (1UL << (30UL-PAGE_SHIFT))); } - return (rnd << PAGE_SHIFT) * 2; + return rnd << PAGE_SHIFT; } void arch_pick_mmap_layout(struct mm_struct *mm)