Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp15668imm; Thu, 30 Aug 2018 06:01:12 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY8/ZxuOxWdH7D2WobC5SN3sFdMRydSJ5pN1VhIh3wGJmaHAOmJ4BayYUsnlHXue4X9cTfG X-Received: by 2002:a63:6b03:: with SMTP id g3-v6mr7550178pgc.57.1535634072779; Thu, 30 Aug 2018 06:01:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535634072; cv=none; d=google.com; s=arc-20160816; b=lvVJsTenAQKmrj0fsJszuUg3vKkiWT6moLSa0CttFvYNEXvzHQa9BZFy6zlfmT8LN8 5KyM4G/EVccaN8fXxebMTA4+YpyMd8pVrxCoAHANN9lUrA5KdJGDLpTb0tsTI4o9iWfB DuWswNFI6DIb2tVqa8dpXyC4kRZSG/5bF74tXajxVa5z4bqA+TXbwm/EW3sYDxIFdnvF VyhRgrwf5Zo7mTa95tmdXJi22e+0BCgnkiQIeKVhi1S6eqIdffj+JI+shFe4ItcQofwd xAnsvR6fLfNrvYtD05pczwZB0fMGKNxdgPkLudtqjxfYZFFaICWm9/Rv3QzRQdgkTn7l Z3tA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date :arc-authentication-results; bh=nykjX8gE2gUHrw/5l0CK7CKOQ4hGwC4gjEnBOTYFSVk=; b=AHBkxqcuU0g05nhFC/PLTOPQenXupIyngg4pOoxgvNNcI2u2axsAelQwNrFSs5acx7 XDtPW6tpGec8egh41OYZmbTVPpdRwBpqfA9ZzewszUyv+amStE4M566C3ZVYrDbNKEWQ kFYZswaZq1gMrG5qRh37THiSUZPg/cj75N39sCSD523OBRCkaJ0+Hof5t4rcOxSR2gHp fW330ZcKv2yvehiBNXCcW0gi5DGLs5hJ5NyEtTVEAxTOHvz+89C2AsuALysdscxjJdPb LT88wIrmdvkNPRyl/BCYNzx1NQ1t3kMVyR2KViQmBmQMgkcWGKijWjJ6SkrdUSqoK82k d0AQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i2-v6si6421781plt.112.2018.08.30.06.00.56; Thu, 30 Aug 2018 06:01:12 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728932AbeH3RBW (ORCPT + 99 others); Thu, 30 Aug 2018 13:01:22 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:50112 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728638AbeH3RBW (ORCPT ); Thu, 30 Aug 2018 13:01:22 -0400 Received: from hsi-kbw-5-158-153-52.hsi19.kabel-badenwuerttemberg.de ([5.158.153.52] helo=nanos.tec.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1fvMXW-0003EC-5a; Thu, 30 Aug 2018 14:59:10 +0200 Date: Thu, 30 Aug 2018 14:59:09 +0200 (CEST) From: Thomas Gleixner To: Gu Zhimin cc: "Rafael J. Wysocki" , Len Brown , Ingo Molnar , "H. Peter Anvin" , Pavel Machek , Yu Chen , x86@kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/3] x86, hibernate: Extract the common code of 64/32 bit system In-Reply-To: <541d9caef16c4a6c6e0ef160f607566c61c081c9.1535361949.git.kookoo.gu@intel.com> Message-ID: References: <541d9caef16c4a6c6e0ef160f607566c61c081c9.1535361949.git.kookoo.gu@intel.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 27 Aug 2018, Gu Zhimin wrote: > diff --git a/arch/x86/power/hibernate.c b/arch/x86/power/hibernate.c > new file mode 100644 > index 0000000..6f91f7b > --- /dev/null > +++ b/arch/x86/power/hibernate.c > @@ -0,0 +1,255 @@ > +/* > + * Hibernation support for x86 > + * > + * Distribute under GPLv2 We have SPDX identifiers for that and not some randomly chosen license hint. > + > +/* > + * pfn_is_nosave - check if given pfn is in the 'nosave' section This is a half baken kernel doc header. > + */ > + Random new line. > +int pfn_is_nosave(unsigned long pfn) > +{ > + unsigned long nosave_begin_pfn = __pa_symbol(&__nosave_begin) >> PAGE_SHIFT; > + unsigned long nosave_end_pfn = PAGE_ALIGN(__pa_symbol(&__nosave_end)) >> PAGE_SHIFT; Instead of blindly copying stuff please fix it so it matches kernel coding rules. > + return (pfn >= nosave_begin_pfn) && (pfn < nosave_end_pfn); The brackets are pointless > +} > + > +#ifdef CONFIG_X86_64 > +static int relocate_restore_code(void) > +{ > + pgd_t *pgd; > + p4d_t *p4d; > + pud_t *pud; > + pmd_t *pmd; > + pte_t *pte; > + > + relocated_restore_code = get_safe_page(GFP_ATOMIC); > + if (!relocated_restore_code) > + return -ENOMEM; > + > + memcpy((void *)relocated_restore_code, core_restore_code, PAGE_SIZE); > + > + /* Make the page containing the relocated code executable */ > + pgd = (pgd_t *)__va(read_cr3_pa()) + > + pgd_index(relocated_restore_code); > + p4d = p4d_offset(pgd, relocated_restore_code); > + if (p4d_large(*p4d)) { > + set_p4d(p4d, __p4d(p4d_val(*p4d) & ~_PAGE_NX)); > + goto out; > + } > + pud = pud_offset(p4d, relocated_restore_code); > + if (pud_large(*pud)) { > + set_pud(pud, __pud(pud_val(*pud) & ~_PAGE_NX)); > + goto out; > + } > + pmd = pmd_offset(pud, relocated_restore_code); > + if (pmd_large(*pmd)) { > + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_NX)); > + goto out; > + } > + pte = pte_offset_kernel(pmd, relocated_restore_code); > + set_pte(pte, __pte(pte_val(*pte) & ~_PAGE_NX)); > +out: > + __flush_tlb_all(); > + return 0; > +} > + > +#define MD5_DIGEST_SIZE 16 > + > +struct restore_data_record { > + unsigned long jump_address; > + unsigned long jump_address_phys; > + unsigned long cr3; > + unsigned long magic; > + u8 e820_digest[MD5_DIGEST_SIZE]; > +}; > + > +#if IS_BUILTIN(CONFIG_CRYPTO_MD5) > +/** > + * get_e820_md5 - calculate md5 according to given e820 table > + * > + * @table: the e820 table to be calculated > + * @buf: the md5 result to be stored to > + */ > +static int get_e820_md5(struct e820_table *table, void *buf) > +{ > + struct crypto_shash *tfm; > + struct shash_desc *desc; > + int size; > + int ret = 0; > + > + tfm = crypto_alloc_shash("md5", 0, 0); > + if (IS_ERR(tfm)) > + return -ENOMEM; > + > + desc = kmalloc(sizeof(struct shash_desc) + crypto_shash_descsize(tfm), > + GFP_KERNEL); > + if (!desc) { > + ret = -ENOMEM; > + goto free_tfm; > + } > + > + desc->tfm = tfm; > + desc->flags = 0; > + > + size = offsetof(struct e820_table, entries) + > + sizeof(struct e820_entry) * table->nr_entries; > + > + if (crypto_shash_digest(desc, (u8 *)table, size, buf)) > + ret = -EINVAL; > + > + kzfree(desc); > + > +free_tfm: > + crypto_free_shash(tfm); > + return ret; > +} > + > +static void hibernation_e820_save(void *buf) > +{ > + get_e820_md5(e820_table_firmware, buf); So if get_e820_md5() fails, then it will hibernate nevertheless. Why is that error code not propagated? Thanks, tglx