Received: by 10.223.185.116 with SMTP id b49csp1028678wrg; Wed, 21 Feb 2018 10:50:27 -0800 (PST) X-Google-Smtp-Source: AH8x225OR2J8N0wsfHXYZBseO2Xq15SetP9EtU+AoFHXkNNGq1nQoHvMjVbtzx/0pITX8HkRIdnE X-Received: by 2002:a17:902:8c91:: with SMTP id t17-v6mr4015012plo.233.1519239027134; Wed, 21 Feb 2018 10:50:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519239027; cv=none; d=google.com; s=arc-20160816; b=fFpRpxk+1pCjShpiFGg4Lk1KfpavUYrmrGq54eSgQXEwDiSVNPutov4FZpj0sPereC wziqEBVvr4hwpl1dzU+Pf1Ds7XImViSErPWbnePr/MGmNsURSTHfKo8MtBLC4BIsI4KD uM6kZMhV8yvgMDWbFNxLzRaHW5FBgGH+d64Ils5aVJiJ9Qs/BfpC9x6nEIOlbxsuo/l4 5/wiX3gw5ztDGY/wg3n1yd2nGCcHGG/JvZ1MeSw3h+mqVLK1h1gw2M7g042NEO7bh6h/ mphgtA0p7wckpHXGxMyWn/i3UjvtadNwoQv02fQ1vINKY0P7sSJo1+QtaN67/g6XYvkr NkpA== 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 :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=/Q9sb6EKFF+NYVgdYyI7gOKKiHJrl57dVf/0kzc4Ubs=; b=rmu+VMCJOqPiIRCmAzVp9/hGA85mU+4v3PJ8YqACy8VfVKK/OKQyuBkN0t3liP0/At j9aDEeiqNyoy2enDjMRGafto0R8nda8NzSHHQFG15jd9kXQk+ROhZnj3UM+JWbphIJ+X oc1bbaeygca8+yi+t0dfhmblMzqz0NXUpACFLGcCLsRUPEaaKe2JOLOBIH0gwy2cdp1+ U+ye1e99AUrGriKKuS1haBVafj552uabsQQDAnE5oI7AlV0F9pAEHHFtr9nJRXiSyCuG 9nqCRy30cpD3wmP4ANjMhN5Zx8zXfB1GiIXfNMO+RTGEnC71wt6BFKLAOJieQ1Zv6hQx gLjA== 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 m73si1632082pfj.131.2018.02.21.10.50.12; Wed, 21 Feb 2018 10:50:27 -0800 (PST) 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 S936308AbeBUOMA (ORCPT + 99 others); Wed, 21 Feb 2018 09:12:00 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:37740 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933066AbeBUNBK (ORCPT ); Wed, 21 Feb 2018 08:01:10 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 233571061; Wed, 21 Feb 2018 13:00:51 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Baoquan He , "Kirill A. Shutemov" , Borislav Petkov , Linus Torvalds , Peter Zijlstra , Thomas Gleixner , linux-mm@kvack.org, Ingo Molnar Subject: [PATCH 4.14 037/167] x86/kexec: Make kexec (mostly) work in 5-level paging mode Date: Wed, 21 Feb 2018 13:47:28 +0100 Message-Id: <20180221124526.630792321@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180221124524.639039577@linuxfoundation.org> References: <20180221124524.639039577@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 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 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kirill A. Shutemov commit 5bf30316991d5bcda046343ee77d823cf16fdd03 upstream. Currently kexec() will crash when switching into a 5-level paging enabled kernel. I missed that we need to change relocate_kernel() to set CR4.LA57 flag if the kernel has 5-level paging enabled. I avoided using #ifdef CONFIG_X86_5LEVEL here and inferred if we need to enable 5-level paging from previous CR4 value. This way the code is ready for boot-time switching between paging modes. With this patch applied, in addition to kexec 4-to-4 which always worked, we can kexec 4-to-5 and 5-to-5 - while 5-to-4 will need more work. Reported-by: Baoquan He Signed-off-by: Kirill A. Shutemov Tested-by: Baoquan He Cc: # v4.14+ Cc: Borislav Petkov Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: linux-mm@kvack.org Fixes: 77ef56e4f0fb ("x86: Enable 5-level paging support via CONFIG_X86_5LEVEL=y") Link: http://lkml.kernel.org/r/20180129110845.26633-1-kirill.shutemov@linux.intel.com Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/relocate_kernel_64.S | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/arch/x86/kernel/relocate_kernel_64.S +++ b/arch/x86/kernel/relocate_kernel_64.S @@ -68,6 +68,9 @@ relocate_kernel: movq %cr4, %rax movq %rax, CR4(%r11) + /* Save CR4. Required to enable the right paging mode later. */ + movq %rax, %r13 + /* zero out flags, and disable interrupts */ pushq $0 popfq @@ -126,8 +129,13 @@ identity_mapped: /* * Set cr4 to a known state: * - physical address extension enabled + * - 5-level paging, if it was enabled before */ movl $X86_CR4_PAE, %eax + testq $X86_CR4_LA57, %r13 + jz 1f + orl $X86_CR4_LA57, %eax +1: movq %rax, %cr4 jmp 1f