From patchwork Wed Feb 6 07:12:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 1039053 Return-Path: Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73ABFC169C4 for ; Wed, 6 Feb 2019 07:24:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4C02A2175B for ; Wed, 6 Feb 2019 07:24:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728003AbfBFHYs (ORCPT ); Wed, 6 Feb 2019 02:24:48 -0500 Received: from mga01.intel.com ([192.55.52.88]:10519 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726822AbfBFHYs (ORCPT ); Wed, 6 Feb 2019 02:24:48 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Feb 2019 23:24:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,339,1544515200"; d="scan'208";a="141953069" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga004.fm.intel.com with ESMTP; 05 Feb 2019 23:24:47 -0800 Subject: [PATCH 1/2] mm/shuffle: Fix shuffle enable From: Dan Williams To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, keescook@chromium.org, linux-kernel@vger.kernel.org Date: Tue, 05 Feb 2019 23:12:10 -0800 Message-ID: <154943713038.3858443.4125180191382062871.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <154943712485.3858443.4491117952728936852.stgit@dwillia2-desk3.amr.corp.intel.com> References: <154943712485.3858443.4491117952728936852.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The removal of shuffle_store() in v10 of the patch series was prompted by the review feedback to convert page_alloc_shuffle() to __memint. I obviously booted a stale kernel build in my tests because shuffle_store() is indeed required: BUG: unable to handle kernel NULL pointer dereference at 0000000000000000 #PF error: [INSTR] PGD 0 P4D 0 Oops: 0010 [#1] SMP PTI CPU: 0 PID: 0 Comm: swapper Not tainted 5.0.0-rc1+ #2867 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS ?-20180531_142017-buildhw-08.phx2.fedoraproject.org-1.fc28 04/01/2014 RIP: 0010: (null) Code: Bad RIP value. RSP: 0000:ffffffff82603e78 EFLAGS: 00010046 RAX: 0000000000000000 RBX: 0000000000000000 RCX: cccccccccccccccd RDX: ffffffff8261d7c0 RSI: ffffffff8244c010 RDI: ffff88843ffe1aaa RBP: ffff88843ffe1aac R08: ffffffff83486978 R09: 0000000000000000 R10: ffffffff82603e80 R11: 0000000000000048 R12: ffff88843ffe1a97 R13: ffff88843ffe1aaa R14: ffffffff8244c010 R15: 000000000000016d FS: 0000000000000000(0000) GS:ffff88811be00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: ffffffffffffffd6 CR3: 0000000002614000 CR4: 00000000000606b0 Call Trace: ? parse_args+0x170/0x360 ? set_init_arg+0x55/0x55 ? start_kernel+0x1d8/0x4c4 ? set_init_arg+0x55/0x55 ? secondary_startup_64+0xa4/0xb0 Reintroduce it and mark it __meminit. Given the sysfs attribute is not writable it will never be called after init. Signed-off-by: Dan Williams --- mm/shuffle.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/mm/shuffle.c b/mm/shuffle.c index 19bbf3e37fb6..3ce12481b1dc 100644 --- a/mm/shuffle.c +++ b/mm/shuffle.c @@ -38,7 +38,21 @@ extern int shuffle_show(char *buffer, const struct kernel_param *kp) return sprintf(buffer, "%c\n", test_bit(SHUFFLE_ENABLE, &shuffle_state) ? 'Y' : 'N'); } -module_param_call(shuffle, NULL, shuffle_show, &shuffle_param, 0400); + +static __meminit int shuffle_store(const char *val, + const struct kernel_param *kp) +{ + int rc = param_set_bool(val, kp); + + if (rc < 0) + return rc; + if (shuffle_param) + page_alloc_shuffle(SHUFFLE_ENABLE); + else + page_alloc_shuffle(SHUFFLE_FORCE_DISABLE); + return 0; +} +module_param_call(shuffle, shuffle_store, shuffle_show, &shuffle_param, 0400); /* * For two pages to be swapped in the shuffle, they must be free (on a From patchwork Wed Feb 6 07:12:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 1039054 Return-Path: Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2B31C282C2 for ; Wed, 6 Feb 2019 07:24:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A92E0218A3 for ; Wed, 6 Feb 2019 07:24:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728073AbfBFHYz (ORCPT ); Wed, 6 Feb 2019 02:24:55 -0500 Received: from mga02.intel.com ([134.134.136.20]:22884 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726822AbfBFHYy (ORCPT ); Wed, 6 Feb 2019 02:24:54 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Feb 2019 23:24:54 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,339,1544515200"; d="scan'208";a="144567009" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga001.fm.intel.com with ESMTP; 05 Feb 2019 23:24:53 -0800 Subject: [PATCH 2/2] [-mm only] mm/shuffle: Default enable all shuffling From: Dan Williams To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, keescook@chromium.org, linux-kernel@vger.kernel.org Date: Tue, 05 Feb 2019 23:12:15 -0800 Message-ID: <154943713572.3858443.11206307988382889377.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <154943712485.3858443.4491117952728936852.stgit@dwillia2-desk3.amr.corp.intel.com> References: <154943712485.3858443.4491117952728936852.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Per Andrew's request arrange for all memory allocation shuffling code to be enabled by default. The page_alloc.shuffle command line parameter can still be used to disable shuffling at boot, but the kernel will default enable the shuffling if the command line option is not specified. Signed-off-by: Dan Williams --- init/Kconfig | 4 ++-- mm/shuffle.c | 4 ++-- mm/shuffle.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/init/Kconfig b/init/Kconfig index cfa199f3e9be..12557e12be4c 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1697,7 +1697,7 @@ config SLAB_MERGE_DEFAULT command line. config SLAB_FREELIST_RANDOM - default n + default y depends on SLAB || SLUB bool "SLAB freelist randomization" help @@ -1716,7 +1716,7 @@ config SLAB_FREELIST_HARDENED config SHUFFLE_PAGE_ALLOCATOR bool "Page allocator randomization" - default SLAB_FREELIST_RANDOM && ACPI_NUMA + default y help Randomization of the page allocator improves the average utilization of a direct-mapped memory-side-cache. See section diff --git a/mm/shuffle.c b/mm/shuffle.c index 3ce12481b1dc..a979b48be469 100644 --- a/mm/shuffle.c +++ b/mm/shuffle.c @@ -9,8 +9,8 @@ #include "internal.h" #include "shuffle.h" -DEFINE_STATIC_KEY_FALSE(page_alloc_shuffle_key); -static unsigned long shuffle_state __ro_after_init; +DEFINE_STATIC_KEY_TRUE(page_alloc_shuffle_key); +static unsigned long shuffle_state __ro_after_init = 1 << SHUFFLE_ENABLE; /* * Depending on the architecture, module parameter parsing may run diff --git a/mm/shuffle.h b/mm/shuffle.h index fc1e327ae22d..466a5620e0aa 100644 --- a/mm/shuffle.h +++ b/mm/shuffle.h @@ -19,7 +19,7 @@ enum mm_shuffle_ctl { #define SHUFFLE_ORDER (MAX_ORDER-1) #ifdef CONFIG_SHUFFLE_PAGE_ALLOCATOR -DECLARE_STATIC_KEY_FALSE(page_alloc_shuffle_key); +DECLARE_STATIC_KEY_TRUE(page_alloc_shuffle_key); extern void page_alloc_shuffle(enum mm_shuffle_ctl ctl); extern void __shuffle_free_memory(pg_data_t *pgdat); static inline void shuffle_free_memory(pg_data_t *pgdat)