Received: by 10.192.165.148 with SMTP id m20csp1578206imm; Thu, 3 May 2018 01:40:16 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq92Z8fUnRKrm5FxCMDOoqVxYWxOmVMa6HjZsdhKEzMoC27sODlRn/sjF9sNyPc3IYPGcEs X-Received: by 10.98.129.5 with SMTP id t5mr22144730pfd.215.1525336815956; Thu, 03 May 2018 01:40:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525336815; cv=none; d=google.com; s=arc-20160816; b=zcFxjvicq5HsiEn+SNn/Fw2AabMKzpl+orWBoQvtl5hVKHKXcJT6jhKu7cxzPABdeo MrJf3/Rfoskz9NecH51K0EqlAC2EeD4xPB1l0VG56RKAI4QLqPOHW8h8bLrvbw4O3uSr qMMnF0t65vHBiCh4OajlzE+0Sux2M9LYhIhfaSt2swuphs5dwGiNAWngqeZC2CkELVeR zmH14SHDjLcXJOCCf6A/F5wvhWt0+JiwGKskniZ1EGEi8iIfEYmdUt371gE/LKqd7T7v YMYZdEelMPUjz4eyoHthR6hpDUxInEjHOaQwAuh7vFBTBiaJOyMg2CabLq532rxux+qZ 5VFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=2pal5ZG9sM1eixivp+gfTyZ9HcGCEj9Ir5/ubwDg/cg=; b=XgV/23xqejWsFEgoYhF9eipoXkfsa7ZMOX77zRvYK6bZelDpvTlWVVQX1vnlZNOXpD iUdgpOW6aLcSVLXrgIQNAgEOvs2OLd1LF5ZQY4/RbiAzj8IPAFtMEdaINVyGYPUkRAD3 RrN5Z3afirWM1V/alO58mRJ7RWf5/uJLoJxI0rJJQHb1sPm4Or29S6dp/YGpl4IC9pR4 1e0B08g9MbGZhTSV+jii8Z/dgAqA5QOjUWvMCt7A8Pnxrh5RfRoKGfZP6V1+HzXneODN xTCLeyqNq2XbBf1wdUordSoA5OKvVxt90WTd3tcqw7XGABRQCVPp+sji3grhFLDuhoNa fClA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=y/nWKeAt; 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 s88si13628775pfe.290.2018.05.03.01.40.02; Thu, 03 May 2018 01:40:15 -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; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=y/nWKeAt; 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 S1751469AbeECIjA (ORCPT + 99 others); Thu, 3 May 2018 04:39:00 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:38907 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751196AbeECIiv (ORCPT ); Thu, 3 May 2018 04:38:51 -0400 Received: by mail-pf0-f195.google.com with SMTP id o76so14135381pfi.5 for ; Thu, 03 May 2018 01:38:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=2pal5ZG9sM1eixivp+gfTyZ9HcGCEj9Ir5/ubwDg/cg=; b=y/nWKeAt6Ob436JH38mktN9YFLMYSYMALv5FZ0W0r+OPWty4N/HefaIrck7m6aV6P6 r+gA5JhuYTdTE+3gFtCZFJmkpy00Y/onCTP1OWONcdy3PREEziFqdA59EbjytMN4Qw+Y dIe0TB37KVChMzkSEuWiRMRpKMEcOVIGj4goS4rWZIbWe9F3VjG7zBMVf42IbF89V5VZ vJhgKO0v6yB5DLQF8QvaYIJuR1dHXSQ0uCNJ3x8z63TAXpiq5h5lhyvlpzRJ4S2DaPFY qu7FcjgXeIeaVayjCHWO6h0pWtIBuDjwWYoa1ZXP/qU7IW0lnTB112Y8jlkUc7budRo+ 0VhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=2pal5ZG9sM1eixivp+gfTyZ9HcGCEj9Ir5/ubwDg/cg=; b=oP4YxtMjkQgUdhrcdLCmcQEQ0oSRRZfzQSBmUqABIR+/hrIWh1NNN8XRo51kBKRWsW p7iOosNGZMmXTISHgQ8BPvkkyStZX/u/DKpmV5AzVvCD4Y0m02Hp/CEes7y1kovpehM2 HeyGxo5OJm91WNLp2VmpqDEAtBxShQj1XbdSIC8S0/WiRVV7Qg0xzG3HRO7Pw/6QzRIy mQlbhUGgHt1JkJ8CtqBiphdO+xAzd3TGsVHB63Ga3sVZuChcEAOK5rK70zCyau5SuZ5I lQzv+mV17yfLrbTs8wJE7nL9hN0Sd1io/WhpMkPMO/PHu8Lj6gc+13IZMIXoukn+QTBi VQbA== X-Gm-Message-State: ALQs6tCHV+Sdo1ZlrGh/kEP0lmbhwYiD7075QK5rIM/HLXPe1+Pe0gLN INjo3FKQMDb5zXprrCkaLKGi11DTev4iBQ== X-Received: by 2002:a17:902:781:: with SMTP id 1-v6mr23271878plj.150.1525336730726; Thu, 03 May 2018 01:38:50 -0700 (PDT) Received: from kshutemo-mobl1.localdomain ([134.134.139.83]) by smtp.gmail.com with ESMTPSA id c8sm24323842pfi.96.2018.05.03.01.38.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 May 2018 01:38:50 -0700 (PDT) Received: by kshutemo-mobl1.localdomain (Postfix, from userid 1000) id 46DBC3003A2; Thu, 3 May 2018 11:38:49 +0300 (+03) Date: Thu, 3 May 2018 11:38:49 +0300 From: "Kirill A. Shutemov" To: Hugh Dickins Cc: "Kirill A. Shutemov" , Ingo Molnar , Thomas Gleixner , "H. Peter Anvin" , Dave Hansen , linux-kernel@vger.kernel.org, x86@kernel.org Subject: Re: [PATCH] x86/boot/compressed: Exclude 'top_pgtable' from relocation Message-ID: <20180503083849.j42uzp6jjpauk475@kshutemo-mobl1> References: <20180502160816.35986-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180323 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 02, 2018 at 08:42:30PM -0700, Hugh Dickins wrote: > On Wed, 2 May 2018, Kirill A. Shutemov wrote: > > > startup_64() copies kernel (including .data section) to the new place. > > It's required for safe in-place decompression. > > > > This is a problem if the original place is referenced: by mistake I've > > put 'top_pgtable' into .data section and the address is loaded into CR3. > > If the original place gets overwritten during image decompression the > > kernel will crash and the machine will be rebooted. > > > > Move 'top_pgtable' into .pgtable section where the rest of page tables > > are. This section is not subject for relocation. > > > > Signed-off-by: Kirill A. Shutemov > > Fixes: e9d0e6330eb8 ("x86/boot/compressed/64: Prepare new top-level page table for trampoline") > > Thanks for the Cc, Kirill, which I presume was because I'd mentioned > to you that I was unable to boot 4.17-rc on laptop or workstation. Right. > Which is still so with 4.17-rc3, and I'm sorry to say still so with this > patch: even if I add the fix which I think this patch needs, see below. Hm.. Could you share your config? IIRC, you use legacy boot. What bootloader? > I did bisect on Monday, and the first bad was your commit 194a9749c73d > "x86/boot/compressed/64: Handle 5-level paging boot if kernel is above 4G". > (Cc'ing Dave since his PTI Global work was my other suspect, but that's > off the hook - if I revert just 194a9749c73d then I have no trouble.) > > Am I really the only one getting immediate reboot on x86_64? There was one more thread: http://lkml.kernel.org/r/5ecfeb13-84e4-f1ef-bd30-391674b2050a@gmail.com But no firm conclusion, only blaming GCC without a good reason. BTW, what compiler do you use? > Perhaps everyone else has machines with 5-level page tables now ?-) No :) > I've looked at the changes a little, and tried a few things (hoping to > avoid a long back and forth describing and trying things for you); but > no success yet, and rather out of my depth with these changes - I've > not had to delve into boot/compressed before. > > (I did briefly get excited by the > trampoline_32bit + TRAMPOLINE_32BIT_PGTABLE_OFFSET > in cleanup_trampoline(), which lacks a "/ sizeof(unsigned long)"; > but since ...PGTABLE_OFFSET is 0 anyway, that's nothing but cosmetic.) It worth fixing anyway. Thanks for pointing it out. > > --- > > arch/x86/boot/compressed/head_64.S | 8 ++++++++ > > arch/x86/boot/compressed/pgtable_64.c | 4 +--- > > 2 files changed, 9 insertions(+), 3 deletions(-) > > > > diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S > > index fca012baba19..c433c21703e6 100644 > > --- a/arch/x86/boot/compressed/head_64.S > > +++ b/arch/x86/boot/compressed/head_64.S > > @@ -649,3 +649,11 @@ boot_stack_end: > > .balign 4096 > > pgtable: > > .fill BOOT_PGT_SIZE, 1, 0 > > + > > +/* > > + * The page table is going to be used instead of page table in the trampoline > > + * memory. > > + */ > > + .global top_pgtable > > +top_pgtable: > > + .fill PAGE_SIZE, 1, 0 > > diff --git a/arch/x86/boot/compressed/pgtable_64.c b/arch/x86/boot/compressed/pgtable_64.c > > index 32af1cbcd903..3a0578f54550 100644 > > --- a/arch/x86/boot/compressed/pgtable_64.c > > +++ b/arch/x86/boot/compressed/pgtable_64.c > > @@ -25,10 +25,8 @@ static char trampoline_save[TRAMPOLINE_32BIT_SIZE]; > > /* > > * The page table is going to be used instead of page table in the trampoline > > * memory. > > - * > > - * It must not be in BSS as BSS is cleared after cleanup_trampoline(). > > */ > > -static char top_pgtable[PAGE_SIZE] __aligned(PAGE_SIZE) __section(.data); > > +extern char *top_pgtable; > > Doesn't that need to be extern char top_pgtable[] ? Ouch. That's embarrassing. So in my case the top_pgtable is zero and apparently it's good enough place to put the page table. It boots :P The patch is bogus and I still don't understand what is going on. Could you please check if bypassing cleanup_trampoline() altogether fixes the issue for you: diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index fca012baba19..73821ac626f6 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -367,16 +367,6 @@ trampoline_return: /* Restore the stack, the 32-bit trampoline uses its own stack */ leaq boot_stack_end(%rbx), %rsp - /* - * cleanup_trampoline() would restore trampoline memory. - * - * RSI holds real mode data and needs to be preserved across - * this function call. - */ - pushq %rsi - call cleanup_trampoline - popq %rsi - /* Zero EFLAGS */ pushq $0 popfq -- Kirill A. Shutemov