From cc4bd8733625e2764c99e2c186b7cfde705c9c84 Mon Sep 17 00:00:00 2001
From: Jan Alexander Steffens <heftig@archlinux.org>
Date: Tue, 12 Jun 2018 19:12:42 +0000
Subject: [PATCH] 4.17.1-1

---
 ...sallow-unprivileged-CLONE_NEWUSER-by.patch |   6 +-
 ...edp-Allow-alternate-fixed-mode-for-e.patch |  10 +-
 ...efer-iTCO_wdt-always-when-WDAT-table.patch | 132 ++++++++++++++++++
 PKGBUILD                                      |  17 ++-
 4 files changed, 152 insertions(+), 13 deletions(-)
 create mode 100644 0003-ACPI-watchdog-Prefer-iTCO_wdt-always-when-WDAT-table.patch

diff --git a/0001-add-sysctl-to-disallow-unprivileged-CLONE_NEWUSER-by.patch b/0001-add-sysctl-to-disallow-unprivileged-CLONE_NEWUSER-by.patch
index 3db4ddd..ef2a8aa 100644
--- a/0001-add-sysctl-to-disallow-unprivileged-CLONE_NEWUSER-by.patch
+++ b/0001-add-sysctl-to-disallow-unprivileged-CLONE_NEWUSER-by.patch
@@ -1,8 +1,8 @@
-From b7e3d341f20581dcd72d3640fa8f6f99fd766d21 Mon Sep 17 00:00:00 2001
-Message-Id: <b7e3d341f20581dcd72d3640fa8f6f99fd766d21.1528140572.git.jan.steffens@gmail.com>
+From 9a5adbc45b1c7d43fe4b27936f2a6939660617a1 Mon Sep 17 00:00:00 2001
+Message-Id: <9a5adbc45b1c7d43fe4b27936f2a6939660617a1.1528777685.git.jan.steffens@gmail.com>
 From: Serge Hallyn <serge.hallyn@canonical.com>
 Date: Fri, 31 May 2013 19:12:12 +0100
-Subject: [PATCH 1/2] add sysctl to disallow unprivileged CLONE_NEWUSER by
+Subject: [PATCH 1/3] add sysctl to disallow unprivileged CLONE_NEWUSER by
  default
 
 Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
diff --git a/0002-Revert-drm-i915-edp-Allow-alternate-fixed-mode-for-e.patch b/0002-Revert-drm-i915-edp-Allow-alternate-fixed-mode-for-e.patch
index 83ac849..8d44c55 100644
--- a/0002-Revert-drm-i915-edp-Allow-alternate-fixed-mode-for-e.patch
+++ b/0002-Revert-drm-i915-edp-Allow-alternate-fixed-mode-for-e.patch
@@ -1,10 +1,10 @@
-From 997fbfe5508bc7d29fdf0a7a103f3864d4db380a Mon Sep 17 00:00:00 2001
-Message-Id: <997fbfe5508bc7d29fdf0a7a103f3864d4db380a.1528140572.git.jan.steffens@gmail.com>
-In-Reply-To: <b7e3d341f20581dcd72d3640fa8f6f99fd766d21.1528140572.git.jan.steffens@gmail.com>
-References: <b7e3d341f20581dcd72d3640fa8f6f99fd766d21.1528140572.git.jan.steffens@gmail.com>
+From 6cc33158e691a70111672a6105c7a37e66e6d3c3 Mon Sep 17 00:00:00 2001
+Message-Id: <6cc33158e691a70111672a6105c7a37e66e6d3c3.1528777685.git.jan.steffens@gmail.com>
+In-Reply-To: <9a5adbc45b1c7d43fe4b27936f2a6939660617a1.1528777685.git.jan.steffens@gmail.com>
+References: <9a5adbc45b1c7d43fe4b27936f2a6939660617a1.1528777685.git.jan.steffens@gmail.com>
 From: Jani Nikula <jani.nikula@intel.com>
 Date: Wed, 16 May 2018 11:01:10 +0300
-Subject: [PATCH 2/2] Revert "drm/i915/edp: Allow alternate fixed mode for eDP
+Subject: [PATCH 2/3] Revert "drm/i915/edp: Allow alternate fixed mode for eDP
  if available."
 
 This reverts commit dc911f5bd8aacfcf8aabd5c26c88e04c837a938e.
diff --git a/0003-ACPI-watchdog-Prefer-iTCO_wdt-always-when-WDAT-table.patch b/0003-ACPI-watchdog-Prefer-iTCO_wdt-always-when-WDAT-table.patch
new file mode 100644
index 0000000..b4db2ad
--- /dev/null
+++ b/0003-ACPI-watchdog-Prefer-iTCO_wdt-always-when-WDAT-table.patch
@@ -0,0 +1,132 @@
+From 1e45a10dbea00f3a9ead21a9b3d25ad00021261d Mon Sep 17 00:00:00 2001
+Message-Id: <1e45a10dbea00f3a9ead21a9b3d25ad00021261d.1528777685.git.jan.steffens@gmail.com>
+In-Reply-To: <9a5adbc45b1c7d43fe4b27936f2a6939660617a1.1528777685.git.jan.steffens@gmail.com>
+References: <9a5adbc45b1c7d43fe4b27936f2a6939660617a1.1528777685.git.jan.steffens@gmail.com>
+From: Mika Westerberg <mika.westerberg@linux.intel.com>
+Date: Tue, 22 May 2018 14:16:50 +0300
+Subject: [PATCH 3/3] ACPI / watchdog: Prefer iTCO_wdt always when WDAT table
+ uses RTC SRAM
+
+After we added quirk for Lenovo Z50-70 it turns out there are at least
+two more systems where WDAT table includes instructions accessing RTC
+SRAM. Instead of quirking each system separately, look for such
+instructions in the table and automatically prefer iTCO_wdt if found.
+
+Link: https://bugzilla.kernel.org/show_bug.cgi?id=199033
+Reported-by: Arnold Guy <aurnoldg@gmail.com>
+Reported-by: Alois Nespor <nespor@fssp.cz>
+Reported-by: Yury Pakin <zxwarior@gmail.com>
+Reported-by: Ihor Chyhin <ihorchyhin@ukr.net>
+Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
+Acked-by: Guenter Roeck <linux@roeck-us.net>
+---
+ drivers/acpi/acpi_watchdog.c | 72 ++++++++++++++++++++++--------------
+ 1 file changed, 45 insertions(+), 27 deletions(-)
+
+diff --git a/drivers/acpi/acpi_watchdog.c b/drivers/acpi/acpi_watchdog.c
+index 4bde16fb97d8..95600309ce42 100644
+--- a/drivers/acpi/acpi_watchdog.c
++++ b/drivers/acpi/acpi_watchdog.c
+@@ -12,54 +12,72 @@
+ #define pr_fmt(fmt) "ACPI: watchdog: " fmt
+ 
+ #include <linux/acpi.h>
+-#include <linux/dmi.h>
+ #include <linux/ioport.h>
+ #include <linux/platform_device.h>
+ 
+ #include "internal.h"
+ 
+-static const struct dmi_system_id acpi_watchdog_skip[] = {
+-	{
+-		/*
+-		 * On Lenovo Z50-70 there are two issues with the WDAT
+-		 * table. First some of the instructions use RTC SRAM
+-		 * to store persistent information. This does not work well
+-		 * with Linux RTC driver. Second, more important thing is
+-		 * that the instructions do not actually reset the system.
+-		 *
+-		 * On this particular system iTCO_wdt seems to work just
+-		 * fine so we prefer that over WDAT for now.
+-		 *
+-		 * See also https://bugzilla.kernel.org/show_bug.cgi?id=199033.
+-		 */
+-		.ident = "Lenovo Z50-70",
+-		.matches = {
+-			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
+-			DMI_MATCH(DMI_PRODUCT_NAME, "20354"),
+-			DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo Z50-70"),
+-		},
+-	},
+-	{}
+-};
++#ifdef CONFIG_RTC_MC146818_LIB
++#include <linux/mc146818rtc.h>
++
++/*
++ * There are several systems where the WDAT table is accessing RTC SRAM to
++ * store persistent information. This does not work well with the Linux RTC
++ * driver so on those systems we skip WDAT driver and prefer iTCO_wdt
++ * instead.
++ *
++ * See also https://bugzilla.kernel.org/show_bug.cgi?id=199033.
++ */
++static bool acpi_watchdog_uses_rtc(const struct acpi_table_wdat *wdat)
++{
++	const struct acpi_wdat_entry *entries;
++	int i;
++
++	entries = (struct acpi_wdat_entry *)(wdat + 1);
++	for (i = 0; i < wdat->entries; i++) {
++		const struct acpi_generic_address *gas;
++
++		gas = &entries[i].register_region;
++		if (gas->space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
++			switch (gas->address) {
++			case RTC_PORT(0):
++			case RTC_PORT(1):
++			case RTC_PORT(2):
++			case RTC_PORT(3):
++				return true;
++			}
++		}
++	}
++
++	return false;
++}
++#else
++static bool acpi_watchdog_uses_rtc(const struct acpi_table_wdat *wdat)
++{
++	return false;
++}
++#endif
+ 
+ static const struct acpi_table_wdat *acpi_watchdog_get_wdat(void)
+ {
+ 	const struct acpi_table_wdat *wdat = NULL;
+ 	acpi_status status;
+ 
+ 	if (acpi_disabled)
+ 		return NULL;
+ 
+-	if (dmi_check_system(acpi_watchdog_skip))
+-		return NULL;
+-
+ 	status = acpi_get_table(ACPI_SIG_WDAT, 0,
+ 				(struct acpi_table_header **)&wdat);
+ 	if (ACPI_FAILURE(status)) {
+ 		/* It is fine if there is no WDAT */
+ 		return NULL;
+ 	}
+ 
++	if (acpi_watchdog_uses_rtc(wdat)) {
++		pr_info("Skipping WDAT on this system because it uses RTC SRAM\n");
++		return NULL;
++	}
++
+ 	return wdat;
+ }
+ 
+-- 
+2.17.1
+
diff --git a/PKGBUILD b/PKGBUILD
index 9286a82..ad1e994 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -4,7 +4,7 @@
 pkgbase=linux               # Build stock -ARCH kernel
 #pkgbase=linux-custom       # Build kernel with a different name
 _srcname=linux-4.17
-pkgver=4.17
+pkgver=4.17.1
 pkgrel=1
 arch=('x86_64')
 url="https://www.kernel.org/"
@@ -13,26 +13,30 @@ makedepends=('xmlto' 'kmod' 'inetutils' 'bc' 'libelf')
 options=('!strip')
 source=(
   https://www.kernel.org/pub/linux/kernel/v4.x/${_srcname}.tar.{xz,sign}
-  #https://www.kernel.org/pub/linux/kernel/v4.x/patch-${pkgver}.{xz,sign}
+  https://www.kernel.org/pub/linux/kernel/v4.x/patch-${pkgver}.{xz,sign}
   config         # the main kernel config file
   60-linux.hook  # pacman hook for depmod
   90-linux.hook  # pacman hook for initramfs regeneration
   linux.preset   # standard config files for mkinitcpio ramdisk
   0001-add-sysctl-to-disallow-unprivileged-CLONE_NEWUSER-by.patch
   0002-Revert-drm-i915-edp-Allow-alternate-fixed-mode-for-e.patch
+  0003-ACPI-watchdog-Prefer-iTCO_wdt-always-when-WDAT-table.patch
 )
 validpgpkeys=(
   'ABAF11C65A2970B130ABE3C479BE3E4300411886'  # Linus Torvalds
   '647F28654894E3BD457199BE38DBBDC86092693E'  # Greg Kroah-Hartman
 )
 sha256sums=('9faa1dd896eaea961dc6e886697c0b3301277102e5bc976b2758f9a62d3ccd13'
+            'SKIP'
+            '31f2f5309d99db632160538d43cf737166ae8b24c1b8091522ca1f9a804c25a1'
             'SKIP'
             '0269d9a56f0d0306c9bd5c179a7e32214b0a1c082d3bca581661203b27305f17'
             'ae2e95db94ef7176207c690224169594d49445e04249d2499e9d2fbc117a0b21'
             '75f99f5239e03238f88d1a834c50043ec32b1dc568f2cc291b07d04718483919'
             'ad6344badc91ad0630caacde83f7f9b97276f80d26a20619a87952be65492c65'
-            '0b77e6bef12735bc91e3f0e8232512e973688466f2e8a2c3a93502cb2d4b4eed'
-            '92615acad59cbef9fd43b2710f5a77ffea45a86543ccff1b12eb676a9c8058cc')
+            'e3c08f9b91611186e5ec579187ecea2a0143e5c2dc7ffc30ac6ea6e2b6d130fd'
+            '5403dead9161344b2c01027526146a250147680f4a2d32a54d40c55fc1becc8a'
+            'd55e7de60b12bca26ded4c1bb8eb5860a9092374914a201a0f6a0ed2849d099f')
 
 _kernelname=${pkgbase#linux}
 : ${_kernelname:=-ARCH}
@@ -41,7 +45,7 @@ prepare() {
   cd ${_srcname}
 
   # add upstream patch
-  #patch -p1 -i ../patch-${pkgver}
+  patch -p1 -i ../patch-${pkgver}
 
   # add latest fixes from stable queue, if needed
   # http://git.kernel.org/?p=linux/kernel/git/stable/stable-queue.git
@@ -52,6 +56,9 @@ prepare() {
   # https://bugs.archlinux.org/task/56711
   patch -Np1 -i ../0002-Revert-drm-i915-edp-Allow-alternate-fixed-mode-for-e.patch
 
+  # https://bugs.archlinux.org/task/56780
+  patch -Np1 -i ../0003-ACPI-watchdog-Prefer-iTCO_wdt-always-when-WDAT-table.patch
+
   cat ../config - >.config <<END
 CONFIG_LOCALVERSION="${_kernelname}"
 CONFIG_LOCALVERSION_AUTO=n