Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp484201imm; Wed, 19 Sep 2018 02:04:09 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaUUbWzNZiQq5liyedE7Z6G02Y2b4FA9r17vd1F+iFGGxKog/Lo5xx580lR8r3S1DMO0/N6 X-Received: by 2002:a63:5558:: with SMTP id f24-v6mr2907995pgm.37.1537347849447; Wed, 19 Sep 2018 02:04:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537347849; cv=none; d=google.com; s=arc-20160816; b=MJP0B5caacIvGdjoIzi92wGM/HCwbQf2PuqjxSRKfWNZPJl9vKC/2vTJXBmkEA8PJE U9aTIV+i20GRL9x2f0uuiqfB1vRcWGxUIp6bVm2frDWoFSKHJtbBO3ZKbK0MRS4dVT4k q3D8fkFDfmGfXrRElaoyjVj2Ndm9Hon7EfotngMHQ0o28vdVjroJ/wCwDNA+W8KnrOu+ 8H9/BBnWuYJx9L7qi+m4vQdjQ08VRkahZm1jQyunowrCoHb3LqU0M7EOEhE12ogfCyH6 emCgym2sj2fbeOBrIQpZjq014GlgYHHaZ5UsCAVdGuu/jKr+0sq6RPcuSuaLDK3iF8uO RFxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=lPNSXbwYrhUMrS2KJUy679KqA5d6LSje+5sW4q9fhTY=; b=OVfzmHD1HOYD/RVKLyivttYDO6b+oEP4k5C+i5a9bTuwxVnwrRf8sgDifR3KWhnCZ/ 69pk/9GYX984dzCtt28BZZSpHuEZ3hzQOnTFYeEZk58XF5qpMy5NTI6/Z5HVP4WTC5OZ 01E3CjPynj7HzY7DpqlfiWuRxBfw8NDYs2jMT7ZgaXswMJy+9Abka88gEU7tLvU1MtUt 7U7sRU8w7ugx/Pjlk6hpLGEpZENykFNF5UKOJlNsfhhVpXT5eRjI3yUDgRQdJYaFan1g s43NKC2LZIZ7QbRnTxZZQl5+2srPiuKwIXJCuHq1Rh+AOUFBG1ZtzP7Ma5Ra9KRAsTOQ 892A== 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w26-v6si19906823pgk.372.2018.09.19.02.03.53; Wed, 19 Sep 2018 02:04:09 -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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731100AbeISOk1 (ORCPT + 99 others); Wed, 19 Sep 2018 10:40:27 -0400 Received: from mail-ot1-f68.google.com ([209.85.210.68]:37216 "EHLO mail-ot1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726163AbeISOk1 (ORCPT ); Wed, 19 Sep 2018 10:40:27 -0400 Received: by mail-ot1-f68.google.com with SMTP id o13-v6so5003943otl.4; Wed, 19 Sep 2018 02:03:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=lPNSXbwYrhUMrS2KJUy679KqA5d6LSje+5sW4q9fhTY=; b=UrXy0Q2bqFEBWG1XJskAPOzWKizeaMy+Tl/ahploslTJYqoFmmzLQ9gxuNsBTDrNHE i50l3SKYAC9VK6/Gkn1vF02g7Oar5hnfsm1LnNAijun9xCGcFfyrfeaeggzTfqUsWHQp 6jpxl0s1RnwmMJvImIVXA0lp7/hUfsxd9+wcmkm4WOzPNr2LTpv3z3b9LItIkHQzpUdb FKQNS9hdkYo9O4wSnmnHITGOb+jb2tgdZCEgcYOk/DWjpgztb22IAo0cky13v1i/JU+S 9fgXH3X/oD0b54w5KZEeG/Ge+JZ/X/fucCE60PBGoScF2+JPuKPZVPxP55y4d2T/9B8O hdjg== X-Gm-Message-State: APzg51AblQ2VFx+XHaZlDERdLJKd8+7vViTm9iYNFvlXdYRQ4g61plqm Od6+9I/+RBVB0lPHNPiF0K+s6GPj6SbPUVWSLWg= X-Received: by 2002:a9d:7317:: with SMTP id e23-v6mr17042277otk.162.1537347810606; Wed, 19 Sep 2018 02:03:30 -0700 (PDT) MIME-Version: 1.0 References: <020db877db6a8d39808dfaef2a5162f541f0853b.1537275915.git.yu.c.chen@intel.com> In-Reply-To: <020db877db6a8d39808dfaef2a5162f541f0853b.1537275915.git.yu.c.chen@intel.com> From: "Rafael J. Wysocki" Date: Wed, 19 Sep 2018 11:03:19 +0200 Message-ID: Subject: Re: [PATCH 04/12][RFC v3] x86, hibernate: Extract the common code of 64/32 bit system To: "Chen, Yu C" Cc: Thomas Gleixner , "Rafael J. Wysocki" , "the arch/x86 maintainers" , Linux Kernel Mailing List , Linux PM , Pavel Machek , Len Brown , kookoo.gu@intel.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 19, 2018 at 9:32 AM Chen Yu wrote: > > From: Zhimin Gu > > Reduce the hibernation code duplication between x86-32 and x86-64 > by extracting the common code into hibernate.c. > > No functional change. > > Acked-by: Pavel Machek > Cc: "Rafael J. Wysocki" > Cc: Thomas Gleixner > Signed-off-by: Zhimin Gu > Signed-off-by: Chen Yu > --- > arch/x86/include/asm/suspend.h | 8 ++ > arch/x86/power/Makefile | 2 +- > arch/x86/power/hibernate.c | 249 +++++++++++++++++++++++++++++++++ > arch/x86/power/hibernate_32.c | 15 +- > arch/x86/power/hibernate_64.c | 221 ----------------------------- > 5 files changed, 259 insertions(+), 236 deletions(-) > create mode 100644 arch/x86/power/hibernate.c > > diff --git a/arch/x86/include/asm/suspend.h b/arch/x86/include/asm/suspend.h > index ecffe81ff65c..40b02558749f 100644 > --- a/arch/x86/include/asm/suspend.h > +++ b/arch/x86/include/asm/suspend.h > @@ -4,3 +4,11 @@ > #else > # include > #endif > +extern unsigned long restore_jump_address __visible; > +extern unsigned long jump_address_phys; > +extern unsigned long restore_cr3 __visible; > +extern unsigned long temp_level4_pgt __visible; > +extern unsigned long relocated_restore_code __visible; > +extern int relocate_restore_code(void); > +/* Defined in hibernate_asm_32/64.S */ > +extern asmlinkage __visible int restore_image(void); > diff --git a/arch/x86/power/Makefile b/arch/x86/power/Makefile > index a4701389562c..37923d715741 100644 > --- a/arch/x86/power/Makefile > +++ b/arch/x86/power/Makefile > @@ -7,4 +7,4 @@ nostackp := $(call cc-option, -fno-stack-protector) > CFLAGS_cpu.o := $(nostackp) > > obj-$(CONFIG_PM_SLEEP) += cpu.o > -obj-$(CONFIG_HIBERNATION) += hibernate_$(BITS).o hibernate_asm_$(BITS).o > +obj-$(CONFIG_HIBERNATION) += hibernate_$(BITS).o hibernate_asm_$(BITS).o hibernate.o > diff --git a/arch/x86/power/hibernate.c b/arch/x86/power/hibernate.c > new file mode 100644 > index 000000000000..fbde8f0e8fe0 > --- /dev/null > +++ b/arch/x86/power/hibernate.c > @@ -0,0 +1,249 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Hibernation support for x86 > + * > + * Copyright (c) 2007 Rafael J. Wysocki > + * Copyright (c) 2002 Pavel Machek > + * Copyright (c) 2001 Patrick Mochel I don't think this "copyright" information has any legal bearing any more at this point. I would just write it as * Authors: * 2007 Rafael J. Wysocki * 2002 Pavel Machek * 2001 Patrick Mochel as a matter of credits to the people who originally developed this code. > + */ > + > +#include > +#include > +#include > +#include > +#include > + > +#include > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +/* > + * Address to jump to in the last phase of restore in order to get to the image > + * kernel's text (this value is passed in the image header). > + */ > +unsigned long restore_jump_address __visible; > +unsigned long jump_address_phys; > + > +/* > + * Value of the cr3 register from before the hibernation (this value is passed > + * in the image header). > + */ > +unsigned long restore_cr3 __visible; > +unsigned long temp_level4_pgt __visible; > +unsigned long relocated_restore_code __visible; > + > +#ifdef CONFIG_X86_64 > +#define RESTORE_MAGIC 0x23456789ABCDEF01UL > +#else > +#define RESTORE_MAGIC 0x12345678UL > +#endif > + > +/** > + * pfn_is_nosave - check if given pfn is in the 'nosave' section > + */ > +int pfn_is_nosave(unsigned long pfn) > +{ > + unsigned long nosave_begin_pfn; > + unsigned long nosave_end_pfn; > + > + nosave_begin_pfn = __pa_symbol(&__nosave_begin) >> PAGE_SHIFT; > + nosave_end_pfn = PAGE_ALIGN(__pa_symbol(&__nosave_end)) >> PAGE_SHIFT; > + > + return pfn >= nosave_begin_pfn && pfn < nosave_end_pfn; > +} > + Since the majority of the code below in this new file is only going to be used on 64-bit to start with, I will put it under #ifdef CONFIG_X86_64 at this point and remove the #ifdef in one of the subsequent patches when 32-bit actually starts to use it. Thanks, Rafael