From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Laura Abbott <labbott@redhat.com>
Date: Wed, 13 Nov 2019 14:44:30 -0500
Subject: [PATCH] Add support for deprecating processors

Message-id: <20191113144431.9403-4-labbott@redhat.com>
Patchwork-id: 286081
O-Subject: [ARK INTERNAL PATCHv2 3/4] [redhat] Add support for deprecating processors
Bugzilla:
RH-Acked-by: Don Zickus <dzickus@redhat.com>
RH-Acked-by: Prarit Bhargava <prarit@redhat.com>
RH-Acked-by: Jiri Benc <jbenc@redhat.com>

This is the squashed version of the following patches
modifed to use the new CONFIG_RH_DISABLE_DEPRECATED option

add rh_check_supported

Message-id: <1525313397-75200-1-git-send-email-darcari@redhat.com>
Patchwork-id: 212189
O-Subject: [RHEL8.0 BZ 1565717 v2] x86: add rh_check_supported
Bugzilla: 1565717
RH-Acked-by: Steve Best <sbest@redhat.com>
RH-Acked-by: Mikulas Patocka <mpatocka@redhat.com>

Description:

Add code to verify that the booted x86 processor is supported by
Red Hat.  In cases where the processor is not supported a critical
message is logged.

Initially the supported set of processors for RHEL8 remains the same
as RHEL7.

Bugzilla: http://bugzilla.redhat.com/1565717
Brew: https://brewweb.devel.redhat.com/taskinfo?taskID=15966242

Test: Booted brew build on supported (Haswell) and unsupported processor (CNL)
      and achieved desired results.

Upstream: RHEL Only

Cc: David Arcari <darcari@redhat.com>
Cc: Mikulas Patocka <mpatocka@redhat.com>
Cc: Dave Young <dyoung@redhat.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Herton R. Krzesinski <herton@redhat.com>

update rh_check_supported processor list

Message-id: <1530618602-17477-1-git-send-email-darcari@redhat.com>
Patchwork-id: 223452
O-Subject: [RHEL8.0 BZ 1595918] x86: update rh_check_supported processor list
Bugzilla: 1595918
RH-Acked-by: Jarod Wilson <jarod@redhat.com>
RH-Acked-by: Prarit Bhargava <prarit@redhat.com>
RH-Acked-by: Steve Best <sbest@redhat.com>

Bugzilla: http://bugzilla.redhat.com/1595918
Upstream Status: RHEL_only
Build Info: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=16916208
Tested: Verified on a varity of supported and unsupported Intel and AMD systems.
	Results as expected.

In RHEL8, we are marking some of the older processors as unsupported. No code
is being removed; however, the older processors are not supported and as such
are not candidates for certification.

Cc: David Arcari <darcari@redhat.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Steve Best <sbest@redhat.com>
Signed-off-by: Herton R. Krzesinski <herton@redhat.com>
Signed-off-by: Jakub Racek <jracek@redhat.com>
refresh: rename FAM6_ATOM again, see f2c4db1bd

mark whiskey-lake processor supported

Message-id: <1533125629-12870-1-git-send-email-darcari@redhat.com>
Patchwork-id: 225809
O-Subject: [ BZ 1609604] mark whiskey-lake processor supported
Bugzilla: 1609604
RH-Acked-by: Steve Best <sbest@redhat.com>
RH-Acked-by: Tony Camuso <tcamuso@redhat.com>
RH-Acked-by: Prarit Bhargava <prarit@redhat.com>

Bugzilla: http://bugzilla.redhat.com/1609604
Build Info: https://brewweb.devel.redhat.com/taskinfo?taskID=17474338
Upstream Status: RHEL Only
Tested: Successful excecution of platform-test suite.

Whiskey Lake is cpu model 142 with stepping 11.  Stepping > 11 for cpu model
142 is not supported.

For model 158, the highest supported stepping is 10.

Cc: Prarit Bhargava <prarit@redhat.com>
Cc: David Arcari <darcari@redhat.com>
Cc: Dave Young <dyoung@redhat.com>
Signed-off-by: Herton R. Krzesinski <herton@redhat.com>

mark intel knights landing and knights mill unsupported

Message-id: <1533580277-126323-1-git-send-email-darcari@redhat.com>
Patchwork-id: 226187
O-Subject: [RHEL8.0 BZ 1610493] mark intel knights landing and knights mill unsupported
Bugzilla: 1610493
RH-Acked-by: Tony Camuso <tcamuso@redhat.com>
RH-Acked-by: Prarit Bhargava <prarit@redhat.com>
RH-Acked-by: Steve Best <sbest@redhat.com>

Bugzilla: http://bugzilla.redhat.com/1610493
Build Info: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=17625348

Tested: verified on KNL/KNM system
Upstream Status: RHEL Only
Depends: http://bugzilla.redhat.com/1609604

We are marking KNL/KNM processors as unsupported. No code is being removed;
however, the older processors are not supported and as such are not
candidates for certification.

Upstream Status: RHEL only
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: David Arcari <darcari@redhat.com>
Cc: Dave Young <dyoung@redhat.com>
Signed-off-by: Herton R. Krzesinski <herton@redhat.com>
---
 arch/x86/kernel/cpu/common.c |   1 +
 arch/x86/kernel/setup.c      | 132 ++++++++++++++++++++++++++++++++++-
 2 files changed, 132 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index c5d6f17d9b9d..9bf902c26a6e 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -1253,6 +1253,7 @@ static void __init early_identify_cpu(struct cpuinfo_x86 *c)
 		cpu_detect(c);
 		get_cpu_vendor(c);
 		get_cpu_cap(c);
+		get_model_name(c); /* RHEL: get model name for unsupported check */
 		get_cpu_address_sizes(c);
 		setup_force_cpu_cap(X86_FEATURE_CPUID);

diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 3511736fbc74..112efbef3414 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -45,6 +45,7 @@
 #include <asm/unwind.h>
 #include <asm/vsyscall.h>
 #include <linux/vmalloc.h>
+#include <asm/intel-family.h>

 /*
  * max_low_pfn_mapped: highest directly mapped pfn < 4 GB
@@ -754,7 +755,132 @@ static void __init trim_low_memory_range(void)
 {
 	memblock_reserve(0, ALIGN(reserve_low, PAGE_SIZE));
 }
-	
+
+static bool valid_amd_processor(__u8 family, const char *model_id)
+{
+	bool valid;
+
+	switch(family) {
+	case 0x15:
+		valid = true;
+		break;
+
+	case 0x17:
+		valid = strstr(model_id, "AMD EPYC 7");
+		break;
+
+	default:
+		valid = false;
+		break;
+	}
+
+	return valid;
+}
+
+static bool valid_intel_processor(__u8 family, __u8 model, __u8 stepping)
+{
+	bool valid;
+
+	if (family != 6)
+		return false;
+
+	switch(model) {
+	case INTEL_FAM6_ATOM_GOLDMONT_D:
+	case INTEL_FAM6_ATOM_GOLDMONT_PLUS:
+
+	case INTEL_FAM6_BROADWELL:
+	case INTEL_FAM6_BROADWELL_G:
+	case INTEL_FAM6_BROADWELL_X:
+	case INTEL_FAM6_BROADWELL_D:
+
+	case INTEL_FAM6_HASWELL:
+	case INTEL_FAM6_HASWELL_G:
+	case INTEL_FAM6_HASWELL_L:
+	case INTEL_FAM6_HASWELL_X:
+		valid = true;
+		break;
+
+	case INTEL_FAM6_KABYLAKE:
+		valid = (stepping <= 10);
+		break;
+
+	case INTEL_FAM6_KABYLAKE_L:
+		valid = (stepping <= 11);
+		break;
+
+	case INTEL_FAM6_SKYLAKE_L:
+	case INTEL_FAM6_SKYLAKE:
+	case INTEL_FAM6_SKYLAKE_X:
+		/* stepping > 4 is Cascade Lake and is not supported */
+		valid = (stepping <= 4);
+		break;
+
+	default:
+		valid = false;
+		break;
+	}
+
+	return valid;
+}
+
+static void rh_check_supported(void)
+{
+	bool guest;
+
+	guest = (x86_hyper_type != X86_HYPER_NATIVE || boot_cpu_has(X86_FEATURE_HYPERVISOR));
+
+	/* RHEL supports single cpu on guests only */
+	if (((boot_cpu_data.x86_max_cores * smp_num_siblings) == 1) &&
+	    !guest && is_kdump_kernel()) {
+		pr_crit("Detected single cpu native boot.\n");
+		pr_crit("Important:  In this kernel, single threaded, single CPU 64-bit physical systems are unsupported.");
+	}
+
+	/*
+	 * If the RHEL kernel does not support this hardware, the kernel will
+	 * attempt to boot, but no support is provided for this hardware
+	 */
+	switch (boot_cpu_data.x86_vendor) {
+	case X86_VENDOR_AMD:
+		if (!valid_amd_processor(boot_cpu_data.x86,
+					 boot_cpu_data.x86_model_id)) {
+			pr_crit("Detected CPU family %xh model %d\n",
+				boot_cpu_data.x86,
+				boot_cpu_data.x86_model);
+			mark_hardware_unsupported("AMD Processor");
+		}
+		break;
+
+	case X86_VENDOR_INTEL:
+		if (!valid_intel_processor(boot_cpu_data.x86,
+					   boot_cpu_data.x86_model,
+					   boot_cpu_data.x86_stepping)) {
+			pr_crit("Detected CPU family %d model %d stepping %d\n",
+				boot_cpu_data.x86,
+				boot_cpu_data.x86_model,
+				boot_cpu_data.x86_stepping);
+			mark_hardware_unsupported("Intel Processor");
+		}
+		break;
+
+	default:
+		pr_crit("Detected processor %s %s\n",
+			boot_cpu_data.x86_vendor_id,
+			boot_cpu_data.x86_model_id);
+		mark_hardware_unsupported("Processor");
+		break;
+	}
+
+	/*
+	 * Due to the complexity of x86 lapic & ioapic enumeration, and PCI IRQ
+	 * routing, ACPI is required for x86.  acpi=off is a valid debug kernel
+	 * parameter, so just print out a loud warning in case something
+	 * goes wrong (which is most of the time).
+	 */
+	if (acpi_disabled && !guest)
+		pr_crit("ACPI has been disabled or is not available on this hardware.  This may result in a single cpu boot, incorrect PCI IRQ routing, or boot failure.\n");
+}
+
 /*
  * Dump out kernel offset information on panic.
  */
@@ -1249,6 +1375,10 @@ void __init setup_arch(char **cmdline_p)
 		efi_apply_memmap_quirks();
 #endif

+#ifdef CONFIG_RH_DISABLE_DEPRECATED
+	rh_check_supported();
+#endif
+
 	unwind_init();
 }

-- 
2.26.2

