Received: by 10.223.185.116 with SMTP id b49csp1012019wrg; Wed, 21 Feb 2018 10:32:38 -0800 (PST) X-Google-Smtp-Source: AH8x226ttvhUZQ+t49wd8GlJ7ECI0BE/UBsHt3g28FNKC1uKuG1GbIDLZq/3/WiTcwTTGBjyDWIC X-Received: by 10.98.86.151 with SMTP id h23mr4120630pfj.79.1519237958643; Wed, 21 Feb 2018 10:32:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519237958; cv=none; d=google.com; s=arc-20160816; b=pRUFk3ZXd1SeU/jpr6C6uR0r9we1cD3x28M65Lnoe5hvwhQ8L/I+co7zktIdxyGcnU VsYDVH149ajP0/qFFAPKhnP5guB8YXnmG7t3TOXksu6eAn+Yu2GoKUxS7MN5alAUTsbR ejibKVqpGeNwcyyNq5scp0hjaQDarHZ9Z4LYC3YfgBylT1DddFtes6wu9zrJXuwO2EmT 9li1On9QTcCBEvCveVIDNIy1f2Bsj3TD0IcQVBl5lZYtuABBJHWnHGz5oZU8ocW1t5XR l3Om/Biz1l9zCVmcnG0EMtWCAsG1sK1zba0sFlS2QzGFWJqo5d5/LxCzd0Zgmk6DECAf /kgg== 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=g9aoSn4q71gUjfiBVkAz6f6dHq8U3M1+CcTpkPm7EK8=; b=uqjkF1Suq5ly2C25dSwHmqAvbnPFH7MR1ISGa9vvVun2C2Dwe/jmVtqBQ2ujMnSzkO g9FDaMue1nQCEzzoRavFGlmQj2mk6Uklyy4inKun4CDbXp1Be5schQwCSOvup0Mm7n7G +1HqKkBUqGBDle3pNaQm+8F9WmJ2iCfTke+CVdV6rUgfc8hEgknFmcMDS+OFZCxWHSS8 rHS6m2hmg++gwZjxPamEXBRn53htFp+eUmrUTuCS4WS5AAUyB9qT22wsDbh21NceQkWp NYJkwP13RflHXOHzelhcoi0prFrsCpKX2CoQcqH2RsnZ52ki8pJN2TVElBPldCvWaqLy nrqw== 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 4si1323924pgh.771.2018.02.21.10.32.24; Wed, 21 Feb 2018 10:32:38 -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 S965101AbeBUNHJ (ORCPT + 99 others); Wed, 21 Feb 2018 08:07:09 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:41466 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965068AbeBUNHG (ORCPT ); Wed, 21 Feb 2018 08:07:06 -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 80A33F78; Wed, 21 Feb 2018 13:07:05 +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.15 036/163] x86/kexec: Make kexec (mostly) work in 5-level paging mode Date: Wed, 21 Feb 2018 13:47:45 +0100 Message-Id: <20180221124532.287826013@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180221124529.931834518@linuxfoundation.org> References: <20180221124529.931834518@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.15-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