All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Mikulas Patocka <mpatocka@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Bernhard Held <berny156@gmx.de>,
	Denys Vlasenko <dvlasenk@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Brian Gerst <brgerst@gmail.com>,
	"Luis R. Rodriguez" <mcgrof@suse.com>,
	Borislav Petkov <bp@alien8.de>, Andy Lutomirski <luto@kernel.org>,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: [PATCH 4.4 56/57] x86/mm/pat: Dont report PAT on CPUs that dont support it
Date: Thu, 13 Jul 2017 17:43:11 +0200	[thread overview]
Message-ID: <20170713154001.351677509@linuxfoundation.org> (raw)
In-Reply-To: <20170713153957.515045341@linuxfoundation.org>

4.4-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Mikulas Patocka <mpatocka@redhat.com>

commit 99c13b8c8896d7bcb92753bf0c63a8de4326e78d upstream.

The pat_enabled() logic is broken on CPUs which do not support PAT and
where the initialization code fails to call pat_init(). Due to that the
enabled flag stays true and pat_enabled() returns true wrongfully.

As a consequence the mappings, e.g. for Xorg, are set up with the wrong
caching mode and the required MTRR setups are omitted.

To cure this the following changes are required:

  1) Make pat_enabled() return true only if PAT initialization was
     invoked and successful.

  2) Invoke init_cache_modes() unconditionally in setup_arch() and
     remove the extra callsites in pat_disable() and the pat disabled
     code path in pat_init().

Also rename __pat_enabled to pat_disabled to reflect the real purpose of
this variable.

Fixes: 9cd25aac1f44 ("x86/mm/pat: Emulate PAT when it is disabled")
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Bernhard Held <berny156@gmx.de>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: "Luis R. Rodriguez" <mcgrof@suse.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: http://lkml.kernel.org/r/alpine.LRH.2.02.1707041749300.3456@file01.intranet.prod.int.rdu2.redhat.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 arch/x86/include/asm/pat.h |    1 +
 arch/x86/kernel/setup.c    |    7 +++++++
 arch/x86/mm/pat.c          |   28 ++++++++++++----------------
 3 files changed, 20 insertions(+), 16 deletions(-)

--- a/arch/x86/include/asm/pat.h
+++ b/arch/x86/include/asm/pat.h
@@ -7,6 +7,7 @@
 bool pat_enabled(void);
 void pat_disable(const char *reason);
 extern void pat_init(void);
+extern void init_cache_modes(void);
 
 extern int reserve_memtype(u64 start, u64 end,
 		enum page_cache_mode req_pcm, enum page_cache_mode *ret_pcm);
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -1048,6 +1048,13 @@ void __init setup_arch(char **cmdline_p)
 	if (mtrr_trim_uncached_memory(max_pfn))
 		max_pfn = e820_end_of_ram_pfn();
 
+	/*
+	 * This call is required when the CPU does not support PAT. If
+	 * mtrr_bp_init() invoked it already via pat_init() the call has no
+	 * effect.
+	 */
+	init_cache_modes();
+
 #ifdef CONFIG_X86_32
 	/* max_low_pfn get updated here */
 	find_low_pfn_range();
--- a/arch/x86/mm/pat.c
+++ b/arch/x86/mm/pat.c
@@ -36,14 +36,14 @@
 #undef pr_fmt
 #define pr_fmt(fmt) "" fmt
 
-static bool boot_cpu_done;
-
-static int __read_mostly __pat_enabled = IS_ENABLED(CONFIG_X86_PAT);
-static void init_cache_modes(void);
+static bool __read_mostly boot_cpu_done;
+static bool __read_mostly pat_disabled = !IS_ENABLED(CONFIG_X86_PAT);
+static bool __read_mostly pat_initialized;
+static bool __read_mostly init_cm_done;
 
 void pat_disable(const char *reason)
 {
-	if (!__pat_enabled)
+	if (pat_disabled)
 		return;
 
 	if (boot_cpu_done) {
@@ -51,10 +51,8 @@ void pat_disable(const char *reason)
 		return;
 	}
 
-	__pat_enabled = 0;
+	pat_disabled = true;
 	pr_info("x86/PAT: %s\n", reason);
-
-	init_cache_modes();
 }
 
 static int __init nopat(char *str)
@@ -66,7 +64,7 @@ early_param("nopat", nopat);
 
 bool pat_enabled(void)
 {
-	return !!__pat_enabled;
+	return pat_initialized;
 }
 EXPORT_SYMBOL_GPL(pat_enabled);
 
@@ -204,6 +202,8 @@ static void __init_cache_modes(u64 pat)
 		update_cache_mode_entry(i, cache);
 	}
 	pr_info("x86/PAT: Configuration [0-7]: %s\n", pat_msg);
+
+	init_cm_done = true;
 }
 
 #define PAT(x, y)	((u64)PAT_ ## y << ((x)*8))
@@ -224,6 +224,7 @@ static void pat_bsp_init(u64 pat)
 	}
 
 	wrmsrl(MSR_IA32_CR_PAT, pat);
+	pat_initialized = true;
 
 	__init_cache_modes(pat);
 }
@@ -241,10 +242,9 @@ static void pat_ap_init(u64 pat)
 	wrmsrl(MSR_IA32_CR_PAT, pat);
 }
 
-static void init_cache_modes(void)
+void init_cache_modes(void)
 {
 	u64 pat = 0;
-	static int init_cm_done;
 
 	if (init_cm_done)
 		return;
@@ -286,8 +286,6 @@ static void init_cache_modes(void)
 	}
 
 	__init_cache_modes(pat);
-
-	init_cm_done = 1;
 }
 
 /**
@@ -305,10 +303,8 @@ void pat_init(void)
 	u64 pat;
 	struct cpuinfo_x86 *c = &boot_cpu_data;
 
-	if (!pat_enabled()) {
-		init_cache_modes();
+	if (pat_disabled)
 		return;
-	}
 
 	if ((c->x86_vendor == X86_VENDOR_INTEL) &&
 	    (((c->x86 == 0x6) && (c->x86_model <= 0xd)) ||

  parent reply	other threads:[~2017-07-13 15:47 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-13 15:42 [PATCH 4.4 00/57] 4.4.77-stable review Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 01/57] fs: add a VALID_OPEN_FLAGS Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 02/57] fs: completely ignore unknown open flags Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 03/57] driver core: platform: fix race condition with driver_override Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 05/57] mm: fix classzone_idx underflow in shrink_zones() Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 06/57] tracing/kprobes: Allow to create probe with a module name starting with a digit Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 08/57] usb: dwc3: replace %p with %pK Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 09/57] USB: serial: cp210x: add ID for CEL EM3588 USB ZigBee stick Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 10/57] Add USB quirk for HVR-950q to avoid intermittent device resets Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 11/57] usb: usbip: set buffer pointers to NULL after free Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 12/57] usb: Fix typo in the definition of Endpoint[out]Request Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 13/57] mac80211_hwsim: Replace bogus hrtimer clockid Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 14/57] sysctl: dont print negative flag for proc_douintvec Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 15/57] sysctl: report EINVAL if value is larger than UINT_MAX " Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 16/57] pinctrl: sh-pfc: r8a7791: Fix SCIF2 pinmux data Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 17/57] pinctrl: sh-pfc: r8a7791: Add missing DVC_MUTE signal Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 18/57] pinctrl: meson: meson8b: fix the NAND DQS pins Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 19/57] pinctrl: sunxi: Fix SPDIF function name for A83T Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 21/57] pinctrl: sh-pfc: Update info pointer after SoC-specific init Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 24/57] gfs2: Fix glock rhashtable rcu bug Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 26/57] x86/uaccess: Optimize copy_user_enhanced_fast_string() for short strings Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 27/57] ath10k: override CE5 config for QCA9377 Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 28/57] KEYS: Fix an error code in request_master_key() Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 29/57] RDMA/uverbs: Check port number supplied by user verbs cmds Greg Kroah-Hartman
2017-07-13 15:54   ` Ismail, Mustafa
     [not found]     ` <5C5647B5F4794941BAAC07CF28785CBC33E4E81F-96pTJSsuoYSkrb+BlOpmy7fspsVTdybXVpNB7YpNyf8@public.gmane.org>
2017-07-13 16:25       ` Greg Kroah-Hartman
2017-07-13 16:25         ` Greg Kroah-Hartman
     [not found]         ` <20170713162540.GB22870-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2017-07-13 18:44           ` Ismail, Mustafa
2017-07-13 18:44             ` Ismail, Mustafa
     [not found]             ` <5C5647B5F4794941BAAC07CF28785CBC33E4EC25-96pTJSsuoYSkrb+BlOpmy7fspsVTdybXVpNB7YpNyf8@public.gmane.org>
2017-07-14  6:49               ` Greg Kroah-Hartman
2017-07-14  6:49                 ` Greg Kroah-Hartman
     [not found]                 ` <20170714064908.GC16816-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2017-07-14 14:54                   ` Ismail, Mustafa
2017-07-14 14:54                     ` Ismail, Mustafa
2017-07-17 17:30           ` Marciniszyn, Mike
2017-07-17 17:30             ` Marciniszyn, Mike
2017-07-17 19:22             ` Greg Kroah-Hartman
2017-07-17 19:24               ` Marciniszyn, Mike
2017-07-13 15:42 ` [PATCH 4.4 30/57] mqueue: fix a use-after-free in sys_mq_notify() Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 31/57] tools include: Add a __fallthrough statement Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 32/57] tools string: Use __fallthrough in perf_atoll() Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 33/57] tools strfilter: Use __fallthrough Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 34/57] perf top: " Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 35/57] perf intel-pt: " Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 36/57] perf thread_map: Correctly size buffer used with dirent->dt_name Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 37/57] perf scripting perl: Fix compile error with some perl5 versions Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 38/57] perf tests: Avoid possible truncation with dirent->d_name + snprintf Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 39/57] perf bench numa: Avoid possible truncation when using snprintf() Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 40/57] perf tools: Use readdir() instead of deprecated readdir_r() Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 41/57] perf thread_map: " Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 42/57] perf script: " Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 43/57] perf tools: Remove duplicate const qualifier Greg Kroah-Hartman
2017-07-13 15:42 ` [PATCH 4.4 44/57] perf annotate browser: Fix behaviour of Shift-Tab with nothing focussed Greg Kroah-Hartman
2017-07-13 15:43 ` [PATCH 4.4 45/57] perf pmu: Fix misleadingly indented assignment (whitespace) Greg Kroah-Hartman
2017-07-13 15:43 ` [PATCH 4.4 46/57] perf dwarf: Guard !x86_64 definitions under #ifdef else clause Greg Kroah-Hartman
2017-07-13 15:43 ` [PATCH 4.4 47/57] perf trace: Do not process PERF_RECORD_LOST twice Greg Kroah-Hartman
2017-07-13 15:43 ` [PATCH 4.4 48/57] perf tests: Remove wrong semicolon in while loop in CQM test Greg Kroah-Hartman
2017-07-13 15:43 ` [PATCH 4.4 49/57] perf tools: Use readdir() instead of deprecated readdir_r() again Greg Kroah-Hartman
2017-07-13 15:43 ` [PATCH 4.4 50/57] md: fix incorrect use of lexx_to_cpu in does_sb_need_changing Greg Kroah-Hartman
2017-07-13 15:43 ` [PATCH 4.4 51/57] md: fix super_offset endianness in super_1_rdev_size_change Greg Kroah-Hartman
2017-07-13 15:43 ` [PATCH 4.4 52/57] tcp: fix tcp_mark_head_lost to check skb len before fragmenting Greg Kroah-Hartman
2017-07-13 15:43 ` [PATCH 4.4 53/57] staging: vt6556: vnt_start Fix missing call to vnt_key_init_table Greg Kroah-Hartman
2017-07-13 15:43 ` [PATCH 4.4 54/57] staging: comedi: fix clean-up of comedi_class in comedi_init() Greg Kroah-Hartman
2017-07-13 15:43 ` [PATCH 4.4 55/57] ext4: check return value of kstrtoull correctly in reserved_clusters_store Greg Kroah-Hartman
2017-07-13 15:43 ` Greg Kroah-Hartman [this message]
2017-07-13 15:43 ` [PATCH 4.4 57/57] [media] saa7134: fix warm Medion 7134 EEPROM read Greg Kroah-Hartman
2017-07-14  1:33 ` [PATCH 4.4 00/57] 4.4.77-stable review Guenter Roeck
2017-07-14  9:50   ` Greg Kroah-Hartman
2017-07-14 19:23     ` Guenter Roeck
2017-07-15  8:10       ` Greg Kroah-Hartman
     [not found] ` <5967e121.9fb6df0a.979fe.f2ca@mx.google.com>
2017-07-14  9:51   ` Greg Kroah-Hartman
2017-07-14 12:21     ` Arnd Bergmann
2017-07-14 13:26       ` Greg Kroah-Hartman
2017-07-14 19:54         ` Arnd Bergmann
2017-07-18 22:56           ` Kevin Hilman
2017-07-15 11:16         ` Geert Uytterhoeven
2017-07-15 11:22           ` Greg Kroah-Hartman
2017-07-14 12:35     ` Mark Brown
2017-07-14 13:26       ` Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170713154001.351677509@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=akpm@linux-foundation.org \
    --cc=berny156@gmx.de \
    --cc=bp@alien8.de \
    --cc=brgerst@gmail.com \
    --cc=dvlasenk@redhat.com \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mcgrof@suse.com \
    --cc=mpatocka@redhat.com \
    --cc=peterz@infradead.org \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.