Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp271887imm; Thu, 20 Sep 2018 23:22:51 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbH+0UAI5szFx4P5qvdLT8lDe5rvBPfeKmuWPLp+L3vYeVV4fXKryLqSIBmslzjZcC1639y X-Received: by 2002:a17:902:8f93:: with SMTP id z19-v6mr42306916plo.263.1537510971248; Thu, 20 Sep 2018 23:22:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537510971; cv=none; d=google.com; s=arc-20160816; b=aETAK6SFIYZQtG9Bb97qkAtVzfJUXCzgmlmSuz6Do+h8cvBS/6RQg/rMw94Hp+CvIj xn8viT7jPur1k2PBnVfAZ2Sjt0yfFGzQ8fAgkn1Pps1WnA3npmpfAphVL1qYxK8GiM6n g3m+KWSQ71g7zaAKywBKrghEssGc1BVQ1gdWi0NBjmzj6mmHqPeqJB550XZEaJRPYd9g OT2/d9gjNqkuHzzWlsPgJnaz91x/+u79frpDyCaACZXtXm/vouD/ZKo6rPJYWVd3/XKH OHVCdw4tbwENId9tguicmyNdASWY7MqGoEKI9VHh84nP2exnX4BAfqljWY6WHUXuf+Zn nO3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=Zka9EYPkA51Oe9g2vtAPi/CsryKFO0psvC1j+4dWzmw=; b=dXkVbVwUfOQKbXAQNN23ojZyQVSc5FDFqLZGp6Iq4rjnk0L1T0cwejmuQqB9TIP1lh 40ZvzuyclC8FVIKm5hD2/+0UgE6VicbpkTUOspzV9bROef3yD68hcBKw8uwO28Q8YsuB EhM7d4Gljx/NnaoxIjXIbp3ARAyo1osSu/xo/UU6t3o4Xbupyk3Xr1+IPUEpsiJj6Ez3 1XD/T9reP9ZH9LJpjX+SmILP3dQEJLGXnfrJrwUwRm/wvhCu8c6zKrMzjcfATPweDMe3 fipuFqBqoyVCgEI6LL3R1TNWmleZQUgC6I7luWkhWsoRxoKh6LXwV0pK3keI7HTKIbz1 3SDA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a5-v6si25128442pls.389.2018.09.20.23.22.35; Thu, 20 Sep 2018 23:22:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389448AbeIUMJB (ORCPT + 99 others); Fri, 21 Sep 2018 08:09:01 -0400 Received: from mga01.intel.com ([192.55.52.88]:32150 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389205AbeIUMJA (ORCPT ); Fri, 21 Sep 2018 08:09:00 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Sep 2018 23:21:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,283,1534834800"; d="scan'208";a="74799022" Received: from chenyu-desktop.sh.intel.com ([10.239.160.116]) by orsmga007.jf.intel.com with ESMTP; 20 Sep 2018 23:21:37 -0700 From: Chen Yu To: Thomas Gleixner , "Rafael J. Wysocki" Cc: Pavel Machek , Len Brown , Zhimin Gu , Chen Yu , x86@kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, "Rafael J. Wysocki" Subject: [PATCH 10/12][v4] x86-32, hibernate: Switch to relocated restore code during resume on 32bit system Date: Fri, 21 Sep 2018 14:28:22 +0800 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhimin Gu On 64bit system, code should be executed in a safe page during page restoring, as the page where instruction is running during resume might be scribbled and causes issues. Although on 32 bit, we only suspend resuming by same kernel that did the suspend, we'd like to remove that restriction in the future. Porting corresponding code from 64bit system: Allocate a safe page, and copy the restore code to it, then jump to the safe page to run the code. Cc: "Rafael J. Wysocki" Signed-off-by: Zhimin Gu Acked-by: Pavel Machek Signed-off-by: Chen Yu --- arch/x86/power/hibernate.c | 2 -- arch/x86/power/hibernate_32.c | 4 ++++ arch/x86/power/hibernate_asm_32.S | 7 +++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/arch/x86/power/hibernate.c b/arch/x86/power/hibernate.c index 4935b8139229..7383cb67ffd7 100644 --- a/arch/x86/power/hibernate.c +++ b/arch/x86/power/hibernate.c @@ -212,7 +212,6 @@ int arch_hibernation_header_restore(void *addr) return 0; } -#ifdef CONFIG_X86_64 int relocate_restore_code(void) { pgd_t *pgd; @@ -251,4 +250,3 @@ int relocate_restore_code(void) __flush_tlb_all(); return 0; } -#endif diff --git a/arch/x86/power/hibernate_32.c b/arch/x86/power/hibernate_32.c index a44bdada4e4e..a9861095fbb8 100644 --- a/arch/x86/power/hibernate_32.c +++ b/arch/x86/power/hibernate_32.c @@ -158,6 +158,10 @@ asmlinkage int swsusp_arch_resume(void) temp_pgt = __pa(resume_pg_dir); + error = relocate_restore_code(); + if (error) + return error; + /* We have got enough memory and from now on we cannot recover */ restore_image(); return 0; diff --git a/arch/x86/power/hibernate_asm_32.S b/arch/x86/power/hibernate_asm_32.S index 6b2b94937113..e9adda6b6b02 100644 --- a/arch/x86/power/hibernate_asm_32.S +++ b/arch/x86/power/hibernate_asm_32.S @@ -39,6 +39,13 @@ ENTRY(restore_image) movl restore_cr3, %ebp movl mmu_cr4_features, %ecx + + /* jump to relocated restore code */ + movl relocated_restore_code, %eax + jmpl *%eax + +/* code below has been relocated to a safe page */ +ENTRY(core_restore_code) movl temp_pgt, %eax movl %eax, %cr3 -- 2.17.1