Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp550638imm; Wed, 19 Sep 2018 03:15:40 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZt/R6DEzTpmL0/7MmHA7PA8PiImHeU1V8LcraIoV4ABMAMehn12GPWzcpYQT99ZNuY6Aui X-Received: by 2002:a63:a112:: with SMTP id b18-v6mr29380144pgf.384.1537352139954; Wed, 19 Sep 2018 03:15:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537352139; cv=none; d=google.com; s=arc-20160816; b=0ww5algE4TRTqcCqxUbNJZtBRY8l3il/2w1vucbHDnRyGJ9N5qnDcYhwBznTD4oWse hOMgHtLAohsPstq73/1Wv7Mn2u68qYLt+GMohpahbGyY06czMKIP1PfMQDMKjho7PoXp j20DAu799yOhoKBWwRYiRHMKts4mj7StAK7d8/PP+mklNWZFjNNhHpSmWkGuDRct3e7c wnQjZ0pMIM/iPDWYzjBcoqoCCg6PXEkDhuSGV/bdZO87NiRCaxs1TGmt6oe2JHZ346z0 TlDmPOUUecxxB4H1vrHD1wAbuzf23dd9D2UmpvDeozsntUGfqU6JoC79hkvbYluWYlh6 bJbA== 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=XIJvzK1ZeoQUugu0xJqc0oe/nQSluxxSu6KeF3a9Woo=; b=tbu/E0+WDY2HWLYOqzVnPETMcYX7errrJaCA/1q2SlVjWXCJylyR5RSqIVPBMmObrU CTJ1LKgsOYitbCC4lS6LqB9M47yJ46GnkWBH0XUKviB1C/M0ptQlxw01OhGM73zDDVIF Fw1AeYSPei6Eb1x9jEQJ07VRRtiO9tVzanK8rPb2Pt0xKbZfznpqqh5uRPBYiTKwkAYr Kol0Zq7GGnd1j1TvQ+zCa3TO/bn0qQ5Wf6Qp1gSRUGKN+HaBkFZOkUcddx/vbnZqcOma rEBtjqszeVLVSG1Cwks4s7eKXwidVgmrRtS/o+xNOmsH8SrJy+ZeItLxR1bqJI7zFtzt k4zQ== 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 n15-v6si22276639pgc.309.2018.09.19.03.15.23; Wed, 19 Sep 2018 03:15:39 -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 S1731040AbeISPw3 (ORCPT + 99 others); Wed, 19 Sep 2018 11:52:29 -0400 Received: from mail-oi0-f67.google.com ([209.85.218.67]:45691 "EHLO mail-oi0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728334AbeISPw3 (ORCPT ); Wed, 19 Sep 2018 11:52:29 -0400 Received: by mail-oi0-f67.google.com with SMTP id t68-v6so4531588oie.12; Wed, 19 Sep 2018 03:15:16 -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=XIJvzK1ZeoQUugu0xJqc0oe/nQSluxxSu6KeF3a9Woo=; b=UNIzR2+7x2IRbMvtyxgWQvLenYIkUNYuDWjkTNr54Zi60KkIOlS5jdCTNvS1Tzp25X oKR17LhO8tJpaaCv3EhGElXzbUPp3MIBr5aYUp0cETSf0eHEJZ+OQfhiD74Zdp87CatQ iG+lqsIep/LDCY+rCj4SfupncMeFdNe9UvJU8A+dzlLj/KibQXnZQnxLnad8J7uhgDwz hriaL4MYTpivMFh3Gjwy3/JjvrUm5jgMKEJYij7Dl1b6BlIrit0JevhMptwiq2Rm1L1o kMKmYNOb1L2Zu25GnySjIG+HHkBeDO+7JI2hiz87jDr6nFwJwW4u+Jz1rB/NJ8CqXvMQ gdZw== X-Gm-Message-State: APzg51DgOh+oWk51n0HSQIvyGC2c2vJ1z0SbK9Ynm9PQRdeaCGXQyDy4 qNdz3gzDFsuIvX4Ef9Vi8iPu+QDd3cbT//uxc0g= X-Received: by 2002:aca:e6d4:: with SMTP id d203-v6mr1178599oih.311.1537352115901; Wed, 19 Sep 2018 03:15:15 -0700 (PDT) MIME-Version: 1.0 References: <020db877db6a8d39808dfaef2a5162f541f0853b.1537275915.git.yu.c.chen@intel.com> In-Reply-To: From: "Rafael J. Wysocki" Date: Wed, 19 Sep 2018 12:15:04 +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 11:03 AM Rafael J. Wysocki wrote: > > 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 I should have said "I would put it under #ifdef" here, sorry for the possible confusion. > 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