From patchwork Fri Apr 1 16:53:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 8726861 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6CF429F39A for ; Fri, 1 Apr 2016 17:04:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7E022203B6 for ; Fri, 1 Apr 2016 17:04:10 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 886B5203B1 for ; Fri, 1 Apr 2016 17:04:09 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1am2Sg-0006AX-3p; Fri, 01 Apr 2016 17:02:18 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1am2Nk-0008Oh-W8 for linux-arm-kernel@lists.infradead.org; Fri, 01 Apr 2016 16:57:18 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5518B361; Fri, 1 Apr 2016 09:56:04 -0700 (PDT) Received: from melchizedek.cambridge.arm.com (melchizedek.cambridge.arm.com [10.1.209.158]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B92833F21A; Fri, 1 Apr 2016 09:57:11 -0700 (PDT) From: James Morse To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v7 16/16] arm64: hibernate: Prevent resume from a different kernel version Date: Fri, 1 Apr 2016 17:53:40 +0100 Message-Id: <1459529620-22150-17-git-send-email-james.morse@arm.com> X-Mailer: git-send-email 2.8.0.rc3 In-Reply-To: <1459529620-22150-1-git-send-email-james.morse@arm.com> References: <1459529620-22150-1-git-send-email-james.morse@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160401_095713_766283_240465C0 X-CRM114-Status: GOOD ( 17.48 ) X-Spam-Score: -7.9 (-------) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lorenzo Pieralisi , Geoff Levand , Catalin Marinas , Will Deacon , AKASHI Takahiro , James Morse MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Resuming using a different kernel version is fragile, while there are sufficient details in the hibernate arch-header to perform the restore, changes in the boot process can have a long-lasting impact on the system. In particular, if the EFI stub causes more runtime services memory to be allocated, the amount of memory left for linux is reduced. If we are lucky, this will cause restore to fail with the message: > PM: Image mismatch: memory size If we are unlucky, the system will explode sometime later when an EFI runtime services call is made. Prevent resuming with a different kernel build, by storing UTS_VERSION in the hibernate header. This also ensures the page size and va bits configuration remain the same. Signed-off-by: James Morse --- arch/arm64/kernel/hibernate.c | 35 +++++------------------------------ 1 file changed, 5 insertions(+), 30 deletions(-) diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.c index 279c556ee24b..486315249f2a 100644 --- a/arch/arm64/kernel/hibernate.c +++ b/arch/arm64/kernel/hibernate.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -42,8 +43,6 @@ #define pud_index(x) 0 #endif -#define TCR_IPS_BITS (0x7UL<<32) - /* * Hibernate core relies on this value being 0 on resume, and marks it * __nosavedata assuming it will keep the resume kernel's '0' value. This @@ -54,17 +53,6 @@ */ extern int in_suspend; -/* - * This value is written to the hibernate arch header, and prevents resuming - * from a hibernate image produced by an incompatible kernel. If you change - * a value that isn't saved/restored by hibernate, you should change this value. - * - * For example, if the mair_el1 values used by the kernel are changed, you - * should prevent resuming from a kernel with incompatible attributes, as these - * aren't saved/restored. - */ -#define HIBERNATE_VERSION KERNEL_VERSION(4, 6, 0) - /* Find a symbols alias in the linear map */ #define LMADDR(x) phys_to_virt(virt_to_phys(x)) @@ -81,8 +69,7 @@ extern char hibernate_el2_vectors[]; extern char el2_setup[]; struct arch_hibernate_hdr_invariants { - unsigned long version; - unsigned long tcr_el1; /* page_size, va bit etc */ + char uts_version[__NEW_UTS_LEN + 1]; }; /* These values need to be know across a hibernate/restore. */ @@ -104,11 +91,8 @@ static struct arch_hibernate_hdr { static inline void arch_hdr_invariants(struct arch_hibernate_hdr_invariants *i) { - i->version = HIBERNATE_VERSION; - asm volatile("mrs %0, tcr_el1" : "=r"(i->tcr_el1)); - - /* IPS bits vary on big/little systems, mask them out */ - i->tcr_el1 &= ~TCR_IPS_BITS; + memset(i, 0, sizeof(*i)); + memcpy(i->uts_version, init_utsname()->version, sizeof(i->uts_version)); } int pfn_is_nosave(unsigned long pfn) @@ -155,18 +139,9 @@ int arch_hibernation_header_restore(void *addr) struct arch_hibernate_hdr_invariants invariants; struct arch_hibernate_hdr *hdr = addr; - /* - * If this header is ancient, it may be smaller than we expect. - * Test the version first. - */ - if (hdr->invariants.version != HIBERNATE_VERSION) { - pr_crit("Hibernate image not compatible with this kernel version!\n"); - return -EINVAL; - } - arch_hdr_invariants(&invariants); if (memcmp(&hdr->invariants, &invariants, sizeof(invariants))) { - pr_crit("Hibernate image not compatible with this kernel configuration!\n"); + pr_crit("Hibernate image not generated by this kernel!\n"); return -EINVAL; }